@toolbox-web/grid 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/all.d.ts +3518 -0
  2. package/all.js +3762 -0
  3. package/all.js.map +1 -0
  4. package/index.d.ts +2367 -0
  5. package/index.js +3105 -0
  6. package/index.js.map +1 -0
  7. package/lib/plugins/clipboard/index.js +365 -0
  8. package/lib/plugins/clipboard/index.js.map +1 -0
  9. package/lib/plugins/column-virtualization/index.js +255 -0
  10. package/lib/plugins/column-virtualization/index.js.map +1 -0
  11. package/lib/plugins/context-menu/index.js +341 -0
  12. package/lib/plugins/context-menu/index.js.map +1 -0
  13. package/lib/plugins/export/index.js +305 -0
  14. package/lib/plugins/export/index.js.map +1 -0
  15. package/lib/plugins/filtering/index.js +759 -0
  16. package/lib/plugins/filtering/index.js.map +1 -0
  17. package/lib/plugins/grouping-columns/index.js +283 -0
  18. package/lib/plugins/grouping-columns/index.js.map +1 -0
  19. package/lib/plugins/grouping-rows/index.js +494 -0
  20. package/lib/plugins/grouping-rows/index.js.map +1 -0
  21. package/lib/plugins/master-detail/index.js +303 -0
  22. package/lib/plugins/master-detail/index.js.map +1 -0
  23. package/lib/plugins/multi-sort/index.js +270 -0
  24. package/lib/plugins/multi-sort/index.js.map +1 -0
  25. package/lib/plugins/pinned-columns/index.js +221 -0
  26. package/lib/plugins/pinned-columns/index.js.map +1 -0
  27. package/lib/plugins/pinned-rows/index.js +459 -0
  28. package/lib/plugins/pinned-rows/index.js.map +1 -0
  29. package/lib/plugins/pivot/index.js +326 -0
  30. package/lib/plugins/pivot/index.js.map +1 -0
  31. package/lib/plugins/reorder/index.js +260 -0
  32. package/lib/plugins/reorder/index.js.map +1 -0
  33. package/lib/plugins/selection/index.js +426 -0
  34. package/lib/plugins/selection/index.js.map +1 -0
  35. package/lib/plugins/server-side/index.js +241 -0
  36. package/lib/plugins/server-side/index.js.map +1 -0
  37. package/lib/plugins/tree/index.js +383 -0
  38. package/lib/plugins/tree/index.js.map +1 -0
  39. package/lib/plugins/undo-redo/index.js +289 -0
  40. package/lib/plugins/undo-redo/index.js.map +1 -0
  41. package/lib/plugins/visibility/index.js +430 -0
  42. package/lib/plugins/visibility/index.js.map +1 -0
  43. package/package.json +53 -0
  44. package/themes/dg-theme-contrast.css +43 -0
  45. package/themes/dg-theme-large.css +54 -0
  46. package/themes/dg-theme-standard.css +19 -0
  47. package/themes/dg-theme-vibrant.css +16 -0
  48. package/umd/grid.all.umd.js +660 -0
  49. package/umd/grid.all.umd.js.map +1 -0
  50. package/umd/grid.umd.js +105 -0
  51. package/umd/grid.umd.js.map +1 -0
  52. package/umd/plugins/clipboard.umd.js +9 -0
  53. package/umd/plugins/clipboard.umd.js.map +1 -0
  54. package/umd/plugins/column-virtualization.umd.js +2 -0
  55. package/umd/plugins/column-virtualization.umd.js.map +1 -0
  56. package/umd/plugins/context-menu.umd.js +53 -0
  57. package/umd/plugins/context-menu.umd.js.map +1 -0
  58. package/umd/plugins/export.umd.js +14 -0
  59. package/umd/plugins/export.umd.js.map +1 -0
  60. package/umd/plugins/filtering.umd.js +175 -0
  61. package/umd/plugins/filtering.umd.js.map +1 -0
  62. package/umd/plugins/grouping-columns.umd.js +29 -0
  63. package/umd/plugins/grouping-columns.umd.js.map +1 -0
  64. package/umd/plugins/grouping-rows.umd.js +40 -0
  65. package/umd/plugins/grouping-rows.umd.js.map +1 -0
  66. package/umd/plugins/master-detail.umd.js +27 -0
  67. package/umd/plugins/master-detail.umd.js.map +1 -0
  68. package/umd/plugins/multi-sort.umd.js +26 -0
  69. package/umd/plugins/multi-sort.umd.js.map +1 -0
  70. package/umd/plugins/pinned-columns.umd.js +2 -0
  71. package/umd/plugins/pinned-columns.umd.js.map +1 -0
  72. package/umd/plugins/pinned-rows.umd.js +73 -0
  73. package/umd/plugins/pinned-rows.umd.js.map +1 -0
  74. package/umd/plugins/pivot.umd.js +8 -0
  75. package/umd/plugins/pivot.umd.js.map +1 -0
  76. package/umd/plugins/reorder.umd.js +31 -0
  77. package/umd/plugins/reorder.umd.js.map +1 -0
  78. package/umd/plugins/selection.umd.js +34 -0
  79. package/umd/plugins/selection.umd.js.map +1 -0
  80. package/umd/plugins/server-side.umd.js +2 -0
  81. package/umd/plugins/server-side.umd.js.map +1 -0
  82. package/umd/plugins/tree.umd.js +11 -0
  83. package/umd/plugins/tree.umd.js.map +1 -0
  84. package/umd/plugins/undo-redo.umd.js +2 -0
  85. package/umd/plugins/undo-redo.umd.js.map +1 -0
  86. package/umd/plugins/visibility.umd.js +94 -0
  87. package/umd/plugins/visibility.umd.js.map +1 -0
