@toolbox-web/grid 0.2.4 → 0.2.5
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.d.ts +5 -0
- package/index.d.ts +5 -0
- package/index.js +75 -57
- package/index.js.map +1 -1
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/export/index.js.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/index.js.map +1 -1
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/reorder/index.js.map +1 -1
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- 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/themes/dg-theme-bootstrap.css +0 -2
- package/themes/dg-theme-contrast.css +0 -1
- package/themes/dg-theme-large.css +0 -1
- package/themes/dg-theme-material.css +0 -2
- package/themes/dg-theme-standard.css +0 -1
- package/themes/dg-theme-vibrant.css +0 -1
- package/umd/grid.all.umd.js +4 -4
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +4 -4
- package/umd/grid.umd.js.map +1 -1
package/umd/grid.all.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(y,J){typeof exports=="object"&&typeof module<"u"?J(exports):typeof define=="function"&&define.amd?define(["exports"],J):(y=typeof globalThis<"u"?globalThis:y||self,J(y.TbwGrid={}))})(this,(function(y){"use strict";const J=":root{color-scheme:light dark}:host{--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-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, #adacac);--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: inherit;--tbw-font-size-header: var(--tbw-font-size);--tbw-font-weight-header: bold;--tbw-cell-padding-header: 2px 8px;--tbw-cell-padding: 2px 8px;--tbw-cell-padding-input: 2px 6px;--tbw-row-height: 28px;--tbw-header-height: 30px;--tbw-cell-white-space: nowrap;--tbw-border-radius: 4px;--tbw-border-input: 1px solid var(--tbw-color-border-strong);--tbw-border-header: 1px solid var(--tbw-color-border-header);--tbw-row-divider: 1px solid var(--tbw-color-border-cell);--tbw-row-hover-outline: 0;--tbw-color-active-row-bg: var(--tbw-color-selection);--tbw-active-row-outline: 0;--tbw-focus-outline: 2px solid var(--tbw-color-accent);--tbw-focus-outline-offset: -2px;--tbw-focus-background: rgba(from var(--tbw-color-accent) r g b / 12%);--tbw-range-border-color: var(--tbw-color-accent);--tbw-range-selection-bg: rgba(from var(--tbw-range-border-color) r g b / 12%);--tbw-resize-handle-width: 4px;--tbw-resize-handle-color: transparent;--tbw-resize-handle-color-hover: var(--tbw-color-accent);--tbw-resize-handle-border-radius: 0;--tbw-scrollbar-thumb: var(--tbw-color-border-strong);--tbw-scrollbar-track: var(--tbw-color-bg);--tbw-transition-duration: .12s;--tbw-transition-ease: ease;--tbw-editing-bg: var(--tbw-color-selection);--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-sort-indicator-color: var(--tbw-color-fg-muted);--tbw-sort-indicator-active-color: var(--tbw-color-accent);--tbw-header-text-transform: none;--tbw-header-letter-spacing: normal;--tbw-color-header-separator: var(--tbw-color-border-cell);--tbw-checkbox-size: 16px;--tbw-density-scale: 1}:host{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);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}:host,:host *{box-sizing:border-box}:host .header{display:block;flex-shrink:0;z-index:var(--tbw-z-layer-header, 30);background:var(--tbw-color-header-bg);overflow:visible}:host .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)}:host .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))}:host .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)}:host .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:hidden;min-width:0}:host .header-row>.cell>span:first-child{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}:host .header-row>.cell>span[part~=sort-indicator]{flex-shrink:0}:host .header-row>.cell:last-child{border-right:0}:host .header-group-cell,:host .header-row>.cell.grouped.group-end{border-right:2px solid var(--tbw-color-border)}:host .tbw-grid-root{display:flex;flex-direction:column;height:100%}:host .rows-body-wrapper{flex:1;min-height:0;display:flex;flex-direction:row;width:100%;min-width:fit-content}:host .rows-body{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow:visible}:host .rows-container{display:flex;flex-direction:row;flex:1;min-height:0;overflow:visible}:host .rows-viewport{flex:1;min-width:0;position:relative;display:block;overflow:clip}:host .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)}:host .faux-vscroll-spacer{width:1px}:host .rows-viewport .rows{position:absolute;top:0;left:0;min-width:100%;will-change:transform;z-index:var(--tbw-z-layer-rows, 1)}:host .data-grid-row{display:grid;grid-template-columns:var(--tbw-column-template);contain:layout style}:host .data-grid-row:has(.editing){background:var(--tbw-editing-bg)}:host .selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}:host .data-grid-row>.cell.selected:focus-visible,:host .data-grid-row>.cell:focus-visible:not(.cell-focus){outline:none}:host .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);line-height:calc(var(--tbw-row-height) - 5px);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}:host .data-grid-row>.cell>*{overflow:hidden;text-overflow:ellipsis;white-space:inherit;min-width:0}:host .data-grid-row>.cell:last-child{border-right:0}:host .data-grid-row>.cell[data-type=boolean]{text-align:center}:host .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}:host .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex}:host .data-grid-row>.cell.editing input:not([type=checkbox]),:host .data-grid-row>.cell.editing select,:host .data-grid-row>.cell.editing textarea{width:100%;height:100%;max-width: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)}:host .data-grid-row:nth-child(2n){background:var(--tbw-color-row-alt)}:host .data-grid-row:hover{background:var(--tbw-color-row-hover)}:host .sortable{cursor:pointer;-webkit-user-select:none;user-select:none}:host .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)}:host .resize-handle:hover{background:var(--tbw-resize-handle-color-hover)}:host .cell-focus,:host .row-focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}:host .group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-color-row-alt);font-weight:500;border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height)}:host .group-row .cell{display:flex;align-items:center;padding:var(--tbw-cell-padding, 2px 8px)}:host .group-row .group-toggle{background:none;border:0;cursor:pointer;padding:0 4px 0 0;font:inherit}:host .group-row .group-count{margin-left:4px;opacity:.7}:host .sticky-left,:host .sticky-right{position:sticky;z-index:25}:host .header-row>.cell.sticky-left,:host .header-row>.cell.sticky-right{background:var(--tbw-color-header-bg);z-index:35}:host .data-grid-row>.cell.sticky-left,:host .data-grid-row>.cell.sticky-right{background:var(--tbw-color-panel-bg)}:host .sticky-left{box-shadow:1px 0 0 var(--tbw-color-border)}:host .sticky-right{box-shadow:-1px 0 0 var(--tbw-color-border)}.grid-container{position:relative;width:100%;height:100%}.grid-placeholder{padding:2rem;text-align:center;color:var(--tbw-color-fg);opacity:.6}:host{--tbw-shell-header-height: 44px;--tbw-shell-header-bg: var(--tbw-color-panel-bg);--tbw-shell-header-border: var(--tbw-color-border);--tbw-shell-title-font-size: 14px;--tbw-shell-title-font-weight: 600;--tbw-tool-panel-width: 280px;--tbw-tool-panel-bg: var(--tbw-color-panel-bg);--tbw-tool-panel-border: var(--tbw-color-border);--tbw-tool-panel-header-height: 40px;--tbw-tool-panel-transition: .2s ease-out;--tbw-toolbar-button-size: 32px;--tbw-toolbar-button-gap: 4px}:host .tbw-grid-root.has-shell{display:flex;flex-direction:column;height:100%}:host .tbw-shell-header{display:flex;align-items:center;gap:8px;min-height:var(--tbw-shell-header-height);padding:0 8px;background:var(--tbw-shell-header-bg);border-bottom:1px solid var(--tbw-shell-header-border);flex-shrink:0}:host .tbw-shell-title{font-size:var(--tbw-shell-title-font-size);font-weight:var(--tbw-shell-title-font-weight);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host .tbw-shell-content{flex:1;display:flex;align-items:center;gap:12px;min-width:0;overflow:hidden}:host .tbw-shell-toolbar{display:flex;align-items:center;gap:var(--tbw-toolbar-button-gap);flex-shrink:0}:host .tbw-toolbar-btn{display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-toolbar-button-size);height:var(--tbw-toolbar-button-size);padding:0;border:1px solid transparent;border-radius:var(--tbw-border-radius);background:transparent;color:var(--tbw-color-fg);cursor:pointer;font-size:16px;transition:background var(--tbw-transition-duration) var(--tbw-transition-ease),border-color var(--tbw-transition-duration) var(--tbw-transition-ease)}:host .tbw-toolbar-btn:hover{background:var(--tbw-color-row-hover)}:host .tbw-toolbar-btn:focus-visible{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}:host .tbw-toolbar-btn.active{background:var(--tbw-focus-background);border-color:var(--tbw-color-accent)}:host .tbw-toolbar-btn:disabled{opacity:.5;cursor:not-allowed}:host .tbw-toolbar-separator{width:1px;height:20px;background:var(--tbw-color-border);margin:0 4px}:host .tbw-shell-body{position:relative;display:flex;flex:1;min-height:0;overflow:visible}:host .tbw-grid-content{flex:1;min-width:0;min-height:0;display:flex;flex-direction:row;overflow:hidden}:host .tbw-scroll-area{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow-x:auto;overflow-y:hidden}:host .tbw-tool-panel{position:absolute;top:0;bottom:0;right:0;width:0;overflow:hidden;background:var(--tbw-tool-panel-bg);border-left:1px solid var(--tbw-tool-panel-border);transition:width var(--tbw-tool-panel-transition);display:flex;flex-direction:column;z-index:30;box-shadow:-2px 0 8px var(--tbw-color-shadow)}:host .tbw-tool-panel[data-position=left]{right:auto;left:0;border-left:none;border-right:1px solid var(--tbw-tool-panel-border);box-shadow:2px 0 8px var(--tbw-color-shadow)}:host .tbw-tool-panel.open{width:var(--tbw-tool-panel-width)}:host .tbw-tool-panel-resize{position:absolute;top:0;bottom:0;width:6px;cursor:col-resize;background:transparent;z-index:10;transition:background .15s ease}:host .tbw-tool-panel-resize[data-handle-position=left]{left:0}:host .tbw-tool-panel-resize[data-handle-position=right]{right:0}:host .tbw-tool-panel-resize:hover,:host .tbw-tool-panel-resize.resizing{background:var(--tbw-color-accent)}:host .tbw-tool-panel-header{display:flex;align-items:center;justify-content:space-between;min-height:var(--tbw-tool-panel-header-height);padding:0 12px;border-bottom:1px solid var(--tbw-tool-panel-border);flex-shrink:0}:host .tbw-tool-panel-title{font-weight:600;font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host .tbw-tool-panel-close{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;padding:0;border:none;border-radius:var(--tbw-border-radius);background:transparent;color:var(--tbw-color-fg-muted);cursor:pointer;font-size:14px}:host .tbw-tool-panel-close:hover{background:var(--tbw-color-row-hover);color:var(--tbw-color-fg)}:host .tbw-tool-panel-content{flex:1;overflow:auto}:host .tbw-accordion{display:flex;flex-direction:column;gap:0}:host .tbw-accordion-section{border-bottom:1px solid var(--tbw-tool-panel-border)}:host .tbw-accordion-section:last-child{border-bottom:none}:host .tbw-accordion-header{display:flex;align-items:center;gap:8px;width:100%;padding:10px 12px;border:none;background:transparent;color:var(--tbw-color-fg);font-size:13px;font-weight:600;text-align:left;cursor:pointer;-webkit-user-select:none;user-select:none}:host .tbw-accordion-header:hover{background:var(--tbw-color-row-hover)}:host .tbw-accordion-section.single .tbw-accordion-header{cursor:default}:host .tbw-accordion-section.single .tbw-accordion-header:hover{background:transparent}:host .tbw-accordion-chevron{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:10px;color:var(--tbw-color-fg-muted);transition:transform .15s ease;flex-shrink:0}:host .tbw-accordion-section.expanded .tbw-accordion-chevron{transform:rotate(90deg)}:host .tbw-accordion-icon{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:14px;flex-shrink:0}:host .tbw-accordion-title{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}:host .tbw-accordion-content{display:none}:host .tbw-accordion-section.expanded .tbw-accordion-content{display:block}:host .tbw-quick-filter-input{flex:1;max-width:300px;height:28px;padding:0 8px;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:13px}:host .tbw-quick-filter-input:focus{outline:none;border-color:var(--tbw-color-accent)}:host .tbw-selection-summary{font-size:13px;color:var(--tbw-color-fg-muted);white-space:nowrap}";function kt(o){const e=new Map;return o._sortState&&e.set(o._sortState.field,{direction:o._sortState.direction===1?"asc":"desc",priority:0}),e}function He(o,e){const t=o._columns,n=kt(o);return{columns:t.map((i,r)=>{const s={field:i.field,order:r,visible:!0},l=i;l.__renderedWidth!==void 0?s.width=l.__renderedWidth:i.width!==void 0&&(s.width=typeof i.width=="string"?parseFloat(i.width):i.width);const a=n.get(i.field);a&&(s.sort=a);for(const c of e)if(c.getColumnState){const d=c.getColumnState(i.field);d&&Object.assign(s,d)}return s})}}function Tt(o,e,t,n){if(!e.columns||e.columns.length===0)return;const i=new Map(e.columns.map(l=>[l.field,l])),r=t.map(l=>{const a=i.get(l.field);if(!a)return l;const c={...l};return a.width!==void 0&&(c.width=a.width,c.__renderedWidth=a.width),a.visible!==void 0&&(c.hidden=!a.visible),c});r.sort((l,a)=>{const c=i.get(l.field)?.order??1/0,d=i.get(a.field)?.order??1/0;return c-d}),o._columns=r;const s=e.columns.filter(l=>l.sort!==void 0).sort((l,a)=>(l.sort?.priority??0)-(a.sort?.priority??0));if(s.length>0){const l=s[0];l.sort&&(o._sortState={field:l.field,direction:l.sort.direction==="asc"?1:-1})}else o._sortState=null;for(const l of n)if(l.applyColumnState)for(const a of e.columns)l.applyColumnState(a.field,a)}function Lt(o,e,t){let n=null;return()=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{n=null;const i=He(o,e());t(i)},100)}}const G={STRETCH:"stretch",FIXED:"fixed"},I={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰"};function Pt(o){return o==null?"string":typeof o=="number"?"number":typeof o=="boolean"?"boolean":o instanceof Date||typeof o=="string"&&/\d{4}-\d{2}-\d{2}/.test(o)&&!isNaN(Date.parse(o))?"date":"string"}function Ne(o,e){if(e&&e.length){const r={};return e.forEach(s=>{s.type&&(r[s.field]=s.type)}),{columns:e,typeMap:r}}const t=o[0]||{},n=Object.keys(t).map(r=>{const s=t[r],l=Pt(s);return{field:r,header:r.charAt(0).toUpperCase()+r.slice(1),type:l}}),i={};return n.forEach(r=>{i[r.field]=r.type||"string"}),{columns:n,typeMap:i}}const Mt=/{{\s*([^}]+)\s*}}/g,H="__DG_EMPTY__",It=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,Ht=/__(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/,Nt=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"]),Oe=/^on\w+$/i,Ot=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),Dt=/^\s*(javascript|vbscript|data|blob):/i;function ne(o){if(!o||typeof o!="string")return"";if(o.indexOf("<")===-1)return o;const e=document.createElement("template");return e.innerHTML=o,zt(e.content),e.innerHTML}function zt(o){const e=[],t=o.querySelectorAll("*");for(const n of t){const i=n.tagName.toLowerCase();if(Nt.has(i)){e.push(n);continue}if((i==="svg"||n.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(n.attributes).some(l=>Oe.test(l.name)||l.name==="href"||l.name==="xlink:href")){e.push(n);continue}const r=[];for(const s of n.attributes){const l=s.name.toLowerCase();if(Oe.test(l)){r.push(s.name);continue}if(Ot.has(l)&&Dt.test(s.value)){r.push(s.name);continue}if(l==="style"&&/expression\s*\(|javascript:|behavior\s*:/i.test(s.value)){r.push(s.name);continue}}r.forEach(s=>n.removeAttribute(s))}e.forEach(n=>n.remove())}function De(o,e){if(!o||o.indexOf("{{")===-1)return o;const t=[],n=o.replace(Mt,(l,a)=>{const c=qt(a,e);return t.push({expr:a.trim(),result:c}),c}),i=Ft(n),r=t.length&&t.every(l=>l.result===""||l.result===H);return/Reflect\.|\bProxy\b|ownKeys\(/.test(o)||r?"":i}function qt(o,e){if(o=(o||"").trim(),!o||/\b(Reflect|Proxy|ownKeys)\b/.test(o))return H;if(o==="value")return e.value==null?H:String(e.value);if(o.startsWith("row.")&&!/[()?]/.test(o)&&!o.includes(":")){const n=o.slice(4),i=e.row?e.row[n]:void 0;return i==null?H:String(i)}if(o.length>80||!It.test(o)||Ht.test(o))return H;const t=o.match(/\./g);if(t&&t.length>1)return H;try{const i=new Function("value","row",`return (${o});`)(e.value,e.row),r=i==null?"":String(i);return/Reflect|Proxy|ownKeys/.test(r)?H:r||H}catch{return H}}function Ft(o){return o&&o.replace(new RegExp(H,"g"),"").replace(/Reflect\.[^<>{}\s]+/g,"").replace(/\bProxy\b/g,"").replace(/ownKeys\([^)]*\)/g,"")}function Bt(o){if(/Reflect|Proxy|ownKeys/.test(o.textContent||"")){if(Array.from(o.childNodes).forEach(e=>{e.nodeType===Node.TEXT_NODE&&/Reflect|Proxy|ownKeys/.test(e.textContent||"")&&(e.textContent="")}),/Reflect|Proxy|ownKeys/.test(o.textContent||"")){if(/Reflect|Proxy|ownKeys/.test(o.textContent||""))for(;o.firstChild;)o.removeChild(o.firstChild);o.textContent=(o.textContent||"").replace(/Reflect|Proxy|ownKeys/g,"")}(o.textContent||"").trim().length===0&&(o.textContent="")}}function ze(o){const e=/Reflect\.|\bProxy\b|ownKeys\(/.test(o),t=n=>e?"":De(o,n);return t.__blocked=e,t}function $t(o){return Array.from(o.querySelectorAll("tbw-grid-column")).map(t=>{const n=t.getAttribute("field")||"";if(!n)return null;const i=t.getAttribute("type")||void 0,s=i&&new Set(["number","string","date","boolean","select","typeahead"]).has(i)?i:void 0,l=t.getAttribute("header")||void 0,a=t.hasAttribute("sortable"),c=t.hasAttribute("editable"),d={field:n,type:s,header:l,sortable:a,editable:c};t.hasAttribute("resizable")&&(d.resizable=!0),t.hasAttribute("sizable")&&(d.resizable=!0);const h=t.getAttribute("options");h&&(d.options=h.split(",").map(g=>{const[w,b]=g.includes(":")?g.split(":"):[g.trim(),g.trim()];return{value:w.trim(),label:b?.trim()||w.trim()}}));const f=t.querySelector("tbw-grid-column-view"),u=t.querySelector("tbw-grid-column-editor"),p=t.querySelector("tbw-grid-column-header");return f&&(d.__viewTemplate=f),u&&(d.__editorTemplate=u),p&&(d.__headerTemplate=p),d}).filter(t=>!!t)}function Gt(o,e){if((!o||!o.length)&&(!e||!e.length))return[];if(!o||!o.length)return e||[];if(!e||!e.length)return o;const t={};e.forEach(i=>t[i.field]=i);const n=o.map(i=>{const r=t[i.field];if(!r)return i;const s={...i};return r.header&&!s.header&&(s.header=r.header),r.type&&!s.type&&(s.type=r.type),s.sortable=i.sortable||r.sortable,(i.resizable===!0||r.resizable===!0)&&(s.resizable=!0),s.editable=i.editable||r.editable,r.__viewTemplate&&(s.__viewTemplate=r.__viewTemplate),r.__editorTemplate&&(s.__editorTemplate=r.__editorTemplate),r.__headerTemplate&&(s.__headerTemplate=r.__headerTemplate),delete t[i.field],s});return Object.keys(t).forEach(i=>n.push(t[i])),n}function se(o,e){try{o.part?.add?.(e)}catch{}const t=o.getAttribute("part");t?t.split(/\s+/).includes(e)||o.setAttribute("part",t+" "+e):o.setAttribute("part",e)}function Kt(o){o.__lightDomColumnsCache||(o.__originalColumnNodes=Array.from(o.querySelectorAll("tbw-grid-column")),o.__lightDomColumnsCache=o.__originalColumnNodes.length?$t(o):[]);const e=o.__lightDomColumnsCache,t=Gt(o._columns,e);t.forEach(i=>{i.__viewTemplate&&!i.__compiledView&&(i.__compiledView=ze(i.__viewTemplate.innerHTML)),i.__editorTemplate&&!i.__compiledEditor&&(i.__compiledEditor=ze(i.__editorTemplate.innerHTML))});const{columns:n}=Ne(o._rows,t);o._columns=n}function qe(o){const e=o.effectiveConfig?.fitMode||o.fitMode||G.STRETCH;if(e!==G.STRETCH&&e!==G.FIXED||o.__didInitialAutoSize||!o.isConnected)return;const t=o._headerRowEl?.children||[];if(!t.length)return;let n=!1;o._visibleColumns.forEach((i,r)=>{if(i.width)return;const s=t[r];let l=s?s.scrollWidth:0;for(const a of o._rowPool){const c=a.children[r];if(c){const d=c.scrollWidth;d>l&&(l=d)}}l>0&&(i.width=l+2,i.__autoSized=!0,n=!0)}),n&&K(o),o.__didInitialAutoSize=!0}function K(o){(o.effectiveConfig?.fitMode||o.fitMode||G.STRETCH)===G.STRETCH?o._gridTemplate=o._visibleColumns.map(t=>{if(t.width)return`${t.width}px`;const n=t.minWidth;return n!=null?`minmax(${n}px, 1fr)`:"1fr"}).join(" ").trim():o._gridTemplate=o._visibleColumns.map(t=>t.width?`${t.width}px`:"max-content").join(" "),o.style.setProperty("--tbw-column-template",o._gridTemplate)}function Vt(o){switch(o.type){case"number":return e=>{const t=document.createElement("input");return t.type="number",t.value=e.value!=null?String(e.value):"",t.addEventListener("blur",()=>e.commit(t.value===""?null:Number(t.value))),t.addEventListener("keydown",n=>{n.key==="Enter"&&e.commit(t.value===""?null:Number(t.value)),n.key==="Escape"&&e.cancel()}),t.focus(),t};case"boolean":return e=>{const t=document.createElement("input");return t.type="checkbox",t.checked=!!e.value,t.addEventListener("change",()=>e.commit(t.checked)),t.focus(),t};case"date":return e=>{const t=document.createElement("input");return t.type="date",e.value instanceof Date&&(t.valueAsDate=e.value),t.addEventListener("change",()=>e.commit(t.valueAsDate)),t.addEventListener("keydown",n=>{n.key==="Escape"&&e.cancel()}),t.focus(),t};case"select":case"typeahead":return e=>{const t=document.createElement("select");e.column.multi&&(t.multiple=!0),(typeof e.column.options=="function"?e.column.options():e.column.options||[]).forEach(r=>{const s=document.createElement("option");s.value=String(r.value),s.textContent=r.label,(e.column.multi&&Array.isArray(e.value)&&e.value.includes(r.value)||!e.column.multi&&e.value===r.value)&&(s.selected=!0),t.appendChild(s)});const i=()=>{if(e.column.multi){const r=[];Array.from(t.selectedOptions).forEach(s=>{r.push(s.value)}),e.commit(r)}else e.commit(t.value)};return t.addEventListener("change",i),t.addEventListener("blur",i),t.addEventListener("keydown",r=>{r.key==="Escape"&&e.cancel()}),t.focus(),t};default:return e=>{const t=document.createElement("input");return t.type="text",t.value=e.value!=null?String(e.value):"",t.addEventListener("blur",()=>e.commit(t.value)),t.addEventListener("keydown",n=>{n.key==="Enter"&&e.commit(t.value),n.key==="Escape"&&e.cancel()}),t.focus(),t}}}function Wt(o,e){if(o._dispatchKeyDown?.(e))return;const t=o._rows.length-1,n=o._visibleColumns.length-1,i=o._activeEditRows!==void 0&&o._activeEditRows!==-1,s=o._visibleColumns[o._focusCol]?.type,l=e.composedPath?e.composedPath():[],a=l&&l.length?l[0]:e.target,c=d=>{if(!d)return!1;const h=d.tagName;return!!(h==="INPUT"||h==="SELECT"||h==="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"))&&!(i&&(s==="select"||s==="typeahead")&&(e.key==="ArrowDown"||e.key==="ArrowUp"))){switch(e.key){case"Tab":{e.preventDefault(),!e.shiftKey?o._focusCol<n?o._focusCol+=1:(typeof o.commitActiveRowEdit=="function"&&o.commitActiveRowEdit(),o._focusRow<t&&(o._focusRow+=1,o._focusCol=0)):o._focusCol>0?o._focusCol-=1:o._focusRow>0&&(typeof o.commitActiveRowEdit=="function"&&o._activeEditRows===o._focusRow&&o.commitActiveRowEdit(),o._focusRow-=1,o._focusCol=n),z(o);return}case"ArrowDown":i&&typeof o.commitActiveRowEdit=="function"&&o.commitActiveRowEdit(),o._focusRow=Math.min(t,o._focusRow+1),e.preventDefault();break;case"ArrowUp":i&&typeof o.commitActiveRowEdit=="function"&&o.commitActiveRowEdit(),o._focusRow=Math.max(0,o._focusRow-1),e.preventDefault();break;case"ArrowRight":o._focusCol=Math.min(n,o._focusCol+1),e.preventDefault();break;case"ArrowLeft":o._focusCol=Math.max(0,o._focusCol-1),e.preventDefault();break;case"Home":(e.ctrlKey||e.metaKey)&&(i&&typeof o.commitActiveRowEdit=="function"&&o.commitActiveRowEdit(),o._focusRow=0),o._focusCol=0,e.preventDefault(),z(o,{forceScrollLeft:!0});return;case"End":(e.ctrlKey||e.metaKey)&&(i&&typeof o.commitActiveRowEdit=="function"&&o.commitActiveRowEdit(),o._focusRow=t),o._focusCol=n,e.preventDefault(),z(o,{forceScrollRight:!0});return;case"PageDown":o._focusRow=Math.min(t,o._focusRow+20),e.preventDefault();break;case"PageUp":o._focusRow=Math.max(0,o._focusRow-20),e.preventDefault();break;case"Enter":return typeof o.beginBulkEdit=="function"?o.beginBulkEdit(o._focusRow):o.dispatchEvent(new CustomEvent("activate-cell",{detail:{row:o._focusRow,col:o._focusCol}})),z(o);default:return}z(o)}}function z(o,e){if(o._virtualization?.enabled){const{rowHeight:s,container:l,viewportEl:a}=o._virtualization,c=l,d=a?.clientHeight??c?.clientHeight??0;if(c&&d>0){const h=o._focusRow*s;h<c.scrollTop?c.scrollTop=h:h+s>c.scrollTop+d&&(c.scrollTop=h-d+s)}}o._activeEditRows!==void 0&&o._activeEditRows!==-1||o.refreshVirtualWindow(!1),Array.from(o._bodyEl.querySelectorAll(".cell-focus")).forEach(s=>s.classList.remove("cell-focus")),Array.from(o._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(s=>{s.setAttribute("aria-selected","false")});const n=o._focusRow,i=o._virtualization.start??0,r=o._virtualization.end??o._rows.length;if(n>=i&&n<r){const s=o._bodyEl.querySelectorAll(".data-grid-row")[n-i],l=s?.children[o._focusCol];if(l){l.classList.add("cell-focus"),l.setAttribute("aria-selected","true");const a=o.shadowRoot?.querySelector(".tbw-scroll-area");if(a&&l)if(e?.forceScrollLeft)a.scrollLeft=0;else if(e?.forceScrollRight)a.scrollLeft=a.scrollWidth-a.clientWidth;else{const c=o._getHorizontalScrollOffsets?.(s??void 0,l)??{left:0,right:0};if(!c.skipScroll){const d=l.getBoundingClientRect(),h=a.getBoundingClientRect(),f=d.left-h.left+a.scrollLeft,u=f+d.width,p=a.scrollLeft+c.left,g=a.scrollLeft+a.clientWidth-c.right;f<p?a.scrollLeft=f-c.left:u>g&&(a.scrollLeft=u-a.clientWidth+c.right)}}if(o._activeEditRows!==void 0&&o._activeEditRows!==-1&&l.classList.contains("editing")){const c=l.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(c&&document.activeElement!==c)try{c.focus()}catch{}}else if(!l.contains(document.activeElement)){l.hasAttribute("tabindex")||l.setAttribute("tabindex","-1");try{l.focus({preventScroll:!0})}catch{}}}}}const jt="__cellDisplayCache",Ut="__cellCacheEpoch";function le(o){o[jt]=void 0,o[Ut]=void 0,o.__hasSpecialColumns=void 0}function Xt(o,e,t,n,i){const r=Math.max(0,t-e),s=o._bodyEl,l=o._visibleColumns,a=l.length;let c=o.__cachedHeaderRowCount;for(c===void 0&&(c=o.shadowRoot?.querySelector(".header-group-row")?2:1,o.__cachedHeaderRowCount=c);o._rowPool.length<r;){const h=document.createElement("div");h.className="data-grid-row",h.setAttribute("role","row"),h.addEventListener("click",f=>Fe(o,f,h,!1)),h.addEventListener("dblclick",f=>Fe(o,f,h,!0)),o._rowPool.push(h)}if(o._rowPool.length>r){for(let h=r;h<o._rowPool.length;h++){const f=o._rowPool[h];f.parentNode===s&&f.remove()}o._rowPool.length=r}const d=i&&o.__hasRenderRowPlugins!==!1;for(let h=0;h<r;h++){const f=e+h,u=o._rows[f],p=o._rowPool[h];if(p.setAttribute("aria-rowindex",String(f+c+1)),d&&i(u,p,f)){p.__epoch=n,p.__rowDataRef=u,p.parentNode!==s&&s.appendChild(p);continue}const g=p.__epoch,w=p.__rowDataRef,b=p.children.length,T=g===n&&b===a,k=w!==u;let m=!1;if(T&&k){for(let E=0;E<a;E++)if(l[E].externalView&&!p.querySelector(`.cell[data-col="${E}"] [data-external-view]`)){m=!0;break}}if(!T||m){const E=p.querySelector(".cell.editing"),C=o._activeEditRows===f;if(E&&!C)p.__isCustomRow&&(p.className="data-grid-row",p.setAttribute("role","row"),p.__isCustomRow=!1),V(o,p,u,f),p.__epoch=n,p.__rowDataRef=u;else if(E&&C)ae(o,p,u,f),p.__rowDataRef=u;else if(p.__isCustomRow&&(p.className="data-grid-row",p.setAttribute("role","row"),p.__isCustomRow=!1),V(o,p,u,f),p.__epoch=n,p.__rowDataRef=u,C){const x=p.children;for(let R=0;R<x.length;R++){const A=o._visibleColumns[R];A&&A.editable&&O(o,u,f,A,x[R])}}}else if(k){const E=p.querySelector(".cell.editing"),C=o._activeEditRows===f;if(E&&!C)V(o,p,u,f),p.__epoch=n,p.__rowDataRef=u;else if(ae(o,p,u,f),p.__rowDataRef=u,C&&!E){const x=p.children;for(let R=0;R<x.length;R++){const A=o._visibleColumns[R];A&&A.editable&&O(o,u,f,A,x[R])}}}else{const E=p.querySelector(".cell.editing"),C=o._activeEditRows===f;if(E&&!C)V(o,p,u,f),p.__epoch=n,p.__rowDataRef=u;else if(ae(o,p,u,f),C&&!E){const x=p.children;for(let R=0;R<x.length;R++){const A=o._visibleColumns[R];A&&A.editable&&O(o,u,f,A,x[R])}}}const v=o._changedRowIndices.has(f),S=p.classList.contains("changed");v!==S&&p.classList.toggle("changed",v),p.parentNode!==s&&s.appendChild(p)}}function ae(o,e,t,n){const i=e.children,r=o._visibleColumns,s=r.length,l=i.length,a=s<l?s:l,c=o._focusRow,d=o._focusCol;let h=o.__hasSpecialColumns;if(h===void 0){h=!1;for(let u=0;u<s;u++){const p=r[u];if(p.__viewTemplate||p.__compiledView||p.viewRenderer||p.externalView||p.format||p.type==="date"||p.type==="boolean"){h=!0;break}}o.__hasSpecialColumns=h}const f=String(n);if(!h){for(let u=0;u<a;u++){const p=i[u],g=t[r[u].field];p.textContent=g==null?"":String(g),p.getAttribute("data-row")!==f&&p.setAttribute("data-row",f);const w=c===n&&d===u,b=p.classList.contains("cell-focus");w!==b&&(p.classList.toggle("cell-focus",w),p.setAttribute("aria-selected",String(w)))}return}for(let u=0;u<a;u++)if(r[u].externalView&&!i[u].querySelector("[data-external-view]")){V(o,e,t,n);return}for(let u=0;u<a;u++){const p=r[u],g=i[u];g.getAttribute("data-row")!==f&&g.setAttribute("data-row",f);const w=c===n&&d===u,b=g.classList.contains("cell-focus");if(w!==b&&(g.classList.toggle("cell-focus",w),g.setAttribute("aria-selected",String(w))),g.classList.contains("editing"))continue;if(p.viewRenderer){const k=t[p.field],m=p.viewRenderer({row:t,value:k,field:p.field,column:p});typeof m=="string"?g.innerHTML=ne(m):m?(g.innerHTML="",g.appendChild(m)):g.textContent=k==null?"":String(k);continue}if(p.__viewTemplate||p.__compiledView||p.externalView)continue;const _=t[p.field];let T;if(p.format)try{const k=p.format(_,t);T=k==null?"":String(k)}catch{T=_==null?"":String(_)}else if(p.type==="date"){if(_==null||_==="")T="";else if(_ instanceof Date)T=isNaN(_.getTime())?"":_.toLocaleDateString();else{const k=new Date(_);T=isNaN(k.getTime())?"":k.toLocaleDateString()}g.textContent=T}else if(p.type==="boolean"){const k=!!_;g.innerHTML=`<span role="checkbox" aria-checked="${k}" aria-label="${k}">${k?"🗹":"☐"}</span>`}else T=_==null?"":String(_),g.textContent=T}}function V(o,e,t,n){e.innerHTML="";const i=o._visibleColumns,r=i.length,s=o._focusRow,l=o._focusCol,a=o.effectiveConfig?.editOn||o.editOn,c=o,d=document.createDocumentFragment();for(let h=0;h<r;h++){const f=i[h],u=document.createElement("div");u.className="cell",se(u,"cell"),u.setAttribute("role","gridcell"),u.setAttribute("aria-colindex",String(h+1)),u.setAttribute("data-col",String(h)),u.setAttribute("data-row",String(n)),f.type,f.type&&u.setAttribute("data-type",f.type);let p=t[f.field];const g=f.format;if(g)try{p=g(p,t)}catch{}const w=f.__compiledView,b=f.__viewTemplate,_=f.viewRenderer,T=f.externalView;let k=!1;if(_){const m=_({row:t,value:p,field:f.field,column:f});typeof m=="string"?(u.innerHTML=ne(m),k=!0):m?u.appendChild(m):u.textContent=p==null?"":String(p)}else if(T){const m=T,v=document.createElement("div");v.setAttribute("data-external-view",""),v.setAttribute("data-field",f.field),u.appendChild(v);const S={row:t,value:p,field:f.field,column:f};if(m.mount)try{m.mount({placeholder:v,context:S,spec:m})}catch{}else queueMicrotask(()=>{try{c.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:v,spec:m,context:S}}))}catch{}});v.setAttribute("data-mounted","")}else if(w){const m=w({row:t,value:p,field:f.field,column:f}),v=w.__blocked;u.innerHTML=v?"":ne(m),k=!0,v&&(u.textContent="",u.setAttribute("data-blocked-template",""))}else if(b){const m=b.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(m)?(u.textContent="",u.setAttribute("data-blocked-template","")):(u.innerHTML=ne(De(m,{row:t,value:p})),k=!0)}else if(f.type==="date")if(p==null||p==="")u.textContent="";else{let m=null;if(p instanceof Date)m=p;else if(typeof p=="number"||typeof p=="string"){const v=new Date(p);isNaN(v.getTime())||(m=v)}u.textContent=m?m.toLocaleDateString():""}else if(f.type==="boolean"){const m=!!p;u.innerHTML=`<span role="checkbox" aria-checked="${m}" aria-label="${m}">${m?"🗹":"☐"}</span>`}else u.textContent=p==null?"":String(p);if(k){Bt(u);const m=u.textContent||"";/Proxy|Reflect\.ownKeys/.test(m)&&(u.textContent=m.replace(/Proxy|Reflect\.ownKeys/g,"").trim(),/Proxy|Reflect\.ownKeys/.test(u.textContent||"")&&(u.textContent=""))}u.hasAttribute("data-blocked-template")&&(u.textContent||"").trim().length&&(u.textContent=""),f.editable?(u.tabIndex=0,u.addEventListener("mousedown",()=>{if(u.classList.contains("editing"))return;const m=Number(u.getAttribute("data-row")),v=Number(u.getAttribute("data-col"));isNaN(m)||isNaN(v)||(o._focusRow=m,o._focusCol=v,z(o))}),a==="click"?u.addEventListener("click",m=>{if(u.classList.contains("editing"))return;m.stopPropagation();const v=Number(u.getAttribute("data-row")),S=Number(u.getAttribute("data-col"));if(isNaN(v)||isNaN(S))return;const E=o._rows[v],C=o._visibleColumns[S];!E||!C||(o._focusRow=v,o._focusCol=S,O(o,E,v,C,u))}):u.addEventListener("dblclick",m=>{m.stopPropagation();const v=Number(u.getAttribute("data-row"));if(isNaN(v))return;const S=o._rows[v];if(!S)return;W(o,v,S);const E=o.findRenderedRowElement?.(v);if(E){const C=E.children;for(let x=0;x<C.length;x++){const R=o._visibleColumns[x];R&&R.editable&&O(o,S,v,R,C[x])}}}),u.addEventListener("keydown",m=>{const v=Number(u.getAttribute("data-row")),S=Number(u.getAttribute("data-col"));if(isNaN(v)||isNaN(S))return;const E=o._rows[v],C=o._visibleColumns[S];if(!(!E||!C)){if((C.type==="select"||C.type==="typeahead")&&!u.classList.contains("editing")&&m.key==="Enter"){m.preventDefault(),o._activeEditRows!==v&&W(o,v,E),O(o,E,v,C,u),setTimeout(()=>{const x=u.querySelector("select");try{x?.showPicker?.()}catch{}x?.focus()},0);return}if(C.type==="boolean"&&m.key===" "&&!u.classList.contains("editing")){m.preventDefault(),o._activeEditRows!==v&&W(o,v,E);const x=!E[C.field];de(o,v,C,x,E),u.innerHTML=`<span role="checkbox" aria-checked="${x}" aria-label="${x}">${x?"🗹":"☐"}</span>`;return}if(m.key==="Enter"&&!u.classList.contains("editing")){m.preventDefault(),m.stopPropagation(),o._focusRow=v,o._focusCol=S,typeof o.beginBulkEdit=="function"?o.beginBulkEdit(v):O(o,E,v,C,u);return}if(m.key==="F2"&&!u.classList.contains("editing")){m.preventDefault(),O(o,E,v,C,u);return}}})):f.type==="boolean"&&(u.hasAttribute("tabindex")||(u.tabIndex=0)),s===n&&l===h?(u.classList.add("cell-focus"),u.setAttribute("aria-selected","true")):u.setAttribute("aria-selected","false"),d.appendChild(u)}e.appendChild(d)}function Fe(o,e,t,n){if(e.target?.closest(".resize-handle"))return;const i=t.querySelector(".cell[data-row]");if(!i)return;const r=Number(i.getAttribute("data-row"));if(isNaN(r))return;const s=o._rows[r];if(!s)return;const l=e.target?.closest(".cell[data-col]");if(l){if(l.classList.contains("editing"))return;const c=Number(l.getAttribute("data-col"));if(!isNaN(c)){if(o._dispatchCellClick?.(e,r,c,l))return;o._focusRow=r,o._focusCol=c,z(o)}}if(t.querySelector(".cell.editing")){const c=t.querySelectorAll(".cell.editing");if(!n)return;c.forEach(d=>d.classList.remove("editing"))}const a=o.effectiveConfig?.editOn||o.editOn||"doubleClick";if(a==="click"||a==="doubleClick"&&n)W(o,r,s);else return;Array.from(t.children).forEach((c,d)=>{const h=o._visibleColumns[d];h&&h.editable&&O(o,s,r,h,c)}),l&&queueMicrotask(()=>{const c=t.querySelector(`.cell[data-col="${o._focusCol}"]`);if(c?.classList.contains("editing")){const d=c.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');try{d?.focus()}catch{}}})}function ce(o){return!(o==="__proto__"||o==="constructor"||o==="prototype")}function W(o,e,t){o._activeEditRows!==e&&(o._rowEditSnapshots.set(e,{...t}),o._activeEditRows=e)}function B(o,e,t){if(o._activeEditRows!==e)return;const n=o._rowEditSnapshots.get(e),i=o._rows[e],r=o.findRenderedRowElement?.(e);if(!t&&r&&i&&r.querySelectorAll(".cell.editing").forEach(l=>{const a=Number(l.getAttribute("data-col"));if(isNaN(a))return;const c=o._visibleColumns[a];if(!c)return;const d=l.querySelector("input,textarea,select");if(d){let h;d instanceof HTMLInputElement&&d.type==="checkbox"?h=d.checked:(h=d.value,c.type==="number"&&h!==""&&(h=Number(h))),i[c.field]!==h&&de(o,e,c,h,i)}}),t&&n&&i)Object.keys(n).forEach(s=>i[s]=n[s]),o._changedRowIndices.delete(e),le(o);else if(!t){const s=o._changedRowIndices.has(e);o.dispatchEvent(new CustomEvent("row-commit",{detail:{rowIndex:e,row:i,changed:s,changedRows:o.changedRows,changedRowIndices:o.changedRowIndices}}))}o._rowEditSnapshots.delete(e),o._activeEditRows=-1,r&&(V(o,r,o._rows[e],e),o._changedRowIndices.has(e)?r.classList.add("changed"):r.classList.remove("changed")),queueMicrotask(()=>{try{const s=o._focusRow,l=o._focusCol,a=o.findRenderedRowElement?.(s);if(a){Array.from(o._bodyEl.querySelectorAll(".cell-focus")).forEach(d=>d.classList.remove("cell-focus"));const c=a.querySelector(`.cell[data-row="${s}"][data-col="${l}"]`);c&&(c.classList.add("cell-focus"),c.setAttribute("aria-selected","true"),c.hasAttribute("tabindex")||c.setAttribute("tabindex","-1"),c.focus({preventScroll:!0}))}}catch{}})}function de(o,e,t,n,i){const r=t.field;if(!ce(r)||i[r]===n)return;i[r]=n;const l=!o._changedRowIndices.has(e);o._changedRowIndices.add(e);const a=o.findRenderedRowElement?.(e);a&&a.classList.add("changed"),o.dispatchEvent(new CustomEvent("cell-commit",{detail:{row:i,field:r,value:n,rowIndex:e,changedRows:o.changedRows,changedRowIndices:o.changedRowIndices,firstTimeForRow:l}}))}function O(o,e,t,n,i){if(!n.editable||(o._activeEditRows!==t&&W(o,t,e),i.classList.contains("editing")))return;const r=ce(n.field)?e[n.field]:void 0;i.classList.add("editing");let s=!1;const l=u=>{s||o._activeEditRows===-1||de(o,t,n,u,e)},a=()=>{s=!0,e[n.field]=ce(n.field)?r:void 0;const u=i.querySelector("input,textarea,select");u&&(typeof HTMLInputElement<"u"&&u instanceof HTMLInputElement&&u.type==="checkbox"?u.checked=!!r:"value"in u&&(u.value=r??""))},c=document.createElement("div");c.style.display="contents",i.innerHTML="",i.appendChild(c),c.addEventListener("keydown",u=>{u.key==="Enter"&&(u.stopPropagation(),u.preventDefault(),s=!0,B(o,t,!1)),u.key==="Escape"&&(u.stopPropagation(),u.preventDefault(),a(),B(o,t,!0))});const d=n.__editorTemplate,h=n.editor||(d?"template":Vt(n)),f=r;if(h==="template"&&d){const u=d.cloneNode(!0),p=n.__compiledEditor;p?u.innerHTML=p({row:e,value:r,field:n.field,column:n}):u.querySelectorAll("*").forEach(w=>{w.childNodes.length===1&&w.firstChild?.nodeType===Node.TEXT_NODE&&(w.textContent=w.textContent?.replace(/{{\s*value\s*}}/g,r==null?"":String(r)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(b,_)=>{const T=e[_];return T==null?"":String(T)})||"")});const g=u.querySelector("input,textarea,select");if(g){const w=typeof HTMLInputElement<"u";w&&g instanceof HTMLInputElement&&g.type==="checkbox"?g.checked=!!r:"value"in g&&(g.value=r??""),g.addEventListener("blur",()=>{const b=w&&g instanceof HTMLInputElement&&g.type==="checkbox"?g.checked:g.value;l(b)}),g.addEventListener("keydown",b=>{if(b.key==="Enter"){b.stopPropagation(),b.preventDefault(),s=!0;const _=w&&g instanceof HTMLInputElement&&g.type==="checkbox"?g.checked:g.value;l(_),B(o,t,!1)}b.key==="Escape"&&(b.stopPropagation(),b.preventDefault(),a(),B(o,t,!0))}),w&&g instanceof HTMLInputElement&&g.type==="checkbox"&&g.addEventListener("change",()=>{const b=g.checked;l(b)}),setTimeout(()=>g.focus(),0)}c.appendChild(u)}else if(typeof h=="string"){const u=document.createElement(h);u.value=f,u.addEventListener("change",()=>l(u.value)),c.appendChild(u)}else if(typeof h=="function"){const u=h({row:e,value:f,field:n.field,column:n,commit:l,cancel:a});typeof u=="string"?c.innerHTML=u:c.appendChild(u)}else if(h&&typeof h=="object"){const u=document.createElement("div");u.setAttribute("data-external-editor",""),u.setAttribute("data-field",n.field),c.appendChild(u);const p={row:e,value:f,field:n.field,column:n,commit:l,cancel:a};if(h.mount)try{h.mount({placeholder:u,context:p,spec:h})}catch{}else o.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:u,spec:h,context:p}}))}}function Be(o,e){!o._sortState||o._sortState.field!==e.field?(o._sortState||(o.__originalOrder=o._rows.slice()),$e(o,e,1)):o._sortState.direction===1?$e(o,e,-1):(o._sortState=null,o.__rowRenderEpoch++,o._rowPool.forEach(n=>n.__epoch=-1),o._rows=o.__originalOrder.slice(),j(o),o._headerRowEl?.querySelectorAll('[role="columnheader"].sortable')?.forEach(n=>{n.getAttribute("aria-sort")?(n.getAttribute("aria-sort")==="ascending"||n.getAttribute("aria-sort")==="descending")&&(o._sortState||n.setAttribute("aria-sort","none")):n.setAttribute("aria-sort","none")}),o.refreshVirtualWindow(!0),o.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:0}})),o.requestStateChange?.())}function $e(o,e,t){o._sortState={field:e.field,direction:t};const n=e.sortComparator||((i,r)=>i==null&&r==null?0:i==null?-1:r==null||i>r?1:i<r?-1:0);o._rows.sort((i,r)=>n(i[e.field],r[e.field],i,r)*t),o.__rowRenderEpoch++,o._rowPool.forEach(i=>i.__epoch=-1),j(o),o.refreshVirtualWindow(!0),o.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:t}})),o.requestStateChange?.()}function Yt(o,e){typeof e=="string"?o.textContent=e:e instanceof HTMLElement&&(o.innerHTML="",o.appendChild(e.cloneNode(!0)))}function j(o){o._headerRowEl=o.findHeaderRow();const e=o._headerRowEl;e.innerHTML="",o._visibleColumns.forEach((t,n)=>{const i=document.createElement("div");i.className="cell",se(i,"header-cell"),i.setAttribute("role","columnheader"),i.setAttribute("aria-colindex",String(n+1)),i.setAttribute("data-field",t.field),i.setAttribute("data-col",String(n));const r=t.__headerTemplate;if(r)Array.from(r.childNodes).forEach(s=>i.appendChild(s.cloneNode(!0)));else{const s=t.header||t.field,l=document.createElement("span");l.textContent=s,i.appendChild(l)}if(t.sortable){i.classList.add("sortable"),i.tabIndex=0;const s=document.createElement("span");se(s,"sort-indicator"),s.style.opacity="0.6";const l=o._sortState?.field===t.field?o._sortState.direction:0,a={...I,...o.icons},c=l===1?a.sortAsc:l===-1?a.sortDesc:a.sortNone;Yt(s,c),i.appendChild(s),i.setAttribute("aria-sort",l===0?"none":l===1?"ascending":"descending"),i.addEventListener("click",d=>{o._resizeController?.isResizing||o._dispatchHeaderClick?.(d,n,i)||Be(o,t)}),i.addEventListener("keydown",d=>{if(d.key==="Enter"||d.key===" "){if(d.preventDefault(),o._dispatchHeaderClick?.(d,n,i))return;Be(o,t)}})}if(t.resizable){i.style.position="relative";const s=document.createElement("div");s.className="resize-handle",s.setAttribute("aria-hidden","true"),s.addEventListener("mousedown",l=>{l.stopPropagation(),l.preventDefault(),o._resizeController.start(l,n,i)}),i.appendChild(s)}e.appendChild(i)}),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"))}function Zt(o){let e=null,t=null,n=null,i=null;const r=a=>{if(!e)return;const c=a.clientX-e.startX,d=Math.max(40,e.startWidth+c),h=o._visibleColumns[e.colIndex];h.width=d,h.__userResized=!0,h.__renderedWidth=d,t==null&&(t=requestAnimationFrame(()=>{t=null,o.updateTemplate?.()})),o.dispatchEvent(new CustomEvent("column-resize",{detail:{field:h.field,width:d}}))};let s=!1;const l=()=>{const a=e!==null;a&&(s=!0,requestAnimationFrame(()=>{s=!1})),window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",l),n!==null&&(document.documentElement.style.cursor=n,n=null),i!==null&&(document.body.style.userSelect=i,i=null),e=null,a&&o.requestStateChange&&o.requestStateChange()};return{get isResizing(){return e!==null||s},start(a,c,d){a.preventDefault();const h=d.getBoundingClientRect();e={startX:a.clientX,colIndex:c,startWidth:h.width},window.addEventListener("mousemove",r),window.addEventListener("mouseup",l),n===null&&(n=document.documentElement.style.cursor),document.documentElement.style.cursor="e-resize",i===null&&(i=document.body.style.userSelect),document.body.style.userSelect="none"},dispose(){l()}}}function Q(o){return o?typeof o=="string"?o:o.outerHTML:""}function Jt(){return{toolPanels:new Map,headerContents:new Map,toolbarButtons:new Map,lightDomButtons:[],lightDomHeaderContent:[],isPanelOpen:!1,expandedSections:new Set,headerContentCleanups:new Map,panelCleanups:new Map,toolbarButtonCleanups:new Map,activePanel:null,activePanelCleanup:null}}function Qt(o,e){return!!(o?.header?.title||o?.header?.toolbarButtons?.length||e.toolPanels.size>0||e.headerContents.size>0||e.toolbarButtons.size>0||e.lightDomButtons.length>0||e.lightDomHeaderContent.length>0)}function eo(o,e,t="☰"){const n=o?.header?.title??"",i=!!n,r=Q(t),s=o?.header?.toolbarButtons??[],l=s.length>0,a=e.toolbarButtons.size>0,c=e.lightDomButtons.length>0,d=e.toolPanels.size>0,f=(l||a||c)&&d,u=[...s].sort((w,b)=>(w.order??100)-(b.order??100)),p=[...e.toolbarButtons.values()].sort((w,b)=>(w.order??100)-(b.order??100));let g="";for(const w of u)w.icon&&w.action&&(g+=`<button class="tbw-toolbar-btn" data-btn="${w.id}" title="${w.label}" aria-label="${w.label}"${w.disabled?" disabled":""}>${w.icon}</button>`);for(const w of p)w.icon&&w.action&&(g+=`<button class="tbw-toolbar-btn" data-btn="${w.id}" title="${w.label}" aria-label="${w.label}"${w.disabled?" disabled":""}>${w.icon}</button>`);for(const w of u)(w.element||w.render)&&(g+=`<div class="tbw-toolbar-btn-slot" data-btn-slot="${w.id}"></div>`);for(const w of p)(w.element||w.render)&&(g+=`<div class="tbw-toolbar-btn-slot" data-btn-slot="${w.id}"></div>`);if(c&&(g+='<slot name="toolbar"></slot>'),f&&(g+='<div class="tbw-toolbar-separator"></div>'),d){const w=e.isPanelOpen;g+=`<button class="tbw-toolbar-btn${w?" active":""}" data-panel-toggle title="Settings" aria-label="Toggle settings panel" aria-pressed="${w}" aria-controls="tbw-tool-panel">${r}</button>`}return`
|
|
1
|
+
(function(y,J){typeof exports=="object"&&typeof module<"u"?J(exports):typeof define=="function"&&define.amd?define(["exports"],J):(y=typeof globalThis<"u"?globalThis:y||self,J(y.TbwGrid={}))})(this,(function(y){"use strict";const J=":root{color-scheme:light dark}:host{--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-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, #adacac);--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: inherit;--tbw-font-size-header: var(--tbw-font-size);--tbw-font-weight-header: bold;--tbw-cell-padding-header: 2px 8px;--tbw-cell-padding: 2px 8px;--tbw-cell-padding-input: 2px 6px;--tbw-row-height: 28px;--tbw-header-height: 30px;--tbw-cell-white-space: nowrap;--tbw-border-radius: 4px;--tbw-border-input: 1px solid var(--tbw-color-border-strong);--tbw-border-header: 1px solid var(--tbw-color-border-header);--tbw-row-divider: 1px solid var(--tbw-color-border-cell);--tbw-row-hover-outline: 0;--tbw-color-active-row-bg: var(--tbw-color-selection);--tbw-active-row-outline: 0;--tbw-focus-outline: 2px solid var(--tbw-color-accent);--tbw-focus-outline-offset: -2px;--tbw-focus-background: rgba(from var(--tbw-color-accent) r g b / 12%);--tbw-range-border-color: var(--tbw-color-accent);--tbw-range-selection-bg: rgba(from var(--tbw-range-border-color) r g b / 12%);--tbw-resize-handle-width: 6px;--tbw-resize-handle-color: transparent;--tbw-resize-handle-color-hover: var(--tbw-color-accent);--tbw-resize-handle-border-radius: 0;--tbw-scrollbar-thumb: var(--tbw-color-border-strong);--tbw-scrollbar-track: var(--tbw-color-bg);--tbw-transition-duration: .12s;--tbw-transition-ease: ease;--tbw-editing-bg: var(--tbw-color-selection);--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-sort-indicator-color: var(--tbw-color-fg-muted);--tbw-sort-indicator-active-color: var(--tbw-color-accent);--tbw-header-text-transform: none;--tbw-header-letter-spacing: normal;--tbw-color-header-separator: var(--tbw-color-border-cell);--tbw-checkbox-size: 16px;--tbw-density-scale: 1}:host{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);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}:host,:host *{box-sizing:border-box}:host .header{display:block;flex-shrink:0;z-index:var(--tbw-z-layer-header, 30);background:var(--tbw-color-header-bg);overflow:visible}:host .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)}:host .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))}:host .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)}:host .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:hidden;min-width:0}:host .header-row>.cell>span:first-child{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}:host .header-row>.cell>span[part~=sort-indicator]{flex-shrink:0}:host .header-row>.cell:last-child{border-right:0}:host .header-group-cell,:host .header-row>.cell.grouped.group-end{border-right:2px solid var(--tbw-color-border)}:host .tbw-grid-root{display:flex;flex-direction:column;height:100%}:host .rows-body-wrapper{flex:1;min-height:0;display:flex;flex-direction:row;width:100%;min-width:fit-content}:host .rows-body{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow:visible}:host .rows-container{display:flex;flex-direction:row;flex:1;min-height:0;overflow:visible}:host .rows-viewport{flex:1;min-width:0;position:relative;display:block;overflow:clip}:host .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)}:host .faux-vscroll-spacer{width:1px}:host .rows-viewport .rows{position:absolute;top:0;left:0;min-width:100%;will-change:transform;z-index:var(--tbw-z-layer-rows, 1)}:host .data-grid-row{display:grid;grid-template-columns:var(--tbw-column-template);contain:layout style}:host .data-grid-row:has(.editing){background:var(--tbw-editing-bg)}:host .selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}:host .data-grid-row>.cell.selected:focus-visible,:host .data-grid-row>.cell:focus-visible:not(.cell-focus){outline:none}:host .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);line-height:calc(var(--tbw-row-height) - 5px);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}:host .data-grid-row>.cell>*{overflow:hidden;text-overflow:ellipsis;white-space:inherit;min-width:0}:host .data-grid-row>.cell:last-child{border-right:0}:host .data-grid-row>.cell[data-type=boolean]{text-align:center}:host .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}:host .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex}:host .data-grid-row>.cell.editing input:not([type=checkbox]),:host .data-grid-row>.cell.editing select,:host .data-grid-row>.cell.editing textarea{width:100%;height:100%;max-width: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)}:host .data-grid-row:nth-child(2n){background:var(--tbw-color-row-alt)}:host .data-grid-row:hover{background:var(--tbw-color-row-hover)}:host .sortable{cursor:pointer;-webkit-user-select:none;user-select:none}:host .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)}:host .resize-handle:hover{background:var(--tbw-resize-handle-color-hover)}:host .cell-focus,:host .row-focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}:host .group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-color-row-alt);font-weight:500;border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height)}:host .group-row .cell{display:flex;align-items:center;padding:var(--tbw-cell-padding, 2px 8px)}:host .group-row .group-toggle{background:none;border:0;cursor:pointer;padding:0 4px 0 0;font:inherit}:host .group-row .group-count{margin-left:4px;opacity:.7}:host .sticky-left,:host .sticky-right{position:sticky;z-index:25}:host .header-row>.cell.sticky-left,:host .header-row>.cell.sticky-right{background:var(--tbw-color-header-bg);z-index:35}:host .data-grid-row>.cell.sticky-left,:host .data-grid-row>.cell.sticky-right{background:var(--tbw-color-panel-bg)}:host .sticky-left{box-shadow:1px 0 0 var(--tbw-color-border)}:host .sticky-right{box-shadow:-1px 0 0 var(--tbw-color-border)}.grid-container{position:relative;width:100%;height:100%}.grid-placeholder{padding:2rem;text-align:center;color:var(--tbw-color-fg);opacity:.6}:host{--tbw-shell-header-height: 44px;--tbw-shell-header-bg: var(--tbw-color-panel-bg);--tbw-shell-header-border: var(--tbw-color-border);--tbw-shell-title-font-size: 14px;--tbw-shell-title-font-weight: 600;--tbw-tool-panel-width: 280px;--tbw-tool-panel-bg: var(--tbw-color-panel-bg);--tbw-tool-panel-border: var(--tbw-color-border);--tbw-tool-panel-header-height: 40px;--tbw-tool-panel-transition: .2s ease-out;--tbw-toolbar-button-size: 32px;--tbw-toolbar-button-gap: 4px}:host .tbw-grid-root.has-shell{display:flex;flex-direction:column;height:100%}:host .tbw-shell-header{display:flex;align-items:center;gap:8px;min-height:var(--tbw-shell-header-height);padding:0 8px;background:var(--tbw-shell-header-bg);border-bottom:1px solid var(--tbw-shell-header-border);flex-shrink:0}:host .tbw-shell-title{font-size:var(--tbw-shell-title-font-size);font-weight:var(--tbw-shell-title-font-weight);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host .tbw-shell-content{flex:1;display:flex;align-items:center;gap:12px;min-width:0;overflow:hidden}:host .tbw-shell-toolbar{display:flex;align-items:center;gap:var(--tbw-toolbar-button-gap);flex-shrink:0}:host .tbw-toolbar-btn{display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-toolbar-button-size);height:var(--tbw-toolbar-button-size);padding:0;border:1px solid transparent;border-radius:var(--tbw-border-radius);background:transparent;color:var(--tbw-color-fg);cursor:pointer;font-size:16px;transition:background var(--tbw-transition-duration) var(--tbw-transition-ease),border-color var(--tbw-transition-duration) var(--tbw-transition-ease)}:host .tbw-toolbar-btn:hover{background:var(--tbw-color-row-hover)}:host .tbw-toolbar-btn:focus-visible{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}:host .tbw-toolbar-btn.active{background:var(--tbw-focus-background);border-color:var(--tbw-color-accent)}:host .tbw-toolbar-btn:disabled{opacity:.5;cursor:not-allowed}:host .tbw-toolbar-separator{width:1px;height:20px;background:var(--tbw-color-border);margin:0 4px}:host .tbw-shell-body{position:relative;display:flex;flex:1;min-height:0;overflow:visible}:host .tbw-grid-content{flex:1;min-width:0;min-height:0;display:flex;flex-direction:row;overflow:hidden}:host .tbw-scroll-area{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow-x:auto;overflow-y:hidden}:host .tbw-tool-panel{position:absolute;top:0;bottom:0;right:0;width:0;overflow:hidden;background:var(--tbw-tool-panel-bg);border-left:1px solid var(--tbw-tool-panel-border);transition:width var(--tbw-tool-panel-transition);display:flex;flex-direction:column;z-index:30;box-shadow:-2px 0 8px var(--tbw-color-shadow)}:host .tbw-tool-panel[data-position=left]{right:auto;left:0;border-left:none;border-right:1px solid var(--tbw-tool-panel-border);box-shadow:2px 0 8px var(--tbw-color-shadow)}:host .tbw-tool-panel.open{width:var(--tbw-tool-panel-width)}:host .tbw-tool-panel-resize{position:absolute;top:0;bottom:0;width:6px;cursor:col-resize;background:transparent;z-index:10;transition:background .15s ease}:host .tbw-tool-panel-resize[data-handle-position=left]{left:0}:host .tbw-tool-panel-resize[data-handle-position=right]{right:0}:host .tbw-tool-panel-resize:hover,:host .tbw-tool-panel-resize.resizing{background:var(--tbw-color-accent)}:host .tbw-tool-panel-header{display:flex;align-items:center;justify-content:space-between;min-height:var(--tbw-tool-panel-header-height);padding:0 12px;border-bottom:1px solid var(--tbw-tool-panel-border);flex-shrink:0}:host .tbw-tool-panel-title{font-weight:600;font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host .tbw-tool-panel-close{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;padding:0;border:none;border-radius:var(--tbw-border-radius);background:transparent;color:var(--tbw-color-fg-muted);cursor:pointer;font-size:14px}:host .tbw-tool-panel-close:hover{background:var(--tbw-color-row-hover);color:var(--tbw-color-fg)}:host .tbw-tool-panel-content{flex:1;overflow:auto}:host .tbw-accordion{display:flex;flex-direction:column;gap:0}:host .tbw-accordion-section{border-bottom:1px solid var(--tbw-tool-panel-border)}:host .tbw-accordion-section:last-child{border-bottom:none}:host .tbw-accordion-header{display:flex;align-items:center;gap:8px;width:100%;padding:10px 12px;border:none;background:transparent;color:var(--tbw-color-fg);font-size:13px;font-weight:600;text-align:left;cursor:pointer;-webkit-user-select:none;user-select:none}:host .tbw-accordion-header:hover{background:var(--tbw-color-row-hover)}:host .tbw-accordion-section.single .tbw-accordion-header{cursor:default}:host .tbw-accordion-section.single .tbw-accordion-header:hover{background:transparent}:host .tbw-accordion-chevron{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:10px;color:var(--tbw-color-fg-muted);transition:transform .15s ease;flex-shrink:0}:host .tbw-accordion-section.expanded .tbw-accordion-chevron{transform:rotate(90deg)}:host .tbw-accordion-icon{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:14px;flex-shrink:0}:host .tbw-accordion-title{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}:host .tbw-accordion-content{display:none}:host .tbw-accordion-section.expanded .tbw-accordion-content{display:block}:host .tbw-quick-filter-input{flex:1;max-width:300px;height:28px;padding:0 8px;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:13px}:host .tbw-quick-filter-input:focus{outline:none;border-color:var(--tbw-color-accent)}:host .tbw-selection-summary{font-size:13px;color:var(--tbw-color-fg-muted);white-space:nowrap}";function kt(o){const e=new Map;return o._sortState&&e.set(o._sortState.field,{direction:o._sortState.direction===1?"asc":"desc",priority:0}),e}function He(o,e){const t=o._columns,n=kt(o);return{columns:t.map((i,r)=>{const s={field:i.field,order:r,visible:!0},l=i;l.__renderedWidth!==void 0?s.width=l.__renderedWidth:i.width!==void 0&&(s.width=typeof i.width=="string"?parseFloat(i.width):i.width);const a=n.get(i.field);a&&(s.sort=a);for(const c of e)if(c.getColumnState){const d=c.getColumnState(i.field);d&&Object.assign(s,d)}return s})}}function Tt(o,e,t,n){if(!e.columns||e.columns.length===0)return;const i=new Map(e.columns.map(l=>[l.field,l])),r=t.map(l=>{const a=i.get(l.field);if(!a)return l;const c={...l};return a.width!==void 0&&(c.width=a.width,c.__renderedWidth=a.width),a.visible!==void 0&&(c.hidden=!a.visible),c});r.sort((l,a)=>{const c=i.get(l.field)?.order??1/0,d=i.get(a.field)?.order??1/0;return c-d}),o._columns=r;const s=e.columns.filter(l=>l.sort!==void 0).sort((l,a)=>(l.sort?.priority??0)-(a.sort?.priority??0));if(s.length>0){const l=s[0];l.sort&&(o._sortState={field:l.field,direction:l.sort.direction==="asc"?1:-1})}else o._sortState=null;for(const l of n)if(l.applyColumnState)for(const a of e.columns)l.applyColumnState(a.field,a)}function Lt(o,e,t){let n=null;return()=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{n=null;const i=He(o,e());t(i)},100)}}const K={STRETCH:"stretch",FIXED:"fixed"},I={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰"};function Pt(o){return o==null?"string":typeof o=="number"?"number":typeof o=="boolean"?"boolean":o instanceof Date||typeof o=="string"&&/\d{4}-\d{2}-\d{2}/.test(o)&&!isNaN(Date.parse(o))?"date":"string"}function Ne(o,e){if(e&&e.length){const r={};return e.forEach(s=>{s.type&&(r[s.field]=s.type)}),{columns:e,typeMap:r}}const t=o[0]||{},n=Object.keys(t).map(r=>{const s=t[r],l=Pt(s);return{field:r,header:r.charAt(0).toUpperCase()+r.slice(1),type:l}}),i={};return n.forEach(r=>{i[r.field]=r.type||"string"}),{columns:n,typeMap:i}}const Mt=/{{\s*([^}]+)\s*}}/g,H="__DG_EMPTY__",It=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,Ht=/__(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/,Nt=new Set(["script","iframe","object","embed","form","input","button","textarea","select","link","meta","base","style","template","slot","portal","frame","frameset","applet","noscript","noembed","plaintext","xmp","listing"]),De=/^on\w+$/i,Dt=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),Ot=/^\s*(javascript|vbscript|data|blob):/i;function ne(o){if(!o||typeof o!="string")return"";if(o.indexOf("<")===-1)return o;const e=document.createElement("template");return e.innerHTML=o,zt(e.content),e.innerHTML}function zt(o){const e=[],t=o.querySelectorAll("*");for(const n of t){const i=n.tagName.toLowerCase();if(Nt.has(i)){e.push(n);continue}if((i==="svg"||n.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(n.attributes).some(l=>De.test(l.name)||l.name==="href"||l.name==="xlink:href")){e.push(n);continue}const r=[];for(const s of n.attributes){const l=s.name.toLowerCase();if(De.test(l)){r.push(s.name);continue}if(Dt.has(l)&&Ot.test(s.value)){r.push(s.name);continue}if(l==="style"&&/expression\s*\(|javascript:|behavior\s*:/i.test(s.value)){r.push(s.name);continue}}r.forEach(s=>n.removeAttribute(s))}e.forEach(n=>n.remove())}function Oe(o,e){if(!o||o.indexOf("{{")===-1)return o;const t=[],n=o.replace(Mt,(l,a)=>{const c=qt(a,e);return t.push({expr:a.trim(),result:c}),c}),i=Ft(n),r=t.length&&t.every(l=>l.result===""||l.result===H);return/Reflect\.|\bProxy\b|ownKeys\(/.test(o)||r?"":i}function qt(o,e){if(o=(o||"").trim(),!o||/\b(Reflect|Proxy|ownKeys)\b/.test(o))return H;if(o==="value")return e.value==null?H:String(e.value);if(o.startsWith("row.")&&!/[()?]/.test(o)&&!o.includes(":")){const n=o.slice(4),i=e.row?e.row[n]:void 0;return i==null?H:String(i)}if(o.length>80||!It.test(o)||Ht.test(o))return H;const t=o.match(/\./g);if(t&&t.length>1)return H;try{const i=new Function("value","row",`return (${o});`)(e.value,e.row),r=i==null?"":String(i);return/Reflect|Proxy|ownKeys/.test(r)?H:r||H}catch{return H}}function Ft(o){return o&&o.replace(new RegExp(H,"g"),"").replace(/Reflect\.[^<>{}\s]+/g,"").replace(/\bProxy\b/g,"").replace(/ownKeys\([^)]*\)/g,"")}function Bt(o){if(/Reflect|Proxy|ownKeys/.test(o.textContent||"")){if(Array.from(o.childNodes).forEach(e=>{e.nodeType===Node.TEXT_NODE&&/Reflect|Proxy|ownKeys/.test(e.textContent||"")&&(e.textContent="")}),/Reflect|Proxy|ownKeys/.test(o.textContent||"")){if(/Reflect|Proxy|ownKeys/.test(o.textContent||""))for(;o.firstChild;)o.removeChild(o.firstChild);o.textContent=(o.textContent||"").replace(/Reflect|Proxy|ownKeys/g,"")}(o.textContent||"").trim().length===0&&(o.textContent="")}}function ze(o){const e=/Reflect\.|\bProxy\b|ownKeys\(/.test(o),t=n=>e?"":Oe(o,n);return t.__blocked=e,t}function $t(o){return Array.from(o.querySelectorAll("tbw-grid-column")).map(t=>{const n=t.getAttribute("field")||"";if(!n)return null;const i=t.getAttribute("type")||void 0,s=i&&new Set(["number","string","date","boolean","select","typeahead"]).has(i)?i:void 0,l=t.getAttribute("header")||void 0,a=t.hasAttribute("sortable"),c=t.hasAttribute("editable"),d={field:n,type:s,header:l,sortable:a,editable:c};t.hasAttribute("resizable")&&(d.resizable=!0),t.hasAttribute("sizable")&&(d.resizable=!0);const h=t.getAttribute("options");h&&(d.options=h.split(",").map(g=>{const[w,b]=g.includes(":")?g.split(":"):[g.trim(),g.trim()];return{value:w.trim(),label:b?.trim()||w.trim()}}));const f=t.querySelector("tbw-grid-column-view"),u=t.querySelector("tbw-grid-column-editor"),p=t.querySelector("tbw-grid-column-header");return f&&(d.__viewTemplate=f),u&&(d.__editorTemplate=u),p&&(d.__headerTemplate=p),d}).filter(t=>!!t)}function Gt(o,e){if((!o||!o.length)&&(!e||!e.length))return[];if(!o||!o.length)return e||[];if(!e||!e.length)return o;const t={};e.forEach(i=>t[i.field]=i);const n=o.map(i=>{const r=t[i.field];if(!r)return i;const s={...i};return r.header&&!s.header&&(s.header=r.header),r.type&&!s.type&&(s.type=r.type),s.sortable=i.sortable||r.sortable,(i.resizable===!0||r.resizable===!0)&&(s.resizable=!0),s.editable=i.editable||r.editable,r.__viewTemplate&&(s.__viewTemplate=r.__viewTemplate),r.__editorTemplate&&(s.__editorTemplate=r.__editorTemplate),r.__headerTemplate&&(s.__headerTemplate=r.__headerTemplate),delete t[i.field],s});return Object.keys(t).forEach(i=>n.push(t[i])),n}function se(o,e){try{o.part?.add?.(e)}catch{}const t=o.getAttribute("part");t?t.split(/\s+/).includes(e)||o.setAttribute("part",t+" "+e):o.setAttribute("part",e)}function Kt(o){o.__lightDomColumnsCache||(o.__originalColumnNodes=Array.from(o.querySelectorAll("tbw-grid-column")),o.__lightDomColumnsCache=o.__originalColumnNodes.length?$t(o):[]);const e=o.__lightDomColumnsCache,t=Gt(o._columns,e);t.forEach(i=>{i.__viewTemplate&&!i.__compiledView&&(i.__compiledView=ze(i.__viewTemplate.innerHTML)),i.__editorTemplate&&!i.__compiledEditor&&(i.__compiledEditor=ze(i.__editorTemplate.innerHTML))});const{columns:n}=Ne(o._rows,t);o._columns=n}function qe(o){const e=o.effectiveConfig?.fitMode||o.fitMode||K.STRETCH;if(e!==K.STRETCH&&e!==K.FIXED||o.__didInitialAutoSize||!o.isConnected)return;const t=o._headerRowEl?.children||[];if(!t.length)return;let n=!1;o._visibleColumns.forEach((i,r)=>{if(i.width)return;const s=t[r];let l=s?s.scrollWidth:0;for(const a of o._rowPool){const c=a.children[r];if(c){const d=c.scrollWidth;d>l&&(l=d)}}l>0&&(i.width=l+2,i.__autoSized=!0,n=!0)}),n&&B(o),o.__didInitialAutoSize=!0}function B(o){(o.effectiveConfig?.fitMode||o.fitMode||K.STRETCH)===K.STRETCH?o._gridTemplate=o._visibleColumns.map(t=>{if(t.width)return`${t.width}px`;const n=t.minWidth;return n!=null?`minmax(${n}px, 1fr)`:"1fr"}).join(" ").trim():o._gridTemplate=o._visibleColumns.map(t=>t.width?`${t.width}px`:"max-content").join(" "),o.style.setProperty("--tbw-column-template",o._gridTemplate)}function Vt(o){switch(o.type){case"number":return e=>{const t=document.createElement("input");return t.type="number",t.value=e.value!=null?String(e.value):"",t.addEventListener("blur",()=>e.commit(t.value===""?null:Number(t.value))),t.addEventListener("keydown",n=>{n.key==="Enter"&&e.commit(t.value===""?null:Number(t.value)),n.key==="Escape"&&e.cancel()}),t.focus(),t};case"boolean":return e=>{const t=document.createElement("input");return t.type="checkbox",t.checked=!!e.value,t.addEventListener("change",()=>e.commit(t.checked)),t.focus(),t};case"date":return e=>{const t=document.createElement("input");return t.type="date",e.value instanceof Date&&(t.valueAsDate=e.value),t.addEventListener("change",()=>e.commit(t.valueAsDate)),t.addEventListener("keydown",n=>{n.key==="Escape"&&e.cancel()}),t.focus(),t};case"select":case"typeahead":return e=>{const t=document.createElement("select");e.column.multi&&(t.multiple=!0),(typeof e.column.options=="function"?e.column.options():e.column.options||[]).forEach(r=>{const s=document.createElement("option");s.value=String(r.value),s.textContent=r.label,(e.column.multi&&Array.isArray(e.value)&&e.value.includes(r.value)||!e.column.multi&&e.value===r.value)&&(s.selected=!0),t.appendChild(s)});const i=()=>{if(e.column.multi){const r=[];Array.from(t.selectedOptions).forEach(s=>{r.push(s.value)}),e.commit(r)}else e.commit(t.value)};return t.addEventListener("change",i),t.addEventListener("blur",i),t.addEventListener("keydown",r=>{r.key==="Escape"&&e.cancel()}),t.focus(),t};default:return e=>{const t=document.createElement("input");return t.type="text",t.value=e.value!=null?String(e.value):"",t.addEventListener("blur",()=>e.commit(t.value)),t.addEventListener("keydown",n=>{n.key==="Enter"&&e.commit(t.value),n.key==="Escape"&&e.cancel()}),t.focus(),t}}}function Wt(o,e){if(o._dispatchKeyDown?.(e))return;const t=o._rows.length-1,n=o._visibleColumns.length-1,i=o._activeEditRows!==void 0&&o._activeEditRows!==-1,s=o._visibleColumns[o._focusCol]?.type,l=e.composedPath?e.composedPath():[],a=l&&l.length?l[0]:e.target,c=d=>{if(!d)return!1;const h=d.tagName;return!!(h==="INPUT"||h==="SELECT"||h==="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"))&&!(i&&(s==="select"||s==="typeahead")&&(e.key==="ArrowDown"||e.key==="ArrowUp"))){switch(e.key){case"Tab":{e.preventDefault(),!e.shiftKey?o._focusCol<n?o._focusCol+=1:(typeof o.commitActiveRowEdit=="function"&&o.commitActiveRowEdit(),o._focusRow<t&&(o._focusRow+=1,o._focusCol=0)):o._focusCol>0?o._focusCol-=1:o._focusRow>0&&(typeof o.commitActiveRowEdit=="function"&&o._activeEditRows===o._focusRow&&o.commitActiveRowEdit(),o._focusRow-=1,o._focusCol=n),z(o);return}case"ArrowDown":i&&typeof o.commitActiveRowEdit=="function"&&o.commitActiveRowEdit(),o._focusRow=Math.min(t,o._focusRow+1),e.preventDefault();break;case"ArrowUp":i&&typeof o.commitActiveRowEdit=="function"&&o.commitActiveRowEdit(),o._focusRow=Math.max(0,o._focusRow-1),e.preventDefault();break;case"ArrowRight":o._focusCol=Math.min(n,o._focusCol+1),e.preventDefault();break;case"ArrowLeft":o._focusCol=Math.max(0,o._focusCol-1),e.preventDefault();break;case"Home":(e.ctrlKey||e.metaKey)&&(i&&typeof o.commitActiveRowEdit=="function"&&o.commitActiveRowEdit(),o._focusRow=0),o._focusCol=0,e.preventDefault(),z(o,{forceScrollLeft:!0});return;case"End":(e.ctrlKey||e.metaKey)&&(i&&typeof o.commitActiveRowEdit=="function"&&o.commitActiveRowEdit(),o._focusRow=t),o._focusCol=n,e.preventDefault(),z(o,{forceScrollRight:!0});return;case"PageDown":o._focusRow=Math.min(t,o._focusRow+20),e.preventDefault();break;case"PageUp":o._focusRow=Math.max(0,o._focusRow-20),e.preventDefault();break;case"Enter":return typeof o.beginBulkEdit=="function"?o.beginBulkEdit(o._focusRow):o.dispatchEvent(new CustomEvent("activate-cell",{detail:{row:o._focusRow,col:o._focusCol}})),z(o);default:return}z(o)}}function z(o,e){if(o._virtualization?.enabled){const{rowHeight:s,container:l,viewportEl:a}=o._virtualization,c=l,d=a?.clientHeight??c?.clientHeight??0;if(c&&d>0){const h=o._focusRow*s;h<c.scrollTop?c.scrollTop=h:h+s>c.scrollTop+d&&(c.scrollTop=h-d+s)}}o._activeEditRows!==void 0&&o._activeEditRows!==-1||o.refreshVirtualWindow(!1),Array.from(o._bodyEl.querySelectorAll(".cell-focus")).forEach(s=>s.classList.remove("cell-focus")),Array.from(o._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(s=>{s.setAttribute("aria-selected","false")});const n=o._focusRow,i=o._virtualization.start??0,r=o._virtualization.end??o._rows.length;if(n>=i&&n<r){const s=o._bodyEl.querySelectorAll(".data-grid-row")[n-i],l=s?.children[o._focusCol];if(l){l.classList.add("cell-focus"),l.setAttribute("aria-selected","true");const a=o.shadowRoot?.querySelector(".tbw-scroll-area");if(a&&l)if(e?.forceScrollLeft)a.scrollLeft=0;else if(e?.forceScrollRight)a.scrollLeft=a.scrollWidth-a.clientWidth;else{const c=o._getHorizontalScrollOffsets?.(s??void 0,l)??{left:0,right:0};if(!c.skipScroll){const d=l.getBoundingClientRect(),h=a.getBoundingClientRect(),f=d.left-h.left+a.scrollLeft,u=f+d.width,p=a.scrollLeft+c.left,g=a.scrollLeft+a.clientWidth-c.right;f<p?a.scrollLeft=f-c.left:u>g&&(a.scrollLeft=u-a.clientWidth+c.right)}}if(o._activeEditRows!==void 0&&o._activeEditRows!==-1&&l.classList.contains("editing")){const c=l.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(c&&document.activeElement!==c)try{c.focus()}catch{}}else if(!l.contains(document.activeElement)){l.hasAttribute("tabindex")||l.setAttribute("tabindex","-1");try{l.focus({preventScroll:!0})}catch{}}}}}const jt="__cellDisplayCache",Ut="__cellCacheEpoch";function le(o){o[jt]=void 0,o[Ut]=void 0,o.__hasSpecialColumns=void 0}function Xt(o,e,t,n,i){const r=Math.max(0,t-e),s=o._bodyEl,l=o._visibleColumns,a=l.length;let c=o.__cachedHeaderRowCount;for(c===void 0&&(c=o.shadowRoot?.querySelector(".header-group-row")?2:1,o.__cachedHeaderRowCount=c);o._rowPool.length<r;){const h=document.createElement("div");h.className="data-grid-row",h.setAttribute("role","row"),h.addEventListener("click",f=>Fe(o,f,h,!1)),h.addEventListener("dblclick",f=>Fe(o,f,h,!0)),o._rowPool.push(h)}if(o._rowPool.length>r){for(let h=r;h<o._rowPool.length;h++){const f=o._rowPool[h];f.parentNode===s&&f.remove()}o._rowPool.length=r}const d=i&&o.__hasRenderRowPlugins!==!1;for(let h=0;h<r;h++){const f=e+h,u=o._rows[f],p=o._rowPool[h];if(p.setAttribute("aria-rowindex",String(f+c+1)),d&&i(u,p,f)){p.__epoch=n,p.__rowDataRef=u,p.parentNode!==s&&s.appendChild(p);continue}const g=p.__epoch,w=p.__rowDataRef,b=p.children.length,T=g===n&&b===a,k=w!==u;let m=!1;if(T&&k){for(let E=0;E<a;E++)if(l[E].externalView&&!p.querySelector(`.cell[data-col="${E}"] [data-external-view]`)){m=!0;break}}if(!T||m){const E=p.querySelector(".cell.editing"),C=o._activeEditRows===f;if(E&&!C)p.__isCustomRow&&(p.className="data-grid-row",p.setAttribute("role","row"),p.__isCustomRow=!1),V(o,p,u,f),p.__epoch=n,p.__rowDataRef=u;else if(E&&C)ae(o,p,u,f),p.__rowDataRef=u;else if(p.__isCustomRow&&(p.className="data-grid-row",p.setAttribute("role","row"),p.__isCustomRow=!1),V(o,p,u,f),p.__epoch=n,p.__rowDataRef=u,C){const x=p.children;for(let R=0;R<x.length;R++){const A=o._visibleColumns[R];A&&A.editable&&D(o,u,f,A,x[R])}}}else if(k){const E=p.querySelector(".cell.editing"),C=o._activeEditRows===f;if(E&&!C)V(o,p,u,f),p.__epoch=n,p.__rowDataRef=u;else if(ae(o,p,u,f),p.__rowDataRef=u,C&&!E){const x=p.children;for(let R=0;R<x.length;R++){const A=o._visibleColumns[R];A&&A.editable&&D(o,u,f,A,x[R])}}}else{const E=p.querySelector(".cell.editing"),C=o._activeEditRows===f;if(E&&!C)V(o,p,u,f),p.__epoch=n,p.__rowDataRef=u;else if(ae(o,p,u,f),C&&!E){const x=p.children;for(let R=0;R<x.length;R++){const A=o._visibleColumns[R];A&&A.editable&&D(o,u,f,A,x[R])}}}const v=o._changedRowIndices.has(f),S=p.classList.contains("changed");v!==S&&p.classList.toggle("changed",v),p.parentNode!==s&&s.appendChild(p)}}function ae(o,e,t,n){const i=e.children,r=o._visibleColumns,s=r.length,l=i.length,a=s<l?s:l,c=o._focusRow,d=o._focusCol;let h=o.__hasSpecialColumns;if(h===void 0){h=!1;for(let u=0;u<s;u++){const p=r[u];if(p.__viewTemplate||p.__compiledView||p.viewRenderer||p.externalView||p.format||p.type==="date"||p.type==="boolean"){h=!0;break}}o.__hasSpecialColumns=h}const f=String(n);if(!h){for(let u=0;u<a;u++){const p=i[u],g=t[r[u].field];p.textContent=g==null?"":String(g),p.getAttribute("data-row")!==f&&p.setAttribute("data-row",f);const w=c===n&&d===u,b=p.classList.contains("cell-focus");w!==b&&(p.classList.toggle("cell-focus",w),p.setAttribute("aria-selected",String(w)))}return}for(let u=0;u<a;u++)if(r[u].externalView&&!i[u].querySelector("[data-external-view]")){V(o,e,t,n);return}for(let u=0;u<a;u++){const p=r[u],g=i[u];g.getAttribute("data-row")!==f&&g.setAttribute("data-row",f);const w=c===n&&d===u,b=g.classList.contains("cell-focus");if(w!==b&&(g.classList.toggle("cell-focus",w),g.setAttribute("aria-selected",String(w))),g.classList.contains("editing"))continue;if(p.viewRenderer){const k=t[p.field],m=p.viewRenderer({row:t,value:k,field:p.field,column:p});typeof m=="string"?g.innerHTML=ne(m):m?(g.innerHTML="",g.appendChild(m)):g.textContent=k==null?"":String(k);continue}if(p.__viewTemplate||p.__compiledView||p.externalView)continue;const _=t[p.field];let T;if(p.format)try{const k=p.format(_,t);T=k==null?"":String(k)}catch{T=_==null?"":String(_)}else if(p.type==="date"){if(_==null||_==="")T="";else if(_ instanceof Date)T=isNaN(_.getTime())?"":_.toLocaleDateString();else{const k=new Date(_);T=isNaN(k.getTime())?"":k.toLocaleDateString()}g.textContent=T}else if(p.type==="boolean"){const k=!!_;g.innerHTML=`<span role="checkbox" aria-checked="${k}" aria-label="${k}">${k?"🗹":"☐"}</span>`}else T=_==null?"":String(_),g.textContent=T}}function V(o,e,t,n){e.innerHTML="";const i=o._visibleColumns,r=i.length,s=o._focusRow,l=o._focusCol,a=o.effectiveConfig?.editOn||o.editOn,c=o,d=document.createDocumentFragment();for(let h=0;h<r;h++){const f=i[h],u=document.createElement("div");u.className="cell",se(u,"cell"),u.setAttribute("role","gridcell"),u.setAttribute("aria-colindex",String(h+1)),u.setAttribute("data-col",String(h)),u.setAttribute("data-row",String(n)),f.type,f.type&&u.setAttribute("data-type",f.type);let p=t[f.field];const g=f.format;if(g)try{p=g(p,t)}catch{}const w=f.__compiledView,b=f.__viewTemplate,_=f.viewRenderer,T=f.externalView;let k=!1;if(_){const m=_({row:t,value:p,field:f.field,column:f});typeof m=="string"?(u.innerHTML=ne(m),k=!0):m?u.appendChild(m):u.textContent=p==null?"":String(p)}else if(T){const m=T,v=document.createElement("div");v.setAttribute("data-external-view",""),v.setAttribute("data-field",f.field),u.appendChild(v);const S={row:t,value:p,field:f.field,column:f};if(m.mount)try{m.mount({placeholder:v,context:S,spec:m})}catch{}else queueMicrotask(()=>{try{c.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:v,spec:m,context:S}}))}catch{}});v.setAttribute("data-mounted","")}else if(w){const m=w({row:t,value:p,field:f.field,column:f}),v=w.__blocked;u.innerHTML=v?"":ne(m),k=!0,v&&(u.textContent="",u.setAttribute("data-blocked-template",""))}else if(b){const m=b.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(m)?(u.textContent="",u.setAttribute("data-blocked-template","")):(u.innerHTML=ne(Oe(m,{row:t,value:p})),k=!0)}else if(f.type==="date")if(p==null||p==="")u.textContent="";else{let m=null;if(p instanceof Date)m=p;else if(typeof p=="number"||typeof p=="string"){const v=new Date(p);isNaN(v.getTime())||(m=v)}u.textContent=m?m.toLocaleDateString():""}else if(f.type==="boolean"){const m=!!p;u.innerHTML=`<span role="checkbox" aria-checked="${m}" aria-label="${m}">${m?"🗹":"☐"}</span>`}else u.textContent=p==null?"":String(p);if(k){Bt(u);const m=u.textContent||"";/Proxy|Reflect\.ownKeys/.test(m)&&(u.textContent=m.replace(/Proxy|Reflect\.ownKeys/g,"").trim(),/Proxy|Reflect\.ownKeys/.test(u.textContent||"")&&(u.textContent=""))}u.hasAttribute("data-blocked-template")&&(u.textContent||"").trim().length&&(u.textContent=""),f.editable?(u.tabIndex=0,u.addEventListener("mousedown",()=>{if(u.classList.contains("editing"))return;const m=Number(u.getAttribute("data-row")),v=Number(u.getAttribute("data-col"));isNaN(m)||isNaN(v)||(o._focusRow=m,o._focusCol=v,z(o))}),a==="click"?u.addEventListener("click",m=>{if(u.classList.contains("editing"))return;m.stopPropagation();const v=Number(u.getAttribute("data-row")),S=Number(u.getAttribute("data-col"));if(isNaN(v)||isNaN(S))return;const E=o._rows[v],C=o._visibleColumns[S];!E||!C||(o._focusRow=v,o._focusCol=S,D(o,E,v,C,u))}):u.addEventListener("dblclick",m=>{m.stopPropagation();const v=Number(u.getAttribute("data-row"));if(isNaN(v))return;const S=o._rows[v];if(!S)return;W(o,v,S);const E=o.findRenderedRowElement?.(v);if(E){const C=E.children;for(let x=0;x<C.length;x++){const R=o._visibleColumns[x];R&&R.editable&&D(o,S,v,R,C[x])}}}),u.addEventListener("keydown",m=>{const v=Number(u.getAttribute("data-row")),S=Number(u.getAttribute("data-col"));if(isNaN(v)||isNaN(S))return;const E=o._rows[v],C=o._visibleColumns[S];if(!(!E||!C)){if((C.type==="select"||C.type==="typeahead")&&!u.classList.contains("editing")&&m.key==="Enter"){m.preventDefault(),o._activeEditRows!==v&&W(o,v,E),D(o,E,v,C,u),setTimeout(()=>{const x=u.querySelector("select");try{x?.showPicker?.()}catch{}x?.focus()},0);return}if(C.type==="boolean"&&m.key===" "&&!u.classList.contains("editing")){m.preventDefault(),o._activeEditRows!==v&&W(o,v,E);const x=!E[C.field];de(o,v,C,x,E),u.innerHTML=`<span role="checkbox" aria-checked="${x}" aria-label="${x}">${x?"🗹":"☐"}</span>`;return}if(m.key==="Enter"&&!u.classList.contains("editing")){m.preventDefault(),m.stopPropagation(),o._focusRow=v,o._focusCol=S,typeof o.beginBulkEdit=="function"?o.beginBulkEdit(v):D(o,E,v,C,u);return}if(m.key==="F2"&&!u.classList.contains("editing")){m.preventDefault(),D(o,E,v,C,u);return}}})):f.type==="boolean"&&(u.hasAttribute("tabindex")||(u.tabIndex=0)),s===n&&l===h?(u.classList.add("cell-focus"),u.setAttribute("aria-selected","true")):u.setAttribute("aria-selected","false"),d.appendChild(u)}e.appendChild(d)}function Fe(o,e,t,n){if(e.target?.closest(".resize-handle"))return;const i=t.querySelector(".cell[data-row]");if(!i)return;const r=Number(i.getAttribute("data-row"));if(isNaN(r))return;const s=o._rows[r];if(!s)return;const l=e.target?.closest(".cell[data-col]");if(l){if(l.classList.contains("editing"))return;const c=Number(l.getAttribute("data-col"));if(!isNaN(c)){if(o._dispatchCellClick?.(e,r,c,l))return;o._focusRow=r,o._focusCol=c,z(o)}}if(t.querySelector(".cell.editing")){const c=t.querySelectorAll(".cell.editing");if(!n)return;c.forEach(d=>d.classList.remove("editing"))}const a=o.effectiveConfig?.editOn||o.editOn||"doubleClick";if(a==="click"||a==="doubleClick"&&n)W(o,r,s);else return;Array.from(t.children).forEach((c,d)=>{const h=o._visibleColumns[d];h&&h.editable&&D(o,s,r,h,c)}),l&&queueMicrotask(()=>{const c=t.querySelector(`.cell[data-col="${o._focusCol}"]`);if(c?.classList.contains("editing")){const d=c.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');try{d?.focus()}catch{}}})}function ce(o){return!(o==="__proto__"||o==="constructor"||o==="prototype")}function W(o,e,t){o._activeEditRows!==e&&(o._rowEditSnapshots.set(e,{...t}),o._activeEditRows=e)}function $(o,e,t){if(o._activeEditRows!==e)return;const n=o._rowEditSnapshots.get(e),i=o._rows[e],r=o.findRenderedRowElement?.(e);if(!t&&r&&i&&r.querySelectorAll(".cell.editing").forEach(l=>{const a=Number(l.getAttribute("data-col"));if(isNaN(a))return;const c=o._visibleColumns[a];if(!c)return;const d=l.querySelector("input,textarea,select");if(d){let h;d instanceof HTMLInputElement&&d.type==="checkbox"?h=d.checked:(h=d.value,c.type==="number"&&h!==""&&(h=Number(h))),i[c.field]!==h&&de(o,e,c,h,i)}}),t&&n&&i)Object.keys(n).forEach(s=>i[s]=n[s]),o._changedRowIndices.delete(e),le(o);else if(!t){const s=o._changedRowIndices.has(e);o.dispatchEvent(new CustomEvent("row-commit",{detail:{rowIndex:e,row:i,changed:s,changedRows:o.changedRows,changedRowIndices:o.changedRowIndices}}))}o._rowEditSnapshots.delete(e),o._activeEditRows=-1,r&&(V(o,r,o._rows[e],e),o._changedRowIndices.has(e)?r.classList.add("changed"):r.classList.remove("changed")),queueMicrotask(()=>{try{const s=o._focusRow,l=o._focusCol,a=o.findRenderedRowElement?.(s);if(a){Array.from(o._bodyEl.querySelectorAll(".cell-focus")).forEach(d=>d.classList.remove("cell-focus"));const c=a.querySelector(`.cell[data-row="${s}"][data-col="${l}"]`);c&&(c.classList.add("cell-focus"),c.setAttribute("aria-selected","true"),c.hasAttribute("tabindex")||c.setAttribute("tabindex","-1"),c.focus({preventScroll:!0}))}}catch{}})}function de(o,e,t,n,i){const r=t.field;if(!ce(r)||i[r]===n)return;i[r]=n;const l=!o._changedRowIndices.has(e);o._changedRowIndices.add(e);const a=o.findRenderedRowElement?.(e);a&&a.classList.add("changed"),o.dispatchEvent(new CustomEvent("cell-commit",{detail:{row:i,field:r,value:n,rowIndex:e,changedRows:o.changedRows,changedRowIndices:o.changedRowIndices,firstTimeForRow:l}}))}function D(o,e,t,n,i){if(!n.editable||(o._activeEditRows!==t&&W(o,t,e),i.classList.contains("editing")))return;const r=ce(n.field)?e[n.field]:void 0;i.classList.add("editing");let s=!1;const l=u=>{s||o._activeEditRows===-1||de(o,t,n,u,e)},a=()=>{s=!0,e[n.field]=ce(n.field)?r:void 0;const u=i.querySelector("input,textarea,select");u&&(typeof HTMLInputElement<"u"&&u instanceof HTMLInputElement&&u.type==="checkbox"?u.checked=!!r:"value"in u&&(u.value=r??""))},c=document.createElement("div");c.style.display="contents",i.innerHTML="",i.appendChild(c),c.addEventListener("keydown",u=>{u.key==="Enter"&&(u.stopPropagation(),u.preventDefault(),s=!0,$(o,t,!1)),u.key==="Escape"&&(u.stopPropagation(),u.preventDefault(),a(),$(o,t,!0))});const d=n.__editorTemplate,h=n.editor||(d?"template":Vt(n)),f=r;if(h==="template"&&d){const u=d.cloneNode(!0),p=n.__compiledEditor;p?u.innerHTML=p({row:e,value:r,field:n.field,column:n}):u.querySelectorAll("*").forEach(w=>{w.childNodes.length===1&&w.firstChild?.nodeType===Node.TEXT_NODE&&(w.textContent=w.textContent?.replace(/{{\s*value\s*}}/g,r==null?"":String(r)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(b,_)=>{const T=e[_];return T==null?"":String(T)})||"")});const g=u.querySelector("input,textarea,select");if(g){const w=typeof HTMLInputElement<"u";w&&g instanceof HTMLInputElement&&g.type==="checkbox"?g.checked=!!r:"value"in g&&(g.value=r??""),g.addEventListener("blur",()=>{const b=w&&g instanceof HTMLInputElement&&g.type==="checkbox"?g.checked:g.value;l(b)}),g.addEventListener("keydown",b=>{if(b.key==="Enter"){b.stopPropagation(),b.preventDefault(),s=!0;const _=w&&g instanceof HTMLInputElement&&g.type==="checkbox"?g.checked:g.value;l(_),$(o,t,!1)}b.key==="Escape"&&(b.stopPropagation(),b.preventDefault(),a(),$(o,t,!0))}),w&&g instanceof HTMLInputElement&&g.type==="checkbox"&&g.addEventListener("change",()=>{const b=g.checked;l(b)}),setTimeout(()=>g.focus(),0)}c.appendChild(u)}else if(typeof h=="string"){const u=document.createElement(h);u.value=f,u.addEventListener("change",()=>l(u.value)),c.appendChild(u)}else if(typeof h=="function"){const u=h({row:e,value:f,field:n.field,column:n,commit:l,cancel:a});typeof u=="string"?c.innerHTML=u:c.appendChild(u)}else if(h&&typeof h=="object"){const u=document.createElement("div");u.setAttribute("data-external-editor",""),u.setAttribute("data-field",n.field),c.appendChild(u);const p={row:e,value:f,field:n.field,column:n,commit:l,cancel:a};if(h.mount)try{h.mount({placeholder:u,context:p,spec:h})}catch{}else o.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:u,spec:h,context:p}}))}}function Be(o,e){!o._sortState||o._sortState.field!==e.field?(o._sortState||(o.__originalOrder=o._rows.slice()),$e(o,e,1)):o._sortState.direction===1?$e(o,e,-1):(o._sortState=null,o.__rowRenderEpoch++,o._rowPool.forEach(n=>n.__epoch=-1),o._rows=o.__originalOrder.slice(),j(o),o._headerRowEl?.querySelectorAll('[role="columnheader"].sortable')?.forEach(n=>{n.getAttribute("aria-sort")?(n.getAttribute("aria-sort")==="ascending"||n.getAttribute("aria-sort")==="descending")&&(o._sortState||n.setAttribute("aria-sort","none")):n.setAttribute("aria-sort","none")}),o.refreshVirtualWindow(!0),o.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:0}})),o.requestStateChange?.())}function $e(o,e,t){o._sortState={field:e.field,direction:t};const n=e.sortComparator||((i,r)=>i==null&&r==null?0:i==null?-1:r==null||i>r?1:i<r?-1:0);o._rows.sort((i,r)=>n(i[e.field],r[e.field],i,r)*t),o.__rowRenderEpoch++,o._rowPool.forEach(i=>i.__epoch=-1),j(o),o.refreshVirtualWindow(!0),o.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:t}})),o.requestStateChange?.()}function Yt(o,e){typeof e=="string"?o.textContent=e:e instanceof HTMLElement&&(o.innerHTML="",o.appendChild(e.cloneNode(!0)))}function j(o){o._headerRowEl=o.findHeaderRow();const e=o._headerRowEl;e.innerHTML="",o._visibleColumns.forEach((t,n)=>{const i=document.createElement("div");i.className="cell",se(i,"header-cell"),i.setAttribute("role","columnheader"),i.setAttribute("aria-colindex",String(n+1)),i.setAttribute("data-field",t.field),i.setAttribute("data-col",String(n));const r=t.__headerTemplate;if(r)Array.from(r.childNodes).forEach(s=>i.appendChild(s.cloneNode(!0)));else{const s=t.header||t.field,l=document.createElement("span");l.textContent=s,i.appendChild(l)}if(t.sortable){i.classList.add("sortable"),i.tabIndex=0;const s=document.createElement("span");se(s,"sort-indicator"),s.style.opacity="0.6";const l=o._sortState?.field===t.field?o._sortState.direction:0,a={...I,...o.icons},c=l===1?a.sortAsc:l===-1?a.sortDesc:a.sortNone;Yt(s,c),i.appendChild(s),i.setAttribute("aria-sort",l===0?"none":l===1?"ascending":"descending"),i.addEventListener("click",d=>{o._resizeController?.isResizing||o._dispatchHeaderClick?.(d,n,i)||Be(o,t)}),i.addEventListener("keydown",d=>{if(d.key==="Enter"||d.key===" "){if(d.preventDefault(),o._dispatchHeaderClick?.(d,n,i))return;Be(o,t)}})}if(t.resizable){i.style.position="relative";const s=document.createElement("div");s.className="resize-handle",s.setAttribute("aria-hidden","true"),s.addEventListener("mousedown",l=>{l.stopPropagation(),l.preventDefault(),o._resizeController.start(l,n,i)}),s.addEventListener("dblclick",l=>{l.stopPropagation(),l.preventDefault(),o._resizeController.resetColumn(n)}),i.appendChild(s)}e.appendChild(i)}),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"))}function Zt(o){let e=null,t=null,n=null,i=null;const r=a=>{if(!e)return;const c=a.clientX-e.startX,d=Math.max(40,e.startWidth+c),h=o._visibleColumns[e.colIndex];h.width=d,h.__userResized=!0,h.__renderedWidth=d,t==null&&(t=requestAnimationFrame(()=>{t=null,o.updateTemplate?.()})),o.dispatchEvent(new CustomEvent("column-resize",{detail:{field:h.field,width:d}}))};let s=!1;const l=()=>{const a=e!==null;a&&(s=!0,requestAnimationFrame(()=>{s=!1})),window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",l),n!==null&&(document.documentElement.style.cursor=n,n=null),i!==null&&(document.body.style.userSelect=i,i=null),e=null,a&&o.requestStateChange&&o.requestStateChange()};return{get isResizing(){return e!==null||s},start(a,c,d){a.preventDefault();const h=d.getBoundingClientRect();e={startX:a.clientX,colIndex:c,startWidth:h.width},window.addEventListener("mousemove",r),window.addEventListener("mouseup",l),n===null&&(n=document.documentElement.style.cursor),document.documentElement.style.cursor="e-resize",i===null&&(i=document.body.style.userSelect),document.body.style.userSelect="none"},resetColumn(a){const c=o._visibleColumns[a];c&&(c.__userResized=!1,c.__renderedWidth=void 0,c.width=c.__originalWidth,o.updateTemplate?.(),o.requestStateChange?.(),o.dispatchEvent(new CustomEvent("column-resize-reset",{detail:{field:c.field,width:c.width}})))},dispose(){l()}}}function Q(o){return o?typeof o=="string"?o:o.outerHTML:""}function Jt(){return{toolPanels:new Map,headerContents:new Map,toolbarButtons:new Map,lightDomButtons:[],lightDomHeaderContent:[],isPanelOpen:!1,expandedSections:new Set,headerContentCleanups:new Map,panelCleanups:new Map,toolbarButtonCleanups:new Map,activePanel:null,activePanelCleanup:null}}function Qt(o,e){return!!(o?.header?.title||o?.header?.toolbarButtons?.length||e.toolPanels.size>0||e.headerContents.size>0||e.toolbarButtons.size>0||e.lightDomButtons.length>0||e.lightDomHeaderContent.length>0)}function eo(o,e,t="☰"){const n=o?.header?.title??"",i=!!n,r=Q(t),s=o?.header?.toolbarButtons??[],l=s.length>0,a=e.toolbarButtons.size>0,c=e.lightDomButtons.length>0,d=e.toolPanels.size>0,f=(l||a||c)&&d,u=[...s].sort((w,b)=>(w.order??100)-(b.order??100)),p=[...e.toolbarButtons.values()].sort((w,b)=>(w.order??100)-(b.order??100));let g="";for(const w of u)w.icon&&w.action&&(g+=`<button class="tbw-toolbar-btn" data-btn="${w.id}" title="${w.label}" aria-label="${w.label}"${w.disabled?" disabled":""}>${w.icon}</button>`);for(const w of p)w.icon&&w.action&&(g+=`<button class="tbw-toolbar-btn" data-btn="${w.id}" title="${w.label}" aria-label="${w.label}"${w.disabled?" disabled":""}>${w.icon}</button>`);for(const w of u)(w.element||w.render)&&(g+=`<div class="tbw-toolbar-btn-slot" data-btn-slot="${w.id}"></div>`);for(const w of p)(w.element||w.render)&&(g+=`<div class="tbw-toolbar-btn-slot" data-btn-slot="${w.id}"></div>`);if(c&&(g+='<slot name="toolbar"></slot>'),f&&(g+='<div class="tbw-toolbar-separator"></div>'),d){const w=e.isPanelOpen;g+=`<button class="tbw-toolbar-btn${w?" active":""}" data-panel-toggle title="Settings" aria-label="Toggle settings panel" aria-pressed="${w}" aria-controls="tbw-tool-panel">${r}</button>`}return`
|
|
2
2
|
<div class="tbw-shell-header" part="shell-header" role="presentation">
|
|
3
3
|
${i?`<div class="tbw-shell-title">${n}</div>`:""}
|
|
4
4
|
<div class="tbw-shell-content" part="shell-content" role="presentation">
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
${u}
|
|
42
42
|
</div>
|
|
43
43
|
`}function Ge(o,e){const t=o.querySelector("tbw-grid-header");if(!t)return;t.style.display="none";const n=t.querySelectorAll("tbw-grid-header-content");e.lightDomHeaderContent=Array.from(n),e.lightDomHeaderContent.forEach(r=>{r.setAttribute("slot","header-content")});const i=t.querySelectorAll("tbw-grid-tool-button");e.lightDomButtons=Array.from(i),e.lightDomButtons.sort((r,s)=>{const l=parseInt(r.getAttribute("order")??"100",10),a=parseInt(s.getAttribute("order")??"100",10);return l-a}),e.lightDomButtons.forEach(r=>{r.setAttribute("slot","toolbar")})}function oo(o,e,t,n){const i=o.querySelector(".tbw-shell-toolbar");i&&i.addEventListener("click",s=>{const l=s.target;if(l.closest("[data-panel-toggle]")){n.onPanelToggle();return}const c=l.closest("[data-btn]");if(c){const d=c.getAttribute("data-btn");d&&n.onToolbarButtonClick(d)}});const r=o.querySelector(".tbw-accordion");r&&r.addEventListener("click",s=>{const a=s.target.closest(".tbw-accordion-header");if(a){const d=a.closest("[data-section]")?.getAttribute("data-section");d&&n.onSectionToggle(d)}})}function no(o,e,t){const n=o.querySelector(".tbw-tool-panel"),i=o.querySelector("[data-resize-handle]"),r=o.querySelector(".tbw-shell-body");if(!n||!i||!r)return()=>{};const s=e?.toolPanel?.position??"right",l=200;let a=0,c=0,d=0,h=!1;const f=g=>{if(!h)return;g.preventDefault();const w=s==="left"?g.clientX-a:a-g.clientX,b=Math.min(d,Math.max(l,c+w));n.style.width=`${b}px`},u=()=>{if(!h)return;h=!1,i.classList.remove("resizing"),n.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const g=n.getBoundingClientRect().width;t(g),document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",u)},p=g=>{g.preventDefault(),h=!0,a=g.clientX,c=n.getBoundingClientRect().width,d=r.getBoundingClientRect().width-20,i.classList.add("resizing"),n.style.transition="none",document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",f),document.addEventListener("mouseup",u)};return i.addEventListener("mousedown",p),()=>{i.removeEventListener("mousedown",p),document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",u)}}function io(o,e,t){const n=[...e?.header?.toolbarButtons??[],...t.toolbarButtons.values()];for(const i of n){const r=o.querySelector(`[data-btn-slot="${i.id}"]`);if(!r)continue;const s=t.toolbarButtonCleanups.get(i.id);if(s&&(s(),t.toolbarButtonCleanups.delete(i.id)),i.element)r.appendChild(i.element);else if(i.render){const l=i.render(r);l&&t.toolbarButtonCleanups.set(i.id,l)}}}function Ke(o,e){const t=o.querySelector(".tbw-shell-content");if(!t)return;const n=[...e.headerContents.values()].sort((r,s)=>(r.order??100)-(s.order??100)),i=t.querySelector('slot[name="header-content"]');for(const r of n){const s=e.headerContentCleanups.get(r.id);s&&(s(),e.headerContentCleanups.delete(r.id));let l=t.querySelector(`[data-header-content="${r.id}"]`);l||(l=document.createElement("div"),l.setAttribute("data-header-content",r.id),i?t.insertBefore(l,i):t.appendChild(l));const a=r.render(l);a&&e.headerContentCleanups.set(r.id,a)}}function ro(o,e,t){if(!e.isPanelOpen)return;const n=Q(t?.expand??I.expand),i=Q(t?.collapse??I.collapse);for(const[r,s]of e.toolPanels){const l=e.expandedSections.has(r),a=o.querySelector(`[data-section="${r}"]`),c=a?.querySelector(".tbw-accordion-content");if(!a||!c)continue;a.classList.toggle("expanded",l);const d=a.querySelector(".tbw-accordion-header");d&&d.setAttribute("aria-expanded",String(l));const h=a.querySelector(".tbw-accordion-chevron");if(h&&(h.innerHTML=l?i:n),l){if(c.children.length===0){const f=s.render(c);f&&e.panelCleanups.set(r,f)}}else{const f=e.panelCleanups.get(r);f&&(f(),e.panelCleanups.delete(r)),c.innerHTML=""}}}function Ve(o,e){const t=o.querySelector("[data-panel-toggle]");t&&(t.classList.toggle("active",e.isPanelOpen),t.setAttribute("aria-pressed",String(e.isPanelOpen)))}function We(o,e){const t=o.querySelector(".tbw-tool-panel");t&&(t.classList.toggle("open",e.isPanelOpen),e.isPanelOpen||(t.style.width=""))}function so(o,e){const t=[];for(const n of o?.header?.toolbarButtons??[])t.push({id:n.id,label:n.label,disabled:n.disabled??!1,source:"config"});for(const n of e.toolbarButtons.values())t.push({id:n.id,label:n.label,disabled:n.disabled??!1,source:"config"});for(let n=0;n<e.lightDomButtons.length;n++){const r=e.lightDomButtons[n].querySelector("button");t.push({id:`light-dom-${n}`,label:r?.getAttribute("title")??r?.getAttribute("aria-label")??"",disabled:r?.disabled??!1,source:"light-dom"})}for(const n of e.toolPanels.values())t.push({id:`panel-toggle-${n.id}`,label:n.tooltip??n.title,disabled:!1,source:"panel-toggle",panelId:n.id});return t}function lo(o){for(const e of o.headerContentCleanups.values())e();o.headerContentCleanups.clear(),o.activePanelCleanup&&(o.activePanelCleanup(),o.activePanelCleanup=null);for(const e of o.toolbarButtonCleanups.values())e();o.toolbarButtonCleanups.clear(),o.activePanel&&o.toolPanels.get(o.activePanel)?.onClose?.(),o.toolPanels.clear(),o.headerContents.clear(),o.toolbarButtons.clear(),o.lightDomButtons=[],o.lightDomHeaderContent=[],o.activePanel=null}function ao(o,e){let t=!1;const n={get isInitialized(){return t},setInitialized(i){t=i},get isPanelOpen(){return o.isPanelOpen},get activePanel(){return o.isPanelOpen&&o.expandedSections.size>0?[...o.expandedSections][0]:null},get expandedSections(){return[...o.expandedSections]},openToolPanel(){if(o.isPanelOpen)return;if(o.toolPanels.size===0){console.warn("[tbw-grid] No tool panels registered");return}if(o.isPanelOpen=!0,o.expandedSections.size===0&&o.toolPanels.size>0){const s=[...o.toolPanels.values()].sort((l,a)=>(l.order??100)-(a.order??100))[0];s&&o.expandedSections.add(s.id)}const i=e.getShadow();Ve(i,o),We(i,o),ro(i,o,e.getAccordionIcons()),e.emit("tool-panel-open",{sections:n.expandedSections})},closeToolPanel(){if(!o.isPanelOpen)return;for(const r of o.panelCleanups.values())r();o.panelCleanups.clear(),o.activePanelCleanup&&(o.activePanelCleanup(),o.activePanelCleanup=null);for(const r of o.toolPanels.values())r.onClose?.();o.isPanelOpen=!1;const i=e.getShadow();Ve(i,o),We(i,o),e.emit("tool-panel-close",{})},toggleToolPanel(){o.isPanelOpen?n.closeToolPanel():n.openToolPanel()},toggleToolPanelSection(i){const r=o.toolPanels.get(i);if(!r){console.warn(`[tbw-grid] Tool panel section "${i}" not found`);return}if(o.toolPanels.size===1)return;const s=e.getShadow(),l=o.expandedSections.has(i);if(l){const a=o.panelCleanups.get(i);a&&(a(),o.panelCleanups.delete(i)),r.onClose?.(),o.expandedSections.delete(i),ue(s,i,!1)}else{for(const[a,c]of o.toolPanels)if(a!==i&&o.expandedSections.has(a)){const d=o.panelCleanups.get(a);d&&(d(),o.panelCleanups.delete(a)),c.onClose?.(),o.expandedSections.delete(a),ue(s,a,!1);const h=s.querySelector(`[data-section="${a}"] .tbw-accordion-content`);h&&(h.innerHTML="")}o.expandedSections.add(i),ue(s,i,!0),co(s,o,i)}e.emit("tool-panel-section-toggle",{id:i,expanded:!l})},getToolPanels(){return[...o.toolPanels.values()]},registerToolPanel(i){if(o.toolPanels.has(i.id)){console.warn(`[tbw-grid] Tool panel "${i.id}" already registered`);return}o.toolPanels.set(i.id,i),t&&e.refreshShellHeader()},unregisterToolPanel(i){if(o.expandedSections.has(i)){const r=o.panelCleanups.get(i);r&&(r(),o.panelCleanups.delete(i)),o.expandedSections.delete(i)}o.toolPanels.delete(i),t&&e.refreshShellHeader()},getHeaderContents(){return[...o.headerContents.values()]},registerHeaderContent(i){if(o.headerContents.has(i.id)){console.warn(`[tbw-grid] Header content "${i.id}" already registered`);return}o.headerContents.set(i.id,i),t&&Ke(e.getShadow(),o)},unregisterHeaderContent(i){const r=o.headerContentCleanups.get(i);r&&(r(),o.headerContentCleanups.delete(i)),o.headerContents.get(i)?.onDestroy?.(),o.headerContents.delete(i),e.getShadow().querySelector(`[data-header-content="${i}"]`)?.remove()},getToolbarButtons(){return so(e.getShellConfig(),o)},registerToolbarButton(i){if(o.toolbarButtons.has(i.id)){console.warn(`[tbw-grid] Toolbar button "${i.id}" already registered`);return}o.toolbarButtons.set(i.id,i),t&&e.refreshShellHeader()},unregisterToolbarButton(i){const r=o.toolbarButtonCleanups.get(i);r&&(r(),o.toolbarButtonCleanups.delete(i)),o.toolbarButtons.delete(i),t&&e.refreshShellHeader()},setToolbarButtonDisabled(i,r){const s=o.toolbarButtons.get(i);s&&(s.disabled=r);const l=e.getShadow().querySelector(`[data-btn="${i}"]`);l&&(l.disabled=r)}};return n}function ue(o,e,t){const n=o.querySelector(`[data-section="${e}"]`);n&&n.classList.toggle("expanded",t)}function co(o,e,t){const n=e.toolPanels.get(t);if(!n?.render)return;const i=o.querySelector(`[data-section="${t}"] .tbw-accordion-content`);if(!i)return;const r=n.render(i);r&&e.panelCleanups.set(t,r)}class je{constructor(e){this.grid=e}plugins=[];pluginMap=new Map;cellRenderers=new Map;headerRenderers=new Map;cellEditors=new Map;attachAll(e){for(const t of e)this.attach(t)}attach(e){if(this.pluginMap.set(e.constructor,e),this.plugins.push(e),e.cellRenderers)for(const[t,n]of Object.entries(e.cellRenderers))this.cellRenderers.set(t,n);if(e.headerRenderers)for(const[t,n]of Object.entries(e.headerRenderers))this.headerRenderers.set(t,n);if(e.cellEditors)for(const[t,n]of Object.entries(e.cellEditors))this.cellEditors.set(t,n);e.attach(this.grid)}detachAll(){for(let e=this.plugins.length-1;e>=0;e--)this.plugins[e].detach();this.plugins=[],this.pluginMap.clear(),this.cellRenderers.clear(),this.headerRenderers.clear(),this.cellEditors.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}getCellRenderer(e){return this.cellRenderers.get(e)}getHeaderRenderer(e){return this.headerRenderers.get(e)}getCellEditor(e){return this.cellEditors.get(e)}getAllStyles(){return this.plugins.filter(e=>e.styles).map(e=>e.styles).join(`
|
|
44
|
-
`)}processRows(e){let t=[...e];for(const n of this.plugins)n.processRows&&(t=n.processRows(t));return t}processColumns(e){let t=[...e];for(const n of this.plugins)n.processColumns&&(t=n.processColumns(t));return t}beforeRender(){for(const e of this.plugins)e.beforeRender?.()}afterRender(){for(const e of this.plugins)e.afterRender?.()}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}getExtraHeightBefore(e){let t=0;for(const n of this.plugins)typeof n.getExtraHeightBefore=="function"&&(t+=n.getExtraHeightBefore(e));return t}adjustVirtualStart(e,t,n){let i=e;for(const r of this.plugins)if(typeof r.adjustVirtualStart=="function"){const s=r.adjustVirtualStart(e,t,n);s<i&&(i=s)}return i}renderRow(e,t,n){for(const i of this.plugins)if(i.renderRow?.(e,t,n))return!0;return!1}queryPlugins(e){const t=[];for(const n of this.plugins){const i=n.onPluginQuery?.(e);i!==void 0&&t.push(i)}return t}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 n=0,i=0,r=!1;for(const s of this.plugins){const l=s.getHorizontalScrollOffsets?.(e,t);l&&(n+=l.left,i+=l.right,l.skipScroll&&(r=!0))}return{left:n,right:i,skipScroll:r}}getToolPanels(){const e=[];for(const t of this.plugins){const n=t.getToolPanel?.();n&&e.push({plugin:t,panel:n})}return e.sort((t,n)=>(t.panel.order??0)-(n.panel.order??0))}getHeaderContents(){const e=[];for(const t of this.plugins){const n=t.getHeaderContent?.();n&&e.push({plugin:t,content:n})}return e.sort((t,n)=>(t.content.order??0)-(n.content.order??0))}}class $ extends HTMLElement{static tagName="tbw-grid";static version=typeof __GRID_VERSION__<"u"?__GRID_VERSION__:"dev";static get observedAttributes(){return["rows","columns","grid-config","fit-mode","edit-on"]}#o;#r=!1;#g;#m;#s=[];#l;#w;#v;#C;#t={};#f=!1;#p=0;#y=null;#x=!1;#L;#E=!1;#R=null;#_=null;#S=null;#A=null;#c;#b;#e;#P;#u;#i=Jt();#n;#k;_rows=[];#M=[];get _columns(){return this.#t.columns??[]}set _columns(e){this.#t.columns=e}get _visibleColumns(){return this._columns.filter(e=>!e.hidden)}_headerRowEl;_bodyEl;_rowPool=[];_resizeController;_virtualization={enabled:!0,rowHeight:28,bypassThreshold:24,start:0,end:0,container:null,viewportEl:null,totalHeightEl:null};_focusRow=0;_focusCol=0;_sortState=null;_activeEditRows=-1;_rowEditSnapshots=new Map;_changedRowIndices=new Set;_gridTemplate="";__rowRenderEpoch=0;__didInitialAutoSize=!1;__lightDomColumnsCache;__originalColumnNodes;__originalOrder=[];get rows(){return this._rows}set rows(e){const t=this.#s;this.#s=e,t!==e&&this.#U()}get sourceRows(){return this.#s}get columns(){return[...this._columns]}set columns(e){const t=this.#l;this.#l=e,t!==e&&this.#X()}get gridConfig(){return this.#t}set gridConfig(e){const t=this.#w;this.#w=e,t!==e&&this.#Y()}get fitMode(){return this.#t.fitMode??"stretch"}set fitMode(e){const t=this.#v;this.#v=e,t!==e&&this.#W()}get editOn(){return this.#t.editOn}set editOn(e){const t=this.#C;this.#C=e,t!==e&&this.#j()}get effectiveConfig(){return this.#t}get disconnectSignal(){return this.#c||(this.#c=new AbortController),this.#c.signal}constructor(){super(),this.#o=this.attachShadow({mode:"open"}),this.#$(),this.#g=new Promise(e=>this.#m=e),this.#n=ao(this.#i,{getShadow:()=>this.#o,getShellConfig:()=>this.#t?.shell,getAccordionIcons:()=>({expand:this.#t?.icons?.expand??I.expand,collapse:this.#t?.icons?.collapse??I.collapse}),emit:(e,t)=>this.#a(e,t),refreshShellHeader:()=>this.refreshShellHeader()})}#$(){const e=new CSSStyleSheet;e.replaceSync(J),this.#o.adoptedStyleSheets=[e]}getPlugin(e){return this.#e?.getPlugin(e)}getPluginByName(e){return this.#e?.getPluginByName(e)}requestRender(){this.#T(),this.#I(),j(this),K(this),this.refreshVirtualWindow(!0)}requestAfterRender(){this.#e?.afterRender()}#O(){this.#e=new je(this);const e=this.#t?.plugins,t=Array.isArray(e)?e:[];this.#e.attachAll(t)}#D(){const e=this.#e?.getAllStyles()??"";if(e){const t=document.createElement("style");t.setAttribute("data-plugin","all"),t.textContent=e,this.#o.appendChild(t)}}#z(){this.#e&&this.#e.detachAll(),this.#O(),this.#D(),this.#x=this.#e?.getAll().some(e=>e.onScroll)??!1}#G(){this.#e?.detachAll()}#K(){if(!this.#e)return;const e=this.#e.getToolPanels();for(const{panel:n}of e)this.#i.toolPanels.has(n.id)||this.#i.toolPanels.set(n.id,n);const t=this.#e.getHeaderContents();for(const{content:n}of t)this.#i.headerContents.has(n.id)||this.#i.headerContents.set(n.id,n)}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.hasAttribute("version")||this.setAttribute("version",$.version),this._rows=Array.isArray(this.#s)?[...this.#s]:[],this.#c?.abort(),this.#c=new AbortController,this.#h(),this.#O(),this.#K(),this.#r||(this.#B(),this.#D(),this.#r=!0),this.#q()}disconnectedCallback(){this.#G(),lo(this.#i),this.#n.setInitialized(!1),this.#k?.(),this.#k=void 0,this.#c&&(this.#c.abort(),this.#c=void 0),this._resizeController&&this._resizeController.dispose(),this.#b&&(this.#b.disconnect(),this.#b=void 0),this.#f=!1}attributeChangedCallback(e,t,n){if(t===n||!n||n==="null"||n==="undefined")return;const r={rows:"rows",columns:"columns","grid-config":"gridConfig","fit-mode":"fitMode","edit-on":"editOn"}[e];if(r)if(e==="rows"||e==="columns"||e==="grid-config")try{this[r]=JSON.parse(n)}catch{console.warn(`[tbw-grid] Invalid JSON for '${e}' attribute:`,n)}else this[r]=n}#q(){const t=this.#o.querySelector(".tbw-grid-content")??this.#o.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.#n.isInitialized){Ke(this.#o,this.#i),io(this.#o,this.#t?.shell,this.#i);const l=this.#t?.shell?.toolPanel?.defaultOpen;l&&this.#i.toolPanels.has(l)&&(this.openToolPanel(),this.#i.expandedSections.add(l))}this.setAttribute("data-upgraded",""),this.#f=!0;const n=this.disconnectSignal;this.#d(),this.addEventListener("keydown",l=>Wt(this,l),{signal:n}),document.addEventListener("keydown",l=>{l.key==="Escape"&&this._activeEditRows!==-1&&B(this,this._activeEditRows,!0)},{capture:!0,signal:n}),document.addEventListener("mousedown",l=>{if(this._activeEditRows===-1)return;const a=this.findRenderedRowElement(this._activeEditRows);!a||(l.composedPath&&l.composedPath()||[]).includes(a)||B(this,this._activeEditRows,!1)},{signal:n});const i=t?.querySelector(".faux-vscroll"),r=t?.querySelector(".rows");if(this._virtualization.container=i??this,this.#x=this.#e?.getAll().some(l=>l.onScroll)??!1,i&&r){i.addEventListener("scroll",()=>{if(!this._virtualization.enabled&&!this.#x)return;const c=i.scrollTop,d=this._virtualization.rowHeight,h=Math.floor(c/d),f=h-h%2,u=-(c-f*d);r.style.transform=`translateY(${u}px)`,this.#y=c,this.#p||(this.#p=requestAnimationFrame(()=>{this.#p=0,this.#y!==null&&(this.#Z(this.#y),this.#y=null)}))},{passive:!0,signal:n});const l=this.#o.querySelector(".tbw-grid-content"),a=this.#o.querySelector(".tbw-scroll-area");l&&(l.addEventListener("wheel",c=>{c.preventDefault(),c.shiftKey||Math.abs(c.deltaX)>Math.abs(c.deltaY)?a&&(a.scrollLeft+=c.shiftKey?c.deltaY:c.deltaX):i.scrollTop+=c.deltaY},{passive:!1,signal:n}),l.addEventListener("touchstart",c=>{c.touches.length===1&&(this.#R=c.touches[0].clientY,this.#_=c.touches[0].clientX,this.#S=i.scrollTop,this.#A=a?.scrollLeft??0)},{passive:!0,signal:n}),l.addEventListener("touchmove",c=>{if(c.touches.length===1&&this.#R!==null&&this.#_!==null&&this.#S!==null&&this.#A!==null){const d=this.#R-c.touches[0].clientY,h=this.#_-c.touches[0].clientX;i.scrollTop=this.#S+d,a&&(a.scrollLeft=this.#A+h),c.preventDefault()}},{passive:!1,signal:n}),l.addEventListener("touchend",()=>{this.#R=null,this.#_=null,this.#S=null,this.#A=null},{passive:!0,signal:n}))}this._resizeController=Zt(this),this.#o.addEventListener("mousedown",l=>this.#J(l),{signal:n}),document.addEventListener("mousemove",l=>this.#Q(l),{signal:n}),document.addEventListener("mouseup",l=>this.#ee(l),{signal:n}),this._virtualization.enabled&&requestAnimationFrame(()=>this.refreshVirtualWindow(!0));const s=this.#t.rowHeight;s&&s>0?this._virtualization.rowHeight=s:requestAnimationFrame(()=>{const l=this._bodyEl?.querySelector(".data-grid-row");if(l){const a=l.getBoundingClientRect().height;a>0&&(this._virtualization.rowHeight=a,this.refreshVirtualWindow(!0))}}),this._virtualization.viewportEl&&(this.#b=new ResizeObserver(()=>{this.#p||(this.#p=requestAnimationFrame(()=>{this.#p=0,this.refreshVirtualWindow(!0),z(this)}))}),this.#b.observe(this._virtualization.viewportEl)),queueMicrotask(()=>this.#V()),requestAnimationFrame(()=>requestAnimationFrame(()=>this.#m?.()))}#a(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}_emitCellCommit(e){this.#a("cell-commit",e)}_emitRowCommit(e){this.#a("row-commit",e)}_emitSortChange(e){this.#a("sort-change",e)}_emitColumnResize(e){this.#a("column-resize",e)}_emitActivateCell(e){this.#a("activate-cell",e)}#V(){this._bodyEl?.querySelectorAll(".data-grid-row")?.forEach((t,n)=>{const i=n===this._focusRow;t.setAttribute("aria-selected",String(i)),t.querySelectorAll(".cell").forEach((r,s)=>{r.setAttribute("aria-selected",String(i&&s===this._focusCol))})})}#W(){if(!this.#f)return;this.#h(),this.#t.fitMode==="fixed"?(this.__didInitialAutoSize=!1,qe(this)):(this._columns.forEach(t=>{!t.__userResized&&t.__autoSized&&delete t.width}),K(this))}#j(){this.#f&&(this.#h(),this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.refreshVirtualWindow(!0))}#U(){this._rows=Array.isArray(this.#s)?[...this.#s]:[],this.#T(),!this.#l||Array.isArray(this.#l)&&this.#l.length===0?this.#d():this.refreshVirtualWindow(!0)}#X(){le(this),this.#f&&(this.#h(),this.#d())}#Y(){this.#f&&(this.#h(),this.#z(),this.#T(),this.#I(),j(this),K(this),this.refreshVirtualWindow(!0))}#I(){if(this.#e){const e=this.#M.length>0?this.#M:this._columns,t=e.filter(r=>!r.hidden),n=e.filter(r=>r.hidden),i=this.#e.processColumns([...t]);if(i!==t){const r=new Map(i.map((l,a)=>[l.field,{col:l,order:a}]));if(!t.some(l=>r.has(l.field))&&i.length>0)this._columns=[...i,...n];else{const l=e.map(a=>{if(a.hidden)return a;const c=r.get(a.field);return c?c.col:a});this._columns=l}}else this._columns=[...e]}}#T(){le(this);const e=Array.isArray(this.#s)?[...this.#s]:[],t=this.#e?.processRows(e)??e;this._rows=t}#h(){const e=this.#w?{...this.#w}:{};let t=Array.isArray(e.columns)?[...e.columns]:[];const n=(this.__lightDomColumnsCache||[]).map(i=>({...i}));if(n.length){const i={};t.forEach(r=>i[r.field]=r),n.forEach(r=>{const s=i[r.field];s?(r.header&&!s.header&&(s.header=r.header),r.type&&!s.type&&(s.type=r.type),s.sortable=s.sortable||r.sortable,r.resizable&&(s.resizable=!0),r.editable&&(s.editable=!0)):(t.push(r),i[r.field]=r)})}if(this.#l&&this.#l.length&&(t=[...this.#l]),(!t||t.length===0)&&this._rows.length&&(t=Ne(this._rows).columns),t.length){t.forEach(s=>{s.sortable===void 0&&(s.sortable=!0),s.resizable===void 0&&(s.resizable=!0)});const i=this.#t.columns;i?.some(s=>s.__compiledView||s.__compiledEditor)?e.columns=i:e.columns=t}else{const i=this.#t.columns;i?.some(r=>r.__compiledView||r.__compiledEditor)&&(e.columns=i)}this.#v&&(e.fitMode=this.#v),e.fitMode||(e.fitMode="stretch"),this.#C&&(e.editOn=this.#C),e.rowHeight&&e.rowHeight>0&&(this._virtualization.rowHeight=e.rowHeight),e.columnState&&!this.#u&&(this.#u=e.columnState),this.#t=e,e.fitMode==="fixed"&&this._columns.forEach(i=>{i.width==null&&(i.width=80)})}#H(e,t,n=this.__rowRenderEpoch){this.#L||(this.#L=(i,r,s)=>this.#e?.renderRow(i,r,s)??!1),Xt(this,e,t,n,this.#L)}#d(){if(!this.isConnected||!this._headerRowEl||!this._bodyEl)return;const e=this.#w?.columns||this.#l||[];if(e.length){const n=new Map(this._columns.filter(r=>r.hidden).map(r=>[r.field,!0])),i=e.map(r=>({...r,hidden:n.get(r.field)??r.hidden}));this._columns=i}if(Kt(this),this.#h(),this.#z(),this.#M=[...this._columns],this.#T(),this.#I(),this.#u){const n=this.#u;this.#u=void 0,this.#F(n)}j(this),K(this),this.refreshVirtualWindow(!0),this.#t.fitMode==="fixed"&&!this.__didInitialAutoSize&&requestAnimationFrame(()=>qe(this)),this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),queueMicrotask(()=>this.#e?.afterRender())}#F(e){const t=this.#t.columns??[],n=this.#e?.getAll()??[];Tt(this,e,t,n);for(const i of e.columns){const r=t.find(s=>s.field===i.field);r&&(r.hidden=!i.visible)}}#Z(e){if(this.refreshVirtualWindow(!1),this.#e?.onScrollRender(),this.#x){const t=this._virtualization.container,n={scrollTop:e,scrollLeft:t?.scrollLeft??0,scrollHeight:t?.scrollHeight??0,scrollWidth:t?.scrollWidth??0,clientHeight:t?.clientHeight??0,clientWidth:t?.clientWidth??0,originalEvent:new Event("scroll")};this.#e?.onScroll(n)}}findHeaderRow(){return this.#o.querySelector(".header-row")}findRenderedRowElement(e){return Array.from(this._bodyEl.querySelectorAll(".data-grid-row")).find(t=>{const n=t.querySelector(".cell[data-row]");return n&&Number(n.getAttribute("data-row"))===e})||null}_dispatchCellClick(e,t,n,i){const r=this._rows[t],s=this._columns[n];if(!r||!s)return!1;const l={row:r,rowIndex:t,colIndex:n,field:s.field,value:r[s.field],cellEl:i,originalEvent:e};return this.#e?.onCellClick(l)??!1}_dispatchHeaderClick(e,t,n){const i=this._columns[t];if(!i)return!1;const r={colIndex:t,field:i.field,column:i,headerEl:n,originalEvent:e};return this.#e?.onHeaderClick(r)??!1}_dispatchKeyDown(e){return this.#e?.onKeyDown(e)??!1}_getHorizontalScrollOffsets(e,t){return this.#e?.getHorizontalScrollOffsets(e,t)??{left:0,right:0}}queryPlugins(e){return this.#e?.queryPlugins(e)??[]}#N(e,t){let n=null;const i=e.composedPath?.();if(i&&i.length>0?n=i[0]:n=e.target,n&&!this.#o.contains(n)){const p=this.#o.elementFromPoint(e.clientX,e.clientY);p&&(n=p)}const r=n?.closest?.("[data-col]"),s=n?.closest?.(".data-grid-row"),l=n?.closest?.(".header-row");let a,c,d,h,f,u;return r&&(a=parseInt(r.getAttribute("data-row")??"-1",10),c=parseInt(r.getAttribute("data-col")??"-1",10),a>=0&&c>=0&&(d=this._rows[a],u=this._columns[c],h=u?.field,f=d&&h?d[h]:void 0)),{type:t,row:d,rowIndex:a!==void 0&&a>=0?a:void 0,colIndex:c!==void 0&&c>=0?c:void 0,field:h,value:f,column:u,originalEvent:e,cellElement:r??void 0,rowElement:s??void 0,isHeader:!!l,cell:a!==void 0&&c!==void 0&&a>=0&&c>=0?{row:a,col:c}:void 0}}#J(e){const t=this.#N(e,"mousedown");(this.#e?.onCellMouseDown(t)??!1)&&(this.#E=!0)}#Q(e){if(!this.#E)return;const t=this.#N(e,"mousemove");this.#e?.onCellMouseMove(t)}#ee(e){if(!this.#E)return;const t=this.#N(e,"mouseup");this.#e?.onCellMouseUp(t),this.#E=!1}get changedRows(){return Array.from(this._changedRowIndices).map(e=>this._rows[e])}get changedRowIndices(){return Array.from(this._changedRowIndices)}async resetChangedRows(e){this._changedRowIndices.clear(),e||this.#a("changed-rows-reset",{rows:this.changedRows,indices:this.changedRowIndices}),this._rowPool.forEach(t=>t.classList.remove("changed"))}async beginBulkEdit(e){if(!this._columns.some(r=>r.editable))return;const n=this._rows[e];W(this,e,n);const i=this.findRenderedRowElement?.(e);i&&(Array.from(i.children).forEach((r,s)=>{const l=this._visibleColumns[s];if(l?.editable){const a=r;a.classList.contains("editing")||O(this,n,e,l,a)}}),queueMicrotask(()=>{const r=i.querySelector(`.cell[data-col="${this._focusCol}"]`);if(r?.classList.contains("editing")){const s=r.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');try{s?.focus()}catch{}}}))}async commitActiveRowEdit(){this._activeEditRows!==-1&&B(this,this._activeEditRows,!1)}async ready(){return this.#g}async forceLayout(){this.#d(),await new Promise(e=>requestAnimationFrame(()=>requestAnimationFrame(e)))}async getConfig(){return Object.freeze({...this.#t||{}})}setColumnVisible(e,t){const n=this.#t.columns,i=n?.find(l=>l.field===e);if(!i||!t&&i.lockVisible||!t&&(n??[]).filter(a=>!a.hidden&&a.field!==e).length===0)return!1;const r=!!i.hidden,s=!t;return r!==s?(i.hidden=s,this.#a("column-visibility",{field:e,visible:t,visibleColumns:(n??[]).filter(l=>!l.hidden).map(l=>l.field)}),this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.#d(),this.requestStateChange(),!0):!1}toggleColumnVisibility(e){const i=!!this.#t.columns?.find(r=>r.field===e)?.hidden;return this.setColumnVisible(e,i)}isColumnVisible(e){const n=this.#t.columns?.find(i=>i.field===e);return n?!n.hidden:!1}showAllColumns(){const e=this.#t.columns;e?.some(n=>n.hidden)&&(e?.forEach(n=>{n.hidden=!1}),this.#a("column-visibility",{visibleColumns:(e??[]).map(n=>n.field)}),this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.#d(),this.requestStateChange())}getAllColumns(){return(this.#t.columns??[]).map(t=>({field:t.field,header:t.header||t.field,visible:!t.hidden,lockVisible:t.lockVisible}))}setColumnOrder(e){if(!e.length)return;const t=new Map(this._columns.map(i=>[i.field,i])),n=[];for(const i of e){const r=t.get(i);r&&(n.push(r),t.delete(i))}for(const i of t.values())n.push(i);this._columns=n,j(this),K(this),this.refreshVirtualWindow(!0)}getColumnOrder(){return this._columns.map(e=>e.field)}getColumnState(){const e=this.#e?.getAll()??[];return He(this,e)}set columnState(e){e&&(this.#u=e,this.#r&&this.#te(e))}get columnState(){return this.getColumnState()}#te(e){(this.#t.columns??[]).forEach(n=>{n.hidden=!1}),this.#F(e),this.#d()}requestStateChange(){this.#P||(this.#P=Lt(this,()=>this.#e?.getAll()??[],e=>this.#a("column-state-change",e))),this.#P()}resetColumnState(){this.#u=void 0,(this.#t.columns??[]).forEach(n=>{n.hidden=!1}),this._sortState=null,this.__originalOrder=[],this.#h(),this.#d();const t=this.#e?.getAll()??[];for(const n of t)if(n.applyColumnState)for(const i of this._columns)n.applyColumnState(i.field,{field:i.field,order:0,visible:!0});this.requestStateChange()}get isToolPanelOpen(){return this.#n.isPanelOpen}get activeToolPanel(){return this.#n.activePanel}get expandedToolPanelSections(){return this.#n.expandedSections}openToolPanel(){this.#n.openToolPanel()}closeToolPanel(){this.#n.closeToolPanel()}toggleToolPanel(){this.#n.toggleToolPanel()}toggleToolPanelSection(e){this.#n.toggleToolPanelSection(e)}getToolPanels(){return this.#n.getToolPanels()}registerToolPanel(e){this.#n.registerToolPanel(e)}unregisterToolPanel(e){this.#n.unregisterToolPanel(e)}getHeaderContents(){return this.#n.getHeaderContents()}registerHeaderContent(e){this.#n.registerHeaderContent(e)}unregisterHeaderContent(e){this.#n.unregisterHeaderContent(e)}getToolbarButtons(){return this.#n.getToolbarButtons()}registerToolbarButton(e){this.#n.registerToolbarButton(e)}unregisterToolbarButton(e){this.#n.unregisterToolbarButton(e)}setToolbarButtonDisabled(e,t){this.#n.setToolbarButtonDisabled(e,t)}refreshShellHeader(){Ge(this,this.#i),this.#B(),this.#q()}refreshVirtualWindow(e=!1){if(!this._bodyEl)return;const t=this._rows.length;if(!this._virtualization.enabled){this.#H(0,t),this.#e?.afterRender();return}if(this._rows.length<=this._virtualization.bypassThreshold){if(this._virtualization.start=0,this._virtualization.end=t,this._bodyEl.style.transform="translateY(0px)",this.#H(0,t,this.__rowRenderEpoch),this._virtualization.totalHeightEl){const S=this.#o.querySelector(".tbw-scroll-area"),E=S?S.offsetHeight-S.clientHeight:0;this._virtualization.totalHeightEl.style.height=`${t*this._virtualization.rowHeight+E}px`}const v=this.#o.querySelector(".rows-body");v?.setAttribute("aria-rowcount",String(t)),v?.setAttribute("aria-colcount",String(this._visibleColumns.length)),this.#e?.afterRender();return}const n=this._virtualization.container??this,r=(this._virtualization.viewportEl??n).clientHeight,s=this._virtualization.rowHeight,l=n.scrollTop;let a=Math.floor(l/s),c=0;const d=10;for(;c<d;){const v=this.#e?.getExtraHeightBefore?.(a)??0,S=Math.floor((l-v)/s);if(S>=a||S<0)break;a=S,c++}a=a-a%2,a<0&&(a=0);const h=this.#e?.adjustVirtualStart(a,l,s);h!==void 0&&h<a&&(a=h,a=a-a%2,a<0&&(a=0));const f=Math.ceil(r/s)+3;let u=a+f;u>t&&(u=t),this._virtualization.start=a,this._virtualization.end=u;const g=this.#o.querySelector(".tbw-footer")?.offsetHeight??0,w=this.#e?.getExtraHeight()??0,b=this.#o.querySelector(".tbw-scroll-area"),_=b?b.offsetHeight-b.clientHeight:0;this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${t*s+s+g+w+_}px`);const T=this.#e?.getExtraHeightBefore?.(a)??0,k=-(l-a*s-T);this._bodyEl.style.transform=`translateY(${k}px)`,this.#H(a,u,e?++this.__rowRenderEpoch:this.__rowRenderEpoch);const m=this.#o.querySelector(".rows-body");m?.setAttribute("aria-rowcount",String(t)),m?.setAttribute("aria-colcount",String(this._visibleColumns.length)),e&&this.#e?.afterRender()}#B(){Ge(this,this.#i);const e=this.#t?.shell,t=Qt(e,this.#i),n=`
|
|
44
|
+
`)}processRows(e){let t=[...e];for(const n of this.plugins)n.processRows&&(t=n.processRows(t));return t}processColumns(e){let t=[...e];for(const n of this.plugins)n.processColumns&&(t=n.processColumns(t));return t}beforeRender(){for(const e of this.plugins)e.beforeRender?.()}afterRender(){for(const e of this.plugins)e.afterRender?.()}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}getExtraHeightBefore(e){let t=0;for(const n of this.plugins)typeof n.getExtraHeightBefore=="function"&&(t+=n.getExtraHeightBefore(e));return t}adjustVirtualStart(e,t,n){let i=e;for(const r of this.plugins)if(typeof r.adjustVirtualStart=="function"){const s=r.adjustVirtualStart(e,t,n);s<i&&(i=s)}return i}renderRow(e,t,n){for(const i of this.plugins)if(i.renderRow?.(e,t,n))return!0;return!1}queryPlugins(e){const t=[];for(const n of this.plugins){const i=n.onPluginQuery?.(e);i!==void 0&&t.push(i)}return t}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 n=0,i=0,r=!1;for(const s of this.plugins){const l=s.getHorizontalScrollOffsets?.(e,t);l&&(n+=l.left,i+=l.right,l.skipScroll&&(r=!0))}return{left:n,right:i,skipScroll:r}}getToolPanels(){const e=[];for(const t of this.plugins){const n=t.getToolPanel?.();n&&e.push({plugin:t,panel:n})}return e.sort((t,n)=>(t.panel.order??0)-(n.panel.order??0))}getHeaderContents(){const e=[];for(const t of this.plugins){const n=t.getHeaderContent?.();n&&e.push({plugin:t,content:n})}return e.sort((t,n)=>(t.content.order??0)-(n.content.order??0))}}class G extends HTMLElement{static tagName="tbw-grid";static version=typeof __GRID_VERSION__<"u"?__GRID_VERSION__:"dev";static get observedAttributes(){return["rows","columns","grid-config","fit-mode","edit-on"]}#o;#r=!1;#g;#m;#s=[];#l;#w;#v;#C;#t={};#f=!1;#p=0;#y=null;#x=!1;#L;#E=!1;#R=null;#_=null;#S=null;#A=null;#c;#b;#e;#P;#u;#i=Jt();#n;#k;_rows=[];#M=[];get _columns(){return this.#t.columns??[]}set _columns(e){this.#t.columns=e}get _visibleColumns(){return this._columns.filter(e=>!e.hidden)}_headerRowEl;_bodyEl;_rowPool=[];_resizeController;_virtualization={enabled:!0,rowHeight:28,bypassThreshold:24,start:0,end:0,container:null,viewportEl:null,totalHeightEl:null};_focusRow=0;_focusCol=0;_sortState=null;_activeEditRows=-1;_rowEditSnapshots=new Map;_changedRowIndices=new Set;_gridTemplate="";__rowRenderEpoch=0;__didInitialAutoSize=!1;__lightDomColumnsCache;__originalColumnNodes;__originalOrder=[];get rows(){return this._rows}set rows(e){const t=this.#s;this.#s=e,t!==e&&this.#U()}get sourceRows(){return this.#s}get columns(){return[...this._columns]}set columns(e){const t=this.#l;this.#l=e,t!==e&&this.#X()}get gridConfig(){return this.#t}set gridConfig(e){const t=this.#w;this.#w=e,t!==e&&this.#Y()}get fitMode(){return this.#t.fitMode??"stretch"}set fitMode(e){const t=this.#v;this.#v=e,t!==e&&this.#W()}get editOn(){return this.#t.editOn}set editOn(e){const t=this.#C;this.#C=e,t!==e&&this.#j()}get effectiveConfig(){return this.#t}get disconnectSignal(){return this.#c||(this.#c=new AbortController),this.#c.signal}constructor(){super(),this.#o=this.attachShadow({mode:"open"}),this.#$(),this.#g=new Promise(e=>this.#m=e),this.#n=ao(this.#i,{getShadow:()=>this.#o,getShellConfig:()=>this.#t?.shell,getAccordionIcons:()=>({expand:this.#t?.icons?.expand??I.expand,collapse:this.#t?.icons?.collapse??I.collapse}),emit:(e,t)=>this.#a(e,t),refreshShellHeader:()=>this.refreshShellHeader()})}#$(){const e=new CSSStyleSheet;e.replaceSync(J),this.#o.adoptedStyleSheets=[e]}getPlugin(e){return this.#e?.getPlugin(e)}getPluginByName(e){return this.#e?.getPluginByName(e)}requestRender(){this.#T(),this.#I(),j(this),B(this),this.refreshVirtualWindow(!0)}updateTemplate(){B(this)}requestAfterRender(){this.#e?.afterRender()}#D(){this.#e=new je(this);const e=this.#t?.plugins,t=Array.isArray(e)?e:[];this.#e.attachAll(t)}#O(){const e=this.#e?.getAllStyles()??"";if(e){const t=document.createElement("style");t.setAttribute("data-plugin","all"),t.textContent=e,this.#o.appendChild(t)}}#z(){this.#e&&this.#e.detachAll(),this.#D(),this.#O(),this.#x=this.#e?.getAll().some(e=>e.onScroll)??!1}#G(){this.#e?.detachAll()}#K(){if(!this.#e)return;const e=this.#e.getToolPanels();for(const{panel:n}of e)this.#i.toolPanels.has(n.id)||this.#i.toolPanels.set(n.id,n);const t=this.#e.getHeaderContents();for(const{content:n}of t)this.#i.headerContents.has(n.id)||this.#i.headerContents.set(n.id,n)}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.hasAttribute("version")||this.setAttribute("version",G.version),this._rows=Array.isArray(this.#s)?[...this.#s]:[],this.#c?.abort(),this.#c=new AbortController,this.#h(),this.#D(),this.#K(),this.#r||(this.#B(),this.#O(),this.#r=!0),this.#q()}disconnectedCallback(){this.#G(),lo(this.#i),this.#n.setInitialized(!1),this.#k?.(),this.#k=void 0,this.#c&&(this.#c.abort(),this.#c=void 0),this._resizeController&&this._resizeController.dispose(),this.#b&&(this.#b.disconnect(),this.#b=void 0),this.#f=!1}attributeChangedCallback(e,t,n){if(t===n||!n||n==="null"||n==="undefined")return;const r={rows:"rows",columns:"columns","grid-config":"gridConfig","fit-mode":"fitMode","edit-on":"editOn"}[e];if(r)if(e==="rows"||e==="columns"||e==="grid-config")try{this[r]=JSON.parse(n)}catch{console.warn(`[tbw-grid] Invalid JSON for '${e}' attribute:`,n)}else this[r]=n}#q(){const t=this.#o.querySelector(".tbw-grid-content")??this.#o.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.#n.isInitialized){Ke(this.#o,this.#i),io(this.#o,this.#t?.shell,this.#i);const l=this.#t?.shell?.toolPanel?.defaultOpen;l&&this.#i.toolPanels.has(l)&&(this.openToolPanel(),this.#i.expandedSections.add(l))}this.setAttribute("data-upgraded",""),this.#f=!0;const n=this.disconnectSignal;this._resizeController=Zt(this),this.#d(),this.addEventListener("keydown",l=>Wt(this,l),{signal:n}),document.addEventListener("keydown",l=>{l.key==="Escape"&&this._activeEditRows!==-1&&$(this,this._activeEditRows,!0)},{capture:!0,signal:n}),document.addEventListener("mousedown",l=>{if(this._activeEditRows===-1)return;const a=this.findRenderedRowElement(this._activeEditRows);!a||(l.composedPath&&l.composedPath()||[]).includes(a)||$(this,this._activeEditRows,!1)},{signal:n});const i=t?.querySelector(".faux-vscroll"),r=t?.querySelector(".rows");if(this._virtualization.container=i??this,this.#x=this.#e?.getAll().some(l=>l.onScroll)??!1,i&&r){i.addEventListener("scroll",()=>{if(!this._virtualization.enabled&&!this.#x)return;const c=i.scrollTop,d=this._virtualization.rowHeight,h=Math.floor(c/d),f=h-h%2,u=-(c-f*d);r.style.transform=`translateY(${u}px)`,this.#y=c,this.#p||(this.#p=requestAnimationFrame(()=>{this.#p=0,this.#y!==null&&(this.#Z(this.#y),this.#y=null)}))},{passive:!0,signal:n});const l=this.#o.querySelector(".tbw-grid-content"),a=this.#o.querySelector(".tbw-scroll-area");l&&(l.addEventListener("wheel",c=>{c.preventDefault(),c.shiftKey||Math.abs(c.deltaX)>Math.abs(c.deltaY)?a&&(a.scrollLeft+=c.shiftKey?c.deltaY:c.deltaX):i.scrollTop+=c.deltaY},{passive:!1,signal:n}),l.addEventListener("touchstart",c=>{c.touches.length===1&&(this.#R=c.touches[0].clientY,this.#_=c.touches[0].clientX,this.#S=i.scrollTop,this.#A=a?.scrollLeft??0)},{passive:!0,signal:n}),l.addEventListener("touchmove",c=>{if(c.touches.length===1&&this.#R!==null&&this.#_!==null&&this.#S!==null&&this.#A!==null){const d=this.#R-c.touches[0].clientY,h=this.#_-c.touches[0].clientX;i.scrollTop=this.#S+d,a&&(a.scrollLeft=this.#A+h),c.preventDefault()}},{passive:!1,signal:n}),l.addEventListener("touchend",()=>{this.#R=null,this.#_=null,this.#S=null,this.#A=null},{passive:!0,signal:n}))}this.#o.addEventListener("mousedown",l=>this.#J(l),{signal:n}),document.addEventListener("mousemove",l=>this.#Q(l),{signal:n}),document.addEventListener("mouseup",l=>this.#ee(l),{signal:n}),this._virtualization.enabled&&requestAnimationFrame(()=>this.refreshVirtualWindow(!0));const s=this.#t.rowHeight;s&&s>0?this._virtualization.rowHeight=s:requestAnimationFrame(()=>{const l=this._bodyEl?.querySelector(".data-grid-row");if(l){const a=l.getBoundingClientRect().height;a>0&&(this._virtualization.rowHeight=a,this.refreshVirtualWindow(!0))}}),this._virtualization.viewportEl&&(this.#b=new ResizeObserver(()=>{this.#p||(this.#p=requestAnimationFrame(()=>{this.#p=0,this.refreshVirtualWindow(!0),z(this)}))}),this.#b.observe(this._virtualization.viewportEl)),queueMicrotask(()=>this.#V()),requestAnimationFrame(()=>requestAnimationFrame(()=>this.#m?.()))}#a(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}_emitCellCommit(e){this.#a("cell-commit",e)}_emitRowCommit(e){this.#a("row-commit",e)}_emitSortChange(e){this.#a("sort-change",e)}_emitColumnResize(e){this.#a("column-resize",e)}_emitActivateCell(e){this.#a("activate-cell",e)}#V(){this._bodyEl?.querySelectorAll(".data-grid-row")?.forEach((t,n)=>{const i=n===this._focusRow;t.setAttribute("aria-selected",String(i)),t.querySelectorAll(".cell").forEach((r,s)=>{r.setAttribute("aria-selected",String(i&&s===this._focusCol))})})}#W(){if(!this.#f)return;this.#h(),this.#t.fitMode==="fixed"?(this.__didInitialAutoSize=!1,qe(this)):(this._columns.forEach(t=>{!t.__userResized&&t.__autoSized&&delete t.width}),B(this))}#j(){this.#f&&(this.#h(),this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.refreshVirtualWindow(!0))}#U(){this._rows=Array.isArray(this.#s)?[...this.#s]:[],this.#T(),!this.#l||Array.isArray(this.#l)&&this.#l.length===0?this.#d():this.refreshVirtualWindow(!0)}#X(){le(this),this.#f&&(this.#h(),this.#d())}#Y(){this.#f&&(this.#h(),this.#z(),this.#T(),this.#I(),j(this),B(this),this.refreshVirtualWindow(!0))}#I(){if(this.#e){const e=this.#M.length>0?this.#M:this._columns,t=e.filter(r=>!r.hidden),n=e.filter(r=>r.hidden),i=this.#e.processColumns([...t]);if(i!==t){const r=new Map(i.map((l,a)=>[l.field,{col:l,order:a}]));if(!t.some(l=>r.has(l.field))&&i.length>0)this._columns=[...i,...n];else{const l=e.map(a=>{if(a.hidden)return a;const c=r.get(a.field);return c?c.col:a});this._columns=l}}else this._columns=[...e]}}#T(){le(this);const e=Array.isArray(this.#s)?[...this.#s]:[],t=this.#e?.processRows(e)??e;this._rows=t}#h(){const e=this.#w?{...this.#w}:{};let t=Array.isArray(e.columns)?[...e.columns]:[];const n=(this.__lightDomColumnsCache||[]).map(i=>({...i}));if(n.length){const i={};t.forEach(r=>i[r.field]=r),n.forEach(r=>{const s=i[r.field];s?(r.header&&!s.header&&(s.header=r.header),r.type&&!s.type&&(s.type=r.type),s.sortable=s.sortable||r.sortable,r.resizable&&(s.resizable=!0),r.editable&&(s.editable=!0)):(t.push(r),i[r.field]=r)})}if(this.#l&&this.#l.length&&(t=[...this.#l]),(!t||t.length===0)&&this._rows.length&&(t=Ne(this._rows).columns),t.length){t.forEach(s=>{s.sortable===void 0&&(s.sortable=!0),s.resizable===void 0&&(s.resizable=!0);const l=s;l.__originalWidth===void 0&&typeof s.width=="number"&&(l.__originalWidth=s.width)});const i=this.#t.columns;i?.some(s=>s.__compiledView||s.__compiledEditor)?e.columns=i:e.columns=t}else{const i=this.#t.columns;i?.some(r=>r.__compiledView||r.__compiledEditor)&&(e.columns=i)}this.#v&&(e.fitMode=this.#v),e.fitMode||(e.fitMode="stretch"),this.#C&&(e.editOn=this.#C),e.rowHeight&&e.rowHeight>0&&(this._virtualization.rowHeight=e.rowHeight),e.columnState&&!this.#u&&(this.#u=e.columnState),this.#t=e,e.fitMode==="fixed"&&this._columns.forEach(i=>{i.width==null&&(i.width=80)})}#H(e,t,n=this.__rowRenderEpoch){this.#L||(this.#L=(i,r,s)=>this.#e?.renderRow(i,r,s)??!1),Xt(this,e,t,n,this.#L)}#d(){if(!this.isConnected||!this._headerRowEl||!this._bodyEl)return;const e=this.#w?.columns||this.#l||[];if(e.length){const n=new Map(this._columns.filter(r=>r.hidden).map(r=>[r.field,!0])),i=e.map(r=>({...r,hidden:n.get(r.field)??r.hidden}));this._columns=i}if(Kt(this),this.#h(),this.#z(),this.#M=[...this._columns],this.#T(),this.#I(),this.#u){const n=this.#u;this.#u=void 0,this.#F(n)}j(this),B(this),this.refreshVirtualWindow(!0),this.#t.fitMode==="fixed"&&!this.__didInitialAutoSize&&requestAnimationFrame(()=>qe(this)),this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),queueMicrotask(()=>this.#e?.afterRender())}#F(e){const t=this.#t.columns??[],n=this.#e?.getAll()??[];Tt(this,e,t,n);for(const i of e.columns){const r=t.find(s=>s.field===i.field);r&&(r.hidden=!i.visible)}}#Z(e){if(this.refreshVirtualWindow(!1),this.#e?.onScrollRender(),this.#x){const t=this._virtualization.container,n={scrollTop:e,scrollLeft:t?.scrollLeft??0,scrollHeight:t?.scrollHeight??0,scrollWidth:t?.scrollWidth??0,clientHeight:t?.clientHeight??0,clientWidth:t?.clientWidth??0,originalEvent:new Event("scroll")};this.#e?.onScroll(n)}}findHeaderRow(){return this.#o.querySelector(".header-row")}findRenderedRowElement(e){return Array.from(this._bodyEl.querySelectorAll(".data-grid-row")).find(t=>{const n=t.querySelector(".cell[data-row]");return n&&Number(n.getAttribute("data-row"))===e})||null}_dispatchCellClick(e,t,n,i){const r=this._rows[t],s=this._columns[n];if(!r||!s)return!1;const l={row:r,rowIndex:t,colIndex:n,field:s.field,value:r[s.field],cellEl:i,originalEvent:e};return this.#e?.onCellClick(l)??!1}_dispatchHeaderClick(e,t,n){const i=this._columns[t];if(!i)return!1;const r={colIndex:t,field:i.field,column:i,headerEl:n,originalEvent:e};return this.#e?.onHeaderClick(r)??!1}_dispatchKeyDown(e){return this.#e?.onKeyDown(e)??!1}_getHorizontalScrollOffsets(e,t){return this.#e?.getHorizontalScrollOffsets(e,t)??{left:0,right:0}}queryPlugins(e){return this.#e?.queryPlugins(e)??[]}#N(e,t){let n=null;const i=e.composedPath?.();if(i&&i.length>0?n=i[0]:n=e.target,n&&!this.#o.contains(n)){const p=this.#o.elementFromPoint(e.clientX,e.clientY);p&&(n=p)}const r=n?.closest?.("[data-col]"),s=n?.closest?.(".data-grid-row"),l=n?.closest?.(".header-row");let a,c,d,h,f,u;return r&&(a=parseInt(r.getAttribute("data-row")??"-1",10),c=parseInt(r.getAttribute("data-col")??"-1",10),a>=0&&c>=0&&(d=this._rows[a],u=this._columns[c],h=u?.field,f=d&&h?d[h]:void 0)),{type:t,row:d,rowIndex:a!==void 0&&a>=0?a:void 0,colIndex:c!==void 0&&c>=0?c:void 0,field:h,value:f,column:u,originalEvent:e,cellElement:r??void 0,rowElement:s??void 0,isHeader:!!l,cell:a!==void 0&&c!==void 0&&a>=0&&c>=0?{row:a,col:c}:void 0}}#J(e){const t=this.#N(e,"mousedown");(this.#e?.onCellMouseDown(t)??!1)&&(this.#E=!0)}#Q(e){if(!this.#E)return;const t=this.#N(e,"mousemove");this.#e?.onCellMouseMove(t)}#ee(e){if(!this.#E)return;const t=this.#N(e,"mouseup");this.#e?.onCellMouseUp(t),this.#E=!1}get changedRows(){return Array.from(this._changedRowIndices).map(e=>this._rows[e])}get changedRowIndices(){return Array.from(this._changedRowIndices)}async resetChangedRows(e){this._changedRowIndices.clear(),e||this.#a("changed-rows-reset",{rows:this.changedRows,indices:this.changedRowIndices}),this._rowPool.forEach(t=>t.classList.remove("changed"))}async beginBulkEdit(e){if(!this._columns.some(r=>r.editable))return;const n=this._rows[e];W(this,e,n);const i=this.findRenderedRowElement?.(e);i&&(Array.from(i.children).forEach((r,s)=>{const l=this._visibleColumns[s];if(l?.editable){const a=r;a.classList.contains("editing")||D(this,n,e,l,a)}}),queueMicrotask(()=>{const r=i.querySelector(`.cell[data-col="${this._focusCol}"]`);if(r?.classList.contains("editing")){const s=r.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');try{s?.focus()}catch{}}}))}async commitActiveRowEdit(){this._activeEditRows!==-1&&$(this,this._activeEditRows,!1)}async ready(){return this.#g}async forceLayout(){this.#d(),await new Promise(e=>requestAnimationFrame(()=>requestAnimationFrame(e)))}async getConfig(){return Object.freeze({...this.#t||{}})}setColumnVisible(e,t){const n=this.#t.columns,i=n?.find(l=>l.field===e);if(!i||!t&&i.lockVisible||!t&&(n??[]).filter(a=>!a.hidden&&a.field!==e).length===0)return!1;const r=!!i.hidden,s=!t;return r!==s?(i.hidden=s,this.#a("column-visibility",{field:e,visible:t,visibleColumns:(n??[]).filter(l=>!l.hidden).map(l=>l.field)}),this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.#d(),this.requestStateChange(),!0):!1}toggleColumnVisibility(e){const i=!!this.#t.columns?.find(r=>r.field===e)?.hidden;return this.setColumnVisible(e,i)}isColumnVisible(e){const n=this.#t.columns?.find(i=>i.field===e);return n?!n.hidden:!1}showAllColumns(){const e=this.#t.columns;e?.some(n=>n.hidden)&&(e?.forEach(n=>{n.hidden=!1}),this.#a("column-visibility",{visibleColumns:(e??[]).map(n=>n.field)}),this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.#d(),this.requestStateChange())}getAllColumns(){return(this.#t.columns??[]).map(t=>({field:t.field,header:t.header||t.field,visible:!t.hidden,lockVisible:t.lockVisible}))}setColumnOrder(e){if(!e.length)return;const t=new Map(this._columns.map(i=>[i.field,i])),n=[];for(const i of e){const r=t.get(i);r&&(n.push(r),t.delete(i))}for(const i of t.values())n.push(i);this._columns=n,j(this),B(this),this.refreshVirtualWindow(!0)}getColumnOrder(){return this._columns.map(e=>e.field)}getColumnState(){const e=this.#e?.getAll()??[];return He(this,e)}set columnState(e){e&&(this.#u=e,this.#r&&this.#te(e))}get columnState(){return this.getColumnState()}#te(e){(this.#t.columns??[]).forEach(n=>{n.hidden=!1}),this.#F(e),this.#d()}requestStateChange(){this.#P||(this.#P=Lt(this,()=>this.#e?.getAll()??[],e=>this.#a("column-state-change",e))),this.#P()}resetColumnState(){this.#u=void 0,(this.#t.columns??[]).forEach(n=>{n.hidden=!1}),this._sortState=null,this.__originalOrder=[],this.#h(),this.#d();const t=this.#e?.getAll()??[];for(const n of t)if(n.applyColumnState)for(const i of this._columns)n.applyColumnState(i.field,{field:i.field,order:0,visible:!0});this.requestStateChange()}get isToolPanelOpen(){return this.#n.isPanelOpen}get activeToolPanel(){return this.#n.activePanel}get expandedToolPanelSections(){return this.#n.expandedSections}openToolPanel(){this.#n.openToolPanel()}closeToolPanel(){this.#n.closeToolPanel()}toggleToolPanel(){this.#n.toggleToolPanel()}toggleToolPanelSection(e){this.#n.toggleToolPanelSection(e)}getToolPanels(){return this.#n.getToolPanels()}registerToolPanel(e){this.#n.registerToolPanel(e)}unregisterToolPanel(e){this.#n.unregisterToolPanel(e)}getHeaderContents(){return this.#n.getHeaderContents()}registerHeaderContent(e){this.#n.registerHeaderContent(e)}unregisterHeaderContent(e){this.#n.unregisterHeaderContent(e)}getToolbarButtons(){return this.#n.getToolbarButtons()}registerToolbarButton(e){this.#n.registerToolbarButton(e)}unregisterToolbarButton(e){this.#n.unregisterToolbarButton(e)}setToolbarButtonDisabled(e,t){this.#n.setToolbarButtonDisabled(e,t)}refreshShellHeader(){Ge(this,this.#i),this.#B(),this.#q()}refreshVirtualWindow(e=!1){if(!this._bodyEl)return;const t=this._rows.length;if(!this._virtualization.enabled){this.#H(0,t),this.#e?.afterRender();return}if(this._rows.length<=this._virtualization.bypassThreshold){if(this._virtualization.start=0,this._virtualization.end=t,this._bodyEl.style.transform="translateY(0px)",this.#H(0,t,this.__rowRenderEpoch),this._virtualization.totalHeightEl){const S=this.#o.querySelector(".tbw-scroll-area"),E=S?S.offsetHeight-S.clientHeight:0;this._virtualization.totalHeightEl.style.height=`${t*this._virtualization.rowHeight+E}px`}const v=this.#o.querySelector(".rows-body");v?.setAttribute("aria-rowcount",String(t)),v?.setAttribute("aria-colcount",String(this._visibleColumns.length)),this.#e?.afterRender();return}const n=this._virtualization.container??this,r=(this._virtualization.viewportEl??n).clientHeight,s=this._virtualization.rowHeight,l=n.scrollTop;let a=Math.floor(l/s),c=0;const d=10;for(;c<d;){const v=this.#e?.getExtraHeightBefore?.(a)??0,S=Math.floor((l-v)/s);if(S>=a||S<0)break;a=S,c++}a=a-a%2,a<0&&(a=0);const h=this.#e?.adjustVirtualStart(a,l,s);h!==void 0&&h<a&&(a=h,a=a-a%2,a<0&&(a=0));const f=Math.ceil(r/s)+3;let u=a+f;u>t&&(u=t),this._virtualization.start=a,this._virtualization.end=u;const g=this.#o.querySelector(".tbw-footer")?.offsetHeight??0,w=this.#e?.getExtraHeight()??0,b=this.#o.querySelector(".tbw-scroll-area"),_=b?b.offsetHeight-b.clientHeight:0;this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${t*s+s+g+w+_}px`);const T=this.#e?.getExtraHeightBefore?.(a)??0,k=-(l-a*s-T);this._bodyEl.style.transform=`translateY(${k}px)`,this.#H(a,u,e?++this.__rowRenderEpoch:this.__rowRenderEpoch);const m=this.#o.querySelector(".rows-body");m?.setAttribute("aria-rowcount",String(t)),m?.setAttribute("aria-colcount",String(this._visibleColumns.length)),e&&this.#e?.afterRender()}#B(){Ge(this,this.#i);const e=this.#t?.shell,t=Qt(e,this.#i),n=`
|
|
45
45
|
<div class="tbw-scroll-area">
|
|
46
46
|
<div class="rows-body-wrapper">
|
|
47
47
|
<div class="rows-body" role="grid">
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
${n}
|
|
71
71
|
</div>
|
|
72
72
|
</div>
|
|
73
|
-
`}#oe(){oo(this.#o,this.#t?.shell,this.#i,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e),onToolbarButtonClick:e=>this.#ne(e)}),this.#k?.(),this.#k=no(this.#o,this.#t?.shell,e=>{this.style.setProperty("--tbw-tool-panel-width",`${e}px`)})}#ne(e){const n=(this.#t?.shell?.header?.toolbarButtons??[]).find(r=>r.id===e);if(n?.action){n.action();return}const i=this.#i.toolbarButtons.get(e);i?.action&&i.action()}}customElements.get(
|
|
73
|
+
`}#oe(){oo(this.#o,this.#t?.shell,this.#i,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e),onToolbarButtonClick:e=>this.#ne(e)}),this.#k?.(),this.#k=no(this.#o,this.#t?.shell,e=>{this.style.setProperty("--tbw-tool-panel-width",`${e}px`)})}#ne(e){const n=(this.#t?.shell?.header?.toolbarButtons??[]).find(r=>r.id===e);if(n?.action){n.action();return}const i=this.#i.toolbarButtons.get(e);i?.action&&i.action()}}customElements.get(G.tagName)||customElements.define(G.tagName,G);const he={CAN_MOVE_COLUMN:"canMoveColumn",GET_CONTEXT_MENU_ITEMS:"getContextMenuItems"};class L{version="1.0.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}attach(e){this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}requestRender(){this.grid?.requestRender?.()}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 shadowRoot(){return this.grid?.shadowRoot??null}get disconnectSignal(){return this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...I,...e}}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 M={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"},ee={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"},uo={ROOT:`.${M.ROOT}`,HEADER:`.${M.HEADER}`,HEADER_ROW:`.${M.HEADER_ROW}`,HEADER_CELL:`.${M.HEADER_CELL}`,ROWS_VIEWPORT:`.${M.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${M.ROWS_CONTAINER}`,DATA_ROW:`.${M.DATA_ROW}`,DATA_CELL:`.${M.DATA_CELL}`,GROUP_ROW:`.${M.GROUP_ROW}`,ROW_BY_INDEX:o=>`.${M.DATA_ROW}[${ee.ROW_INDEX}="${o}"]`,CELL_BY_FIELD:o=>`.${M.DATA_CELL}[${ee.FIELD}="${o}"]`,CELL_AT:(o,e)=>`.${M.DATA_ROW}[${ee.ROW_INDEX}="${o}"] .${M.DATA_CELL}[${ee.COL_INDEX}="${e}"]`,SELECTED_ROWS:`.${M.DATA_ROW}.${M.SELECTED}`,EDITING_CELL:`.${M.DATA_CELL}.${M.EDITING}`},ho={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"},fo={CELL_COMMIT:"cell-commit",ROW_COMMIT:"row-commit",CHANGED_ROWS_RESET:"changed-rows-reset",MOUNT_EXTERNAL_VIEW:"mount-external-view",MOUNT_EXTERNAL_EDITOR:"mount-external-editor",SORT_CHANGE:"sort-change",COLUMN_RESIZE:"column-resize",ACTIVATE_CELL:"activate-cell",GROUP_TOGGLE:"group-toggle",COLUMN_STATE_CHANGE:"column-state-change"},po={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"},fe={sum:(o,e)=>o.reduce((t,n)=>t+(Number(n[e])||0),0),avg:(o,e)=>{const t=o.reduce((n,i)=>n+(Number(i[e])||0),0);return o.length?t/o.length:0},count:o=>o.length,min:(o,e)=>Math.min(...o.map(t=>Number(t[e])||1/0)),max:(o,e)=>Math.max(...o.map(t=>Number(t[e])||-1/0)),first:(o,e)=>o[0]?.[e],last:(o,e)=>o[o.length-1]?.[e]},te=new Map,N={register(o,e){te.set(o,e)},unregister(o){te.delete(o)},get(o){if(o!==void 0)return typeof o=="function"?o:te.get(o)??fe[o]},run(o,e,t,n){const i=this.get(o);return i?i(e,t,n):void 0},has(o){return te.has(o)||o in fe},list(){return[...Object.keys(fe),...te.keys()]}},Ue={sum:o=>o.reduce((e,t)=>e+t,0),avg:o=>o.length?o.reduce((e,t)=>e+t,0)/o.length:0,count:o=>o.length,min:o=>o.length?Math.min(...o):0,max:o=>o.length?Math.max(...o):0,first:o=>o[0]??0,last:o=>o[o.length-1]??0};function pe(o){return Ue[o]??Ue.sum}function go(o,e){return pe(o)(e)}const wo=N.register.bind(N),bo=N.unregister.bind(N),Xe=N.get.bind(N),ge=N.run.bind(N),mo=N.list.bind(N);function vo(o,e,t,n){if(n.processCell)return n.processCell(o,e,t);if(o==null)return"";if(o instanceof Date)return o.toISOString();if(typeof o=="object")return JSON.stringify(o);const i=String(o),r=n.delimiter??" ",s=n.newline??`
|
|
74
74
|
`;return n.quoteStrings||i.includes(r)||i.includes(s)||i.includes('"')?`"${i.replace(/"/g,'""')}"`:i}function we(o){const{rows:e,columns:t,selectedIndices:n,config:i}=o,r=i.delimiter??" ",s=i.newline??`
|
|
75
75
|
`,l=t.filter(h=>!h.hidden&&!h.field.startsWith("__")),a=[];if(i.includeHeaders){const h=l.map(f=>{const u=f.header||f.field;return u.includes(r)||u.includes(s)||u.includes('"')?`"${u.replace(/"/g,'""')}"`:u});a.push(h.join(r))}const d=[...n instanceof Set?[...n]:n].sort((h,f)=>h-f);for(const h of d){const f=e[h];if(!f)continue;const u=l.map(p=>vo(f[p.field],p.field,f,i));a.push(u.join(r))}return a.join(s)}async function be(o){try{return await navigator.clipboard.writeText(o),!0}catch{const e=document.createElement("textarea");e.value=o,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 Ye(o,e){const t=e.delimiter??" ",n=e.newline??`
|
|
76
76
|
`,i=o.replace(/\r\n/g,`
|
|
@@ -89,5 +89,5 @@
|
|
|
89
89
|
<Row>`;for(const r of e){let s=i[r.field];t.processCell&&(s=t.processCell(s,r.field,i));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=it(String(s)),n+=`<Cell><Data ss:Type="${l}">${a}</Data></Cell>`}n+="</Row>"}return n+=`
|
|
90
90
|
</Table>
|
|
91
91
|
</Worksheet>
|
|
92
|
-
</Workbook>`,n}function Po(o,e){const t=e.endsWith(".xls")?e:`${e}.xls`,n=new Blob([o],{type:"application/vnd.ms-excel;charset=utf-8;"});Ee(n,t)}class Mo extends L{name="export";version="1.0.0";get defaultConfig(){return{fileName:"export",includeHeaders:!0,onlyVisible:!0,onlySelected:!1}}isExportingFlag=!1;lastExportInfo=null;performExport(e,t){const n=this.config,i={format:e,fileName:t?.fileName??n.fileName??"export",includeHeaders:t?.includeHeaders??n.includeHeaders,processCell:t?.processCell,processHeader:t?.processHeader,columns:t?.columns,rowIndices:t?.rowIndices};let r=[...this.columns];if(n.onlyVisible&&(r=r.filter(a=>!a.hidden&&!a.field.startsWith("__"))),t?.columns){const a=new Set(t.columns);r=r.filter(c=>a.has(c.field))}let s=[...this.rows];if(n.onlySelected){const a=this.getSelectionState();a?.selected?.size&&(s=[...a.selected].sort((d,h)=>d-h).map(d=>this.rows[d]).filter(Boolean))}t?.rowIndices&&(s=t.rowIndices.map(a=>this.rows[a]).filter(Boolean)),this.isExportingFlag=!0;let l=i.fileName;try{switch(e){case"csv":{const a=ko(s,r,i,{bom:!0});l=l.endsWith(".csv")?l:`${l}.csv`,To(a,l);break}case"excel":{const a=Lo(s,r,i);l=l.endsWith(".xls")?l:`${l}.xls`,Po(a,l);break}case"json":{const a=s.map(h=>{const f={};for(const u of r){let p=h[u.field];i.processCell&&(p=i.processCell(p,u.field,h)),f[u.field]=p}return f}),c=JSON.stringify(a,null,2);l=l.endsWith(".json")?l:`${l}.json`;const d=new Blob([c],{type:"application/json"});Ee(d,l);break}}this.lastExportInfo={format:e,timestamp:new Date},this.emit("export-complete",{format:e,fileName:l,rowCount:s.length,columnCount:r.length})}finally{this.isExportingFlag=!1}}getSelectionState(){try{return this.grid?.getPluginState?.("selection")??null}catch{return null}}exportCsv(e){this.performExport("csv",e)}exportExcel(e){this.performExport("excel",e)}exportJson(e){this.performExport("json",e)}isExporting(){return this.isExportingFlag}getLastExport(){return this.lastExportInfo}}function Io(o){const{totalRows:e,viewportHeight:t,scrollTop:n,rowHeight:i,overscan:r}=o,s=Math.ceil(t/i);let l=Math.floor(n/i)-r;l<0&&(l=0);let a=l+s+r*2;return a>e&&(a=e),a===e&&l>0&&(l=Math.max(0,a-s-r*2)),{start:l,end:a,offsetY:l*i,totalHeight:e*i}}function Ho(o,e){return o<=e}function No(o,e,t=!1){const n=o[e.field];if(e.operator==="blank")return n==null||n==="";if(e.operator==="notBlank")return n!=null&&n!=="";if(n==null)return!1;const i=String(n),r=t?i:i.toLowerCase(),s=t?String(e.value):String(e.value).toLowerCase();switch(e.operator){case"contains":return r.includes(s);case"notContains":return!r.includes(s);case"equals":return r===s;case"notEquals":return r!==s;case"startsWith":return r.startsWith(s);case"endsWith":return r.endsWith(s);case"lessThan":return Number(n)<Number(e.value);case"lessThanOrEqual":return Number(n)<=Number(e.value);case"greaterThan":return Number(n)>Number(e.value);case"greaterThanOrEqual":return Number(n)>=Number(e.value);case"between":return Number(n)>=Number(e.value)&&Number(n)<=Number(e.valueTo);case"in":return Array.isArray(e.value)&&e.value.includes(n);case"notIn":return Array.isArray(e.value)&&!e.value.includes(n);default:return!0}}function Oo(o,e,t=!1){return e.length?o.filter(n=>e.every(i=>No(n,i,t))):o}function Do(o){return JSON.stringify(o.map(e=>({field:e.field,operator:e.operator,value:e.value,valueTo:e.valueTo})))}function rt(o,e){const t=new Set;for(const n of o){const i=n[e];i!=null&&t.add(i)}return[...t].sort((n,i)=>typeof n=="number"&&typeof i=="number"?n-i:String(n).localeCompare(String(i)))}const zo='.header-cell.filtered:before{content:"";position:absolute;top:4px;right:4px;width:6px;height:6px;background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border-radius:50%}.tbw-filter-btn{display:inline-flex;align-items:center;justify-content:center;background:transparent;border:none;cursor:pointer;padding:2px;margin-left:4px;opacity:.4;transition:opacity .15s;color:inherit;vertical-align:middle}.tbw-filter-btn:hover,.tbw-filter-btn.active{opacity:1}.tbw-filter-btn.active{color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6))}',qo=".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, 4px));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:12px;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, 13px)}.tbw-filter-search{margin-bottom:8px}.tbw-filter-search-input{width:100%;padding:6px 10px;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, 4px);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:4px 2px;margin-bottom:8px;border-bottom:1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)))}.tbw-filter-action-btn{background:transparent;border:none;color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));cursor:pointer;font-size:12px;padding:2px 0}.tbw-filter-action-btn:hover{text-decoration:underline}.tbw-filter-values{flex:1;overflow-y:auto;margin-bottom:8px;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:8px;padding:4px 2px;cursor:pointer;border-radius:3px}.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:8px 0;text-align:center;font-style:italic}.tbw-filter-buttons{display:flex;gap:8px;padding-top:8px;border-top:1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)))}.tbw-filter-apply-btn{flex:1;padding:6px 12px;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:4px;cursor:pointer;font-size:13px}.tbw-filter-apply-btn:hover{filter:brightness(.9)}.tbw-filter-clear-btn{flex:1;padding:6px 12px;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:4px;cursor:pointer;font-size:13px}.tbw-filter-clear-btn:hover{background:var(--tbw-filter-hover, var(--tbw-color-row-hover, light-dark(#f0f6ff, #1c1c1c)))}";class F extends L{name="filtering";version="1.0.0";get defaultConfig(){return{debounceMs:300,caseSensitive:!1,trimInput:!0,useWorker:!0}}filters=new Map;cachedResult=null;cacheKey=null;openPanelField=null;panelElement=null;searchText=new Map;excludedValues=new Map;panelAbortController=null;globalStylesInjected=!1;static LIST_ITEM_HEIGHT=28;static LIST_OVERSCAN=3;static LIST_BYPASS_THRESHOLD=50;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];const n=Do(t);if(this.cacheKey===n&&this.cachedResult)return this.cachedResult;const i=Oo([...e],t,this.config.caseSensitive);return this.cachedResult=i,this.cacheKey=n,i}afterRender(){const e=this.shadowRoot;if(!e)return;e.querySelectorAll('[part~="header-cell"]').forEach(n=>{const i=n.getAttribute("data-col");if(i===null)return;const r=this.columns[parseInt(i,10)];if(!r||r.filterable===!1||n.querySelector(".tbw-filter-btn"))return;const s=r.field;if(!s)return;const l=document.createElement("button");l.className="tbw-filter-btn",l.setAttribute("aria-label",`Filter ${r.header??s}`),l.innerHTML='<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>',this.filters.has(s)&&(l.classList.add("active"),n.classList.add("filtered")),l.addEventListener("click",a=>{a.stopPropagation(),this.toggleFilterPanel(s,r,l)}),n.appendChild(l)})}setFilter(e,t){t===null?this.filters.delete(e):this.filters.set(e,{...t,field:e}),this.cachedResult=null,this.cacheKey=null,this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0}),this.requestRender()}getFilter(e){return this.filters.get(e)}getFilters(){return[...this.filters.values()]}getFilterModel(){return this.getFilters()}setFilterModel(e){this.filters.clear();for(const t of e)this.filters.set(t.field,t);this.cachedResult=null,this.cacheKey=null,this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0}),this.requestRender()}clearAllFilters(){this.filters.clear(),this.excludedValues.clear(),this.searchText.clear(),this.cachedResult=null,this.cacheKey=null,this.emit("filter-change",{filters:[],filteredRowCount:this.rows.length}),this.requestRender()}clearFieldFilter(e){this.filters.delete(e),this.excludedValues.delete(e),this.searchText.delete(e),this.cachedResult=null,this.cacheKey=null,this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0}),this.requestRender()}isFieldFiltered(e){return this.filters.has(e)}getFilteredRowCount(){return this.cachedResult?.length??this.rows.length}getActiveFilters(){return this.getFilters()}getUniqueValues(e){return rt(this.sourceRows,e)}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=qo,document.head.appendChild(e),this.globalStylesInjected=!0}toggleFilterPanel(e,t,n){if(this.openPanelField===e){this.closeFilterPanel();return}this.closeFilterPanel();const i=document.createElement("div");i.className="tbw-filter-panel",this.panelElement=i,this.openPanelField=e;const r=rt(this.sourceRows,e);let s=this.excludedValues.get(e);s||(s=new Set,this.excludedValues.set(e,s));const l=this.searchText.get(e)??"",a={field:e,column:t,uniqueValues:r,excludedValues:s,searchText:l,applySetFilter:d=>{this.applySetFilter(e,d),this.closeFilterPanel()},applyTextFilter:(d,h,f)=>{this.applyTextFilter(e,d,h,f),this.closeFilterPanel()},clearFilter:()=>{this.clearFieldFilter(e),this.closeFilterPanel()},closePanel:()=>this.closeFilterPanel()};let c=!1;this.config.filterPanelRenderer&&(this.config.filterPanelRenderer(i,a),c=i.children.length>0),c||this.renderDefaultFilterPanel(i,a,r,s),document.body.appendChild(i),this.positionPanel(i,n),this.panelAbortController=new AbortController,setTimeout(()=>{document.addEventListener("click",d=>{!i.contains(d.target)&&d.target!==n&&this.closeFilterPanel()},{signal:this.panelAbortController?.signal})},0)}closeFilterPanel(){this.panelElement&&(this.panelElement.remove(),this.panelElement=null),this.openPanelField=null,this.panelAbortController?.abort(),this.panelAbortController=null}positionPanel(e,t){const n=t.getBoundingClientRect();e.style.position="fixed",e.style.top=`${n.bottom+4}px`,e.style.left=`${n.left}px`,requestAnimationFrame(()=>{const i=e.getBoundingClientRect();i.right>window.innerWidth-8&&(e.style.left=`${window.innerWidth-i.width-8}px`),i.bottom>window.innerHeight-8&&(e.style.top=`${n.top-i.height-4}px`)})}renderDefaultFilterPanel(e,t,n,i){const{field:r}=t,s=document.createElement("div");s.className="tbw-filter-search";const l=document.createElement("input");l.type="text",l.placeholder="Search...",l.className="tbw-filter-search-input",l.value=this.searchText.get(r)??"",s.appendChild(l),e.appendChild(s);const a=document.createElement("div");a.className="tbw-filter-actions";const c=document.createElement("label");c.className="tbw-filter-value-item",c.style.padding="0",c.style.margin="0";const d=document.createElement("input");d.type="checkbox",d.className="tbw-filter-checkbox";const h=document.createElement("span");h.textContent="Select All",c.appendChild(d),c.appendChild(h),a.appendChild(c);const f=()=>{const C=[...w.values()],x=C.every(A=>A),R=C.every(A=>!A);d.checked=x,d.indeterminate=!x&&!R};d.addEventListener("change",()=>{const C=d.checked;for(const x of w.keys())w.set(x,C);f(),T()}),e.appendChild(a);const u=document.createElement("div");u.className="tbw-filter-values";const p=document.createElement("div");p.className="tbw-filter-values-spacer",u.appendChild(p);const g=document.createElement("div");g.className="tbw-filter-values-content",u.appendChild(g);const w=new Map;n.forEach(C=>{const x=C==null?"__null__":String(C);w.set(x,!i.has(C))}),f();let b=[];const _=(C,x)=>{const R=C==null?"(Blank)":String(C),A=C==null?"__null__":String(C),P=document.createElement("label");P.className="tbw-filter-value-item",P.style.position="absolute",P.style.top=`${x*F.LIST_ITEM_HEIGHT}px`,P.style.left="0",P.style.right="0",P.style.height=`${F.LIST_ITEM_HEIGHT}px`,P.style.boxSizing="border-box";const D=document.createElement("input");D.type="checkbox",D.className="tbw-filter-checkbox",D.checked=w.get(A)??!0,D.dataset.value=A,D.addEventListener("change",()=>{w.set(A,D.checked),f()});const At=document.createElement("span");return At.textContent=R,P.appendChild(D),P.appendChild(At),P},T=()=>{const C=b.length,x=u.clientHeight,R=u.scrollTop;if(p.style.height=`${C*F.LIST_ITEM_HEIGHT}px`,Ho(C,F.LIST_BYPASS_THRESHOLD/3)){g.innerHTML="",g.style.transform="translateY(0px)",b.forEach((P,D)=>{g.appendChild(_(P,D))});return}const A=Io({totalRows:C,viewportHeight:x,scrollTop:R,rowHeight:F.LIST_ITEM_HEIGHT,overscan:F.LIST_OVERSCAN});g.style.transform=`translateY(${A.offsetY}px)`,g.innerHTML="";for(let P=A.start;P<A.end;P++)g.appendChild(_(b[P],P-A.start))},k=C=>{const x=C.toLowerCase();if(b=n.filter(R=>{const A=R==null?"(Blank)":String(R);return!C||A.toLowerCase().includes(x)}),b.length===0){p.style.height="0px",g.innerHTML="";const R=document.createElement("div");R.className="tbw-filter-no-match",R.textContent="No matching values",g.appendChild(R);return}T()};u.addEventListener("scroll",()=>{b.length>0&&T()},{passive:!0}),k(l.value),e.appendChild(u);let m;l.addEventListener("input",()=>{clearTimeout(m),m=setTimeout(()=>{this.searchText.set(r,l.value),k(l.value)},this.config.debounceMs??150)});const v=document.createElement("div");v.className="tbw-filter-buttons";const S=document.createElement("button");S.className="tbw-filter-apply-btn",S.textContent="Apply",S.addEventListener("click",()=>{const C=[];for(const[x,R]of w)if(!R)if(x==="__null__")C.push(null);else{const A=n.find(P=>String(P)===x);C.push(A!==void 0?A:x)}t.applySetFilter(C)}),v.appendChild(S);const E=document.createElement("button");E.className="tbw-filter-clear-btn",E.textContent="Clear Filter",E.addEventListener("click",()=>{t.clearFilter()}),v.appendChild(E),e.appendChild(v)}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.cachedResult=null,this.cacheKey=null,this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0}),this.requestRender()}applyTextFilter(e,t,n,i){this.filters.set(e,{field:e,type:"text",operator:t,value:n,valueTo:i}),this.cachedResult=null,this.cacheKey=null,this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0}),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 n={field:e,type:t.filter.type,operator:t.filter.operator,value:t.filter.value,valueTo:t.filter.valueTo};this.filters.set(e,n),this.cachedResult=null,this.cacheKey=null}styles=zo}function Fo(o){if(!o.length)return[];const e=new Map,t=[],n=(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 i=[],r=0;return o.forEach((s,l)=>{const a=s.group;if(!a){i.length===0&&(r=l),i.push(s);return}i.length&&(n(r,i.slice()),i=[]);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)}),i.length&&n(r,i),t.length===1&&t[0].implicit&&t[0].columns.length===o.length?[]:t}function Bo(o,e,t){if(!e.length||!o)return;const n=new Map;for(const r of e)for(const s of r.columns)s?.field&&n.set(s.field,r.id);const i=Array.from(o.querySelectorAll(".cell[data-field]"));i.forEach(r=>{const s=r.getAttribute("data-field")||"",l=n.get(s);l&&(r.classList.add("grouped"),r.getAttribute("data-group")||r.setAttribute("data-group",l))});for(const r of e){const s=r.columns[r.columns.length-1],l=i.find(a=>a.getAttribute("data-field")===s.field);l&&l.classList.add("group-end")}}function $o(o,e){if(o.length===0)return null;const t=document.createElement("div");t.className="header-group-row",t.setAttribute("role","row");for(const n of o){const i=n.firstIndex!=null?n.firstIndex:e.findIndex(a=>n.columns.includes(a)),r=String(n.id).startsWith("__implicit__"),s=r?"":n.label||n.id,l=document.createElement("div");l.className="cell header-group-cell",r&&l.classList.add("implicit-group"),l.setAttribute("data-group",String(n.id)),l.style.gridColumn=`${i+1} / span ${n.columns.length}`,l.textContent=s,t.appendChild(l)}return t}function Go(o){return o.some(e=>e.group!=null)}const Ko=".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:4px 8px;font-weight:600;font-size:.9em;text-transform:uppercase;letter-spacing:.5px;border-right:1px solid var(--tbw-grouping-columns-border, 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))}";class Vo extends L{name="groupingColumns";version="1.0.0";get defaultConfig(){return{showGroupBorders:!0}}groups=[];isActive=!1;detach(){this.groups=[],this.isActive=!1}static detect(e,t){const n=t?.columns;return Array.isArray(n)?Go(n):!1}processColumns(e){const t=Fo(e);return t.length===0?(this.isActive=!1,this.groups=[],[...e]):(this.isActive=!0,this.groups=t,[...e])}afterRender(){if(!this.isActive||this.groups.length===0){const s=this.shadowRoot?.querySelector(".header")?.querySelector(".header-group-row");s&&s.remove();return}const e=this.shadowRoot?.querySelector(".header");if(!e)return;const t=e.querySelector(".header-group-row");t&&t.remove();const n=$o(this.groups,this.columns);if(n){const r=e.querySelector(".header-row");r?e.insertBefore(n,r):e.appendChild(n)}const i=e.querySelector(".header-row");i&&Bo(i,this.groups,this.columns)}isGroupingActive(){return this.isActive}getGroups(){return this.groups}getGroupColumns(e){const t=this.groups.find(n=>n.id===e);return t?t.columns:[]}refresh(){this.requestRender()}styles=Ko}function Wo({rows:o,config:e,expanded:t}){const n=e.groupOn;if(typeof n!="function")return[];const i={key:"__root__",value:null,depth:-1,rows:[],children:new Map};if(o.forEach(l=>{let a=n(l);a==null||a===!1?a=["__ungrouped__"]:Array.isArray(a)||(a=[a]);let c=i;a.forEach((d,h)=>{const f=d==null?"∅":String(d),u=c.key==="__root__"?f:c.key+"||"+f;let p=c.children.get(f);p||(p={key:u,value:d,depth:h,rows:[],children:new Map,parent:c},c.children.set(f,p)),c=p}),c.rows.push(l)}),i.children.size===1&&i.children.has("__ungrouped__")&&i.children.get("__ungrouped__").rows.length===o.length)return[];const r=[],s=l=>{if(l===i){l.children.forEach(c=>s(c));return}const a=t.has(l.key);r.push({kind:"group",key:l.key,value:l.value,depth:l.depth,rows:l.rows,expanded:a}),a&&(l.children.size?l.children.forEach(c=>s(c)):l.rows.forEach(c=>r.push({kind:"data",row:c,rowIndex:o.indexOf(c)})))};return s(i),r}function jo(o,e){const t=new Set(o);return t.has(e)?t.delete(e):t.add(e),t}function Uo(o){const e=new Set;for(const t of o)t.kind==="group"&&e.add(t.key);return e}function Xo(){return new Set}function Yo(o){return o.kind!=="group"?0:o.rows.length}const Zo='.group-row{background:var(--tbw-grouping-rows-bg, var(--tbw-color-panel-bg));font-weight:500}.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:20px;height:20px;margin-right:4px;font-size:10px}.group-toggle:hover{background:var(--tbw-grouping-rows-toggle-hover, var(--tbw-color-row-hover));border-radius:2px}.group-label{display:inline-flex;align-items:center;gap:8px}.group-count{color:var(--tbw-grouping-rows-count-color, var(--tbw-color-fg-muted));font-size:.85em;font-weight:400}[data-group-depth="0"] .group-label{padding-left:0}[data-group-depth="1"] .group-label{padding-left:20px}[data-group-depth="2"] .group-label{padding-left:40px}[data-group-depth="3"] .group-label{padding-left:60px}[data-group-depth="4"] .group-label{padding-left:80px}';class Jo extends L{name="groupingRows";version="1.0.0";get defaultConfig(){return{defaultExpanded:!1,showRowCount:!0,indentWidth:20,aggregators:{}}}expandedKeys=new Set;flattenedRows=[];isActive=!1;detach(){this.expandedKeys.clear(),this.flattenedRows=[],this.isActive=!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 n=Wo({rows:e,config:t,expanded:this.expandedKeys});return n.length===0?(this.isActive=!1,this.flattenedRows=[],[...e]):(this.isActive=!0,this.flattenedRows=n,n.map(i=>i.kind==="group"?{__isGroupRow:!0,__groupKey:i.key,__groupValue:i.value,__groupDepth:i.depth,__groupRows:i.rows,__groupExpanded:i.expanded,__groupRowCount:Yo(i)}:i.row))}onCellClick(e){const t=e.row;if(t?.__isGroupRow&&e.originalEvent.target?.closest(".group-toggle"))return this.toggle(t.__groupKey),!0}renderRow(e,t,n){if(!e?.__isGroupRow)return!1;const i=this.config;if(i.groupRowRenderer){const l=()=>{this.toggle(e.__groupKey)},a=i.groupRowRenderer({key:e.__groupKey,value:e.__groupValue,depth:e.__groupDepth,rows:e.__groupRows,expanded:e.__groupExpanded,toggleExpand:l});if(a)return t.className="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 r=()=>{this.toggle(e.__groupKey)};return t.className="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.paddingLeft=`${(e.__groupDepth||0)*(i.indentWidth??20)}px`,t.innerHTML="",i.fullWidth!==!1?this.renderFullWidthGroupRow(e,t,r):this.renderPerColumnGroupRow(e,t,r),!0}afterRender(){}renderFullWidthGroupRow(e,t,n){const i=this.config,r=document.createElement("div");r.className="cell group-full",r.style.gridColumn="1 / -1",r.setAttribute("role","gridcell");const s=document.createElement("button");s.type="button",s.className="group-toggle",s.setAttribute("aria-label",e.__groupExpanded?"Collapse group":"Expand group"),this.setIcon(s,this.resolveIcon(e.__groupExpanded?"collapse":"expand")),s.addEventListener("click",c=>{c.stopPropagation(),n()}),r.appendChild(s);const l=document.createElement("span");l.className="group-label";const a=i.formatLabel?i.formatLabel(e.__groupValue,e.__groupDepth||0,e.__groupKey):String(e.__groupValue);if(l.textContent=a,r.appendChild(l),i.showRowCount!==!1){const c=document.createElement("span");c.className="group-count",c.textContent=`(${e.__groupRowCount??e.__groupRows?.length??0})`,r.appendChild(c)}t.appendChild(r)}renderPerColumnGroupRow(e,t,n){const i=this.config,r=i.aggregators??{},s=this.columns,l=e.__groupRows??[],c=this.shadowRoot?.querySelector(".body")?.style.gridTemplateColumns||"";c&&(t.style.display="grid",t.style.gridTemplateColumns=c),s.forEach((d,h)=>{const f=document.createElement("div");if(f.className="cell group-cell",f.setAttribute("data-col",String(h)),f.setAttribute("role","gridcell"),h===0){const u=document.createElement("button");u.type="button",u.className="group-toggle",u.setAttribute("aria-label",e.__groupExpanded?"Collapse group":"Expand group"),this.setIcon(u,this.resolveIcon(e.__groupExpanded?"collapse":"expand")),u.addEventListener("click",w=>{w.stopPropagation(),n()}),f.appendChild(u);const p=document.createElement("span"),g=r[d.field];if(g){const w=ge(g,l,d.field,d);p.textContent=w!=null?String(w):String(e.__groupValue)}else{const w=i.formatLabel?i.formatLabel(e.__groupValue,e.__groupDepth||0,e.__groupKey):String(e.__groupValue);p.textContent=w}if(f.appendChild(p),i.showRowCount!==!1){const w=document.createElement("span");w.className="group-count",w.textContent=` (${l.length})`,f.appendChild(w)}}else{const u=r[d.field];if(u){const p=ge(u,l,d.field,d);f.textContent=p!=null?String(p):""}else f.textContent=""}t.appendChild(f)})}expandAll(){this.expandedKeys=Uo(this.flattenedRows),this.requestRender()}collapseAll(){this.expandedKeys=Xo(),this.requestRender()}toggle(e){this.expandedKeys=jo(this.expandedKeys,e);const t=this.flattenedRows.find(n=>n.kind==="group"&&n.key===e);this.emit("group-toggle",{key:e,expanded:this.expandedKeys.has(e),value:t?.value,depth:t?.depth??0}),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()}styles=Zo}function Re(o,e){const t=new Set(o);return t.has(e)?t.delete(e):t.add(e),t}function Qo(o,e){const t=new Set(o);return t.add(e),t}function en(o,e){const t=new Set(o);return t.delete(e),t}function tn(o,e){return o.has(e)}function on(o,e,t,n){const i=document.createElement("div");i.className="master-detail-row",i.setAttribute("data-detail-for",String(e)),i.setAttribute("role","row");const r=document.createElement("div");r.className="master-detail-cell",r.setAttribute("role","cell"),r.style.gridColumn=`1 / ${n+1}`;const s=t(o,e);return typeof s=="string"?r.innerHTML=s:s instanceof HTMLElement&&r.appendChild(s),i.appendChild(r),i}const nn=".master-detail-cell-wrapper{display:flex;align-items:center;gap:4px}.master-detail-toggle{cursor:pointer;font-size:10px;opacity:.7;-webkit-user-select:none;user-select:none}.master-detail-toggle:hover{opacity:1}.master-detail-row{grid-column:1 / -1;display:grid;background:var(--tbw-master-detail-bg, var(--tbw-color-row-alt));border-bottom:1px solid var(--tbw-master-detail-border, var(--tbw-color-border))}.master-detail-cell{padding:16px;overflow:auto}";class rn extends L{name="masterDetail";version="1.0.0";get defaultConfig(){return{detailHeight:"auto",expandOnRowClick:!1,collapseOnClickOutside:!1,showExpandColumn:!0}}expandedRows=new Set;detailElements=new Map;detach(){this.expandedRows.clear(),this.detailElements.clear()}processColumns(e){if(!this.config.detailRenderer)return[...e];const t=[...e];if(t.length>0){const n={...t[0]},i=n.viewRenderer;if(i?.__masterDetailWrapped)return t;const r=s=>{const{value:l,row:a}=s,c=this.expandedRows.has(a),d=document.createElement("span");d.className="master-detail-cell-wrapper";const h=document.createElement("span");h.className="master-detail-toggle",this.setIcon(h,this.resolveIcon(c?"collapse":"expand")),h.setAttribute("role","button"),h.setAttribute("tabindex","0"),h.setAttribute("aria-expanded",String(c)),h.setAttribute("aria-label",c?"Collapse details":"Expand details"),h.addEventListener("click",u=>{u.stopPropagation();const p=this.rows.indexOf(a);this.expandedRows=Re(this.expandedRows,a),this.emit("detail-expand",{rowIndex:p,row:a,expanded:this.expandedRows.has(a)}),this.requestRender()}),d.appendChild(h);const f=document.createElement("span");if(i){const u=i(s);u instanceof Node?f.appendChild(u):f.textContent=String(u??l??"")}else f.textContent=String(l??"");return d.appendChild(f),d};r.__masterDetailWrapped=!0,n.viewRenderer=r,t[0]=n}return t}onRowClick(e){if(!(!this.config.expandOnRowClick||!this.config.detailRenderer))return this.expandedRows=Re(this.expandedRows,e.row),this.emit("detail-expand",{rowIndex:e.rowIndex,row:e.row,expanded:this.expandedRows.has(e.row)}),this.requestRender(),!1}onCellClick(){this.expandedRows.size>0&&queueMicrotask(()=>this.#o())}afterRender(){this.#o()}onScrollRender(){!this.config.detailRenderer||this.expandedRows.size===0||this.#o()}#o(){if(!this.config.detailRenderer)return;const e=this.shadowRoot?.querySelector(".rows");if(!e)return;const t=new Map,n=e.querySelectorAll(".data-grid-row"),i=this.columns.length;for(const s of n){const l=s.querySelector(".cell[data-row]"),a=l?parseInt(l.getAttribute("data-row")??"-1",10):-1;a>=0&&t.set(a,s)}const r=e.querySelectorAll(".master-detail-row");for(const s of r){const l=parseInt(s.getAttribute("data-detail-for")??"-1",10),a=l>=0?this.rows[l]:void 0,c=a&&this.expandedRows.has(a),d=t.has(l);(!c||!d)&&(s.remove(),a&&this.detailElements.delete(a))}for(const[s,l]of t){const a=this.rows[s];if(!a||!this.expandedRows.has(a))continue;const c=this.detailElements.get(a);if(c){c.previousElementSibling!==l&&l.after(c);continue}const d=on(a,s,this.config.detailRenderer,i);typeof this.config.detailHeight=="number"&&(d.style.height=`${this.config.detailHeight}px`),l.after(d),this.detailElements.set(a,d)}}getExtraHeight(){let e=0;for(const t of this.expandedRows){const n=this.detailElements.get(t);if(n)e+=n.offsetHeight;else{const i=this.config?.detailHeight;e+=typeof i=="number"?i:150}}return e}getExtraHeightBefore(e){let t=0;for(const n of this.expandedRows){const i=this.rows.indexOf(n);if(i>=0&&i<e){const r=this.detailElements.get(n);if(r)t+=r.offsetHeight;else{const s=this.config?.detailHeight;t+=typeof s=="number"?s:150}}}return t}adjustVirtualStart(e,t,n){if(this.expandedRows.size===0)return e;const i=[];for(const l of this.expandedRows){const a=this.rows.indexOf(l);a>=0&&i.push({index:a,row:l})}i.sort((l,a)=>l.index-a.index);let r=e,s=0;for(const{index:l,row:a}of i){const c=l*n+s,h=this.detailElements.get(a)?.offsetHeight??(typeof this.config?.detailHeight=="number"?this.config.detailHeight:150),f=c+n+h;s+=h,!(l>=e)&&f>t&&l<r&&(r=l)}return r}expand(e){const t=this.rows[e];t&&(this.expandedRows=Qo(this.expandedRows,t),this.requestRender())}collapse(e){const t=this.rows[e];t&&(this.expandedRows=en(this.expandedRows,t),this.requestRender())}toggle(e){const t=this.rows[e];t&&(this.expandedRows=Re(this.expandedRows,t),this.requestRender())}isExpanded(e){const t=this.rows[e];return t?tn(this.expandedRows,t):!1}expandAll(){for(const e of this.rows)this.expandedRows.add(e);this.requestRender()}collapseAll(){this.expandedRows.clear(),this.requestRender()}getExpandedRows(){const e=[];for(const t of this.expandedRows){const n=this.rows.indexOf(t);n>=0&&e.push(n)}return e}getDetailElement(e){const t=this.rows[e];return t?this.detailElements.get(t):void 0}styles=nn}function sn(o,e,t){return e.length?[...o].sort((n,i)=>{for(const r of e){const l=t.find(h=>h.field===r.field)?.sortComparator??ln,a=n[r.field],c=i[r.field],d=l(a,c,n,i);if(d!==0)return r.direction==="asc"?d:-d}return 0}):[...o]}function ln(o,e){return o==null&&e==null?0:o==null?1:e==null?-1:typeof o=="number"&&typeof e=="number"?o-e:o instanceof Date&&e instanceof Date?o.getTime()-e.getTime():typeof o=="boolean"&&typeof e=="boolean"?o===e?0:o?-1:1:String(o).localeCompare(String(e))}function an(o,e,t,n){const i=o.find(r=>r.field===e);return t?i?i.direction==="asc"?o.map(r=>r.field===e?{...r,direction:"desc"}:r):o.filter(r=>r.field!==e):o.length<n?[...o,{field:e,direction:"asc"}]:o:i?.direction==="asc"?[{field:e,direction:"desc"}]:i?.direction==="desc"?[]:[{field:e,direction:"asc"}]}function st(o,e){const t=o.findIndex(n=>n.field===e);return t>=0?t+1:void 0}function lt(o,e){return o.find(t=>t.field===e)?.direction}const cn='.header-cell[data-sort=asc]:after{content:"↑";margin-left:4px;opacity:.8}.header-cell[data-sort=desc]:after{content:"↓";margin-left:4px;opacity:.8}.sort-index{font-size:10px;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:14px;height:14px;display:inline-flex;align-items:center;justify-content:center;margin-left:2px;font-weight:600}';class dn extends L{name="multiSort";version="1.0.0";get defaultConfig(){return{maxSortColumns:3,showSortIndex:!0}}sortModel=[];detach(){this.sortModel=[]}processRows(e){return this.sortModel.length===0?[...e]:sn([...e],this.sortModel,[...this.columns])}onHeaderClick(e){if(!this.columns.find(r=>r.field===e.field)?.sortable)return!1;const n=e.originalEvent.shiftKey,i=this.config.maxSortColumns??3;return this.sortModel=an(this.sortModel,e.field,n,i),this.emit("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),!0}afterRender(){const e=this.shadowRoot;if(!e)return;const t=this.config.showSortIndex!==!1;e.querySelectorAll(".header-row .cell[data-field]").forEach(i=>{const r=i.getAttribute("data-field");if(!r)return;const s=st(this.sortModel,r),l=lt(this.sortModel,r);if(i.querySelector(".sort-index")?.remove(),l){i.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove(),i.setAttribute("data-sort",l);const d=document.createElement("span");if(d.className="sort-indicator",d.style.marginLeft="4px",d.style.opacity="0.8",this.setIcon(d,this.resolveIcon(l==="asc"?"sortAsc":"sortDesc")),i.appendChild(d),t&&this.sortModel.length>1&&s!==void 0){const h=document.createElement("span");h.className="sort-index",h.textContent=String(s),i.appendChild(h)}}else i.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 st(this.sortModel,e)}getSortDirection(e){return lt(this.sortModel,e)}getColumnState(e){const t=this.sortModel.findIndex(i=>i.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(r=>r.field!==e);return}const n=this.sortModel.findIndex(r=>r.field===e),i={field:e,direction:t.sort.direction};n!==-1?this.sortModel[n]=i:this.sortModel.splice(t.sort.priority,0,i)}styles=cn}function un(o){return o.filter(e=>e.sticky==="left")}function hn(o){return o.filter(e=>e.sticky==="right")}function _e(o){return o.some(e=>e.sticky==="left"||e.sticky==="right")}function at(o,e){const t=o.shadowRoot;if(!t)return;const n=Array.from(t.querySelectorAll(".header-row .cell"));if(!n.length)return;const i=new Map;e.forEach((l,a)=>{l.field&&i.set(l.field,a)});let r=0;for(const l of e)if(l.sticky==="left"){const a=i.get(l.field),c=n.find(d=>d.getAttribute("data-field")===l.field);c&&(c.classList.add("sticky-left"),c.style.position="sticky",c.style.left=r+"px",a!==void 0&&t.querySelectorAll(`.data-grid-row .cell[data-col="${a}"]`).forEach(d=>{d.classList.add("sticky-left"),d.style.position="sticky",d.style.left=r+"px"}),r+=c.offsetWidth)}let s=0;for(const l of[...e].reverse())if(l.sticky==="right"){const a=i.get(l.field),c=n.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&&t.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 ct(o){const e=o.shadowRoot;if(!e)return;e.querySelectorAll(".sticky-left, .sticky-right").forEach(n=>{n.classList.remove("sticky-left","sticky-right"),n.style.position="",n.style.left="",n.style.right=""})}class fn extends L{name="pinnedColumns";version="1.0.0";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 n=t?.columns;return Array.isArray(n)?_e(n):!1}processColumns(e){return this.isApplied=_e([...e]),[...e]}afterRender(){if(!this.isApplied)return;const e=this.grid,t=[...this.columns];if(!_e(t)){ct(e),this.isApplied=!1;return}queueMicrotask(()=>{at(e,t)})}onPluginQuery(e){switch(e.type){case he.CAN_MOVE_COLUMN:{const t=e.context,n=t.sticky;if(n==="left"||n==="right")return!1;const i=t.meta?.sticky;return i==="left"||i==="right"?!1:void 0}default:return}}refreshStickyOffsets(){const e=[...this.columns];at(this.grid,e)}getLeftPinnedColumns(){const e=[...this.columns];return un(e)}getRightPinnedColumns(){const e=[...this.columns];return hn(e)}clearStickyPositions(){ct(this.grid)}getHorizontalScrollOffsets(e,t){if(!this.isApplied)return;let n=0,i=0;if(e){const s=e.querySelectorAll(".sticky-left"),l=e.querySelectorAll(".sticky-right");s.forEach(a=>{n+=a.offsetWidth}),l.forEach(a=>{i+=a.offsetWidth})}else{const l=this.grid.shadowRoot;l&&l.querySelectorAll(".header-row .cell").forEach(c=>{c.classList.contains("sticky-left")?n+=c.offsetWidth:c.classList.contains("sticky-right")&&(i+=c.offsetWidth)})}const r=t?.classList.contains("sticky-left")||t?.classList.contains("sticky-right");return{left:n,right:i,skipScroll:r}}}function Se(o,e){const t=document.createElement("div");t.className="tbw-pinned-rows",t.setAttribute("role","presentation"),t.setAttribute("aria-live","polite");const n=document.createElement("div");n.className="tbw-pinned-rows-left";const i=document.createElement("div");i.className="tbw-pinned-rows-center";const r=document.createElement("div");if(r.className="tbw-pinned-rows-right",o.showRowCount!==!1){const s=document.createElement("span");s.className="tbw-status-panel tbw-status-panel-row-count",s.textContent=`Total: ${e.totalRows} rows`,n.appendChild(s)}if(o.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}`,n.appendChild(s)}if(o.showSelectedCount&&e.selectedRows>0){const s=document.createElement("span");s.className="tbw-status-panel tbw-status-panel-selected-count",s.textContent=`Selected: ${e.selectedRows}`,r.appendChild(s)}if(o.customPanels)for(const s of o.customPanels){const l=pn(s,e);switch(s.position){case"left":n.appendChild(l);break;case"center":i.appendChild(l);break;case"right":r.appendChild(l);break}}return t.appendChild(n),t.appendChild(i),t.appendChild(r),t}function dt(o){const e=document.createElement("div");return e.className=`tbw-aggregation-rows tbw-aggregation-rows-${o}`,e.setAttribute("role","presentation"),e}function ut(o,e,t,n){o.innerHTML="";for(const i of e){const r=document.createElement("div");if(r.className="tbw-aggregation-row",r.setAttribute("role","presentation"),i.id&&r.setAttribute("data-aggregation-id",i.id),i.fullWidth){const s=document.createElement("div");s.className="tbw-aggregation-cell tbw-aggregation-cell-full",s.style.gridColumn="1 / -1",s.textContent=i.label||"",r.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;const c=i.aggregators?.[s.field];if(c){const d=Xe(c);d&&(a=d(n,s.field,s))}else if(i.cells&&Object.prototype.hasOwnProperty.call(i.cells,s.field)){const d=i.cells[s.field];typeof d=="function"?a=d(n,s.field,s):a=d}l.textContent=a!=null?String(a):"",r.appendChild(l)}o.appendChild(r)}}function pn(o,e){const t=document.createElement("div");t.className="tbw-status-panel tbw-status-panel-custom",t.id=`status-panel-${o.id}`;const n=o.render(e);return typeof n=="string"?t.innerHTML=n:t.appendChild(n),t}function ht(o,e,t,n,i){return{totalRows:o.length,filteredRows:i?.cachedResult?.length??o.length,selectedRows:n?.selected?.size??0,columns:e,rows:o,grid:t}}const gn=".tbw-footer{position:sticky;bottom: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:8px 12px;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:12px;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:16px}.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-weight:var(--tbw-aggregation-font-weight, 600)}.tbw-aggregation-cell{padding:var(--tbw-cell-padding, 2px 8px);min-height:var(--tbw-row-height, 28px);display:flex;align-items:center;border-right:1px solid var(--tbw-color-border-cell)}.tbw-aggregation-cell:last-child{border-right:0}.tbw-aggregation-cell-full{grid-column:1 / -1;border-right:0}";class wn extends L{name="pinnedRows";version="1.0.0";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.shadowRoot;if(!e)return;const t=e.querySelector(".tbw-scroll-area")??e.querySelector(".tbw-grid-content")??e.children[0];if(!t)return;const n=this.getSelectionState(),i=this.getFilterState(),r=ht(this.rows,this.columns,this.grid,n,i),s=this.config.aggregationRows||[],l=s.filter(f=>f.position==="top"),a=s.filter(f=>f.position!=="top");if(l.length>0){if(!this.topAggregationContainer){this.topAggregationContainer=dt("top");const f=e.querySelector(".header");f&&f.nextSibling?t.insertBefore(this.topAggregationContainer,f.nextSibling):t.appendChild(this.topAggregationContainer)}ut(this.topAggregationContainer,l,this.visibleColumns,this.rows)}else this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null);const c=this.config.showRowCount!==!1||this.config.showSelectedCount&&r.selectedRows>0||this.config.showFilteredCount&&r.filteredRows!==r.totalRows||this.config.customPanels&&this.config.customPanels.length>0,d=c&&this.config.position!=="top",h=a.length>0||d;if(c&&this.config.position==="top")if(!this.infoBarElement)this.infoBarElement=Se(this.config,r),t.insertBefore(this.infoBarElement,t.firstChild);else{const f=Se(this.config,r);this.infoBarElement.replaceWith(f),this.infoBarElement=f}else this.config.position==="top"&&this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null);h?(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=dt("bottom")),this.footerWrapper.appendChild(this.bottomAggregationContainer),ut(this.bottomAggregationContainer,a,this.visibleColumns,this.rows)),d&&(this.infoBarElement=Se(this.config,r),this.footerWrapper.appendChild(this.infoBarElement))):this.cleanupFooter()}cleanup(){this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null),this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null)}cleanupFooter(){this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.infoBarElement&&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 ht(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())}styles=gn}const bn=pe;function mn(o){const e=[];return!o.rowGroupFields?.length&&!o.columnGroupFields?.length&&e.push("At least one row or column group field is required"),o.valueFields?.length||e.push("At least one value field is required"),e}function Ae(o,e){return[...o,e].join("|")}function vn(o,e){const t=e.rowGroupFields??[],n=e.columnGroupFields??[],i=e.valueFields??[],r=Cn(o,n),s=ft(o,t,n,r,i,0,""),l=xn(s,r,i),a=Object.values(l).reduce((c,d)=>c+d,0);return{rows:s,columnKeys:r,totals:l,grandTotal:a}}function Cn(o,e){if(e.length===0)return["value"];const t=new Set;for(const n of o){const i=e.map(r=>String(n[r]??"")).join("|");t.add(i)}return[...t].sort()}function yn(o,e){const t=new Map;for(const n of o){const i=String(n[e]??""),r=t.get(i);r?r.push(n):t.set(i,[n])}return t}function ft(o,e,t,n,i,r,s){const l=[];if(e.length===0){const f=pt(o,t,n,i),u=gt(f);return l.push({rowKey:s||"all",rowLabel:s||"All",depth:r,values:f,total:u,isGroup:!1,rowCount:o.length}),l}const a=e[0],c=e.slice(1),d=c.length>0,h=yn(o,a);for(const[f,u]of h){const p=s?`${s}|${f}`:f,g=pt(u,t,n,i),w=gt(g);let b;d&&(b=ft(u,c,t,n,i,r+1,p)),l.push({rowKey:p,rowLabel:f||"(blank)",depth:r,values:g,total:w,isGroup:d,children:b,rowCount:u.length})}return l}function pt(o,e,t,n){const i={};for(const r of t)for(const s of n){const a=(e.length>0?o.filter(f=>e.map(u=>String(f[u]??"")).join("|")===r):o).map(f=>Number(f[s.field])||0),c=bn(s.aggFunc),d=a.length>0?c(a):null,h=Ae([r],s.field);i[h]=d}return i}function gt(o){let e=0;for(const t of Object.values(o))e+=t??0;return e}function xn(o,e,t){const n={};function i(r){for(const s of r)if(!s.isGroup||!s.children?.length)for(const l of e)for(const a of t){const c=Ae([l],a.field);n[c]=(n[c]??0)+(s.values[c]??0)}else s.children&&i(s.children)}return i(o),n}function En(o,e,t=!0){const n=[];function i(r){n.push(r);const s=e?e.has(r.rowKey):t;if(r.children&&s)for(const l of r.children)i(l)}for(const r of o)i(r);return n}function ke(o){const e=[];function t(n){if(n.isGroup&&e.push(n.rowKey),n.children)for(const i of n.children)t(i)}for(const n of o)t(n);return e}const Rn=["sum","avg","count","min","max","first","last"];function _n(o,e,t,n){const i=new AbortController,r={config:e,callbacks:n,signal:i.signal},s=document.createElement("div");return s.className="tbw-pivot-panel",s.appendChild(oe("Options",()=>Ln(t,r))),s.appendChild(oe("Row Groups",()=>wt("rowGroups",r))),s.appendChild(oe("Column Groups",()=>wt("columnGroups",r))),s.appendChild(oe("Values",()=>An(r))),s.appendChild(oe("Available Fields",()=>Tn(r))),o.appendChild(s),()=>{i.abort(),s.remove()}}function oe(o,e){const t=document.createElement("div");t.className="tbw-pivot-section";const n=document.createElement("div");n.className="tbw-pivot-section-header",n.textContent=o;const i=document.createElement("div");return i.className="tbw-pivot-section-content",i.appendChild(e()),t.appendChild(n),t.appendChild(i),t}function wt(o,e){const{config:t,callbacks:n,signal:i}=e,r=document.createElement("div");r.className="tbw-pivot-drop-zone",r.setAttribute("data-zone",o);const s=o==="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",r.appendChild(l)}else for(const l of s)r.appendChild(Sn(l,o,e));return r.addEventListener("dragover",l=>{l.preventDefault(),r.classList.add("drag-over")},{signal:i}),r.addEventListener("dragleave",()=>{r.classList.remove("drag-over")},{signal:i}),r.addEventListener("drop",l=>{l.preventDefault(),r.classList.remove("drag-over");const a=l.dataTransfer?.getData("text/plain");a&&n.onAddFieldToZone(a,o)},{signal:i}),r}function Sn(o,e,t){const{callbacks:n,signal:i}=t,r=document.createElement("div");r.className="tbw-pivot-field-chip",r.draggable=!0;const s=n.getAvailableFields().find(c=>c.field===o),l=document.createElement("span");l.className="tbw-pivot-chip-label",l.textContent=s?.header??o;const a=document.createElement("button");return a.className="tbw-pivot-chip-remove",a.innerHTML="×",a.title="Remove field",a.addEventListener("click",c=>{c.stopPropagation(),n.onRemoveFieldFromZone(o,e)},{signal:i}),r.appendChild(l),r.appendChild(a),r.addEventListener("dragstart",c=>{c.dataTransfer?.setData("text/plain",o),c.dataTransfer?.setData("source-zone",e),r.classList.add("dragging")},{signal:i}),r.addEventListener("dragend",()=>{r.classList.remove("dragging")},{signal:i}),r}function An(o){const{config:e,callbacks:t,signal:n}=o,i=document.createElement("div");i.className="tbw-pivot-drop-zone tbw-pivot-values-zone",i.setAttribute("data-zone","values");const r=e.valueFields??[];if(r.length===0){const s=document.createElement("div");s.className="tbw-pivot-placeholder",s.textContent="Drag numeric fields here for aggregation",i.appendChild(s)}else for(const s of r)i.appendChild(kn(s,o));return i.addEventListener("dragover",s=>{s.preventDefault(),i.classList.add("drag-over")},{signal:n}),i.addEventListener("dragleave",()=>{i.classList.remove("drag-over")},{signal:n}),i.addEventListener("drop",s=>{s.preventDefault(),i.classList.remove("drag-over");const l=s.dataTransfer?.getData("text/plain");l&&t.onAddValueField(l,"sum")},{signal:n}),i}function kn(o,e){const{callbacks:t,signal:n}=e,i=document.createElement("div");i.className="tbw-pivot-field-chip tbw-pivot-value-chip";const r=t.getAvailableFields().find(d=>d.field===o.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=r?.header??o.field;const a=document.createElement("select");a.className="tbw-pivot-agg-select",a.title="Aggregation function";for(const d of Rn){const h=document.createElement("option");h.value=d,h.textContent=d.toUpperCase(),h.selected=d===o.aggFunc,a.appendChild(h)}a.addEventListener("change",()=>{t.onUpdateValueAggFunc(o.field,a.value)},{signal:n});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(o.field)},{signal:n}),s.appendChild(l),s.appendChild(a),i.appendChild(s),i.appendChild(c),i}function Tn(o){const{config:e,callbacks:t,signal:n}=o,i=document.createElement("div");i.className="tbw-pivot-available-fields";const r=t.getAvailableFields(),s=new Set([...e.rowGroupFields??[],...e.columnGroupFields??[],...e.valueFields?.map(a=>a.field)??[]]),l=r.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",i.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:n}),c.addEventListener("dragend",()=>{c.classList.remove("dragging")},{signal:n}),i.appendChild(c)}return i}function Ln(o,e){const{config:t,callbacks:n,signal:i}=e,r=document.createElement("div");return r.className="tbw-pivot-options",r.appendChild(Te("Enable Pivot View",o,s=>{n.onTogglePivot(s)},i)),r.appendChild(Te("Show Row Totals",t.showTotals??!0,s=>{n.onOptionChange("showTotals",s)},i)),r.appendChild(Te("Show Grand Total",t.showGrandTotal??!0,s=>{n.onOptionChange("showGrandTotal",s)},i)),r}function Te(o,e,t,n){const i=document.createElement("label");i.className="tbw-pivot-checkbox";const r=document.createElement("input");r.type="checkbox",r.checked=e,r.addEventListener("change",()=>t(r.checked),{signal:n});const s=document.createElement("span");return s.textContent=o,i.appendChild(r),i.appendChild(s),i}function Pn(o,e,t){return e.className="pivot-group-row",e.setAttribute("data-pivot-depth",String(o.__pivotDepth??0)),e.setAttribute("role","row"),e.innerHTML="",t.columns.forEach((n,i)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(i)),r.setAttribute("role","gridcell"),i===0){const s=Number(o.__pivotIndent)||0;r.style.paddingLeft=`${s}px`;const l=String(o.__pivotRowKey),a=document.createElement("button");a.type="button",a.className="pivot-toggle",a.setAttribute("aria-label",o.__pivotExpanded?"Collapse group":"Expand group"),t.setIcon(a,t.resolveIcon(o.__pivotExpanded?"collapse":"expand")),a.addEventListener("click",h=>{h.stopPropagation(),t.onToggle(l)}),r.appendChild(a);const c=document.createElement("span");c.className="pivot-label",c.textContent=String(o.__pivotLabel??""),r.appendChild(c);const d=document.createElement("span");d.className="pivot-count",d.textContent=` (${Number(o.__pivotRowCount)||0})`,r.appendChild(d)}else{const s=o[n.field];r.textContent=s!=null?String(s):""}e.appendChild(r)}),!0}function Mn(o,e,t){return e.className="pivot-leaf-row",e.setAttribute("data-pivot-depth",String(o.__pivotDepth??0)),e.innerHTML="",t.forEach((n,i)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(i)),r.setAttribute("role","gridcell"),i===0){const s=Number(o.__pivotIndent)||0;r.style.paddingLeft=`${s+20}px`;const l=document.createElement("span");l.className="pivot-label",l.textContent=String(o.__pivotLabel??""),r.appendChild(l)}else{const s=o[n.field];r.textContent=s!=null?String(s):""}e.appendChild(r)}),!0}function In(o,e,t){return e.className="pivot-grand-total-row",e.setAttribute("role","presentation"),e.innerHTML="",t.forEach((n,i)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(i)),i===0){const s=document.createElement("span");s.className="pivot-label",s.textContent="Grand Total",r.appendChild(s)}else{const s=o[n.field];r.textContent=s!=null?String(s):""}e.appendChild(r)}),!0}const Hn='.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:18px;height:18px;margin-right:6px;border:none;background:transparent;cursor:pointer;font-size:10px;color:var(--tbw-pivot-toggle-color, var(--tbw-color-fg-muted));border-radius:var(--tbw-border-radius);transition:background .15s,color .15s}.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:12px;padding:12px;height:100%;overflow-y:auto;font-size:13px}.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:8px 12px;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:8px}.tbw-pivot-toggle-wrapper{display:flex;align-items:center}.tbw-pivot-toggle-label{display:flex;align-items:center;gap:8px;cursor:pointer}.tbw-pivot-toggle-label input{width:16px;height:16px;cursor:pointer}.tbw-pivot-drop-zone{min-height:60px;padding:8px;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:6px;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:8px;text-align:center;width:100%}.tbw-pivot-field-chip{display:inline-flex;align-items:center;gap:6px;padding:4px 8px;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:12px;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:16px;height:16px;padding:0;border:none;background:transparent;color:var(--tbw-color-fg-muted);font-size:14px;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:4px 8px}.tbw-pivot-value-label-wrapper{display:flex;align-items:center;gap:8px;flex:1;min-width:0}.tbw-pivot-agg-select{padding:2px 4px;font-size:11px;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:6px;min-height:40px}.tbw-pivot-options{display:flex;flex-direction:column;gap:8px}.tbw-pivot-checkbox{display:flex;align-items:center;gap:8px;cursor:pointer}.tbw-pivot-checkbox input{width:14px;height:14px;cursor:pointer}';class Y extends L{name="pivot";version="1.0.0";static PANEL_ID="pivot";get defaultConfig(){return{active:!0,showTotals:!0,showGrandTotal:!0}}isActive=!1;hasInitialized=!1;pivotResult=null;fieldHeaderMap=new Map;expandedKeys=new Set;defaultExpanded=!0;originalColumns=[];panelContainer=null;grandTotalFooter=null;hasValidPivotConfig(){return(this.config.valueFields?.length??0)>0}detach(){this.isActive=!1,this.hasInitialized=!1,this.pivotResult=null,this.fieldHeaderMap.clear(),this.originalColumns=[],this.panelContainer=null,this.cleanupGrandTotalFooter()}getToolPanel(){return{id:Y.PANEL_ID,title:"Pivot",icon:"⊞",tooltip:"Configure pivot table",order:90,render:e=>this.renderPanel(e)}}processRows(e){if(!this.hasInitialized&&this.config.active!==!1&&this.hasValidPivotConfig()&&(this.hasInitialized=!0,this.isActive=!0),!this.isActive)return[...e];const t=mn(this.config);if(t.length>0)return this.warn(`Config errors: ${t.join(", ")}`),[...e];if(this.buildFieldHeaderMap(),this.defaultExpanded=this.config.defaultExpanded??!0,this.expandedKeys.size===0&&this.defaultExpanded&&this.pivotResult){const r=ke(this.pivotResult.rows);for(const s of r)this.expandedKeys.add(s)}if(this.pivotResult=vn(e,this.config),this.expandedKeys.size===0&&this.defaultExpanded){const r=ke(this.pivotResult.rows);for(const s of r)this.expandedKeys.add(s)}const n=this.config.indentWidth??20;return En(this.pivotResult.rows,this.expandedKeys,this.defaultExpanded).map(r=>({__pivotRowKey:r.rowKey,__pivotLabel:r.rowLabel,__pivotDepth:r.depth,__pivotIsGroup:r.isGroup,__pivotHasChildren:!!r.children?.length,__pivotExpanded:this.expandedKeys.has(r.rowKey),__pivotRowCount:r.rowCount??0,__pivotIndent:r.depth*n,__pivotTotal:r.total,...r.values}))}processColumns(e){if(!this.isActive||!this.pivotResult)return[...e];const t=[],n=(this.config.rowGroupFields??[]).map(i=>this.fieldHeaderMap.get(i)??i).join(" / ");t.push({field:"__pivotLabel",header:n||"Group",width:200});for(const i of this.pivotResult.columnKeys)for(const r of this.config.valueFields??[]){const s=Ae([i],r.field),l=r.header||this.fieldHeaderMap.get(r.field)||r.field;t.push({field:s,header:`${i} - ${l} (${r.aggFunc})`,width:120,type:"number"})}return this.config.showTotals&&t.push({field:"__pivotTotal",header:"Total",width:100,type:"number"}),t}renderRow(e,t){const n=e;return n.__pivotRowKey&&n.__pivotHasChildren?Pn(n,t,{columns:this.gridColumns,onToggle:i=>this.toggle(i),resolveIcon:i=>this.resolveIcon(i),setIcon:(i,r)=>this.setIcon(i,r)}):n.__pivotRowKey!==void 0&&this.isActive?Mn(n,t,this.gridColumns):(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="")}afterRender(){this.isActive&&this.config.showGrandTotal&&this.pivotResult?this.renderGrandTotalFooter():this.cleanupGrandTotalFooter()}renderGrandTotalFooter(){if(!this.pivotResult)return;const e=this.shadowRoot;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 n={__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals};In(n,this.grandTotalFooter,this.gridColumns)}cleanupGrandTotalFooter(){this.grandTotalFooter&&(this.grandTotalFooter.remove(),this.grandTotalFooter=null)}toggle(e){this.expandedKeys.has(e)?this.expandedKeys.delete(e):this.expandedKeys.add(e),this.requestRender()}expand(e){this.expandedKeys.add(e),this.requestRender()}collapse(e){this.expandedKeys.delete(e),this.requestRender()}expandAll(){if(this.pivotResult){const e=ke(this.pivotResult.rows);for(const t of e)this.expandedKeys.add(t);this.requestRender()}}collapseAll(){this.expandedKeys.clear(),this.requestRender()}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(Y.PANEL_ID)}hidePanel(){this.grid.closeToolPanel()}togglePanel(){this.grid.toggleToolPanel(Y.PANEL_ID)}isPanelVisible(){return this.grid.activeToolPanel===Y.PANEL_ID}get gridColumns(){return this.grid.columns??[]}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(){const e=this.grid;try{const t=e.getAllColumns?.()??e.columns??[];return this.originalColumns=t.filter(n=>!n.field.startsWith("__pivot")).map(n=>({field:n.field,header:n.header??n.field})),this.originalColumns}catch{return[]}}renderPanel(e){this.panelContainer=e,this.originalColumns.length===0&&this.captureOriginalColumns();const t={onTogglePivot:n=>{n?this.enablePivot():this.disablePivot(),this.refreshPanel()},onAddFieldToZone:(n,i)=>this.addFieldToZone(n,i),onRemoveFieldFromZone:(n,i)=>this.removeFieldFromZone(n,i),onAddValueField:(n,i)=>this.addValueField(n,i),onRemoveValueField:n=>this.removeValueField(n),onUpdateValueAggFunc:(n,i)=>this.updateValueAggFunc(n,i),onOptionChange:(n,i)=>{this.config[n]=i,this.isActive&&this.refresh()},getAvailableFields:()=>this.getAvailableFields()};return _n(e,this.config,this.isActive,t)}refreshPanel(){this.panelContainer&&(this.panelContainer.innerHTML="",this.renderPanel(this.panelContainer))}addFieldToZone(e,t){if(t==="rowGroups"){const n=this.config.rowGroupFields??[];n.includes(e)||(this.config.rowGroupFields=[...n,e])}else{const n=this.config.columnGroupFields??[];n.includes(e)||(this.config.columnGroupFields=[...n,e])}this.removeFromOtherZones(e,t),this.isActive&&this.refresh(),this.refreshPanel()}removeFieldFromZone(e,t){t==="rowGroups"?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(n=>n!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(n=>n!==e),this.isActive&&this.refresh(),this.refreshPanel()}removeFromOtherZones(e,t){t!=="rowGroups"&&(this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(n=>n!==e)),t!=="columnGroups"&&(this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(n=>n!==e)),t!=="values"&&(this.config.valueFields=(this.config.valueFields??[]).filter(n=>n.field!==e))}addValueField(e,t){const n=this.config.valueFields??[];n.some(i=>i.field===e)||(this.config.valueFields=[...n,{field:e,aggFunc:t}]),this.removeFromOtherZones(e,"values"),this.isActive&&this.refresh(),this.refreshPanel()}removeValueField(e){this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e),this.isActive&&this.refresh(),this.refreshPanel()}updateValueAggFunc(e,t){const n=this.config.valueFields??[],i=n.findIndex(r=>r.field===e);i>=0&&(n[i]={...n[i],aggFunc:t},this.config.valueFields=[...n]),this.isActive&&this.refresh()}styles=Hn}function Nn(o){const e=o.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}function bt(o,e,t){if(e===t||e<0||e>=o.length||t<0||t>o.length)return o;const n=[...o],[i]=n.splice(e,1);return n.splice(t,0,i),n}const On='.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}';class Dn extends L{name="reorder";version="1.0.0";get defaultConfig(){return{animation:!0,animationDuration:200}}isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;attach(e){super.attach(e),e.addEventListener("column-reorder-request",t=>{const n=t.detail;n?.field&&typeof n.toIndex=="number"&&this.moveColumn(n.field,n.toIndex)},{signal:this.disconnectSignal})}detach(){this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null}afterRender(){const e=this.shadowRoot;if(!e)return;e.querySelectorAll(".header-row > .cell").forEach(n=>{const i=n,r=i.getAttribute("data-field");if(!r)return;const s=this.columns.find(d=>d.field===r),c=!this.grid.queryPlugins({type:he.CAN_MOVE_COLUMN,context:s}).includes(!1);if(!s||!Nn(s)||!c){i.draggable=!1;return}i.draggable=!0,!i.getAttribute("data-dragstart-bound")&&(i.setAttribute("data-dragstart-bound","true"),i.addEventListener("dragstart",d=>{const f=this.getColumnOrder().indexOf(r);this.isDragging=!0,this.draggedField=r,this.draggedIndex=f,d.dataTransfer&&(d.dataTransfer.effectAllowed="move",d.dataTransfer.setData("text/plain",r)),i.classList.add("dragging")}),i.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,e.querySelectorAll(".header-row > .cell").forEach(d=>{d.classList.remove("dragging","drop-target","drop-before","drop-after")})}),i.addEventListener("dragover",d=>{if(d.preventDefault(),!this.isDragging||this.draggedField===r)return;const h=i.getBoundingClientRect(),f=h.left+h.width/2,p=this.getColumnOrder().indexOf(r);this.dropIndex=d.clientX<f?p:p+1,i.classList.add("drop-target"),i.classList.toggle("drop-before",d.clientX<f),i.classList.toggle("drop-after",d.clientX>=f)}),i.addEventListener("dragleave",()=>{i.classList.remove("drop-target","drop-before","drop-after")}),i.addEventListener("drop",d=>{d.preventDefault();const h=this.draggedField,f=this.draggedIndex,u=this.dropIndex;if(!this.isDragging||h===null||f===null||u===null)return;const p=u>f?u-1:u,g=this.getColumnOrder(),w=bt(g,f,p),b={field:h,fromIndex:f,toIndex:p,columnOrder:w};this.grid.setColumnOrder(w),this.emit("column-move",b),this.grid.requestStateChange?.()}))})}getColumnOrder(){return this.grid.getColumnOrder()}moveColumn(e,t){const n=this.getColumnOrder(),i=n.indexOf(e);if(i===-1)return;const r=bt(n,i,t);this.grid.setColumnOrder(r),this.emit("column-move",{field:e,fromIndex:i,toIndex:t,columnOrder:r}),this.grid.requestStateChange?.()}setColumnOrder(e){this.grid.setColumnOrder(e),this.grid.requestStateChange?.()}resetColumnOrder(){const e=this.columns.map(t=>t.field);this.grid.setColumnOrder(e),this.grid.requestStateChange?.()}styles=On}function ie(o){return{startRow:Math.min(o.startRow,o.endRow),startCol:Math.min(o.startCol,o.endCol),endRow:Math.max(o.startRow,o.endRow),endCol:Math.max(o.startCol,o.endCol)}}function zn(o){const e=ie(o);return{from:{row:e.startRow,col:e.startCol},to:{row:e.endRow,col:e.endCol}}}function Le(o){return o.map(zn)}function qn(o,e,t){const n=ie(t);return o>=n.startRow&&o<=n.endRow&&e>=n.startCol&&e<=n.endCol}function mt(o,e,t){return t.some(n=>qn(o,e,n))}function Fn(o){const e=[],t=ie(o);for(let n=t.startRow;n<=t.endRow;n++)for(let i=t.startCol;i<=t.endCol;i++)e.push({row:n,col:i});return e}function Bn(o){const e=new Map;for(const t of o)for(const n of Fn(t))e.set(`${n.row},${n.col}`,n);return[...e.values()]}function Pe(o,e){return{startRow:o.row,startCol:o.col,endRow:e.row,endCol:e.col}}const $n=':host .selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}:host .data-grid-row.row-focus{background-color:var(--tbw-focus-background, rgba(from var(--tbw-color-accent) r g b / 12%))}:host([data-selection-mode="row"]) .cell-focus{outline:none}:host .data-grid-row>.cell.selected{background-color:var(--tbw-range-selection-bg)}:host .data-grid-row>.cell.selected.top{border-top:2px solid var(--tbw-range-border-color)}:host .data-grid-row>.cell.selected.bottom{border-bottom:2px solid var(--tbw-range-border-color)}:host .data-grid-row>.cell.selected.first{border-left:2px solid var(--tbw-range-border-color)}:host .data-grid-row>.cell.selected.last{border-right:2px solid var(--tbw-range-border-color)}';function Gn(o,e,t){if(o==="cell"&&e.selectedCell)return{mode:o,ranges:[{from:{row:e.selectedCell.row,col:e.selectedCell.col},to:{row:e.selectedCell.row,col:e.selectedCell.col}}]};if(o==="row"&&e.selected.size>0){const n=[...e.selected].map(i=>({from:{row:i,col:0},to:{row:i,col:t-1}}));return{mode:o,ranges:n}}return o==="range"&&e.ranges.length>0?{mode:o,ranges:Le(e.ranges)}:{mode:o,ranges:[]}}class Kn extends L{name="selection";version="1.0.0";get defaultConfig(){return{mode:"cell"}}selected=new Set;lastSelected=null;anchor=null;ranges=[];activeRange=null;cellAnchor=null;isDragging=!1;selectedCell=null;detach(){this.selected.clear(),this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.isDragging=!1,this.selectedCell=null}onCellClick(e){const{rowIndex:t,colIndex:n,originalEvent:i}=e,{mode:r}=this.config;if(r==="cell")return this.selectedCell={row:t,col:n},this.emit("selection-change",this.#r()),this.requestAfterRender(),!1;if(r==="row")return this.selected.clear(),this.selected.add(t),this.lastSelected=t,this.emit("selection-change",this.#r()),this.requestAfterRender(),!1;if(r==="range"){const s=i.shiftKey,l=i.ctrlKey||i.metaKey;if(s&&this.cellAnchor){const a=Pe(this.cellAnchor,{row:t,col:n});l?this.ranges.length>0?this.ranges[this.ranges.length-1]=a:this.ranges.push(a):this.ranges=[a],this.activeRange=a}else if(l){const a={startRow:t,startCol:n,endRow:t,endCol:n};this.ranges.push(a),this.activeRange=a,this.cellAnchor={row:t,col:n}}else{const a={startRow:t,startCol:n,endRow:t,endCol:n};this.ranges=[a],this.activeRange=a,this.cellAnchor={row:t,col:n}}return this.emit("selection-change",this.#r()),this.requestAfterRender(),!1}return!1}onKeyDown(e){const{mode:t}=this.config,i=["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.#r()),this.requestAfterRender(),!0;if(t==="cell"&&i)return queueMicrotask(()=>{this.selectedCell={row:this.grid.focusRow,col:this.grid.focusCol},this.emit("selection-change",this.#r()),this.requestAfterRender()}),!1;if(t==="row"&&(e.key==="ArrowUp"||e.key==="ArrowDown"))return queueMicrotask(()=>{this.selected.clear(),this.selected.add(this.grid.focusRow),this.lastSelected=this.grid.focusRow,this.emit("selection-change",this.#r()),this.requestAfterRender()}),!1;if(t==="range"&&i){const r=e.shiftKey;return queueMicrotask(()=>{const s=this.grid.focusRow,l=this.grid.focusCol;if(r){this.cellAnchor||(this.cellAnchor={row:s,col:l});const a=Pe(this.cellAnchor,{row:s,col:l});this.ranges=[a],this.activeRange=a}else this.ranges=[],this.activeRange=null,this.cellAnchor={row:s,col:l};this.emit("selection-change",this.#r()),this.requestAfterRender()}),!1}if(t==="range"&&e.key==="a"&&(e.ctrlKey||e.metaKey)){const r=this.rows.length,s=this.columns.length;if(r>0&&s>0){const l={startRow:0,startCol:0,endRow:r-1,endCol:s-1};return this.ranges=[l],this.activeRange=l,this.emit("selection-change",this.#r()),this.requestAfterRender(),!0}}return!1}onCellMouseDown(e){if(this.config.mode!=="range"||e.rowIndex===void 0||e.colIndex===void 0||e.rowIndex<0||e.originalEvent.shiftKey&&this.cellAnchor)return;this.isDragging=!0;const t=e.rowIndex,n=e.colIndex;this.cellAnchor={row:t,col:n},e.originalEvent.ctrlKey||e.originalEvent.metaKey||(this.ranges=[]);const r={startRow:t,startCol:n,endRow:t,endCol:n};return this.ranges.push(r),this.activeRange=r,this.emit("selection-change",this.#r()),this.requestAfterRender(),!0}onCellMouseMove(e){if(this.config.mode!=="range"||!this.isDragging||!this.cellAnchor||e.rowIndex===void 0||e.colIndex===void 0||e.rowIndex<0)return;const t=Pe(this.cellAnchor,{row:e.rowIndex,col:e.colIndex});return this.ranges.length>0?this.ranges[this.ranges.length-1]=t:this.ranges.push(t),this.activeRange=t,this.emit("selection-change",this.#r()),this.requestAfterRender(),!0}onCellMouseUp(e){if(this.config.mode==="range"&&this.isDragging)return this.isDragging=!1,!0}#o(){const e=this.shadowRoot;if(!e)return;const{mode:t}=this.config;e.querySelectorAll(".cell").forEach(r=>{r.classList.remove("selected","top","bottom","first","last")});const i=e.querySelectorAll(".data-grid-row");if(i.forEach(r=>{r.classList.remove("selected","row-focus")}),t==="row"&&(e.querySelectorAll(".cell-focus").forEach(r=>r.classList.remove("cell-focus")),i.forEach(r=>{const s=r.querySelector(".cell[data-row]"),l=parseInt(s?.getAttribute("data-row")??"-1",10);l>=0&&this.selected.has(l)&&r.classList.add("selected","row-focus")})),t==="range"&&this.ranges.length>0){const r=this.activeRange?ie(this.activeRange):null;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&&mt(a,c,this.ranges)&&(l.classList.add("selected"),l.classList.remove("cell-focus"),r&&(a===r.startRow&&l.classList.add("top"),a===r.endRow&&l.classList.add("bottom"),c===r.startCol&&l.classList.add("first"),c===r.endCol&&l.classList.add("last")))})}t==="cell"&&this.selectedCell&&e.querySelectorAll(".cell-focus").forEach(r=>r.classList.remove("cell-focus"))}afterRender(){const e=this.shadowRoot;if(!e)return;const t=e.children[0],{mode:n}=this.config;this.grid.setAttribute("data-selection-mode",n),t&&t.classList.toggle("selecting",this.isDragging),this.#o()}onScrollRender(){this.#o()}getSelectedCell(){return this.selectedCell}getSelectedRows(){return[...this.selected]}getRanges(){return Le(this.ranges)}getSelectedCells(){return Bn(this.ranges)}isCellSelected(e,t){return mt(e,t,this.ranges)}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:Le(this.ranges)}),this.requestAfterRender()}#r(){return Gn(this.config.mode,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges},this.columns.length)}styles=$n}function re(o,e){return Math.floor(o/e)}function Vn(o,e){return{start:o*e,end:(o+1)*e}}function Wn(o,e,t){const n=re(o,t),i=re(e-1,t),r=[];for(let s=n;s<=i;s++)r.push(s);return r}async function vt(o,e,t,n){const i=Vn(e,t);return o.getRows({startRow:i.start,endRow:i.end,sortModel:n.sortModel,filterModel:n.filterModel})}function jn(o,e,t){const n=re(o,e),i=t.get(n);if(!i)return;const r=o%e;return i[r]}const Un=100;class Xn extends L{name="serverSide";version="1.0.0";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,n={startRow:e.virtualization.start,endRow:e.virtualization.end},i=Wn(n.startRow,n.endRow,t);for(const r of i)if(!(this.loadedBlocks.has(r)||this.loadingBlocks.has(r))){if(this.loadingBlocks.size>=(this.config.maxConcurrentRequests??2))break;this.loadingBlocks.add(r),vt(this.dataSource,r,t,{}).then(s=>{this.loadedBlocks.set(r,s.rows),this.totalRowCount=s.totalRowCount,this.loadingBlocks.delete(r),this.requestRender(),this.loadRequiredBlocks()}).catch(()=>{this.loadingBlocks.delete(r)})}}processRows(e){if(!this.dataSource)return[...e];const t=[];for(let n=0;n<this.totalRowCount;n++){const i=jn(n,this.config.cacheBlockSize??100,this.loadedBlocks);t.push(i??{__loading:!0,__index:n})}return t}onScroll(e){this.dataSource&&(this.loadRequiredBlocks(),this.scrollDebounceTimer&&clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=setTimeout(()=>{this.loadRequiredBlocks()},Un))}setDataSource(e){this.dataSource=e,this.loadedBlocks.clear(),this.loadingBlocks.clear();const t=this.config.cacheBlockSize??100;vt(e,0,t,{}).then(n=>{this.loadedBlocks.set(0,n.rows),this.totalRowCount=n.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,n=re(e,t);return this.loadedBlocks.has(n)}getLoadedBlockCount(){return this.loadedBlocks.size}}function Me(o,e,t){return o.id!==void 0?String(o.id):t?`${t}-${e}`:String(e)}function Ct(o,e,t,n=null,i=0){const r=e.childrenField??"children",s=[];for(let l=0;l<o.length;l++){const a=o[l],c=Me(a,l,n),d=a[r],h=Array.isArray(d)&&d.length>0,f=t.has(c);if(s.push({key:c,data:a,depth:i,hasChildren:h,isExpanded:f,parentKey:n}),h&&f){const u=Ct(d,e,t,c,i+1);s.push(...u)}}return s}function yt(o,e){const t=new Set(o);return t.has(e)?t.delete(e):t.add(e),t}function Ie(o,e,t=null,n=0){const i=e.childrenField??"children",r=new Set;for(let s=0;s<o.length;s++){const l=o[s],a=Me(l,s,t),c=l[i];if(Array.isArray(c)&&c.length>0){r.add(a);const d=Ie(c,e,a,n+1);for(const h of d)r.add(h)}}return r}function Yn(){return new Set}function xt(o,e,t,n=null,i=0){const r=t.childrenField??"children";for(let s=0;s<o.length;s++){const l=o[s],a=Me(l,s,n);if(a===e)return[a];const c=l[r];if(Array.isArray(c)&&c.length>0){const d=xt(c,e,t,a,i+1);if(d)return[a,...d]}}return null}function Zn(o,e,t,n){const i=xt(o,e,t);if(!i)return n;const r=new Set(n);for(let s=0;s<i.length-1;s++)r.add(i[s]);return r}function Et(o,e="children"){if(!Array.isArray(o)||o.length===0)return!1;for(const t of o)if(t&&Array.isArray(t[e])&&t[e].length>0)return!0;return!1}function Jn(o){if(!Array.isArray(o)||o.length===0)return null;const e=["children","items","nodes","subRows","nested"];for(const t of o)if(!(!t||typeof t!="object")){for(const n of e)if(Array.isArray(t[n])&&t[n].length>0)return n}return null}const Qn=".tree-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;transition:transform .2s}.tree-toggle:hover{color:var(--tbw-tree-accent, var(--tbw-color-accent))}";class ei extends L{name="tree";version="1.0.0";get defaultConfig(){return{childrenField:"children",autoDetect:!0,defaultExpanded:!1,indentWidth:20,showExpandIcons:!0}}expandedKeys=new Set;initialExpansionDone=!1;flattenedRows=[];rowKeyMap=new Map;detach(){this.expandedKeys.clear(),this.initialExpansionDone=!1,this.flattenedRows=[],this.rowKeyMap.clear()}detect(e){if(!this.config.autoDetect)return!1;const t=this.config.childrenField??Jn(e)??"children";return Et(e,t)}processRows(e){const t=this.config.childrenField??"children";if(!Et(e,t))return this.flattenedRows=[],this.rowKeyMap.clear(),[...e];this.config.defaultExpanded&&!this.initialExpansionDone&&(this.expandedKeys=Ie(e,this.config),this.initialExpansionDone=!0),this.flattenedRows=Ct(e,this.config,this.expandedKeys),this.rowKeyMap.clear();for(const n of this.flattenedRows)this.rowKeyMap.set(n.key,n);return this.flattenedRows.map(n=>({...n.data,__treeKey:n.key,__treeDepth:n.depth,__treeHasChildren:n.hasChildren,__treeExpanded:n.isExpanded}))}processColumns(e){if(this.flattenedRows.length===0)return[...e];const t=this.config.indentWidth??20,n=this.config.showExpandIcons??!0,i=[...e];if(i.length>0){const r={...i[0]},s=r.viewRenderer;if(s?.__treeWrapped)return i;const l=a=>{const{value:c,row:d,column:h}=a,f=d.__treeDepth??0,u=d.__treeHasChildren??!1,p=d.__treeExpanded??!1,g=document.createElement("span");if(g.style.display="flex",g.style.alignItems="center",g.style.paddingLeft=`${f*t}px`,u&&n){const b=document.createElement("span");b.className="tree-toggle",this.setIcon(b,this.resolveIcon(p?"collapse":"expand")),b.style.cursor="pointer",b.style.marginRight="4px",b.style.fontSize="10px",b.setAttribute("data-tree-key",d.__treeKey),g.appendChild(b)}else if(n){const b=document.createElement("span");b.style.width="14px",b.style.display="inline-block",g.appendChild(b)}const w=document.createElement("span");if(s){const b=s(a);b instanceof Node?w.appendChild(b):w.textContent=String(b??c??"")}else w.textContent=String(c??"");return g.appendChild(w),g};l.__treeWrapped=!0,r.viewRenderer=l,i[0]=r}return i}onCellClick(e){const t=e.originalEvent?.target;if(!t?.classList.contains("tree-toggle"))return!1;const n=t.getAttribute("data-tree-key");if(!n)return!1;const i=this.rowKeyMap.get(n);return i?(this.expandedKeys=yt(this.expandedKeys,n),this.emit("tree-expand",{key:n,row:i.data,expanded:this.expandedKeys.has(n),depth:i.depth}),this.requestRender(),!0):!1}expand(e){this.expandedKeys.add(e),this.requestRender()}collapse(e){this.expandedKeys.delete(e),this.requestRender()}toggle(e){this.expandedKeys=yt(this.expandedKeys,e),this.requestRender()}expandAll(){this.expandedKeys=Ie(this.rows,this.config),this.requestRender()}collapseAll(){this.expandedKeys=Yn(),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=Zn(this.rows,e,this.config,this.expandedKeys),this.requestRender()}styles=Qn}function ti(o,e,t){const n=[...o.undoStack,e];for(;n.length>t;)n.shift();return{undoStack:n,redoStack:[]}}function Rt(o){if(o.undoStack.length===0)return{newState:o,action:null};const e=[...o.undoStack],t=e.pop();return t?{newState:{undoStack:e,redoStack:[...o.redoStack,t]},action:t}:{newState:o,action:null}}function _t(o){if(o.redoStack.length===0)return{newState:o,action:null};const e=[...o.redoStack],t=e.pop();return t?{newState:{undoStack:[...o.undoStack,t],redoStack:e},action:t}:{newState:o,action:null}}function oi(o){return o.undoStack.length>0}function ni(o){return o.redoStack.length>0}function ii(){return{undoStack:[],redoStack:[]}}function ri(o,e,t,n){return{type:"cell-edit",rowIndex:o,field:e,oldValue:t,newValue:n,timestamp:Date.now()}}class si extends L{name="undoRedo";version="1.0.0";get defaultConfig(){return{maxHistorySize:100}}undoStack=[];redoStack=[];detach(){this.undoStack=[],this.redoStack=[]}onKeyDown(e){const t=(e.ctrlKey||e.metaKey)&&e.key==="z"&&!e.shiftKey,n=(e.ctrlKey||e.metaKey)&&(e.key==="y"||e.key==="z"&&e.shiftKey);if(t){const i=Rt({undoStack:this.undoStack,redoStack:this.redoStack});if(i.action){const r=this.rows;r[i.action.rowIndex]&&(r[i.action.rowIndex][i.action.field]=i.action.oldValue),this.undoStack=i.newState.undoStack,this.redoStack=i.newState.redoStack,this.emit("undo",{action:i.action,type:"undo"}),this.requestRender()}return!0}if(n){const i=_t({undoStack:this.undoStack,redoStack:this.redoStack});if(i.action){const r=this.rows;r[i.action.rowIndex]&&(r[i.action.rowIndex][i.action.field]=i.action.newValue),this.undoStack=i.newState.undoStack,this.redoStack=i.newState.redoStack,this.emit("redo",{action:i.action,type:"redo"}),this.requestRender()}return!0}return!1}recordEdit(e,t,n,i){const r=ri(e,t,n,i),s=ti({undoStack:this.undoStack,redoStack:this.redoStack},r,this.config.maxHistorySize??100);this.undoStack=s.undoStack,this.redoStack=s.redoStack}undo(){const e=Rt({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=_t({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 oi({undoStack:this.undoStack,redoStack:this.redoStack})}canRedo(){return ni({undoStack:this.undoStack,redoStack:this.redoStack})}clearHistory(){const e=ii();this.undoStack=e.undoStack,this.redoStack=e.redoStack}getUndoStack(){return[...this.undoStack]}getRedoStack(){return[...this.redoStack]}}const li='.tbw-visibility-content{display:flex;flex-direction:column;height:100%}.tbw-visibility-list{flex:1;overflow-y:auto;padding:8px}.tbw-visibility-row{display:flex;align-items:center;gap:8px;padding:6px 4px;cursor:pointer;font-size:13px;border-radius:var(--tbw-border-radius, 4px);position:relative}.tbw-visibility-row:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover, #f3f4f6))}.tbw-visibility-row input[type=checkbox]{cursor:pointer}.tbw-visibility-row.locked span{color:var(--tbw-color-fg-muted, #888)}.tbw-visibility-handle{cursor:grab;color:var(--tbw-color-fg-muted, #888);font-size:10px;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, #1f2937)}.tbw-visibility-label{display:flex;align-items:center;gap:8px;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-reorder-indicator, var(--tbw-color-accent, #3b82f6))}.tbw-visibility-row.drop-after:after{content:"";position:absolute;left:0;right:0;bottom:0;height:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent, #3b82f6))}.tbw-visibility-show-all{margin:8px;padding:8px 12px;border:1px solid var(--tbw-visibility-border, var(--tbw-color-border, #e5e7eb));border-radius:var(--tbw-border-radius, 4px);background:var(--tbw-visibility-btn-bg, var(--tbw-color-header-bg, #f9fafb));color:var(--tbw-color-fg, #1f2937);cursor:pointer;font-size:13px}.tbw-visibility-show-all:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover, #f3f4f6))}';function St(o){const e=o.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}class Z extends L{name="visibility";version="1.0.0";static PANEL_ID="columns";get defaultConfig(){return{allowHideAll:!1}}columnListElement=null;isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;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(Z.PANEL_ID)}hide(){this.grid.closeToolPanel()}toggle(){this.grid.toggleToolPanel(Z.PANEL_ID)}isColumnVisible(e){return this.grid.isColumnVisible(e)}setColumnVisible(e,t){this.grid.setColumnVisible(e,t)}getVisibleColumns(){return this.grid.getAllColumns().filter(t=>t.visible).map(t=>t.field)}getHiddenColumns(){return this.grid.getAllColumns().filter(t=>!t.visible).map(t=>t.field)}showAll(){this.grid.showAllColumns()}toggleColumn(e){this.grid.toggleColumnVisibility(e)}showColumn(e){this.grid.setColumnVisible(e,!0)}hideColumn(e){this.grid.setColumnVisible(e,!1)}getAllColumns(){return this.grid.getAllColumns()}isPanelVisible(){return this.grid.activeToolPanel===Z.PANEL_ID}renderPanelContent(e){const t=this.grid,n=document.createElement("div");n.className="tbw-visibility-content";const i=document.createElement("div");i.className="tbw-visibility-list",n.appendChild(i);const r=document.createElement("button");return r.className="tbw-visibility-show-all",r.textContent="Show All",r.addEventListener("click",()=>{t.showAllColumns(),this.rebuildToggles(i)}),n.appendChild(r),this.columnListElement=i,this.rebuildToggles(i),e.appendChild(n),()=>{this.columnListElement=null,n.remove()}}hasReorderPlugin(){const e=this.grid?.getPluginByName?.("reorder");return!!(e&&typeof e.moveColumn=="function")}rebuildToggles(e){const t=this.grid,n=this.hasReorderPlugin();e.innerHTML="";const i=t.getAllColumns();for(let r=0;r<i.length;r++){const s=i[r],l=s.header||s.field,a=document.createElement("div");a.className=s.lockVisible?"tbw-visibility-row locked":"tbw-visibility-row",a.setAttribute("data-field",s.field),a.setAttribute("data-index",String(r)),n&&St(s)&&(a.draggable=!0,a.classList.add("reorderable"),this.setupDragListeners(a,s.field,r,e));const c=document.createElement("label");c.className="tbw-visibility-label";const d=document.createElement("input");d.type="checkbox",d.checked=s.visible,d.disabled=s.lockVisible??!1,d.addEventListener("change",()=>{t.toggleColumnVisibility(s.field),setTimeout(()=>this.rebuildToggles(e),0)});const h=document.createElement("span");if(h.textContent=l,c.appendChild(d),c.appendChild(h),n&&St(s)){const f=document.createElement("span");f.className="tbw-visibility-handle",this.setIcon(f,this.resolveIcon("dragHandle")),f.title="Drag to reorder",a.appendChild(f)}a.appendChild(c),e.appendChild(a)}}setupDragListeners(e,t,n,i){e.addEventListener("dragstart",r=>{this.isDragging=!0,this.draggedField=t,this.draggedIndex=n,r.dataTransfer&&(r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",t)),e.classList.add("dragging")}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,i.querySelectorAll(".tbw-visibility-row").forEach(r=>{r.classList.remove("dragging","drop-target","drop-before","drop-after")})}),e.addEventListener("dragover",r=>{if(r.preventDefault(),!this.isDragging||this.draggedField===t)return;const s=e.getBoundingClientRect(),l=s.top+s.height/2;this.dropIndex=r.clientY<l?n:n+1,i.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",r.clientY<l),e.classList.toggle("drop-after",r.clientY>=l)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",r=>{r.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={field:s,fromIndex:l,toIndex:c};this.emit("column-reorder-request",d),setTimeout(()=>{this.rebuildToggles(i)},0)}})}styles=li}y.BaseGridPlugin=L,y.ClipboardPlugin=Co,y.ColumnVirtualizationPlugin=Ro,y.ContextMenuPlugin=Ao,y.DEFAULT_GRID_ICONS=I,y.DGEvents=fo,y.DataGridElement=$,y.ExportPlugin=Mo,y.FilteringPlugin=F,y.FitModeEnum=G,y.GridCSSVars=ho,y.GridClasses=M,y.GridDataAttrs=ee,y.GridElement=$,y.GridSelectors=uo,y.GroupingColumnsPlugin=Vo,y.GroupingRowsPlugin=Jo,y.MasterDetailPlugin=rn,y.MultiSortPlugin=dn,y.PLUGIN_QUERIES=he,y.PinnedColumnsPlugin=fn,y.PinnedRowsPlugin=wn,y.PivotPlugin=Y,y.PluginEvents=po,y.PluginManager=je,y.ReorderPlugin=Dn,y.SelectionPlugin=Kn,y.ServerSidePlugin=Xn,y.TreePlugin=ei,y.UndoRedoPlugin=si,y.VisibilityPlugin=Z,y.aggregatorRegistry=N,y.getAggregator=Xe,y.getValueAggregator=pe,y.listAggregators=mo,y.registerAggregator=wo,y.runAggregator=ge,y.runValueAggregator=go,y.unregisterAggregator=bo,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})}));
|
|
92
|
+
</Workbook>`,n}function Po(o,e){const t=e.endsWith(".xls")?e:`${e}.xls`,n=new Blob([o],{type:"application/vnd.ms-excel;charset=utf-8;"});Ee(n,t)}class Mo extends L{name="export";version="1.0.0";get defaultConfig(){return{fileName:"export",includeHeaders:!0,onlyVisible:!0,onlySelected:!1}}isExportingFlag=!1;lastExportInfo=null;performExport(e,t){const n=this.config,i={format:e,fileName:t?.fileName??n.fileName??"export",includeHeaders:t?.includeHeaders??n.includeHeaders,processCell:t?.processCell,processHeader:t?.processHeader,columns:t?.columns,rowIndices:t?.rowIndices};let r=[...this.columns];if(n.onlyVisible&&(r=r.filter(a=>!a.hidden&&!a.field.startsWith("__"))),t?.columns){const a=new Set(t.columns);r=r.filter(c=>a.has(c.field))}let s=[...this.rows];if(n.onlySelected){const a=this.getSelectionState();a?.selected?.size&&(s=[...a.selected].sort((d,h)=>d-h).map(d=>this.rows[d]).filter(Boolean))}t?.rowIndices&&(s=t.rowIndices.map(a=>this.rows[a]).filter(Boolean)),this.isExportingFlag=!0;let l=i.fileName;try{switch(e){case"csv":{const a=ko(s,r,i,{bom:!0});l=l.endsWith(".csv")?l:`${l}.csv`,To(a,l);break}case"excel":{const a=Lo(s,r,i);l=l.endsWith(".xls")?l:`${l}.xls`,Po(a,l);break}case"json":{const a=s.map(h=>{const f={};for(const u of r){let p=h[u.field];i.processCell&&(p=i.processCell(p,u.field,h)),f[u.field]=p}return f}),c=JSON.stringify(a,null,2);l=l.endsWith(".json")?l:`${l}.json`;const d=new Blob([c],{type:"application/json"});Ee(d,l);break}}this.lastExportInfo={format:e,timestamp:new Date},this.emit("export-complete",{format:e,fileName:l,rowCount:s.length,columnCount:r.length})}finally{this.isExportingFlag=!1}}getSelectionState(){try{return this.grid?.getPluginState?.("selection")??null}catch{return null}}exportCsv(e){this.performExport("csv",e)}exportExcel(e){this.performExport("excel",e)}exportJson(e){this.performExport("json",e)}isExporting(){return this.isExportingFlag}getLastExport(){return this.lastExportInfo}}function Io(o){const{totalRows:e,viewportHeight:t,scrollTop:n,rowHeight:i,overscan:r}=o,s=Math.ceil(t/i);let l=Math.floor(n/i)-r;l<0&&(l=0);let a=l+s+r*2;return a>e&&(a=e),a===e&&l>0&&(l=Math.max(0,a-s-r*2)),{start:l,end:a,offsetY:l*i,totalHeight:e*i}}function Ho(o,e){return o<=e}function No(o,e,t=!1){const n=o[e.field];if(e.operator==="blank")return n==null||n==="";if(e.operator==="notBlank")return n!=null&&n!=="";if(n==null)return!1;const i=String(n),r=t?i:i.toLowerCase(),s=t?String(e.value):String(e.value).toLowerCase();switch(e.operator){case"contains":return r.includes(s);case"notContains":return!r.includes(s);case"equals":return r===s;case"notEquals":return r!==s;case"startsWith":return r.startsWith(s);case"endsWith":return r.endsWith(s);case"lessThan":return Number(n)<Number(e.value);case"lessThanOrEqual":return Number(n)<=Number(e.value);case"greaterThan":return Number(n)>Number(e.value);case"greaterThanOrEqual":return Number(n)>=Number(e.value);case"between":return Number(n)>=Number(e.value)&&Number(n)<=Number(e.valueTo);case"in":return Array.isArray(e.value)&&e.value.includes(n);case"notIn":return Array.isArray(e.value)&&!e.value.includes(n);default:return!0}}function Do(o,e,t=!1){return e.length?o.filter(n=>e.every(i=>No(n,i,t))):o}function Oo(o){return JSON.stringify(o.map(e=>({field:e.field,operator:e.operator,value:e.value,valueTo:e.valueTo})))}function rt(o,e){const t=new Set;for(const n of o){const i=n[e];i!=null&&t.add(i)}return[...t].sort((n,i)=>typeof n=="number"&&typeof i=="number"?n-i:String(n).localeCompare(String(i)))}const zo='.header-cell.filtered:before{content:"";position:absolute;top:4px;right:4px;width:6px;height:6px;background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border-radius:50%}.tbw-filter-btn{display:inline-flex;align-items:center;justify-content:center;background:transparent;border:none;cursor:pointer;padding:2px;margin-left:4px;opacity:.4;transition:opacity .15s;color:inherit;vertical-align:middle}.tbw-filter-btn:hover,.tbw-filter-btn.active{opacity:1}.tbw-filter-btn.active{color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6))}',qo=".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, 4px));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:12px;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, 13px)}.tbw-filter-search{margin-bottom:8px}.tbw-filter-search-input{width:100%;padding:6px 10px;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, 4px);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:4px 2px;margin-bottom:8px;border-bottom:1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)))}.tbw-filter-action-btn{background:transparent;border:none;color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));cursor:pointer;font-size:12px;padding:2px 0}.tbw-filter-action-btn:hover{text-decoration:underline}.tbw-filter-values{flex:1;overflow-y:auto;margin-bottom:8px;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:8px;padding:4px 2px;cursor:pointer;border-radius:3px}.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:8px 0;text-align:center;font-style:italic}.tbw-filter-buttons{display:flex;gap:8px;padding-top:8px;border-top:1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)))}.tbw-filter-apply-btn{flex:1;padding:6px 12px;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:4px;cursor:pointer;font-size:13px}.tbw-filter-apply-btn:hover{filter:brightness(.9)}.tbw-filter-clear-btn{flex:1;padding:6px 12px;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:4px;cursor:pointer;font-size:13px}.tbw-filter-clear-btn:hover{background:var(--tbw-filter-hover, var(--tbw-color-row-hover, light-dark(#f0f6ff, #1c1c1c)))}";class F extends L{name="filtering";version="1.0.0";get defaultConfig(){return{debounceMs:300,caseSensitive:!1,trimInput:!0,useWorker:!0}}filters=new Map;cachedResult=null;cacheKey=null;openPanelField=null;panelElement=null;searchText=new Map;excludedValues=new Map;panelAbortController=null;globalStylesInjected=!1;static LIST_ITEM_HEIGHT=28;static LIST_OVERSCAN=3;static LIST_BYPASS_THRESHOLD=50;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];const n=Oo(t);if(this.cacheKey===n&&this.cachedResult)return this.cachedResult;const i=Do([...e],t,this.config.caseSensitive);return this.cachedResult=i,this.cacheKey=n,i}afterRender(){const e=this.shadowRoot;if(!e)return;e.querySelectorAll('[part~="header-cell"]').forEach(n=>{const i=n.getAttribute("data-col");if(i===null)return;const r=this.columns[parseInt(i,10)];if(!r||r.filterable===!1||n.querySelector(".tbw-filter-btn"))return;const s=r.field;if(!s)return;const l=document.createElement("button");l.className="tbw-filter-btn",l.setAttribute("aria-label",`Filter ${r.header??s}`),l.innerHTML='<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>',this.filters.has(s)&&(l.classList.add("active"),n.classList.add("filtered")),l.addEventListener("click",a=>{a.stopPropagation(),this.toggleFilterPanel(s,r,l)}),n.appendChild(l)})}setFilter(e,t){t===null?this.filters.delete(e):this.filters.set(e,{...t,field:e}),this.cachedResult=null,this.cacheKey=null,this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0}),this.requestRender()}getFilter(e){return this.filters.get(e)}getFilters(){return[...this.filters.values()]}getFilterModel(){return this.getFilters()}setFilterModel(e){this.filters.clear();for(const t of e)this.filters.set(t.field,t);this.cachedResult=null,this.cacheKey=null,this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0}),this.requestRender()}clearAllFilters(){this.filters.clear(),this.excludedValues.clear(),this.searchText.clear(),this.cachedResult=null,this.cacheKey=null,this.emit("filter-change",{filters:[],filteredRowCount:this.rows.length}),this.requestRender()}clearFieldFilter(e){this.filters.delete(e),this.excludedValues.delete(e),this.searchText.delete(e),this.cachedResult=null,this.cacheKey=null,this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0}),this.requestRender()}isFieldFiltered(e){return this.filters.has(e)}getFilteredRowCount(){return this.cachedResult?.length??this.rows.length}getActiveFilters(){return this.getFilters()}getUniqueValues(e){return rt(this.sourceRows,e)}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=qo,document.head.appendChild(e),this.globalStylesInjected=!0}toggleFilterPanel(e,t,n){if(this.openPanelField===e){this.closeFilterPanel();return}this.closeFilterPanel();const i=document.createElement("div");i.className="tbw-filter-panel",this.panelElement=i,this.openPanelField=e;const r=rt(this.sourceRows,e);let s=this.excludedValues.get(e);s||(s=new Set,this.excludedValues.set(e,s));const l=this.searchText.get(e)??"",a={field:e,column:t,uniqueValues:r,excludedValues:s,searchText:l,applySetFilter:d=>{this.applySetFilter(e,d),this.closeFilterPanel()},applyTextFilter:(d,h,f)=>{this.applyTextFilter(e,d,h,f),this.closeFilterPanel()},clearFilter:()=>{this.clearFieldFilter(e),this.closeFilterPanel()},closePanel:()=>this.closeFilterPanel()};let c=!1;this.config.filterPanelRenderer&&(this.config.filterPanelRenderer(i,a),c=i.children.length>0),c||this.renderDefaultFilterPanel(i,a,r,s),document.body.appendChild(i),this.positionPanel(i,n),this.panelAbortController=new AbortController,setTimeout(()=>{document.addEventListener("click",d=>{!i.contains(d.target)&&d.target!==n&&this.closeFilterPanel()},{signal:this.panelAbortController?.signal})},0)}closeFilterPanel(){this.panelElement&&(this.panelElement.remove(),this.panelElement=null),this.openPanelField=null,this.panelAbortController?.abort(),this.panelAbortController=null}positionPanel(e,t){const n=t.getBoundingClientRect();e.style.position="fixed",e.style.top=`${n.bottom+4}px`,e.style.left=`${n.left}px`,requestAnimationFrame(()=>{const i=e.getBoundingClientRect();i.right>window.innerWidth-8&&(e.style.left=`${window.innerWidth-i.width-8}px`),i.bottom>window.innerHeight-8&&(e.style.top=`${n.top-i.height-4}px`)})}renderDefaultFilterPanel(e,t,n,i){const{field:r}=t,s=document.createElement("div");s.className="tbw-filter-search";const l=document.createElement("input");l.type="text",l.placeholder="Search...",l.className="tbw-filter-search-input",l.value=this.searchText.get(r)??"",s.appendChild(l),e.appendChild(s);const a=document.createElement("div");a.className="tbw-filter-actions";const c=document.createElement("label");c.className="tbw-filter-value-item",c.style.padding="0",c.style.margin="0";const d=document.createElement("input");d.type="checkbox",d.className="tbw-filter-checkbox";const h=document.createElement("span");h.textContent="Select All",c.appendChild(d),c.appendChild(h),a.appendChild(c);const f=()=>{const C=[...w.values()],x=C.every(A=>A),R=C.every(A=>!A);d.checked=x,d.indeterminate=!x&&!R};d.addEventListener("change",()=>{const C=d.checked;for(const x of w.keys())w.set(x,C);f(),T()}),e.appendChild(a);const u=document.createElement("div");u.className="tbw-filter-values";const p=document.createElement("div");p.className="tbw-filter-values-spacer",u.appendChild(p);const g=document.createElement("div");g.className="tbw-filter-values-content",u.appendChild(g);const w=new Map;n.forEach(C=>{const x=C==null?"__null__":String(C);w.set(x,!i.has(C))}),f();let b=[];const _=(C,x)=>{const R=C==null?"(Blank)":String(C),A=C==null?"__null__":String(C),P=document.createElement("label");P.className="tbw-filter-value-item",P.style.position="absolute",P.style.top=`${x*F.LIST_ITEM_HEIGHT}px`,P.style.left="0",P.style.right="0",P.style.height=`${F.LIST_ITEM_HEIGHT}px`,P.style.boxSizing="border-box";const O=document.createElement("input");O.type="checkbox",O.className="tbw-filter-checkbox",O.checked=w.get(A)??!0,O.dataset.value=A,O.addEventListener("change",()=>{w.set(A,O.checked),f()});const At=document.createElement("span");return At.textContent=R,P.appendChild(O),P.appendChild(At),P},T=()=>{const C=b.length,x=u.clientHeight,R=u.scrollTop;if(p.style.height=`${C*F.LIST_ITEM_HEIGHT}px`,Ho(C,F.LIST_BYPASS_THRESHOLD/3)){g.innerHTML="",g.style.transform="translateY(0px)",b.forEach((P,O)=>{g.appendChild(_(P,O))});return}const A=Io({totalRows:C,viewportHeight:x,scrollTop:R,rowHeight:F.LIST_ITEM_HEIGHT,overscan:F.LIST_OVERSCAN});g.style.transform=`translateY(${A.offsetY}px)`,g.innerHTML="";for(let P=A.start;P<A.end;P++)g.appendChild(_(b[P],P-A.start))},k=C=>{const x=C.toLowerCase();if(b=n.filter(R=>{const A=R==null?"(Blank)":String(R);return!C||A.toLowerCase().includes(x)}),b.length===0){p.style.height="0px",g.innerHTML="";const R=document.createElement("div");R.className="tbw-filter-no-match",R.textContent="No matching values",g.appendChild(R);return}T()};u.addEventListener("scroll",()=>{b.length>0&&T()},{passive:!0}),k(l.value),e.appendChild(u);let m;l.addEventListener("input",()=>{clearTimeout(m),m=setTimeout(()=>{this.searchText.set(r,l.value),k(l.value)},this.config.debounceMs??150)});const v=document.createElement("div");v.className="tbw-filter-buttons";const S=document.createElement("button");S.className="tbw-filter-apply-btn",S.textContent="Apply",S.addEventListener("click",()=>{const C=[];for(const[x,R]of w)if(!R)if(x==="__null__")C.push(null);else{const A=n.find(P=>String(P)===x);C.push(A!==void 0?A:x)}t.applySetFilter(C)}),v.appendChild(S);const E=document.createElement("button");E.className="tbw-filter-clear-btn",E.textContent="Clear Filter",E.addEventListener("click",()=>{t.clearFilter()}),v.appendChild(E),e.appendChild(v)}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.cachedResult=null,this.cacheKey=null,this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0}),this.requestRender()}applyTextFilter(e,t,n,i){this.filters.set(e,{field:e,type:"text",operator:t,value:n,valueTo:i}),this.cachedResult=null,this.cacheKey=null,this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0}),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 n={field:e,type:t.filter.type,operator:t.filter.operator,value:t.filter.value,valueTo:t.filter.valueTo};this.filters.set(e,n),this.cachedResult=null,this.cacheKey=null}styles=zo}function Fo(o){if(!o.length)return[];const e=new Map,t=[],n=(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 i=[],r=0;return o.forEach((s,l)=>{const a=s.group;if(!a){i.length===0&&(r=l),i.push(s);return}i.length&&(n(r,i.slice()),i=[]);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)}),i.length&&n(r,i),t.length===1&&t[0].implicit&&t[0].columns.length===o.length?[]:t}function Bo(o,e,t){if(!e.length||!o)return;const n=new Map;for(const r of e)for(const s of r.columns)s?.field&&n.set(s.field,r.id);const i=Array.from(o.querySelectorAll(".cell[data-field]"));i.forEach(r=>{const s=r.getAttribute("data-field")||"",l=n.get(s);l&&(r.classList.add("grouped"),r.getAttribute("data-group")||r.setAttribute("data-group",l))});for(const r of e){const s=r.columns[r.columns.length-1],l=i.find(a=>a.getAttribute("data-field")===s.field);l&&l.classList.add("group-end")}}function $o(o,e){if(o.length===0)return null;const t=document.createElement("div");t.className="header-group-row",t.setAttribute("role","row");for(const n of o){const i=n.firstIndex!=null?n.firstIndex:e.findIndex(a=>n.columns.includes(a)),r=String(n.id).startsWith("__implicit__"),s=r?"":n.label||n.id,l=document.createElement("div");l.className="cell header-group-cell",r&&l.classList.add("implicit-group"),l.setAttribute("data-group",String(n.id)),l.style.gridColumn=`${i+1} / span ${n.columns.length}`,l.textContent=s,t.appendChild(l)}return t}function Go(o){return o.some(e=>e.group!=null)}const Ko=".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:4px 8px;font-weight:600;font-size:.9em;text-transform:uppercase;letter-spacing:.5px;border-right:1px solid var(--tbw-grouping-columns-border, 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))}";class Vo extends L{name="groupingColumns";version="1.0.0";get defaultConfig(){return{showGroupBorders:!0}}groups=[];isActive=!1;detach(){this.groups=[],this.isActive=!1}static detect(e,t){const n=t?.columns;return Array.isArray(n)?Go(n):!1}processColumns(e){const t=Fo(e);return t.length===0?(this.isActive=!1,this.groups=[],[...e]):(this.isActive=!0,this.groups=t,[...e])}afterRender(){if(!this.isActive||this.groups.length===0){const s=this.shadowRoot?.querySelector(".header")?.querySelector(".header-group-row");s&&s.remove();return}const e=this.shadowRoot?.querySelector(".header");if(!e)return;const t=e.querySelector(".header-group-row");t&&t.remove();const n=$o(this.groups,this.columns);if(n){const r=e.querySelector(".header-row");r?e.insertBefore(n,r):e.appendChild(n)}const i=e.querySelector(".header-row");i&&Bo(i,this.groups,this.columns)}isGroupingActive(){return this.isActive}getGroups(){return this.groups}getGroupColumns(e){const t=this.groups.find(n=>n.id===e);return t?t.columns:[]}refresh(){this.requestRender()}styles=Ko}function Wo({rows:o,config:e,expanded:t}){const n=e.groupOn;if(typeof n!="function")return[];const i={key:"__root__",value:null,depth:-1,rows:[],children:new Map};if(o.forEach(l=>{let a=n(l);a==null||a===!1?a=["__ungrouped__"]:Array.isArray(a)||(a=[a]);let c=i;a.forEach((d,h)=>{const f=d==null?"∅":String(d),u=c.key==="__root__"?f:c.key+"||"+f;let p=c.children.get(f);p||(p={key:u,value:d,depth:h,rows:[],children:new Map,parent:c},c.children.set(f,p)),c=p}),c.rows.push(l)}),i.children.size===1&&i.children.has("__ungrouped__")&&i.children.get("__ungrouped__").rows.length===o.length)return[];const r=[],s=l=>{if(l===i){l.children.forEach(c=>s(c));return}const a=t.has(l.key);r.push({kind:"group",key:l.key,value:l.value,depth:l.depth,rows:l.rows,expanded:a}),a&&(l.children.size?l.children.forEach(c=>s(c)):l.rows.forEach(c=>r.push({kind:"data",row:c,rowIndex:o.indexOf(c)})))};return s(i),r}function jo(o,e){const t=new Set(o);return t.has(e)?t.delete(e):t.add(e),t}function Uo(o){const e=new Set;for(const t of o)t.kind==="group"&&e.add(t.key);return e}function Xo(){return new Set}function Yo(o){return o.kind!=="group"?0:o.rows.length}const Zo='.group-row{background:var(--tbw-grouping-rows-bg, var(--tbw-color-panel-bg));font-weight:500}.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:20px;height:20px;margin-right:4px;font-size:10px}.group-toggle:hover{background:var(--tbw-grouping-rows-toggle-hover, var(--tbw-color-row-hover));border-radius:2px}.group-label{display:inline-flex;align-items:center;gap:8px}.group-count{color:var(--tbw-grouping-rows-count-color, var(--tbw-color-fg-muted));font-size:.85em;font-weight:400}[data-group-depth="0"] .group-label{padding-left:0}[data-group-depth="1"] .group-label{padding-left:20px}[data-group-depth="2"] .group-label{padding-left:40px}[data-group-depth="3"] .group-label{padding-left:60px}[data-group-depth="4"] .group-label{padding-left:80px}';class Jo extends L{name="groupingRows";version="1.0.0";get defaultConfig(){return{defaultExpanded:!1,showRowCount:!0,indentWidth:20,aggregators:{}}}expandedKeys=new Set;flattenedRows=[];isActive=!1;detach(){this.expandedKeys.clear(),this.flattenedRows=[],this.isActive=!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 n=Wo({rows:e,config:t,expanded:this.expandedKeys});return n.length===0?(this.isActive=!1,this.flattenedRows=[],[...e]):(this.isActive=!0,this.flattenedRows=n,n.map(i=>i.kind==="group"?{__isGroupRow:!0,__groupKey:i.key,__groupValue:i.value,__groupDepth:i.depth,__groupRows:i.rows,__groupExpanded:i.expanded,__groupRowCount:Yo(i)}:i.row))}onCellClick(e){const t=e.row;if(t?.__isGroupRow&&e.originalEvent.target?.closest(".group-toggle"))return this.toggle(t.__groupKey),!0}renderRow(e,t,n){if(!e?.__isGroupRow)return!1;const i=this.config;if(i.groupRowRenderer){const l=()=>{this.toggle(e.__groupKey)},a=i.groupRowRenderer({key:e.__groupKey,value:e.__groupValue,depth:e.__groupDepth,rows:e.__groupRows,expanded:e.__groupExpanded,toggleExpand:l});if(a)return t.className="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 r=()=>{this.toggle(e.__groupKey)};return t.className="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.paddingLeft=`${(e.__groupDepth||0)*(i.indentWidth??20)}px`,t.innerHTML="",i.fullWidth!==!1?this.renderFullWidthGroupRow(e,t,r):this.renderPerColumnGroupRow(e,t,r),!0}afterRender(){}renderFullWidthGroupRow(e,t,n){const i=this.config,r=document.createElement("div");r.className="cell group-full",r.style.gridColumn="1 / -1",r.setAttribute("role","gridcell");const s=document.createElement("button");s.type="button",s.className="group-toggle",s.setAttribute("aria-label",e.__groupExpanded?"Collapse group":"Expand group"),this.setIcon(s,this.resolveIcon(e.__groupExpanded?"collapse":"expand")),s.addEventListener("click",c=>{c.stopPropagation(),n()}),r.appendChild(s);const l=document.createElement("span");l.className="group-label";const a=i.formatLabel?i.formatLabel(e.__groupValue,e.__groupDepth||0,e.__groupKey):String(e.__groupValue);if(l.textContent=a,r.appendChild(l),i.showRowCount!==!1){const c=document.createElement("span");c.className="group-count",c.textContent=`(${e.__groupRowCount??e.__groupRows?.length??0})`,r.appendChild(c)}t.appendChild(r)}renderPerColumnGroupRow(e,t,n){const i=this.config,r=i.aggregators??{},s=this.columns,l=e.__groupRows??[],c=this.shadowRoot?.querySelector(".body")?.style.gridTemplateColumns||"";c&&(t.style.display="grid",t.style.gridTemplateColumns=c),s.forEach((d,h)=>{const f=document.createElement("div");if(f.className="cell group-cell",f.setAttribute("data-col",String(h)),f.setAttribute("role","gridcell"),h===0){const u=document.createElement("button");u.type="button",u.className="group-toggle",u.setAttribute("aria-label",e.__groupExpanded?"Collapse group":"Expand group"),this.setIcon(u,this.resolveIcon(e.__groupExpanded?"collapse":"expand")),u.addEventListener("click",w=>{w.stopPropagation(),n()}),f.appendChild(u);const p=document.createElement("span"),g=r[d.field];if(g){const w=ge(g,l,d.field,d);p.textContent=w!=null?String(w):String(e.__groupValue)}else{const w=i.formatLabel?i.formatLabel(e.__groupValue,e.__groupDepth||0,e.__groupKey):String(e.__groupValue);p.textContent=w}if(f.appendChild(p),i.showRowCount!==!1){const w=document.createElement("span");w.className="group-count",w.textContent=` (${l.length})`,f.appendChild(w)}}else{const u=r[d.field];if(u){const p=ge(u,l,d.field,d);f.textContent=p!=null?String(p):""}else f.textContent=""}t.appendChild(f)})}expandAll(){this.expandedKeys=Uo(this.flattenedRows),this.requestRender()}collapseAll(){this.expandedKeys=Xo(),this.requestRender()}toggle(e){this.expandedKeys=jo(this.expandedKeys,e);const t=this.flattenedRows.find(n=>n.kind==="group"&&n.key===e);this.emit("group-toggle",{key:e,expanded:this.expandedKeys.has(e),value:t?.value,depth:t?.depth??0}),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()}styles=Zo}function Re(o,e){const t=new Set(o);return t.has(e)?t.delete(e):t.add(e),t}function Qo(o,e){const t=new Set(o);return t.add(e),t}function en(o,e){const t=new Set(o);return t.delete(e),t}function tn(o,e){return o.has(e)}function on(o,e,t,n){const i=document.createElement("div");i.className="master-detail-row",i.setAttribute("data-detail-for",String(e)),i.setAttribute("role","row");const r=document.createElement("div");r.className="master-detail-cell",r.setAttribute("role","cell"),r.style.gridColumn=`1 / ${n+1}`;const s=t(o,e);return typeof s=="string"?r.innerHTML=s:s instanceof HTMLElement&&r.appendChild(s),i.appendChild(r),i}const nn=".master-detail-cell-wrapper{display:flex;align-items:center;gap:4px}.master-detail-toggle{cursor:pointer;font-size:10px;opacity:.7;-webkit-user-select:none;user-select:none}.master-detail-toggle:hover{opacity:1}.master-detail-row{grid-column:1 / -1;display:grid;background:var(--tbw-master-detail-bg, var(--tbw-color-row-alt));border-bottom:1px solid var(--tbw-master-detail-border, var(--tbw-color-border))}.master-detail-cell{padding:16px;overflow:auto}";class rn extends L{name="masterDetail";version="1.0.0";get defaultConfig(){return{detailHeight:"auto",expandOnRowClick:!1,collapseOnClickOutside:!1,showExpandColumn:!0}}expandedRows=new Set;detailElements=new Map;detach(){this.expandedRows.clear(),this.detailElements.clear()}processColumns(e){if(!this.config.detailRenderer)return[...e];const t=[...e];if(t.length>0){const n={...t[0]},i=n.viewRenderer;if(i?.__masterDetailWrapped)return t;const r=s=>{const{value:l,row:a}=s,c=this.expandedRows.has(a),d=document.createElement("span");d.className="master-detail-cell-wrapper";const h=document.createElement("span");h.className="master-detail-toggle",this.setIcon(h,this.resolveIcon(c?"collapse":"expand")),h.setAttribute("role","button"),h.setAttribute("tabindex","0"),h.setAttribute("aria-expanded",String(c)),h.setAttribute("aria-label",c?"Collapse details":"Expand details"),h.addEventListener("click",u=>{u.stopPropagation();const p=this.rows.indexOf(a);this.expandedRows=Re(this.expandedRows,a),this.emit("detail-expand",{rowIndex:p,row:a,expanded:this.expandedRows.has(a)}),this.requestRender()}),d.appendChild(h);const f=document.createElement("span");if(i){const u=i(s);u instanceof Node?f.appendChild(u):f.textContent=String(u??l??"")}else f.textContent=String(l??"");return d.appendChild(f),d};r.__masterDetailWrapped=!0,n.viewRenderer=r,t[0]=n}return t}onRowClick(e){if(!(!this.config.expandOnRowClick||!this.config.detailRenderer))return this.expandedRows=Re(this.expandedRows,e.row),this.emit("detail-expand",{rowIndex:e.rowIndex,row:e.row,expanded:this.expandedRows.has(e.row)}),this.requestRender(),!1}onCellClick(){this.expandedRows.size>0&&queueMicrotask(()=>this.#o())}afterRender(){this.#o()}onScrollRender(){!this.config.detailRenderer||this.expandedRows.size===0||this.#o()}#o(){if(!this.config.detailRenderer)return;const e=this.shadowRoot?.querySelector(".rows");if(!e)return;const t=new Map,n=e.querySelectorAll(".data-grid-row"),i=this.columns.length;for(const s of n){const l=s.querySelector(".cell[data-row]"),a=l?parseInt(l.getAttribute("data-row")??"-1",10):-1;a>=0&&t.set(a,s)}const r=e.querySelectorAll(".master-detail-row");for(const s of r){const l=parseInt(s.getAttribute("data-detail-for")??"-1",10),a=l>=0?this.rows[l]:void 0,c=a&&this.expandedRows.has(a),d=t.has(l);(!c||!d)&&(s.remove(),a&&this.detailElements.delete(a))}for(const[s,l]of t){const a=this.rows[s];if(!a||!this.expandedRows.has(a))continue;const c=this.detailElements.get(a);if(c){c.previousElementSibling!==l&&l.after(c);continue}const d=on(a,s,this.config.detailRenderer,i);typeof this.config.detailHeight=="number"&&(d.style.height=`${this.config.detailHeight}px`),l.after(d),this.detailElements.set(a,d)}}getExtraHeight(){let e=0;for(const t of this.expandedRows){const n=this.detailElements.get(t);if(n)e+=n.offsetHeight;else{const i=this.config?.detailHeight;e+=typeof i=="number"?i:150}}return e}getExtraHeightBefore(e){let t=0;for(const n of this.expandedRows){const i=this.rows.indexOf(n);if(i>=0&&i<e){const r=this.detailElements.get(n);if(r)t+=r.offsetHeight;else{const s=this.config?.detailHeight;t+=typeof s=="number"?s:150}}}return t}adjustVirtualStart(e,t,n){if(this.expandedRows.size===0)return e;const i=[];for(const l of this.expandedRows){const a=this.rows.indexOf(l);a>=0&&i.push({index:a,row:l})}i.sort((l,a)=>l.index-a.index);let r=e,s=0;for(const{index:l,row:a}of i){const c=l*n+s,h=this.detailElements.get(a)?.offsetHeight??(typeof this.config?.detailHeight=="number"?this.config.detailHeight:150),f=c+n+h;s+=h,!(l>=e)&&f>t&&l<r&&(r=l)}return r}expand(e){const t=this.rows[e];t&&(this.expandedRows=Qo(this.expandedRows,t),this.requestRender())}collapse(e){const t=this.rows[e];t&&(this.expandedRows=en(this.expandedRows,t),this.requestRender())}toggle(e){const t=this.rows[e];t&&(this.expandedRows=Re(this.expandedRows,t),this.requestRender())}isExpanded(e){const t=this.rows[e];return t?tn(this.expandedRows,t):!1}expandAll(){for(const e of this.rows)this.expandedRows.add(e);this.requestRender()}collapseAll(){this.expandedRows.clear(),this.requestRender()}getExpandedRows(){const e=[];for(const t of this.expandedRows){const n=this.rows.indexOf(t);n>=0&&e.push(n)}return e}getDetailElement(e){const t=this.rows[e];return t?this.detailElements.get(t):void 0}styles=nn}function sn(o,e,t){return e.length?[...o].sort((n,i)=>{for(const r of e){const l=t.find(h=>h.field===r.field)?.sortComparator??ln,a=n[r.field],c=i[r.field],d=l(a,c,n,i);if(d!==0)return r.direction==="asc"?d:-d}return 0}):[...o]}function ln(o,e){return o==null&&e==null?0:o==null?1:e==null?-1:typeof o=="number"&&typeof e=="number"?o-e:o instanceof Date&&e instanceof Date?o.getTime()-e.getTime():typeof o=="boolean"&&typeof e=="boolean"?o===e?0:o?-1:1:String(o).localeCompare(String(e))}function an(o,e,t,n){const i=o.find(r=>r.field===e);return t?i?i.direction==="asc"?o.map(r=>r.field===e?{...r,direction:"desc"}:r):o.filter(r=>r.field!==e):o.length<n?[...o,{field:e,direction:"asc"}]:o:i?.direction==="asc"?[{field:e,direction:"desc"}]:i?.direction==="desc"?[]:[{field:e,direction:"asc"}]}function st(o,e){const t=o.findIndex(n=>n.field===e);return t>=0?t+1:void 0}function lt(o,e){return o.find(t=>t.field===e)?.direction}const cn='.header-cell[data-sort=asc]:after{content:"↑";margin-left:4px;opacity:.8}.header-cell[data-sort=desc]:after{content:"↓";margin-left:4px;opacity:.8}.sort-index{font-size:10px;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:14px;height:14px;display:inline-flex;align-items:center;justify-content:center;margin-left:2px;font-weight:600}';class dn extends L{name="multiSort";version="1.0.0";get defaultConfig(){return{maxSortColumns:3,showSortIndex:!0}}sortModel=[];detach(){this.sortModel=[]}processRows(e){return this.sortModel.length===0?[...e]:sn([...e],this.sortModel,[...this.columns])}onHeaderClick(e){if(!this.columns.find(r=>r.field===e.field)?.sortable)return!1;const n=e.originalEvent.shiftKey,i=this.config.maxSortColumns??3;return this.sortModel=an(this.sortModel,e.field,n,i),this.emit("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),!0}afterRender(){const e=this.shadowRoot;if(!e)return;const t=this.config.showSortIndex!==!1;e.querySelectorAll(".header-row .cell[data-field]").forEach(i=>{const r=i.getAttribute("data-field");if(!r)return;const s=st(this.sortModel,r),l=lt(this.sortModel,r);if(i.querySelector(".sort-index")?.remove(),l){i.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove(),i.setAttribute("data-sort",l);const d=document.createElement("span");if(d.className="sort-indicator",d.style.marginLeft="4px",d.style.opacity="0.8",this.setIcon(d,this.resolveIcon(l==="asc"?"sortAsc":"sortDesc")),i.appendChild(d),t&&this.sortModel.length>1&&s!==void 0){const h=document.createElement("span");h.className="sort-index",h.textContent=String(s),i.appendChild(h)}}else i.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 st(this.sortModel,e)}getSortDirection(e){return lt(this.sortModel,e)}getColumnState(e){const t=this.sortModel.findIndex(i=>i.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(r=>r.field!==e);return}const n=this.sortModel.findIndex(r=>r.field===e),i={field:e,direction:t.sort.direction};n!==-1?this.sortModel[n]=i:this.sortModel.splice(t.sort.priority,0,i)}styles=cn}function un(o){return o.filter(e=>e.sticky==="left")}function hn(o){return o.filter(e=>e.sticky==="right")}function _e(o){return o.some(e=>e.sticky==="left"||e.sticky==="right")}function at(o,e){const t=o.shadowRoot;if(!t)return;const n=Array.from(t.querySelectorAll(".header-row .cell"));if(!n.length)return;const i=new Map;e.forEach((l,a)=>{l.field&&i.set(l.field,a)});let r=0;for(const l of e)if(l.sticky==="left"){const a=i.get(l.field),c=n.find(d=>d.getAttribute("data-field")===l.field);c&&(c.classList.add("sticky-left"),c.style.position="sticky",c.style.left=r+"px",a!==void 0&&t.querySelectorAll(`.data-grid-row .cell[data-col="${a}"]`).forEach(d=>{d.classList.add("sticky-left"),d.style.position="sticky",d.style.left=r+"px"}),r+=c.offsetWidth)}let s=0;for(const l of[...e].reverse())if(l.sticky==="right"){const a=i.get(l.field),c=n.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&&t.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 ct(o){const e=o.shadowRoot;if(!e)return;e.querySelectorAll(".sticky-left, .sticky-right").forEach(n=>{n.classList.remove("sticky-left","sticky-right"),n.style.position="",n.style.left="",n.style.right=""})}class fn extends L{name="pinnedColumns";version="1.0.0";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 n=t?.columns;return Array.isArray(n)?_e(n):!1}processColumns(e){return this.isApplied=_e([...e]),[...e]}afterRender(){if(!this.isApplied)return;const e=this.grid,t=[...this.columns];if(!_e(t)){ct(e),this.isApplied=!1;return}queueMicrotask(()=>{at(e,t)})}onPluginQuery(e){switch(e.type){case he.CAN_MOVE_COLUMN:{const t=e.context,n=t.sticky;if(n==="left"||n==="right")return!1;const i=t.meta?.sticky;return i==="left"||i==="right"?!1:void 0}default:return}}refreshStickyOffsets(){const e=[...this.columns];at(this.grid,e)}getLeftPinnedColumns(){const e=[...this.columns];return un(e)}getRightPinnedColumns(){const e=[...this.columns];return hn(e)}clearStickyPositions(){ct(this.grid)}getHorizontalScrollOffsets(e,t){if(!this.isApplied)return;let n=0,i=0;if(e){const s=e.querySelectorAll(".sticky-left"),l=e.querySelectorAll(".sticky-right");s.forEach(a=>{n+=a.offsetWidth}),l.forEach(a=>{i+=a.offsetWidth})}else{const l=this.grid.shadowRoot;l&&l.querySelectorAll(".header-row .cell").forEach(c=>{c.classList.contains("sticky-left")?n+=c.offsetWidth:c.classList.contains("sticky-right")&&(i+=c.offsetWidth)})}const r=t?.classList.contains("sticky-left")||t?.classList.contains("sticky-right");return{left:n,right:i,skipScroll:r}}}function Se(o,e){const t=document.createElement("div");t.className="tbw-pinned-rows",t.setAttribute("role","presentation"),t.setAttribute("aria-live","polite");const n=document.createElement("div");n.className="tbw-pinned-rows-left";const i=document.createElement("div");i.className="tbw-pinned-rows-center";const r=document.createElement("div");if(r.className="tbw-pinned-rows-right",o.showRowCount!==!1){const s=document.createElement("span");s.className="tbw-status-panel tbw-status-panel-row-count",s.textContent=`Total: ${e.totalRows} rows`,n.appendChild(s)}if(o.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}`,n.appendChild(s)}if(o.showSelectedCount&&e.selectedRows>0){const s=document.createElement("span");s.className="tbw-status-panel tbw-status-panel-selected-count",s.textContent=`Selected: ${e.selectedRows}`,r.appendChild(s)}if(o.customPanels)for(const s of o.customPanels){const l=pn(s,e);switch(s.position){case"left":n.appendChild(l);break;case"center":i.appendChild(l);break;case"right":r.appendChild(l);break}}return t.appendChild(n),t.appendChild(i),t.appendChild(r),t}function dt(o){const e=document.createElement("div");return e.className=`tbw-aggregation-rows tbw-aggregation-rows-${o}`,e.setAttribute("role","presentation"),e}function ut(o,e,t,n){o.innerHTML="";for(const i of e){const r=document.createElement("div");if(r.className="tbw-aggregation-row",r.setAttribute("role","presentation"),i.id&&r.setAttribute("data-aggregation-id",i.id),i.fullWidth){const s=document.createElement("div");s.className="tbw-aggregation-cell tbw-aggregation-cell-full",s.style.gridColumn="1 / -1",s.textContent=i.label||"",r.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;const c=i.aggregators?.[s.field];if(c){const d=Xe(c);d&&(a=d(n,s.field,s))}else if(i.cells&&Object.prototype.hasOwnProperty.call(i.cells,s.field)){const d=i.cells[s.field];typeof d=="function"?a=d(n,s.field,s):a=d}l.textContent=a!=null?String(a):"",r.appendChild(l)}o.appendChild(r)}}function pn(o,e){const t=document.createElement("div");t.className="tbw-status-panel tbw-status-panel-custom",t.id=`status-panel-${o.id}`;const n=o.render(e);return typeof n=="string"?t.innerHTML=n:t.appendChild(n),t}function ht(o,e,t,n,i){return{totalRows:o.length,filteredRows:i?.cachedResult?.length??o.length,selectedRows:n?.selected?.size??0,columns:e,rows:o,grid:t}}const gn=".tbw-footer{position:sticky;bottom: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:8px 12px;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:12px;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:16px}.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-weight:var(--tbw-aggregation-font-weight, 600)}.tbw-aggregation-cell{padding:var(--tbw-cell-padding, 2px 8px);min-height:var(--tbw-row-height, 28px);display:flex;align-items:center;border-right:1px solid var(--tbw-color-border-cell)}.tbw-aggregation-cell:last-child{border-right:0}.tbw-aggregation-cell-full{grid-column:1 / -1;border-right:0}";class wn extends L{name="pinnedRows";version="1.0.0";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.shadowRoot;if(!e)return;const t=e.querySelector(".tbw-scroll-area")??e.querySelector(".tbw-grid-content")??e.children[0];if(!t)return;const n=this.getSelectionState(),i=this.getFilterState(),r=ht(this.rows,this.columns,this.grid,n,i),s=this.config.aggregationRows||[],l=s.filter(f=>f.position==="top"),a=s.filter(f=>f.position!=="top");if(l.length>0){if(!this.topAggregationContainer){this.topAggregationContainer=dt("top");const f=e.querySelector(".header");f&&f.nextSibling?t.insertBefore(this.topAggregationContainer,f.nextSibling):t.appendChild(this.topAggregationContainer)}ut(this.topAggregationContainer,l,this.visibleColumns,this.rows)}else this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null);const c=this.config.showRowCount!==!1||this.config.showSelectedCount&&r.selectedRows>0||this.config.showFilteredCount&&r.filteredRows!==r.totalRows||this.config.customPanels&&this.config.customPanels.length>0,d=c&&this.config.position!=="top",h=a.length>0||d;if(c&&this.config.position==="top")if(!this.infoBarElement)this.infoBarElement=Se(this.config,r),t.insertBefore(this.infoBarElement,t.firstChild);else{const f=Se(this.config,r);this.infoBarElement.replaceWith(f),this.infoBarElement=f}else this.config.position==="top"&&this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null);h?(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=dt("bottom")),this.footerWrapper.appendChild(this.bottomAggregationContainer),ut(this.bottomAggregationContainer,a,this.visibleColumns,this.rows)),d&&(this.infoBarElement=Se(this.config,r),this.footerWrapper.appendChild(this.infoBarElement))):this.cleanupFooter()}cleanup(){this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null),this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null)}cleanupFooter(){this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.infoBarElement&&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 ht(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())}styles=gn}const bn=pe;function mn(o){const e=[];return!o.rowGroupFields?.length&&!o.columnGroupFields?.length&&e.push("At least one row or column group field is required"),o.valueFields?.length||e.push("At least one value field is required"),e}function Ae(o,e){return[...o,e].join("|")}function vn(o,e){const t=e.rowGroupFields??[],n=e.columnGroupFields??[],i=e.valueFields??[],r=Cn(o,n),s=ft(o,t,n,r,i,0,""),l=xn(s,r,i),a=Object.values(l).reduce((c,d)=>c+d,0);return{rows:s,columnKeys:r,totals:l,grandTotal:a}}function Cn(o,e){if(e.length===0)return["value"];const t=new Set;for(const n of o){const i=e.map(r=>String(n[r]??"")).join("|");t.add(i)}return[...t].sort()}function yn(o,e){const t=new Map;for(const n of o){const i=String(n[e]??""),r=t.get(i);r?r.push(n):t.set(i,[n])}return t}function ft(o,e,t,n,i,r,s){const l=[];if(e.length===0){const f=pt(o,t,n,i),u=gt(f);return l.push({rowKey:s||"all",rowLabel:s||"All",depth:r,values:f,total:u,isGroup:!1,rowCount:o.length}),l}const a=e[0],c=e.slice(1),d=c.length>0,h=yn(o,a);for(const[f,u]of h){const p=s?`${s}|${f}`:f,g=pt(u,t,n,i),w=gt(g);let b;d&&(b=ft(u,c,t,n,i,r+1,p)),l.push({rowKey:p,rowLabel:f||"(blank)",depth:r,values:g,total:w,isGroup:d,children:b,rowCount:u.length})}return l}function pt(o,e,t,n){const i={};for(const r of t)for(const s of n){const a=(e.length>0?o.filter(f=>e.map(u=>String(f[u]??"")).join("|")===r):o).map(f=>Number(f[s.field])||0),c=bn(s.aggFunc),d=a.length>0?c(a):null,h=Ae([r],s.field);i[h]=d}return i}function gt(o){let e=0;for(const t of Object.values(o))e+=t??0;return e}function xn(o,e,t){const n={};function i(r){for(const s of r)if(!s.isGroup||!s.children?.length)for(const l of e)for(const a of t){const c=Ae([l],a.field);n[c]=(n[c]??0)+(s.values[c]??0)}else s.children&&i(s.children)}return i(o),n}function En(o,e,t=!0){const n=[];function i(r){n.push(r);const s=e?e.has(r.rowKey):t;if(r.children&&s)for(const l of r.children)i(l)}for(const r of o)i(r);return n}function ke(o){const e=[];function t(n){if(n.isGroup&&e.push(n.rowKey),n.children)for(const i of n.children)t(i)}for(const n of o)t(n);return e}const Rn=["sum","avg","count","min","max","first","last"];function _n(o,e,t,n){const i=new AbortController,r={config:e,callbacks:n,signal:i.signal},s=document.createElement("div");return s.className="tbw-pivot-panel",s.appendChild(oe("Options",()=>Ln(t,r))),s.appendChild(oe("Row Groups",()=>wt("rowGroups",r))),s.appendChild(oe("Column Groups",()=>wt("columnGroups",r))),s.appendChild(oe("Values",()=>An(r))),s.appendChild(oe("Available Fields",()=>Tn(r))),o.appendChild(s),()=>{i.abort(),s.remove()}}function oe(o,e){const t=document.createElement("div");t.className="tbw-pivot-section";const n=document.createElement("div");n.className="tbw-pivot-section-header",n.textContent=o;const i=document.createElement("div");return i.className="tbw-pivot-section-content",i.appendChild(e()),t.appendChild(n),t.appendChild(i),t}function wt(o,e){const{config:t,callbacks:n,signal:i}=e,r=document.createElement("div");r.className="tbw-pivot-drop-zone",r.setAttribute("data-zone",o);const s=o==="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",r.appendChild(l)}else for(const l of s)r.appendChild(Sn(l,o,e));return r.addEventListener("dragover",l=>{l.preventDefault(),r.classList.add("drag-over")},{signal:i}),r.addEventListener("dragleave",()=>{r.classList.remove("drag-over")},{signal:i}),r.addEventListener("drop",l=>{l.preventDefault(),r.classList.remove("drag-over");const a=l.dataTransfer?.getData("text/plain");a&&n.onAddFieldToZone(a,o)},{signal:i}),r}function Sn(o,e,t){const{callbacks:n,signal:i}=t,r=document.createElement("div");r.className="tbw-pivot-field-chip",r.draggable=!0;const s=n.getAvailableFields().find(c=>c.field===o),l=document.createElement("span");l.className="tbw-pivot-chip-label",l.textContent=s?.header??o;const a=document.createElement("button");return a.className="tbw-pivot-chip-remove",a.innerHTML="×",a.title="Remove field",a.addEventListener("click",c=>{c.stopPropagation(),n.onRemoveFieldFromZone(o,e)},{signal:i}),r.appendChild(l),r.appendChild(a),r.addEventListener("dragstart",c=>{c.dataTransfer?.setData("text/plain",o),c.dataTransfer?.setData("source-zone",e),r.classList.add("dragging")},{signal:i}),r.addEventListener("dragend",()=>{r.classList.remove("dragging")},{signal:i}),r}function An(o){const{config:e,callbacks:t,signal:n}=o,i=document.createElement("div");i.className="tbw-pivot-drop-zone tbw-pivot-values-zone",i.setAttribute("data-zone","values");const r=e.valueFields??[];if(r.length===0){const s=document.createElement("div");s.className="tbw-pivot-placeholder",s.textContent="Drag numeric fields here for aggregation",i.appendChild(s)}else for(const s of r)i.appendChild(kn(s,o));return i.addEventListener("dragover",s=>{s.preventDefault(),i.classList.add("drag-over")},{signal:n}),i.addEventListener("dragleave",()=>{i.classList.remove("drag-over")},{signal:n}),i.addEventListener("drop",s=>{s.preventDefault(),i.classList.remove("drag-over");const l=s.dataTransfer?.getData("text/plain");l&&t.onAddValueField(l,"sum")},{signal:n}),i}function kn(o,e){const{callbacks:t,signal:n}=e,i=document.createElement("div");i.className="tbw-pivot-field-chip tbw-pivot-value-chip";const r=t.getAvailableFields().find(d=>d.field===o.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=r?.header??o.field;const a=document.createElement("select");a.className="tbw-pivot-agg-select",a.title="Aggregation function";for(const d of Rn){const h=document.createElement("option");h.value=d,h.textContent=d.toUpperCase(),h.selected=d===o.aggFunc,a.appendChild(h)}a.addEventListener("change",()=>{t.onUpdateValueAggFunc(o.field,a.value)},{signal:n});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(o.field)},{signal:n}),s.appendChild(l),s.appendChild(a),i.appendChild(s),i.appendChild(c),i}function Tn(o){const{config:e,callbacks:t,signal:n}=o,i=document.createElement("div");i.className="tbw-pivot-available-fields";const r=t.getAvailableFields(),s=new Set([...e.rowGroupFields??[],...e.columnGroupFields??[],...e.valueFields?.map(a=>a.field)??[]]),l=r.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",i.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:n}),c.addEventListener("dragend",()=>{c.classList.remove("dragging")},{signal:n}),i.appendChild(c)}return i}function Ln(o,e){const{config:t,callbacks:n,signal:i}=e,r=document.createElement("div");return r.className="tbw-pivot-options",r.appendChild(Te("Enable Pivot View",o,s=>{n.onTogglePivot(s)},i)),r.appendChild(Te("Show Row Totals",t.showTotals??!0,s=>{n.onOptionChange("showTotals",s)},i)),r.appendChild(Te("Show Grand Total",t.showGrandTotal??!0,s=>{n.onOptionChange("showGrandTotal",s)},i)),r}function Te(o,e,t,n){const i=document.createElement("label");i.className="tbw-pivot-checkbox";const r=document.createElement("input");r.type="checkbox",r.checked=e,r.addEventListener("change",()=>t(r.checked),{signal:n});const s=document.createElement("span");return s.textContent=o,i.appendChild(r),i.appendChild(s),i}function Pn(o,e,t){return e.className="pivot-group-row",e.setAttribute("data-pivot-depth",String(o.__pivotDepth??0)),e.setAttribute("role","row"),e.innerHTML="",t.columns.forEach((n,i)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(i)),r.setAttribute("role","gridcell"),i===0){const s=Number(o.__pivotIndent)||0;r.style.paddingLeft=`${s}px`;const l=String(o.__pivotRowKey),a=document.createElement("button");a.type="button",a.className="pivot-toggle",a.setAttribute("aria-label",o.__pivotExpanded?"Collapse group":"Expand group"),t.setIcon(a,t.resolveIcon(o.__pivotExpanded?"collapse":"expand")),a.addEventListener("click",h=>{h.stopPropagation(),t.onToggle(l)}),r.appendChild(a);const c=document.createElement("span");c.className="pivot-label",c.textContent=String(o.__pivotLabel??""),r.appendChild(c);const d=document.createElement("span");d.className="pivot-count",d.textContent=` (${Number(o.__pivotRowCount)||0})`,r.appendChild(d)}else{const s=o[n.field];r.textContent=s!=null?String(s):""}e.appendChild(r)}),!0}function Mn(o,e,t){return e.className="pivot-leaf-row",e.setAttribute("data-pivot-depth",String(o.__pivotDepth??0)),e.innerHTML="",t.forEach((n,i)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(i)),r.setAttribute("role","gridcell"),i===0){const s=Number(o.__pivotIndent)||0;r.style.paddingLeft=`${s+20}px`;const l=document.createElement("span");l.className="pivot-label",l.textContent=String(o.__pivotLabel??""),r.appendChild(l)}else{const s=o[n.field];r.textContent=s!=null?String(s):""}e.appendChild(r)}),!0}function In(o,e,t){return e.className="pivot-grand-total-row",e.setAttribute("role","presentation"),e.innerHTML="",t.forEach((n,i)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(i)),i===0){const s=document.createElement("span");s.className="pivot-label",s.textContent="Grand Total",r.appendChild(s)}else{const s=o[n.field];r.textContent=s!=null?String(s):""}e.appendChild(r)}),!0}const Hn='.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:18px;height:18px;margin-right:6px;border:none;background:transparent;cursor:pointer;font-size:10px;color:var(--tbw-pivot-toggle-color, var(--tbw-color-fg-muted));border-radius:var(--tbw-border-radius);transition:background .15s,color .15s}.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:12px;padding:12px;height:100%;overflow-y:auto;font-size:13px}.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:8px 12px;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:8px}.tbw-pivot-toggle-wrapper{display:flex;align-items:center}.tbw-pivot-toggle-label{display:flex;align-items:center;gap:8px;cursor:pointer}.tbw-pivot-toggle-label input{width:16px;height:16px;cursor:pointer}.tbw-pivot-drop-zone{min-height:60px;padding:8px;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:6px;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:8px;text-align:center;width:100%}.tbw-pivot-field-chip{display:inline-flex;align-items:center;gap:6px;padding:4px 8px;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:12px;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:16px;height:16px;padding:0;border:none;background:transparent;color:var(--tbw-color-fg-muted);font-size:14px;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:4px 8px}.tbw-pivot-value-label-wrapper{display:flex;align-items:center;gap:8px;flex:1;min-width:0}.tbw-pivot-agg-select{padding:2px 4px;font-size:11px;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:6px;min-height:40px}.tbw-pivot-options{display:flex;flex-direction:column;gap:8px}.tbw-pivot-checkbox{display:flex;align-items:center;gap:8px;cursor:pointer}.tbw-pivot-checkbox input{width:14px;height:14px;cursor:pointer}';class Y extends L{name="pivot";version="1.0.0";static PANEL_ID="pivot";get defaultConfig(){return{active:!0,showTotals:!0,showGrandTotal:!0}}isActive=!1;hasInitialized=!1;pivotResult=null;fieldHeaderMap=new Map;expandedKeys=new Set;defaultExpanded=!0;originalColumns=[];panelContainer=null;grandTotalFooter=null;hasValidPivotConfig(){return(this.config.valueFields?.length??0)>0}detach(){this.isActive=!1,this.hasInitialized=!1,this.pivotResult=null,this.fieldHeaderMap.clear(),this.originalColumns=[],this.panelContainer=null,this.cleanupGrandTotalFooter()}getToolPanel(){return{id:Y.PANEL_ID,title:"Pivot",icon:"⊞",tooltip:"Configure pivot table",order:90,render:e=>this.renderPanel(e)}}processRows(e){if(!this.hasInitialized&&this.config.active!==!1&&this.hasValidPivotConfig()&&(this.hasInitialized=!0,this.isActive=!0),!this.isActive)return[...e];const t=mn(this.config);if(t.length>0)return this.warn(`Config errors: ${t.join(", ")}`),[...e];if(this.buildFieldHeaderMap(),this.defaultExpanded=this.config.defaultExpanded??!0,this.expandedKeys.size===0&&this.defaultExpanded&&this.pivotResult){const r=ke(this.pivotResult.rows);for(const s of r)this.expandedKeys.add(s)}if(this.pivotResult=vn(e,this.config),this.expandedKeys.size===0&&this.defaultExpanded){const r=ke(this.pivotResult.rows);for(const s of r)this.expandedKeys.add(s)}const n=this.config.indentWidth??20;return En(this.pivotResult.rows,this.expandedKeys,this.defaultExpanded).map(r=>({__pivotRowKey:r.rowKey,__pivotLabel:r.rowLabel,__pivotDepth:r.depth,__pivotIsGroup:r.isGroup,__pivotHasChildren:!!r.children?.length,__pivotExpanded:this.expandedKeys.has(r.rowKey),__pivotRowCount:r.rowCount??0,__pivotIndent:r.depth*n,__pivotTotal:r.total,...r.values}))}processColumns(e){if(!this.isActive||!this.pivotResult)return[...e];const t=[],n=(this.config.rowGroupFields??[]).map(i=>this.fieldHeaderMap.get(i)??i).join(" / ");t.push({field:"__pivotLabel",header:n||"Group",width:200});for(const i of this.pivotResult.columnKeys)for(const r of this.config.valueFields??[]){const s=Ae([i],r.field),l=r.header||this.fieldHeaderMap.get(r.field)||r.field;t.push({field:s,header:`${i} - ${l} (${r.aggFunc})`,width:120,type:"number"})}return this.config.showTotals&&t.push({field:"__pivotTotal",header:"Total",width:100,type:"number"}),t}renderRow(e,t){const n=e;return n.__pivotRowKey&&n.__pivotHasChildren?Pn(n,t,{columns:this.gridColumns,onToggle:i=>this.toggle(i),resolveIcon:i=>this.resolveIcon(i),setIcon:(i,r)=>this.setIcon(i,r)}):n.__pivotRowKey!==void 0&&this.isActive?Mn(n,t,this.gridColumns):(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="")}afterRender(){this.isActive&&this.config.showGrandTotal&&this.pivotResult?this.renderGrandTotalFooter():this.cleanupGrandTotalFooter()}renderGrandTotalFooter(){if(!this.pivotResult)return;const e=this.shadowRoot;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 n={__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals};In(n,this.grandTotalFooter,this.gridColumns)}cleanupGrandTotalFooter(){this.grandTotalFooter&&(this.grandTotalFooter.remove(),this.grandTotalFooter=null)}toggle(e){this.expandedKeys.has(e)?this.expandedKeys.delete(e):this.expandedKeys.add(e),this.requestRender()}expand(e){this.expandedKeys.add(e),this.requestRender()}collapse(e){this.expandedKeys.delete(e),this.requestRender()}expandAll(){if(this.pivotResult){const e=ke(this.pivotResult.rows);for(const t of e)this.expandedKeys.add(t);this.requestRender()}}collapseAll(){this.expandedKeys.clear(),this.requestRender()}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(Y.PANEL_ID)}hidePanel(){this.grid.closeToolPanel()}togglePanel(){this.grid.toggleToolPanel(Y.PANEL_ID)}isPanelVisible(){return this.grid.activeToolPanel===Y.PANEL_ID}get gridColumns(){return this.grid.columns??[]}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(){const e=this.grid;try{const t=e.getAllColumns?.()??e.columns??[];return this.originalColumns=t.filter(n=>!n.field.startsWith("__pivot")).map(n=>({field:n.field,header:n.header??n.field})),this.originalColumns}catch{return[]}}renderPanel(e){this.panelContainer=e,this.originalColumns.length===0&&this.captureOriginalColumns();const t={onTogglePivot:n=>{n?this.enablePivot():this.disablePivot(),this.refreshPanel()},onAddFieldToZone:(n,i)=>this.addFieldToZone(n,i),onRemoveFieldFromZone:(n,i)=>this.removeFieldFromZone(n,i),onAddValueField:(n,i)=>this.addValueField(n,i),onRemoveValueField:n=>this.removeValueField(n),onUpdateValueAggFunc:(n,i)=>this.updateValueAggFunc(n,i),onOptionChange:(n,i)=>{this.config[n]=i,this.isActive&&this.refresh()},getAvailableFields:()=>this.getAvailableFields()};return _n(e,this.config,this.isActive,t)}refreshPanel(){this.panelContainer&&(this.panelContainer.innerHTML="",this.renderPanel(this.panelContainer))}addFieldToZone(e,t){if(t==="rowGroups"){const n=this.config.rowGroupFields??[];n.includes(e)||(this.config.rowGroupFields=[...n,e])}else{const n=this.config.columnGroupFields??[];n.includes(e)||(this.config.columnGroupFields=[...n,e])}this.removeFromOtherZones(e,t),this.isActive&&this.refresh(),this.refreshPanel()}removeFieldFromZone(e,t){t==="rowGroups"?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(n=>n!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(n=>n!==e),this.isActive&&this.refresh(),this.refreshPanel()}removeFromOtherZones(e,t){t!=="rowGroups"&&(this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(n=>n!==e)),t!=="columnGroups"&&(this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(n=>n!==e)),t!=="values"&&(this.config.valueFields=(this.config.valueFields??[]).filter(n=>n.field!==e))}addValueField(e,t){const n=this.config.valueFields??[];n.some(i=>i.field===e)||(this.config.valueFields=[...n,{field:e,aggFunc:t}]),this.removeFromOtherZones(e,"values"),this.isActive&&this.refresh(),this.refreshPanel()}removeValueField(e){this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e),this.isActive&&this.refresh(),this.refreshPanel()}updateValueAggFunc(e,t){const n=this.config.valueFields??[],i=n.findIndex(r=>r.field===e);i>=0&&(n[i]={...n[i],aggFunc:t},this.config.valueFields=[...n]),this.isActive&&this.refresh()}styles=Hn}function Nn(o){const e=o.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}function bt(o,e,t){if(e===t||e<0||e>=o.length||t<0||t>o.length)return o;const n=[...o],[i]=n.splice(e,1);return n.splice(t,0,i),n}const Dn='.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}';class On extends L{name="reorder";version="1.0.0";get defaultConfig(){return{animation:!0,animationDuration:200}}isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;attach(e){super.attach(e),e.addEventListener("column-reorder-request",t=>{const n=t.detail;n?.field&&typeof n.toIndex=="number"&&this.moveColumn(n.field,n.toIndex)},{signal:this.disconnectSignal})}detach(){this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null}afterRender(){const e=this.shadowRoot;if(!e)return;e.querySelectorAll(".header-row > .cell").forEach(n=>{const i=n,r=i.getAttribute("data-field");if(!r)return;const s=this.columns.find(d=>d.field===r),c=!this.grid.queryPlugins({type:he.CAN_MOVE_COLUMN,context:s}).includes(!1);if(!s||!Nn(s)||!c){i.draggable=!1;return}i.draggable=!0,!i.getAttribute("data-dragstart-bound")&&(i.setAttribute("data-dragstart-bound","true"),i.addEventListener("dragstart",d=>{const f=this.getColumnOrder().indexOf(r);this.isDragging=!0,this.draggedField=r,this.draggedIndex=f,d.dataTransfer&&(d.dataTransfer.effectAllowed="move",d.dataTransfer.setData("text/plain",r)),i.classList.add("dragging")}),i.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,e.querySelectorAll(".header-row > .cell").forEach(d=>{d.classList.remove("dragging","drop-target","drop-before","drop-after")})}),i.addEventListener("dragover",d=>{if(d.preventDefault(),!this.isDragging||this.draggedField===r)return;const h=i.getBoundingClientRect(),f=h.left+h.width/2,p=this.getColumnOrder().indexOf(r);this.dropIndex=d.clientX<f?p:p+1,i.classList.add("drop-target"),i.classList.toggle("drop-before",d.clientX<f),i.classList.toggle("drop-after",d.clientX>=f)}),i.addEventListener("dragleave",()=>{i.classList.remove("drop-target","drop-before","drop-after")}),i.addEventListener("drop",d=>{d.preventDefault();const h=this.draggedField,f=this.draggedIndex,u=this.dropIndex;if(!this.isDragging||h===null||f===null||u===null)return;const p=u>f?u-1:u,g=this.getColumnOrder(),w=bt(g,f,p),b={field:h,fromIndex:f,toIndex:p,columnOrder:w};this.grid.setColumnOrder(w),this.emit("column-move",b),this.grid.requestStateChange?.()}))})}getColumnOrder(){return this.grid.getColumnOrder()}moveColumn(e,t){const n=this.getColumnOrder(),i=n.indexOf(e);if(i===-1)return;const r=bt(n,i,t);this.grid.setColumnOrder(r),this.emit("column-move",{field:e,fromIndex:i,toIndex:t,columnOrder:r}),this.grid.requestStateChange?.()}setColumnOrder(e){this.grid.setColumnOrder(e),this.grid.requestStateChange?.()}resetColumnOrder(){const e=this.columns.map(t=>t.field);this.grid.setColumnOrder(e),this.grid.requestStateChange?.()}styles=Dn}function ie(o){return{startRow:Math.min(o.startRow,o.endRow),startCol:Math.min(o.startCol,o.endCol),endRow:Math.max(o.startRow,o.endRow),endCol:Math.max(o.startCol,o.endCol)}}function zn(o){const e=ie(o);return{from:{row:e.startRow,col:e.startCol},to:{row:e.endRow,col:e.endCol}}}function Le(o){return o.map(zn)}function qn(o,e,t){const n=ie(t);return o>=n.startRow&&o<=n.endRow&&e>=n.startCol&&e<=n.endCol}function mt(o,e,t){return t.some(n=>qn(o,e,n))}function Fn(o){const e=[],t=ie(o);for(let n=t.startRow;n<=t.endRow;n++)for(let i=t.startCol;i<=t.endCol;i++)e.push({row:n,col:i});return e}function Bn(o){const e=new Map;for(const t of o)for(const n of Fn(t))e.set(`${n.row},${n.col}`,n);return[...e.values()]}function Pe(o,e){return{startRow:o.row,startCol:o.col,endRow:e.row,endCol:e.col}}const $n=':host .selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}:host .data-grid-row.row-focus{background-color:var(--tbw-focus-background, rgba(from var(--tbw-color-accent) r g b / 12%))}:host([data-selection-mode="row"]) .cell-focus{outline:none}:host .data-grid-row>.cell.selected{background-color:var(--tbw-range-selection-bg)}:host .data-grid-row>.cell.selected.top{border-top:2px solid var(--tbw-range-border-color)}:host .data-grid-row>.cell.selected.bottom{border-bottom:2px solid var(--tbw-range-border-color)}:host .data-grid-row>.cell.selected.first{border-left:2px solid var(--tbw-range-border-color)}:host .data-grid-row>.cell.selected.last{border-right:2px solid var(--tbw-range-border-color)}';function Gn(o,e,t){if(o==="cell"&&e.selectedCell)return{mode:o,ranges:[{from:{row:e.selectedCell.row,col:e.selectedCell.col},to:{row:e.selectedCell.row,col:e.selectedCell.col}}]};if(o==="row"&&e.selected.size>0){const n=[...e.selected].map(i=>({from:{row:i,col:0},to:{row:i,col:t-1}}));return{mode:o,ranges:n}}return o==="range"&&e.ranges.length>0?{mode:o,ranges:Le(e.ranges)}:{mode:o,ranges:[]}}class Kn extends L{name="selection";version="1.0.0";get defaultConfig(){return{mode:"cell"}}selected=new Set;lastSelected=null;anchor=null;ranges=[];activeRange=null;cellAnchor=null;isDragging=!1;selectedCell=null;detach(){this.selected.clear(),this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.isDragging=!1,this.selectedCell=null}onCellClick(e){const{rowIndex:t,colIndex:n,originalEvent:i}=e,{mode:r}=this.config;if(r==="cell")return this.selectedCell={row:t,col:n},this.emit("selection-change",this.#r()),this.requestAfterRender(),!1;if(r==="row")return this.selected.clear(),this.selected.add(t),this.lastSelected=t,this.emit("selection-change",this.#r()),this.requestAfterRender(),!1;if(r==="range"){const s=i.shiftKey,l=i.ctrlKey||i.metaKey;if(s&&this.cellAnchor){const a=Pe(this.cellAnchor,{row:t,col:n});l?this.ranges.length>0?this.ranges[this.ranges.length-1]=a:this.ranges.push(a):this.ranges=[a],this.activeRange=a}else if(l){const a={startRow:t,startCol:n,endRow:t,endCol:n};this.ranges.push(a),this.activeRange=a,this.cellAnchor={row:t,col:n}}else{const a={startRow:t,startCol:n,endRow:t,endCol:n};this.ranges=[a],this.activeRange=a,this.cellAnchor={row:t,col:n}}return this.emit("selection-change",this.#r()),this.requestAfterRender(),!1}return!1}onKeyDown(e){const{mode:t}=this.config,i=["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.#r()),this.requestAfterRender(),!0;if(t==="cell"&&i)return queueMicrotask(()=>{this.selectedCell={row:this.grid.focusRow,col:this.grid.focusCol},this.emit("selection-change",this.#r()),this.requestAfterRender()}),!1;if(t==="row"&&(e.key==="ArrowUp"||e.key==="ArrowDown"))return queueMicrotask(()=>{this.selected.clear(),this.selected.add(this.grid.focusRow),this.lastSelected=this.grid.focusRow,this.emit("selection-change",this.#r()),this.requestAfterRender()}),!1;if(t==="range"&&i){const r=e.shiftKey;return queueMicrotask(()=>{const s=this.grid.focusRow,l=this.grid.focusCol;if(r){this.cellAnchor||(this.cellAnchor={row:s,col:l});const a=Pe(this.cellAnchor,{row:s,col:l});this.ranges=[a],this.activeRange=a}else this.ranges=[],this.activeRange=null,this.cellAnchor={row:s,col:l};this.emit("selection-change",this.#r()),this.requestAfterRender()}),!1}if(t==="range"&&e.key==="a"&&(e.ctrlKey||e.metaKey)){const r=this.rows.length,s=this.columns.length;if(r>0&&s>0){const l={startRow:0,startCol:0,endRow:r-1,endCol:s-1};return this.ranges=[l],this.activeRange=l,this.emit("selection-change",this.#r()),this.requestAfterRender(),!0}}return!1}onCellMouseDown(e){if(this.config.mode!=="range"||e.rowIndex===void 0||e.colIndex===void 0||e.rowIndex<0||e.originalEvent.shiftKey&&this.cellAnchor)return;this.isDragging=!0;const t=e.rowIndex,n=e.colIndex;this.cellAnchor={row:t,col:n},e.originalEvent.ctrlKey||e.originalEvent.metaKey||(this.ranges=[]);const r={startRow:t,startCol:n,endRow:t,endCol:n};return this.ranges.push(r),this.activeRange=r,this.emit("selection-change",this.#r()),this.requestAfterRender(),!0}onCellMouseMove(e){if(this.config.mode!=="range"||!this.isDragging||!this.cellAnchor||e.rowIndex===void 0||e.colIndex===void 0||e.rowIndex<0)return;const t=Pe(this.cellAnchor,{row:e.rowIndex,col:e.colIndex});return this.ranges.length>0?this.ranges[this.ranges.length-1]=t:this.ranges.push(t),this.activeRange=t,this.emit("selection-change",this.#r()),this.requestAfterRender(),!0}onCellMouseUp(e){if(this.config.mode==="range"&&this.isDragging)return this.isDragging=!1,!0}#o(){const e=this.shadowRoot;if(!e)return;const{mode:t}=this.config;e.querySelectorAll(".cell").forEach(r=>{r.classList.remove("selected","top","bottom","first","last")});const i=e.querySelectorAll(".data-grid-row");if(i.forEach(r=>{r.classList.remove("selected","row-focus")}),t==="row"&&(e.querySelectorAll(".cell-focus").forEach(r=>r.classList.remove("cell-focus")),i.forEach(r=>{const s=r.querySelector(".cell[data-row]"),l=parseInt(s?.getAttribute("data-row")??"-1",10);l>=0&&this.selected.has(l)&&r.classList.add("selected","row-focus")})),t==="range"&&this.ranges.length>0){const r=this.activeRange?ie(this.activeRange):null;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&&mt(a,c,this.ranges)&&(l.classList.add("selected"),l.classList.remove("cell-focus"),r&&(a===r.startRow&&l.classList.add("top"),a===r.endRow&&l.classList.add("bottom"),c===r.startCol&&l.classList.add("first"),c===r.endCol&&l.classList.add("last")))})}t==="cell"&&this.selectedCell&&e.querySelectorAll(".cell-focus").forEach(r=>r.classList.remove("cell-focus"))}afterRender(){const e=this.shadowRoot;if(!e)return;const t=e.children[0],{mode:n}=this.config;this.grid.setAttribute("data-selection-mode",n),t&&t.classList.toggle("selecting",this.isDragging),this.#o()}onScrollRender(){this.#o()}getSelectedCell(){return this.selectedCell}getSelectedRows(){return[...this.selected]}getRanges(){return Le(this.ranges)}getSelectedCells(){return Bn(this.ranges)}isCellSelected(e,t){return mt(e,t,this.ranges)}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:Le(this.ranges)}),this.requestAfterRender()}#r(){return Gn(this.config.mode,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges},this.columns.length)}styles=$n}function re(o,e){return Math.floor(o/e)}function Vn(o,e){return{start:o*e,end:(o+1)*e}}function Wn(o,e,t){const n=re(o,t),i=re(e-1,t),r=[];for(let s=n;s<=i;s++)r.push(s);return r}async function vt(o,e,t,n){const i=Vn(e,t);return o.getRows({startRow:i.start,endRow:i.end,sortModel:n.sortModel,filterModel:n.filterModel})}function jn(o,e,t){const n=re(o,e),i=t.get(n);if(!i)return;const r=o%e;return i[r]}const Un=100;class Xn extends L{name="serverSide";version="1.0.0";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,n={startRow:e.virtualization.start,endRow:e.virtualization.end},i=Wn(n.startRow,n.endRow,t);for(const r of i)if(!(this.loadedBlocks.has(r)||this.loadingBlocks.has(r))){if(this.loadingBlocks.size>=(this.config.maxConcurrentRequests??2))break;this.loadingBlocks.add(r),vt(this.dataSource,r,t,{}).then(s=>{this.loadedBlocks.set(r,s.rows),this.totalRowCount=s.totalRowCount,this.loadingBlocks.delete(r),this.requestRender(),this.loadRequiredBlocks()}).catch(()=>{this.loadingBlocks.delete(r)})}}processRows(e){if(!this.dataSource)return[...e];const t=[];for(let n=0;n<this.totalRowCount;n++){const i=jn(n,this.config.cacheBlockSize??100,this.loadedBlocks);t.push(i??{__loading:!0,__index:n})}return t}onScroll(e){this.dataSource&&(this.loadRequiredBlocks(),this.scrollDebounceTimer&&clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=setTimeout(()=>{this.loadRequiredBlocks()},Un))}setDataSource(e){this.dataSource=e,this.loadedBlocks.clear(),this.loadingBlocks.clear();const t=this.config.cacheBlockSize??100;vt(e,0,t,{}).then(n=>{this.loadedBlocks.set(0,n.rows),this.totalRowCount=n.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,n=re(e,t);return this.loadedBlocks.has(n)}getLoadedBlockCount(){return this.loadedBlocks.size}}function Me(o,e,t){return o.id!==void 0?String(o.id):t?`${t}-${e}`:String(e)}function Ct(o,e,t,n=null,i=0){const r=e.childrenField??"children",s=[];for(let l=0;l<o.length;l++){const a=o[l],c=Me(a,l,n),d=a[r],h=Array.isArray(d)&&d.length>0,f=t.has(c);if(s.push({key:c,data:a,depth:i,hasChildren:h,isExpanded:f,parentKey:n}),h&&f){const u=Ct(d,e,t,c,i+1);s.push(...u)}}return s}function yt(o,e){const t=new Set(o);return t.has(e)?t.delete(e):t.add(e),t}function Ie(o,e,t=null,n=0){const i=e.childrenField??"children",r=new Set;for(let s=0;s<o.length;s++){const l=o[s],a=Me(l,s,t),c=l[i];if(Array.isArray(c)&&c.length>0){r.add(a);const d=Ie(c,e,a,n+1);for(const h of d)r.add(h)}}return r}function Yn(){return new Set}function xt(o,e,t,n=null,i=0){const r=t.childrenField??"children";for(let s=0;s<o.length;s++){const l=o[s],a=Me(l,s,n);if(a===e)return[a];const c=l[r];if(Array.isArray(c)&&c.length>0){const d=xt(c,e,t,a,i+1);if(d)return[a,...d]}}return null}function Zn(o,e,t,n){const i=xt(o,e,t);if(!i)return n;const r=new Set(n);for(let s=0;s<i.length-1;s++)r.add(i[s]);return r}function Et(o,e="children"){if(!Array.isArray(o)||o.length===0)return!1;for(const t of o)if(t&&Array.isArray(t[e])&&t[e].length>0)return!0;return!1}function Jn(o){if(!Array.isArray(o)||o.length===0)return null;const e=["children","items","nodes","subRows","nested"];for(const t of o)if(!(!t||typeof t!="object")){for(const n of e)if(Array.isArray(t[n])&&t[n].length>0)return n}return null}const Qn=".tree-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;transition:transform .2s}.tree-toggle:hover{color:var(--tbw-tree-accent, var(--tbw-color-accent))}";class ei extends L{name="tree";version="1.0.0";get defaultConfig(){return{childrenField:"children",autoDetect:!0,defaultExpanded:!1,indentWidth:20,showExpandIcons:!0}}expandedKeys=new Set;initialExpansionDone=!1;flattenedRows=[];rowKeyMap=new Map;detach(){this.expandedKeys.clear(),this.initialExpansionDone=!1,this.flattenedRows=[],this.rowKeyMap.clear()}detect(e){if(!this.config.autoDetect)return!1;const t=this.config.childrenField??Jn(e)??"children";return Et(e,t)}processRows(e){const t=this.config.childrenField??"children";if(!Et(e,t))return this.flattenedRows=[],this.rowKeyMap.clear(),[...e];this.config.defaultExpanded&&!this.initialExpansionDone&&(this.expandedKeys=Ie(e,this.config),this.initialExpansionDone=!0),this.flattenedRows=Ct(e,this.config,this.expandedKeys),this.rowKeyMap.clear();for(const n of this.flattenedRows)this.rowKeyMap.set(n.key,n);return this.flattenedRows.map(n=>({...n.data,__treeKey:n.key,__treeDepth:n.depth,__treeHasChildren:n.hasChildren,__treeExpanded:n.isExpanded}))}processColumns(e){if(this.flattenedRows.length===0)return[...e];const t=this.config.indentWidth??20,n=this.config.showExpandIcons??!0,i=[...e];if(i.length>0){const r={...i[0]},s=r.viewRenderer;if(s?.__treeWrapped)return i;const l=a=>{const{value:c,row:d,column:h}=a,f=d.__treeDepth??0,u=d.__treeHasChildren??!1,p=d.__treeExpanded??!1,g=document.createElement("span");if(g.style.display="flex",g.style.alignItems="center",g.style.paddingLeft=`${f*t}px`,u&&n){const b=document.createElement("span");b.className="tree-toggle",this.setIcon(b,this.resolveIcon(p?"collapse":"expand")),b.style.cursor="pointer",b.style.marginRight="4px",b.style.fontSize="10px",b.setAttribute("data-tree-key",d.__treeKey),g.appendChild(b)}else if(n){const b=document.createElement("span");b.style.width="14px",b.style.display="inline-block",g.appendChild(b)}const w=document.createElement("span");if(s){const b=s(a);b instanceof Node?w.appendChild(b):w.textContent=String(b??c??"")}else w.textContent=String(c??"");return g.appendChild(w),g};l.__treeWrapped=!0,r.viewRenderer=l,i[0]=r}return i}onCellClick(e){const t=e.originalEvent?.target;if(!t?.classList.contains("tree-toggle"))return!1;const n=t.getAttribute("data-tree-key");if(!n)return!1;const i=this.rowKeyMap.get(n);return i?(this.expandedKeys=yt(this.expandedKeys,n),this.emit("tree-expand",{key:n,row:i.data,expanded:this.expandedKeys.has(n),depth:i.depth}),this.requestRender(),!0):!1}expand(e){this.expandedKeys.add(e),this.requestRender()}collapse(e){this.expandedKeys.delete(e),this.requestRender()}toggle(e){this.expandedKeys=yt(this.expandedKeys,e),this.requestRender()}expandAll(){this.expandedKeys=Ie(this.rows,this.config),this.requestRender()}collapseAll(){this.expandedKeys=Yn(),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=Zn(this.rows,e,this.config,this.expandedKeys),this.requestRender()}styles=Qn}function ti(o,e,t){const n=[...o.undoStack,e];for(;n.length>t;)n.shift();return{undoStack:n,redoStack:[]}}function Rt(o){if(o.undoStack.length===0)return{newState:o,action:null};const e=[...o.undoStack],t=e.pop();return t?{newState:{undoStack:e,redoStack:[...o.redoStack,t]},action:t}:{newState:o,action:null}}function _t(o){if(o.redoStack.length===0)return{newState:o,action:null};const e=[...o.redoStack],t=e.pop();return t?{newState:{undoStack:[...o.undoStack,t],redoStack:e},action:t}:{newState:o,action:null}}function oi(o){return o.undoStack.length>0}function ni(o){return o.redoStack.length>0}function ii(){return{undoStack:[],redoStack:[]}}function ri(o,e,t,n){return{type:"cell-edit",rowIndex:o,field:e,oldValue:t,newValue:n,timestamp:Date.now()}}class si extends L{name="undoRedo";version="1.0.0";get defaultConfig(){return{maxHistorySize:100}}undoStack=[];redoStack=[];detach(){this.undoStack=[],this.redoStack=[]}onKeyDown(e){const t=(e.ctrlKey||e.metaKey)&&e.key==="z"&&!e.shiftKey,n=(e.ctrlKey||e.metaKey)&&(e.key==="y"||e.key==="z"&&e.shiftKey);if(t){const i=Rt({undoStack:this.undoStack,redoStack:this.redoStack});if(i.action){const r=this.rows;r[i.action.rowIndex]&&(r[i.action.rowIndex][i.action.field]=i.action.oldValue),this.undoStack=i.newState.undoStack,this.redoStack=i.newState.redoStack,this.emit("undo",{action:i.action,type:"undo"}),this.requestRender()}return!0}if(n){const i=_t({undoStack:this.undoStack,redoStack:this.redoStack});if(i.action){const r=this.rows;r[i.action.rowIndex]&&(r[i.action.rowIndex][i.action.field]=i.action.newValue),this.undoStack=i.newState.undoStack,this.redoStack=i.newState.redoStack,this.emit("redo",{action:i.action,type:"redo"}),this.requestRender()}return!0}return!1}recordEdit(e,t,n,i){const r=ri(e,t,n,i),s=ti({undoStack:this.undoStack,redoStack:this.redoStack},r,this.config.maxHistorySize??100);this.undoStack=s.undoStack,this.redoStack=s.redoStack}undo(){const e=Rt({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=_t({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 oi({undoStack:this.undoStack,redoStack:this.redoStack})}canRedo(){return ni({undoStack:this.undoStack,redoStack:this.redoStack})}clearHistory(){const e=ii();this.undoStack=e.undoStack,this.redoStack=e.redoStack}getUndoStack(){return[...this.undoStack]}getRedoStack(){return[...this.redoStack]}}const li='.tbw-visibility-content{display:flex;flex-direction:column;height:100%}.tbw-visibility-list{flex:1;overflow-y:auto;padding:8px}.tbw-visibility-row{display:flex;align-items:center;gap:8px;padding:6px 4px;cursor:pointer;font-size:13px;border-radius:var(--tbw-border-radius, 4px);position:relative}.tbw-visibility-row:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover, #f3f4f6))}.tbw-visibility-row input[type=checkbox]{cursor:pointer}.tbw-visibility-row.locked span{color:var(--tbw-color-fg-muted, #888)}.tbw-visibility-handle{cursor:grab;color:var(--tbw-color-fg-muted, #888);font-size:10px;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, #1f2937)}.tbw-visibility-label{display:flex;align-items:center;gap:8px;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-reorder-indicator, var(--tbw-color-accent, #3b82f6))}.tbw-visibility-row.drop-after:after{content:"";position:absolute;left:0;right:0;bottom:0;height:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent, #3b82f6))}.tbw-visibility-show-all{margin:8px;padding:8px 12px;border:1px solid var(--tbw-visibility-border, var(--tbw-color-border, #e5e7eb));border-radius:var(--tbw-border-radius, 4px);background:var(--tbw-visibility-btn-bg, var(--tbw-color-header-bg, #f9fafb));color:var(--tbw-color-fg, #1f2937);cursor:pointer;font-size:13px}.tbw-visibility-show-all:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover, #f3f4f6))}';function St(o){const e=o.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}class Z extends L{name="visibility";version="1.0.0";static PANEL_ID="columns";get defaultConfig(){return{allowHideAll:!1}}columnListElement=null;isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;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(Z.PANEL_ID)}hide(){this.grid.closeToolPanel()}toggle(){this.grid.toggleToolPanel(Z.PANEL_ID)}isColumnVisible(e){return this.grid.isColumnVisible(e)}setColumnVisible(e,t){this.grid.setColumnVisible(e,t)}getVisibleColumns(){return this.grid.getAllColumns().filter(t=>t.visible).map(t=>t.field)}getHiddenColumns(){return this.grid.getAllColumns().filter(t=>!t.visible).map(t=>t.field)}showAll(){this.grid.showAllColumns()}toggleColumn(e){this.grid.toggleColumnVisibility(e)}showColumn(e){this.grid.setColumnVisible(e,!0)}hideColumn(e){this.grid.setColumnVisible(e,!1)}getAllColumns(){return this.grid.getAllColumns()}isPanelVisible(){return this.grid.activeToolPanel===Z.PANEL_ID}renderPanelContent(e){const t=this.grid,n=document.createElement("div");n.className="tbw-visibility-content";const i=document.createElement("div");i.className="tbw-visibility-list",n.appendChild(i);const r=document.createElement("button");return r.className="tbw-visibility-show-all",r.textContent="Show All",r.addEventListener("click",()=>{t.showAllColumns(),this.rebuildToggles(i)}),n.appendChild(r),this.columnListElement=i,this.rebuildToggles(i),e.appendChild(n),()=>{this.columnListElement=null,n.remove()}}hasReorderPlugin(){const e=this.grid?.getPluginByName?.("reorder");return!!(e&&typeof e.moveColumn=="function")}rebuildToggles(e){const t=this.grid,n=this.hasReorderPlugin();e.innerHTML="";const i=t.getAllColumns();for(let r=0;r<i.length;r++){const s=i[r],l=s.header||s.field,a=document.createElement("div");a.className=s.lockVisible?"tbw-visibility-row locked":"tbw-visibility-row",a.setAttribute("data-field",s.field),a.setAttribute("data-index",String(r)),n&&St(s)&&(a.draggable=!0,a.classList.add("reorderable"),this.setupDragListeners(a,s.field,r,e));const c=document.createElement("label");c.className="tbw-visibility-label";const d=document.createElement("input");d.type="checkbox",d.checked=s.visible,d.disabled=s.lockVisible??!1,d.addEventListener("change",()=>{t.toggleColumnVisibility(s.field),setTimeout(()=>this.rebuildToggles(e),0)});const h=document.createElement("span");if(h.textContent=l,c.appendChild(d),c.appendChild(h),n&&St(s)){const f=document.createElement("span");f.className="tbw-visibility-handle",this.setIcon(f,this.resolveIcon("dragHandle")),f.title="Drag to reorder",a.appendChild(f)}a.appendChild(c),e.appendChild(a)}}setupDragListeners(e,t,n,i){e.addEventListener("dragstart",r=>{this.isDragging=!0,this.draggedField=t,this.draggedIndex=n,r.dataTransfer&&(r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",t)),e.classList.add("dragging")}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,i.querySelectorAll(".tbw-visibility-row").forEach(r=>{r.classList.remove("dragging","drop-target","drop-before","drop-after")})}),e.addEventListener("dragover",r=>{if(r.preventDefault(),!this.isDragging||this.draggedField===t)return;const s=e.getBoundingClientRect(),l=s.top+s.height/2;this.dropIndex=r.clientY<l?n:n+1,i.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",r.clientY<l),e.classList.toggle("drop-after",r.clientY>=l)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",r=>{r.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={field:s,fromIndex:l,toIndex:c};this.emit("column-reorder-request",d),setTimeout(()=>{this.rebuildToggles(i)},0)}})}styles=li}y.BaseGridPlugin=L,y.ClipboardPlugin=Co,y.ColumnVirtualizationPlugin=Ro,y.ContextMenuPlugin=Ao,y.DEFAULT_GRID_ICONS=I,y.DGEvents=fo,y.DataGridElement=G,y.ExportPlugin=Mo,y.FilteringPlugin=F,y.FitModeEnum=K,y.GridCSSVars=ho,y.GridClasses=M,y.GridDataAttrs=ee,y.GridElement=G,y.GridSelectors=uo,y.GroupingColumnsPlugin=Vo,y.GroupingRowsPlugin=Jo,y.MasterDetailPlugin=rn,y.MultiSortPlugin=dn,y.PLUGIN_QUERIES=he,y.PinnedColumnsPlugin=fn,y.PinnedRowsPlugin=wn,y.PivotPlugin=Y,y.PluginEvents=po,y.PluginManager=je,y.ReorderPlugin=On,y.SelectionPlugin=Kn,y.ServerSidePlugin=Xn,y.TreePlugin=ei,y.UndoRedoPlugin=si,y.VisibilityPlugin=Z,y.aggregatorRegistry=N,y.getAggregator=Xe,y.getValueAggregator=pe,y.listAggregators=mo,y.registerAggregator=wo,y.runAggregator=ge,y.runValueAggregator=go,y.unregisterAggregator=bo,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})}));
|
|
93
93
|
//# sourceMappingURL=grid.all.umd.js.map
|