@toolbox-web/grid 1.13.0 → 1.14.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/all.js +1483 -1403
- package/all.js.map +1 -1
- package/index.js +11 -4
- package/index.js.map +1 -1
- package/lib/core/internal/row-animation.d.ts.map +1 -1
- package/lib/core/plugin/types.d.ts +1 -1
- package/lib/core/plugin/types.d.ts.map +1 -1
- package/lib/core/types.d.ts +44 -1
- package/lib/core/types.d.ts.map +1 -1
- package/lib/plugins/clipboard/ClipboardPlugin.d.ts +69 -8
- package/lib/plugins/clipboard/ClipboardPlugin.d.ts.map +1 -1
- package/lib/plugins/clipboard/index.d.ts +1 -1
- package/lib/plugins/clipboard/index.d.ts.map +1 -1
- package/lib/plugins/clipboard/index.js +257 -192
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/clipboard/types.d.ts +31 -0
- package/lib/plugins/clipboard/types.d.ts.map +1 -1
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/ContextMenuPlugin.d.ts +8 -0
- package/lib/plugins/context-menu/ContextMenuPlugin.d.ts.map +1 -1
- package/lib/plugins/context-menu/index.js +75 -60
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/context-menu/types.d.ts +7 -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/editors.d.ts +2 -2
- package/lib/plugins/editing/editors.d.ts.map +1 -1
- package/lib/plugins/editing/index.js +420 -381
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/editing/types.d.ts +6 -23
- package/lib/plugins/editing/types.d.ts.map +1 -1
- package/lib/plugins/export/ExportPlugin.d.ts.map +1 -1
- package/lib/plugins/export/index.js +75 -66
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/index.d.ts +1 -1
- package/lib/plugins/filtering/index.d.ts.map +1 -1
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts +1 -0
- package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts.map +1 -1
- package/lib/plugins/pinned-rows/index.js +118 -87
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pinned-rows/pinned-rows.d.ts +2 -1
- package/lib/plugins/pinned-rows/pinned-rows.d.ts.map +1 -1
- package/lib/plugins/pinned-rows/types.d.ts +23 -2
- package/lib/plugins/pinned-rows/types.d.ts.map +1 -1
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/print/index.js.map +1 -1
- package/lib/plugins/reorder/index.js.map +1 -1
- package/lib/plugins/responsive/index.js.map +1 -1
- package/lib/plugins/row-reorder/index.js.map +1 -1
- package/lib/plugins/selection/SelectionPlugin.d.ts.map +1 -1
- package/lib/plugins/selection/index.js +147 -139
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/shared/data-collection.d.ts +33 -0
- package/lib/plugins/shared/data-collection.d.ts.map +1 -0
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/umd/grid.all.umd.js +23 -23
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +2 -2
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/clipboard.umd.js +5 -5
- package/umd/plugins/clipboard.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 +7 -7
- package/umd/plugins/export.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/selection.umd.js +2 -2
- package/umd/plugins/selection.umd.js.map +1 -1
package/umd/grid.all.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(E,se){typeof exports=="object"&&typeof module<"u"?se(exports):typeof define=="function"&&define.amd?define(["exports"],se):(E=typeof globalThis<"u"?globalThis:E||self,se(E.TbwGrid={}))})(this,(function(E){"use strict";function se(){return{rowCount:-1,colCount:-1,ariaLabel:void 0,ariaDescribedBy:void 0}}function Wi(r,e,t,i,n){if(i===r.rowCount&&n===r.colCount)return!1;const o=r.rowCount;return r.rowCount=i,r.colCount=n,e&&(e.setAttribute("aria-rowcount",String(i)),e.setAttribute("aria-colcount",String(n))),i!==o&&t&&(i>0?t.setAttribute("role","rowgroup"):t.removeAttribute("role")),!0}function Vi(r,e){const t=r?.gridAriaLabel;return t||(r?.shell?.header?.title??e?.lightDomTitle??void 0)}function Ui(r,e,t,i){if(!e)return!1;let n=!1;const o=Vi(t,i);o!==r.ariaLabel&&(r.ariaLabel=o,o?e.setAttribute("aria-label",o):e.removeAttribute("aria-label"),n=!0);const s=t?.gridAriaDescribedBy;return s!==r.ariaDescribedBy&&(r.ariaDescribedBy=s,s?e.setAttribute("aria-describedby",s):e.removeAttribute("aria-describedby"),n=!0),n}const ee={STRETCH:"stretch",FIXED:"fixed"},pt={mode:"reduced-motion",duration:200,easing:"ease-out"},wt='<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>',G={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:wt,filterActive:wt,print:"🖨️"};function ji(r){return Array.from(r.querySelectorAll("tbw-grid-column")).map(t=>{const i=t.getAttribute("field")||"";if(!i)return null;const n=t.getAttribute("type")||void 0,s=n&&new Set(["number","string","date","boolean","select"]).has(n)?n:void 0,l=t.getAttribute("header")||void 0,a=t.hasAttribute("sortable"),c=t.hasAttribute("editable"),d={field:i,type:s,header:l,sortable:a,editable:c},u=t.getAttribute("width");if(u){const y=parseFloat(u);!isNaN(y)&&/^\d+(\.\d+)?$/.test(u.trim())?d.width=y:d.width=u}const h=t.getAttribute("minWidth")||t.getAttribute("min-width");if(h){const y=parseFloat(h);isNaN(y)||(d.minWidth=y)}t.hasAttribute("resizable")&&(d.resizable=!0),t.hasAttribute("sizable")&&(d.resizable=!0);const f=t.getAttribute("editor"),p=t.getAttribute("renderer");f&&(d.__editorName=f),p&&(d.__rendererName=p);const g=t.getAttribute("options");g&&(d.options=g.split(",").map(y=>{const[A,_]=y.includes(":")?y.split(":"):[y.trim(),y.trim()];return{value:A.trim(),label:_?.trim()||A.trim()}}));const w=t.querySelector("tbw-grid-column-view"),b=t.querySelector("tbw-grid-column-editor"),m=t.querySelector("tbw-grid-column-header");w&&(d.__viewTemplate=w),b&&(d.__editorTemplate=b),m&&(d.__headerTemplate=m);const x=globalThis.DataGridElement?.getAdapters?.()??[],S=w??t,R=x.find(y=>y.canHandle(S));if(R){const y=R.createRenderer(S);y&&(d.viewRenderer=y)}const L=b??t,P=x.find(y=>y.canHandle(L));if(P){const y=P.createEditor(L);y&&(d.editor=y)}return d}).filter(t=>!!t)}function mt(r,e){if((!r||!r.length)&&(!e||!e.length))return[];if(!r||!r.length)return e||[];if(!e||!e.length)return r;const t={};e.forEach(n=>{const o=t[n.field];if(o){n.header&&!o.header&&(o.header=n.header),n.type&&!o.type&&(o.type=n.type),n.sortable&&(o.sortable=!0),n.editable&&(o.editable=!0),n.resizable&&(o.resizable=!0),n.width!=null&&o.width==null&&(o.width=n.width),n.minWidth!=null&&o.minWidth==null&&(o.minWidth=n.minWidth),n.__viewTemplate&&(o.__viewTemplate=n.__viewTemplate),n.__editorTemplate&&(o.__editorTemplate=n.__editorTemplate),n.__headerTemplate&&(o.__headerTemplate=n.__headerTemplate);const s=n.renderer||n.viewRenderer,l=o.renderer||o.viewRenderer;s&&!l&&(o.viewRenderer=s,n.renderer&&(o.renderer=s)),n.editor&&!o.editor&&(o.editor=n.editor)}else t[n.field]={...n}});const i=r.map(n=>{const o=t[n.field];if(!o)return n;const s={...n};o.header&&!s.header&&(s.header=o.header),o.type&&!s.type&&(s.type=o.type),s.sortable=n.sortable||o.sortable,(n.resizable===!0||o.resizable===!0)&&(s.resizable=!0),s.editable=n.editable||o.editable,o.width!=null&&s.width==null&&(s.width=o.width),o.minWidth!=null&&s.minWidth==null&&(s.minWidth=o.minWidth),o.__viewTemplate&&(s.__viewTemplate=o.__viewTemplate),o.__editorTemplate&&(s.__editorTemplate=o.__editorTemplate),o.__headerTemplate&&(s.__headerTemplate=o.__headerTemplate);const l=o.renderer||o.viewRenderer,a=s.renderer||s.viewRenderer;return l&&!a&&(s.viewRenderer=l,o.renderer&&(s.renderer=l)),o.editor&&!s.editor&&(s.editor=o.editor),delete t[n.field],s});return Object.keys(t).forEach(n=>i.push(t[n])),i}function bt(r,e){try{r.part?.add?.(e)}catch{}const t=r.getAttribute("part");t?t.split(/\s+/).includes(e)||r.setAttribute("part",t+" "+e):r.setAttribute("part",e)}function vt(r){const e=r.effectiveConfig?.fitMode||r.fitMode||ee.STRETCH;if(e!==ee.STRETCH&&e!==ee.FIXED||r.__didInitialAutoSize||!r.isConnected)return;const t=Array.from(r._headerRowEl?.children||[]);if(!t.length)return;let i=!1;r._visibleColumns.forEach((n,o)=>{if(n.width)return;const s=t[o];let l=s?s.scrollWidth:0;for(const a of r._rowPool){const c=a.children[o];if(c){const d=c.scrollWidth;d>l&&(l=d)}}l>0&&(n.width=l+2,n.__autoSized=!0,i=!0)}),i&&le(r),r.__didInitialAutoSize=!0}function le(r){(r.effectiveConfig?.fitMode||r.fitMode||ee.STRETCH)===ee.STRETCH?r._gridTemplate=r._visibleColumns.map(t=>{if(t.width)return`${t.width}px`;const i=t.minWidth;return i!=null?`minmax(${i}px, 1fr)`:"1fr"}).join(" ").trim():r._gridTemplate=r._visibleColumns.map(t=>t.width?`${t.width}px`:"max-content").join(" "),r.style.setProperty("--tbw-column-template",r._gridTemplate)}function Yi(r){return r==null?"string":typeof r=="number"?"number":typeof r=="boolean"?"boolean":r instanceof Date||typeof r=="string"&&/\d{4}-\d{2}-\d{2}/.test(r)&&!isNaN(Date.parse(r))?"date":"string"}function Xi(r,e){const t=r[0]||{},i=Object.keys(t).map(o=>{const s=t[o],l=Yi(s);return{field:o,header:o.charAt(0).toUpperCase()+o.slice(1),type:l}}),n={};return i.forEach(o=>{n[o.field]=o.type||"string"}),{columns:i,typeMap:n}}const Zi=/{{\s*([^}]+)\s*}}/g,F="__DG_EMPTY__",Qi=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,Ji=/__(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 en(r){return!r||typeof r!="string"?"":r.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const tn=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"]),yt=/^on\w+$/i,nn=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),rn=/^\s*(javascript|vbscript|data|blob):/i;function V(r){if(!r||typeof r!="string")return"";if(r.indexOf("<")===-1)return r;const e=document.createElement("template");return e.innerHTML=r,on(e.content),e.innerHTML}function on(r){const e=[],t=r.querySelectorAll("*");for(const i of t){const n=i.tagName.toLowerCase();if(tn.has(n)){e.push(i);continue}if((n==="svg"||i.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(i.attributes).some(l=>yt.test(l.name)||l.name==="href"||l.name==="xlink:href")){e.push(i);continue}const o=[];for(const s of i.attributes){const l=s.name.toLowerCase();if(yt.test(l)){o.push(s.name);continue}if(nn.has(l)&&rn.test(s.value)){o.push(s.name);continue}if(l==="style"&&/expression\s*\(|javascript:|behavior\s*:/i.test(s.value)){o.push(s.name);continue}}o.forEach(s=>i.removeAttribute(s))}e.forEach(i=>i.remove())}function me(r,e){if(!r||r.indexOf("{{")===-1)return r;const t=[],i=r.replace(Zi,(l,a)=>{const c=sn(a,e);return t.push({expr:a.trim(),result:c}),c}),n=ln(i),o=t.length&&t.every(l=>l.result===""||l.result===F);return j.test(r)||o?"":n}function sn(r,e){if(r=(r||"").trim(),!r||j.test(r))return F;if(r==="value")return e.value==null?F:String(e.value);if(r.startsWith("row.")&&!/[()?]/.test(r)&&!r.includes(":")){const i=r.slice(4),n=e.row?e.row[i]:void 0;return n==null?F:String(n)}if(r.length>80||!Qi.test(r)||Ji.test(r))return F;const t=r.match(/\./g);if(t&&t.length>1)return F;try{const n=new Function("value","row",`return (${r});`)(e.value,e.row),o=n==null?"":String(n);return j.test(o)?F:o||F}catch{return F}}const j=/Reflect|Proxy|ownKeys/;function ln(r){return r&&r.replace(new RegExp(F,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,"")}function an(r){if(j.test(r.textContent||"")){for(const e of r.childNodes)e.nodeType===Node.TEXT_NODE&&j.test(e.textContent||"")&&(e.textContent="");j.test(r.textContent||"")&&(r.textContent="")}}function Ct(r){const e=j.test(r),t=(i=>e?"":me(r,i));return t.__blocked=e,t}const cn=100;class dn{#t;#e;#u;#c;#i;#l={};#n={};#f=!0;#h=[];#w;#a;#v;#d;#g;constructor(e){this.#d=e}get original(){return this.#l}get effective(){return this.#n}get columns(){return this.#n.columns??[]}set columns(e){this.#n.columns=e}get lightDomColumnsCache(){return this.#c}set lightDomColumnsCache(e){this.#c=e}get originalColumnNodes(){return this.#i}set originalColumnNodes(e){this.#i=e}get lightDomTitle(){return this.#g}set lightDomTitle(e){this.#g=e}get initialColumnState(){return this.#v}set initialColumnState(e){this.#v=e}get sourcesChanged(){return this.#f}markSourcesChanged(){this.#f=!0}setGridConfig(e){this.#t=e,this.#f=!0,this.#c=void 0}getGridConfig(){return this.#t}setColumns(e){this.#e=e,this.#f=!0}getColumns(){return this.#e}setFitMode(e){this.#u=e,this.#f=!0}getFitMode(){return this.#u}merge(){const e=(this.#n.columns?.length??0)>0;if(!this.#f&&e)return;const t=this.#m();this.#f=!1,this.#l=t,Object.freeze(this.#l),this.#l.columns&&Object.freeze(this.#l.columns),this.#n=this.#R(this.#l),this.#p()}#R(e){const t={...e};return e.columns&&(t.columns=e.columns.map(i=>({...i}))),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(i=>({...i})),headerContents:e.shell.headerContents?.map(i=>({...i}))}),t}#p(){const e=this.#n;this.#x(),typeof e.rowHeight=="number"&&e.rowHeight>0&&this.#d.setRowHeight(e.rowHeight),e.fitMode==="fixed"&&this.columns.forEach(i=>{i.width==null&&(i.width=80)}),this.#d.applyAnimationConfig(e)}#x(){const e=this.#n.typeDefaults;if(!e)return;const t=this.columns;for(const i of t){if(!i.type)continue;const n=e[i.type];n&&(!i.renderer&&!i.viewRenderer&&n.renderer&&(i.renderer=n.renderer),!i.format&&n.format&&(i.format=n.format),!i.editor&&n.editor&&(i.editor=n.editor),!i.editorParams&&n.editorParams&&(i.editorParams=n.editorParams))}}#m(){const e=this.#t?{...this.#t}:{},t=Array.isArray(e.columns)?[...e.columns]:[],i=(this.#c??[]).map(s=>({...s}));let n=mt(t,i);this.#e&&this.#e.length&&(n=mt(this.#e,i));const o=this.#d.getRows();return n.length===0&&o.length&&(n=Xi(o).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=Ct(s.__viewTemplate.innerHTML)),s.__editorTemplate&&!s.__compiledEditor&&(s.__compiledEditor=Ct(s.__editorTemplate.innerHTML))}),e.columns=n),this.#u&&(e.fitMode=this.#u),e.fitMode||(e.fitMode="stretch"),this.#y(e),e.columnState&&!this.#v&&(this.#v=e.columnState),e}#y(e){e.shell=e.shell?{...e.shell}:{},e.shell.header=e.shell.header?{...e.shell.header}:{};const t=this.#d.getShellLightDomTitle();t&&(this.#g=t),this.#g&&!e.shell.header.title&&(e.shell.header.title=this.#g);const i=this.#d.getShellLightDomHeaderContent();i?.length>0&&(e.shell.header.lightDomContent=i),this.#d.getShellHasToolButtonsContainer()&&(e.shell.header.hasToolButtonsContainer=!0);const n=this.#d.getShellToolPanels();if(n.size>0){const u=Array.from(n.values());u.sort((h,f)=>(h.order??100)-(f.order??100)),e.shell.toolPanels=u}const o=this.#d.getShellHeaderContents();if(o.size>0){const u=Array.from(o.values());u.sort((h,f)=>(h.order??100)-(f.order??100)),e.shell.headerContents=u}const s=this.#d.getShellToolbarContents(),l=Array.from(s.values()),a=this.#t?.shell?.header?.toolbarContents??[],c=new Set(a.map(u=>u.id)),d=[...a];for(const u of l)c.has(u.id)||d.push(u);d.sort((u,h)=>(u.order??0)-(h.order??0)),e.shell.header.toolbarContents=d}collectState(e){const t=this.columns,i=this.#E();return{columns:t.map((n,o)=>{const s={field:n.field,order:o,visible:!n.hidden},l=n;l.__renderedWidth!==void 0?s.width=l.__renderedWidth:n.width!==void 0&&(s.width=typeof n.width=="string"?parseFloat(n.width):n.width);const a=i.get(n.field);a&&(s.sort=a);for(const c of e)if(c.getColumnState){const d=c.getColumnState(n.field);d&&Object.assign(s,d)}return s})}}applyState(e,t){if(!e.columns||e.columns.length===0)return;const i=this.columns,n=new Map(e.columns.map(l=>[l.field,l])),o=i.map(l=>{const a=n.get(l.field);if(!a)return l;const c={...l};return a.width!==void 0&&(c.width=a.width,c.__renderedWidth=a.width),a.visible!==void 0&&(c.hidden=!a.visible),c});o.sort((l,a)=>{const c=n.get(l.field)?.order??1/0,d=n.get(a.field)?.order??1/0;return c-d}),this.columns=o;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.#d.setSortState({field:l.field,direction:l.sort.direction==="asc"?1:-1})}else this.#d.setSortState(null);for(const l of t)if(l.applyColumnState)for(const a of e.columns)l.applyColumnState(a.field,a)}resetState(e){this.#v=void 0,this.#d.setSortState(null),this.#n=this.#R(this.#l),this.#p();for(const t of e)if(t.applyColumnState)for(const i of this.columns)t.applyColumnState(i.field,{field:i.field,order:0,visible:!0});this.requestStateChange(e)}#E(){const e=new Map,t=this.#d.getSortState();return t&&e.set(t.field,{direction:t.direction===1?"asc":"desc",priority:0}),e}requestStateChange(e){this.#a&&clearTimeout(this.#a),this.#a=setTimeout(()=>{this.#a=void 0;const t=this.collectState(e);this.#d.emit("column-state-change",t)},cn)}setColumnVisible(e,t){const i=this.columns,n=i.find(s=>s.field===e);return!n||!t&&n.lockVisible||!t&&i.filter(l=>!l.hidden&&l.field!==e).length===0||!!n.hidden===!t?!1:(n.hidden=!t,this.#d.emit("column-visibility",{field:e,visible:t,visibleColumns:i.filter(s=>!s.hidden).map(s=>s.field)}),this.#d.clearRowPool(),this.#d.setup(),!0)}toggleColumnVisibility(e){const t=this.columns.find(i=>i.field===e);return t?this.setColumnVisible(e,!!t.hidden):!1}isColumnVisible(e){const t=this.columns.find(i=>i.field===e);return t?!t.hidden:!1}showAllColumns(){const e=this.columns;e.some(t=>t.hidden)&&(e.forEach(t=>t.hidden=!1),this.#d.emit("column-visibility",{visibleColumns:e.map(t=>t.field)}),this.#d.clearRowPool(),this.#d.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 t=new Map(this.columns.map(n=>[n.field,n])),i=[];for(const n of e){const o=t.get(n);o&&(i.push(o),t.delete(n))}for(const n of t.values())i.push(n);this.columns=i,this.#d.renderHeader(),this.#d.updateTemplate(),this.#d.refreshVirtualWindow()}parseLightDomColumns(e){this.#c||(this.#i=Array.from(e.querySelectorAll("tbw-grid-column")),this.#c=this.#i.length?ji(e):[])}clearLightDomCache(){this.#c=void 0}#C=new Map;registerLightDomHandler(e,t){this.#C.set(e.toLowerCase(),t)}unregisterLightDomHandler(e){this.#C.delete(e.toLowerCase())}observeLightDOM(e){this.#w&&this.#w.disconnect();const t=new Set;let i=null;const n=()=>{i=null;for(const o of t)this.#C.get(o)?.();t.clear()};this.#w=new MutationObserver(o=>{for(const s of o){for(const l of s.addedNodes){if(l.nodeType!==Node.ELEMENT_NODE)continue;const c=l.tagName.toLowerCase();this.#C.has(c)&&t.add(c)}if(s.type==="attributes"&&s.target.nodeType===Node.ELEMENT_NODE){const a=s.target.tagName.toLowerCase();this.#C.has(a)&&t.add(a)}}t.size>0&&!i&&(i=setTimeout(n,0))}),this.#w.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["title","field","header","width","hidden","id","icon","tooltip","order"]})}onChange(e){this.#h.push(e)}notifyChange(){for(const e of this.#h)e()}dispose(){this.#w?.disconnect(),this.#h=[],this.#a&&clearTimeout(this.#a)}}function Me(){if(typeof window<"u"&&window.location){const r=window.location.hostname;if(r==="localhost"||r==="127.0.0.1"||r==="::1")return!0}return typeof process<"u"&&process.env?.NODE_ENV!=="production"}function xt(r){return`<span role="checkbox" aria-checked="${r}" aria-label="${r}">${r?"🗹":"☐"}</span>`}function Et(r){if(r==null||r==="")return"";if(r instanceof Date)return isNaN(r.getTime())?"":r.toLocaleDateString();if(typeof r=="number"||typeof r=="string"){const e=new Date(r);return isNaN(e.getTime())?"":e.toLocaleDateString()}return""}function be(r){if(!r)return-1;const e=r.getAttribute("data-row");if(e)return parseInt(e,10);const t=r.closest(".data-grid-row");if(!t)return-1;const i=t.parentElement;if(!i)return-1;const n=i.querySelectorAll(":scope > .data-grid-row");for(let o=0;o<n.length;o++)if(n[o]===t)return o;return-1}function un(r){if(!r)return-1;const e=r.getAttribute("data-col");return e?parseInt(e,10):-1}function ae(r){r&&r.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function ve(r){try{if(getComputedStyle(r).direction==="rtl")return"rtl"}catch{}try{if(r.closest?.("[dir]")?.getAttribute("dir")==="rtl")return"rtl"}catch{}return"ltr"}function Rt(r){return ve(r)==="rtl"}function hn(r,e){return r==="left"||r==="right"?r:e==="rtl"?r==="start"?"right":"left":r==="start"?"left":"right"}function St(r,e){const t=e.renderer||e.viewRenderer;if(t)return t;if(!e.type)return;const i=r.__frameworkAdapter;if(i?.getTypeDefault){const n=i.getTypeDefault(e.type);if(n?.renderer)return n.renderer}}function _t(r,e){if(e.format)return e.format;if(!e.type)return;const t=r.__frameworkAdapter;if(t?.getTypeDefault){const i=t.getTypeDefault(e.type);if(i?.format)return i.format}}const B='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function ze(r){return(r.__editingCellCount??0)>0}function Ne(r){r.__editingCellCount=0,r.removeAttribute("data-has-editing"),r.querySelectorAll(".cell.editing").forEach(t=>t.classList.remove("editing"))}const At=document.createElement("template");At.innerHTML='<div class="cell" role="gridcell" part="cell"></div>';const kt=document.createElement("template");kt.innerHTML='<div class="data-grid-row" role="row" part="row"></div>';function fn(){return At.content.firstElementChild.cloneNode(!0)}function gn(){return kt.content.firstElementChild.cloneNode(!0)}function ye(r){r.__cellDisplayCache=void 0,r.__cellCacheEpoch=void 0,r.__hasSpecialColumns=void 0}function pn(r,e,t,i,n){const o=Math.max(0,t-e),s=r._bodyEl,l=r._visibleColumns,a=l.length;let c=r.__cachedHeaderRowCount;for(c===void 0&&(c=r.querySelector(".header-group-row")?2:1,r.__cachedHeaderRowCount=c);r._rowPool.length<o;){const h=gn();r._rowPool.push(h)}if(r._rowPool.length>o){for(let h=o;h<r._rowPool.length;h++){const f=r._rowPool[h];f.parentNode===s&&f.remove()}r._rowPool.length=o}const d=n&&r.__hasRenderRowPlugins!==!1,u=r._hasAfterRowRenderHook?.()??!1;for(let h=0;h<o;h++){const f=e+h,p=r._rows[f],g=r._rowPool[h];if(g.setAttribute("aria-rowindex",String(f+c+1)),d&&n(p,g,f)){g.__epoch=i,g.__rowDataRef=p,g.parentNode!==s&&s.appendChild(g);continue}const w=g.__epoch,b=g.__rowDataRef,m=g.children.length,x=w===i&&m===a,S=b!==p;let R=!1;if(x&&S){for(let _=0;_<a;_++)if(l[_].externalView&&!g.querySelector(`.cell[data-col="${_}"] [data-external-view]`)){R=!0;break}}if(!x||R){const _=ze(g),T=r._activeEditRows===f;_&&!T?(g.__isCustomRow&&(g.className="data-grid-row",g.setAttribute("role","row"),g.__isCustomRow=!1),Ne(g),ce(r,g,p,f),g.__epoch=i,g.__rowDataRef=p):_&&T?(Oe(r,g,p,f),g.__rowDataRef=p):(g.__isCustomRow&&(g.className="data-grid-row",g.setAttribute("role","row"),g.__isCustomRow=!1),ce(r,g,p,f),g.__epoch=i,g.__rowDataRef=p)}else if(S){const _=ze(g),T=r._activeEditRows===f;_&&!T?(Ne(g),ce(r,g,p,f),g.__epoch=i,g.__rowDataRef=p):(Oe(r,g,p,f),g.__rowDataRef=p)}else{const _=ze(g),T=r._activeEditRows===f;_&&!T?(Ne(g),ce(r,g,p,f),g.__epoch=i,g.__rowDataRef=p):Oe(r,g,p,f)}let L=!1;const P=r.changedRowIds;if(P&&P.length>0)try{const _=r.getRowId?.(p);_&&(L=P.includes(_))}catch{}const y=g.classList.contains("changed");L!==y&&g.classList.toggle("changed",L);const A=r.effectiveConfig?.rowClass;if(A){const _=g.getAttribute("data-dynamic-classes");_&&_.split(" ").forEach(T=>T&&g.classList.remove(T));try{const T=A(p);if(T&&T.length>0){const C=T.filter(k=>k&&typeof k=="string");C.forEach(k=>g.classList.add(k)),g.setAttribute("data-dynamic-classes",C.join(" "))}else g.removeAttribute("data-dynamic-classes")}catch(T){console.warn("[tbw-grid] rowClass callback error:",T),g.removeAttribute("data-dynamic-classes")}}u&&r._afterRowRender?.({row:p,rowIndex:f,rowElement:g}),g.parentNode!==s&&s.appendChild(g)}}function Oe(r,e,t,i){const n=e.children,o=r._visibleColumns,s=o.length,l=n.length,a=s<l?s:l,c=r._focusRow,d=r._focusCol,u=r._hasAfterCellRenderHook?.()??!1;let h=r.__hasSpecialColumns;if(h===void 0){h=!1;const p=r.__frameworkAdapter;for(let g=0;g<s;g++){const w=o[g];if(w.__viewTemplate||w.__compiledView||w.renderer||w.viewRenderer||w.externalView||w.format||w.type==="date"||w.type==="boolean"||w.type&&p?.getTypeDefault?.(w.type)?.renderer||w.type&&p?.getTypeDefault?.(w.type)?.format){h=!0;break}}r.__hasSpecialColumns=h}const f=String(i);if(!h){for(let p=0;p<a;p++){const g=n[p];if(g.classList.contains("editing"))continue;const w=o[p],b=t[w.field];g.textContent=b==null?"":String(b),g.getAttribute("data-row")!==f&&g.setAttribute("data-row",f);const m=c===i&&d===p,v=g.classList.contains("cell-focus");m!==v&&(g.classList.toggle("cell-focus",m),g.setAttribute("aria-selected",String(m))),u&&r._afterCellRender?.({row:t,rowIndex:i,column:w,colIndex:p,value:b,cellElement:g,rowElement:e})}return}for(let p=0;p<a;p++)if(o[p].externalView&&!n[p].querySelector("[data-external-view]")){ce(r,e,t,i);return}for(let p=0;p<a;p++){const g=o[p],w=n[p];w.getAttribute("data-row")!==f&&w.setAttribute("data-row",f);const b=c===i&&d===p,m=w.classList.contains("cell-focus");b!==m&&(w.classList.toggle("cell-focus",b),w.setAttribute("aria-selected",String(b)));const v=g.cellClass;if(v){const P=w.getAttribute("data-dynamic-classes");P&&P.split(" ").forEach(y=>y&&w.classList.remove(y));try{const y=t[g.field],A=v(y,t,g);if(A&&A.length>0){const _=A.filter(T=>T&&typeof T=="string");_.forEach(T=>w.classList.add(T)),w.setAttribute("data-dynamic-classes",_.join(" "))}else w.removeAttribute("data-dynamic-classes")}catch(y){console.warn(`[tbw-grid] cellClass callback error for column '${g.field}':`,y),w.removeAttribute("data-dynamic-classes")}}if(w.classList.contains("editing"))continue;const x=St(r,g);if(x){const P=t[g.field],y=x({row:t,value:P,field:g.field,column:g,cellEl:w});typeof y=="string"?w.innerHTML=V(y):y instanceof Node?y.parentElement!==w&&(w.innerHTML="",w.appendChild(y)):y==null&&(w.textContent=P==null?"":String(P)),u&&r._afterCellRender?.({row:t,rowIndex:i,column:g,colIndex:p,value:P,cellElement:w,rowElement:e});continue}if(g.__viewTemplate||g.__compiledView||g.externalView)continue;const S=t[g.field];let R;const L=_t(r,g);if(L){try{const P=L(S,t);R=P==null?"":String(P)}catch(P){console.warn(`[tbw-grid] Format error in column '${g.field}':`,P),R=S==null?"":String(S)}w.textContent=R}else g.type==="date"?(R=Et(S),w.textContent=R):g.type==="boolean"?w.innerHTML=xt(!!S):(R=S==null?"":String(S),w.textContent=R);u&&r._afterCellRender?.({row:t,rowIndex:i,column:g,colIndex:p,value:S,cellElement:w,rowElement:e})}}function ce(r,e,t,i){e.innerHTML="";const n=r._visibleColumns,o=n.length,s=r._focusRow,l=r._focusCol,a=r,c=r._hasAfterCellRenderHook?.()??!1,d=document.createDocumentFragment();for(let u=0;u<o;u++){const h=n[u],f=fn();f.setAttribute("aria-colindex",String(u+1)),f.setAttribute("data-col",String(u)),f.setAttribute("data-row",String(i)),f.setAttribute("data-field",h.field),f.setAttribute("data-header",h.header??h.field),h.type&&f.setAttribute("data-type",h.type);let p=t[h.field];const g=_t(r,h);if(g)try{p=g(p,t)}catch(R){console.warn(`[tbw-grid] Format error in column '${h.field}':`,R)}const w=h.__compiledView,b=h.__viewTemplate,m=St(r,h),v=h.externalView;let x=!1;if(m){const R=m({row:t,value:p,field:h.field,column:h,cellEl:f});typeof R=="string"?(f.innerHTML=V(R),x=!0):R instanceof Node?R.parentElement!==f&&(f.textContent="",f.appendChild(R)):R==null&&(f.textContent=p==null?"":String(p))}else if(v){const R=v,L=document.createElement("div");L.setAttribute("data-external-view",""),L.setAttribute("data-field",h.field),f.appendChild(L);const P={row:t,value:p,field:h.field,column:h};if(R.mount)try{R.mount({placeholder:L,context:P,spec:R})}catch(y){console.warn(`[tbw-grid] External view mount error for column '${h.field}':`,y)}else queueMicrotask(()=>{try{a.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:L,spec:R,context:P}}))}catch(y){console.warn(`[tbw-grid] External view event dispatch error for column '${h.field}':`,y)}});L.setAttribute("data-mounted","")}else if(w){const R=w({row:t,value:p,field:h.field,column:h}),L=w.__blocked;f.innerHTML=L?"":V(R),x=!0,L&&(f.textContent="",f.setAttribute("data-blocked-template",""))}else if(b){const R=b.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(R)?(f.textContent="",f.setAttribute("data-blocked-template","")):(f.innerHTML=V(me(R,{row:t,value:p})),x=!0)}else g?f.textContent=p==null?"":String(p):h.type==="date"?f.textContent=Et(p):h.type==="boolean"?f.innerHTML=xt(!!p):f.textContent=p==null?"":String(p);if(x){an(f);const R=f.textContent||"";/Proxy|Reflect\.ownKeys/.test(R)&&(f.textContent=R.replace(/Proxy|Reflect\.ownKeys/g,"").trim(),/Proxy|Reflect\.ownKeys/.test(f.textContent||"")&&(f.textContent=""))}f.hasAttribute("data-blocked-template")&&(f.textContent||"").trim().length&&(f.textContent=""),h.editable?f.tabIndex=0:h.type==="boolean"&&(f.hasAttribute("tabindex")||(f.tabIndex=0)),s===i&&l===u?(f.classList.add("cell-focus"),f.setAttribute("aria-selected","true")):f.setAttribute("aria-selected","false");const S=h.cellClass;if(S)try{const R=t[h.field],L=S(R,t,h);if(L&&L.length>0){const P=L.filter(y=>y&&typeof y=="string");P.forEach(y=>f.classList.add(y)),f.setAttribute("data-dynamic-classes",P.join(" "))}}catch(R){console.warn(`[tbw-grid] cellClass callback error for column '${h.field}':`,R)}c&&r._afterCellRender?.({row:t,rowIndex:i,column:h,colIndex:u,value:p,cellElement:f,rowElement:e}),d.appendChild(f)}e.appendChild(d)}function Tt(r,e,t){if(e.target?.closest(".resize-handle"))return;const i=t.querySelector(".cell[data-row]"),n=be(i);if(n<0)return;const o=r._rows[n];if(!o||r._dispatchRowClick?.(e,n,o,t))return;const s=e.target?.closest(".cell[data-col]");if(s){const l=Number(s.getAttribute("data-col"));if(!isNaN(l)){if(r._dispatchCellClick?.(e,n,l,s))return;const a=r._focusRow!==n||r._focusCol!==l;if(r._focusRow=n,r._focusCol=l,s.classList.contains("editing")){a&&(ae(r._bodyEl??r),s.classList.add("cell-focus"));const c=s.querySelector(B);try{c?.focus({preventScroll:!0})}catch{}return}M(r)}}}function wn(r,e){if(r._dispatchKeyDown?.(e))return;const t=r._rows.length-1,i=r._visibleColumns.length-1,n=r._activeEditRows!==void 0&&r._activeEditRows!==-1,s=r._visibleColumns[r._focusCol]?.type,l=e.composedPath?.()??[],a=l.length?l[0]:e.target,c=d=>{if(!d)return!1;const u=d.tagName;return!!(u==="INPUT"||u==="SELECT"||u==="TEXTAREA"||d.isContentEditable)};if(!(c(a)&&(e.key==="Home"||e.key==="End"))&&!(c(a)&&(e.key==="ArrowUp"||e.key==="ArrowDown")&&a.tagName==="INPUT"&&a.type==="number")&&!(c(a)&&(e.key==="ArrowLeft"||e.key==="ArrowRight"))&&!(c(a)&&(e.key==="Enter"||e.key==="Escape"))&&!(n&&s==="select"&&(e.key==="ArrowDown"||e.key==="ArrowUp"))){switch(e.key){case"Tab":{e.preventDefault(),!e.shiftKey?r._focusCol<i?r._focusCol+=1:(typeof r.commitActiveRowEdit=="function"&&r.commitActiveRowEdit(),r._focusRow<t&&(r._focusRow+=1,r._focusCol=0)):r._focusCol>0?r._focusCol-=1:r._focusRow>0&&(typeof r.commitActiveRowEdit=="function"&&r._activeEditRows===r._focusRow&&r.commitActiveRowEdit(),r._focusRow-=1,r._focusCol=i),M(r);return}case"ArrowDown":n&&typeof r.commitActiveRowEdit=="function"&&r.commitActiveRowEdit(),r._focusRow=Math.min(t,r._focusRow+1),e.preventDefault();break;case"ArrowUp":n&&typeof r.commitActiveRowEdit=="function"&&r.commitActiveRowEdit(),r._focusRow=Math.max(0,r._focusRow-1),e.preventDefault();break;case"ArrowRight":{Rt(r)?r._focusCol=Math.max(0,r._focusCol-1):r._focusCol=Math.min(i,r._focusCol+1),e.preventDefault();break}case"ArrowLeft":{Rt(r)?r._focusCol=Math.min(i,r._focusCol+1):r._focusCol=Math.max(0,r._focusCol-1),e.preventDefault();break}case"Home":(e.ctrlKey||e.metaKey)&&(n&&typeof r.commitActiveRowEdit=="function"&&r.commitActiveRowEdit(),r._focusRow=0),r._focusCol=0,e.preventDefault(),M(r,{forceScrollLeft:!0});return;case"End":(e.ctrlKey||e.metaKey)&&(n&&typeof r.commitActiveRowEdit=="function"&&r.commitActiveRowEdit(),r._focusRow=t),r._focusCol=i,e.preventDefault(),M(r,{forceScrollRight:!0});return;case"PageDown":r._focusRow=Math.min(t,r._focusRow+20),e.preventDefault();break;case"PageUp":r._focusRow=Math.max(0,r._focusRow-20),e.preventDefault();break;case"Enter":{const d=r._focusRow,u=r._focusCol,h=r._visibleColumns[u],f=r._rows[d],p=h?.field??"",g=p&&f?f[p]:void 0,w=r.querySelector(`[data-row="${d}"][data-col="${u}"]`),b={rowIndex:d,colIndex:u,field:p,value:g,row:f,cellEl:w,trigger:"keyboard",originalEvent:e},m=new CustomEvent("cell-activate",{cancelable:!0,detail:b});r.dispatchEvent(m);const v=new CustomEvent("activate-cell",{cancelable:!0,detail:{row:d,col:u}});if(r.dispatchEvent(v),m.defaultPrevented||v.defaultPrevented){e.preventDefault();return}break}default:return}M(r)}}function M(r,e){if(r._virtualization?.enabled){const{rowHeight:s,container:l,viewportEl:a}=r._virtualization,c=l,d=a?.clientHeight??c?.clientHeight??0;if(c&&d>0){const u=r._focusRow*s;u<c.scrollTop?c.scrollTop=u:u+s>c.scrollTop+d&&(c.scrollTop=u-d+s)}}const t=r._activeEditRows!==void 0&&r._activeEditRows!==-1;t||r.refreshVirtualWindow(!1),ae(r._bodyEl),Array.from(r._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(s=>{s.setAttribute("aria-selected","false")});const i=r._focusRow,n=r._virtualization.start??0,o=r._virtualization.end??r._rows.length;if(i>=n&&i<o){const s=r._bodyEl.querySelectorAll(".data-grid-row")[i-n];let l=s?.children[r._focusCol];if((!l||!l.classList?.contains("cell"))&&(l=s?.querySelector(`.cell[data-col="${r._focusCol}"]`)??s?.querySelector(".cell[data-col]")),l){l.classList.add("cell-focus"),l.setAttribute("aria-selected","true");const a=r.querySelector(".tbw-scroll-area");if(a&&l&&(!t||e?.forceHorizontalScroll))if(e?.forceScrollLeft)a.scrollLeft=0;else if(e?.forceScrollRight)a.scrollLeft=a.scrollWidth-a.clientWidth;else{const c=r._getHorizontalScrollOffsets?.(s??void 0,l)??{left:0,right:0};if(!c.skipScroll){const d=l.getBoundingClientRect(),u=a.getBoundingClientRect(),h=d.left-u.left+a.scrollLeft,f=h+d.width,p=a.scrollLeft+c.left,g=a.scrollLeft+a.clientWidth-c.right;h<p?a.scrollLeft=h-c.left:f>g&&(a.scrollLeft=f-a.clientWidth+c.right)}}if(r._activeEditRows!==void 0&&r._activeEditRows!==-1&&l.classList.contains("editing")){const c=l.querySelector(B);if(c&&document.activeElement!==c)try{c.focus({preventScroll:!0})}catch{}}else if(!l.contains(document.activeElement)){l.hasAttribute("tabindex")||l.setAttribute("tabindex","-1");try{l.focus({preventScroll:!0})}catch{}}}}}const Ce=new WeakMap;function mn(r,e){const t=be(e),i=un(e);t<0||i<0||(r._focusRow=t,r._focusCol=i,ae(r._bodyEl),e.classList.add("cell-focus"),e.setAttribute("aria-selected","true"))}function Fe(r,e,t,i){let n=null;const o=t.composedPath?.();if(o&&o.length>0?n=o[0]:n=t.target,n&&!e.contains(n)){const g=document.elementFromPoint(t.clientX,t.clientY);g&&(n=g)}const s=n?.closest?.("[data-col]"),l=n?.closest?.(".data-grid-row"),a=n?.closest?.(".header-row");let c,d,u,h,f,p;return s&&(c=parseInt(s.getAttribute("data-row")??"-1",10),d=parseInt(s.getAttribute("data-col")??"-1",10),c>=0&&d>=0&&(u=r._rows[c],p=r._columns[d],h=p?.field,f=u&&h?u[h]:void 0)),{type:i,row:u,rowIndex:c!==void 0&&c>=0?c:void 0,colIndex:d!==void 0&&d>=0?d:void 0,field:h,value:f,column:p,originalEvent:t,cellElement:s??void 0,rowElement:l??void 0,isHeader:!!a,cell:c!==void 0&&d!==void 0&&c>=0&&d>=0?{row:c,col:d}:void 0}}function bn(r,e,t){const i=Fe(r,e,t,"mousedown");(r._dispatchCellMouseDown?.(i)??!1)&&Ce.set(r,!0)}function vn(r,e,t){if(!Ce.get(r))return;const i=Fe(r,e,t,"mousemove");r._dispatchCellMouseMove?.(i)}function yn(r,e,t){if(!Ce.get(r))return;const i=Fe(r,e,t,"mouseup");r._dispatchCellMouseUp?.(i),Ce.set(r,!1)}function Cn(r,e,t){e.addEventListener("mousedown",i=>{const n=i.target.closest(".cell[data-col]");n&&(n.classList.contains("editing")||mn(r,n))},{signal:t}),e.addEventListener("click",i=>{const n=i.target.closest(".data-grid-row");n&&Tt(r,i,n)},{signal:t}),e.addEventListener("dblclick",i=>{const n=i.target.closest(".data-grid-row");n&&Tt(r,i,n)},{signal:t})}function xn(r,e,t,i){e.addEventListener("keydown",n=>wn(r,n),{signal:i}),t.addEventListener("mousedown",n=>bn(r,t,n),{signal:i}),document.addEventListener("mousemove",n=>vn(r,t,n),{signal:i}),document.addEventListener("mouseup",n=>yn(r,t,n),{signal:i})}function Lt(r,e){return r==null&&e==null?0:r==null?-1:e==null||r>e?1:r<e?-1:0}function Pt(r,e,t){const n=t.find(l=>l.field===e.field)?.sortComparator??Lt,{field:o,direction:s}=e;return[...r].sort((l,a)=>n(l[o],a[o],l,a)*s)}function Ht(r,e,t,i){r._rows=e,r.__rowRenderEpoch++,r._rowPool.forEach(n=>n.__epoch=-1),_e(r),r.refreshVirtualWindow(!0),r.dispatchEvent(new CustomEvent("sort-change",{detail:{field:t.field,direction:i}})),r.requestStateChange?.()}function Dt(r,e){!r._sortState||r._sortState.field!==e.field?(r._sortState||(r.__originalOrder=r._rows.slice()),It(r,e,1)):r._sortState.direction===1?It(r,e,-1):(r._sortState=null,r.__rowRenderEpoch++,r._rowPool.forEach(i=>i.__epoch=-1),r._rows=r.__originalOrder.slice(),_e(r),r._headerRowEl?.querySelectorAll('[role="columnheader"].sortable')?.forEach(i=>{i.getAttribute("aria-sort")?(i.getAttribute("aria-sort")==="ascending"||i.getAttribute("aria-sort")==="descending")&&(r._sortState||i.setAttribute("aria-sort","none")):i.setAttribute("aria-sort","none")}),r.refreshVirtualWindow(!0),r.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:0}})),r.requestStateChange?.())}function It(r,e,t){r._sortState={field:e.field,direction:t};const i={field:e.field,direction:t},n=r._columns,s=(r.effectiveConfig?.sortHandler??Pt)(r._rows,i,n);s&&typeof s.then=="function"?s.then(l=>{Ht(r,l,e,t)}):Ht(r,s,e,t)}function de(r,e){return r.effectiveConfig?.sortable!==!1&&e.sortable===!0}function xe(r,e){return r.effectiveConfig?.resizable!==!1&&e.resizable!==!1}function En(r,e){typeof e=="string"?r.textContent=e:e instanceof HTMLElement&&(r.innerHTML="",r.appendChild(e.cloneNode(!0)))}function Ee(r,e){const t=document.createElement("span");bt(t,"sort-indicator");const i=r._sortState?.field===e.field?r._sortState.direction:0,n={...G,...r.icons},o=i===1?n.sortAsc:i===-1?n.sortDesc:n.sortNone;return En(t,o),t}function Re(r,e,t){const i=document.createElement("div");return i.className="resize-handle",i.setAttribute("aria-hidden","true"),i.addEventListener("mousedown",n=>{n.stopPropagation(),n.preventDefault(),r._resizeController.start(n,e,t)}),i.addEventListener("dblclick",n=>{n.stopPropagation(),n.preventDefault(),r._resizeController.resetColumn(e)}),i}function Se(r,e,t,i){i.classList.add("sortable"),i.tabIndex=0;const n=r._sortState?.field===e.field?r._sortState.direction:0;i.setAttribute("aria-sort",n===0?"none":n===1?"ascending":"descending"),i.addEventListener("click",o=>{r._resizeController?.isResizing||r._dispatchHeaderClick?.(o,t,i)||Dt(r,e)}),i.addEventListener("keydown",o=>{if(o.key==="Enter"||o.key===" "){if(o.preventDefault(),r._dispatchHeaderClick?.(o,t,i))return;Dt(r,e)}})}function Rn(r,e){if(e!=null)if(typeof e=="string"){const t=document.createElement("span");for(t.innerHTML=V(e);t.firstChild;)r.appendChild(t.firstChild)}else e instanceof Node&&r.appendChild(e)}function _e(r){r._headerRowEl=r.findHeaderRow();const e=r._headerRowEl;e&&(e.innerHTML="",r._visibleColumns.forEach((t,i)=>{const n=document.createElement("div");n.className="cell",bt(n,"header-cell"),n.setAttribute("role","columnheader"),n.setAttribute("aria-colindex",String(i+1)),n.setAttribute("data-field",t.field),n.setAttribute("data-col",String(i));const o=t.header??t.field,s=r._sortState?.field===t.field?r._sortState.direction:0,l=s===1?"asc":s===-1?"desc":null;if(t.headerRenderer){const a={column:t,value:o,sortState:l,filterActive:!1,cellEl:n,renderSortIcon:()=>de(r,t)?Ee(r,t):null,renderFilterButton:()=>null},c=t.headerRenderer(a);Rn(n,c),de(r,t)&&Se(r,t,i,n),xe(r,t)&&(n.classList.add("resizable"),n.appendChild(Re(r,i,n)))}else if(t.headerLabelRenderer){const a={column:t,value:o},c=t.headerLabelRenderer(a),d=document.createElement("span");c==null?d.textContent=o:typeof c=="string"?d.innerHTML=V(c):c instanceof Node&&d.appendChild(c),n.appendChild(d),de(r,t)&&(Se(r,t,i,n),n.appendChild(Ee(r,t))),xe(r,t)&&(n.classList.add("resizable"),n.appendChild(Re(r,i,n)))}else if(t.__headerTemplate)Array.from(t.__headerTemplate.childNodes).forEach(a=>n.appendChild(a.cloneNode(!0))),de(r,t)&&(Se(r,t,i,n),n.appendChild(Ee(r,t))),xe(r,t)&&(n.classList.add("resizable"),n.appendChild(Re(r,i,n)));else{const a=document.createElement("span");a.textContent=o,n.appendChild(a),de(r,t)&&(Se(r,t,i,n),n.appendChild(Ee(r,t))),xe(r,t)&&(n.classList.add("resizable"),n.appendChild(Re(r,i,n)))}e.appendChild(n)}),e.querySelectorAll(".cell.sortable").forEach(t=>{t.getAttribute("aria-sort")||t.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 Mt=typeof requestIdleCallback=="function";function Sn(r,e){return Mt?requestIdleCallback(r,e):window.setTimeout(()=>{const t=Date.now();r({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})},1)}function zt(r){Mt?cancelIdleCallback(r):clearTimeout(r)}function _n(r){const e=document.createElement("div");return e.className=`tbw-spinner tbw-spinner--${r}`,e.setAttribute("role","progressbar"),e.setAttribute("aria-label","Loading"),e}function An(r,e){if(e){const i=e({size:r});if(typeof i=="string"){const n=document.createElement("div");return n.innerHTML=i,n}return i}return _n(r)}function kn(r){const e=document.createElement("div");return e.className="tbw-loading-overlay",e.setAttribute("role","status"),e.setAttribute("aria-live","polite"),e.appendChild(An("large",r)),e}function Tn(r,e){r.appendChild(e)}function Ln(r){r?.remove()}function Pn(r,e){e?(r.classList.add("tbw-row-loading"),r.setAttribute("aria-busy","true")):(r.classList.remove("tbw-row-loading"),r.removeAttribute("aria-busy"))}function Hn(r,e){e?(r.classList.add("tbw-cell-loading"),r.setAttribute("aria-busy","true")):(r.classList.remove("tbw-cell-loading"),r.removeAttribute("aria-busy"))}var I=(r=>(r[r.STYLE=1]="STYLE",r[r.VIRTUALIZATION=2]="VIRTUALIZATION",r[r.HEADER=3]="HEADER",r[r.ROWS=4]="ROWS",r[r.COLUMNS=5]="COLUMNS",r[r.FULL=6]="FULL",r))(I||{});class Dn{#t;#e=0;#u=0;#c=null;#i=null;#l=null;#n=!1;constructor(e){this.#t=e}requestPhase(e,t){e>this.#e&&(this.#e=e),this.#u===0&&(this.#f(),this.#u=requestAnimationFrame(()=>this.#h()))}whenReady(){return this.#c?this.#c:Promise.resolve()}setInitialReadyResolver(e){this.#l=e}cancel(){this.#u!==0&&(cancelAnimationFrame(this.#u),this.#u=0),this.#e=0,this.#i&&(this.#i(),this.#i=null,this.#c=null)}get isPending(){return this.#e!==0}get pendingPhase(){return this.#e}#f(){this.#c||(this.#c=new Promise(e=>{this.#i=e}))}#h(){if(this.#u=0,!this.#t.isConnected()){this.#e=0,this.#i&&(this.#i(),this.#i=null,this.#c=null);return}const e=this.#e;this.#e=0,e>=5&&this.#t.mergeConfig(),e>=4&&this.#t.processRows(),e>=5&&(this.#t.processColumns(),this.#t.updateTemplate()),e>=3&&this.#t.renderHeader(),e>=2&&this.#t.renderVirtualWindow(),e>=1&&this.#t.afterRender(),!this.#n&&this.#l&&(this.#n=!0,this.#l()),this.#i&&(this.#i(),this.#i=null,this.#c=null)}}function Nt(r){let e=null,t=null,i=null,n=null;const o=a=>{if(!e)return;const c=a.clientX-e.startX,d=Math.max(40,e.startWidth+c),u=r._visibleColumns[e.colIndex];u.width=d,u.__userResized=!0,u.__renderedWidth=d,t==null&&(t=requestAnimationFrame(()=>{t=null,r.updateTemplate?.()})),r.dispatchEvent(new CustomEvent("column-resize",{detail:{field:u.field,width:d}}))};let s=!1;const l=()=>{const a=e!==null;a&&(s=!0,requestAnimationFrame(()=>{s=!1})),window.removeEventListener("mousemove",o),window.removeEventListener("mouseup",l),i!==null&&(document.documentElement.style.cursor=i,i=null),n!==null&&(document.body.style.userSelect=n,n=null),e=null,a&&r.requestStateChange&&r.requestStateChange()};return{get isResizing(){return e!==null||s},start(a,c,d){a.preventDefault();const u=r._visibleColumns[c],h=typeof u?.width=="number"?u.width:void 0,f=u?.__renderedWidth??h??d.getBoundingClientRect().width;e={startX:a.clientX,colIndex:c,startWidth:f},window.addEventListener("mousemove",o),window.addEventListener("mouseup",l),i===null&&(i=document.documentElement.style.cursor),document.documentElement.style.cursor="e-resize",n===null&&(n=document.body.style.userSelect),document.body.style.userSelect="none"},resetColumn(a){const c=r._visibleColumns[a];c&&(c.__userResized=!1,c.__renderedWidth=void 0,c.width=c.__originalWidth,r.updateTemplate?.(),r.requestStateChange?.(),r.dispatchEvent(new CustomEvent("column-resize-reset",{detail:{field:c.field,width:c.width}})))},dispose(){l()}}}const qe="data-animating",In={change:"--tbw-row-change-duration",insert:"--tbw-row-insert-duration",remove:"--tbw-row-remove-duration"},Mn={change:500,insert:300,remove:200};function zn(r){const e=r.trim().toLowerCase();return e.endsWith("ms")?parseFloat(e):e.endsWith("s")?parseFloat(e)*1e3:parseFloat(e)}function Nn(r,e){const t=In[e],i=getComputedStyle(r).getPropertyValue(t);if(i){const n=zn(i);if(!isNaN(n)&&n>0)return n}return Mn[e]}function On(r,e,t){r.removeAttribute(qe),r.offsetWidth,r.setAttribute(qe,e);const i=Nn(r,e);setTimeout(()=>{e!=="remove"&&r.removeAttribute(qe)},i)}function Ge(r,e,t){if(e<0)return!1;const i=r.findRenderedRowElement?.(e);return i?(On(i,t),!0):!1}function Fn(r,e,t){let i=0;for(const n of e)Ge(r,n,t)&&i++;return i}function qn(r,e,t){const i=r._rows??[],n=r.getRowId;if(!n)return!1;const o=i.findIndex(s=>n(s)===e);return o<0?!1:Ge(r,o,t)}function Ae(r,e,t){const i=document.createElement(r);if(e)for(const n in e){const o=e[n];o!=null&&i.setAttribute(n,o)}return i}function O(r,e){const t=document.createElement("div");if(r&&(t.className=r),e)for(const i in e){const n=e[i];n!=null&&t.setAttribute(i,n)}return t}function Ot(r,e,t){const i=document.createElement("button");if(r&&(i.className=r),e)for(const n in e){const o=e[n];o!=null&&i.setAttribute(n,o)}return i}const Ft=document.createElement("template");Ft.innerHTML=`
|
|
1
|
+
(function(R,se){typeof exports=="object"&&typeof module<"u"?se(exports):typeof define=="function"&&define.amd?define(["exports"],se):(R=typeof globalThis<"u"?globalThis:R||self,se(R.TbwGrid={}))})(this,(function(R){"use strict";function se(){return{rowCount:-1,colCount:-1,ariaLabel:void 0,ariaDescribedBy:void 0}}function Ui(r,e,t,i,n){if(i===r.rowCount&&n===r.colCount)return!1;const o=r.rowCount;return r.rowCount=i,r.colCount=n,e&&(e.setAttribute("aria-rowcount",String(i)),e.setAttribute("aria-colcount",String(n))),i!==o&&t&&(i>0?t.setAttribute("role","rowgroup"):t.removeAttribute("role")),!0}function ji(r,e){const t=r?.gridAriaLabel;return t||(r?.shell?.header?.title??e?.lightDomTitle??void 0)}function Yi(r,e,t,i){if(!e)return!1;let n=!1;const o=ji(t,i);o!==r.ariaLabel&&(r.ariaLabel=o,o?e.setAttribute("aria-label",o):e.removeAttribute("aria-label"),n=!0);const s=t?.gridAriaDescribedBy;return s!==r.ariaDescribedBy&&(r.ariaDescribedBy=s,s?e.setAttribute("aria-describedby",s):e.removeAttribute("aria-describedby"),n=!0),n}const J={STRETCH:"stretch",FIXED:"fixed"},wt={mode:"reduced-motion",duration:200,easing:"ease-out"},bt='<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>',G={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:bt,filterActive:bt,print:"🖨️"};function Xi(r){return Array.from(r.querySelectorAll("tbw-grid-column")).map(t=>{const i=t.getAttribute("field")||"";if(!i)return null;const n=t.getAttribute("type")||void 0,s=n&&new Set(["number","string","date","boolean","select"]).has(n)?n:void 0,l=t.getAttribute("header")||void 0,a=t.hasAttribute("sortable"),c=t.hasAttribute("editable"),d={field:i,type:s,header:l,sortable:a,editable:c},u=t.getAttribute("width");if(u){const m=parseFloat(u);!isNaN(m)&&/^\d+(\.\d+)?$/.test(u.trim())?d.width=m:d.width=u}const h=t.getAttribute("minWidth")||t.getAttribute("min-width");if(h){const m=parseFloat(h);isNaN(m)||(d.minWidth=m)}t.hasAttribute("resizable")&&(d.resizable=!0),t.hasAttribute("sizable")&&(d.resizable=!0);const f=t.getAttribute("editor"),p=t.getAttribute("renderer");f&&(d.__editorName=f),p&&(d.__rendererName=p);const g=t.getAttribute("options");g&&(d.options=g.split(",").map(m=>{const[_,S]=m.includes(":")?m.split(":"):[m.trim(),m.trim()];return{value:_.trim(),label:S?.trim()||_.trim()}}));const w=t.querySelector("tbw-grid-column-view"),y=t.querySelector("tbw-grid-column-editor"),v=t.querySelector("tbw-grid-column-header");w&&(d.__viewTemplate=w),y&&(d.__editorTemplate=y),v&&(d.__headerTemplate=v);const P=globalThis.DataGridElement?.getAdapters?.()??[],E=w??t,b=P.find(m=>m.canHandle(E));if(b){const m=b.createRenderer(E);m&&(d.viewRenderer=m)}const C=y??t,A=P.find(m=>m.canHandle(C));if(A){const m=A.createEditor(C);m&&(d.editor=m)}return d}).filter(t=>!!t)}function mt(r,e){if((!r||!r.length)&&(!e||!e.length))return[];if(!r||!r.length)return e||[];if(!e||!e.length)return r;const t={};e.forEach(n=>{const o=t[n.field];if(o){n.header&&!o.header&&(o.header=n.header),n.type&&!o.type&&(o.type=n.type),n.sortable&&(o.sortable=!0),n.editable&&(o.editable=!0),n.resizable&&(o.resizable=!0),n.width!=null&&o.width==null&&(o.width=n.width),n.minWidth!=null&&o.minWidth==null&&(o.minWidth=n.minWidth),n.__viewTemplate&&(o.__viewTemplate=n.__viewTemplate),n.__editorTemplate&&(o.__editorTemplate=n.__editorTemplate),n.__headerTemplate&&(o.__headerTemplate=n.__headerTemplate);const s=n.renderer||n.viewRenderer,l=o.renderer||o.viewRenderer;s&&!l&&(o.viewRenderer=s,n.renderer&&(o.renderer=s)),n.editor&&!o.editor&&(o.editor=n.editor)}else t[n.field]={...n}});const i=r.map(n=>{const o=t[n.field];if(!o)return n;const s={...n};o.header&&!s.header&&(s.header=o.header),o.type&&!s.type&&(s.type=o.type),s.sortable=n.sortable||o.sortable,(n.resizable===!0||o.resizable===!0)&&(s.resizable=!0),s.editable=n.editable||o.editable,o.width!=null&&s.width==null&&(s.width=o.width),o.minWidth!=null&&s.minWidth==null&&(s.minWidth=o.minWidth),o.__viewTemplate&&(s.__viewTemplate=o.__viewTemplate),o.__editorTemplate&&(s.__editorTemplate=o.__editorTemplate),o.__headerTemplate&&(s.__headerTemplate=o.__headerTemplate);const l=o.renderer||o.viewRenderer,a=s.renderer||s.viewRenderer;return l&&!a&&(s.viewRenderer=l,o.renderer&&(s.renderer=l)),o.editor&&!s.editor&&(s.editor=o.editor),delete t[n.field],s});return Object.keys(t).forEach(n=>i.push(t[n])),i}function vt(r,e){try{r.part?.add?.(e)}catch{}const t=r.getAttribute("part");t?t.split(/\s+/).includes(e)||r.setAttribute("part",t+" "+e):r.setAttribute("part",e)}function yt(r){const e=r.effectiveConfig?.fitMode||r.fitMode||J.STRETCH;if(e!==J.STRETCH&&e!==J.FIXED||r.__didInitialAutoSize||!r.isConnected)return;const t=Array.from(r._headerRowEl?.children||[]);if(!t.length)return;let i=!1;r._visibleColumns.forEach((n,o)=>{if(n.width)return;const s=t[o];let l=s?s.scrollWidth:0;for(const a of r._rowPool){const c=a.children[o];if(c){const d=c.scrollWidth;d>l&&(l=d)}}l>0&&(n.width=l+2,n.__autoSized=!0,i=!0)}),i&&le(r),r.__didInitialAutoSize=!0}function le(r){(r.effectiveConfig?.fitMode||r.fitMode||J.STRETCH)===J.STRETCH?r._gridTemplate=r._visibleColumns.map(t=>{if(t.width)return`${t.width}px`;const i=t.minWidth;return i!=null?`minmax(${i}px, 1fr)`:"1fr"}).join(" ").trim():r._gridTemplate=r._visibleColumns.map(t=>t.width?`${t.width}px`:"max-content").join(" "),r.style.setProperty("--tbw-column-template",r._gridTemplate)}function Zi(r){return r==null?"string":typeof r=="number"?"number":typeof r=="boolean"?"boolean":r instanceof Date||typeof r=="string"&&/\d{4}-\d{2}-\d{2}/.test(r)&&!isNaN(Date.parse(r))?"date":"string"}function Qi(r,e){const t=r[0]||{},i=Object.keys(t).map(o=>{const s=t[o],l=Zi(s);return{field:o,header:o.charAt(0).toUpperCase()+o.slice(1),type:l}}),n={};return i.forEach(o=>{n[o.field]=o.type||"string"}),{columns:i,typeMap:n}}const Ji=/{{\s*([^}]+)\s*}}/g,F="__DG_EMPTY__",en=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,tn=/__(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 nn(r){return!r||typeof r!="string"?"":r.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const rn=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"]),Ct=/^on\w+$/i,on=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),sn=/^\s*(javascript|vbscript|data|blob):/i;function V(r){if(!r||typeof r!="string")return"";if(r.indexOf("<")===-1)return r;const e=document.createElement("template");return e.innerHTML=r,ln(e.content),e.innerHTML}function ln(r){const e=[],t=r.querySelectorAll("*");for(const i of t){const n=i.tagName.toLowerCase();if(rn.has(n)){e.push(i);continue}if((n==="svg"||i.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(i.attributes).some(l=>Ct.test(l.name)||l.name==="href"||l.name==="xlink:href")){e.push(i);continue}const o=[];for(const s of i.attributes){const l=s.name.toLowerCase();if(Ct.test(l)){o.push(s.name);continue}if(on.has(l)&&sn.test(s.value)){o.push(s.name);continue}if(l==="style"&&/expression\s*\(|javascript:|behavior\s*:/i.test(s.value)){o.push(s.name);continue}}o.forEach(s=>i.removeAttribute(s))}e.forEach(i=>i.remove())}function be(r,e){if(!r||r.indexOf("{{")===-1)return r;const t=[],i=r.replace(Ji,(l,a)=>{const c=an(a,e);return t.push({expr:a.trim(),result:c}),c}),n=cn(i),o=t.length&&t.every(l=>l.result===""||l.result===F);return j.test(r)||o?"":n}function an(r,e){if(r=(r||"").trim(),!r||j.test(r))return F;if(r==="value")return e.value==null?F:String(e.value);if(r.startsWith("row.")&&!/[()?]/.test(r)&&!r.includes(":")){const i=r.slice(4),n=e.row?e.row[i]:void 0;return n==null?F:String(n)}if(r.length>80||!en.test(r)||tn.test(r))return F;const t=r.match(/\./g);if(t&&t.length>1)return F;try{const n=new Function("value","row",`return (${r});`)(e.value,e.row),o=n==null?"":String(n);return j.test(o)?F:o||F}catch{return F}}const j=/Reflect|Proxy|ownKeys/;function cn(r){return r&&r.replace(new RegExp(F,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,"")}function dn(r){if(j.test(r.textContent||"")){for(const e of r.childNodes)e.nodeType===Node.TEXT_NODE&&j.test(e.textContent||"")&&(e.textContent="");j.test(r.textContent||"")&&(r.textContent="")}}function xt(r){const e=j.test(r),t=(i=>e?"":be(r,i));return t.__blocked=e,t}const un=100;class hn{#t;#e;#u;#c;#n;#l={};#i={};#h=!0;#w=[];#f;#a;#v;#d;#g;constructor(e){this.#d=e}get original(){return this.#l}get effective(){return this.#i}get columns(){return this.#i.columns??[]}set columns(e){this.#i.columns=e}get lightDomColumnsCache(){return this.#c}set lightDomColumnsCache(e){this.#c=e}get originalColumnNodes(){return this.#n}set originalColumnNodes(e){this.#n=e}get lightDomTitle(){return this.#g}set lightDomTitle(e){this.#g=e}get initialColumnState(){return this.#v}set initialColumnState(e){this.#v=e}get sourcesChanged(){return this.#h}markSourcesChanged(){this.#h=!0}setGridConfig(e){this.#t=e,this.#h=!0,this.#c=void 0}getGridConfig(){return this.#t}setColumns(e){this.#e=e,this.#h=!0}getColumns(){return this.#e}setFitMode(e){this.#u=e,this.#h=!0}getFitMode(){return this.#u}merge(){const e=(this.#i.columns?.length??0)>0;if(!this.#h&&e)return;const t=this.#R();this.#h=!1,this.#l=t,Object.freeze(this.#l),this.#l.columns&&Object.freeze(this.#l.columns),this.#i=this.#E(this.#l),this.#b()}#E(e){const t={...e};return e.columns&&(t.columns=e.columns.map(i=>({...i}))),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(i=>({...i})),headerContents:e.shell.headerContents?.map(i=>({...i}))}),t}#b(){const e=this.#i;this.#C(),typeof e.rowHeight=="number"&&e.rowHeight>0&&this.#d.setRowHeight(e.rowHeight),e.fitMode==="fixed"&&this.columns.forEach(i=>{i.width==null&&(i.width=80)}),this.#d.applyAnimationConfig(e)}#C(){const e=this.#i.typeDefaults;if(!e)return;const t=this.columns;for(const i of t){if(!i.type)continue;const n=e[i.type];n&&(!i.renderer&&!i.viewRenderer&&n.renderer&&(i.renderer=n.renderer),!i.format&&n.format&&(i.format=n.format),!i.editor&&n.editor&&(i.editor=n.editor),!i.editorParams&&n.editorParams&&(i.editorParams=n.editorParams))}}#R(){const e=this.#t?{...this.#t}:{},t=Array.isArray(e.columns)?[...e.columns]:[],i=(this.#c??[]).map(s=>({...s}));let n=mt(t,i);this.#e&&this.#e.length&&(n=mt(this.#e,i));const o=this.#d.getRows();return n.length===0&&o.length&&(n=Qi(o).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=xt(s.__viewTemplate.innerHTML)),s.__editorTemplate&&!s.__compiledEditor&&(s.__compiledEditor=xt(s.__editorTemplate.innerHTML))}),e.columns=n),this.#u&&(e.fitMode=this.#u),e.fitMode||(e.fitMode="stretch"),this.#p(e),e.columnState&&!this.#v&&(this.#v=e.columnState),e}#p(e){e.shell=e.shell?{...e.shell}:{},e.shell.header=e.shell.header?{...e.shell.header}:{};const t=this.#d.getShellLightDomTitle();t&&(this.#g=t),this.#g&&!e.shell.header.title&&(e.shell.header.title=this.#g);const i=this.#d.getShellLightDomHeaderContent();i?.length>0&&(e.shell.header.lightDomContent=i),this.#d.getShellHasToolButtonsContainer()&&(e.shell.header.hasToolButtonsContainer=!0);const n=this.#d.getShellToolPanels();if(n.size>0){const u=Array.from(n.values());u.sort((h,f)=>(h.order??100)-(f.order??100)),e.shell.toolPanels=u}const o=this.#d.getShellHeaderContents();if(o.size>0){const u=Array.from(o.values());u.sort((h,f)=>(h.order??100)-(f.order??100)),e.shell.headerContents=u}const s=this.#d.getShellToolbarContents(),l=Array.from(s.values()),a=this.#t?.shell?.header?.toolbarContents??[],c=new Set(a.map(u=>u.id)),d=[...a];for(const u of l)c.has(u.id)||d.push(u);d.sort((u,h)=>(u.order??0)-(h.order??0)),e.shell.header.toolbarContents=d}collectState(e){const t=this.columns,i=this.#x();return{columns:t.map((n,o)=>{const s={field:n.field,order:o,visible:!n.hidden},l=n;l.__renderedWidth!==void 0?s.width=l.__renderedWidth:n.width!==void 0&&(s.width=typeof n.width=="string"?parseFloat(n.width):n.width);const a=i.get(n.field);a&&(s.sort=a);for(const c of e)if(c.getColumnState){const d=c.getColumnState(n.field);d&&Object.assign(s,d)}return s})}}applyState(e,t){if(!e.columns||e.columns.length===0)return;const i=this.columns,n=new Map(e.columns.map(l=>[l.field,l])),o=i.map(l=>{const a=n.get(l.field);if(!a)return l;const c={...l};return a.width!==void 0&&(c.width=a.width,c.__renderedWidth=a.width),a.visible!==void 0&&(c.hidden=!a.visible),c});o.sort((l,a)=>{const c=n.get(l.field)?.order??1/0,d=n.get(a.field)?.order??1/0;return c-d}),this.columns=o;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.#d.setSortState({field:l.field,direction:l.sort.direction==="asc"?1:-1})}else this.#d.setSortState(null);for(const l of t)if(l.applyColumnState)for(const a of e.columns)l.applyColumnState(a.field,a)}resetState(e){this.#v=void 0,this.#d.setSortState(null),this.#i=this.#E(this.#l),this.#b();for(const t of e)if(t.applyColumnState)for(const i of this.columns)t.applyColumnState(i.field,{field:i.field,order:0,visible:!0});this.requestStateChange(e)}#x(){const e=new Map,t=this.#d.getSortState();return t&&e.set(t.field,{direction:t.direction===1?"asc":"desc",priority:0}),e}requestStateChange(e){this.#a&&clearTimeout(this.#a),this.#a=setTimeout(()=>{this.#a=void 0;const t=this.collectState(e);this.#d.emit("column-state-change",t)},un)}setColumnVisible(e,t){const i=this.columns,n=i.find(s=>s.field===e);return!n||!t&&n.lockVisible||!t&&i.filter(l=>!l.hidden&&l.field!==e).length===0||!!n.hidden===!t?!1:(n.hidden=!t,this.#d.emit("column-visibility",{field:e,visible:t,visibleColumns:i.filter(s=>!s.hidden).map(s=>s.field)}),this.#d.clearRowPool(),this.#d.setup(),!0)}toggleColumnVisibility(e){const t=this.columns.find(i=>i.field===e);return t?this.setColumnVisible(e,!!t.hidden):!1}isColumnVisible(e){const t=this.columns.find(i=>i.field===e);return t?!t.hidden:!1}showAllColumns(){const e=this.columns;e.some(t=>t.hidden)&&(e.forEach(t=>t.hidden=!1),this.#d.emit("column-visibility",{visibleColumns:e.map(t=>t.field)}),this.#d.clearRowPool(),this.#d.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 t=new Map(this.columns.map(n=>[n.field,n])),i=[];for(const n of e){const o=t.get(n);o&&(i.push(o),t.delete(n))}for(const n of t.values())i.push(n);this.columns=i,this.#d.renderHeader(),this.#d.updateTemplate(),this.#d.refreshVirtualWindow()}parseLightDomColumns(e){this.#c||(this.#n=Array.from(e.querySelectorAll("tbw-grid-column")),this.#c=this.#n.length?Xi(e):[])}clearLightDomCache(){this.#c=void 0}#m=new Map;registerLightDomHandler(e,t){this.#m.set(e.toLowerCase(),t)}unregisterLightDomHandler(e){this.#m.delete(e.toLowerCase())}observeLightDOM(e){this.#f&&this.#f.disconnect();const t=new Set;let i=null;const n=()=>{i=null;for(const o of t)this.#m.get(o)?.();t.clear()};this.#f=new MutationObserver(o=>{for(const s of o){for(const l of s.addedNodes){if(l.nodeType!==Node.ELEMENT_NODE)continue;const c=l.tagName.toLowerCase();this.#m.has(c)&&t.add(c)}if(s.type==="attributes"&&s.target.nodeType===Node.ELEMENT_NODE){const a=s.target.tagName.toLowerCase();this.#m.has(a)&&t.add(a)}}t.size>0&&!i&&(i=setTimeout(n,0))}),this.#f.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.#f?.disconnect(),this.#w=[],this.#a&&clearTimeout(this.#a)}}function ze(){if(typeof window<"u"&&window.location){const r=window.location.hostname;if(r==="localhost"||r==="127.0.0.1"||r==="::1")return!0}return typeof process<"u"&&process.env?.NODE_ENV!=="production"}function Et(r){return`<span role="checkbox" aria-checked="${r}" aria-label="${r}">${r?"🗹":"☐"}</span>`}function Rt(r){if(r==null||r==="")return"";if(r instanceof Date)return isNaN(r.getTime())?"":r.toLocaleDateString();if(typeof r=="number"||typeof r=="string"){const e=new Date(r);return isNaN(e.getTime())?"":e.toLocaleDateString()}return""}function me(r){if(!r)return-1;const e=r.getAttribute("data-row");if(e)return parseInt(e,10);const t=r.closest(".data-grid-row");if(!t)return-1;const i=t.parentElement;if(!i)return-1;const n=i.querySelectorAll(":scope > .data-grid-row");for(let o=0;o<n.length;o++)if(n[o]===t)return o;return-1}function fn(r){if(!r)return-1;const e=r.getAttribute("data-col");return e?parseInt(e,10):-1}function ae(r){r&&r.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function ve(r){try{if(getComputedStyle(r).direction==="rtl")return"rtl"}catch{}try{if(r.closest?.("[dir]")?.getAttribute("dir")==="rtl")return"rtl"}catch{}return"ltr"}function St(r){return ve(r)==="rtl"}function gn(r,e){return r==="left"||r==="right"?r:e==="rtl"?r==="start"?"right":"left":r==="start"?"left":"right"}function _t(r,e){const t=e.renderer||e.viewRenderer;if(t)return t;if(!e.type)return;const i=r.__frameworkAdapter;if(i?.getTypeDefault){const n=i.getTypeDefault(e.type);if(n?.renderer)return n.renderer}}function At(r,e){if(e.format)return e.format;if(!e.type)return;const t=r.__frameworkAdapter;if(t?.getTypeDefault){const i=t.getTypeDefault(e.type);if(i?.format)return i.format}}const $='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function Ne(r){return(r.__editingCellCount??0)>0}function Oe(r){r.__editingCellCount=0,r.removeAttribute("data-has-editing"),r.querySelectorAll(".cell.editing").forEach(t=>t.classList.remove("editing"))}const kt=document.createElement("template");kt.innerHTML='<div class="cell" role="gridcell" part="cell"></div>';const Tt=document.createElement("template");Tt.innerHTML='<div class="data-grid-row" role="row" part="row"></div>';function pn(){return kt.content.firstElementChild.cloneNode(!0)}function wn(){return Tt.content.firstElementChild.cloneNode(!0)}function ye(r){r.__cellDisplayCache=void 0,r.__cellCacheEpoch=void 0,r.__hasSpecialColumns=void 0}function bn(r,e,t,i,n){const o=Math.max(0,t-e),s=r._bodyEl,l=r._visibleColumns,a=l.length;let c=r.__cachedHeaderRowCount;for(c===void 0&&(c=r.querySelector(".header-group-row")?2:1,r.__cachedHeaderRowCount=c);r._rowPool.length<o;){const h=wn();r._rowPool.push(h)}if(r._rowPool.length>o){for(let h=o;h<r._rowPool.length;h++){const f=r._rowPool[h];f.parentNode===s&&f.remove()}r._rowPool.length=o}const d=n&&r.__hasRenderRowPlugins!==!1,u=r._hasAfterRowRenderHook?.()??!1;for(let h=0;h<o;h++){const f=e+h,p=r._rows[f],g=r._rowPool[h];if(g.setAttribute("aria-rowindex",String(f+c+1)),d&&n(p,g,f)){g.__epoch=i,g.__rowDataRef=p,g.parentNode!==s&&s.appendChild(g);continue}const w=g.__epoch,y=g.__rowDataRef,v=g.children.length,P=w===i&&v===a,E=y!==p;let b=!1;if(P&&E){for(let S=0;S<a;S++)if(l[S].externalView&&!g.querySelector(`.cell[data-col="${S}"] [data-external-view]`)){b=!0;break}}if(!P||b){const S=Ne(g),L=r._activeEditRows===f;S&&!L?(g.__isCustomRow&&(g.className="data-grid-row",g.setAttribute("role","row"),g.__isCustomRow=!1),Oe(g),ce(r,g,p,f),g.__epoch=i,g.__rowDataRef=p):S&&L?(Fe(r,g,p,f),g.__rowDataRef=p):(g.__isCustomRow&&(g.className="data-grid-row",g.setAttribute("role","row"),g.__isCustomRow=!1),ce(r,g,p,f),g.__epoch=i,g.__rowDataRef=p)}else if(E){const S=Ne(g),L=r._activeEditRows===f;S&&!L?(Oe(g),ce(r,g,p,f),g.__epoch=i,g.__rowDataRef=p):(Fe(r,g,p,f),g.__rowDataRef=p)}else{const S=Ne(g),L=r._activeEditRows===f;S&&!L?(Oe(g),ce(r,g,p,f),g.__epoch=i,g.__rowDataRef=p):Fe(r,g,p,f)}let C=!1;const A=r.changedRowIds;if(A&&A.length>0)try{const S=r.getRowId?.(p);S&&(C=A.includes(S))}catch{}const m=g.classList.contains("changed");C!==m&&g.classList.toggle("changed",C);const _=r.effectiveConfig?.rowClass;if(_){const S=g.getAttribute("data-dynamic-classes");S&&S.split(" ").forEach(L=>L&&g.classList.remove(L));try{const L=_(p);if(L&&L.length>0){const x=L.filter(k=>k&&typeof k=="string");x.forEach(k=>g.classList.add(k)),g.setAttribute("data-dynamic-classes",x.join(" "))}else g.removeAttribute("data-dynamic-classes")}catch(L){console.warn("[tbw-grid] rowClass callback error:",L),g.removeAttribute("data-dynamic-classes")}}u&&r._afterRowRender?.({row:p,rowIndex:f,rowElement:g}),g.parentNode!==s&&s.appendChild(g)}}function Fe(r,e,t,i){const n=e.children,o=r._visibleColumns,s=o.length,l=n.length,a=s<l?s:l,c=r._focusRow,d=r._focusCol,u=r._hasAfterCellRenderHook?.()??!1;let h=r.__hasSpecialColumns;if(h===void 0){h=!1;const p=r.__frameworkAdapter;for(let g=0;g<s;g++){const w=o[g];if(w.__viewTemplate||w.__compiledView||w.renderer||w.viewRenderer||w.externalView||w.format||w.type==="date"||w.type==="boolean"||w.type&&p?.getTypeDefault?.(w.type)?.renderer||w.type&&p?.getTypeDefault?.(w.type)?.format){h=!0;break}}r.__hasSpecialColumns=h}const f=String(i);if(!h){for(let p=0;p<a;p++){const g=n[p];if(g.classList.contains("editing"))continue;const w=o[p],y=t[w.field];g.textContent=y==null?"":String(y),g.getAttribute("data-row")!==f&&g.setAttribute("data-row",f);const v=c===i&&d===p,T=g.classList.contains("cell-focus");v!==T&&(g.classList.toggle("cell-focus",v),g.setAttribute("aria-selected",String(v))),u&&r._afterCellRender?.({row:t,rowIndex:i,column:w,colIndex:p,value:y,cellElement:g,rowElement:e})}return}for(let p=0;p<a;p++)if(o[p].externalView&&!n[p].querySelector("[data-external-view]")){ce(r,e,t,i);return}for(let p=0;p<a;p++){const g=o[p],w=n[p];w.getAttribute("data-row")!==f&&w.setAttribute("data-row",f);const y=c===i&&d===p,v=w.classList.contains("cell-focus");y!==v&&(w.classList.toggle("cell-focus",y),w.setAttribute("aria-selected",String(y)));const T=g.cellClass;if(T){const A=w.getAttribute("data-dynamic-classes");A&&A.split(" ").forEach(m=>m&&w.classList.remove(m));try{const m=t[g.field],_=T(m,t,g);if(_&&_.length>0){const S=_.filter(L=>L&&typeof L=="string");S.forEach(L=>w.classList.add(L)),w.setAttribute("data-dynamic-classes",S.join(" "))}else w.removeAttribute("data-dynamic-classes")}catch(m){console.warn(`[tbw-grid] cellClass callback error for column '${g.field}':`,m),w.removeAttribute("data-dynamic-classes")}}if(w.classList.contains("editing"))continue;const P=_t(r,g);if(P){const A=t[g.field],m=P({row:t,value:A,field:g.field,column:g,cellEl:w});typeof m=="string"?w.innerHTML=V(m):m instanceof Node?m.parentElement!==w&&(w.innerHTML="",w.appendChild(m)):m==null&&(w.textContent=A==null?"":String(A)),u&&r._afterCellRender?.({row:t,rowIndex:i,column:g,colIndex:p,value:A,cellElement:w,rowElement:e});continue}if(g.__viewTemplate||g.__compiledView||g.externalView)continue;const E=t[g.field];let b;const C=At(r,g);if(C){try{const A=C(E,t);b=A==null?"":String(A)}catch(A){console.warn(`[tbw-grid] Format error in column '${g.field}':`,A),b=E==null?"":String(E)}w.textContent=b}else g.type==="date"?(b=Rt(E),w.textContent=b):g.type==="boolean"?w.innerHTML=Et(!!E):(b=E==null?"":String(E),w.textContent=b);u&&r._afterCellRender?.({row:t,rowIndex:i,column:g,colIndex:p,value:E,cellElement:w,rowElement:e})}}function ce(r,e,t,i){e.innerHTML="";const n=r._visibleColumns,o=n.length,s=r._focusRow,l=r._focusCol,a=r,c=r._hasAfterCellRenderHook?.()??!1,d=document.createDocumentFragment();for(let u=0;u<o;u++){const h=n[u],f=pn();f.setAttribute("aria-colindex",String(u+1)),f.setAttribute("data-col",String(u)),f.setAttribute("data-row",String(i)),f.setAttribute("data-field",h.field),f.setAttribute("data-header",h.header??h.field),h.type&&f.setAttribute("data-type",h.type);let p=t[h.field];const g=At(r,h);if(g)try{p=g(p,t)}catch(b){console.warn(`[tbw-grid] Format error in column '${h.field}':`,b)}const w=h.__compiledView,y=h.__viewTemplate,v=_t(r,h),T=h.externalView;let P=!1;if(v){const b=v({row:t,value:p,field:h.field,column:h,cellEl:f});typeof b=="string"?(f.innerHTML=V(b),P=!0):b instanceof Node?b.parentElement!==f&&(f.textContent="",f.appendChild(b)):b==null&&(f.textContent=p==null?"":String(p))}else if(T){const b=T,C=document.createElement("div");C.setAttribute("data-external-view",""),C.setAttribute("data-field",h.field),f.appendChild(C);const A={row:t,value:p,field:h.field,column:h};if(b.mount)try{b.mount({placeholder:C,context:A,spec:b})}catch(m){console.warn(`[tbw-grid] External view mount error for column '${h.field}':`,m)}else queueMicrotask(()=>{try{a.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:C,spec:b,context:A}}))}catch(m){console.warn(`[tbw-grid] External view event dispatch error for column '${h.field}':`,m)}});C.setAttribute("data-mounted","")}else if(w){const b=w({row:t,value:p,field:h.field,column:h}),C=w.__blocked;f.innerHTML=C?"":V(b),P=!0,C&&(f.textContent="",f.setAttribute("data-blocked-template",""))}else if(y){const b=y.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(b)?(f.textContent="",f.setAttribute("data-blocked-template","")):(f.innerHTML=V(be(b,{row:t,value:p})),P=!0)}else g?f.textContent=p==null?"":String(p):h.type==="date"?f.textContent=Rt(p):h.type==="boolean"?f.innerHTML=Et(!!p):f.textContent=p==null?"":String(p);if(P){dn(f);const b=f.textContent||"";/Proxy|Reflect\.ownKeys/.test(b)&&(f.textContent=b.replace(/Proxy|Reflect\.ownKeys/g,"").trim(),/Proxy|Reflect\.ownKeys/.test(f.textContent||"")&&(f.textContent=""))}f.hasAttribute("data-blocked-template")&&(f.textContent||"").trim().length&&(f.textContent=""),h.editable?f.tabIndex=0:h.type==="boolean"&&(f.hasAttribute("tabindex")||(f.tabIndex=0)),s===i&&l===u?(f.classList.add("cell-focus"),f.setAttribute("aria-selected","true")):f.setAttribute("aria-selected","false");const E=h.cellClass;if(E)try{const b=t[h.field],C=E(b,t,h);if(C&&C.length>0){const A=C.filter(m=>m&&typeof m=="string");A.forEach(m=>f.classList.add(m)),f.setAttribute("data-dynamic-classes",A.join(" "))}}catch(b){console.warn(`[tbw-grid] cellClass callback error for column '${h.field}':`,b)}c&&r._afterCellRender?.({row:t,rowIndex:i,column:h,colIndex:u,value:p,cellElement:f,rowElement:e}),d.appendChild(f)}e.appendChild(d)}function Lt(r,e,t){if(e.target?.closest(".resize-handle"))return;const i=t.querySelector(".cell[data-row]"),n=me(i);if(n<0)return;const o=r._rows[n];if(!o||r._dispatchRowClick?.(e,n,o,t))return;const s=e.target?.closest(".cell[data-col]");if(s){const l=Number(s.getAttribute("data-col"));if(!isNaN(l)){if(r._dispatchCellClick?.(e,n,l,s))return;const a=r._focusRow!==n||r._focusCol!==l;if(r._focusRow=n,r._focusCol=l,s.classList.contains("editing")){a&&(ae(r._bodyEl??r),s.classList.add("cell-focus"));const c=s.querySelector($);try{c?.focus({preventScroll:!0})}catch{}return}I(r)}}}function mn(r,e){if(r._dispatchKeyDown?.(e))return;const t=r._rows.length-1,i=r._visibleColumns.length-1,n=r._activeEditRows!==void 0&&r._activeEditRows!==-1,s=r._visibleColumns[r._focusCol]?.type,l=e.composedPath?.()??[],a=l.length?l[0]:e.target,c=d=>{if(!d)return!1;const u=d.tagName;return!!(u==="INPUT"||u==="SELECT"||u==="TEXTAREA"||d.isContentEditable)};if(!(c(a)&&(e.key==="Home"||e.key==="End"))&&!(c(a)&&(e.key==="ArrowUp"||e.key==="ArrowDown")&&a.tagName==="INPUT"&&a.type==="number")&&!(c(a)&&(e.key==="ArrowLeft"||e.key==="ArrowRight"))&&!(c(a)&&(e.key==="Enter"||e.key==="Escape"))&&!(n&&s==="select"&&(e.key==="ArrowDown"||e.key==="ArrowUp"))){switch(e.key){case"Tab":{e.preventDefault(),!e.shiftKey?r._focusCol<i?r._focusCol+=1:(typeof r.commitActiveRowEdit=="function"&&r.commitActiveRowEdit(),r._focusRow<t&&(r._focusRow+=1,r._focusCol=0)):r._focusCol>0?r._focusCol-=1:r._focusRow>0&&(typeof r.commitActiveRowEdit=="function"&&r._activeEditRows===r._focusRow&&r.commitActiveRowEdit(),r._focusRow-=1,r._focusCol=i),I(r);return}case"ArrowDown":n&&typeof r.commitActiveRowEdit=="function"&&r.commitActiveRowEdit(),r._focusRow=Math.min(t,r._focusRow+1),e.preventDefault();break;case"ArrowUp":n&&typeof r.commitActiveRowEdit=="function"&&r.commitActiveRowEdit(),r._focusRow=Math.max(0,r._focusRow-1),e.preventDefault();break;case"ArrowRight":{St(r)?r._focusCol=Math.max(0,r._focusCol-1):r._focusCol=Math.min(i,r._focusCol+1),e.preventDefault();break}case"ArrowLeft":{St(r)?r._focusCol=Math.min(i,r._focusCol+1):r._focusCol=Math.max(0,r._focusCol-1),e.preventDefault();break}case"Home":(e.ctrlKey||e.metaKey)&&(n&&typeof r.commitActiveRowEdit=="function"&&r.commitActiveRowEdit(),r._focusRow=0),r._focusCol=0,e.preventDefault(),I(r,{forceScrollLeft:!0});return;case"End":(e.ctrlKey||e.metaKey)&&(n&&typeof r.commitActiveRowEdit=="function"&&r.commitActiveRowEdit(),r._focusRow=t),r._focusCol=i,e.preventDefault(),I(r,{forceScrollRight:!0});return;case"PageDown":r._focusRow=Math.min(t,r._focusRow+20),e.preventDefault();break;case"PageUp":r._focusRow=Math.max(0,r._focusRow-20),e.preventDefault();break;case"Enter":{const d=r._focusRow,u=r._focusCol,h=r._visibleColumns[u],f=r._rows[d],p=h?.field??"",g=p&&f?f[p]:void 0,w=r.querySelector(`[data-row="${d}"][data-col="${u}"]`),y={rowIndex:d,colIndex:u,field:p,value:g,row:f,cellEl:w,trigger:"keyboard",originalEvent:e},v=new CustomEvent("cell-activate",{cancelable:!0,detail:y});r.dispatchEvent(v);const T=new CustomEvent("activate-cell",{cancelable:!0,detail:{row:d,col:u}});if(r.dispatchEvent(T),v.defaultPrevented||T.defaultPrevented){e.preventDefault();return}break}default:return}I(r)}}function I(r,e){if(r._virtualization?.enabled){const{rowHeight:s,container:l,viewportEl:a}=r._virtualization,c=l,d=a?.clientHeight??c?.clientHeight??0;if(c&&d>0){const u=r._focusRow*s;u<c.scrollTop?c.scrollTop=u:u+s>c.scrollTop+d&&(c.scrollTop=u-d+s)}}const t=r._activeEditRows!==void 0&&r._activeEditRows!==-1;t||r.refreshVirtualWindow(!1),ae(r._bodyEl),Array.from(r._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(s=>{s.setAttribute("aria-selected","false")});const i=r._focusRow,n=r._virtualization.start??0,o=r._virtualization.end??r._rows.length;if(i>=n&&i<o){const s=r._bodyEl.querySelectorAll(".data-grid-row")[i-n];let l=s?.children[r._focusCol];if((!l||!l.classList?.contains("cell"))&&(l=s?.querySelector(`.cell[data-col="${r._focusCol}"]`)??s?.querySelector(".cell[data-col]")),l){l.classList.add("cell-focus"),l.setAttribute("aria-selected","true");const a=r.querySelector(".tbw-scroll-area");if(a&&l&&(!t||e?.forceHorizontalScroll))if(e?.forceScrollLeft)a.scrollLeft=0;else if(e?.forceScrollRight)a.scrollLeft=a.scrollWidth-a.clientWidth;else{const c=r._getHorizontalScrollOffsets?.(s??void 0,l)??{left:0,right:0};if(!c.skipScroll){const d=l.getBoundingClientRect(),u=a.getBoundingClientRect(),h=d.left-u.left+a.scrollLeft,f=h+d.width,p=a.scrollLeft+c.left,g=a.scrollLeft+a.clientWidth-c.right;h<p?a.scrollLeft=h-c.left:f>g&&(a.scrollLeft=f-a.clientWidth+c.right)}}if(r._activeEditRows!==void 0&&r._activeEditRows!==-1&&l.classList.contains("editing")){const c=l.querySelector($);if(c&&document.activeElement!==c)try{c.focus({preventScroll:!0})}catch{}}else if(!l.contains(document.activeElement)){l.hasAttribute("tabindex")||l.setAttribute("tabindex","-1");try{l.focus({preventScroll:!0})}catch{}}}}}const Ce=new WeakMap;function vn(r,e){const t=me(e),i=fn(e);t<0||i<0||(r._focusRow=t,r._focusCol=i,ae(r._bodyEl),e.classList.add("cell-focus"),e.setAttribute("aria-selected","true"))}function qe(r,e,t,i){let n=null;const o=t.composedPath?.();if(o&&o.length>0?n=o[0]:n=t.target,n&&!e.contains(n)){const g=document.elementFromPoint(t.clientX,t.clientY);g&&(n=g)}const s=n?.closest?.("[data-col]"),l=n?.closest?.(".data-grid-row"),a=n?.closest?.(".header-row");let c,d,u,h,f,p;return s&&(c=parseInt(s.getAttribute("data-row")??"-1",10),d=parseInt(s.getAttribute("data-col")??"-1",10),c>=0&&d>=0&&(u=r._rows[c],p=r._columns[d],h=p?.field,f=u&&h?u[h]:void 0)),{type:i,row:u,rowIndex:c!==void 0&&c>=0?c:void 0,colIndex:d!==void 0&&d>=0?d:void 0,field:h,value:f,column:p,originalEvent:t,cellElement:s??void 0,rowElement:l??void 0,isHeader:!!a,cell:c!==void 0&&d!==void 0&&c>=0&&d>=0?{row:c,col:d}:void 0}}function yn(r,e,t){const i=qe(r,e,t,"mousedown");(r._dispatchCellMouseDown?.(i)??!1)&&Ce.set(r,!0)}function Cn(r,e,t){if(!Ce.get(r))return;const i=qe(r,e,t,"mousemove");r._dispatchCellMouseMove?.(i)}function xn(r,e,t){if(!Ce.get(r))return;const i=qe(r,e,t,"mouseup");r._dispatchCellMouseUp?.(i),Ce.set(r,!1)}function En(r,e,t){e.addEventListener("mousedown",i=>{const n=i.target.closest(".cell[data-col]");n&&(n.classList.contains("editing")||vn(r,n))},{signal:t}),e.addEventListener("click",i=>{const n=i.target.closest(".data-grid-row");n&&Lt(r,i,n)},{signal:t}),e.addEventListener("dblclick",i=>{const n=i.target.closest(".data-grid-row");n&&Lt(r,i,n)},{signal:t})}function Rn(r,e,t,i){e.addEventListener("keydown",n=>mn(r,n),{signal:i}),t.addEventListener("mousedown",n=>yn(r,t,n),{signal:i}),document.addEventListener("mousemove",n=>Cn(r,t,n),{signal:i}),document.addEventListener("mouseup",n=>xn(r,t,n),{signal:i})}function Pt(r,e){return r==null&&e==null?0:r==null?-1:e==null||r>e?1:r<e?-1:0}function Ht(r,e,t){const n=t.find(l=>l.field===e.field)?.sortComparator??Pt,{field:o,direction:s}=e;return[...r].sort((l,a)=>n(l[o],a[o],l,a)*s)}function Dt(r,e,t,i){r._rows=e,r.__rowRenderEpoch++,r._rowPool.forEach(n=>n.__epoch=-1),_e(r),r.refreshVirtualWindow(!0),r.dispatchEvent(new CustomEvent("sort-change",{detail:{field:t.field,direction:i}})),r.requestStateChange?.()}function Mt(r,e){!r._sortState||r._sortState.field!==e.field?(r._sortState||(r.__originalOrder=r._rows.slice()),It(r,e,1)):r._sortState.direction===1?It(r,e,-1):(r._sortState=null,r.__rowRenderEpoch++,r._rowPool.forEach(i=>i.__epoch=-1),r._rows=r.__originalOrder.slice(),_e(r),r._headerRowEl?.querySelectorAll('[role="columnheader"].sortable')?.forEach(i=>{i.getAttribute("aria-sort")?(i.getAttribute("aria-sort")==="ascending"||i.getAttribute("aria-sort")==="descending")&&(r._sortState||i.setAttribute("aria-sort","none")):i.setAttribute("aria-sort","none")}),r.refreshVirtualWindow(!0),r.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:0}})),r.requestStateChange?.())}function It(r,e,t){r._sortState={field:e.field,direction:t};const i={field:e.field,direction:t},n=r._columns,s=(r.effectiveConfig?.sortHandler??Ht)(r._rows,i,n);s&&typeof s.then=="function"?s.then(l=>{Dt(r,l,e,t)}):Dt(r,s,e,t)}function de(r,e){return r.effectiveConfig?.sortable!==!1&&e.sortable===!0}function xe(r,e){return r.effectiveConfig?.resizable!==!1&&e.resizable!==!1}function Sn(r,e){typeof e=="string"?r.textContent=e:e instanceof HTMLElement&&(r.innerHTML="",r.appendChild(e.cloneNode(!0)))}function Ee(r,e){const t=document.createElement("span");vt(t,"sort-indicator");const i=r._sortState?.field===e.field?r._sortState.direction:0,n={...G,...r.icons},o=i===1?n.sortAsc:i===-1?n.sortDesc:n.sortNone;return Sn(t,o),t}function Re(r,e,t){const i=document.createElement("div");return i.className="resize-handle",i.setAttribute("aria-hidden","true"),i.addEventListener("mousedown",n=>{n.stopPropagation(),n.preventDefault(),r._resizeController.start(n,e,t)}),i.addEventListener("dblclick",n=>{n.stopPropagation(),n.preventDefault(),r._resizeController.resetColumn(e)}),i}function Se(r,e,t,i){i.classList.add("sortable"),i.tabIndex=0;const n=r._sortState?.field===e.field?r._sortState.direction:0;i.setAttribute("aria-sort",n===0?"none":n===1?"ascending":"descending"),i.addEventListener("click",o=>{r._resizeController?.isResizing||r._dispatchHeaderClick?.(o,t,i)||Mt(r,e)}),i.addEventListener("keydown",o=>{if(o.key==="Enter"||o.key===" "){if(o.preventDefault(),r._dispatchHeaderClick?.(o,t,i))return;Mt(r,e)}})}function _n(r,e){if(e!=null)if(typeof e=="string"){const t=document.createElement("span");for(t.innerHTML=V(e);t.firstChild;)r.appendChild(t.firstChild)}else e instanceof Node&&r.appendChild(e)}function _e(r){r._headerRowEl=r.findHeaderRow();const e=r._headerRowEl;e&&(e.innerHTML="",r._visibleColumns.forEach((t,i)=>{const n=document.createElement("div");n.className="cell",vt(n,"header-cell"),n.setAttribute("role","columnheader"),n.setAttribute("aria-colindex",String(i+1)),n.setAttribute("data-field",t.field),n.setAttribute("data-col",String(i));const o=t.header??t.field,s=r._sortState?.field===t.field?r._sortState.direction:0,l=s===1?"asc":s===-1?"desc":null;if(t.headerRenderer){const a={column:t,value:o,sortState:l,filterActive:!1,cellEl:n,renderSortIcon:()=>de(r,t)?Ee(r,t):null,renderFilterButton:()=>null},c=t.headerRenderer(a);_n(n,c),de(r,t)&&Se(r,t,i,n),xe(r,t)&&(n.classList.add("resizable"),n.appendChild(Re(r,i,n)))}else if(t.headerLabelRenderer){const a={column:t,value:o},c=t.headerLabelRenderer(a),d=document.createElement("span");c==null?d.textContent=o:typeof c=="string"?d.innerHTML=V(c):c instanceof Node&&d.appendChild(c),n.appendChild(d),de(r,t)&&(Se(r,t,i,n),n.appendChild(Ee(r,t))),xe(r,t)&&(n.classList.add("resizable"),n.appendChild(Re(r,i,n)))}else if(t.__headerTemplate)Array.from(t.__headerTemplate.childNodes).forEach(a=>n.appendChild(a.cloneNode(!0))),de(r,t)&&(Se(r,t,i,n),n.appendChild(Ee(r,t))),xe(r,t)&&(n.classList.add("resizable"),n.appendChild(Re(r,i,n)));else{const a=document.createElement("span");a.textContent=o,n.appendChild(a),de(r,t)&&(Se(r,t,i,n),n.appendChild(Ee(r,t))),xe(r,t)&&(n.classList.add("resizable"),n.appendChild(Re(r,i,n)))}e.appendChild(n)}),e.querySelectorAll(".cell.sortable").forEach(t=>{t.getAttribute("aria-sort")||t.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 zt=typeof requestIdleCallback=="function";function An(r,e){return zt?requestIdleCallback(r,e):window.setTimeout(()=>{const t=Date.now();r({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})},1)}function Nt(r){zt?cancelIdleCallback(r):clearTimeout(r)}function kn(r){const e=document.createElement("div");return e.className=`tbw-spinner tbw-spinner--${r}`,e.setAttribute("role","progressbar"),e.setAttribute("aria-label","Loading"),e}function Tn(r,e){if(e){const i=e({size:r});if(typeof i=="string"){const n=document.createElement("div");return n.innerHTML=i,n}return i}return kn(r)}function Ln(r){const e=document.createElement("div");return e.className="tbw-loading-overlay",e.setAttribute("role","status"),e.setAttribute("aria-live","polite"),e.appendChild(Tn("large",r)),e}function Pn(r,e){r.appendChild(e)}function Hn(r){r?.remove()}function Dn(r,e){e?(r.classList.add("tbw-row-loading"),r.setAttribute("aria-busy","true")):(r.classList.remove("tbw-row-loading"),r.removeAttribute("aria-busy"))}function Mn(r,e){e?(r.classList.add("tbw-cell-loading"),r.setAttribute("aria-busy","true")):(r.classList.remove("tbw-cell-loading"),r.removeAttribute("aria-busy"))}var M=(r=>(r[r.STYLE=1]="STYLE",r[r.VIRTUALIZATION=2]="VIRTUALIZATION",r[r.HEADER=3]="HEADER",r[r.ROWS=4]="ROWS",r[r.COLUMNS=5]="COLUMNS",r[r.FULL=6]="FULL",r))(M||{});class In{#t;#e=0;#u=0;#c=null;#n=null;#l=null;#i=!1;constructor(e){this.#t=e}requestPhase(e,t){e>this.#e&&(this.#e=e),this.#u===0&&(this.#h(),this.#u=requestAnimationFrame(()=>this.#w()))}whenReady(){return this.#c?this.#c:Promise.resolve()}setInitialReadyResolver(e){this.#l=e}cancel(){this.#u!==0&&(cancelAnimationFrame(this.#u),this.#u=0),this.#e=0,this.#n&&(this.#n(),this.#n=null,this.#c=null)}get isPending(){return this.#e!==0}get pendingPhase(){return this.#e}#h(){this.#c||(this.#c=new Promise(e=>{this.#n=e}))}#w(){if(this.#u=0,!this.#t.isConnected()){this.#e=0,this.#n&&(this.#n(),this.#n=null,this.#c=null);return}const e=this.#e;this.#e=0,e>=5&&this.#t.mergeConfig(),e>=4&&this.#t.processRows(),e>=5&&(this.#t.processColumns(),this.#t.updateTemplate()),e>=3&&this.#t.renderHeader(),e>=2&&this.#t.renderVirtualWindow(),e>=1&&this.#t.afterRender(),!this.#i&&this.#l&&(this.#i=!0,this.#l()),this.#n&&(this.#n(),this.#n=null,this.#c=null)}}function Ot(r){let e=null,t=null,i=null,n=null;const o=a=>{if(!e)return;const c=a.clientX-e.startX,d=Math.max(40,e.startWidth+c),u=r._visibleColumns[e.colIndex];u.width=d,u.__userResized=!0,u.__renderedWidth=d,t==null&&(t=requestAnimationFrame(()=>{t=null,r.updateTemplate?.()})),r.dispatchEvent(new CustomEvent("column-resize",{detail:{field:u.field,width:d}}))};let s=!1;const l=()=>{const a=e!==null;a&&(s=!0,requestAnimationFrame(()=>{s=!1})),window.removeEventListener("mousemove",o),window.removeEventListener("mouseup",l),i!==null&&(document.documentElement.style.cursor=i,i=null),n!==null&&(document.body.style.userSelect=n,n=null),e=null,a&&r.requestStateChange&&r.requestStateChange()};return{get isResizing(){return e!==null||s},start(a,c,d){a.preventDefault();const u=r._visibleColumns[c],h=typeof u?.width=="number"?u.width:void 0,f=u?.__renderedWidth??h??d.getBoundingClientRect().width;e={startX:a.clientX,colIndex:c,startWidth:f},window.addEventListener("mousemove",o),window.addEventListener("mouseup",l),i===null&&(i=document.documentElement.style.cursor),document.documentElement.style.cursor="e-resize",n===null&&(n=document.body.style.userSelect),document.body.style.userSelect="none"},resetColumn(a){const c=r._visibleColumns[a];c&&(c.__userResized=!1,c.__renderedWidth=void 0,c.width=c.__originalWidth,r.updateTemplate?.(),r.requestStateChange?.(),r.dispatchEvent(new CustomEvent("column-resize-reset",{detail:{field:c.field,width:c.width}})))},dispose(){l()}}}const Ge="data-animating",zn={change:"--tbw-row-change-duration",insert:"--tbw-row-insert-duration",remove:"--tbw-row-remove-duration"},Nn={change:500,insert:300,remove:200};function On(r){const e=r.trim().toLowerCase();return e.endsWith("ms")?parseFloat(e):e.endsWith("s")?parseFloat(e)*1e3:parseFloat(e)}function Fn(r,e){const t=zn[e],i=getComputedStyle(r).getPropertyValue(t);if(i){const n=On(i);if(!isNaN(n)&&n>0)return n}return Nn[e]}function qn(r,e,t){r.removeAttribute(Ge),r.offsetWidth,r.setAttribute(Ge,e);const i=Fn(r,e);setTimeout(()=>{e!=="remove"&&r.removeAttribute(Ge)},i)}function $e(r,e,t){if(e<0)return!1;const i=r.findRenderedRowElement?.(e);return i?(qn(i,t),!0):!1}function Gn(r,e,t){let i=0;for(const n of e)$e(r,n,t)&&i++;return i}function $n(r,e,t){const i=r._rows??[],n=r.getRowId;if(!n)return!1;const o=i.findIndex(s=>{if(s==null)return!1;try{return n(s)===e}catch{return!1}});return o<0?!1:$e(r,o,t)}function Ae(r,e,t){const i=document.createElement(r);if(e)for(const n in e){const o=e[n];o!=null&&i.setAttribute(n,o)}return i}function O(r,e){const t=document.createElement("div");if(r&&(t.className=r),e)for(const i in e){const n=e[i];n!=null&&t.setAttribute(i,n)}return t}function Ft(r,e,t){const i=document.createElement("button");if(r&&(i.className=r),e)for(const n in e){const o=e[n];o!=null&&i.setAttribute(n,o)}return i}const qt=document.createElement("template");qt.innerHTML=`
|
|
2
2
|
<div class="tbw-scroll-area">
|
|
3
3
|
<div class="rows-body-wrapper">
|
|
4
4
|
<div class="rows-body" role="grid">
|
|
@@ -16,20 +16,20 @@
|
|
|
16
16
|
<div class="faux-vscroll">
|
|
17
17
|
<div class="faux-vscroll-spacer"></div>
|
|
18
18
|
</div>
|
|
19
|
-
`;function
|
|
19
|
+
`;function Gt(){return qt.content.cloneNode(!0)}function $t(r){const e=document.createDocumentFragment(),t=O(r.hasShell?"tbw-grid-root has-shell":"tbw-grid-root");if(r.hasShell&&r.shellHeader&&r.shellBody)t.appendChild(r.shellHeader),t.appendChild(r.shellBody);else{const i=O("tbw-grid-content");i.appendChild(Gt()),t.appendChild(i)}return e.appendChild(t),e}function Bn(r){const e=O("tbw-shell-header",{part:"shell-header",role:"presentation"});if(r.title){const o=O("tbw-shell-title");o.textContent=r.title,e.appendChild(o)}const t=O("tbw-shell-content",{part:"shell-content",role:"presentation","data-light-dom-header-content":""});e.appendChild(t);const i=O("tbw-shell-toolbar",{part:"shell-toolbar",role:"presentation"});for(const o of r.configButtons)o.hasRender&&i.appendChild(O("tbw-toolbar-content-slot",{"data-toolbar-content":o.id}));for(const o of r.apiButtons)o.hasRender&&i.appendChild(O("tbw-toolbar-content-slot",{"data-toolbar-content":o.id}));if((r.configButtons.some(o=>o.hasRender)||r.apiButtons.some(o=>o.hasRender))&&r.hasPanels&&i.appendChild(O("tbw-toolbar-separator")),r.hasPanels){const o=Ft(r.isPanelOpen?"tbw-toolbar-btn active":"tbw-toolbar-btn",{"data-panel-toggle":"",title:"Settings","aria-label":"Toggle settings panel","aria-pressed":String(r.isPanelOpen),"aria-controls":"tbw-tool-panel"});o.innerHTML=r.toolPanelIcon,i.appendChild(o)}return e.appendChild(i),e}function Kn(r){const e=O("tbw-shell-body"),t=r.panels.length>0,i=r.panels.length===1,n=O("tbw-grid-content");n.appendChild(Gt());let o=null;if(t){o=Ae("aside",{class:r.isPanelOpen?"tbw-tool-panel open":"tbw-tool-panel",part:"tool-panel","data-position":r.position,role:"presentation",id:"tbw-tool-panel"});const s=r.position==="left"?"right":"left";o.appendChild(O("tbw-tool-panel-resize",{"data-resize-handle":"","data-handle-position":s,"aria-hidden":"true"}));const l=O("tbw-tool-panel-content",{role:"presentation"}),a=O("tbw-accordion");for(const c of r.panels){const d=`tbw-accordion-section${c.isExpanded?" expanded":""}${i?" single":""}`,u=O(d,{"data-section":c.id}),h=Ft("tbw-accordion-header",{"aria-expanded":String(c.isExpanded),"aria-controls":`tbw-section-${c.id}`});if(i&&h.setAttribute("aria-disabled","true"),c.icon){const p=Ae("span",{class:"tbw-accordion-icon"});p.innerHTML=c.icon,h.appendChild(p)}const f=Ae("span",{class:"tbw-accordion-title"});if(f.textContent=c.title,h.appendChild(f),!i){const p=Ae("span",{class:"tbw-accordion-chevron"});p.innerHTML=c.isExpanded?r.collapseIcon:r.expandIcon,h.appendChild(p)}u.appendChild(h),u.appendChild(O("tbw-accordion-content",{id:`tbw-section-${c.id}`,role:"presentation"})),a.appendChild(u)}l.appendChild(a),o.appendChild(l)}return r.position==="left"&&o?(e.appendChild(o),e.appendChild(n)):(e.appendChild(n),o&&e.appendChild(o)),e}function Y(r){return r?typeof r=="string"?r:r.outerHTML:""}function Wn(){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 Bt(r){return!!(r?.header?.title||r?.header?.toolbarContents?.length||r?.toolPanels?.length||r?.headerContents?.length||r?.header?.lightDomContent?.length||r?.header?.hasToolButtonsContainer)}function Vn(r,e,t="☰"){const i=r?.header?.title??e.lightDomTitle??"",n=!!i,o=Y(t),s=r?.header?.toolbarContents??[],l=[...e.toolbarContents.values()],a=new Set(s.map(g=>g.id)),c=[...s];for(const g of l)a.has(g.id)||c.push(g);const d=c.length>0,u=e.toolPanels.size>0,h=d&&u,f=[...c].sort((g,w)=>(g.order??0)-(w.order??0));let p="";for(const g of f)p+=`<div class="tbw-toolbar-content-slot" data-toolbar-content="${g.id}"></div>`;if(h&&(p+='<div class="tbw-toolbar-separator"></div>'),u){const g=e.isPanelOpen;p+=`<button class="${g?"tbw-toolbar-btn active":"tbw-toolbar-btn"}" data-panel-toggle title="Settings" aria-label="Toggle settings panel" aria-pressed="${g}" aria-controls="tbw-tool-panel">${o}</button>`}return`
|
|
20
20
|
<div class="tbw-shell-header" part="shell-header" role="presentation">
|
|
21
|
-
${n?`<div class="tbw-shell-title">${
|
|
21
|
+
${n?`<div class="tbw-shell-title">${nn(i)}</div>`:""}
|
|
22
22
|
<div class="tbw-shell-content" part="shell-content" role="presentation" data-light-dom-header-content></div>
|
|
23
23
|
<div class="tbw-shell-toolbar" part="shell-toolbar" role="presentation">
|
|
24
24
|
${p}
|
|
25
25
|
</div>
|
|
26
26
|
</div>
|
|
27
|
-
`}function Kt(r,e){const t=r.querySelector("tbw-grid-header");if(!t)return;if(!e.lightDomTitle){const n=t.getAttribute("title");n&&(e.lightDomTitle=n)}const i=t.querySelectorAll("tbw-grid-header-content");i.length>0&&e.lightDomHeaderContent.length===0&&(e.lightDomHeaderContent=Array.from(i)),t.style.display="none"}function $t(r,e,t){const i=r.querySelector(":scope > tbw-grid-tool-buttons");if(!i)return;e.hasToolButtonsContainer=!0;const n="light-dom-toolbar-content";if(e.lightDomToolbarContentIds.has(n))return;const o={id:n,order:0,render:(s=>{for(;i.firstChild;)s.appendChild(i.firstChild);return()=>{for(;s.firstChild;)i.appendChild(s.firstChild)}})};e.toolbarContents.set(n,o),e.lightDomToolbarContentIds.add(n),i.style.display="none"}function Wt(r,e,t){r.querySelectorAll(":scope > tbw-grid-tool-panel").forEach(n=>{const o=n,s=o.getAttribute("id"),l=o.getAttribute("title");if(!s||!l){console.warn(`[parseLightDomToolPanels] Tool panel missing required id or title attribute: id="${s??""}", title="${l??""}"`);return}const a=o.getAttribute("icon")??void 0,c=o.getAttribute("tooltip")??void 0,d=parseInt(o.getAttribute("order")??"100",10);let u;const h=t?.(o);if(h)u=h;else{const g=o.innerHTML.trim();u=w=>{const b=document.createElement("div");return b.innerHTML=g,w.appendChild(b),()=>b.remove()}}const f=e.toolPanels.get(s);if(f){if(h){f.render=u,f.order=d,f.icon=a,f.tooltip=c;const g=e.panelCleanups.get(s);g&&(g(),e.panelCleanups.delete(s))}return}const p={id:s,title:l,icon:a,tooltip:c,order:d,render:u};e.toolPanels.set(s,p),e.lightDomToolPanelIds.add(s),o.style.display="none"})}function Wn(r,e,t,i){const n=r.querySelector(".tbw-shell-toolbar");n&&n.addEventListener("click",s=>{if(s.target.closest("[data-panel-toggle]")){i.onPanelToggle();return}});const o=r.querySelector(".tbw-accordion");o&&o.addEventListener("click",s=>{const a=s.target.closest(".tbw-accordion-header");if(a){const d=a.closest("[data-section]")?.getAttribute("data-section");d&&i.onSectionToggle(d)}})}function Vn(r,e,t){const i=r.querySelector(".tbw-tool-panel"),n=r.querySelector("[data-resize-handle]"),o=r.querySelector(".tbw-shell-body");if(!i||!n||!o)return()=>{};const s=e?.toolPanel?.position??"right",l=200;let a=0,c=0,d=0,u=!1;const h=g=>{if(!u)return;g.preventDefault();const w=s==="left"?g.clientX-a:a-g.clientX,b=Math.min(d,Math.max(l,c+w));i.style.width=`${b}px`},f=()=>{if(!u)return;u=!1,n.classList.remove("resizing"),i.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const g=i.getBoundingClientRect().width;t(g),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",f)},p=g=>{g.preventDefault(),u=!0,a=g.clientX,c=i.getBoundingClientRect().width,d=o.getBoundingClientRect().width-20,n.classList.add("resizing"),i.style.transition="none",document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",h),document.addEventListener("mouseup",f)};return n.addEventListener("mousedown",p),()=>{n.removeEventListener("mousedown",p),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",f)}}function Be(r,e,t){const i=e?.header?.toolbarContents??[],n=[...t.toolbarContents.values()],o=new Set(i.map(l=>l.id)),s=[...i];for(const l of n)o.has(l.id)||s.push(l);for(const l of s){if(t.toolbarContentCleanups.has(l.id)||!l.render)continue;const a=r.querySelector(`[data-toolbar-content="${l.id}"]`);if(!a)continue;const c=l.render(a);c&&t.toolbarContentCleanups.set(l.id,c)}}function Ke(r,e){const t=e.lightDomHeaderContent.length>0&&!e.lightDomContentMoved,i=e.headerContents.size>0;if(!t&&!i)return;const n=r.querySelector(".tbw-shell-content");if(!n)return;if(t){for(const s of e.lightDomHeaderContent)s.style.display="",n.appendChild(s);e.lightDomContentMoved=!0}const o=[...e.headerContents.values()].sort((s,l)=>(s.order??100)-(l.order??100));for(const s of o){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 Un(r,e,t){if(!e.isPanelOpen)return;const i=Y(t?.expand??G.expand),n=Y(t?.collapse??G.collapse);for(const[o,s]of e.toolPanels){const l=e.expandedSections.has(o),a=r.querySelector(`[data-section="${o}"]`),c=a?.querySelector(".tbw-accordion-content");if(!a||!c)continue;a.classList.toggle("expanded",l);const d=a.querySelector(".tbw-accordion-header");d&&d.setAttribute("aria-expanded",String(l));const u=a.querySelector(".tbw-accordion-chevron");if(u&&(u.innerHTML=l?n:i),l){if(c.children.length===0){const h=s.render(c);h&&e.panelCleanups.set(o,h)}}else{const h=e.panelCleanups.get(o);h&&(h(),e.panelCleanups.delete(o)),c.innerHTML=""}}}function Vt(r,e){const t=r.querySelector("[data-panel-toggle]");t&&(t.classList.toggle("active",e.isPanelOpen),t.setAttribute("aria-pressed",String(e.isPanelOpen)))}function Ut(r,e){const t=r.querySelector(".tbw-tool-panel");t&&(t.classList.toggle("open",e.isPanelOpen),e.isPanelOpen||(t.style.width=""))}function $e(r){for(const e of r.toolbarContentCleanups.values())e();r.toolbarContentCleanups.clear()}function jn(r){for(const e of r.headerContentCleanups.values())e();r.headerContentCleanups.clear();for(const e of r.panelCleanups.values())e();r.panelCleanups.clear();for(const e of r.toolbarContentCleanups.values())e();r.toolbarContentCleanups.clear();for(const e of r.toolbarContents.values())e.onDestroy?.();if(r.isPanelOpen)for(const e of r.expandedSections)r.toolPanels.get(e)?.onClose?.();r.isPanelOpen=!1,r.expandedSections.clear(),r.toolPanels.clear(),r.headerContents.clear(),r.toolbarContents.clear(),r.lightDomHeaderContent=[],r.lightDomToolPanelIds.clear(),r.lightDomToolbarContentIds.clear(),r.lightDomContentMoved=!1}function Yn(r,e){let t=!1;const i={get isInitialized(){return t},setInitialized(n){t=n},get isPanelOpen(){return r.isPanelOpen},get activePanel(){return r.isPanelOpen&&r.expandedSections.size>0?[...r.expandedSections][0]:null},get expandedSections(){return[...r.expandedSections]},openToolPanel(){if(r.isPanelOpen)return;if(r.toolPanels.size===0){console.warn("[tbw-grid] No tool panels registered");return}if(r.isPanelOpen=!0,r.expandedSections.size===0&&r.toolPanels.size>0){const s=[...r.toolPanels.values()].sort((l,a)=>(l.order??100)-(a.order??100))[0];s&&r.expandedSections.add(s.id)}const n=e.getShadow();Vt(n,r),Ut(n,r),Un(n,r,e.getAccordionIcons()),e.emit("tool-panel-open",{sections:i.expandedSections})},closeToolPanel(){if(!r.isPanelOpen)return;for(const o of r.panelCleanups.values())o();r.panelCleanups.clear();for(const o of r.toolPanels.values())o.onClose?.();r.isPanelOpen=!1;const n=e.getShadow();Vt(n,r),Ut(n,r),e.emit("tool-panel-close",{})},toggleToolPanel(){r.isPanelOpen?i.closeToolPanel():i.openToolPanel()},toggleToolPanelSection(n){const o=r.toolPanels.get(n);if(!o){console.warn(`[tbw-grid] Tool panel section "${n}" not found`);return}if(r.toolPanels.size===1)return;const s=e.getShadow(),l=r.expandedSections.has(n);if(l){const a=r.panelCleanups.get(n);a&&(a(),r.panelCleanups.delete(n)),o.onClose?.(),r.expandedSections.delete(n),We(s,n,!1)}else{for(const[a,c]of r.toolPanels)if(a!==n&&r.expandedSections.has(a)){const d=r.panelCleanups.get(a);d&&(d(),r.panelCleanups.delete(a)),c.onClose?.(),r.expandedSections.delete(a),We(s,a,!1);const u=s.querySelector(`[data-section="${a}"] .tbw-accordion-content`);u&&(u.innerHTML="")}r.expandedSections.add(n),We(s,n,!0),Xn(s,r,n)}e.emit("tool-panel-section-toggle",{id:n,expanded:!l})},getToolPanels(){return[...r.toolPanels.values()]},registerToolPanel(n){if(r.toolPanels.has(n.id)){console.warn(`[tbw-grid] Tool panel "${n.id}" already registered`);return}r.toolPanels.set(n.id,n),t&&e.refreshShellHeader()},unregisterToolPanel(n){if(r.expandedSections.has(n)){const o=r.panelCleanups.get(n);o&&(o(),r.panelCleanups.delete(n)),r.expandedSections.delete(n)}r.toolPanels.delete(n),t&&e.refreshShellHeader()},getHeaderContents(){return[...r.headerContents.values()]},registerHeaderContent(n){if(r.headerContents.has(n.id)){console.warn(`[tbw-grid] Header content "${n.id}" already registered`);return}r.headerContents.set(n.id,n),t&&Ke(e.getShadow(),r)},unregisterHeaderContent(n){const o=r.headerContentCleanups.get(n);o&&(o(),r.headerContentCleanups.delete(n)),r.headerContents.get(n)?.onDestroy?.(),r.headerContents.delete(n),e.getShadow().querySelector(`[data-header-content="${n}"]`)?.remove()},getToolbarContents(){return[...r.toolbarContents.values()].sort((n,o)=>(n.order??0)-(o.order??0))},registerToolbarContent(n){if(r.toolbarContents.has(n.id)){console.warn(`[tbw-grid] Toolbar content "${n.id}" already registered`);return}r.toolbarContents.set(n.id,n),t&&e.refreshShellHeader()},unregisterToolbarContent(n){const o=r.toolbarContentCleanups.get(n);o&&(o(),r.toolbarContentCleanups.delete(n));const s=r.toolbarContents.get(n);s?.onDestroy&&s.onDestroy(),r.toolbarContents.delete(n),t&&e.refreshShellHeader()}};return i}function We(r,e,t){const i=r.querySelector(`[data-section="${e}"]`);i&&i.classList.toggle("expanded",t)}function Xn(r,e,t){const i=e.toolPanels.get(t);if(!i?.render)return;const n=r.querySelector(`[data-section="${t}"] .tbw-accordion-content`);if(!n)return;const o=i.render(n);o&&e.panelCleanups.set(t,o)}function Zn(r,e,t,i){const n=Bt(e),o=[],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)r.querySelectorAll(`:scope > ${l}`).forEach(c=>o.push(c));r.replaceChildren();for(const l of o)r.appendChild(l);if(n){const l=Y(i?.toolPanel??G.toolPanel),a=Y(i?.expand??G.expand),c=Y(i?.collapse??G.collapse),u=[...e?.header?.toolbarContents??[]].sort((v,x)=>(v.order??0)-(x.order??0)),f=[...e?.toolPanels??[]].sort((v,x)=>(v.order??100)-(x.order??100)),p={title:e?.header?.title??void 0,hasPanels:f.length>0,isPanelOpen:t.isPanelOpen,toolPanelIcon:l,configButtons:u.map(v=>({id:v.id,hasElement:!1,hasRender:!!v.render})),apiButtons:[]},g={position:e?.toolPanel?.position??"right",isPanelOpen:t.isPanelOpen,expandIcon:a,collapseIcon:c,panels:f.map(v=>({id:v.id,title:v.title,icon:Y(v.icon),isExpanded:t.expandedSections.has(v.id)}))},w=Gn(p),b=Bn(g),m=Gt({hasShell:!0,shellHeader:w,shellBody:b});r.appendChild(m)}else{const l=Gt({hasShell:!1});r.appendChild(l)}return n}const jt="tbw-grid-styles";let ke="";const Ve=new Map;function Qn(){let r=document.getElementById(jt);return r||(r=document.createElement("style"),r.id=jt,r.setAttribute("data-tbw-grid","true"),document.head.appendChild(r)),r}function Ue(){const r=Qn(),e=Array.from(Ve.values()).join(`
|
|
27
|
+
`}function Kt(r,e){const t=r.querySelector("tbw-grid-header");if(!t)return;if(!e.lightDomTitle){const n=t.getAttribute("title");n&&(e.lightDomTitle=n)}const i=t.querySelectorAll("tbw-grid-header-content");i.length>0&&e.lightDomHeaderContent.length===0&&(e.lightDomHeaderContent=Array.from(i)),t.style.display="none"}function Wt(r,e,t){const i=r.querySelector(":scope > tbw-grid-tool-buttons");if(!i)return;e.hasToolButtonsContainer=!0;const n="light-dom-toolbar-content";if(e.lightDomToolbarContentIds.has(n))return;const o={id:n,order:0,render:(s=>{for(;i.firstChild;)s.appendChild(i.firstChild);return()=>{for(;s.firstChild;)i.appendChild(s.firstChild)}})};e.toolbarContents.set(n,o),e.lightDomToolbarContentIds.add(n),i.style.display="none"}function Vt(r,e,t){r.querySelectorAll(":scope > tbw-grid-tool-panel").forEach(n=>{const o=n,s=o.getAttribute("id"),l=o.getAttribute("title");if(!s||!l){console.warn(`[parseLightDomToolPanels] Tool panel missing required id or title attribute: id="${s??""}", title="${l??""}"`);return}const a=o.getAttribute("icon")??void 0,c=o.getAttribute("tooltip")??void 0,d=parseInt(o.getAttribute("order")??"100",10);let u;const h=t?.(o);if(h)u=h;else{const g=o.innerHTML.trim();u=w=>{const y=document.createElement("div");return y.innerHTML=g,w.appendChild(y),()=>y.remove()}}const f=e.toolPanels.get(s);if(f){if(h){f.render=u,f.order=d,f.icon=a,f.tooltip=c;const g=e.panelCleanups.get(s);g&&(g(),e.panelCleanups.delete(s))}return}const p={id:s,title:l,icon:a,tooltip:c,order:d,render:u};e.toolPanels.set(s,p),e.lightDomToolPanelIds.add(s),o.style.display="none"})}function Un(r,e,t,i){const n=r.querySelector(".tbw-shell-toolbar");n&&n.addEventListener("click",s=>{if(s.target.closest("[data-panel-toggle]")){i.onPanelToggle();return}});const o=r.querySelector(".tbw-accordion");o&&o.addEventListener("click",s=>{const a=s.target.closest(".tbw-accordion-header");if(a){const d=a.closest("[data-section]")?.getAttribute("data-section");d&&i.onSectionToggle(d)}})}function jn(r,e,t){const i=r.querySelector(".tbw-tool-panel"),n=r.querySelector("[data-resize-handle]"),o=r.querySelector(".tbw-shell-body");if(!i||!n||!o)return()=>{};const s=e?.toolPanel?.position??"right",l=200;let a=0,c=0,d=0,u=!1;const h=g=>{if(!u)return;g.preventDefault();const w=s==="left"?g.clientX-a:a-g.clientX,y=Math.min(d,Math.max(l,c+w));i.style.width=`${y}px`},f=()=>{if(!u)return;u=!1,n.classList.remove("resizing"),i.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const g=i.getBoundingClientRect().width;t(g),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",f)},p=g=>{g.preventDefault(),u=!0,a=g.clientX,c=i.getBoundingClientRect().width,d=o.getBoundingClientRect().width-20,n.classList.add("resizing"),i.style.transition="none",document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",h),document.addEventListener("mouseup",f)};return n.addEventListener("mousedown",p),()=>{n.removeEventListener("mousedown",p),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",f)}}function Be(r,e,t){const i=e?.header?.toolbarContents??[],n=[...t.toolbarContents.values()],o=new Set(i.map(l=>l.id)),s=[...i];for(const l of n)o.has(l.id)||s.push(l);for(const l of s){if(t.toolbarContentCleanups.has(l.id)||!l.render)continue;const a=r.querySelector(`[data-toolbar-content="${l.id}"]`);if(!a)continue;const c=l.render(a);c&&t.toolbarContentCleanups.set(l.id,c)}}function Ke(r,e){const t=e.lightDomHeaderContent.length>0&&!e.lightDomContentMoved,i=e.headerContents.size>0;if(!t&&!i)return;const n=r.querySelector(".tbw-shell-content");if(!n)return;if(t){for(const s of e.lightDomHeaderContent)s.style.display="",n.appendChild(s);e.lightDomContentMoved=!0}const o=[...e.headerContents.values()].sort((s,l)=>(s.order??100)-(l.order??100));for(const s of o){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 Yn(r,e,t){if(!e.isPanelOpen)return;const i=Y(t?.expand??G.expand),n=Y(t?.collapse??G.collapse);for(const[o,s]of e.toolPanels){const l=e.expandedSections.has(o),a=r.querySelector(`[data-section="${o}"]`),c=a?.querySelector(".tbw-accordion-content");if(!a||!c)continue;a.classList.toggle("expanded",l);const d=a.querySelector(".tbw-accordion-header");d&&d.setAttribute("aria-expanded",String(l));const u=a.querySelector(".tbw-accordion-chevron");if(u&&(u.innerHTML=l?n:i),l){if(c.children.length===0){const h=s.render(c);h&&e.panelCleanups.set(o,h)}}else{const h=e.panelCleanups.get(o);h&&(h(),e.panelCleanups.delete(o)),c.innerHTML=""}}}function Ut(r,e){const t=r.querySelector("[data-panel-toggle]");t&&(t.classList.toggle("active",e.isPanelOpen),t.setAttribute("aria-pressed",String(e.isPanelOpen)))}function jt(r,e){const t=r.querySelector(".tbw-tool-panel");t&&(t.classList.toggle("open",e.isPanelOpen),e.isPanelOpen||(t.style.width=""))}function We(r){for(const e of r.toolbarContentCleanups.values())e();r.toolbarContentCleanups.clear()}function Xn(r){for(const e of r.headerContentCleanups.values())e();r.headerContentCleanups.clear();for(const e of r.panelCleanups.values())e();r.panelCleanups.clear();for(const e of r.toolbarContentCleanups.values())e();r.toolbarContentCleanups.clear();for(const e of r.toolbarContents.values())e.onDestroy?.();if(r.isPanelOpen)for(const e of r.expandedSections)r.toolPanels.get(e)?.onClose?.();r.isPanelOpen=!1,r.expandedSections.clear(),r.toolPanels.clear(),r.headerContents.clear(),r.toolbarContents.clear(),r.lightDomHeaderContent=[],r.lightDomToolPanelIds.clear(),r.lightDomToolbarContentIds.clear(),r.lightDomContentMoved=!1}function Zn(r,e){let t=!1;const i={get isInitialized(){return t},setInitialized(n){t=n},get isPanelOpen(){return r.isPanelOpen},get activePanel(){return r.isPanelOpen&&r.expandedSections.size>0?[...r.expandedSections][0]:null},get expandedSections(){return[...r.expandedSections]},openToolPanel(){if(r.isPanelOpen)return;if(r.toolPanels.size===0){console.warn("[tbw-grid] No tool panels registered");return}if(r.isPanelOpen=!0,r.expandedSections.size===0&&r.toolPanels.size>0){const s=[...r.toolPanels.values()].sort((l,a)=>(l.order??100)-(a.order??100))[0];s&&r.expandedSections.add(s.id)}const n=e.getShadow();Ut(n,r),jt(n,r),Yn(n,r,e.getAccordionIcons()),e.emit("tool-panel-open",{sections:i.expandedSections})},closeToolPanel(){if(!r.isPanelOpen)return;for(const o of r.panelCleanups.values())o();r.panelCleanups.clear();for(const o of r.toolPanels.values())o.onClose?.();r.isPanelOpen=!1;const n=e.getShadow();Ut(n,r),jt(n,r),e.emit("tool-panel-close",{})},toggleToolPanel(){r.isPanelOpen?i.closeToolPanel():i.openToolPanel()},toggleToolPanelSection(n){const o=r.toolPanels.get(n);if(!o){console.warn(`[tbw-grid] Tool panel section "${n}" not found`);return}if(r.toolPanels.size===1)return;const s=e.getShadow(),l=r.expandedSections.has(n);if(l){const a=r.panelCleanups.get(n);a&&(a(),r.panelCleanups.delete(n)),o.onClose?.(),r.expandedSections.delete(n),Ve(s,n,!1)}else{for(const[a,c]of r.toolPanels)if(a!==n&&r.expandedSections.has(a)){const d=r.panelCleanups.get(a);d&&(d(),r.panelCleanups.delete(a)),c.onClose?.(),r.expandedSections.delete(a),Ve(s,a,!1);const u=s.querySelector(`[data-section="${a}"] .tbw-accordion-content`);u&&(u.innerHTML="")}r.expandedSections.add(n),Ve(s,n,!0),Qn(s,r,n)}e.emit("tool-panel-section-toggle",{id:n,expanded:!l})},getToolPanels(){return[...r.toolPanels.values()]},registerToolPanel(n){if(r.toolPanels.has(n.id)){console.warn(`[tbw-grid] Tool panel "${n.id}" already registered`);return}r.toolPanels.set(n.id,n),t&&e.refreshShellHeader()},unregisterToolPanel(n){if(r.expandedSections.has(n)){const o=r.panelCleanups.get(n);o&&(o(),r.panelCleanups.delete(n)),r.expandedSections.delete(n)}r.toolPanels.delete(n),t&&e.refreshShellHeader()},getHeaderContents(){return[...r.headerContents.values()]},registerHeaderContent(n){if(r.headerContents.has(n.id)){console.warn(`[tbw-grid] Header content "${n.id}" already registered`);return}r.headerContents.set(n.id,n),t&&Ke(e.getShadow(),r)},unregisterHeaderContent(n){const o=r.headerContentCleanups.get(n);o&&(o(),r.headerContentCleanups.delete(n)),r.headerContents.get(n)?.onDestroy?.(),r.headerContents.delete(n),e.getShadow().querySelector(`[data-header-content="${n}"]`)?.remove()},getToolbarContents(){return[...r.toolbarContents.values()].sort((n,o)=>(n.order??0)-(o.order??0))},registerToolbarContent(n){if(r.toolbarContents.has(n.id)){console.warn(`[tbw-grid] Toolbar content "${n.id}" already registered`);return}r.toolbarContents.set(n.id,n),t&&e.refreshShellHeader()},unregisterToolbarContent(n){const o=r.toolbarContentCleanups.get(n);o&&(o(),r.toolbarContentCleanups.delete(n));const s=r.toolbarContents.get(n);s?.onDestroy&&s.onDestroy(),r.toolbarContents.delete(n),t&&e.refreshShellHeader()}};return i}function Ve(r,e,t){const i=r.querySelector(`[data-section="${e}"]`);i&&i.classList.toggle("expanded",t)}function Qn(r,e,t){const i=e.toolPanels.get(t);if(!i?.render)return;const n=r.querySelector(`[data-section="${t}"] .tbw-accordion-content`);if(!n)return;const o=i.render(n);o&&e.panelCleanups.set(t,o)}function Jn(r,e,t,i){const n=Bt(e),o=[],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)r.querySelectorAll(`:scope > ${l}`).forEach(c=>o.push(c));r.replaceChildren();for(const l of o)r.appendChild(l);if(n){const l=Y(i?.toolPanel??G.toolPanel),a=Y(i?.expand??G.expand),c=Y(i?.collapse??G.collapse),u=[...e?.header?.toolbarContents??[]].sort((T,P)=>(T.order??0)-(P.order??0)),f=[...e?.toolPanels??[]].sort((T,P)=>(T.order??100)-(P.order??100)),p={title:e?.header?.title??void 0,hasPanels:f.length>0,isPanelOpen:t.isPanelOpen,toolPanelIcon:l,configButtons:u.map(T=>({id:T.id,hasElement:!1,hasRender:!!T.render})),apiButtons:[]},g={position:e?.toolPanel?.position??"right",isPanelOpen:t.isPanelOpen,expandIcon:a,collapseIcon:c,panels:f.map(T=>({id:T.id,title:T.title,icon:Y(T.icon),isExpanded:t.expandedSections.has(T.id)}))},w=Bn(p),y=Kn(g),v=$t({hasShell:!0,shellHeader:w,shellBody:y});r.appendChild(v)}else{const l=$t({hasShell:!1});r.appendChild(l)}return n}const Yt="tbw-grid-styles";let ke="";const Ue=new Map;function er(){let r=document.getElementById(Yt);return r||(r=document.createElement("style"),r.id=Yt,r.setAttribute("data-tbw-grid","true"),document.head.appendChild(r)),r}function je(){const r=er(),e=Array.from(Ue.values()).join(`
|
|
28
28
|
`);r.textContent=`${ke}
|
|
29
29
|
|
|
30
30
|
/* Plugin Styles */
|
|
31
|
-
${e}`}function
|
|
32
|
-
`);if(t.includes(".tbw-grid-root")&&t.includes("tbw-grid"))return t}catch{continue}}catch(r){console.warn("[tbw-grid] Failed to extract grid.css from document stylesheets:",r)}return null}async function
|
|
31
|
+
${e}`}function tr(r){let e=!1;for(const{name:t,styles:i}of r)Ue.has(t)||(Ue.set(t,i),e=!0);return e&&je(),e}function ir(){try{for(const r of Array.from(document.styleSheets))try{const t=Array.from(r.cssRules||[]).map(i=>i.cssText).join(`
|
|
32
|
+
`);if(t.includes(".tbw-grid-root")&&t.includes("tbw-grid"))return t}catch{continue}}catch(r){console.warn("[tbw-grid] Failed to extract grid.css from document stylesheets:",r)}return null}async function nr(r){if(ke)return;if(typeof r=="string"&&r.length>0){ke=r,je();return}await new Promise(t=>setTimeout(t,50));const e=ir();e?(ke=e,je()):(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(t=>t.href||"(inline)"))}function rr(){return{startY:null,startX:null,scrollTop:null,scrollLeft:null,lastY:null,lastX:null,lastTime:null,velocityY:0,velocityX:0,momentumRaf:0}}function or(r){r.startY=null,r.startX=null,r.scrollTop=null,r.scrollLeft=null,r.lastY=null,r.lastX=null,r.lastTime=null}function Xt(r){r.momentumRaf&&(cancelAnimationFrame(r.momentumRaf),r.momentumRaf=0)}function sr(r,e,t){if(r.touches.length!==1)return;Xt(e);const i=r.touches[0];e.startY=i.clientY,e.startX=i.clientX,e.lastY=i.clientY,e.lastX=i.clientX,e.lastTime=performance.now(),e.scrollTop=t.fauxScrollbar.scrollTop,e.scrollLeft=t.scrollArea?.scrollLeft??0,e.velocityY=0,e.velocityX=0}function lr(r,e,t){if(r.touches.length!==1||e.startY===null||e.startX===null||e.scrollTop===null||e.scrollLeft===null)return!1;const i=r.touches[0],n=i.clientY,o=i.clientX,s=performance.now(),l=e.startY-n,a=e.startX-o;if(e.lastTime!==null&&e.lastY!==null&&e.lastX!==null){const g=s-e.lastTime;g>0&&(e.velocityY=(e.lastY-n)/g,e.velocityX=(e.lastX-o)/g)}e.lastY=n,e.lastX=o,e.lastTime=s;const{scrollTop:c,scrollHeight:d,clientHeight:u}=t.fauxScrollbar,h=d-u,f=l>0&&c<h||l<0&&c>0;let p=!1;if(t.scrollArea){const{scrollLeft:g,scrollWidth:w,clientWidth:y}=t.scrollArea,v=w-y;p=a>0&&g<v||a<0&&g>0}return f&&(t.fauxScrollbar.scrollTop=e.scrollTop+l),p&&t.scrollArea&&(t.scrollArea.scrollLeft=e.scrollLeft+a),f||p}function ar(r,e){(Math.abs(r.velocityY)>.1||Math.abs(r.velocityX)>.1)&&cr(r,e),or(r)}function cr(r,e){const n=()=>{r.velocityY*=.95,r.velocityX*=.95;const o=r.velocityY*16,s=r.velocityX*16;Math.abs(r.velocityY)>.01&&(e.fauxScrollbar.scrollTop+=o),Math.abs(r.velocityX)>.01&&e.scrollArea&&(e.scrollArea.scrollLeft+=s),Math.abs(r.velocityY)>.01||Math.abs(r.velocityX)>.01?r.momentumRaf=requestAnimationFrame(n):r.momentumRaf=0};r.momentumRaf=requestAnimationFrame(n)}function dr(r,e,t,i){r.addEventListener("touchstart",n=>sr(n,e,t),{passive:!0,signal:i}),r.addEventListener("touchmove",n=>{lr(n,e,t)&&n.preventDefault()},{passive:!1,signal:i}),r.addEventListener("touchend",()=>ar(e,t),{passive:!0,signal:i})}const ur=[{property:"editable",pluginName:"editing",level:"column",description:'the "editable" column property',isUsed:r=>r===!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:"sticky",pluginName:"pinnedColumns",level:"column",description:'the "sticky" column property',isUsed:r=>r==="left"||r==="right"||r==="start"||r==="end"}],hr=[{property:"columnGroups",pluginName:"groupingColumns",level:"config",description:'the "columnGroups" config property',isUsed:r=>Array.isArray(r)&&r.length>0}];function fr(r){return r.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function Ye(r){return`import { ${q(r)}Plugin } from '@toolbox-web/grid/plugins/${fr(r)}';`}function q(r){return r.charAt(0).toUpperCase()+r.slice(1)}function Zt(r,e){return r.some(t=>t.name===e)}function gr(r,e){const t=ur,i=hr,n=new Map;function o(l,a,c,d,u=!1){n.has(l)||n.set(l,{description:a,importHint:c,fields:[],isConfigProperty:u});const h=n.get(l);h.fields.includes(d)||h.fields.push(d)}for(const l of i){const a=r[l.property];(l.isUsed?l.isUsed(a):a!==void 0)&&!Zt(e,l.pluginName)&&o(l.pluginName,l.description,Ye(l.pluginName),l.property,!0)}const s=r.columns;if(s&&s.length>0)for(const l of s)for(const a of t){const c=l[a.property];if((a.isUsed?a.isUsed(c):c!==void 0)&&!Zt(e,a.pluginName)){const u=l.field||"<unknown>";o(a.pluginName,a.description,Ye(a.pluginName),u)}}if(n.size>0){const l=[];for(const[a,{description:c,importHint:d,fields:u,isConfigProperty:h}]of n)if(h)l.push(`Config uses ${c}, but the required plugin is not loaded.
|
|
33
33
|
→ Add the plugin to your gridConfig.plugins array:
|
|
34
34
|
${d}
|
|
35
35
|
plugins: [new ${q(a)}Plugin(), ...]`);else{const f=u.slice(0,3).join(", ")+(u.length>3?`, ... (${u.length} total)`:"");l.push(`Column(s) [${f}] use ${c}, but the required plugin is not loaded.
|
|
@@ -41,25 +41,25 @@ ${l.join(`
|
|
|
41
41
|
|
|
42
42
|
`)}
|
|
43
43
|
|
|
44
|
-
This validation helps catch misconfigurations early. The properties listed above require their respective plugins to function.`)}}function
|
|
44
|
+
This validation helps catch misconfigurations early. The properties listed above require their respective plugins to function.`)}}function pr(r){const e=[],t=[];for(const i of r){const o=i.constructor.manifest;if(o?.configRules)for(const s of o.configRules){const l=i.config;if(s.check(l)){const c=`${`[tbw-grid:${q(i.name)}Plugin]`} Configuration warning: ${s.message}`;s.severity==="error"?e.push(c):t.push(c)}}}if(t.length>0&&ze())for(const i of t)console.warn(i);if(e.length>0)throw new Error(`[tbw-grid] Configuration error:
|
|
45
45
|
|
|
46
46
|
${e.join(`
|
|
47
47
|
|
|
48
|
-
`)}`)}function
|
|
48
|
+
`)}`)}function wr(r,e){const t=r.name,n=r.constructor.dependencies??[];for(const o of n){const s=o.name,l=o.required??!0,a=o.reason;if(!e.some(d=>d.name===s)){const d=a??`${q(t)}Plugin requires ${q(s)}Plugin`,u=Ye(s);if(l)throw new Error(`[tbw-grid] Plugin dependency error:
|
|
49
49
|
|
|
50
50
|
${d}.
|
|
51
51
|
|
|
52
52
|
→ Add the plugin to your gridConfig.plugins array BEFORE ${q(t)}Plugin:
|
|
53
53
|
${u}
|
|
54
|
-
plugins: [new ${q(s)}Plugin(), new ${q(t)}Plugin()]`);console.info(`[tbw-grid] ${q(t)}Plugin: Optional "${s}" plugin not found. Some features may be unavailable.`)}}}function
|
|
54
|
+
plugins: [new ${q(s)}Plugin(), new ${q(t)}Plugin()]`);console.info(`[tbw-grid] ${q(t)}Plugin: Optional "${s}" plugin not found. Some features may be unavailable.`)}}}function br(r){if(!ze())return;const e=new Set(r.map(i=>i.name)),t=new Set;for(const i of r){const o=i.constructor.manifest;if(o?.incompatibleWith){for(const s of o.incompatibleWith)if(e.has(s.name)){const l=[i.name,s.name].sort().join("↔");if(t.has(l))continue;t.add(l),console.warn(`[tbw-grid] Plugin incompatibility warning:
|
|
55
55
|
|
|
56
56
|
${q(i.name)}Plugin and ${q(s.name)}Plugin are both loaded, but they are currently incompatible.
|
|
57
57
|
|
|
58
58
|
→ ${s.reason}
|
|
59
59
|
|
|
60
|
-
Consider removing one of these plugins to avoid unexpected behavior.`)}}}}function
|
|
60
|
+
Consider removing one of these plugins to avoid unexpected behavior.`)}}}}function Qt(r,e){return!r||typeof r!="object"?r:"__rowCacheKey"in r?r.__rowCacheKey:"rowId"in r&&r.rowId!=null?`id:${r.rowId}`:e?`id:${e(r)}`:r}function mr(r,e,t){const i=Qt(e,t);if(typeof i=="string")return r.byKey.get(i);if(i&&typeof i=="object")return r.byRef.get(i)}function vr(r,e,t,i){const n=Qt(e,i);typeof n=="string"?r.byKey.set(n,t):n&&typeof n=="object"&&r.byRef.set(n,t)}function yr(r,e,t,i,n){const o=new Array(r.length);let s=0;for(let l=0;l<r.length;l++){const a=r[l];let c=n?.(a,l),d=c!==void 0;c===void 0&&(c=mr(e,a,i.rowId),d=c!==void 0),c===void 0&&(c=t,d=!1),o[l]={offset:s,height:c,measured:d},s+=c}return o}function Xe(r,e,t){if(e<0||e>=r.length)return;const i=r[e],n=t-i.height;if(n!==0){i.height=t,i.measured=!0;for(let o=e+1;o<r.length;o++)r[o].offset+=n}}function Cr(r){if(r.length===0)return 0;const e=r[r.length-1];return e.offset+e.height}function Jt(r,e){if(r.length===0)return-1;if(e<=0)return 0;let t=0,i=r.length-1;for(;t<=i;){const n=Math.floor((t+i)/2),o=r[n],s=o.offset+o.height;if(e<o.offset)i=n-1;else if(e>=s)t=n+1;else return n}return Math.max(0,Math.min(t,r.length-1))}function xr(r,e){let t=0,i=0;for(const n of r)n.measured&&(t+=n.height,i++);return i>0?t/i:e}function Er(r){let e=0;for(const t of r)t.measured&&e++;return e}function Rr(r,e){const{positionCache:t,heightCache:i,rows:n,start:o,end:s,getPluginHeight:l,getRowId:a}=r;let c=!1;e.forEach(h=>{const f=h.dataset.rowIndex;if(!f)return;const p=parseInt(f,10);if(p<o||p>=s||p>=n.length)return;const g=n[p],w=l?.(g,p);if(w!==void 0){const v=t[p];(!v.measured||Math.abs(v.height-w)>1)&&(Xe(t,p,w),c=!0);return}const y=h.offsetHeight;if(y>0){const v=t[p];(!v.measured||Math.abs(v.height-y)>1)&&(Xe(t,p,y),vr(i,g,y,a),c=!0)}});const d=c?Er(t):0,u=c?xr(t,r.defaultHeight):0;return{hasChanges:c,measuredCount:d,averageHeight:u}}function Sr(r,e,t,i){let n=0,o=0;for(let s=0;s<r.length;s++){const l=r[s];l.measured&&i?.(e[s],s)===void 0&&(o+=l.height,n++)}return{measuredCount:n,averageHeight:n>0?o/n:t}}function _r(r){const{totalRows:e,viewportHeight:t,scrollTop:i,rowHeight:n,overscan:o}=r,s=Math.ceil(t/n);let l=Math.floor(i/n)-o;l<0&&(l=0);let a=l+s+o*2;return a>e&&(a=e),a===e&&l>0&&(l=Math.max(0,a-s-o*2)),{start:l,end:a,offsetY:l*n,totalHeight:e*n}}function Ar(r,e){return r<=e}class ue{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(wr(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 i=e.constructor.manifest;if(i?.queries)for(const n of i.queries){let o=this.queryHandlers.get(n.type);o||(o=new Set,this.queryHandlers.set(n.type,o)),o.add(e)}}warnDeprecatedHooks(e){const t=e.constructor;if(ue.deprecationWarned.has(t)||!ze())return;const i=typeof e.getExtraHeight=="function"||typeof e.getExtraHeightBefore=="function",n=typeof e.getRowHeight=="function";i&&!n&&(ue.deprecationWarned.add(t),console.warn(`[tbw-grid] Deprecation warning: "${e.name}" uses getExtraHeight() / getExtraHeightBefore() which are deprecated and will be removed in v3.0.
|
|
61
61
|
→ Migrate to getRowHeight(row, index) for better variable row height support.
|
|
62
|
-
→ See: https://toolbox-web.dev/docs/grid/plugins/migration#row-height-hooks`))}unregisterQueryHandlers(e){for(const[t,i]of this.queryHandlers)i.delete(e),i.size===0&&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=>typeof e.afterCellRender=="function")}afterRowRender(e){for(const t of this.plugins)t.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 t of this.plugins)typeof t.getExtraHeight=="function"&&(e+=t.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 t=0;for(const i of this.plugins)typeof i.getExtraHeightBefore=="function"&&(t+=i.getExtraHeightBefore(e));return t}getRowHeight(e,t){for(const i of this.plugins)if(typeof i.getRowHeight=="function"){const n=i.getRowHeight(e,t);if(n!==void 0)return n}}hasRowHeightPlugin(){for(const e of this.plugins)if(typeof e.getRowHeight=="function")return!0;return!1}adjustVirtualStart(e,t,i){let n=e;for(const o of this.plugins)if(typeof o.adjustVirtualStart=="function"){const s=o.adjustVirtualStart(e,t,i);s<n&&(n=s)}return n}renderRow(e,t,i){for(const n of this.plugins)if(n.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 n of i){const o=n.handleQuery?.(e)??n.onPluginQuery?.(e);o!==void 0&&t.push(o)}return t}for(const n of this.plugins){const o=n.handleQuery?.(e)??n.onPluginQuery?.(e);o!==void 0&&t.push(o)}return t}subscribe(e,t,i){let n=this.eventListeners.get(t);n||(n=new Map,this.eventListeners.set(t,n)),n.set(e,i)}unsubscribe(e,t){const i=this.eventListeners.get(t);i&&(i.delete(e),i.size===0&&this.eventListeners.delete(t))}unsubscribeAll(e){for(const[t,i]of this.eventListeners)i.delete(e),i.size===0&&this.eventListeners.delete(t)}emitPluginEvent(e,t){const i=this.eventListeners.get(e);if(i)for(const n of i.values())try{n(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,n=0,o=!1;for(const s of this.plugins){const l=s.getHorizontalScrollOffsets?.(e,t);l&&(i+=l.left,n+=l.right,l.skipScroll&&(o=!0))}return{left:i,right:n,skipScroll:o}}getToolPanels(){const e=[];for(const t of this.plugins){const i=t.getToolPanel?.();i&&e.push({plugin:t,panel:i})}return e.sort((t,i)=>(t.panel.order??0)-(i.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((t,i)=>(t.content.order??0)-(i.content.order??0))}}const
|
|
62
|
+
→ See: https://toolbox-web.dev/docs/grid/plugins/migration#row-height-hooks`))}unregisterQueryHandlers(e){for(const[t,i]of this.queryHandlers)i.delete(e),i.size===0&&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=>typeof e.afterCellRender=="function")}afterRowRender(e){for(const t of this.plugins)t.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 t of this.plugins)typeof t.getExtraHeight=="function"&&(e+=t.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 t=0;for(const i of this.plugins)typeof i.getExtraHeightBefore=="function"&&(t+=i.getExtraHeightBefore(e));return t}getRowHeight(e,t){for(const i of this.plugins)if(typeof i.getRowHeight=="function"){const n=i.getRowHeight(e,t);if(n!==void 0)return n}}hasRowHeightPlugin(){for(const e of this.plugins)if(typeof e.getRowHeight=="function")return!0;return!1}adjustVirtualStart(e,t,i){let n=e;for(const o of this.plugins)if(typeof o.adjustVirtualStart=="function"){const s=o.adjustVirtualStart(e,t,i);s<n&&(n=s)}return n}renderRow(e,t,i){for(const n of this.plugins)if(n.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 n of i){const o=n.handleQuery?.(e)??n.onPluginQuery?.(e);o!==void 0&&t.push(o)}return t}for(const n of this.plugins){const o=n.handleQuery?.(e)??n.onPluginQuery?.(e);o!==void 0&&t.push(o)}return t}subscribe(e,t,i){let n=this.eventListeners.get(t);n||(n=new Map,this.eventListeners.set(t,n)),n.set(e,i)}unsubscribe(e,t){const i=this.eventListeners.get(t);i&&(i.delete(e),i.size===0&&this.eventListeners.delete(t))}unsubscribeAll(e){for(const[t,i]of this.eventListeners)i.delete(e),i.size===0&&this.eventListeners.delete(t)}emitPluginEvent(e,t){const i=this.eventListeners.get(e);if(i)for(const n of i.values())try{n(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,n=0,o=!1;for(const s of this.plugins){const l=s.getHorizontalScrollOffsets?.(e,t);l&&(i+=l.left,n+=l.right,l.skipScroll&&(o=!0))}return{left:i,right:n,skipScroll:o}}getToolPanels(){const e=[];for(const t of this.plugins){const i=t.getToolPanel?.();i&&e.push({plugin:t,panel:i})}return e.sort((t,i)=>(t.panel.order??0)-(i.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((t,i)=>(t.content.order??0)-(i.content.order??0))}}const kr=`/**
|
|
63
63
|
* tbw-grid Light DOM Styles
|
|
64
64
|
*
|
|
65
65
|
* This stylesheet uses CSS nesting to scope all styles to the tbw-grid element.
|
|
@@ -78,7 +78,7 @@ ${q(i.name)}Plugin and ${q(s.name)}Plugin are both loaded, but they are currentl
|
|
|
78
78
|
/* Declare layer order - earlier layers have lower priority */
|
|
79
79
|
@layer tbw-base, tbw-plugins, tbw-theme;
|
|
80
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-
|
|
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
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
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
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}}
|
|
@@ -87,14 +87,14 @@ ${q(i.name)}Plugin and ${q(s.name)}Plugin are both loaded, but they are currentl
|
|
|
87
87
|
@layer tbw-base{.tbw-loading-overlay{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:1000;pointer-events:all;animation:tbw-fade-in .15s ease-out}.tbw-spinner{--tbw-spinner-size: 48px;--tbw-spinner-border-width: 3px;--tbw-spinner-color: var(--tbw-color-accent);--tbw-spinner-track-color: var(--tbw-color-border);width:var(--tbw-spinner-size);height:var(--tbw-spinner-size);border:var(--tbw-spinner-border-width) solid var(--tbw-spinner-track-color);border-top-color:var(--tbw-spinner-color);border-radius:50%;animation:tbw-spin .8s linear infinite}.tbw-spinner--large{--tbw-spinner-size: min(48px, calc(100% - 16px) )}.tbw-spinner--small{--tbw-spinner-size: calc(var(--tbw-row-height, 28px) * .6);--tbw-spinner-border-width: 2px}.data-grid-row.tbw-row-loading{position:relative;pointer-events:none}.data-grid-row.tbw-row-loading:before{content:"";position:absolute;inset:0;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:10;animation:tbw-fade-in .15s ease-out}.data-grid-row.tbw-row-loading:after{--_spinner-size: calc(var(--tbw-row-height, 28px) * .6);content:"";position:absolute;left:var(--tbw-spacing-md);top:0;bottom:0;margin:auto 0;width:var(--_spinner-size);height:var(--_spinner-size);border:2px solid var(--tbw-spinner-track-color, var(--tbw-color-border));border-top-color:var(--tbw-spinner-color, var(--tbw-color-accent));border-radius:50%;animation:tbw-spin .8s linear infinite;z-index:11}.cell.tbw-cell-loading{position:relative;pointer-events:none}.cell.tbw-cell-loading:before{content:"";position:absolute;inset:0;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:10;animation:tbw-fade-in .15s ease-out}.cell.tbw-cell-loading:after{--_spinner-size: calc(var(--tbw-row-height, 28px) * .5);content:"";position:absolute;left:var(--tbw-spacing-sm);top:0;bottom:0;margin:auto 0;width:var(--_spinner-size);height:var(--_spinner-size);border:2px solid var(--tbw-spinner-track-color, var(--tbw-color-border));border-top-color:var(--tbw-spinner-color, var(--tbw-color-accent));border-radius:50%;animation:tbw-spin .8s linear infinite;z-index:11}}
|
|
88
88
|
@layer tbw-base{tbw-grid .tbw-expanding{animation:tbw-expand var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}tbw-grid .tbw-collapsing{animation:tbw-collapse var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}tbw-grid[data-animation-mode=off]{--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms}tbw-grid[data-animation-mode=off] .data-grid-row[data-animating]{animation:none}tbw-grid .data-grid-row[data-animating=change]{animation:tbw-row-change var(--tbw-row-change-duration) ease-out}tbw-grid .data-grid-row[data-animating=insert]{animation:tbw-row-insert var(--tbw-row-insert-duration) ease-out;will-change:max-height,opacity}tbw-grid .data-grid-row[data-animating=remove]{animation:tbw-row-remove var(--tbw-row-remove-duration) ease-out forwards;will-change:max-height,opacity,transform;pointer-events:none}}@keyframes tbw-expand{0%{opacity:0;max-height:0;transform:translateY(-8px)}to{opacity:1;max-height:500px;transform:translateY(0)}}@keyframes tbw-collapse{0%{opacity:1;max-height:500px;transform:translateY(0)}to{opacity:0;max-height:0;transform:translateY(-8px)}}@keyframes tbw-row-change{0%{background-color:transparent}20%{background-color:var(--tbw-row-change-color)}to{background-color:transparent}}@keyframes tbw-row-insert{0%{opacity:0;max-height:0;overflow:hidden}to{opacity:1;max-height:var(--tbw-row-height, 28px);overflow:hidden}}@keyframes tbw-row-remove{0%{opacity:1;transform:translateY(0);max-height:var(--tbw-row-height, 28px)}to{opacity:0;max-height:0;transform:translateY(-8px)}}@keyframes tbw-spin{to{transform:rotate(360deg)}}@keyframes tbw-fade-in{0%{opacity:0}to{opacity:1}}
|
|
89
89
|
@layer tbw-base{@media(forced-colors:active){tbw-grid{--tbw-color-border: CanvasText;--tbw-color-border-strong: CanvasText;--tbw-color-border-cell: CanvasText;--tbw-color-border-header: CanvasText;--tbw-color-fg: CanvasText;--tbw-color-bg: Canvas;--tbw-color-panel-bg: Canvas;--tbw-color-header-bg: Canvas;--tbw-color-header-fg: CanvasText;--tbw-color-accent: Highlight;--tbw-color-accent-fg: HighlightText;--tbw-color-selection: Highlight;--tbw-color-row-hover: Highlight;--tbw-focus-outline: 2px solid Highlight;--tbw-range-border-color: Highlight}tbw-grid .cell:focus,tbw-grid .cell.active-cell{outline:2px solid Highlight!important;outline-offset:-2px}tbw-grid .data-grid-row[aria-selected=true]{background:Highlight!important;color:HighlightText!important}}@media(prefers-reduced-motion:reduce){tbw-grid[data-animation-mode=reduced-motion]{--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms}tbw-grid[data-animation-mode=reduced-motion] .data-grid-row[data-animating]{animation:none}}}
|
|
90
|
-
`;class K extends HTMLElement{static tagName="tbw-grid";static version=typeof __GRID_VERSION__<"u"?__GRID_VERSION__:"dev";static#t=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#e(){return this}#u=!1;#c;#i;#l=[];get#n(){return this.#o?.effective??{}}#f=!1;#h=!1;#w={rows:!1,columns:!1,gridConfig:!1,fitMode:!1};#a;#v=0;#d=null;#g=!1;#R=!1;#p=0;#x;#m=ir();#y;#E;#C;#S;#A={scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0};#r;#_;#O=!1;#M;#W;#z;#o;#s=Kn();#b;#F;#q=!1;#P=new Set;#H=new Map;#G;#k=new Map;_rows=[];#V=[];get _columns(){return this.#n.columns??[]}set _columns(e){this.#n.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.#o?.lightDomColumnsCache}set __lightDomColumnsCache(e){this.#o&&(this.#o.lightDomColumnsCache=e)}get __originalColumnNodes(){return this.#o?.originalColumnNodes}set __originalColumnNodes(e){this.#o&&(this.#o.originalColumnNodes=e)}__originalOrder=[];__frameworkAdapter;__rowsBodyEl=null;get rows(){return this._rows}set rows(e){const t=this.#l;this.#l=e,t!==e&&this.#$("rows")}get sourceRows(){return this.#l}get columns(){return[...this._columns]}set columns(e){const t=this.#o?.getColumns();this.#o?.setColumns(e),t!==e&&this.#$("columns")}get gridConfig(){return this.#n}set gridConfig(e){const t=this.#o?.getGridConfig();this.#o?.setGridConfig(e),t!==e&&(this.#o.clearLightDomCache(),this.#$("gridConfig"))}get fitMode(){return this.#n.fitMode??"stretch"}set fitMode(e){const t=this.#o?.getFitMode();this.#o?.setFitMode(e),t!==e&&this.#$("fitMode")}get loading(){return this.#q}set loading(e){const t=this.#q;this.#q=e,e?this.setAttribute("loading",""):this.removeAttribute("loading"),t!==e&&this.#Pe()}setRowLoading(e,t){const i=this.#P.has(e);t?this.#P.add(e):this.#P.delete(e),i!==t&&this.#de(e,t)}setCellLoading(e,t,i){let n=this.#H.get(e);const o=n?.has(t)??!1;i?(n||(n=new Set,this.#H.set(e,n)),n.add(t)):(n?.delete(t),n?.size===0&&this.#H.delete(e)),o!==i&&this.#ue(e,t,i)}isRowLoading(e){return this.#P.has(e)}isCellLoading(e,t){return this.#H.get(e)?.has(t)??!1}clearAllLoading(){this.loading=!1;for(const e of this.#P)this.#de(e,!1);this.#P.clear();for(const[e,t]of this.#H)for(const i of t)this.#ue(e,i,!1);this.#H.clear()}get effectiveConfig(){return this.#n}get disconnectSignal(){return this.#y||(this.#y=new AbortController),this.#y.signal}constructor(){super(),this.#we(),this.#c=new Promise(e=>this.#i=e),this.#a=new Dn({mergeConfig:()=>{this.#o.parseLightDomColumns(this),this.#o.merge(),this.#ee(),hr(this.#n,this.#r?.getPlugins()??[]),fr(this.#r?.getPlugins()??[]),pr(this.#r?.getPlugins()??[]),this.#Le(),this.#V=[...this._columns]},processColumns:()=>this.#Ae(),processRows:()=>this.#ke(),renderHeader:()=>_e(this),updateTemplate:()=>le(this),renderVirtualWindow:()=>this.refreshVirtualWindow(!0,!0),afterRender:()=>{this.#r?.afterRender(),this._virtualization.enabled&&this._virtualization.totalHeightEl&&queueMicrotask(()=>{if(!this._virtualization.totalHeightEl)return;const t=this.#L(this._rows.length);this._virtualization.totalHeightEl.style.height=`${t}px`}),this.#n.fitMode==="fixed"&&!this.__didInitialAutoSize&&(this.__didInitialAutoSize=!0,vt(this)),this._restoreFocusAfterRender&&(this._restoreFocusAfterRender=!1,M(this)),this._virtualization.enabled&&!this.#K&&this.#ve(),this.#R&&(this.#R=!1,requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.#be()})}))},isConnected:()=>this.isConnected&&this.#f}),this.#a.setInitialReadyResolver(()=>this.#i?.()),this.#b=Yn(this.#s,{getShadow:()=>this.#e,getShellConfig:()=>this.#n?.shell,getAccordionIcons:()=>({expand:this.#n?.icons?.expand??G.expand,collapse:this.#n?.icons?.collapse??G.collapse}),emit:(e,t)=>this.#D(e,t),refreshShellHeader:()=>this.refreshShellHeader()}),this.#o=new dn({getRows:()=>this.#l,getSortState:()=>this._sortState,setSortState:e=>{this._sortState=e},onConfigChange:()=>{this.#a.requestPhase(I.FULL,"configChange")},emit:(e,t)=>this.#D(e,t),clearRowPool:()=>{this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++},setup:()=>this.#I(),renderHeader:()=>_e(this),updateTemplate:()=>le(this),refreshVirtualWindow:()=>this.#a.requestPhase(I.VIRTUALIZATION,"configManager"),getVirtualization:()=>this._virtualization,setRowHeight:e=>{this._virtualization.rowHeight=e},applyAnimationConfig:e=>this.#Te(e),getShellLightDomTitle:()=>this.#s.lightDomTitle,getShellToolPanels:()=>this.#s.toolPanels,getShellHeaderContents:()=>this.#s.headerContents,getShellToolbarContents:()=>this.#s.toolbarContents,getShellLightDomHeaderContent:()=>this.#s.lightDomHeaderContent,getShellHasToolButtonsContainer:()=>this.#s.hasToolButtonsContainer})}async#we(){await tr(_r)}getPlugin(e){return this.#r?.getPlugin(e)}getPluginByName(e){return this.#r?.getPluginByName(e)}requestRender(){this.#a.requestPhase(I.ROWS,"plugin:requestRender")}requestColumnsRender(){this.#a.requestPhase(I.COLUMNS,"plugin:requestColumnsRender")}requestRenderWithFocus(){this._restoreFocusAfterRender=!0,this.#a.requestPhase(I.ROWS,"plugin:requestRenderWithFocus")}updateTemplate(){le(this)}requestAfterRender(){this.#a.requestPhase(I.STYLE,"plugin:requestAfterRender")}#J(){this.#r=new ue(this);const e=this.#n?.plugins,t=Array.isArray(e)?e:[];this.#r.attachAll(t)}#B(){const e=this.#r?.getPluginStyles()??[];Jn(e)}#ee(){const e=this.#n?.plugins,t=Array.isArray(e)?e:[];if(this.#_===t)return;if(this.#_&&this.#_.length===t.length&&this.#_.every((n,o)=>n===t[o])){this.#_=t;return}this.#r&&this.#r.detachAll();for(const n of this.#s.toolPanels.keys()){const o=this.#s.lightDomToolPanelIds.has(n),s=this.#s.apiToolPanelIds.has(n);if(!o&&!s){const l=this.#s.panelCleanups.get(n);l&&(l(),this.#s.panelCleanups.delete(n)),this.#s.toolPanels.delete(n)}}for(const n of this.#s.headerContents.keys()){const o=this.#s.headerContentCleanups.get(n);o&&(o(),this.#s.headerContentCleanups.delete(n)),this.#s.headerContents.delete(n)}this.#J(),this.#B(),this.#_=t,this.#re(),this.#te();const i=this.#g;if(this.#g=this.#r?.getAll().some(n=>n.onScroll)??!1,!i&&this.#g){const o=this.#e.querySelector(".tbw-grid-content")??this.#e.querySelector(".tbw-grid-root");this.#U(o)}}#me(){this.#r?.detachAll()}#te(){if(!this.#r)return;const e=this.#r.getToolPanels();for(const{panel:i}of e)this.#s.toolPanels.has(i.id)||this.#s.toolPanels.set(i.id,i);const t=this.#r.getHeaderContents();for(const{content:i}of t)this.#s.headerContents.has(i.id)||this.#s.headerContents.set(i.id,i)}#ie(){const e=K.getAdapters();if(e.length===0&&!this.__frameworkAdapter)return;const t=this.__frameworkAdapter;return i=>{if(t?.createToolPanelRenderer){const n=t.createToolPanelRenderer(i);if(n)return n}for(const n of e)if(n.createToolPanelRenderer){const o=n.createToolPanelRenderer(i);if(o)return o}}}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.hasAttribute("version")||this.setAttribute("version",K.version),this.id||(this.id=`tbw-grid-${++K.#t}`),this._rows=Array.isArray(this.#l)?[...this.#l]:[],this.#y&&(this.#y.abort(),this.#O=!1),this.#y=new AbortController,this.#S&&(zt(this.#S),this.#S=void 0),this.#N(),this.#o.parseLightDomColumns(this),this.#o.merge(),this.#J();const e=this.#n?.plugins;this.#_=Array.isArray(e)?e:[],this.#te(),this.#u||(this.#Q(),this.#B(),this.#u=!0),this.#ne(),this.#S=Sn(()=>{this.#Me()},{timeout:100})}disconnectedCallback(){this.#S&&(zt(this.#S),this.#S=void 0),this.#p&&(clearTimeout(this.#p),this.#p=0),this.#me(),jn(this.#s),this.#b.setInitialized(!1),this.#F?.(),this.#F=void 0,Yt(this.#m),this.#y&&(this.#y.abort(),this.#y=void 0),this.#M?.abort(),this.#M=void 0,this.#O=!1,this._resizeController&&this._resizeController.dispose(),this.#E&&(this.#E.disconnect(),this.#E=void 0),this.#C&&(this.#C.disconnect(),this.#C=void 0,this.#K=!1),ye(this),this.#T.clear(),this.#_=void 0;for(const e of this._rowPool)e.remove();this._rowPool.length=0,this.__rowsBodyEl=null,this.#f=!1}attributeChangedCallback(e,t,i){if(e==="loading"){const n=i!==null&&i!=="false";this.loading!==n&&(this.loading=n);return}if(!(t===i||!i||i==="null"||i==="undefined"))if(e==="rows"||e==="columns"||e==="grid-config")try{const n=JSON.parse(i);e==="rows"?this.rows=n:e==="columns"?this.columns=n:e==="grid-config"&&(this.gridConfig=n)}catch{console.warn(`[tbw-grid] Invalid JSON for '${e}' attribute:`,i)}else e==="fit-mode"&&(this.fitMode=i)}#ne(){const t=this.#e.querySelector(".tbw-grid-content")??this.#e.querySelector(".tbw-grid-root");if(this._headerRowEl=t?.querySelector(".header-row"),this._virtualization.totalHeightEl=t?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=t?.querySelector(".rows-viewport"),this._bodyEl=t?.querySelector(".rows"),this.__rowsBodyEl=t?.querySelector(".rows-body"),this.#b.isInitialized){Ke(this.#e,this.#s),Be(this.#e,this.#n?.shell,this.#s);const n=this.#n?.shell?.toolPanel?.defaultOpen;n&&this.#s.toolPanels.has(n)&&(this.openToolPanel(),this.#s.expandedSections.add(n))}if(this.setAttribute("data-upgraded",""),this.#f=!0,this._resizeController=Nt(this),this.#I(),this.#U(t),this.#O)return;this.#O=!0;const i=this.disconnectSignal;xn(this,this,this.#e,i),this.#re(),queueMicrotask(()=>this.#ye()),this.#a.requestPhase(I.FULL,"afterConnect")}#re(){const e=this.#n.rowHeight,t=this.#r.hasRowHeightPlugin();typeof e=="function"||t?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.#R=!0)):!t&&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.#oe())}#oe(){if(this.#r.hasExtraHeight())return;const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const t=e.querySelectorAll(".cell");let i=0;t.forEach(s=>{const l=s.offsetHeight;l>i&&(i=l)});const n=e.getBoundingClientRect(),o=Math.max(n.height,i);o>0&&Math.abs(o-this._virtualization.rowHeight)>1&&(this._virtualization.rowHeight=o,this.#a.requestPhase(I.VIRTUALIZATION,"measureRowHeight"))}#be(){const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const t=e.querySelectorAll(".cell");let i=0;t.forEach(s=>{const l=s.offsetHeight;l>i&&(i=l)});const n=e.getBoundingClientRect(),o=Math.max(n.height,i);if(o>0&&(Math.abs(o-this._virtualization.rowHeight)>1&&(this._virtualization.rowHeight=o),this.#Z(),this._virtualization.totalHeightEl)){const l=this.#L(this._rows.length);this._virtualization.totalHeightEl.style.height=`${l}px`}}#U(e){this.#M?.abort(),this.#M=new AbortController;const t=this.#M.signal,i=e?.querySelector(".faux-vscroll"),n=e?.querySelector(".rows");if(this._virtualization.container=i??this,this.#g=this.#r?.getAll().some(o=>o.onScroll)??!1,i&&n){i.addEventListener("scroll",()=>{if(!this._virtualization.enabled&&!this.#g)return;const a=i.scrollTop,c=this._virtualization.rowHeight;if(this._rows.length<=this._virtualization.bypassThreshold)n.style.transform=`translateY(${-a}px)`;else{const d=this._virtualization.positionCache;let u,h;if(this._virtualization.variableHeights&&d&&d.length>0){u=Qt(d,a),u===-1&&(u=0);const p=u-u%2;h=d[p]?.offset??p*c}else u=Math.floor(a/c),h=(u-u%2)*c;const f=-(a-h);n.style.transform=`translateY(${f}px)`}this.#d=a,this.#v||(this.#v=requestAnimationFrame(()=>{this.#v=0,this.#d!==null&&(this.#He(this.#d),this.#d=null)}))},{passive:!0,signal:t});const o=this.#e.querySelector(".tbw-scroll-area");this.#W=o,this._virtualization.scrollAreaEl=o,o&&this.#g&&o.addEventListener("scroll",()=>{const a=this.#A;a.scrollTop=i.scrollTop,a.scrollLeft=o.scrollLeft,a.scrollHeight=i.scrollHeight,a.scrollWidth=o.scrollWidth,a.clientHeight=i.clientHeight,a.clientWidth=o.clientWidth,this.#r?.onScroll(a)},{passive:!0,signal:t});const s=this.#e.querySelector(".tbw-grid-content"),l=this.#W;s&&(s.addEventListener("wheel",a=>{const c=a.shiftKey||Math.abs(a.deltaX)>Math.abs(a.deltaY);if(c&&l){const d=a.shiftKey?a.deltaY:a.deltaX,{scrollLeft:u,scrollWidth:h,clientWidth:f}=l;(d>0&&u<h-f||d<0&&u>0)&&(a.preventDefault(),l.scrollLeft+=d)}else if(!c){const{scrollTop:d,scrollHeight:u,clientHeight:h}=i;(a.deltaY>0&&d<u-h||a.deltaY<0&&d>0)&&(a.preventDefault(),i.scrollTop+=a.deltaY)}},{passive:!1,signal:t}),ar(s,this.#m,{fauxScrollbar:i,scrollArea:l},t))}this._bodyEl&&Cn(this,this._bodyEl,t),this.#E?.disconnect(),this._virtualization.viewportEl&&(this.#E=new ResizeObserver(()=>{this.#ze(),this.#a.requestPhase(I.VIRTUALIZATION,"resize-observer")}),this.#E.observe(this._virtualization.viewportEl)),this.#e.addEventListener("focusin",()=>{this.dataset.hasFocus=""},{signal:t}),this.#e.addEventListener("focusout",o=>{const s=o.relatedTarget;(!s||!this.#e.contains(s))&&delete this.dataset.hasFocus},{signal:t})}#K=!1;#ve(){if(this.#K)return;const e=this._bodyEl?.querySelector(".data-grid-row");e&&(this.#K=!0,this.#C?.disconnect(),this.#C=new ResizeObserver(()=>{this.#oe()}),this.#C.observe(e))}addEventListener(e,t,i){super.addEventListener(e,t,i)}removeEventListener(e,t,i){super.removeEventListener(e,t,i)}#D(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}#ye(){this._bodyEl?.querySelectorAll(".data-grid-row")?.forEach((t,i)=>{const n=i===this._focusRow;t.setAttribute("aria-selected",String(n)),t.querySelectorAll(".cell").forEach((o,s)=>{o.setAttribute("aria-selected",String(n&&s===this._focusCol))})})}#$(e){this.#w[e]=!0,!this.#h&&(this.#h=!0,queueMicrotask(()=>this.#Ce()))}#Ce(){if(!this.#h||!this.#f){this.#h=!1;return}const e=this.#w;if(this.#h=!1,this.#w={rows:!1,columns:!1,gridConfig:!1,fitMode:!1},e.gridConfig){this.#Se(),e.rows&&this.#se();return}e.columns&&this.#Ee(),e.rows&&this.#se(),e.fitMode&&this.#Re()}#se(){this._rows=Array.isArray(this.#l)?[...this.#l]:[],this.#j(),this.#a.requestPhase(I.ROWS,"applyRowsUpdate")}#j(){this.#k.clear();const e=this.#n.getRowId;this._rows.forEach((t,i)=>{const n=this.#le(t,e);n!==void 0&&this.#k.set(n,{row:t,index:i})})}#le(e,t){if(t)return t(e);const i=e;if("id"in i&&i.id!=null)return String(i.id);if("_id"in i&&i._id!=null)return String(i._id)}#xe(e,t){const i=this.#le(e,t);if(i===void 0)throw new Error('[tbw-grid] Cannot determine row ID. Configure getRowId in gridConfig or ensure rows have an "id" property.');return i}#Ee(){ye(this),this.#o.merge(),this.#I()}#Re(){this.#o.merge(),this.#n.fitMode==="fixed"?(this.__didInitialAutoSize=!1,vt(this)):(this._columns.forEach(t=>{!t.__userResized&&t.__autoSized&&delete t.width}),le(this))}#Se(){Kt(this,this.#s),$t(this,this.#s);const e=!!this.#e.querySelector(".has-shell"),t=!!this.#e.querySelector(".tbw-tool-panel"),i=this.#e.querySelectorAll(".tbw-accordion-section").length;this.#o.parseLightDomColumns(this),this.#o.merge(),this.#ee(),Wt(this,this.#s,this.#ie()),this.#o.markSourcesChanged(),this.#o.merge();const n=Bt(this.#n?.shell),o=(this.#n?.shell?.toolPanels?.length??0)>0,s=this.#n?.shell?.toolPanels?.length??0;if(e!==n||!t&&o||t&&s!==i){$e(this.#s),this.#Q(),this.#B(),this.#ne(),this.#j();return}e&&this.#_e(),this.#j(),this.#a.requestPhase(I.COLUMNS,"applyGridConfigUpdate")}#_e(){const e=this.#e.querySelector(".tbw-shell-header");if(!e)return;const t=this.#n.shell?.header?.title??this.#s.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()}#Ae(){if(this.#r){const e=this.#V.length>0?this.#V:this._columns,t=e.filter(o=>!o.hidden),i=e.filter(o=>o.hidden),n=this.#r.processColumns([...t]);if(n!==t){const o=new Set(n.map(l=>l.field));!t.some(l=>o.has(l.field))&&n.length>0?this._columns=[...n,...i]:this._columns=[...n,...i]}else this._columns=[...e]}}#ke(){ye(this);const e=Array.isArray(this.#l)?[...this.#l]:[],t=this.#r?.processRows(e)??e;this._rows=t,this._virtualization.variableHeights&&this.#Z()}#Te(e){const t={...pt,...e.animation},i=t.mode??"reduced-motion";let n=1;i===!1||i==="off"?n=0:(i===!0||i==="on")&&(n=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(n)),this.dataset.animationMode=typeof i=="boolean"?i?"on":"off":i}#Y(e,t,i=this.__rowRenderEpoch){this.#x||(this.#x=(n,o,s)=>this.#r?.renderRow(n,o,s)??!1),pn(this,e,t,i,this.#x)}#ae=se();#ce(e,t){Wi(this.#ae,this.__rowsBodyEl,this._bodyEl,e,t)}#Le(){Ui(this.#ae,this.__rowsBodyEl,this.#n,this.#s)}#Pe(){const e=this.querySelector(".tbw-grid-root");e&&(this.#q?(this.#G||(this.#G=kn(this.#n?.loadingRenderer)),Tn(e,this.#G)):Ln(this.#G))}#de(e,t){const i=this.#k.get(e);if(!i)return;const n=this.findRenderedRowElement?.(i.index);n&&Pn(n,t)}#ue(e,t,i){const n=this.#k.get(e);if(!n)return;const o=this.findRenderedRowElement?.(n.index);if(!o)return;const s=this._visibleColumns.findIndex(a=>a.field===t);if(s<0)return;const l=o.children[s];l&&Hn(l,i)}#I(){if(this.isConnected&&!(!this._headerRowEl||!this._bodyEl)){if(this.#o.parseLightDomColumns(this),this.#z){const e=this.#z;this.#z=void 0,this.#o.merge();const t=this.#r?.getAll()??[];this.#o.applyState(e,t)}this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),this.#a.requestPhase(I.FULL,"setup")}}#He(e){let t=0,i=0,n=0,o=0,s=0;if(this.#g){const a=this._virtualization.container,c=this.#W;t=c?.scrollLeft??0,i=a?.scrollHeight??0,n=c?.scrollWidth??0,o=a?.clientHeight??0,s=c?.clientWidth??0}if(this.refreshVirtualWindow(!1)&&this.#r?.onScrollRender(),this._virtualization.variableHeights&&(this.#p&&clearTimeout(this.#p),this.#p=window.setTimeout(()=>{this.#p=0,this.#ge(this._virtualization.start,this._virtualization.end)},100)),this.#g){const a=this.#A;a.scrollTop=e,a.scrollLeft=t,a.scrollHeight=i,a.scrollWidth=n,a.clientHeight=o,a.clientWidth=s,this.#r?.onScroll(a)}}findHeaderRow(){return this.#e.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,n){const o=this._rows[t],s=this._columns[i];if(!o||!s)return!1;const l=s.field,a=o[l],c=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,composed:!0,detail:{rowIndex:t,colIndex:i,field:l,value:a,row:o,cellEl:n,trigger:"pointer",originalEvent:e}});if(this.dispatchEvent(c),c.defaultPrevented)return!0;const d={row:o,rowIndex:t,colIndex:i,field:l,value:a,cellEl:n,originalEvent:e},u=this.#r?.onCellClick(d)??!1;return this.#D("cell-click",d),u}_dispatchRowClick(e,t,i,n){if(!i)return!1;const o={rowIndex:t,row:i,rowEl:n,originalEvent:e},s=this.#r?.onRowClick(o)??!1;return this.#D("row-click",o),s}_dispatchHeaderClick(e,t,i){const n=this._columns[t];if(!n)return!1;const o={colIndex:t,field:n.field,column:n,headerEl:i,originalEvent:e};return this.#r?.onHeaderClick(o)??!1}_dispatchKeyDown(e){return this.#r?.onKeyDown(e)??!1}_getHorizontalScrollOffsets(e,t){return this.#r?.getHorizontalScrollOffsets(e,t)??{left:0,right:0}}queryPlugins(e){return this.#r?.queryPlugins(e)??[]}query(e,t){return this.#r?.queryPlugins({type:e,context:t})??[]}_dispatchCellMouseDown(e){return this.#r?.onCellMouseDown(e)??!1}_dispatchCellMouseMove(e){this.#r?.onCellMouseMove(e)}_dispatchCellMouseUp(e){this.#r?.onCellMouseUp(e)}_afterCellRender(e){this.#r?.afterCellRender(e)}_hasAfterCellRenderHook(){return this.#r?.hasAfterCellRenderHook()??!1}_afterRowRender(e){this.#r?.afterRowRender(e)}_hasAfterRowRenderHook(){return this.#r?.hasAfterRowRenderHook()??!1}async ready(){return this.#c}async forceLayout(){return this.#a.requestPhase(I.FULL,"forceLayout"),this.#a.whenReady()}async getConfig(){return Object.freeze({...this.#n||{}})}getRowId(e){return this.#xe(e,this.#n.getRowId)}getRow(e){return this.#k.get(e)?.row}updateRow(e,t,i="api"){const n=this.#k.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:o,index:s}=n,l=[];for(const[a,c]of Object.entries(t)){const d=o[a];d!==c&&(l.push({field:a,oldValue:d,newValue:c}),o[a]=c)}for(const{field:a,oldValue:c,newValue:d}of l)this.#D("cell-change",{row:o,rowId:e,rowIndex:s,field:a,oldValue:c,newValue:d,changes:t,source:i});l.length>0&&this.#a.requestPhase(I.ROWS,"updateRow")}updateRows(e,t="api"){let i=!1;for(const{id:n,changes:o}of e){const s=this.#k.get(n);if(!s)throw new Error(`[tbw-grid] Row with ID "${n}" not found. Ensure the row exists and getRowId is correctly configured.`);const{row:l,index:a}=s;for(const[c,d]of Object.entries(o)){const u=l[c];u!==d&&(i=!0,l[c]=d,this.#D("cell-change",{row:l,rowId:n,rowIndex:a,field:c,oldValue:u,newValue:d,changes:o,source:t}))}}i&&this.#a.requestPhase(I.ROWS,"updateRows")}animateRow(e,t){Ge(this,e,t)}animateRows(e,t){Fn(this,e,t)}animateRowById(e,t){return qn(this,e,t)}setColumnVisible(e,t){const i=this.#o.setColumnVisible(e,t);return i&&this.requestStateChange(),i}toggleColumnVisibility(e){const t=this.#o.toggleColumnVisibility(e);return t&&this.requestStateChange(),t}isColumnVisible(e){return this.#o.isColumnVisible(e)}showAllColumns(){this.#o.showAllColumns(),this.requestStateChange()}getAllColumns(){return this.#o.getAllColumns()}setColumnOrder(e){this.#o.setColumnOrder(e),this.requestStateChange()}getColumnOrder(){return this.#o.getColumnOrder()}getColumnState(){const e=this.#r?.getAll()??[];return this.#o.collectState(e)}set columnState(e){e&&(this.#z=e,this.#o.initialColumnState=e,this.#u&&this.#De(e))}get columnState(){return this.getColumnState()}#De(e){const t=this.#r?.getAll()??[];this.#o.applyState(e,t),this.#I()}requestStateChange(){const e=this.#r?.getAll()??[];this.#o.requestStateChange(e)}resetColumnState(){this.#z=void 0,this.__originalOrder=[];const e=this.#r?.getAll()??[];this.#o.resetState(e),this.#o.merge(),this.#I()}get isToolPanelOpen(){return this.#b.isPanelOpen}get defaultRowHeight(){return this._virtualization.rowHeight}get expandedToolPanelSections(){return this.#b.expandedSections}openToolPanel(){this.#b.openToolPanel()}closeToolPanel(){this.#b.closeToolPanel()}toggleToolPanel(){this.#b.toggleToolPanel()}toggleToolPanelSection(e){this.#b.toggleToolPanelSection(e)}getToolPanels(){return this.#b.getToolPanels()}registerToolPanel(e){this.#s.apiToolPanelIds.add(e.id),this.#b.registerToolPanel(e)}unregisterToolPanel(e){this.#s.apiToolPanelIds.delete(e),this.#b.unregisterToolPanel(e)}getHeaderContents(){return this.#b.getHeaderContents()}registerHeaderContent(e){this.#b.registerHeaderContent(e)}unregisterHeaderContent(e){this.#b.unregisterHeaderContent(e)}getToolbarContents(){return this.#b.getToolbarContents()}registerToolbarContent(e){this.#b.registerToolbarContent(e)}unregisterToolbarContent(e){this.#b.unregisterToolbarContent(e)}#X=!1;refreshShellHeader(){this.#X||(this.#X=!0,queueMicrotask(()=>{this.#X=!1,this.isConnected&&(this.#N(),this.#o.markSourcesChanged(),this.#o.merge(),$e(this.#s),this.#Q(),this.#B(),this.#Ie())}))}#Ie(){const t=this.#e.querySelector(".tbw-grid-content")??this.#e.querySelector(".tbw-grid-root");if(this._headerRowEl=t?.querySelector(".header-row"),this._virtualization.totalHeightEl=t?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=t?.querySelector(".rows-viewport"),this._bodyEl=t?.querySelector(".rows"),this.__rowsBodyEl=t?.querySelector(".rows-body"),this.#b.isInitialized){Ke(this.#e,this.#s),Be(this.#e,this.#n?.shell,this.#s);const i=this.#n?.shell?.toolPanel?.defaultOpen;i&&this.#s.toolPanels.has(i)&&(this.openToolPanel(),this.#s.expandedSections.add(i))}this._resizeController=Nt(this),this.#U(t),this.#a.requestPhase(I.COLUMNS,"shellRefresh")}#T=new Map;registerStyles(e,t){let i=this.#T.get(e);i||(i=new CSSStyleSheet,this.#T.set(e,i)),i.replaceSync(t),this.#he()}unregisterStyles(e){this.#T.delete(e)&&this.#he()}getRegisteredStyles(){return Array.from(this.#T.keys())}#he(){const e=Array.from(this.#T.values()),t=document.adoptedStyleSheets.filter(i=>!Array.from(this.#T.values()).includes(i));document.adoptedStyleSheets=[...t,...e]}#N(){Kt(this,this.#s),$t(this,this.#s),Wt(this,this.#s,this.#ie())}#fe(){const e=this.#e.querySelector(".tbw-shell-header");if(!e)return;$e(this.#s);const t=$n(this.#n.shell,this.#s,this.#n.icons?.toolPanel),i=document.createElement("div");i.innerHTML=t;const n=i.firstElementChild;n&&(e.replaceWith(n),this.#pe(),Be(this.#e,this.#n?.shell,this.#s))}#Me(){const e=()=>{const i=this.#s.lightDomTitle,n=this.#s.hasToolButtonsContainer;this.#N();const o=this.#s.lightDomTitle,s=this.#s.hasToolButtonsContainer;(o&&!i||s&&!n)&&(this.#o.markSourcesChanged(),this.#o.merge(),this.#fe())},t=()=>{this.__lightDomColumnsCache=void 0,this.#I()};this.#o.registerLightDomHandler("tbw-grid-header",e),this.#o.registerLightDomHandler("tbw-grid-tool-buttons",e),this.#o.registerLightDomHandler("tbw-grid-tool-panel",e),this.#o.registerLightDomHandler("tbw-grid-column",t),this.#o.registerLightDomHandler("tbw-grid-detail",t),this.#o.observeLightDOM(this)}refreshColumns(){this.__lightDomColumnsCache=void 0,ye(this),this.#o.parseLightDomColumns(this);const e=this.#s.lightDomTitle,t=this.#s.hasToolButtonsContainer;this.#N();const i=this.#s.lightDomTitle,n=this.#s.hasToolButtonsContainer;(i&&!e||n&&!t)&&(this.#o.markSourcesChanged(),this.#o.merge(),this.#fe()),this.#a.requestPhase(I.COLUMNS,"refreshColumns")}#ze(){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)}#L(e,t=!1){const i=this._virtualization;let n,o,s;if(t){const h=i.container??this,f=i.viewportEl??h,p=i.scrollAreaEl;n=h.clientHeight,o=f.clientHeight,s=p?p.clientHeight:n,i.cachedFauxHeight=n,i.cachedViewportHeight=o,i.cachedScrollAreaHeight=s}else n=i.cachedFauxHeight,o=i.cachedViewportHeight,s=i.cachedScrollAreaHeight||n;const l=s-o,a=Math.max(0,n-s);let c,d=0;return i.variableHeights&&i.positionCache?c=vr(i.positionCache):(c=e*i.rowHeight,d=this.#r?.getExtraHeight()??0),c+l+d+a}#Z(){if(!this._virtualization.variableHeights)return;const e=this._rows,t=this._virtualization.rowHeight||28,i=this.#n.rowHeight,n=this.#n.getRowId,o=n?l=>n(l):void 0;this._virtualization.positionCache=br(e,this._virtualization.heightCache,t,{rowId:o},(l,a)=>{const c=this.#r?.getRowHeight?.(l,a);if(c!==void 0)return c;if(i){const d=i(l,a);if(d!==void 0&&d>0)return d}});const s=Er(this._virtualization.positionCache,e,t,(l,a)=>this.#r?.getRowHeight?.(l,a));this._virtualization.measuredCount=s.measuredCount,s.measuredCount>0&&(this._virtualization.averageHeight=s.averageHeight)}invalidateRowHeight(e,t){if(!this._virtualization.variableHeights||!this._virtualization.positionCache||e<0||e>=this._rows.length)return;const i=this._virtualization.positionCache,n=this._rows[e];let o=t;o===void 0&&(o=this.#r?.getRowHeight?.(n,e)),o===void 0&&(o=this._virtualization.rowHeight);const s=i[e];if(!(!s||Math.abs(s.height-o)<1)&&(Ye(i,e,o),this._virtualization.totalHeightEl)){const l=this.#L(this._rows.length);this._virtualization.totalHeightEl.style.height=`${l}px`}}#ge(e,t){if(!this._virtualization.variableHeights||!this._virtualization.positionCache||!this._bodyEl)return;const i=this._bodyEl.querySelectorAll(".data-grid-row"),n=this.#n.getRowId,o=xr({positionCache:this._virtualization.positionCache,heightCache:this._virtualization.heightCache,rows:this._rows,defaultHeight:this._virtualization.rowHeight,start:e,end:t,getPluginHeight:(s,l)=>this.#r?.getRowHeight?.(s,l),getRowId:n?s=>n(s):void 0},i);if(o.hasChanges&&(this._virtualization.measuredCount=o.measuredCount,this._virtualization.averageHeight=o.averageHeight,this._virtualization.totalHeightEl)){const s=this.#L(this._rows.length);this._virtualization.totalHeightEl.style.height=`${s}px`}}refreshVirtualWindow(e=!1,t=!1){if(!this._bodyEl)return!1;const i=this._rows.length;if(!this._virtualization.enabled)return this.#Y(0,i),t||this.#r?.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.#Y(0,i,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),e&&this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${this.#L(i,!0)}px`),this.#ce(i,this._visibleColumns.length),t||this.#r?.afterRender(),!0;const n=this._virtualization.container??this,o=this._virtualization.viewportEl??n,s=e?this._virtualization.cachedViewportHeight=o.clientHeight:this._virtualization.cachedViewportHeight||(this._virtualization.cachedViewportHeight=o.clientHeight),l=this._virtualization.rowHeight,a=n.scrollTop;let c;const d=this._virtualization.positionCache;if(this._virtualization.variableHeights&&d&&d.length>0)c=Qt(d,a),c===-1&&(c=0);else{c=Math.floor(a/l);let m=0;const v=10;for(;m<v;){const x=this.#r?.getExtraHeightBefore?.(c)??0,S=Math.floor((a-x)/l);if(S>=c||S<0)break;c=S,m++}}c=c-c%2,c<0&&(c=0);const u=this.#r?.adjustVirtualStart(c,a,l);u!==void 0&&u<c&&(c=u,c=c-c%2,c<0&&(c=0));let h;if(this._virtualization.variableHeights&&d&&d.length>0){const m=s+l*3;let v=0;for(h=c;h<i&&v<m;)v+=d[h].height,h++;const x=Math.ceil(s/l)+3;h-c<x&&(h=Math.min(c+x,i))}else{const m=Math.ceil(s/l)+3;h=c+m}h>i&&(h=i);const f=this._virtualization.start,p=this._virtualization.end;if(!e&&c===f&&h===p)return!1;this._virtualization.start=c,this._virtualization.end=h;const g=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(g===0&&s>0)return this.#a.requestPhase(I.VIRTUALIZATION,"stale-refs-retry"),!1;if(e&&this._virtualization.totalHeightEl){const m=this.#L(i);this._virtualization.totalHeightEl.style.height=`${m}px`}let w;if(this._virtualization.variableHeights&&d&&d[c])w=d[c].offset;else{const m=this.#r?.getExtraHeightBefore?.(c)??0;w=c*l+m}const b=-(a-w);return this._bodyEl.style.transform=`translateY(${b}px)`,this.#Y(c,h,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),e&&this._virtualization.variableHeights&&this.#ge(c,h),this.#ce(i,this._visibleColumns.length),e&&!t&&(this.#r?.afterRender(),queueMicrotask(()=>{if(!this._virtualization.totalHeightEl)return;const m=this.#L(i);this._virtualization.cachedFauxHeight===0&&this._virtualization.cachedViewportHeight>0||(this._virtualization.totalHeightEl.style.height=`${m}px`)})),!0}#Q(){this.#N(),this.#o.markSourcesChanged(),this.#o.merge();const e=this.#n?.shell;Zn(this.#e,e,{isPanelOpen:this.#s.isPanelOpen,expandedSections:this.#s.expandedSections},this.#n?.icons)&&(this.#pe(),this.#b.setInitialized(!0))}#pe(){Wn(this.#e,this.#n?.shell,this.#s,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e)}),this.#F?.(),this.#F=Vn(this.#e,this.#n?.shell,e=>{this.style.setProperty("--tbw-tool-panel-width",`${e}px`)})}}customElements.get(K.tagName)||customElements.define(K.tagName,K),globalThis.DataGridElement=K;const Ar={CAN_MOVE_COLUMN:"canMoveColumn",GET_CONTEXT_MENU_ITEMS:"getContextMenuItems"};class D{static dependencies;static manifest;version=typeof __GRID_VERSION__<"u"?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}attach(e){this.#t?.abort(),this.#t=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=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.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...G,...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 t=this.gridElement;return t?getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()!=="0":!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 t!==void 0?t:this.gridIcons[e]}setIcon(e,t){typeof t=="string"?e.innerHTML=t:t instanceof HTMLElement&&(e.innerHTML="",e.appendChild(t.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}const z={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"},he={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"},kr={ROOT:`.${z.ROOT}`,HEADER:`.${z.HEADER}`,HEADER_ROW:`.${z.HEADER_ROW}`,HEADER_CELL:`.${z.HEADER_CELL}`,ROWS_VIEWPORT:`.${z.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${z.ROWS_CONTAINER}`,DATA_ROW:`.${z.DATA_ROW}`,DATA_CELL:`.${z.DATA_CELL}`,GROUP_ROW:`.${z.GROUP_ROW}`,ROW_BY_INDEX:r=>`.${z.DATA_ROW}[${he.ROW_INDEX}="${r}"]`,CELL_BY_FIELD:r=>`.${z.DATA_CELL}[${he.FIELD}="${r}"]`,CELL_AT:(r,e)=>`.${z.DATA_ROW}[${he.ROW_INDEX}="${r}"] .${z.DATA_CELL}[${he.COL_INDEX}="${e}"]`,SELECTED_ROWS:`.${z.DATA_ROW}.${z.SELECTED}`,EDITING_CELL:`.${z.DATA_CELL}.${z.EDITING}`},Tr={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 Lr(r){const e=document.createElement("tbw-grid");return r&&(e.gridConfig=r),e}function Pr(r,e=document){return e.querySelector(r)}const Hr={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"},Dr={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"},Jt="__tbw_expander",Ir=32;function Te(r){return r.field===Jt}function X(r){return r.meta?.utility===!0}function Mr(r){return r.find(Te)}function zr(r){return{field:Jt,header:"",width:Ir,resizable:!1,sortable:!1,filterable:!1,meta:{lockPosition:!0,suppressMovable:!0,expanderColumn:!0,expanderPlugin:r,utility:!0}}}async function Xe(r){try{return await navigator.clipboard.writeText(r),!0}catch{const e=document.createElement("textarea");e.value=r,e.style.position="fixed",e.style.opacity="0",e.style.pointerEvents="none",document.body.appendChild(e),e.select();const t=document.execCommand("copy");return document.body.removeChild(e),t}}function ei(r,e){const t=e.delimiter??" ",i=e.newline??`
|
|
90
|
+
`;class B extends HTMLElement{static tagName="tbw-grid";static version=typeof __GRID_VERSION__<"u"?__GRID_VERSION__:"dev";static#t=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#e(){return this}#u=!1;#c;#n;#l=[];get#i(){return this.#o?.effective??{}}#h=!1;#w=!1;#f={rows:!1,columns:!1,gridConfig:!1,fitMode:!1};#a;#v=0;#d=null;#g=!1;#E=!1;#b=0;#C;#R=rr();#p;#x;#m;#S;#L={scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0};#r;#_;#O=!1;#I;#W;#z;#o;#s=Wn();#y;#F;#q=!1;#P=new Set;#H=new Map;#G;#A=new Map;_rows=[];#V=[];get _columns(){return this.#i.columns??[]}set _columns(e){this.#i.columns=e}get _visibleColumns(){return this._columns.filter(e=>!e.hidden)}_headerRowEl;_bodyEl;_rowPool=[];_resizeController;_virtualization={enabled:!0,rowHeight:28,bypassThreshold:24,start:0,end:0,container:null,viewportEl:null,totalHeightEl:null,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.#o?.lightDomColumnsCache}set __lightDomColumnsCache(e){this.#o&&(this.#o.lightDomColumnsCache=e)}get __originalColumnNodes(){return this.#o?.originalColumnNodes}set __originalColumnNodes(e){this.#o&&(this.#o.originalColumnNodes=e)}__originalOrder=[];__frameworkAdapter;__rowsBodyEl=null;get rows(){return this._rows}set rows(e){const t=this.#l;this.#l=e,t!==e&&this.#K("rows")}get sourceRows(){return this.#l}get columns(){return[...this._columns]}set columns(e){const t=this.#o?.getColumns();this.#o?.setColumns(e),t!==e&&this.#K("columns")}get gridConfig(){return this.#i}set gridConfig(e){const t=this.#o?.getGridConfig();this.#o?.setGridConfig(e),t!==e&&(this.#o.clearLightDomCache(),this.#K("gridConfig"))}get fitMode(){return this.#i.fitMode??"stretch"}set fitMode(e){const t=this.#o?.getFitMode();this.#o?.setFitMode(e),t!==e&&this.#K("fitMode")}get loading(){return this.#q}set loading(e){const t=this.#q;this.#q=e,e?this.setAttribute("loading",""):this.removeAttribute("loading"),t!==e&&this.#Pe()}setRowLoading(e,t){const i=this.#P.has(e);t?this.#P.add(e):this.#P.delete(e),i!==t&&this.#de(e,t)}setCellLoading(e,t,i){let n=this.#H.get(e);const o=n?.has(t)??!1;i?(n||(n=new Set,this.#H.set(e,n)),n.add(t)):(n?.delete(t),n?.size===0&&this.#H.delete(e)),o!==i&&this.#ue(e,t,i)}isRowLoading(e){return this.#P.has(e)}isCellLoading(e,t){return this.#H.get(e)?.has(t)??!1}clearAllLoading(){this.loading=!1;for(const e of this.#P)this.#de(e,!1);this.#P.clear();for(const[e,t]of this.#H)for(const i of t)this.#ue(e,i,!1);this.#H.clear()}get effectiveConfig(){return this.#i}get disconnectSignal(){return this.#p||(this.#p=new AbortController),this.#p.signal}constructor(){super(),this.#we(),this.#c=new Promise(e=>this.#n=e),this.#a=new In({mergeConfig:()=>{this.#o.parseLightDomColumns(this),this.#o.merge(),this.#ee(),gr(this.#i,this.#r?.getPlugins()??[]),pr(this.#r?.getPlugins()??[]),br(this.#r?.getPlugins()??[]),this.#Le(),this.#V=[...this._columns]},processColumns:()=>this.#Ae(),processRows:()=>this.#ke(),renderHeader:()=>_e(this),updateTemplate:()=>le(this),renderVirtualWindow:()=>this.refreshVirtualWindow(!0,!0),afterRender:()=>{this.#r?.afterRender(),this._virtualization.enabled&&this._virtualization.totalHeightEl&&queueMicrotask(()=>{if(!this._virtualization.totalHeightEl)return;const t=this.#T(this._rows.length);this._virtualization.totalHeightEl.style.height=`${t}px`}),this.#i.fitMode==="fixed"&&!this.__didInitialAutoSize&&(this.__didInitialAutoSize=!0,yt(this)),this._restoreFocusAfterRender&&(this._restoreFocusAfterRender=!1,I(this)),this._virtualization.enabled&&!this.#B&&this.#ve(),this.#E&&(this.#E=!1,requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.#me()})}))},isConnected:()=>this.isConnected&&this.#h}),this.#a.setInitialReadyResolver(()=>this.#n?.()),this.#y=Zn(this.#s,{getShadow:()=>this.#e,getShellConfig:()=>this.#i?.shell,getAccordionIcons:()=>({expand:this.#i?.icons?.expand??G.expand,collapse:this.#i?.icons?.collapse??G.collapse}),emit:(e,t)=>this.#D(e,t),refreshShellHeader:()=>this.refreshShellHeader()}),this.#o=new hn({getRows:()=>this.#l,getSortState:()=>this._sortState,setSortState:e=>{this._sortState=e},onConfigChange:()=>{this.#a.requestPhase(M.FULL,"configChange")},emit:(e,t)=>this.#D(e,t),clearRowPool:()=>{this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++},setup:()=>this.#M(),renderHeader:()=>_e(this),updateTemplate:()=>le(this),refreshVirtualWindow:()=>this.#a.requestPhase(M.VIRTUALIZATION,"configManager"),getVirtualization:()=>this._virtualization,setRowHeight:e=>{this._virtualization.rowHeight=e},applyAnimationConfig:e=>this.#Te(e),getShellLightDomTitle:()=>this.#s.lightDomTitle,getShellToolPanels:()=>this.#s.toolPanels,getShellHeaderContents:()=>this.#s.headerContents,getShellToolbarContents:()=>this.#s.toolbarContents,getShellLightDomHeaderContent:()=>this.#s.lightDomHeaderContent,getShellHasToolButtonsContainer:()=>this.#s.hasToolButtonsContainer})}async#we(){await nr(kr)}getPlugin(e){return this.#r?.getPlugin(e)}getPluginByName(e){return this.#r?.getPluginByName(e)}requestRender(){this.#a.requestPhase(M.ROWS,"plugin:requestRender")}requestColumnsRender(){this.#a.requestPhase(M.COLUMNS,"plugin:requestColumnsRender")}requestRenderWithFocus(){this._restoreFocusAfterRender=!0,this.#a.requestPhase(M.ROWS,"plugin:requestRenderWithFocus")}updateTemplate(){le(this)}requestAfterRender(){this.#a.requestPhase(M.STYLE,"plugin:requestAfterRender")}#J(){this.#r=new ue(this);const e=this.#i?.plugins,t=Array.isArray(e)?e:[];this.#r.attachAll(t)}#$(){const e=this.#r?.getPluginStyles()??[];tr(e)}#ee(){const e=this.#i?.plugins,t=Array.isArray(e)?e:[];if(this.#_===t)return;if(this.#_&&this.#_.length===t.length&&this.#_.every((n,o)=>n===t[o])){this.#_=t;return}this.#r&&this.#r.detachAll();for(const n of this.#s.toolPanels.keys()){const o=this.#s.lightDomToolPanelIds.has(n),s=this.#s.apiToolPanelIds.has(n);if(!o&&!s){const l=this.#s.panelCleanups.get(n);l&&(l(),this.#s.panelCleanups.delete(n)),this.#s.toolPanels.delete(n)}}for(const n of this.#s.headerContents.keys()){const o=this.#s.headerContentCleanups.get(n);o&&(o(),this.#s.headerContentCleanups.delete(n)),this.#s.headerContents.delete(n)}this.#J(),this.#$(),this.#_=t,this.#re(),this.#te();const i=this.#g;if(this.#g=this.#r?.getAll().some(n=>n.onScroll)??!1,!i&&this.#g){const o=this.#e.querySelector(".tbw-grid-content")??this.#e.querySelector(".tbw-grid-root");this.#U(o)}}#be(){this.#r?.detachAll()}#te(){if(!this.#r)return;const e=this.#r.getToolPanels();for(const{panel:i}of e)this.#s.toolPanels.has(i.id)||this.#s.toolPanels.set(i.id,i);const t=this.#r.getHeaderContents();for(const{content:i}of t)this.#s.headerContents.has(i.id)||this.#s.headerContents.set(i.id,i)}#ie(){const e=B.getAdapters();if(e.length===0&&!this.__frameworkAdapter)return;const t=this.__frameworkAdapter;return i=>{if(t?.createToolPanelRenderer){const n=t.createToolPanelRenderer(i);if(n)return n}for(const n of e)if(n.createToolPanelRenderer){const o=n.createToolPanelRenderer(i);if(o)return o}}}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.hasAttribute("version")||this.setAttribute("version",B.version),this.id||(this.id=`tbw-grid-${++B.#t}`),this._rows=Array.isArray(this.#l)?[...this.#l]:[],this.#p&&(this.#p.abort(),this.#O=!1),this.#p=new AbortController,this.#S&&(Nt(this.#S),this.#S=void 0),this.#N(),this.#o.parseLightDomColumns(this),this.#o.merge(),this.#J();const e=this.#i?.plugins;this.#_=Array.isArray(e)?e:[],this.#te(),this.#u||(this.#Q(),this.#$(),this.#u=!0),this.#ne(),this.#S=An(()=>{this.#Ie()},{timeout:100})}disconnectedCallback(){this.#S&&(Nt(this.#S),this.#S=void 0),this.#b&&(clearTimeout(this.#b),this.#b=0),this.#be(),Xn(this.#s),this.#y.setInitialized(!1),this.#F?.(),this.#F=void 0,Xt(this.#R),this.#p&&(this.#p.abort(),this.#p=void 0),this.#I?.abort(),this.#I=void 0,this.#O=!1,this._resizeController&&this._resizeController.dispose(),this.#x&&(this.#x.disconnect(),this.#x=void 0),this.#m&&(this.#m.disconnect(),this.#m=void 0,this.#B=!1),ye(this),this.#k.clear(),this.#_=void 0;for(const e of this._rowPool)e.remove();this._rowPool.length=0,this.__rowsBodyEl=null,this.#h=!1}attributeChangedCallback(e,t,i){if(e==="loading"){const n=i!==null&&i!=="false";this.loading!==n&&(this.loading=n);return}if(!(t===i||!i||i==="null"||i==="undefined"))if(e==="rows"||e==="columns"||e==="grid-config")try{const n=JSON.parse(i);e==="rows"?this.rows=n:e==="columns"?this.columns=n:e==="grid-config"&&(this.gridConfig=n)}catch{console.warn(`[tbw-grid] Invalid JSON for '${e}' attribute:`,i)}else e==="fit-mode"&&(this.fitMode=i)}#ne(){const t=this.#e.querySelector(".tbw-grid-content")??this.#e.querySelector(".tbw-grid-root");if(this._headerRowEl=t?.querySelector(".header-row"),this._virtualization.totalHeightEl=t?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=t?.querySelector(".rows-viewport"),this._bodyEl=t?.querySelector(".rows"),this.__rowsBodyEl=t?.querySelector(".rows-body"),this.#y.isInitialized){Ke(this.#e,this.#s),Be(this.#e,this.#i?.shell,this.#s);const n=this.#i?.shell?.toolPanel?.defaultOpen;n&&this.#s.toolPanels.has(n)&&(this.openToolPanel(),this.#s.expandedSections.add(n))}if(this.setAttribute("data-upgraded",""),this.#h=!0,this._resizeController=Ot(this),this.#M(),this.#U(t),this.#O)return;this.#O=!0;const i=this.disconnectSignal;Rn(this,this,this.#e,i),this.#re(),queueMicrotask(()=>this.#ye()),this.#a.requestPhase(M.FULL,"afterConnect")}#re(){const e=this.#i.rowHeight,t=this.#r.hasRowHeightPlugin();typeof e=="function"||t?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.#E=!0)):!t&&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.#oe())}#oe(){if(this.#r.hasExtraHeight())return;const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const t=e.querySelectorAll(".cell");let i=0;t.forEach(s=>{const l=s.offsetHeight;l>i&&(i=l)});const n=e.getBoundingClientRect(),o=Math.max(n.height,i);o>0&&Math.abs(o-this._virtualization.rowHeight)>1&&(this._virtualization.rowHeight=o,this.#a.requestPhase(M.VIRTUALIZATION,"measureRowHeight"))}#me(){const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const t=e.querySelectorAll(".cell");let i=0;t.forEach(s=>{const l=s.offsetHeight;l>i&&(i=l)});const n=e.getBoundingClientRect(),o=Math.max(n.height,i);if(o>0&&(Math.abs(o-this._virtualization.rowHeight)>1&&(this._virtualization.rowHeight=o),this.#Z(),this._virtualization.totalHeightEl)){const l=this.#T(this._rows.length);this._virtualization.totalHeightEl.style.height=`${l}px`}}#U(e){this.#I?.abort(),this.#I=new AbortController;const t=this.#I.signal,i=e?.querySelector(".faux-vscroll"),n=e?.querySelector(".rows");if(this._virtualization.container=i??this,this.#g=this.#r?.getAll().some(o=>o.onScroll)??!1,i&&n){i.addEventListener("scroll",()=>{if(!this._virtualization.enabled&&!this.#g)return;const a=i.scrollTop,c=this._virtualization.rowHeight;if(this._rows.length<=this._virtualization.bypassThreshold)n.style.transform=`translateY(${-a}px)`;else{const d=this._virtualization.positionCache;let u,h;if(this._virtualization.variableHeights&&d&&d.length>0){u=Jt(d,a),u===-1&&(u=0);const p=u-u%2;h=d[p]?.offset??p*c}else u=Math.floor(a/c),h=(u-u%2)*c;const f=-(a-h);n.style.transform=`translateY(${f}px)`}this.#d=a,this.#v||(this.#v=requestAnimationFrame(()=>{this.#v=0,this.#d!==null&&(this.#He(this.#d),this.#d=null)}))},{passive:!0,signal:t});const o=this.#e.querySelector(".tbw-scroll-area");this.#W=o,this._virtualization.scrollAreaEl=o,o&&this.#g&&o.addEventListener("scroll",()=>{const a=this.#L;a.scrollTop=i.scrollTop,a.scrollLeft=o.scrollLeft,a.scrollHeight=i.scrollHeight,a.scrollWidth=o.scrollWidth,a.clientHeight=i.clientHeight,a.clientWidth=o.clientWidth,this.#r?.onScroll(a)},{passive:!0,signal:t});const s=this.#e.querySelector(".tbw-grid-content"),l=this.#W;s&&(s.addEventListener("wheel",a=>{const c=a.shiftKey||Math.abs(a.deltaX)>Math.abs(a.deltaY);if(c&&l){const d=a.shiftKey?a.deltaY:a.deltaX,{scrollLeft:u,scrollWidth:h,clientWidth:f}=l;(d>0&&u<h-f||d<0&&u>0)&&(a.preventDefault(),l.scrollLeft+=d)}else if(!c){const{scrollTop:d,scrollHeight:u,clientHeight:h}=i;(a.deltaY>0&&d<u-h||a.deltaY<0&&d>0)&&(a.preventDefault(),i.scrollTop+=a.deltaY)}},{passive:!1,signal:t}),dr(s,this.#R,{fauxScrollbar:i,scrollArea:l},t))}this._bodyEl&&En(this,this._bodyEl,t),this.#x?.disconnect(),this._virtualization.viewportEl&&(this.#x=new ResizeObserver(()=>{this.#ze(),this.#a.requestPhase(M.VIRTUALIZATION,"resize-observer")}),this.#x.observe(this._virtualization.viewportEl)),this.#e.addEventListener("focusin",()=>{this.dataset.hasFocus=""},{signal:t}),this.#e.addEventListener("focusout",o=>{const s=o.relatedTarget;(!s||!this.#e.contains(s))&&delete this.dataset.hasFocus},{signal:t})}#B=!1;#ve(){if(this.#B)return;const e=this._bodyEl?.querySelector(".data-grid-row");e&&(this.#B=!0,this.#m?.disconnect(),this.#m=new ResizeObserver(()=>{this.#oe()}),this.#m.observe(e))}addEventListener(e,t,i){super.addEventListener(e,t,i)}removeEventListener(e,t,i){super.removeEventListener(e,t,i)}#D(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}#ye(){this._bodyEl?.querySelectorAll(".data-grid-row")?.forEach((t,i)=>{const n=i===this._focusRow;t.setAttribute("aria-selected",String(n)),t.querySelectorAll(".cell").forEach((o,s)=>{o.setAttribute("aria-selected",String(n&&s===this._focusCol))})})}#K(e){this.#f[e]=!0,!this.#w&&(this.#w=!0,queueMicrotask(()=>this.#Ce()))}#Ce(){if(!this.#w||!this.#h){this.#w=!1;return}const e=this.#f;if(this.#w=!1,this.#f={rows:!1,columns:!1,gridConfig:!1,fitMode:!1},e.gridConfig){this.#Se(),e.rows&&this.#se();return}e.columns&&this.#Ee(),e.rows&&this.#se(),e.fitMode&&this.#Re()}#se(){this._rows=Array.isArray(this.#l)?[...this.#l]:[],this.#j(),this.#a.requestPhase(M.ROWS,"applyRowsUpdate")}#j(){this.#A.clear();const e=this.#i.getRowId;this._rows.forEach((t,i)=>{const n=this.#le(t,e);n!==void 0&&this.#A.set(n,{row:t,index:i})})}#le(e,t){if(t)return t(e);const i=e;if("id"in i&&i.id!=null)return String(i.id);if("_id"in i&&i._id!=null)return String(i._id)}#xe(e,t){const i=this.#le(e,t);if(i===void 0)throw new Error('[tbw-grid] Cannot determine row ID. Configure getRowId in gridConfig or ensure rows have an "id" property.');return i}#Ee(){ye(this),this.#o.merge(),this.#M()}#Re(){this.#o.merge(),this.#i.fitMode==="fixed"?(this.__didInitialAutoSize=!1,yt(this)):(this._columns.forEach(t=>{!t.__userResized&&t.__autoSized&&delete t.width}),le(this))}#Se(){Kt(this,this.#s),Wt(this,this.#s);const e=!!this.#e.querySelector(".has-shell"),t=!!this.#e.querySelector(".tbw-tool-panel"),i=this.#e.querySelectorAll(".tbw-accordion-section").length;this.#o.parseLightDomColumns(this),this.#o.merge(),this.#ee(),Vt(this,this.#s,this.#ie()),this.#o.markSourcesChanged(),this.#o.merge();const n=Bt(this.#i?.shell),o=(this.#i?.shell?.toolPanels?.length??0)>0,s=this.#i?.shell?.toolPanels?.length??0;if(e!==n||!t&&o||t&&s!==i){We(this.#s),this.#Q(),this.#$(),this.#ne(),this.#j();return}e&&this.#_e(),this.#j(),this.#a.requestPhase(M.COLUMNS,"applyGridConfigUpdate")}#_e(){const e=this.#e.querySelector(".tbw-shell-header");if(!e)return;const t=this.#i.shell?.header?.title??this.#s.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()}#Ae(){if(this.#r){const e=this.#V.length>0?this.#V:this._columns,t=e.filter(o=>!o.hidden),i=e.filter(o=>o.hidden),n=this.#r.processColumns([...t]);if(n!==t){const o=new Set(n.map(l=>l.field));!t.some(l=>o.has(l.field))&&n.length>0?this._columns=[...n,...i]:this._columns=[...n,...i]}else this._columns=[...e]}}#ke(){ye(this);const e=Array.isArray(this.#l)?[...this.#l]:[],t=this.#r?.processRows(e)??e;this._rows=t,this._virtualization.variableHeights&&this.#Z()}#Te(e){const t={...wt,...e.animation},i=t.mode??"reduced-motion";let n=1;i===!1||i==="off"?n=0:(i===!0||i==="on")&&(n=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(n)),this.dataset.animationMode=typeof i=="boolean"?i?"on":"off":i}#Y(e,t,i=this.__rowRenderEpoch){this.#C||(this.#C=(n,o,s)=>this.#r?.renderRow(n,o,s)??!1),bn(this,e,t,i,this.#C)}#ae=se();#ce(e,t){Ui(this.#ae,this.__rowsBodyEl,this._bodyEl,e,t)}#Le(){Yi(this.#ae,this.__rowsBodyEl,this.#i,this.#s)}#Pe(){const e=this.querySelector(".tbw-grid-root");e&&(this.#q?(this.#G||(this.#G=Ln(this.#i?.loadingRenderer)),Pn(e,this.#G)):Hn(this.#G))}#de(e,t){const i=this.#A.get(e);if(!i)return;const n=this.findRenderedRowElement?.(i.index);n&&Dn(n,t)}#ue(e,t,i){const n=this.#A.get(e);if(!n)return;const o=this.findRenderedRowElement?.(n.index);if(!o)return;const s=this._visibleColumns.findIndex(a=>a.field===t);if(s<0)return;const l=o.children[s];l&&Mn(l,i)}#M(){if(this.isConnected&&!(!this._headerRowEl||!this._bodyEl)){if(this.#o.parseLightDomColumns(this),this.#z){const e=this.#z;this.#z=void 0,this.#o.merge();const t=this.#r?.getAll()??[];this.#o.applyState(e,t)}this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),this.#a.requestPhase(M.FULL,"setup")}}#He(e){let t=0,i=0,n=0,o=0,s=0;if(this.#g){const a=this._virtualization.container,c=this.#W;t=c?.scrollLeft??0,i=a?.scrollHeight??0,n=c?.scrollWidth??0,o=a?.clientHeight??0,s=c?.clientWidth??0}if(this.refreshVirtualWindow(!1)&&this.#r?.onScrollRender(),this._virtualization.variableHeights&&(this.#b&&clearTimeout(this.#b),this.#b=window.setTimeout(()=>{this.#b=0,this.#ge(this._virtualization.start,this._virtualization.end)},100)),this.#g){const a=this.#L;a.scrollTop=e,a.scrollLeft=t,a.scrollHeight=i,a.scrollWidth=n,a.clientHeight=o,a.clientWidth=s,this.#r?.onScroll(a)}}findHeaderRow(){return this.#e.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,n){const o=this._rows[t],s=this._columns[i];if(!o||!s)return!1;const l=s.field,a=o[l],c=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,composed:!0,detail:{rowIndex:t,colIndex:i,field:l,value:a,row:o,cellEl:n,trigger:"pointer",originalEvent:e}});if(this.dispatchEvent(c),c.defaultPrevented)return!0;const d={row:o,rowIndex:t,colIndex:i,field:l,value:a,cellEl:n,originalEvent:e},u=this.#r?.onCellClick(d)??!1;return this.#D("cell-click",d),u}_dispatchRowClick(e,t,i,n){if(!i)return!1;const o={rowIndex:t,row:i,rowEl:n,originalEvent:e},s=this.#r?.onRowClick(o)??!1;return this.#D("row-click",o),s}_dispatchHeaderClick(e,t,i){const n=this._columns[t];if(!n)return!1;const o={colIndex:t,field:n.field,column:n,headerEl:i,originalEvent:e};return this.#r?.onHeaderClick(o)??!1}_dispatchKeyDown(e){return this.#r?.onKeyDown(e)??!1}_getHorizontalScrollOffsets(e,t){return this.#r?.getHorizontalScrollOffsets(e,t)??{left:0,right:0}}queryPlugins(e){return this.#r?.queryPlugins(e)??[]}query(e,t){return this.#r?.queryPlugins({type:e,context:t})??[]}_dispatchCellMouseDown(e){return this.#r?.onCellMouseDown(e)??!1}_dispatchCellMouseMove(e){this.#r?.onCellMouseMove(e)}_dispatchCellMouseUp(e){this.#r?.onCellMouseUp(e)}_afterCellRender(e){this.#r?.afterCellRender(e)}_hasAfterCellRenderHook(){return this.#r?.hasAfterCellRenderHook()??!1}_afterRowRender(e){this.#r?.afterRowRender(e)}_hasAfterRowRenderHook(){return this.#r?.hasAfterRowRenderHook()??!1}async ready(){return this.#c}async forceLayout(){return this.#a.requestPhase(M.FULL,"forceLayout"),this.#a.whenReady()}async getConfig(){return Object.freeze({...this.#i||{}})}getRowId(e){return this.#xe(e,this.#i.getRowId)}getRow(e){return this.#A.get(e)?.row}updateRow(e,t,i="api"){const n=this.#A.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:o,index:s}=n,l=[];for(const[a,c]of Object.entries(t)){const d=o[a];d!==c&&(l.push({field:a,oldValue:d,newValue:c}),o[a]=c)}for(const{field:a,oldValue:c,newValue:d}of l)this.#D("cell-change",{row:o,rowId:e,rowIndex:s,field:a,oldValue:c,newValue:d,changes:t,source:i});l.length>0&&this.#a.requestPhase(M.ROWS,"updateRow")}updateRows(e,t="api"){let i=!1;for(const{id:n,changes:o}of e){const s=this.#A.get(n);if(!s)throw new Error(`[tbw-grid] Row with ID "${n}" not found. Ensure the row exists and getRowId is correctly configured.`);const{row:l,index:a}=s;for(const[c,d]of Object.entries(o)){const u=l[c];u!==d&&(i=!0,l[c]=d,this.#D("cell-change",{row:l,rowId:n,rowIndex:a,field:c,oldValue:u,newValue:d,changes:o,source:t}))}}i&&this.#a.requestPhase(M.ROWS,"updateRows")}animateRow(e,t){$e(this,e,t)}animateRows(e,t){Gn(this,e,t)}animateRowById(e,t){return $n(this,e,t)}setColumnVisible(e,t){const i=this.#o.setColumnVisible(e,t);return i&&this.requestStateChange(),i}toggleColumnVisibility(e){const t=this.#o.toggleColumnVisibility(e);return t&&this.requestStateChange(),t}isColumnVisible(e){return this.#o.isColumnVisible(e)}showAllColumns(){this.#o.showAllColumns(),this.requestStateChange()}getAllColumns(){return this.#o.getAllColumns()}setColumnOrder(e){this.#o.setColumnOrder(e),this.requestStateChange()}getColumnOrder(){return this.#o.getColumnOrder()}getColumnState(){const e=this.#r?.getAll()??[];return this.#o.collectState(e)}set columnState(e){e&&(this.#z=e,this.#o.initialColumnState=e,this.#u&&this.#De(e))}get columnState(){return this.getColumnState()}#De(e){const t=this.#r?.getAll()??[];this.#o.applyState(e,t),this.#M()}requestStateChange(){const e=this.#r?.getAll()??[];this.#o.requestStateChange(e)}resetColumnState(){this.#z=void 0,this.__originalOrder=[];const e=this.#r?.getAll()??[];this.#o.resetState(e),this.#o.merge(),this.#M()}get isToolPanelOpen(){return this.#y.isPanelOpen}get defaultRowHeight(){return this._virtualization.rowHeight}get expandedToolPanelSections(){return this.#y.expandedSections}openToolPanel(){this.#y.openToolPanel()}closeToolPanel(){this.#y.closeToolPanel()}toggleToolPanel(){this.#y.toggleToolPanel()}toggleToolPanelSection(e){this.#y.toggleToolPanelSection(e)}getToolPanels(){return this.#y.getToolPanels()}registerToolPanel(e){this.#s.apiToolPanelIds.add(e.id),this.#y.registerToolPanel(e)}unregisterToolPanel(e){this.#s.apiToolPanelIds.delete(e),this.#y.unregisterToolPanel(e)}getHeaderContents(){return this.#y.getHeaderContents()}registerHeaderContent(e){this.#y.registerHeaderContent(e)}unregisterHeaderContent(e){this.#y.unregisterHeaderContent(e)}getToolbarContents(){return this.#y.getToolbarContents()}registerToolbarContent(e){this.#y.registerToolbarContent(e)}unregisterToolbarContent(e){this.#y.unregisterToolbarContent(e)}#X=!1;refreshShellHeader(){this.#X||(this.#X=!0,queueMicrotask(()=>{this.#X=!1,this.isConnected&&(this.#N(),this.#o.markSourcesChanged(),this.#o.merge(),We(this.#s),this.#Q(),this.#$(),this.#Me())}))}#Me(){const t=this.#e.querySelector(".tbw-grid-content")??this.#e.querySelector(".tbw-grid-root");if(this._headerRowEl=t?.querySelector(".header-row"),this._virtualization.totalHeightEl=t?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=t?.querySelector(".rows-viewport"),this._bodyEl=t?.querySelector(".rows"),this.__rowsBodyEl=t?.querySelector(".rows-body"),this.#y.isInitialized){Ke(this.#e,this.#s),Be(this.#e,this.#i?.shell,this.#s);const i=this.#i?.shell?.toolPanel?.defaultOpen;i&&this.#s.toolPanels.has(i)&&(this.openToolPanel(),this.#s.expandedSections.add(i))}this._resizeController=Ot(this),this.#U(t),this.#a.requestPhase(M.COLUMNS,"shellRefresh")}#k=new Map;registerStyles(e,t){let i=this.#k.get(e);i||(i=new CSSStyleSheet,this.#k.set(e,i)),i.replaceSync(t),this.#he()}unregisterStyles(e){this.#k.delete(e)&&this.#he()}getRegisteredStyles(){return Array.from(this.#k.keys())}#he(){const e=Array.from(this.#k.values()),t=document.adoptedStyleSheets.filter(i=>!Array.from(this.#k.values()).includes(i));document.adoptedStyleSheets=[...t,...e]}#N(){Kt(this,this.#s),Wt(this,this.#s),Vt(this,this.#s,this.#ie())}#fe(){const e=this.#e.querySelector(".tbw-shell-header");if(!e)return;We(this.#s);const t=Vn(this.#i.shell,this.#s,this.#i.icons?.toolPanel),i=document.createElement("div");i.innerHTML=t;const n=i.firstElementChild;n&&(e.replaceWith(n),this.#pe(),Be(this.#e,this.#i?.shell,this.#s))}#Ie(){const e=()=>{const i=this.#s.lightDomTitle,n=this.#s.hasToolButtonsContainer;this.#N();const o=this.#s.lightDomTitle,s=this.#s.hasToolButtonsContainer;(o&&!i||s&&!n)&&(this.#o.markSourcesChanged(),this.#o.merge(),this.#fe())},t=()=>{this.__lightDomColumnsCache=void 0,this.#M()};this.#o.registerLightDomHandler("tbw-grid-header",e),this.#o.registerLightDomHandler("tbw-grid-tool-buttons",e),this.#o.registerLightDomHandler("tbw-grid-tool-panel",e),this.#o.registerLightDomHandler("tbw-grid-column",t),this.#o.registerLightDomHandler("tbw-grid-detail",t),this.#o.observeLightDOM(this)}refreshColumns(){this.__lightDomColumnsCache=void 0,ye(this),this.#o.parseLightDomColumns(this);const e=this.#s.lightDomTitle,t=this.#s.hasToolButtonsContainer;this.#N();const i=this.#s.lightDomTitle,n=this.#s.hasToolButtonsContainer;(i&&!e||n&&!t)&&(this.#o.markSourcesChanged(),this.#o.merge(),this.#fe()),this.#a.requestPhase(M.COLUMNS,"refreshColumns")}#ze(){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)}#T(e,t=!1){const i=this._virtualization;let n,o,s;if(t){const h=i.container??this,f=i.viewportEl??h,p=i.scrollAreaEl;n=h.clientHeight,o=f.clientHeight,s=p?p.clientHeight:n,i.cachedFauxHeight=n,i.cachedViewportHeight=o,i.cachedScrollAreaHeight=s}else n=i.cachedFauxHeight,o=i.cachedViewportHeight,s=i.cachedScrollAreaHeight||n;const l=s-o,a=Math.max(0,n-s);let c,d=0;return i.variableHeights&&i.positionCache?c=Cr(i.positionCache):(c=e*i.rowHeight,d=this.#r?.getExtraHeight()??0),c+l+d+a}#Z(){if(!this._virtualization.variableHeights)return;const e=this._rows,t=this._virtualization.rowHeight||28,i=this.#i.rowHeight,n=this.#i.getRowId,o=n?l=>n(l):void 0;this._virtualization.positionCache=yr(e,this._virtualization.heightCache,t,{rowId:o},(l,a)=>{const c=this.#r?.getRowHeight?.(l,a);if(c!==void 0)return c;if(i){const d=i(l,a);if(d!==void 0&&d>0)return d}});const s=Sr(this._virtualization.positionCache,e,t,(l,a)=>this.#r?.getRowHeight?.(l,a));this._virtualization.measuredCount=s.measuredCount,s.measuredCount>0&&(this._virtualization.averageHeight=s.averageHeight)}invalidateRowHeight(e,t){if(!this._virtualization.variableHeights||!this._virtualization.positionCache||e<0||e>=this._rows.length)return;const i=this._virtualization.positionCache,n=this._rows[e];let o=t;o===void 0&&(o=this.#r?.getRowHeight?.(n,e)),o===void 0&&(o=this._virtualization.rowHeight);const s=i[e];if(!(!s||Math.abs(s.height-o)<1)&&(Xe(i,e,o),this._virtualization.totalHeightEl)){const l=this.#T(this._rows.length);this._virtualization.totalHeightEl.style.height=`${l}px`}}#ge(e,t){if(!this._virtualization.variableHeights||!this._virtualization.positionCache||!this._bodyEl)return;const i=this._bodyEl.querySelectorAll(".data-grid-row"),n=this.#i.getRowId,o=Rr({positionCache:this._virtualization.positionCache,heightCache:this._virtualization.heightCache,rows:this._rows,defaultHeight:this._virtualization.rowHeight,start:e,end:t,getPluginHeight:(s,l)=>this.#r?.getRowHeight?.(s,l),getRowId:n?s=>n(s):void 0},i);if(o.hasChanges&&(this._virtualization.measuredCount=o.measuredCount,this._virtualization.averageHeight=o.averageHeight,this._virtualization.totalHeightEl)){const s=this.#T(this._rows.length);this._virtualization.totalHeightEl.style.height=`${s}px`}}refreshVirtualWindow(e=!1,t=!1){if(!this._bodyEl)return!1;const i=this._rows.length;if(!this._virtualization.enabled)return this.#Y(0,i),t||this.#r?.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.#Y(0,i,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),e&&this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${this.#T(i,!0)}px`),this.#ce(i,this._visibleColumns.length),t||this.#r?.afterRender(),!0;const n=this._virtualization.container??this,o=this._virtualization.viewportEl??n,s=e?this._virtualization.cachedViewportHeight=o.clientHeight:this._virtualization.cachedViewportHeight||(this._virtualization.cachedViewportHeight=o.clientHeight),l=this._virtualization.rowHeight,a=n.scrollTop;let c;const d=this._virtualization.positionCache;if(this._virtualization.variableHeights&&d&&d.length>0)c=Jt(d,a),c===-1&&(c=0);else{c=Math.floor(a/l);let v=0;const T=10;for(;v<T;){const P=this.#r?.getExtraHeightBefore?.(c)??0,E=Math.floor((a-P)/l);if(E>=c||E<0)break;c=E,v++}}c=c-c%2,c<0&&(c=0);const u=this.#r?.adjustVirtualStart(c,a,l);u!==void 0&&u<c&&(c=u,c=c-c%2,c<0&&(c=0));let h;if(this._virtualization.variableHeights&&d&&d.length>0){const v=s+l*3;let T=0;for(h=c;h<i&&T<v;)T+=d[h].height,h++;const P=Math.ceil(s/l)+3;h-c<P&&(h=Math.min(c+P,i))}else{const v=Math.ceil(s/l)+3;h=c+v}h>i&&(h=i);const f=this._virtualization.start,p=this._virtualization.end;if(!e&&c===f&&h===p)return!1;this._virtualization.start=c,this._virtualization.end=h;const g=e?this._virtualization.cachedFauxHeight=n.clientHeight:this._virtualization.cachedFauxHeight||(this._virtualization.cachedFauxHeight=n.clientHeight);if(e){const v=this._virtualization.scrollAreaEl;v&&(this._virtualization.cachedScrollAreaHeight=v.clientHeight)}if(g===0&&s>0)return this.#a.requestPhase(M.VIRTUALIZATION,"stale-refs-retry"),!1;if(e&&this._virtualization.totalHeightEl){const v=this.#T(i);this._virtualization.totalHeightEl.style.height=`${v}px`}let w;if(this._virtualization.variableHeights&&d&&d[c])w=d[c].offset;else{const v=this.#r?.getExtraHeightBefore?.(c)??0;w=c*l+v}const y=-(a-w);return this._bodyEl.style.transform=`translateY(${y}px)`,this.#Y(c,h,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),e&&this._virtualization.variableHeights&&this.#ge(c,h),this.#ce(i,this._visibleColumns.length),e&&!t&&(this.#r?.afterRender(),queueMicrotask(()=>{if(!this._virtualization.totalHeightEl)return;const v=this.#T(i);this._virtualization.cachedFauxHeight===0&&this._virtualization.cachedViewportHeight>0||(this._virtualization.totalHeightEl.style.height=`${v}px`)})),!0}#Q(){this.#N(),this.#o.markSourcesChanged(),this.#o.merge();const e=this.#i?.shell;Jn(this.#e,e,{isPanelOpen:this.#s.isPanelOpen,expandedSections:this.#s.expandedSections},this.#i?.icons)&&(this.#pe(),this.#y.setInitialized(!0))}#pe(){Un(this.#e,this.#i?.shell,this.#s,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e)}),this.#F?.(),this.#F=jn(this.#e,this.#i?.shell,e=>{this.style.setProperty("--tbw-tool-panel-width",`${e}px`)})}}customElements.get(B.tagName)||customElements.define(B.tagName,B),globalThis.DataGridElement=B;const Tr={CAN_MOVE_COLUMN:"canMoveColumn",GET_CONTEXT_MENU_ITEMS:"getContextMenuItems"};class D{static dependencies;static manifest;version=typeof __GRID_VERSION__<"u"?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}attach(e){this.#t?.abort(),this.#t=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=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.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...G,...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 t=this.gridElement;return t?getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()!=="0":!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 t!==void 0?t:this.gridIcons[e]}setIcon(e,t){typeof t=="string"?e.innerHTML=t:t instanceof HTMLElement&&(e.innerHTML="",e.appendChild(t.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}const z={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"},he={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"},Lr={ROOT:`.${z.ROOT}`,HEADER:`.${z.HEADER}`,HEADER_ROW:`.${z.HEADER_ROW}`,HEADER_CELL:`.${z.HEADER_CELL}`,ROWS_VIEWPORT:`.${z.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${z.ROWS_CONTAINER}`,DATA_ROW:`.${z.DATA_ROW}`,DATA_CELL:`.${z.DATA_CELL}`,GROUP_ROW:`.${z.GROUP_ROW}`,ROW_BY_INDEX:r=>`.${z.DATA_ROW}[${he.ROW_INDEX}="${r}"]`,CELL_BY_FIELD:r=>`.${z.DATA_CELL}[${he.FIELD}="${r}"]`,CELL_AT:(r,e)=>`.${z.DATA_ROW}[${he.ROW_INDEX}="${r}"] .${z.DATA_CELL}[${he.COL_INDEX}="${e}"]`,SELECTED_ROWS:`.${z.DATA_ROW}.${z.SELECTED}`,EDITING_CELL:`.${z.DATA_CELL}.${z.EDITING}`},Pr={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 Hr(r){const e=document.createElement("tbw-grid");return r&&(e.gridConfig=r),e}function Dr(r,e=document){return e.querySelector(r)}const Mr={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"},Ir={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"};function Te(r,e,t=!0){let i=r;if(t&&(i=i.filter(n=>!n.hidden&&!n.field.startsWith("__")&&n.meta?.utility!==!0)),e?.length){const n=new Set(e);i=i.filter(o=>n.has(o.field))}return i}function Ze(r,e){return e?.length?[...e].sort((t,i)=>t-i).map(t=>r[t]).filter(t=>t!=null):r}function zr(r){return r==null?"":r instanceof Date?r.toISOString():typeof r=="object"?JSON.stringify(r):String(r)}async function Nr(r){try{return await navigator.clipboard.writeText(r),!0}catch{const e=document.createElement("textarea");e.value=r,e.style.position="fixed",e.style.opacity="0",e.style.pointerEvents="none",document.body.appendChild(e),e.select();const t=document.execCommand("copy");return document.body.removeChild(e),t}}function ei(r,e){const t=e.delimiter??" ",i=e.newline??`
|
|
91
91
|
`,n=r.replace(/\r\n/g,`
|
|
92
92
|
`).replace(/\r/g,`
|
|
93
|
-
`),o=[];let s=[],l="",a=!1;for(let c=0;c<n.length;c++){const d=n[c];d==='"'&&!a?a=!0:d==='"'&&a?n[c+1]==='"'?(l+='"',c++):a=!1:d===t&&!a?(s.push(l),l=""):d===i&&!a?(s.push(l),l="",(s.length>1||s.some(u=>u.trim()!==""))&&o.push(s),s=[]):l+=d}return s.push(l),(s.length>1||s.some(c=>c.trim()!==""))&&o.push(s),o}async function
|
|
94
|
-
`,quoteStrings:!1}}lastCopied=null;attach(e){super.attach(e),e.addEventListener("paste",t=>this.#e(t),{signal:this.disconnectSignal})}detach(){this.lastCopied=null}onKeyDown(e){return(e.ctrlKey||e.metaKey)&&e.key==="c"?(this.#t(e.target),!0):!1}#t(e){const t=this.#c()
|
|
95
|
-
`,h=[],f=this.columns.slice(a,c+1).filter(p=>!X(p));if(this.config.includeHeaders){const p=f.map(g=>g.header||g.field);h.push(p.join(d))}for(let p=s;p<=l;p++){const g=this.rows[p];if(!g)continue;const w=f.map(b=>{const m=g[b.field];return m==null?"":m instanceof Date?m.toISOString():String(m)});h.push(w.join(d))}return{text:h.join(u),rowCount:l-s+1,columnCount:c-a+1}}#l(e){const t=e.closest("[data-field-cache]");if(!t)return null;const i=t.dataset.fieldCache,n=t.dataset.row;if(!i||!n)return null;const o=parseInt(n,10);if(isNaN(o))return null;const s=this.columns.findIndex(l=>l.field===i);return s===-1?null:{row:o,col:s}}async copy(){const e=this.#c(),t=this.columns.length-1;let i={startRow:0,startCol:0,endRow:this.rows.length-1,endCol:t};if(e&&e.ranges.length>0){const o=e.ranges[e.ranges.length-1];e.mode==="row"?i={startRow:o.from.row,startCol:0,endRow:o.to.row,endCol:t}:i={startRow:o.from.row,startCol:o.from.col,endRow:o.to.row,endCol:o.to.col}}const n=this.#i(i);return await Xe(n.text),this.lastCopied={text:n.text,timestamp:Date.now()},n.text}async copyRows(e){if(e.length===0)return"";const t=[...e].sort((s,l)=>s-l),i=this.columns.length-1,n={startRow:t[0],startCol:0,endRow:t[t.length-1],endCol:i},o=this.#i(n);return await Xe(o.text),this.lastCopied={text:o.text,timestamp:Date.now()},o.text}async paste(){const e=await Nr();return e?ei(e,this.config):null}getLastCopied(){return this.lastCopied}}const ii=100;function Ze(r){if(r==null)return ii;if(typeof r=="number")return r;const e=parseFloat(r);return isNaN(e)?ii:e}function ni(r){return r.map(e=>Ze(e.width))}function ri(r){const e=[];let t=0;for(const i of r)e.push(t),t+=Ze(i.width);return e}function oi(r){return r.reduce((e,t)=>e+Ze(t.width),0)}function Fr(r,e,t,i,n){const o=t.length;if(o===0)return{startCol:0,endCol:0,visibleColumns:[]};let s=qr(r,t,i);s=Math.max(0,s-n);const l=r+e;let a=s;for(let d=s;d<o;d++){if(t[d]>=l){a=d-1;break}a=d}a=Math.min(o-1,a+n);const c=[];for(let d=s;d<=a;d++)c.push(d);return{startCol:s,endCol:a,visibleColumns:c}}function qr(r,e,t){let i=0,n=e.length-1;for(;i<n;){const o=Math.floor((i+n)/2);e[o]+t[o]<=r?i=o+1:n=o}return i}function Gr(r,e,t){return t?r>e:!1}class Br extends D{name="columnVirtualization";get defaultConfig(){return{autoEnable:!0,threshold:30,overscan:3}}isVirtualized=!1;startCol=0;endCol=0;scrollLeft=0;totalWidth=0;columnWidths=[];columnOffsets=[];originalColumns=[];attach(e){super.attach(e);const t=this.columns;this.columnWidths=ni(t),this.columnOffsets=ri(t),this.totalWidth=oi(t),this.endCol=t.length-1}detach(){this.#t(),this.columnWidths=[],this.columnOffsets=[],this.originalColumns=[],this.isVirtualized=!1,this.startCol=0,this.endCol=0,this.scrollLeft=0,this.totalWidth=0}#t(){const e=this.gridElement;if(!e)return;const t=e.querySelector(".header-row");t&&(t.style.paddingLeft="",t.style.minWidth=""),e.querySelectorAll(".data-grid-row").forEach(s=>{s.style.paddingLeft=""});const n=e.querySelector(".rows-viewport .rows");n&&(n.style.width="");const o=e.querySelector(".rows-body");o&&(o.style.minWidth="")}processColumns(e){(this.originalColumns.length===0||e.length>this.originalColumns.length)&&(this.originalColumns=e,this.columnWidths=ni(e),this.columnOffsets=ri(e),this.totalWidth=oi(e));const i=this.originalColumns,n=Gr(i.length,this.config.threshold??30,this.config.autoEnable??!0);if(this.isVirtualized=n??!1,!n)return this.startCol=0,this.endCol=i.length-1,[...i];const o=this.grid.clientWidth||800,s=Fr(this.scrollLeft,o,this.columnOffsets,this.columnWidths,this.config.overscan??3);return this.startCol=s.startCol,this.endCol=s.endCol,s.visibleColumns.map(l=>i[l])}afterRender(){if(!this.isVirtualized)return;const e=this.gridElement;if(!e)return;const t=this.columnOffsets[this.startCol]??0,i=e.querySelector(".header-row"),n=e.querySelectorAll(".data-grid-row");i&&(i.style.paddingLeft=`${t}px`,i.style.minWidth=`${this.totalWidth}px`),n.forEach(l=>{l.style.paddingLeft=`${t}px`});const o=e.querySelector(".rows-viewport .rows");o&&(o.style.width=`${this.totalWidth}px`);const s=e.querySelector(".rows-body");s&&(s.style.minWidth=`${this.totalWidth}px`)}onScroll(e){!this.isVirtualized||Math.abs(e.scrollLeft-this.scrollLeft)<1||(this.scrollLeft=e.scrollLeft,this.requestColumnsRender())}getIsVirtualized(){return this.isVirtualized}getVisibleColumnRange(){return{start:this.startCol,end:this.endCol}}scrollToColumn(e){const t=this.columnOffsets[e]??0,i=this.grid;i.scrollLeft=t}getColumnOffset(e){return this.columnOffsets[e]??0}getTotalWidth(){return this.totalWidth}}const Qe="@layer tbw-plugins{.tbw-context-menu{position:fixed;background:var(--tbw-context-menu-bg, var(--tbw-color-panel-bg));color:var(--tbw-context-menu-fg, var(--tbw-color-fg));border:1px solid var(--tbw-context-menu-border, var(--tbw-color-border));border-radius:var(--tbw-context-menu-radius, var(--tbw-border-radius));box-shadow:var(--tbw-context-menu-shadow, 0 2px 10px var(--tbw-color-shadow));min-width:var(--tbw-context-menu-min-width, var(--tbw-menu-min-width));padding:var(--tbw-spacing-xs) 0;z-index:10000;font-size:var(--tbw-context-menu-font-size, var(--tbw-font-size-sm));font-family:var(--tbw-context-menu-font-family, var(--tbw-font-family))}.tbw-context-menu-item{display:flex;align-items:center;padding:var(--tbw-context-menu-item-padding, var(--tbw-menu-item-padding));cursor:pointer;gap:var(--tbw-context-menu-item-gap, var(--tbw-menu-item-gap))}.tbw-context-menu-item:hover:not(.disabled){background:var(--tbw-context-menu-hover, var(--tbw-color-row-hover))}.tbw-context-menu-item.disabled{opacity:.5;cursor:default}.tbw-context-menu-item.danger{color:var(--tbw-context-menu-danger, var(--tbw-color-danger))}.tbw-context-menu-icon{width:var(--tbw-context-menu-icon-size, var(--tbw-icon-size));text-align:center}.tbw-context-menu-label{flex:1}.tbw-context-menu-shortcut{color:var(--tbw-context-menu-muted, var(--tbw-color-fg-muted));font-size:var(--tbw-context-menu-shortcut-size, var(--tbw-font-size-xs))}.tbw-context-menu-arrow{font-size:var(--tbw-context-menu-arrow-size, var(--tbw-font-size-2xs));color:var(--tbw-context-menu-muted, var(--tbw-color-fg-muted))}.tbw-context-menu-separator{height:1px;background:var(--tbw-context-menu-border, var(--tbw-color-border));margin:var(--tbw-spacing-xs) 0}}";function Je(r,e){return(typeof r=="function"?r(e):r).filter(i=>!(i.hidden===!0||typeof i.hidden=="function"&&i.hidden(e)))}function Kr(r,e){return r.disabled===!0?!0:typeof r.disabled=="function"?r.disabled(e):!1}function et(r,e,t,i=G.submenuArrow){const n=document.createElement("div");n.className="tbw-context-menu",n.setAttribute("role","menu");for(const o of r){if(o.separator){const c=document.createElement("div");c.className="tbw-context-menu-separator",c.setAttribute("role","separator"),n.appendChild(c);continue}const s=document.createElement("div");s.className="tbw-context-menu-item",o.cssClass&&s.classList.add(o.cssClass),s.setAttribute("role","menuitem"),s.setAttribute("data-id",o.id);const l=Kr(o,e);if(l&&(s.classList.add("disabled"),s.setAttribute("aria-disabled","true")),o.icon){const c=document.createElement("span");c.className="tbw-context-menu-icon",c.innerHTML=o.icon,s.appendChild(c)}const a=document.createElement("span");if(a.className="tbw-context-menu-label",a.textContent=o.name,s.appendChild(a),o.shortcut){const c=document.createElement("span");c.className="tbw-context-menu-shortcut",c.textContent=o.shortcut,s.appendChild(c)}if(o.subMenu?.length){const c=document.createElement("span");c.className="tbw-context-menu-arrow",typeof i=="string"?c.innerHTML=i:i instanceof HTMLElement&&c.appendChild(i.cloneNode(!0)),s.appendChild(c),s.addEventListener("mouseenter",()=>{if(s.querySelector(".tbw-context-menu")||!o.subMenu)return;const u=Je(o.subMenu,e),h=et(u,e,t,i);h.classList.add("tbw-context-submenu"),h.style.position="absolute",h.style.left="100%",h.style.top="0",s.style.position="relative",s.appendChild(h)}),s.addEventListener("mouseleave",()=>{const d=s.querySelector(".tbw-context-menu");d&&d.remove()})}!l&&o.action&&!o.subMenu&&s.addEventListener("click",c=>{c.stopPropagation(),t(o)}),n.appendChild(s)}return n}function si(r,e,t){r.style.position="fixed",r.style.left=`${e}px`,r.style.top=`${t}px`,r.style.visibility="hidden",r.style.zIndex="10000";const i=r.getBoundingClientRect(),n=window.innerWidth,o=window.innerHeight;let s=e,l=t;e+i.width>n&&(s=e-i.width),t+i.height>o&&(l=t-i.height),s=Math.max(0,s),l=Math.max(0,l),r.style.left=`${s}px`,r.style.top=`${l}px`,r.style.visibility="visible"}let te=null,ie=null,U=null,tt=0;const it=[{id:"copy",name:"Copy",shortcut:"Ctrl+C",action:r=>{r.grid?.plugins?.clipboard?.copy?.()}},{separator:!0,id:"sep1",name:""},{id:"export-csv",name:"Export CSV",action:r=>{r.grid?.plugins?.export?.exportCsv?.()}}];class nt extends D{name="contextMenu";get defaultConfig(){return{items:it}}isOpen=!1;position={x:0,y:0};params=null;menuElement=null;attach(e){super.attach(e),this.installGlobalHandlers(),tt++}detach(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null),this.isOpen=!1,this.params=null,this.uninstallGlobalHandlers()}static CSS_VARS_TO_COPY=["--tbw-color-panel-bg","--tbw-color-fg","--tbw-color-fg-muted","--tbw-color-border","--tbw-color-row-hover","--tbw-color-shadow","--tbw-color-danger","--tbw-border-radius","--tbw-font-family","--tbw-font-size-sm","--tbw-font-size-xs","--tbw-font-size-2xs","--tbw-spacing-xs","--tbw-icon-size","--tbw-menu-min-width","--tbw-menu-item-padding","--tbw-menu-item-gap","--tbw-context-menu-bg","--tbw-context-menu-fg","--tbw-context-menu-border","--tbw-context-menu-radius","--tbw-context-menu-shadow","--tbw-context-menu-hover","--tbw-context-menu-danger","--tbw-context-menu-muted","--tbw-context-menu-min-width","--tbw-context-menu-font-size","--tbw-context-menu-font-family","--tbw-context-menu-item-padding","--tbw-context-menu-item-gap","--tbw-context-menu-icon-size","--tbw-context-menu-shortcut-size","--tbw-context-menu-arrow-size"];copyGridStyles(e){const t=this.gridElement;if(!t)return;const i=getComputedStyle(t),n=[],o=i.getPropertyValue("color-scheme").trim();o&&n.push(`color-scheme: ${o}`);for(const s of nt.CSS_VARS_TO_COPY){const l=i.getPropertyValue(s).trim();l&&n.push(`${s}: ${l}`)}if(n.length>0){const s=e.getAttribute("style")||"";e.setAttribute("style",s+n.join("; ")+";")}}installGlobalHandlers(){!U&&typeof document<"u"&&typeof Qe=="string"&&Qe&&(U=document.createElement("style"),U.id="tbw-context-menu-styles",U.textContent=Qe,document.head.appendChild(U)),te||(te=()=>{document.querySelectorAll(".tbw-context-menu").forEach(t=>t.remove())},document.addEventListener("click",te)),ie||(ie=e=>{e.key==="Escape"&&document.querySelectorAll(".tbw-context-menu").forEach(i=>i.remove())},document.addEventListener("keydown",ie))}uninstallGlobalHandlers(){tt--,!(tt>0)&&(te&&(document.removeEventListener("click",te),te=null),ie&&(document.removeEventListener("keydown",ie),ie=null),U&&(U.remove(),U=null))}afterRender(){const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-grid-root");t&&t.getAttribute("data-context-menu-bound")!=="true"&&(t.setAttribute("data-context-menu-bound","true"),t.addEventListener("contextmenu",i=>{const n=i;n.preventDefault();const o=n.target,s=o.closest("[data-row][data-col]"),l=o.closest(".header-cell");let a;if(s){const d=parseInt(s.getAttribute("data-row")??"-1",10),u=parseInt(s.getAttribute("data-col")??"-1",10),h=this.columns[u],f=this.rows[d];a={row:f,rowIndex:d,column:h,columnIndex:u,field:h?.field??"",value:f?.[h?.field]??null,isHeader:!1,event:n}}else if(l){const d=parseInt(l.getAttribute("data-col")??"-1",10),u=this.columns[d];a={row:null,rowIndex:-1,column:u,columnIndex:d,field:u?.field??"",value:null,isHeader:!0,event:n}}else return;this.params=a,this.position={x:n.clientX,y:n.clientY};const c=Je(this.config.items??it,a);c.length&&(this.menuElement&&this.menuElement.remove(),this.menuElement=et(c,a,d=>{d.action&&d.action(a),this.menuElement?.remove(),this.menuElement=null,this.isOpen=!1},this.gridIcons.submenuArrow),document.body.appendChild(this.menuElement),this.copyGridStyles(this.menuElement),si(this.menuElement,n.clientX,n.clientY),this.isOpen=!0,this.emit("context-menu-open",{params:a,items:c}))}))}showMenu(e,t,i){const n={row:i.row??null,rowIndex:i.rowIndex??-1,column:i.column??null,columnIndex:i.columnIndex??-1,field:i.field??"",value:i.value??null,isHeader:i.isHeader??!1,event:i.event??new MouseEvent("contextmenu")},o=Je(this.config.items??it,n);this.menuElement&&this.menuElement.remove(),this.menuElement=et(o,n,s=>{s.action&&s.action(n),this.menuElement?.remove(),this.menuElement=null,this.isOpen=!1},this.gridIcons.submenuArrow),document.body.appendChild(this.menuElement),this.copyGridStyles(this.menuElement),si(this.menuElement,e,t),this.isOpen=!0}hideMenu(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null,this.isOpen=!1)}isMenuOpen(){return this.isOpen}}const $r="@layer tbw-plugins{tbw-grid{--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-row-bg: var(--tbw-editing-bg);--tbw-editing-border: var(--tbw-border-input, 1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input: var(--tbw-cell-padding-input, 2px 6px);--tbw-font-size-editor: inherit;--tbw-editing-row-outline-color: var(--tbw-color-accent);--tbw-editing-row-outline-width: 1px;--tbw-invalid-bg: light-dark(#fef2f2, #450a0a);--tbw-invalid-border-color: light-dark(#ef4444, #f87171)}tbw-grid:not(.tbw-grid-mode) .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}tbw-grid .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex;min-height:calc(var(--tbw-row-height) + 2px);align-items:center;justify-content:center}tbw-grid .data-grid-row>.cell.editing input:not([type=checkbox]),tbw-grid .data-grid-row>.cell.editing select,tbw-grid .data-grid-row>.cell.editing textarea{width:100%;height:100%;flex:1 1 auto;min-width:0;border:var(--tbw-editing-border);padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor)}tbw-grid .tbw-editor-host{display:contents}tbw-grid .data-grid-row>.cell[data-invalid=true]{background:var(--tbw-invalid-bg);outline:1px solid var(--tbw-invalid-border-color);outline-offset:-1px}}";function Wr(r){const e=r.options;return e?typeof e=="function"?e():e:[]}function Vr(r){return e=>{const t=r.editorParams,i=document.createElement("input");i.type="number",i.value=e.value!=null?String(e.value):"",t?.min!==void 0&&(i.min=String(t.min)),t?.max!==void 0&&(i.max=String(t.max)),t?.step!==void 0&&(i.step=String(t.step)),t?.placeholder&&(i.placeholder=t.placeholder);const n=()=>e.commit(i.value===""?null:Number(i.value));return i.addEventListener("blur",n),i.addEventListener("keydown",o=>{o.key==="Enter"&&n(),o.key==="Escape"&&e.cancel()}),i}}function Ur(){return r=>{const e=document.createElement("input");return e.type="checkbox",e.checked=!!r.value,e.addEventListener("change",()=>r.commit(e.checked)),e}}function jr(r){return e=>{const t=r.editorParams,i=document.createElement("input");i.type="date",e.value instanceof Date?i.valueAsDate=e.value:typeof e.value=="string"&&e.value&&(i.value=e.value.split("T")[0]),t?.min&&(i.min=t.min),t?.max&&(i.max=t.max),t?.placeholder&&(i.placeholder=t.placeholder);const n=()=>{typeof e.value=="string"?e.commit(i.value):e.commit(i.valueAsDate)};return i.addEventListener("change",n),i.addEventListener("keydown",o=>{o.key==="Escape"&&e.cancel()}),i}}function Yr(r){return e=>{const t=r.editorParams,i=document.createElement("select");if(r.multi&&(i.multiple=!0),t?.includeEmpty){const s=document.createElement("option");s.value="",s.textContent=t.emptyLabel??"",i.appendChild(s)}Wr(r).forEach(s=>{const l=document.createElement("option");l.value=String(s.value),l.textContent=s.label,(r.multi&&Array.isArray(e.value)&&e.value.includes(s.value)||!r.multi&&e.value===s.value)&&(l.selected=!0),i.appendChild(l)});const o=()=>{if(r.multi){const s=Array.from(i.selectedOptions).map(l=>l.value);e.commit(s)}else e.commit(i.value)};return i.addEventListener("change",o),i.addEventListener("blur",o),i.addEventListener("keydown",s=>{s.key==="Escape"&&e.cancel()}),i}}function Xr(r){return e=>{const t=r.editorParams,i=document.createElement("input");i.type="text",i.value=e.value!=null?String(e.value):"",t?.maxLength!==void 0&&(i.maxLength=t.maxLength),t?.pattern&&(i.pattern=t.pattern),t?.placeholder&&(i.placeholder=t.placeholder);const n=()=>{const o=i.value;(e.value===null||e.value===void 0)&&o===""||typeof e.value=="string"&&o===e.value.replace(/[\n\r]/g,"")||(typeof e.value=="number"&&o!==""?e.commit(Number(o)):e.commit(o))};return i.addEventListener("blur",n),i.addEventListener("keydown",o=>{o.key==="Enter"&&n(),o.key==="Escape"&&e.cancel()}),i}}function li(r){switch(r.type){case"number":return Vr(r);case"boolean":return Ur();case"date":return jr(r);case"select":return Yr(r);default:return Xr(r)}}function Zr(r,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=r.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const n=r.__frameworkAdapter;if(n?.getTypeDefault){const o=n.getTypeDefault(e.type);if(o?.editor)return o.editor}}function fe(r){return!(typeof r!="string"||r==="__proto__"||r==="constructor"||r==="prototype")}function Qr(r){const e=(r.__editingCellCount??0)+1;r.__editingCellCount=e,r.setAttribute("data-has-editing","")}function Jr(r){r.__editingCellCount=0,r.removeAttribute("data-has-editing")}function ne(r,e,t){return r instanceof HTMLInputElement?r.type==="checkbox"?r.checked:r.type==="number"?r.value===""?null:Number(r.value):r.type==="date"?typeof t=="string"?r.value:r.valueAsDate:typeof t=="number"?r.value===""?null:Number(r.value):t==null&&r.value===""||typeof t=="string"&&r.value===t.replace(/[\n\r]/g,"")?t:r.value:e?.type==="number"&&r.value!==""||typeof t=="number"&&r.value!==""?Number(r.value):t==null&&r.value===""?t:r.value}function ai(r){}function eo(r,e,t,i){const n=r.querySelector("input,textarea,select");n&&(n.addEventListener("blur",()=>{t(ne(n,e,i))}),n instanceof HTMLInputElement&&n.type==="checkbox"?n.addEventListener("change",()=>t(n.checked)):n instanceof HTMLSelectElement&&n.addEventListener("change",()=>t(ne(n,e,i))))}class to extends D{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:e=>e===!0},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'}],events:[{type:"cell-edit-committed",description:"Emitted when a cell edit is committed (for plugin-to-plugin coordination)"}],queries:[{type:"isEditing",description:"Returns whether any cell is currently being edited"}]};name="editing";styles=$r;get defaultConfig(){return{mode:"row",editOn:"click"}}get#t(){return this.config.mode==="grid"}#e=-1;#u=-1;#c=new Map;#i=new Set;#l=new Set;#n=!1;#f=-1;#h=new Map;#w=!1;#a=!1;attach(e){super.attach(e);const t=this.disconnectSignal,i=e;i._activeEditRows=-1,i._rowEditSnapshots=new Map,Object.defineProperty(e,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(e,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),e.resetChangedRows=n=>this.resetChangedRows(n),e.beginBulkEdit=(n,o)=>{o&&this.beginCellEdit(n,o)},document.addEventListener("keydown",n=>{if(!this.#t&&n.key==="Escape"&&this.#e!==-1){if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(n)===!1)return;this.#m(this.#e,!0)}},{capture:!0,signal:t}),document.addEventListener("mousedown",n=>{if(this.#t||this.#e===-1)return;const o=i.findRenderedRowElement?.(this.#e);!o||(n.composedPath&&n.composedPath()||[]).includes(o)||this.config.onBeforeEditClose&&this.config.onBeforeEditClose(n)===!1||queueMicrotask(()=>{this.#e!==-1&&this.#m(this.#e,!1)})},{signal:t}),this.#t&&(this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.gridElement.addEventListener("focusin",n=>{const o=n.target;if(o.matches(B)){if(this.#a){o.blur(),this.gridElement.focus();return}this.#w=!0}},{signal:t}),this.gridElement.addEventListener("focusout",n=>{const o=n.relatedTarget;(!o||!this.gridElement.contains(o)||!o.matches(B))&&(this.#w=!1)},{signal:t}),this.gridElement.addEventListener("keydown",n=>{if(n.key==="Escape"&&this.#w){const o=document.activeElement;o&&this.gridElement.contains(o)&&(o.blur(),this.gridElement.focus()),this.#w=!1,this.#a=!0,n.preventDefault(),n.stopPropagation()}},{capture:!0,signal:t}),this.gridElement.addEventListener("mousedown",n=>{n.target.matches(B)&&(this.#a=!1)},{signal:t}))}detach(){this.gridElement.classList.remove("tbw-grid-mode"),this.#e=-1,this.#u=-1,this.#c.clear(),this.#i.clear(),this.#l.clear(),this.#w=!1,this.#a=!1,super.detach()}handleQuery(e){if(e.type==="isEditing")return this.#t||this.#e!==-1}onCellClick(e){if(this.#t)return!1;const t=this.grid,i=this.config.editOn??t.effectiveConfig?.editOn;if(i===!1||i==="manual"||i!=="click"&&i!=="dblclick")return!1;const n=e.originalEvent.type==="dblclick";if(i==="click"&&n||i==="dblclick"&&!n)return!1;const{rowIndex:o}=e;return t._columns?.some(l=>l.editable)?(e.originalEvent.stopPropagation(),this.beginBulkEdit(o),!0):!1}onKeyDown(e){const t=this.grid;if(e.key==="Escape"){if(this.#t&&this.#w){const i=document.activeElement;return i&&this.gridElement.contains(i)&&i.blur(),this.#w=!1,this.requestAfterRender(),!0}if(this.#e!==-1&&!this.#t)return this.config.onBeforeEditClose&&this.config.onBeforeEditClose(e)===!1||this.#m(this.#e,!0),!0}if(this.#t&&!this.#w&&(e.key==="ArrowUp"||e.key==="ArrowDown"||e.key==="ArrowLeft"||e.key==="ArrowRight"))return!1;if((e.key==="ArrowUp"||e.key==="ArrowDown")&&this.#e!==-1&&!this.#t){if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(e)===!1)return!0;const i=t._rows.length-1,n=this.#e;return this.#m(n,!1),e.key==="ArrowDown"?t._focusRow=Math.min(i,t._focusRow+1):t._focusRow=Math.max(0,t._focusRow-1),e.preventDefault(),M(t),this.requestAfterRender(),!0}if(e.key==="Tab"&&(this.#e!==-1||this.#t)){e.preventDefault();const i=!e.shiftKey;return this.#R(i),!0}if(e.key===" "||e.key==="Spacebar"){if(this.#e!==-1)return!1;const i=t._focusRow,n=t._focusCol;if(i>=0&&n>=0){const o=t._visibleColumns[n],s=t._rows[i];if(o?.editable&&o.type==="boolean"&&s){const l=o.field;if(fe(l)){const c=!s[l];return this.#y(i,o,c,s),e.preventDefault(),this.requestRender(),!0}}}return!1}if(e.key==="Enter"&&!e.shiftKey){if(this.#t&&!this.#w)return this.#g(),!0;if(this.#e!==-1)return!!(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(e)===!1);const i=this.config.editOn??t.effectiveConfig?.editOn;if(i===!1||i==="manual")return!1;const n=t._focusRow,o=t._focusCol;if(n>=0&&t._columns?.some(l=>l.editable)){const l=t._visibleColumns[o],a=t._rows[n],c=l?.field??"",d=c&&a?a[c]:void 0,u=this.gridElement.querySelector(`[data-row="${n}"][data-col="${o}"]`),h=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:n,colIndex:o,field:c,value:d,row:a,cellEl:u,trigger:"keyboard",originalEvent:e}});this.gridElement.dispatchEvent(h);const f=new CustomEvent("activate-cell",{cancelable:!0,bubbles:!0,detail:{row:n,col:o}});return this.gridElement.dispatchEvent(f),h.defaultPrevented||f.defaultPrevented?(e.preventDefault(),!0):(this.beginBulkEdit(n),!0)}return!1}return!1}processColumns(e){const t=this.grid,i=t.effectiveConfig?.typeDefaults,n=t.__frameworkAdapter;return!i&&!n?.getTypeDefault?e:e.map(o=>{if(!o.type)return o;let s;if(i?.[o.type]?.editorParams&&(s=i[o.type].editorParams),!s&&n?.getTypeDefault){const l=n.getTypeDefault(o.type);l?.editorParams&&(s=l.editorParams)}return s?{...o,editorParams:{...s,...o.editorParams}}:o})}afterRender(){const e=this.grid;if(this.#n&&(this.#n=!1,this.#A(e)),this.#f!==-1){const t=this.#f;this.#f=-1,e.animateRow?.(t,"change")}if(!this.#t&&this.#l.size!==0)for(const t of this.#l){const[i,n]=t.split(":"),o=parseInt(i,10),s=parseInt(n,10),l=e.findRenderedRowElement?.(o);if(!l)continue;const a=l.querySelector(`.cell[data-col="${s}"]`);if(!a||a.classList.contains("editing"))continue;const c=e._rows[o],d=e._visibleColumns[s];c&&d&&this.#E(c,o,d,s,a,!0)}}afterCellRender(e){if(!this.#t)return;const{row:t,rowIndex:i,column:n,colIndex:o,cellElement:s}=e;n.editable&&(s.classList.contains("editing")||this.#E(t,i,n,o,s,!0))}onScrollRender(){this.afterRender()}get changedRows(){const e=[];for(const t of this.#i){const i=this.grid.getRow(t);i&&e.push(i)}return e}get changedRowIds(){return Array.from(this.#i)}get activeEditRow(){return this.#e}get activeEditCol(){return this.#u}isRowEditing(e){return this.#e===e}isCellEditing(e,t){return this.#l.has(`${e}:${t}`)}isRowChanged(e){const t=this.grid,i=t._rows[e];if(!i)return!1;try{const n=t.getRowId?.(i);return n?this.#i.has(n):!1}catch{return!1}}isRowChangedById(e){return this.#i.has(e)}setInvalid(e,t,i=""){let n=this.#h.get(e);n||(n=new Map,this.#h.set(e,n)),n.set(t,i),this.#v(e,t,!0)}clearInvalid(e,t){const i=this.#h.get(e);i&&(i.delete(t),i.size===0&&this.#h.delete(e)),this.#v(e,t,!1)}clearRowInvalid(e){const t=this.#h.get(e);if(t){const i=Array.from(t.keys());this.#h.delete(e),i.forEach(n=>this.#v(e,n,!1))}}clearAllInvalid(){const e=Array.from(this.#h.entries());this.#h.clear(),e.forEach(([t,i])=>{i.forEach((n,o)=>this.#v(t,o,!1))})}isCellInvalid(e,t){return this.#h.get(e)?.has(t)??!1}getInvalidMessage(e,t){return this.#h.get(e)?.get(t)}hasInvalidCells(e){const t=this.#h.get(e);return t?t.size>0:!1}getInvalidFields(e){return new Map(this.#h.get(e)??[])}#v(e,t,i){const n=this.grid,o=n._visibleColumns?.findIndex(d=>d.field===t);if(o===-1||o===void 0)return;const l=n._rows?.findIndex(d=>{try{return n.getRowId?.(d)===e}catch{return!1}});if(l===-1||l===void 0)return;const c=n.findRenderedRowElement?.(l)?.querySelector(`.cell[data-col="${o}"]`);if(c)if(i){c.setAttribute("data-invalid","true");const d=this.#h.get(e)?.get(t);d&&c.setAttribute("title",d)}else c.removeAttribute("data-invalid"),c.removeAttribute("title")}resetChangedRows(e){const t=this.changedRows,i=this.changedRowIds;this.#i.clear(),this.#p(),e||this.emit("changed-rows-reset",{rows:t,ids:i}),this.grid._rowPool?.forEach(o=>o.classList.remove("changed"))}beginCellEdit(e,t){const i=this.grid,n=i._visibleColumns.findIndex(a=>a.field===t);if(n===-1||!i._visibleColumns[n]?.editable)return;const l=i.findRenderedRowElement?.(e)?.querySelector(`.cell[data-col="${n}"]`);l&&this.#d(e,n,l)}beginBulkEdit(e){const t=this.grid;if((this.config.editOn??t.effectiveConfig?.editOn)===!1||!t._columns?.some(l=>l.editable))return;const o=t.findRenderedRowElement?.(e);if(!o)return;const s=t._rows[e];this.#x(e,s),Array.from(o.children).forEach((l,a)=>{const c=t._visibleColumns[a];if(c?.editable){const d=l;d.classList.contains("editing")||this.#E(s,e,c,a,d,!0)}}),setTimeout(()=>{let l=o.querySelector(`.cell[data-col="${t._focusCol}"]`);if(l?.classList.contains("editing")||(l=o.querySelector(".cell.editing")),l?.classList.contains("editing")){const a=l.querySelector(B);try{a?.focus({preventScroll:!0})}catch{}}},0)}commitActiveRowEdit(){this.#e!==-1&&this.#m(this.#e,!1)}cancelActiveRowEdit(){this.#e!==-1&&this.#m(this.#e,!0)}#d(e,t,i){const n=this.grid,o=n._rows[e],s=n._visibleColumns[t];!o||!s?.editable||i.classList.contains("editing")||(this.#e!==e&&this.#x(e,o),this.#u=t,this.#E(o,e,s,t,i,!1))}#g(){const e=this.grid,t=e._focusRow,i=e._focusCol;if(t<0||i<0)return;const o=e.findRenderedRowElement?.(t)?.querySelector(`.cell[data-col="${i}"]`);if(o?.classList.contains("editing")){const s=o.querySelector(B);s&&(this.#a=!1,s.focus(),this.#w=!0,s instanceof HTMLInputElement&&(s.type==="text"||s.type==="number")&&s.select())}}#R(e){const t=this.grid,i=t._rows,n=this.#t?t._focusRow:this.#e,o=t._visibleColumns.map((c,d)=>c.editable?d:-1).filter(c=>c>=0);if(o.length===0)return;const l=o.indexOf(t._focusCol)+(e?1:-1);if(l>=0&&l<o.length){t._focusCol=o[l];const d=t.findRenderedRowElement?.(n)?.querySelector(`.cell[data-col="${o[l]}"]`);d?.classList.contains("editing")&&d.querySelector(B)?.focus({preventScroll:!0}),M(t,{forceHorizontalScroll:!0});return}const a=n+(e?1:-1);a>=0&&a<i.length&&(this.#t?(t._focusRow=a,t._focusCol=e?o[0]:o[o.length-1],M(t,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const d=t.findRenderedRowElement?.(a)?.querySelector(`.cell[data-col="${t._focusCol}"]`);d?.classList.contains("editing")&&d.querySelector(B)?.focus({preventScroll:!0})},0)):(this.#m(n,!1),t._focusRow=a,t._focusCol=e?o[0]:o[o.length-1],this.beginBulkEdit(a),M(t,{forceHorizontalScroll:!0})))}#p(){const e=this.grid;e._activeEditRows=this.#e,e._rowEditSnapshots=this.#c}#x(e,t){if(this.#e!==e&&(this.#c.set(e,{...t}),this.#e=e,this.#p(),!this.#t)){const i=this.grid;let n="";try{n=i.getRowId?.(t)??""}catch{}this.emit("edit-open",{rowIndex:e,rowId:n,row:t})}}#m(e,t){if(this.#e!==e)return;const i=this.grid,n=this.#c.get(e),o=i._rows[e],s=i.findRenderedRowElement?.(e);let l;if(o)try{l=i.getRowId?.(o)}catch{}if(!t&&s&&o&&s.querySelectorAll(".cell.editing").forEach(c=>{const d=Number(c.getAttribute("data-col"));if(isNaN(d))return;const u=i._visibleColumns[d];if(!u||c.hasAttribute("data-editor-managed"))return;const h=c.querySelector("input,textarea,select");if(h){const f=u.field,p=o[f],g=ne(h,u,p);p!==g&&this.#y(e,u,g,o)}}),t&&n&&o)Object.keys(n).forEach(a=>{o[a]=n[a]}),l&&(this.#i.delete(l),this.clearRowInvalid(l));else if(!t&&o){const a=this.#S(n,o),c=l?this.#i.has(l):a,d=this.emitCancelable("row-commit",{rowIndex:e,rowId:l??"",row:o,oldValue:n,newValue:o,changed:c,changedRows:this.changedRows,changedRowIds:this.changedRowIds});d&&n?(Object.keys(n).forEach(u=>{o[u]=n[u]}),l&&(this.#i.delete(l),this.clearRowInvalid(l))):!d&&a&&this.isAnimationEnabled&&(this.#f=e)}this.#c.delete(e),this.#e=-1,this.#u=-1,this.#p();for(const a of this.#l)a.startsWith(`${e}:`)&&this.#l.delete(a);s&&(s.querySelectorAll(".cell.editing").forEach(a=>{a.classList.remove("editing"),Jr(a.parentElement)}),this.requestRender()),this.#n=!0,s||(this.#A(i),this.#n=!1),!this.#t&&o&&this.emit("edit-close",{rowIndex:e,rowId:l??"",row:o,reverted:t})}#y(e,t,i,n){const o=t.field;if(!fe(o))return;const s=n[o];if(s===i)return;const l=this.grid;let a;try{a=this.grid.getRowId(n)}catch{}const c=a?!this.#i.has(a):!0,d=a?g=>this.grid.updateRow(a,g,"cascade"):ai;let u=!1;const h=a?g=>{u=!0,this.setInvalid(a,o,g??"")}:()=>{};if(this.emitCancelable("cell-commit",{row:n,rowId:a??"",field:o,oldValue:s,value:i,rowIndex:e,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:c,updateRow:d,setInvalid:h}))return;a&&!u&&this.isCellInvalid(a,o)&&this.clearInvalid(a,o),n[o]=i,a&&this.#i.add(a),this.#p(),this.emitPluginEvent("cell-edit-committed",{rowIndex:e,field:o,oldValue:s,newValue:i});const p=l.findRenderedRowElement?.(e);p&&p.classList.add("changed")}#E(e,t,i,n,o,s){if(!i.editable||o.classList.contains("editing"))return;let l;try{l=this.grid.getRowId(e)}catch{}const a=l?v=>this.grid.updateRow(l,v,"cascade"):ai,c=fe(i.field)?e[i.field]:void 0;o.classList.add("editing"),this.#l.add(`${t}:${n}`);const d=o.parentElement;d&&Qr(d);let u=!1;const h=v=>{u||!this.#t&&this.#e===-1||this.#y(t,i,v,e)},f=()=>{u=!0,fe(i.field)&&(e[i.field]=c)},p=document.createElement("div");p.className="tbw-editor-host",o.innerHTML="",o.appendChild(p),p.addEventListener("keydown",v=>{if(v.key==="Enter"){if(this.#t){v.stopPropagation(),v.preventDefault();const x=p.querySelector("input,textarea,select");x&&h(ne(x,i,c));return}if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(v)===!1)return;v.stopPropagation(),v.preventDefault(),u=!0,this.#m(t,!1)}if(v.key==="Escape"){if(this.#t){v.stopPropagation(),v.preventDefault();return}if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(v)===!1)return;v.stopPropagation(),v.preventDefault(),f(),this.#m(t,!0)}});const g=i,w=g.__editorTemplate,b=Zr(this.grid,g)??li(i),m=c;if(b==="template"&&w)this.#C(p,g,e,c,h,f,s,t);else if(typeof b=="string"){const v=document.createElement(b);v.value=m,v.addEventListener("change",()=>h(v.value)),p.appendChild(v),s||queueMicrotask(()=>{p.querySelector(B)?.focus({preventScroll:!0})})}else if(typeof b=="function"){const v={row:e,rowId:l??"",value:m,field:i.field,column:i,commit:h,cancel:f,updateRow:a},x=b(v);typeof x=="string"?(p.innerHTML=x,eo(p,i,h,c)):x instanceof Node&&(p.appendChild(x),x instanceof HTMLInputElement||x instanceof HTMLSelectElement||x instanceof HTMLTextAreaElement||o.setAttribute("data-editor-managed","")),s||queueMicrotask(()=>{p.querySelector(B)?.focus({preventScroll:!0})})}else if(b&&typeof b=="object"){const v=document.createElement("div");v.setAttribute("data-external-editor",""),v.setAttribute("data-field",i.field),p.appendChild(v),o.setAttribute("data-editor-managed","");const x={row:e,rowId:l??"",value:m,field:i.field,column:i,commit:h,cancel:f,updateRow:a};if(b.mount)try{b.mount({placeholder:v,context:x,spec:b})}catch(S){console.warn(`[tbw-grid] External editor mount error for column '${i.field}':`,S)}else this.grid.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:v,spec:b,context:x}}))}}#C(e,t,i,n,o,s,l,a){const c=t.__editorTemplate;if(!c)return;const d=c.cloneNode(!0),u=t.__compiledEditor;u?d.innerHTML=u({row:i,value:n,field:t.field,column:t,commit:o,cancel:s}):d.querySelectorAll("*").forEach(f=>{f.childNodes.length===1&&f.firstChild?.nodeType===Node.TEXT_NODE&&(f.textContent=f.textContent?.replace(/{{\s*value\s*}}/g,n==null?"":String(n)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(p,g)=>{if(!fe(g))return"";const w=i[g];return w==null?"":String(w)})||"")});const h=d.querySelector("input,textarea,select");if(h){h instanceof HTMLInputElement&&h.type==="checkbox"?h.checked=!!n:h.value=String(n??"");let f=!1;h.addEventListener("blur",()=>{f||o(ne(h,t,n))}),h.addEventListener("keydown",p=>{const g=p;if(g.key==="Enter"){if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(g)===!1)return;g.stopPropagation(),g.preventDefault(),f=!0,o(ne(h,t,n)),this.#m(a,!1)}if(g.key==="Escape"){if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(g)===!1)return;g.stopPropagation(),g.preventDefault(),s(),this.#m(a,!0)}}),h instanceof HTMLInputElement&&h.type==="checkbox"&&h.addEventListener("change",()=>o(h.checked)),l||setTimeout(()=>h.focus({preventScroll:!0}),0)}e.appendChild(d)}#S(e,t){if(!e)return!1;const i=e,n=t,o=new Set([...Object.keys(i),...Object.keys(n)]);for(const s of o)if(i[s]!==n[s])return!0;return!1}#A(e){queueMicrotask(()=>{try{const t=e._focusRow,i=e._focusCol,n=e.findRenderedRowElement?.(t);if(n){Array.from(e._bodyEl.querySelectorAll(".cell-focus")).forEach(s=>s.classList.remove("cell-focus"));const o=n.querySelector(`.cell[data-row="${t}"][data-col="${i}"]`);o&&(o.classList.add("cell-focus"),o.setAttribute("aria-selected","true"),o.hasAttribute("tabindex")||o.setAttribute("tabindex","-1"),o.focus({preventScroll:!0}))}}catch{}})}}function ci(r,e=!0){if(r==null)return"";if(r instanceof Date)return r.toISOString();if(typeof r=="object")return JSON.stringify(r);const t=String(r);return e&&(t.includes(",")||t.includes('"')||t.includes(`
|
|
96
|
-
`)||t.includes("\r"))?`"${t.replace(/"/g,'""')}"`:t}function
|
|
97
|
-
`,s=[],l=i.bom?"\uFEFF":"";if(t.includeHeaders!==!1){const a=e.map(c=>{const d=c.header||c.field,u=t.processHeader?t.processHeader(d,c.field):d;return ci(u)});s.push(a.join(n))}for(const a of r){const c=e.map(d=>{let u=a[d.field];return t.processCell&&(u=t.processCell(u,d.field,a)),ci(u)});s.push(c.join(n))}return l+s.join(o)}function
|
|
93
|
+
`),o=[];let s=[],l="",a=!1;for(let c=0;c<n.length;c++){const d=n[c];d==='"'&&!a?a=!0:d==='"'&&a?n[c+1]==='"'?(l+='"',c++):a=!1:d===t&&!a?(s.push(l),l=""):d===i&&!a?(s.push(l),l="",(s.length>1||s.some(u=>u.trim()!==""))&&o.push(s),s=[]):l+=d}return s.push(l),(s.length>1||s.some(c=>c.trim()!==""))&&o.push(s),o}async function Or(){try{return await navigator.clipboard.readText()}catch{return""}}function ti(r,e){const{rows:t,target:i,fields:n}=r;if(!i)return;const o=e.rows,s=e.effectiveConfig.columns??[],l=s.map(u=>u.field),a=new Map;s.forEach(u=>{a.set(u.field,u.editable===!0)});const c=[...o],d=i.bounds?i.bounds.endRow:1/0;t.forEach((u,h)=>{const f=i.row+h;if(!(f>d)){if(i.bounds){if(f>=c.length)return}else for(;f>=c.length;){const p={};l.forEach(g=>p[g]=""),c.push(p)}c[f]={...c[f]},u.forEach((p,g)=>{const w=n[g];w&&a.get(w)&&(c[f][w]=p)})}}),e.rows=c}class Fr extends D{static dependencies=[{name:"selection",required:!1,reason:"Enables copy/paste of selected cells instead of entire grid"}];name="clipboard";get defaultConfig(){return{includeHeaders:!1,delimiter:" ",newline:`
|
|
94
|
+
`,quoteStrings:!1}}lastCopied=null;attach(e){super.attach(e),e.addEventListener("paste",t=>this.#e(t),{signal:this.disconnectSignal})}detach(){this.lastCopied=null}onKeyDown(e){return(e.ctrlKey||e.metaKey)&&e.key==="c"?(this.#t(e.target),!0):!1}#t(e){const t=this.#c();if(t&&t.ranges.length===0){const i=this.#i(e);if(!i)return;const n=this.columns[i.col];if(!n)return;this.copy({rowIndices:[i.row],columns:[n.field]});return}this.copy()}#e(e){const t=e.clipboardData?.getData("text/plain");if(!t)return;e.preventDefault();const i=ei(t,this.config),n=this.#c(),o=n?.ranges?.[0],s=o?.from.row??0,l=o?.from.col??0,c=o&&(n?.mode==="range"||n?.mode==="row")&&(o.from.row!==o.to.row||o.from.col!==o.to.col)?{endRow:o.to.row,endCol:o.to.col}:null,d=c?.endCol??this.columns.length-1,u=this.columns[l],h=u?{row:s,col:l,field:u.field,bounds:c}:null,f=[],p=i[0]?.length??0;for(let w=0;w<p&&l+w<=d;w++){const y=this.columns[l+w];y&&!y.hidden&&f.push(y.field)}const g={rows:i,text:t,target:h,fields:f};this.emit("paste",g),this.#u(g)}#u(e){if(!this.grid)return;const{pasteHandler:t}=this.config;if(t===null)return;(t??ti)(e,this.grid)}#c(){return this.grid?.query("getSelection")?.[0]}#n(e){const t=this.#c();let i;if(e?.columns)i=Te(this.columns,e.columns);else if(t?.ranges.length&&t.mode!=="row"){const o=t.ranges[t.ranges.length-1],s=Math.min(o.from.col,o.to.col),l=Math.max(o.from.col,o.to.col);i=Te(this.columns.slice(s,l+1))}else i=Te(this.columns);let n;if(e?.rowIndices)n=Ze(this.rows,e.rowIndices);else if(t?.ranges.length){const o=t.ranges[t.ranges.length-1],s=Math.min(o.from.row,o.to.row),l=Math.max(o.from.row,o.to.row);n=[];for(let a=s;a<=l;a++){const c=this.rows[a];c&&n.push(c)}}else n=this.rows;return{columns:i,rows:n}}#l(e,t,i){const n=i?.delimiter??this.config.delimiter??" ",o=i?.newline??this.config.newline??`
|
|
95
|
+
`,s=i?.includeHeaders??this.config.includeHeaders??!1,l=i?.processCell??this.config.processCell,a=[];s&&a.push(e.map(c=>c.header||c.field).join(n));for(const c of t){const d=e.map(u=>{const h=c[u.field];return l?l(h,u.field,c):zr(h)});a.push(d.join(n))}return a.join(o)}#i(e){const t=e.closest("[data-field-cache]");if(!t)return null;const i=t.dataset.fieldCache,n=t.dataset.row;if(!i||!n)return null;const o=parseInt(n,10);if(isNaN(o))return null;const s=this.columns.findIndex(l=>l.field===i);return s===-1?null:{row:o,col:s}}getSelectionAsText(e){const{columns:t,rows:i}=this.#n(e);return t.length===0||i.length===0?"":this.#l(t,i,e)}async copy(e){const{columns:t,rows:i}=this.#n(e);if(t.length===0||i.length===0)return"";const n=this.#l(t,i,e);return await Nr(n),this.lastCopied={text:n,timestamp:Date.now()},this.emit("copy",{text:n,rowCount:i.length,columnCount:t.length}),n}async copyRows(e,t){return e.length===0?"":this.copy({...t,rowIndices:e})}async paste(){const e=await Or();return e?ei(e,this.config):null}getLastCopied(){return this.lastCopied}}const ii=100;function Qe(r){if(r==null)return ii;if(typeof r=="number")return r;const e=parseFloat(r);return isNaN(e)?ii:e}function ni(r){return r.map(e=>Qe(e.width))}function ri(r){const e=[];let t=0;for(const i of r)e.push(t),t+=Qe(i.width);return e}function oi(r){return r.reduce((e,t)=>e+Qe(t.width),0)}function qr(r,e,t,i,n){const o=t.length;if(o===0)return{startCol:0,endCol:0,visibleColumns:[]};let s=Gr(r,t,i);s=Math.max(0,s-n);const l=r+e;let a=s;for(let d=s;d<o;d++){if(t[d]>=l){a=d-1;break}a=d}a=Math.min(o-1,a+n);const c=[];for(let d=s;d<=a;d++)c.push(d);return{startCol:s,endCol:a,visibleColumns:c}}function Gr(r,e,t){let i=0,n=e.length-1;for(;i<n;){const o=Math.floor((i+n)/2);e[o]+t[o]<=r?i=o+1:n=o}return i}function $r(r,e,t){return t?r>e:!1}class Br extends D{name="columnVirtualization";get defaultConfig(){return{autoEnable:!0,threshold:30,overscan:3}}isVirtualized=!1;startCol=0;endCol=0;scrollLeft=0;totalWidth=0;columnWidths=[];columnOffsets=[];originalColumns=[];attach(e){super.attach(e);const t=this.columns;this.columnWidths=ni(t),this.columnOffsets=ri(t),this.totalWidth=oi(t),this.endCol=t.length-1}detach(){this.#t(),this.columnWidths=[],this.columnOffsets=[],this.originalColumns=[],this.isVirtualized=!1,this.startCol=0,this.endCol=0,this.scrollLeft=0,this.totalWidth=0}#t(){const e=this.gridElement;if(!e)return;const t=e.querySelector(".header-row");t&&(t.style.paddingLeft="",t.style.minWidth=""),e.querySelectorAll(".data-grid-row").forEach(s=>{s.style.paddingLeft=""});const n=e.querySelector(".rows-viewport .rows");n&&(n.style.width="");const o=e.querySelector(".rows-body");o&&(o.style.minWidth="")}processColumns(e){(this.originalColumns.length===0||e.length>this.originalColumns.length)&&(this.originalColumns=e,this.columnWidths=ni(e),this.columnOffsets=ri(e),this.totalWidth=oi(e));const i=this.originalColumns,n=$r(i.length,this.config.threshold??30,this.config.autoEnable??!0);if(this.isVirtualized=n??!1,!n)return this.startCol=0,this.endCol=i.length-1,[...i];const o=this.grid.clientWidth||800,s=qr(this.scrollLeft,o,this.columnOffsets,this.columnWidths,this.config.overscan??3);return this.startCol=s.startCol,this.endCol=s.endCol,s.visibleColumns.map(l=>i[l])}afterRender(){if(!this.isVirtualized)return;const e=this.gridElement;if(!e)return;const t=this.columnOffsets[this.startCol]??0,i=e.querySelector(".header-row"),n=e.querySelectorAll(".data-grid-row");i&&(i.style.paddingLeft=`${t}px`,i.style.minWidth=`${this.totalWidth}px`),n.forEach(l=>{l.style.paddingLeft=`${t}px`});const o=e.querySelector(".rows-viewport .rows");o&&(o.style.width=`${this.totalWidth}px`);const s=e.querySelector(".rows-body");s&&(s.style.minWidth=`${this.totalWidth}px`)}onScroll(e){!this.isVirtualized||Math.abs(e.scrollLeft-this.scrollLeft)<1||(this.scrollLeft=e.scrollLeft,this.requestColumnsRender())}getIsVirtualized(){return this.isVirtualized}getVisibleColumnRange(){return{start:this.startCol,end:this.endCol}}scrollToColumn(e){const t=this.columnOffsets[e]??0,i=this.grid;i.scrollLeft=t}getColumnOffset(e){return this.columnOffsets[e]??0}getTotalWidth(){return this.totalWidth}}const Je="@layer tbw-plugins{.tbw-context-menu{position:fixed;background:var(--tbw-context-menu-bg, var(--tbw-color-panel-bg));color:var(--tbw-context-menu-fg, var(--tbw-color-fg));border:1px solid var(--tbw-context-menu-border, var(--tbw-color-border));border-radius:var(--tbw-context-menu-radius, var(--tbw-border-radius));box-shadow:var(--tbw-context-menu-shadow, 0 2px 10px var(--tbw-color-shadow));min-width:var(--tbw-context-menu-min-width, var(--tbw-menu-min-width));padding:var(--tbw-spacing-xs) 0;z-index:10000;font-size:var(--tbw-context-menu-font-size, var(--tbw-font-size-sm));font-family:var(--tbw-context-menu-font-family, var(--tbw-font-family))}.tbw-context-menu-item{display:flex;align-items:center;padding:var(--tbw-context-menu-item-padding, var(--tbw-menu-item-padding));cursor:pointer;gap:var(--tbw-context-menu-item-gap, var(--tbw-menu-item-gap))}.tbw-context-menu-item:hover:not(.disabled){background:var(--tbw-context-menu-hover, var(--tbw-color-row-hover))}.tbw-context-menu-item.disabled{opacity:.5;cursor:default}.tbw-context-menu-item.danger{color:var(--tbw-context-menu-danger, var(--tbw-color-danger))}.tbw-context-menu-icon{width:var(--tbw-context-menu-icon-size, var(--tbw-icon-size));text-align:center}.tbw-context-menu-label{flex:1}.tbw-context-menu-shortcut{color:var(--tbw-context-menu-muted, var(--tbw-color-fg-muted));font-size:var(--tbw-context-menu-shortcut-size, var(--tbw-font-size-xs))}.tbw-context-menu-arrow{font-size:var(--tbw-context-menu-arrow-size, var(--tbw-font-size-2xs));color:var(--tbw-context-menu-muted, var(--tbw-color-fg-muted))}.tbw-context-menu-separator{height:1px;background:var(--tbw-context-menu-border, var(--tbw-color-border));margin:var(--tbw-spacing-xs) 0}}";function et(r,e){return(typeof r=="function"?r(e):r).filter(i=>!(i.hidden===!0||typeof i.hidden=="function"&&i.hidden(e)))}function Kr(r,e){return r.disabled===!0?!0:typeof r.disabled=="function"?r.disabled(e):!1}function tt(r,e,t,i=G.submenuArrow){const n=document.createElement("div");n.className="tbw-context-menu",n.setAttribute("role","menu");for(const o of r){if(o.separator){const c=document.createElement("div");c.className="tbw-context-menu-separator",c.setAttribute("role","separator"),n.appendChild(c);continue}const s=document.createElement("div");s.className="tbw-context-menu-item",o.cssClass&&s.classList.add(o.cssClass),s.setAttribute("role","menuitem"),s.setAttribute("data-id",o.id);const l=Kr(o,e);if(l&&(s.classList.add("disabled"),s.setAttribute("aria-disabled","true")),o.icon){const c=document.createElement("span");c.className="tbw-context-menu-icon",c.innerHTML=o.icon,s.appendChild(c)}const a=document.createElement("span");if(a.className="tbw-context-menu-label",a.textContent=o.name,s.appendChild(a),o.shortcut){const c=document.createElement("span");c.className="tbw-context-menu-shortcut",c.textContent=o.shortcut,s.appendChild(c)}if(o.subMenu?.length){const c=document.createElement("span");c.className="tbw-context-menu-arrow",typeof i=="string"?c.innerHTML=i:i instanceof HTMLElement&&c.appendChild(i.cloneNode(!0)),s.appendChild(c),s.addEventListener("mouseenter",()=>{if(s.querySelector(".tbw-context-menu")||!o.subMenu)return;const u=et(o.subMenu,e),h=tt(u,e,t,i);h.classList.add("tbw-context-submenu"),h.style.position="absolute",h.style.left="100%",h.style.top="0",s.style.position="relative",s.appendChild(h)}),s.addEventListener("mouseleave",()=>{const d=s.querySelector(".tbw-context-menu");d&&d.remove()})}!l&&o.action&&!o.subMenu&&s.addEventListener("click",c=>{c.stopPropagation(),t(o)}),n.appendChild(s)}return n}function si(r,e,t){r.style.position="fixed",r.style.left=`${e}px`,r.style.top=`${t}px`,r.style.visibility="hidden",r.style.zIndex="10000";const i=r.getBoundingClientRect(),n=window.innerWidth,o=window.innerHeight;let s=e,l=t;e+i.width>n&&(s=e-i.width),t+i.height>o&&(l=t-i.height),s=Math.max(0,s),l=Math.max(0,l),r.style.left=`${s}px`,r.style.top=`${l}px`,r.style.visibility="visible"}let ee=null,te=null,U=null,it=0;const nt=[{id:"copy",name:"Copy",shortcut:"Ctrl+C",action:r=>{r.grid?.plugins?.clipboard?.copy?.()}},{separator:!0,id:"sep1",name:""},{id:"export-csv",name:"Export CSV",action:r=>{r.grid?.plugins?.export?.exportCsv?.()}}];class rt extends D{name="contextMenu";get defaultConfig(){return{items:nt}}isOpen=!1;position={x:0,y:0};params=null;menuElement=null;attach(e){super.attach(e),this.installGlobalHandlers(),it++}detach(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null),this.isOpen=!1,this.params=null,this.uninstallGlobalHandlers()}syncSelectionOnContextMenu(e){if(e<0)return[];const i=this.grid?.query("getSelectedRowIndices")?.[0];return i?i.includes(e)?i:(this.grid?.query("selectRows",[e]),[e]):[e]}static CSS_VARS_TO_COPY=["--tbw-color-panel-bg","--tbw-color-fg","--tbw-color-fg-muted","--tbw-color-border","--tbw-color-row-hover","--tbw-color-shadow","--tbw-color-danger","--tbw-border-radius","--tbw-font-family","--tbw-font-size-sm","--tbw-font-size-xs","--tbw-font-size-2xs","--tbw-spacing-xs","--tbw-icon-size","--tbw-menu-min-width","--tbw-menu-item-padding","--tbw-menu-item-gap","--tbw-context-menu-bg","--tbw-context-menu-fg","--tbw-context-menu-border","--tbw-context-menu-radius","--tbw-context-menu-shadow","--tbw-context-menu-hover","--tbw-context-menu-danger","--tbw-context-menu-muted","--tbw-context-menu-min-width","--tbw-context-menu-font-size","--tbw-context-menu-font-family","--tbw-context-menu-item-padding","--tbw-context-menu-item-gap","--tbw-context-menu-icon-size","--tbw-context-menu-shortcut-size","--tbw-context-menu-arrow-size"];copyGridStyles(e){const t=this.gridElement;if(!t)return;const i=getComputedStyle(t),n=[],o=i.getPropertyValue("color-scheme").trim();o&&n.push(`color-scheme: ${o}`);for(const s of rt.CSS_VARS_TO_COPY){const l=i.getPropertyValue(s).trim();l&&n.push(`${s}: ${l}`)}if(n.length>0){const s=e.getAttribute("style")||"";e.setAttribute("style",s+n.join("; ")+";")}}installGlobalHandlers(){!U&&typeof document<"u"&&typeof Je=="string"&&Je&&(U=document.createElement("style"),U.id="tbw-context-menu-styles",U.textContent=Je,document.head.appendChild(U)),ee||(ee=()=>{document.querySelectorAll(".tbw-context-menu").forEach(t=>t.remove())},document.addEventListener("click",ee)),te||(te=e=>{e.key==="Escape"&&document.querySelectorAll(".tbw-context-menu").forEach(i=>i.remove())},document.addEventListener("keydown",te))}uninstallGlobalHandlers(){it--,!(it>0)&&(ee&&(document.removeEventListener("click",ee),ee=null),te&&(document.removeEventListener("keydown",te),te=null),U&&(U.remove(),U=null))}afterRender(){const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-grid-root");t&&t.getAttribute("data-context-menu-bound")!=="true"&&(t.setAttribute("data-context-menu-bound","true"),t.addEventListener("contextmenu",i=>{const n=i;n.preventDefault();const o=n.target,s=o.closest("[data-row][data-col]"),l=o.closest(".header-cell");let a;if(s){const d=parseInt(s.getAttribute("data-row")??"-1",10),u=parseInt(s.getAttribute("data-col")??"-1",10),h=this.columns[u],f=this.rows[d],p=this.syncSelectionOnContextMenu(d);a={row:f,rowIndex:d,column:h,columnIndex:u,field:h?.field??"",value:f?.[h?.field]??null,isHeader:!1,event:n,selectedRows:p}}else if(l){const d=parseInt(l.getAttribute("data-col")??"-1",10),u=this.columns[d];a={row:null,rowIndex:-1,column:u,columnIndex:d,field:u?.field??"",value:null,isHeader:!0,event:n,selectedRows:[]}}else return;this.params=a,this.position={x:n.clientX,y:n.clientY};const c=et(this.config.items??nt,a);c.length&&(this.menuElement&&this.menuElement.remove(),this.menuElement=tt(c,a,d=>{d.action&&d.action(a),this.menuElement?.remove(),this.menuElement=null,this.isOpen=!1},this.gridIcons.submenuArrow),document.body.appendChild(this.menuElement),this.copyGridStyles(this.menuElement),si(this.menuElement,n.clientX,n.clientY),this.isOpen=!0,this.emit("context-menu-open",{params:a,items:c}))}))}showMenu(e,t,i){const n={row:i.row??null,rowIndex:i.rowIndex??-1,column:i.column??null,columnIndex:i.columnIndex??-1,field:i.field??"",value:i.value??null,isHeader:i.isHeader??!1,event:i.event??new MouseEvent("contextmenu"),selectedRows:i.selectedRows??[]},o=et(this.config.items??nt,n);this.menuElement&&this.menuElement.remove(),this.menuElement=tt(o,n,s=>{s.action&&s.action(n),this.menuElement?.remove(),this.menuElement=null,this.isOpen=!1},this.gridIcons.submenuArrow),document.body.appendChild(this.menuElement),this.copyGridStyles(this.menuElement),si(this.menuElement,e,t),this.isOpen=!0}hideMenu(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null,this.isOpen=!1)}isMenuOpen(){return this.isOpen}}const Wr="@layer tbw-plugins{tbw-grid{--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-row-bg: var(--tbw-editing-bg);--tbw-editing-border: var(--tbw-border-input, 1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input: var(--tbw-cell-padding-input, 2px 6px);--tbw-font-size-editor: inherit;--tbw-editing-row-outline-color: var(--tbw-color-accent);--tbw-editing-row-outline-width: 1px;--tbw-invalid-bg: light-dark(#fef2f2, #450a0a);--tbw-invalid-border-color: light-dark(#ef4444, #f87171)}tbw-grid:not(.tbw-grid-mode) .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}tbw-grid .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex;min-height:calc(var(--tbw-row-height) + 2px);align-items:center;justify-content:center}tbw-grid .data-grid-row>.cell.editing input:not([type=checkbox]),tbw-grid .data-grid-row>.cell.editing select,tbw-grid .data-grid-row>.cell.editing textarea{width:100%;height:100%;flex:1 1 auto;min-width:0;border:var(--tbw-editing-border);padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor)}tbw-grid .tbw-editor-host{display:contents}tbw-grid .data-grid-row>.cell[data-invalid=true]{background:var(--tbw-invalid-bg);outline:1px solid var(--tbw-invalid-border-color);outline-offset:-1px}}";function Vr(r){const e=r.options;return e?typeof e=="function"?e():e:[]}function Ur(r){return e=>{const t=r.editorParams,i=document.createElement("input");i.type="number",i.value=e.value!=null?String(e.value):"",t?.min!==void 0&&(i.min=String(t.min)),t?.max!==void 0&&(i.max=String(t.max)),t?.step!==void 0&&(i.step=String(t.step)),t?.placeholder&&(i.placeholder=t.placeholder);const n=()=>e.commit(i.value===""?null:Number(i.value));return i.addEventListener("blur",n),i.addEventListener("keydown",o=>{o.key==="Enter"&&n(),o.key==="Escape"&&e.cancel()}),i}}function jr(){return r=>{const e=document.createElement("input");return e.type="checkbox",e.checked=!!r.value,e.addEventListener("change",()=>r.commit(e.checked)),e}}function Yr(r){return e=>{const t=r.editorParams,i=document.createElement("input");i.type="date",e.value instanceof Date?i.valueAsDate=e.value:typeof e.value=="string"&&e.value&&(i.value=e.value.split("T")[0]),t?.min&&(i.min=t.min),t?.max&&(i.max=t.max),t?.placeholder&&(i.placeholder=t.placeholder);const n=()=>{typeof e.value=="string"?e.commit(i.value):e.commit(i.valueAsDate)};return i.addEventListener("change",n),i.addEventListener("keydown",o=>{o.key==="Escape"&&e.cancel()}),i}}function Xr(r){return e=>{const t=r.editorParams,i=document.createElement("select");if(r.multi&&(i.multiple=!0),t?.includeEmpty){const s=document.createElement("option");s.value="",s.textContent=t.emptyLabel??"",i.appendChild(s)}Vr(r).forEach(s=>{const l=document.createElement("option");l.value=String(s.value),l.textContent=s.label,(r.multi&&Array.isArray(e.value)&&e.value.includes(s.value)||!r.multi&&e.value===s.value)&&(l.selected=!0),i.appendChild(l)});const o=()=>{if(r.multi){const s=Array.from(i.selectedOptions).map(l=>l.value);e.commit(s)}else e.commit(i.value)};return i.addEventListener("change",o),i.addEventListener("blur",o),i.addEventListener("keydown",s=>{s.key==="Escape"&&e.cancel()}),i}}function Zr(r){return e=>{const t=r.editorParams,i=document.createElement("input");i.type="text",i.value=e.value!=null?String(e.value):"",t?.maxLength!==void 0&&(i.maxLength=t.maxLength),t?.pattern&&(i.pattern=t.pattern),t?.placeholder&&(i.placeholder=t.placeholder);const n=()=>{const o=i.value;(e.value===null||e.value===void 0)&&o===""||typeof e.value=="string"&&o===e.value.replace(/[\n\r]/g,"")||(typeof e.value=="number"&&o!==""?e.commit(Number(o)):e.commit(o))};return i.addEventListener("blur",n),i.addEventListener("keydown",o=>{o.key==="Enter"&&n(),o.key==="Escape"&&e.cancel()}),i}}function li(r){switch(r.type){case"number":return Ur(r);case"boolean":return jr();case"date":return Yr(r);case"select":return Xr(r);default:return Zr(r)}}function Qr(r,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=r.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const n=r.__frameworkAdapter;if(n?.getTypeDefault){const o=n.getTypeDefault(e.type);if(o?.editor)return o.editor}}function fe(r){return!(typeof r!="string"||r==="__proto__"||r==="constructor"||r==="prototype")}function Jr(r){const e=(r.__editingCellCount??0)+1;r.__editingCellCount=e,r.setAttribute("data-has-editing","")}function eo(r){r.__editingCellCount=0,r.removeAttribute("data-has-editing")}function ie(r,e,t){return r instanceof HTMLInputElement?r.type==="checkbox"?r.checked:r.type==="number"?r.value===""?null:Number(r.value):r.type==="date"?typeof t=="string"?r.value:r.valueAsDate:typeof t=="number"?r.value===""?null:Number(r.value):t==null&&r.value===""||typeof t=="string"&&r.value===t.replace(/[\n\r]/g,"")?t:r.value:e?.type==="number"&&r.value!==""||typeof t=="number"&&r.value!==""?Number(r.value):t==null&&r.value===""?t:r.value}function ai(r){}function to(r,e,t,i){const n=r.querySelector("input,textarea,select");n&&(n.addEventListener("blur",()=>{t(ie(n,e,i))}),n instanceof HTMLInputElement&&n.type==="checkbox"?n.addEventListener("change",()=>t(n.checked)):n instanceof HTMLSelectElement&&n.addEventListener("change",()=>t(ie(n,e,i))))}class io extends D{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:e=>e===!0},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'}],events:[{type:"cell-edit-committed",description:"Emitted when a cell edit is committed (for plugin-to-plugin coordination)"}],queries:[{type:"isEditing",description:"Returns whether any cell is currently being edited"}]};name="editing";styles=Wr;get defaultConfig(){return{mode:"row",editOn:"click"}}get#t(){return this.config.mode==="grid"}#e=-1;#u=-1;#c=new Map;#n=new Set;#l=new Set;#i=new Map;#h=!1;#w=-1;#f=new Map;#a=!1;#v=!1;attach(e){super.attach(e);const t=this.disconnectSignal,i=e;i._activeEditRows=-1,i._rowEditSnapshots=new Map,Object.defineProperty(e,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(e,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),e.resetChangedRows=n=>this.resetChangedRows(n),e.beginBulkEdit=(n,o)=>{o&&this.beginCellEdit(n,o)},document.addEventListener("keydown",n=>{if(!this.#t&&n.key==="Escape"&&this.#e!==-1){if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(n)===!1)return;this.#p(this.#e,!0)}},{capture:!0,signal:t}),document.addEventListener("mousedown",n=>{if(this.#t||this.#e===-1)return;const o=i.findRenderedRowElement?.(this.#e);!o||(n.composedPath&&n.composedPath()||[]).includes(o)||this.config.onBeforeEditClose&&this.config.onBeforeEditClose(n)===!1||queueMicrotask(()=>{this.#e!==-1&&this.#p(this.#e,!1)})},{signal:t}),this.gridElement.addEventListener("cell-change",n=>{const o=n.detail;if(o.source==="user")return;const s=`${o.rowIndex}:${o.field}`,l=this.#i.get(s);l&&l(o.newValue)},{signal:t}),this.#t&&(this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.gridElement.addEventListener("focusin",n=>{const o=n.target;if(o.matches($)){if(this.#v){o.blur(),this.gridElement.focus();return}this.#a=!0}},{signal:t}),this.gridElement.addEventListener("focusout",n=>{const o=n.relatedTarget;(!o||!this.gridElement.contains(o)||!o.matches($))&&(this.#a=!1)},{signal:t}),this.gridElement.addEventListener("keydown",n=>{if(n.key==="Escape"&&this.#a){const o=document.activeElement;o&&this.gridElement.contains(o)&&(o.blur(),this.gridElement.focus()),this.#a=!1,this.#v=!0,n.preventDefault(),n.stopPropagation()}},{capture:!0,signal:t}),this.gridElement.addEventListener("mousedown",n=>{n.target.matches($)&&(this.#v=!1)},{signal:t}))}detach(){this.gridElement.classList.remove("tbw-grid-mode"),this.#e=-1,this.#u=-1,this.#c.clear(),this.#n.clear(),this.#l.clear(),this.#i.clear(),this.#a=!1,this.#v=!1,super.detach()}handleQuery(e){if(e.type==="isEditing")return this.#t||this.#e!==-1}onCellClick(e){if(this.#t)return!1;const t=this.grid,i=this.config.editOn??t.effectiveConfig?.editOn;if(i===!1||i==="manual"||i!=="click"&&i!=="dblclick")return!1;const n=e.originalEvent.type==="dblclick";if(i==="click"&&n||i==="dblclick"&&!n)return!1;const{rowIndex:o}=e;return t._columns?.some(l=>l.editable)?(e.originalEvent.stopPropagation(),this.beginBulkEdit(o),!0):!1}onKeyDown(e){const t=this.grid;if(e.key==="Escape"){if(this.#t&&this.#a){const i=document.activeElement;return i&&this.gridElement.contains(i)&&i.blur(),this.#a=!1,this.requestAfterRender(),!0}if(this.#e!==-1&&!this.#t)return this.config.onBeforeEditClose&&this.config.onBeforeEditClose(e)===!1||this.#p(this.#e,!0),!0}if(this.#t&&!this.#a&&(e.key==="ArrowUp"||e.key==="ArrowDown"||e.key==="ArrowLeft"||e.key==="ArrowRight"))return!1;if((e.key==="ArrowUp"||e.key==="ArrowDown")&&this.#e!==-1&&!this.#t){if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(e)===!1)return!0;const i=t._rows.length-1,n=this.#e;return this.#p(n,!1),e.key==="ArrowDown"?t._focusRow=Math.min(i,t._focusRow+1):t._focusRow=Math.max(0,t._focusRow-1),e.preventDefault(),I(t),this.requestAfterRender(),!0}if(e.key==="Tab"&&(this.#e!==-1||this.#t)){e.preventDefault();const i=!e.shiftKey;return this.#b(i),!0}if(e.key===" "||e.key==="Spacebar"){if(this.#e!==-1)return!1;const i=t._focusRow,n=t._focusCol;if(i>=0&&n>=0){const o=t._visibleColumns[n],s=t._rows[i];if(o?.editable&&o.type==="boolean"&&s){const l=o.field;if(fe(l)){const c=!s[l];return this.#x(i,o,c,s),e.preventDefault(),this.requestRender(),!0}}}return!1}if(e.key==="Enter"&&!e.shiftKey){if(this.#t&&!this.#a)return this.#E(),!0;if(this.#e!==-1)return!!(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(e)===!1);const i=this.config.editOn??t.effectiveConfig?.editOn;if(i===!1||i==="manual")return!1;const n=t._focusRow,o=t._focusCol;if(n>=0&&t._columns?.some(l=>l.editable)){const l=t._visibleColumns[o],a=t._rows[n],c=l?.field??"",d=c&&a?a[c]:void 0,u=this.gridElement.querySelector(`[data-row="${n}"][data-col="${o}"]`),h=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:n,colIndex:o,field:c,value:d,row:a,cellEl:u,trigger:"keyboard",originalEvent:e}});this.gridElement.dispatchEvent(h);const f=new CustomEvent("activate-cell",{cancelable:!0,bubbles:!0,detail:{row:n,col:o}});return this.gridElement.dispatchEvent(f),h.defaultPrevented||f.defaultPrevented?(e.preventDefault(),!0):(this.beginBulkEdit(n),!0)}return!1}return!1}processColumns(e){const t=this.grid,i=t.effectiveConfig?.typeDefaults,n=t.__frameworkAdapter;return!i&&!n?.getTypeDefault?e:e.map(o=>{if(!o.type)return o;let s;if(i?.[o.type]?.editorParams&&(s=i[o.type].editorParams),!s&&n?.getTypeDefault){const l=n.getTypeDefault(o.type);l?.editorParams&&(s=l.editorParams)}return s?{...o,editorParams:{...s,...o.editorParams}}:o})}afterRender(){const e=this.grid;if(this.#h&&(this.#h=!1,this.#r(e)),this.#w!==-1){const t=this.#w;this.#w=-1,e.animateRow?.(t,"change")}if(!this.#t&&this.#l.size!==0)for(const t of this.#l){const[i,n]=t.split(":"),o=parseInt(i,10),s=parseInt(n,10),l=e.findRenderedRowElement?.(o);if(!l)continue;const a=l.querySelector(`.cell[data-col="${s}"]`);if(!a||a.classList.contains("editing"))continue;const c=e._rows[o],d=e._visibleColumns[s];c&&d&&this.#m(c,o,d,s,a,!0)}}afterCellRender(e){if(!this.#t)return;const{row:t,rowIndex:i,column:n,colIndex:o,cellElement:s}=e;n.editable&&(s.classList.contains("editing")||this.#m(t,i,n,o,s,!0))}onScrollRender(){this.afterRender()}get changedRows(){const e=[];for(const t of this.#n){const i=this.grid.getRow(t);i&&e.push(i)}return e}get changedRowIds(){return Array.from(this.#n)}get activeEditRow(){return this.#e}get activeEditCol(){return this.#u}isRowEditing(e){return this.#e===e}isCellEditing(e,t){return this.#l.has(`${e}:${t}`)}isRowChanged(e){const t=this.grid,i=t._rows[e];if(!i)return!1;try{const n=t.getRowId?.(i);return n?this.#n.has(n):!1}catch{return!1}}isRowChangedById(e){return this.#n.has(e)}setInvalid(e,t,i=""){let n=this.#f.get(e);n||(n=new Map,this.#f.set(e,n)),n.set(t,i),this.#d(e,t,!0)}clearInvalid(e,t){const i=this.#f.get(e);i&&(i.delete(t),i.size===0&&this.#f.delete(e)),this.#d(e,t,!1)}clearRowInvalid(e){const t=this.#f.get(e);if(t){const i=Array.from(t.keys());this.#f.delete(e),i.forEach(n=>this.#d(e,n,!1))}}clearAllInvalid(){const e=Array.from(this.#f.entries());this.#f.clear(),e.forEach(([t,i])=>{i.forEach((n,o)=>this.#d(t,o,!1))})}isCellInvalid(e,t){return this.#f.get(e)?.has(t)??!1}getInvalidMessage(e,t){return this.#f.get(e)?.get(t)}hasInvalidCells(e){const t=this.#f.get(e);return t?t.size>0:!1}getInvalidFields(e){return new Map(this.#f.get(e)??[])}#d(e,t,i){const n=this.grid,o=n._visibleColumns?.findIndex(d=>d.field===t);if(o===-1||o===void 0)return;const l=n._rows?.findIndex(d=>{try{return n.getRowId?.(d)===e}catch{return!1}});if(l===-1||l===void 0)return;const c=n.findRenderedRowElement?.(l)?.querySelector(`.cell[data-col="${o}"]`);if(c)if(i){c.setAttribute("data-invalid","true");const d=this.#f.get(e)?.get(t);d&&c.setAttribute("title",d)}else c.removeAttribute("data-invalid"),c.removeAttribute("title")}resetChangedRows(e){const t=this.changedRows,i=this.changedRowIds;this.#n.clear(),this.#C(),e||this.emit("changed-rows-reset",{rows:t,ids:i}),this.grid._rowPool?.forEach(o=>o.classList.remove("changed"))}beginCellEdit(e,t){const i=this.grid,n=i._visibleColumns.findIndex(a=>a.field===t);if(n===-1||!i._visibleColumns[n]?.editable)return;const l=i.findRenderedRowElement?.(e)?.querySelector(`.cell[data-col="${n}"]`);l&&this.#g(e,n,l)}beginBulkEdit(e){const t=this.grid;if((this.config.editOn??t.effectiveConfig?.editOn)===!1||!t._columns?.some(l=>l.editable))return;const o=t.findRenderedRowElement?.(e);if(!o)return;const s=t._rows[e];this.#R(e,s),Array.from(o.children).forEach((l,a)=>{const c=t._visibleColumns[a];if(c?.editable){const d=l;d.classList.contains("editing")||this.#m(s,e,c,a,d,!0)}}),setTimeout(()=>{let l=o.querySelector(`.cell[data-col="${t._focusCol}"]`);if(l?.classList.contains("editing")||(l=o.querySelector(".cell.editing")),l?.classList.contains("editing")){const a=l.querySelector($);try{a?.focus({preventScroll:!0})}catch{}}},0)}commitActiveRowEdit(){this.#e!==-1&&this.#p(this.#e,!1)}cancelActiveRowEdit(){this.#e!==-1&&this.#p(this.#e,!0)}#g(e,t,i){const n=this.grid,o=n._rows[e],s=n._visibleColumns[t];!o||!s?.editable||i.classList.contains("editing")||(this.#e!==e&&this.#R(e,o),this.#u=t,this.#m(o,e,s,t,i,!1))}#E(){const e=this.grid,t=e._focusRow,i=e._focusCol;if(t<0||i<0)return;const o=e.findRenderedRowElement?.(t)?.querySelector(`.cell[data-col="${i}"]`);if(o?.classList.contains("editing")){const s=o.querySelector($);s&&(this.#v=!1,s.focus(),this.#a=!0,s instanceof HTMLInputElement&&(s.type==="text"||s.type==="number")&&s.select())}}#b(e){const t=this.grid,i=t._rows,n=this.#t?t._focusRow:this.#e,o=t._visibleColumns.map((c,d)=>c.editable?d:-1).filter(c=>c>=0);if(o.length===0)return;const l=o.indexOf(t._focusCol)+(e?1:-1);if(l>=0&&l<o.length){t._focusCol=o[l];const d=t.findRenderedRowElement?.(n)?.querySelector(`.cell[data-col="${o[l]}"]`);d?.classList.contains("editing")&&d.querySelector($)?.focus({preventScroll:!0}),I(t,{forceHorizontalScroll:!0});return}const a=n+(e?1:-1);a>=0&&a<i.length&&(this.#t?(t._focusRow=a,t._focusCol=e?o[0]:o[o.length-1],I(t,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const d=t.findRenderedRowElement?.(a)?.querySelector(`.cell[data-col="${t._focusCol}"]`);d?.classList.contains("editing")&&d.querySelector($)?.focus({preventScroll:!0})},0)):(this.#p(n,!1),t._focusRow=a,t._focusCol=e?o[0]:o[o.length-1],this.beginBulkEdit(a),I(t,{forceHorizontalScroll:!0})))}#C(){const e=this.grid;e._activeEditRows=this.#e,e._rowEditSnapshots=this.#c}#R(e,t){if(this.#e!==e&&(this.#c.set(e,{...t}),this.#e=e,this.#C(),!this.#t)){const i=this.grid;let n="";try{n=i.getRowId?.(t)??""}catch{}this.emit("edit-open",{rowIndex:e,rowId:n,row:t})}}#p(e,t){if(this.#e!==e)return;const i=this.grid,n=this.#c.get(e),o=i._rows[e],s=i.findRenderedRowElement?.(e);let l;if(o)try{l=i.getRowId?.(o)}catch{}if(!t&&s&&o&&s.querySelectorAll(".cell.editing").forEach(c=>{const d=Number(c.getAttribute("data-col"));if(isNaN(d))return;const u=i._visibleColumns[d];if(!u||c.hasAttribute("data-editor-managed"))return;const h=c.querySelector("input,textarea,select");if(h){const f=u.field,p=o[f],g=ie(h,u,p);p!==g&&this.#x(e,u,g,o)}}),t&&n&&o)Object.keys(n).forEach(a=>{o[a]=n[a]}),l&&(this.#n.delete(l),this.clearRowInvalid(l));else if(!t&&o){const a=this.#L(n,o),c=l?this.#n.has(l):a,d=this.emitCancelable("row-commit",{rowIndex:e,rowId:l??"",row:o,oldValue:n,newValue:o,changed:c,changedRows:this.changedRows,changedRowIds:this.changedRowIds});d&&n?(Object.keys(n).forEach(u=>{o[u]=n[u]}),l&&(this.#n.delete(l),this.clearRowInvalid(l))):!d&&a&&this.isAnimationEnabled&&(this.#w=e)}this.#c.delete(e),this.#e=-1,this.#u=-1,this.#C();for(const a of this.#l)a.startsWith(`${e}:`)&&this.#l.delete(a);for(const a of this.#i.keys())a.startsWith(`${e}:`)&&this.#i.delete(a);s&&(s.querySelectorAll(".cell.editing").forEach(a=>{a.classList.remove("editing"),eo(a.parentElement)}),this.requestRender()),this.#h=!0,s||(this.#r(i),this.#h=!1),!this.#t&&o&&this.emit("edit-close",{rowIndex:e,rowId:l??"",row:o,reverted:t})}#x(e,t,i,n){const o=t.field;if(!fe(o))return;const s=n[o];if(s===i)return;const l=this.grid;let a;try{a=this.grid.getRowId(n)}catch{}const c=a?!this.#n.has(a):!0,d=a?g=>this.grid.updateRow(a,g,"cascade"):ai;let u=!1;const h=a?g=>{u=!0,this.setInvalid(a,o,g??"")}:()=>{};if(this.emitCancelable("cell-commit",{row:n,rowId:a??"",field:o,oldValue:s,value:i,rowIndex:e,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:c,updateRow:d,setInvalid:h}))return;a&&!u&&this.isCellInvalid(a,o)&&this.clearInvalid(a,o),n[o]=i,a&&this.#n.add(a),this.#C(),this.emitPluginEvent("cell-edit-committed",{rowIndex:e,field:o,oldValue:s,newValue:i});const p=l.findRenderedRowElement?.(e);p&&p.classList.add("changed")}#m(e,t,i,n,o,s){if(!i.editable||o.classList.contains("editing"))return;let l;try{l=this.grid.getRowId(e)}catch{}const a=l?b=>this.grid.updateRow(l,b,"cascade"):ai,c=fe(i.field)?e[i.field]:void 0;o.classList.add("editing"),this.#l.add(`${t}:${n}`);const d=o.parentElement;d&&Jr(d);let u=!1;const h=b=>{u||!this.#t&&this.#e===-1||this.#x(t,i,b,e)},f=()=>{u=!0,fe(i.field)&&(e[i.field]=c)},p=document.createElement("div");p.className="tbw-editor-host",o.innerHTML="",o.appendChild(p),p.addEventListener("keydown",b=>{if(b.key==="Enter"){if(this.#t){b.stopPropagation(),b.preventDefault();const C=p.querySelector("input,textarea,select");C&&h(ie(C,i,c));return}if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(b)===!1)return;b.stopPropagation(),b.preventDefault(),u=!0,this.#p(t,!1)}if(b.key==="Escape"){if(this.#t){b.stopPropagation(),b.preventDefault();return}if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(b)===!1)return;b.stopPropagation(),b.preventDefault(),f(),this.#p(t,!0)}});const g=i,w=g.__editorTemplate,y=Qr(this.grid,g)??li(i),v=c,T=`${t}:${i.field}`,P=[];this.#i.set(T,b=>{for(const C of P)C(b)});const E=b=>{P.push(b)};if(y==="template"&&w)this.#S(p,g,e,c,h,f,s,t),E(b=>{const C=p.querySelector("input,textarea,select");C&&(C instanceof HTMLInputElement&&C.type==="checkbox"?C.checked=!!b:C.value=String(b??""))});else if(typeof y=="string"){const b=document.createElement(y);b.value=v,b.addEventListener("change",()=>h(b.value)),E(C=>{b.value=C}),p.appendChild(b),s||queueMicrotask(()=>{p.querySelector($)?.focus({preventScroll:!0})})}else if(typeof y=="function"){const b={row:e,rowId:l??"",value:v,field:i.field,column:i,commit:h,cancel:f,updateRow:a,onValueChange:E},C=y(b);typeof C=="string"?(p.innerHTML=C,to(p,i,h,c),E(A=>{const m=p.querySelector("input,textarea,select");m&&(m instanceof HTMLInputElement&&m.type==="checkbox"?m.checked=!!A:m.value=String(A??""))})):C instanceof Node&&(p.appendChild(C),C instanceof HTMLInputElement||C instanceof HTMLSelectElement||C instanceof HTMLTextAreaElement?E(m=>{C instanceof HTMLInputElement&&C.type==="checkbox"?C.checked=!!m:C.value=String(m??"")}):o.setAttribute("data-editor-managed","")),s||queueMicrotask(()=>{p.querySelector($)?.focus({preventScroll:!0})})}else if(y&&typeof y=="object"){const b=document.createElement("div");b.setAttribute("data-external-editor",""),b.setAttribute("data-field",i.field),p.appendChild(b),o.setAttribute("data-editor-managed","");const C={row:e,rowId:l??"",value:v,field:i.field,column:i,commit:h,cancel:f,updateRow:a,onValueChange:E};if(y.mount)try{y.mount({placeholder:b,context:C,spec:y})}catch(A){console.warn(`[tbw-grid] External editor mount error for column '${i.field}':`,A)}else this.grid.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:b,spec:y,context:C}}))}}#S(e,t,i,n,o,s,l,a){const c=t.__editorTemplate;if(!c)return;const d=c.cloneNode(!0),u=t.__compiledEditor;u?d.innerHTML=u({row:i,value:n,field:t.field,column:t,commit:o,cancel:s}):d.querySelectorAll("*").forEach(f=>{f.childNodes.length===1&&f.firstChild?.nodeType===Node.TEXT_NODE&&(f.textContent=f.textContent?.replace(/{{\s*value\s*}}/g,n==null?"":String(n)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(p,g)=>{if(!fe(g))return"";const w=i[g];return w==null?"":String(w)})||"")});const h=d.querySelector("input,textarea,select");if(h){h instanceof HTMLInputElement&&h.type==="checkbox"?h.checked=!!n:h.value=String(n??"");let f=!1;h.addEventListener("blur",()=>{f||o(ie(h,t,n))}),h.addEventListener("keydown",p=>{const g=p;if(g.key==="Enter"){if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(g)===!1)return;g.stopPropagation(),g.preventDefault(),f=!0,o(ie(h,t,n)),this.#p(a,!1)}if(g.key==="Escape"){if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(g)===!1)return;g.stopPropagation(),g.preventDefault(),s(),this.#p(a,!0)}}),h instanceof HTMLInputElement&&h.type==="checkbox"&&h.addEventListener("change",()=>o(h.checked)),l||setTimeout(()=>h.focus({preventScroll:!0}),0)}e.appendChild(d)}#L(e,t){if(!e)return!1;const i=e,n=t,o=new Set([...Object.keys(i),...Object.keys(n)]);for(const s of o)if(i[s]!==n[s])return!0;return!1}#r(e){queueMicrotask(()=>{try{const t=e._focusRow,i=e._focusCol,n=e.findRenderedRowElement?.(t);if(n){Array.from(e._bodyEl.querySelectorAll(".cell-focus")).forEach(s=>s.classList.remove("cell-focus"));const o=n.querySelector(`.cell[data-row="${t}"][data-col="${i}"]`);o&&(o.classList.add("cell-focus"),o.setAttribute("aria-selected","true"),o.hasAttribute("tabindex")||o.setAttribute("tabindex","-1"),o.focus({preventScroll:!0}))}}catch{}})}}function ci(r,e=!0){if(r==null)return"";if(r instanceof Date)return r.toISOString();if(typeof r=="object")return JSON.stringify(r);const t=String(r);return e&&(t.includes(",")||t.includes('"')||t.includes(`
|
|
96
|
+
`)||t.includes("\r"))?`"${t.replace(/"/g,'""')}"`:t}function no(r,e,t,i={}){const n=i.delimiter??",",o=i.newline??`
|
|
97
|
+
`,s=[],l=i.bom?"\uFEFF":"";if(t.includeHeaders!==!1){const a=e.map(c=>{const d=c.header||c.field,u=t.processHeader?t.processHeader(d,c.field):d;return ci(u)});s.push(a.join(n))}for(const a of r){const c=e.map(d=>{let u=a[d.field];return t.processCell&&(u=t.processCell(u,d.field,a)),ci(u)});s.push(c.join(n))}return l+s.join(o)}function ot(r,e){const t=URL.createObjectURL(r),i=document.createElement("a");i.href=t,i.download=e,i.style.display="none",document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(t)}function ro(r,e){const t=new Blob([r],{type:"text/csv;charset=utf-8;"});ot(t,e)}function di(r){return r.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function oo(r,e,t){let i=`<?xml version="1.0" encoding="UTF-8"?>
|
|
98
98
|
<?mso-application progid="Excel.Sheet"?>
|
|
99
99
|
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
|
|
100
100
|
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
|
|
@@ -104,10 +104,10 @@ ${q(i.name)}Plugin and ${q(s.name)}Plugin are both loaded, but they are currentl
|
|
|
104
104
|
<Row>`;for(const o of e){let s=n[o.field];t.processCell&&(s=t.processCell(s,o.field,n));let l="String",a="";s==null?a="":typeof s=="number"&&!isNaN(s)?(l="Number",a=String(s)):s instanceof Date?(l="DateTime",a=s.toISOString()):a=di(String(s)),i+=`<Cell><Data ss:Type="${l}">${a}</Data></Cell>`}i+="</Row>"}return i+=`
|
|
105
105
|
</Table>
|
|
106
106
|
</Worksheet>
|
|
107
|
-
</Workbook>`,i}function oo(r,e){const t=e.endsWith(".xls")?e:`${e}.xls`,i=new Blob([r],{type:"application/vnd.ms-excel;charset=utf-8;"});rt(i,t)}class so extends D{name="export";get defaultConfig(){return{fileName:"export",includeHeaders:!0,onlyVisible:!0,onlySelected:!1}}isExportingFlag=!1;lastExportInfo=null;performExport(e,t){const i=this.config,n={format:e,fileName:t?.fileName??i.fileName??"export",includeHeaders:t?.includeHeaders??i.includeHeaders,processCell:t?.processCell,processHeader:t?.processHeader,columns:t?.columns,rowIndices:t?.rowIndices};let o=[...this.columns];if(i.onlyVisible&&(o=o.filter(a=>!a.hidden&&!a.field.startsWith("__"))),t?.columns){const a=new Set(t.columns);o=o.filter(c=>a.has(c.field))}let s=[...this.rows];if(i.onlySelected){const a=this.getSelectionState();a?.selected?.size&&(s=[...a.selected].sort((d,u)=>d-u).map(d=>this.rows[d]).filter(Boolean))}t?.rowIndices&&(s=t.rowIndices.map(a=>this.rows[a]).filter(Boolean)),this.isExportingFlag=!0;let l=n.fileName;try{switch(e){case"csv":{const a=io(s,o,n,{bom:!0});l=l.endsWith(".csv")?l:`${l}.csv`,no(a,l);break}case"excel":{const a=ro(s,o,n);l=l.endsWith(".xls")?l:`${l}.xls`,oo(a,l);break}case"json":{const a=s.map(u=>{const h={};for(const f of o){let p=u[f.field];n.processCell&&(p=n.processCell(p,f.field,u)),h[f.field]=p}return h}),c=JSON.stringify(a,null,2);l=l.endsWith(".json")?l:`${l}.json`;const d=new Blob([c],{type:"application/json"});rt(d,l);break}}this.lastExportInfo={format:e,timestamp:new Date},this.emit("export-complete",{format:e,fileName:l,rowCount:s.length,columnCount:o.length})}finally{this.isExportingFlag=!1}}getSelectionState(){try{return this.grid?.getPluginState?.("selection")??null}catch{return null}}exportCsv(e){this.performExport("csv",e)}exportExcel(e){this.performExport("excel",e)}exportJson(e){this.performExport("json",e)}isExporting(){return this.isExportingFlag}getLastExport(){return this.lastExportInfo}}function lo(r,e,t=!1){const i=r[e.field];if(e.operator==="blank")return i==null||i==="";if(e.operator==="notBlank")return i!=null&&i!=="";if(i==null)return!1;const n=String(i),o=t?n:n.toLowerCase(),s=t?String(e.value):String(e.value).toLowerCase();switch(e.operator){case"contains":return o.includes(s);case"notContains":return!o.includes(s);case"equals":return o===s;case"notEquals":return o!==s;case"startsWith":return o.startsWith(s);case"endsWith":return o.endsWith(s);case"lessThan":return Number(i)<Number(e.value);case"lessThanOrEqual":return Number(i)<=Number(e.value);case"greaterThan":return Number(i)>Number(e.value);case"greaterThanOrEqual":return Number(i)>=Number(e.value);case"between":return Number(i)>=Number(e.value)&&Number(i)<=Number(e.valueTo);case"in":return Array.isArray(e.value)&&e.value.includes(i);case"notIn":return Array.isArray(e.value)&&!e.value.includes(i);default:return!0}}function ao(r,e,t=!1){return e.length?r.filter(i=>e.every(n=>lo(i,n,t))):r}function co(r){return JSON.stringify(r.map(e=>({field:e.field,operator:e.operator,value:e.value,valueTo:e.valueTo})))}function ui(r,e){const t=new Set;for(const i of r){const n=i[e];n!=null&&t.add(n)}return[...t].sort((i,n)=>typeof i=="number"&&typeof n=="number"?i-n:String(i).localeCompare(String(n)))}const uo='@layer tbw-plugins{tbw-grid .tbw-quick-filter-input{flex:1;max-width:300px;height:var(--tbw-input-height, 1.75rem);padding:var(--tbw-input-padding, 0 .5rem);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);background:var(--tbw-color-bg);color:var(--tbw-color-fg);font-size:var(--tbw-font-size-sm, .8125rem)}tbw-grid .tbw-quick-filter-input:focus{outline:none;border-color:var(--tbw-color-accent)}tbw-grid .header-cell.filtered:before{content:"";position:absolute;top:var(--tbw-spacing-xs, .25rem);right:var(--tbw-spacing-xs, .25rem);width:var(--tbw-indicator-size, .375rem);height:var(--tbw-indicator-size, .375rem);background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border-radius:50%}tbw-grid .tbw-filter-btn{display:var(--tbw-filter-btn-display, inline-flex);visibility:var(--tbw-filter-btn-visibility, visible);align-items:center;justify-content:center;background:transparent;border:none;cursor:pointer;padding:2px;margin-left:var(--tbw-spacing-xs, .25rem);opacity:.4;transition:opacity .15s,visibility 0s,display 0s allow-discrete;color:inherit;vertical-align:middle;transition-behavior:allow-discrete}tbw-grid .tbw-filter-btn:hover,tbw-grid .tbw-filter-btn.active{opacity:1;visibility:visible;display:inline-flex}tbw-grid .tbw-filter-btn.active{color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6))}tbw-grid .header-row .cell:hover .tbw-filter-btn,tbw-grid .header-row .cell.filtered .tbw-filter-btn{display:inline-flex;visibility:visible}}',ho="@layer tbw-plugins{.tbw-filter-panel{position:fixed;background:var(--tbw-filter-panel-bg, var(--tbw-color-panel-bg, light-dark(#eeeeee, #222222)));color:var(--tbw-filter-panel-fg, var(--tbw-color-fg, light-dark(#222222, #eeeeee)));border:1px solid var(--tbw-filter-panel-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-filter-panel-radius, var(--tbw-border-radius, .25rem));box-shadow:0 4px 16px var(--tbw-filter-panel-shadow, var(--tbw-color-shadow, light-dark(rgba(0, 0, 0, .1), rgba(0, 0, 0, .3))));padding:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));z-index:10000;min-width:200px;max-width:280px;max-height:350px;display:flex;flex-direction:column;font-family:var(--tbw-font-family, system-ui, sans-serif);font-size:var(--tbw-font-size, .8125rem);transform-origin:top center}.tbw-filter-panel.tbw-filter-panel-above{transform-origin:bottom center}.tbw-filter-panel.tbw-filter-panel-animated{animation:tbw-filter-panel-enter var(--tbw-animation-duration, .15s) var(--tbw-animation-easing, ease-out)}.tbw-filter-panel.tbw-filter-panel-above.tbw-filter-panel-animated{animation:tbw-filter-panel-enter-above var(--tbw-animation-duration, .15s) var(--tbw-animation-easing, ease-out)}@keyframes tbw-filter-panel-enter{0%{opacity:0;transform:scaleY(.3) translateY(-10px)}to{opacity:1;transform:scaleY(1) translateY(0)}}@keyframes tbw-filter-panel-enter-above{0%{opacity:0;transform:scaleY(.3) translateY(10px)}to{opacity:1;transform:scaleY(1) translateY(0)}}@supports (anchor-name: --test){.tbw-filter-panel{position-anchor:--tbw-filter-anchor;top:anchor(bottom);left:anchor(left);margin-top:4px;position-try-fallbacks:flip-inline,flip-block,flip-block flip-inline}}.tbw-filter-search{margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));min-height:var(--tbw-filter-item-height, 28px)}.tbw-filter-search-input{height:var(--tbw-filter-item-height, 28px);width:100%;padding:var(--tbw-filter-search-padding, var(--tbw-spacing-sm, .375rem) var(--tbw-spacing-md, .5rem));background:var(--tbw-filter-input-bg, var(--tbw-color-bg, transparent));color:inherit;border:1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-filter-input-radius, var(--tbw-border-radius, .25rem));font-size:inherit;box-sizing:border-box}.tbw-filter-search-input:focus{outline:none;border-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));box-shadow:0 0 0 2px rgba(from var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6)) r g b / 15%)}.tbw-filter-actions{display:flex;padding:var(--tbw-button-padding-sm, .25rem .125rem);margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border-bottom:1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));min-height:var(--tbw-filter-item-height, 28px)}.tbw-filter-actions .tbw-filter-value-item{flex:1}.tbw-filter-values{flex:1;overflow-y:auto;margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));max-height:180px;position:relative}.tbw-filter-values-spacer{width:1px}.tbw-filter-values-content{position:absolute;top:0;left:0;right:0}.tbw-filter-value-item{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding:var(--tbw-button-padding-sm, .25rem .125rem);cursor:pointer;border-radius:3px;height:var(--tbw-filter-item-height, 28px)}.tbw-filter-value-item:hover{background:var(--tbw-filter-hover, var(--tbw-color-row-hover, light-dark(#f0f6ff, #1c1c1c)))}.tbw-filter-checkbox{margin:0;cursor:pointer;accent-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6))}.tbw-filter-no-match{color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem)) 0;text-align:center;font-style:italic}.tbw-filter-buttons{display:flex;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding-top:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border-top:1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)))}.tbw-filter-apply-btn{flex:1;padding:var(--tbw-filter-btn-padding, var(--tbw-button-padding, .375rem .75rem));background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));color:var(--tbw-filter-accent-fg, var(--tbw-color-accent-fg, light-dark(#ffffff, #000000)));border:none;border-radius:var(--tbw-border-radius, .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem);font-weight:var(--tbw-filter-btn-font-weight, 500);min-height:var(--tbw-filter-btn-min-height, auto)}.tbw-filter-apply-btn:hover{filter:brightness(.9)}.tbw-filter-clear-btn{flex:1;padding:var(--tbw-filter-btn-padding, var(--tbw-button-padding, .375rem .75rem));background:transparent;color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));border:1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-border-radius, .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem);font-weight:var(--tbw-filter-btn-font-weight, 500);min-height:var(--tbw-filter-btn-min-height, auto)}.tbw-filter-clear-btn:hover{background:var(--tbw-filter-hover, var(--tbw-color-row-hover, light-dark(#f0f6ff, #1c1c1c)))}.tbw-filter-range-inputs,.tbw-filter-date-range{display:flex;align-items:flex-end;gap:var(--tbw-spacing-sm, .375rem);margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-filter-range-group,.tbw-filter-date-group{display:flex;flex-direction:column;gap:var(--tbw-spacing-xs, .25rem);flex:1}.tbw-filter-range-label{font-size:var(--tbw-font-size-xs, .75rem);color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)))}.tbw-filter-range-input,.tbw-filter-date-input{width:100%;height:var(--tbw-filter-item-height, 28px);padding:var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-sm, .375rem);background:var(--tbw-filter-input-bg, var(--tbw-color-bg, transparent));color:inherit;border:1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-filter-input-radius, var(--tbw-border-radius, .25rem));font-size:inherit;box-sizing:border-box}.tbw-filter-range-input:focus,.tbw-filter-date-input:focus{outline:none;border-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));box-shadow:0 0 0 2px rgba(from var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6)) r g b / 15%)}.tbw-filter-range-separator{color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));padding-bottom:var(--tbw-spacing-xs, .25rem)}.tbw-filter-range-slider{position:relative;height:24px;margin:var(--tbw-spacing-md, .5rem) 0 var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-filter-range-track{position:absolute;top:50%;left:0;right:0;height:4px;background:var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:2px;transform:translateY(-50%)}.tbw-filter-range-fill{position:absolute;top:50%;height:4px;background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border-radius:2px;transform:translateY(-50%)}.tbw-filter-range-thumb{position:absolute;top:0;width:100%;height:100%;background:none;pointer-events:none;-webkit-appearance:none;appearance:none}.tbw-filter-range-thumb::-webkit-slider-thumb{-webkit-appearance:none;appearance:none;width:16px;height:16px;background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border:2px solid var(--tbw-filter-panel-bg, var(--tbw-color-panel-bg, light-dark(#eeeeee, #222222)));border-radius:50%;cursor:pointer;pointer-events:all;box-shadow:0 1px 3px #0003}.tbw-filter-range-thumb::-moz-range-thumb{width:16px;height:16px;background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border:2px solid var(--tbw-filter-panel-bg, var(--tbw-color-panel-bg, light-dark(#eeeeee, #222222)));border-radius:50%;cursor:pointer;pointer-events:all;box-shadow:0 1px 3px #0003}.tbw-filter-range-thumb::-webkit-slider-thumb:hover{transform:scale(1.1)}.tbw-filter-range-thumb::-moz-range-thumb:hover{transform:scale(1.1)}}";class W extends D{static manifest={events:[{type:"filter-applied",description:"Emitted when filter criteria change. Subscribers can react to row visibility changes."}]};name="filtering";styles=uo;get defaultConfig(){return{debounceMs:300,caseSensitive:!1,trimInput:!0,useWorker:!0}}isFilteringEnabled(){return this.grid.effectiveConfig?.filterable!==!1}isColumnFilterable(e){return this.isFilteringEnabled()?e.filterable!==!1:!1}filters=new Map;cachedResult=null;cacheKey=null;openPanelField=null;panelElement=null;panelAnchorElement=null;searchText=new Map;excludedValues=new Map;panelAbortController=null;globalStylesInjected=!1;static DEFAULT_LIST_ITEM_HEIGHT=28;static LIST_OVERSCAN=3;static LIST_BYPASS_THRESHOLD=50;getListItemHeight(){if(this.panelElement){const e=getComputedStyle(this.panelElement).getPropertyValue("--tbw-filter-item-height");if(e&&e.trim()){const t=parseFloat(e);if(!isNaN(t)&&t>0)return t}}return W.DEFAULT_LIST_ITEM_HEIGHT}syncExcludedValues(e,t){t?t.type==="set"&&t.operator==="notIn"&&Array.isArray(t.value)?this.excludedValues.set(e,new Set(t.value)):t.type==="set"&&this.excludedValues.delete(e):this.excludedValues.delete(e)}attach(e){super.attach(e),this.injectGlobalStyles()}detach(){this.filters.clear(),this.cachedResult=null,this.cacheKey=null,this.openPanelField=null,this.panelElement&&(this.panelElement.remove(),this.panelElement=null),this.searchText.clear(),this.excludedValues.clear(),this.panelAbortController?.abort(),this.panelAbortController=null}processRows(e){const t=[...this.filters.values()];if(!t.length)return[...e];if(this.config.filterHandler)return this.cachedResult?this.cachedResult:[...e];const i=co(t);if(this.cacheKey===i&&this.cachedResult)return this.cachedResult;const n=ao([...e],t,this.config.caseSensitive);return this.cachedResult=n,this.cacheKey=i,n}afterRender(){const e=this.gridElement;if(!e)return;e.querySelectorAll('[part~="header-cell"]').forEach(i=>{const n=i.getAttribute("data-col");if(n===null)return;const o=this.visibleColumns[parseInt(n,10)];if(!o||!this.isColumnFilterable(o)||X(o))return;const s=o.field;if(!s)return;const l=this.filters.has(s);let a=i.querySelector(".tbw-filter-btn");if(a){const u=a.classList.contains("active");if(a.classList.toggle("active",l),i.classList.toggle("filtered",l),u!==l){const h=l?"filterActive":"filter";this.setIcon(a,this.resolveIcon(h))}return}a=document.createElement("button"),a.className="tbw-filter-btn",a.setAttribute("aria-label",`Filter ${o.header??s}`);const c=l?"filterActive":"filter";this.setIcon(a,this.resolveIcon(c)),l&&(a.classList.add("active"),i.classList.add("filtered")),a.addEventListener("click",u=>{u.stopPropagation(),this.toggleFilterPanel(s,o,a)});const d=i.querySelector(".resize-handle");d?i.insertBefore(a,d):i.appendChild(a)})}setFilter(e,t){if(t===null)this.filters.delete(e),this.syncExcludedValues(e,null);else{const i={...t,field:e};this.filters.set(e,i),this.syncExcludedValues(e,i)}this.cachedResult=null,this.cacheKey=null,this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0}),this.emitPluginEvent("filter-applied",{filters:[...this.filters.values()]}),this.requestRender()}getFilter(e){return this.filters.get(e)}getFilters(){return[...this.filters.values()]}getFilterModel(){return this.getFilters()}setFilterModel(e){this.filters.clear(),this.excludedValues.clear();for(const t of e)this.filters.set(t.field,t),this.syncExcludedValues(t.field,t);this.cachedResult=null,this.cacheKey=null,this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0}),this.emitPluginEvent("filter-applied",{filters:[...this.filters.values()]}),this.requestRender()}clearAllFilters(){this.filters.clear(),this.excludedValues.clear(),this.searchText.clear(),this.applyFiltersInternal()}clearFieldFilter(e){this.filters.delete(e),this.excludedValues.delete(e),this.searchText.delete(e),this.applyFiltersInternal()}isFieldFiltered(e){return this.filters.has(e)}getFilteredRowCount(){return this.cachedResult?.length??this.rows.length}getActiveFilters(){return this.getFilters()}getUniqueValues(e){return ui(this.sourceRows,e)}copyGridThemeContext(e){const t=this.gridElement;if(!t)return;for(const n of t.classList)n.startsWith("tbw-")||n==="selecting"||e.classList.add(n);const i=t.dataset.theme;i&&(e.dataset.theme=i)}injectGlobalStyles(){if(this.globalStylesInjected)return;if(document.getElementById("tbw-filter-panel-styles")){this.globalStylesInjected=!0;return}const e=document.createElement("style");e.id="tbw-filter-panel-styles",e.textContent=ho,document.head.appendChild(e),this.globalStylesInjected=!0}toggleFilterPanel(e,t,i){if(this.openPanelField===e){this.closeFilterPanel();return}this.closeFilterPanel();const n=document.createElement("div");if(n.className="tbw-filter-panel",this.copyGridThemeContext(n),this.isAnimationEnabled&&n.classList.add("tbw-filter-panel-animated"),this.panelElement=n,this.openPanelField=e,this.config.valuesHandler){n.innerHTML='<div class="tbw-filter-loading">Loading...</div>',document.body.appendChild(n),this.positionPanel(n,i),this.setupPanelCloseHandler(n,i),this.config.valuesHandler(e,t).then(s=>{this.openPanelField!==e||!this.panelElement||(n.innerHTML="",this.renderPanelContent(e,t,n,s))});return}const o=ui(this.sourceRows,e);document.body.appendChild(n),this.positionPanel(n,i),this.renderPanelContent(e,t,n,o),this.setupPanelCloseHandler(n,i)}renderPanelContent(e,t,i,n){let o=this.excludedValues.get(e);o||(o=new Set,this.excludedValues.set(e,o));const s=this.searchText.get(e)??"",l={field:e,column:t,uniqueValues:n,excludedValues:o,searchText:s,applySetFilter:c=>{this.applySetFilter(e,c),this.closeFilterPanel()},applyTextFilter:(c,d,u)=>{this.applyTextFilter(e,c,d,u),this.closeFilterPanel()},clearFilter:()=>{this.clearFieldFilter(e),this.closeFilterPanel()},closePanel:()=>this.closeFilterPanel()};let a=!1;if(this.config.filterPanelRenderer&&(this.config.filterPanelRenderer(i,l),a=i.children.length>0),!a&&t.type){const c=this.grid.effectiveConfig.typeDefaults?.[t.type];c?.filterPanelRenderer&&(c.filterPanelRenderer(i,l),a=i.children.length>0)}if(!a){const c=t.type;c==="number"?this.renderNumberFilterPanel(i,l,n):c==="date"?this.renderDateFilterPanel(i,l,n):this.renderDefaultFilterPanel(i,l,n,o)}}setupPanelCloseHandler(e,t){this.panelAbortController=new AbortController,setTimeout(()=>{document.addEventListener("click",i=>{!e.contains(i.target)&&i.target!==t&&this.closeFilterPanel()},{signal:this.panelAbortController?.signal})},0)}closeFilterPanel(){const e=this.panelElement;e&&(e.remove(),this.panelElement=null),this.panelAnchorElement&&(this.panelAnchorElement.style.anchorName="",this.panelAnchorElement=null),this.openPanelField=null,this.panelAbortController?.abort(),this.panelAbortController=null}static supportsAnchorPositioning=null;static checkAnchorPositioningSupport(){return W.supportsAnchorPositioning===null&&(W.supportsAnchorPositioning=CSS.supports("anchor-name","--test")),W.supportsAnchorPositioning}positionPanel(e,t){const n=t.closest(".cell")??t;if(n.style.anchorName="--tbw-filter-anchor",this.panelAnchorElement=n,W.checkAnchorPositioningSupport()){requestAnimationFrame(()=>{const s=e.getBoundingClientRect(),l=n.getBoundingClientRect();s.top<l.top&&e.classList.add("tbw-filter-panel-above")});return}const o=n.getBoundingClientRect();e.style.position="fixed",e.style.top=`${o.bottom+4}px`,e.style.left=`${o.left}px`,requestAnimationFrame(()=>{const s=e.getBoundingClientRect();s.right>window.innerWidth-8&&(e.style.left=`${o.right-s.width}px`),s.bottom>window.innerHeight-8&&(e.style.top=`${o.top-s.height-4}px`,e.classList.add("tbw-filter-panel-above"))})}renderDefaultFilterPanel(e,t,i,n){const{field:o}=t,s=this.getListItemHeight(),l=document.createElement("div");l.className="tbw-filter-search";const a=document.createElement("input");a.type="text",a.placeholder="Search...",a.className="tbw-filter-search-input",a.value=this.searchText.get(o)??"",l.appendChild(a),e.appendChild(l);const c=document.createElement("div");c.className="tbw-filter-actions";const d=document.createElement("label");d.className="tbw-filter-value-item",d.style.padding="0",d.style.margin="0";const u=document.createElement("input");u.type="checkbox",u.className="tbw-filter-checkbox";const h=document.createElement("span");h.textContent="Select All",d.appendChild(u),d.appendChild(h),c.appendChild(d);const f=()=>{const A=[...b.values()],_=A.every(C=>C),T=A.every(C=>!C);u.checked=_,u.indeterminate=!_&&!T};u.addEventListener("change",()=>{const A=u.checked;for(const _ of b.keys())b.set(_,A);f(),x()}),e.appendChild(c);const p=document.createElement("div");p.className="tbw-filter-values";const g=document.createElement("div");g.className="tbw-filter-values-spacer",p.appendChild(g);const w=document.createElement("div");w.className="tbw-filter-values-content",p.appendChild(w);const b=new Map;i.forEach(A=>{const _=A==null?"__null__":String(A);b.set(_,!n.has(A))}),f();let m=[];const v=(A,_)=>{const T=A==null?"(Blank)":String(A),C=A==null?"__null__":String(A),k=document.createElement("label");k.className="tbw-filter-value-item",k.style.position="absolute",k.style.top=`calc(var(--tbw-filter-item-height, 28px) * ${_})`,k.style.left="0",k.style.right="0",k.style.boxSizing="border-box";const N=document.createElement("input");N.type="checkbox",N.className="tbw-filter-checkbox",N.checked=b.get(C)??!0,N.dataset.value=C,N.addEventListener("change",()=>{b.set(C,N.checked),f()});const J=document.createElement("span");return J.textContent=T,k.appendChild(N),k.appendChild(J),k},x=()=>{const A=m.length,_=p.clientHeight,T=p.scrollTop;if(g.style.height=`${A*s}px`,Sr(A,W.LIST_BYPASS_THRESHOLD/3)){w.innerHTML="",w.style.transform="translateY(0px)",m.forEach((k,N)=>{w.appendChild(v(k,N))});return}const C=Rr({totalRows:A,viewportHeight:_,scrollTop:T,rowHeight:s,overscan:W.LIST_OVERSCAN});w.style.transform=`translateY(${C.offsetY}px)`,w.innerHTML="";for(let k=C.start;k<C.end;k++)w.appendChild(v(m[k],k-C.start))},S=A=>{const _=this.config.caseSensitive??!1,T=_?A:A.toLowerCase();if(m=i.filter(C=>{const k=C==null?"(Blank)":String(C),N=_?k:k.toLowerCase();return!A||N.includes(T)}),m.length===0){g.style.height="0px",w.innerHTML="";const C=document.createElement("div");C.className="tbw-filter-no-match",C.textContent="No matching values",w.appendChild(C);return}x()};p.addEventListener("scroll",()=>{m.length>0&&x()},{passive:!0}),S(a.value),e.appendChild(p);let R;a.addEventListener("input",()=>{clearTimeout(R),R=setTimeout(()=>{this.searchText.set(o,a.value),S(a.value)},this.config.debounceMs??150)});const L=document.createElement("div");L.className="tbw-filter-buttons";const P=document.createElement("button");P.className="tbw-filter-apply-btn",P.textContent="Apply",P.addEventListener("click",()=>{const A=[];for(const[_,T]of b)if(!T)if(_==="__null__")A.push(null);else{const C=i.find(k=>String(k)===_);A.push(C!==void 0?C:_)}t.applySetFilter(A)}),L.appendChild(P);const y=document.createElement("button");y.className="tbw-filter-clear-btn",y.textContent="Clear Filter",y.addEventListener("click",()=>{t.clearFilter()}),L.appendChild(y),e.appendChild(L)}renderNumberFilterPanel(e,t,i){const{field:n,column:o}=t,s=o.filterParams,l=o.editorParams,a=(H,oe)=>{if(typeof H=="number")return H;if(typeof H=="string"){const we=parseFloat(H);return isNaN(we)?oe:we}return oe},c=i.filter(H=>typeof H=="number"&&!isNaN(H)),d=c.length>0?Math.min(...c):0,u=c.length>0?Math.max(...c):100,h=a(s?.min??l?.min,d),f=a(s?.max??l?.max,u),p=s?.step??l?.step??1,g=this.filters.get(n);let w=h,b=f;g?.operator==="between"?(w=a(g.value,h),b=a(g.valueTo,f)):g?.operator==="greaterThanOrEqual"?w=a(g.value,h):g?.operator==="lessThanOrEqual"&&(b=a(g.value,f));const m=document.createElement("div");m.className="tbw-filter-range-inputs";const v=document.createElement("div");v.className="tbw-filter-range-group";const x=document.createElement("label");x.textContent="Min",x.className="tbw-filter-range-label";const S=document.createElement("input");S.type="number",S.className="tbw-filter-range-input",S.min=String(h),S.max=String(f),S.step=String(p),S.value=String(w),v.appendChild(x),v.appendChild(S),m.appendChild(v);const R=document.createElement("span");R.className="tbw-filter-range-separator",R.textContent="–",m.appendChild(R);const L=document.createElement("div");L.className="tbw-filter-range-group";const P=document.createElement("label");P.textContent="Max",P.className="tbw-filter-range-label";const y=document.createElement("input");y.type="number",y.className="tbw-filter-range-input",y.min=String(h),y.max=String(f),y.step=String(p),y.value=String(b),L.appendChild(P),L.appendChild(y),m.appendChild(L),e.appendChild(m);const A=document.createElement("div");A.className="tbw-filter-range-slider";const _=document.createElement("div");_.className="tbw-filter-range-track";const T=document.createElement("div");T.className="tbw-filter-range-fill";const C=document.createElement("input");C.type="range",C.className="tbw-filter-range-thumb tbw-filter-range-thumb-min",C.min=String(h),C.max=String(f),C.step=String(p),C.value=String(w);const k=document.createElement("input");k.type="range",k.className="tbw-filter-range-thumb tbw-filter-range-thumb-max",k.min=String(h),k.max=String(f),k.step=String(p),k.value=String(b),A.appendChild(_),A.appendChild(T),A.appendChild(C),A.appendChild(k),e.appendChild(A);const N=()=>{const H=parseFloat(C.value),oe=parseFloat(k.value),we=f-h,$i=(H-h)/we*100,Ws=(oe-h)/we*100;T.style.left=`${$i}%`,T.style.width=`${Ws-$i}%`};C.addEventListener("input",()=>{const H=Math.min(parseFloat(C.value),parseFloat(k.value));C.value=String(H),S.value=String(H),N()}),k.addEventListener("input",()=>{const H=Math.max(parseFloat(k.value),parseFloat(C.value));k.value=String(H),y.value=String(H),N()}),S.addEventListener("input",()=>{let H=parseFloat(S.value)||h;H=Math.max(h,Math.min(H,parseFloat(y.value))),C.value=String(H),N()}),y.addEventListener("input",()=>{let H=parseFloat(y.value)||f;H=Math.min(f,Math.max(H,parseFloat(S.value))),k.value=String(H),N()}),N();const J=document.createElement("div");J.className="tbw-filter-buttons";const De=document.createElement("button");De.className="tbw-filter-apply-btn",De.textContent="Apply",De.addEventListener("click",()=>{const H=parseFloat(S.value),oe=parseFloat(y.value);t.applyTextFilter("between",H,oe)}),J.appendChild(De);const Ie=document.createElement("button");Ie.className="tbw-filter-clear-btn",Ie.textContent="Clear Filter",Ie.addEventListener("click",()=>{t.clearFilter()}),J.appendChild(Ie),e.appendChild(J)}renderDateFilterPanel(e,t,i){const{field:n,column:o}=t,s=o.filterParams,l=o.editorParams,a=i.filter(C=>C instanceof Date||typeof C=="string"&&!isNaN(Date.parse(C))).map(C=>C instanceof Date?C:new Date(C)).filter(C=>!isNaN(C.getTime())),c=a.length>0?new Date(Math.min(...a.map(C=>C.getTime()))):null,d=a.length>0?new Date(Math.max(...a.map(C=>C.getTime()))):null,u=C=>C?C.toISOString().split("T")[0]:"",h=C=>C?typeof C=="string"?C:typeof C=="number"?u(new Date(C)):"":"",f=h(s?.min)||h(l?.min)||u(c),p=h(s?.max)||h(l?.max)||u(d),g=this.filters.get(n);let w="",b="";g?.operator==="between"?(w=h(g.value)||"",b=h(g.valueTo)||""):g?.operator==="greaterThanOrEqual"?w=h(g.value)||"":g?.operator==="lessThanOrEqual"&&(b=h(g.value)||"");const m=document.createElement("div");m.className="tbw-filter-date-range";const v=document.createElement("div");v.className="tbw-filter-date-group";const x=document.createElement("label");x.textContent="From",x.className="tbw-filter-range-label";const S=document.createElement("input");S.type="date",S.className="tbw-filter-date-input",f&&(S.min=f),p&&(S.max=p),S.value=w,v.appendChild(x),v.appendChild(S),m.appendChild(v);const R=document.createElement("span");R.className="tbw-filter-range-separator",R.textContent="–",m.appendChild(R);const L=document.createElement("div");L.className="tbw-filter-date-group";const P=document.createElement("label");P.textContent="To",P.className="tbw-filter-range-label";const y=document.createElement("input");y.type="date",y.className="tbw-filter-date-input",f&&(y.min=f),p&&(y.max=p),y.value=b,L.appendChild(P),L.appendChild(y),m.appendChild(L),e.appendChild(m);const A=document.createElement("div");A.className="tbw-filter-buttons";const _=document.createElement("button");_.className="tbw-filter-apply-btn",_.textContent="Apply",_.addEventListener("click",()=>{const C=S.value,k=y.value;C&&k?t.applyTextFilter("between",C,k):C?t.applyTextFilter("greaterThanOrEqual",C):k?t.applyTextFilter("lessThanOrEqual",k):t.clearFilter()}),A.appendChild(_);const T=document.createElement("button");T.className="tbw-filter-clear-btn",T.textContent="Clear Filter",T.addEventListener("click",()=>{t.clearFilter()}),A.appendChild(T),e.appendChild(A)}applySetFilter(e,t){this.excludedValues.set(e,new Set(t)),t.length===0?this.filters.delete(e):this.filters.set(e,{field:e,type:"set",operator:"notIn",value:t}),this.applyFiltersInternal()}applyTextFilter(e,t,i,n){this.filters.set(e,{field:e,type:"text",operator:t,value:i,valueTo:n}),this.applyFiltersInternal()}applyFiltersInternal(){this.cachedResult=null,this.cacheKey=null;const e=[...this.filters.values()];if(this.config.filterHandler){const t=this.grid;t.setAttribute("aria-busy","true");const i=this.config.filterHandler(e,this.sourceRows),n=o=>{t.removeAttribute("aria-busy"),this.cachedResult=o,this.grid.rows=o,this.emit("filter-change",{filters:e,filteredRowCount:o.length}),this.emitPluginEvent("filter-applied",{filters:e}),this.requestRender()};i&&typeof i.then=="function"?i.then(n):n(i);return}this.emit("filter-change",{filters:e,filteredRowCount:0}),this.emitPluginEvent("filter-applied",{filters:e}),this.requestRender()}getColumnState(e){const t=this.filters.get(e);if(t)return{filter:{type:t.type,operator:t.operator,value:t.value,valueTo:t.valueTo}}}applyColumnState(e,t){if(!t.filter){this.filters.delete(e);return}const i={field:e,type:t.filter.type,operator:t.filter.operator,value:t.filter.value,valueTo:t.filter.valueTo};this.filters.set(e,i),this.cachedResult=null,this.cacheKey=null}}function hi(r){if(!r.length)return[];const e=new Map,t=[],i=(s,l)=>{if(!l.length)return;const a=t[t.length-1];if(a&&a.implicit&&a.firstIndex+a.columns.length===s){a.columns.push(...l);return}t.push({id:"__implicit__"+s,label:void 0,columns:l,firstIndex:s,implicit:!0})};let n=[],o=0;return r.forEach((s,l)=>{const a=s.group;if(!a){n.length===0&&(o=l),n.push(s);return}n.length&&(i(o,n.slice()),n=[]);const c=typeof a=="string"?a:a.id;let d=e.get(c);d||(d={id:c,label:typeof a=="string"?void 0:a.label,columns:[],firstIndex:l},e.set(c,d),t.push(d)),d.columns.push(s)}),n.length&&i(o,n),t.length===1&&t[0].implicit&&t[0].columns.length===r.length?[]:t}function fo(r,e,t){if(!e.length||!r)return;const i=new Map;for(const o of e)for(const s of o.columns)s.field&&i.set(s.field,o.id);const n=Array.from(r.querySelectorAll(".cell[data-field]"));n.forEach(o=>{const s=o.getAttribute("data-field")||"",l=i.get(s);l&&(o.classList.add("grouped"),o.getAttribute("data-group")||o.setAttribute("data-group",l))});for(const o of e){const s=o.columns[o.columns.length-1],l=n.find(a=>a.getAttribute("data-field")===s.field);l&&l.classList.add("group-end")}}function go(r,e){if(r.length===0)return null;const t=document.createElement("div");t.className="header-group-row",t.setAttribute("role","row");for(const i of r){const n=i.columns[0],o=n?e.findIndex(c=>c.field===n.field):-1;if(o===-1)continue;const s=String(i.id).startsWith("__implicit__"),l=s?"":i.label||i.id,a=document.createElement("div");a.className="cell header-group-cell",s&&a.classList.add("implicit-group"),a.setAttribute("data-group",String(i.id)),a.style.gridColumn=`${o+1} / span ${i.columns.length}`,a.textContent=l,t.appendChild(a)}return t}function po(r){return r.some(e=>e.group!=null)}const wo="@layer tbw-plugins{.header-group-row{display:grid;grid-auto-flow:column;background:var(--tbw-grouping-columns-header-bg, var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-grouping-columns-border, var(--tbw-color-border))}.header-group-cell{display:flex;align-items:center;justify-content:center;padding:var(--tbw-button-padding-sm, .25rem .5rem);font-weight:600;font-size:var(--tbw-font-size-sm, .9em);text-transform:uppercase;letter-spacing:.5px;border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-group-cell:last-child{border-right:none}.header-row .cell.grouped{border-top:none}.header-row .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-row .cell.group-end:last-child{border-right:none}.rows .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.rows .cell.group-end:last-child{border-right:none}.header-group-row.no-borders{border-bottom:none}.header-group-row.no-borders .header-group-cell{border-right:none}.header-row.no-group-borders .cell.group-end{border-right:1px solid var(--tbw-color-border)}}";class mo extends D{static manifest={ownedProperties:[{property:"group",level:"column",description:'the "group" column property'},{property:"columnGroups",level:"config",description:'the "columnGroups" config property',isUsed:e=>Array.isArray(e)&&e.length>0}]};name="groupingColumns";styles=wo;get defaultConfig(){return{showGroupBorders:!0}}groups=[];isActive=!1;#t=new Set;detach(){this.groups=[],this.isActive=!1,this.#t.clear()}static detect(e,t){if(t?.columnGroups&&Array.isArray(t.columnGroups)&&t.columnGroups.length>0)return!0;const i=t?.columns;return Array.isArray(i)?po(i):!1}processColumns(e){const t=this.grid?.gridConfig?.columnGroups;let i;if(t&&Array.isArray(t)&&t.length>0){const o=new Map;for(const s of t)for(const l of s.children)o.set(l,{id:s.id,label:s.header});i=e.map(s=>{const l=o.get(s.field);return l&&!s.group?{...s,group:l}:s})}else i=[...e];const n=hi(i);if(n.length===0)return this.isActive=!1,this.groups=[],i;this.isActive=!0,this.groups=n,this.#t.clear();for(const o of n){const s=o.columns[o.columns.length-1];s?.field&&this.#t.add(s.field)}return i}afterRender(){if(!this.isActive){const a=this.gridElement?.querySelector(".header")?.querySelector(".header-group-row");a&&a.remove();return}const e=this.gridElement?.querySelector(".header");if(!e)return;const t=e.querySelector(".header-group-row");t&&t.remove();const i=this.columns,n=hi(i);if(n.length===0)return;const o=go(n,i);if(o){o.classList.toggle("no-borders",!this.config.showGroupBorders);const l=e.querySelector(".header-row");l?e.insertBefore(o,l):e.appendChild(o)}const s=e.querySelector(".header-row");s&&(s.classList.toggle("no-group-borders",!this.config.showGroupBorders),fo(s,n))}afterCellRender(e){!this.isActive||!this.config.showGroupBorders||e.cellElement.classList.toggle("group-end",this.#t.has(e.column.field))}isGroupingActive(){return this.isActive}getGroups(){return this.groups}getGroupColumns(e){const t=this.groups.find(i=>i.id===e);return t?t.columns:[]}refresh(){this.requestRender()}}const ot={sum:(r,e)=>r.reduce((t,i)=>t+(Number(i[e])||0),0),avg:(r,e)=>{const t=r.reduce((i,n)=>i+(Number(n[e])||0),0);return r.length?t/r.length:0},count:r=>r.length,min:(r,e)=>r.length?Math.min(...r.map(t=>Number(t[e])||1/0)):0,max:(r,e)=>r.length?Math.max(...r.map(t=>Number(t[e])||-1/0)):0,first:(r,e)=>r[0]?.[e],last:(r,e)=>r[r.length-1]?.[e]},ge=new Map,$={register(r,e){ge.set(r,e)},unregister(r){ge.delete(r)},get(r){if(r!==void 0)return typeof r=="function"?r:ge.get(r)??ot[r]},run(r,e,t,i){const n=this.get(r);return n?n(e,t,i):void 0},has(r){return ge.has(r)||r in ot},list(){return[...Object.keys(ot),...ge.keys()]}},fi={sum:r=>r.reduce((e,t)=>e+t,0),avg:r=>r.length?r.reduce((e,t)=>e+t,0)/r.length:0,count:r=>r.length,min:r=>r.length?Math.min(...r):0,max:r=>r.length?Math.max(...r):0,first:r=>r[0]??0,last:r=>r[r.length-1]??0};function bo(r){return fi[r]??fi.sum}$.register.bind($),$.unregister.bind($);const gi=$.get.bind($),st=$.run.bind($);$.list.bind($);function pi({rows:r,config:e,expanded:t,initialExpanded:i}){const n=e.groupOn;if(typeof n!="function")return[];const o={key:"__root__",value:null,depth:-1,rows:[],children:new Map};if(r.forEach(c=>{let d=n(c);d==null||d===!1?d=["__ungrouped__"]:Array.isArray(d)||(d=[d]);let u=o;d.forEach((h,f)=>{const p=h==null?"∅":String(h),g=u.key==="__root__"?p:u.key+"||"+p;let w=u.children.get(p);w||(w={key:g,value:h,depth:f,rows:[],children:new Map,parent:u},u.children.set(p,w)),u=w}),u.rows.push(c)}),o.children.size===1&&o.children.has("__ungrouped__")&&o.children.get("__ungrouped__").rows.length===r.length)return[];const s=new Set([...t,...i??[]]),l=[],a=c=>{if(c===o){c.children.forEach(u=>a(u));return}const d=s.has(c.key);l.push({kind:"group",key:c.key,value:c.value,depth:c.depth,rows:c.rows,expanded:d}),d&&(c.children.size?c.children.forEach(u=>a(u)):c.rows.forEach(u=>l.push({kind:"data",row:u,rowIndex:r.indexOf(u)})))};return a(o),l}function vo(r,e){const t=new Set(r);return t.has(e)?t.delete(e):t.add(e),t}function yo(r){const e=new Set;for(const t of r)t.kind==="group"&&e.add(t.key);return e}function Co(){return new Set}function xo(r,e){if(r===!0)return new Set(e);if(r===!1||r==null)return new Set;if(typeof r=="number"){const t=e[r];return t?new Set([t]):new Set}return typeof r=="string"?new Set([r]):Array.isArray(r)?new Set(r):new Set}function Eo(r){return r.filter(e=>e.kind==="group").map(e=>e.key)}function Ro(r){return r.kind!=="group"?0:r.rows.length}const So="@layer tbw-plugins{.group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-grouping-rows-bg, var(--tbw-color-panel-bg));font-weight:500;border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height)}.group-row .cell{display:flex;align-items:center;padding:var(--tbw-cell-padding, .125rem .5rem)}.group-row:hover{background:var(--tbw-grouping-rows-bg-hover, var(--tbw-color-row-hover))}.group-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-toggle-size, 1.25rem);height:var(--tbw-toggle-size, 1.25rem);margin-right:.25rem;background:none;border:0;font:inherit}.group-toggle:hover{background:var(--tbw-grouping-rows-toggle-hover, var(--tbw-color-row-hover));border-radius:var(--tbw-border-radius, .125rem)}.group-label{display:inline-flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.group-count{color:var(--tbw-grouping-rows-count-color, var(--tbw-color-fg-muted));font-size:var(--tbw-font-size-xs, .85em);font-weight:400}.group-aggregates{display:inline-flex;align-items:center;gap:var(--tbw-spacing-lg, 1rem);margin-left:var(--tbw-spacing-lg, 1rem);font-weight:400;font-size:var(--tbw-font-size-sm, .875em);color:var(--tbw-grouping-rows-aggregate-color, var(--tbw-color-fg-muted))}.group-aggregate{white-space:nowrap}.group-row{padding-left:calc(var(--tbw-group-depth, 0) * var(--tbw-group-indent-width, 1.25em))}.data-grid-row.tbw-group-slide-in{animation:tbw-group-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-group-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.data-grid-row.tbw-group-fade-in{animation:tbw-group-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-group-fade-in{0%{opacity:0}to{opacity:1}}}";class _o extends D{static manifest={events:[{type:"grouping-state-change",description:"Emitted when groups are expanded/collapsed. Subscribers can react to row visibility changes."}],queries:[{type:"canMoveRow",description:"Returns false for group header rows (cannot be reordered)"}],configRules:[{id:"groupingRows/accordion-defaultExpanded",severity:"warn",message:`"accordion: true" and "defaultExpanded" (non-false) are used together.
|
|
107
|
+
</Workbook>`,i}function so(r,e){const t=e.endsWith(".xls")?e:`${e}.xls`,i=new Blob([r],{type:"application/vnd.ms-excel;charset=utf-8;"});ot(i,t)}class lo extends D{name="export";get defaultConfig(){return{fileName:"export",includeHeaders:!0,onlyVisible:!0,onlySelected:!1}}isExportingFlag=!1;lastExportInfo=null;performExport(e,t){const i=this.config,n={format:e,fileName:t?.fileName??i.fileName??"export",includeHeaders:t?.includeHeaders??i.includeHeaders,processCell:t?.processCell,processHeader:t?.processHeader,columns:t?.columns,rowIndices:t?.rowIndices},o=Te(this.columns,t?.columns,i.onlyVisible);let s;if(t?.rowIndices)s=Ze(this.rows,t.rowIndices);else if(i.onlySelected){const a=this.getSelectionState();a?.selected?.size?s=Ze(this.rows,[...a.selected]):s=[...this.rows]}else s=[...this.rows];this.isExportingFlag=!0;let l=n.fileName;try{switch(e){case"csv":{const a=no(s,o,n,{bom:!0});l=l.endsWith(".csv")?l:`${l}.csv`,ro(a,l);break}case"excel":{const a=oo(s,o,n);l=l.endsWith(".xls")?l:`${l}.xls`,so(a,l);break}case"json":{const a=s.map(u=>{const h={};for(const f of o){let p=u[f.field];n.processCell&&(p=n.processCell(p,f.field,u)),h[f.field]=p}return h}),c=JSON.stringify(a,null,2);l=l.endsWith(".json")?l:`${l}.json`;const d=new Blob([c],{type:"application/json"});ot(d,l);break}}this.lastExportInfo={format:e,timestamp:new Date},this.emit("export-complete",{format:e,fileName:l,rowCount:s.length,columnCount:o.length})}finally{this.isExportingFlag=!1}}getSelectionState(){try{return this.grid?.getPluginState?.("selection")??null}catch{return null}}exportCsv(e){this.performExport("csv",e)}exportExcel(e){this.performExport("excel",e)}exportJson(e){this.performExport("json",e)}isExporting(){return this.isExportingFlag}getLastExport(){return this.lastExportInfo}}const ui="__tbw_expander",ao=32;function Le(r){return r.field===ui}function ne(r){return r.meta?.utility===!0}function co(r){return r.find(Le)}function uo(r){return{field:ui,header:"",width:ao,resizable:!1,sortable:!1,filterable:!1,meta:{lockPosition:!0,suppressMovable:!0,expanderColumn:!0,expanderPlugin:r,utility:!0}}}function ho(r,e,t=!1){const i=r[e.field];if(e.operator==="blank")return i==null||i==="";if(e.operator==="notBlank")return i!=null&&i!=="";if(i==null)return!1;const n=String(i),o=t?n:n.toLowerCase(),s=t?String(e.value):String(e.value).toLowerCase();switch(e.operator){case"contains":return o.includes(s);case"notContains":return!o.includes(s);case"equals":return o===s;case"notEquals":return o!==s;case"startsWith":return o.startsWith(s);case"endsWith":return o.endsWith(s);case"lessThan":return Number(i)<Number(e.value);case"lessThanOrEqual":return Number(i)<=Number(e.value);case"greaterThan":return Number(i)>Number(e.value);case"greaterThanOrEqual":return Number(i)>=Number(e.value);case"between":return Number(i)>=Number(e.value)&&Number(i)<=Number(e.valueTo);case"in":return Array.isArray(e.value)&&e.value.includes(i);case"notIn":return Array.isArray(e.value)&&!e.value.includes(i);default:return!0}}function fo(r,e,t=!1){return e.length?r.filter(i=>e.every(n=>ho(i,n,t))):r}function go(r){return JSON.stringify(r.map(e=>({field:e.field,operator:e.operator,value:e.value,valueTo:e.valueTo})))}function hi(r,e){const t=new Set;for(const i of r){const n=i[e];n!=null&&t.add(n)}return[...t].sort((i,n)=>typeof i=="number"&&typeof n=="number"?i-n:String(i).localeCompare(String(n)))}const po='@layer tbw-plugins{tbw-grid .tbw-quick-filter-input{flex:1;max-width:300px;height:var(--tbw-input-height, 1.75rem);padding:var(--tbw-input-padding, 0 .5rem);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);background:var(--tbw-color-bg);color:var(--tbw-color-fg);font-size:var(--tbw-font-size-sm, .8125rem)}tbw-grid .tbw-quick-filter-input:focus{outline:none;border-color:var(--tbw-color-accent)}tbw-grid .header-cell.filtered:before{content:"";position:absolute;top:var(--tbw-spacing-xs, .25rem);right:var(--tbw-spacing-xs, .25rem);width:var(--tbw-indicator-size, .375rem);height:var(--tbw-indicator-size, .375rem);background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border-radius:50%}tbw-grid .tbw-filter-btn{display:var(--tbw-filter-btn-display, inline-flex);visibility:var(--tbw-filter-btn-visibility, visible);align-items:center;justify-content:center;background:transparent;border:none;cursor:pointer;padding:2px;margin-left:var(--tbw-spacing-xs, .25rem);opacity:.4;transition:opacity .15s,visibility 0s,display 0s allow-discrete;color:inherit;vertical-align:middle;transition-behavior:allow-discrete}tbw-grid .tbw-filter-btn:hover,tbw-grid .tbw-filter-btn.active{opacity:1;visibility:visible;display:inline-flex}tbw-grid .tbw-filter-btn.active{color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6))}tbw-grid .header-row .cell:hover .tbw-filter-btn,tbw-grid .header-row .cell.filtered .tbw-filter-btn{display:inline-flex;visibility:visible}}',wo="@layer tbw-plugins{.tbw-filter-panel{position:fixed;background:var(--tbw-filter-panel-bg, var(--tbw-color-panel-bg, light-dark(#eeeeee, #222222)));color:var(--tbw-filter-panel-fg, var(--tbw-color-fg, light-dark(#222222, #eeeeee)));border:1px solid var(--tbw-filter-panel-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-filter-panel-radius, var(--tbw-border-radius, .25rem));box-shadow:0 4px 16px var(--tbw-filter-panel-shadow, var(--tbw-color-shadow, light-dark(rgba(0, 0, 0, .1), rgba(0, 0, 0, .3))));padding:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));z-index:10000;min-width:200px;max-width:280px;max-height:350px;display:flex;flex-direction:column;font-family:var(--tbw-font-family, system-ui, sans-serif);font-size:var(--tbw-font-size, .8125rem);transform-origin:top center}.tbw-filter-panel.tbw-filter-panel-above{transform-origin:bottom center}.tbw-filter-panel.tbw-filter-panel-animated{animation:tbw-filter-panel-enter var(--tbw-animation-duration, .15s) var(--tbw-animation-easing, ease-out)}.tbw-filter-panel.tbw-filter-panel-above.tbw-filter-panel-animated{animation:tbw-filter-panel-enter-above var(--tbw-animation-duration, .15s) var(--tbw-animation-easing, ease-out)}@keyframes tbw-filter-panel-enter{0%{opacity:0;transform:scaleY(.3) translateY(-10px)}to{opacity:1;transform:scaleY(1) translateY(0)}}@keyframes tbw-filter-panel-enter-above{0%{opacity:0;transform:scaleY(.3) translateY(10px)}to{opacity:1;transform:scaleY(1) translateY(0)}}@supports (anchor-name: --test){.tbw-filter-panel{position-anchor:--tbw-filter-anchor;top:anchor(bottom);left:anchor(left);margin-top:4px;position-try-fallbacks:flip-inline,flip-block,flip-block flip-inline}}.tbw-filter-search{margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));min-height:var(--tbw-filter-item-height, 28px)}.tbw-filter-search-input{height:var(--tbw-filter-item-height, 28px);width:100%;padding:var(--tbw-filter-search-padding, var(--tbw-spacing-sm, .375rem) var(--tbw-spacing-md, .5rem));background:var(--tbw-filter-input-bg, var(--tbw-color-bg, transparent));color:inherit;border:1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-filter-input-radius, var(--tbw-border-radius, .25rem));font-size:inherit;box-sizing:border-box}.tbw-filter-search-input:focus{outline:none;border-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));box-shadow:0 0 0 2px rgba(from var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6)) r g b / 15%)}.tbw-filter-actions{display:flex;padding:var(--tbw-button-padding-sm, .25rem .125rem);margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border-bottom:1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));min-height:var(--tbw-filter-item-height, 28px)}.tbw-filter-actions .tbw-filter-value-item{flex:1}.tbw-filter-values{flex:1;overflow-y:auto;margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));max-height:180px;position:relative}.tbw-filter-values-spacer{width:1px}.tbw-filter-values-content{position:absolute;top:0;left:0;right:0}.tbw-filter-value-item{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding:var(--tbw-button-padding-sm, .25rem .125rem);cursor:pointer;border-radius:3px;height:var(--tbw-filter-item-height, 28px)}.tbw-filter-value-item:hover{background:var(--tbw-filter-hover, var(--tbw-color-row-hover, light-dark(#f0f6ff, #1c1c1c)))}.tbw-filter-checkbox{margin:0;cursor:pointer;accent-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6))}.tbw-filter-no-match{color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem)) 0;text-align:center;font-style:italic}.tbw-filter-buttons{display:flex;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding-top:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border-top:1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)))}.tbw-filter-apply-btn{flex:1;padding:var(--tbw-filter-btn-padding, var(--tbw-button-padding, .375rem .75rem));background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));color:var(--tbw-filter-accent-fg, var(--tbw-color-accent-fg, light-dark(#ffffff, #000000)));border:none;border-radius:var(--tbw-border-radius, .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem);font-weight:var(--tbw-filter-btn-font-weight, 500);min-height:var(--tbw-filter-btn-min-height, auto)}.tbw-filter-apply-btn:hover{filter:brightness(.9)}.tbw-filter-clear-btn{flex:1;padding:var(--tbw-filter-btn-padding, var(--tbw-button-padding, .375rem .75rem));background:transparent;color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));border:1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-border-radius, .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem);font-weight:var(--tbw-filter-btn-font-weight, 500);min-height:var(--tbw-filter-btn-min-height, auto)}.tbw-filter-clear-btn:hover{background:var(--tbw-filter-hover, var(--tbw-color-row-hover, light-dark(#f0f6ff, #1c1c1c)))}.tbw-filter-range-inputs,.tbw-filter-date-range{display:flex;align-items:flex-end;gap:var(--tbw-spacing-sm, .375rem);margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-filter-range-group,.tbw-filter-date-group{display:flex;flex-direction:column;gap:var(--tbw-spacing-xs, .25rem);flex:1}.tbw-filter-range-label{font-size:var(--tbw-font-size-xs, .75rem);color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)))}.tbw-filter-range-input,.tbw-filter-date-input{width:100%;height:var(--tbw-filter-item-height, 28px);padding:var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-sm, .375rem);background:var(--tbw-filter-input-bg, var(--tbw-color-bg, transparent));color:inherit;border:1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-filter-input-radius, var(--tbw-border-radius, .25rem));font-size:inherit;box-sizing:border-box}.tbw-filter-range-input:focus,.tbw-filter-date-input:focus{outline:none;border-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));box-shadow:0 0 0 2px rgba(from var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6)) r g b / 15%)}.tbw-filter-range-separator{color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));padding-bottom:var(--tbw-spacing-xs, .25rem)}.tbw-filter-range-slider{position:relative;height:24px;margin:var(--tbw-spacing-md, .5rem) 0 var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-filter-range-track{position:absolute;top:50%;left:0;right:0;height:4px;background:var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:2px;transform:translateY(-50%)}.tbw-filter-range-fill{position:absolute;top:50%;height:4px;background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border-radius:2px;transform:translateY(-50%)}.tbw-filter-range-thumb{position:absolute;top:0;width:100%;height:100%;background:none;pointer-events:none;-webkit-appearance:none;appearance:none}.tbw-filter-range-thumb::-webkit-slider-thumb{-webkit-appearance:none;appearance:none;width:16px;height:16px;background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border:2px solid var(--tbw-filter-panel-bg, var(--tbw-color-panel-bg, light-dark(#eeeeee, #222222)));border-radius:50%;cursor:pointer;pointer-events:all;box-shadow:0 1px 3px #0003}.tbw-filter-range-thumb::-moz-range-thumb{width:16px;height:16px;background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border:2px solid var(--tbw-filter-panel-bg, var(--tbw-color-panel-bg, light-dark(#eeeeee, #222222)));border-radius:50%;cursor:pointer;pointer-events:all;box-shadow:0 1px 3px #0003}.tbw-filter-range-thumb::-webkit-slider-thumb:hover{transform:scale(1.1)}.tbw-filter-range-thumb::-moz-range-thumb:hover{transform:scale(1.1)}}";class W extends D{static manifest={events:[{type:"filter-applied",description:"Emitted when filter criteria change. Subscribers can react to row visibility changes."}]};name="filtering";styles=po;get defaultConfig(){return{debounceMs:300,caseSensitive:!1,trimInput:!0,useWorker:!0}}isFilteringEnabled(){return this.grid.effectiveConfig?.filterable!==!1}isColumnFilterable(e){return this.isFilteringEnabled()?e.filterable!==!1:!1}filters=new Map;cachedResult=null;cacheKey=null;openPanelField=null;panelElement=null;panelAnchorElement=null;searchText=new Map;excludedValues=new Map;panelAbortController=null;globalStylesInjected=!1;static DEFAULT_LIST_ITEM_HEIGHT=28;static LIST_OVERSCAN=3;static LIST_BYPASS_THRESHOLD=50;getListItemHeight(){if(this.panelElement){const e=getComputedStyle(this.panelElement).getPropertyValue("--tbw-filter-item-height");if(e&&e.trim()){const t=parseFloat(e);if(!isNaN(t)&&t>0)return t}}return W.DEFAULT_LIST_ITEM_HEIGHT}syncExcludedValues(e,t){t?t.type==="set"&&t.operator==="notIn"&&Array.isArray(t.value)?this.excludedValues.set(e,new Set(t.value)):t.type==="set"&&this.excludedValues.delete(e):this.excludedValues.delete(e)}attach(e){super.attach(e),this.injectGlobalStyles()}detach(){this.filters.clear(),this.cachedResult=null,this.cacheKey=null,this.openPanelField=null,this.panelElement&&(this.panelElement.remove(),this.panelElement=null),this.searchText.clear(),this.excludedValues.clear(),this.panelAbortController?.abort(),this.panelAbortController=null}processRows(e){const t=[...this.filters.values()];if(!t.length)return[...e];if(this.config.filterHandler)return this.cachedResult?this.cachedResult:[...e];const i=go(t);if(this.cacheKey===i&&this.cachedResult)return this.cachedResult;const n=fo([...e],t,this.config.caseSensitive);return this.cachedResult=n,this.cacheKey=i,n}afterRender(){const e=this.gridElement;if(!e)return;e.querySelectorAll('[part~="header-cell"]').forEach(i=>{const n=i.getAttribute("data-col");if(n===null)return;const o=this.visibleColumns[parseInt(n,10)];if(!o||!this.isColumnFilterable(o)||ne(o))return;const s=o.field;if(!s)return;const l=this.filters.has(s);let a=i.querySelector(".tbw-filter-btn");if(a){const u=a.classList.contains("active");if(a.classList.toggle("active",l),i.classList.toggle("filtered",l),u!==l){const h=l?"filterActive":"filter";this.setIcon(a,this.resolveIcon(h))}return}a=document.createElement("button"),a.className="tbw-filter-btn",a.setAttribute("aria-label",`Filter ${o.header??s}`);const c=l?"filterActive":"filter";this.setIcon(a,this.resolveIcon(c)),l&&(a.classList.add("active"),i.classList.add("filtered")),a.addEventListener("click",u=>{u.stopPropagation(),this.toggleFilterPanel(s,o,a)});const d=i.querySelector(".resize-handle");d?i.insertBefore(a,d):i.appendChild(a)})}setFilter(e,t){if(t===null)this.filters.delete(e),this.syncExcludedValues(e,null);else{const i={...t,field:e};this.filters.set(e,i),this.syncExcludedValues(e,i)}this.cachedResult=null,this.cacheKey=null,this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0}),this.emitPluginEvent("filter-applied",{filters:[...this.filters.values()]}),this.requestRender()}getFilter(e){return this.filters.get(e)}getFilters(){return[...this.filters.values()]}getFilterModel(){return this.getFilters()}setFilterModel(e){this.filters.clear(),this.excludedValues.clear();for(const t of e)this.filters.set(t.field,t),this.syncExcludedValues(t.field,t);this.cachedResult=null,this.cacheKey=null,this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0}),this.emitPluginEvent("filter-applied",{filters:[...this.filters.values()]}),this.requestRender()}clearAllFilters(){this.filters.clear(),this.excludedValues.clear(),this.searchText.clear(),this.applyFiltersInternal()}clearFieldFilter(e){this.filters.delete(e),this.excludedValues.delete(e),this.searchText.delete(e),this.applyFiltersInternal()}isFieldFiltered(e){return this.filters.has(e)}getFilteredRowCount(){return this.cachedResult?.length??this.rows.length}getActiveFilters(){return this.getFilters()}getUniqueValues(e){return hi(this.sourceRows,e)}copyGridThemeContext(e){const t=this.gridElement;if(!t)return;for(const n of t.classList)n.startsWith("tbw-")||n==="selecting"||e.classList.add(n);const i=t.dataset.theme;i&&(e.dataset.theme=i)}injectGlobalStyles(){if(this.globalStylesInjected)return;if(document.getElementById("tbw-filter-panel-styles")){this.globalStylesInjected=!0;return}const e=document.createElement("style");e.id="tbw-filter-panel-styles",e.textContent=wo,document.head.appendChild(e),this.globalStylesInjected=!0}toggleFilterPanel(e,t,i){if(this.openPanelField===e){this.closeFilterPanel();return}this.closeFilterPanel();const n=document.createElement("div");if(n.className="tbw-filter-panel",this.copyGridThemeContext(n),this.isAnimationEnabled&&n.classList.add("tbw-filter-panel-animated"),this.panelElement=n,this.openPanelField=e,this.config.valuesHandler){n.innerHTML='<div class="tbw-filter-loading">Loading...</div>',document.body.appendChild(n),this.positionPanel(n,i),this.setupPanelCloseHandler(n,i),this.config.valuesHandler(e,t).then(s=>{this.openPanelField!==e||!this.panelElement||(n.innerHTML="",this.renderPanelContent(e,t,n,s))});return}const o=hi(this.sourceRows,e);document.body.appendChild(n),this.positionPanel(n,i),this.renderPanelContent(e,t,n,o),this.setupPanelCloseHandler(n,i)}renderPanelContent(e,t,i,n){let o=this.excludedValues.get(e);o||(o=new Set,this.excludedValues.set(e,o));const s=this.searchText.get(e)??"",l={field:e,column:t,uniqueValues:n,excludedValues:o,searchText:s,applySetFilter:c=>{this.applySetFilter(e,c),this.closeFilterPanel()},applyTextFilter:(c,d,u)=>{this.applyTextFilter(e,c,d,u),this.closeFilterPanel()},clearFilter:()=>{this.clearFieldFilter(e),this.closeFilterPanel()},closePanel:()=>this.closeFilterPanel()};let a=!1;if(this.config.filterPanelRenderer&&(this.config.filterPanelRenderer(i,l),a=i.children.length>0),!a&&t.type){const c=this.grid.effectiveConfig.typeDefaults?.[t.type];c?.filterPanelRenderer&&(c.filterPanelRenderer(i,l),a=i.children.length>0)}if(!a){const c=t.type;c==="number"?this.renderNumberFilterPanel(i,l,n):c==="date"?this.renderDateFilterPanel(i,l,n):this.renderDefaultFilterPanel(i,l,n,o)}}setupPanelCloseHandler(e,t){this.panelAbortController=new AbortController,setTimeout(()=>{document.addEventListener("click",i=>{!e.contains(i.target)&&i.target!==t&&this.closeFilterPanel()},{signal:this.panelAbortController?.signal})},0)}closeFilterPanel(){const e=this.panelElement;e&&(e.remove(),this.panelElement=null),this.panelAnchorElement&&(this.panelAnchorElement.style.anchorName="",this.panelAnchorElement=null),this.openPanelField=null,this.panelAbortController?.abort(),this.panelAbortController=null}static supportsAnchorPositioning=null;static checkAnchorPositioningSupport(){return W.supportsAnchorPositioning===null&&(W.supportsAnchorPositioning=CSS.supports("anchor-name","--test")),W.supportsAnchorPositioning}positionPanel(e,t){const n=t.closest(".cell")??t;if(n.style.anchorName="--tbw-filter-anchor",this.panelAnchorElement=n,W.checkAnchorPositioningSupport()){requestAnimationFrame(()=>{const s=e.getBoundingClientRect(),l=n.getBoundingClientRect();s.top<l.top&&e.classList.add("tbw-filter-panel-above")});return}const o=n.getBoundingClientRect();e.style.position="fixed",e.style.top=`${o.bottom+4}px`,e.style.left=`${o.left}px`,requestAnimationFrame(()=>{const s=e.getBoundingClientRect();s.right>window.innerWidth-8&&(e.style.left=`${o.right-s.width}px`),s.bottom>window.innerHeight-8&&(e.style.top=`${o.top-s.height-4}px`,e.classList.add("tbw-filter-panel-above"))})}renderDefaultFilterPanel(e,t,i,n){const{field:o}=t,s=this.getListItemHeight(),l=document.createElement("div");l.className="tbw-filter-search";const a=document.createElement("input");a.type="text",a.placeholder="Search...",a.className="tbw-filter-search-input",a.value=this.searchText.get(o)??"",l.appendChild(a),e.appendChild(l);const c=document.createElement("div");c.className="tbw-filter-actions";const d=document.createElement("label");d.className="tbw-filter-value-item",d.style.padding="0",d.style.margin="0";const u=document.createElement("input");u.type="checkbox",u.className="tbw-filter-checkbox";const h=document.createElement("span");h.textContent="Select All",d.appendChild(u),d.appendChild(h),c.appendChild(d);const f=()=>{const _=[...y.values()],S=_.every(x=>x),L=_.every(x=>!x);u.checked=S,u.indeterminate=!S&&!L};u.addEventListener("change",()=>{const _=u.checked;for(const S of y.keys())y.set(S,_);f(),P()}),e.appendChild(c);const p=document.createElement("div");p.className="tbw-filter-values";const g=document.createElement("div");g.className="tbw-filter-values-spacer",p.appendChild(g);const w=document.createElement("div");w.className="tbw-filter-values-content",p.appendChild(w);const y=new Map;i.forEach(_=>{const S=_==null?"__null__":String(_);y.set(S,!n.has(_))}),f();let v=[];const T=(_,S)=>{const L=_==null?"(Blank)":String(_),x=_==null?"__null__":String(_),k=document.createElement("label");k.className="tbw-filter-value-item",k.style.position="absolute",k.style.top=`calc(var(--tbw-filter-item-height, 28px) * ${S})`,k.style.left="0",k.style.right="0",k.style.boxSizing="border-box";const N=document.createElement("input");N.type="checkbox",N.className="tbw-filter-checkbox",N.checked=y.get(x)??!0,N.dataset.value=x,N.addEventListener("change",()=>{y.set(x,N.checked),f()});const Q=document.createElement("span");return Q.textContent=L,k.appendChild(N),k.appendChild(Q),k},P=()=>{const _=v.length,S=p.clientHeight,L=p.scrollTop;if(g.style.height=`${_*s}px`,Ar(_,W.LIST_BYPASS_THRESHOLD/3)){w.innerHTML="",w.style.transform="translateY(0px)",v.forEach((k,N)=>{w.appendChild(T(k,N))});return}const x=_r({totalRows:_,viewportHeight:S,scrollTop:L,rowHeight:s,overscan:W.LIST_OVERSCAN});w.style.transform=`translateY(${x.offsetY}px)`,w.innerHTML="";for(let k=x.start;k<x.end;k++)w.appendChild(T(v[k],k-x.start))},E=_=>{const S=this.config.caseSensitive??!1,L=S?_:_.toLowerCase();if(v=i.filter(x=>{const k=x==null?"(Blank)":String(x),N=S?k:k.toLowerCase();return!_||N.includes(L)}),v.length===0){g.style.height="0px",w.innerHTML="";const x=document.createElement("div");x.className="tbw-filter-no-match",x.textContent="No matching values",w.appendChild(x);return}P()};p.addEventListener("scroll",()=>{v.length>0&&P()},{passive:!0}),E(a.value),e.appendChild(p);let b;a.addEventListener("input",()=>{clearTimeout(b),b=setTimeout(()=>{this.searchText.set(o,a.value),E(a.value)},this.config.debounceMs??150)});const C=document.createElement("div");C.className="tbw-filter-buttons";const A=document.createElement("button");A.className="tbw-filter-apply-btn",A.textContent="Apply",A.addEventListener("click",()=>{const _=[];for(const[S,L]of y)if(!L)if(S==="__null__")_.push(null);else{const x=i.find(k=>String(k)===S);_.push(x!==void 0?x:S)}t.applySetFilter(_)}),C.appendChild(A);const m=document.createElement("button");m.className="tbw-filter-clear-btn",m.textContent="Clear Filter",m.addEventListener("click",()=>{t.clearFilter()}),C.appendChild(m),e.appendChild(C)}renderNumberFilterPanel(e,t,i){const{field:n,column:o}=t,s=o.filterParams,l=o.editorParams,a=(H,oe)=>{if(typeof H=="number")return H;if(typeof H=="string"){const we=parseFloat(H);return isNaN(we)?oe:we}return oe},c=i.filter(H=>typeof H=="number"&&!isNaN(H)),d=c.length>0?Math.min(...c):0,u=c.length>0?Math.max(...c):100,h=a(s?.min??l?.min,d),f=a(s?.max??l?.max,u),p=s?.step??l?.step??1,g=this.filters.get(n);let w=h,y=f;g?.operator==="between"?(w=a(g.value,h),y=a(g.valueTo,f)):g?.operator==="greaterThanOrEqual"?w=a(g.value,h):g?.operator==="lessThanOrEqual"&&(y=a(g.value,f));const v=document.createElement("div");v.className="tbw-filter-range-inputs";const T=document.createElement("div");T.className="tbw-filter-range-group";const P=document.createElement("label");P.textContent="Min",P.className="tbw-filter-range-label";const E=document.createElement("input");E.type="number",E.className="tbw-filter-range-input",E.min=String(h),E.max=String(f),E.step=String(p),E.value=String(w),T.appendChild(P),T.appendChild(E),v.appendChild(T);const b=document.createElement("span");b.className="tbw-filter-range-separator",b.textContent="–",v.appendChild(b);const C=document.createElement("div");C.className="tbw-filter-range-group";const A=document.createElement("label");A.textContent="Max",A.className="tbw-filter-range-label";const m=document.createElement("input");m.type="number",m.className="tbw-filter-range-input",m.min=String(h),m.max=String(f),m.step=String(p),m.value=String(y),C.appendChild(A),C.appendChild(m),v.appendChild(C),e.appendChild(v);const _=document.createElement("div");_.className="tbw-filter-range-slider";const S=document.createElement("div");S.className="tbw-filter-range-track";const L=document.createElement("div");L.className="tbw-filter-range-fill";const x=document.createElement("input");x.type="range",x.className="tbw-filter-range-thumb tbw-filter-range-thumb-min",x.min=String(h),x.max=String(f),x.step=String(p),x.value=String(w);const k=document.createElement("input");k.type="range",k.className="tbw-filter-range-thumb tbw-filter-range-thumb-max",k.min=String(h),k.max=String(f),k.step=String(p),k.value=String(y),_.appendChild(S),_.appendChild(L),_.appendChild(x),_.appendChild(k),e.appendChild(_);const N=()=>{const H=parseFloat(x.value),oe=parseFloat(k.value),we=f-h,Vi=(H-h)/we*100,Qs=(oe-h)/we*100;L.style.left=`${Vi}%`,L.style.width=`${Qs-Vi}%`};x.addEventListener("input",()=>{const H=Math.min(parseFloat(x.value),parseFloat(k.value));x.value=String(H),E.value=String(H),N()}),k.addEventListener("input",()=>{const H=Math.max(parseFloat(k.value),parseFloat(x.value));k.value=String(H),m.value=String(H),N()}),E.addEventListener("input",()=>{let H=parseFloat(E.value)||h;H=Math.max(h,Math.min(H,parseFloat(m.value))),x.value=String(H),N()}),m.addEventListener("input",()=>{let H=parseFloat(m.value)||f;H=Math.min(f,Math.max(H,parseFloat(E.value))),k.value=String(H),N()}),N();const Q=document.createElement("div");Q.className="tbw-filter-buttons";const Me=document.createElement("button");Me.className="tbw-filter-apply-btn",Me.textContent="Apply",Me.addEventListener("click",()=>{const H=parseFloat(E.value),oe=parseFloat(m.value);t.applyTextFilter("between",H,oe)}),Q.appendChild(Me);const Ie=document.createElement("button");Ie.className="tbw-filter-clear-btn",Ie.textContent="Clear Filter",Ie.addEventListener("click",()=>{t.clearFilter()}),Q.appendChild(Ie),e.appendChild(Q)}renderDateFilterPanel(e,t,i){const{field:n,column:o}=t,s=o.filterParams,l=o.editorParams,a=i.filter(x=>x instanceof Date||typeof x=="string"&&!isNaN(Date.parse(x))).map(x=>x instanceof Date?x:new Date(x)).filter(x=>!isNaN(x.getTime())),c=a.length>0?new Date(Math.min(...a.map(x=>x.getTime()))):null,d=a.length>0?new Date(Math.max(...a.map(x=>x.getTime()))):null,u=x=>x?x.toISOString().split("T")[0]:"",h=x=>x?typeof x=="string"?x:typeof x=="number"?u(new Date(x)):"":"",f=h(s?.min)||h(l?.min)||u(c),p=h(s?.max)||h(l?.max)||u(d),g=this.filters.get(n);let w="",y="";g?.operator==="between"?(w=h(g.value)||"",y=h(g.valueTo)||""):g?.operator==="greaterThanOrEqual"?w=h(g.value)||"":g?.operator==="lessThanOrEqual"&&(y=h(g.value)||"");const v=document.createElement("div");v.className="tbw-filter-date-range";const T=document.createElement("div");T.className="tbw-filter-date-group";const P=document.createElement("label");P.textContent="From",P.className="tbw-filter-range-label";const E=document.createElement("input");E.type="date",E.className="tbw-filter-date-input",f&&(E.min=f),p&&(E.max=p),E.value=w,T.appendChild(P),T.appendChild(E),v.appendChild(T);const b=document.createElement("span");b.className="tbw-filter-range-separator",b.textContent="–",v.appendChild(b);const C=document.createElement("div");C.className="tbw-filter-date-group";const A=document.createElement("label");A.textContent="To",A.className="tbw-filter-range-label";const m=document.createElement("input");m.type="date",m.className="tbw-filter-date-input",f&&(m.min=f),p&&(m.max=p),m.value=y,C.appendChild(A),C.appendChild(m),v.appendChild(C),e.appendChild(v);const _=document.createElement("div");_.className="tbw-filter-buttons";const S=document.createElement("button");S.className="tbw-filter-apply-btn",S.textContent="Apply",S.addEventListener("click",()=>{const x=E.value,k=m.value;x&&k?t.applyTextFilter("between",x,k):x?t.applyTextFilter("greaterThanOrEqual",x):k?t.applyTextFilter("lessThanOrEqual",k):t.clearFilter()}),_.appendChild(S);const L=document.createElement("button");L.className="tbw-filter-clear-btn",L.textContent="Clear Filter",L.addEventListener("click",()=>{t.clearFilter()}),_.appendChild(L),e.appendChild(_)}applySetFilter(e,t){this.excludedValues.set(e,new Set(t)),t.length===0?this.filters.delete(e):this.filters.set(e,{field:e,type:"set",operator:"notIn",value:t}),this.applyFiltersInternal()}applyTextFilter(e,t,i,n){this.filters.set(e,{field:e,type:"text",operator:t,value:i,valueTo:n}),this.applyFiltersInternal()}applyFiltersInternal(){this.cachedResult=null,this.cacheKey=null;const e=[...this.filters.values()];if(this.config.filterHandler){const t=this.grid;t.setAttribute("aria-busy","true");const i=this.config.filterHandler(e,this.sourceRows),n=o=>{t.removeAttribute("aria-busy"),this.cachedResult=o,this.grid.rows=o,this.emit("filter-change",{filters:e,filteredRowCount:o.length}),this.emitPluginEvent("filter-applied",{filters:e}),this.requestRender()};i&&typeof i.then=="function"?i.then(n):n(i);return}this.emit("filter-change",{filters:e,filteredRowCount:0}),this.emitPluginEvent("filter-applied",{filters:e}),this.requestRender()}getColumnState(e){const t=this.filters.get(e);if(t)return{filter:{type:t.type,operator:t.operator,value:t.value,valueTo:t.valueTo}}}applyColumnState(e,t){if(!t.filter){this.filters.delete(e);return}const i={field:e,type:t.filter.type,operator:t.filter.operator,value:t.filter.value,valueTo:t.filter.valueTo};this.filters.set(e,i),this.cachedResult=null,this.cacheKey=null}}function fi(r){if(!r.length)return[];const e=new Map,t=[],i=(s,l)=>{if(!l.length)return;const a=t[t.length-1];if(a&&a.implicit&&a.firstIndex+a.columns.length===s){a.columns.push(...l);return}t.push({id:"__implicit__"+s,label:void 0,columns:l,firstIndex:s,implicit:!0})};let n=[],o=0;return r.forEach((s,l)=>{const a=s.group;if(!a){n.length===0&&(o=l),n.push(s);return}n.length&&(i(o,n.slice()),n=[]);const c=typeof a=="string"?a:a.id;let d=e.get(c);d||(d={id:c,label:typeof a=="string"?void 0:a.label,columns:[],firstIndex:l},e.set(c,d),t.push(d)),d.columns.push(s)}),n.length&&i(o,n),t.length===1&&t[0].implicit&&t[0].columns.length===r.length?[]:t}function bo(r,e,t){if(!e.length||!r)return;const i=new Map;for(const o of e)for(const s of o.columns)s.field&&i.set(s.field,o.id);const n=Array.from(r.querySelectorAll(".cell[data-field]"));n.forEach(o=>{const s=o.getAttribute("data-field")||"",l=i.get(s);l&&(o.classList.add("grouped"),o.getAttribute("data-group")||o.setAttribute("data-group",l))});for(const o of e){const s=o.columns[o.columns.length-1],l=n.find(a=>a.getAttribute("data-field")===s.field);l&&l.classList.add("group-end")}}function mo(r,e){if(r.length===0)return null;const t=document.createElement("div");t.className="header-group-row",t.setAttribute("role","row");for(const i of r){const n=i.columns[0],o=n?e.findIndex(c=>c.field===n.field):-1;if(o===-1)continue;const s=String(i.id).startsWith("__implicit__"),l=s?"":i.label||i.id,a=document.createElement("div");a.className="cell header-group-cell",s&&a.classList.add("implicit-group"),a.setAttribute("data-group",String(i.id)),a.style.gridColumn=`${o+1} / span ${i.columns.length}`,a.textContent=l,t.appendChild(a)}return t}function vo(r){return r.some(e=>e.group!=null)}const yo="@layer tbw-plugins{.header-group-row{display:grid;grid-auto-flow:column;background:var(--tbw-grouping-columns-header-bg, var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-grouping-columns-border, var(--tbw-color-border))}.header-group-cell{display:flex;align-items:center;justify-content:center;padding:var(--tbw-button-padding-sm, .25rem .5rem);font-weight:600;font-size:var(--tbw-font-size-sm, .9em);text-transform:uppercase;letter-spacing:.5px;border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-group-cell:last-child{border-right:none}.header-row .cell.grouped{border-top:none}.header-row .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-row .cell.group-end:last-child{border-right:none}.rows .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.rows .cell.group-end:last-child{border-right:none}.header-group-row.no-borders{border-bottom:none}.header-group-row.no-borders .header-group-cell{border-right:none}.header-row.no-group-borders .cell.group-end{border-right:1px solid var(--tbw-color-border)}}";class Co extends D{static manifest={ownedProperties:[{property:"group",level:"column",description:'the "group" column property'},{property:"columnGroups",level:"config",description:'the "columnGroups" config property',isUsed:e=>Array.isArray(e)&&e.length>0}]};name="groupingColumns";styles=yo;get defaultConfig(){return{showGroupBorders:!0}}groups=[];isActive=!1;#t=new Set;detach(){this.groups=[],this.isActive=!1,this.#t.clear()}static detect(e,t){if(t?.columnGroups&&Array.isArray(t.columnGroups)&&t.columnGroups.length>0)return!0;const i=t?.columns;return Array.isArray(i)?vo(i):!1}processColumns(e){const t=this.grid?.gridConfig?.columnGroups;let i;if(t&&Array.isArray(t)&&t.length>0){const o=new Map;for(const s of t)for(const l of s.children)o.set(l,{id:s.id,label:s.header});i=e.map(s=>{const l=o.get(s.field);return l&&!s.group?{...s,group:l}:s})}else i=[...e];const n=fi(i);if(n.length===0)return this.isActive=!1,this.groups=[],i;this.isActive=!0,this.groups=n,this.#t.clear();for(const o of n){const s=o.columns[o.columns.length-1];s?.field&&this.#t.add(s.field)}return i}afterRender(){if(!this.isActive){const a=this.gridElement?.querySelector(".header")?.querySelector(".header-group-row");a&&a.remove();return}const e=this.gridElement?.querySelector(".header");if(!e)return;const t=e.querySelector(".header-group-row");t&&t.remove();const i=this.columns,n=fi(i);if(n.length===0)return;const o=mo(n,i);if(o){o.classList.toggle("no-borders",!this.config.showGroupBorders);const l=e.querySelector(".header-row");l?e.insertBefore(o,l):e.appendChild(o)}const s=e.querySelector(".header-row");s&&(s.classList.toggle("no-group-borders",!this.config.showGroupBorders),bo(s,n))}afterCellRender(e){!this.isActive||!this.config.showGroupBorders||e.cellElement.classList.toggle("group-end",this.#t.has(e.column.field))}isGroupingActive(){return this.isActive}getGroups(){return this.groups}getGroupColumns(e){const t=this.groups.find(i=>i.id===e);return t?t.columns:[]}refresh(){this.requestRender()}}const st={sum:(r,e)=>r.reduce((t,i)=>t+(Number(i[e])||0),0),avg:(r,e)=>{const t=r.reduce((i,n)=>i+(Number(n[e])||0),0);return r.length?t/r.length:0},count:r=>r.length,min:(r,e)=>r.length?Math.min(...r.map(t=>Number(t[e])||1/0)):0,max:(r,e)=>r.length?Math.max(...r.map(t=>Number(t[e])||-1/0)):0,first:(r,e)=>r[0]?.[e],last:(r,e)=>r[r.length-1]?.[e]},ge=new Map,K={register(r,e){ge.set(r,e)},unregister(r){ge.delete(r)},get(r){if(r!==void 0)return typeof r=="function"?r:ge.get(r)??st[r]},run(r,e,t,i){const n=this.get(r);return n?n(e,t,i):void 0},has(r){return ge.has(r)||r in st},list(){return[...Object.keys(st),...ge.keys()]}},gi={sum:r=>r.reduce((e,t)=>e+t,0),avg:r=>r.length?r.reduce((e,t)=>e+t,0)/r.length:0,count:r=>r.length,min:r=>r.length?Math.min(...r):0,max:r=>r.length?Math.max(...r):0,first:r=>r[0]??0,last:r=>r[r.length-1]??0};function xo(r){return gi[r]??gi.sum}K.register.bind(K),K.unregister.bind(K);const pi=K.get.bind(K),lt=K.run.bind(K);K.list.bind(K);function wi({rows:r,config:e,expanded:t,initialExpanded:i}){const n=e.groupOn;if(typeof n!="function")return[];const o={key:"__root__",value:null,depth:-1,rows:[],children:new Map};if(r.forEach(c=>{let d=n(c);d==null||d===!1?d=["__ungrouped__"]:Array.isArray(d)||(d=[d]);let u=o;d.forEach((h,f)=>{const p=h==null?"∅":String(h),g=u.key==="__root__"?p:u.key+"||"+p;let w=u.children.get(p);w||(w={key:g,value:h,depth:f,rows:[],children:new Map,parent:u},u.children.set(p,w)),u=w}),u.rows.push(c)}),o.children.size===1&&o.children.has("__ungrouped__")&&o.children.get("__ungrouped__").rows.length===r.length)return[];const s=new Set([...t,...i??[]]),l=[],a=c=>{if(c===o){c.children.forEach(u=>a(u));return}const d=s.has(c.key);l.push({kind:"group",key:c.key,value:c.value,depth:c.depth,rows:c.rows,expanded:d}),d&&(c.children.size?c.children.forEach(u=>a(u)):c.rows.forEach(u=>l.push({kind:"data",row:u,rowIndex:r.indexOf(u)})))};return a(o),l}function Eo(r,e){const t=new Set(r);return t.has(e)?t.delete(e):t.add(e),t}function Ro(r){const e=new Set;for(const t of r)t.kind==="group"&&e.add(t.key);return e}function So(){return new Set}function _o(r,e){if(r===!0)return new Set(e);if(r===!1||r==null)return new Set;if(typeof r=="number"){const t=e[r];return t?new Set([t]):new Set}return typeof r=="string"?new Set([r]):Array.isArray(r)?new Set(r):new Set}function Ao(r){return r.filter(e=>e.kind==="group").map(e=>e.key)}function ko(r){return r.kind!=="group"?0:r.rows.length}const To="@layer tbw-plugins{.group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-grouping-rows-bg, var(--tbw-color-panel-bg));font-weight:500;border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height)}.group-row .cell{display:flex;align-items:center;padding:var(--tbw-cell-padding, .125rem .5rem)}.group-row:hover{background:var(--tbw-grouping-rows-bg-hover, var(--tbw-color-row-hover))}.group-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-toggle-size, 1.25rem);height:var(--tbw-toggle-size, 1.25rem);margin-right:.25rem;background:none;border:0;font:inherit}.group-toggle:hover{background:var(--tbw-grouping-rows-toggle-hover, var(--tbw-color-row-hover));border-radius:var(--tbw-border-radius, .125rem)}.group-label{display:inline-flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.group-count{color:var(--tbw-grouping-rows-count-color, var(--tbw-color-fg-muted));font-size:var(--tbw-font-size-xs, .85em);font-weight:400}.group-aggregates{display:inline-flex;align-items:center;gap:var(--tbw-spacing-lg, 1rem);margin-left:var(--tbw-spacing-lg, 1rem);font-weight:400;font-size:var(--tbw-font-size-sm, .875em);color:var(--tbw-grouping-rows-aggregate-color, var(--tbw-color-fg-muted))}.group-aggregate{white-space:nowrap}.group-row{padding-left:calc(var(--tbw-group-depth, 0) * var(--tbw-group-indent-width, 1.25em))}.data-grid-row.tbw-group-slide-in{animation:tbw-group-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-group-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.data-grid-row.tbw-group-fade-in{animation:tbw-group-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-group-fade-in{0%{opacity:0}to{opacity:1}}}";class Lo extends D{static manifest={events:[{type:"grouping-state-change",description:"Emitted when groups are expanded/collapsed. Subscribers can react to row visibility changes."}],queries:[{type:"canMoveRow",description:"Returns false for group header rows (cannot be reordered)"}],configRules:[{id:"groupingRows/accordion-defaultExpanded",severity:"warn",message:`"accordion: true" and "defaultExpanded" (non-false) are used together.
|
|
108
108
|
→ In accordion mode, only one group can be open at a time.
|
|
109
109
|
→ Using defaultExpanded with multiple groups will collapse to one on first toggle.
|
|
110
|
-
→ Consider using "defaultExpanded: false" or a single group key/index with accordion mode.`,check:e=>e.accordion===!0&&e.defaultExpanded!==!1&&e.defaultExpanded!==void 0&&typeof e.defaultExpanded!="number"&&typeof e.defaultExpanded!="string"&&(e.defaultExpanded===!0||Array.isArray(e.defaultExpanded)&&e.defaultExpanded.length>1)}]};name="groupingRows";styles=So;get defaultConfig(){return{defaultExpanded:!1,showRowCount:!0,indentWidth:20,aggregators:{},animation:"slide",accordion:!1}}expandedKeys=new Set;flattenedRows=[];isActive=!1;previousVisibleKeys=new Set;keysToAnimate=new Set;hasAppliedDefaultExpanded=!1;get animationStyle(){return this.isAnimationEnabled?this.config.animation??"slide":!1}detach(){this.expandedKeys.clear(),this.flattenedRows=[],this.isActive=!1,this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.hasAppliedDefaultExpanded=!1}getRowHeight(e,t){if(this.config.groupRowHeight!=null&&e.__isGroupRow===!0)return this.config.groupRowHeight}handleQuery(e){if(e.type==="canMoveRow"&&e.context?.__isGroupRow===!0)return!1}static detect(e,t){return typeof t?.groupOn=="function"||typeof t?.enableRowGrouping=="boolean"}processRows(e){const t=this.config;if(typeof t.groupOn!="function")return this.isActive=!1,this.flattenedRows=[],[...e];const i=pi({rows:[...e],config:t,expanded:new Set});if(i.length===0)return this.isActive=!1,this.flattenedRows=[],[...e];let n;if(!this.hasAppliedDefaultExpanded&&this.expandedKeys.size===0&&t.defaultExpanded!==!1){const l=Eo(i);n=xo(t.defaultExpanded??!1,l),n.size>0&&(this.expandedKeys=new Set(n),this.hasAppliedDefaultExpanded=!0)}const o=pi({rows:[...e],config:t,expanded:this.expandedKeys,initialExpanded:n});this.isActive=!0,this.flattenedRows=o,this.keysToAnimate.clear();const s=new Set;return o.forEach((l,a)=>{if(l.kind==="data"){const c=`data-${a}`;s.add(c),this.previousVisibleKeys.has(c)||this.keysToAnimate.add(c)}}),this.previousVisibleKeys=s,o.map(l=>l.kind==="group"?{__isGroupRow:!0,__groupKey:l.key,__groupValue:l.value,__groupDepth:l.depth,__groupRows:l.rows,__groupExpanded:l.expanded,__groupRowCount:Ro(l),__rowCacheKey:`group:${l.key}`}:l.row)}onCellClick(e){const t=e.row;if(t?.__isGroupRow&&e.originalEvent.target?.closest(".group-toggle"))return this.toggle(t.__groupKey),!0}onKeyDown(e){if(e.key!==" ")return;const t=this.grid._focusRow,i=this.rows[t];if(i?.__isGroupRow)return e.preventDefault(),this.toggle(i.__groupKey),this.requestRenderWithFocus(),!0}renderRow(e,t,i){if(!e?.__isGroupRow)return!1;const n=this.config;if(n.groupRowRenderer){const l=()=>{this.toggle(e.__groupKey)},a=n.groupRowRenderer({key:e.__groupKey,value:e.__groupValue,depth:e.__groupDepth,rows:e.__groupRows,expanded:e.__groupExpanded,toggleExpand:l});if(a)return t.className="data-grid-row group-row",t.__isCustomRow=!0,t.setAttribute("data-group-depth",String(e.__groupDepth)),typeof a=="string"?t.innerHTML=a:(t.innerHTML="",t.appendChild(a)),!0}const o=()=>{this.toggle(e.__groupKey)};return t.className="data-grid-row group-row",t.__isCustomRow=!0,t.setAttribute("data-group-depth",String(e.__groupDepth)),t.setAttribute("role","row"),t.setAttribute("aria-expanded",String(e.__groupExpanded)),t.style.setProperty("--tbw-group-depth",String(e.__groupDepth||0)),n.indentWidth!==void 0&&t.style.setProperty("--tbw-group-indent-width",`${n.indentWidth}px`),t.style.height="",t.innerHTML="",n.fullWidth!==!1?this.renderFullWidthGroupRow(e,t,o):this.renderPerColumnGroupRow(e,t,o),!0}afterRender(){const e=this.animationStyle;if(e===!1||this.keysToAnimate.size===0)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const i=e==="fade"?"tbw-group-fade-in":"tbw-group-slide-in";for(const n of t.querySelectorAll(".data-grid-row:not(.group-row)")){const o=n.querySelector(".cell[data-row]"),s=o?parseInt(o.getAttribute("data-row")??"-1",10):-1,a=this.flattenedRows[s]?.kind==="data"?`data-${s}`:void 0;a&&this.keysToAnimate.has(a)&&(n.classList.add(i),n.addEventListener("animationend",()=>n.classList.remove(i),{once:!0}))}this.keysToAnimate.clear()}createToggleButton(e,t){const i=document.createElement("button");return i.type="button",i.className=`group-toggle${e?" expanded":""}`,i.setAttribute("aria-label",e?"Collapse group":"Expand group"),this.setIcon(i,this.resolveIcon(e?"collapse":"expand")),i.addEventListener("click",n=>{n.stopPropagation(),t()}),i}getGroupLabelText(e,t,i){const n=this.config;return n.formatLabel?n.formatLabel(e,t,i):String(e)}renderFullWidthGroupRow(e,t,i){const n=this.config,o=n.aggregators??{},s=e.__groupRows??[],l=document.createElement("div");l.className="cell group-full",l.style.gridColumn="1 / -1",l.setAttribute("role","gridcell"),l.setAttribute("data-col","0"),l.appendChild(this.createToggleButton(e.__groupExpanded,i));const a=document.createElement("span");if(a.className="group-label",a.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey),l.appendChild(a),n.showRowCount!==!1){const d=document.createElement("span");d.className="group-count",d.textContent=`(${e.__groupRowCount??e.__groupRows?.length??0})`,l.appendChild(d)}const c=Object.entries(o);if(c.length>0){const d=document.createElement("span");d.className="group-aggregates";for(const[u,h]of c){const f=this.columns.find(g=>g.field===u),p=st(h,s,u,f);if(p!=null){const g=document.createElement("span");g.className="group-aggregate",g.setAttribute("data-field",u);const w=f?.header??u;g.textContent=`${w}: ${p}`,d.appendChild(g)}}d.children.length>0&&l.appendChild(d)}t.appendChild(l)}renderPerColumnGroupRow(e,t,i){const n=this.config,o=n.aggregators??{},s=this.columns,l=e.__groupRows??[],c=this.gridElement?.querySelector(".body")?.style.gridTemplateColumns||"";c&&(t.style.display="grid",t.style.gridTemplateColumns=c);let d=!1;s.forEach((u,h)=>{const f=document.createElement("div");if(f.className="cell group-cell",f.setAttribute("data-col",String(h)),f.setAttribute("role","gridcell"),Te(u)){f.setAttribute("data-field",u.field),t.appendChild(f);return}if(d){const p=o[u.field];if(p){const g=st(p,l,u.field,u);f.textContent=g!=null?String(g):""}else f.textContent=""}else{d=!0,f.appendChild(this.createToggleButton(e.__groupExpanded,i));const p=document.createElement("span"),g=o[u.field];if(g){const w=st(g,l,u.field,u);p.textContent=w!=null?String(w):String(e.__groupValue)}else p.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey);if(f.appendChild(p),n.showRowCount!==!1){const w=document.createElement("span");w.className="group-count",w.textContent=` (${l.length})`,f.appendChild(w)}}t.appendChild(f)})}expandAll(){this.expandedKeys=yo(this.flattenedRows),this.emitPluginEvent("grouping-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}collapseAll(){this.expandedKeys=Co(),this.emitPluginEvent("grouping-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}toggle(e){const t=!this.expandedKeys.has(e),i=this.config,n=this.flattenedRows.find(o=>o.kind==="group"&&o.key===e);if(i.accordion&&t&&n){const o=new Set;for(const s of this.expandedKeys)if(e.startsWith(s+"||")||s.startsWith(e+"||"))e.startsWith(s+"||")&&o.add(s);else{const l=this.flattenedRows.find(a=>a.kind==="group"&&a.key===s);l&&l.depth!==n.depth&&o.add(s)}o.add(e),this.expandedKeys=o}else this.expandedKeys=vo(this.expandedKeys,e);this.emit("group-toggle",{key:e,expanded:this.expandedKeys.has(e),value:n?.value,depth:n?.depth??0}),this.emitPluginEvent("grouping-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}expand(e){this.expandedKeys.has(e)||(this.expandedKeys=new Set([...this.expandedKeys,e]),this.requestRender())}collapse(e){if(this.expandedKeys.has(e)){const t=new Set(this.expandedKeys);t.delete(e),this.expandedKeys=t,this.requestRender()}}getGroupState(){const e=this.flattenedRows.filter(t=>t.kind==="group");return{isActive:this.isActive,expandedCount:this.expandedKeys.size,totalGroups:e.length,expandedKeys:[...this.expandedKeys]}}getRowCount(){return this.flattenedRows.length}refreshGroups(){this.requestRender()}getExpandedGroups(){return[...this.expandedKeys]}getFlattenedRows(){return this.flattenedRows}isGroupingActive(){return this.isActive}setGroupOn(e){this.config.groupOn=e,this.requestRender()}}function wi(r,e){const t=new Set(r);return t.has(e)?t.delete(e):t.add(e),t}function Ao(r,e){const t=new Set(r);return t.add(e),t}function ko(r,e){const t=new Set(r);return t.delete(e),t}function To(r,e){return r.has(e)}function Lo(r,e,t,i){const n=document.createElement("div");n.className="master-detail-row",n.setAttribute("data-detail-for",String(e)),n.setAttribute("role","row");const o=document.createElement("div");o.className="master-detail-cell",o.setAttribute("role","cell"),o.style.gridColumn=`1 / ${i+1}`;const s=t(r,e);return typeof s=="string"?o.innerHTML=s:s instanceof HTMLElement&&o.appendChild(s),n.appendChild(o),n}const Po="@layer tbw-plugins{tbw-grid .cell[data-field=__tbw_expander]{border-right:none!important;padding:0;display:flex;align-items:center;justify-content:center}tbw-grid .header-row .cell[data-field=__tbw_expander]{display:none}tbw-grid .header-row .cell[data-field=__tbw_expander]+.cell{grid-column:1 / 3}tbw-grid .master-detail-expander{display:flex;align-items:center;justify-content:center;width:100%;height:100%}tbw-grid .master-detail-toggle{cursor:pointer;opacity:.7;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center}tbw-grid .master-detail-toggle:hover{opacity:1}tbw-grid .master-detail-row{grid-column:1 / -1;display:grid;background:var(--tbw-master-detail-bg, var(--tbw-color-row-alt));border-bottom:1px solid var(--tbw-master-detail-border, var(--tbw-color-border));overflow:hidden}tbw-grid .master-detail-cell{padding:var(--tbw-detail-padding, var(--tbw-spacing-xl, 1rem));overflow:auto}tbw-grid .master-detail-row.tbw-expanding{animation:tbw-detail-expand var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}tbw-grid .master-detail-row.tbw-collapsing{animation:tbw-detail-collapse var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-detail-expand{0%{opacity:0;max-height:0;padding-top:0;padding-bottom:0}to{opacity:1;max-height:var(--tbw-detail-max-height, 31.25rem);padding-top:var(--tbw-detail-padding, var(--tbw-spacing-xl, 1rem));padding-bottom:var(--tbw-detail-padding, var(--tbw-spacing-xl, 1rem))}}@keyframes tbw-detail-collapse{0%{opacity:1;max-height:var(--tbw-detail-max-height, 31.25rem)}to{opacity:0;max-height:0}}}";class lt extends D{name="masterDetail";styles=Po;get defaultConfig(){return{detailHeight:"auto",expandOnRowClick:!1,collapseOnClickOutside:!1,animation:"slide"}}attach(e){super.attach(e),this.parseLightDomDetail()}parseLightDomDetail(){const e=this.grid;if(!e||typeof e.querySelector!="function")return;const t=e.querySelector("tbw-grid-detail");if(!t)return;const i=e;if(i.__frameworkAdapter?.parseDetailElement){const u=i.__frameworkAdapter.parseDetailElement(t);if(u){this.config={...this.config,detailRenderer:u};return}}const n=t.getAttribute("animation"),o=t.getAttribute("show-expand-column"),s=t.getAttribute("expand-on-row-click"),l=t.getAttribute("collapse-on-click-outside"),a=t.getAttribute("height"),c={};n!==null&&(c.animation=n==="false"?!1:n),o!==null&&(c.showExpandColumn=o!=="false"),s!==null&&(c.expandOnRowClick=s==="true"),l!==null&&(c.collapseOnClickOutside=l==="true"),a!==null&&(c.detailHeight=a==="auto"?"auto":parseInt(a,10));const d=t.innerHTML.trim();d&&!this.config.detailRenderer&&(c.detailRenderer=(u,h)=>{const f=me(d,{value:u,row:u});return V(f)}),Object.keys(c).length>0&&(this.config={...this.config,...c})}get animationStyle(){return this.isAnimationEnabled?this.config.animation??"slide":!1}animateExpand(e,t,i){if(!this.isAnimationEnabled||this.animationStyle===!1)return!1;e.classList.add("tbw-expanding");let n=!1;const o=()=>{n||(n=!0,e.classList.remove("tbw-expanding"),t!==void 0&&i!==void 0&&this.#t(e,t,i))};return e.addEventListener("animationend",o,{once:!0}),setTimeout(o,this.animationDuration+50),!0}animateCollapse(e,t){if(!this.isAnimationEnabled||this.animationStyle===!1){t();return}e.classList.add("tbw-collapsing");const i=()=>{e.classList.remove("tbw-collapsing"),t()};e.addEventListener("animationend",i,{once:!0}),setTimeout(i,this.animationDuration+50)}#t(e,t,i){if(!e.isConnected)return;const n=e.offsetHeight;if(n>0){const o=this.measuredDetailHeights.get(t);this.measuredDetailHeights.set(t,n),o!==n&&this.grid.invalidateRowHeight(i)}}expandedRows=new Set;detailElements=new Map;measuredDetailHeights=new Map;rowsToAnimate=new Set;static DEFAULT_DETAIL_HEIGHT=150;getDetailHeight(e){const t=this.detailElements.get(e);if(t&&!(t.classList.contains("tbw-expanding")||t.classList.contains("tbw-collapsing"))){const o=t.offsetHeight;if(o>0)return this.measuredDetailHeights.set(e,o),o}const i=this.measuredDetailHeights.get(e);return i&&i>0?i:typeof this.config?.detailHeight=="number"?this.config.detailHeight:lt.DEFAULT_DETAIL_HEIGHT}toggleAndEmit(e,t){this.expandedRows=wi(this.expandedRows,e);const i=this.expandedRows.has(e);i&&this.rowsToAnimate.add(e),this.emit("detail-expand",{rowIndex:t,row:e,expanded:i}),this.requestRender()}detach(){this.expandedRows.clear(),this.detailElements.clear(),this.measuredDetailHeights.clear(),this.rowsToAnimate.clear()}processColumns(e){if(!(this.config.showExpandColumn===!0||this.config.showExpandColumn!==!1&&!!this.config.detailRenderer))return[...e];const i=[...e];if(Mr(i))return i;const o=zr(this.name);return o.viewRenderer=s=>{const{row:l}=s,a=this.expandedRows.has(l),c=document.createElement("span");c.className="master-detail-expander expander-cell";const d=document.createElement("span");return d.className=`master-detail-toggle${a?" expanded":""}`,this.setIcon(d,this.resolveIcon(a?"collapse":"expand")),d.setAttribute("role","button"),d.setAttribute("tabindex","0"),d.setAttribute("aria-expanded",String(a)),d.setAttribute("aria-label",a?"Collapse details":"Expand details"),c.appendChild(d),c},[o,...i]}onRowClick(e){if(!(!this.config.expandOnRowClick||!this.config.detailRenderer))return this.toggleAndEmit(e.row,e.rowIndex),!1}onCellClick(e){if(e.originalEvent?.target?.classList.contains("master-detail-toggle"))return this.toggleAndEmit(e.row,e.rowIndex),!0;this.expandedRows.size>0&&queueMicrotask(()=>this.#e())}onKeyDown(e){if(e.key!==" ")return;const t=this.grid._focusCol,i=this.grid._focusRow,n=this.columns[t];if(!n||!Te(n))return;const o=this.rows[i];if(o)return e.preventDefault(),this.toggleAndEmit(o,i),this.requestRenderWithFocus(),!0}afterRender(){this.#e()}onScrollRender(){!this.config.detailRenderer||this.expandedRows.size===0||this.#e()}#e(){if(!this.config.detailRenderer)return;const e=this.gridElement?.querySelector(".rows");if(!e)return;const t=this.grid,i=t._rowPool,n=t._virtualization?.start??0,o=t._virtualization?.end??0,s=this.columns.length,l=n,a=o,c=new Map;if(i){const d=Math.min(i.length,a-l);for(let u=0;u<d;u++){const h=i[u];h.parentNode===e&&c.set(l+u,h)}}else{const d=e.querySelectorAll(".data-grid-row");for(const u of d){const h=u.querySelector(".cell[data-row]"),f=h?parseInt(h.getAttribute("data-row")??"-1",10):-1;f>=0&&c.set(f,u)}}for(const[d,u]of this.detailElements){const h=this.rows.indexOf(d),f=this.expandedRows.has(d),p=h>=0&&c.has(h);(!f||!p)&&(u.parentNode&&u.remove(),this.detailElements.delete(d))}for(const[d,u]of c){const h=this.rows[d];if(!h||!this.expandedRows.has(h))continue;const f=this.detailElements.get(h);if(f){f.previousElementSibling!==u&&u.after(f);continue}const p=Lo(h,d,this.config.detailRenderer,s);typeof this.config.detailHeight=="number"&&(p.style.height=`${this.config.detailHeight}px`),u.after(p),this.detailElements.set(h,p);const g=this.rowsToAnimate.has(h);g&&this.rowsToAnimate.delete(h),g&&this.animateExpand(p,h,d)||requestAnimationFrame(()=>{this.#t(p,h,d)})}}getExtraHeight(){let e=0;for(const t of this.expandedRows)e+=this.getDetailHeight(t);return e}getExtraHeightBefore(e){let t=0;for(const i of this.expandedRows){const n=this.rows.indexOf(i);n>=0&&n<e&&(t+=this.getDetailHeight(i))}return t}getRowHeight(e,t){if(!this.expandedRows.has(e))return;const n=this.grid.defaultRowHeight??28,o=this.getDetailHeight(e);return n+o}adjustVirtualStart(e,t,i){if(this.expandedRows.size===0)return e;const n=this.grid?._virtualization?.positionCache;let o=e;if(n&&n.length>0)for(const s of this.expandedRows){const l=this.rows.indexOf(s);if(l<0||l>=e)continue;n[l].offset+n[l].height>t&&l<o&&(o=l)}else{const s=[];for(const a of this.expandedRows){const c=this.rows.indexOf(a);c>=0&&s.push({index:c,row:a})}s.sort((a,c)=>a.index-c.index);let l=0;for(const{index:a,row:c}of s){const d=a*i+l,u=this.getDetailHeight(c),h=d+i+u;l+=u,!(a>=e)&&h>t&&a<o&&(o=a)}}return o}expand(e){const t=this.rows[e];t&&(this.rowsToAnimate.add(t),this.expandedRows=Ao(this.expandedRows,t),this.requestRender())}collapse(e){const t=this.rows[e];t&&(this.expandedRows=ko(this.expandedRows,t),this.requestRender())}toggle(e){const t=this.rows[e];t&&(this.expandedRows=wi(this.expandedRows,t),this.expandedRows.has(t)&&this.rowsToAnimate.add(t),this.requestRender())}isExpanded(e){const t=this.rows[e];return t?To(this.expandedRows,t):!1}expandAll(){for(const e of this.rows)this.rowsToAnimate.add(e),this.expandedRows.add(e);this.requestRender()}collapseAll(){this.expandedRows.clear(),this.requestRender()}getExpandedRows(){const e=[];for(const t of this.expandedRows){const i=this.rows.indexOf(t);i>=0&&e.push(i)}return e}getDetailElement(e){const t=this.rows[e];return t?this.detailElements.get(t):void 0}refreshDetailRenderer(){const e=this.config.detailRenderer;if(this.config={...this.config,detailRenderer:void 0},this.parseLightDomDetail(),!this.config.detailRenderer&&e&&(this.config={...this.config,detailRenderer:e}),this.config.detailRenderer){const t=this.grid;typeof t.refreshColumns=="function"?t.refreshColumns():this.requestRender()}}}function Ho(r,e,t){return e.length?[...r].sort((i,n)=>{for(const o of e){const l=t.find(u=>u.field===o.field)?.sortComparator??Do,a=i[o.field],c=n[o.field],d=l(a,c,i,n);if(d!==0)return o.direction==="asc"?d:-d}return 0}):[...r]}function Do(r,e){return r==null&&e==null?0:r==null?1:e==null?-1:typeof r=="number"&&typeof e=="number"?r-e:r instanceof Date&&e instanceof Date?r.getTime()-e.getTime():typeof r=="boolean"&&typeof e=="boolean"?r===e?0:r?-1:1:String(r).localeCompare(String(e))}function Io(r,e,t,i){const n=r.find(o=>o.field===e);return t?n?n.direction==="asc"?r.map(o=>o.field===e?{...o,direction:"desc"}:o):r.filter(o=>o.field!==e):r.length<i?[...r,{field:e,direction:"asc"}]:r:n?.direction==="asc"?[{field:e,direction:"desc"}]:n?.direction==="desc"?[]:[{field:e,direction:"asc"}]}function mi(r,e){const t=r.findIndex(i=>i.field===e);return t>=0?t+1:void 0}function bi(r,e){return r.find(t=>t.field===e)?.direction}const Mo='@layer tbw-plugins{.header-cell[data-sort=asc]:after{content:"↑";margin-left:var(--tbw-spacing-xs, .25em);opacity:.8}.header-cell[data-sort=desc]:after{content:"↓";margin-left:var(--tbw-spacing-xs, .25em);opacity:.8}.sort-indicator{margin-left:var(--tbw-spacing-xs, .25em);opacity:.8}.sort-index{font-size:var(--tbw-font-size-2xs, .7em);background:var(--tbw-multi-sort-badge-bg, var(--tbw-color-panel-bg));color:var(--tbw-multi-sort-badge-color, var(--tbw-color-fg));border-radius:50%;width:var(--tbw-multi-sort-badge-size, 1em);height:var(--tbw-multi-sort-badge-size, 1em);display:inline-flex;align-items:center;justify-content:center;margin-left:var(--tbw-spacing-xs, .125em);font-weight:600}}';class zo extends D{name="multiSort";styles=Mo;get defaultConfig(){return{maxSortColumns:3,showSortIndex:!0}}sortModel=[];detach(){this.sortModel=[]}processRows(e){return this.sortModel.length===0?[...e]:Ho([...e],this.sortModel,[...this.columns])}onHeaderClick(e){if(!this.columns.find(o=>o.field===e.field)?.sortable)return!1;const i=e.originalEvent.shiftKey,n=this.config.maxSortColumns??3;return this.sortModel=Io(this.sortModel,e.field,i,n),this.emit("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),!0}afterRender(){const e=this.gridElement;if(!e)return;const t=this.config.showSortIndex!==!1;e.querySelectorAll(".header-row .cell[data-field]").forEach(n=>{const o=n.getAttribute("data-field");if(!o)return;const s=mi(this.sortModel,o),l=bi(this.sortModel,o);if(n.querySelector(".sort-index")?.remove(),l){n.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove(),n.setAttribute("data-sort",l);const d=document.createElement("span");d.className="sort-indicator",this.setIcon(d,this.resolveIcon(l==="asc"?"sortAsc":"sortDesc"));const u=n.querySelector(".tbw-filter-btn"),h=n.querySelector(".resize-handle"),f=u??h;if(f?n.insertBefore(d,f):n.appendChild(d),t&&this.sortModel.length>1&&s!==void 0){const p=document.createElement("span");p.className="sort-index",p.textContent=String(s),d.nextSibling?n.insertBefore(p,d.nextSibling):n.appendChild(p)}}else n.removeAttribute("data-sort")})}getSortModel(){return[...this.sortModel]}setSortModel(e){this.sortModel=[...e],this.emit("sort-change",{sortModel:[...e]}),this.requestRender()}clearSort(){this.sortModel=[],this.emit("sort-change",{sortModel:[]}),this.requestRender()}getSortIndex(e){return mi(this.sortModel,e)}getSortDirection(e){return bi(this.sortModel,e)}getColumnState(e){const t=this.sortModel.findIndex(n=>n.field===e);return t===-1?void 0:{sort:{direction:this.sortModel[t].direction,priority:t}}}applyColumnState(e,t){if(!t.sort){this.sortModel=this.sortModel.filter(o=>o.field!==e);return}const i=this.sortModel.findIndex(o=>o.field===e),n={field:e,direction:t.sort.direction};i!==-1?this.sortModel[i]=n:this.sortModel.splice(t.sort.priority,0,n)}}function vi(r,e){return hn(r,e)}function yi(r,e){const t=r.sticky;return t?vi(t,e)==="left":!1}function Ci(r,e){const t=r.sticky;return t?vi(t,e)==="right":!1}function No(r,e="ltr"){return r.filter(t=>yi(t,e))}function Oo(r,e="ltr"){return r.filter(t=>Ci(t,e))}function at(r){return r.some(e=>e.sticky==="left"||e.sticky==="right"||e.sticky==="start"||e.sticky==="end")}function xi(r,e){const t=Array.from(r.querySelectorAll(".header-row .cell"));if(!t.length)return;const i=ve(r),n=new Map;e.forEach((l,a)=>{l.field&&n.set(l.field,a)});let o=0;for(const l of e)if(yi(l,i)){const a=n.get(l.field),c=t.find(d=>d.getAttribute("data-field")===l.field);c&&(c.classList.add("sticky-left"),c.style.position="sticky",c.style.left=o+"px",a!==void 0&&r.querySelectorAll(`.data-grid-row .cell[data-col="${a}"]`).forEach(d=>{d.classList.add("sticky-left"),d.style.position="sticky",d.style.left=o+"px"}),o+=c.offsetWidth)}let s=0;for(const l of[...e].reverse())if(Ci(l,i)){const a=n.get(l.field),c=t.find(d=>d.getAttribute("data-field")===l.field);c&&(c.classList.add("sticky-right"),c.style.position="sticky",c.style.right=s+"px",a!==void 0&&r.querySelectorAll(`.data-grid-row .cell[data-col="${a}"]`).forEach(d=>{d.classList.add("sticky-right"),d.style.position="sticky",d.style.right=s+"px"}),s+=c.offsetWidth)}}function Ei(r){r.querySelectorAll(".sticky-left, .sticky-right").forEach(t=>{t.classList.remove("sticky-left","sticky-right"),t.style.position="",t.style.left="",t.style.right=""})}const Ri="canMoveColumn";class Fo extends D{static manifest={ownedProperties:[{property:"sticky",level:"column",description:'the "sticky" column property',isUsed:e=>e==="left"||e==="right"||e==="start"||e==="end"}],queries:[{type:Ri,description:"Prevents pinned (sticky) columns from being moved/reordered"},{type:"getStickyOffsets",description:"Returns the sticky offsets for left/right pinned columns"}]};name="pinnedColumns";get defaultConfig(){return{}}isApplied=!1;leftOffsets=new Map;rightOffsets=new Map;detach(){this.leftOffsets.clear(),this.rightOffsets.clear(),this.isApplied=!1}static detect(e,t){const i=t?.columns;return Array.isArray(i)?at(i):!1}processColumns(e){return this.isApplied=at([...e]),[...e]}afterRender(){if(!this.isApplied)return;const e=this.grid,t=[...this.columns];if(!at(t)){Ei(e),this.isApplied=!1;return}queueMicrotask(()=>{xi(e,t)})}handleQuery(e){switch(e.type){case Ri:{const t=e.context,i=t.sticky;if(i==="left"||i==="right"||i==="start"||i==="end")return!1;const n=t.meta?.sticky;return n==="left"||n==="right"||n==="start"||n==="end"?!1:void 0}case"getStickyOffsets":return{left:Object.fromEntries(this.leftOffsets),right:Object.fromEntries(this.rightOffsets)};default:return}}refreshStickyOffsets(){const e=[...this.columns];xi(this.grid,e)}getLeftPinnedColumns(){const e=[...this.columns],t=ve(this.grid);return No(e,t)}getRightPinnedColumns(){const e=[...this.columns],t=ve(this.grid);return Oo(e,t)}clearStickyPositions(){Ei(this.grid)}getHorizontalScrollOffsets(e,t){if(!this.isApplied)return;let i=0,n=0;if(e){const s=e.querySelectorAll(".sticky-left"),l=e.querySelectorAll(".sticky-right");s.forEach(a=>{i+=a.offsetWidth}),l.forEach(a=>{n+=a.offsetWidth})}else this.grid.querySelectorAll(".header-row .cell").forEach(a=>{a.classList.contains("sticky-left")?i+=a.offsetWidth:a.classList.contains("sticky-right")&&(n+=a.offsetWidth)});const o=t?.classList.contains("sticky-left")||t?.classList.contains("sticky-right");return{left:i,right:n,skipScroll:o}}}function qo(r){return typeof r=="object"&&r!==null&&"aggFunc"in r}function ct(r,e){const t=document.createElement("div");t.className="tbw-pinned-rows",t.setAttribute("role","presentation"),t.setAttribute("aria-live","polite");const i=document.createElement("div");i.className="tbw-pinned-rows-left";const n=document.createElement("div");n.className="tbw-pinned-rows-center";const o=document.createElement("div");if(o.className="tbw-pinned-rows-right",r.showRowCount!==!1){const s=document.createElement("span");s.className="tbw-status-panel tbw-status-panel-row-count",s.textContent=`Total: ${e.totalRows} rows`,i.appendChild(s)}if(r.showFilteredCount&&e.filteredRows!==e.totalRows){const s=document.createElement("span");s.className="tbw-status-panel tbw-status-panel-filtered-count",s.textContent=`Filtered: ${e.filteredRows}`,i.appendChild(s)}if(r.showSelectedCount&&e.selectedRows>0){const s=document.createElement("span");s.className="tbw-status-panel tbw-status-panel-selected-count",s.textContent=`Selected: ${e.selectedRows}`,o.appendChild(s)}if(r.customPanels)for(const s of r.customPanels){const l=Go(s,e);switch(s.position){case"left":i.appendChild(l);break;case"center":n.appendChild(l);break;case"right":o.appendChild(l);break}}return t.appendChild(i),t.appendChild(n),t.appendChild(o),t}function Si(r){const e=document.createElement("div");return e.className=`tbw-aggregation-rows tbw-aggregation-rows-${r}`,e.setAttribute("role","presentation"),e}function _i(r,e,t,i){r.innerHTML="";for(const n of e){const o=document.createElement("div");if(o.className="tbw-aggregation-row",o.setAttribute("role","presentation"),n.id&&o.setAttribute("data-aggregation-id",n.id),n.fullWidth){const s=document.createElement("div");s.className="tbw-aggregation-cell tbw-aggregation-cell-full",s.style.gridColumn="1 / -1",s.textContent=n.label||"",o.appendChild(s)}else for(const s of t){const l=document.createElement("div");l.className="tbw-aggregation-cell",l.setAttribute("data-field",s.field);let a,c;const d=n.aggregators?.[s.field];if(d)if(qo(d)){const u=gi(d.aggFunc);u&&(a=u(i,s.field,s)),c=d.formatter}else{const u=gi(d);u&&(a=u(i,s.field,s))}else if(n.cells&&Object.prototype.hasOwnProperty.call(n.cells,s.field)){const u=n.cells[s.field];typeof u=="function"?a=u(i,s.field,s):a=u}a!=null?l.textContent=c?c(a,s.field,s):String(a):l.textContent="",o.appendChild(l)}r.appendChild(o)}}function Go(r,e){const t=document.createElement("div");t.className="tbw-status-panel tbw-status-panel-custom",t.id=`status-panel-${r.id}`;const i=r.render(e);return typeof i=="string"?t.innerHTML=i:t.appendChild(i),t}function Ai(r,e,t,i,n){return{totalRows:r.length,filteredRows:n?.cachedResult?.length??r.length,selectedRows:i?.selected?.size??0,columns:e,rows:r,grid:t}}const Bo="@layer tbw-plugins{.tbw-footer{flex-shrink:0;z-index:var(--tbw-z-layer-pinned-rows, 20);background:var(--tbw-color-panel-bg)}.tbw-pinned-rows{display:flex;align-items:center;justify-content:space-between;padding:var(--tbw-button-padding, var(--tbw-spacing-md, .5rem) var(--tbw-spacing-lg, .75rem));background:var(--tbw-pinned-rows-bg, var(--tbw-color-panel-bg));border-top:1px solid var(--tbw-pinned-rows-border, var(--tbw-color-border));font-size:var(--tbw-font-size-xs, .75rem);color:var(--tbw-pinned-rows-color, var(--tbw-color-fg-muted));min-height:32px;box-sizing:border-box;min-width:fit-content}.tbw-pinned-rows-left,.tbw-pinned-rows-center,.tbw-pinned-rows-right{display:flex;align-items:center;gap:var(--tbw-spacing-xl, 1rem)}.tbw-pinned-rows-left{justify-content:flex-start}.tbw-pinned-rows-center{justify-content:center;flex:1}.tbw-pinned-rows-right{justify-content:flex-end}.tbw-status-panel{white-space:nowrap}.tbw-aggregation-rows{min-width:fit-content;background:var(--tbw-aggregation-bg, var(--tbw-color-header-bg))}.tbw-aggregation-rows-top{border-bottom:1px solid var(--tbw-aggregation-border, var(--tbw-color-border))}.tbw-aggregation-rows-bottom{border-top:1px solid var(--tbw-aggregation-border, var(--tbw-color-border))}.tbw-aggregation-row{display:grid;grid-template-columns:var(--tbw-column-template);font-size:var(--tbw-aggregation-font-size, .8em);font-weight:var(--tbw-aggregation-font-weight, 600)}.tbw-aggregation-cell{padding:var(--tbw-cell-padding, .125rem .5rem);min-height:var(--tbw-row-height, 1.75rem);display:block;align-items:center;border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;text-overflow:ellipsis;white-space:var(--tbw-cell-white-space, nowrap)}.tbw-aggregation-cell:last-child{border-right:0}.tbw-aggregation-cell-full{grid-column:1 / -1;border-right:0}}";class Ko extends D{name="pinnedRows";styles=Bo;get defaultConfig(){return{position:"bottom",showRowCount:!0,showSelectedCount:!0,showFilteredCount:!0}}infoBarElement=null;topAggregationContainer=null;bottomAggregationContainer=null;footerWrapper=null;detach(){this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null),this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null)}afterRender(){const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-scroll-area")??e.querySelector(".tbw-grid-content")??e.children[0];if(!t)return;this.footerWrapper&&!t.contains(this.footerWrapper)&&(this.footerWrapper=null,this.bottomAggregationContainer=null,this.infoBarElement=null),this.topAggregationContainer&&!t.contains(this.topAggregationContainer)&&(this.topAggregationContainer=null),this.infoBarElement&&!t.contains(this.infoBarElement)&&(this.infoBarElement=null);const i=this.getSelectionState(),n=this.getFilterState(),o=Ai(this.sourceRows,this.columns,this.grid,i,n),s=this.config.aggregationRows||[],l=s.filter(h=>h.position==="top"),a=s.filter(h=>h.position!=="top");if(l.length>0){if(!this.topAggregationContainer){this.topAggregationContainer=Si("top");const h=e.querySelector(".header");h&&h.nextSibling?t.insertBefore(this.topAggregationContainer,h.nextSibling):t.appendChild(this.topAggregationContainer)}_i(this.topAggregationContainer,l,this.visibleColumns,this.sourceRows)}else this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null);const c=this.config.showRowCount!==!1||this.config.showSelectedCount&&o.selectedRows>0||this.config.showFilteredCount&&o.filteredRows!==o.totalRows||this.config.customPanels&&this.config.customPanels.length>0,d=c&&this.config.position!=="top",u=a.length>0||d;if(c&&this.config.position==="top")if(!this.infoBarElement)this.infoBarElement=ct(this.config,o),t.insertBefore(this.infoBarElement,t.firstChild);else{const h=ct(this.config,o);this.infoBarElement.replaceWith(h),this.infoBarElement=h}else this.config.position==="top"&&this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null);u?(this.footerWrapper||(this.footerWrapper=document.createElement("div"),this.footerWrapper.className="tbw-footer",t.appendChild(this.footerWrapper)),this.footerWrapper.innerHTML="",a.length>0&&(this.bottomAggregationContainer||(this.bottomAggregationContainer=Si("bottom")),this.footerWrapper.appendChild(this.bottomAggregationContainer),_i(this.bottomAggregationContainer,a,this.visibleColumns,this.sourceRows)),d&&(this.infoBarElement=ct(this.config,o),this.footerWrapper.appendChild(this.infoBarElement))):this.cleanupFooter()}cleanup(){this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null),this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null)}cleanupFooter(){this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.infoBarElement&&this.config.position!=="top"&&(this.infoBarElement.remove(),this.infoBarElement=null)}getSelectionState(){try{return this.grid?.getPluginState?.("selection")??null}catch{return null}}getFilterState(){try{return this.grid?.getPluginState?.("filtering")??null}catch{return null}}refresh(){this.requestRender()}getContext(){const e=this.getSelectionState(),t=this.getFilterState();return Ai(this.rows,this.columns,this.grid,e,t)}addPanel(e){this.config.customPanels||(this.config.customPanels=[]),this.config.customPanels.push(e),this.requestRender()}removePanel(e){this.config.customPanels&&(this.config.customPanels=this.config.customPanels.filter(t=>t.id!==e),this.requestRender())}addAggregationRow(e){this.config.aggregationRows||(this.config.aggregationRows=[]),this.config.aggregationRows.push(e),this.requestRender()}removeAggregationRow(e){this.config.aggregationRows&&(this.config.aggregationRows=this.config.aggregationRows.filter(t=>t.id!==e),this.requestRender())}}const $o=bo;function Wo(r){const e=[];return!r.rowGroupFields?.length&&!r.columnGroupFields?.length&&e.push("At least one row or column group field is required"),r.valueFields?.length||e.push("At least one value field is required"),e}function dt(r,e){return[...r,e].join("|")}function Vo(r,e){const t=e.rowGroupFields??[],i=e.columnGroupFields??[],n=e.valueFields??[],o=Uo(r,i),s=ki(r,t,i,o,n,0,""),l=Yo(s,o,n),a=Object.values(l).reduce((c,d)=>c+d,0);return{rows:s,columnKeys:o,totals:l,grandTotal:a}}function Uo(r,e){if(e.length===0)return["value"];const t=new Set;for(const i of r){const n=e.map(o=>String(i[o]??"")).join("|");t.add(n)}return[...t].sort()}function jo(r,e){const t=new Map;for(const i of r){const n=String(i[e]??""),o=t.get(n);o?o.push(i):t.set(n,[i])}return t}function ki(r,e,t,i,n,o,s){const l=[];if(e.length===0){const h=Ti(r,t,i,n),f=Li(h);return l.push({rowKey:s||"all",rowLabel:s||"All",depth:o,values:h,total:f,isGroup:!1,rowCount:r.length}),l}const a=e[0],c=e.slice(1),d=c.length>0,u=jo(r,a);for(const[h,f]of u){const p=s?`${s}|${h}`:h,g=Ti(f,t,i,n),w=Li(g);let b;d&&(b=ki(f,c,t,i,n,o+1,p)),l.push({rowKey:p,rowLabel:h||"(blank)",depth:o,values:g,total:w,isGroup:d,children:b,rowCount:f.length})}return l}function Ti(r,e,t,i){const n={};for(const o of t)for(const s of i){const a=(e.length>0?r.filter(h=>e.map(f=>String(h[f]??"")).join("|")===o):r).map(h=>Number(h[s.field])||0),c=$o(s.aggFunc),d=a.length>0?c(a):null,u=dt([o],s.field);n[u]=d}return n}function Li(r){let e=0;for(const t of Object.values(r))e+=t??0;return e}function Yo(r,e,t){const i={};function n(o){for(const s of o)if(!s.isGroup||!s.children?.length)for(const l of e)for(const a of t){const c=dt([l],a.field);i[c]=(i[c]??0)+(s.values[c]??0)}else s.children&&n(s.children)}return n(r),i}function Xo(r,e,t=!0){const i=[];function n(o){i.push(o);const s=e?e.has(o.rowKey):t;if(o.children&&s)for(const l of o.children)n(l)}for(const o of r)n(o);return i}function Zo(r){const e=[];function t(i){if(i.isGroup&&e.push(i.rowKey),i.children)for(const n of i.children)t(n)}for(const i of r)t(i);return e}const Qo=["sum","avg","count","min","max","first","last"];function Jo(r,e,t,i){const n=new AbortController,o={config:e,callbacks:i,signal:n.signal},s=document.createElement("div");return s.className="tbw-pivot-panel",s.appendChild(pe("Options",()=>rs(t,o))),s.appendChild(pe("Row Groups",()=>Pi("rowGroups",o))),s.appendChild(pe("Column Groups",()=>Pi("columnGroups",o))),s.appendChild(pe("Values",()=>ts(o))),s.appendChild(pe("Available Fields",()=>ns(o))),r.appendChild(s),()=>{n.abort(),s.remove()}}function pe(r,e){const t=document.createElement("div");t.className="tbw-pivot-section";const i=document.createElement("div");i.className="tbw-pivot-section-header",i.textContent=r;const n=document.createElement("div");return n.className="tbw-pivot-section-content",n.appendChild(e()),t.appendChild(i),t.appendChild(n),t}function Pi(r,e){const{config:t,callbacks:i,signal:n}=e,o=document.createElement("div");o.className="tbw-pivot-drop-zone",o.setAttribute("data-zone",r);const s=r==="rowGroups"?t.rowGroupFields??[]:t.columnGroupFields??[];if(s.length===0){const l=document.createElement("div");l.className="tbw-pivot-placeholder",l.textContent="Drag fields here or click to add",o.appendChild(l)}else for(const l of s)o.appendChild(es(l,r,e));return o.addEventListener("dragover",l=>{l.preventDefault(),o.classList.add("drag-over")},{signal:n}),o.addEventListener("dragleave",()=>{o.classList.remove("drag-over")},{signal:n}),o.addEventListener("drop",l=>{l.preventDefault(),o.classList.remove("drag-over");const a=l.dataTransfer?.getData("text/plain");a&&i.onAddFieldToZone(a,r)},{signal:n}),o}function es(r,e,t){const{callbacks:i,signal:n}=t,o=document.createElement("div");o.className="tbw-pivot-field-chip",o.draggable=!0;const s=i.getAvailableFields().find(c=>c.field===r),l=document.createElement("span");l.className="tbw-pivot-chip-label",l.textContent=s?.header??r;const a=document.createElement("button");return a.className="tbw-pivot-chip-remove",a.innerHTML="×",a.title="Remove field",a.addEventListener("click",c=>{c.stopPropagation(),i.onRemoveFieldFromZone(r,e)},{signal:n}),o.appendChild(l),o.appendChild(a),o.addEventListener("dragstart",c=>{c.dataTransfer?.setData("text/plain",r),c.dataTransfer?.setData("source-zone",e),o.classList.add("dragging")},{signal:n}),o.addEventListener("dragend",()=>{o.classList.remove("dragging")},{signal:n}),o}function ts(r){const{config:e,callbacks:t,signal:i}=r,n=document.createElement("div");n.className="tbw-pivot-drop-zone tbw-pivot-values-zone",n.setAttribute("data-zone","values");const o=e.valueFields??[];if(o.length===0){const s=document.createElement("div");s.className="tbw-pivot-placeholder",s.textContent="Drag numeric fields here for aggregation",n.appendChild(s)}else for(const s of o)n.appendChild(is(s,r));return n.addEventListener("dragover",s=>{s.preventDefault(),n.classList.add("drag-over")},{signal:i}),n.addEventListener("dragleave",()=>{n.classList.remove("drag-over")},{signal:i}),n.addEventListener("drop",s=>{s.preventDefault(),n.classList.remove("drag-over");const l=s.dataTransfer?.getData("text/plain");l&&t.onAddValueField(l,"sum")},{signal:i}),n}function is(r,e){const{callbacks:t,signal:i}=e,n=document.createElement("div");n.className="tbw-pivot-field-chip tbw-pivot-value-chip";const o=t.getAvailableFields().find(d=>d.field===r.field),s=document.createElement("div");s.className="tbw-pivot-value-label-wrapper";const l=document.createElement("span");l.className="tbw-pivot-chip-label",l.textContent=o?.header??r.field;const a=document.createElement("select");a.className="tbw-pivot-agg-select",a.title="Aggregation function";for(const d of Qo){const u=document.createElement("option");u.value=d,u.textContent=d.toUpperCase(),u.selected=d===r.aggFunc,a.appendChild(u)}a.addEventListener("change",()=>{t.onUpdateValueAggFunc(r.field,a.value)},{signal:i});const c=document.createElement("button");return c.className="tbw-pivot-chip-remove",c.innerHTML="×",c.title="Remove value field",c.addEventListener("click",d=>{d.stopPropagation(),t.onRemoveValueField(r.field)},{signal:i}),s.appendChild(l),s.appendChild(a),n.appendChild(s),n.appendChild(c),n}function ns(r){const{config:e,callbacks:t,signal:i}=r,n=document.createElement("div");n.className="tbw-pivot-available-fields";const o=t.getAvailableFields(),s=new Set([...e.rowGroupFields??[],...e.columnGroupFields??[],...e.valueFields?.map(a=>a.field)??[]]),l=o.filter(a=>!s.has(a.field));if(l.length===0){const a=document.createElement("div");a.className="tbw-pivot-placeholder",a.textContent="All fields are in use",n.appendChild(a)}else for(const a of l){const c=document.createElement("div");c.className="tbw-pivot-field-chip available",c.textContent=a.header,c.draggable=!0,c.title=`Drag to add "${a.field}" to a zone`,c.addEventListener("dragstart",d=>{d.dataTransfer?.setData("text/plain",a.field),c.classList.add("dragging")},{signal:i}),c.addEventListener("dragend",()=>{c.classList.remove("dragging")},{signal:i}),n.appendChild(c)}return n}function rs(r,e){const{config:t,callbacks:i,signal:n}=e,o=document.createElement("div");return o.className="tbw-pivot-options",o.appendChild(ut("Enable Pivot View",r,s=>{i.onTogglePivot(s)},n)),o.appendChild(ut("Show Row Totals",t.showTotals??!0,s=>{i.onOptionChange("showTotals",s)},n)),o.appendChild(ut("Show Grand Total",t.showGrandTotal??!0,s=>{i.onOptionChange("showGrandTotal",s)},n)),o}function ut(r,e,t,i){const n=document.createElement("label");n.className="tbw-pivot-checkbox";const o=document.createElement("input");o.type="checkbox",o.checked=e,o.addEventListener("change",()=>t(o.checked),{signal:i});const s=document.createElement("span");return s.textContent=r,n.appendChild(o),n.appendChild(s),n}function os(r,e,t){return e.className="data-grid-row pivot-group-row",e.setAttribute("data-pivot-depth",String(r.__pivotDepth??0)),e.setAttribute("data-pivot-key",String(r.__pivotRowKey??"")),e.setAttribute("role","row"),e.innerHTML="",t.columns.forEach((i,n)=>{const o=document.createElement("div");if(o.className="cell",o.setAttribute("data-col",String(n)),o.setAttribute("data-row",String(t.rowIndex)),o.setAttribute("role","gridcell"),n===0){const s=Number(r.__pivotIndent)||0;o.style.paddingLeft=`${s}px`;const l=String(r.__pivotRowKey),a=document.createElement("button");a.type="button",a.className="pivot-toggle",a.setAttribute("aria-label",r.__pivotExpanded?"Collapse group":"Expand group"),t.setIcon(a,t.resolveIcon(r.__pivotExpanded?"collapse":"expand")),a.addEventListener("click",u=>{u.stopPropagation(),t.onToggle(l)}),o.appendChild(a);const c=document.createElement("span");c.className="pivot-label",c.textContent=String(r.__pivotLabel??""),o.appendChild(c);const d=document.createElement("span");d.className="pivot-count",d.textContent=` (${Number(r.__pivotRowCount)||0})`,o.appendChild(d)}else{const s=r[i.field];o.textContent=s!=null?String(s):""}e.appendChild(o)}),!0}function ss(r,e,t,i){return e.className="data-grid-row pivot-leaf-row",e.setAttribute("data-pivot-depth",String(r.__pivotDepth??0)),e.setAttribute("data-pivot-key",String(r.__pivotRowKey??"")),e.innerHTML="",t.forEach((n,o)=>{const s=document.createElement("div");if(s.className="cell",s.setAttribute("data-col",String(o)),s.setAttribute("data-row",String(i)),s.setAttribute("role","gridcell"),o===0){const l=Number(r.__pivotIndent)||0;s.style.paddingLeft=`${l+20}px`;const a=document.createElement("span");a.className="pivot-label",a.textContent=String(r.__pivotLabel??""),s.appendChild(a)}else{const l=r[n.field];s.textContent=l!=null?String(l):""}e.appendChild(s)}),!0}function ls(r,e,t){return e.className="pivot-grand-total-row",e.setAttribute("role","presentation"),e.innerHTML="",t.forEach((i,n)=>{const o=document.createElement("div");if(o.className="cell",o.setAttribute("data-col",String(n)),n===0){const s=document.createElement("span");s.className="pivot-label",s.textContent="Grand Total",o.appendChild(s)}else{const s=r[i.field];o.textContent=s!=null?String(s):""}e.appendChild(o)}),!0}const as='@layer tbw-plugins{.pivot-group-row{display:grid;grid-template-columns:var(--tbw-column-template);font-weight:600;background:var(--tbw-pivot-group-bg, var(--tbw-color-row-alt));min-height:var(--tbw-row-height);border-bottom:var(--tbw-row-divider)}.pivot-group-row:hover{background:var(--tbw-pivot-group-hover, var(--tbw-color-row-hover))}.pivot-leaf-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-pivot-leaf-bg, var(--tbw-color-bg));min-height:var(--tbw-row-height);border-bottom:var(--tbw-row-divider)}.pivot-grand-total-row{display:grid;grid-template-columns:var(--tbw-column-template);font-weight:700;background:var(--tbw-pivot-grand-total-bg, var(--tbw-color-header-bg));min-height:var(--tbw-row-height);border-top:2px solid var(--tbw-color-border-strong)}.pivot-grand-total-row>.cell{display:flex;align-items:center;padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}.pivot-grand-total-row>.cell:last-child{border-right:0}.pivot-grand-total-footer{position:sticky;bottom:0;z-index:var(--tbw-z-layer-pinned-rows, 20);background:var(--tbw-pivot-grand-total-bg, var(--tbw-color-header-bg));min-width:fit-content}.pivot-group-row>.cell,.pivot-leaf-row>.cell{display:flex;align-items:center;padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}.pivot-group-row>.cell:last-child,.pivot-leaf-row>.cell:last-child{border-right:0}.pivot-toggle{display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-pivot-toggle-size, var(--tbw-toggle-size, 1.25em));height:var(--tbw-pivot-toggle-size, var(--tbw-toggle-size, 1.25em));margin-right:var(--tbw-spacing-sm, .375em);border:none;background:transparent;cursor:pointer;color:var(--tbw-pivot-toggle-color, var(--tbw-color-fg-muted));border-radius:var(--tbw-border-radius);transition:background var(--tbw-transition-duration, .12s) var(--tbw-transition-ease, ease),color var(--tbw-transition-duration, .12s) var(--tbw-transition-ease, ease)}.pivot-toggle:hover{background:var(--tbw-pivot-toggle-hover-bg, var(--tbw-color-row-hover));color:var(--tbw-pivot-toggle-hover-color, var(--tbw-color-fg))}.pivot-toggle:focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}.pivot-label{font-weight:inherit}.pivot-count{color:var(--tbw-pivot-count-color, var(--tbw-color-fg-muted));font-size:.9em;font-weight:400}.pivot-total-row{font-weight:700;border-top:2px solid var(--tbw-pivot-border, var(--tbw-color-border-strong))}[data-pivot-depth="1"]{--tbw-pivot-depth: 1}[data-pivot-depth="2"]{--tbw-pivot-depth: 2}[data-pivot-depth="3"]{--tbw-pivot-depth: 3}[data-pivot-depth="4"]{--tbw-pivot-depth: 4}.tbw-pivot-panel{display:flex;flex-direction:column;gap:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));padding:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));height:100%;overflow-y:auto;font-size:var(--tbw-font-size-sm, .8125rem)}.tbw-pivot-section{border:1px solid var(--tbw-pivot-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);background:var(--tbw-pivot-section-bg, var(--tbw-color-bg))}.tbw-pivot-section-header{padding:var(--tbw-button-padding, var(--tbw-spacing-md, .5rem) var(--tbw-spacing-lg, .75rem));font-weight:600;background:var(--tbw-pivot-header-bg, var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-pivot-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius) var(--tbw-border-radius) 0 0}.tbw-pivot-section-content{padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-pivot-toggle-wrapper{display:flex;align-items:center}.tbw-pivot-toggle-label{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));cursor:pointer}.tbw-pivot-toggle-label input{width:var(--tbw-icon-size, 1rem);height:var(--tbw-icon-size, 1rem);cursor:pointer}.tbw-pivot-drop-zone{min-height:60px;padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border:2px dashed var(--tbw-pivot-drop-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);background:var(--tbw-pivot-drop-bg, var(--tbw-color-row-alt));display:flex;flex-wrap:wrap;gap:var(--tbw-spacing-sm, .375rem);align-content:flex-start;transition:all .15s ease}.tbw-pivot-drop-zone.drag-over{border-color:var(--tbw-color-accent);background:var(--tbw-pivot-drop-active, var(--tbw-focus-background))}.tbw-pivot-placeholder{color:var(--tbw-color-fg-muted);font-style:italic;padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));text-align:center;width:100%}.tbw-pivot-field-chip{display:inline-flex;align-items:center;gap:var(--tbw-spacing-sm, .375rem);padding:var(--tbw-button-padding-sm, var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-md, .5rem));background:var(--tbw-pivot-chip-bg, var(--tbw-color-header-bg));border:1px solid var(--tbw-pivot-chip-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);cursor:grab;font-size:var(--tbw-font-size-xs, .75rem);transition:all .15s ease}.tbw-pivot-field-chip:hover{background:var(--tbw-pivot-chip-hover, var(--tbw-color-row-hover));border-color:var(--tbw-color-accent)}.tbw-pivot-field-chip.available{background:var(--tbw-color-bg)}.tbw-pivot-field-chip.dragging{opacity:.5;cursor:grabbing}.tbw-pivot-chip-label{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:120px}.tbw-pivot-chip-remove{display:flex;align-items:center;justify-content:center;width:var(--tbw-icon-size, 1rem);height:var(--tbw-icon-size, 1rem);padding:0;border:none;background:transparent;color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-sm, .875rem);font-weight:700;cursor:pointer;border-radius:50%;transition:all .15s ease}.tbw-pivot-chip-remove:hover{background:var(--tbw-pivot-chip-remove-hover-bg, var(--tbw-color-accent));color:var(--tbw-pivot-chip-remove-hover-fg, var(--tbw-color-accent-fg))}.tbw-pivot-value-chip{padding:var(--tbw-button-padding-sm, var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-md, .5rem))}.tbw-pivot-value-label-wrapper{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));flex:1;min-width:0}.tbw-pivot-agg-select{padding:var(--tbw-spacing-xs, .125rem) var(--tbw-spacing-xs, .25rem);font-size:var(--tbw-font-size-xs, .6875rem);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);background:var(--tbw-color-bg);cursor:pointer}.tbw-pivot-available-fields{display:flex;flex-wrap:wrap;gap:var(--tbw-spacing-sm, .375rem);min-height:40px}.tbw-pivot-options{display:flex;flex-direction:column;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-pivot-checkbox{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));cursor:pointer}.tbw-pivot-checkbox input{width:var(--tbw-icon-size-sm, .875rem);height:var(--tbw-icon-size-sm, .875rem);cursor:pointer}.pivot-group-row.tbw-pivot-slide-in,.pivot-leaf-row.tbw-pivot-slide-in{animation:tbw-pivot-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-pivot-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.pivot-group-row.tbw-pivot-fade-in,.pivot-leaf-row.tbw-pivot-fade-in{animation:tbw-pivot-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-pivot-fade-in{0%{opacity:0}to{opacity:1}}}';class Z extends D{name="pivot";styles=as;static PANEL_ID="pivot";get defaultConfig(){return{active:!0,showTotals:!0,showGrandTotal:!0,showToolPanel:!0,animation:"slide"}}isActive=!1;hasInitialized=!1;pivotResult=null;fieldHeaderMap=new Map;expandedKeys=new Set;defaultExpanded=!0;userHasToggledExpand=!1;originalColumns=[];panelContainer=null;grandTotalFooter=null;previousVisibleKeys=new Set;keysToAnimate=new Set;hasValidPivotConfig(){return(this.config.valueFields?.length??0)>0}get animationStyle(){return this.isAnimationEnabled?this.config.animation??"slide":!1}detach(){this.isActive=!1,this.hasInitialized=!1,this.pivotResult=null,this.fieldHeaderMap.clear(),this.originalColumns=[],this.panelContainer=null,this.cleanupGrandTotalFooter(),this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.userHasToggledExpand=!1}getToolPanel(){if((this.config?.showToolPanel??this.userConfig?.showToolPanel??!0)!==!1)return{id:Z.PANEL_ID,title:"Pivot",icon:"⊞",tooltip:"Configure pivot table",order:90,render:t=>this.renderPanel(t)}}processRows(e){if(!this.hasInitialized&&this.config.active!==!1&&this.hasValidPivotConfig()&&(this.hasInitialized=!0,this.isActive=!0),!this.isActive)return[...e];const t=Wo(this.config);if(t.length>0)return this.warn(`Config errors: ${t.join(", ")}`),[...e];this.buildFieldHeaderMap(),this.defaultExpanded=this.config.defaultExpanded??!0,this.pivotResult=Vo(e,this.config),this.expandedKeys.size===0&&this.defaultExpanded&&!this.userHasToggledExpand&&this.expandAllKeys();const i=this.config.indentWidth??20,n=Xo(this.pivotResult.rows,this.expandedKeys,this.defaultExpanded).map(s=>({__pivotRowKey:s.rowKey,__pivotLabel:s.rowLabel,__pivotDepth:s.depth,__pivotIsGroup:s.isGroup,__pivotHasChildren:!!s.children?.length,__pivotExpanded:this.expandedKeys.has(s.rowKey),__pivotRowCount:s.rowCount??0,__pivotIndent:s.depth*i,__pivotTotal:s.total,...s.values}));this.keysToAnimate.clear();const o=new Set;for(const s of n){const l=s.__pivotRowKey;o.add(l),!this.previousVisibleKeys.has(l)&&s.__pivotDepth>0&&this.keysToAnimate.add(l)}return this.previousVisibleKeys=o,n}processColumns(e){if(!this.isActive||!this.pivotResult)return[...e];const t=[],i=(this.config.rowGroupFields??[]).map(n=>this.fieldHeaderMap.get(n)??n).join(" / ");t.push({field:"__pivotLabel",header:i||"Group",width:200});for(const n of this.pivotResult.columnKeys)for(const o of this.config.valueFields??[]){const s=dt([n],o.field),l=o.header||this.fieldHeaderMap.get(o.field)||o.field;t.push({field:s,header:`${n} - ${l} (${o.aggFunc})`,width:120,type:"number"})}return this.config.showTotals&&t.push({field:"__pivotTotal",header:"Total",width:100,type:"number"}),t}renderRow(e,t,i){const n=e;return n.__pivotRowKey&&n.__pivotHasChildren?os(n,t,{columns:this.gridColumns,rowIndex:i,onToggle:o=>this.toggle(o),resolveIcon:o=>this.resolveIcon(o),setIcon:(o,s)=>this.setIcon(o,s)}):n.__pivotRowKey!==void 0&&this.isActive?ss(n,t,this.gridColumns,i):(this.cleanupPivotStyling(t),!1)}cleanupPivotStyling(e){(e.classList.contains("pivot-group-row")||e.classList.contains("pivot-leaf-row")||e.classList.contains("pivot-grand-total-row"))&&(e.classList.remove("pivot-group-row","pivot-leaf-row","pivot-grand-total-row"),e.classList.add("data-grid-row"),e.removeAttribute("data-pivot-depth"),e.innerHTML="")}onKeyDown(e){if(e.key!==" "||!this.isActive)return;const t=this.grid._focusRow,i=this.rows[t];if(!(!i?.__pivotIsGroup||!i.__pivotHasChildren))return e.preventDefault(),this.toggle(i.__pivotRowKey),this.requestRenderWithFocus(),!0}afterRender(){this.isActive&&this.config.showGrandTotal&&this.pivotResult?this.renderGrandTotalFooter():this.cleanupGrandTotalFooter();const e=this.animationStyle;if(e===!1||this.keysToAnimate.size===0)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const i=e==="fade"?"tbw-pivot-fade-in":"tbw-pivot-slide-in";for(const n of t.querySelectorAll(".pivot-group-row, .pivot-leaf-row")){const o=n.dataset.pivotKey;o&&this.keysToAnimate.has(o)&&(n.classList.add(i),n.addEventListener("animationend",()=>n.classList.remove(i),{once:!0}))}this.keysToAnimate.clear()}renderGrandTotalFooter(){if(!this.pivotResult)return;const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-scroll-area")??e.querySelector(".tbw-grid-content")??e.children[0];if(!t)return;this.grandTotalFooter||(this.grandTotalFooter=document.createElement("div"),this.grandTotalFooter.className="pivot-grand-total-footer",t.appendChild(this.grandTotalFooter));const i={__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals};ls(i,this.grandTotalFooter,this.gridColumns)}cleanupGrandTotalFooter(){this.grandTotalFooter&&(this.grandTotalFooter.remove(),this.grandTotalFooter=null)}toggle(e){this.userHasToggledExpand=!0,this.expandedKeys.has(e)?this.expandedKeys.delete(e):this.expandedKeys.add(e),this.requestRender()}expand(e){this.userHasToggledExpand=!0,this.expandedKeys.add(e),this.requestRender()}collapse(e){this.userHasToggledExpand=!0,this.expandedKeys.delete(e),this.requestRender()}expandAll(){this.userHasToggledExpand=!0,this.expandAllKeys(),this.requestRender()}collapseAll(){this.userHasToggledExpand=!0,this.expandedKeys.clear(),this.requestRender()}expandAllKeys(){if(!this.pivotResult)return;const e=Zo(this.pivotResult.rows);for(const t of e)this.expandedKeys.add(t)}isExpanded(e){return this.expandedKeys.has(e)}enablePivot(){this.originalColumns.length===0&&this.captureOriginalColumns(),this.isActive=!0,this.requestRender()}disablePivot(){this.isActive=!1,this.pivotResult=null,this.requestRender()}isPivotActive(){return this.isActive}getPivotResult(){return this.pivotResult}setRowGroupFields(e){this.config.rowGroupFields=e,this.requestRender()}setColumnGroupFields(e){this.config.columnGroupFields=e,this.requestRender()}setValueFields(e){this.config.valueFields=e,this.requestRender()}refresh(){this.pivotResult=null,this.requestRender()}showPanel(){this.grid.openToolPanel(),this.grid.expandedToolPanelSections.includes(Z.PANEL_ID)||this.grid.toggleToolPanelSection(Z.PANEL_ID)}hidePanel(){this.grid.closeToolPanel()}togglePanel(){this.grid.isToolPanelOpen||this.grid.openToolPanel(),this.grid.toggleToolPanelSection(Z.PANEL_ID)}isPanelVisible(){return this.grid.isToolPanelOpen&&this.grid.expandedToolPanelSections.includes(Z.PANEL_ID)}get gridColumns(){return this.grid.columns??[]}refreshIfActive(){this.isActive&&this.refresh(),this.refreshPanel()}buildFieldHeaderMap(){const e=this.getAvailableFields();this.fieldHeaderMap.clear();for(const t of e)this.fieldHeaderMap.set(t.field,t.header)}getAvailableFields(){return this.originalColumns.length>0?this.originalColumns:this.captureOriginalColumns()}captureOriginalColumns(){try{const e=this.grid.getAllColumns?.()??this.grid.columns??[];return this.originalColumns=e.filter(t=>!t.field.startsWith("__pivot")).map(t=>({field:t.field,header:t.header??t.field})),this.originalColumns}catch{return[]}}renderPanel(e){this.panelContainer=e,this.originalColumns.length===0&&this.captureOriginalColumns();const t={onTogglePivot:i=>{i?this.enablePivot():this.disablePivot(),this.refreshPanel()},onAddFieldToZone:(i,n)=>this.addFieldToZone(i,n),onRemoveFieldFromZone:(i,n)=>this.removeFieldFromZone(i,n),onAddValueField:(i,n)=>this.addValueField(i,n),onRemoveValueField:i=>this.removeValueField(i),onUpdateValueAggFunc:(i,n)=>this.updateValueAggFunc(i,n),onOptionChange:(i,n)=>{this.config[i]=n,this.isActive&&this.refresh()},getAvailableFields:()=>this.getAvailableFields()};return Jo(e,this.config,this.isActive,t)}refreshPanel(){this.panelContainer&&(this.panelContainer.innerHTML="",this.renderPanel(this.panelContainer))}addFieldToZone(e,t){if(t==="rowGroups"){const i=this.config.rowGroupFields??[];i.includes(e)||(this.config.rowGroupFields=[...i,e])}else{const i=this.config.columnGroupFields??[];i.includes(e)||(this.config.columnGroupFields=[...i,e])}this.removeFromOtherZones(e,t),this.refreshIfActive()}removeFieldFromZone(e,t){t==="rowGroups"?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(i=>i!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(i=>i!==e),this.refreshIfActive()}removeFromOtherZones(e,t){t!=="rowGroups"&&(this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(i=>i!==e)),t!=="columnGroups"&&(this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(i=>i!==e)),t!=="values"&&(this.config.valueFields=(this.config.valueFields??[]).filter(i=>i.field!==e))}addValueField(e,t){const i=this.config.valueFields??[];i.some(n=>n.field===e)||(this.config.valueFields=[...i,{field:e,aggFunc:t}]),this.removeFromOtherZones(e,"values"),this.refreshIfActive()}removeValueField(e){this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e),this.refreshIfActive()}updateValueAggFunc(e,t){const i=this.config.valueFields??[],n=i.findIndex(o=>o.field===e);n>=0&&(i[n]={...i[n],aggFunc:t},this.config.valueFields=[...i]),this.isActive&&this.refresh()}}const Le="tbw-print-isolation-style";function cs(r,e){const t=document.createElement("style");return t.id=Le,t.textContent=`
|
|
110
|
+
→ Consider using "defaultExpanded: false" or a single group key/index with accordion mode.`,check:e=>e.accordion===!0&&e.defaultExpanded!==!1&&e.defaultExpanded!==void 0&&typeof e.defaultExpanded!="number"&&typeof e.defaultExpanded!="string"&&(e.defaultExpanded===!0||Array.isArray(e.defaultExpanded)&&e.defaultExpanded.length>1)}]};name="groupingRows";styles=To;get defaultConfig(){return{defaultExpanded:!1,showRowCount:!0,indentWidth:20,aggregators:{},animation:"slide",accordion:!1}}expandedKeys=new Set;flattenedRows=[];isActive=!1;previousVisibleKeys=new Set;keysToAnimate=new Set;hasAppliedDefaultExpanded=!1;get animationStyle(){return this.isAnimationEnabled?this.config.animation??"slide":!1}detach(){this.expandedKeys.clear(),this.flattenedRows=[],this.isActive=!1,this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.hasAppliedDefaultExpanded=!1}getRowHeight(e,t){if(this.config.groupRowHeight!=null&&e.__isGroupRow===!0)return this.config.groupRowHeight}handleQuery(e){if(e.type==="canMoveRow"&&e.context?.__isGroupRow===!0)return!1}static detect(e,t){return typeof t?.groupOn=="function"||typeof t?.enableRowGrouping=="boolean"}processRows(e){const t=this.config;if(typeof t.groupOn!="function")return this.isActive=!1,this.flattenedRows=[],[...e];const i=wi({rows:[...e],config:t,expanded:new Set});if(i.length===0)return this.isActive=!1,this.flattenedRows=[],[...e];let n;if(!this.hasAppliedDefaultExpanded&&this.expandedKeys.size===0&&t.defaultExpanded!==!1){const l=Ao(i);n=_o(t.defaultExpanded??!1,l),n.size>0&&(this.expandedKeys=new Set(n),this.hasAppliedDefaultExpanded=!0)}const o=wi({rows:[...e],config:t,expanded:this.expandedKeys,initialExpanded:n});this.isActive=!0,this.flattenedRows=o,this.keysToAnimate.clear();const s=new Set;return o.forEach((l,a)=>{if(l.kind==="data"){const c=`data-${a}`;s.add(c),this.previousVisibleKeys.has(c)||this.keysToAnimate.add(c)}}),this.previousVisibleKeys=s,o.map(l=>l.kind==="group"?{__isGroupRow:!0,__groupKey:l.key,__groupValue:l.value,__groupDepth:l.depth,__groupRows:l.rows,__groupExpanded:l.expanded,__groupRowCount:ko(l),__rowCacheKey:`group:${l.key}`}:l.row)}onCellClick(e){const t=e.row;if(t?.__isGroupRow&&e.originalEvent.target?.closest(".group-toggle"))return this.toggle(t.__groupKey),!0}onKeyDown(e){if(e.key!==" ")return;const t=this.grid._focusRow,i=this.rows[t];if(i?.__isGroupRow)return e.preventDefault(),this.toggle(i.__groupKey),this.requestRenderWithFocus(),!0}renderRow(e,t,i){if(!e?.__isGroupRow)return!1;const n=this.config;if(n.groupRowRenderer){const l=()=>{this.toggle(e.__groupKey)},a=n.groupRowRenderer({key:e.__groupKey,value:e.__groupValue,depth:e.__groupDepth,rows:e.__groupRows,expanded:e.__groupExpanded,toggleExpand:l});if(a)return t.className="data-grid-row group-row",t.__isCustomRow=!0,t.setAttribute("data-group-depth",String(e.__groupDepth)),typeof a=="string"?t.innerHTML=a:(t.innerHTML="",t.appendChild(a)),!0}const o=()=>{this.toggle(e.__groupKey)};return t.className="data-grid-row group-row",t.__isCustomRow=!0,t.setAttribute("data-group-depth",String(e.__groupDepth)),t.setAttribute("role","row"),t.setAttribute("aria-expanded",String(e.__groupExpanded)),t.style.setProperty("--tbw-group-depth",String(e.__groupDepth||0)),n.indentWidth!==void 0&&t.style.setProperty("--tbw-group-indent-width",`${n.indentWidth}px`),t.style.height="",t.innerHTML="",n.fullWidth!==!1?this.renderFullWidthGroupRow(e,t,o):this.renderPerColumnGroupRow(e,t,o),!0}afterRender(){const e=this.animationStyle;if(e===!1||this.keysToAnimate.size===0)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const i=e==="fade"?"tbw-group-fade-in":"tbw-group-slide-in";for(const n of t.querySelectorAll(".data-grid-row:not(.group-row)")){const o=n.querySelector(".cell[data-row]"),s=o?parseInt(o.getAttribute("data-row")??"-1",10):-1,a=this.flattenedRows[s]?.kind==="data"?`data-${s}`:void 0;a&&this.keysToAnimate.has(a)&&(n.classList.add(i),n.addEventListener("animationend",()=>n.classList.remove(i),{once:!0}))}this.keysToAnimate.clear()}createToggleButton(e,t){const i=document.createElement("button");return i.type="button",i.className=`group-toggle${e?" expanded":""}`,i.setAttribute("aria-label",e?"Collapse group":"Expand group"),this.setIcon(i,this.resolveIcon(e?"collapse":"expand")),i.addEventListener("click",n=>{n.stopPropagation(),t()}),i}getGroupLabelText(e,t,i){const n=this.config;return n.formatLabel?n.formatLabel(e,t,i):String(e)}renderFullWidthGroupRow(e,t,i){const n=this.config,o=n.aggregators??{},s=e.__groupRows??[],l=document.createElement("div");l.className="cell group-full",l.style.gridColumn="1 / -1",l.setAttribute("role","gridcell"),l.setAttribute("data-col","0"),l.appendChild(this.createToggleButton(e.__groupExpanded,i));const a=document.createElement("span");if(a.className="group-label",a.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey),l.appendChild(a),n.showRowCount!==!1){const d=document.createElement("span");d.className="group-count",d.textContent=`(${e.__groupRowCount??e.__groupRows?.length??0})`,l.appendChild(d)}const c=Object.entries(o);if(c.length>0){const d=document.createElement("span");d.className="group-aggregates";for(const[u,h]of c){const f=this.columns.find(g=>g.field===u),p=lt(h,s,u,f);if(p!=null){const g=document.createElement("span");g.className="group-aggregate",g.setAttribute("data-field",u);const w=f?.header??u;g.textContent=`${w}: ${p}`,d.appendChild(g)}}d.children.length>0&&l.appendChild(d)}t.appendChild(l)}renderPerColumnGroupRow(e,t,i){const n=this.config,o=n.aggregators??{},s=this.columns,l=e.__groupRows??[],c=this.gridElement?.querySelector(".body")?.style.gridTemplateColumns||"";c&&(t.style.display="grid",t.style.gridTemplateColumns=c);let d=!1;s.forEach((u,h)=>{const f=document.createElement("div");if(f.className="cell group-cell",f.setAttribute("data-col",String(h)),f.setAttribute("role","gridcell"),Le(u)){f.setAttribute("data-field",u.field),t.appendChild(f);return}if(d){const p=o[u.field];if(p){const g=lt(p,l,u.field,u);f.textContent=g!=null?String(g):""}else f.textContent=""}else{d=!0,f.appendChild(this.createToggleButton(e.__groupExpanded,i));const p=document.createElement("span"),g=o[u.field];if(g){const w=lt(g,l,u.field,u);p.textContent=w!=null?String(w):String(e.__groupValue)}else p.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey);if(f.appendChild(p),n.showRowCount!==!1){const w=document.createElement("span");w.className="group-count",w.textContent=` (${l.length})`,f.appendChild(w)}}t.appendChild(f)})}expandAll(){this.expandedKeys=Ro(this.flattenedRows),this.emitPluginEvent("grouping-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}collapseAll(){this.expandedKeys=So(),this.emitPluginEvent("grouping-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}toggle(e){const t=!this.expandedKeys.has(e),i=this.config,n=this.flattenedRows.find(o=>o.kind==="group"&&o.key===e);if(i.accordion&&t&&n){const o=new Set;for(const s of this.expandedKeys)if(e.startsWith(s+"||")||s.startsWith(e+"||"))e.startsWith(s+"||")&&o.add(s);else{const l=this.flattenedRows.find(a=>a.kind==="group"&&a.key===s);l&&l.depth!==n.depth&&o.add(s)}o.add(e),this.expandedKeys=o}else this.expandedKeys=Eo(this.expandedKeys,e);this.emit("group-toggle",{key:e,expanded:this.expandedKeys.has(e),value:n?.value,depth:n?.depth??0}),this.emitPluginEvent("grouping-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}expand(e){this.expandedKeys.has(e)||(this.expandedKeys=new Set([...this.expandedKeys,e]),this.requestRender())}collapse(e){if(this.expandedKeys.has(e)){const t=new Set(this.expandedKeys);t.delete(e),this.expandedKeys=t,this.requestRender()}}getGroupState(){const e=this.flattenedRows.filter(t=>t.kind==="group");return{isActive:this.isActive,expandedCount:this.expandedKeys.size,totalGroups:e.length,expandedKeys:[...this.expandedKeys]}}getRowCount(){return this.flattenedRows.length}refreshGroups(){this.requestRender()}getExpandedGroups(){return[...this.expandedKeys]}getFlattenedRows(){return this.flattenedRows}isGroupingActive(){return this.isActive}setGroupOn(e){this.config.groupOn=e,this.requestRender()}}function bi(r,e){const t=new Set(r);return t.has(e)?t.delete(e):t.add(e),t}function Po(r,e){const t=new Set(r);return t.add(e),t}function Ho(r,e){const t=new Set(r);return t.delete(e),t}function Do(r,e){return r.has(e)}function Mo(r,e,t,i){const n=document.createElement("div");n.className="master-detail-row",n.setAttribute("data-detail-for",String(e)),n.setAttribute("role","row");const o=document.createElement("div");o.className="master-detail-cell",o.setAttribute("role","cell"),o.style.gridColumn=`1 / ${i+1}`;const s=t(r,e);return typeof s=="string"?o.innerHTML=s:s instanceof HTMLElement&&o.appendChild(s),n.appendChild(o),n}const Io="@layer tbw-plugins{tbw-grid .cell[data-field=__tbw_expander]{border-right:none!important;padding:0;display:flex;align-items:center;justify-content:center}tbw-grid .header-row .cell[data-field=__tbw_expander]{display:none}tbw-grid .header-row .cell[data-field=__tbw_expander]+.cell{grid-column:1 / 3}tbw-grid .master-detail-expander{display:flex;align-items:center;justify-content:center;width:100%;height:100%}tbw-grid .master-detail-toggle{cursor:pointer;opacity:.7;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center}tbw-grid .master-detail-toggle:hover{opacity:1}tbw-grid .master-detail-row{grid-column:1 / -1;display:grid;background:var(--tbw-master-detail-bg, var(--tbw-color-row-alt));border-bottom:1px solid var(--tbw-master-detail-border, var(--tbw-color-border));overflow:hidden}tbw-grid .master-detail-cell{padding:var(--tbw-detail-padding, var(--tbw-spacing-xl, 1rem));overflow:auto}tbw-grid .master-detail-row.tbw-expanding{animation:tbw-detail-expand var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}tbw-grid .master-detail-row.tbw-collapsing{animation:tbw-detail-collapse var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-detail-expand{0%{opacity:0;max-height:0;padding-top:0;padding-bottom:0}to{opacity:1;max-height:var(--tbw-detail-max-height, 31.25rem);padding-top:var(--tbw-detail-padding, var(--tbw-spacing-xl, 1rem));padding-bottom:var(--tbw-detail-padding, var(--tbw-spacing-xl, 1rem))}}@keyframes tbw-detail-collapse{0%{opacity:1;max-height:var(--tbw-detail-max-height, 31.25rem)}to{opacity:0;max-height:0}}}";class at extends D{name="masterDetail";styles=Io;get defaultConfig(){return{detailHeight:"auto",expandOnRowClick:!1,collapseOnClickOutside:!1,animation:"slide"}}attach(e){super.attach(e),this.parseLightDomDetail()}parseLightDomDetail(){const e=this.grid;if(!e||typeof e.querySelector!="function")return;const t=e.querySelector("tbw-grid-detail");if(!t)return;const i=e;if(i.__frameworkAdapter?.parseDetailElement){const u=i.__frameworkAdapter.parseDetailElement(t);if(u){this.config={...this.config,detailRenderer:u};return}}const n=t.getAttribute("animation"),o=t.getAttribute("show-expand-column"),s=t.getAttribute("expand-on-row-click"),l=t.getAttribute("collapse-on-click-outside"),a=t.getAttribute("height"),c={};n!==null&&(c.animation=n==="false"?!1:n),o!==null&&(c.showExpandColumn=o!=="false"),s!==null&&(c.expandOnRowClick=s==="true"),l!==null&&(c.collapseOnClickOutside=l==="true"),a!==null&&(c.detailHeight=a==="auto"?"auto":parseInt(a,10));const d=t.innerHTML.trim();d&&!this.config.detailRenderer&&(c.detailRenderer=(u,h)=>{const f=be(d,{value:u,row:u});return V(f)}),Object.keys(c).length>0&&(this.config={...this.config,...c})}get animationStyle(){return this.isAnimationEnabled?this.config.animation??"slide":!1}animateExpand(e,t,i){if(!this.isAnimationEnabled||this.animationStyle===!1)return!1;e.classList.add("tbw-expanding");let n=!1;const o=()=>{n||(n=!0,e.classList.remove("tbw-expanding"),t!==void 0&&i!==void 0&&this.#t(e,t,i))};return e.addEventListener("animationend",o,{once:!0}),setTimeout(o,this.animationDuration+50),!0}animateCollapse(e,t){if(!this.isAnimationEnabled||this.animationStyle===!1){t();return}e.classList.add("tbw-collapsing");const i=()=>{e.classList.remove("tbw-collapsing"),t()};e.addEventListener("animationend",i,{once:!0}),setTimeout(i,this.animationDuration+50)}#t(e,t,i){if(!e.isConnected)return;const n=e.offsetHeight;if(n>0){const o=this.measuredDetailHeights.get(t);this.measuredDetailHeights.set(t,n),o!==n&&this.grid.invalidateRowHeight(i)}}expandedRows=new Set;detailElements=new Map;measuredDetailHeights=new Map;rowsToAnimate=new Set;static DEFAULT_DETAIL_HEIGHT=150;getDetailHeight(e){const t=this.detailElements.get(e);if(t&&!(t.classList.contains("tbw-expanding")||t.classList.contains("tbw-collapsing"))){const o=t.offsetHeight;if(o>0)return this.measuredDetailHeights.set(e,o),o}const i=this.measuredDetailHeights.get(e);return i&&i>0?i:typeof this.config?.detailHeight=="number"?this.config.detailHeight:at.DEFAULT_DETAIL_HEIGHT}toggleAndEmit(e,t){this.expandedRows=bi(this.expandedRows,e);const i=this.expandedRows.has(e);i&&this.rowsToAnimate.add(e),this.emit("detail-expand",{rowIndex:t,row:e,expanded:i}),this.requestRender()}detach(){this.expandedRows.clear(),this.detailElements.clear(),this.measuredDetailHeights.clear(),this.rowsToAnimate.clear()}processColumns(e){if(!(this.config.showExpandColumn===!0||this.config.showExpandColumn!==!1&&!!this.config.detailRenderer))return[...e];const i=[...e];if(co(i))return i;const o=uo(this.name);return o.viewRenderer=s=>{const{row:l}=s,a=this.expandedRows.has(l),c=document.createElement("span");c.className="master-detail-expander expander-cell";const d=document.createElement("span");return d.className=`master-detail-toggle${a?" expanded":""}`,this.setIcon(d,this.resolveIcon(a?"collapse":"expand")),d.setAttribute("role","button"),d.setAttribute("tabindex","0"),d.setAttribute("aria-expanded",String(a)),d.setAttribute("aria-label",a?"Collapse details":"Expand details"),c.appendChild(d),c},[o,...i]}onRowClick(e){if(!(!this.config.expandOnRowClick||!this.config.detailRenderer))return this.toggleAndEmit(e.row,e.rowIndex),!1}onCellClick(e){if(e.originalEvent?.target?.classList.contains("master-detail-toggle"))return this.toggleAndEmit(e.row,e.rowIndex),!0;this.expandedRows.size>0&&queueMicrotask(()=>this.#e())}onKeyDown(e){if(e.key!==" ")return;const t=this.grid._focusCol,i=this.grid._focusRow,n=this.columns[t];if(!n||!Le(n))return;const o=this.rows[i];if(o)return e.preventDefault(),this.toggleAndEmit(o,i),this.requestRenderWithFocus(),!0}afterRender(){this.#e()}onScrollRender(){!this.config.detailRenderer||this.expandedRows.size===0||this.#e()}#e(){if(!this.config.detailRenderer)return;const e=this.gridElement?.querySelector(".rows");if(!e)return;const t=this.grid,i=t._rowPool,n=t._virtualization?.start??0,o=t._virtualization?.end??0,s=this.columns.length,l=n,a=o,c=new Map;if(i){const d=Math.min(i.length,a-l);for(let u=0;u<d;u++){const h=i[u];h.parentNode===e&&c.set(l+u,h)}}else{const d=e.querySelectorAll(".data-grid-row");for(const u of d){const h=u.querySelector(".cell[data-row]"),f=h?parseInt(h.getAttribute("data-row")??"-1",10):-1;f>=0&&c.set(f,u)}}for(const[d,u]of this.detailElements){const h=this.rows.indexOf(d),f=this.expandedRows.has(d),p=h>=0&&c.has(h);(!f||!p)&&(u.parentNode&&u.remove(),this.detailElements.delete(d))}for(const[d,u]of c){const h=this.rows[d];if(!h||!this.expandedRows.has(h))continue;const f=this.detailElements.get(h);if(f){f.previousElementSibling!==u&&u.after(f);continue}const p=Mo(h,d,this.config.detailRenderer,s);typeof this.config.detailHeight=="number"&&(p.style.height=`${this.config.detailHeight}px`),u.after(p),this.detailElements.set(h,p);const g=this.rowsToAnimate.has(h);g&&this.rowsToAnimate.delete(h),g&&this.animateExpand(p,h,d)||requestAnimationFrame(()=>{this.#t(p,h,d)})}}getExtraHeight(){let e=0;for(const t of this.expandedRows)e+=this.getDetailHeight(t);return e}getExtraHeightBefore(e){let t=0;for(const i of this.expandedRows){const n=this.rows.indexOf(i);n>=0&&n<e&&(t+=this.getDetailHeight(i))}return t}getRowHeight(e,t){if(!this.expandedRows.has(e))return;const n=this.grid.defaultRowHeight??28,o=this.getDetailHeight(e);return n+o}adjustVirtualStart(e,t,i){if(this.expandedRows.size===0)return e;const n=this.grid?._virtualization?.positionCache;let o=e;if(n&&n.length>0)for(const s of this.expandedRows){const l=this.rows.indexOf(s);if(l<0||l>=e)continue;n[l].offset+n[l].height>t&&l<o&&(o=l)}else{const s=[];for(const a of this.expandedRows){const c=this.rows.indexOf(a);c>=0&&s.push({index:c,row:a})}s.sort((a,c)=>a.index-c.index);let l=0;for(const{index:a,row:c}of s){const d=a*i+l,u=this.getDetailHeight(c),h=d+i+u;l+=u,!(a>=e)&&h>t&&a<o&&(o=a)}}return o}expand(e){const t=this.rows[e];t&&(this.rowsToAnimate.add(t),this.expandedRows=Po(this.expandedRows,t),this.requestRender())}collapse(e){const t=this.rows[e];t&&(this.expandedRows=Ho(this.expandedRows,t),this.requestRender())}toggle(e){const t=this.rows[e];t&&(this.expandedRows=bi(this.expandedRows,t),this.expandedRows.has(t)&&this.rowsToAnimate.add(t),this.requestRender())}isExpanded(e){const t=this.rows[e];return t?Do(this.expandedRows,t):!1}expandAll(){for(const e of this.rows)this.rowsToAnimate.add(e),this.expandedRows.add(e);this.requestRender()}collapseAll(){this.expandedRows.clear(),this.requestRender()}getExpandedRows(){const e=[];for(const t of this.expandedRows){const i=this.rows.indexOf(t);i>=0&&e.push(i)}return e}getDetailElement(e){const t=this.rows[e];return t?this.detailElements.get(t):void 0}refreshDetailRenderer(){const e=this.config.detailRenderer;if(this.config={...this.config,detailRenderer:void 0},this.parseLightDomDetail(),!this.config.detailRenderer&&e&&(this.config={...this.config,detailRenderer:e}),this.config.detailRenderer){const t=this.grid;typeof t.refreshColumns=="function"?t.refreshColumns():this.requestRender()}}}function zo(r,e,t){return e.length?[...r].sort((i,n)=>{for(const o of e){const l=t.find(u=>u.field===o.field)?.sortComparator??No,a=i[o.field],c=n[o.field],d=l(a,c,i,n);if(d!==0)return o.direction==="asc"?d:-d}return 0}):[...r]}function No(r,e){return r==null&&e==null?0:r==null?1:e==null?-1:typeof r=="number"&&typeof e=="number"?r-e:r instanceof Date&&e instanceof Date?r.getTime()-e.getTime():typeof r=="boolean"&&typeof e=="boolean"?r===e?0:r?-1:1:String(r).localeCompare(String(e))}function Oo(r,e,t,i){const n=r.find(o=>o.field===e);return t?n?n.direction==="asc"?r.map(o=>o.field===e?{...o,direction:"desc"}:o):r.filter(o=>o.field!==e):r.length<i?[...r,{field:e,direction:"asc"}]:r:n?.direction==="asc"?[{field:e,direction:"desc"}]:n?.direction==="desc"?[]:[{field:e,direction:"asc"}]}function mi(r,e){const t=r.findIndex(i=>i.field===e);return t>=0?t+1:void 0}function vi(r,e){return r.find(t=>t.field===e)?.direction}const Fo='@layer tbw-plugins{.header-cell[data-sort=asc]:after{content:"↑";margin-left:var(--tbw-spacing-xs, .25em);opacity:.8}.header-cell[data-sort=desc]:after{content:"↓";margin-left:var(--tbw-spacing-xs, .25em);opacity:.8}.sort-indicator{margin-left:var(--tbw-spacing-xs, .25em);opacity:.8}.sort-index{font-size:var(--tbw-font-size-2xs, .7em);background:var(--tbw-multi-sort-badge-bg, var(--tbw-color-panel-bg));color:var(--tbw-multi-sort-badge-color, var(--tbw-color-fg));border-radius:50%;width:var(--tbw-multi-sort-badge-size, 1em);height:var(--tbw-multi-sort-badge-size, 1em);display:inline-flex;align-items:center;justify-content:center;margin-left:var(--tbw-spacing-xs, .125em);font-weight:600}}';class qo extends D{name="multiSort";styles=Fo;get defaultConfig(){return{maxSortColumns:3,showSortIndex:!0}}sortModel=[];detach(){this.sortModel=[]}processRows(e){return this.sortModel.length===0?[...e]:zo([...e],this.sortModel,[...this.columns])}onHeaderClick(e){if(!this.columns.find(o=>o.field===e.field)?.sortable)return!1;const i=e.originalEvent.shiftKey,n=this.config.maxSortColumns??3;return this.sortModel=Oo(this.sortModel,e.field,i,n),this.emit("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),!0}afterRender(){const e=this.gridElement;if(!e)return;const t=this.config.showSortIndex!==!1;e.querySelectorAll(".header-row .cell[data-field]").forEach(n=>{const o=n.getAttribute("data-field");if(!o)return;const s=mi(this.sortModel,o),l=vi(this.sortModel,o);if(n.querySelector(".sort-index")?.remove(),l){n.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove(),n.setAttribute("data-sort",l);const d=document.createElement("span");d.className="sort-indicator",this.setIcon(d,this.resolveIcon(l==="asc"?"sortAsc":"sortDesc"));const u=n.querySelector(".tbw-filter-btn"),h=n.querySelector(".resize-handle"),f=u??h;if(f?n.insertBefore(d,f):n.appendChild(d),t&&this.sortModel.length>1&&s!==void 0){const p=document.createElement("span");p.className="sort-index",p.textContent=String(s),d.nextSibling?n.insertBefore(p,d.nextSibling):n.appendChild(p)}}else n.removeAttribute("data-sort")})}getSortModel(){return[...this.sortModel]}setSortModel(e){this.sortModel=[...e],this.emit("sort-change",{sortModel:[...e]}),this.requestRender()}clearSort(){this.sortModel=[],this.emit("sort-change",{sortModel:[]}),this.requestRender()}getSortIndex(e){return mi(this.sortModel,e)}getSortDirection(e){return vi(this.sortModel,e)}getColumnState(e){const t=this.sortModel.findIndex(n=>n.field===e);return t===-1?void 0:{sort:{direction:this.sortModel[t].direction,priority:t}}}applyColumnState(e,t){if(!t.sort){this.sortModel=this.sortModel.filter(o=>o.field!==e);return}const i=this.sortModel.findIndex(o=>o.field===e),n={field:e,direction:t.sort.direction};i!==-1?this.sortModel[i]=n:this.sortModel.splice(t.sort.priority,0,n)}}function yi(r,e){return gn(r,e)}function Ci(r,e){const t=r.sticky;return t?yi(t,e)==="left":!1}function xi(r,e){const t=r.sticky;return t?yi(t,e)==="right":!1}function Go(r,e="ltr"){return r.filter(t=>Ci(t,e))}function $o(r,e="ltr"){return r.filter(t=>xi(t,e))}function ct(r){return r.some(e=>e.sticky==="left"||e.sticky==="right"||e.sticky==="start"||e.sticky==="end")}function Ei(r,e){const t=Array.from(r.querySelectorAll(".header-row .cell"));if(!t.length)return;const i=ve(r),n=new Map;e.forEach((l,a)=>{l.field&&n.set(l.field,a)});let o=0;for(const l of e)if(Ci(l,i)){const a=n.get(l.field),c=t.find(d=>d.getAttribute("data-field")===l.field);c&&(c.classList.add("sticky-left"),c.style.position="sticky",c.style.left=o+"px",a!==void 0&&r.querySelectorAll(`.data-grid-row .cell[data-col="${a}"]`).forEach(d=>{d.classList.add("sticky-left"),d.style.position="sticky",d.style.left=o+"px"}),o+=c.offsetWidth)}let s=0;for(const l of[...e].reverse())if(xi(l,i)){const a=n.get(l.field),c=t.find(d=>d.getAttribute("data-field")===l.field);c&&(c.classList.add("sticky-right"),c.style.position="sticky",c.style.right=s+"px",a!==void 0&&r.querySelectorAll(`.data-grid-row .cell[data-col="${a}"]`).forEach(d=>{d.classList.add("sticky-right"),d.style.position="sticky",d.style.right=s+"px"}),s+=c.offsetWidth)}}function Ri(r){r.querySelectorAll(".sticky-left, .sticky-right").forEach(t=>{t.classList.remove("sticky-left","sticky-right"),t.style.position="",t.style.left="",t.style.right=""})}const Si="canMoveColumn";class Bo extends D{static manifest={ownedProperties:[{property:"sticky",level:"column",description:'the "sticky" column property',isUsed:e=>e==="left"||e==="right"||e==="start"||e==="end"}],queries:[{type:Si,description:"Prevents pinned (sticky) columns from being moved/reordered"},{type:"getStickyOffsets",description:"Returns the sticky offsets for left/right pinned columns"}]};name="pinnedColumns";get defaultConfig(){return{}}isApplied=!1;leftOffsets=new Map;rightOffsets=new Map;detach(){this.leftOffsets.clear(),this.rightOffsets.clear(),this.isApplied=!1}static detect(e,t){const i=t?.columns;return Array.isArray(i)?ct(i):!1}processColumns(e){return this.isApplied=ct([...e]),[...e]}afterRender(){if(!this.isApplied)return;const e=this.grid,t=[...this.columns];if(!ct(t)){Ri(e),this.isApplied=!1;return}queueMicrotask(()=>{Ei(e,t)})}handleQuery(e){switch(e.type){case Si:{const t=e.context,i=t.sticky;if(i==="left"||i==="right"||i==="start"||i==="end")return!1;const n=t.meta?.sticky;return n==="left"||n==="right"||n==="start"||n==="end"?!1:void 0}case"getStickyOffsets":return{left:Object.fromEntries(this.leftOffsets),right:Object.fromEntries(this.rightOffsets)};default:return}}refreshStickyOffsets(){const e=[...this.columns];Ei(this.grid,e)}getLeftPinnedColumns(){const e=[...this.columns],t=ve(this.grid);return Go(e,t)}getRightPinnedColumns(){const e=[...this.columns],t=ve(this.grid);return $o(e,t)}clearStickyPositions(){Ri(this.grid)}getHorizontalScrollOffsets(e,t){if(!this.isApplied)return;let i=0,n=0;if(e){const s=e.querySelectorAll(".sticky-left"),l=e.querySelectorAll(".sticky-right");s.forEach(a=>{i+=a.offsetWidth}),l.forEach(a=>{n+=a.offsetWidth})}else this.grid.querySelectorAll(".header-row .cell").forEach(a=>{a.classList.contains("sticky-left")?i+=a.offsetWidth:a.classList.contains("sticky-right")&&(n+=a.offsetWidth)});const o=t?.classList.contains("sticky-left")||t?.classList.contains("sticky-right");return{left:i,right:n,skipScroll:o}}}function Ko(r){return typeof r=="object"&&r!==null&&"aggFunc"in r}function dt(r,e){const t=document.createElement("div");t.className="tbw-pinned-rows",t.setAttribute("role","presentation"),t.setAttribute("aria-live","polite");const i=document.createElement("div");i.className="tbw-pinned-rows-left";const n=document.createElement("div");n.className="tbw-pinned-rows-center";const o=document.createElement("div");if(o.className="tbw-pinned-rows-right",r.showRowCount!==!1){const s=document.createElement("span");s.className="tbw-status-panel tbw-status-panel-row-count",s.textContent=`Total: ${e.totalRows} rows`,i.appendChild(s)}if(r.showFilteredCount&&e.filteredRows!==e.totalRows){const s=document.createElement("span");s.className="tbw-status-panel tbw-status-panel-filtered-count",s.textContent=`Filtered: ${e.filteredRows}`,i.appendChild(s)}if(r.showSelectedCount&&e.selectedRows>0){const s=document.createElement("span");s.className="tbw-status-panel tbw-status-panel-selected-count",s.textContent=`Selected: ${e.selectedRows}`,o.appendChild(s)}if(r.customPanels)for(const s of r.customPanels){const l=jo(s,e);switch(s.position){case"left":i.appendChild(l);break;case"center":n.appendChild(l);break;case"right":o.appendChild(l);break}}return t.appendChild(i),t.appendChild(n),t.appendChild(o),t}function _i(r){const e=document.createElement("div");return e.className=`tbw-aggregation-rows tbw-aggregation-rows-${r}`,e.setAttribute("role","presentation"),e}function Ai(r,e,t,i,n=!1){r.innerHTML="";for(const o of e){const s=document.createElement("div");s.className="tbw-aggregation-row",s.setAttribute("role","presentation"),o.id&&s.setAttribute("data-aggregation-id",o.id),o.fullWidth??n?Wo(s,o,t,i):Vo(s,o,t,i),r.appendChild(s)}}function Wo(r,e,t,i){const n=document.createElement("div");n.className="tbw-aggregation-cell tbw-aggregation-cell-full",n.style.gridColumn="1 / -1";const o=typeof e.label=="function"?e.label(i,t):e.label;if(o){const l=document.createElement("span");l.className="tbw-aggregation-label",l.textContent=o,n.appendChild(l)}const s=Uo(e,t,i);s&&n.appendChild(s),r.appendChild(n)}function Vo(r,e,t,i){for(const n of t){const o=document.createElement("div");o.className="tbw-aggregation-cell",o.setAttribute("data-field",n.field);const{value:s,formatter:l}=ki(e,n,i);s!=null?o.textContent=l?l(s,n.field,n):String(s):o.textContent="",r.appendChild(o)}}function ki(r,e,t){let i,n;const o=r.aggregators?.[e.field];if(o)if(Ko(o)){const s=pi(o.aggFunc);s&&(i=s(t,e.field,e)),n=o.formatter}else{const s=pi(o);s&&(i=s(t,e.field,e))}else if(r.cells&&Object.prototype.hasOwnProperty.call(r.cells,e.field)){const s=r.cells[e.field];typeof s=="function"?i=s(t,e.field,e):i=s}return{value:i,formatter:n}}function Uo(r,e,t){const i=r.aggregators&&Object.keys(r.aggregators).length>0,n=r.cells&&Object.keys(r.cells).length>0;if(!i&&!n)return null;const o=document.createElement("span");o.className="tbw-aggregation-aggregates";for(const s of e){const{value:l,formatter:a}=ki(r,s,t);if(l!=null){const c=document.createElement("span");c.className="tbw-aggregation-aggregate",c.setAttribute("data-field",s.field);const d=s.header??s.field,u=a?a(l,s.field,s):String(l);c.textContent=`${d}: ${u}`,o.appendChild(c)}}return o.children.length>0?o:null}function jo(r,e){const t=document.createElement("div");t.className="tbw-status-panel tbw-status-panel-custom",t.id=`status-panel-${r.id}`;const i=r.render(e);return typeof i=="string"?t.innerHTML=i:t.appendChild(i),t}function Ti(r,e,t,i,n){return{totalRows:r.length,filteredRows:n?.cachedResult?.length??r.length,selectedRows:i?.selected?.size??0,columns:e,rows:r,grid:t}}const Yo="@layer tbw-plugins{.tbw-footer{flex-shrink:0;z-index:var(--tbw-z-layer-pinned-rows, 20);background:var(--tbw-color-panel-bg)}.tbw-pinned-rows{display:flex;align-items:center;justify-content:space-between;padding:var(--tbw-button-padding, var(--tbw-spacing-md, .5rem) var(--tbw-spacing-lg, .75rem));background:var(--tbw-pinned-rows-bg, var(--tbw-color-panel-bg));border-top:1px solid var(--tbw-pinned-rows-border, var(--tbw-color-border));font-size:var(--tbw-font-size-xs, .75rem);color:var(--tbw-pinned-rows-color, var(--tbw-color-fg-muted));min-height:32px;box-sizing:border-box;min-width:fit-content}.tbw-pinned-rows-left,.tbw-pinned-rows-center,.tbw-pinned-rows-right{display:flex;align-items:center;gap:var(--tbw-spacing-xl, 1rem)}.tbw-pinned-rows-left{justify-content:flex-start}.tbw-pinned-rows-center{justify-content:center;flex:1}.tbw-pinned-rows-right{justify-content:flex-end}.tbw-status-panel{white-space:nowrap}.tbw-aggregation-rows{min-width:fit-content;background:var(--tbw-aggregation-bg, var(--tbw-color-header-bg))}.tbw-aggregation-rows-top{border-bottom:1px solid var(--tbw-aggregation-border, var(--tbw-color-border))}.tbw-aggregation-rows-bottom{border-top:1px solid var(--tbw-aggregation-border, var(--tbw-color-border))}.tbw-aggregation-row{display:grid;grid-template-columns:var(--tbw-column-template);font-size:var(--tbw-aggregation-font-size, .8em);font-weight:var(--tbw-aggregation-font-weight, 600)}.tbw-aggregation-cell{padding:var(--tbw-cell-padding, .125rem .5rem);min-height:var(--tbw-row-height, 1.75rem);display:block;align-items:center;align-content:center;border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;text-overflow:ellipsis;white-space:var(--tbw-cell-white-space, nowrap)}.tbw-aggregation-cell:last-child{border-right:0}.tbw-aggregation-cell-full{grid-column:1 / -1;border-right:0;display:flex;align-items:center;gap:var(--tbw-spacing-lg, .75rem)}.tbw-aggregation-label{white-space:nowrap}.tbw-aggregation-aggregates{display:flex;align-items:center;gap:var(--tbw-spacing-lg, .75rem);font-weight:400;opacity:.85}.tbw-aggregation-aggregate{white-space:nowrap}}";class Xo extends D{name="pinnedRows";styles=Yo;get defaultConfig(){return{position:"bottom",showRowCount:!0,showSelectedCount:!0,showFilteredCount:!0}}infoBarElement=null;topAggregationContainer=null;bottomAggregationContainer=null;footerWrapper=null;detach(){this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null),this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null)}afterRender(){const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-scroll-area")??e.querySelector(".tbw-grid-content")??e.children[0];if(!t)return;this.footerWrapper&&!t.contains(this.footerWrapper)&&(this.footerWrapper=null,this.bottomAggregationContainer=null,this.infoBarElement=null),this.topAggregationContainer&&!t.contains(this.topAggregationContainer)&&(this.topAggregationContainer=null),this.infoBarElement&&!t.contains(this.infoBarElement)&&(this.infoBarElement=null);const i=this.getSelectionState(),n=this.getFilterState(),o=Ti(this.sourceRows,this.columns,this.grid,i,n),s=this.config.aggregationRows||[],l=s.filter(h=>h.position==="top"),a=s.filter(h=>h.position!=="top");if(l.length>0){if(!this.topAggregationContainer){this.topAggregationContainer=_i("top");const h=e.querySelector(".header");h&&h.nextSibling?t.insertBefore(this.topAggregationContainer,h.nextSibling):t.appendChild(this.topAggregationContainer)}Ai(this.topAggregationContainer,l,this.visibleColumns,this.sourceRows,this.config.fullWidth)}else this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null);const c=this.config.showRowCount!==!1||this.config.showSelectedCount&&o.selectedRows>0||this.config.showFilteredCount&&o.filteredRows!==o.totalRows||this.config.customPanels&&this.config.customPanels.length>0,d=c&&this.config.position!=="top",u=a.length>0||d;if(c&&this.config.position==="top")if(!this.infoBarElement)this.infoBarElement=dt(this.config,o),t.insertBefore(this.infoBarElement,t.firstChild);else{const h=dt(this.config,o);this.infoBarElement.replaceWith(h),this.infoBarElement=h}else this.config.position==="top"&&this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null);u?(this.footerWrapper||(this.footerWrapper=document.createElement("div"),this.footerWrapper.className="tbw-footer",t.appendChild(this.footerWrapper)),this.footerWrapper.innerHTML="",a.length>0&&(this.bottomAggregationContainer||(this.bottomAggregationContainer=_i("bottom")),this.footerWrapper.appendChild(this.bottomAggregationContainer),Ai(this.bottomAggregationContainer,a,this.visibleColumns,this.sourceRows,this.config.fullWidth)),d&&(this.infoBarElement=dt(this.config,o),this.footerWrapper.appendChild(this.infoBarElement))):this.cleanupFooter()}cleanup(){this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null),this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null)}cleanupFooter(){this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.infoBarElement&&this.config.position!=="top"&&(this.infoBarElement.remove(),this.infoBarElement=null)}getSelectionState(){try{return this.grid?.getPluginState?.("selection")??null}catch{return null}}getFilterState(){try{return this.grid?.getPluginState?.("filtering")??null}catch{return null}}refresh(){this.requestRender()}getContext(){const e=this.getSelectionState(),t=this.getFilterState();return Ti(this.rows,this.columns,this.grid,e,t)}addPanel(e){this.config.customPanels||(this.config.customPanels=[]),this.config.customPanels.push(e),this.requestRender()}removePanel(e){this.config.customPanels&&(this.config.customPanels=this.config.customPanels.filter(t=>t.id!==e),this.requestRender())}addAggregationRow(e){this.config.aggregationRows||(this.config.aggregationRows=[]),this.config.aggregationRows.push(e),this.requestRender()}removeAggregationRow(e){this.config.aggregationRows&&(this.config.aggregationRows=this.config.aggregationRows.filter(t=>t.id!==e),this.requestRender())}}const Zo=xo;function Qo(r){const e=[];return!r.rowGroupFields?.length&&!r.columnGroupFields?.length&&e.push("At least one row or column group field is required"),r.valueFields?.length||e.push("At least one value field is required"),e}function ut(r,e){return[...r,e].join("|")}function Jo(r,e){const t=e.rowGroupFields??[],i=e.columnGroupFields??[],n=e.valueFields??[],o=es(r,i),s=Li(r,t,i,o,n,0,""),l=is(s,o,n),a=Object.values(l).reduce((c,d)=>c+d,0);return{rows:s,columnKeys:o,totals:l,grandTotal:a}}function es(r,e){if(e.length===0)return["value"];const t=new Set;for(const i of r){const n=e.map(o=>String(i[o]??"")).join("|");t.add(n)}return[...t].sort()}function ts(r,e){const t=new Map;for(const i of r){const n=String(i[e]??""),o=t.get(n);o?o.push(i):t.set(n,[i])}return t}function Li(r,e,t,i,n,o,s){const l=[];if(e.length===0){const h=Pi(r,t,i,n),f=Hi(h);return l.push({rowKey:s||"all",rowLabel:s||"All",depth:o,values:h,total:f,isGroup:!1,rowCount:r.length}),l}const a=e[0],c=e.slice(1),d=c.length>0,u=ts(r,a);for(const[h,f]of u){const p=s?`${s}|${h}`:h,g=Pi(f,t,i,n),w=Hi(g);let y;d&&(y=Li(f,c,t,i,n,o+1,p)),l.push({rowKey:p,rowLabel:h||"(blank)",depth:o,values:g,total:w,isGroup:d,children:y,rowCount:f.length})}return l}function Pi(r,e,t,i){const n={};for(const o of t)for(const s of i){const a=(e.length>0?r.filter(h=>e.map(f=>String(h[f]??"")).join("|")===o):r).map(h=>Number(h[s.field])||0),c=Zo(s.aggFunc),d=a.length>0?c(a):null,u=ut([o],s.field);n[u]=d}return n}function Hi(r){let e=0;for(const t of Object.values(r))e+=t??0;return e}function is(r,e,t){const i={};function n(o){for(const s of o)if(!s.isGroup||!s.children?.length)for(const l of e)for(const a of t){const c=ut([l],a.field);i[c]=(i[c]??0)+(s.values[c]??0)}else s.children&&n(s.children)}return n(r),i}function ns(r,e,t=!0){const i=[];function n(o){i.push(o);const s=e?e.has(o.rowKey):t;if(o.children&&s)for(const l of o.children)n(l)}for(const o of r)n(o);return i}function rs(r){const e=[];function t(i){if(i.isGroup&&e.push(i.rowKey),i.children)for(const n of i.children)t(n)}for(const i of r)t(i);return e}const os=["sum","avg","count","min","max","first","last"];function ss(r,e,t,i){const n=new AbortController,o={config:e,callbacks:i,signal:n.signal},s=document.createElement("div");return s.className="tbw-pivot-panel",s.appendChild(pe("Options",()=>us(t,o))),s.appendChild(pe("Row Groups",()=>Di("rowGroups",o))),s.appendChild(pe("Column Groups",()=>Di("columnGroups",o))),s.appendChild(pe("Values",()=>as(o))),s.appendChild(pe("Available Fields",()=>ds(o))),r.appendChild(s),()=>{n.abort(),s.remove()}}function pe(r,e){const t=document.createElement("div");t.className="tbw-pivot-section";const i=document.createElement("div");i.className="tbw-pivot-section-header",i.textContent=r;const n=document.createElement("div");return n.className="tbw-pivot-section-content",n.appendChild(e()),t.appendChild(i),t.appendChild(n),t}function Di(r,e){const{config:t,callbacks:i,signal:n}=e,o=document.createElement("div");o.className="tbw-pivot-drop-zone",o.setAttribute("data-zone",r);const s=r==="rowGroups"?t.rowGroupFields??[]:t.columnGroupFields??[];if(s.length===0){const l=document.createElement("div");l.className="tbw-pivot-placeholder",l.textContent="Drag fields here or click to add",o.appendChild(l)}else for(const l of s)o.appendChild(ls(l,r,e));return o.addEventListener("dragover",l=>{l.preventDefault(),o.classList.add("drag-over")},{signal:n}),o.addEventListener("dragleave",()=>{o.classList.remove("drag-over")},{signal:n}),o.addEventListener("drop",l=>{l.preventDefault(),o.classList.remove("drag-over");const a=l.dataTransfer?.getData("text/plain");a&&i.onAddFieldToZone(a,r)},{signal:n}),o}function ls(r,e,t){const{callbacks:i,signal:n}=t,o=document.createElement("div");o.className="tbw-pivot-field-chip",o.draggable=!0;const s=i.getAvailableFields().find(c=>c.field===r),l=document.createElement("span");l.className="tbw-pivot-chip-label",l.textContent=s?.header??r;const a=document.createElement("button");return a.className="tbw-pivot-chip-remove",a.innerHTML="×",a.title="Remove field",a.addEventListener("click",c=>{c.stopPropagation(),i.onRemoveFieldFromZone(r,e)},{signal:n}),o.appendChild(l),o.appendChild(a),o.addEventListener("dragstart",c=>{c.dataTransfer?.setData("text/plain",r),c.dataTransfer?.setData("source-zone",e),o.classList.add("dragging")},{signal:n}),o.addEventListener("dragend",()=>{o.classList.remove("dragging")},{signal:n}),o}function as(r){const{config:e,callbacks:t,signal:i}=r,n=document.createElement("div");n.className="tbw-pivot-drop-zone tbw-pivot-values-zone",n.setAttribute("data-zone","values");const o=e.valueFields??[];if(o.length===0){const s=document.createElement("div");s.className="tbw-pivot-placeholder",s.textContent="Drag numeric fields here for aggregation",n.appendChild(s)}else for(const s of o)n.appendChild(cs(s,r));return n.addEventListener("dragover",s=>{s.preventDefault(),n.classList.add("drag-over")},{signal:i}),n.addEventListener("dragleave",()=>{n.classList.remove("drag-over")},{signal:i}),n.addEventListener("drop",s=>{s.preventDefault(),n.classList.remove("drag-over");const l=s.dataTransfer?.getData("text/plain");l&&t.onAddValueField(l,"sum")},{signal:i}),n}function cs(r,e){const{callbacks:t,signal:i}=e,n=document.createElement("div");n.className="tbw-pivot-field-chip tbw-pivot-value-chip";const o=t.getAvailableFields().find(d=>d.field===r.field),s=document.createElement("div");s.className="tbw-pivot-value-label-wrapper";const l=document.createElement("span");l.className="tbw-pivot-chip-label",l.textContent=o?.header??r.field;const a=document.createElement("select");a.className="tbw-pivot-agg-select",a.title="Aggregation function";for(const d of os){const u=document.createElement("option");u.value=d,u.textContent=d.toUpperCase(),u.selected=d===r.aggFunc,a.appendChild(u)}a.addEventListener("change",()=>{t.onUpdateValueAggFunc(r.field,a.value)},{signal:i});const c=document.createElement("button");return c.className="tbw-pivot-chip-remove",c.innerHTML="×",c.title="Remove value field",c.addEventListener("click",d=>{d.stopPropagation(),t.onRemoveValueField(r.field)},{signal:i}),s.appendChild(l),s.appendChild(a),n.appendChild(s),n.appendChild(c),n}function ds(r){const{config:e,callbacks:t,signal:i}=r,n=document.createElement("div");n.className="tbw-pivot-available-fields";const o=t.getAvailableFields(),s=new Set([...e.rowGroupFields??[],...e.columnGroupFields??[],...e.valueFields?.map(a=>a.field)??[]]),l=o.filter(a=>!s.has(a.field));if(l.length===0){const a=document.createElement("div");a.className="tbw-pivot-placeholder",a.textContent="All fields are in use",n.appendChild(a)}else for(const a of l){const c=document.createElement("div");c.className="tbw-pivot-field-chip available",c.textContent=a.header,c.draggable=!0,c.title=`Drag to add "${a.field}" to a zone`,c.addEventListener("dragstart",d=>{d.dataTransfer?.setData("text/plain",a.field),c.classList.add("dragging")},{signal:i}),c.addEventListener("dragend",()=>{c.classList.remove("dragging")},{signal:i}),n.appendChild(c)}return n}function us(r,e){const{config:t,callbacks:i,signal:n}=e,o=document.createElement("div");return o.className="tbw-pivot-options",o.appendChild(ht("Enable Pivot View",r,s=>{i.onTogglePivot(s)},n)),o.appendChild(ht("Show Row Totals",t.showTotals??!0,s=>{i.onOptionChange("showTotals",s)},n)),o.appendChild(ht("Show Grand Total",t.showGrandTotal??!0,s=>{i.onOptionChange("showGrandTotal",s)},n)),o}function ht(r,e,t,i){const n=document.createElement("label");n.className="tbw-pivot-checkbox";const o=document.createElement("input");o.type="checkbox",o.checked=e,o.addEventListener("change",()=>t(o.checked),{signal:i});const s=document.createElement("span");return s.textContent=r,n.appendChild(o),n.appendChild(s),n}function hs(r,e,t){return e.className="data-grid-row pivot-group-row",e.setAttribute("data-pivot-depth",String(r.__pivotDepth??0)),e.setAttribute("data-pivot-key",String(r.__pivotRowKey??"")),e.setAttribute("role","row"),e.innerHTML="",t.columns.forEach((i,n)=>{const o=document.createElement("div");if(o.className="cell",o.setAttribute("data-col",String(n)),o.setAttribute("data-row",String(t.rowIndex)),o.setAttribute("role","gridcell"),n===0){const s=Number(r.__pivotIndent)||0;o.style.paddingLeft=`${s}px`;const l=String(r.__pivotRowKey),a=document.createElement("button");a.type="button",a.className="pivot-toggle",a.setAttribute("aria-label",r.__pivotExpanded?"Collapse group":"Expand group"),t.setIcon(a,t.resolveIcon(r.__pivotExpanded?"collapse":"expand")),a.addEventListener("click",u=>{u.stopPropagation(),t.onToggle(l)}),o.appendChild(a);const c=document.createElement("span");c.className="pivot-label",c.textContent=String(r.__pivotLabel??""),o.appendChild(c);const d=document.createElement("span");d.className="pivot-count",d.textContent=` (${Number(r.__pivotRowCount)||0})`,o.appendChild(d)}else{const s=r[i.field];o.textContent=s!=null?String(s):""}e.appendChild(o)}),!0}function fs(r,e,t,i){return e.className="data-grid-row pivot-leaf-row",e.setAttribute("data-pivot-depth",String(r.__pivotDepth??0)),e.setAttribute("data-pivot-key",String(r.__pivotRowKey??"")),e.innerHTML="",t.forEach((n,o)=>{const s=document.createElement("div");if(s.className="cell",s.setAttribute("data-col",String(o)),s.setAttribute("data-row",String(i)),s.setAttribute("role","gridcell"),o===0){const l=Number(r.__pivotIndent)||0;s.style.paddingLeft=`${l+20}px`;const a=document.createElement("span");a.className="pivot-label",a.textContent=String(r.__pivotLabel??""),s.appendChild(a)}else{const l=r[n.field];s.textContent=l!=null?String(l):""}e.appendChild(s)}),!0}function gs(r,e,t){return e.className="pivot-grand-total-row",e.setAttribute("role","presentation"),e.innerHTML="",t.forEach((i,n)=>{const o=document.createElement("div");if(o.className="cell",o.setAttribute("data-col",String(n)),n===0){const s=document.createElement("span");s.className="pivot-label",s.textContent="Grand Total",o.appendChild(s)}else{const s=r[i.field];o.textContent=s!=null?String(s):""}e.appendChild(o)}),!0}const ps='@layer tbw-plugins{.pivot-group-row{display:grid;grid-template-columns:var(--tbw-column-template);font-weight:600;background:var(--tbw-pivot-group-bg, var(--tbw-color-row-alt));min-height:var(--tbw-row-height);border-bottom:var(--tbw-row-divider)}.pivot-group-row:hover{background:var(--tbw-pivot-group-hover, var(--tbw-color-row-hover))}.pivot-leaf-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-pivot-leaf-bg, var(--tbw-color-bg));min-height:var(--tbw-row-height);border-bottom:var(--tbw-row-divider)}.pivot-grand-total-row{display:grid;grid-template-columns:var(--tbw-column-template);font-weight:700;background:var(--tbw-pivot-grand-total-bg, var(--tbw-color-header-bg));min-height:var(--tbw-row-height);border-top:2px solid var(--tbw-color-border-strong)}.pivot-grand-total-row>.cell{display:flex;align-items:center;padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}.pivot-grand-total-row>.cell:last-child{border-right:0}.pivot-grand-total-footer{position:sticky;bottom:0;z-index:var(--tbw-z-layer-pinned-rows, 20);background:var(--tbw-pivot-grand-total-bg, var(--tbw-color-header-bg));min-width:fit-content}.pivot-group-row>.cell,.pivot-leaf-row>.cell{display:flex;align-items:center;padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}.pivot-group-row>.cell:last-child,.pivot-leaf-row>.cell:last-child{border-right:0}.pivot-toggle{display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-pivot-toggle-size, var(--tbw-toggle-size, 1.25em));height:var(--tbw-pivot-toggle-size, var(--tbw-toggle-size, 1.25em));margin-right:var(--tbw-spacing-sm, .375em);border:none;background:transparent;cursor:pointer;color:var(--tbw-pivot-toggle-color, var(--tbw-color-fg-muted));border-radius:var(--tbw-border-radius);transition:background var(--tbw-transition-duration, .12s) var(--tbw-transition-ease, ease),color var(--tbw-transition-duration, .12s) var(--tbw-transition-ease, ease)}.pivot-toggle:hover{background:var(--tbw-pivot-toggle-hover-bg, var(--tbw-color-row-hover));color:var(--tbw-pivot-toggle-hover-color, var(--tbw-color-fg))}.pivot-toggle:focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}.pivot-label{font-weight:inherit}.pivot-count{color:var(--tbw-pivot-count-color, var(--tbw-color-fg-muted));font-size:.9em;font-weight:400}.pivot-total-row{font-weight:700;border-top:2px solid var(--tbw-pivot-border, var(--tbw-color-border-strong))}[data-pivot-depth="1"]{--tbw-pivot-depth: 1}[data-pivot-depth="2"]{--tbw-pivot-depth: 2}[data-pivot-depth="3"]{--tbw-pivot-depth: 3}[data-pivot-depth="4"]{--tbw-pivot-depth: 4}.tbw-pivot-panel{display:flex;flex-direction:column;gap:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));padding:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));height:100%;overflow-y:auto;font-size:var(--tbw-font-size-sm, .8125rem)}.tbw-pivot-section{border:1px solid var(--tbw-pivot-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);background:var(--tbw-pivot-section-bg, var(--tbw-color-bg))}.tbw-pivot-section-header{padding:var(--tbw-button-padding, var(--tbw-spacing-md, .5rem) var(--tbw-spacing-lg, .75rem));font-weight:600;background:var(--tbw-pivot-header-bg, var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-pivot-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius) var(--tbw-border-radius) 0 0}.tbw-pivot-section-content{padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-pivot-toggle-wrapper{display:flex;align-items:center}.tbw-pivot-toggle-label{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));cursor:pointer}.tbw-pivot-toggle-label input{width:var(--tbw-icon-size, 1rem);height:var(--tbw-icon-size, 1rem);cursor:pointer}.tbw-pivot-drop-zone{min-height:60px;padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border:2px dashed var(--tbw-pivot-drop-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);background:var(--tbw-pivot-drop-bg, var(--tbw-color-row-alt));display:flex;flex-wrap:wrap;gap:var(--tbw-spacing-sm, .375rem);align-content:flex-start;transition:all .15s ease}.tbw-pivot-drop-zone.drag-over{border-color:var(--tbw-color-accent);background:var(--tbw-pivot-drop-active, var(--tbw-focus-background))}.tbw-pivot-placeholder{color:var(--tbw-color-fg-muted);font-style:italic;padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));text-align:center;width:100%}.tbw-pivot-field-chip{display:inline-flex;align-items:center;gap:var(--tbw-spacing-sm, .375rem);padding:var(--tbw-button-padding-sm, var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-md, .5rem));background:var(--tbw-pivot-chip-bg, var(--tbw-color-header-bg));border:1px solid var(--tbw-pivot-chip-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);cursor:grab;font-size:var(--tbw-font-size-xs, .75rem);transition:all .15s ease}.tbw-pivot-field-chip:hover{background:var(--tbw-pivot-chip-hover, var(--tbw-color-row-hover));border-color:var(--tbw-color-accent)}.tbw-pivot-field-chip.available{background:var(--tbw-color-bg)}.tbw-pivot-field-chip.dragging{opacity:.5;cursor:grabbing}.tbw-pivot-chip-label{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:120px}.tbw-pivot-chip-remove{display:flex;align-items:center;justify-content:center;width:var(--tbw-icon-size, 1rem);height:var(--tbw-icon-size, 1rem);padding:0;border:none;background:transparent;color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-sm, .875rem);font-weight:700;cursor:pointer;border-radius:50%;transition:all .15s ease}.tbw-pivot-chip-remove:hover{background:var(--tbw-pivot-chip-remove-hover-bg, var(--tbw-color-accent));color:var(--tbw-pivot-chip-remove-hover-fg, var(--tbw-color-accent-fg))}.tbw-pivot-value-chip{padding:var(--tbw-button-padding-sm, var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-md, .5rem))}.tbw-pivot-value-label-wrapper{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));flex:1;min-width:0}.tbw-pivot-agg-select{padding:var(--tbw-spacing-xs, .125rem) var(--tbw-spacing-xs, .25rem);font-size:var(--tbw-font-size-xs, .6875rem);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);background:var(--tbw-color-bg);cursor:pointer}.tbw-pivot-available-fields{display:flex;flex-wrap:wrap;gap:var(--tbw-spacing-sm, .375rem);min-height:40px}.tbw-pivot-options{display:flex;flex-direction:column;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-pivot-checkbox{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));cursor:pointer}.tbw-pivot-checkbox input{width:var(--tbw-icon-size-sm, .875rem);height:var(--tbw-icon-size-sm, .875rem);cursor:pointer}.pivot-group-row.tbw-pivot-slide-in,.pivot-leaf-row.tbw-pivot-slide-in{animation:tbw-pivot-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-pivot-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.pivot-group-row.tbw-pivot-fade-in,.pivot-leaf-row.tbw-pivot-fade-in{animation:tbw-pivot-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-pivot-fade-in{0%{opacity:0}to{opacity:1}}}';class X extends D{name="pivot";styles=ps;static PANEL_ID="pivot";get defaultConfig(){return{active:!0,showTotals:!0,showGrandTotal:!0,showToolPanel:!0,animation:"slide"}}isActive=!1;hasInitialized=!1;pivotResult=null;fieldHeaderMap=new Map;expandedKeys=new Set;defaultExpanded=!0;userHasToggledExpand=!1;originalColumns=[];panelContainer=null;grandTotalFooter=null;previousVisibleKeys=new Set;keysToAnimate=new Set;hasValidPivotConfig(){return(this.config.valueFields?.length??0)>0}get animationStyle(){return this.isAnimationEnabled?this.config.animation??"slide":!1}detach(){this.isActive=!1,this.hasInitialized=!1,this.pivotResult=null,this.fieldHeaderMap.clear(),this.originalColumns=[],this.panelContainer=null,this.cleanupGrandTotalFooter(),this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.userHasToggledExpand=!1}getToolPanel(){if((this.config?.showToolPanel??this.userConfig?.showToolPanel??!0)!==!1)return{id:X.PANEL_ID,title:"Pivot",icon:"⊞",tooltip:"Configure pivot table",order:90,render:t=>this.renderPanel(t)}}processRows(e){if(!this.hasInitialized&&this.config.active!==!1&&this.hasValidPivotConfig()&&(this.hasInitialized=!0,this.isActive=!0),!this.isActive)return[...e];const t=Qo(this.config);if(t.length>0)return this.warn(`Config errors: ${t.join(", ")}`),[...e];this.buildFieldHeaderMap(),this.defaultExpanded=this.config.defaultExpanded??!0,this.pivotResult=Jo(e,this.config),this.expandedKeys.size===0&&this.defaultExpanded&&!this.userHasToggledExpand&&this.expandAllKeys();const i=this.config.indentWidth??20,n=ns(this.pivotResult.rows,this.expandedKeys,this.defaultExpanded).map(s=>({__pivotRowKey:s.rowKey,__pivotLabel:s.rowLabel,__pivotDepth:s.depth,__pivotIsGroup:s.isGroup,__pivotHasChildren:!!s.children?.length,__pivotExpanded:this.expandedKeys.has(s.rowKey),__pivotRowCount:s.rowCount??0,__pivotIndent:s.depth*i,__pivotTotal:s.total,...s.values}));this.keysToAnimate.clear();const o=new Set;for(const s of n){const l=s.__pivotRowKey;o.add(l),!this.previousVisibleKeys.has(l)&&s.__pivotDepth>0&&this.keysToAnimate.add(l)}return this.previousVisibleKeys=o,n}processColumns(e){if(!this.isActive||!this.pivotResult)return[...e];const t=[],i=(this.config.rowGroupFields??[]).map(n=>this.fieldHeaderMap.get(n)??n).join(" / ");t.push({field:"__pivotLabel",header:i||"Group",width:200});for(const n of this.pivotResult.columnKeys)for(const o of this.config.valueFields??[]){const s=ut([n],o.field),l=o.header||this.fieldHeaderMap.get(o.field)||o.field;t.push({field:s,header:`${n} - ${l} (${o.aggFunc})`,width:120,type:"number"})}return this.config.showTotals&&t.push({field:"__pivotTotal",header:"Total",width:100,type:"number"}),t}renderRow(e,t,i){const n=e;return n.__pivotRowKey&&n.__pivotHasChildren?hs(n,t,{columns:this.gridColumns,rowIndex:i,onToggle:o=>this.toggle(o),resolveIcon:o=>this.resolveIcon(o),setIcon:(o,s)=>this.setIcon(o,s)}):n.__pivotRowKey!==void 0&&this.isActive?fs(n,t,this.gridColumns,i):(this.cleanupPivotStyling(t),!1)}cleanupPivotStyling(e){(e.classList.contains("pivot-group-row")||e.classList.contains("pivot-leaf-row")||e.classList.contains("pivot-grand-total-row"))&&(e.classList.remove("pivot-group-row","pivot-leaf-row","pivot-grand-total-row"),e.classList.add("data-grid-row"),e.removeAttribute("data-pivot-depth"),e.innerHTML="")}onKeyDown(e){if(e.key!==" "||!this.isActive)return;const t=this.grid._focusRow,i=this.rows[t];if(!(!i?.__pivotIsGroup||!i.__pivotHasChildren))return e.preventDefault(),this.toggle(i.__pivotRowKey),this.requestRenderWithFocus(),!0}afterRender(){this.isActive&&this.config.showGrandTotal&&this.pivotResult?this.renderGrandTotalFooter():this.cleanupGrandTotalFooter();const e=this.animationStyle;if(e===!1||this.keysToAnimate.size===0)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const i=e==="fade"?"tbw-pivot-fade-in":"tbw-pivot-slide-in";for(const n of t.querySelectorAll(".pivot-group-row, .pivot-leaf-row")){const o=n.dataset.pivotKey;o&&this.keysToAnimate.has(o)&&(n.classList.add(i),n.addEventListener("animationend",()=>n.classList.remove(i),{once:!0}))}this.keysToAnimate.clear()}renderGrandTotalFooter(){if(!this.pivotResult)return;const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-scroll-area")??e.querySelector(".tbw-grid-content")??e.children[0];if(!t)return;this.grandTotalFooter||(this.grandTotalFooter=document.createElement("div"),this.grandTotalFooter.className="pivot-grand-total-footer",t.appendChild(this.grandTotalFooter));const i={__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals};gs(i,this.grandTotalFooter,this.gridColumns)}cleanupGrandTotalFooter(){this.grandTotalFooter&&(this.grandTotalFooter.remove(),this.grandTotalFooter=null)}toggle(e){this.userHasToggledExpand=!0,this.expandedKeys.has(e)?this.expandedKeys.delete(e):this.expandedKeys.add(e),this.requestRender()}expand(e){this.userHasToggledExpand=!0,this.expandedKeys.add(e),this.requestRender()}collapse(e){this.userHasToggledExpand=!0,this.expandedKeys.delete(e),this.requestRender()}expandAll(){this.userHasToggledExpand=!0,this.expandAllKeys(),this.requestRender()}collapseAll(){this.userHasToggledExpand=!0,this.expandedKeys.clear(),this.requestRender()}expandAllKeys(){if(!this.pivotResult)return;const e=rs(this.pivotResult.rows);for(const t of e)this.expandedKeys.add(t)}isExpanded(e){return this.expandedKeys.has(e)}enablePivot(){this.originalColumns.length===0&&this.captureOriginalColumns(),this.isActive=!0,this.requestRender()}disablePivot(){this.isActive=!1,this.pivotResult=null,this.requestRender()}isPivotActive(){return this.isActive}getPivotResult(){return this.pivotResult}setRowGroupFields(e){this.config.rowGroupFields=e,this.requestRender()}setColumnGroupFields(e){this.config.columnGroupFields=e,this.requestRender()}setValueFields(e){this.config.valueFields=e,this.requestRender()}refresh(){this.pivotResult=null,this.requestRender()}showPanel(){this.grid.openToolPanel(),this.grid.expandedToolPanelSections.includes(X.PANEL_ID)||this.grid.toggleToolPanelSection(X.PANEL_ID)}hidePanel(){this.grid.closeToolPanel()}togglePanel(){this.grid.isToolPanelOpen||this.grid.openToolPanel(),this.grid.toggleToolPanelSection(X.PANEL_ID)}isPanelVisible(){return this.grid.isToolPanelOpen&&this.grid.expandedToolPanelSections.includes(X.PANEL_ID)}get gridColumns(){return this.grid.columns??[]}refreshIfActive(){this.isActive&&this.refresh(),this.refreshPanel()}buildFieldHeaderMap(){const e=this.getAvailableFields();this.fieldHeaderMap.clear();for(const t of e)this.fieldHeaderMap.set(t.field,t.header)}getAvailableFields(){return this.originalColumns.length>0?this.originalColumns:this.captureOriginalColumns()}captureOriginalColumns(){try{const e=this.grid.getAllColumns?.()??this.grid.columns??[];return this.originalColumns=e.filter(t=>!t.field.startsWith("__pivot")).map(t=>({field:t.field,header:t.header??t.field})),this.originalColumns}catch{return[]}}renderPanel(e){this.panelContainer=e,this.originalColumns.length===0&&this.captureOriginalColumns();const t={onTogglePivot:i=>{i?this.enablePivot():this.disablePivot(),this.refreshPanel()},onAddFieldToZone:(i,n)=>this.addFieldToZone(i,n),onRemoveFieldFromZone:(i,n)=>this.removeFieldFromZone(i,n),onAddValueField:(i,n)=>this.addValueField(i,n),onRemoveValueField:i=>this.removeValueField(i),onUpdateValueAggFunc:(i,n)=>this.updateValueAggFunc(i,n),onOptionChange:(i,n)=>{this.config[i]=n,this.isActive&&this.refresh()},getAvailableFields:()=>this.getAvailableFields()};return ss(e,this.config,this.isActive,t)}refreshPanel(){this.panelContainer&&(this.panelContainer.innerHTML="",this.renderPanel(this.panelContainer))}addFieldToZone(e,t){if(t==="rowGroups"){const i=this.config.rowGroupFields??[];i.includes(e)||(this.config.rowGroupFields=[...i,e])}else{const i=this.config.columnGroupFields??[];i.includes(e)||(this.config.columnGroupFields=[...i,e])}this.removeFromOtherZones(e,t),this.refreshIfActive()}removeFieldFromZone(e,t){t==="rowGroups"?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(i=>i!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(i=>i!==e),this.refreshIfActive()}removeFromOtherZones(e,t){t!=="rowGroups"&&(this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(i=>i!==e)),t!=="columnGroups"&&(this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(i=>i!==e)),t!=="values"&&(this.config.valueFields=(this.config.valueFields??[]).filter(i=>i.field!==e))}addValueField(e,t){const i=this.config.valueFields??[];i.some(n=>n.field===e)||(this.config.valueFields=[...i,{field:e,aggFunc:t}]),this.removeFromOtherZones(e,"values"),this.refreshIfActive()}removeValueField(e){this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e),this.refreshIfActive()}updateValueAggFunc(e,t){const i=this.config.valueFields??[],n=i.findIndex(o=>o.field===e);n>=0&&(i[n]={...i[n],aggFunc:t},this.config.valueFields=[...i]),this.isActive&&this.refresh()}}const Pe="tbw-print-isolation-style";function ws(r,e){const t=document.createElement("style");return t.id=Pe,t.textContent=`
|
|
111
111
|
/* Print isolation: hide everything except the target grid */
|
|
112
112
|
@media print {
|
|
113
113
|
/* Hide all body children by default */
|
|
@@ -177,11 +177,11 @@ ${q(i.name)}Plugin and ${q(s.name)}Plugin are both loaded, but they are currentl
|
|
|
177
177
|
/* When this stylesheet is active, we're about to print */
|
|
178
178
|
/* No screen-specific rules needed - isolation only applies to print */
|
|
179
179
|
}
|
|
180
|
-
`,t}async function
|
|
180
|
+
`,t}async function Mi(r,e={}){const{orientation:t="landscape"}=e,i=r.id;document.querySelectorAll(`#${CSS.escape(i)}`).length>1&&console.warn(`[tbw-grid:print] Multiple elements found with id="${i}". Print isolation may not work correctly. Ensure each grid has a unique ID.`),document.getElementById(Pe)?.remove();const o=ws(i,t);return document.head.appendChild(o),new Promise(s=>{const l=()=>{window.removeEventListener("afterprint",l),document.getElementById(Pe)?.remove(),s()};window.addEventListener("afterprint",l),window.print(),setTimeout(()=>{window.removeEventListener("afterprint",l),document.getElementById(Pe)?.remove(),s()},5e3)})}const bs=".tbw-print-header,.tbw-print-footer{display:none}@media print{tbw-grid{overflow:visible!important;height:auto!important;border:none!important;border-radius:0!important;color-scheme:light only;-webkit-print-color-adjust:exact;print-color-adjust:exact}tbw-grid .tbw-grid-content{overflow:visible!important;height:auto!important;max-height:none!important}tbw-grid .tbw-scroll-area{overflow:visible!important;height:auto!important;max-height:none!important}tbw-grid .rows-body{overflow:visible!important;height:auto!important;max-height:none!important}tbw-grid .rows-container,tbw-grid .rows-viewport,tbw-grid .rows{overflow:visible!important;height:auto!important;max-height:none!important;transform:none!important}tbw-grid .rows-viewport .rows{position:static!important}tbw-grid .resize-handle,tbw-grid [part=sort-indicator],tbw-grid .tbw-filter-btn,tbw-grid .tool-panel,tbw-grid .tool-panel-content,tbw-grid .tbw-shell-header,tbw-grid .shell-toolbar,tbw-grid .tool-panel-toggle,tbw-grid [data-print-hide],tbw-grid .expander-cell,tbw-grid .tree-toggle,tbw-grid .context-menu,tbw-grid .faux-vscroll{display:none!important}tbw-grid .tbw-print-header{display:flex;justify-content:space-between;align-items:baseline;padding:var(--tbw-spacing-md, .5em) 0;margin-bottom:var(--tbw-spacing-md, .5em);border-bottom:2px solid var(--tbw-print-border, var(--tbw-color-border-strong));font-family:inherit}.tbw-print-header-title{font-size:1.25em;font-weight:700}.tbw-print-header-timestamp{font-size:var(--tbw-font-size-sm, .875em);color:var(--tbw-print-muted, var(--tbw-color-fg-muted))}tbw-grid .tbw-print-footer{display:block;margin-top:var(--tbw-spacing-md, .5em);padding-top:var(--tbw-spacing-md, .5em);border-top:1px solid var(--tbw-print-border, var(--tbw-color-border));font-size:var(--tbw-font-size-xs, .75em);color:var(--tbw-print-muted, var(--tbw-color-fg-muted));text-align:end}tbw-grid .data-grid-row{break-inside:avoid;page-break-inside:avoid}tbw-grid .cell{border:1px solid var(--tbw-print-cell-border, var(--tbw-color-border))!important}tbw-grid .header-row,tbw-grid .data-grid-row{padding-inline-end:1px}tbw-grid .data-grid-row:hover,tbw-grid .cell:hover{background:inherit!important}@page{margin:1cm}@page{tbw-grid.print-landscape{size:landscape}}@page{tbw-grid.print-portrait{size:portrait}}}",ms={button:!1,orientation:"landscape",warnThreshold:500,maxRows:0,includeTitle:!0,includeTimestamp:!0,title:"",isolate:!1};class vs extends D{name="print";version="1.0.0";styles=bs;#t=!1;#e=null;#u=null;#c=null;#n=null;#l=null;#i=null;get#h(){return this.grid}isPrinting(){return this.#t}async print(e){if(this.#t){console.warn("[PrintPlugin] Print already in progress");return}const t=this.gridElement;if(!t){console.warn("[PrintPlugin] Grid not available");return}const i={...ms,...this.config,...e},o=this.rows.length;let s=o,l=!1;if(i.warnThreshold>0&&o>i.warnThreshold){const c=i.maxRows>0?`
|
|
181
181
|
|
|
182
182
|
Note: Output will be limited to ${i.maxRows.toLocaleString()} rows.`:"";if(!confirm(`This grid has ${o.toLocaleString()} rows. Printing large datasets may cause performance issues or browser slowdowns.${c}
|
|
183
183
|
|
|
184
|
-
Click OK to continue, or Cancel to abort.`))return}i.maxRows>0&&o>i.maxRows&&(s=i.maxRows,l=!0),this.#t=!0;const a=performance.now();this.emit("print-start",{rowCount:s,limitApplied:l,originalRowCount:o});try{const c=this.#f;this.#u={bypassThreshold:c._virtualization?.bypassThreshold??24},this.#d(),l&&(this.#c=this.sourceRows,this.grid.rows=this.sourceRows.slice(0,s),await new Promise(d=>setTimeout(d,50))),(i.includeTitle||i.includeTimestamp)&&this.#h(i),await this.#w(),await new Promise(d=>requestAnimationFrame(d)),await new Promise(d=>requestAnimationFrame(d)),t.classList.add(`print-${i.orientation}`),await new Promise(d=>requestAnimationFrame(d)),await new Promise(d=>requestAnimationFrame(d)),i.isolate?await this.#v(i):await this.#a(),this.emit("print-complete",{success:!0,rowCount:s,duration:Math.round(performance.now()-a)})}catch(c){console.error("[PrintPlugin] Print failed:",c),this.emit("print-complete",{success:!1,rowCount:0,duration:Math.round(performance.now()-a)})}finally{this.#R(),this.#t=!1}}#h(e){const t=this.gridElement;if(t){if(this.#i=document.createElement("div"),this.#i.className="tbw-print-header",e.includeTitle){const i=e.title||this.grid.effectiveConfig?.shell?.header?.title||"Grid Data",n=document.createElement("div");n.className="tbw-print-header-title",n.textContent=i,this.#i.appendChild(n)}if(e.includeTimestamp){const i=document.createElement("div");i.className="tbw-print-header-timestamp",i.textContent=`Printed: ${new Date().toLocaleString()}`,this.#i.appendChild(i)}t.insertBefore(this.#i,t.firstChild),this.#l=document.createElement("div"),this.#l.className="tbw-print-footer",this.#l.textContent=`Page generated from ${window.location.hostname}`,t.appendChild(this.#l)}}async#w(){const e=this.#f;if(!e._virtualization)return;const t=this.rows.length;e._virtualization.bypassThreshold=t+100,e.refreshVirtualWindow(!0),await new Promise(i=>setTimeout(i,100))}async#a(){return new Promise(e=>{const t=()=>{window.removeEventListener("afterprint",t),e()};window.addEventListener("afterprint",t),window.print(),setTimeout(()=>{typeof window<"u"&&window.removeEventListener("afterprint",t),e()},1e3)})}async#v(e){const t=this.gridElement;t&&await Hi(t,{orientation:e.orientation})}#d(){const e=this.columns;if(e){this.#e=new Map;for(const t of e)t.printHidden&&t.field&&(this.#e.set(t.field,!t.hidden),this.grid.setColumnVisible(t.field,!1))}}#g(){if(this.#e){for(const[e,t]of this.#e)this.grid.setColumnVisible(e,t);this.#e=null}}#R(){const e=this.gridElement;if(!e)return;this.#g(),e.classList.remove("print-portrait","print-landscape"),this.#n!==null&&(e.style.transform="",e.style.transformOrigin="",e.style.width="",this.#n=null),this.#i&&(this.#i.remove(),this.#i=null),this.#l&&(this.#l.remove(),this.#l=null);const t=this.#f;this.#u&&t._virtualization&&(t._virtualization.bypassThreshold=this.#u.bypassThreshold,t.refreshVirtualWindow(!0),this.#u=null),this.#c!==null&&(this.grid.rows=this.#c,this.#c=null)}afterRender(){this.config?.button&&!this.#p&&(this.#x(),this.#p=!0)}#p=!1;#x(){this.#f.registerToolbarContent?.({id:"print-button",order:900,render:t=>{const i=document.createElement("button");i.className="tbw-toolbar-btn tbw-print-btn",i.title="Print grid",i.type="button";const n=this.resolveIcon("print")||"🖨️";this.setIcon(i,n),i.addEventListener("click",()=>{this.print()},{signal:this.disconnectSignal}),t.appendChild(i)}})}}function fs(r){const e=r.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}function Di(r,e,t){if(e===t||e<0||e>=r.length||t<0||t>r.length)return r;const i=[...r],[n]=i.splice(e,1);return i.splice(t,0,n),i}const gs='@layer tbw-plugins{.header-row>.cell[draggable=true]{cursor:grab;position:relative}.header-row>.cell.dragging{opacity:.5;cursor:grabbing}.header-row>.cell.drop-before:before{content:"";position:absolute;left:0;top:0;bottom:0;width:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent));z-index:1}.header-row>.cell.drop-after:after{content:"";position:absolute;right:0;top:0;bottom:0;width:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent));z-index:1}.cell.flip-animating{transition:transform var(--tbw-animation-duration, .2s) ease-out;will-change:transform;z-index:1}@keyframes reorder-fade-in{0%{opacity:0}to{opacity:1}}.cell.fade-animating{animation:reorder-fade-in var(--tbw-animation-duration, .2s) ease-out backwards}}';class ps extends D{name="reorder";styles=gs;get defaultConfig(){return{animation:"flip"}}get animationType(){return this.isAnimationEnabled?this.config.animation!==void 0?this.config.animation:"flip":!1}get animationDuration(){return this.config.animationDuration!==void 0?this.config.animationDuration:super.animationDuration}isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;canMoveColumnWithPlugins(e){return!e||!fs(e)?!1:!this.grid.query("canMoveColumn",e).includes(!1)}clearDragClasses(){this.gridElement?.querySelectorAll(".header-row > .cell").forEach(e=>{e.classList.remove("dragging","drop-target","drop-before","drop-after")})}attach(e){super.attach(e),e.addEventListener("column-reorder-request",t=>{const i=t.detail;i?.field&&typeof i.toIndex=="number"&&this.moveColumn(i.field,i.toIndex)},{signal:this.disconnectSignal})}detach(){this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null}afterRender(){const e=this.gridElement;if(!e)return;e.querySelectorAll(".header-row > .cell").forEach(i=>{const n=i,o=n.getAttribute("data-field");if(!o)return;const s=this.columns.find(l=>l.field===o);if(!this.canMoveColumnWithPlugins(s)){n.draggable=!1;return}n.draggable=!0,!n.getAttribute("data-dragstart-bound")&&(n.setAttribute("data-dragstart-bound","true"),n.addEventListener("dragstart",l=>{const c=this.getColumnOrder().indexOf(o);this.isDragging=!0,this.draggedField=o,this.draggedIndex=c,l.dataTransfer&&(l.dataTransfer.effectAllowed="move",l.dataTransfer.setData("text/plain",o)),n.classList.add("dragging")}),n.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.clearDragClasses()}),n.addEventListener("dragover",l=>{if(l.preventDefault(),!this.isDragging||this.draggedField===o)return;const a=n.getBoundingClientRect(),c=a.left+a.width/2,u=this.getColumnOrder().indexOf(o);this.dropIndex=l.clientX<c?u:u+1,n.classList.add("drop-target"),n.classList.toggle("drop-before",l.clientX<c),n.classList.toggle("drop-after",l.clientX>=c)}),n.addEventListener("dragleave",()=>{n.classList.remove("drop-target","drop-before","drop-after")}),n.addEventListener("drop",l=>{l.preventDefault();const a=this.draggedField,c=this.draggedIndex,d=this.dropIndex;if(!this.isDragging||a===null||c===null||d===null)return;const u=d>c?d-1:d,h=this.getColumnOrder(),f=Di(h,c,u),p={field:a,fromIndex:c,toIndex:u,columnOrder:f};this.emitCancelable("column-move",p)||this.updateColumnOrder(f)}))})}onKeyDown(e){if(!e.altKey||e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;const t=this.grid,i=t._focusCol,n=t._visibleColumns;if(i<0||i>=n.length)return;const o=n[i];if(!this.canMoveColumnWithPlugins(o))return;const s=this.getColumnOrder(),l=s.indexOf(o.field);if(l===-1)return;const a=e.key==="ArrowLeft"?l-1:l+1;if(a<0||a>=s.length)return;const c=n.find(d=>d.field===s[a]);if(this.canMoveColumnWithPlugins(c))return this.moveColumn(o.field,a),t._focusCol=a,M(this.grid),e.preventDefault(),e.stopPropagation(),!0}getColumnOrder(){return this.grid.getColumnOrder()}moveColumn(e,t){const i=this.getColumnOrder(),n=i.indexOf(e);if(n===-1)return;const o=Di(i,n,t);this.emitCancelable("column-move",{field:e,fromIndex:n,toIndex:t,columnOrder:o})||this.updateColumnOrder(o)}setColumnOrder(e){this.updateColumnOrder(e)}resetColumnOrder(){const e=this.columns.map(t=>t.field);this.updateColumnOrder(e)}captureHeaderPositions(){const e=new Map;return this.gridElement?.querySelectorAll(".header-row > .cell[data-field]").forEach(t=>{const i=t.getAttribute("data-field");i&&e.set(i,t.getBoundingClientRect().left)}),e}animateFLIP(e){const t=this.gridElement;if(!t||e.size===0)return;const i=new Map;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(s=>{const l=s.getAttribute("data-field");if(!l)return;const a=e.get(l);if(a===void 0)return;const c=a-s.getBoundingClientRect().left;Math.abs(c)>1&&i.set(l,c)}),i.size===0)return;const n=[];if(t.querySelectorAll(".cell[data-field]").forEach(s=>{const l=i.get(s.getAttribute("data-field")??"");if(l!==void 0){const a=s;a.style.transform=`translateX(${l}px)`,n.push(a)}}),n.length===0)return;this.gridElement.offsetHeight;const o=this.animationDuration;requestAnimationFrame(()=>{n.forEach(s=>{s.classList.add("flip-animating"),s.style.transform=""}),setTimeout(()=>{n.forEach(s=>{s.style.transform="",s.classList.remove("flip-animating")})},o+50)})}animateFade(e){const t=this.gridElement;if(!t){e();return}const i=this.captureHeaderPositions();e();const n=new Set;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(l=>{const a=l.getAttribute("data-field");if(!a)return;const c=i.get(a);if(c===void 0)return;const d=l.getBoundingClientRect().left;Math.abs(c-d)>1&&n.add(a)}),n.size===0)return;const o=[];if(t.querySelectorAll(".cell[data-field]").forEach(l=>{const a=l.getAttribute("data-field");if(a&&n.has(a)){const c=l;c.classList.add("fade-animating"),o.push(c)}}),o.length===0)return;const s=this.animationDuration;setTimeout(()=>{o.forEach(l=>l.classList.remove("fade-animating"))},s+50)}updateColumnOrder(e){const t=this.animationType;if(t==="flip"&&this.gridElement){const i=this.captureHeaderPositions();this.grid.setColumnOrder(e),requestAnimationFrame(()=>{this.gridElement.offsetHeight,this.animateFLIP(i)})}else t==="fade"?this.animateFade(()=>this.grid.setColumnOrder(e)):this.grid.setColumnOrder(e);this.grid.requestStateChange?.()}}const ws='tbw-grid[data-responsive-animate] .data-grid-row,tbw-grid[data-responsive-animate] .data-grid-row>.cell{transition:opacity var(--tbw-responsive-duration, .2s) ease-out,transform var(--tbw-responsive-duration, .2s) ease-out}tbw-grid[data-responsive][data-responsive-animate] .data-grid-row{animation:responsive-card-enter var(--tbw-responsive-duration, .2s) ease-out}@keyframes responsive-card-enter{0%{opacity:0;transform:translateY(-10px)}to{opacity:1;transform:translateY(0)}}tbw-grid[data-responsive] .header{display:none!important}tbw-grid[data-responsive] .footer-row{display:none}tbw-grid[data-responsive] .tbw-scroll-area{overflow-x:hidden;min-width:0!important}tbw-grid[data-responsive] .rows-body-wrapper{min-width:0!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row){display:block!important;grid-template-columns:none!important;padding:var(--tbw-cell-padding);padding-inline-start:var(--tbw-spacing-xl);border-bottom:1px solid var(--tbw-color-border);min-height:auto!important;height:auto!important;contain:none!important;content-visibility:visible!important;background:var(--tbw-color-bg);position:relative}tbw-grid[data-responsive] .data-grid-row:not(.group-row):nth-child(2n){background:var(--tbw-color-row-alt)}tbw-grid[data-responsive] .data-grid-row:not(.group-row):hover{background:var(--tbw-color-row-hover)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)[aria-selected=true]{background:var(--tbw-color-selection)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)[aria-selected=true]:before{content:"";position:absolute;inset-inline-start:0;top:0;bottom:0;width:4px;background:var(--tbw-color-accent)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell{display:flex!important;justify-content:space-between;align-items:center;padding:var(--tbw-spacing-xs) var(--tbw-spacing-md);width:100%!important;min-width:0!important;min-height:auto!important;height:auto!important;line-height:1.5!important;position:static!important;left:auto!important;right:auto!important;border:none!important;border-bottom:none!important;border-inline-end:none!important;background:transparent!important;white-space:normal!important;overflow:visible!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell:before{content:attr(data-header) ": ";font-weight:600;color:var(--tbw-color-header-fg);flex-shrink:0;margin-inline-end:var(--tbw-spacing-md);min-width:100px}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell:after{content:none}tbw-grid[data-responsive] .cell[data-utility]{display:none!important}tbw-grid[data-responsive] .cell[data-responsive-hidden]{display:none!important}tbw-grid[data-responsive] .cell[data-responsive-value-only]{justify-content:flex-start!important;font-weight:500}tbw-grid[data-responsive] .cell[data-responsive-value-only]:before{display:none!important}tbw-grid:not([data-responsive]) .cell[data-responsive-hidden]{display:none!important}tbw-grid[data-responsive] .tbw-footer,tbw-grid[data-responsive] .tbw-pinned-rows,tbw-grid[data-responsive] .tbw-aggregation-rows{display:none!important}tbw-grid[data-responsive] .tbw-pinned-rows,tbw-grid[data-responsive] .tbw-aggregation-rows,tbw-grid[data-responsive] .tbw-aggregation-row{min-width:0!important}tbw-grid[data-responsive] .data-grid-row.responsive-card{display:block!important;padding:var(--tbw-cell-padding);border-bottom:1px solid var(--tbw-color-border)}tbw-grid[data-responsive] .data-grid-row.responsive-card>*{width:100%}tbw-grid[data-responsive] .data-grid-row.responsive-card .cell:before{display:none}';class ms extends D{name="responsive";version="1.0.0";styles=ws;static manifest={incompatibleWith:[{name:"groupingRows",reason:"Responsive card layout does not yet support row grouping. The variable row heights (cards vs group headers) cause scroll calculation issues."}],queries:[{type:"isCardMode",description:"Returns whether the grid is currently in responsive card mode"}]};#t;#e=!1;#u;#c=!1;#i=0;#l=new Set;#n=new Set;#f=null;#h=[];isResponsive(){return this.#e}setResponsive(e){e!==this.#e&&(this.#e=e,this.#R(),this.emit("responsive-change",{isResponsive:e,width:this.#i,breakpoint:this.config.breakpoint??0}))}setBreakpoint(e){this.config.breakpoint=e,this.#v(this.#i)}setCardRenderer(e){this.config.cardRenderer=e,this.#e&&this.requestRender()}getWidth(){return this.#i}getActiveBreakpoint(){return this.#f}attach(e){super.attach(e),this.#w(),this.#a(this.config.hiddenColumns),this.config.breakpoints?.length&&(this.#h=[...this.config.breakpoints].sort((t,i)=>i.maxWidth-t.maxWidth)),this.#t=new ResizeObserver(t=>{const i=t[0]?.contentRect.width??0;this.#i=i,clearTimeout(this.#u),this.#u=setTimeout(()=>{this.#v(i)},this.config.debounceMs??100)}),this.#t.observe(this.gridElement)}#w(){const e=this.grid;if(!e||typeof e.querySelector!="function")return;const t=e.querySelector("tbw-grid-responsive-card");if(!t)return;const i=e;if(i.__frameworkAdapter?.parseResponsiveCardElement){const u=i.__frameworkAdapter.parseResponsiveCardElement(t);u&&(this.config={...this.config,cardRenderer:u})}const n=t.getAttribute("breakpoint"),o=t.getAttribute("card-row-height"),s=t.getAttribute("hidden-columns"),l=t.getAttribute("hide-header"),a=t.getAttribute("debounce-ms"),c={};if(n!==null){const u=parseInt(n,10);isNaN(u)||(c.breakpoint=u)}if(o!==null&&(c.cardRowHeight=o==="auto"?"auto":parseInt(o,10)),s!==null&&(c.hiddenColumns=s.split(",").map(u=>u.trim()).filter(u=>u.length>0)),l!==null&&(c.hideHeader=l!=="false"),a!==null){const u=parseInt(a,10);isNaN(u)||(c.debounceMs=u)}const d=t.innerHTML.trim();d&&!this.config.cardRenderer&&!i.__frameworkAdapter?.parseResponsiveCardElement&&(c.cardRenderer=u=>{const h=me(d,{value:u,row:u}),f=V(h),p=document.createElement("div");return p.className="tbw-responsive-card-content",p.innerHTML=f,p}),Object.keys(c).length>0&&(this.config={...this.config,...c})}#a(e){if(this.#l.clear(),this.#n.clear(),!!e)for(const t of e)typeof t=="string"?this.#l.add(t):t.showValue?this.#n.add(t.field):this.#l.add(t.field)}detach(){this.#t?.disconnect(),this.#t=void 0,clearTimeout(this.#u),this.#u=void 0,this.gridElement&&this.gridElement.removeAttribute("data-responsive"),super.detach()}handleQuery(e){if(e.type==="isCardMode")return this.#e}afterRender(){if(this.#_(),!(this.#h.length>0?this.#f!==null:this.#e))return;const t=this.#l.size>0,i=this.#n.size>0;if(!t&&!i)return;const n=this.gridElement.querySelectorAll(".cell[data-field]");for(const o of n){const s=o.getAttribute("data-field");s&&(this.#l.has(s)?(o.setAttribute("data-responsive-hidden",""),o.removeAttribute("data-responsive-value-only")):this.#n.has(s)?(o.setAttribute("data-responsive-value-only",""),o.removeAttribute("data-responsive-hidden")):(o.removeAttribute("data-responsive-hidden"),o.removeAttribute("data-responsive-value-only")))}}#v(e){if(this.#h.length>0){this.#d(e);return}const t=this.config.breakpoint??0;t===0&&!this.#c&&(this.#c=!0,console.warn("[tbw-grid:ResponsivePlugin] No breakpoint configured. Responsive mode is disabled. Set a breakpoint based on your grid's column count."));const i=t>0&&e<t;i!==this.#e&&(this.#e=i,this.#R(),this.emit("responsive-change",{isResponsive:i,width:e,breakpoint:t}),this.requestRender())}#d(e){let t=null;for(const n of this.#h)e<=n.maxWidth&&(t=n);if(t!==this.#f){this.#f=t,t?.hiddenColumns?this.#a(t.hiddenColumns):this.#a(this.config.hiddenColumns);const n=t?.cardLayout===!0;n!==this.#e&&(this.#e=n,this.#R()),this.emit("responsive-change",{isResponsive:this.#e,width:e,breakpoint:t?.maxWidth??0}),this.requestRender()}}#g;#R(){this.gridElement.toggleAttribute("data-responsive",this.#e);const e=this.config.animate!==!1;this.gridElement.toggleAttribute("data-responsive-animate",e),this.config.animationDuration&&this.gridElement.style.setProperty("--tbw-responsive-duration",`${this.config.animationDuration}ms`);const t=this.grid;if(this.#e){t._virtualization&&(this.#g=t._virtualization.rowHeight);const i=this.gridElement.querySelector(".tbw-scroll-area");i&&(i.scrollLeft=0)}else{const i=this.gridElement.querySelectorAll(".data-grid-row");for(const n of i)n.style.height="",n.classList.remove("responsive-card");this.#g&&this.#g>0&&t._virtualization&&(t._virtualization.rowHeight=this.#g,this.#g=void 0),this.#p=void 0,this.#x=void 0,this.#m=void 0}}renderRow(e,t,i){if(!this.#e||!this.config.cardRenderer||e.__isGroupRow)return;t.replaceChildren();const n=this.config.cardRenderer(e,i);t.className="data-grid-row responsive-card";const o=this.config.cardRowHeight??"auto";return o!=="auto"?t.style.height=`${o}px`:t.style.height="auto",t.appendChild(n),!0}onKeyDown(e){if(!this.#e||this.config.cardRenderer&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(e.key))return!1;const t=this.rows.length-1,i=this.visibleColumns.length-1;switch(e.key){case"ArrowDown":if(this.grid._focusCol<i)return this.grid._focusCol+=1,e.preventDefault(),M(this.grid),!0;if(this.grid._focusRow<t)return this.grid._focusRow+=1,this.grid._focusCol=0,e.preventDefault(),M(this.grid),!0;break;case"ArrowUp":if(this.grid._focusCol>0)return this.grid._focusCol-=1,e.preventDefault(),M(this.grid),!0;if(this.grid._focusRow>0)return this.grid._focusRow-=1,this.grid._focusCol=i,e.preventDefault(),M(this.grid),!0;break;case"ArrowRight":if(this.grid._focusRow<t)return this.grid._focusRow+=1,e.preventDefault(),M(this.grid),!0;break;case"ArrowLeft":if(this.grid._focusRow>0)return this.grid._focusRow-=1,e.preventDefault(),M(this.grid),!0;break}return!1}#p;#x;#m;#y(){if(this.#p&&this.#p>0)return this.#p;const e=this.config.cardRowHeight;return typeof e=="number"&&e>0?e:80}#E(){return this.#x&&this.#x>0?this.#x:this.#g??28}#C(){for(const e of this.rows)if(e.__isGroupRow)return!0;return!1}#S(){let e=0,t=0;for(const i of this.rows)i.__isGroupRow?e++:t++;return{groupCount:e,cardCount:t}}getExtraHeight(){if(!this.#e||!this.config.cardRenderer||!this.#C())return 0;const e=this.#g??28,t=this.#E(),i=this.#y(),{groupCount:n,cardCount:o}=this.#S(),s=n*Math.max(0,t-e),l=o*Math.max(0,i-e);return s+l}getExtraHeightBefore(e){if(!this.#e||!this.config.cardRenderer||!this.#C())return 0;const t=this.#g??28,i=this.#E(),n=this.#y(),o=Math.max(0,i-t),s=Math.max(0,n-t);let l=0,a=0;const c=this.rows,d=Math.min(e,c.length);for(let u=0;u<d;u++)c[u].__isGroupRow?l++:a++;return l*o+a*s}getRowHeight(e,t){if(!(!this.#e||!this.config.cardRenderer))return e.__isGroupRow?this.#E():this.#y()}#A(){let e=0;for(const t of this.rows)t.__isGroupRow||e++;return e}#r=!1;#_(){if(!this.#e||!this.config.cardRenderer)return;let e=!1;const t=this.grid,i=this.#C(),n=this.#A();if(n!==this.#m&&(this.#m=n,e=!0),i){const s=this.gridElement.querySelector(".data-grid-row.group-row");if(s){const l=s.getBoundingClientRect().height;l>0&&l!==this.#x&&(this.#x=l,e=!0)}}const o=this.gridElement.querySelector(".data-grid-row.responsive-card");if(o){const s=o.getBoundingClientRect().height;s>0&&s!==this.#p&&(this.#p=s,e=!0,!i&&t._virtualization&&(t._virtualization.rowHeight=s))}e&&!this.#r&&(this.#r=!0,queueMicrotask(()=>{this.#r=!1,this.grid&&this.#e&&this.grid.refreshVirtualWindow?.(!0,!0)}))}}const bs='@layer tbw-plugins{[data-field=__tbw_row_drag]{display:flex;align-items:center;justify-content:center}.dg-row-drag-handle{display:flex;align-items:center;justify-content:center;min-width:1em;min-height:1em;cursor:grab;-webkit-user-select:none;user-select:none;color:var(--tbw-row-reorder-handle-color, var(--tbw-color-fg-muted));transition:color var(--tbw-transition-duration, .12s) var(--tbw-transition-ease, ease);font-size:var(--tbw-font-size, 1em);letter-spacing:-2px}.dg-row-drag-handle:hover{color:var(--tbw-row-reorder-handle-hover, var(--tbw-color-fg))}.dg-row-drag-handle:active{cursor:grabbing}.data-grid-row.dragging{opacity:.6}.data-grid-row.drop-target{position:relative}.data-grid-row.drop-target.drop-before:before{content:"";position:absolute;top:0;left:0;right:0;height:2px;background-color:var(--tbw-row-reorder-indicator, var(--tbw-color-accent));z-index:10}.data-grid-row.drop-target.drop-after:after{content:"";position:absolute;bottom:0;left:0;right:0;height:2px;background-color:var(--tbw-row-reorder-indicator, var(--tbw-color-accent));z-index:10}.data-grid-row.keyboard-moving{background-color:var(--tbw-row-reorder-moving-bg, var(--tbw-focus-background));box-shadow:0 0 0 1px var(--tbw-row-reorder-moving-border, var(--tbw-color-accent)) inset}.data-grid-row.flip-animating{transition:transform var(--tbw-animation-duration, .2s) ease-out;will-change:transform;z-index:1}}',Ii="__tbw_row_drag";class vs extends D{name="rowReorder";styles=bs;get defaultConfig(){return{enableKeyboard:!0,showDragHandle:!0,dragHandlePosition:"left",dragHandleWidth:40,debounceMs:150,animation:"flip"}}get animationType(){return this.isAnimationEnabled?this.config.animation!==void 0?this.config.animation:"flip":!1}isDragging=!1;draggedRowIndex=null;dropRowIndex=null;pendingMove=null;debounceTimer=null;lastFocusCol=0;detach(){this.clearDebounceTimer(),this.isDragging=!1,this.draggedRowIndex=null,this.dropRowIndex=null,this.pendingMove=null}processColumns(e){if(!this.config.showDragHandle)return[...e];const t={field:Ii,header:"",width:this.config.dragHandleWidth??40,resizable:!1,sortable:!1,filterable:!1,meta:{lockPosition:!0,suppressMovable:!0,utility:!0},viewRenderer:()=>{const i=document.createElement("div");return i.className="dg-row-drag-handle",i.setAttribute("aria-label","Drag to reorder"),i.setAttribute("role","button"),i.setAttribute("tabindex","-1"),i.draggable=!0,this.setIcon(i,this.resolveIcon("dragHandle")),i}};return this.config.dragHandlePosition==="right"?[...e,t]:[t,...e]}afterRender(){if(!this.config.showDragHandle)return;const e=this.gridElement;if(!e)return;e.querySelectorAll(".dg-row-drag-handle").forEach(n=>{const o=n;if(o.getAttribute("data-drag-bound"))return;o.setAttribute("data-drag-bound","true");const s=o.closest(".data-grid-row");s&&this.setupHandleDragListeners(o,s)}),e.querySelectorAll(".data-grid-row").forEach(n=>{const o=n;o.getAttribute("data-drop-bound")||(o.setAttribute("data-drop-bound","true"),this.setupRowDropListeners(o))})}onKeyDown(e){if(!this.config.enableKeyboard||!e.ctrlKey||e.key!=="ArrowUp"&&e.key!=="ArrowDown")return;const t=this.grid,i=t._focusRow,n=t._rows??this.sourceRows;if(i<0||i>=n.length)return;const o=e.key==="ArrowUp"?"up":"down",s=o==="up"?i-1:i+1;if(s<0||s>=n.length)return;const l=n[i];if(!(this.config.canMove&&!this.config.canMove(l,i,s,o)))return this.handleKeyboardMove(l,i,s,o,t._focusCol),e.preventDefault(),e.stopPropagation(),!0}onCellClick(){this.flushPendingMove()}moveRow(e,t){const i=[...this.sourceRows];if(e<0||e>=i.length||t<0||t>=i.length||e===t)return;const n=t<e?"up":"down",o=i[e];this.config.canMove&&!this.config.canMove(o,e,t,n)||this.executeMove(o,e,t,"keyboard")}canMoveRow(e,t){const i=this.sourceRows;if(e<0||e>=i.length||t<0||t>=i.length||e===t)return!1;if(!this.config.canMove)return!0;const n=t<e?"up":"down";return this.config.canMove(i[e],e,t,n)}setupHandleDragListeners(e,t){e.addEventListener("dragstart",i=>{const n=this.getRowIndex(t);n<0||(this.isDragging=!0,this.draggedRowIndex=n,i.dataTransfer&&(i.dataTransfer.effectAllowed="move",i.dataTransfer.setData("text/plain",String(n))),t.classList.add("dragging"))}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedRowIndex=null,this.dropRowIndex=null,this.clearDragClasses()})}setupRowDropListeners(e){e.addEventListener("dragover",t=>{if(t.preventDefault(),!this.isDragging||this.draggedRowIndex===null)return;const i=this.getRowIndex(e);if(i<0||i===this.draggedRowIndex)return;const n=e.getBoundingClientRect(),o=n.top+n.height/2,s=t.clientY<o;this.dropRowIndex=s?i:i+1,e.classList.add("drop-target"),e.classList.toggle("drop-before",s),e.classList.toggle("drop-after",!s)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",t=>{t.preventDefault();const i=this.draggedRowIndex;let n=this.dropRowIndex;if(!(!this.isDragging||i===null||n===null)&&(n>i&&n--,i!==n)){const s=this.sourceRows[i],l=n<i?"up":"down";(!this.config.canMove||this.config.canMove(s,i,n,l))&&this.executeMove(s,i,n,"drag")}})}handleKeyboardMove(e,t,i,n,o){this.pendingMove?this.pendingMove.currentIndex=i:this.pendingMove={originalIndex:t,currentIndex:i,row:e},this.lastFocusCol=o;const s=this.grid,l=[...s._rows??this.sourceRows],[a]=l.splice(t,1);l.splice(i,0,a),s._rows=l,s._focusRow=i,s._focusCol=o,s.refreshVirtualWindow(!0),M(s),this.clearDebounceTimer(),this.debounceTimer=setTimeout(()=>{this.flushPendingMove()},this.config.debounceMs??300)}flushPendingMove(){if(this.clearDebounceTimer(),!this.pendingMove)return;const{originalIndex:e,currentIndex:t,row:i}=this.pendingMove;if(this.pendingMove=null,e===t)return;const n={row:i,fromIndex:e,toIndex:t,rows:[...this.sourceRows],source:"keyboard"};if(this.emitCancelable("row-move",n)){const s=[...this.sourceRows],[l]=s.splice(t,1);s.splice(e,0,l);const a=this.grid;a._rows=s,a._focusRow=e,a._focusCol=this.lastFocusCol,a.refreshVirtualWindow(!0),M(a)}}executeMove(e,t,i,n){const o=[...this.sourceRows],[s]=o.splice(t,1);o.splice(i,0,s);const l={row:e,fromIndex:t,toIndex:i,rows:o,source:n};if(!this.emitCancelable("row-move",l))if(this.animationType==="flip"&&this.gridElement){const c=this.captureRowPositions();this.grid.rows=o,requestAnimationFrame(()=>{this.gridElement.offsetHeight,this.animateFLIP(c,t,i)})}else this.grid.rows=o}captureRowPositions(){const e=new Map;return this.gridElement?.querySelectorAll(".data-grid-row").forEach(t=>{const i=this.getRowIndex(t);i>=0&&e.set(i,t.getBoundingClientRect().top)}),e}animateFLIP(e,t,i){const n=this.gridElement;if(!n||e.size===0)return;const o=Math.min(t,i),s=Math.max(t,i),l=[];if(n.querySelectorAll(".data-grid-row").forEach(c=>{const d=c,u=this.getRowIndex(d);if(u<0||u<o||u>s)return;let h;u===i?h=t:t<i?h=u+1:h=u-1;const f=e.get(h);if(f===void 0)return;const p=d.getBoundingClientRect().top,g=f-p;Math.abs(g)>1&&l.push({el:d,deltaY:g})}),l.length===0)return;l.forEach(({el:c,deltaY:d})=>{c.style.transform=`translateY(${d}px)`}),n.offsetHeight;const a=this.animationDuration;requestAnimationFrame(()=>{l.forEach(({el:c})=>{c.classList.add("flip-animating"),c.style.transform=""}),setTimeout(()=>{l.forEach(({el:c})=>{c.style.transform="",c.classList.remove("flip-animating")})},a+50)})}getRowIndex(e){const t=e.querySelector(".cell[data-row]");return t?parseInt(t.getAttribute("data-row")??"-1",10):-1}clearDragClasses(){this.gridElement?.querySelectorAll(".data-grid-row").forEach(e=>{e.classList.remove("dragging","drop-target","drop-before","drop-after")})}clearDebounceTimer(){this.debounceTimer&&(clearTimeout(this.debounceTimer),this.debounceTimer=null)}}function re(r){return{startRow:Math.min(r.startRow,r.endRow),startCol:Math.min(r.startCol,r.endCol),endRow:Math.max(r.startRow,r.endRow),endCol:Math.max(r.startCol,r.endCol)}}function ys(r){const e=re(r);return{from:{row:e.startRow,col:e.startCol},to:{row:e.endRow,col:e.endCol}}}function Mi(r){return r.map(ys)}function Cs(r,e,t){const i=re(t);return r>=i.startRow&&r<=i.endRow&&e>=i.startCol&&e<=i.endCol}function xs(r,e,t){return t.some(i=>Cs(r,e,i))}function Es(r){const e=[],t=re(r);for(let i=t.startRow;i<=t.endRow;i++)for(let n=t.startCol;n<=t.endCol;n++)e.push({row:i,col:n});return e}function Rs(r){const e=new Map;for(const t of r)for(const i of Es(t))e.set(`${i.row},${i.col}`,i);return[...e.values()]}function ht(r,e){return{startRow:r.row,startCol:r.col,endRow:e.row,endCol:e.col}}function Pe(r,e){const t=re(r),i=re(e);return t.startRow===i.startRow&&t.startCol===i.startCol&&t.endRow===i.endRow&&t.endCol===i.endCol}const Ss='@layer tbw-plugins{tbw-grid.selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}tbw-grid:has(.selection){-webkit-user-select:none;user-select:none}tbw-grid[data-has-focus] .data-grid-row.row-focus{background-color:var(--tbw-focus-background, rgba(from var(--tbw-color-accent) r g b / 12%));outline:none;position:relative}tbw-grid[data-has-focus] .data-grid-row.row-focus:after{content:"";position:absolute;inset:0;pointer-events:none;border:0 solid var(--tbw-range-border-color, var(--tbw-color-accent));border-top-width:2px;border-bottom-width:2px;z-index:1}tbw-grid[data-has-focus] .data-grid-row.row-focus+.data-grid-row.row-focus:after{border-top-width:0}tbw-grid[data-has-focus] .data-grid-row.row-focus:has(+.data-grid-row.row-focus):after{border-bottom-width:0}tbw-grid[data-selection-mode=row] .cell-focus,tbw-grid[data-selection-mode=row] .row-focus,tbw-grid[data-selection-mode=range] .cell-focus{outline:none}tbw-grid .data-grid-row>.cell.selected{background-color:var(--tbw-range-selection-bg);position:relative}tbw-grid .data-grid-row>.cell.selected:after{content:"";position:absolute;inset:0;pointer-events:none;border:0 solid var(--tbw-range-border-color);z-index:1}tbw-grid .data-grid-row>.cell.selected.top:after{border-top-width:2px}tbw-grid .data-grid-row>.cell.selected.bottom:after{border-bottom-width:2px}tbw-grid .data-grid-row>.cell.selected.first:after{border-left-width:2px}tbw-grid .data-grid-row>.cell.selected.last:after{border-right-width:2px}tbw-grid .data-grid-row[data-selectable=false]{cursor:not-allowed;opacity:.6}tbw-grid .data-grid-row[data-selectable=false].row-focus{background-color:var(--tbw-color-row-alt)}tbw-grid .data-grid-row>.cell[data-selectable=false]{cursor:not-allowed;opacity:.6}tbw-grid .data-grid-row>.cell[data-selectable=false].selected{background-color:var(--tbw-selection-warning-bg, rgba(from var(--tbw-color-error) r g b / 50%))}tbw-grid .tbw-selection-summary{font-size:var(--tbw-font-size-sm, .8125rem);color:var(--tbw-color-fg-muted);white-space:nowrap}tbw-grid .data-grid-row>.cell[data-field=__tbw_checkbox],tbw-grid .header-row>.cell[data-field=__tbw_checkbox]{text-align:center;cursor:pointer;padding:0;display:flex;align-items:center;justify-content:center}tbw-grid .tbw-select-row-checkbox{pointer-events:none;margin:0;cursor:pointer}tbw-grid .tbw-checkbox-header{display:flex;justify-content:center;align-items:center;height:100%}tbw-grid .tbw-select-all-checkbox{margin:0;cursor:pointer}}',zi="__tbw_checkbox";function _s(r,e,t){if(r==="cell"&&e.selectedCell)return{mode:r,ranges:[{from:{row:e.selectedCell.row,col:e.selectedCell.col},to:{row:e.selectedCell.row,col:e.selectedCell.col}}]};if(r==="row"&&e.selected.size>0){const i=[...e.selected].sort((l,a)=>l-a),n=[];let o=i[0],s=o;for(let l=1;l<i.length;l++)i[l]===s+1?s=i[l]:(n.push({from:{row:o,col:0},to:{row:s,col:t-1}}),o=i[l],s=o);return n.push({from:{row:o,col:0},to:{row:s,col:t-1}}),{mode:r,ranges:n}}return r==="range"&&e.ranges.length>0?{mode:r,ranges:Mi(e.ranges)}:{mode:r,ranges:[]}}class As extends D{static manifest={queries:[{type:"getSelection",description:"Get the current selection state"}],configRules:[{id:"selection/range-dblclick",severity:"warn",message:`"triggerOn: 'dblclick'" has no effect when mode is "range".
|
|
184
|
+
Click OK to continue, or Cancel to abort.`))return}i.maxRows>0&&o>i.maxRows&&(s=i.maxRows,l=!0),this.#t=!0;const a=performance.now();this.emit("print-start",{rowCount:s,limitApplied:l,originalRowCount:o});try{const c=this.#h;this.#u={bypassThreshold:c._virtualization?.bypassThreshold??24},this.#d(),l&&(this.#c=this.sourceRows,this.grid.rows=this.sourceRows.slice(0,s),await new Promise(d=>setTimeout(d,50))),(i.includeTitle||i.includeTimestamp)&&this.#w(i),await this.#f(),await new Promise(d=>requestAnimationFrame(d)),await new Promise(d=>requestAnimationFrame(d)),t.classList.add(`print-${i.orientation}`),await new Promise(d=>requestAnimationFrame(d)),await new Promise(d=>requestAnimationFrame(d)),i.isolate?await this.#v(i):await this.#a(),this.emit("print-complete",{success:!0,rowCount:s,duration:Math.round(performance.now()-a)})}catch(c){console.error("[PrintPlugin] Print failed:",c),this.emit("print-complete",{success:!1,rowCount:0,duration:Math.round(performance.now()-a)})}finally{this.#E(),this.#t=!1}}#w(e){const t=this.gridElement;if(t){if(this.#n=document.createElement("div"),this.#n.className="tbw-print-header",e.includeTitle){const i=e.title||this.grid.effectiveConfig?.shell?.header?.title||"Grid Data",n=document.createElement("div");n.className="tbw-print-header-title",n.textContent=i,this.#n.appendChild(n)}if(e.includeTimestamp){const i=document.createElement("div");i.className="tbw-print-header-timestamp",i.textContent=`Printed: ${new Date().toLocaleString()}`,this.#n.appendChild(i)}t.insertBefore(this.#n,t.firstChild),this.#l=document.createElement("div"),this.#l.className="tbw-print-footer",this.#l.textContent=`Page generated from ${window.location.hostname}`,t.appendChild(this.#l)}}async#f(){const e=this.#h;if(!e._virtualization)return;const t=this.rows.length;e._virtualization.bypassThreshold=t+100,e.refreshVirtualWindow(!0),await new Promise(i=>setTimeout(i,100))}async#a(){return new Promise(e=>{const t=()=>{window.removeEventListener("afterprint",t),e()};window.addEventListener("afterprint",t),window.print(),setTimeout(()=>{typeof window<"u"&&window.removeEventListener("afterprint",t),e()},1e3)})}async#v(e){const t=this.gridElement;t&&await Mi(t,{orientation:e.orientation})}#d(){const e=this.columns;if(e){this.#e=new Map;for(const t of e)t.printHidden&&t.field&&(this.#e.set(t.field,!t.hidden),this.grid.setColumnVisible(t.field,!1))}}#g(){if(this.#e){for(const[e,t]of this.#e)this.grid.setColumnVisible(e,t);this.#e=null}}#E(){const e=this.gridElement;if(!e)return;this.#g(),e.classList.remove("print-portrait","print-landscape"),this.#i!==null&&(e.style.transform="",e.style.transformOrigin="",e.style.width="",this.#i=null),this.#n&&(this.#n.remove(),this.#n=null),this.#l&&(this.#l.remove(),this.#l=null);const t=this.#h;this.#u&&t._virtualization&&(t._virtualization.bypassThreshold=this.#u.bypassThreshold,t.refreshVirtualWindow(!0),this.#u=null),this.#c!==null&&(this.grid.rows=this.#c,this.#c=null)}afterRender(){this.config?.button&&!this.#b&&(this.#C(),this.#b=!0)}#b=!1;#C(){this.#h.registerToolbarContent?.({id:"print-button",order:900,render:t=>{const i=document.createElement("button");i.className="tbw-toolbar-btn tbw-print-btn",i.title="Print grid",i.type="button";const n=this.resolveIcon("print")||"🖨️";this.setIcon(i,n),i.addEventListener("click",()=>{this.print()},{signal:this.disconnectSignal}),t.appendChild(i)}})}}function ys(r){const e=r.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}function Ii(r,e,t){if(e===t||e<0||e>=r.length||t<0||t>r.length)return r;const i=[...r],[n]=i.splice(e,1);return i.splice(t,0,n),i}const Cs='@layer tbw-plugins{.header-row>.cell[draggable=true]{cursor:grab;position:relative}.header-row>.cell.dragging{opacity:.5;cursor:grabbing}.header-row>.cell.drop-before:before{content:"";position:absolute;left:0;top:0;bottom:0;width:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent));z-index:1}.header-row>.cell.drop-after:after{content:"";position:absolute;right:0;top:0;bottom:0;width:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent));z-index:1}.cell.flip-animating{transition:transform var(--tbw-animation-duration, .2s) ease-out;will-change:transform;z-index:1}@keyframes reorder-fade-in{0%{opacity:0}to{opacity:1}}.cell.fade-animating{animation:reorder-fade-in var(--tbw-animation-duration, .2s) ease-out backwards}}';class xs extends D{name="reorder";styles=Cs;get defaultConfig(){return{animation:"flip"}}get animationType(){return this.isAnimationEnabled?this.config.animation!==void 0?this.config.animation:"flip":!1}get animationDuration(){return this.config.animationDuration!==void 0?this.config.animationDuration:super.animationDuration}isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;canMoveColumnWithPlugins(e){return!e||!ys(e)?!1:!this.grid.query("canMoveColumn",e).includes(!1)}clearDragClasses(){this.gridElement?.querySelectorAll(".header-row > .cell").forEach(e=>{e.classList.remove("dragging","drop-target","drop-before","drop-after")})}attach(e){super.attach(e),e.addEventListener("column-reorder-request",t=>{const i=t.detail;i?.field&&typeof i.toIndex=="number"&&this.moveColumn(i.field,i.toIndex)},{signal:this.disconnectSignal})}detach(){this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null}afterRender(){const e=this.gridElement;if(!e)return;e.querySelectorAll(".header-row > .cell").forEach(i=>{const n=i,o=n.getAttribute("data-field");if(!o)return;const s=this.columns.find(l=>l.field===o);if(!this.canMoveColumnWithPlugins(s)){n.draggable=!1;return}n.draggable=!0,!n.getAttribute("data-dragstart-bound")&&(n.setAttribute("data-dragstart-bound","true"),n.addEventListener("dragstart",l=>{const c=this.getColumnOrder().indexOf(o);this.isDragging=!0,this.draggedField=o,this.draggedIndex=c,l.dataTransfer&&(l.dataTransfer.effectAllowed="move",l.dataTransfer.setData("text/plain",o)),n.classList.add("dragging")}),n.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.clearDragClasses()}),n.addEventListener("dragover",l=>{if(l.preventDefault(),!this.isDragging||this.draggedField===o)return;const a=n.getBoundingClientRect(),c=a.left+a.width/2,u=this.getColumnOrder().indexOf(o);this.dropIndex=l.clientX<c?u:u+1,n.classList.add("drop-target"),n.classList.toggle("drop-before",l.clientX<c),n.classList.toggle("drop-after",l.clientX>=c)}),n.addEventListener("dragleave",()=>{n.classList.remove("drop-target","drop-before","drop-after")}),n.addEventListener("drop",l=>{l.preventDefault();const a=this.draggedField,c=this.draggedIndex,d=this.dropIndex;if(!this.isDragging||a===null||c===null||d===null)return;const u=d>c?d-1:d,h=this.getColumnOrder(),f=Ii(h,c,u),p={field:a,fromIndex:c,toIndex:u,columnOrder:f};this.emitCancelable("column-move",p)||this.updateColumnOrder(f)}))})}onKeyDown(e){if(!e.altKey||e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;const t=this.grid,i=t._focusCol,n=t._visibleColumns;if(i<0||i>=n.length)return;const o=n[i];if(!this.canMoveColumnWithPlugins(o))return;const s=this.getColumnOrder(),l=s.indexOf(o.field);if(l===-1)return;const a=e.key==="ArrowLeft"?l-1:l+1;if(a<0||a>=s.length)return;const c=n.find(d=>d.field===s[a]);if(this.canMoveColumnWithPlugins(c))return this.moveColumn(o.field,a),t._focusCol=a,I(this.grid),e.preventDefault(),e.stopPropagation(),!0}getColumnOrder(){return this.grid.getColumnOrder()}moveColumn(e,t){const i=this.getColumnOrder(),n=i.indexOf(e);if(n===-1)return;const o=Ii(i,n,t);this.emitCancelable("column-move",{field:e,fromIndex:n,toIndex:t,columnOrder:o})||this.updateColumnOrder(o)}setColumnOrder(e){this.updateColumnOrder(e)}resetColumnOrder(){const e=this.columns.map(t=>t.field);this.updateColumnOrder(e)}captureHeaderPositions(){const e=new Map;return this.gridElement?.querySelectorAll(".header-row > .cell[data-field]").forEach(t=>{const i=t.getAttribute("data-field");i&&e.set(i,t.getBoundingClientRect().left)}),e}animateFLIP(e){const t=this.gridElement;if(!t||e.size===0)return;const i=new Map;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(s=>{const l=s.getAttribute("data-field");if(!l)return;const a=e.get(l);if(a===void 0)return;const c=a-s.getBoundingClientRect().left;Math.abs(c)>1&&i.set(l,c)}),i.size===0)return;const n=[];if(t.querySelectorAll(".cell[data-field]").forEach(s=>{const l=i.get(s.getAttribute("data-field")??"");if(l!==void 0){const a=s;a.style.transform=`translateX(${l}px)`,n.push(a)}}),n.length===0)return;this.gridElement.offsetHeight;const o=this.animationDuration;requestAnimationFrame(()=>{n.forEach(s=>{s.classList.add("flip-animating"),s.style.transform=""}),setTimeout(()=>{n.forEach(s=>{s.style.transform="",s.classList.remove("flip-animating")})},o+50)})}animateFade(e){const t=this.gridElement;if(!t){e();return}const i=this.captureHeaderPositions();e();const n=new Set;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(l=>{const a=l.getAttribute("data-field");if(!a)return;const c=i.get(a);if(c===void 0)return;const d=l.getBoundingClientRect().left;Math.abs(c-d)>1&&n.add(a)}),n.size===0)return;const o=[];if(t.querySelectorAll(".cell[data-field]").forEach(l=>{const a=l.getAttribute("data-field");if(a&&n.has(a)){const c=l;c.classList.add("fade-animating"),o.push(c)}}),o.length===0)return;const s=this.animationDuration;setTimeout(()=>{o.forEach(l=>l.classList.remove("fade-animating"))},s+50)}updateColumnOrder(e){const t=this.animationType;if(t==="flip"&&this.gridElement){const i=this.captureHeaderPositions();this.grid.setColumnOrder(e),requestAnimationFrame(()=>{this.gridElement.offsetHeight,this.animateFLIP(i)})}else t==="fade"?this.animateFade(()=>this.grid.setColumnOrder(e)):this.grid.setColumnOrder(e);this.grid.requestStateChange?.()}}const Es='tbw-grid[data-responsive-animate] .data-grid-row,tbw-grid[data-responsive-animate] .data-grid-row>.cell{transition:opacity var(--tbw-responsive-duration, .2s) ease-out,transform var(--tbw-responsive-duration, .2s) ease-out}tbw-grid[data-responsive][data-responsive-animate] .data-grid-row{animation:responsive-card-enter var(--tbw-responsive-duration, .2s) ease-out}@keyframes responsive-card-enter{0%{opacity:0;transform:translateY(-10px)}to{opacity:1;transform:translateY(0)}}tbw-grid[data-responsive] .header{display:none!important}tbw-grid[data-responsive] .footer-row{display:none}tbw-grid[data-responsive] .tbw-scroll-area{overflow-x:hidden;min-width:0!important}tbw-grid[data-responsive] .rows-body-wrapper{min-width:0!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row){display:block!important;grid-template-columns:none!important;padding:var(--tbw-cell-padding);padding-inline-start:var(--tbw-spacing-xl);border-bottom:1px solid var(--tbw-color-border);min-height:auto!important;height:auto!important;contain:none!important;content-visibility:visible!important;background:var(--tbw-color-bg);position:relative}tbw-grid[data-responsive] .data-grid-row:not(.group-row):nth-child(2n){background:var(--tbw-color-row-alt)}tbw-grid[data-responsive] .data-grid-row:not(.group-row):hover{background:var(--tbw-color-row-hover)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)[aria-selected=true]{background:var(--tbw-color-selection)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)[aria-selected=true]:before{content:"";position:absolute;inset-inline-start:0;top:0;bottom:0;width:4px;background:var(--tbw-color-accent)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell{display:flex!important;justify-content:space-between;align-items:center;padding:var(--tbw-spacing-xs) var(--tbw-spacing-md);width:100%!important;min-width:0!important;min-height:auto!important;height:auto!important;line-height:1.5!important;position:static!important;left:auto!important;right:auto!important;border:none!important;border-bottom:none!important;border-inline-end:none!important;background:transparent!important;white-space:normal!important;overflow:visible!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell:before{content:attr(data-header) ": ";font-weight:600;color:var(--tbw-color-header-fg);flex-shrink:0;margin-inline-end:var(--tbw-spacing-md);min-width:100px}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell:after{content:none}tbw-grid[data-responsive] .cell[data-utility]{display:none!important}tbw-grid[data-responsive] .cell[data-responsive-hidden]{display:none!important}tbw-grid[data-responsive] .cell[data-responsive-value-only]{justify-content:flex-start!important;font-weight:500}tbw-grid[data-responsive] .cell[data-responsive-value-only]:before{display:none!important}tbw-grid:not([data-responsive]) .cell[data-responsive-hidden]{display:none!important}tbw-grid[data-responsive] .tbw-footer,tbw-grid[data-responsive] .tbw-pinned-rows,tbw-grid[data-responsive] .tbw-aggregation-rows{display:none!important}tbw-grid[data-responsive] .tbw-pinned-rows,tbw-grid[data-responsive] .tbw-aggregation-rows,tbw-grid[data-responsive] .tbw-aggregation-row{min-width:0!important}tbw-grid[data-responsive] .data-grid-row.responsive-card{display:block!important;padding:var(--tbw-cell-padding);border-bottom:1px solid var(--tbw-color-border)}tbw-grid[data-responsive] .data-grid-row.responsive-card>*{width:100%}tbw-grid[data-responsive] .data-grid-row.responsive-card .cell:before{display:none}';class Rs extends D{name="responsive";version="1.0.0";styles=Es;static manifest={incompatibleWith:[{name:"groupingRows",reason:"Responsive card layout does not yet support row grouping. The variable row heights (cards vs group headers) cause scroll calculation issues."}],queries:[{type:"isCardMode",description:"Returns whether the grid is currently in responsive card mode"}]};#t;#e=!1;#u;#c=!1;#n=0;#l=new Set;#i=new Set;#h=null;#w=[];isResponsive(){return this.#e}setResponsive(e){e!==this.#e&&(this.#e=e,this.#E(),this.emit("responsive-change",{isResponsive:e,width:this.#n,breakpoint:this.config.breakpoint??0}))}setBreakpoint(e){this.config.breakpoint=e,this.#v(this.#n)}setCardRenderer(e){this.config.cardRenderer=e,this.#e&&this.requestRender()}getWidth(){return this.#n}getActiveBreakpoint(){return this.#h}attach(e){super.attach(e),this.#f(),this.#a(this.config.hiddenColumns),this.config.breakpoints?.length&&(this.#w=[...this.config.breakpoints].sort((t,i)=>i.maxWidth-t.maxWidth)),this.#t=new ResizeObserver(t=>{const i=t[0]?.contentRect.width??0;this.#n=i,clearTimeout(this.#u),this.#u=setTimeout(()=>{this.#v(i)},this.config.debounceMs??100)}),this.#t.observe(this.gridElement)}#f(){const e=this.grid;if(!e||typeof e.querySelector!="function")return;const t=e.querySelector("tbw-grid-responsive-card");if(!t)return;const i=e;if(i.__frameworkAdapter?.parseResponsiveCardElement){const u=i.__frameworkAdapter.parseResponsiveCardElement(t);u&&(this.config={...this.config,cardRenderer:u})}const n=t.getAttribute("breakpoint"),o=t.getAttribute("card-row-height"),s=t.getAttribute("hidden-columns"),l=t.getAttribute("hide-header"),a=t.getAttribute("debounce-ms"),c={};if(n!==null){const u=parseInt(n,10);isNaN(u)||(c.breakpoint=u)}if(o!==null&&(c.cardRowHeight=o==="auto"?"auto":parseInt(o,10)),s!==null&&(c.hiddenColumns=s.split(",").map(u=>u.trim()).filter(u=>u.length>0)),l!==null&&(c.hideHeader=l!=="false"),a!==null){const u=parseInt(a,10);isNaN(u)||(c.debounceMs=u)}const d=t.innerHTML.trim();d&&!this.config.cardRenderer&&!i.__frameworkAdapter?.parseResponsiveCardElement&&(c.cardRenderer=u=>{const h=be(d,{value:u,row:u}),f=V(h),p=document.createElement("div");return p.className="tbw-responsive-card-content",p.innerHTML=f,p}),Object.keys(c).length>0&&(this.config={...this.config,...c})}#a(e){if(this.#l.clear(),this.#i.clear(),!!e)for(const t of e)typeof t=="string"?this.#l.add(t):t.showValue?this.#i.add(t.field):this.#l.add(t.field)}detach(){this.#t?.disconnect(),this.#t=void 0,clearTimeout(this.#u),this.#u=void 0,this.gridElement&&this.gridElement.removeAttribute("data-responsive"),super.detach()}handleQuery(e){if(e.type==="isCardMode")return this.#e}afterRender(){if(this.#_(),!(this.#w.length>0?this.#h!==null:this.#e))return;const t=this.#l.size>0,i=this.#i.size>0;if(!t&&!i)return;const n=this.gridElement.querySelectorAll(".cell[data-field]");for(const o of n){const s=o.getAttribute("data-field");s&&(this.#l.has(s)?(o.setAttribute("data-responsive-hidden",""),o.removeAttribute("data-responsive-value-only")):this.#i.has(s)?(o.setAttribute("data-responsive-value-only",""),o.removeAttribute("data-responsive-hidden")):(o.removeAttribute("data-responsive-hidden"),o.removeAttribute("data-responsive-value-only")))}}#v(e){if(this.#w.length>0){this.#d(e);return}const t=this.config.breakpoint??0;t===0&&!this.#c&&(this.#c=!0,console.warn("[tbw-grid:ResponsivePlugin] No breakpoint configured. Responsive mode is disabled. Set a breakpoint based on your grid's column count."));const i=t>0&&e<t;i!==this.#e&&(this.#e=i,this.#E(),this.emit("responsive-change",{isResponsive:i,width:e,breakpoint:t}),this.requestRender())}#d(e){let t=null;for(const n of this.#w)e<=n.maxWidth&&(t=n);if(t!==this.#h){this.#h=t,t?.hiddenColumns?this.#a(t.hiddenColumns):this.#a(this.config.hiddenColumns);const n=t?.cardLayout===!0;n!==this.#e&&(this.#e=n,this.#E()),this.emit("responsive-change",{isResponsive:this.#e,width:e,breakpoint:t?.maxWidth??0}),this.requestRender()}}#g;#E(){this.gridElement.toggleAttribute("data-responsive",this.#e);const e=this.config.animate!==!1;this.gridElement.toggleAttribute("data-responsive-animate",e),this.config.animationDuration&&this.gridElement.style.setProperty("--tbw-responsive-duration",`${this.config.animationDuration}ms`);const t=this.grid;if(this.#e){t._virtualization&&(this.#g=t._virtualization.rowHeight);const i=this.gridElement.querySelector(".tbw-scroll-area");i&&(i.scrollLeft=0)}else{const i=this.gridElement.querySelectorAll(".data-grid-row");for(const n of i)n.style.height="",n.classList.remove("responsive-card");this.#g&&this.#g>0&&t._virtualization&&(t._virtualization.rowHeight=this.#g,this.#g=void 0),this.#b=void 0,this.#C=void 0,this.#R=void 0}}renderRow(e,t,i){if(!this.#e||!this.config.cardRenderer||e.__isGroupRow)return;t.replaceChildren();const n=this.config.cardRenderer(e,i);t.className="data-grid-row responsive-card";const o=this.config.cardRowHeight??"auto";return o!=="auto"?t.style.height=`${o}px`:t.style.height="auto",t.appendChild(n),!0}onKeyDown(e){if(!this.#e||this.config.cardRenderer&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(e.key))return!1;const t=this.rows.length-1,i=this.visibleColumns.length-1;switch(e.key){case"ArrowDown":if(this.grid._focusCol<i)return this.grid._focusCol+=1,e.preventDefault(),I(this.grid),!0;if(this.grid._focusRow<t)return this.grid._focusRow+=1,this.grid._focusCol=0,e.preventDefault(),I(this.grid),!0;break;case"ArrowUp":if(this.grid._focusCol>0)return this.grid._focusCol-=1,e.preventDefault(),I(this.grid),!0;if(this.grid._focusRow>0)return this.grid._focusRow-=1,this.grid._focusCol=i,e.preventDefault(),I(this.grid),!0;break;case"ArrowRight":if(this.grid._focusRow<t)return this.grid._focusRow+=1,e.preventDefault(),I(this.grid),!0;break;case"ArrowLeft":if(this.grid._focusRow>0)return this.grid._focusRow-=1,e.preventDefault(),I(this.grid),!0;break}return!1}#b;#C;#R;#p(){if(this.#b&&this.#b>0)return this.#b;const e=this.config.cardRowHeight;return typeof e=="number"&&e>0?e:80}#x(){return this.#C&&this.#C>0?this.#C:this.#g??28}#m(){for(const e of this.rows)if(e.__isGroupRow)return!0;return!1}#S(){let e=0,t=0;for(const i of this.rows)i.__isGroupRow?e++:t++;return{groupCount:e,cardCount:t}}getExtraHeight(){if(!this.#e||!this.config.cardRenderer||!this.#m())return 0;const e=this.#g??28,t=this.#x(),i=this.#p(),{groupCount:n,cardCount:o}=this.#S(),s=n*Math.max(0,t-e),l=o*Math.max(0,i-e);return s+l}getExtraHeightBefore(e){if(!this.#e||!this.config.cardRenderer||!this.#m())return 0;const t=this.#g??28,i=this.#x(),n=this.#p(),o=Math.max(0,i-t),s=Math.max(0,n-t);let l=0,a=0;const c=this.rows,d=Math.min(e,c.length);for(let u=0;u<d;u++)c[u].__isGroupRow?l++:a++;return l*o+a*s}getRowHeight(e,t){if(!(!this.#e||!this.config.cardRenderer))return e.__isGroupRow?this.#x():this.#p()}#L(){let e=0;for(const t of this.rows)t.__isGroupRow||e++;return e}#r=!1;#_(){if(!this.#e||!this.config.cardRenderer)return;let e=!1;const t=this.grid,i=this.#m(),n=this.#L();if(n!==this.#R&&(this.#R=n,e=!0),i){const s=this.gridElement.querySelector(".data-grid-row.group-row");if(s){const l=s.getBoundingClientRect().height;l>0&&l!==this.#C&&(this.#C=l,e=!0)}}const o=this.gridElement.querySelector(".data-grid-row.responsive-card");if(o){const s=o.getBoundingClientRect().height;s>0&&s!==this.#b&&(this.#b=s,e=!0,!i&&t._virtualization&&(t._virtualization.rowHeight=s))}e&&!this.#r&&(this.#r=!0,queueMicrotask(()=>{this.#r=!1,this.grid&&this.#e&&this.grid.refreshVirtualWindow?.(!0,!0)}))}}const Ss='@layer tbw-plugins{[data-field=__tbw_row_drag]{display:flex;align-items:center;justify-content:center}.dg-row-drag-handle{display:flex;align-items:center;justify-content:center;min-width:1em;min-height:1em;cursor:grab;-webkit-user-select:none;user-select:none;color:var(--tbw-row-reorder-handle-color, var(--tbw-color-fg-muted));transition:color var(--tbw-transition-duration, .12s) var(--tbw-transition-ease, ease);font-size:var(--tbw-font-size, 1em);letter-spacing:-2px}.dg-row-drag-handle:hover{color:var(--tbw-row-reorder-handle-hover, var(--tbw-color-fg))}.dg-row-drag-handle:active{cursor:grabbing}.data-grid-row.dragging{opacity:.6}.data-grid-row.drop-target{position:relative}.data-grid-row.drop-target.drop-before:before{content:"";position:absolute;top:0;left:0;right:0;height:2px;background-color:var(--tbw-row-reorder-indicator, var(--tbw-color-accent));z-index:10}.data-grid-row.drop-target.drop-after:after{content:"";position:absolute;bottom:0;left:0;right:0;height:2px;background-color:var(--tbw-row-reorder-indicator, var(--tbw-color-accent));z-index:10}.data-grid-row.keyboard-moving{background-color:var(--tbw-row-reorder-moving-bg, var(--tbw-focus-background));box-shadow:0 0 0 1px var(--tbw-row-reorder-moving-border, var(--tbw-color-accent)) inset}.data-grid-row.flip-animating{transition:transform var(--tbw-animation-duration, .2s) ease-out;will-change:transform;z-index:1}}',zi="__tbw_row_drag";class _s extends D{name="rowReorder";styles=Ss;get defaultConfig(){return{enableKeyboard:!0,showDragHandle:!0,dragHandlePosition:"left",dragHandleWidth:40,debounceMs:150,animation:"flip"}}get animationType(){return this.isAnimationEnabled?this.config.animation!==void 0?this.config.animation:"flip":!1}isDragging=!1;draggedRowIndex=null;dropRowIndex=null;pendingMove=null;debounceTimer=null;lastFocusCol=0;detach(){this.clearDebounceTimer(),this.isDragging=!1,this.draggedRowIndex=null,this.dropRowIndex=null,this.pendingMove=null}processColumns(e){if(!this.config.showDragHandle)return[...e];const t={field:zi,header:"",width:this.config.dragHandleWidth??40,resizable:!1,sortable:!1,filterable:!1,meta:{lockPosition:!0,suppressMovable:!0,utility:!0},viewRenderer:()=>{const i=document.createElement("div");return i.className="dg-row-drag-handle",i.setAttribute("aria-label","Drag to reorder"),i.setAttribute("role","button"),i.setAttribute("tabindex","-1"),i.draggable=!0,this.setIcon(i,this.resolveIcon("dragHandle")),i}};return this.config.dragHandlePosition==="right"?[...e,t]:[t,...e]}afterRender(){if(!this.config.showDragHandle)return;const e=this.gridElement;if(!e)return;e.querySelectorAll(".dg-row-drag-handle").forEach(n=>{const o=n;if(o.getAttribute("data-drag-bound"))return;o.setAttribute("data-drag-bound","true");const s=o.closest(".data-grid-row");s&&this.setupHandleDragListeners(o,s)}),e.querySelectorAll(".data-grid-row").forEach(n=>{const o=n;o.getAttribute("data-drop-bound")||(o.setAttribute("data-drop-bound","true"),this.setupRowDropListeners(o))})}onKeyDown(e){if(!this.config.enableKeyboard||!e.ctrlKey||e.key!=="ArrowUp"&&e.key!=="ArrowDown")return;const t=this.grid,i=t._focusRow,n=t._rows??this.sourceRows;if(i<0||i>=n.length)return;const o=e.key==="ArrowUp"?"up":"down",s=o==="up"?i-1:i+1;if(s<0||s>=n.length)return;const l=n[i];if(!(this.config.canMove&&!this.config.canMove(l,i,s,o)))return this.handleKeyboardMove(l,i,s,o,t._focusCol),e.preventDefault(),e.stopPropagation(),!0}onCellClick(){this.flushPendingMove()}moveRow(e,t){const i=[...this.sourceRows];if(e<0||e>=i.length||t<0||t>=i.length||e===t)return;const n=t<e?"up":"down",o=i[e];this.config.canMove&&!this.config.canMove(o,e,t,n)||this.executeMove(o,e,t,"keyboard")}canMoveRow(e,t){const i=this.sourceRows;if(e<0||e>=i.length||t<0||t>=i.length||e===t)return!1;if(!this.config.canMove)return!0;const n=t<e?"up":"down";return this.config.canMove(i[e],e,t,n)}setupHandleDragListeners(e,t){e.addEventListener("dragstart",i=>{const n=this.getRowIndex(t);n<0||(this.isDragging=!0,this.draggedRowIndex=n,i.dataTransfer&&(i.dataTransfer.effectAllowed="move",i.dataTransfer.setData("text/plain",String(n))),t.classList.add("dragging"))}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedRowIndex=null,this.dropRowIndex=null,this.clearDragClasses()})}setupRowDropListeners(e){e.addEventListener("dragover",t=>{if(t.preventDefault(),!this.isDragging||this.draggedRowIndex===null)return;const i=this.getRowIndex(e);if(i<0||i===this.draggedRowIndex)return;const n=e.getBoundingClientRect(),o=n.top+n.height/2,s=t.clientY<o;this.dropRowIndex=s?i:i+1,e.classList.add("drop-target"),e.classList.toggle("drop-before",s),e.classList.toggle("drop-after",!s)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",t=>{t.preventDefault();const i=this.draggedRowIndex;let n=this.dropRowIndex;if(!(!this.isDragging||i===null||n===null)&&(n>i&&n--,i!==n)){const s=this.sourceRows[i],l=n<i?"up":"down";(!this.config.canMove||this.config.canMove(s,i,n,l))&&this.executeMove(s,i,n,"drag")}})}handleKeyboardMove(e,t,i,n,o){this.pendingMove?this.pendingMove.currentIndex=i:this.pendingMove={originalIndex:t,currentIndex:i,row:e},this.lastFocusCol=o;const s=this.grid,l=[...s._rows??this.sourceRows],[a]=l.splice(t,1);l.splice(i,0,a),s._rows=l,s._focusRow=i,s._focusCol=o,s.refreshVirtualWindow(!0),I(s),this.clearDebounceTimer(),this.debounceTimer=setTimeout(()=>{this.flushPendingMove()},this.config.debounceMs??300)}flushPendingMove(){if(this.clearDebounceTimer(),!this.pendingMove)return;const{originalIndex:e,currentIndex:t,row:i}=this.pendingMove;if(this.pendingMove=null,e===t)return;const n={row:i,fromIndex:e,toIndex:t,rows:[...this.sourceRows],source:"keyboard"};if(this.emitCancelable("row-move",n)){const s=[...this.sourceRows],[l]=s.splice(t,1);s.splice(e,0,l);const a=this.grid;a._rows=s,a._focusRow=e,a._focusCol=this.lastFocusCol,a.refreshVirtualWindow(!0),I(a)}}executeMove(e,t,i,n){const o=[...this.sourceRows],[s]=o.splice(t,1);o.splice(i,0,s);const l={row:e,fromIndex:t,toIndex:i,rows:o,source:n};if(!this.emitCancelable("row-move",l))if(this.animationType==="flip"&&this.gridElement){const c=this.captureRowPositions();this.grid.rows=o,requestAnimationFrame(()=>{this.gridElement.offsetHeight,this.animateFLIP(c,t,i)})}else this.grid.rows=o}captureRowPositions(){const e=new Map;return this.gridElement?.querySelectorAll(".data-grid-row").forEach(t=>{const i=this.getRowIndex(t);i>=0&&e.set(i,t.getBoundingClientRect().top)}),e}animateFLIP(e,t,i){const n=this.gridElement;if(!n||e.size===0)return;const o=Math.min(t,i),s=Math.max(t,i),l=[];if(n.querySelectorAll(".data-grid-row").forEach(c=>{const d=c,u=this.getRowIndex(d);if(u<0||u<o||u>s)return;let h;u===i?h=t:t<i?h=u+1:h=u-1;const f=e.get(h);if(f===void 0)return;const p=d.getBoundingClientRect().top,g=f-p;Math.abs(g)>1&&l.push({el:d,deltaY:g})}),l.length===0)return;l.forEach(({el:c,deltaY:d})=>{c.style.transform=`translateY(${d}px)`}),n.offsetHeight;const a=this.animationDuration;requestAnimationFrame(()=>{l.forEach(({el:c})=>{c.classList.add("flip-animating"),c.style.transform=""}),setTimeout(()=>{l.forEach(({el:c})=>{c.style.transform="",c.classList.remove("flip-animating")})},a+50)})}getRowIndex(e){const t=e.querySelector(".cell[data-row]");return t?parseInt(t.getAttribute("data-row")??"-1",10):-1}clearDragClasses(){this.gridElement?.querySelectorAll(".data-grid-row").forEach(e=>{e.classList.remove("dragging","drop-target","drop-before","drop-after")})}clearDebounceTimer(){this.debounceTimer&&(clearTimeout(this.debounceTimer),this.debounceTimer=null)}}function re(r){return{startRow:Math.min(r.startRow,r.endRow),startCol:Math.min(r.startCol,r.endCol),endRow:Math.max(r.startRow,r.endRow),endCol:Math.max(r.startCol,r.endCol)}}function As(r){const e=re(r);return{from:{row:e.startRow,col:e.startCol},to:{row:e.endRow,col:e.endCol}}}function Ni(r){return r.map(As)}function ks(r,e,t){const i=re(t);return r>=i.startRow&&r<=i.endRow&&e>=i.startCol&&e<=i.endCol}function Ts(r,e,t){return t.some(i=>ks(r,e,i))}function Ls(r){const e=[],t=re(r);for(let i=t.startRow;i<=t.endRow;i++)for(let n=t.startCol;n<=t.endCol;n++)e.push({row:i,col:n});return e}function Ps(r){const e=new Map;for(const t of r)for(const i of Ls(t))e.set(`${i.row},${i.col}`,i);return[...e.values()]}function ft(r,e){return{startRow:r.row,startCol:r.col,endRow:e.row,endCol:e.col}}function He(r,e){const t=re(r),i=re(e);return t.startRow===i.startRow&&t.startCol===i.startCol&&t.endRow===i.endRow&&t.endCol===i.endCol}const Hs='@layer tbw-plugins{tbw-grid.selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}tbw-grid:has(.selection){-webkit-user-select:none;user-select:none}tbw-grid .data-grid-row.row-focus{background-color:var(--tbw-focus-background, rgba(from var(--tbw-color-accent) r g b / 12%));outline:none;position:relative}tbw-grid .data-grid-row.row-focus:after{content:"";position:absolute;inset:0;pointer-events:none;border-width:0;border-style:var(--tbw-selection-border-style, var(--tbw-border-style));border-color:var(--tbw-range-border-color, var(--tbw-color-accent));border-top-width:var(--tbw-selection-border-width, var(--tbw-border-width));border-bottom-width:var(--tbw-selection-border-width, var(--tbw-border-width));z-index:1}tbw-grid .data-grid-row.row-focus+.data-grid-row.row-focus:after{border-top-width:0}tbw-grid .data-grid-row.row-focus:has(+.data-grid-row.row-focus):after{border-bottom-width:0}tbw-grid[data-selection-mode=row] .cell-focus,tbw-grid[data-selection-mode=row] .row-focus,tbw-grid[data-selection-mode=range] .cell-focus{outline:none}tbw-grid .data-grid-row>.cell.selected{background-color:var(--tbw-range-selection-bg);position:relative}tbw-grid .data-grid-row>.cell.selected:after{content:"";position:absolute;inset:0;pointer-events:none;border:0 var(--tbw-selection-border-style, var(--tbw-border-style)) var(--tbw-range-border-color);z-index:1}tbw-grid .data-grid-row>.cell.selected.top:after{border-top-width:var(--tbw-selection-border-width, var(--tbw-border-width))}tbw-grid .data-grid-row>.cell.selected.bottom:after{border-bottom-width:var(--tbw-selection-border-width, var(--tbw-border-width))}tbw-grid .data-grid-row>.cell.selected.first:after{border-left-width:var(--tbw-selection-border-width, var(--tbw-border-width))}tbw-grid .data-grid-row>.cell.selected.last:after{border-right-width:var(--tbw-selection-border-width, var(--tbw-border-width))}tbw-grid .data-grid-row[data-selectable=false]{cursor:not-allowed;opacity:.6}tbw-grid .data-grid-row[data-selectable=false].row-focus{background-color:var(--tbw-color-row-alt)}tbw-grid .data-grid-row>.cell[data-selectable=false]{cursor:not-allowed;opacity:.6}tbw-grid .data-grid-row>.cell[data-selectable=false].selected{background-color:var(--tbw-selection-warning-bg, rgba(from var(--tbw-color-error) r g b / 50%))}tbw-grid .tbw-selection-summary{font-size:var(--tbw-font-size-sm, .8125rem);color:var(--tbw-color-fg-muted);white-space:nowrap}tbw-grid .data-grid-row>.cell[data-field=__tbw_checkbox],tbw-grid .header-row>.cell[data-field=__tbw_checkbox]{text-align:center;cursor:pointer;padding:0;display:flex;align-items:center;justify-content:center}tbw-grid .tbw-select-row-checkbox{pointer-events:none;margin:0;cursor:pointer}tbw-grid .tbw-checkbox-header{display:flex;justify-content:center;align-items:center;height:100%}tbw-grid .tbw-select-all-checkbox{margin:0;cursor:pointer}}',Oi="__tbw_checkbox";function Ds(r,e,t){if(r==="cell"&&e.selectedCell)return{mode:r,ranges:[{from:{row:e.selectedCell.row,col:e.selectedCell.col},to:{row:e.selectedCell.row,col:e.selectedCell.col}}]};if(r==="row"&&e.selected.size>0){const i=[...e.selected].sort((l,a)=>l-a),n=[];let o=i[0],s=o;for(let l=1;l<i.length;l++)i[l]===s+1?s=i[l]:(n.push({from:{row:o,col:0},to:{row:s,col:t-1}}),o=i[l],s=o);return n.push({from:{row:o,col:0},to:{row:s,col:t-1}}),{mode:r,ranges:n}}return r==="range"&&e.ranges.length>0?{mode:r,ranges:Ni(e.ranges)}:{mode:r,ranges:[]}}class Ms extends D{static manifest={queries:[{type:"getSelection",description:"Get the current selection state"},{type:"selectRows",description:"Select specific rows by index (row mode only)"},{type:"getSelectedRowIndices",description:"Get sorted array of selected row indices"}],configRules:[{id:"selection/range-dblclick",severity:"warn",message:`"triggerOn: 'dblclick'" has no effect when mode is "range".
|
|
185
185
|
→ Range selection uses drag interaction (mousedown → mousemove), not click events.
|
|
186
|
-
→ The "triggerOn" option only affects "cell" and "row" selection modes.`,check:e=>e.mode==="range"&&e.triggerOn==="dblclick"}]};name="selection";styles=Ss;get defaultConfig(){return{mode:"cell",triggerOn:"click",enabled:!0}}selected=new Set;lastSelected=null;anchor=null;ranges=[];activeRange=null;cellAnchor=null;isDragging=!1;pendingKeyboardUpdate=null;selectedCell=null;lastSyncedFocusRow=-1;lastSyncedFocusCol=-1;explicitSelection=!1;isSelectionEnabled(){return this.config.enabled===!1?!1:this.grid.effectiveConfig?.selectable!==!1}checkSelectable(e,t){const{isSelectable:i}=this.config;if(!i)return!0;const n=this.rows[e];if(!n)return!1;const o=t!==void 0?this.columns[t]:void 0;return i(n,e,o,t)}isRowSelectable(e){return this.checkSelectable(e)}isCellSelectable(e,t){return this.checkSelectable(e,t)}attach(e){super.attach(e),this.on("filter-applied",()=>this.clearSelectionSilent()),this.on("grouping-state-change",()=>this.clearSelectionSilent()),this.on("tree-state-change",()=>this.clearSelectionSilent())}handleQuery(e){if(e.type==="getSelection")return this.getSelection()}detach(){this.selected.clear(),this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.isDragging=!1,this.selectedCell=null,this.pendingKeyboardUpdate=null,this.lastSyncedFocusRow=-1,this.lastSyncedFocusCol=-1}clearSelectionSilent(){this.selected.clear(),this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.selectedCell=null,this.lastSelected=null,this.anchor=null,this.lastSyncedFocusRow=-1,this.lastSyncedFocusCol=-1,this.requestAfterRender()}onCellClick(e){if(!this.isSelectionEnabled())return!1;const{rowIndex:t,colIndex:i,originalEvent:n}=e,{mode:o,triggerOn:s="click"}=this.config;if(n.type!==s)return!1;const l=this.columns[i],a=l&&X(l);if(o==="cell"){if(a||!this.isCellSelectable(t,i))return!1;const c=this.selectedCell;return c&&c.row===t&&c.col===i||(this.selectedCell={row:t,col:i},this.emit("selection-change",this.#i()),this.requestAfterRender()),!1}if(o==="row"){if(!this.isRowSelectable(t))return!1;const c=n.shiftKey,d=n.ctrlKey||n.metaKey,u=l?.meta?.checkboxColumn===!0;if(c&&this.anchor!==null){const h=Math.min(this.anchor,t),f=Math.max(this.anchor,t);d||this.selected.clear();for(let p=h;p<=f;p++)this.isRowSelectable(p)&&this.selected.add(p)}else if(d||u)this.selected.has(t)?this.selected.delete(t):this.selected.add(t),this.anchor=t;else{if(this.selected.size===1&&this.selected.has(t))return!1;this.selected.clear(),this.selected.add(t),this.anchor=t}return this.lastSelected=t,this.explicitSelection=!0,this.emit("selection-change",this.#i()),this.requestAfterRender(),!1}if(o==="range"){if(a||!this.isCellSelectable(t,i))return!1;const c=n.shiftKey,d=n.ctrlKey||n.metaKey;if(c&&this.cellAnchor){const u=ht(this.cellAnchor,{row:t,col:i}),h=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;if(h&&Pe(h,u))return!1;d?this.ranges.length>0?this.ranges[this.ranges.length-1]=u:this.ranges.push(u):this.ranges=[u],this.activeRange=u}else if(d){const u={startRow:t,startCol:i,endRow:t,endCol:i};this.ranges.push(u),this.activeRange=u,this.cellAnchor={row:t,col:i}}else{const u={startRow:t,startCol:i,endRow:t,endCol:i};if(this.ranges.length===1&&Pe(this.ranges[0],u))return!1;this.ranges=[u],this.activeRange=u,this.cellAnchor={row:t,col:i}}return this.emit("selection-change",this.#i()),this.requestAfterRender(),!1}return!1}onKeyDown(e){if(!this.isSelectionEnabled())return!1;const{mode:t}=this.config,n=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Tab","Home","End","PageUp","PageDown"].includes(e.key);if(e.key==="Escape")return t==="cell"?this.selectedCell=null:t==="row"?(this.selected.clear(),this.anchor=null):t==="range"&&(this.ranges=[],this.activeRange=null,this.cellAnchor=null),this.emit("selection-change",this.#i()),this.requestAfterRender(),!0;if(t==="cell"&&n)return queueMicrotask(()=>{const o=this.grid._focusRow,s=this.grid._focusCol;this.isCellSelectable(o,s)?this.selectedCell={row:o,col:s}:this.selectedCell=null,this.emit("selection-change",this.#i()),this.requestAfterRender()}),!1;if(t==="row"){if(e.key==="ArrowUp"||e.key==="ArrowDown"){const o=e.shiftKey;return o&&this.anchor===null&&(this.anchor=this.grid._focusRow),queueMicrotask(()=>{const s=this.grid._focusRow;if(o&&this.anchor!==null){this.selected.clear();const l=Math.min(this.anchor,s),a=Math.max(this.anchor,s);for(let c=l;c<=a;c++)this.isRowSelectable(c)&&this.selected.add(c)}else this.isRowSelectable(s)?(this.selected.clear(),this.selected.add(s),this.anchor=s):this.selected.clear();this.lastSelected=s,this.explicitSelection=!0,this.emit("selection-change",this.#i()),this.requestAfterRender()}),!1}if(e.key==="a"&&(e.ctrlKey||e.metaKey))return e.preventDefault(),e.stopPropagation(),this.selectAll(),!0}if(t==="range"&&n){const o=e.key==="Tab",s=e.shiftKey&&!o;return s&&!this.cellAnchor&&(this.cellAnchor={row:this.grid._focusRow,col:this.grid._focusCol}),this.pendingKeyboardUpdate={shiftKey:s},queueMicrotask(()=>this.requestAfterRender()),!1}return t==="range"&&e.key==="a"&&(e.ctrlKey||e.metaKey)?(e.preventDefault(),e.stopPropagation(),this.selectAll(),!0):!1}onCellMouseDown(e){if(!this.isSelectionEnabled()||this.config.mode!=="range"||e.rowIndex===void 0||e.colIndex===void 0||e.rowIndex<0)return;const t=this.columns[e.colIndex];if(t&&X(t)||!this.isCellSelectable(e.rowIndex,e.colIndex)||e.originalEvent.shiftKey&&this.cellAnchor)return;this.isDragging=!0;const i=e.rowIndex,n=e.colIndex,o=e.originalEvent.ctrlKey||e.originalEvent.metaKey,s={startRow:i,startCol:n,endRow:i,endCol:n};return!o&&this.ranges.length===1&&Pe(this.ranges[0],s)?(this.cellAnchor={row:i,col:n},!0):(this.cellAnchor={row:i,col:n},o||(this.ranges=[]),this.ranges.push(s),this.activeRange=s,this.emit("selection-change",this.#i()),this.requestAfterRender(),!0)}onCellMouseMove(e){if(!this.isSelectionEnabled()||this.config.mode!=="range"||!this.isDragging||!this.cellAnchor||e.rowIndex===void 0||e.colIndex===void 0||e.rowIndex<0)return;let t=e.colIndex;const i=this.columns[t];if(i&&X(i)){const s=this.columns.findIndex(l=>!X(l));s>=0&&(t=s)}const n=ht(this.cellAnchor,{row:e.rowIndex,col:t}),o=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;return o&&Pe(o,n)||(this.ranges.length>0?this.ranges[this.ranges.length-1]=n:this.ranges.push(n),this.activeRange=n,this.emit("selection-change",this.#i()),this.requestAfterRender()),!0}onCellMouseUp(e){if(this.isSelectionEnabled()&&this.config.mode==="range"&&this.isDragging)return this.isDragging=!1,!0}processColumns(e){if(this.config.checkbox&&this.config.mode==="row"){if(e.some(o=>o.field===zi))return e;const t=this.#t(),i=e.findIndex(Te),n=i>=0?i+1:0;return[...e.slice(0,n),t,...e.slice(n)]}return e}#t(){return{field:zi,header:"",width:32,resizable:!1,sortable:!1,meta:{lockPosition:!0,suppressMovable:!0,utility:!0,checkboxColumn:!0},headerRenderer:()=>{const e=document.createElement("div");e.className="tbw-checkbox-header";const t=document.createElement("input");return t.type="checkbox",t.className="tbw-select-all-checkbox",t.addEventListener("click",i=>{i.stopPropagation(),i.target.checked?this.selectAll():this.clearSelection()}),e.appendChild(t),e},renderer:e=>{const t=document.createElement("input");t.type="checkbox",t.className="tbw-select-row-checkbox";const i=e.cellEl;if(i){const n=parseInt(i.getAttribute("data-row")??"-1",10);n>=0&&(t.checked=this.selected.has(n))}return t}}}#e(e){e.querySelectorAll(".tbw-select-row-checkbox").forEach(n=>{const o=n.closest(".cell"),s=o?be(o):-1;s>=0&&(n.checked=this.selected.has(s))});const i=e.querySelector(".tbw-select-all-checkbox");if(i){const n=this.rows.length;let o=0;if(this.config.isSelectable)for(let a=0;a<n;a++)this.isRowSelectable(a)&&o++;else o=n;const s=o>0&&this.selected.size>=o,l=this.selected.size>0;i.checked=s,i.indeterminate=l&&!s}}#u(e){const t=this.grid._focusRow,i=this.grid._focusCol;if(e==="row"){if(this.explicitSelection){this.explicitSelection=!1,this.lastSyncedFocusRow=t;return}t!==this.lastSyncedFocusRow&&(this.lastSyncedFocusRow=t,this.isRowSelectable(t)&&(!this.selected.has(t)||this.selected.size!==1)&&(this.selected.clear(),this.selected.add(t),this.lastSelected=t,this.anchor=t,this.emit("selection-change",this.#i())))}if(e==="cell"){if(this.explicitSelection){this.explicitSelection=!1,this.lastSyncedFocusRow=t,this.lastSyncedFocusCol=i;return}if((t!==this.lastSyncedFocusRow||i!==this.lastSyncedFocusCol)&&(this.lastSyncedFocusRow=t,this.lastSyncedFocusCol=i,this.isCellSelectable(t,i))){const n=this.selectedCell;(!n||n.row!==t||n.col!==i)&&(this.selectedCell={row:t,col:i},this.emit("selection-change",this.#i()))}}}#c(){const e=this.gridElement;if(!e)return;const{mode:t}=this.config,i=!!this.config.isSelectable;e.querySelectorAll(".cell").forEach(s=>{s.classList.remove("selected","top","bottom","first","last"),i&&s.removeAttribute("data-selectable")});const o=e.querySelectorAll(".data-grid-row");if(o.forEach(s=>{s.classList.remove("selected","row-focus"),i&&s.removeAttribute("data-selectable")}),t==="row"&&(ae(e),o.forEach(s=>{const l=s.querySelector(".cell[data-row]"),a=be(l);a>=0&&(i&&!this.isRowSelectable(a)&&s.setAttribute("data-selectable","false"),this.selected.has(a)&&s.classList.add("selected","row-focus"))}),this.config.checkbox&&this.#e(e)),(t==="cell"||t==="range")&&i&&e.querySelectorAll(".cell[data-row][data-col]").forEach(l=>{const a=parseInt(l.getAttribute("data-row")??"-1",10),c=parseInt(l.getAttribute("data-col")??"-1",10);a>=0&&c>=0&&(this.isCellSelectable(a,c)||l.setAttribute("data-selectable","false"))}),t==="range"&&this.ranges.length>0){ae(e);const s=this.ranges.map(re),l=(c,d)=>{for(const u of s)if(c>=u.startRow&&c<=u.endRow&&d>=u.startCol&&d<=u.endCol)return!0;return!1};e.querySelectorAll(".cell[data-row][data-col]").forEach(c=>{const d=parseInt(c.getAttribute("data-row")??"-1",10),u=parseInt(c.getAttribute("data-col")??"-1",10);if(d>=0&&u>=0){const h=this.columns[u];if(h&&X(h))return;l(d,u)&&(c.classList.add("selected"),l(d-1,u)||c.classList.add("top"),l(d+1,u)||c.classList.add("bottom"),l(d,u-1)||c.classList.add("first"),l(d,u+1)||c.classList.add("last"))}})}}afterRender(){if(!this.isSelectionEnabled())return;const e=this.gridElement;if(!e)return;const t=e.children[0],{mode:i}=this.config;if(this.pendingKeyboardUpdate&&i==="range"){const{shiftKey:n}=this.pendingKeyboardUpdate;this.pendingKeyboardUpdate=null;const o=this.grid._focusRow,s=this.grid._focusCol;if(n&&this.cellAnchor){const l=ht(this.cellAnchor,{row:o,col:s});this.ranges=[l],this.activeRange=l}else n||(this.ranges=[],this.activeRange=null,this.cellAnchor={row:o,col:s});this.emit("selection-change",this.#i())}this.#u(i),this.grid.setAttribute("data-selection-mode",i),t&&t.classList.toggle("selecting",this.isDragging),this.#c()}onScrollRender(){this.isSelectionEnabled()&&this.#c()}getSelection(){return{mode:this.config.mode,ranges:this.#i().ranges,anchor:this.cellAnchor}}getSelectedCells(){return Rs(this.ranges)}isCellSelected(e,t){return xs(e,t,this.ranges)}selectAll(){const{mode:e}=this.config;if(e==="row"){this.selected.clear();for(let t=0;t<this.rows.length;t++)this.isRowSelectable(t)&&this.selected.add(t);this.explicitSelection=!0,this.emit("selection-change",this.#i()),this.requestAfterRender()}else if(e==="range"){const t=this.rows.length,i=this.columns.length;if(t>0&&i>0){const n={startRow:0,startCol:0,endRow:t-1,endCol:i-1};this.ranges=[n],this.activeRange=n,this.emit("selection-change",this.#i()),this.requestAfterRender()}}}selectRows(e){if(this.config.mode==="row"){this.selected.clear();for(const t of e)t>=0&&t<this.rows.length&&this.isRowSelectable(t)&&this.selected.add(t);this.anchor=e.length>0?e[e.length-1]:null,this.explicitSelection=!0,this.emit("selection-change",this.#i()),this.requestAfterRender()}}getSelectedRowIndices(){return[...this.selected].sort((e,t)=>e-t)}clearSelection(){this.selectedCell=null,this.selected.clear(),this.anchor=null,this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.emit("selection-change",{mode:this.config.mode,ranges:[]}),this.requestAfterRender()}setRanges(e){this.ranges=e.map(t=>({startRow:t.from.row,startCol:t.from.col,endRow:t.to.row,endCol:t.to.col})),this.activeRange=this.ranges.length>0?this.ranges[this.ranges.length-1]:null,this.emit("selection-change",{mode:this.config.mode,ranges:Mi(this.ranges)}),this.requestAfterRender()}#i(){return _s(this.config.mode,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges},this.columns.length)}}function He(r,e){return Math.floor(r/e)}function ks(r,e){return{start:r*e,end:(r+1)*e}}function Ts(r,e,t){const i=He(r,t),n=He(e-1,t),o=[];for(let s=i;s<=n;s++)o.push(s);return o}async function Ni(r,e,t,i){const n=ks(e,t);return r.getRows({startRow:n.start,endRow:n.end,sortModel:i.sortModel,filterModel:i.filterModel})}function Ls(r,e,t){const i=He(r,e),n=t.get(i);if(!n)return;const o=r%e;return n[o]}const Ps=100;class Hs extends D{name="serverSide";get defaultConfig(){return{pageSize:100,cacheBlockSize:100,maxConcurrentRequests:2}}dataSource=null;totalRowCount=0;loadedBlocks=new Map;loadingBlocks=new Set;lastRequestId=0;scrollDebounceTimer;detach(){this.dataSource=null,this.totalRowCount=0,this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.lastRequestId=0,this.scrollDebounceTimer&&(clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=void 0)}loadRequiredBlocks(){if(!this.dataSource)return;const e=this.grid,t=this.config.cacheBlockSize??100,i={startRow:e._virtualization.start,endRow:e._virtualization.end},n=Ts(i.startRow,i.endRow,t);for(const o of n)if(!(this.loadedBlocks.has(o)||this.loadingBlocks.has(o))){if(this.loadingBlocks.size>=(this.config.maxConcurrentRequests??2))break;this.loadingBlocks.add(o),Ni(this.dataSource,o,t,{}).then(s=>{this.loadedBlocks.set(o,s.rows),this.totalRowCount=s.totalRowCount,this.loadingBlocks.delete(o),this.requestRender(),this.loadRequiredBlocks()}).catch(()=>{this.loadingBlocks.delete(o)})}}processRows(e){if(!this.dataSource)return[...e];const t=[];for(let i=0;i<this.totalRowCount;i++){const n=Ls(i,this.config.cacheBlockSize??100,this.loadedBlocks);t.push(n??{__loading:!0,__index:i})}return t}onScroll(e){this.dataSource&&(this.loadRequiredBlocks(),this.scrollDebounceTimer&&clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=setTimeout(()=>{this.loadRequiredBlocks()},Ps))}setDataSource(e){this.dataSource=e,this.loadedBlocks.clear(),this.loadingBlocks.clear();const t=this.config.cacheBlockSize??100;Ni(e,0,t,{}).then(i=>{this.loadedBlocks.set(0,i.rows),this.totalRowCount=i.totalRowCount,this.requestRender()})}refresh(){this.dataSource&&(this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.requestRender())}purgeCache(){this.loadedBlocks.clear()}getTotalRowCount(){return this.totalRowCount}isRowLoaded(e){const t=this.config.cacheBlockSize??100,i=He(e,t);return this.loadedBlocks.has(i)}getLoadedBlockCount(){return this.loadedBlocks.size}}function Oi(r,e,t){return r.id!==void 0?String(r.id):t?`${t}-${e}`:String(e)}function ft(r,e){const t=new Set(r);return t.has(e)?t.delete(e):t.add(e),t}function gt(r,e,t=null,i=0){const n=e.childrenField??"children",o=new Set;for(let s=0;s<r.length;s++){const l=r[s],a=Oi(l,s,t),c=l[n];if(Array.isArray(c)&&c.length>0){o.add(a);const d=gt(c,e,a,i+1);for(const u of d)o.add(u)}}return o}function Ds(){return new Set}function Fi(r,e,t,i=null,n=0){const o=t.childrenField??"children";for(let s=0;s<r.length;s++){const l=r[s],a=Oi(l,s,i);if(a===e)return[a];const c=l[o];if(Array.isArray(c)&&c.length>0){const d=Fi(c,e,t,a,n+1);if(d)return[a,...d]}}return null}function Is(r,e,t,i){const n=Fi(r,e,t);if(!n)return i;const o=new Set(i);for(let s=0;s<n.length-1;s++)o.add(n[s]);return o}function qi(r,e="children"){if(!Array.isArray(r)||r.length===0)return!1;for(const t of r){if(!t)continue;const i=t[e];if(Array.isArray(i)&&i.length>0)return!0}return!1}function Ms(r){if(!Array.isArray(r)||r.length===0)return null;const e=["children","items","nodes","subRows","nested"];for(const t of r)if(!(!t||typeof t!="object"))for(const i of e){const n=t[i];if(Array.isArray(n)&&n.length>0)return i}return null}const zs="@layer tbw-plugins{tbw-grid .cell[data-field=__tbw_expander]{border-inline-end:none!important;padding:0;display:flex;align-items:center;justify-content:flex-start}tbw-grid .header-row .cell[data-field=__tbw_expander]{display:none}tbw-grid .header-row .cell[data-field=__tbw_expander]+.cell{grid-column:1 / 3}tbw-grid .tree-cell-wrapper{display:inline-flex;align-items:center;padding-inline-start:calc(var(--tbw-tree-depth, 0) * var(--tbw-tree-indent-width, var(--tbw-tree-toggle-size, 1.25em)))}tbw-grid .tree-expander{display:flex;align-items:center;justify-content:flex-start;width:100%;height:100%;box-sizing:border-box}tbw-grid .tree-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-tree-toggle-size, 1.25em);height:var(--tbw-tree-toggle-size, 1.25em);flex-shrink:0}tbw-grid .tree-toggle:hover{color:var(--tbw-tree-accent, var(--tbw-color-accent))}tbw-grid .tree-spacer{width:var(--tbw-tree-toggle-size, 1.25em);display:inline-block;flex-shrink:0}tbw-grid .data-grid-row.tbw-tree-slide-in{animation:tbw-tree-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}tbw-grid .data-grid-row.tbw-tree-fade-in{animation:tbw-tree-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-tree-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}@keyframes tbw-tree-fade-in{0%{opacity:0}to{opacity:1}}}";class Ns extends D{static manifest={events:[{type:"tree-state-change",description:"Emitted when tree expansion state changes (toggle, expand all, collapse all)"}],queries:[{type:"canMoveRow",description:"Returns false for rows with children (parent nodes cannot be reordered)"}]};name="tree";styles=zs;get defaultConfig(){return{childrenField:"children",autoDetect:!0,defaultExpanded:!1,indentWidth:20,showExpandIcons:!0,animation:"slide"}}expandedKeys=new Set;initialExpansionDone=!1;flattenedRows=[];rowKeyMap=new Map;previousVisibleKeys=new Set;keysToAnimate=new Set;sortState=null;detach(){this.expandedKeys.clear(),this.initialExpansionDone=!1,this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.sortState=null}handleQuery(e){if(e.type==="canMoveRow"){const t=e.context,i=this.config.childrenField??"children",n=t?.[i];if(Array.isArray(n)&&n.length>0)return!1}}get animationStyle(){return this.isAnimationEnabled?this.config.animation??"slide":!1}detect(e){if(!this.config.autoDetect)return!1;const t=e,i=this.config.childrenField??Ms(t)??"children";return qi(t,i)}processRows(e){const t=this.config.childrenField??"children",i=e;if(!qi(i,t))return this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),[...e];let n=this.withStableKeys(i);this.sortState&&(n=this.sortTree(n,this.sortState.field,this.sortState.direction)),this.config.defaultExpanded&&!this.initialExpansionDone&&(this.expandedKeys=gt(n,this.config),this.initialExpansionDone=!0),this.flattenedRows=this.flattenTree(n,this.expandedKeys),this.rowKeyMap.clear(),this.keysToAnimate.clear();const o=new Set;for(const s of this.flattenedRows)this.rowKeyMap.set(s.key,s),o.add(s.key),!this.previousVisibleKeys.has(s.key)&&s.depth>0&&this.keysToAnimate.add(s.key);return this.previousVisibleKeys=o,this.flattenedRows.map(s=>({...s.data,__treeKey:s.key,__treeDepth:s.depth,__treeHasChildren:s.hasChildren,__treeExpanded:s.isExpanded}))}withStableKeys(e,t=null){const i=this.config.childrenField??"children";return e.map((n,o)=>{const s=n.__stableKey,l=n.id!==void 0?String(n.id):s??(t?`${t}-${o}`:String(o)),a=n[i],c=Array.isArray(a)&&a.length>0;return{...n,__stableKey:l,...c?{[i]:this.withStableKeys(a,l)}:{}}})}flattenTree(e,t,i=0){const n=this.config.childrenField??"children",o=[];for(const s of e){const a=s.__stableKey??String(s.id??"?"),c=s[n],d=Array.isArray(c)&&c.length>0,u=t.has(a);o.push({key:a,data:s,depth:i,hasChildren:d,isExpanded:u,parentKey:i>0&&a.substring(0,a.lastIndexOf("-"))||null}),d&&u&&o.push(...this.flattenTree(c,t,i+1))}return o}sortTree(e,t,i){const n=this.config.childrenField??"children";return[...e].sort((s,l)=>{const a=s[t],c=l[t];return a==null&&c==null?0:a==null?-1:c==null?1:a>c?i:a<c?-i:0}).map(s=>{const l=s[n];return Array.isArray(l)&&l.length>0?{...s,[n]:this.sortTree(l,t,i)}:s})}processColumns(e){if(this.flattenedRows.length===0)return[...e];const t=[...e];if(t.length===0)return t;const i=t[0],n=i.viewRenderer,o=()=>this.config,s=this.setIcon.bind(this),l=this.resolveIcon.bind(this),a=c=>{const{row:d,value:u}=c,{showExpandIcons:h=!0,indentWidth:f}=o(),p=d,g=p.__treeDepth??0,w=document.createElement("span");if(w.className="tree-cell-wrapper",w.style.setProperty("--tbw-tree-depth",String(g)),f!==void 0&&w.style.setProperty("--tbw-tree-indent-width",`${f}px`),h)if(p.__treeHasChildren){const m=document.createElement("span");m.className=`tree-toggle${p.__treeExpanded?" expanded":""}`,s(m,l(p.__treeExpanded?"collapse":"expand")),m.setAttribute("data-tree-key",String(p.__treeKey??"")),w.appendChild(m)}else{const m=document.createElement("span");m.className="tree-spacer",w.appendChild(m)}const b=document.createElement("span");if(b.className="tree-content",n){const m=n(c);m instanceof Node?b.appendChild(m):typeof m=="string"&&(b.innerHTML=m)}else b.textContent=u!=null?String(u):"";return w.appendChild(b),w};return t[0]={...i,viewRenderer:a},t}onCellClick(e){const t=e.originalEvent?.target;if(!t?.classList.contains("tree-toggle"))return!1;const i=t.getAttribute("data-tree-key");if(!i)return!1;const n=this.rowKeyMap.get(i);return n?(this.expandedKeys=ft(this.expandedKeys,i),this.emit("tree-expand",{key:i,row:n.data,expanded:this.expandedKeys.has(i),depth:n.depth}),this.requestRender(),!0):!1}onKeyDown(e){if(e.key!==" ")return;const t=this.grid._focusRow,i=this.flattenedRows[t];if(i?.hasChildren)return e.preventDefault(),this.expandedKeys=ft(this.expandedKeys,i.key),this.emit("tree-expand",{key:i.key,row:i.data,expanded:this.expandedKeys.has(i.key),depth:i.depth}),this.requestRenderWithFocus(),!0}onHeaderClick(e){if(this.flattenedRows.length===0||!e.column.sortable)return!1;const{field:t}=e.column;!this.sortState||this.sortState.field!==t?this.sortState={field:t,direction:1}:this.sortState.direction===1?this.sortState={field:t,direction:-1}:this.sortState=null;const i=this.grid;return i._sortState!==void 0&&(i._sortState=this.sortState?{...this.sortState}:null),this.emit("sort-change",{field:t,direction:this.sortState?.direction??0}),this.requestRender(),!0}afterRender(){const e=this.animationStyle;if(e===!1||this.keysToAnimate.size===0)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const i=e==="fade"?"tbw-tree-fade-in":"tbw-tree-slide-in";for(const n of t.querySelectorAll(".data-grid-row")){const o=n.querySelector(".cell[data-row]"),s=o?parseInt(o.getAttribute("data-row")??"-1",10):-1,l=this.flattenedRows[s]?.key;l&&this.keysToAnimate.has(l)&&(n.classList.add(i),n.addEventListener("animationend",()=>n.classList.remove(i),{once:!0}))}this.keysToAnimate.clear()}expand(e){this.expandedKeys.add(e),this.requestRender()}collapse(e){this.expandedKeys.delete(e),this.requestRender()}toggle(e){this.expandedKeys=ft(this.expandedKeys,e),this.emitPluginEvent("tree-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}expandAll(){this.expandedKeys=gt(this.rows,this.config),this.emitPluginEvent("tree-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}collapseAll(){this.expandedKeys=Ds(),this.emitPluginEvent("tree-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}getExpandedKeys(){return[...this.expandedKeys]}getFlattenedRows(){return[...this.flattenedRows]}getRowByKey(e){return this.rowKeyMap.get(e)?.data}expandToKey(e){this.expandedKeys=Is(this.rows,e,this.config,this.expandedKeys),this.requestRender()}}function Os(r,e,t){const i=[...r.undoStack,e];for(;i.length>t;)i.shift();return{undoStack:i,redoStack:[]}}function Gi(r){if(r.undoStack.length===0)return{newState:r,action:null};const e=[...r.undoStack],t=e.pop();return t?{newState:{undoStack:e,redoStack:[...r.redoStack,t]},action:t}:{newState:r,action:null}}function Bi(r){if(r.redoStack.length===0)return{newState:r,action:null};const e=[...r.redoStack],t=e.pop();return t?{newState:{undoStack:[...r.undoStack,t],redoStack:e},action:t}:{newState:r,action:null}}function Fs(r){return r.undoStack.length>0}function qs(r){return r.redoStack.length>0}function Gs(){return{undoStack:[],redoStack:[]}}function Bs(r,e,t,i){return{type:"cell-edit",rowIndex:r,field:e,oldValue:t,newValue:i,timestamp:Date.now()}}class Ks extends D{static dependencies=[{name:"editing",required:!0,reason:"UndoRedoPlugin tracks cell edit history"}];name="undoRedo";get defaultConfig(){return{maxHistorySize:100}}undoStack=[];redoStack=[];attach(e){super.attach(e),this.on("cell-edit-committed",t=>{this.recordEdit(t.rowIndex,t.field,t.oldValue,t.newValue)})}detach(){this.undoStack=[],this.redoStack=[]}onKeyDown(e){const t=(e.ctrlKey||e.metaKey)&&e.key==="z"&&!e.shiftKey,i=(e.ctrlKey||e.metaKey)&&(e.key==="y"||e.key==="z"&&e.shiftKey);if(t){const n=Gi({undoStack:this.undoStack,redoStack:this.redoStack});if(n.action){const o=this.rows;o[n.action.rowIndex]&&(o[n.action.rowIndex][n.action.field]=n.action.oldValue),this.undoStack=n.newState.undoStack,this.redoStack=n.newState.redoStack,this.emit("undo",{action:n.action,type:"undo"}),this.requestRender()}return!0}if(i){const n=Bi({undoStack:this.undoStack,redoStack:this.redoStack});if(n.action){const o=this.rows;o[n.action.rowIndex]&&(o[n.action.rowIndex][n.action.field]=n.action.newValue),this.undoStack=n.newState.undoStack,this.redoStack=n.newState.redoStack,this.emit("redo",{action:n.action,type:"redo"}),this.requestRender()}return!0}return!1}recordEdit(e,t,i,n){const o=Bs(e,t,i,n),s=Os({undoStack:this.undoStack,redoStack:this.redoStack},o,this.config.maxHistorySize??100);this.undoStack=s.undoStack,this.redoStack=s.redoStack}undo(){const e=Gi({undoStack:this.undoStack,redoStack:this.redoStack});if(e.action){const t=this.rows;t[e.action.rowIndex]&&(t[e.action.rowIndex][e.action.field]=e.action.oldValue),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.requestRender()}return e.action}redo(){const e=Bi({undoStack:this.undoStack,redoStack:this.redoStack});if(e.action){const t=this.rows;t[e.action.rowIndex]&&(t[e.action.rowIndex][e.action.field]=e.action.newValue),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.requestRender()}return e.action}canUndo(){return Fs({undoStack:this.undoStack,redoStack:this.redoStack})}canRedo(){return qs({undoStack:this.undoStack,redoStack:this.redoStack})}clearHistory(){const e=Gs();this.undoStack=e.undoStack,this.redoStack=e.redoStack}getUndoStack(){return[...this.undoStack]}getRedoStack(){return[...this.redoStack]}}const $s='@layer tbw-plugins{.tbw-visibility-content{display:flex;flex-direction:column;height:100%}.tbw-visibility-list{flex:1;overflow-y:auto;padding:var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem))}.tbw-visibility-row{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding:var(--tbw-menu-item-padding, .375rem .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem);border-radius:var(--tbw-border-radius, .25rem);position:relative}.tbw-visibility-row:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover))}.tbw-visibility-row input[type=checkbox]{cursor:pointer}.tbw-visibility-row.locked span{color:var(--tbw-color-fg-muted)}.tbw-visibility-handle{cursor:grab;color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-2xs, .625rem);letter-spacing:-2px;-webkit-user-select:none;user-select:none;flex-shrink:0}.tbw-visibility-row.reorderable:hover .tbw-visibility-handle{color:var(--tbw-color-fg)}.tbw-visibility-label{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));flex:1;cursor:pointer}.tbw-visibility-row.dragging{opacity:.5;cursor:grabbing}.tbw-visibility-row.drop-before:before{content:"";position:absolute;left:0;right:0;top:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-row.drop-after:after{content:"";position:absolute;left:0;right:0;bottom:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-show-all{margin:var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem));padding:var(--tbw-button-padding, .5rem .75rem);border:1px solid var(--tbw-visibility-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius, .25rem);background:var(--tbw-visibility-btn-bg, var(--tbw-color-header-bg));color:var(--tbw-color-fg);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem)}.tbw-visibility-show-all:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover))}}';function Ki(r){const e=r.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}class Q extends D{static dependencies=[{name:"reorder",required:!1,reason:"Enables drag-to-reorder columns in visibility panel"}];name="visibility";static PANEL_ID="columns";styles=$s;get defaultConfig(){return{allowHideAll:!1}}columnListElement=null;isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;clearDragClasses(e){e.querySelectorAll(".tbw-visibility-row").forEach(t=>{t.classList.remove("dragging","drop-target","drop-before","drop-after")})}detach(){this.columnListElement=null,this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null}getToolPanel(){return{id:Q.PANEL_ID,title:"Columns",icon:"☰",tooltip:"Column visibility",order:100,render:e=>this.renderPanelContent(e)}}show(){this.grid.openToolPanel(),this.grid.expandedToolPanelSections.includes(Q.PANEL_ID)||this.grid.toggleToolPanelSection(Q.PANEL_ID)}hide(){this.grid.closeToolPanel()}toggle(){this.grid.isToolPanelOpen||this.grid.openToolPanel(),this.grid.toggleToolPanelSection(Q.PANEL_ID)}isColumnVisible(e){return this.grid.isColumnVisible(e)}setColumnVisible(e,t){this.grid.setColumnVisible(e,t)}getVisibleColumns(){return this.grid.getAllColumns().filter(e=>e.visible).map(e=>e.field)}getHiddenColumns(){return this.grid.getAllColumns().filter(e=>!e.visible).map(e=>e.field)}showAll(){this.grid.showAllColumns()}toggleColumn(e){this.grid.toggleColumnVisibility(e)}showColumn(e){this.setColumnVisible(e,!0)}hideColumn(e){this.setColumnVisible(e,!1)}getAllColumns(){return this.grid.getAllColumns()}isPanelVisible(){return this.grid.isToolPanelOpen&&this.grid.expandedToolPanelSections.includes(Q.PANEL_ID)}renderPanelContent(e){const t=document.createElement("div");t.className="tbw-visibility-content";const i=document.createElement("div");i.className="tbw-visibility-list",t.appendChild(i);const n=document.createElement("button");return n.className="tbw-visibility-show-all",n.textContent="Show All",n.addEventListener("click",()=>{this.grid.showAllColumns(),this.rebuildToggles(i)}),t.appendChild(n),this.columnListElement=i,this.rebuildToggles(i),e.appendChild(t),()=>{this.columnListElement=null,t.remove()}}hasReorderPlugin(){const e=this.grid?.getPluginByName?.("reorder");return!!(e&&typeof e.moveColumn=="function")}rebuildToggles(e){const t=this.hasReorderPlugin();e.innerHTML="";const i=this.grid.getAllColumns().filter(n=>!n.utility);for(let n=0;n<i.length;n++){const o=i[n],s=o.header||o.field,l=document.createElement("div");l.className=o.lockVisible?"tbw-visibility-row locked":"tbw-visibility-row",l.setAttribute("data-field",o.field),l.setAttribute("data-index",String(n)),t&&Ki(o)&&(l.draggable=!0,l.classList.add("reorderable"),this.setupDragListeners(l,o.field,n,e));const a=document.createElement("label");a.className="tbw-visibility-label";const c=document.createElement("input");c.type="checkbox",c.checked=o.visible,c.disabled=o.lockVisible??!1,c.addEventListener("change",()=>{this.grid.toggleColumnVisibility(o.field),setTimeout(()=>this.rebuildToggles(e),0)});const d=document.createElement("span");if(d.textContent=s,a.appendChild(c),a.appendChild(d),t&&Ki(o)){const u=document.createElement("span");u.className="tbw-visibility-handle",this.setIcon(u,this.resolveIcon("dragHandle")),u.title="Drag to reorder",l.appendChild(u)}l.appendChild(a),e.appendChild(l)}}setupDragListeners(e,t,i,n){e.addEventListener("dragstart",o=>{this.isDragging=!0,this.draggedField=t,this.draggedIndex=i,o.dataTransfer&&(o.dataTransfer.effectAllowed="move",o.dataTransfer.setData("text/plain",t)),e.classList.add("dragging")}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.clearDragClasses(n)}),e.addEventListener("dragover",o=>{if(o.preventDefault(),!this.isDragging||this.draggedField===t)return;const s=e.getBoundingClientRect(),l=s.top+s.height/2;this.dropIndex=o.clientY<l?i:i+1,n.querySelectorAll(".tbw-visibility-row").forEach(a=>{a!==e&&a.classList.remove("drop-target","drop-before","drop-after")}),e.classList.add("drop-target"),e.classList.toggle("drop-before",o.clientY<l),e.classList.toggle("drop-after",o.clientY>=l)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",o=>{o.preventDefault();const s=this.draggedField,l=this.draggedIndex,a=this.dropIndex;if(!this.isDragging||s===null||l===null||a===null)return;const c=a>l?a-1:a;if(c!==l){const d=this.grid.getAllColumns(),h=d.filter(g=>!g.utility)[c]?.field,f=h?d.findIndex(g=>g.field===h):d.length,p={field:s,fromIndex:l,toIndex:f};this.emit("column-reorder-request",p),setTimeout(()=>{this.rebuildToggles(n)},0)}})}}E.BaseGridPlugin=D,E.ClipboardPlugin=Or,E.ColumnVirtualizationPlugin=Br,E.ContextMenuPlugin=nt,E.DEFAULT_ANIMATION_CONFIG=pt,E.DEFAULT_GRID_ICONS=G,E.DGEvents=Hr,E.DataGridElement=K,E.EditingPlugin=to,E.ExportPlugin=so,E.FilteringPlugin=W,E.FitModeEnum=ee,E.GridCSSVars=Tr,E.GridClasses=z,E.GridDataAttrs=he,E.GridElement=K,E.GridSelectors=kr,E.GroupingColumnsPlugin=mo,E.GroupingRowsPlugin=_o,E.MasterDetailPlugin=lt,E.MultiSortPlugin=zo,E.PLUGIN_QUERIES=Ar,E.PinnedColumnsPlugin=Fo,E.PinnedRowsPlugin=Ko,E.PivotPlugin=Z,E.PluginEvents=Dr,E.PluginManager=ue,E.PrintPlugin=hs,E.ROW_DRAG_HANDLE_FIELD=Ii,E.RenderPhase=I,E.ReorderPlugin=ps,E.ResponsivePlugin=ms,E.RowReorderPlugin=vs,E.SelectionPlugin=As,E.ServerSidePlugin=Hs,E.TreePlugin=Ns,E.UndoRedoPlugin=Ks,E.VisibilityPlugin=Q,E.builtInSort=Pt,E.createGrid=Lr,E.defaultComparator=Lt,E.defaultEditorFor=li,E.defaultPasteHandler=ti,E.printGridIsolated=Hi,E.queryGrid=Pr,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})}));
|
|
186
|
+
→ The "triggerOn" option only affects "cell" and "row" selection modes.`,check:e=>e.mode==="range"&&e.triggerOn==="dblclick"}]};name="selection";styles=Hs;get defaultConfig(){return{mode:"cell",triggerOn:"click",enabled:!0}}selected=new Set;lastSelected=null;anchor=null;ranges=[];activeRange=null;cellAnchor=null;isDragging=!1;pendingKeyboardUpdate=null;selectedCell=null;lastSyncedFocusRow=-1;lastSyncedFocusCol=-1;explicitSelection=!1;isSelectionEnabled(){return this.config.enabled===!1?!1:this.grid.effectiveConfig?.selectable!==!1}checkSelectable(e,t){const{isSelectable:i}=this.config;if(!i)return!0;const n=this.rows[e];if(!n)return!1;const o=t!==void 0?this.columns[t]:void 0;return i(n,e,o,t)}isRowSelectable(e){return this.checkSelectable(e)}isCellSelectable(e,t){return this.checkSelectable(e,t)}attach(e){super.attach(e),this.on("filter-applied",()=>this.clearSelectionSilent()),this.on("grouping-state-change",()=>this.clearSelectionSilent()),this.on("tree-state-change",()=>this.clearSelectionSilent())}handleQuery(e){if(e.type==="getSelection")return this.getSelection();if(e.type==="getSelectedRowIndices")return this.getSelectedRowIndices();if(e.type==="selectRows")return this.selectRows(e.context),!0}detach(){this.selected.clear(),this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.isDragging=!1,this.selectedCell=null,this.pendingKeyboardUpdate=null,this.lastSyncedFocusRow=-1,this.lastSyncedFocusCol=-1}clearSelectionSilent(){this.selected.clear(),this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.selectedCell=null,this.lastSelected=null,this.anchor=null,this.lastSyncedFocusRow=-1,this.lastSyncedFocusCol=-1,this.requestAfterRender()}onCellClick(e){if(!this.isSelectionEnabled())return!1;const{rowIndex:t,colIndex:i,originalEvent:n}=e,{mode:o,triggerOn:s="click"}=this.config;if(n.type!==s)return!1;const l=this.columns[i],a=l&&ne(l);if(o==="cell"){if(a||!this.isCellSelectable(t,i))return!1;const c=this.selectedCell;return c&&c.row===t&&c.col===i||(this.selectedCell={row:t,col:i},this.emit("selection-change",this.#n()),this.requestAfterRender()),!1}if(o==="row"){if(!this.isRowSelectable(t))return!1;const c=n.shiftKey,d=n.ctrlKey||n.metaKey,u=l?.meta?.checkboxColumn===!0;if(c&&this.anchor!==null){const h=Math.min(this.anchor,t),f=Math.max(this.anchor,t);d||this.selected.clear();for(let p=h;p<=f;p++)this.isRowSelectable(p)&&this.selected.add(p)}else if(d||u)this.selected.has(t)?this.selected.delete(t):this.selected.add(t),this.anchor=t;else{if(this.selected.size===1&&this.selected.has(t))return!1;this.selected.clear(),this.selected.add(t),this.anchor=t}return this.lastSelected=t,this.explicitSelection=!0,this.emit("selection-change",this.#n()),this.requestAfterRender(),!1}if(o==="range"){if(a||!this.isCellSelectable(t,i))return!1;const c=n.shiftKey,d=n.ctrlKey||n.metaKey;if(c&&this.cellAnchor){const u=ft(this.cellAnchor,{row:t,col:i}),h=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;if(h&&He(h,u))return!1;d?this.ranges.length>0?this.ranges[this.ranges.length-1]=u:this.ranges.push(u):this.ranges=[u],this.activeRange=u}else if(d){const u={startRow:t,startCol:i,endRow:t,endCol:i};this.ranges.push(u),this.activeRange=u,this.cellAnchor={row:t,col:i}}else{const u={startRow:t,startCol:i,endRow:t,endCol:i};if(this.ranges.length===1&&He(this.ranges[0],u))return!1;this.ranges=[u],this.activeRange=u,this.cellAnchor={row:t,col:i}}return this.emit("selection-change",this.#n()),this.requestAfterRender(),!1}return!1}onKeyDown(e){if(!this.isSelectionEnabled())return!1;const{mode:t}=this.config,n=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Tab","Home","End","PageUp","PageDown"].includes(e.key);if(e.key==="Escape")return this.grid.query("isEditing").some(Boolean)?!1:(t==="cell"?this.selectedCell=null:t==="row"?(this.selected.clear(),this.anchor=null):t==="range"&&(this.ranges=[],this.activeRange=null,this.cellAnchor=null),this.emit("selection-change",this.#n()),this.requestAfterRender(),!0);if(t==="cell"&&n)return queueMicrotask(()=>{const o=this.grid._focusRow,s=this.grid._focusCol;this.isCellSelectable(o,s)?this.selectedCell={row:o,col:s}:this.selectedCell=null,this.emit("selection-change",this.#n()),this.requestAfterRender()}),!1;if(t==="row"){if(e.key==="ArrowUp"||e.key==="ArrowDown"){const o=e.shiftKey;return o&&this.anchor===null&&(this.anchor=this.grid._focusRow),queueMicrotask(()=>{const s=this.grid._focusRow;if(o&&this.anchor!==null){this.selected.clear();const l=Math.min(this.anchor,s),a=Math.max(this.anchor,s);for(let c=l;c<=a;c++)this.isRowSelectable(c)&&this.selected.add(c)}else this.isRowSelectable(s)?(this.selected.clear(),this.selected.add(s),this.anchor=s):this.selected.clear();this.lastSelected=s,this.explicitSelection=!0,this.emit("selection-change",this.#n()),this.requestAfterRender()}),!1}if(e.key==="a"&&(e.ctrlKey||e.metaKey))return e.preventDefault(),e.stopPropagation(),this.selectAll(),!0}if(t==="range"&&n){const o=e.key==="Tab",s=e.shiftKey&&!o;return s&&!this.cellAnchor&&(this.cellAnchor={row:this.grid._focusRow,col:this.grid._focusCol}),this.pendingKeyboardUpdate={shiftKey:s},queueMicrotask(()=>this.requestAfterRender()),!1}return t==="range"&&e.key==="a"&&(e.ctrlKey||e.metaKey)?(e.preventDefault(),e.stopPropagation(),this.selectAll(),!0):!1}onCellMouseDown(e){if(!this.isSelectionEnabled()||this.config.mode!=="range"||e.rowIndex===void 0||e.colIndex===void 0||e.rowIndex<0)return;const t=this.columns[e.colIndex];if(t&&ne(t)||!this.isCellSelectable(e.rowIndex,e.colIndex)||e.originalEvent.shiftKey&&this.cellAnchor)return;this.isDragging=!0;const i=e.rowIndex,n=e.colIndex,o=e.originalEvent.ctrlKey||e.originalEvent.metaKey,s={startRow:i,startCol:n,endRow:i,endCol:n};return!o&&this.ranges.length===1&&He(this.ranges[0],s)?(this.cellAnchor={row:i,col:n},!0):(this.cellAnchor={row:i,col:n},o||(this.ranges=[]),this.ranges.push(s),this.activeRange=s,this.emit("selection-change",this.#n()),this.requestAfterRender(),!0)}onCellMouseMove(e){if(!this.isSelectionEnabled()||this.config.mode!=="range"||!this.isDragging||!this.cellAnchor||e.rowIndex===void 0||e.colIndex===void 0||e.rowIndex<0)return;let t=e.colIndex;const i=this.columns[t];if(i&&ne(i)){const s=this.columns.findIndex(l=>!ne(l));s>=0&&(t=s)}const n=ft(this.cellAnchor,{row:e.rowIndex,col:t}),o=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;return o&&He(o,n)||(this.ranges.length>0?this.ranges[this.ranges.length-1]=n:this.ranges.push(n),this.activeRange=n,this.emit("selection-change",this.#n()),this.requestAfterRender()),!0}onCellMouseUp(e){if(this.isSelectionEnabled()&&this.config.mode==="range"&&this.isDragging)return this.isDragging=!1,!0}processColumns(e){if(this.config.checkbox&&this.config.mode==="row"){if(e.some(o=>o.field===Oi))return e;const t=this.#t(),i=e.findIndex(Le),n=i>=0?i+1:0;return[...e.slice(0,n),t,...e.slice(n)]}return e}#t(){return{field:Oi,header:"",width:32,resizable:!1,sortable:!1,meta:{lockPosition:!0,suppressMovable:!0,utility:!0,checkboxColumn:!0},headerRenderer:()=>{const e=document.createElement("div");e.className="tbw-checkbox-header";const t=document.createElement("input");return t.type="checkbox",t.className="tbw-select-all-checkbox",t.addEventListener("click",i=>{i.stopPropagation(),i.target.checked?this.selectAll():this.clearSelection()}),e.appendChild(t),e},renderer:e=>{const t=document.createElement("input");t.type="checkbox",t.className="tbw-select-row-checkbox";const i=e.cellEl;if(i){const n=parseInt(i.getAttribute("data-row")??"-1",10);n>=0&&(t.checked=this.selected.has(n))}return t}}}#e(e){e.querySelectorAll(".tbw-select-row-checkbox").forEach(n=>{const o=n.closest(".cell"),s=o?me(o):-1;s>=0&&(n.checked=this.selected.has(s))});const i=e.querySelector(".tbw-select-all-checkbox");if(i){const n=this.rows.length;let o=0;if(this.config.isSelectable)for(let a=0;a<n;a++)this.isRowSelectable(a)&&o++;else o=n;const s=o>0&&this.selected.size>=o,l=this.selected.size>0;i.checked=s,i.indeterminate=l&&!s}}#u(e){const t=this.grid._focusRow,i=this.grid._focusCol;if(e==="row"){if(this.explicitSelection){this.explicitSelection=!1,this.lastSyncedFocusRow=t;return}t!==this.lastSyncedFocusRow&&(this.lastSyncedFocusRow=t,this.isRowSelectable(t)&&(!this.selected.has(t)||this.selected.size!==1)&&(this.selected.clear(),this.selected.add(t),this.lastSelected=t,this.anchor=t,this.emit("selection-change",this.#n())))}if(e==="cell"){if(this.explicitSelection){this.explicitSelection=!1,this.lastSyncedFocusRow=t,this.lastSyncedFocusCol=i;return}if((t!==this.lastSyncedFocusRow||i!==this.lastSyncedFocusCol)&&(this.lastSyncedFocusRow=t,this.lastSyncedFocusCol=i,this.isCellSelectable(t,i))){const n=this.selectedCell;(!n||n.row!==t||n.col!==i)&&(this.selectedCell={row:t,col:i},this.emit("selection-change",this.#n()))}}}#c(){const e=this.gridElement;if(!e)return;const{mode:t}=this.config,i=!!this.config.isSelectable;e.querySelectorAll(".cell").forEach(s=>{s.classList.remove("selected","top","bottom","first","last"),i&&s.removeAttribute("data-selectable")});const o=e.querySelectorAll(".data-grid-row");if(o.forEach(s=>{s.classList.remove("selected","row-focus"),i&&s.removeAttribute("data-selectable")}),t==="row"&&(ae(e),o.forEach(s=>{const l=s.querySelector(".cell[data-row]"),a=me(l);a>=0&&(i&&!this.isRowSelectable(a)&&s.setAttribute("data-selectable","false"),this.selected.has(a)&&s.classList.add("selected","row-focus"))}),this.config.checkbox&&this.#e(e)),(t==="cell"||t==="range")&&i&&e.querySelectorAll(".cell[data-row][data-col]").forEach(l=>{const a=parseInt(l.getAttribute("data-row")??"-1",10),c=parseInt(l.getAttribute("data-col")??"-1",10);a>=0&&c>=0&&(this.isCellSelectable(a,c)||l.setAttribute("data-selectable","false"))}),t==="range"&&this.ranges.length>0){ae(e);const s=this.ranges.map(re),l=(c,d)=>{for(const u of s)if(c>=u.startRow&&c<=u.endRow&&d>=u.startCol&&d<=u.endCol)return!0;return!1};e.querySelectorAll(".cell[data-row][data-col]").forEach(c=>{const d=parseInt(c.getAttribute("data-row")??"-1",10),u=parseInt(c.getAttribute("data-col")??"-1",10);if(d>=0&&u>=0){const h=this.columns[u];if(h&&ne(h))return;l(d,u)&&(c.classList.add("selected"),l(d-1,u)||c.classList.add("top"),l(d+1,u)||c.classList.add("bottom"),l(d,u-1)||c.classList.add("first"),l(d,u+1)||c.classList.add("last"))}})}}afterRender(){if(!this.isSelectionEnabled())return;const e=this.gridElement;if(!e)return;const t=e.children[0],{mode:i}=this.config;if(this.pendingKeyboardUpdate&&i==="range"){const{shiftKey:n}=this.pendingKeyboardUpdate;this.pendingKeyboardUpdate=null;const o=this.grid._focusRow,s=this.grid._focusCol;if(n&&this.cellAnchor){const l=ft(this.cellAnchor,{row:o,col:s});this.ranges=[l],this.activeRange=l}else n||(this.ranges=[],this.activeRange=null,this.cellAnchor={row:o,col:s});this.emit("selection-change",this.#n())}this.#u(i),this.grid.setAttribute("data-selection-mode",i),t&&t.classList.toggle("selecting",this.isDragging),this.#c()}onScrollRender(){this.isSelectionEnabled()&&this.#c()}getSelection(){return{mode:this.config.mode,ranges:this.#n().ranges,anchor:this.cellAnchor}}getSelectedCells(){return Ps(this.ranges)}isCellSelected(e,t){return Ts(e,t,this.ranges)}selectAll(){const{mode:e}=this.config;if(e==="row"){this.selected.clear();for(let t=0;t<this.rows.length;t++)this.isRowSelectable(t)&&this.selected.add(t);this.explicitSelection=!0,this.emit("selection-change",this.#n()),this.requestAfterRender()}else if(e==="range"){const t=this.rows.length,i=this.columns.length;if(t>0&&i>0){const n={startRow:0,startCol:0,endRow:t-1,endCol:i-1};this.ranges=[n],this.activeRange=n,this.emit("selection-change",this.#n()),this.requestAfterRender()}}}selectRows(e){if(this.config.mode==="row"){this.selected.clear();for(const t of e)t>=0&&t<this.rows.length&&this.isRowSelectable(t)&&this.selected.add(t);this.anchor=e.length>0?e[e.length-1]:null,this.explicitSelection=!0,this.emit("selection-change",this.#n()),this.requestAfterRender()}}getSelectedRowIndices(){return[...this.selected].sort((e,t)=>e-t)}clearSelection(){this.selectedCell=null,this.selected.clear(),this.anchor=null,this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.emit("selection-change",{mode:this.config.mode,ranges:[]}),this.requestAfterRender()}setRanges(e){this.ranges=e.map(t=>({startRow:t.from.row,startCol:t.from.col,endRow:t.to.row,endCol:t.to.col})),this.activeRange=this.ranges.length>0?this.ranges[this.ranges.length-1]:null,this.emit("selection-change",{mode:this.config.mode,ranges:Ni(this.ranges)}),this.requestAfterRender()}#n(){return Ds(this.config.mode,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges},this.columns.length)}}function De(r,e){return Math.floor(r/e)}function Is(r,e){return{start:r*e,end:(r+1)*e}}function zs(r,e,t){const i=De(r,t),n=De(e-1,t),o=[];for(let s=i;s<=n;s++)o.push(s);return o}async function Fi(r,e,t,i){const n=Is(e,t);return r.getRows({startRow:n.start,endRow:n.end,sortModel:i.sortModel,filterModel:i.filterModel})}function Ns(r,e,t){const i=De(r,e),n=t.get(i);if(!n)return;const o=r%e;return n[o]}const Os=100;class Fs extends D{name="serverSide";get defaultConfig(){return{pageSize:100,cacheBlockSize:100,maxConcurrentRequests:2}}dataSource=null;totalRowCount=0;loadedBlocks=new Map;loadingBlocks=new Set;lastRequestId=0;scrollDebounceTimer;detach(){this.dataSource=null,this.totalRowCount=0,this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.lastRequestId=0,this.scrollDebounceTimer&&(clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=void 0)}loadRequiredBlocks(){if(!this.dataSource)return;const e=this.grid,t=this.config.cacheBlockSize??100,i={startRow:e._virtualization.start,endRow:e._virtualization.end},n=zs(i.startRow,i.endRow,t);for(const o of n)if(!(this.loadedBlocks.has(o)||this.loadingBlocks.has(o))){if(this.loadingBlocks.size>=(this.config.maxConcurrentRequests??2))break;this.loadingBlocks.add(o),Fi(this.dataSource,o,t,{}).then(s=>{this.loadedBlocks.set(o,s.rows),this.totalRowCount=s.totalRowCount,this.loadingBlocks.delete(o),this.requestRender(),this.loadRequiredBlocks()}).catch(()=>{this.loadingBlocks.delete(o)})}}processRows(e){if(!this.dataSource)return[...e];const t=[];for(let i=0;i<this.totalRowCount;i++){const n=Ns(i,this.config.cacheBlockSize??100,this.loadedBlocks);t.push(n??{__loading:!0,__index:i})}return t}onScroll(e){this.dataSource&&(this.loadRequiredBlocks(),this.scrollDebounceTimer&&clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=setTimeout(()=>{this.loadRequiredBlocks()},Os))}setDataSource(e){this.dataSource=e,this.loadedBlocks.clear(),this.loadingBlocks.clear();const t=this.config.cacheBlockSize??100;Fi(e,0,t,{}).then(i=>{this.loadedBlocks.set(0,i.rows),this.totalRowCount=i.totalRowCount,this.requestRender()})}refresh(){this.dataSource&&(this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.requestRender())}purgeCache(){this.loadedBlocks.clear()}getTotalRowCount(){return this.totalRowCount}isRowLoaded(e){const t=this.config.cacheBlockSize??100,i=De(e,t);return this.loadedBlocks.has(i)}getLoadedBlockCount(){return this.loadedBlocks.size}}function qi(r,e,t){return r.id!==void 0?String(r.id):t?`${t}-${e}`:String(e)}function gt(r,e){const t=new Set(r);return t.has(e)?t.delete(e):t.add(e),t}function pt(r,e,t=null,i=0){const n=e.childrenField??"children",o=new Set;for(let s=0;s<r.length;s++){const l=r[s],a=qi(l,s,t),c=l[n];if(Array.isArray(c)&&c.length>0){o.add(a);const d=pt(c,e,a,i+1);for(const u of d)o.add(u)}}return o}function qs(){return new Set}function Gi(r,e,t,i=null,n=0){const o=t.childrenField??"children";for(let s=0;s<r.length;s++){const l=r[s],a=qi(l,s,i);if(a===e)return[a];const c=l[o];if(Array.isArray(c)&&c.length>0){const d=Gi(c,e,t,a,n+1);if(d)return[a,...d]}}return null}function Gs(r,e,t,i){const n=Gi(r,e,t);if(!n)return i;const o=new Set(i);for(let s=0;s<n.length-1;s++)o.add(n[s]);return o}function $i(r,e="children"){if(!Array.isArray(r)||r.length===0)return!1;for(const t of r){if(!t)continue;const i=t[e];if(Array.isArray(i)&&i.length>0)return!0}return!1}function $s(r){if(!Array.isArray(r)||r.length===0)return null;const e=["children","items","nodes","subRows","nested"];for(const t of r)if(!(!t||typeof t!="object"))for(const i of e){const n=t[i];if(Array.isArray(n)&&n.length>0)return i}return null}const Bs="@layer tbw-plugins{tbw-grid .cell[data-field=__tbw_expander]{border-inline-end:none!important;padding:0;display:flex;align-items:center;justify-content:flex-start}tbw-grid .header-row .cell[data-field=__tbw_expander]{display:none}tbw-grid .header-row .cell[data-field=__tbw_expander]+.cell{grid-column:1 / 3}tbw-grid .tree-cell-wrapper{display:inline-flex;align-items:center;padding-inline-start:calc(var(--tbw-tree-depth, 0) * var(--tbw-tree-indent-width, var(--tbw-tree-toggle-size, 1.25em)))}tbw-grid .tree-expander{display:flex;align-items:center;justify-content:flex-start;width:100%;height:100%;box-sizing:border-box}tbw-grid .tree-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-tree-toggle-size, 1.25em);height:var(--tbw-tree-toggle-size, 1.25em);flex-shrink:0}tbw-grid .tree-toggle:hover{color:var(--tbw-tree-accent, var(--tbw-color-accent))}tbw-grid .tree-spacer{width:var(--tbw-tree-toggle-size, 1.25em);display:inline-block;flex-shrink:0}tbw-grid .data-grid-row.tbw-tree-slide-in{animation:tbw-tree-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}tbw-grid .data-grid-row.tbw-tree-fade-in{animation:tbw-tree-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-tree-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}@keyframes tbw-tree-fade-in{0%{opacity:0}to{opacity:1}}}";class Ks extends D{static manifest={events:[{type:"tree-state-change",description:"Emitted when tree expansion state changes (toggle, expand all, collapse all)"}],queries:[{type:"canMoveRow",description:"Returns false for rows with children (parent nodes cannot be reordered)"}]};name="tree";styles=Bs;get defaultConfig(){return{childrenField:"children",autoDetect:!0,defaultExpanded:!1,indentWidth:20,showExpandIcons:!0,animation:"slide"}}expandedKeys=new Set;initialExpansionDone=!1;flattenedRows=[];rowKeyMap=new Map;previousVisibleKeys=new Set;keysToAnimate=new Set;sortState=null;detach(){this.expandedKeys.clear(),this.initialExpansionDone=!1,this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.sortState=null}handleQuery(e){if(e.type==="canMoveRow"){const t=e.context,i=this.config.childrenField??"children",n=t?.[i];if(Array.isArray(n)&&n.length>0)return!1}}get animationStyle(){return this.isAnimationEnabled?this.config.animation??"slide":!1}detect(e){if(!this.config.autoDetect)return!1;const t=e,i=this.config.childrenField??$s(t)??"children";return $i(t,i)}processRows(e){const t=this.config.childrenField??"children",i=e;if(!$i(i,t))return this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),[...e];let n=this.withStableKeys(i);this.sortState&&(n=this.sortTree(n,this.sortState.field,this.sortState.direction)),this.config.defaultExpanded&&!this.initialExpansionDone&&(this.expandedKeys=pt(n,this.config),this.initialExpansionDone=!0),this.flattenedRows=this.flattenTree(n,this.expandedKeys),this.rowKeyMap.clear(),this.keysToAnimate.clear();const o=new Set;for(const s of this.flattenedRows)this.rowKeyMap.set(s.key,s),o.add(s.key),!this.previousVisibleKeys.has(s.key)&&s.depth>0&&this.keysToAnimate.add(s.key);return this.previousVisibleKeys=o,this.flattenedRows.map(s=>({...s.data,__treeKey:s.key,__treeDepth:s.depth,__treeHasChildren:s.hasChildren,__treeExpanded:s.isExpanded}))}withStableKeys(e,t=null){const i=this.config.childrenField??"children";return e.map((n,o)=>{const s=n.__stableKey,l=n.id!==void 0?String(n.id):s??(t?`${t}-${o}`:String(o)),a=n[i],c=Array.isArray(a)&&a.length>0;return{...n,__stableKey:l,...c?{[i]:this.withStableKeys(a,l)}:{}}})}flattenTree(e,t,i=0){const n=this.config.childrenField??"children",o=[];for(const s of e){const a=s.__stableKey??String(s.id??"?"),c=s[n],d=Array.isArray(c)&&c.length>0,u=t.has(a);o.push({key:a,data:s,depth:i,hasChildren:d,isExpanded:u,parentKey:i>0&&a.substring(0,a.lastIndexOf("-"))||null}),d&&u&&o.push(...this.flattenTree(c,t,i+1))}return o}sortTree(e,t,i){const n=this.config.childrenField??"children";return[...e].sort((s,l)=>{const a=s[t],c=l[t];return a==null&&c==null?0:a==null?-1:c==null?1:a>c?i:a<c?-i:0}).map(s=>{const l=s[n];return Array.isArray(l)&&l.length>0?{...s,[n]:this.sortTree(l,t,i)}:s})}processColumns(e){if(this.flattenedRows.length===0)return[...e];const t=[...e];if(t.length===0)return t;const i=t[0],n=i.viewRenderer,o=()=>this.config,s=this.setIcon.bind(this),l=this.resolveIcon.bind(this),a=c=>{const{row:d,value:u}=c,{showExpandIcons:h=!0,indentWidth:f}=o(),p=d,g=p.__treeDepth??0,w=document.createElement("span");if(w.className="tree-cell-wrapper",w.style.setProperty("--tbw-tree-depth",String(g)),f!==void 0&&w.style.setProperty("--tbw-tree-indent-width",`${f}px`),h)if(p.__treeHasChildren){const v=document.createElement("span");v.className=`tree-toggle${p.__treeExpanded?" expanded":""}`,s(v,l(p.__treeExpanded?"collapse":"expand")),v.setAttribute("data-tree-key",String(p.__treeKey??"")),w.appendChild(v)}else{const v=document.createElement("span");v.className="tree-spacer",w.appendChild(v)}const y=document.createElement("span");if(y.className="tree-content",n){const v=n(c);v instanceof Node?y.appendChild(v):typeof v=="string"&&(y.innerHTML=v)}else y.textContent=u!=null?String(u):"";return w.appendChild(y),w};return t[0]={...i,viewRenderer:a},t}onCellClick(e){const t=e.originalEvent?.target;if(!t?.classList.contains("tree-toggle"))return!1;const i=t.getAttribute("data-tree-key");if(!i)return!1;const n=this.rowKeyMap.get(i);return n?(this.expandedKeys=gt(this.expandedKeys,i),this.emit("tree-expand",{key:i,row:n.data,expanded:this.expandedKeys.has(i),depth:n.depth}),this.requestRender(),!0):!1}onKeyDown(e){if(e.key!==" ")return;const t=this.grid._focusRow,i=this.flattenedRows[t];if(i?.hasChildren)return e.preventDefault(),this.expandedKeys=gt(this.expandedKeys,i.key),this.emit("tree-expand",{key:i.key,row:i.data,expanded:this.expandedKeys.has(i.key),depth:i.depth}),this.requestRenderWithFocus(),!0}onHeaderClick(e){if(this.flattenedRows.length===0||!e.column.sortable)return!1;const{field:t}=e.column;!this.sortState||this.sortState.field!==t?this.sortState={field:t,direction:1}:this.sortState.direction===1?this.sortState={field:t,direction:-1}:this.sortState=null;const i=this.grid;return i._sortState!==void 0&&(i._sortState=this.sortState?{...this.sortState}:null),this.emit("sort-change",{field:t,direction:this.sortState?.direction??0}),this.requestRender(),!0}afterRender(){const e=this.animationStyle;if(e===!1||this.keysToAnimate.size===0)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const i=e==="fade"?"tbw-tree-fade-in":"tbw-tree-slide-in";for(const n of t.querySelectorAll(".data-grid-row")){const o=n.querySelector(".cell[data-row]"),s=o?parseInt(o.getAttribute("data-row")??"-1",10):-1,l=this.flattenedRows[s]?.key;l&&this.keysToAnimate.has(l)&&(n.classList.add(i),n.addEventListener("animationend",()=>n.classList.remove(i),{once:!0}))}this.keysToAnimate.clear()}expand(e){this.expandedKeys.add(e),this.requestRender()}collapse(e){this.expandedKeys.delete(e),this.requestRender()}toggle(e){this.expandedKeys=gt(this.expandedKeys,e),this.emitPluginEvent("tree-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}expandAll(){this.expandedKeys=pt(this.rows,this.config),this.emitPluginEvent("tree-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}collapseAll(){this.expandedKeys=qs(),this.emitPluginEvent("tree-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}getExpandedKeys(){return[...this.expandedKeys]}getFlattenedRows(){return[...this.flattenedRows]}getRowByKey(e){return this.rowKeyMap.get(e)?.data}expandToKey(e){this.expandedKeys=Gs(this.rows,e,this.config,this.expandedKeys),this.requestRender()}}function Ws(r,e,t){const i=[...r.undoStack,e];for(;i.length>t;)i.shift();return{undoStack:i,redoStack:[]}}function Bi(r){if(r.undoStack.length===0)return{newState:r,action:null};const e=[...r.undoStack],t=e.pop();return t?{newState:{undoStack:e,redoStack:[...r.redoStack,t]},action:t}:{newState:r,action:null}}function Ki(r){if(r.redoStack.length===0)return{newState:r,action:null};const e=[...r.redoStack],t=e.pop();return t?{newState:{undoStack:[...r.undoStack,t],redoStack:e},action:t}:{newState:r,action:null}}function Vs(r){return r.undoStack.length>0}function Us(r){return r.redoStack.length>0}function js(){return{undoStack:[],redoStack:[]}}function Ys(r,e,t,i){return{type:"cell-edit",rowIndex:r,field:e,oldValue:t,newValue:i,timestamp:Date.now()}}class Xs extends D{static dependencies=[{name:"editing",required:!0,reason:"UndoRedoPlugin tracks cell edit history"}];name="undoRedo";get defaultConfig(){return{maxHistorySize:100}}undoStack=[];redoStack=[];attach(e){super.attach(e),this.on("cell-edit-committed",t=>{this.recordEdit(t.rowIndex,t.field,t.oldValue,t.newValue)})}detach(){this.undoStack=[],this.redoStack=[]}onKeyDown(e){const t=(e.ctrlKey||e.metaKey)&&e.key==="z"&&!e.shiftKey,i=(e.ctrlKey||e.metaKey)&&(e.key==="y"||e.key==="z"&&e.shiftKey);if(t){const n=Bi({undoStack:this.undoStack,redoStack:this.redoStack});if(n.action){const o=this.rows;o[n.action.rowIndex]&&(o[n.action.rowIndex][n.action.field]=n.action.oldValue),this.undoStack=n.newState.undoStack,this.redoStack=n.newState.redoStack,this.emit("undo",{action:n.action,type:"undo"}),this.requestRender()}return!0}if(i){const n=Ki({undoStack:this.undoStack,redoStack:this.redoStack});if(n.action){const o=this.rows;o[n.action.rowIndex]&&(o[n.action.rowIndex][n.action.field]=n.action.newValue),this.undoStack=n.newState.undoStack,this.redoStack=n.newState.redoStack,this.emit("redo",{action:n.action,type:"redo"}),this.requestRender()}return!0}return!1}recordEdit(e,t,i,n){const o=Ys(e,t,i,n),s=Ws({undoStack:this.undoStack,redoStack:this.redoStack},o,this.config.maxHistorySize??100);this.undoStack=s.undoStack,this.redoStack=s.redoStack}undo(){const e=Bi({undoStack:this.undoStack,redoStack:this.redoStack});if(e.action){const t=this.rows;t[e.action.rowIndex]&&(t[e.action.rowIndex][e.action.field]=e.action.oldValue),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.requestRender()}return e.action}redo(){const e=Ki({undoStack:this.undoStack,redoStack:this.redoStack});if(e.action){const t=this.rows;t[e.action.rowIndex]&&(t[e.action.rowIndex][e.action.field]=e.action.newValue),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.requestRender()}return e.action}canUndo(){return Vs({undoStack:this.undoStack,redoStack:this.redoStack})}canRedo(){return Us({undoStack:this.undoStack,redoStack:this.redoStack})}clearHistory(){const e=js();this.undoStack=e.undoStack,this.redoStack=e.redoStack}getUndoStack(){return[...this.undoStack]}getRedoStack(){return[...this.redoStack]}}const Zs='@layer tbw-plugins{.tbw-visibility-content{display:flex;flex-direction:column;height:100%}.tbw-visibility-list{flex:1;overflow-y:auto;padding:var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem))}.tbw-visibility-row{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding:var(--tbw-menu-item-padding, .375rem .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem);border-radius:var(--tbw-border-radius, .25rem);position:relative}.tbw-visibility-row:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover))}.tbw-visibility-row input[type=checkbox]{cursor:pointer}.tbw-visibility-row.locked span{color:var(--tbw-color-fg-muted)}.tbw-visibility-handle{cursor:grab;color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-2xs, .625rem);letter-spacing:-2px;-webkit-user-select:none;user-select:none;flex-shrink:0}.tbw-visibility-row.reorderable:hover .tbw-visibility-handle{color:var(--tbw-color-fg)}.tbw-visibility-label{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));flex:1;cursor:pointer}.tbw-visibility-row.dragging{opacity:.5;cursor:grabbing}.tbw-visibility-row.drop-before:before{content:"";position:absolute;left:0;right:0;top:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-row.drop-after:after{content:"";position:absolute;left:0;right:0;bottom:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-show-all{margin:var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem));padding:var(--tbw-button-padding, .5rem .75rem);border:1px solid var(--tbw-visibility-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius, .25rem);background:var(--tbw-visibility-btn-bg, var(--tbw-color-header-bg));color:var(--tbw-color-fg);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem)}.tbw-visibility-show-all:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover))}}';function Wi(r){const e=r.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}class Z extends D{static dependencies=[{name:"reorder",required:!1,reason:"Enables drag-to-reorder columns in visibility panel"}];name="visibility";static PANEL_ID="columns";styles=Zs;get defaultConfig(){return{allowHideAll:!1}}columnListElement=null;isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;clearDragClasses(e){e.querySelectorAll(".tbw-visibility-row").forEach(t=>{t.classList.remove("dragging","drop-target","drop-before","drop-after")})}detach(){this.columnListElement=null,this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null}getToolPanel(){return{id:Z.PANEL_ID,title:"Columns",icon:"☰",tooltip:"Column visibility",order:100,render:e=>this.renderPanelContent(e)}}show(){this.grid.openToolPanel(),this.grid.expandedToolPanelSections.includes(Z.PANEL_ID)||this.grid.toggleToolPanelSection(Z.PANEL_ID)}hide(){this.grid.closeToolPanel()}toggle(){this.grid.isToolPanelOpen||this.grid.openToolPanel(),this.grid.toggleToolPanelSection(Z.PANEL_ID)}isColumnVisible(e){return this.grid.isColumnVisible(e)}setColumnVisible(e,t){this.grid.setColumnVisible(e,t)}getVisibleColumns(){return this.grid.getAllColumns().filter(e=>e.visible).map(e=>e.field)}getHiddenColumns(){return this.grid.getAllColumns().filter(e=>!e.visible).map(e=>e.field)}showAll(){this.grid.showAllColumns()}toggleColumn(e){this.grid.toggleColumnVisibility(e)}showColumn(e){this.setColumnVisible(e,!0)}hideColumn(e){this.setColumnVisible(e,!1)}getAllColumns(){return this.grid.getAllColumns()}isPanelVisible(){return this.grid.isToolPanelOpen&&this.grid.expandedToolPanelSections.includes(Z.PANEL_ID)}renderPanelContent(e){const t=document.createElement("div");t.className="tbw-visibility-content";const i=document.createElement("div");i.className="tbw-visibility-list",t.appendChild(i);const n=document.createElement("button");return n.className="tbw-visibility-show-all",n.textContent="Show All",n.addEventListener("click",()=>{this.grid.showAllColumns(),this.rebuildToggles(i)}),t.appendChild(n),this.columnListElement=i,this.rebuildToggles(i),e.appendChild(t),()=>{this.columnListElement=null,t.remove()}}hasReorderPlugin(){const e=this.grid?.getPluginByName?.("reorder");return!!(e&&typeof e.moveColumn=="function")}rebuildToggles(e){const t=this.hasReorderPlugin();e.innerHTML="";const i=this.grid.getAllColumns().filter(n=>!n.utility);for(let n=0;n<i.length;n++){const o=i[n],s=o.header||o.field,l=document.createElement("div");l.className=o.lockVisible?"tbw-visibility-row locked":"tbw-visibility-row",l.setAttribute("data-field",o.field),l.setAttribute("data-index",String(n)),t&&Wi(o)&&(l.draggable=!0,l.classList.add("reorderable"),this.setupDragListeners(l,o.field,n,e));const a=document.createElement("label");a.className="tbw-visibility-label";const c=document.createElement("input");c.type="checkbox",c.checked=o.visible,c.disabled=o.lockVisible??!1,c.addEventListener("change",()=>{this.grid.toggleColumnVisibility(o.field),setTimeout(()=>this.rebuildToggles(e),0)});const d=document.createElement("span");if(d.textContent=s,a.appendChild(c),a.appendChild(d),t&&Wi(o)){const u=document.createElement("span");u.className="tbw-visibility-handle",this.setIcon(u,this.resolveIcon("dragHandle")),u.title="Drag to reorder",l.appendChild(u)}l.appendChild(a),e.appendChild(l)}}setupDragListeners(e,t,i,n){e.addEventListener("dragstart",o=>{this.isDragging=!0,this.draggedField=t,this.draggedIndex=i,o.dataTransfer&&(o.dataTransfer.effectAllowed="move",o.dataTransfer.setData("text/plain",t)),e.classList.add("dragging")}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.clearDragClasses(n)}),e.addEventListener("dragover",o=>{if(o.preventDefault(),!this.isDragging||this.draggedField===t)return;const s=e.getBoundingClientRect(),l=s.top+s.height/2;this.dropIndex=o.clientY<l?i:i+1,n.querySelectorAll(".tbw-visibility-row").forEach(a=>{a!==e&&a.classList.remove("drop-target","drop-before","drop-after")}),e.classList.add("drop-target"),e.classList.toggle("drop-before",o.clientY<l),e.classList.toggle("drop-after",o.clientY>=l)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",o=>{o.preventDefault();const s=this.draggedField,l=this.draggedIndex,a=this.dropIndex;if(!this.isDragging||s===null||l===null||a===null)return;const c=a>l?a-1:a;if(c!==l){const d=this.grid.getAllColumns(),h=d.filter(g=>!g.utility)[c]?.field,f=h?d.findIndex(g=>g.field===h):d.length,p={field:s,fromIndex:l,toIndex:f};this.emit("column-reorder-request",p),setTimeout(()=>{this.rebuildToggles(n)},0)}})}}R.BaseGridPlugin=D,R.ClipboardPlugin=Fr,R.ColumnVirtualizationPlugin=Br,R.ContextMenuPlugin=rt,R.DEFAULT_ANIMATION_CONFIG=wt,R.DEFAULT_GRID_ICONS=G,R.DGEvents=Mr,R.DataGridElement=B,R.EditingPlugin=io,R.ExportPlugin=lo,R.FilteringPlugin=W,R.FitModeEnum=J,R.GridCSSVars=Pr,R.GridClasses=z,R.GridDataAttrs=he,R.GridElement=B,R.GridSelectors=Lr,R.GroupingColumnsPlugin=Co,R.GroupingRowsPlugin=Lo,R.MasterDetailPlugin=at,R.MultiSortPlugin=qo,R.PLUGIN_QUERIES=Tr,R.PinnedColumnsPlugin=Bo,R.PinnedRowsPlugin=Xo,R.PivotPlugin=X,R.PluginEvents=Ir,R.PluginManager=ue,R.PrintPlugin=vs,R.ROW_DRAG_HANDLE_FIELD=zi,R.RenderPhase=M,R.ReorderPlugin=xs,R.ResponsivePlugin=Rs,R.RowReorderPlugin=_s,R.SelectionPlugin=Ms,R.ServerSidePlugin=Fs,R.TreePlugin=Ks,R.UndoRedoPlugin=Xs,R.VisibilityPlugin=Z,R.builtInSort=Ht,R.createGrid=Hr,R.defaultComparator=Pt,R.defaultEditorFor=li,R.defaultPasteHandler=ti,R.printGridIsolated=Mi,R.queryGrid=Dr,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"})}));
|
|
187
187
|
//# sourceMappingURL=grid.all.umd.js.map
|