@@ -0,0 +1,660 @@
1
+ (function(v,F){typeof exports=="object"&&typeof module<"u"?F(exports):typeof define=="function"&&define.amd?define(["exports"],F):(v=typeof globalThis<"u"?globalThis:v||self,F(v.TbwGrid={}))})(this,(function(v){"use strict";const F=":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-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-success);--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{display:flex;align-items:center;padding:var(--tbw-cell-padding, 2px 8px);border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}:host .data-grid-row>.cell>*{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}:host .data-grid-row>.cell:last-child{border-right:0}:host .data-grid-row>.cell[data-type=boolean]{justify-content:center}:host .data-grid-row>.cell[data-type=boolean] input[type=checkbox]{margin:0;width:var(--tbw-checkbox-size);height:var(--tbw-checkbox-size)}:host .data-grid-row>.cell.editing{overflow:hidden;padding:0}: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{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{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;flex-shrink:0}:host .tbw-tool-panel[data-position=left]{border-left:none;border-right:1px solid var(--tbw-tool-panel-border);order:-1}:host .tbw-tool-panel.open{width:var(--tbw-tool-panel-width)}: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;padding:12px}: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 at(o){const e=new Map;return o.sortState&&e.set(o.sortState.field,{direction:o.sortState.direction===1?"asc":"desc",priority:0}),e}function we(o,e){const t=o._columns,n=at(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 d of e)if(d.getColumnState){const c=d.getColumnState(i.field);c&&Object.assign(s,c)}return s})}}function ct(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 d={...l};return a.width!==void 0&&(d.width=a.width,d.__renderedWidth=a.width),a.visible!==void 0&&(d.hidden=!a.visible),d});r.sort((l,a)=>{const d=i.get(l.field)?.order??1/0,c=i.get(a.field)?.order??1/0;return d-c}),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 dt(o,e,t){let n=null;return()=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{n=null;const i=we(o,e());t(i)},100)}}const q={STRETCH:"stretch",FIXED:"fixed"};function ut(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 me(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=ut(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 ht=/{{\s*([^}]+)\s*}}/g,L="__DG_EMPTY__",ft=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,pt=/__(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/,gt=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"]),ve=/^on\w+$/i,bt=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),wt=/^\s*(javascript|vbscript|data|blob):/i;function X(o){if(!o||typeof o!="string")return"";if(o.indexOf("<")===-1)return o;const e=document.createElement("template");return e.innerHTML=o,mt(e.content),e.innerHTML}function mt(o){const e=[],t=o.querySelectorAll("*");for(const n of t){const i=n.tagName.toLowerCase();if(gt.has(i)){e.push(n);continue}if((i==="svg"||n.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(n.attributes).some(l=>ve.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(ve.test(l)){r.push(s.name);continue}if(bt.has(l)&&wt.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 Ce(o,e){if(!o||o.indexOf("{{")===-1)return o;const t=[],n=o.replace(ht,(l,a)=>{const d=vt(a,e);return t.push({expr:a.trim(),result:d}),d}),i=Ct(n),r=t.length&&t.every(l=>l.result===""||l.result===L);return/Reflect\.|\bProxy\b|ownKeys\(/.test(o)||r?"":i}function vt(o,e){if(o=(o||"").trim(),!o||/\b(Reflect|Proxy|ownKeys)\b/.test(o))return L;if(o==="value")return e.value==null?L: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?L:String(i)}if(o.length>80||!ft.test(o)||pt.test(o))return L;const t=o.match(/\./g);if(t&&t.length>1)return L;try{const i=new Function("value","row",`return (${o});`)(e.value,e.row),r=i==null?"":String(i);return/Reflect|Proxy|ownKeys/.test(r)?L:r||L}catch{return L}}function Ct(o){return o&&o.replace(new RegExp(L,"g"),"").replace(/Reflect\.[^<>{}\s]+/g,"").replace(/\bProxy\b/g,"").replace(/ownKeys\([^)]*\)/g,"")}function yt(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 ye(o){const e=/Reflect\.|\bProxy\b|ownKeys\(/.test(o),t=n=>e?"":Ce(o,n);return t.__blocked=e,t}function xt(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"),d=t.hasAttribute("editable"),c={field:n,type:s,header:l,sortable:a,editable:d};t.hasAttribute("resizable")&&(c.resizable=!0),t.hasAttribute("sizable")&&(c.resizable=!0);const h=t.getAttribute("options");h&&(c.options=h.split(",").map(g=>{const[b,y]=g.includes(":")?g.split(":"):[g.trim(),g.trim()];return{value:b.trim(),label:y?.trim()||b.trim()}}));const u=t.querySelector("tbw-grid-column-view"),f=t.querySelector("tbw-grid-column-editor"),p=t.querySelector("tbw-grid-column-header");return u&&(c.__viewTemplate=u),f&&(c.__editorTemplate=f),p&&(c.__headerTemplate=p),c}).filter(t=>!!t)}function Et(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 Y(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 Rt(o){o.__lightDomColumnsCache||(o.__originalColumnNodes=Array.from(o.querySelectorAll("tbw-grid-column")),o.__lightDomColumnsCache=o.__originalColumnNodes.length?xt(o):[]);const e=o.__lightDomColumnsCache,t=Et(o._columns,e);t.forEach(i=>{i.__viewTemplate&&!i.__compiledView&&(i.__compiledView=ye(i.__viewTemplate.innerHTML)),i.__editorTemplate&&!i.__compiledEditor&&(i.__compiledEditor=ye(i.__editorTemplate.innerHTML))});const{columns:n}=me(o._rows,t);o._columns=n}function St(o){const e=o.effectiveConfig?.fitMode||o.fitMode||q.STRETCH;if(e!==q.STRETCH&&e!==q.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 d=a.children[r];if(d){const c=d.scrollWidth;c>l&&(l=c)}}l>0&&(i.width=l+2,i.__autoSized=!0,n=!0)}),n&&xe(o),o.__didInitialAutoSize=!0}function xe(o){(o.effectiveConfig?.fitMode||o.fitMode||q.STRETCH)===q.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 _t(o){switch(o.type){case"number":return e=>{const t=document.createElement("input");return t.type="number",t.value=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??"",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 At(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,d=c=>{if(!c)return!1;const h=c.tagName;return!!(h==="INPUT"||h==="SELECT"||h==="TEXTAREA"||c.isContentEditable)};if(!(d(a)&&(e.key==="Home"||e.key==="End"))&&!(d(a)&&(e.key==="ArrowUp"||e.key==="ArrowDown")&&a.tagName==="INPUT"&&a.type==="number")&&!(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),$(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":o.focusCol=0,e.preventDefault();break;case"End":o.focusCol=n,e.preventDefault();break;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}})),$(o);default:return}$(o)}}function $(o){if(o.virtualization?.enabled){const{rowHeight:i}=o.virtualization,r=o,s=o.focusRow*i;s<r.scrollTop?r.scrollTop=s:s+i>r.scrollTop+r.clientHeight&&(r.scrollTop=s-r.clientHeight+i)}o.refreshVirtualWindow(!1),Array.from(o.bodyEl.querySelectorAll(".cell-focus")).forEach(i=>i.classList.remove("cell-focus")),Array.from(o.bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(i=>{i.setAttribute("aria-selected","false")});const e=o.focusRow,t=o.virtualization.start??0,n=o.virtualization.end??o._rows.length;if(e>=t&&e<n){const r=o.bodyEl.querySelectorAll(".data-grid-row")[e-t]?.children[o.focusCol];if(r){if(r.classList.add("cell-focus"),r.setAttribute("aria-selected","true"),o.activeEditRows!==void 0&&o.activeEditRows!==-1&&r.classList.contains("editing")){const s=r.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(s&&document.activeElement!==s)try{s.focus()}catch{}}else if(!r.contains(document.activeElement)){r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1");try{r.focus({preventScroll:!0})}catch{}}}}}const kt="__cellDisplayCache",Tt="__cellCacheEpoch";function Ee(o){o[kt]=void 0,o[Tt]=void 0,o.__hasSpecialColumns=void 0}function Lt(o,e,t,n,i){const r=Math.max(0,t-e),s=o.bodyEl,l=o.visibleColumns,a=l.length;let d=o.__cachedHeaderRowCount;for(d===void 0&&(d=o.shadowRoot?.querySelector(".header-group-row")?2:1,o.__cachedHeaderRowCount=d);o.rowPool.length<r;){const h=document.createElement("div");h.className="data-grid-row",h.setAttribute("role","row"),h.addEventListener("click",u=>Se(o,u,h,!1)),h.addEventListener("dblclick",u=>Se(o,u,h,!0)),o.rowPool.push(h)}if(o.rowPool.length>r){for(let h=r;h<o.rowPool.length;h++){const u=o.rowPool[h];u.parentNode===s&&u.remove()}o.rowPool.length=r}const c=i&&o.__hasRenderRowPlugins!==!1;for(let h=0;h<r;h++){const u=e+h,f=o._rows[u],p=o.rowPool[h];if(p.setAttribute("aria-rowindex",String(u+d+1)),c&&i(f,p,u)){p.__epoch=n,p.__rowDataRef=f,p.parentNode!==s&&s.appendChild(p);continue}const g=p.__epoch,b=p.__rowDataRef,y=p.children.length,I=g===n&&y===a,H=b!==f;let M=!1;if(I&&H){for(let k=0;k<a;k++)if(l[k].externalView&&!p.querySelector(`.cell[data-col="${k}"] [data-external-view]`)){M=!0;break}}!I||M?(p.__isCustomRow&&(p.className="data-grid-row",p.setAttribute("role","row"),p.__isCustomRow=!1),J(o,p,f,u),p.__epoch=n,p.__rowDataRef=f):H?(Re(o,p,f,u),p.__rowDataRef=f):Re(o,p,f,u);const w=o._changedRowIndices.has(u),m=p.classList.contains("changed");w!==m&&p.classList.toggle("changed",w),p.parentNode!==s&&s.appendChild(p)}}function Re(o,e,t,n){const i=e.children,r=o.visibleColumns,s=r.length,l=i.length,a=s<l?s:l;let d=o.__hasSpecialColumns;if(d===void 0){d=!1;for(let h=0;h<s;h++){const u=r[h];if(u.__viewTemplate||u.__compiledView||u.viewRenderer||u.externalView||u.format||u.type==="date"||u.type==="boolean"){d=!0;break}}o.__hasSpecialColumns=d}const c=String(n);if(!d){for(let h=0;h<a;h++){const u=i[h],f=t[r[h].field];u.textContent=f==null?"":String(f),u.getAttribute("data-row")!==c&&u.setAttribute("data-row",c)}return}for(let h=0;h<a;h++)if(r[h].externalView&&!i[h].querySelector("[data-external-view]")){J(o,e,t,n);return}for(let h=0;h<a;h++){const u=r[h],f=i[h];if(f.getAttribute("data-row")!==c&&f.setAttribute("data-row",c),f.classList.contains("editing")||u.__viewTemplate||u.__compiledView||u.viewRenderer||u.externalView)continue;const p=t[u.field];let g;if(u.format)try{const b=u.format(p,t);g=b==null?"":String(b)}catch{g=p==null?"":String(p)}else if(u.type==="date")if(p==null||p==="")g="";else if(p instanceof Date)g=isNaN(p.getTime())?"":p.toLocaleDateString();else{const b=new Date(p);g=isNaN(b.getTime())?"":b.toLocaleDateString()}else u.type==="boolean"?(g=p?"🗹":"☐",f.setAttribute("aria-checked",String(!!p))):g=p==null?"":String(p);f.textContent=g}}function J(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,d=o,c=document.createDocumentFragment();for(let h=0;h<r;h++){const u=i[h],f=document.createElement("div");f.className="cell",Y(f,"cell"),u.type!=="boolean"&&f.setAttribute("role","gridcell"),f.setAttribute("data-col",String(h)),f.setAttribute("data-row",String(n)),f.setAttribute("aria-colindex",String(h+1)),u.type&&f.setAttribute("data-type",u.type);const p=u.sticky;p==="left"?f.classList.add("sticky-left"):p==="right"&&f.classList.add("sticky-right");let g=t[u.field];const b=u.format;if(b)try{g=b(g,t)}catch{}const y=u.__compiledView,A=u.__viewTemplate,I=u.viewRenderer,H=u.externalView;let M=!1;if(I){const w=I({row:t,value:g,field:u.field,column:u});typeof w=="string"?(f.innerHTML=X(w),M=!0):w?f.appendChild(w):f.textContent=g==null?"":String(g)}else if(H){const w=H,m=document.createElement("div");m.setAttribute("data-external-view",""),m.setAttribute("data-field",u.field),f.appendChild(m);const k={row:t,value:g,field:u.field,column:u};if(w.mount)try{w.mount({placeholder:m,context:k,spec:w})}catch{}else queueMicrotask(()=>{try{d.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:m,spec:w,context:k}}))}catch{}});m.setAttribute("data-mounted","")}else if(y){const w=y({row:t,value:g,field:u.field,column:u}),m=y.__blocked;f.innerHTML=m?"":X(w),M=!0,m&&(f.textContent="",f.setAttribute("data-blocked-template",""))}else if(A){const w=A.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(w)?(f.textContent="",f.setAttribute("data-blocked-template","")):(f.innerHTML=X(Ce(w,{row:t,value:g})),M=!0)}else if(u.type==="date")if(g==null||g==="")f.textContent="";else{let w=null;if(g instanceof Date)w=g;else if(typeof g=="number"||typeof g=="string"){const m=new Date(g);isNaN(m.getTime())||(w=m)}f.textContent=w?w.toLocaleDateString():""}else if(u.type==="boolean"){const w=!!g;f.innerHTML=w?"&#x1F5F9;":"&#9744;",f.setAttribute("role","checkbox"),f.setAttribute("aria-checked",String(w)),f.setAttribute("aria-label",String(w))}else f.textContent=g==null?"":String(g);if(M){yt(f);const w=f.textContent||"";/Proxy|Reflect\.ownKeys/.test(w)&&(f.textContent=w.replace(/Proxy|Reflect\.ownKeys/g,"").trim(),/Proxy|Reflect\.ownKeys/.test(f.textContent||"")&&(f.textContent=""))}f.hasAttribute("data-blocked-template")&&(f.textContent||"").trim().length&&(f.textContent=""),u.editable?(f.tabIndex=0,f.addEventListener("mousedown",()=>{o.focusRow=n,o.focusCol=h,$(o)}),a==="click"?f.addEventListener("click",w=>{f.classList.contains("editing")||(w.stopPropagation(),o.focusRow=n,o.focusCol=h,z(o,t,n,u,f))}):f.addEventListener("dblclick",w=>{w.stopPropagation(),N(o,n,t);const m=o.findRenderedRowElement?.(n);if(m){const k=m.children;for(let C=0;C<k.length;C++){const x=o.visibleColumns[C];x&&x.editable&&z(o,t,n,x,k[C])}}}),f.addEventListener("keydown",w=>{if((u.type==="select"||u.type==="typeahead")&&!f.classList.contains("editing")&&w.key==="Enter"){w.preventDefault(),o.activeEditRows!==n&&N(o,n,t),z(o,t,n,u,f),setTimeout(()=>{const m=f.querySelector("select");try{m?.showPicker?.()}catch{}m?.focus()},0);return}if(u.type==="boolean"&&w.key===" "&&!f.classList.contains("editing")){w.preventDefault(),o.activeEditRows!==n&&N(o,n,t);const m=!t[u.field];Z(o,n,u,m,t),f.innerHTML=m?"&#x1F5F9;":"&#9744;",f.setAttribute("aria-label",String(!!m));return}if(w.key==="Enter"&&!f.classList.contains("editing")){w.preventDefault(),o.focusRow=n,o.focusCol=h,typeof o.beginBulkEdit=="function"?o.beginBulkEdit(n):z(o,t,n,u,f);return}if(w.key==="F2"&&!f.classList.contains("editing")){w.preventDefault(),z(o,t,n,u,f);return}})):u.type==="boolean"&&(f.hasAttribute("tabindex")||(f.tabIndex=0),f.addEventListener("keydown",w=>{if(w.key===" "){w.preventDefault();const m=!t[u.field];o.activeEditRows!==n&&N(o,n,t),Z(o,n,u,m,t),f.innerHTML=m?"&#x1F5F9;":"&#9744;",f.setAttribute("role","checkbox"),f.setAttribute("aria-checked",String(!!m)),f.setAttribute("aria-label",String(!!m))}})),s===n&&l===h?f.setAttribute("aria-selected","true"):f.setAttribute("aria-selected","false"),c.appendChild(f)}e.appendChild(c)}function Se(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){const d=Number(l.getAttribute("data-col"));if(!isNaN(d)){if(o.dispatchCellClick?.(e,r,d,l))return;o.focusRow=r,o.focusCol=d,$(o)}}if(t.querySelector(".cell.editing")){const d=t.querySelectorAll(".cell.editing");if(!n)return;d.forEach(c=>c.classList.remove("editing"))}const a=o.effectiveConfig?.editOn||o.editOn||"doubleClick";if(a==="click"||a==="doubleClick"&&n)N(o,r,s);else return;Array.from(t.children).forEach((d,c)=>{const h=o.visibleColumns[c];h&&h.editable&&z(o,s,r,h,d)}),l&&queueMicrotask(()=>{const d=t.querySelector(`.cell[data-col="${o.focusCol}"]`);if(d?.classList.contains("editing")){const c=d.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');try{c?.focus()}catch{}}})}function N(o,e,t){o.activeEditRows!==e&&(o.rowEditSnapshots.set(e,{...t}),o.activeEditRows=e)}function Pt(o,e,t){if(o.activeEditRows!==e)return;const n=o.rowEditSnapshots.get(e),i=o._rows[e];if(t&&n&&i)Object.keys(n).forEach(s=>i[s]=n[s]),o._changedRowIndices.delete(e);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;const r=o.findRenderedRowElement?.(e);r&&(J(o,r,o._rows[e],e),o._changedRowIndices.has(e)?r.classList.add("changed"):r.classList.remove("changed")),t&&queueMicrotask(()=>{try{o.focus();const s=o.focusRow,l=o.focusCol,a=o.findRenderedRowElement?.(s);if(a){Array.from(o.bodyEl.querySelectorAll(".cell-focus")).forEach(c=>c.classList.remove("cell-focus"));const d=a.querySelector(`.cell[data-row="${s}"][data-col="${l}"]`);d&&d.classList.add("cell-focus")}}catch{}})}function Z(o,e,t,n,i){const r=t.field;if(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 z(o,e,t,n,i){if(!n.editable||(o.activeEditRows!==t&&N(o,t,e),i.classList.contains("editing")))return;const r=e[n.field];i.classList.add("editing");const s=u=>{Z(o,t,n,u,e)},l=()=>{e[n.field]=r;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??""))},a=document.createElement("div");a.style.display="contents",i.innerHTML="",i.appendChild(a);const d=n.__editorTemplate,c=n.editor||(d?"template":_t(n)),h=r;if(c==="template"&&d){const u=d.cloneNode(!0),f=n.__compiledEditor;f?u.innerHTML=f({row:e,value:r,field:n.field,column:n}):u.querySelectorAll("*").forEach(g=>{g.childNodes.length===1&&g.firstChild?.nodeType===Node.TEXT_NODE&&(g.textContent=g.textContent?.replace(/{{\s*value\s*}}/g,r==null?"":String(r)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(b,y)=>{const A=e[y];return A==null?"":String(A)})||"")});const p=u.querySelector("input,textarea,select");if(p){const g=typeof HTMLInputElement<"u";g&&p instanceof HTMLInputElement&&p.type==="checkbox"?p.checked=!!r:"value"in p&&(p.value=r??""),p.addEventListener("blur",()=>{const b=g&&p instanceof HTMLInputElement&&p.type==="checkbox"?p.checked:p.value;s(b)}),p.addEventListener("keydown",b=>{if(b.key==="Enter"){const y=g&&p instanceof HTMLInputElement&&p.type==="checkbox"?p.checked:p.value;s(y)}b.key==="Escape"&&l()}),g&&p instanceof HTMLInputElement&&p.type==="checkbox"&&p.addEventListener("change",()=>{const b=p.checked;s(b)}),setTimeout(()=>p.focus(),0)}a.appendChild(u)}else if(typeof c=="string"){const u=document.createElement(c);u.value=h,u.addEventListener("change",()=>s(u.value)),a.appendChild(u)}else if(typeof c=="function"){const u=c({row:e,value:h,field:n.field,column:n,commit:s,cancel:l});typeof u=="string"?a.innerHTML=u:a.appendChild(u)}else if(c&&typeof c=="object"){const u=document.createElement("div");u.setAttribute("data-external-editor",""),u.setAttribute("data-field",n.field),a.appendChild(u);const f={row:e,value:h,field:n.field,column:n,commit:s,cancel:l};if(c.mount)try{c.mount({placeholder:u,context:f,spec:c})}catch{}else o.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:u,spec:c,context:f}}))}}function _e(o,e){!o.sortState||o.sortState.field!==e.field?(o.sortState||(o.__originalOrder=o._rows.slice()),Ae(o,e,1)):o.sortState.direction===1?Ae(o,e,-1):(o.sortState=null,o.__rowRenderEpoch++,o.rowPool.forEach(n=>n.__epoch=-1),o._rows=o.__originalOrder.slice(),Q(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 Ae(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),Q(o),o.refreshVirtualWindow(!0),o.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:t}})),o.requestStateChange?.()}function Q(o){o.headerRowEl=o.findHeaderRow();const e=o.headerRowEl;e.innerHTML="",e.setAttribute("role","row"),e.setAttribute("aria-rowindex","1"),o.visibleColumns.forEach((t,n)=>{const i=document.createElement("div");i.className="cell",Y(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)),t.sticky==="left"?i.classList.add("sticky-left"):t.sticky==="right"&&i.classList.add("sticky-right");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");Y(s,"sort-indicator"),s.style.opacity="0.6";const l=o.sortState?.field===t.field?o.sortState.direction:0;s.textContent=l===1?"▲":l===-1?"▼":"⇅",i.appendChild(s),i.setAttribute("aria-sort",l===0?"none":l===1?"ascending":"descending"),i.addEventListener("click",a=>{o.resizeController?.isResizing||o.dispatchHeaderClick?.(a,n,i)||_e(o,t)}),i.addEventListener("keydown",a=>{if(a.key==="Enter"||a.key===" "){if(a.preventDefault(),o.dispatchHeaderClick?.(a,n,i))return;_e(o,t)}})}if(t.resizable){t.sticky||(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)});try{const t=o.shadowRoot;t&&t.querySelectorAll(".header-group-row .cell").forEach(i=>{i.getAttribute("data-group")&&i.classList.add("grouped")})}catch{}e.querySelectorAll(".cell.sortable").forEach(t=>{t.getAttribute("aria-sort")||t.setAttribute("aria-sort","none")})}function Mt(o){let e=null,t=null,n=null,i=null;const r=a=>{if(!e)return;const d=a.clientX-e.startX,c=Math.max(40,e.startWidth+d),h=o.visibleColumns[e.colIndex];h.width=c,h.__userResized=!0,h.__renderedWidth=c,t==null&&(t=requestAnimationFrame(()=>{t=null,o.updateTemplate?.()})),o.dispatchEvent(new CustomEvent("column-resize",{detail:{field:h.field,width:c}}))};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,d,c){a.preventDefault();const h=c.getBoundingClientRect();e={startX:a.clientX,colIndex:d,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 It(){return{toolPanels:new Map,headerContents:new Map,toolbarButtons:new Map,lightDomButtons:[],lightDomHeaderContent:[],activePanel:null,headerContentCleanups:new Map,activePanelCleanup:null,toolbarButtonCleanups:new Map}}function Ot(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 Dt(o,e){const t=o?.header?.title??"",n=!!t,i=o?.header?.toolbarButtons??[],r=i.length>0,s=e.toolbarButtons.size>0,l=e.lightDomButtons.length>0,a=e.toolPanels.size>0,c=(r||s||l)&&a,h=[...i].sort((g,b)=>(g.order??100)-(b.order??100)),u=[...e.toolbarButtons.values()].sort((g,b)=>(g.order??100)-(b.order??100)),f=[...e.toolPanels.values()].sort((g,b)=>(g.order??100)-(b.order??100));let p="";for(const g of h)g.icon&&g.action&&(p+=`<button class="tbw-toolbar-btn" data-btn="${g.id}" title="${g.label}" aria-label="${g.label}"${g.disabled?" disabled":""}>${g.icon}</button>`);for(const g of u)g.icon&&g.action&&(p+=`<button class="tbw-toolbar-btn" data-btn="${g.id}" title="${g.label}" aria-label="${g.label}"${g.disabled?" disabled":""}>${g.icon}</button>`);for(const g of h)(g.element||g.render)&&(p+=`<div class="tbw-toolbar-btn-slot" data-btn-slot="${g.id}"></div>`);for(const g of u)(g.element||g.render)&&(p+=`<div class="tbw-toolbar-btn-slot" data-btn-slot="${g.id}"></div>`);l&&(p+='<slot name="toolbar"></slot>'),c&&(p+='<div class="tbw-toolbar-separator"></div>');for(const g of f){const b=e.activePanel===g.id;p+=`<button class="tbw-toolbar-btn${b?" active":""}" data-panel="${g.id}" title="${g.tooltip??g.title}" aria-label="${g.tooltip??g.title}" aria-pressed="${b}" aria-controls="tbw-panel-${g.id}">${g.icon}</button>`}return`
2
+ <div class="tbw-shell-header" part="shell-header" role="banner">
3
+ ${n?`<div class="tbw-shell-title">${t}</div>`:""}
4
+ <div class="tbw-shell-content" part="shell-content" role="region" aria-label="Grid information">
5
+ <slot name="header-content"></slot>
6
+ </div>
7
+ <div class="tbw-shell-toolbar" part="shell-toolbar" role="toolbar" aria-label="Grid tools">
8
+ ${p}
9
+ </div>
10
+ </div>
11
+ `}function Ht(o,e,t){const n=o?.toolPanel?.position??"right",i=e.toolPanels.size>0,r=e.activePanel!==null,s=e.activePanel?e.toolPanels.get(e.activePanel):null,l=i?`
12
+ <aside class="tbw-tool-panel${r?" open":""}" part="tool-panel" data-position="${n}" role="complementary" aria-label="${s?.title??"Tool panel"}" id="tbw-panel-${e.activePanel??"closed"}">
13
+ <div class="tbw-tool-panel-header">
14
+ <span class="tbw-tool-panel-title">${s?.title??""}</span>
15
+ <button class="tbw-tool-panel-close" aria-label="Close panel">✕</button>
16
+ </div>
17
+ <div class="tbw-tool-panel-content" role="region"></div>
18
+ </aside>
19
+ `:"";return n==="left"?`
20
+ <div class="tbw-shell-body">
21
+ ${l}
22
+ <div class="tbw-grid-content">
23
+ ${t}
24
+ </div>
25
+ </div>
26
+ `:`
27
+ <div class="tbw-shell-body">
28
+ <div class="tbw-grid-content">
29
+ ${t}
30
+ </div>
31
+ ${l}
32
+ </div>
33
+ `}function ke(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,s)=>{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 Nt(o,e,t,n){const i=o.querySelector(".tbw-shell-toolbar");i&&i.addEventListener("click",s=>{const l=s.target,a=l.closest("[data-panel]");if(a){const c=a.getAttribute("data-panel");c&&n.onPanelToggle(c);return}const d=l.closest("[data-btn]");if(d){const c=d.getAttribute("data-btn");c&&n.onToolbarButtonClick(c)}});const r=o.querySelector(".tbw-tool-panel-close");r&&r.addEventListener("click",()=>{n.onPanelClose()})}function qt(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 Te(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 zt(o,e){if(!e.activePanel)return;const t=e.toolPanels.get(e.activePanel);if(!t)return;const n=o.querySelector(".tbw-tool-panel-content");if(!n)return;e.activePanelCleanup&&(e.activePanelCleanup(),e.activePanelCleanup=null),n.innerHTML="";const i=t.render(n);i&&(e.activePanelCleanup=i)}function Le(o,e){o.querySelectorAll("[data-panel]").forEach(n=>{const r=n.getAttribute("data-panel")===e.activePanel;n.classList.toggle("active",r),n.setAttribute("aria-pressed",String(r))})}function Pe(o,e){const t=o.querySelector(".tbw-tool-panel");if(!t)return;const n=e.activePanel!==null;if(t.classList.toggle("open",n),n&&e.activePanel){const i=e.toolPanels.get(e.activePanel),r=t.querySelector(".tbw-tool-panel-title");r&&(r.textContent=i?.title??""),t.setAttribute("aria-label",`${i?.title??"Tool"} panel`),t.id=`tbw-panel-${e.activePanel}`}}function Bt(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 Ft(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}class $t{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(`
34
+ `)}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?.()}renderRow(e,t,n){for(const i of this.plugins)if(i.renderRow?.(e,t,n))return!0;return!1}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}getContextMenuItems(e){const t=[];for(const n of this.plugins){const i=n.getContextMenuItems?.(e);i&&t.push(...i)}return t}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 K extends HTMLElement{static tagName="tbw-grid";#t;#b=!1;#w;#y;#i=[];#r;#m;#x;#E;#n={};#u=!1;#T=0;#R=null;#S=!1;#L;#h;#f;#_=!1;#p;#g;#o;#P;#c;#e=It();#l=!1;_rows=[];get _columns(){return this.#n.columns??[]}set _columns(e){this.#n.columns=e}get visibleColumns(){return this._columns.filter(e=>!e.hidden)}rowPool=[];__rowRenderEpoch=0;activeEditRows=-1;resizeController;__didInitialAutoSize=!1;__lightDomColumnsCache;__originalColumnNodes;headerRowEl;bodyEl;virtualization={enabled:!0,rowHeight:28,bypassThreshold:24,start:0,end:0,container:null,viewportEl:null,totalHeightEl:null};sortState=null;__originalOrder=[];focusRow=0;focusCol=0;gridTemplate="";rowEditSnapshots=new Map;_changedRowIndices=new Set;get rows(){return this._rows}set rows(e){const t=this.#i;this.#i=e,t!==e&&this.#X()}get sourceRows(){return this.#i}get columns(){return[...this._columns]}set columns(e){const t=this.#r;this.#r=e,t!==e&&this.#Y()}get gridConfig(){return this.#n}set gridConfig(e){const t=this.#m;this.#m=e,t!==e&&this.#J()}get fitMode(){return this.#n.fitMode??"stretch"}set fitMode(e){const t=this.#x;this.#x=e,t!==e&&this.#j()}get editOn(){return this.#n.editOn}set editOn(e){const t=this.#E;this.#E=e,t!==e&&this.#U()}get effectiveConfig(){return this.#n}constructor(){super(),this.#t=this.attachShadow({mode:"open"}),this.#K(),this.#w=new Promise(e=>this.#y=e)}#K(){const e=new CSSStyleSheet;e.replaceSync(F),this.#t.adoptedStyleSheets=[e]}getPlugin(e){return this.#o?.getPlugin(e)}getPluginByName(e){return this.#o?.getPluginByName(e)}requestRender(){this.#k(),this.#M(),this.#A(),this.updateTemplate(),this.refreshVirtualWindow(!0)}requestAfterRender(){this.#v()}#H(){this.#o=new $t(this);const e=this.#n?.plugins,t=Array.isArray(e)?e:[];this.#o.attachAll(t)}#N(){const e=this.#o?.getAllStyles()??"";if(e){const t=document.createElement("style");t.setAttribute("data-plugin","all"),t.textContent=e,this.#t.appendChild(t)}}#q(){this.#o&&this.#o.detachAll(),this.#H(),this.#N(),this.#S=this.#o?.getAll().some(e=>e.onScroll)??!1}#W(){this.#o?.detachAll()}#V(){if(!this.#o)return;const e=this.#o.getToolPanels();for(const{panel:n}of e)this.#e.toolPanels.has(n.id)||this.#e.toolPanels.set(n.id,n);const t=this.#o.getHeaderContents();for(const{content:n}of t)this.#e.headerContents.has(n.id)||this.#e.headerContents.set(n.id,n)}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this._rows=Array.isArray(this.#i)?[...this.#i]:[],this.#d(),this.#H(),this.#V(),this.#b||(this.#$(),this.#N(),this.#b=!0),this.#z()}disconnectedCallback(){this.#W(),Ft(this.#e),this.#l=!1,this.#h&&(document.removeEventListener("keydown",this.#h,!0),this.#h=void 0),this.#f&&(document.removeEventListener("mousedown",this.#f,!1),this.#f=void 0),this.#p&&(document.removeEventListener("mousemove",this.#p),this.#p=void 0),this.#g&&(document.removeEventListener("mouseup",this.#g),this.#g=void 0),this.resizeController&&this.resizeController.dispose(),this.#u=!1}#z(){const t=this.#t.querySelector(".tbw-grid-content")??this.#t.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.#l){Te(this.#t,this.#e),qt(this.#t,this.#n?.shell,this.#e);const r=this.#n?.shell?.toolPanel?.defaultOpen;r&&this.#e.toolPanels.has(r)&&this.openToolPanel(r)}this.setAttribute("data-upgraded",""),this.hasAttribute("role")||this.setAttribute("role","grid"),this.#u=!0,this.#a(),this.addEventListener("keydown",r=>At(this,r)),this.#h||(this.#h=r=>{r.key==="Escape"&&this.activeEditRows!==-1&&this.#O(this.activeEditRows,!0)},document.addEventListener("keydown",this.#h,!0)),this.#f||(this.#f=r=>{if(this.activeEditRows===-1)return;const s=this.findRenderedRowElement(this.activeEditRows);!s||(r.composedPath&&r.composedPath()||[]).includes(s)||this.#O(this.activeEditRows,!1)},document.addEventListener("mousedown",this.#f,!1));const n=t?.querySelector(".faux-vscroll"),i=t?.querySelector(".rows");if(this.virtualization.container=n??this,this.#S=this.#o?.getAll().some(r=>r.onScroll)??!1,n&&i){n.addEventListener("scroll",()=>{if(!this.virtualization.enabled&&!this.#S)return;const s=n.scrollTop,l=this.virtualization.rowHeight,a=-(s%l);i.style.transform=`translateY(${a}px)`,this.#R=s,this.#T||(this.#T=requestAnimationFrame(()=>{this.#T=0,this.#R!==null&&(this.#te(this.#R),this.#R=null)}))},{passive:!0});const r=t?.querySelector(".rows-body");r&&r.addEventListener("wheel",s=>{s.preventDefault(),n.scrollTop+=s.deltaY},{passive:!1})}this.resizeController=Mt(this),this.#t.addEventListener("mousedown",r=>this.#oe(r)),this.#p||(this.#p=r=>this.#ne(r),document.addEventListener("mousemove",this.#p)),this.#g||(this.#g=r=>this.#ie(r),document.addEventListener("mouseup",this.#g)),this.virtualization.enabled&&requestAnimationFrame(()=>this.refreshVirtualWindow(!0)),requestAnimationFrame(()=>{const r=this.bodyEl.querySelector(".data-grid-row");if(r){const s=r.getBoundingClientRect().height;s&&Math.abs(s-this.virtualization.rowHeight)>.1&&(this.virtualization.rowHeight=s,this.refreshVirtualWindow(!0))}}),queueMicrotask(()=>this.#G()),requestAnimationFrame(()=>requestAnimationFrame(()=>this.#y?.()))}#s(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}emitCellCommit(e){this.#s("cell-commit",e)}emitRowCommit(e){this.#s("row-commit",e)}emitSortChange(e){this.#s("sort-change",e)}emitColumnResize(e){this.#s("column-resize",e)}emitActivateCell(e){this.#s("activate-cell",e)}#G(){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))})})}#j(){if(!this.#u)return;this.#d(),this.#n.fitMode==="fixed"?(this.__didInitialAutoSize=!1,this.#B()):(this._columns.forEach(t=>{!t.__userResized&&t.__autoSized&&delete t.width}),this.updateTemplate())}#U(){this.#u&&(this.#d(),this.rowPool.length=0,this.bodyEl&&(this.bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.refreshVirtualWindow(!0))}#X(){this._rows=Array.isArray(this.#i)?[...this.#i]:[],this.#k(),!this.#r||Array.isArray(this.#r)&&this.#r.length===0?this.#a():this.refreshVirtualWindow(!0)}#Y(){Ee(this),this.#u&&(this.#d(),this.#a())}#J(){this.#u&&(this.#d(),this.#q(),this.#k(),this.#M(),this.#A(),this.updateTemplate(),this.refreshVirtualWindow(!0))}#Z(){Rt(this)}#A(){Q(this)}updateTemplate(){xe(this)}#B(){St(this)}#M(){if(this.#o){const e=this._columns.filter(n=>!n.hidden),t=this.#o.processColumns([...e]);if(t!==e){const n=new Map(t.map((r,s)=>[r.field,{col:r,order:s}])),i=this._columns.map(r=>{if(r.hidden)return r;const s=n.get(r.field);return s?s.col:r});this._columns=i}}}#v(){this.#o?.afterRender()}#k(){Ee(this);const e=Array.isArray(this.#i)?[...this.#i]:[],t=this.#o?.processRows(e)??e;this._rows=t}#d(){const e=this.#m?{...this.#m}:{};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.#r&&this.#r.length&&(t=[...this.#r]),(!t||t.length===0)&&this._rows.length&&(t=me(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.#n.columns;i?.some(s=>s.__compiledView||s.__compiledEditor)?e.columns=i:e.columns=t}else{const i=this.#n.columns;i?.some(r=>r.__compiledView||r.__compiledEditor)&&(e.columns=i)}this.#x&&(e.fitMode=this.#x),e.fitMode||(e.fitMode="stretch"),this.#E&&(e.editOn=this.#E),e.columnState&&!this.#c&&(this.#c=e.columnState),this.#n=e,e.fitMode==="fixed"&&this._columns.forEach(i=>{i.width==null&&(i.width=80)})}#I(e,t,n=this.__rowRenderEpoch){this.#L||(this.#L=(i,r,s)=>this.#o?.renderRow(i,r,s)??!1),Lt(this,e,t,n,this.#L)}#Q(e,t){N(this,e,t)}#O(e,t){Pt(this,e,t)}#a(){if(!this.isConnected||!this.headerRowEl||!this.bodyEl)return;const e=this.#m?.columns||this.#r||[];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(this.#Z(),this.#d(),this.#q(),this.#k(),this.#M(),this.#c){const n=this.#c;this.#c=void 0,this.#F(n)}this.#A(),this.updateTemplate(),this.refreshVirtualWindow(!0),this.#n.fitMode==="fixed"&&!this.__didInitialAutoSize&&requestAnimationFrame(()=>this.#B()),this.bodyEl&&(this.bodyEl.style.display="",this.bodyEl.style.gridTemplateColumns=""),queueMicrotask(()=>this.#v())}#F(e){const t=this.#n.columns??[],n=this.#o?.getAll()??[];ct(this,e,t,n);for(const i of e.columns){const r=t.find(s=>s.field===i.field);r&&(r.hidden=!i.visible)}}#ee(){return this._rows.length<=this.virtualization.bypassThreshold}#te(e){if(this.refreshVirtualWindow(!1),this.#S){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.#o?.onScroll(n)}}findHeaderRow(){return this.#t.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.#o?.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.#o?.onHeaderClick(r)??!1}dispatchKeyDown(e){return this.#o?.onKeyDown(e)??!1}#D(e,t){let n=null;const i=e.composedPath?.();if(i&&i.length>0?n=i[0]:n=e.target,n&&!this.#t.contains(n)){const p=this.#t.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,d,c,h,u,f;return r&&(a=parseInt(r.getAttribute("data-row")??"-1",10),d=parseInt(r.getAttribute("data-col")??"-1",10),a>=0&&d>=0&&(c=this._rows[a],f=this._columns[d],h=f?.field,u=c&&h?c[h]:void 0)),{type:t,row:c,rowIndex:a!==void 0&&a>=0?a:void 0,colIndex:d!==void 0&&d>=0?d:void 0,field:h,value:u,column:f,originalEvent:e,cellElement:r??void 0,rowElement:s??void 0,isHeader:!!l,cell:a!==void 0&&d!==void 0&&a>=0&&d>=0?{row:a,col:d}:void 0}}#oe(e){const t=this.#D(e,"mousedown");(this.#o?.onCellMouseDown(t)??!1)&&(this.#_=!0)}#ne(e){if(!this.#_)return;const t=this.#D(e,"mousemove");this.#o?.onCellMouseMove(t)}#ie(e){if(!this.#_)return;const t=this.#D(e,"mouseup");this.#o?.onCellMouseUp(t),this.#_=!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.#s("changed-rows-reset",{rows:this.changedRows,indices:this.changedRowIndices}),this.rowPool.forEach(t=>t.classList.remove("changed"))}async beginBulkEdit(e){this.#Q(e,this._rows[e])}async commitActiveRowEdit(){this.activeEditRows!==-1&&this.#O(this.activeEditRows,!1)}async ready(){return this.#w}async forceLayout(){this.#a(),await new Promise(e=>requestAnimationFrame(()=>requestAnimationFrame(e)))}async getConfig(){return Object.freeze({...this.#n||{}})}setColumnVisible(e,t){const n=this.#n.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.#s("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.#a(),this.requestStateChange(),!0):!1}toggleColumnVisibility(e){const i=!!this.#n.columns?.find(r=>r.field===e)?.hidden;return this.setColumnVisible(e,i)}isColumnVisible(e){const n=this.#n.columns?.find(i=>i.field===e);return n?!n.hidden:!1}showAllColumns(){const e=this.#n.columns;e?.some(n=>n.hidden)&&(e?.forEach(n=>{n.hidden=!1}),this.#s("column-visibility",{visibleColumns:(e??[]).map(n=>n.field)}),this.rowPool.length=0,this.bodyEl&&(this.bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.#a(),this.requestStateChange())}getAllColumns(){return(this.#n.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,this.#A(),this.updateTemplate(),this.refreshVirtualWindow(!0)}getColumnOrder(){return this._columns.map(e=>e.field)}getColumnState(){const e=this.#o?.getAll()??[];return we(this,e)}set columnState(e){e&&(this.#c=e,this.#b&&this.#re(e))}get columnState(){return this.getColumnState()}#re(e){(this.#n.columns??[]).forEach(n=>{n.hidden=!1}),this.#F(e),this.#a()}requestStateChange(){this.#P||(this.#P=dt(this,()=>this.#o?.getAll()??[],e=>this.#s("column-state-change",e))),this.#P()}resetColumnState(){this.#c=void 0,(this.#n.columns??[]).forEach(n=>{n.hidden=!1}),this.sortState=null,this.__originalOrder=[],this.#d(),this.#a();const t=this.#o?.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 activeToolPanel(){return this.#e.activePanel}openToolPanel(e){if(!this.#e.toolPanels.get(e)){console.warn(`[tbw-grid] Tool panel "${e}" not found`);return}this.#e.activePanel&&this.#e.activePanel!==e&&this.closeToolPanel(),this.#e.activePanel=e,Le(this.#t,this.#e),Pe(this.#t,this.#e),zt(this.#t,this.#e),this.#s("tool-panel-open",{id:e})}closeToolPanel(){if(!this.#e.activePanel)return;const e=this.#e.activePanel,t=this.#e.toolPanels.get(e);this.#e.activePanelCleanup&&(this.#e.activePanelCleanup(),this.#e.activePanelCleanup=null),t?.onClose?.(),this.#e.activePanel=null,Le(this.#t,this.#e),Pe(this.#t,this.#e),this.#s("tool-panel-close",{id:e})}toggleToolPanel(e){this.#e.activePanel===e?this.closeToolPanel():this.openToolPanel(e)}getToolPanels(){return[...this.#e.toolPanels.values()]}registerToolPanel(e){if(this.#e.toolPanels.has(e.id)){console.warn(`[tbw-grid] Tool panel "${e.id}" already registered`);return}this.#e.toolPanels.set(e.id,e),this.#l&&this.#C()}unregisterToolPanel(e){this.#e.activePanel===e&&this.closeToolPanel(),this.#e.toolPanels.delete(e),this.#l&&this.#C()}getHeaderContents(){return[...this.#e.headerContents.values()]}registerHeaderContent(e){if(this.#e.headerContents.has(e.id)){console.warn(`[tbw-grid] Header content "${e.id}" already registered`);return}this.#e.headerContents.set(e.id,e),this.#l&&Te(this.#t,this.#e)}unregisterHeaderContent(e){const t=this.#e.headerContentCleanups.get(e);t&&(t(),this.#e.headerContentCleanups.delete(e)),this.#e.headerContents.get(e)?.onDestroy?.(),this.#e.headerContents.delete(e),this.#t.querySelector(`[data-header-content="${e}"]`)?.remove()}getToolbarButtons(){return Bt(this.#n?.shell,this.#e)}registerToolbarButton(e){if(this.#e.toolbarButtons.has(e.id)){console.warn(`[tbw-grid] Toolbar button "${e.id}" already registered`);return}this.#e.toolbarButtons.set(e.id,e),this.#l&&this.#C()}unregisterToolbarButton(e){const t=this.#e.toolbarButtonCleanups.get(e);t&&(t(),this.#e.toolbarButtonCleanups.delete(e)),this.#e.toolbarButtons.delete(e),this.#l&&this.#C()}setToolbarButtonDisabled(e,t){const n=this.#e.toolbarButtons.get(e);n&&(n.disabled=t);const i=this.#t.querySelector(`[data-btn="${e}"]`);i&&(i.disabled=t)}refreshShellHeader(){this.#C()}#C(){ke(this,this.#e),this.#$(),this.#z()}refreshVirtualWindow(e=!1){if(!this.bodyEl)return;const t=this._rows.length;if(!this.virtualization.enabled){this.#I(0,t),this.#v();return}if(this.#ee()){this.virtualization.start=0,this.virtualization.end=t,this.bodyEl.style.transform="translateY(0px)",this.#I(0,t,this.__rowRenderEpoch),this.virtualization.totalHeightEl&&(this.virtualization.totalHeightEl.style.height=`${t*this.virtualization.rowHeight}px`),this.setAttribute("aria-rowcount",String(t)),this.setAttribute("aria-colcount",String(this.visibleColumns.length)),this.#v();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);a<0&&(a=0);const d=Math.ceil(r/s)+2;let c=a+d;c>t&&(c=t),this.virtualization.start=a,this.virtualization.end=c,this.virtualization.totalHeightEl&&(this.virtualization.totalHeightEl.style.height=`${t*s}px`);const h=-(l%s);this.bodyEl.style.transform=`translateY(${h}px)`,this.#I(a,c,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),this.setAttribute("aria-rowcount",String(t)),this.setAttribute("aria-colcount",String(this.visibleColumns.length)),e&&this.#v()}#$(){ke(this,this.#e);const e=this.#n?.shell,t=Ot(e,this.#e),n=`
35
+ <div class="tbw-scroll-area">
36
+ <div class="rows-body-wrapper">
37
+ <div class="rows-body">
38
+ <div class="header">
39
+ <div class="header-row" part="header-row"></div>
40
+ </div>
41
+ <div class="rows-container">
42
+ <div class="rows-viewport">
43
+ <div class="rows"></div>
44
+ </div>
45
+ </div>
46
+ </div>
47
+ </div>
48
+ </div>
49
+ <div class="faux-vscroll">
50
+ <div class="faux-vscroll-spacer"></div>
51
+ </div>
52
+ `;if(t){const i=Dt(e,this.#e),r=Ht(e,this.#e,n);this.#t.innerHTML=`
53
+ <div class="tbw-grid-root has-shell">
54
+ ${i}
55
+ ${r}
56
+ </div>
57
+ `,this.#se(),this.#l=!0}else this.#t.innerHTML=`
58
+ <div class="tbw-grid-root">
59
+ <div class="tbw-grid-content">
60
+ ${n}
61
+ </div>
62
+ </div>
63
+ `}#se(){Nt(this.#t,this.#n?.shell,this.#e,{onPanelToggle:e=>this.toggleToolPanel(e),onPanelClose:()=>this.closeToolPanel(),onToolbarButtonClick:e=>this.#le(e)})}#le(e){const n=(this.#n?.shell?.header?.toolbarButtons??[]).find(r=>r.id===e);if(n?.action){n.action();return}const i=this.#e.toolbarButtons.get(e);i?.action&&i.action()}}customElements.get(K.tagName)||customElements.define(K.tagName,K);class E{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}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}function j(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 Kt(o){const e=j(o);return{from:{row:e.startRow,col:e.startCol},to:{row:e.endRow,col:e.endCol}}}function ee(o){return o.map(Kt)}function Wt(o,e,t){const n=j(t);return o>=n.startRow&&o<=n.endRow&&e>=n.startCol&&e<=n.endCol}function Me(o,e,t){return t.some(n=>Wt(o,e,n))}function Vt(o){const e=[],t=j(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 Gt(o){const e=new Map;for(const t of o)for(const n of Vt(t))e.set(`${n.row},${n.col}`,n);return[...e.values()]}function Ie(o,e){return{startRow:o.row,startCol:o.col,endRow:e.row,endCol:e.col}}function jt(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:ee(e.ranges)}:{mode:o,ranges:[]}}class Ut extends E{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.#t()),this.requestAfterRender(),!1;if(r==="row")return this.selected.clear(),this.selected.add(t),this.lastSelected=t,this.emit("selection-change",this.#t()),this.requestAfterRender(),!1;if(r==="range"){const s=i.shiftKey,l=i.ctrlKey||i.metaKey;if(s&&this.cellAnchor){const a=Ie(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.#t()),this.requestAfterRender(),!1}return!1}onKeyDown(e){const{mode:t}=this.config;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.#t()),this.requestAfterRender(),!0;if(t==="range"&&e.key==="a"&&(e.ctrlKey||e.metaKey)){const n=this.rows.length,i=this.columns.length;if(n>0&&i>0){const r={startRow:0,startCol:0,endRow:n-1,endCol:i-1};return this.ranges=[r],this.activeRange=r,this.emit("selection-change",this.#t()),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.#t()),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=Ie(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.#t()),this.requestAfterRender(),!0}onCellMouseUp(e){if(this.config.mode==="range"&&this.isDragging)return this.isDragging=!1,!0}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),e.querySelectorAll(".cell").forEach(s=>{s.classList.remove("selected","top","bottom","first","last")});const r=e.querySelectorAll(".data-grid-row");if(r.forEach(s=>{s.classList.remove("selected")}),n==="row"&&(r.forEach(s=>s.classList.remove("row-focus")),r.forEach(s=>{const l=s.querySelector(".cell[data-row]"),a=parseInt(l?.getAttribute("data-row")??"-1",10);a>=0&&this.selected.has(a)&&s.classList.add("selected","row-focus")})),n==="range"&&this.ranges.length>0){const s=this.activeRange?j(this.activeRange):null;e.querySelectorAll(".cell[data-row][data-col]").forEach(a=>{const d=parseInt(a.getAttribute("data-row")??"-1",10),c=parseInt(a.getAttribute("data-col")??"-1",10);d>=0&&c>=0&&Me(d,c,this.ranges)&&(a.classList.add("selected"),s&&(d===s.startRow&&a.classList.add("top"),d===s.endRow&&a.classList.add("bottom"),c===s.startCol&&a.classList.add("first"),c===s.endCol&&a.classList.add("last")))})}}getSelectedCell(){return this.selectedCell}getSelectedRows(){return[...this.selected]}getRanges(){return ee(this.ranges)}getSelectedCells(){return Gt(this.ranges)}isCellSelected(e,t){return Me(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:ee(this.ranges)}),this.requestAfterRender()}#t(){return jt(this.config.mode,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges},this.columns.length)}styles=`
64
+ /* Prevent text selection during range drag */
65
+ :host .selecting .data-grid-row > .cell {
66
+ user-select: none;
67
+ }
68
+
69
+ /* Row selection - use accent color for row focus */
70
+ :host .data-grid-row.row-focus {
71
+ background-color: var(--tbw-focus-background, rgba(from var(--tbw-color-accent) r g b / 12%));
72
+ }
73
+
74
+ /* Disable cell-focus outline in row mode - row is the focus unit */
75
+ :host([data-selection-mode="row"]) .cell-focus {
76
+ outline: none;
77
+ }
78
+
79
+ /* Selection cell styles - for range mode */
80
+ :host .data-grid-row > .cell.selected {
81
+ background-color: var(--tbw-range-selection-bg);
82
+ }
83
+ :host .data-grid-row > .cell.selected.top {
84
+ border-top: 2px solid var(--tbw-range-border-color);
85
+ }
86
+ :host .data-grid-row > .cell.selected.bottom {
87
+ border-bottom: 2px solid var(--tbw-range-border-color);
88
+ }
89
+ :host .data-grid-row > .cell.selected.first {
90
+ border-left: 2px solid var(--tbw-range-border-color);
91
+ }
92
+ :host .data-grid-row > .cell.selected.last {
93
+ border-right: 2px solid var(--tbw-range-border-color);
94
+ }
95
+ `}function te(o,e,t){return o.id!==void 0?String(o.id):t?`${t}-${e}`:String(e)}function Oe(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],d=te(a,l,n),c=a[r],h=Array.isArray(c)&&c.length>0,u=t.has(d);if(s.push({key:d,data:a,depth:i,hasChildren:h,isExpanded:u,parentKey:n}),h&&u){const f=Oe(c,e,t,d,i+1);s.push(...f)}}return s}function De(o,e){const t=new Set(o);return t.has(e)?t.delete(e):t.add(e),t}function oe(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=te(l,s,t),d=l[i];if(Array.isArray(d)&&d.length>0){r.add(a);const c=oe(d,e,a,n+1);for(const h of c)r.add(h)}}return r}function Xt(){return new Set}function He(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=te(l,s,n);if(a===e)return[a];const d=l[r];if(Array.isArray(d)&&d.length>0){const c=He(d,e,t,a,i+1);if(c)return[a,...c]}}return null}function Yt(o,e,t,n){const i=He(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 Ne(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 Jt(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}class Zt extends E{name="tree";version="1.0.0";get defaultConfig(){return{enabled:!0,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??Jt(e)??"children";return Ne(e,t)}processRows(e){const t=this.config.childrenField??"children";if(!Ne(e,t))return this.flattenedRows=[],this.rowKeyMap.clear(),[...e];this.config.defaultExpanded&&!this.initialExpansionDone&&(this.expandedKeys=oe(e,this.config),this.initialExpansionDone=!0),this.flattenedRows=Oe(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;r.viewRenderer=l=>{const{value:a,row:d,column:c}=l,h=d.__treeDepth??0,u=d.__treeHasChildren??!1,f=d.__treeExpanded??!1,p=document.createElement("span");if(p.style.display="flex",p.style.alignItems="center",p.style.paddingLeft=`${h*t}px`,u&&n){const b=document.createElement("span");b.className="tree-toggle",b.textContent=f?"▼":"▶",b.style.cursor="pointer",b.style.marginRight="4px",b.style.fontSize="10px",b.setAttribute("data-tree-key",d.__treeKey),p.appendChild(b)}else if(n){const b=document.createElement("span");b.style.width="14px",b.style.display="inline-block",p.appendChild(b)}const g=document.createElement("span");if(s){const b=s(l);b instanceof Node?g.appendChild(b):g.textContent=String(b??a??"")}else g.textContent=String(a??"");return p.appendChild(g),p},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=De(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=De(this.expandedKeys,e),this.requestRender()}expandAll(){this.expandedKeys=oe(this.rows,this.config),this.requestRender()}collapseAll(){this.expandedKeys=Xt(),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=Yt(this.rows,e,this.config,this.expandedKeys),this.requestRender()}styles=`
96
+ .tree-toggle {
97
+ cursor: pointer;
98
+ user-select: none;
99
+ transition: transform 0.2s;
100
+ }
101
+ .tree-toggle:hover {
102
+ color: var(--tbw-tree-accent, var(--tbw-color-accent));
103
+ }
104
+ `}const S={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"},W={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"},Qt={ROOT:`.${S.ROOT}`,HEADER:`.${S.HEADER}`,HEADER_ROW:`.${S.HEADER_ROW}`,HEADER_CELL:`.${S.HEADER_CELL}`,ROWS_VIEWPORT:`.${S.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${S.ROWS_CONTAINER}`,DATA_ROW:`.${S.DATA_ROW}`,DATA_CELL:`.${S.DATA_CELL}`,GROUP_ROW:`.${S.GROUP_ROW}`,ROW_BY_INDEX:o=>`.${S.DATA_ROW}[${W.ROW_INDEX}="${o}"]`,CELL_BY_FIELD:o=>`.${S.DATA_CELL}[${W.FIELD}="${o}"]`,CELL_AT:(o,e)=>`.${S.DATA_ROW}[${W.ROW_INDEX}="${o}"] .${S.DATA_CELL}[${W.COL_INDEX}="${e}"]`,SELECTED_ROWS:`.${S.DATA_ROW}.${S.SELECTED}`,EDITING_CELL:`.${S.DATA_CELL}.${S.EDITING}`},eo={COLOR_BG:"--tbw-color-bg",COLOR_FG:"--tbw-color-fg",COLOR_FG_MUTED:"--tbw-color-fg-muted",COLOR_BORDER:"--tbw-color-border",COLOR_ACCENT:"--tbw-color-accent",COLOR_HEADER_BG:"--tbw-color-header-bg",COLOR_HEADER_FG:"--tbw-color-header-fg",COLOR_SELECTION:"--tbw-color-selection",COLOR_ROW_HOVER:"--tbw-color-row-hover",COLOR_ROW_ALT:"--tbw-color-row-alt",ROW_HEIGHT:"--tbw-row-height",HEADER_HEIGHT:"--tbw-header-height",CELL_PADDING:"--tbw-cell-padding",FONT_FAMILY:"--tbw-font-family",FONT_SIZE:"--tbw-font-size",BORDER_RADIUS:"--tbw-border-radius",FOCUS_OUTLINE:"--tbw-focus-outline"},to={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"},oo={SELECTION_CHANGE:"selection-change",TREE_EXPAND:"tree-expand",FILTER_CHANGE:"filter-change",SORT_MODEL_CHANGE:"sort-model-change",EXPORT_START:"export-start",EXPORT_COMPLETE:"export-complete",CLIPBOARD_COPY:"clipboard-copy",CLIPBOARD_PASTE:"clipboard-paste",CONTEXT_MENU_OPEN:"context-menu-open",CONTEXT_MENU_CLOSE:"context-menu-close",HISTORY_CHANGE:"history-change",SERVER_LOADING:"server-loading",SERVER_ERROR:"server-error",COLUMN_VISIBILITY_CHANGE:"column-visibility-change",COLUMN_REORDER:"column-reorder",DETAIL_EXPAND:"detail-expand",GROUP_EXPAND:"group-expand"};function no(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??`
105
+ `;return n.quoteStrings||i.includes(r)||i.includes(s)||i.includes('"')?`"${i.replace(/"/g,'""')}"`:i}function ne(o){const{rows:e,columns:t,selectedIndices:n,config:i}=o,r=i.delimiter??" ",s=i.newline??`
106
+ `,l=t.filter(h=>!h.hidden&&!h.field.startsWith("__")),a=[];if(i.includeHeaders){const h=l.map(u=>{const f=u.header||u.field;return f.includes(r)||f.includes(s)||f.includes('"')?`"${f.replace(/"/g,'""')}"`:f});a.push(h.join(r))}const c=[...n instanceof Set?[...n]:n].sort((h,u)=>h-u);for(const h of c){const u=e[h];if(!u)continue;const f=l.map(p=>no(u[p.field],p.field,u,i));a.push(f.join(r))}return a.join(s)}async function ie(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 qe(o,e){const t=e.delimiter??" ",n=e.newline??`
107
+ `,i=o.replace(/\r\n/g,`
108
+ `).replace(/\r/g,`
109
+ `),r=[];let s=[],l="",a=!1;for(let d=0;d<i.length;d++){const c=i[d];c==='"'&&!a?a=!0:c==='"'&&a?i[d+1]==='"'?(l+='"',d++):a=!1:c===t&&!a?(s.push(l),l=""):c===n&&!a?(s.push(l),l="",(s.length>1||s.some(h=>h.trim()!==""))&&r.push(s),s=[]):l+=c}return s.push(l),(s.length>1||s.some(d=>d.trim()!==""))&&r.push(s),r}async function ze(){try{return await navigator.clipboard.readText()}catch{return""}}class io extends E{name="clipboard";version="1.0.0";get defaultConfig(){return{enabled:!0,includeHeaders:!1,delimiter:" ",newline:`
110
+ `,quoteStrings:!1}}lastCopied=null;detach(){this.lastCopied=null}onKeyDown(e){if(this.config.enabled===!1)return!1;const t=(e.ctrlKey||e.metaKey)&&e.key==="c",n=(e.ctrlKey||e.metaKey)&&e.key==="v";return t?(this.#t(e.target),!0):n?(this.#b(),!0):!1}#t(e){const t=this.#w(),n=t?.getSelectedRows()??[],i=n.length>0,r=t?.getRanges()??[],s=r.length>0,l=t?.getSelectedCell()!=null;let a,d,c;if(i&&t)a=ne({rows:this.rows,columns:[...this.columns],selectedIndices:n,config:this.config}),d=n.length,c=this.columns.filter(h=>!h.hidden&&!h.field.startsWith("__")).length;else if(s&&t){const h=r[r.length-1],u=this.#i({startRow:h.from.row,startCol:h.from.col,endRow:h.to.row,endCol:h.to.col});a=u.text,d=u.rowCount,c=u.columnCount}else if(l&&t){const h=t.getSelectedCell(),u=this.#y(h.row,h.col);if(!u)return;a=u.text,d=1,c=1}else{const h=this.#r(e);if(!h)return;a=h.text,d=1,c=1}ie(a).then(()=>{this.lastCopied={text:a,timestamp:Date.now()},this.emit("copy",{text:a,rowCount:d,columnCount:c})})}#b(){ze().then(e=>{if(!e)return;const t=qe(e,this.config);this.emit("paste",{rows:t,text:e})})}#w(){try{const e=this.grid;if(e?._plugins){for(const t of e._plugins)if(t.name==="selection")return t}}catch{}}#y(e,t){const n=this.rows[e];if(!n)return null;const i=this.columns[t];if(!i)return null;const r=n[i.field],s=i.header||i.field;let l;if(this.config.includeHeaders){const a=r==null?"":String(r);l=`${s}: ${a}`}else l=r==null?"":String(r);return{text:l}}#i(e){const{startRow:t,startCol:n,endRow:i,endCol:r}=e,s=Math.min(t,i),l=Math.max(t,i),a=Math.min(n,r),d=Math.max(n,r),c=this.config.delimiter??" ",h=this.config.newline??`
111
+ `,u=[],f=this.columns.slice(a,d+1);if(this.config.includeHeaders){const p=f.map(g=>g.header||g.field);u.push(p.join(c))}for(let p=s;p<=l;p++){const g=this.rows[p];if(!g)continue;const b=f.map(y=>{const A=g[y.field];return A==null?"":A instanceof Date?A.toISOString():String(A)});u.push(b.join(c))}return{text:u.join(h),rowCount:l-s+1,columnCount:d-a+1}}#r(e){const t=e.closest("[data-field-cache]");if(!t)return null;const n=t.dataset.fieldCache;if(!n)return null;const i=t.dataset.row;if(!i)return null;const r=parseInt(i,10);if(isNaN(r))return null;const s=this.rows[r];if(!s)return null;const l=s[n],d=this.columns.find(h=>h.field===n)?.header||n;let c;if(this.config.includeHeaders){const h=l==null?"":String(l);c=`${d}: ${h}`}else c=l==null?"":String(l);return{text:c,field:n,value:l}}async copy(){const t=this.#w()?.getSelectedRows()??[],n=ne({rows:this.rows,columns:[...this.columns],selectedIndices:t,config:this.config});return await ie(n),this.lastCopied={text:n,timestamp:Date.now()},n}async copyRows(e){const t=ne({rows:this.rows,columns:[...this.columns],selectedIndices:e,config:this.config});return await ie(t),this.lastCopied={text:t,timestamp:Date.now()},t}async paste(){const e=await ze();return e?qe(e,this.config):null}getLastCopied(){return this.lastCopied}}const Be=100;function re(o){if(o==null)return Be;if(typeof o=="number")return o;const e=parseFloat(o);return isNaN(e)?Be:e}function Fe(o){return o.map(e=>re(e.width))}function $e(o){const e=[];let t=0;for(const n of o)e.push(t),t+=re(n.width);return e}function Ke(o){return o.reduce((e,t)=>e+re(t.width),0)}function ro(o,e,t,n,i){const r=t.length;if(r===0)return{startCol:0,endCol:0,visibleColumns:[]};let s=so(o,t,n);s=Math.max(0,s-i);const l=o+e;let a=s;for(let c=s;c<r;c++){if(t[c]>=l){a=c-1;break}a=c}a=Math.min(r-1,a+i);const d=[];for(let c=s;c<=a;c++)d.push(c);return{startCol:s,endCol:a,visibleColumns:d}}function so(o,e,t){let n=0,i=e.length-1;for(;n<i;){const r=Math.floor((n+i)/2);e[r]+t[r]<=o?n=r+1:i=r}return n}function lo(o,e,t){return t?o>e:!1}class ao extends E{name="columnVirtualization";version="1.0.0";get defaultConfig(){return{enabled:!0,autoEnable:!0,threshold:30,overscan:3}}isVirtualized=!1;startCol=0;endCol=0;scrollLeft=0;totalWidth=0;columnWidths=[];columnOffsets=[];attach(e){super.attach(e);const t=this.columns;this.columnWidths=Fe(t),this.columnOffsets=$e(t),this.totalWidth=Ke(t),this.endCol=t.length-1}detach(){this.columnWidths=[],this.columnOffsets=[],this.isVirtualized=!1,this.startCol=0,this.endCol=0,this.scrollLeft=0,this.totalWidth=0}processColumns(e){const t=this.config.enabled&&lo(e.length,this.config.threshold??30,this.config.autoEnable??!0);if(this.isVirtualized=t??!1,this.columnWidths=Fe(e),this.columnOffsets=$e(e),this.totalWidth=Ke(e),!t)return this.startCol=0,this.endCol=e.length-1,[...e];const n=this.grid.clientWidth||800,i=ro(this.scrollLeft,n,this.columnOffsets,this.columnWidths,this.config.overscan??3);return this.startCol=i.startCol,this.endCol=i.endCol,i.visibleColumns.map(r=>e[r])}afterRender(){if(!this.isVirtualized)return;const e=this.shadowRoot;if(!e)return;const t=this.columnOffsets[this.startCol]??0,n=e.querySelector(".header-row"),i=e.querySelectorAll(".data-grid-row");n&&(n.style.paddingLeft=`${t}px`),i.forEach(s=>{s.style.paddingLeft=`${t}px`});const r=e.querySelector(".rows-viewport .rows");r&&(r.style.width=`${this.totalWidth}px`)}onScroll(e){!this.isVirtualized||Math.abs(e.scrollLeft-this.scrollLeft)<1||(this.scrollLeft=e.scrollLeft,this.requestRender())}getIsVirtualized(){return this.isVirtualized}getVisibleColumnRange(){return{start:this.startCol,end:this.endCol}}scrollToColumn(e){const t=this.columnOffsets[e]??0,n=this.grid;n.scrollLeft=t}getColumnOffset(e){return this.columnOffsets[e]??0}getTotalWidth(){return this.totalWidth}}function se(o,e){return(typeof o=="function"?o(e):o).filter(n=>!(n.hidden===!0||typeof n.hidden=="function"&&n.hidden(e)))}function co(o,e){return o.disabled===!0?!0:typeof o.disabled=="function"?o.disabled(e):!1}function le(o,e,t){const n=document.createElement("div");n.className="tbw-context-menu",n.setAttribute("role","menu");for(const i of o){if(i.separator){const a=document.createElement("div");a.className="tbw-context-menu-separator",a.setAttribute("role","separator"),n.appendChild(a);continue}const r=document.createElement("div");r.className="tbw-context-menu-item",i.cssClass&&r.classList.add(i.cssClass),r.setAttribute("role","menuitem"),r.setAttribute("data-id",i.id);const s=co(i,e);if(s&&(r.classList.add("disabled"),r.setAttribute("aria-disabled","true")),i.icon){const a=document.createElement("span");a.className="tbw-context-menu-icon",a.innerHTML=i.icon,r.appendChild(a)}const l=document.createElement("span");if(l.className="tbw-context-menu-label",l.textContent=i.name,r.appendChild(l),i.shortcut){const a=document.createElement("span");a.className="tbw-context-menu-shortcut",a.textContent=i.shortcut,r.appendChild(a)}if(i.subMenu?.length){const a=document.createElement("span");a.className="tbw-context-menu-arrow",a.textContent="▶",r.appendChild(a),r.addEventListener("mouseenter",()=>{if(r.querySelector(".tbw-context-menu")||!i.subMenu)return;const c=se(i.subMenu,e),h=le(c,e,t);h.classList.add("tbw-context-submenu"),h.style.position="absolute",h.style.left="100%",h.style.top="0",r.style.position="relative",r.appendChild(h)}),r.addEventListener("mouseleave",()=>{const d=r.querySelector(".tbw-context-menu");d&&d.remove()})}!s&&i.action&&!i.subMenu&&r.addEventListener("click",a=>{a.stopPropagation(),t(i)}),n.appendChild(r)}return n}function We(o,e,t){o.style.position="fixed",o.style.left=`${e}px`,o.style.top=`${t}px`,o.style.visibility="hidden",o.style.zIndex="10000";const n=o.getBoundingClientRect(),i=window.innerWidth,r=window.innerHeight;let s=e,l=t;e+n.width>i&&(s=e-n.width),t+n.height>r&&(l=t-n.height),s=Math.max(0,s),l=Math.max(0,l),o.style.left=`${s}px`,o.style.top=`${l}px`,o.style.visibility="visible"}let ae=null,ce=null,V=null;const uo=`
112
+ .tbw-context-menu {
113
+ position: fixed;
114
+ background: light-dark(#f5f5f5, #2a2a2a);
115
+ color: light-dark(#222, #eee);
116
+ border: 1px solid light-dark(#d0d0d4, #454545);
117
+ border-radius: 4px;
118
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
119
+ min-width: 160px;
120
+ padding: 4px 0;
121
+ z-index: 10000;
122
+ font-size: 13px;
123
+ font-family: system-ui, sans-serif;
124
+ }
125
+ .tbw-context-menu-item {
126
+ display: flex;
127
+ align-items: center;
128
+ padding: 6px 12px;
129
+ cursor: pointer;
130
+ gap: 8px;
131
+ }
132
+ .tbw-context-menu-item:hover:not(.disabled) {
133
+ background: light-dark(#e8e8e8, #3a3a3a);
134
+ }
135
+ .tbw-context-menu-item.disabled {
136
+ opacity: 0.5;
137
+ cursor: default;
138
+ }
139
+ .tbw-context-menu-item.danger {
140
+ color: light-dark(#c00, #f66);
141
+ }
142
+ .tbw-context-menu-icon {
143
+ width: 16px;
144
+ text-align: center;
145
+ }
146
+ .tbw-context-menu-label {
147
+ flex: 1;
148
+ }
149
+ .tbw-context-menu-shortcut {
150
+ color: light-dark(#888, #888);
151
+ font-size: 11px;
152
+ }
153
+ .tbw-context-menu-arrow {
154
+ font-size: 10px;
155
+ color: light-dark(#888, #888);
156
+ }
157
+ .tbw-context-menu-separator {
158
+ height: 1px;
159
+ background: light-dark(#d0d0d4, #454545);
160
+ margin: 4px 0;
161
+ }
162
+ `,de=[{id:"copy",name:"Copy",shortcut:"Ctrl+C",action:o=>{o.grid?.plugins?.clipboard?.copy?.()}},{separator:!0,id:"sep1",name:""},{id:"export-csv",name:"Export CSV",action:o=>{o.grid?.plugins?.export?.exportCsv?.()}}];class ho extends E{name="contextMenu";version="1.0.0";get defaultConfig(){return{enabled:!0,items:de}}isOpen=!1;position={x:0,y:0};params=null;menuElement=null;attach(e){super.attach(e),this.installGlobalHandlers()}detach(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null),this.isOpen=!1,this.params=null}installGlobalHandlers(){!V&&typeof document<"u"&&(V=document.createElement("style"),V.id="tbw-context-menu-styles",V.textContent=uo,document.head.appendChild(V)),ae||(ae=()=>{document.querySelectorAll(".tbw-context-menu").forEach(t=>t.remove())},document.addEventListener("click",ae)),ce||(ce=e=>{e.key==="Escape"&&document.querySelectorAll(".tbw-context-menu").forEach(n=>n.remove())},document.addEventListener("keydown",ce))}afterRender(){if(!this.config.enabled)return;const e=this.shadowRoot;if(!e)return;const t=e.children[0];t&&t.getAttribute("data-context-menu-bound")!=="true"&&(t.setAttribute("data-context-menu-bound","true"),t.addEventListener("contextmenu",n=>{if(!this.config.enabled)return;const i=n;i.preventDefault();const r=i.target,s=r.closest("[data-row][data-col]"),l=r.closest(".header-cell");let a;if(s){const c=parseInt(s.getAttribute("data-row")??"-1",10),h=parseInt(s.getAttribute("data-col")??"-1",10),u=this.columns[h],f=this.rows[c];a={row:f,rowIndex:c,column:u,columnIndex:h,field:u?.field??"",value:f?.[u?.field]??null,isHeader:!1,event:i}}else if(l){const c=parseInt(l.getAttribute("data-col")??"-1",10),h=this.columns[c];a={row:null,rowIndex:-1,column:h,columnIndex:c,field:h?.field??"",value:null,isHeader:!0,event:i}}else return;this.params=a,this.position={x:i.clientX,y:i.clientY};const d=se(this.config.items??de,a);d.length&&(this.menuElement&&this.menuElement.remove(),this.menuElement=le(d,a,c=>{c.action&&c.action(a),this.menuElement?.remove(),this.menuElement=null,this.isOpen=!1}),document.body.appendChild(this.menuElement),We(this.menuElement,i.clientX,i.clientY),this.isOpen=!0,this.emit("context-menu-open",{params:a,items:d}))}))}showMenu(e,t,n){const i={row:n.row??null,rowIndex:n.rowIndex??-1,column:n.column??null,columnIndex:n.columnIndex??-1,field:n.field??"",value:n.value??null,isHeader:n.isHeader??!1,event:n.event??new MouseEvent("contextmenu")},r=se(this.config.items??de,i);this.menuElement&&this.menuElement.remove(),this.menuElement=le(r,i,s=>{s.action&&s.action(i),this.menuElement?.remove(),this.menuElement=null,this.isOpen=!1}),document.body.appendChild(this.menuElement),We(this.menuElement,e,t),this.isOpen=!0}hideMenu(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null,this.isOpen=!1)}isMenuOpen(){return this.isOpen}}function Ve(o,e=!0){if(o==null)return"";if(o instanceof Date)return o.toISOString();if(typeof o=="object")return JSON.stringify(o);const t=String(o);return e&&(t.includes(",")||t.includes('"')||t.includes(`
163
+ `)||t.includes("\r"))?`"${t.replace(/"/g,'""')}"`:t}function fo(o,e,t,n={}){const i=n.delimiter??",",r=n.newline??`
164
+ `,s=[],l=n.bom?"\uFEFF":"";if(t.includeHeaders!==!1){const a=e.map(d=>{const c=d.header||d.field,h=t.processHeader?t.processHeader(c,d.field):c;return Ve(h)});s.push(a.join(i))}for(const a of o){const d=e.map(c=>{let h=a[c.field];return t.processCell&&(h=t.processCell(h,c.field,a)),Ve(h)});s.push(d.join(i))}return l+s.join(r)}function ue(o,e){const t=URL.createObjectURL(o),n=document.createElement("a");n.href=t,n.download=e,n.style.display="none",document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(t)}function po(o,e){const t=new Blob([o],{type:"text/csv;charset=utf-8;"});ue(t,e)}function Ge(o){return o.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}function go(o,e,t){let n=`<?xml version="1.0" encoding="UTF-8"?>
165
+ <?mso-application progid="Excel.Sheet"?>
166
+ <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
167
+ xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
168
+ <Worksheet ss:Name="Sheet1">
169
+ <Table>`;if(t.includeHeaders!==!1){n+=`
170
+ <Row>`;for(const i of e){const r=i.header||i.field,s=t.processHeader?t.processHeader(r,i.field):r;n+=`<Cell><Data ss:Type="String">${Ge(s)}</Data></Cell>`}n+="</Row>"}for(const i of o){n+=`
171
+ <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=Ge(String(s)),n+=`<Cell><Data ss:Type="${l}">${a}</Data></Cell>`}n+="</Row>"}return n+=`
172
+ </Table>
173
+ </Worksheet>
174
+ </Workbook>`,n}function bo(o,e){const t=e.endsWith(".xls")?e:`${e}.xls`,n=new Blob([o],{type:"application/vnd.ms-excel;charset=utf-8;"});ue(n,t)}class wo extends E{name="export";version="1.0.0";get defaultConfig(){return{enabled:!0,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(d=>a.has(d.field))}let s=[...this.rows];if(n.onlySelected){const a=this.getSelectionState();a?.selected?.size&&(s=[...a.selected].sort((c,h)=>c-h).map(c=>this.rows[c]).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=fo(s,r,i,{bom:!0});l=l.endsWith(".csv")?l:`${l}.csv`,po(a,l);break}case"excel":{const a=go(s,r,i);l=l.endsWith(".xls")?l:`${l}.xls`,bo(a,l);break}case"json":{const a=s.map(h=>{const u={};for(const f of r){let p=h[f.field];i.processCell&&(p=i.processCell(p,f.field,h)),u[f.field]=p}return u}),d=JSON.stringify(a,null,2);l=l.endsWith(".json")?l:`${l}.json`;const c=new Blob([d],{type:"application/json"});ue(c,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 mo(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 vo(o,e){return o<=e}function Co(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 yo(o,e,t=!1){return e.length?o.filter(n=>e.every(i=>Co(n,i,t))):o}function xo(o){return JSON.stringify(o.map(e=>({field:e.field,operator:e.operator,value:e.value,valueTo:e.valueTo})))}function je(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 Eo=`
175
+ .tbw-filter-panel {
176
+ position: fixed;
177
+ background: var(--tbw-filter-panel-bg, var(--tbw-color-panel-bg, light-dark(#eeeeee, #222222)));
178
+ color: var(--tbw-filter-panel-fg, var(--tbw-color-fg, light-dark(#222222, #eeeeee)));
179
+ border: 1px solid var(--tbw-filter-panel-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));
180
+ border-radius: var(--tbw-filter-panel-radius, var(--tbw-border-radius, 4px));
181
+ box-shadow: 0 4px 16px var(--tbw-filter-panel-shadow, var(--tbw-color-shadow, light-dark(rgba(0,0,0,0.1), rgba(0,0,0,0.3))));
182
+ padding: 12px;
183
+ z-index: 10000;
184
+ min-width: 200px;
185
+ max-width: 280px;
186
+ max-height: 350px;
187
+ display: flex;
188
+ flex-direction: column;
189
+ font-family: var(--tbw-font-family, system-ui, sans-serif);
190
+ font-size: var(--tbw-font-size, 13px);
191
+ }
192
+
193
+ .tbw-filter-search {
194
+ margin-bottom: 8px;
195
+ }
196
+
197
+ .tbw-filter-search-input {
198
+ width: 100%;
199
+ padding: 6px 10px;
200
+ background: var(--tbw-filter-input-bg, var(--tbw-color-bg, transparent));
201
+ color: inherit;
202
+ border: 1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));
203
+ border-radius: var(--tbw-filter-input-radius, 4px);
204
+ font-size: inherit;
205
+ box-sizing: border-box;
206
+ }
207
+
208
+ .tbw-filter-search-input:focus {
209
+ outline: none;
210
+ border-color: var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));
211
+ box-shadow: 0 0 0 2px rgba(from var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6)) r g b / 15%);
212
+ }
213
+
214
+ .tbw-filter-actions {
215
+ display: flex;
216
+ padding: 4px 2px;
217
+ margin-bottom: 8px;
218
+ border-bottom: 1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));
219
+ }
220
+
221
+ .tbw-filter-action-btn {
222
+ background: transparent;
223
+ border: none;
224
+ color: var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));
225
+ cursor: pointer;
226
+ font-size: 12px;
227
+ padding: 2px 0;
228
+ }
229
+
230
+ .tbw-filter-action-btn:hover {
231
+ text-decoration: underline;
232
+ }
233
+
234
+ .tbw-filter-values {
235
+ flex: 1;
236
+ overflow-y: auto;
237
+ margin-bottom: 8px;
238
+ max-height: 180px;
239
+ position: relative;
240
+ }
241
+
242
+ .tbw-filter-values-spacer {
243
+ width: 1px;
244
+ }
245
+
246
+ .tbw-filter-values-content {
247
+ position: absolute;
248
+ top: 0;
249
+ left: 0;
250
+ right: 0;
251
+ }
252
+
253
+ .tbw-filter-value-item {
254
+ display: flex;
255
+ align-items: center;
256
+ gap: 8px;
257
+ padding: 4px 2px;
258
+ cursor: pointer;
259
+ border-radius: 3px;
260
+ }
261
+
262
+ .tbw-filter-value-item:hover {
263
+ background: var(--tbw-filter-hover, var(--tbw-color-row-hover, light-dark(#f0f6ff, #1c1c1c)));
264
+ }
265
+
266
+ .tbw-filter-checkbox {
267
+ margin: 0;
268
+ cursor: pointer;
269
+ accent-color: var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));
270
+ }
271
+
272
+ .tbw-filter-no-match {
273
+ color: var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));
274
+ padding: 8px 0;
275
+ text-align: center;
276
+ font-style: italic;
277
+ }
278
+
279
+ .tbw-filter-buttons {
280
+ display: flex;
281
+ gap: 8px;
282
+ padding-top: 8px;
283
+ border-top: 1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));
284
+ }
285
+
286
+ .tbw-filter-apply-btn {
287
+ flex: 1;
288
+ padding: 6px 12px;
289
+ background: var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));
290
+ color: var(--tbw-filter-accent-fg, var(--tbw-color-accent-fg, light-dark(#ffffff, #000000)));
291
+ border: none;
292
+ border-radius: 4px;
293
+ cursor: pointer;
294
+ font-size: 13px;
295
+ }
296
+
297
+ .tbw-filter-apply-btn:hover {
298
+ filter: brightness(0.9);
299
+ }
300
+
301
+ .tbw-filter-clear-btn {
302
+ flex: 1;
303
+ padding: 6px 12px;
304
+ background: transparent;
305
+ color: var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));
306
+ border: 1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));
307
+ border-radius: 4px;
308
+ cursor: pointer;
309
+ font-size: 13px;
310
+ }
311
+
312
+ .tbw-filter-clear-btn:hover {
313
+ background: var(--tbw-filter-hover, var(--tbw-color-row-hover, light-dark(#f0f6ff, #1c1c1c)));
314
+ }
315
+ `;class D extends E{name="filtering";version="1.0.0";get defaultConfig(){return{enabled:!0,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;documentClickHandler=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.removeDocumentClickHandler()}processRows(e){const t=[...this.filters.values()];if(!t.length)return[...e];const n=xo(t);if(this.cacheKey===n&&this.cachedResult)return this.cachedResult;const i=yo([...e],t,this.config.caseSensitive);return this.cachedResult=i,this.cacheKey=n,i}afterRender(){if(!this.config.enabled)return;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 je(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=Eo,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=je(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:h=>{this.applySetFilter(e,h),this.closeFilterPanel()},applyTextFilter:(h,u,f)=>{this.applyTextFilter(e,h,u,f),this.closeFilterPanel()},clearFilter:()=>{this.clearFieldFilter(e),this.closeFilterPanel()},closePanel:()=>this.closeFilterPanel()};let d=!1;this.config.filterPanelRenderer&&(this.config.filterPanelRenderer(i,a),d=i.children.length>0),d||this.renderDefaultFilterPanel(i,a,r,s),document.body.appendChild(i),this.positionPanel(i,n);const c=h=>{!i.contains(h.target)&&h.target!==n&&this.closeFilterPanel()};this.documentClickHandler=c,setTimeout(()=>{document.addEventListener("click",c)},0)}closeFilterPanel(){this.panelElement&&(this.panelElement.remove(),this.panelElement=null),this.openPanelField=null,this.removeDocumentClickHandler()}removeDocumentClickHandler(){this.documentClickHandler&&(document.removeEventListener("click",this.documentClickHandler),this.documentClickHandler=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 d=document.createElement("label");d.className="tbw-filter-value-item",d.style.padding="0",d.style.margin="0";const c=document.createElement("input");c.type="checkbox",c.className="tbw-filter-checkbox";const h=document.createElement("span");h.textContent="Select All",d.appendChild(c),d.appendChild(h),a.appendChild(d);const u=()=>{const C=[...b.values()],x=C.every(_=>_),T=C.every(_=>!_);c.checked=x,c.indeterminate=!x&&!T};c.addEventListener("change",()=>{const C=c.checked;for(const x of b.keys())b.set(x,C);u(),I()}),e.appendChild(a);const f=document.createElement("div");f.className="tbw-filter-values";const p=document.createElement("div");p.className="tbw-filter-values-spacer",f.appendChild(p);const g=document.createElement("div");g.className="tbw-filter-values-content",f.appendChild(g);const b=new Map;n.forEach(C=>{const x=C==null?"__null__":String(C);b.set(x,!i.has(C))}),u();let y=[];const A=(C,x)=>{const T=C==null?"(Blank)":String(C),_=C==null?"__null__":String(C),R=document.createElement("label");R.className="tbw-filter-value-item",R.style.position="absolute",R.style.top=`${x*D.LIST_ITEM_HEIGHT}px`,R.style.left="0",R.style.right="0",R.style.height=`${D.LIST_ITEM_HEIGHT}px`,R.style.boxSizing="border-box";const O=document.createElement("input");O.type="checkbox",O.className="tbw-filter-checkbox",O.checked=b.get(_)??!0,O.dataset.value=_,O.addEventListener("change",()=>{b.set(_,O.checked),u()});const lt=document.createElement("span");return lt.textContent=T,R.appendChild(O),R.appendChild(lt),R},I=()=>{const C=y.length,x=f.clientHeight,T=f.scrollTop;if(p.style.height=`${C*D.LIST_ITEM_HEIGHT}px`,vo(C,D.LIST_BYPASS_THRESHOLD/3)){g.innerHTML="",g.style.transform="translateY(0px)",y.forEach((R,O)=>{g.appendChild(A(R,O))});return}const _=mo({totalRows:C,viewportHeight:x,scrollTop:T,rowHeight:D.LIST_ITEM_HEIGHT,overscan:D.LIST_OVERSCAN});g.style.transform=`translateY(${_.offsetY}px)`,g.innerHTML="";for(let R=_.start;R<_.end;R++)g.appendChild(A(y[R],R-_.start))},H=C=>{const x=C.toLowerCase();if(y=n.filter(T=>{const _=T==null?"(Blank)":String(T);return!C||_.toLowerCase().includes(x)}),y.length===0){p.style.height="0px",g.innerHTML="";const T=document.createElement("div");T.className="tbw-filter-no-match",T.textContent="No matching values",g.appendChild(T);return}I()};f.addEventListener("scroll",()=>{y.length>0&&I()},{passive:!0}),H(l.value),e.appendChild(f);let M;l.addEventListener("input",()=>{clearTimeout(M),M=setTimeout(()=>{this.searchText.set(r,l.value),H(l.value)},this.config.debounceMs??150)});const w=document.createElement("div");w.className="tbw-filter-buttons";const m=document.createElement("button");m.className="tbw-filter-apply-btn",m.textContent="Apply",m.addEventListener("click",()=>{const C=[];for(const[x,T]of b)if(!T)if(x==="__null__")C.push(null);else{const _=n.find(R=>String(R)===x);C.push(_!==void 0?_:x)}t.applySetFilter(C)}),w.appendChild(m);const k=document.createElement("button");k.className="tbw-filter-clear-btn",k.textContent="Clear Filter",k.addEventListener("click",()=>{t.clearFilter()}),w.appendChild(k),e.appendChild(w)}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=`
316
+ .header-cell.filtered::before {
317
+ content: '';
318
+ position: absolute;
319
+ top: 4px;
320
+ right: 4px;
321
+ width: 6px;
322
+ height: 6px;
323
+ background: var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));
324
+ border-radius: 50%;
325
+ }
326
+ .tbw-filter-btn {
327
+ display: inline-flex;
328
+ align-items: center;
329
+ justify-content: center;
330
+ background: transparent;
331
+ border: none;
332
+ cursor: pointer;
333
+ padding: 2px;
334
+ margin-left: 4px;
335
+ opacity: 0.4;
336
+ transition: opacity 0.15s;
337
+ color: inherit;
338
+ vertical-align: middle;
339
+ }
340
+ .tbw-filter-btn:hover,
341
+ .tbw-filter-btn.active {
342
+ opacity: 1;
343
+ }
344
+ .tbw-filter-btn.active {
345
+ color: var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));
346
+ }
347
+ `}function Ro(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 d=typeof a=="string"?a:a.id;let c=e.get(d);c||(c={id:d,label:typeof a=="string"?void 0:a.label,columns:[],firstIndex:l},e.set(d,c),t.push(c)),c.columns.push(s)}),i.length&&n(r,i),t.length===1&&t[0].implicit&&t[0].columns.length===o.length?[]:t}function So(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 Ao(o){return o.some(e=>e.group!=null)}class ko extends E{name="groupingColumns";version="1.0.0";get defaultConfig(){return{enabled:!0,showGroupBorders:!0}}groups=[];isActive=!1;detach(){this.groups=[],this.isActive=!1}static detect(e,t){const n=t?.columns;return Array.isArray(n)?Ao(n):!1}processColumns(e){if(!this.config.enabled)return this.isActive=!1,this.groups=[],[...e];const t=Ro(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&&So(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=`
348
+ .header-group-row {
349
+ display: grid;
350
+ grid-auto-flow: column;
351
+ background: var(--tbw-grouping-columns-header-bg, var(--tbw-color-header-bg));
352
+ border-bottom: 1px solid var(--tbw-grouping-columns-border, var(--tbw-color-border));
353
+ }
354
+ .header-group-cell {
355
+ display: flex;
356
+ align-items: center;
357
+ justify-content: center;
358
+ padding: 4px 8px;
359
+ font-weight: 600;
360
+ font-size: 0.9em;
361
+ text-transform: uppercase;
362
+ letter-spacing: 0.5px;
363
+ border-right: 1px solid var(--tbw-grouping-columns-border, var(--tbw-color-border));
364
+ }
365
+ .header-group-cell:last-child {
366
+ border-right: none;
367
+ }
368
+ .header-row .cell.grouped {
369
+ border-top: none;
370
+ }
371
+ .header-row .cell.group-end {
372
+ border-right: 2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong));
373
+ }
374
+ `}const he={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]},G=new Map,P={register(o,e){G.set(o,e)},unregister(o){G.delete(o)},get(o){if(o!==void 0)return typeof o=="function"?o:G.get(o)??he[o]},run(o,e,t,n){const i=this.get(o);return i?i(e,t,n):void 0},has(o){return G.has(o)||o in he},list(){return[...Object.keys(he),...G.keys()]}};P.register.bind(P),P.unregister.bind(P);const To=P.get.bind(P),Ue=P.run.bind(P);P.list.bind(P);function Lo({rows:o,config:e,expanded:t}){const n=e.groupOn;if(!e.enabled||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 d=i;a.forEach((c,h)=>{const u=c==null?"∅":String(c),f=d.key==="__root__"?u:d.key+"||"+u;let p=d.children.get(u);p||(p={key:f,value:c,depth:h,rows:[],children:new Map,parent:d},d.children.set(u,p)),d=p}),d.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(d=>s(d));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(d=>s(d)):l.rows.forEach(d=>r.push({kind:"data",row:d,rowIndex:o.indexOf(d)})))};return s(i),r}function Po(o,e){const t=new Set(o);return t.has(e)?t.delete(e):t.add(e),t}function Mo(o){const e=new Set;for(const t of o)t.kind==="group"&&e.add(t.key);return e}function Io(){return new Set}function Oo(o){return o.kind!=="group"?0:o.rows.length}class Do extends E{name="groupingRows";version="1.0.0";get defaultConfig(){return{enabled:!0,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(!t.enabled||typeof t.groupOn!="function")return this.isActive=!1,this.flattenedRows=[],[...e];const n=Lo({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:Oo(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"),s.textContent=e.__groupExpanded?"▾":"▸",s.addEventListener("click",d=>{d.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 d=document.createElement("span");d.className="group-count",d.textContent=`(${e.__groupRowCount??e.__groupRows?.length??0})`,r.appendChild(d)}t.appendChild(r)}renderPerColumnGroupRow(e,t,n){const i=this.config,r=i.aggregators??{},s=this.columns,l=e.__groupRows??[];this.grid;const d=this.shadowRoot?.querySelector(".body")?.style.gridTemplateColumns||"";d&&(t.style.display="grid",t.style.gridTemplateColumns=d),s.forEach((c,h)=>{const u=document.createElement("div");if(u.className="cell group-cell",u.setAttribute("data-col",String(h)),u.setAttribute("role","gridcell"),h===0){const f=document.createElement("button");f.type="button",f.className="group-toggle",f.textContent=e.__groupExpanded?"▾":"▸",f.addEventListener("click",b=>{b.stopPropagation(),n()}),u.appendChild(f);const p=document.createElement("span"),g=r[c.field];if(g){const b=Ue(g,l,c.field,c);p.textContent=b!=null?String(b):String(e.__groupValue)}else{const b=i.formatLabel?i.formatLabel(e.__groupValue,e.__groupDepth||0,e.__groupKey):String(e.__groupValue);p.textContent=b}if(u.appendChild(p),i.showRowCount!==!1){const b=document.createElement("span");b.className="group-count",b.textContent=` (${l.length})`,u.appendChild(b)}}else{const f=r[c.field];if(f){const p=Ue(f,l,c.field,c);u.textContent=p!=null?String(p):""}else u.textContent=""}t.appendChild(u)})}expandAll(){this.expandedKeys=Mo(this.flattenedRows),this.requestRender()}collapseAll(){this.expandedKeys=Io(),this.requestRender()}toggle(e){this.expandedKeys=Po(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=`
375
+ .group-row {
376
+ background: var(--tbw-grouping-rows-bg, var(--tbw-color-panel-bg));
377
+ font-weight: 500;
378
+ }
379
+ .group-row:hover {
380
+ background: var(--tbw-grouping-rows-bg-hover, var(--tbw-color-row-hover));
381
+ }
382
+ .group-toggle {
383
+ cursor: pointer;
384
+ user-select: none;
385
+ display: inline-flex;
386
+ align-items: center;
387
+ justify-content: center;
388
+ width: 20px;
389
+ height: 20px;
390
+ margin-right: 4px;
391
+ font-size: 10px;
392
+ }
393
+ .group-toggle:hover {
394
+ background: var(--tbw-grouping-rows-toggle-hover, var(--tbw-color-row-hover));
395
+ border-radius: 2px;
396
+ }
397
+ .group-label {
398
+ display: inline-flex;
399
+ align-items: center;
400
+ gap: 8px;
401
+ }
402
+ .group-count {
403
+ color: var(--tbw-grouping-rows-count-color, var(--tbw-color-fg-muted));
404
+ font-size: 0.85em;
405
+ font-weight: normal;
406
+ }
407
+ [data-group-depth="0"] .group-label { padding-left: 0; }
408
+ [data-group-depth="1"] .group-label { padding-left: 20px; }
409
+ [data-group-depth="2"] .group-label { padding-left: 40px; }
410
+ [data-group-depth="3"] .group-label { padding-left: 60px; }
411
+ [data-group-depth="4"] .group-label { padding-left: 80px; }
412
+ `}function fe(o,e){const t=new Set(o);return t.has(e)?t.delete(e):t.add(e),t}function Ho(o,e){const t=new Set(o);return t.add(e),t}function No(o,e){const t=new Set(o);return t.delete(e),t}function qo(o,e){return o.has(e)}function zo(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}class Bo extends E{name="masterDetail";version="1.0.0";get defaultConfig(){return{enabled:!0,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;n.viewRenderer=r=>{const{value:s,row:l}=r,a=this.expandedRows.has(l),d=document.createElement("span");d.className="master-detail-cell-wrapper";const c=document.createElement("span");c.className="master-detail-toggle",c.textContent=a?"▼":"▶",c.setAttribute("aria-expanded",String(a)),c.setAttribute("aria-label",a?"Collapse details":"Expand details"),c.addEventListener("click",u=>{u.stopPropagation();const f=this.rows.indexOf(l);this.expandedRows=fe(this.expandedRows,l),this.emit("detail-expand",{rowIndex:f,row:l,expanded:this.expandedRows.has(l)}),this.requestRender()}),d.appendChild(c);const h=document.createElement("span");if(i){const u=i(r);u instanceof Node?h.appendChild(u):h.textContent=String(u??s??"")}else h.textContent=String(s??"");return d.appendChild(h),d},t[0]=n}return t}onRowClick(e){if(!(!this.config.expandOnRowClick||!this.config.detailRenderer))return this.expandedRows=fe(this.expandedRows,e.row),this.emit("detail-expand",{rowIndex:e.rowIndex,row:e.row,expanded:this.expandedRows.has(e.row)}),this.requestRender(),!1}afterRender(){if(!this.config.detailRenderer)return;const e=this.shadowRoot?.querySelector(".rows");if(!e)return;e.querySelectorAll(".master-detail-row").forEach(i=>i.remove()),this.detailElements.clear();const t=e.querySelectorAll(".data-grid-row"),n=this.columns.length;for(const i of t){const r=i.querySelector(".cell[data-row]"),s=r?parseInt(r.getAttribute("data-row")??"-1",10):-1;if(s<0)continue;const l=this.rows[s];if(!l||!this.expandedRows.has(l))continue;const a=zo(l,s,this.config.detailRenderer,n);typeof this.config.detailHeight=="number"&&(a.style.height=`${this.config.detailHeight}px`),i.appendChild(a),this.detailElements.set(l,a)}}expand(e){const t=this.rows[e];t&&(this.expandedRows=Ho(this.expandedRows,t),this.requestRender())}collapse(e){const t=this.rows[e];t&&(this.expandedRows=No(this.expandedRows,t),this.requestRender())}toggle(e){const t=this.rows[e];t&&(this.expandedRows=fe(this.expandedRows,t),this.requestRender())}isExpanded(e){const t=this.rows[e];return t?qo(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=`
413
+ .master-detail-cell-wrapper {
414
+ display: flex;
415
+ align-items: center;
416
+ gap: 4px;
417
+ }
418
+ .master-detail-toggle {
419
+ cursor: pointer;
420
+ font-size: 10px;
421
+ opacity: 0.7;
422
+ user-select: none;
423
+ }
424
+ .master-detail-toggle:hover {
425
+ opacity: 1;
426
+ }
427
+ .master-detail-row {
428
+ grid-column: 1 / -1;
429
+ display: grid;
430
+ background: var(--tbw-master-detail-bg, var(--tbw-color-row-alt));
431
+ border-bottom: 1px solid var(--tbw-master-detail-border, var(--tbw-color-border));
432
+ }
433
+ .master-detail-cell {
434
+ padding: 16px;
435
+ overflow: auto;
436
+ }
437
+ `}function Fo(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??$o,a=n[r.field],d=i[r.field],c=l(a,d,n,i);if(c!==0)return r.direction==="asc"?c:-c}return 0}):[...o]}function $o(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 Ko(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 Xe(o,e){const t=o.findIndex(n=>n.field===e);return t>=0?t+1:void 0}function Ye(o,e){return o.find(t=>t.field===e)?.direction}class Wo extends E{name="multiSort";version="1.0.0";get defaultConfig(){return{enabled:!0,maxSortColumns:3,showSortIndex:!0}}sortModel=[];detach(){this.sortModel=[]}processRows(e){return this.sortModel.length===0?[...e]:Fo([...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=Ko(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=Xe(this.sortModel,r),l=Ye(this.sortModel,r);if(i.querySelector(".sort-index")?.remove(),l){i.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove(),i.setAttribute("data-sort",l);const c=document.createElement("span");if(c.className="sort-indicator",c.style.marginLeft="4px",c.style.opacity="0.8",c.textContent=l==="asc"?"▲":"▼",i.appendChild(c),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 Xe(this.sortModel,e)}getSortDirection(e){return Ye(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=`
438
+ .header-cell[data-sort="asc"]::after {
439
+ content: '↑';
440
+ margin-left: 4px;
441
+ opacity: 0.8;
442
+ }
443
+ .header-cell[data-sort="desc"]::after {
444
+ content: '↓';
445
+ margin-left: 4px;
446
+ opacity: 0.8;
447
+ }
448
+ .sort-index {
449
+ font-size: 10px;
450
+ background: var(--tbw-multi-sort-badge-bg, var(--tbw-color-panel-bg));
451
+ color: var(--tbw-multi-sort-badge-color, var(--tbw-color-fg));
452
+ border-radius: 50%;
453
+ width: 14px;
454
+ height: 14px;
455
+ display: inline-flex;
456
+ align-items: center;
457
+ justify-content: center;
458
+ margin-left: 2px;
459
+ font-weight: 600;
460
+ }
461
+ `}function Vo(o){return o.filter(e=>e.sticky==="left")}function Go(o){return o.filter(e=>e.sticky==="right")}function pe(o){return o.some(e=>e.sticky==="left"||e.sticky==="right")}function Je(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),d=n.find(c=>c.getAttribute("data-field")===l.field);d&&(d.classList.add("sticky-left"),d.style.left=r+"px",a!==void 0&&t.querySelectorAll(`.data-grid-row .cell[data-col="${a}"]`).forEach(c=>{c.classList.add("sticky-left"),c.style.left=r+"px"}),r+=d.offsetWidth)}let s=0;for(const l of[...e].reverse())if(l.sticky==="right"){const a=i.get(l.field),d=n.find(c=>c.getAttribute("data-field")===l.field);d&&(d.classList.add("sticky-right"),d.style.right=s+"px",a!==void 0&&t.querySelectorAll(`.data-grid-row .cell[data-col="${a}"]`).forEach(c=>{c.classList.add("sticky-right"),c.style.right=s+"px"}),s+=d.offsetWidth)}}function Ze(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.left="",n.style.right=""})}class jo extends E{name="pinnedColumns";version="1.0.0";get defaultConfig(){return{enabled:!0}}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)?pe(n):!1}processColumns(e){return this.config.enabled?(this.isApplied=pe([...e]),[...e]):(this.isApplied=!1,[...e])}afterRender(){if(!this.config.enabled||!this.isApplied)return;const e=this.grid,t=[...this.columns];if(!pe(t)){Ze(e),this.isApplied=!1;return}queueMicrotask(()=>{Je(e,t)})}refreshStickyOffsets(){const e=[...this.columns];Je(this.grid,e)}getLeftPinnedColumns(){const e=[...this.columns];return Vo(e)}getRightPinnedColumns(){const e=[...this.columns];return Go(e)}clearStickyPositions(){Ze(this.grid)}}function ge(o,e){const t=document.createElement("div");t.className="tbw-pinned-rows",t.setAttribute("role","status"),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=Uo(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 Qe(o){const e=document.createElement("div");return e.className=`tbw-aggregation-rows tbw-aggregation-rows-${o}`,e.setAttribute("role","rowgroup"),e}function et(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","row"),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 d=i.aggregators?.[s.field];if(d){const c=To(d);c&&(a=c(n,s.field,s))}else if(i.cells&&Object.prototype.hasOwnProperty.call(i.cells,s.field)){const c=i.cells[s.field];typeof c=="function"?a=c(n,s.field,s):a=c}l.textContent=a!=null?String(a):"",r.appendChild(l)}o.appendChild(r)}}function Uo(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 tt(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}}class Xo extends E{name="pinnedRows";version="1.0.0";get defaultConfig(){return{enabled:!0,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(){if(!this.config.enabled){this.cleanup();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;const n=this.getSelectionState(),i=this.getFilterState(),r=tt(this.rows,this.columns,this.grid,n,i),s=this.config.aggregationRows||[],l=s.filter(u=>u.position==="top"),a=s.filter(u=>u.position!=="top");if(l.length>0){if(!this.topAggregationContainer){this.topAggregationContainer=Qe("top");const u=e.querySelector(".header");u&&u.nextSibling?t.insertBefore(this.topAggregationContainer,u.nextSibling):t.appendChild(this.topAggregationContainer)}et(this.topAggregationContainer,l,this.visibleColumns,this.rows)}else this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null);const d=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,c=d&&this.config.position!=="top",h=a.length>0||c;if(d&&this.config.position==="top")if(!this.infoBarElement)this.infoBarElement=ge(this.config,r),t.insertBefore(this.infoBarElement,t.firstChild);else{const u=ge(this.config,r);this.infoBarElement.replaceWith(u),this.infoBarElement=u}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=Qe("bottom")),this.footerWrapper.appendChild(this.bottomAggregationContainer),et(this.bottomAggregationContainer,a,this.visibleColumns,this.rows)),c&&(this.infoBarElement=ge(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 tt(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=`
462
+ .tbw-footer {
463
+ position: sticky;
464
+ bottom: 0;
465
+ z-index: var(--tbw-z-layer-pinned-rows, 20);
466
+ background: var(--tbw-color-panel-bg);
467
+ }
468
+
469
+ .tbw-pinned-rows {
470
+ display: flex;
471
+ align-items: center;
472
+ justify-content: space-between;
473
+ padding: 8px 12px;
474
+ background: var(--tbw-pinned-rows-bg, var(--tbw-color-panel-bg));
475
+ border-top: 1px solid var(--tbw-pinned-rows-border, var(--tbw-color-border));
476
+ font-size: 12px;
477
+ color: var(--tbw-pinned-rows-color, var(--tbw-color-fg-muted));
478
+ min-height: 32px;
479
+ box-sizing: border-box;
480
+ min-width: fit-content;
481
+ }
482
+ .tbw-pinned-rows-left,
483
+ .tbw-pinned-rows-center,
484
+ .tbw-pinned-rows-right {
485
+ display: flex;
486
+ align-items: center;
487
+ gap: 16px;
488
+ }
489
+ .tbw-pinned-rows-left {
490
+ justify-content: flex-start;
491
+ }
492
+ .tbw-pinned-rows-center {
493
+ justify-content: center;
494
+ flex: 1;
495
+ }
496
+ .tbw-pinned-rows-right {
497
+ justify-content: flex-end;
498
+ }
499
+ .tbw-status-panel {
500
+ white-space: nowrap;
501
+ }
502
+
503
+ .tbw-aggregation-rows {
504
+ min-width: fit-content;
505
+ background: var(--tbw-aggregation-bg, var(--tbw-color-header-bg));
506
+ }
507
+ .tbw-aggregation-rows-top {
508
+ border-bottom: 1px solid var(--tbw-aggregation-border, var(--tbw-color-border));
509
+ }
510
+ .tbw-aggregation-rows-bottom {
511
+ border-top: 1px solid var(--tbw-aggregation-border, var(--tbw-color-border));
512
+ }
513
+ .tbw-aggregation-row {
514
+ display: grid;
515
+ grid-template-columns: var(--tbw-column-template);
516
+ font-weight: var(--tbw-aggregation-font-weight, 600);
517
+ }
518
+ .tbw-aggregation-cell {
519
+ padding: var(--tbw-cell-padding, 2px 8px);
520
+ min-height: var(--tbw-row-height, 28px);
521
+ display: flex;
522
+ align-items: center;
523
+ border-right: 1px solid var(--tbw-color-border-cell);
524
+ }
525
+ .tbw-aggregation-cell:last-child {
526
+ border-right: 0;
527
+ }
528
+ .tbw-aggregation-cell-full {
529
+ grid-column: 1 / -1;
530
+ border-right: 0;
531
+ }
532
+ `}function Yo(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 Jo(o){switch(o){case"sum":return e=>e.reduce((t,n)=>t+n,0);case"avg":return e=>e.length?e.reduce((t,n)=>t+n,0)/e.length:0;case"count":return e=>e.length;case"min":return e=>e.length?Math.min(...e):0;case"max":return e=>e.length?Math.max(...e):0;case"first":return e=>e[0]??0;case"last":return e=>e[e.length-1]??0;default:return e=>e.reduce((t,n)=>t+n,0)}}function be(o,e){return[...o,e].join("|")}function Zo(o,e){const t=e.rowGroupFields??[],n=e.columnGroupFields??[],i=e.valueFields??[],r=Qo(o,n),s=en(o,t),l=tn(s,n,r,i,0),a=on(l,r,i),d=Object.values(a).reduce((c,h)=>c+h,0);return{rows:l,columnKeys:r,totals:a,grandTotal:d}}function Qo(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 en(o,e){const t=new Map;for(const n of o){const i=e.map(s=>String(n[s]??"")).join("|");t.has(i)||t.set(i,[]);const r=t.get(i);r&&r.push(n)}return t}function tn(o,e,t,n,i){const r=[];for(const[s,l]of o){const a={};let d=0;for(const c of t)for(const h of n){const f=(e.length>0?l.filter(y=>e.map(A=>String(y[A]??"")).join("|")===c):l).map(y=>Number(y[h.field])||0),p=Jo(h.aggFunc),g=f.length>0?p(f):null,b=be([c],h.field);a[b]=g,g!==null&&(d+=g)}r.push({rowKey:s,rowLabel:s||"(blank)",depth:i,values:a,total:d,isGroup:!1})}return r}function on(o,e,t){const n={};for(const i of e)for(const r of t){const s=be([i],r.field);n[s]=o.reduce((l,a)=>l+(a.values[s]??0),0)}return n}function nn(o){const e=[];function t(n){if(e.push(n),n.children)for(const i of n.children)t(i)}for(const n of o)t(n);return e}class rn extends E{name="pivot";version="1.0.0";get defaultConfig(){return{enabled:!0,showTotals:!0,showGrandTotal:!0}}isActive=!1;pivotResult=null;columnHeaders=[];rowHeaders=[];detach(){this.isActive=!1,this.pivotResult=null,this.columnHeaders=[],this.rowHeaders=[]}processRows(e){if(!this.config.enabled||!this.isActive)return[...e];const t=Yo(this.config);return t.length>0?(this.warn(`Config errors: ${t.join(", ")}`),[...e]):(this.pivotResult=Zo(e,this.config),nn(this.pivotResult.rows).map(n=>({__pivotRowKey:n.rowKey,__pivotLabel:n.rowLabel,__pivotDepth:n.depth,__pivotIsGroup:n.isGroup,__pivotTotal:n.total,...n.values})))}processColumns(e){if(!this.config.enabled||!this.isActive||!this.pivotResult)return[...e];const t=[];t.push({field:"__pivotLabel",header:this.config.rowGroupFields?.join(" / ")??"Group",width:200});for(const n of this.pivotResult.columnKeys)for(const i of this.config.valueFields??[]){const r=be([n],i.field);t.push({field:r,header:`${n} - ${i.header||i.field} (${i.aggFunc})`,width:120,type:"number"})}return this.config.showTotals&&t.push({field:"__pivotTotal",header:"Total",width:100,type:"number"}),t}enablePivot(){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()}styles=`
533
+ [data-pivot-depth="1"] { padding-left: 20px; }
534
+ [data-pivot-depth="2"] { padding-left: 40px; }
535
+ [data-pivot-depth="3"] { padding-left: 60px; }
536
+ .pivot-group-row { font-weight: bold; background: var(--tbw-pivot-group-bg, var(--tbw-color-panel-bg)); }
537
+ .pivot-total-row { font-weight: bold; border-top: 2px solid var(--tbw-pivot-border, var(--tbw-color-border-strong)); }
538
+ `}function sn(o){const e=o.meta??{},t=e.sticky;return t==="left"||t==="right"?!1:e.lockPosition!==!0&&e.suppressMovable!==!0}function ot(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}class ln extends E{name="reorder";version="1.0.0";get defaultConfig(){return{enabled:!0,animation:!0,animationDuration:200}}isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;boundReorderRequestHandler=null;attach(e){super.attach(e),this.boundReorderRequestHandler=t=>{const n=t.detail;n?.field&&typeof n.toIndex=="number"&&this.moveColumn(n.field,n.toIndex)},e.addEventListener("column-reorder-request",this.boundReorderRequestHandler)}detach(){this.boundReorderRequestHandler&&this.grid&&(this.grid.removeEventListener("column-reorder-request",this.boundReorderRequestHandler),this.boundReorderRequestHandler=null),this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null}afterRender(){if(!this.config.enabled)return;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(l=>l.field===r);if(!s||!sn(s)){i.draggable=!1;return}i.draggable=!0,!i.getAttribute("data-dragstart-bound")&&(i.setAttribute("data-dragstart-bound","true"),i.addEventListener("dragstart",l=>{const d=this.getColumnOrder().indexOf(r);this.isDragging=!0,this.draggedField=r,this.draggedIndex=d,l.dataTransfer&&(l.dataTransfer.effectAllowed="move",l.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(l=>{l.classList.remove("dragging","drop-target","drop-before","drop-after")})}),i.addEventListener("dragover",l=>{if(l.preventDefault(),!this.isDragging||this.draggedField===r)return;const a=i.getBoundingClientRect(),d=a.left+a.width/2,h=this.getColumnOrder().indexOf(r);this.dropIndex=l.clientX<d?h:h+1,i.classList.add("drop-target"),i.classList.toggle("drop-before",l.clientX<d),i.classList.toggle("drop-after",l.clientX>=d)}),i.addEventListener("dragleave",()=>{i.classList.remove("drop-target","drop-before","drop-after")}),i.addEventListener("drop",l=>{l.preventDefault();const a=this.draggedField,d=this.draggedIndex,c=this.dropIndex;if(!this.isDragging||a===null||d===null||c===null)return;const h=c>d?c-1:c,u=this.getColumnOrder(),f=ot(u,d,h),p={field:a,fromIndex:d,toIndex:h,columnOrder:f};this.grid.setColumnOrder(f),this.emit("column-move",p),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=ot(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=`
539
+ .header-row > .cell[draggable="true"] {
540
+ cursor: grab;
541
+ position: relative;
542
+ }
543
+ .header-row > .cell.dragging {
544
+ opacity: 0.5;
545
+ cursor: grabbing;
546
+ }
547
+ .header-row > .cell.drop-before::before {
548
+ content: '';
549
+ position: absolute;
550
+ left: 0;
551
+ top: 0;
552
+ bottom: 0;
553
+ width: 2px;
554
+ background: var(--tbw-reorder-indicator, var(--tbw-color-accent));
555
+ z-index: 1;
556
+ }
557
+ .header-row > .cell.drop-after::after {
558
+ content: '';
559
+ position: absolute;
560
+ right: 0;
561
+ top: 0;
562
+ bottom: 0;
563
+ width: 2px;
564
+ background: var(--tbw-reorder-indicator, var(--tbw-color-accent));
565
+ z-index: 1;
566
+ }
567
+ `}function U(o,e){return Math.floor(o/e)}function an(o,e){return{start:o*e,end:(o+1)*e}}function cn(o,e,t){const n=U(o,t),i=U(e-1,t),r=[];for(let s=n;s<=i;s++)r.push(s);return r}async function nt(o,e,t,n){const i=an(e,t);return o.getRows({startRow:i.start,endRow:i.end,sortModel:n.sortModel,filterModel:n.filterModel})}function dn(o,e,t){const n=U(o,e),i=t.get(n);if(!i)return;const r=o%e;return i[r]}const un=100;class hn extends E{name="serverSide";version="1.0.0";get defaultConfig(){return{enabled:!0,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=cn(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),nt(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=dn(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;nt(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=U(e,t);return this.loadedBlocks.has(n)}getLoadedBlockCount(){return this.loadedBlocks.size}}function fn(o,e,t){const n=[...o.undoStack,e];for(;n.length>t;)n.shift();return{undoStack:n,redoStack:[]}}function it(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 rt(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 pn(o){return o.undoStack.length>0}function gn(o){return o.redoStack.length>0}function bn(){return{undoStack:[],redoStack:[]}}function wn(o,e,t,n){return{type:"cell-edit",rowIndex:o,field:e,oldValue:t,newValue:n,timestamp:Date.now()}}class mn extends E{name="undoRedo";version="1.0.0";get defaultConfig(){return{enabled:!0,maxHistorySize:100}}undoStack=[];redoStack=[];detach(){this.undoStack=[],this.redoStack=[]}onKeyDown(e){if(!this.config.enabled)return!1;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=it({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=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.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=wn(e,t,n,i),s=fn({undoStack:this.undoStack,redoStack:this.redoStack},r,this.config.maxHistorySize??100);this.undoStack=s.undoStack,this.redoStack=s.redoStack}undo(){const e=it({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=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.newValue),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.requestRender()}return e.action}canUndo(){return pn({undoStack:this.undoStack,redoStack:this.redoStack})}canRedo(){return gn({undoStack:this.undoStack,redoStack:this.redoStack})}clearHistory(){const e=bn();this.undoStack=e.undoStack,this.redoStack=e.redoStack}getUndoStack(){return[...this.undoStack]}getRedoStack(){return[...this.redoStack]}}function st(o){const e=o.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}class B extends E{name="visibility";version="1.0.0";static PANEL_ID="columns";get defaultConfig(){return{enabled:!0,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(){if(this.config.enabled)return{id:B.PANEL_ID,title:"Columns",icon:"☰",tooltip:"Column visibility",order:100,render:e=>this.renderPanelContent(e)}}show(){this.grid.openToolPanel(B.PANEL_ID)}hide(){this.grid.closeToolPanel()}toggle(){this.grid.toggleToolPanel(B.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===B.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 d=document.createElement("label");d.className="tbw-visibility-label";const c=document.createElement("input");c.type="checkbox",c.checked=s.visible,c.disabled=s.lockVisible??!1,c.addEventListener("change",()=>{t.toggleColumnVisibility(s.field),setTimeout(()=>this.rebuildToggles(e),0)});const h=document.createElement("span");if(h.textContent=l,d.appendChild(c),d.appendChild(h),n&&st(s)){const u=document.createElement("span");u.className="tbw-visibility-handle",u.textContent="⋮⋮",u.title="Drag to reorder",a.appendChild(u)}a.appendChild(d),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 d=a>l?a-1:a;if(d!==l){const c={field:s,fromIndex:l,toIndex:d};this.emit("column-reorder-request",c),setTimeout(()=>{this.rebuildToggles(i)},0)}})}styles=`
568
+ .tbw-visibility-content {
569
+ display: flex;
570
+ flex-direction: column;
571
+ height: 100%;
572
+ }
573
+
574
+ .tbw-visibility-list {
575
+ flex: 1;
576
+ overflow-y: auto;
577
+ padding: 8px;
578
+ }
579
+
580
+ .tbw-visibility-row {
581
+ display: flex;
582
+ align-items: center;
583
+ gap: 8px;
584
+ padding: 6px 4px;
585
+ cursor: pointer;
586
+ font-size: 13px;
587
+ border-radius: var(--tbw-border-radius, 4px);
588
+ position: relative;
589
+ }
590
+ .tbw-visibility-row:hover {
591
+ background: var(--tbw-visibility-hover, var(--tbw-color-row-hover, #f3f4f6));
592
+ }
593
+ .tbw-visibility-row input[type="checkbox"] {
594
+ cursor: pointer;
595
+ }
596
+ .tbw-visibility-row.locked span {
597
+ color: var(--tbw-color-fg-muted, #888);
598
+ }
599
+
600
+ /* Drag handle */
601
+ .tbw-visibility-handle {
602
+ cursor: grab;
603
+ color: var(--tbw-color-fg-muted, #888);
604
+ font-size: 10px;
605
+ letter-spacing: -2px;
606
+ user-select: none;
607
+ flex-shrink: 0;
608
+ }
609
+ .tbw-visibility-row.reorderable:hover .tbw-visibility-handle {
610
+ color: var(--tbw-color-fg, #1f2937);
611
+ }
612
+
613
+ /* Label wrapper for checkbox and text */
614
+ .tbw-visibility-label {
615
+ display: flex;
616
+ align-items: center;
617
+ gap: 8px;
618
+ flex: 1;
619
+ cursor: pointer;
620
+ }
621
+
622
+ /* Drag states */
623
+ .tbw-visibility-row.dragging {
624
+ opacity: 0.5;
625
+ cursor: grabbing;
626
+ }
627
+ .tbw-visibility-row.drop-before::before {
628
+ content: '';
629
+ position: absolute;
630
+ left: 0;
631
+ right: 0;
632
+ top: 0;
633
+ height: 2px;
634
+ background: var(--tbw-reorder-indicator, var(--tbw-color-accent, #3b82f6));
635
+ }
636
+ .tbw-visibility-row.drop-after::after {
637
+ content: '';
638
+ position: absolute;
639
+ left: 0;
640
+ right: 0;
641
+ bottom: 0;
642
+ height: 2px;
643
+ background: var(--tbw-reorder-indicator, var(--tbw-color-accent, #3b82f6));
644
+ }
645
+
646
+ .tbw-visibility-show-all {
647
+ margin: 8px;
648
+ padding: 8px 12px;
649
+ border: 1px solid var(--tbw-visibility-border, var(--tbw-color-border, #e5e7eb));
650
+ border-radius: var(--tbw-border-radius, 4px);
651
+ background: var(--tbw-visibility-btn-bg, var(--tbw-color-header-bg, #f9fafb));
652
+ color: var(--tbw-color-fg, #1f2937);
653
+ cursor: pointer;
654
+ font-size: 13px;
655
+ }
656
+ .tbw-visibility-show-all:hover {
657
+ background: var(--tbw-visibility-hover, var(--tbw-color-row-hover, #f3f4f6));
658
+ }
659
+ `}v.BaseGridPlugin=E,v.ClipboardPlugin=io,v.ColumnVirtualizationPlugin=ao,v.ContextMenuPlugin=ho,v.DGEvents=to,v.DataGridElement=K,v.ExportPlugin=wo,v.FilteringPlugin=D,v.FitModeEnum=q,v.GridCSSVars=eo,v.GridClasses=S,v.GridDataAttrs=W,v.GridElement=K,v.GridSelectors=Qt,v.GroupingColumnsPlugin=ko,v.GroupingRowsPlugin=Do,v.MasterDetailPlugin=Bo,v.MultiSortPlugin=Wo,v.PinnedColumnsPlugin=jo,v.PinnedRowsPlugin=Xo,v.PivotPlugin=rn,v.PluginEvents=oo,v.ReorderPlugin=ln,v.SelectionPlugin=Ut,v.ServerSidePlugin=hn,v.TreePlugin=Zt,v.UndoRedoPlugin=mn,v.VisibilityPlugin=B,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
660
+ //# sourceMappingURL=grid.all.umd.js.map