@toolbox-web/grid 0.0.7 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/all.d.ts +151 -95
  2. package/all.js +1554 -1452
  3. package/all.js.map +1 -1
  4. package/custom-elements.json +89 -7
  5. package/index.d.ts +68 -23
  6. package/index.js +1066 -948
  7. package/index.js.map +1 -1
  8. package/lib/plugins/clipboard/index.js +48 -49
  9. package/lib/plugins/clipboard/index.js.map +1 -1
  10. package/lib/plugins/column-virtualization/index.js +6 -6
  11. package/lib/plugins/column-virtualization/index.js.map +1 -1
  12. package/lib/plugins/context-menu/index.js +32 -34
  13. package/lib/plugins/context-menu/index.js.map +1 -1
  14. package/lib/plugins/export/index.js +7 -7
  15. package/lib/plugins/export/index.js.map +1 -1
  16. package/lib/plugins/filtering/index.js +5 -38
  17. package/lib/plugins/filtering/index.js.map +1 -1
  18. package/lib/plugins/grouping-columns/index.js +4 -32
  19. package/lib/plugins/grouping-columns/index.js.map +1 -1
  20. package/lib/plugins/grouping-rows/index.js +8 -45
  21. package/lib/plugins/grouping-rows/index.js.map +1 -1
  22. package/lib/plugins/master-detail/index.js +6 -30
  23. package/lib/plugins/master-detail/index.js.map +1 -1
  24. package/lib/plugins/multi-sort/index.js +19 -42
  25. package/lib/plugins/multi-sort/index.js.map +1 -1
  26. package/lib/plugins/pinned-columns/index.js +5 -6
  27. package/lib/plugins/pinned-columns/index.js.map +1 -1
  28. package/lib/plugins/pinned-rows/index.js +6 -80
  29. package/lib/plugins/pinned-rows/index.js.map +1 -1
  30. package/lib/plugins/pivot/index.js +673 -145
  31. package/lib/plugins/pivot/index.js.map +1 -1
  32. package/lib/plugins/reorder/index.js +22 -51
  33. package/lib/plugins/reorder/index.js.map +1 -1
  34. package/lib/plugins/selection/index.js +53 -83
  35. package/lib/plugins/selection/index.js.map +1 -1
  36. package/lib/plugins/server-side/index.js +2 -2
  37. package/lib/plugins/server-side/index.js.map +1 -1
  38. package/lib/plugins/tree/index.js +6 -14
  39. package/lib/plugins/tree/index.js.map +1 -1
  40. package/lib/plugins/undo-redo/index.js +2 -3
  41. package/lib/plugins/undo-redo/index.js.map +1 -1
  42. package/lib/plugins/visibility/index.js +13 -105
  43. package/lib/plugins/visibility/index.js.map +1 -1
  44. package/package.json +1 -1
  45. package/themes/dg-theme-bootstrap.css +73 -0
  46. package/themes/dg-theme-material.css +71 -0
  47. package/umd/grid.all.umd.js +40 -415
  48. package/umd/grid.all.umd.js.map +1 -1
  49. package/umd/grid.umd.js +29 -60
  50. package/umd/grid.umd.js.map +1 -1
  51. package/umd/plugins/clipboard.umd.js +4 -4
  52. package/umd/plugins/clipboard.umd.js.map +1 -1
  53. package/umd/plugins/column-virtualization.umd.js +1 -1
  54. package/umd/plugins/column-virtualization.umd.js.map +1 -1
  55. package/umd/plugins/context-menu.umd.js +2 -2
  56. package/umd/plugins/context-menu.umd.js.map +1 -1
  57. package/umd/plugins/export.umd.js +1 -1
  58. package/umd/plugins/export.umd.js.map +1 -1
  59. package/umd/plugins/filtering.umd.js +2 -34
  60. package/umd/plugins/filtering.umd.js.map +1 -1
  61. package/umd/plugins/grouping-columns.umd.js +1 -28
  62. package/umd/plugins/grouping-columns.umd.js.map +1 -1
  63. package/umd/plugins/grouping-rows.umd.js +1 -39
  64. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  65. package/umd/plugins/master-detail.umd.js +1 -26
  66. package/umd/plugins/master-detail.umd.js.map +1 -1
  67. package/umd/plugins/multi-sort.umd.js +1 -25
  68. package/umd/plugins/multi-sort.umd.js.map +1 -1
  69. package/umd/plugins/pinned-columns.umd.js +1 -1
  70. package/umd/plugins/pinned-columns.umd.js.map +1 -1
  71. package/umd/plugins/pinned-rows.umd.js +1 -72
  72. package/umd/plugins/pinned-rows.umd.js.map +1 -1
  73. package/umd/plugins/pivot.umd.js +1 -7
  74. package/umd/plugins/pivot.umd.js.map +1 -1
  75. package/umd/plugins/reorder.umd.js +1 -30
  76. package/umd/plugins/reorder.umd.js.map +1 -1
  77. package/umd/plugins/selection.umd.js +1 -33
  78. package/umd/plugins/selection.umd.js.map +1 -1
  79. package/umd/plugins/server-side.umd.js +1 -1
  80. package/umd/plugins/server-side.umd.js.map +1 -1
  81. package/umd/plugins/tree.umd.js +1 -10
  82. package/umd/plugins/tree.umd.js.map +1 -1
  83. package/umd/plugins/undo-redo.umd.js +1 -1
  84. package/umd/plugins/undo-redo.umd.js.map +1 -1
  85. package/umd/plugins/visibility.umd.js +1 -93
  86. package/umd/plugins/visibility.umd.js.map +1 -1
package/umd/grid.umd.js CHANGED
@@ -1,24 +1,34 @@
1
- (function(C,M){typeof exports=="object"&&typeof module<"u"?M(exports):typeof define=="function"&&define.amd?define(["exports"],M):(C=typeof globalThis<"u"?globalThis:C||self,M(C.TbwGrid={}))})(this,(function(C){"use strict";const M=":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-accent);--tbw-range-selection-bg: rgba(from var(--tbw-range-border-color) r g b / 12%);--tbw-resize-handle-width: 4px;--tbw-resize-handle-color: transparent;--tbw-resize-handle-color-hover: var(--tbw-color-accent);--tbw-resize-handle-border-radius: 0;--tbw-scrollbar-thumb: var(--tbw-color-border-strong);--tbw-scrollbar-track: var(--tbw-color-bg);--tbw-transition-duration: .12s;--tbw-transition-ease: ease;--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-border: var(--tbw-border-input, 1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input: var(--tbw-cell-padding-input, 2px 6px);--tbw-font-size-editor: inherit;--tbw-sort-indicator-color: var(--tbw-color-fg-muted);--tbw-sort-indicator-active-color: var(--tbw-color-accent);--tbw-header-text-transform: none;--tbw-header-letter-spacing: normal;--tbw-color-header-separator: var(--tbw-color-border-cell);--tbw-checkbox-size: 16px;--tbw-density-scale: 1}:host{position:relative;display:block;width:100%;height:100%;min-height:0;contain:content;font-family:var(--tbw-font-family);font-size:var(--tbw-font-size);background:var(--tbw-color-bg);color:var(--tbw-color-fg);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);overflow:clip;outline:none}:host,:host *{box-sizing:border-box}:host .header{display:block;flex-shrink:0;z-index:var(--tbw-z-layer-header, 30);background:var(--tbw-color-header-bg);overflow:visible}:host .header-group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-color-header-bg);z-index:var(--tbw-z-layer-header, 30)}:host .header-group-cell{display:flex;align-items:center;justify-content:flex-start;padding:var(--tbw-cell-padding-header, 2px 8px);color:var(--tbw-color-header-group-fg, var(--tbw-color-header-fg));font-weight:var(--tbw-font-weight-header-group, var(--tbw-font-weight-header));justify-content:var(--tbw-align-header-group, var(--tbw-align-header, flex-start))}:host .header-row{display:grid;grid-template-columns:var(--tbw-column-template);color:var(--tbw-color-header-fg);font-size:var(--tbw-font-size-header);min-height:var(--tbw-header-height);border-bottom:var(--tbw-border-header);z-index:var(--tbw-z-layer-header, 30)}:host .header-row>.cell{display:flex;align-items:center;gap:4px;padding:var(--tbw-cell-padding-header, 2px 8px);background-color:var(--tbw-color-header-bg);font-weight:var(--tbw-font-weight-header);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}:host .header-row>.cell>span:first-child{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}:host .header-row>.cell>span[part~=sort-indicator]{flex-shrink:0}:host .header-row>.cell:last-child{border-right:0}:host .header-group-cell,:host .header-row>.cell.grouped.group-end{border-right:2px solid var(--tbw-color-border)}:host .tbw-grid-root{display:flex;flex-direction:column;height:100%}:host .rows-body-wrapper{flex:1;min-height:0;display:flex;flex-direction:row;width:100%;min-width:fit-content}:host .rows-body{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow:visible}:host .rows-container{display:flex;flex-direction:row;flex:1;min-height:0;overflow:visible}:host .rows-viewport{flex:1;min-width:0;position:relative;display:block;overflow:clip}:host .faux-vscroll{position:sticky;inset-inline-end:0;flex-shrink:0;width:auto;overflow-y:auto;overflow-x:hidden;z-index:var(--tbw-z-layer-header, 30)}:host .faux-vscroll-spacer{width:1px}:host .rows-viewport .rows{position:absolute;top:0;left:0;min-width:100%;will-change:transform;z-index:var(--tbw-z-layer-rows, 1)}:host .data-grid-row{display:grid;grid-template-columns:var(--tbw-column-template);contain:layout style}:host .data-grid-row:has(.editing){background:var(--tbw-editing-bg)}:host .selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}:host .data-grid-row>.cell:focus-visible{outline: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 ve(o){const e=new Map;return o.sortState&&e.set(o.sortState.field,{direction:o.sortState.direction===1?"asc":"desc",priority:0}),e}function Z(o,e){const t=o._columns,n=ve(o);return{columns:t.map((i,s)=>{const r={field:i.field,order:s,visible:!0},a=i;a.__renderedWidth!==void 0?r.width=a.__renderedWidth:i.width!==void 0&&(r.width=typeof i.width=="string"?parseFloat(i.width):i.width);const l=n.get(i.field);l&&(r.sort=l);for(const f of e)if(f.getColumnState){const p=f.getColumnState(i.field);p&&Object.assign(r,p)}return r})}}function Ce(o,e,t,n){if(!e.columns||e.columns.length===0)return;const i=new Map(e.columns.map(a=>[a.field,a])),s=t.map(a=>{const l=i.get(a.field);if(!l)return a;const f={...a};return l.width!==void 0&&(f.width=l.width,f.__renderedWidth=l.width),l.visible!==void 0&&(f.hidden=!l.visible),f});s.sort((a,l)=>{const f=i.get(a.field)?.order??1/0,p=i.get(l.field)?.order??1/0;return f-p}),o._columns=s;const r=e.columns.filter(a=>a.sort!==void 0).sort((a,l)=>(a.sort?.priority??0)-(l.sort?.priority??0));if(r.length>0){const a=r[0];a.sort&&(o.sortState={field:a.field,direction:a.sort.direction==="asc"?1:-1})}else o.sortState=null;for(const a of n)if(a.applyColumnState)for(const l of e.columns)a.applyColumnState(l.field,l)}function Ee(o,e,t){let n=null;return()=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{n=null;const i=Z(o,e());t(i)},100)}}const k={STRETCH:"stretch",FIXED:"fixed"},$={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮"};function ye(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 J(o,e){if(e&&e.length){const s={};return e.forEach(r=>{r.type&&(s[r.field]=r.type)}),{columns:e,typeMap:s}}const t=o[0]||{},n=Object.keys(t).map(s=>{const r=t[s],a=ye(r);return{field:s,header:s.charAt(0).toUpperCase()+s.slice(1),type:a}}),i={};return n.forEach(s=>{i[s.field]=s.type||"string"}),{columns:n,typeMap:i}}const Re=/{{\s*([^}]+)\s*}}/g,A="__DG_EMPTY__",_e=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,Ae=/__(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/,Se=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"]),Q=/^on\w+$/i,xe=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),Te=/^\s*(javascript|vbscript|data|blob):/i;function I(o){if(!o||typeof o!="string")return"";if(o.indexOf("<")===-1)return o;const e=document.createElement("template");return e.innerHTML=o,Le(e.content),e.innerHTML}function Le(o){const e=[],t=o.querySelectorAll("*");for(const n of t){const i=n.tagName.toLowerCase();if(Se.has(i)){e.push(n);continue}if((i==="svg"||n.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(n.attributes).some(a=>Q.test(a.name)||a.name==="href"||a.name==="xlink:href")){e.push(n);continue}const s=[];for(const r of n.attributes){const a=r.name.toLowerCase();if(Q.test(a)){s.push(r.name);continue}if(xe.has(a)&&Te.test(r.value)){s.push(r.name);continue}if(a==="style"&&/expression\s*\(|javascript:|behavior\s*:/i.test(r.value)){s.push(r.name);continue}}s.forEach(r=>n.removeAttribute(r))}e.forEach(n=>n.remove())}function ee(o,e){if(!o||o.indexOf("{{")===-1)return o;const t=[],n=o.replace(Re,(a,l)=>{const f=ke(l,e);return t.push({expr:l.trim(),result:f}),f}),i=Pe(n),s=t.length&&t.every(a=>a.result===""||a.result===A);return/Reflect\.|\bProxy\b|ownKeys\(/.test(o)||s?"":i}function ke(o,e){if(o=(o||"").trim(),!o||/\b(Reflect|Proxy|ownKeys)\b/.test(o))return A;if(o==="value")return e.value==null?A: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?A:String(i)}if(o.length>80||!_e.test(o)||Ae.test(o))return A;const t=o.match(/\./g);if(t&&t.length>1)return A;try{const i=new Function("value","row",`return (${o});`)(e.value,e.row),s=i==null?"":String(i);return/Reflect|Proxy|ownKeys/.test(s)?A:s||A}catch{return A}}function Pe(o){return o&&o.replace(new RegExp(A,"g"),"").replace(/Reflect\.[^<>{}\s]+/g,"").replace(/\bProxy\b/g,"").replace(/ownKeys\([^)]*\)/g,"")}function Me(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 te(o){const e=/Reflect\.|\bProxy\b|ownKeys\(/.test(o),t=n=>e?"":ee(o,n);return t.__blocked=e,t}function He(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,r=i&&new Set(["number","string","date","boolean","select","typeahead"]).has(i)?i:void 0,a=t.getAttribute("header")||void 0,l=t.hasAttribute("sortable"),f=t.hasAttribute("editable"),p={field:n,type:r,header:a,sortable:l,editable:f};t.hasAttribute("resizable")&&(p.resizable=!0),t.hasAttribute("sizable")&&(p.resizable=!0);const g=t.getAttribute("options");g&&(p.options=g.split(",").map(d=>{const[b,m]=d.includes(":")?d.split(":"):[d.trim(),d.trim()];return{value:b.trim(),label:m?.trim()||b.trim()}}));const h=t.querySelector("tbw-grid-column-view"),c=t.querySelector("tbw-grid-column-editor"),u=t.querySelector("tbw-grid-column-header");return h&&(p.__viewTemplate=h),c&&(p.__editorTemplate=c),u&&(p.__headerTemplate=u),p}).filter(t=>!!t)}function Oe(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 s=t[i.field];if(!s)return i;const r={...i};return s.header&&!r.header&&(r.header=s.header),s.type&&!r.type&&(r.type=s.type),r.sortable=i.sortable||s.sortable,(i.resizable===!0||s.resizable===!0)&&(r.resizable=!0),r.editable=i.editable||s.editable,s.__viewTemplate&&(r.__viewTemplate=s.__viewTemplate),s.__editorTemplate&&(r.__editorTemplate=s.__editorTemplate),s.__headerTemplate&&(r.__headerTemplate=s.__headerTemplate),delete t[i.field],r});return Object.keys(t).forEach(i=>n.push(t[i])),n}function G(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 De(o){o.__lightDomColumnsCache||(o.__originalColumnNodes=Array.from(o.querySelectorAll("tbw-grid-column")),o.__lightDomColumnsCache=o.__originalColumnNodes.length?He(o):[]);const e=o.__lightDomColumnsCache,t=Oe(o._columns,e);t.forEach(i=>{i.__viewTemplate&&!i.__compiledView&&(i.__compiledView=te(i.__viewTemplate.innerHTML)),i.__editorTemplate&&!i.__compiledEditor&&(i.__compiledEditor=te(i.__editorTemplate.innerHTML))});const{columns:n}=J(o._rows,t);o._columns=n}function ze(o){const e=o.effectiveConfig?.fitMode||o.fitMode||k.STRETCH;if(e!==k.STRETCH&&e!==k.FIXED||o.__didInitialAutoSize||!o.isConnected)return;const t=o.headerRowEl?.children||[];if(!t.length)return;let n=!1;o.visibleColumns.forEach((i,s)=>{if(i.width)return;const r=t[s];let a=r?r.scrollWidth:0;for(const l of o.rowPool){const f=l.children[s];if(f){const p=f.scrollWidth;p>a&&(a=p)}}a>0&&(i.width=a+2,i.__autoSized=!0,n=!0)}),n&&oe(o),o.__didInitialAutoSize=!0}function oe(o){(o.effectiveConfig?.fitMode||o.fitMode||k.STRETCH)===k.STRETCH?o.gridTemplate=o.visibleColumns.map(t=>{if(t.width)return`${t.width}px`;const n=t.minWidth;return n!=null?`minmax(${n}px, 1fr)`:"1fr"}).join(" ").trim():o.gridTemplate=o.visibleColumns.map(t=>t.width?`${t.width}px`:"max-content").join(" "),o.style.setProperty("--tbw-column-template",o.gridTemplate)}function Ne(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(s=>{const r=document.createElement("option");r.value=String(s.value),r.textContent=s.label,(e.column.multi&&Array.isArray(e.value)&&e.value.includes(s.value)||!e.column.multi&&e.value===s.value)&&(r.selected=!0),t.appendChild(r)});const i=()=>{if(e.column.multi){const s=[];Array.from(t.selectedOptions).forEach(r=>{s.push(r.value)}),e.commit(s)}else e.commit(t.value)};return t.addEventListener("change",i),t.addEventListener("blur",i),t.addEventListener("keydown",s=>{s.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 Ie(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,r=o.visibleColumns[o.focusCol]?.type,a=e.composedPath?e.composedPath():[],l=a&&a.length?a[0]:e.target,f=p=>{if(!p)return!1;const g=p.tagName;return!!(g==="INPUT"||g==="SELECT"||g==="TEXTAREA"||p.isContentEditable)};if(!(f(l)&&(e.key==="Home"||e.key==="End"))&&!(f(l)&&(e.key==="ArrowUp"||e.key==="ArrowDown")&&l.tagName==="INPUT"&&l.type==="number")&&!(i&&(r==="select"||r==="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),H(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}})),H(o);default:return}H(o)}}function H(o){if(o.virtualization?.enabled){const{rowHeight:i}=o.virtualization,s=o,r=o.focusRow*i;r<s.scrollTop?s.scrollTop=r:r+i>s.scrollTop+s.clientHeight&&(s.scrollTop=r-s.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 s=o.bodyEl.querySelectorAll(".data-grid-row")[e-t]?.children[o.focusCol];if(s){if(s.classList.add("cell-focus"),s.setAttribute("aria-selected","true"),o.activeEditRows!==void 0&&o.activeEditRows!==-1&&s.classList.contains("editing")){const r=s.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(r&&document.activeElement!==r)try{r.focus()}catch{}}else if(!s.contains(document.activeElement)){s.hasAttribute("tabindex")||s.setAttribute("tabindex","-1");try{s.focus({preventScroll:!0})}catch{}}}}}const qe="__cellDisplayCache",Be="__cellCacheEpoch";function ne(o){o[qe]=void 0,o[Be]=void 0,o.__hasSpecialColumns=void 0}function $e(o,e,t,n,i){const s=Math.max(0,t-e),r=o.bodyEl,a=o.visibleColumns,l=a.length;let f=o.__cachedHeaderRowCount;for(f===void 0&&(f=o.shadowRoot?.querySelector(".header-group-row")?2:1,o.__cachedHeaderRowCount=f);o.rowPool.length<s;){const g=document.createElement("div");g.className="data-grid-row",g.setAttribute("role","row"),g.addEventListener("click",h=>se(o,h,g,!1)),g.addEventListener("dblclick",h=>se(o,h,g,!0)),o.rowPool.push(g)}if(o.rowPool.length>s){for(let g=s;g<o.rowPool.length;g++){const h=o.rowPool[g];h.parentNode===r&&h.remove()}o.rowPool.length=s}const p=i&&o.__hasRenderRowPlugins!==!1;for(let g=0;g<s;g++){const h=e+g,c=o._rows[h],u=o.rowPool[g];if(u.setAttribute("aria-rowindex",String(h+f+1)),p&&i(c,u,h)){u.__epoch=n,u.__rowDataRef=c,u.parentNode!==r&&r.appendChild(u);continue}const d=u.__epoch,b=u.__rowDataRef,m=u.children.length,_=d===n&&m===l,y=b!==c;let S=!1;if(_&&y){for(let T=0;T<l;T++)if(a[T].externalView&&!u.querySelector(`.cell[data-col="${T}"] [data-external-view]`)){S=!0;break}}!_||S?(u.__isCustomRow&&(u.className="data-grid-row",u.setAttribute("role","row"),u.__isCustomRow=!1),K(o,u,c,h),u.__epoch=n,u.__rowDataRef=c):y?(ie(o,u,c,h),u.__rowDataRef=c):ie(o,u,c,h);const w=o._changedRowIndices.has(h),v=u.classList.contains("changed");w!==v&&u.classList.toggle("changed",w),u.parentNode!==r&&r.appendChild(u)}}function ie(o,e,t,n){const i=e.children,s=o.visibleColumns,r=s.length,a=i.length,l=r<a?r:a,f=o.focusRow,p=o.focusCol;let g=o.__hasSpecialColumns;if(g===void 0){g=!1;for(let c=0;c<r;c++){const u=s[c];if(u.__viewTemplate||u.__compiledView||u.viewRenderer||u.externalView||u.format||u.type==="date"||u.type==="boolean"){g=!0;break}}o.__hasSpecialColumns=g}const h=String(n);if(!g){for(let c=0;c<l;c++){const u=i[c],d=t[s[c].field];u.textContent=d==null?"":String(d),u.getAttribute("data-row")!==h&&u.setAttribute("data-row",h);const b=f===n&&p===c,m=u.classList.contains("cell-focus");b!==m&&(u.classList.toggle("cell-focus",b),u.setAttribute("aria-selected",String(b)))}return}for(let c=0;c<l;c++)if(s[c].externalView&&!i[c].querySelector("[data-external-view]")){K(o,e,t,n);return}for(let c=0;c<l;c++){const u=s[c],d=i[c];d.getAttribute("data-row")!==h&&d.setAttribute("data-row",h);const b=f===n&&p===c,m=d.classList.contains("cell-focus");if(b!==m&&(d.classList.toggle("cell-focus",b),d.setAttribute("aria-selected",String(b))),d.classList.contains("editing"))continue;if(u.viewRenderer){const y=t[u.field],S=u.viewRenderer({row:t,value:y,field:u.field,column:u});typeof S=="string"?d.innerHTML=I(S):S?(d.innerHTML="",d.appendChild(S)):d.textContent=y==null?"":String(y);continue}if(u.__viewTemplate||u.__compiledView||u.externalView)continue;const E=t[u.field];let _;if(u.format)try{const y=u.format(E,t);_=y==null?"":String(y)}catch{_=E==null?"":String(E)}else if(u.type==="date")if(E==null||E==="")_="";else if(E instanceof Date)_=isNaN(E.getTime())?"":E.toLocaleDateString();else{const y=new Date(E);_=isNaN(y.getTime())?"":y.toLocaleDateString()}else u.type==="boolean"?(_=E?"🗹":"☐",d.setAttribute("aria-checked",String(!!E))):_=E==null?"":String(E);d.textContent=_}}function K(o,e,t,n){e.innerHTML="";const i=o.visibleColumns,s=i.length,r=o.focusRow,a=o.focusCol,l=o.effectiveConfig?.editOn||o.editOn,f=o,p=document.createDocumentFragment();for(let g=0;g<s;g++){const h=i[g],c=document.createElement("div");c.className="cell",G(c,"cell"),h.type!=="boolean"&&c.setAttribute("role","gridcell"),c.setAttribute("data-col",String(g)),c.setAttribute("data-row",String(n)),c.setAttribute("aria-colindex",String(g+1)),h.type&&c.setAttribute("data-type",h.type);const u=h.sticky;u==="left"?c.classList.add("sticky-left"):u==="right"&&c.classList.add("sticky-right");let d=t[h.field];const b=h.format;if(b)try{d=b(d,t)}catch{}const m=h.__compiledView,E=h.__viewTemplate,_=h.viewRenderer,y=h.externalView;let S=!1;if(_){const w=_({row:t,value:d,field:h.field,column:h});typeof w=="string"?(c.innerHTML=I(w),S=!0):w?c.appendChild(w):c.textContent=d==null?"":String(d)}else if(y){const w=y,v=document.createElement("div");v.setAttribute("data-external-view",""),v.setAttribute("data-field",h.field),c.appendChild(v);const T={row:t,value:d,field:h.field,column:h};if(w.mount)try{w.mount({placeholder:v,context:T,spec:w})}catch{}else queueMicrotask(()=>{try{f.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:v,spec:w,context:T}}))}catch{}});v.setAttribute("data-mounted","")}else if(m){const w=m({row:t,value:d,field:h.field,column:h}),v=m.__blocked;c.innerHTML=v?"":I(w),S=!0,v&&(c.textContent="",c.setAttribute("data-blocked-template",""))}else if(E){const w=E.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(w)?(c.textContent="",c.setAttribute("data-blocked-template","")):(c.innerHTML=I(ee(w,{row:t,value:d})),S=!0)}else if(h.type==="date")if(d==null||d==="")c.textContent="";else{let w=null;if(d instanceof Date)w=d;else if(typeof d=="number"||typeof d=="string"){const v=new Date(d);isNaN(v.getTime())||(w=v)}c.textContent=w?w.toLocaleDateString():""}else if(h.type==="boolean"){const w=!!d;c.innerHTML=w?"&#x1F5F9;":"&#9744;",c.setAttribute("role","checkbox"),c.setAttribute("aria-checked",String(w)),c.setAttribute("aria-label",String(w))}else c.textContent=d==null?"":String(d);if(S){Me(c);const w=c.textContent||"";/Proxy|Reflect\.ownKeys/.test(w)&&(c.textContent=w.replace(/Proxy|Reflect\.ownKeys/g,"").trim(),/Proxy|Reflect\.ownKeys/.test(c.textContent||"")&&(c.textContent=""))}c.hasAttribute("data-blocked-template")&&(c.textContent||"").trim().length&&(c.textContent=""),h.editable?(c.tabIndex=0,c.addEventListener("mousedown",()=>{o.focusRow=n,o.focusCol=g,H(o)}),l==="click"?c.addEventListener("click",w=>{c.classList.contains("editing")||(w.stopPropagation(),o.focusRow=n,o.focusCol=g,P(o,t,n,h,c))}):c.addEventListener("dblclick",w=>{w.stopPropagation(),L(o,n,t);const v=o.findRenderedRowElement?.(n);if(v){const T=v.children;for(let N=0;N<T.length;N++){const B=o.visibleColumns[N];B&&B.editable&&P(o,t,n,B,T[N])}}}),c.addEventListener("keydown",w=>{if((h.type==="select"||h.type==="typeahead")&&!c.classList.contains("editing")&&w.key==="Enter"){w.preventDefault(),o.activeEditRows!==n&&L(o,n,t),P(o,t,n,h,c),setTimeout(()=>{const v=c.querySelector("select");try{v?.showPicker?.()}catch{}v?.focus()},0);return}if(h.type==="boolean"&&w.key===" "&&!c.classList.contains("editing")){w.preventDefault(),o.activeEditRows!==n&&L(o,n,t);const v=!t[h.field];F(o,n,h,v,t),c.innerHTML=v?"&#x1F5F9;":"&#9744;",c.setAttribute("aria-label",String(!!v));return}if(w.key==="Enter"&&!c.classList.contains("editing")){w.preventDefault(),o.focusRow=n,o.focusCol=g,typeof o.beginBulkEdit=="function"?o.beginBulkEdit(n):P(o,t,n,h,c);return}if(w.key==="F2"&&!c.classList.contains("editing")){w.preventDefault(),P(o,t,n,h,c);return}})):h.type==="boolean"&&(c.hasAttribute("tabindex")||(c.tabIndex=0),c.addEventListener("keydown",w=>{if(w.key===" "){w.preventDefault();const v=!t[h.field];o.activeEditRows!==n&&L(o,n,t),F(o,n,h,v,t),c.innerHTML=v?"&#x1F5F9;":"&#9744;",c.setAttribute("role","checkbox"),c.setAttribute("aria-checked",String(!!v)),c.setAttribute("aria-label",String(!!v))}})),r===n&&a===g?c.setAttribute("aria-selected","true"):c.setAttribute("aria-selected","false"),p.appendChild(c)}e.appendChild(p)}function se(o,e,t,n){if(e.target?.closest(".resize-handle"))return;const i=t.querySelector(".cell[data-row]");if(!i)return;const s=Number(i.getAttribute("data-row"));if(isNaN(s))return;const r=o._rows[s];if(!r)return;const a=e.target?.closest(".cell[data-col]");if(a){const f=Number(a.getAttribute("data-col"));if(!isNaN(f)){if(o.dispatchCellClick?.(e,s,f,a))return;o.focusRow=s,o.focusCol=f,H(o)}}if(t.querySelector(".cell.editing")){const f=t.querySelectorAll(".cell.editing");if(!n)return;f.forEach(p=>p.classList.remove("editing"))}const l=o.effectiveConfig?.editOn||o.editOn||"doubleClick";if(l==="click"||l==="doubleClick"&&n)L(o,s,r);else return;Array.from(t.children).forEach((f,p)=>{const g=o.visibleColumns[p];g&&g.editable&&P(o,r,s,g,f)}),a&&queueMicrotask(()=>{const f=t.querySelector(`.cell[data-col="${o.focusCol}"]`);if(f?.classList.contains("editing")){const p=f.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');try{p?.focus()}catch{}}})}function L(o,e,t){o.activeEditRows!==e&&(o.rowEditSnapshots.set(e,{...t}),o.activeEditRows=e)}function Ge(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(r=>i[r]=n[r]),o._changedRowIndices.delete(e);else if(!t){const r=o._changedRowIndices.has(e);o.dispatchEvent(new CustomEvent("row-commit",{detail:{rowIndex:e,row:i,changed:r,changedRows:o.changedRows,changedRowIndices:o.changedRowIndices}}))}o.rowEditSnapshots.delete(e),o.activeEditRows=-1;const s=o.findRenderedRowElement?.(e);s&&(K(o,s,o._rows[e],e),o._changedRowIndices.has(e)?s.classList.add("changed"):s.classList.remove("changed")),t&&queueMicrotask(()=>{try{o.focus();const r=o.focusRow,a=o.focusCol,l=o.findRenderedRowElement?.(r);if(l){Array.from(o.bodyEl.querySelectorAll(".cell-focus")).forEach(p=>p.classList.remove("cell-focus"));const f=l.querySelector(`.cell[data-row="${r}"][data-col="${a}"]`);f&&f.classList.add("cell-focus")}}catch{}})}function F(o,e,t,n,i){const s=t.field;if(i[s]===n)return;i[s]=n;const a=!o._changedRowIndices.has(e);o._changedRowIndices.add(e);const l=o.findRenderedRowElement?.(e);l&&l.classList.add("changed"),o.dispatchEvent(new CustomEvent("cell-commit",{detail:{row:i,field:s,value:n,rowIndex:e,changedRows:o.changedRows,changedRowIndices:o.changedRowIndices,firstTimeForRow:a}}))}function P(o,e,t,n,i){if(!n.editable||(o.activeEditRows!==t&&L(o,t,e),i.classList.contains("editing")))return;const s=e[n.field];i.classList.add("editing");const r=h=>{F(o,t,n,h,e)},a=()=>{e[n.field]=s;const h=i.querySelector("input,textarea,select");h&&(typeof HTMLInputElement<"u"&&h instanceof HTMLInputElement&&h.type==="checkbox"?h.checked=!!s:"value"in h&&(h.value=s??""))},l=document.createElement("div");l.style.display="contents",i.innerHTML="",i.appendChild(l);const f=n.__editorTemplate,p=n.editor||(f?"template":Ne(n)),g=s;if(p==="template"&&f){const h=f.cloneNode(!0),c=n.__compiledEditor;c?h.innerHTML=c({row:e,value:s,field:n.field,column:n}):h.querySelectorAll("*").forEach(d=>{d.childNodes.length===1&&d.firstChild?.nodeType===Node.TEXT_NODE&&(d.textContent=d.textContent?.replace(/{{\s*value\s*}}/g,s==null?"":String(s)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(b,m)=>{const E=e[m];return E==null?"":String(E)})||"")});const u=h.querySelector("input,textarea,select");if(u){const d=typeof HTMLInputElement<"u";d&&u instanceof HTMLInputElement&&u.type==="checkbox"?u.checked=!!s:"value"in u&&(u.value=s??""),u.addEventListener("blur",()=>{const b=d&&u instanceof HTMLInputElement&&u.type==="checkbox"?u.checked:u.value;r(b)}),u.addEventListener("keydown",b=>{if(b.key==="Enter"){const m=d&&u instanceof HTMLInputElement&&u.type==="checkbox"?u.checked:u.value;r(m)}b.key==="Escape"&&a()}),d&&u instanceof HTMLInputElement&&u.type==="checkbox"&&u.addEventListener("change",()=>{const b=u.checked;r(b)}),setTimeout(()=>u.focus(),0)}l.appendChild(h)}else if(typeof p=="string"){const h=document.createElement(p);h.value=g,h.addEventListener("change",()=>r(h.value)),l.appendChild(h)}else if(typeof p=="function"){const h=p({row:e,value:g,field:n.field,column:n,commit:r,cancel:a});typeof h=="string"?l.innerHTML=h:l.appendChild(h)}else if(p&&typeof p=="object"){const h=document.createElement("div");h.setAttribute("data-external-editor",""),h.setAttribute("data-field",n.field),l.appendChild(h);const c={row:e,value:g,field:n.field,column:n,commit:r,cancel:a};if(p.mount)try{p.mount({placeholder:h,context:c,spec:p})}catch{}else o.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:h,spec:p,context:c}}))}}function re(o,e){!o.sortState||o.sortState.field!==e.field?(o.sortState||(o.__originalOrder=o._rows.slice()),le(o,e,1)):o.sortState.direction===1?le(o,e,-1):(o.sortState=null,o.__rowRenderEpoch++,o.rowPool.forEach(n=>n.__epoch=-1),o._rows=o.__originalOrder.slice(),W(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 le(o,e,t){o.sortState={field:e.field,direction:t};const n=e.sortComparator||((i,s)=>i==null&&s==null?0:i==null?-1:s==null||i>s?1:i<s?-1:0);o._rows.sort((i,s)=>n(i[e.field],s[e.field],i,s)*t),o.__rowRenderEpoch++,o.rowPool.forEach(i=>i.__epoch=-1),W(o),o.refreshVirtualWindow(!0),o.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:t}})),o.requestStateChange?.()}function Ke(o,e){typeof e=="string"?o.textContent=e:e instanceof HTMLElement&&(o.innerHTML="",o.appendChild(e.cloneNode(!0)))}function W(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",G(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 s=t.__headerTemplate;if(s)Array.from(s.childNodes).forEach(r=>i.appendChild(r.cloneNode(!0)));else{const r=t.header||t.field,a=document.createElement("span");a.textContent=r,i.appendChild(a)}if(t.sortable){i.classList.add("sortable"),i.tabIndex=0;const r=document.createElement("span");G(r,"sort-indicator"),r.style.opacity="0.6";const a=o.sortState?.field===t.field?o.sortState.direction:0,l={...$,...o.icons},f=a===1?l.sortAsc:a===-1?l.sortDesc:l.sortNone;Ke(r,f),i.appendChild(r),i.setAttribute("aria-sort",a===0?"none":a===1?"ascending":"descending"),i.addEventListener("click",p=>{o.resizeController?.isResizing||o.dispatchHeaderClick?.(p,n,i)||re(o,t)}),i.addEventListener("keydown",p=>{if(p.key==="Enter"||p.key===" "){if(p.preventDefault(),o.dispatchHeaderClick?.(p,n,i))return;re(o,t)}})}if(t.resizable){t.sticky||(i.style.position="relative");const r=document.createElement("div");r.className="resize-handle",r.setAttribute("aria-hidden","true"),r.addEventListener("mousedown",a=>{a.stopPropagation(),a.preventDefault(),o.resizeController.start(a,n,i)}),i.appendChild(r)}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 Fe(o){let e=null,t=null,n=null,i=null;const s=l=>{if(!e)return;const f=l.clientX-e.startX,p=Math.max(40,e.startWidth+f),g=o.visibleColumns[e.colIndex];g.width=p,g.__userResized=!0,g.__renderedWidth=p,t==null&&(t=requestAnimationFrame(()=>{t=null,o.updateTemplate?.()})),o.dispatchEvent(new CustomEvent("column-resize",{detail:{field:g.field,width:p}}))};let r=!1;const a=()=>{const l=e!==null;l&&(r=!0,requestAnimationFrame(()=>{r=!1})),window.removeEventListener("mousemove",s),window.removeEventListener("mouseup",a),n!==null&&(document.documentElement.style.cursor=n,n=null),i!==null&&(document.body.style.userSelect=i,i=null),e=null,l&&o.requestStateChange&&o.requestStateChange()};return{get isResizing(){return e!==null||r},start(l,f,p){l.preventDefault();const g=p.getBoundingClientRect();e={startX:l.clientX,colIndex:f,startWidth:g.width},window.addEventListener("mousemove",s),window.addEventListener("mouseup",a),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(){a()}}}function We(){return{toolPanels:new Map,headerContents:new Map,toolbarButtons:new Map,lightDomButtons:[],lightDomHeaderContent:[],activePanel:null,headerContentCleanups:new Map,activePanelCleanup:null,toolbarButtonCleanups:new Map}}function Ve(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 Ue(o,e){const t=o?.header?.title??"",n=!!t,i=o?.header?.toolbarButtons??[],s=i.length>0,r=e.toolbarButtons.size>0,a=e.lightDomButtons.length>0,l=e.toolPanels.size>0,p=(s||r||a)&&l,g=[...i].sort((d,b)=>(d.order??100)-(b.order??100)),h=[...e.toolbarButtons.values()].sort((d,b)=>(d.order??100)-(b.order??100)),c=[...e.toolPanels.values()].sort((d,b)=>(d.order??100)-(b.order??100));let u="";for(const d of g)d.icon&&d.action&&(u+=`<button class="tbw-toolbar-btn" data-btn="${d.id}" title="${d.label}" aria-label="${d.label}"${d.disabled?" disabled":""}>${d.icon}</button>`);for(const d of h)d.icon&&d.action&&(u+=`<button class="tbw-toolbar-btn" data-btn="${d.id}" title="${d.label}" aria-label="${d.label}"${d.disabled?" disabled":""}>${d.icon}</button>`);for(const d of g)(d.element||d.render)&&(u+=`<div class="tbw-toolbar-btn-slot" data-btn-slot="${d.id}"></div>`);for(const d of h)(d.element||d.render)&&(u+=`<div class="tbw-toolbar-btn-slot" data-btn-slot="${d.id}"></div>`);a&&(u+='<slot name="toolbar"></slot>'),p&&(u+='<div class="tbw-toolbar-separator"></div>');for(const d of c){const b=e.activePanel===d.id;u+=`<button class="tbw-toolbar-btn${b?" active":""}" data-panel="${d.id}" title="${d.tooltip??d.title}" aria-label="${d.tooltip??d.title}" aria-pressed="${b}" aria-controls="tbw-panel-${d.id}">${d.icon}</button>`}return`
1
+ (function(y,O){typeof exports=="object"&&typeof module<"u"?O(exports):typeof define=="function"&&define.amd?define(["exports"],O):(y=typeof globalThis<"u"?globalThis:y||self,O(y.TbwGrid={}))})(this,(function(y){"use strict";const O=":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-accent);--tbw-range-selection-bg: rgba(from var(--tbw-range-border-color) r g b / 12%);--tbw-resize-handle-width: 4px;--tbw-resize-handle-color: transparent;--tbw-resize-handle-color-hover: var(--tbw-color-accent);--tbw-resize-handle-border-radius: 0;--tbw-scrollbar-thumb: var(--tbw-color-border-strong);--tbw-scrollbar-track: var(--tbw-color-bg);--tbw-transition-duration: .12s;--tbw-transition-ease: ease;--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-border: var(--tbw-border-input, 1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input: var(--tbw-cell-padding-input, 2px 6px);--tbw-font-size-editor: inherit;--tbw-sort-indicator-color: var(--tbw-color-fg-muted);--tbw-sort-indicator-active-color: var(--tbw-color-accent);--tbw-header-text-transform: none;--tbw-header-letter-spacing: normal;--tbw-color-header-separator: var(--tbw-color-border-cell);--tbw-checkbox-size: 16px;--tbw-density-scale: 1}:host{position:relative;display:block;width:100%;height:100%;min-height:0;contain:content;font-family:var(--tbw-font-family);font-size:var(--tbw-font-size);background:var(--tbw-color-bg);color:var(--tbw-color-fg);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);overflow:clip;outline:none}:host,:host *{box-sizing:border-box}:host .header{display:block;flex-shrink:0;z-index:var(--tbw-z-layer-header, 30);background:var(--tbw-color-header-bg);overflow:visible}:host .header-group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-color-header-bg);z-index:var(--tbw-z-layer-header, 30)}:host .header-group-cell{display:flex;align-items:center;justify-content:flex-start;padding:var(--tbw-cell-padding-header, 2px 8px);color:var(--tbw-color-header-group-fg, var(--tbw-color-header-fg));font-weight:var(--tbw-font-weight-header-group, var(--tbw-font-weight-header));justify-content:var(--tbw-align-header-group, var(--tbw-align-header, flex-start))}:host .header-row{display:grid;grid-template-columns:var(--tbw-column-template);color:var(--tbw-color-header-fg);font-size:var(--tbw-font-size-header);min-height:var(--tbw-header-height);border-bottom:var(--tbw-border-header);z-index:var(--tbw-z-layer-header, 30)}:host .header-row>.cell{display:flex;align-items:center;gap:4px;padding:var(--tbw-cell-padding-header, 2px 8px);background-color:var(--tbw-color-header-bg);font-weight:var(--tbw-font-weight-header);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}:host .header-row>.cell>span:first-child{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}:host .header-row>.cell>span[part~=sort-indicator]{flex-shrink:0}:host .header-row>.cell:last-child{border-right:0}:host .header-group-cell,:host .header-row>.cell.grouped.group-end{border-right:2px solid var(--tbw-color-border)}:host .tbw-grid-root{display:flex;flex-direction:column;height:100%}:host .rows-body-wrapper{flex:1;min-height:0;display:flex;flex-direction:row;width:100%;min-width:fit-content}:host .rows-body{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow:visible}:host .rows-container{display:flex;flex-direction:row;flex:1;min-height:0;overflow:visible}:host .rows-viewport{flex:1;min-width:0;position:relative;display:block;overflow:clip}:host .faux-vscroll{position:sticky;inset-inline-end:0;flex-shrink:0;width:auto;overflow-y:auto;overflow-x:hidden;z-index:var(--tbw-z-layer-header, 30)}:host .faux-vscroll-spacer{width:1px}:host .rows-viewport .rows{position:absolute;top:0;left:0;min-width:100%;will-change:transform;z-index:var(--tbw-z-layer-rows, 1)}:host .data-grid-row{display:grid;grid-template-columns:var(--tbw-column-template);contain:layout style}:host .data-grid-row:has(.editing){background:var(--tbw-editing-bg)}:host .selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}:host .data-grid-row>.cell:focus-visible{outline: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{position:relative;display:flex;flex:1;min-height:0;overflow:visible}:host .tbw-grid-content{flex:1;min-width:0;min-height:0;display:flex;flex-direction:row;overflow:hidden}:host .tbw-scroll-area{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow-x:auto;overflow-y:hidden}:host .tbw-tool-panel{position:absolute;top:0;bottom:0;right:0;width:0;overflow:hidden;background:var(--tbw-tool-panel-bg);border-left:1px solid var(--tbw-tool-panel-border);transition:width var(--tbw-tool-panel-transition);display:flex;flex-direction:column;z-index:30;box-shadow:-2px 0 8px var(--tbw-color-shadow)}:host .tbw-tool-panel[data-position=left]{right:auto;left:0;border-left:none;border-right:1px solid var(--tbw-tool-panel-border);box-shadow:2px 0 8px var(--tbw-color-shadow)}:host .tbw-tool-panel.open{width:var(--tbw-tool-panel-width)}:host .tbw-tool-panel-resize{position:absolute;top:0;bottom:0;width:6px;cursor:col-resize;background:transparent;z-index:10;transition:background .15s ease}:host .tbw-tool-panel-resize[data-handle-position=left]{left:0}:host .tbw-tool-panel-resize[data-handle-position=right]{right:0}:host .tbw-tool-panel-resize:hover,:host .tbw-tool-panel-resize.resizing{background:var(--tbw-color-accent)}:host .tbw-tool-panel-header{display:flex;align-items:center;justify-content:space-between;min-height:var(--tbw-tool-panel-header-height);padding:0 12px;border-bottom:1px solid var(--tbw-tool-panel-border);flex-shrink:0}:host .tbw-tool-panel-title{font-weight:600;font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host .tbw-tool-panel-close{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;padding:0;border:none;border-radius:var(--tbw-border-radius);background:transparent;color:var(--tbw-color-fg-muted);cursor:pointer;font-size:14px}:host .tbw-tool-panel-close:hover{background:var(--tbw-color-row-hover);color:var(--tbw-color-fg)}:host .tbw-tool-panel-content{flex:1;overflow:auto}:host .tbw-accordion{display:flex;flex-direction:column;gap:0}:host .tbw-accordion-section{border-bottom:1px solid var(--tbw-tool-panel-border)}:host .tbw-accordion-section:last-child{border-bottom:none}:host .tbw-accordion-header{display:flex;align-items:center;gap:8px;width:100%;padding:10px 12px;border:none;background:transparent;color:var(--tbw-color-fg);font-size:13px;font-weight:600;text-align:left;cursor:pointer;-webkit-user-select:none;user-select:none}:host .tbw-accordion-header:hover{background:var(--tbw-color-row-hover)}:host .tbw-accordion-section.single .tbw-accordion-header{cursor:default}:host .tbw-accordion-section.single .tbw-accordion-header:hover{background:transparent}:host .tbw-accordion-chevron{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:10px;color:var(--tbw-color-fg-muted);transition:transform .15s ease;flex-shrink:0}:host .tbw-accordion-section.expanded .tbw-accordion-chevron{transform:rotate(90deg)}:host .tbw-accordion-icon{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:14px;flex-shrink:0}:host .tbw-accordion-title{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}:host .tbw-accordion-content{display:none}:host .tbw-accordion-section.expanded .tbw-accordion-content{display:block}:host .tbw-quick-filter-input{flex:1;max-width:300px;height:28px;padding:0 8px;border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);background:var(--tbw-color-bg);color:var(--tbw-color-fg);font-size:13px}:host .tbw-quick-filter-input:focus{outline:none;border-color:var(--tbw-color-accent)}:host .tbw-selection-summary{font-size:13px;color:var(--tbw-color-fg-muted);white-space:nowrap}";function Ee(o){const e=new Map;return o.sortState&&e.set(o.sortState.field,{direction:o.sortState.direction===1?"asc":"desc",priority:0}),e}function J(o,e){const t=o._columns,n=Ee(o);return{columns:t.map((s,i)=>{const r={field:s.field,order:i,visible:!0},a=s;a.__renderedWidth!==void 0?r.width=a.__renderedWidth:s.width!==void 0&&(r.width=typeof s.width=="string"?parseFloat(s.width):s.width);const l=n.get(s.field);l&&(r.sort=l);for(const d of e)if(d.getColumnState){const u=d.getColumnState(s.field);u&&Object.assign(r,u)}return r})}}function Re(o,e,t,n){if(!e.columns||e.columns.length===0)return;const s=new Map(e.columns.map(a=>[a.field,a])),i=t.map(a=>{const l=s.get(a.field);if(!l)return a;const d={...a};return l.width!==void 0&&(d.width=l.width,d.__renderedWidth=l.width),l.visible!==void 0&&(d.hidden=!l.visible),d});i.sort((a,l)=>{const d=s.get(a.field)?.order??1/0,u=s.get(l.field)?.order??1/0;return d-u}),o._columns=i;const r=e.columns.filter(a=>a.sort!==void 0).sort((a,l)=>(a.sort?.priority??0)-(l.sort?.priority??0));if(r.length>0){const a=r[0];a.sort&&(o.sortState={field:a.field,direction:a.sort.direction==="asc"?1:-1})}else o.sortState=null;for(const a of n)if(a.applyColumnState)for(const l of e.columns)a.applyColumnState(l.field,l)}function _e(o,e,t){let n=null;return()=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{n=null;const s=J(o,e());t(s)},100)}}const P={STRETCH:"stretch",FIXED:"fixed"},S={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰"};function Se(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 Q(o,e){if(e&&e.length){const i={};return e.forEach(r=>{r.type&&(i[r.field]=r.type)}),{columns:e,typeMap:i}}const t=o[0]||{},n=Object.keys(t).map(i=>{const r=t[i],a=Se(r);return{field:i,header:i.charAt(0).toUpperCase()+i.slice(1),type:a}}),s={};return n.forEach(i=>{s[i.field]=i.type||"string"}),{columns:n,typeMap:s}}const Ae=/{{\s*([^}]+)\s*}}/g,A="__DG_EMPTY__",xe=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,Te=/__(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/,Le=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"]),ee=/^on\w+$/i,ke=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),Pe=/^\s*(javascript|vbscript|data|blob):/i;function B(o){if(!o||typeof o!="string")return"";if(o.indexOf("<")===-1)return o;const e=document.createElement("template");return e.innerHTML=o,Me(e.content),e.innerHTML}function Me(o){const e=[],t=o.querySelectorAll("*");for(const n of t){const s=n.tagName.toLowerCase();if(Le.has(s)){e.push(n);continue}if((s==="svg"||n.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(n.attributes).some(a=>ee.test(a.name)||a.name==="href"||a.name==="xlink:href")){e.push(n);continue}const i=[];for(const r of n.attributes){const a=r.name.toLowerCase();if(ee.test(a)){i.push(r.name);continue}if(ke.has(a)&&Pe.test(r.value)){i.push(r.name);continue}if(a==="style"&&/expression\s*\(|javascript:|behavior\s*:/i.test(r.value)){i.push(r.name);continue}}i.forEach(r=>n.removeAttribute(r))}e.forEach(n=>n.remove())}function te(o,e){if(!o||o.indexOf("{{")===-1)return o;const t=[],n=o.replace(Ae,(a,l)=>{const d=Oe(l,e);return t.push({expr:l.trim(),result:d}),d}),s=He(n),i=t.length&&t.every(a=>a.result===""||a.result===A);return/Reflect\.|\bProxy\b|ownKeys\(/.test(o)||i?"":s}function Oe(o,e){if(o=(o||"").trim(),!o||/\b(Reflect|Proxy|ownKeys)\b/.test(o))return A;if(o==="value")return e.value==null?A:String(e.value);if(o.startsWith("row.")&&!/[()?]/.test(o)&&!o.includes(":")){const n=o.slice(4),s=e.row?e.row[n]:void 0;return s==null?A:String(s)}if(o.length>80||!xe.test(o)||Te.test(o))return A;const t=o.match(/\./g);if(t&&t.length>1)return A;try{const s=new Function("value","row",`return (${o});`)(e.value,e.row),i=s==null?"":String(s);return/Reflect|Proxy|ownKeys/.test(i)?A:i||A}catch{return A}}function He(o){return o&&o.replace(new RegExp(A,"g"),"").replace(/Reflect\.[^<>{}\s]+/g,"").replace(/\bProxy\b/g,"").replace(/ownKeys\([^)]*\)/g,"")}function ze(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 oe(o){const e=/Reflect\.|\bProxy\b|ownKeys\(/.test(o),t=n=>e?"":te(o,n);return t.__blocked=e,t}function De(o){return Array.from(o.querySelectorAll("tbw-grid-column")).map(t=>{const n=t.getAttribute("field")||"";if(!n)return null;const s=t.getAttribute("type")||void 0,r=s&&new Set(["number","string","date","boolean","select","typeahead"]).has(s)?s:void 0,a=t.getAttribute("header")||void 0,l=t.hasAttribute("sortable"),d=t.hasAttribute("editable"),u={field:n,type:r,header:a,sortable:l,editable:d};t.hasAttribute("resizable")&&(u.resizable=!0),t.hasAttribute("sizable")&&(u.resizable=!0);const g=t.getAttribute("options");g&&(u.options=g.split(",").map(p=>{const[b,m]=p.includes(":")?p.split(":"):[p.trim(),p.trim()];return{value:b.trim(),label:m?.trim()||b.trim()}}));const h=t.querySelector("tbw-grid-column-view"),c=t.querySelector("tbw-grid-column-editor"),f=t.querySelector("tbw-grid-column-header");return h&&(u.__viewTemplate=h),c&&(u.__editorTemplate=c),f&&(u.__headerTemplate=f),u}).filter(t=>!!t)}function Ne(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(s=>t[s.field]=s);const n=o.map(s=>{const i=t[s.field];if(!i)return s;const r={...s};return i.header&&!r.header&&(r.header=i.header),i.type&&!r.type&&(r.type=i.type),r.sortable=s.sortable||i.sortable,(s.resizable===!0||i.resizable===!0)&&(r.resizable=!0),r.editable=s.editable||i.editable,i.__viewTemplate&&(r.__viewTemplate=i.__viewTemplate),i.__editorTemplate&&(r.__editorTemplate=i.__editorTemplate),i.__headerTemplate&&(r.__headerTemplate=i.__headerTemplate),delete t[s.field],r});return Object.keys(t).forEach(s=>n.push(t[s])),n}function V(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 qe(o){o.__lightDomColumnsCache||(o.__originalColumnNodes=Array.from(o.querySelectorAll("tbw-grid-column")),o.__lightDomColumnsCache=o.__originalColumnNodes.length?De(o):[]);const e=o.__lightDomColumnsCache,t=Ne(o._columns,e);t.forEach(s=>{s.__viewTemplate&&!s.__compiledView&&(s.__compiledView=oe(s.__viewTemplate.innerHTML)),s.__editorTemplate&&!s.__compiledEditor&&(s.__compiledEditor=oe(s.__editorTemplate.innerHTML))});const{columns:n}=Q(o._rows,t);o._columns=n}function Ie(o){const e=o.effectiveConfig?.fitMode||o.fitMode||P.STRETCH;if(e!==P.STRETCH&&e!==P.FIXED||o.__didInitialAutoSize||!o.isConnected)return;const t=o.headerRowEl?.children||[];if(!t.length)return;let n=!1;o.visibleColumns.forEach((s,i)=>{if(s.width)return;const r=t[i];let a=r?r.scrollWidth:0;for(const l of o.rowPool){const d=l.children[i];if(d){const u=d.scrollWidth;u>a&&(a=u)}}a>0&&(s.width=a+2,s.__autoSized=!0,n=!0)}),n&&ne(o),o.__didInitialAutoSize=!0}function ne(o){(o.effectiveConfig?.fitMode||o.fitMode||P.STRETCH)===P.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 Be(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(i=>{const r=document.createElement("option");r.value=String(i.value),r.textContent=i.label,(e.column.multi&&Array.isArray(e.value)&&e.value.includes(i.value)||!e.column.multi&&e.value===i.value)&&(r.selected=!0),t.appendChild(r)});const s=()=>{if(e.column.multi){const i=[];Array.from(t.selectedOptions).forEach(r=>{i.push(r.value)}),e.commit(i)}else e.commit(t.value)};return t.addEventListener("change",s),t.addEventListener("blur",s),t.addEventListener("keydown",i=>{i.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 $e(o,e){if(o.dispatchKeyDown?.(e))return;const t=o._rows.length-1,n=o.visibleColumns.length-1,s=o.activeEditRows!==void 0&&o.activeEditRows!==-1,r=o.visibleColumns[o.focusCol]?.type,a=e.composedPath?e.composedPath():[],l=a&&a.length?a[0]:e.target,d=u=>{if(!u)return!1;const g=u.tagName;return!!(g==="INPUT"||g==="SELECT"||g==="TEXTAREA"||u.isContentEditable)};if(!(d(l)&&(e.key==="Home"||e.key==="End"))&&!(d(l)&&(e.key==="ArrowUp"||e.key==="ArrowDown")&&l.tagName==="INPUT"&&l.type==="number")&&!(s&&(r==="select"||r==="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),H(o);return}case"ArrowDown":s&&typeof o.commitActiveRowEdit=="function"&&o.commitActiveRowEdit(),o.focusRow=Math.min(t,o.focusRow+1),e.preventDefault();break;case"ArrowUp":s&&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}})),H(o);default:return}H(o)}}function H(o){if(o.virtualization?.enabled){const{rowHeight:s}=o.virtualization,i=o,r=o.focusRow*s;r<i.scrollTop?i.scrollTop=r:r+s>i.scrollTop+i.clientHeight&&(i.scrollTop=r-i.clientHeight+s)}o.refreshVirtualWindow(!1),Array.from(o.bodyEl.querySelectorAll(".cell-focus")).forEach(s=>s.classList.remove("cell-focus")),Array.from(o.bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(s=>{s.setAttribute("aria-selected","false")});const e=o.focusRow,t=o.virtualization.start??0,n=o.virtualization.end??o._rows.length;if(e>=t&&e<n){const i=o.bodyEl.querySelectorAll(".data-grid-row")[e-t]?.children[o.focusCol];if(i){if(i.classList.add("cell-focus"),i.setAttribute("aria-selected","true"),o.activeEditRows!==void 0&&o.activeEditRows!==-1&&i.classList.contains("editing")){const r=i.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(r&&document.activeElement!==r)try{r.focus()}catch{}}else if(!i.contains(document.activeElement)){i.hasAttribute("tabindex")||i.setAttribute("tabindex","-1");try{i.focus({preventScroll:!0})}catch{}}}}}const We="__cellDisplayCache",Ve="__cellCacheEpoch";function se(o){o[We]=void 0,o[Ve]=void 0,o.__hasSpecialColumns=void 0}function Fe(o,e,t,n,s){const i=Math.max(0,t-e),r=o.bodyEl,a=o.visibleColumns,l=a.length;let d=o.__cachedHeaderRowCount;for(d===void 0&&(d=o.shadowRoot?.querySelector(".header-group-row")?2:1,o.__cachedHeaderRowCount=d);o.rowPool.length<i;){const g=document.createElement("div");g.className="data-grid-row",g.setAttribute("role","row"),g.addEventListener("click",h=>re(o,h,g,!1)),g.addEventListener("dblclick",h=>re(o,h,g,!0)),o.rowPool.push(g)}if(o.rowPool.length>i){for(let g=i;g<o.rowPool.length;g++){const h=o.rowPool[g];h.parentNode===r&&h.remove()}o.rowPool.length=i}const u=s&&o.__hasRenderRowPlugins!==!1;for(let g=0;g<i;g++){const h=e+g,c=o._rows[h],f=o.rowPool[g];if(f.setAttribute("aria-rowindex",String(h+d+1)),u&&s(c,f,h)){f.__epoch=n,f.__rowDataRef=c,f.parentNode!==r&&r.appendChild(f);continue}const p=f.__epoch,b=f.__rowDataRef,m=f.children.length,_=p===n&&m===l,E=b!==c;let x=!1;if(_&&E){for(let L=0;L<l;L++)if(a[L].externalView&&!f.querySelector(`.cell[data-col="${L}"] [data-external-view]`)){x=!0;break}}!_||x?(f.__isCustomRow&&(f.className="data-grid-row",f.setAttribute("role","row"),f.__isCustomRow=!1),F(o,f,c,h),f.__epoch=n,f.__rowDataRef=c):E?(ie(o,f,c,h),f.__rowDataRef=c):ie(o,f,c,h);const w=o._changedRowIndices.has(h),v=f.classList.contains("changed");w!==v&&f.classList.toggle("changed",w),f.parentNode!==r&&r.appendChild(f)}}function ie(o,e,t,n){const s=e.children,i=o.visibleColumns,r=i.length,a=s.length,l=r<a?r:a,d=o.focusRow,u=o.focusCol;let g=o.__hasSpecialColumns;if(g===void 0){g=!1;for(let c=0;c<r;c++){const f=i[c];if(f.__viewTemplate||f.__compiledView||f.viewRenderer||f.externalView||f.format||f.type==="date"||f.type==="boolean"){g=!0;break}}o.__hasSpecialColumns=g}const h=String(n);if(!g){for(let c=0;c<l;c++){const f=s[c],p=t[i[c].field];f.textContent=p==null?"":String(p),f.getAttribute("data-row")!==h&&f.setAttribute("data-row",h);const b=d===n&&u===c,m=f.classList.contains("cell-focus");b!==m&&(f.classList.toggle("cell-focus",b),f.setAttribute("aria-selected",String(b)))}return}for(let c=0;c<l;c++)if(i[c].externalView&&!s[c].querySelector("[data-external-view]")){F(o,e,t,n);return}for(let c=0;c<l;c++){const f=i[c],p=s[c];p.getAttribute("data-row")!==h&&p.setAttribute("data-row",h);const b=d===n&&u===c,m=p.classList.contains("cell-focus");if(b!==m&&(p.classList.toggle("cell-focus",b),p.setAttribute("aria-selected",String(b))),p.classList.contains("editing"))continue;if(f.viewRenderer){const E=t[f.field],x=f.viewRenderer({row:t,value:E,field:f.field,column:f});typeof x=="string"?p.innerHTML=B(x):x?(p.innerHTML="",p.appendChild(x)):p.textContent=E==null?"":String(E);continue}if(f.__viewTemplate||f.__compiledView||f.externalView)continue;const C=t[f.field];let _;if(f.format)try{const E=f.format(C,t);_=E==null?"":String(E)}catch{_=C==null?"":String(C)}else if(f.type==="date")if(C==null||C==="")_="";else if(C instanceof Date)_=isNaN(C.getTime())?"":C.toLocaleDateString();else{const E=new Date(C);_=isNaN(E.getTime())?"":E.toLocaleDateString()}else f.type==="boolean"?(_=C?"🗹":"☐",p.setAttribute("aria-checked",String(!!C))):_=C==null?"":String(C);p.textContent=_}}function F(o,e,t,n){e.innerHTML="";const s=o.visibleColumns,i=s.length,r=o.focusRow,a=o.focusCol,l=o.effectiveConfig?.editOn||o.editOn,d=o,u=document.createDocumentFragment();for(let g=0;g<i;g++){const h=s[g],c=document.createElement("div");c.className="cell",V(c,"cell"),h.type!=="boolean"&&c.setAttribute("role","gridcell"),c.setAttribute("data-col",String(g)),c.setAttribute("data-row",String(n)),c.setAttribute("aria-colindex",String(g+1)),h.type&&c.setAttribute("data-type",h.type);const f=h.sticky;f==="left"?c.classList.add("sticky-left"):f==="right"&&c.classList.add("sticky-right");let p=t[h.field];const b=h.format;if(b)try{p=b(p,t)}catch{}const m=h.__compiledView,C=h.__viewTemplate,_=h.viewRenderer,E=h.externalView;let x=!1;if(_){const w=_({row:t,value:p,field:h.field,column:h});typeof w=="string"?(c.innerHTML=B(w),x=!0):w?c.appendChild(w):c.textContent=p==null?"":String(p)}else if(E){const w=E,v=document.createElement("div");v.setAttribute("data-external-view",""),v.setAttribute("data-field",h.field),c.appendChild(v);const L={row:t,value:p,field:h.field,column:h};if(w.mount)try{w.mount({placeholder:v,context:L,spec:w})}catch{}else queueMicrotask(()=>{try{d.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:v,spec:w,context:L}}))}catch{}});v.setAttribute("data-mounted","")}else if(m){const w=m({row:t,value:p,field:h.field,column:h}),v=m.__blocked;c.innerHTML=v?"":B(w),x=!0,v&&(c.textContent="",c.setAttribute("data-blocked-template",""))}else if(C){const w=C.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(w)?(c.textContent="",c.setAttribute("data-blocked-template","")):(c.innerHTML=B(te(w,{row:t,value:p})),x=!0)}else if(h.type==="date")if(p==null||p==="")c.textContent="";else{let w=null;if(p instanceof Date)w=p;else if(typeof p=="number"||typeof p=="string"){const v=new Date(p);isNaN(v.getTime())||(w=v)}c.textContent=w?w.toLocaleDateString():""}else if(h.type==="boolean"){const w=!!p;c.innerHTML=w?"&#x1F5F9;":"&#9744;",c.setAttribute("role","checkbox"),c.setAttribute("aria-checked",String(w)),c.setAttribute("aria-label",String(w))}else c.textContent=p==null?"":String(p);if(x){ze(c);const w=c.textContent||"";/Proxy|Reflect\.ownKeys/.test(w)&&(c.textContent=w.replace(/Proxy|Reflect\.ownKeys/g,"").trim(),/Proxy|Reflect\.ownKeys/.test(c.textContent||"")&&(c.textContent=""))}c.hasAttribute("data-blocked-template")&&(c.textContent||"").trim().length&&(c.textContent=""),h.editable?(c.tabIndex=0,c.addEventListener("mousedown",()=>{o.focusRow=n,o.focusCol=g,H(o)}),l==="click"?c.addEventListener("click",w=>{c.classList.contains("editing")||(w.stopPropagation(),o.focusRow=n,o.focusCol=g,M(o,t,n,h,c))}):c.addEventListener("dblclick",w=>{w.stopPropagation(),k(o,n,t);const v=o.findRenderedRowElement?.(n);if(v){const L=v.children;for(let I=0;I<L.length;I++){const W=o.visibleColumns[I];W&&W.editable&&M(o,t,n,W,L[I])}}}),c.addEventListener("keydown",w=>{if((h.type==="select"||h.type==="typeahead")&&!c.classList.contains("editing")&&w.key==="Enter"){w.preventDefault(),o.activeEditRows!==n&&k(o,n,t),M(o,t,n,h,c),setTimeout(()=>{const v=c.querySelector("select");try{v?.showPicker?.()}catch{}v?.focus()},0);return}if(h.type==="boolean"&&w.key===" "&&!c.classList.contains("editing")){w.preventDefault(),o.activeEditRows!==n&&k(o,n,t);const v=!t[h.field];G(o,n,h,v,t),c.innerHTML=v?"&#x1F5F9;":"&#9744;",c.setAttribute("aria-label",String(!!v));return}if(w.key==="Enter"&&!c.classList.contains("editing")){w.preventDefault(),o.focusRow=n,o.focusCol=g,typeof o.beginBulkEdit=="function"?o.beginBulkEdit(n):M(o,t,n,h,c);return}if(w.key==="F2"&&!c.classList.contains("editing")){w.preventDefault(),M(o,t,n,h,c);return}})):h.type==="boolean"&&(c.hasAttribute("tabindex")||(c.tabIndex=0),c.addEventListener("keydown",w=>{if(w.key===" "){w.preventDefault();const v=!t[h.field];o.activeEditRows!==n&&k(o,n,t),G(o,n,h,v,t),c.innerHTML=v?"&#x1F5F9;":"&#9744;",c.setAttribute("role","checkbox"),c.setAttribute("aria-checked",String(!!v)),c.setAttribute("aria-label",String(!!v))}})),r===n&&a===g?c.setAttribute("aria-selected","true"):c.setAttribute("aria-selected","false"),u.appendChild(c)}e.appendChild(u)}function re(o,e,t,n){if(e.target?.closest(".resize-handle"))return;const s=t.querySelector(".cell[data-row]");if(!s)return;const i=Number(s.getAttribute("data-row"));if(isNaN(i))return;const r=o._rows[i];if(!r)return;const a=e.target?.closest(".cell[data-col]");if(a){const d=Number(a.getAttribute("data-col"));if(!isNaN(d)){if(o.dispatchCellClick?.(e,i,d,a))return;o.focusRow=i,o.focusCol=d,H(o)}}if(t.querySelector(".cell.editing")){const d=t.querySelectorAll(".cell.editing");if(!n)return;d.forEach(u=>u.classList.remove("editing"))}const l=o.effectiveConfig?.editOn||o.editOn||"doubleClick";if(l==="click"||l==="doubleClick"&&n)k(o,i,r);else return;Array.from(t.children).forEach((d,u)=>{const g=o.visibleColumns[u];g&&g.editable&&M(o,r,i,g,d)}),a&&queueMicrotask(()=>{const d=t.querySelector(`.cell[data-col="${o.focusCol}"]`);if(d?.classList.contains("editing")){const u=d.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');try{u?.focus()}catch{}}})}function k(o,e,t){o.activeEditRows!==e&&(o.rowEditSnapshots.set(e,{...t}),o.activeEditRows=e)}function Ge(o,e,t){if(o.activeEditRows!==e)return;const n=o.rowEditSnapshots.get(e),s=o._rows[e];if(t&&n&&s)Object.keys(n).forEach(r=>s[r]=n[r]),o._changedRowIndices.delete(e);else if(!t){const r=o._changedRowIndices.has(e);o.dispatchEvent(new CustomEvent("row-commit",{detail:{rowIndex:e,row:s,changed:r,changedRows:o.changedRows,changedRowIndices:o.changedRowIndices}}))}o.rowEditSnapshots.delete(e),o.activeEditRows=-1;const i=o.findRenderedRowElement?.(e);i&&(F(o,i,o._rows[e],e),o._changedRowIndices.has(e)?i.classList.add("changed"):i.classList.remove("changed")),t&&queueMicrotask(()=>{try{o.focus();const r=o.focusRow,a=o.focusCol,l=o.findRenderedRowElement?.(r);if(l){Array.from(o.bodyEl.querySelectorAll(".cell-focus")).forEach(u=>u.classList.remove("cell-focus"));const d=l.querySelector(`.cell[data-row="${r}"][data-col="${a}"]`);d&&d.classList.add("cell-focus")}}catch{}})}function G(o,e,t,n,s){const i=t.field;if(s[i]===n)return;s[i]=n;const a=!o._changedRowIndices.has(e);o._changedRowIndices.add(e);const l=o.findRenderedRowElement?.(e);l&&l.classList.add("changed"),o.dispatchEvent(new CustomEvent("cell-commit",{detail:{row:s,field:i,value:n,rowIndex:e,changedRows:o.changedRows,changedRowIndices:o.changedRowIndices,firstTimeForRow:a}}))}function M(o,e,t,n,s){if(!n.editable||(o.activeEditRows!==t&&k(o,t,e),s.classList.contains("editing")))return;const i=e[n.field];s.classList.add("editing");const r=h=>{G(o,t,n,h,e)},a=()=>{e[n.field]=i;const h=s.querySelector("input,textarea,select");h&&(typeof HTMLInputElement<"u"&&h instanceof HTMLInputElement&&h.type==="checkbox"?h.checked=!!i:"value"in h&&(h.value=i??""))},l=document.createElement("div");l.style.display="contents",s.innerHTML="",s.appendChild(l);const d=n.__editorTemplate,u=n.editor||(d?"template":Be(n)),g=i;if(u==="template"&&d){const h=d.cloneNode(!0),c=n.__compiledEditor;c?h.innerHTML=c({row:e,value:i,field:n.field,column:n}):h.querySelectorAll("*").forEach(p=>{p.childNodes.length===1&&p.firstChild?.nodeType===Node.TEXT_NODE&&(p.textContent=p.textContent?.replace(/{{\s*value\s*}}/g,i==null?"":String(i)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(b,m)=>{const C=e[m];return C==null?"":String(C)})||"")});const f=h.querySelector("input,textarea,select");if(f){const p=typeof HTMLInputElement<"u";p&&f instanceof HTMLInputElement&&f.type==="checkbox"?f.checked=!!i:"value"in f&&(f.value=i??""),f.addEventListener("blur",()=>{const b=p&&f instanceof HTMLInputElement&&f.type==="checkbox"?f.checked:f.value;r(b)}),f.addEventListener("keydown",b=>{if(b.key==="Enter"){const m=p&&f instanceof HTMLInputElement&&f.type==="checkbox"?f.checked:f.value;r(m)}b.key==="Escape"&&a()}),p&&f instanceof HTMLInputElement&&f.type==="checkbox"&&f.addEventListener("change",()=>{const b=f.checked;r(b)}),setTimeout(()=>f.focus(),0)}l.appendChild(h)}else if(typeof u=="string"){const h=document.createElement(u);h.value=g,h.addEventListener("change",()=>r(h.value)),l.appendChild(h)}else if(typeof u=="function"){const h=u({row:e,value:g,field:n.field,column:n,commit:r,cancel:a});typeof h=="string"?l.innerHTML=h:l.appendChild(h)}else if(u&&typeof u=="object"){const h=document.createElement("div");h.setAttribute("data-external-editor",""),h.setAttribute("data-field",n.field),l.appendChild(h);const c={row:e,value:g,field:n.field,column:n,commit:r,cancel:a};if(u.mount)try{u.mount({placeholder:h,context:c,spec:u})}catch{}else o.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:h,spec:u,context:c}}))}}function le(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(),K(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||((s,i)=>s==null&&i==null?0:s==null?-1:i==null||s>i?1:s<i?-1:0);o._rows.sort((s,i)=>n(s[e.field],i[e.field],s,i)*t),o.__rowRenderEpoch++,o.rowPool.forEach(s=>s.__epoch=-1),K(o),o.refreshVirtualWindow(!0),o.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:t}})),o.requestStateChange?.()}function Ke(o,e){typeof e=="string"?o.textContent=e:e instanceof HTMLElement&&(o.innerHTML="",o.appendChild(e.cloneNode(!0)))}function K(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 s=document.createElement("div");s.className="cell",V(s,"header-cell"),s.setAttribute("role","columnheader"),s.setAttribute("aria-colindex",String(n+1)),s.setAttribute("data-field",t.field),s.setAttribute("data-col",String(n)),t.sticky==="left"?s.classList.add("sticky-left"):t.sticky==="right"&&s.classList.add("sticky-right");const i=t.__headerTemplate;if(i)Array.from(i.childNodes).forEach(r=>s.appendChild(r.cloneNode(!0)));else{const r=t.header||t.field,a=document.createElement("span");a.textContent=r,s.appendChild(a)}if(t.sortable){s.classList.add("sortable"),s.tabIndex=0;const r=document.createElement("span");V(r,"sort-indicator"),r.style.opacity="0.6";const a=o.sortState?.field===t.field?o.sortState.direction:0,l={...S,...o.icons},d=a===1?l.sortAsc:a===-1?l.sortDesc:l.sortNone;Ke(r,d),s.appendChild(r),s.setAttribute("aria-sort",a===0?"none":a===1?"ascending":"descending"),s.addEventListener("click",u=>{o.resizeController?.isResizing||o.dispatchHeaderClick?.(u,n,s)||le(o,t)}),s.addEventListener("keydown",u=>{if(u.key==="Enter"||u.key===" "){if(u.preventDefault(),o.dispatchHeaderClick?.(u,n,s))return;le(o,t)}})}if(t.resizable){t.sticky||(s.style.position="relative");const r=document.createElement("div");r.className="resize-handle",r.setAttribute("aria-hidden","true"),r.addEventListener("mousedown",a=>{a.stopPropagation(),a.preventDefault(),o.resizeController.start(a,n,s)}),s.appendChild(r)}e.appendChild(s)});try{const t=o.shadowRoot;t&&t.querySelectorAll(".header-group-row .cell").forEach(s=>{s.getAttribute("data-group")&&s.classList.add("grouped")})}catch{}e.querySelectorAll(".cell.sortable").forEach(t=>{t.getAttribute("aria-sort")||t.setAttribute("aria-sort","none")})}function Ue(o){let e=null,t=null,n=null,s=null;const i=l=>{if(!e)return;const d=l.clientX-e.startX,u=Math.max(40,e.startWidth+d),g=o.visibleColumns[e.colIndex];g.width=u,g.__userResized=!0,g.__renderedWidth=u,t==null&&(t=requestAnimationFrame(()=>{t=null,o.updateTemplate?.()})),o.dispatchEvent(new CustomEvent("column-resize",{detail:{field:g.field,width:u}}))};let r=!1;const a=()=>{const l=e!==null;l&&(r=!0,requestAnimationFrame(()=>{r=!1})),window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",a),n!==null&&(document.documentElement.style.cursor=n,n=null),s!==null&&(document.body.style.userSelect=s,s=null),e=null,l&&o.requestStateChange&&o.requestStateChange()};return{get isResizing(){return e!==null||r},start(l,d,u){l.preventDefault();const g=u.getBoundingClientRect();e={startX:l.clientX,colIndex:d,startWidth:g.width},window.addEventListener("mousemove",i),window.addEventListener("mouseup",a),n===null&&(n=document.documentElement.style.cursor),document.documentElement.style.cursor="e-resize",s===null&&(s=document.body.style.userSelect),document.body.style.userSelect="none"},dispose(){a()}}}function z(o){return o?typeof o=="string"?o:o.outerHTML:""}function Xe(){return{toolPanels:new Map,headerContents:new Map,toolbarButtons:new Map,lightDomButtons:[],lightDomHeaderContent:[],isPanelOpen:!1,expandedSections:new Set,headerContentCleanups:new Map,panelCleanups:new Map,toolbarButtonCleanups:new Map,activePanel:null,activePanelCleanup:null}}function je(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 Ye(o,e,t="☰"){const n=o?.header?.title??"",s=!!n,i=z(t),r=o?.header?.toolbarButtons??[],a=r.length>0,l=e.toolbarButtons.size>0,d=e.lightDomButtons.length>0,u=e.toolPanels.size>0,h=(a||l||d)&&u,c=[...r].sort((b,m)=>(b.order??100)-(m.order??100)),f=[...e.toolbarButtons.values()].sort((b,m)=>(b.order??100)-(m.order??100));let p="";for(const b of c)b.icon&&b.action&&(p+=`<button class="tbw-toolbar-btn" data-btn="${b.id}" title="${b.label}" aria-label="${b.label}"${b.disabled?" disabled":""}>${b.icon}</button>`);for(const b of f)b.icon&&b.action&&(p+=`<button class="tbw-toolbar-btn" data-btn="${b.id}" title="${b.label}" aria-label="${b.label}"${b.disabled?" disabled":""}>${b.icon}</button>`);for(const b of c)(b.element||b.render)&&(p+=`<div class="tbw-toolbar-btn-slot" data-btn-slot="${b.id}"></div>`);for(const b of f)(b.element||b.render)&&(p+=`<div class="tbw-toolbar-btn-slot" data-btn-slot="${b.id}"></div>`);if(d&&(p+='<slot name="toolbar"></slot>'),h&&(p+='<div class="tbw-toolbar-separator"></div>'),u){const b=e.isPanelOpen;p+=`<button class="tbw-toolbar-btn${b?" active":""}" data-panel-toggle title="Settings" aria-label="Toggle settings panel" aria-pressed="${b}" aria-controls="tbw-tool-panel">${i}</button>`}return`
2
2
  <div class="tbw-shell-header" part="shell-header" role="banner">
3
- ${n?`<div class="tbw-shell-title">${t}</div>`:""}
3
+ ${s?`<div class="tbw-shell-title">${n}</div>`:""}
4
4
  <div class="tbw-shell-content" part="shell-content" role="region" aria-label="Grid information">
5
5
  <slot name="header-content"></slot>
6
6
  </div>
7
7
  <div class="tbw-shell-toolbar" part="shell-toolbar" role="toolbar" aria-label="Grid tools">
8
- ${u}
8
+ ${p}
9
9
  </div>
10
10
  </div>
11
- `}function je(o,e,t){const n=o?.toolPanel?.position??"right",i=e.toolPanels.size>0,s=e.activePanel!==null,r=e.activePanel?e.toolPanels.get(e.activePanel):null,a=i?`
12
- <aside class="tbw-tool-panel${s?" open":""}" part="tool-panel" data-position="${n}" role="complementary" aria-label="${r?.title??"Tool panel"}" id="tbw-panel-${e.activePanel??"closed"}">
13
- <div class="tbw-tool-panel-header">
14
- <span class="tbw-tool-panel-title">${r?.title??""}</span>
15
- <button class="tbw-tool-panel-close" aria-label="Close panel">✕</button>
11
+ `}function Ze(o,e,t,n){const s=o?.toolPanel?.position??"right",i=e.toolPanels.size>0,r=e.isPanelOpen,a=z(n?.expand??S.expand),l=z(n?.collapse??S.collapse),d=[...e.toolPanels.values()].sort((f,p)=>(f.order??100)-(p.order??100)),u=d.length===1;let g="";for(const f of d){const p=e.expandedSections.has(f.id),b=f.icon?`<span class="tbw-accordion-icon">${f.icon}</span>`:"",m=u?"":`<span class="tbw-accordion-chevron">${p?l:a}</span>`;g+=`
12
+ <div class="${`tbw-accordion-section${p?" expanded":""}${u?" single":""}`}" data-section="${f.id}">
13
+ <button class="tbw-accordion-header" aria-expanded="${p}" aria-controls="tbw-section-${f.id}"${u?' aria-disabled="true"':""}>
14
+ ${b}
15
+ <span class="tbw-accordion-title">${f.title}</span>
16
+ ${m}
17
+ </button>
18
+ <div class="tbw-accordion-content" id="tbw-section-${f.id}" role="region" aria-labelledby="tbw-section-header-${f.id}"></div>
19
+ </div>
20
+ `}const c=i?`
21
+ <aside class="tbw-tool-panel${r?" open":""}" part="tool-panel" data-position="${s}" role="complementary" aria-label="Tool panel" id="tbw-tool-panel">
22
+ <div class="tbw-tool-panel-resize" data-resize-handle data-handle-position="${s==="left"?"right":"left"}" aria-hidden="true"></div>
23
+ <div class="tbw-tool-panel-content" role="region">
24
+ <div class="tbw-accordion">
25
+ ${g}
26
+ </div>
16
27
  </div>
17
- <div class="tbw-tool-panel-content" role="region"></div>
18
28
  </aside>
19
- `:"";return n==="left"?`
29
+ `:"";return s==="left"?`
20
30
  <div class="tbw-shell-body">
21
- ${a}
31
+ ${c}
22
32
  <div class="tbw-grid-content">
23
33
  ${t}
24
34
  </div>
@@ -28,10 +38,10 @@
28
38
  <div class="tbw-grid-content">
29
39
  ${t}
30
40
  </div>
31
- ${a}
41
+ ${c}
32
42
  </div>
33
- `}function ae(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((s,r)=>{s.setAttribute("slot","header-content")});const i=t.querySelectorAll("tbw-grid-tool-button");e.lightDomButtons=Array.from(i),e.lightDomButtons.sort((s,r)=>{const a=parseInt(s.getAttribute("order")??"100",10),l=parseInt(r.getAttribute("order")??"100",10);return a-l}),e.lightDomButtons.forEach(s=>{s.setAttribute("slot","toolbar")})}function Xe(o,e,t,n){const i=o.querySelector(".tbw-shell-toolbar");i&&i.addEventListener("click",r=>{const a=r.target,l=a.closest("[data-panel]");if(l){const p=l.getAttribute("data-panel");p&&n.onPanelToggle(p);return}const f=a.closest("[data-btn]");if(f){const p=f.getAttribute("data-btn");p&&n.onToolbarButtonClick(p)}});const s=o.querySelector(".tbw-tool-panel-close");s&&s.addEventListener("click",()=>{n.onPanelClose()})}function Ye(o,e,t){const n=[...e?.header?.toolbarButtons??[],...t.toolbarButtons.values()];for(const i of n){const s=o.querySelector(`[data-btn-slot="${i.id}"]`);if(!s)continue;const r=t.toolbarButtonCleanups.get(i.id);if(r&&(r(),t.toolbarButtonCleanups.delete(i.id)),i.element)s.appendChild(i.element);else if(i.render){const a=i.render(s);a&&t.toolbarButtonCleanups.set(i.id,a)}}}function ce(o,e){const t=o.querySelector(".tbw-shell-content");if(!t)return;const n=[...e.headerContents.values()].sort((s,r)=>(s.order??100)-(r.order??100)),i=t.querySelector('slot[name="header-content"]');for(const s of n){const r=e.headerContentCleanups.get(s.id);r&&(r(),e.headerContentCleanups.delete(s.id));let a=t.querySelector(`[data-header-content="${s.id}"]`);a||(a=document.createElement("div"),a.setAttribute("data-header-content",s.id),i?t.insertBefore(a,i):t.appendChild(a));const l=s.render(a);l&&e.headerContentCleanups.set(s.id,l)}}function Ze(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 de(o,e){o.querySelectorAll("[data-panel]").forEach(n=>{const s=n.getAttribute("data-panel")===e.activePanel;n.classList.toggle("active",s),n.setAttribute("aria-pressed",String(s))})}function he(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),s=t.querySelector(".tbw-tool-panel-title");s&&(s.textContent=i?.title??""),t.setAttribute("aria-label",`${i?.title??"Tool"} panel`),t.id=`tbw-panel-${e.activePanel}`}}function Je(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 s=e.lightDomButtons[n].querySelector("button");t.push({id:`light-dom-${n}`,label:s?.getAttribute("title")??s?.getAttribute("aria-label")??"",disabled:s?.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 Qe(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 ue{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?.()}onScrollRender(){for(const e of this.plugins)e.onScrollRender?.()}getExtraHeight(){let e=0;for(const t of this.plugins)typeof t.getExtraHeight=="function"&&(e+=t.getExtraHeight());return e}getExtraHeightBefore(e){let t=0;for(const n of this.plugins)typeof n.getExtraHeightBefore=="function"&&(t+=n.getExtraHeightBefore(e));return t}adjustVirtualStart(e,t,n){let i=e;for(const s of this.plugins)if(typeof s.adjustVirtualStart=="function"){const r=s.adjustVirtualStart(e,t,n);r<i&&(i=r)}return i}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 O extends HTMLElement{static tagName="tbw-grid";#o;#i=!1;#z;#N;#r=[];#l;#g;#v;#C;#n={};#f=!1;#p=0;#E=null;#y=!1;#k;#R=!1;#_=null;#A=null;#S=null;#x=null;#a;#w;#t;#P;#h;#e=We();#c=!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.#r;this.#r=e,t!==e&&this.#Z()}get sourceRows(){return this.#r}get columns(){return[...this._columns]}set columns(e){const t=this.#l;this.#l=e,t!==e&&this.#J()}get gridConfig(){return this.#n}set gridConfig(e){const t=this.#g;this.#g=e,t!==e&&this.#Q()}get fitMode(){return this.#n.fitMode??"stretch"}set fitMode(e){const t=this.#v;this.#v=e,t!==e&&this.#X()}get editOn(){return this.#n.editOn}set editOn(e){const t=this.#C;this.#C=e,t!==e&&this.#Y()}get effectiveConfig(){return this.#n}get disconnectSignal(){return this.#a||(this.#a=new AbortController),this.#a.signal}constructor(){super(),this.#o=this.attachShadow({mode:"open"}),this.#W(),this.#z=new Promise(e=>this.#N=e)}#W(){const e=new CSSStyleSheet;e.replaceSync(M),this.#o.adoptedStyleSheets=[e]}getPlugin(e){return this.#t?.getPlugin(e)}getPluginByName(e){return this.#t?.getPluginByName(e)}requestRender(){this.#L(),this.#M(),this.#T(),this.updateTemplate(),this.refreshVirtualWindow(!0)}requestAfterRender(){this.#b()}#I(){this.#t=new ue(this);const e=this.#n?.plugins,t=Array.isArray(e)?e:[];this.#t.attachAll(t)}#q(){const e=this.#t?.getAllStyles()??"";if(e){const t=document.createElement("style");t.setAttribute("data-plugin","all"),t.textContent=e,this.#o.appendChild(t)}}#B(){this.#t&&this.#t.detachAll(),this.#I(),this.#q(),this.#y=this.#t?.getAll().some(e=>e.onScroll)??!1}#V(){this.#t?.detachAll()}#U(){if(!this.#t)return;const e=this.#t.getToolPanels();for(const{panel:n}of e)this.#e.toolPanels.has(n.id)||this.#e.toolPanels.set(n.id,n);const t=this.#t.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.#r)?[...this.#r]:[],this.#a?.abort(),this.#a=new AbortController,this.#u(),this.#I(),this.#U(),this.#i||(this.#F(),this.#q(),this.#i=!0),this.#$()}disconnectedCallback(){this.#V(),Qe(this.#e),this.#c=!1,this.#a&&(this.#a.abort(),this.#a=void 0),this.resizeController&&this.resizeController.dispose(),this.#w&&(this.#w.disconnect(),this.#w=void 0),this.#f=!1}#$(){const t=this.#o.querySelector(".tbw-grid-content")??this.#o.querySelector(".tbw-grid-root");if(this.headerRowEl=t?.querySelector(".header-row"),this.virtualization.totalHeightEl=t?.querySelector(".faux-vscroll-spacer"),this.virtualization.viewportEl=t?.querySelector(".rows-viewport"),this.bodyEl=t?.querySelector(".rows"),this.#c){ce(this.#o,this.#e),Ye(this.#o,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.#f=!0;const n=this.disconnectSignal;this.#d(),this.addEventListener("keydown",r=>Ie(this,r),{signal:n}),document.addEventListener("keydown",r=>{r.key==="Escape"&&this.activeEditRows!==-1&&this.#O(this.activeEditRows,!0)},{capture:!0,signal:n}),document.addEventListener("mousedown",r=>{if(this.activeEditRows===-1)return;const a=this.findRenderedRowElement(this.activeEditRows);!a||(r.composedPath&&r.composedPath()||[]).includes(a)||this.#O(this.activeEditRows,!1)},{signal:n});const i=t?.querySelector(".faux-vscroll"),s=t?.querySelector(".rows");if(this.virtualization.container=i??this,this.#y=this.#t?.getAll().some(r=>r.onScroll)??!1,i&&s){i.addEventListener("scroll",()=>{if(!this.virtualization.enabled&&!this.#y)return;const l=i.scrollTop,f=this.virtualization.rowHeight,p=Math.floor(l/f),g=p-p%2,h=-(l-g*f);s.style.transform=`translateY(${h}px)`,this.#E=l,this.#p||(this.#p=requestAnimationFrame(()=>{this.#p=0,this.#E!==null&&(this.#ne(this.#E),this.#E=null)}))},{passive:!0,signal:n});const r=this.#o.querySelector(".tbw-grid-content"),a=this.#o.querySelector(".tbw-scroll-area");r&&(r.addEventListener("wheel",l=>{l.preventDefault(),l.shiftKey||Math.abs(l.deltaX)>Math.abs(l.deltaY)?a&&(a.scrollLeft+=l.shiftKey?l.deltaY:l.deltaX):i.scrollTop+=l.deltaY},{passive:!1,signal:n}),r.addEventListener("touchstart",l=>{l.touches.length===1&&(this.#_=l.touches[0].clientY,this.#A=l.touches[0].clientX,this.#S=i.scrollTop,this.#x=a?.scrollLeft??0)},{passive:!0,signal:n}),r.addEventListener("touchmove",l=>{if(l.touches.length===1&&this.#_!==null&&this.#A!==null&&this.#S!==null&&this.#x!==null){const f=this.#_-l.touches[0].clientY,p=this.#A-l.touches[0].clientX;i.scrollTop=this.#S+f,a&&(a.scrollLeft=this.#x+p),l.preventDefault()}},{passive:!1,signal:n}),r.addEventListener("touchend",()=>{this.#_=null,this.#A=null,this.#S=null,this.#x=null},{passive:!0,signal:n}))}this.resizeController=Fe(this),this.#o.addEventListener("mousedown",r=>this.#ie(r),{signal:n}),document.addEventListener("mousemove",r=>this.#se(r),{signal:n}),document.addEventListener("mouseup",r=>this.#re(r),{signal:n}),this.virtualization.enabled&&requestAnimationFrame(()=>this.refreshVirtualWindow(!0)),requestAnimationFrame(()=>{const r=this.bodyEl.querySelector(".data-grid-row");if(r){const a=r.getBoundingClientRect().height;a&&Math.abs(a-this.virtualization.rowHeight)>.1&&(this.virtualization.rowHeight=a,this.refreshVirtualWindow(!0))}}),this.virtualization.viewportEl&&(this.#w=new ResizeObserver(()=>{this.#p||(this.#p=requestAnimationFrame(()=>{this.#p=0,this.refreshVirtualWindow(!0)}))}),this.#w.observe(this.virtualization.viewportEl)),queueMicrotask(()=>this.#j()),requestAnimationFrame(()=>requestAnimationFrame(()=>this.#N?.()))}#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)}#j(){this.bodyEl?.querySelectorAll(".data-grid-row")?.forEach((t,n)=>{const i=n===this.focusRow;t.setAttribute("aria-selected",String(i)),t.querySelectorAll(".cell").forEach((s,r)=>{s.setAttribute("aria-selected",String(i&&r===this.focusCol))})})}#X(){if(!this.#f)return;this.#u(),this.#n.fitMode==="fixed"?(this.__didInitialAutoSize=!1,this.#G()):(this._columns.forEach(t=>{!t.__userResized&&t.__autoSized&&delete t.width}),this.updateTemplate())}#Y(){this.#f&&(this.#u(),this.rowPool.length=0,this.bodyEl&&(this.bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.refreshVirtualWindow(!0))}#Z(){this._rows=Array.isArray(this.#r)?[...this.#r]:[],this.#L(),!this.#l||Array.isArray(this.#l)&&this.#l.length===0?this.#d():this.refreshVirtualWindow(!0)}#J(){ne(this),this.#f&&(this.#u(),this.#d())}#Q(){this.#f&&(this.#u(),this.#B(),this.#L(),this.#M(),this.#T(),this.updateTemplate(),this.refreshVirtualWindow(!0))}#ee(){De(this)}#T(){W(this)}updateTemplate(){oe(this)}#G(){ze(this)}#M(){if(this.#t){const e=this._columns.filter(n=>!n.hidden),t=this.#t.processColumns([...e]);if(t!==e){const n=new Map(t.map((s,r)=>[s.field,{col:s,order:r}])),i=this._columns.map(s=>{if(s.hidden)return s;const r=n.get(s.field);return r?r.col:s});this._columns=i}}}#b(){this.#t?.afterRender()}#L(){ne(this);const e=Array.isArray(this.#r)?[...this.#r]:[],t=this.#t?.processRows(e)??e;this._rows=t}#u(){const e=this.#g?{...this.#g}:{};let t=Array.isArray(e.columns)?[...e.columns]:[];const n=(this.__lightDomColumnsCache||[]).map(i=>({...i}));if(n.length){const i={};t.forEach(s=>i[s.field]=s),n.forEach(s=>{const r=i[s.field];r?(s.header&&!r.header&&(r.header=s.header),s.type&&!r.type&&(r.type=s.type),r.sortable=r.sortable||s.sortable,s.resizable&&(r.resizable=!0),s.editable&&(r.editable=!0)):(t.push(s),i[s.field]=s)})}if(this.#l&&this.#l.length&&(t=[...this.#l]),(!t||t.length===0)&&this._rows.length&&(t=J(this._rows).columns),t.length){t.forEach(r=>{r.sortable===void 0&&(r.sortable=!0),r.resizable===void 0&&(r.resizable=!0)});const i=this.#n.columns;i?.some(r=>r.__compiledView||r.__compiledEditor)?e.columns=i:e.columns=t}else{const i=this.#n.columns;i?.some(s=>s.__compiledView||s.__compiledEditor)&&(e.columns=i)}this.#v&&(e.fitMode=this.#v),e.fitMode||(e.fitMode="stretch"),this.#C&&(e.editOn=this.#C),e.columnState&&!this.#h&&(this.#h=e.columnState),this.#n=e,e.fitMode==="fixed"&&this._columns.forEach(i=>{i.width==null&&(i.width=80)})}#H(e,t,n=this.__rowRenderEpoch){this.#k||(this.#k=(i,s,r)=>this.#t?.renderRow(i,s,r)??!1),$e(this,e,t,n,this.#k)}#te(e,t){L(this,e,t)}#O(e,t){Ge(this,e,t)}#d(){if(!this.isConnected||!this.headerRowEl||!this.bodyEl)return;const e=this.#g?.columns||this.#l||[];if(e.length){const n=new Map(this._columns.filter(s=>s.hidden).map(s=>[s.field,!0])),i=e.map(s=>({...s,hidden:n.get(s.field)??s.hidden}));this._columns=i}if(this.#ee(),this.#u(),this.#B(),this.#L(),this.#M(),this.#h){const n=this.#h;this.#h=void 0,this.#K(n)}this.#T(),this.updateTemplate(),this.refreshVirtualWindow(!0),this.#n.fitMode==="fixed"&&!this.__didInitialAutoSize&&requestAnimationFrame(()=>this.#G()),this.bodyEl&&(this.bodyEl.style.display="",this.bodyEl.style.gridTemplateColumns=""),queueMicrotask(()=>this.#b())}#K(e){const t=this.#n.columns??[],n=this.#t?.getAll()??[];Ce(this,e,t,n);for(const i of e.columns){const s=t.find(r=>r.field===i.field);s&&(s.hidden=!i.visible)}}#oe(){return this._rows.length<=this.virtualization.bypassThreshold}#ne(e){if(this.refreshVirtualWindow(!1),this.#t?.onScrollRender(),this.#y){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.#t?.onScroll(n)}}findHeaderRow(){return this.#o.querySelector(".header-row")}findRenderedRowElement(e){return Array.from(this.bodyEl.querySelectorAll(".data-grid-row")).find(t=>{const n=t.querySelector(".cell[data-row]");return n&&Number(n.getAttribute("data-row"))===e})||null}dispatchCellClick(e,t,n,i){const s=this._rows[t],r=this._columns[n];if(!s||!r)return!1;const a={row:s,rowIndex:t,colIndex:n,field:r.field,value:s[r.field],cellEl:i,originalEvent:e};return this.#t?.onCellClick(a)??!1}dispatchHeaderClick(e,t,n){const i=this._columns[t];if(!i)return!1;const s={colIndex:t,field:i.field,column:i,headerEl:n,originalEvent:e};return this.#t?.onHeaderClick(s)??!1}dispatchKeyDown(e){return this.#t?.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.#o.contains(n)){const u=this.#o.elementFromPoint(e.clientX,e.clientY);u&&(n=u)}const s=n?.closest?.("[data-col]"),r=n?.closest?.(".data-grid-row"),a=n?.closest?.(".header-row");let l,f,p,g,h,c;return s&&(l=parseInt(s.getAttribute("data-row")??"-1",10),f=parseInt(s.getAttribute("data-col")??"-1",10),l>=0&&f>=0&&(p=this._rows[l],c=this._columns[f],g=c?.field,h=p&&g?p[g]:void 0)),{type:t,row:p,rowIndex:l!==void 0&&l>=0?l:void 0,colIndex:f!==void 0&&f>=0?f:void 0,field:g,value:h,column:c,originalEvent:e,cellElement:s??void 0,rowElement:r??void 0,isHeader:!!a,cell:l!==void 0&&f!==void 0&&l>=0&&f>=0?{row:l,col:f}:void 0}}#ie(e){const t=this.#D(e,"mousedown");(this.#t?.onCellMouseDown(t)??!1)&&(this.#R=!0)}#se(e){if(!this.#R)return;const t=this.#D(e,"mousemove");this.#t?.onCellMouseMove(t)}#re(e){if(!this.#R)return;const t=this.#D(e,"mouseup");this.#t?.onCellMouseUp(t),this.#R=!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.#te(e,this._rows[e])}async commitActiveRowEdit(){this.activeEditRows!==-1&&this.#O(this.activeEditRows,!1)}async ready(){return this.#z}async forceLayout(){this.#d(),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(a=>a.field===e);if(!i||!t&&i.lockVisible||!t&&(n??[]).filter(l=>!l.hidden&&l.field!==e).length===0)return!1;const s=!!i.hidden,r=!t;return s!==r?(i.hidden=r,this.#s("column-visibility",{field:e,visible:t,visibleColumns:(n??[]).filter(a=>!a.hidden).map(a=>a.field)}),this.rowPool.length=0,this.bodyEl&&(this.bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.#d(),this.requestStateChange(),!0):!1}toggleColumnVisibility(e){const i=!!this.#n.columns?.find(s=>s.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.#d(),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 s=t.get(i);s&&(n.push(s),t.delete(i))}for(const i of t.values())n.push(i);this._columns=n,this.#T(),this.updateTemplate(),this.refreshVirtualWindow(!0)}getColumnOrder(){return this._columns.map(e=>e.field)}getColumnState(){const e=this.#t?.getAll()??[];return Z(this,e)}set columnState(e){e&&(this.#h=e,this.#i&&this.#le(e))}get columnState(){return this.getColumnState()}#le(e){(this.#n.columns??[]).forEach(n=>{n.hidden=!1}),this.#K(e),this.#d()}requestStateChange(){this.#P||(this.#P=Ee(this,()=>this.#t?.getAll()??[],e=>this.#s("column-state-change",e))),this.#P()}resetColumnState(){this.#h=void 0,(this.#n.columns??[]).forEach(n=>{n.hidden=!1}),this.sortState=null,this.__originalOrder=[],this.#u(),this.#d();const t=this.#t?.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,de(this.#o,this.#e),he(this.#o,this.#e),Ze(this.#o,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,de(this.#o,this.#e),he(this.#o,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.#c&&this.#m()}unregisterToolPanel(e){this.#e.activePanel===e&&this.closeToolPanel(),this.#e.toolPanels.delete(e),this.#c&&this.#m()}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.#c&&ce(this.#o,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.#o.querySelector(`[data-header-content="${e}"]`)?.remove()}getToolbarButtons(){return Je(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.#c&&this.#m()}unregisterToolbarButton(e){const t=this.#e.toolbarButtonCleanups.get(e);t&&(t(),this.#e.toolbarButtonCleanups.delete(e)),this.#e.toolbarButtons.delete(e),this.#c&&this.#m()}setToolbarButtonDisabled(e,t){const n=this.#e.toolbarButtons.get(e);n&&(n.disabled=t);const i=this.#o.querySelector(`[data-btn="${e}"]`);i&&(i.disabled=t)}refreshShellHeader(){this.#m()}#m(){ae(this,this.#e),this.#F(),this.#$()}refreshVirtualWindow(e=!1){if(!this.bodyEl)return;const t=this._rows.length;if(!this.virtualization.enabled){this.#H(0,t),this.#b();return}if(this.#oe()){this.virtualization.start=0,this.virtualization.end=t,this.bodyEl.style.transform="translateY(0px)",this.#H(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.#b();return}const n=this.virtualization.container??this,s=(this.virtualization.viewportEl??n).clientHeight,r=this.virtualization.rowHeight,a=n.scrollTop;let l=Math.floor(a/r),f=0;const p=10;for(;f<p;){const _=this.#t?.getExtraHeightBefore?.(l)??0,y=Math.floor((a-_)/r);if(y>=l||y<0)break;l=y,f++}l=l-l%2,l<0&&(l=0);const g=this.#t?.adjustVirtualStart(l,a,r);g!==void 0&&g<l&&(l=g,l=l-l%2,l<0&&(l=0));const h=Math.ceil(s/r)+3;let c=l+h;c>t&&(c=t),this.virtualization.start=l,this.virtualization.end=c;const d=this.#o.querySelector(".tbw-footer")?.offsetHeight??0,b=this.#t?.getExtraHeight()??0;this.virtualization.totalHeightEl&&(this.virtualization.totalHeightEl.style.height=`${t*r+r+d+b}px`);const m=this.#t?.getExtraHeightBefore?.(l)??0,E=-(a-l*r-m);this.bodyEl.style.transform=`translateY(${E}px)`,this.#H(l,c,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),this.setAttribute("aria-rowcount",String(t)),this.setAttribute("aria-colcount",String(this.visibleColumns.length)),e&&this.#b()}#F(){ae(this,this.#e);const e=this.#n?.shell,t=Ve(e,this.#e),n=`
43
+ `}function ce(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(i=>{i.setAttribute("slot","header-content")});const s=t.querySelectorAll("tbw-grid-tool-button");e.lightDomButtons=Array.from(s),e.lightDomButtons.sort((i,r)=>{const a=parseInt(i.getAttribute("order")??"100",10),l=parseInt(r.getAttribute("order")??"100",10);return a-l}),e.lightDomButtons.forEach(i=>{i.setAttribute("slot","toolbar")})}function Je(o,e,t,n){const s=o.querySelector(".tbw-shell-toolbar");s&&s.addEventListener("click",r=>{const a=r.target;if(a.closest("[data-panel-toggle]")){n.onPanelToggle();return}const d=a.closest("[data-btn]");if(d){const u=d.getAttribute("data-btn");u&&n.onToolbarButtonClick(u)}});const i=o.querySelector(".tbw-accordion");i&&i.addEventListener("click",r=>{const l=r.target.closest(".tbw-accordion-header");if(l){const u=l.closest("[data-section]")?.getAttribute("data-section");u&&n.onSectionToggle(u)}})}function Qe(o,e,t){const n=o.querySelector(".tbw-tool-panel"),s=o.querySelector("[data-resize-handle]"),i=o.querySelector(".tbw-shell-body");if(!n||!s||!i)return()=>{};const r=e?.toolPanel?.position??"right",a=200;let l=0,d=0,u=0,g=!1;const h=p=>{if(!g)return;p.preventDefault();const b=r==="left"?p.clientX-l:l-p.clientX,m=Math.min(u,Math.max(a,d+b));n.style.width=`${m}px`},c=()=>{if(!g)return;g=!1,s.classList.remove("resizing"),n.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const p=n.getBoundingClientRect().width;t(p),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",c)},f=p=>{p.preventDefault(),g=!0,l=p.clientX,d=n.getBoundingClientRect().width,u=i.getBoundingClientRect().width-20,s.classList.add("resizing"),n.style.transition="none",document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",h),document.addEventListener("mouseup",c)};return s.addEventListener("mousedown",f),()=>{s.removeEventListener("mousedown",f),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",c)}}function et(o,e,t){const n=[...e?.header?.toolbarButtons??[],...t.toolbarButtons.values()];for(const s of n){const i=o.querySelector(`[data-btn-slot="${s.id}"]`);if(!i)continue;const r=t.toolbarButtonCleanups.get(s.id);if(r&&(r(),t.toolbarButtonCleanups.delete(s.id)),s.element)i.appendChild(s.element);else if(s.render){const a=s.render(i);a&&t.toolbarButtonCleanups.set(s.id,a)}}}function de(o,e){const t=o.querySelector(".tbw-shell-content");if(!t)return;const n=[...e.headerContents.values()].sort((i,r)=>(i.order??100)-(r.order??100)),s=t.querySelector('slot[name="header-content"]');for(const i of n){const r=e.headerContentCleanups.get(i.id);r&&(r(),e.headerContentCleanups.delete(i.id));let a=t.querySelector(`[data-header-content="${i.id}"]`);a||(a=document.createElement("div"),a.setAttribute("data-header-content",i.id),s?t.insertBefore(a,s):t.appendChild(a));const l=i.render(a);l&&e.headerContentCleanups.set(i.id,l)}}function tt(o,e,t){if(!e.isPanelOpen)return;const n=z(t?.expand??S.expand),s=z(t?.collapse??S.collapse);for(const[i,r]of e.toolPanels){const a=e.expandedSections.has(i),l=o.querySelector(`[data-section="${i}"]`),d=l?.querySelector(".tbw-accordion-content");if(!l||!d)continue;l.classList.toggle("expanded",a);const u=l.querySelector(".tbw-accordion-header");u&&u.setAttribute("aria-expanded",String(a));const g=l.querySelector(".tbw-accordion-chevron");if(g&&(g.innerHTML=a?s:n),a){if(d.children.length===0){const h=r.render(d);h&&e.panelCleanups.set(i,h)}}else{const h=e.panelCleanups.get(i);h&&(h(),e.panelCleanups.delete(i)),d.innerHTML=""}}}function he(o,e){const t=o.querySelector("[data-panel-toggle]");t&&(t.classList.toggle("active",e.isPanelOpen),t.setAttribute("aria-pressed",String(e.isPanelOpen)))}function ue(o,e){const t=o.querySelector(".tbw-tool-panel");t&&(t.classList.toggle("open",e.isPanelOpen),e.isPanelOpen||(t.style.width=""))}function ot(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 i=e.lightDomButtons[n].querySelector("button");t.push({id:`light-dom-${n}`,label:i?.getAttribute("title")??i?.getAttribute("aria-label")??"",disabled:i?.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 nt(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 fe{constructor(e){this.grid=e}plugins=[];pluginMap=new Map;cellRenderers=new Map;headerRenderers=new Map;cellEditors=new Map;attachAll(e){for(const t of e)this.attach(t)}attach(e){if(this.pluginMap.set(e.constructor,e),this.plugins.push(e),e.cellRenderers)for(const[t,n]of Object.entries(e.cellRenderers))this.cellRenderers.set(t,n);if(e.headerRenderers)for(const[t,n]of Object.entries(e.headerRenderers))this.headerRenderers.set(t,n);if(e.cellEditors)for(const[t,n]of Object.entries(e.cellEditors))this.cellEditors.set(t,n);e.attach(this.grid)}detachAll(){for(let e=this.plugins.length-1;e>=0;e--)this.plugins[e].detach();this.plugins=[],this.pluginMap.clear(),this.cellRenderers.clear(),this.headerRenderers.clear(),this.cellEditors.clear()}getPlugin(e){return this.pluginMap.get(e)}getPluginByName(e){return this.plugins.find(t=>t.name===e)}hasPlugin(e){return this.pluginMap.has(e)}getAll(){return this.plugins}getCellRenderer(e){return this.cellRenderers.get(e)}getHeaderRenderer(e){return this.headerRenderers.get(e)}getCellEditor(e){return this.cellEditors.get(e)}getAllStyles(){return this.plugins.filter(e=>e.styles).map(e=>e.styles).join(`
44
+ `)}processRows(e){let t=[...e];for(const n of this.plugins)n.processRows&&(t=n.processRows(t));return t}processColumns(e){let t=[...e];for(const n of this.plugins)n.processColumns&&(t=n.processColumns(t));return t}beforeRender(){for(const e of this.plugins)e.beforeRender?.()}afterRender(){for(const e of this.plugins)e.afterRender?.()}onScrollRender(){for(const e of this.plugins)e.onScrollRender?.()}getExtraHeight(){let e=0;for(const t of this.plugins)typeof t.getExtraHeight=="function"&&(e+=t.getExtraHeight());return e}getExtraHeightBefore(e){let t=0;for(const n of this.plugins)typeof n.getExtraHeightBefore=="function"&&(t+=n.getExtraHeightBefore(e));return t}adjustVirtualStart(e,t,n){let s=e;for(const i of this.plugins)if(typeof i.adjustVirtualStart=="function"){const r=i.adjustVirtualStart(e,t,n);r<s&&(s=r)}return s}renderRow(e,t,n){for(const s of this.plugins)if(s.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 s=n.getContextMenuItems?.(e);s&&t.push(...s)}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 D extends HTMLElement{static tagName="tbw-grid";#n;#i=!1;#I;#B;#r=[];#l;#g;#v;#y;#o={};#f=!1;#p=0;#C=null;#E=!1;#P;#R=!1;#_=null;#S=null;#A=null;#x=null;#a;#b;#t;#M;#h;#e=Xe();#c=!1;#T;_rows=[];#O=[];get _columns(){return this.#o.columns??[]}set _columns(e){this.#o.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.#r;this.#r=e,t!==e&&this.#ee()}get sourceRows(){return this.#r}get columns(){return[...this._columns]}set columns(e){const t=this.#l;this.#l=e,t!==e&&this.#te()}get gridConfig(){return this.#o}set gridConfig(e){const t=this.#g;this.#g=e,t!==e&&this.#oe()}get fitMode(){return this.#o.fitMode??"stretch"}set fitMode(e){const t=this.#v;this.#v=e,t!==e&&this.#J()}get editOn(){return this.#o.editOn}set editOn(e){const t=this.#y;this.#y=e,t!==e&&this.#Q()}get effectiveConfig(){return this.#o}get disconnectSignal(){return this.#a||(this.#a=new AbortController),this.#a.signal}constructor(){super(),this.#n=this.attachShadow({mode:"open"}),this.#X(),this.#I=new Promise(e=>this.#B=e)}#X(){const e=new CSSStyleSheet;e.replaceSync(O),this.#n.adoptedStyleSheets=[e]}getPlugin(e){return this.#t?.getPlugin(e)}getPluginByName(e){return this.#t?.getPluginByName(e)}requestRender(){this.#k(),this.#H(),this.#L(),this.updateTemplate(),this.refreshVirtualWindow(!0)}requestAfterRender(){this.#w()}#$(){this.#t=new fe(this);const e=this.#o?.plugins,t=Array.isArray(e)?e:[];this.#t.attachAll(t)}#W(){const e=this.#t?.getAllStyles()??"";if(e){const t=document.createElement("style");t.setAttribute("data-plugin","all"),t.textContent=e,this.#n.appendChild(t)}}#V(){this.#t&&this.#t.detachAll(),this.#$(),this.#W(),this.#E=this.#t?.getAll().some(e=>e.onScroll)??!1}#j(){this.#t?.detachAll()}#Y(){if(!this.#t)return;const e=this.#t.getToolPanels();for(const{panel:n}of e)this.#e.toolPanels.has(n.id)||this.#e.toolPanels.set(n.id,n);const t=this.#t.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.#r)?[...this.#r]:[],this.#a?.abort(),this.#a=new AbortController,this.#u(),this.#$(),this.#Y(),this.#i||(this.#U(),this.#W(),this.#i=!0),this.#F()}disconnectedCallback(){this.#j(),nt(this.#e),this.#c=!1,this.#T?.(),this.#T=void 0,this.#a&&(this.#a.abort(),this.#a=void 0),this.resizeController&&this.resizeController.dispose(),this.#b&&(this.#b.disconnect(),this.#b=void 0),this.#f=!1}#F(){const t=this.#n.querySelector(".tbw-grid-content")??this.#n.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.#c){de(this.#n,this.#e),et(this.#n,this.#o?.shell,this.#e);const r=this.#o?.shell?.toolPanel?.defaultOpen;r&&this.#e.toolPanels.has(r)&&(this.openToolPanel(),this.#e.expandedSections.add(r))}this.setAttribute("data-upgraded",""),this.hasAttribute("role")||this.setAttribute("role","grid"),this.#f=!0;const n=this.disconnectSignal;this.#d(),this.addEventListener("keydown",r=>$e(this,r),{signal:n}),document.addEventListener("keydown",r=>{r.key==="Escape"&&this.activeEditRows!==-1&&this.#D(this.activeEditRows,!0)},{capture:!0,signal:n}),document.addEventListener("mousedown",r=>{if(this.activeEditRows===-1)return;const a=this.findRenderedRowElement(this.activeEditRows);!a||(r.composedPath&&r.composedPath()||[]).includes(a)||this.#D(this.activeEditRows,!1)},{signal:n});const s=t?.querySelector(".faux-vscroll"),i=t?.querySelector(".rows");if(this.virtualization.container=s??this,this.#E=this.#t?.getAll().some(r=>r.onScroll)??!1,s&&i){s.addEventListener("scroll",()=>{if(!this.virtualization.enabled&&!this.#E)return;const l=s.scrollTop,d=this.virtualization.rowHeight,u=Math.floor(l/d),g=u-u%2,h=-(l-g*d);i.style.transform=`translateY(${h}px)`,this.#C=l,this.#p||(this.#p=requestAnimationFrame(()=>{this.#p=0,this.#C!==null&&(this.#re(this.#C),this.#C=null)}))},{passive:!0,signal:n});const r=this.#n.querySelector(".tbw-grid-content"),a=this.#n.querySelector(".tbw-scroll-area");r&&(r.addEventListener("wheel",l=>{l.preventDefault(),l.shiftKey||Math.abs(l.deltaX)>Math.abs(l.deltaY)?a&&(a.scrollLeft+=l.shiftKey?l.deltaY:l.deltaX):s.scrollTop+=l.deltaY},{passive:!1,signal:n}),r.addEventListener("touchstart",l=>{l.touches.length===1&&(this.#_=l.touches[0].clientY,this.#S=l.touches[0].clientX,this.#A=s.scrollTop,this.#x=a?.scrollLeft??0)},{passive:!0,signal:n}),r.addEventListener("touchmove",l=>{if(l.touches.length===1&&this.#_!==null&&this.#S!==null&&this.#A!==null&&this.#x!==null){const d=this.#_-l.touches[0].clientY,u=this.#S-l.touches[0].clientX;s.scrollTop=this.#A+d,a&&(a.scrollLeft=this.#x+u),l.preventDefault()}},{passive:!1,signal:n}),r.addEventListener("touchend",()=>{this.#_=null,this.#S=null,this.#A=null,this.#x=null},{passive:!0,signal:n}))}this.resizeController=Ue(this),this.#n.addEventListener("mousedown",r=>this.#le(r),{signal:n}),document.addEventListener("mousemove",r=>this.#ae(r),{signal:n}),document.addEventListener("mouseup",r=>this.#ce(r),{signal:n}),this.virtualization.enabled&&requestAnimationFrame(()=>this.refreshVirtualWindow(!0)),requestAnimationFrame(()=>{const r=this.bodyEl.querySelector(".data-grid-row");if(r){const a=r.getBoundingClientRect().height;a&&Math.abs(a-this.virtualization.rowHeight)>.1&&(this.virtualization.rowHeight=a,this.refreshVirtualWindow(!0))}}),this.virtualization.viewportEl&&(this.#b=new ResizeObserver(()=>{this.#p||(this.#p=requestAnimationFrame(()=>{this.#p=0,this.refreshVirtualWindow(!0)}))}),this.#b.observe(this.virtualization.viewportEl)),queueMicrotask(()=>this.#Z()),requestAnimationFrame(()=>requestAnimationFrame(()=>this.#B?.()))}#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)}#Z(){this.bodyEl?.querySelectorAll(".data-grid-row")?.forEach((t,n)=>{const s=n===this.focusRow;t.setAttribute("aria-selected",String(s)),t.querySelectorAll(".cell").forEach((i,r)=>{i.setAttribute("aria-selected",String(s&&r===this.focusCol))})})}#J(){if(!this.#f)return;this.#u(),this.#o.fitMode==="fixed"?(this.__didInitialAutoSize=!1,this.#G()):(this._columns.forEach(t=>{!t.__userResized&&t.__autoSized&&delete t.width}),this.updateTemplate())}#Q(){this.#f&&(this.#u(),this.rowPool.length=0,this.bodyEl&&(this.bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.refreshVirtualWindow(!0))}#ee(){this._rows=Array.isArray(this.#r)?[...this.#r]:[],this.#k(),!this.#l||Array.isArray(this.#l)&&this.#l.length===0?this.#d():this.refreshVirtualWindow(!0)}#te(){se(this),this.#f&&(this.#u(),this.#d())}#oe(){this.#f&&(this.#u(),this.#V(),this.#k(),this.#H(),this.#L(),this.updateTemplate(),this.refreshVirtualWindow(!0))}#ne(){qe(this)}#L(){K(this)}updateTemplate(){ne(this)}#G(){Ie(this)}#H(){if(this.#t){const e=this.#O.length>0?this.#O:this._columns,t=e.filter(i=>!i.hidden),n=e.filter(i=>i.hidden),s=this.#t.processColumns([...t]);if(s!==t){const i=new Map(s.map((a,l)=>[a.field,{col:a,order:l}]));if(!t.some(a=>i.has(a.field))&&s.length>0)this._columns=[...s,...n];else{const a=e.map(l=>{if(l.hidden)return l;const d=i.get(l.field);return d?d.col:l});this._columns=a}}else this._columns=[...e]}}#w(){this.#t?.afterRender()}#k(){se(this);const e=Array.isArray(this.#r)?[...this.#r]:[],t=this.#t?.processRows(e)??e;this._rows=t}#u(){const e=this.#g?{...this.#g}:{};let t=Array.isArray(e.columns)?[...e.columns]:[];const n=(this.__lightDomColumnsCache||[]).map(s=>({...s}));if(n.length){const s={};t.forEach(i=>s[i.field]=i),n.forEach(i=>{const r=s[i.field];r?(i.header&&!r.header&&(r.header=i.header),i.type&&!r.type&&(r.type=i.type),r.sortable=r.sortable||i.sortable,i.resizable&&(r.resizable=!0),i.editable&&(r.editable=!0)):(t.push(i),s[i.field]=i)})}if(this.#l&&this.#l.length&&(t=[...this.#l]),(!t||t.length===0)&&this._rows.length&&(t=Q(this._rows).columns),t.length){t.forEach(r=>{r.sortable===void 0&&(r.sortable=!0),r.resizable===void 0&&(r.resizable=!0)});const s=this.#o.columns;s?.some(r=>r.__compiledView||r.__compiledEditor)?e.columns=s:e.columns=t}else{const s=this.#o.columns;s?.some(i=>i.__compiledView||i.__compiledEditor)&&(e.columns=s)}this.#v&&(e.fitMode=this.#v),e.fitMode||(e.fitMode="stretch"),this.#y&&(e.editOn=this.#y),e.columnState&&!this.#h&&(this.#h=e.columnState),this.#o=e,e.fitMode==="fixed"&&this._columns.forEach(s=>{s.width==null&&(s.width=80)})}#z(e,t,n=this.__rowRenderEpoch){this.#P||(this.#P=(s,i,r)=>this.#t?.renderRow(s,i,r)??!1),Fe(this,e,t,n,this.#P)}#se(e,t){k(this,e,t)}#D(e,t){Ge(this,e,t)}#d(){if(!this.isConnected||!this.headerRowEl||!this.bodyEl)return;const e=this.#g?.columns||this.#l||[];if(e.length){const n=new Map(this._columns.filter(i=>i.hidden).map(i=>[i.field,!0])),s=e.map(i=>({...i,hidden:n.get(i.field)??i.hidden}));this._columns=s}if(this.#ne(),this.#u(),this.#V(),this.#O=[...this._columns],this.#k(),this.#H(),this.#h){const n=this.#h;this.#h=void 0,this.#K(n)}this.#L(),this.updateTemplate(),this.refreshVirtualWindow(!0),this.#o.fitMode==="fixed"&&!this.__didInitialAutoSize&&requestAnimationFrame(()=>this.#G()),this.bodyEl&&(this.bodyEl.style.display="",this.bodyEl.style.gridTemplateColumns=""),queueMicrotask(()=>this.#w())}#K(e){const t=this.#o.columns??[],n=this.#t?.getAll()??[];Re(this,e,t,n);for(const s of e.columns){const i=t.find(r=>r.field===s.field);i&&(i.hidden=!s.visible)}}#ie(){return this._rows.length<=this.virtualization.bypassThreshold}#re(e){if(this.refreshVirtualWindow(!1),this.#t?.onScrollRender(),this.#E){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.#t?.onScroll(n)}}findHeaderRow(){return this.#n.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,s){const i=this._rows[t],r=this._columns[n];if(!i||!r)return!1;const a={row:i,rowIndex:t,colIndex:n,field:r.field,value:i[r.field],cellEl:s,originalEvent:e};return this.#t?.onCellClick(a)??!1}dispatchHeaderClick(e,t,n){const s=this._columns[t];if(!s)return!1;const i={colIndex:t,field:s.field,column:s,headerEl:n,originalEvent:e};return this.#t?.onHeaderClick(i)??!1}dispatchKeyDown(e){return this.#t?.onKeyDown(e)??!1}#N(e,t){let n=null;const s=e.composedPath?.();if(s&&s.length>0?n=s[0]:n=e.target,n&&!this.#n.contains(n)){const f=this.#n.elementFromPoint(e.clientX,e.clientY);f&&(n=f)}const i=n?.closest?.("[data-col]"),r=n?.closest?.(".data-grid-row"),a=n?.closest?.(".header-row");let l,d,u,g,h,c;return i&&(l=parseInt(i.getAttribute("data-row")??"-1",10),d=parseInt(i.getAttribute("data-col")??"-1",10),l>=0&&d>=0&&(u=this._rows[l],c=this._columns[d],g=c?.field,h=u&&g?u[g]:void 0)),{type:t,row:u,rowIndex:l!==void 0&&l>=0?l:void 0,colIndex:d!==void 0&&d>=0?d:void 0,field:g,value:h,column:c,originalEvent:e,cellElement:i??void 0,rowElement:r??void 0,isHeader:!!a,cell:l!==void 0&&d!==void 0&&l>=0&&d>=0?{row:l,col:d}:void 0}}#le(e){const t=this.#N(e,"mousedown");(this.#t?.onCellMouseDown(t)??!1)&&(this.#R=!0)}#ae(e){if(!this.#R)return;const t=this.#N(e,"mousemove");this.#t?.onCellMouseMove(t)}#ce(e){if(!this.#R)return;const t=this.#N(e,"mouseup");this.#t?.onCellMouseUp(t),this.#R=!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.#se(e,this._rows[e])}async commitActiveRowEdit(){this.activeEditRows!==-1&&this.#D(this.activeEditRows,!1)}async ready(){return this.#I}async forceLayout(){this.#d(),await new Promise(e=>requestAnimationFrame(()=>requestAnimationFrame(e)))}async getConfig(){return Object.freeze({...this.#o||{}})}setColumnVisible(e,t){const n=this.#o.columns,s=n?.find(a=>a.field===e);if(!s||!t&&s.lockVisible||!t&&(n??[]).filter(l=>!l.hidden&&l.field!==e).length===0)return!1;const i=!!s.hidden,r=!t;return i!==r?(s.hidden=r,this.#s("column-visibility",{field:e,visible:t,visibleColumns:(n??[]).filter(a=>!a.hidden).map(a=>a.field)}),this.rowPool.length=0,this.bodyEl&&(this.bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.#d(),this.requestStateChange(),!0):!1}toggleColumnVisibility(e){const s=!!this.#o.columns?.find(i=>i.field===e)?.hidden;return this.setColumnVisible(e,s)}isColumnVisible(e){const n=this.#o.columns?.find(s=>s.field===e);return n?!n.hidden:!1}showAllColumns(){const e=this.#o.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.#d(),this.requestStateChange())}getAllColumns(){return(this.#o.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(s=>[s.field,s])),n=[];for(const s of e){const i=t.get(s);i&&(n.push(i),t.delete(s))}for(const s of t.values())n.push(s);this._columns=n,this.#L(),this.updateTemplate(),this.refreshVirtualWindow(!0)}getColumnOrder(){return this._columns.map(e=>e.field)}getColumnState(){const e=this.#t?.getAll()??[];return J(this,e)}set columnState(e){e&&(this.#h=e,this.#i&&this.#de(e))}get columnState(){return this.getColumnState()}#de(e){(this.#o.columns??[]).forEach(n=>{n.hidden=!1}),this.#K(e),this.#d()}requestStateChange(){this.#M||(this.#M=_e(this,()=>this.#t?.getAll()??[],e=>this.#s("column-state-change",e))),this.#M()}resetColumnState(){this.#h=void 0,(this.#o.columns??[]).forEach(n=>{n.hidden=!1}),this.sortState=null,this.__originalOrder=[],this.#u(),this.#d();const t=this.#t?.getAll()??[];for(const n of t)if(n.applyColumnState)for(const s of this._columns)n.applyColumnState(s.field,{field:s.field,order:0,visible:!0});this.requestStateChange()}get isToolPanelOpen(){return this.#e.isPanelOpen}get activeToolPanel(){return this.#e.activePanel}get expandedToolPanelSections(){return[...this.#e.expandedSections]}openToolPanel(){if(this.#e.isPanelOpen)return;if(this.#e.isPanelOpen=!0,this.#e.expandedSections.size===0&&this.#e.toolPanels.size>0){const n=[...this.#e.toolPanels.values()].sort((s,i)=>(s.order??100)-(i.order??100))[0];n&&this.#e.expandedSections.add(n.id)}he(this.#n,this.#e),ue(this.#n,this.#e);const e={expand:this.#o?.icons?.expand??S.expand,collapse:this.#o?.icons?.collapse??S.collapse};tt(this.#n,this.#e,e),this.#s("tool-panel-open",{sections:this.expandedToolPanelSections})}closeToolPanel(){if(this.#e.isPanelOpen){for(const e of this.#e.panelCleanups.values())e();this.#e.panelCleanups.clear(),this.#e.activePanelCleanup&&(this.#e.activePanelCleanup(),this.#e.activePanelCleanup=null);for(const e of this.#e.toolPanels.values())e.onClose?.();this.#e.isPanelOpen=!1,he(this.#n,this.#e),ue(this.#n,this.#e),this.#s("tool-panel-close",{})}}toggleToolPanel(){this.#e.isPanelOpen?this.closeToolPanel():this.openToolPanel()}toggleToolPanelSection(e){const t=this.#e.toolPanels.get(e);if(!t){console.warn(`[tbw-grid] Tool panel section "${e}" not found`);return}if(this.#e.toolPanels.size===1)return;const n=this.#e.expandedSections.has(e);if(n){const s=this.#e.panelCleanups.get(e);s&&(s(),this.#e.panelCleanups.delete(e)),t.onClose?.(),this.#e.expandedSections.delete(e),this.#q(e,!1)}else{for(const[s,i]of this.#e.toolPanels)if(s!==e&&this.#e.expandedSections.has(s)){const r=this.#e.panelCleanups.get(s);r&&(r(),this.#e.panelCleanups.delete(s)),i.onClose?.(),this.#e.expandedSections.delete(s),this.#q(s,!1);const a=this.#n.querySelector(`[data-section="${s}"] .tbw-accordion-content`);a&&(a.innerHTML="")}this.#e.expandedSections.add(e),this.#q(e,!0),this.#he(e)}this.#s("tool-panel-section-toggle",{id:e,expanded:!n})}#q(e,t){const n=this.#n.querySelector(`[data-section="${e}"]`);n&&n.classList.toggle("expanded",t)}#he(e){const t=this.#e.toolPanels.get(e);if(!t?.render)return;const n=this.#n.querySelector(`[data-section="${e}"] .tbw-accordion-content`);if(!n)return;const s=t.render(n);s&&this.#e.panelCleanups.set(e,s)}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.#c&&this.#m()}unregisterToolPanel(e){this.#e.activePanel===e&&this.closeToolPanel(),this.#e.toolPanels.delete(e),this.#c&&this.#m()}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.#c&&de(this.#n,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.#n.querySelector(`[data-header-content="${e}"]`)?.remove()}getToolbarButtons(){return ot(this.#o?.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.#c&&this.#m()}unregisterToolbarButton(e){const t=this.#e.toolbarButtonCleanups.get(e);t&&(t(),this.#e.toolbarButtonCleanups.delete(e)),this.#e.toolbarButtons.delete(e),this.#c&&this.#m()}setToolbarButtonDisabled(e,t){const n=this.#e.toolbarButtons.get(e);n&&(n.disabled=t);const s=this.#n.querySelector(`[data-btn="${e}"]`);s&&(s.disabled=t)}refreshShellHeader(){this.#m()}#m(){ce(this,this.#e),this.#U(),this.#F()}refreshVirtualWindow(e=!1){if(!this.bodyEl)return;const t=this._rows.length;if(!this.virtualization.enabled){this.#z(0,t),this.#w();return}if(this.#ie()){this.virtualization.start=0,this.virtualization.end=t,this.bodyEl.style.transform="translateY(0px)",this.#z(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.#w();return}const n=this.virtualization.container??this,i=(this.virtualization.viewportEl??n).clientHeight,r=this.virtualization.rowHeight,a=n.scrollTop;let l=Math.floor(a/r),d=0;const u=10;for(;d<u;){const _=this.#t?.getExtraHeightBefore?.(l)??0,E=Math.floor((a-_)/r);if(E>=l||E<0)break;l=E,d++}l=l-l%2,l<0&&(l=0);const g=this.#t?.adjustVirtualStart(l,a,r);g!==void 0&&g<l&&(l=g,l=l-l%2,l<0&&(l=0));const h=Math.ceil(i/r)+3;let c=l+h;c>t&&(c=t),this.virtualization.start=l,this.virtualization.end=c;const p=this.#n.querySelector(".tbw-footer")?.offsetHeight??0,b=this.#t?.getExtraHeight()??0;this.virtualization.totalHeightEl&&(this.virtualization.totalHeightEl.style.height=`${t*r+r+p+b}px`);const m=this.#t?.getExtraHeightBefore?.(l)??0,C=-(a-l*r-m);this.bodyEl.style.transform=`translateY(${C}px)`,this.#z(l,c,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),this.setAttribute("aria-rowcount",String(t)),this.setAttribute("aria-colcount",String(this.visibleColumns.length)),e&&this.#w()}#U(){ce(this,this.#e);const e=this.#o?.shell,t=je(e,this.#e),n=`
35
45
  <div class="tbw-scroll-area">
36
46
  <div class="rows-body-wrapper">
37
47
  <div class="rows-body">
@@ -49,57 +59,16 @@
49
59
  <div class="faux-vscroll">
50
60
  <div class="faux-vscroll-spacer"></div>
51
61
  </div>
52
- `;if(t){const i=Ue(e,this.#e),s=je(e,this.#e,n);this.#o.innerHTML=`
62
+ `;if(t){const s=this.#o?.icons?.toolPanel??S.toolPanel,i={expand:this.#o?.icons?.expand??S.expand,collapse:this.#o?.icons?.collapse??S.collapse},r=Ye(e,this.#e,s),a=Ze(e,this.#e,n,i);this.#n.innerHTML=`
53
63
  <div class="tbw-grid-root has-shell">
54
- ${i}
55
- ${s}
64
+ ${r}
65
+ ${a}
56
66
  </div>
57
- `,this.#ae(),this.#c=!0}else this.#o.innerHTML=`
67
+ `,this.#ue(),this.#c=!0}else this.#n.innerHTML=`
58
68
  <div class="tbw-grid-root">
59
69
  <div class="tbw-grid-content">
60
70
  ${n}
61
71
  </div>
62
72
  </div>
63
- `}#ae(){Xe(this.#o,this.#n?.shell,this.#e,{onPanelToggle:e=>this.toggleToolPanel(e),onPanelClose:()=>this.closeToolPanel(),onToolbarButtonClick:e=>this.#ce(e)})}#ce(e){const n=(this.#n?.shell?.header?.toolbarButtons??[]).find(s=>s.id===e);if(n?.action){n.action();return}const i=this.#e.toolbarButtons.get(e);i?.action&&i.action()}}customElements.get(O.tagName)||customElements.define(O.tagName,O);class V{version="1.0.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}attach(e){this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}requestRender(){this.grid?.requestRender?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?.visibleColumns??[]}get shadowRoot(){return this.grid?.shadowRoot??null}get disconnectSignal(){return this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...$,...e}}resolveIcon(e,t){return t!==void 0?t:this.gridIcons[e]}setIcon(e,t){typeof t=="string"?e.innerHTML=t:t instanceof HTMLElement&&(e.innerHTML="",e.appendChild(t.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}function q(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 et(o){const e=q(o);return{from:{row:e.startRow,col:e.startCol},to:{row:e.endRow,col:e.endCol}}}function U(o){return o.map(et)}function tt(o,e,t){const n=q(t);return o>=n.startRow&&o<=n.endRow&&e>=n.startCol&&e<=n.endCol}function fe(o,e,t){return t.some(n=>tt(o,e,n))}function ot(o){const e=[],t=q(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 nt(o){const e=new Map;for(const t of o)for(const n of ot(t))e.set(`${n.row},${n.col}`,n);return[...e.values()]}function pe(o,e){return{startRow:o.row,startCol:o.col,endRow:e.row,endCol:e.col}}function it(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:U(e.ranges)}:{mode:o,ranges:[]}}class st extends V{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:s}=this.config;if(s==="cell")return this.selectedCell={row:t,col:n},this.emit("selection-change",this.#i()),this.requestAfterRender(),!1;if(s==="row")return this.selected.clear(),this.selected.add(t),this.lastSelected=t,this.emit("selection-change",this.#i()),this.requestAfterRender(),!1;if(s==="range"){const r=i.shiftKey,a=i.ctrlKey||i.metaKey;if(r&&this.cellAnchor){const l=pe(this.cellAnchor,{row:t,col:n});a?this.ranges.length>0?this.ranges[this.ranges.length-1]=l:this.ranges.push(l):this.ranges=[l],this.activeRange=l}else if(a){const l={startRow:t,startCol:n,endRow:t,endCol:n};this.ranges.push(l),this.activeRange=l,this.cellAnchor={row:t,col:n}}else{const l={startRow:t,startCol:n,endRow:t,endCol:n};this.ranges=[l],this.activeRange=l,this.cellAnchor={row:t,col:n}}return this.emit("selection-change",this.#i()),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.#i()),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 s={startRow:0,startCol:0,endRow:n-1,endCol:i-1};return this.ranges=[s],this.activeRange=s,this.emit("selection-change",this.#i()),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 s={startRow:t,startCol:n,endRow:t,endCol:n};return this.ranges.push(s),this.activeRange=s,this.emit("selection-change",this.#i()),this.requestAfterRender(),!0}onCellMouseMove(e){if(this.config.mode!=="range"||!this.isDragging||!this.cellAnchor||e.rowIndex===void 0||e.colIndex===void 0||e.rowIndex<0)return;const t=pe(this.cellAnchor,{row:e.rowIndex,col:e.colIndex});return this.ranges.length>0?this.ranges[this.ranges.length-1]=t:this.ranges.push(t),this.activeRange=t,this.emit("selection-change",this.#i()),this.requestAfterRender(),!0}onCellMouseUp(e){if(this.config.mode==="range"&&this.isDragging)return this.isDragging=!1,!0}#o(){const e=this.shadowRoot;if(!e)return;const{mode:t}=this.config;e.querySelectorAll(".cell").forEach(s=>{s.classList.remove("selected","top","bottom","first","last")});const i=e.querySelectorAll(".data-grid-row");if(i.forEach(s=>{s.classList.remove("selected","row-focus")}),t==="row"&&i.forEach(s=>{const r=s.querySelector(".cell[data-row]"),a=parseInt(r?.getAttribute("data-row")??"-1",10);a>=0&&this.selected.has(a)&&(s.classList.add("selected","row-focus"),s.querySelectorAll(".cell-focus").forEach(l=>l.classList.remove("cell-focus")))}),t==="range"&&this.ranges.length>0){const s=this.activeRange?q(this.activeRange):null;e.querySelectorAll(".cell[data-row][data-col]").forEach(a=>{const l=parseInt(a.getAttribute("data-row")??"-1",10),f=parseInt(a.getAttribute("data-col")??"-1",10);l>=0&&f>=0&&fe(l,f,this.ranges)&&(a.classList.add("selected"),a.classList.remove("cell-focus"),s&&(l===s.startRow&&a.classList.add("top"),l===s.endRow&&a.classList.add("bottom"),f===s.startCol&&a.classList.add("first"),f===s.endCol&&a.classList.add("last")))})}t==="cell"&&this.selectedCell&&e.querySelectorAll(".cell-focus").forEach(s=>s.classList.remove("cell-focus"))}afterRender(){const e=this.shadowRoot;if(!e)return;const t=e.children[0],{mode:n}=this.config;this.grid.setAttribute("data-selection-mode",n),t&&t.classList.toggle("selecting",this.isDragging),this.#o()}onScrollRender(){this.#o()}getSelectedCell(){return this.selectedCell}getSelectedRows(){return[...this.selected]}getRanges(){return U(this.ranges)}getSelectedCells(){return nt(this.ranges)}isCellSelected(e,t){return fe(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:U(this.ranges)}),this.requestAfterRender()}#i(){return it(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 j(o,e,t){return o.id!==void 0?String(o.id):t?`${t}-${e}`:String(e)}function ge(o,e,t,n=null,i=0){const s=e.childrenField??"children",r=[];for(let a=0;a<o.length;a++){const l=o[a],f=j(l,a,n),p=l[s],g=Array.isArray(p)&&p.length>0,h=t.has(f);if(r.push({key:f,data:l,depth:i,hasChildren:g,isExpanded:h,parentKey:n}),g&&h){const c=ge(p,e,t,f,i+1);r.push(...c)}}return r}function we(o,e){const t=new Set(o);return t.has(e)?t.delete(e):t.add(e),t}function X(o,e,t=null,n=0){const i=e.childrenField??"children",s=new Set;for(let r=0;r<o.length;r++){const a=o[r],l=j(a,r,t),f=a[i];if(Array.isArray(f)&&f.length>0){s.add(l);const p=X(f,e,l,n+1);for(const g of p)s.add(g)}}return s}function rt(){return new Set}function be(o,e,t,n=null,i=0){const s=t.childrenField??"children";for(let r=0;r<o.length;r++){const a=o[r],l=j(a,r,n);if(l===e)return[l];const f=a[s];if(Array.isArray(f)&&f.length>0){const p=be(f,e,t,l,i+1);if(p)return[l,...p]}}return null}function lt(o,e,t,n){const i=be(o,e,t);if(!i)return n;const s=new Set(n);for(let r=0;r<i.length-1;r++)s.add(i[r]);return s}function me(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 at(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 ct extends V{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??at(e)??"children";return me(e,t)}processRows(e){const t=this.config.childrenField??"children";if(!me(e,t))return this.flattenedRows=[],this.rowKeyMap.clear(),[...e];this.config.defaultExpanded&&!this.initialExpansionDone&&(this.expandedKeys=X(e,this.config),this.initialExpansionDone=!0),this.flattenedRows=ge(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 s={...i[0]},r=s.viewRenderer;if(r?.__treeWrapped)return i;const a=l=>{const{value:f,row:p,column:g}=l,h=p.__treeDepth??0,c=p.__treeHasChildren??!1,u=p.__treeExpanded??!1,d=document.createElement("span");if(d.style.display="flex",d.style.alignItems="center",d.style.paddingLeft=`${h*t}px`,c&&n){const m=document.createElement("span");m.className="tree-toggle",this.setIcon(m,this.resolveIcon(u?"collapse":"expand")),m.style.cursor="pointer",m.style.marginRight="4px",m.style.fontSize="10px",m.setAttribute("data-tree-key",p.__treeKey),d.appendChild(m)}else if(n){const m=document.createElement("span");m.style.width="14px",m.style.display="inline-block",d.appendChild(m)}const b=document.createElement("span");if(r){const m=r(l);m instanceof Node?b.appendChild(m):b.textContent=String(m??f??"")}else b.textContent=String(f??"");return d.appendChild(b),d};a.__treeWrapped=!0,s.viewRenderer=a,i[0]=s}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=we(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=we(this.expandedKeys,e),this.requestRender()}expandAll(){this.expandedKeys=X(this.rows,this.config),this.requestRender()}collapseAll(){this.expandedKeys=rt(),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=lt(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 R={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"},D={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"},dt={ROOT:`.${R.ROOT}`,HEADER:`.${R.HEADER}`,HEADER_ROW:`.${R.HEADER_ROW}`,HEADER_CELL:`.${R.HEADER_CELL}`,ROWS_VIEWPORT:`.${R.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${R.ROWS_CONTAINER}`,DATA_ROW:`.${R.DATA_ROW}`,DATA_CELL:`.${R.DATA_CELL}`,GROUP_ROW:`.${R.GROUP_ROW}`,ROW_BY_INDEX:o=>`.${R.DATA_ROW}[${D.ROW_INDEX}="${o}"]`,CELL_BY_FIELD:o=>`.${R.DATA_CELL}[${D.FIELD}="${o}"]`,CELL_AT:(o,e)=>`.${R.DATA_ROW}[${D.ROW_INDEX}="${o}"] .${R.DATA_CELL}[${D.COL_INDEX}="${e}"]`,SELECTED_ROWS:`.${R.DATA_ROW}.${R.SELECTED}`,EDITING_CELL:`.${R.DATA_CELL}.${R.EDITING}`},ht={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"},ut={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"},ft={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"},Y={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]},z=new Map,x={register(o,e){z.set(o,e)},unregister(o){z.delete(o)},get(o){if(o!==void 0)return typeof o=="function"?o:z.get(o)??Y[o]},run(o,e,t,n){const i=this.get(o);return i?i(e,t,n):void 0},has(o){return z.has(o)||o in Y},list(){return[...Object.keys(Y),...z.keys()]}},pt=x.register.bind(x),gt=x.unregister.bind(x),wt=x.get.bind(x),bt=x.run.bind(x),mt=x.list.bind(x);C.BaseGridPlugin=V,C.DEFAULT_GRID_ICONS=$,C.DGEvents=ut,C.DataGridElement=O,C.FitModeEnum=k,C.GridCSSVars=ht,C.GridClasses=R,C.GridDataAttrs=D,C.GridElement=O,C.GridSelectors=dt,C.PluginEvents=ft,C.PluginManager=ue,C.SelectionPlugin=st,C.TreePlugin=ct,C.aggregatorRegistry=x,C.getAggregator=wt,C.listAggregators=mt,C.registerAggregator=pt,C.runAggregator=bt,C.unregisterAggregator=gt,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})}));
73
+ `}#ue(){Je(this.#n,this.#o?.shell,this.#e,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e),onToolbarButtonClick:e=>this.#fe(e)}),this.#T?.(),this.#T=Qe(this.#n,this.#o?.shell,e=>{this.style.setProperty("--tbw-tool-panel-width",`${e}px`)})}#fe(e){const n=(this.#o?.shell?.header?.toolbarButtons??[]).find(i=>i.id===e);if(n?.action){n.action();return}const s=this.#e.toolbarButtons.get(e);s?.action&&s.action()}}customElements.get(D.tagName)||customElements.define(D.tagName,D);class U{version="1.0.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}attach(e){this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}requestRender(){this.grid?.requestRender?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?.visibleColumns??[]}get shadowRoot(){return this.grid?.shadowRoot??null}get disconnectSignal(){return this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...S,...e}}resolveIcon(e,t){return t!==void 0?t:this.gridIcons[e]}setIcon(e,t){typeof t=="string"?e.innerHTML=t:t instanceof HTMLElement&&(e.innerHTML="",e.appendChild(t.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}function $(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 st(o){const e=$(o);return{from:{row:e.startRow,col:e.startCol},to:{row:e.endRow,col:e.endCol}}}function X(o){return o.map(st)}function it(o,e,t){const n=$(t);return o>=n.startRow&&o<=n.endRow&&e>=n.startCol&&e<=n.endCol}function pe(o,e,t){return t.some(n=>it(o,e,n))}function rt(o){const e=[],t=$(o);for(let n=t.startRow;n<=t.endRow;n++)for(let s=t.startCol;s<=t.endCol;s++)e.push({row:n,col:s});return e}function lt(o){const e=new Map;for(const t of o)for(const n of rt(t))e.set(`${n.row},${n.col}`,n);return[...e.values()]}function ge(o,e){return{startRow:o.row,startCol:o.col,endRow:e.row,endCol:e.col}}const at=':host .selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}:host .data-grid-row.row-focus{background-color:var(--tbw-focus-background, rgba(from var(--tbw-color-accent) r g b / 12%))}:host([data-selection-mode="row"]) .cell-focus{outline:none}:host .data-grid-row>.cell.selected{background-color:var(--tbw-range-selection-bg)}:host .data-grid-row>.cell.selected.top{border-top:2px solid var(--tbw-range-border-color)}:host .data-grid-row>.cell.selected.bottom{border-bottom:2px solid var(--tbw-range-border-color)}:host .data-grid-row>.cell.selected.first{border-left:2px solid var(--tbw-range-border-color)}:host .data-grid-row>.cell.selected.last{border-right:2px solid var(--tbw-range-border-color)}';function ct(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(s=>({from:{row:s,col:0},to:{row:s,col:t-1}}));return{mode:o,ranges:n}}return o==="range"&&e.ranges.length>0?{mode:o,ranges:X(e.ranges)}:{mode:o,ranges:[]}}class dt extends U{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:s}=e,{mode:i}=this.config;if(i==="cell")return this.selectedCell={row:t,col:n},this.emit("selection-change",this.#i()),this.requestAfterRender(),!1;if(i==="row")return this.selected.clear(),this.selected.add(t),this.lastSelected=t,this.emit("selection-change",this.#i()),this.requestAfterRender(),!1;if(i==="range"){const r=s.shiftKey,a=s.ctrlKey||s.metaKey;if(r&&this.cellAnchor){const l=ge(this.cellAnchor,{row:t,col:n});a?this.ranges.length>0?this.ranges[this.ranges.length-1]=l:this.ranges.push(l):this.ranges=[l],this.activeRange=l}else if(a){const l={startRow:t,startCol:n,endRow:t,endCol:n};this.ranges.push(l),this.activeRange=l,this.cellAnchor={row:t,col:n}}else{const l={startRow:t,startCol:n,endRow:t,endCol:n};this.ranges=[l],this.activeRange=l,this.cellAnchor={row:t,col:n}}return this.emit("selection-change",this.#i()),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.#i()),this.requestAfterRender(),!0;if(t==="range"&&e.key==="a"&&(e.ctrlKey||e.metaKey)){const n=this.rows.length,s=this.columns.length;if(n>0&&s>0){const i={startRow:0,startCol:0,endRow:n-1,endCol:s-1};return this.ranges=[i],this.activeRange=i,this.emit("selection-change",this.#i()),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 i={startRow:t,startCol:n,endRow:t,endCol:n};return this.ranges.push(i),this.activeRange=i,this.emit("selection-change",this.#i()),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=ge(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.#i()),this.requestAfterRender(),!0}onCellMouseUp(e){if(this.config.mode==="range"&&this.isDragging)return this.isDragging=!1,!0}#n(){const e=this.shadowRoot;if(!e)return;const{mode:t}=this.config;e.querySelectorAll(".cell").forEach(i=>{i.classList.remove("selected","top","bottom","first","last")});const s=e.querySelectorAll(".data-grid-row");if(s.forEach(i=>{i.classList.remove("selected","row-focus")}),t==="row"&&s.forEach(i=>{const r=i.querySelector(".cell[data-row]"),a=parseInt(r?.getAttribute("data-row")??"-1",10);a>=0&&this.selected.has(a)&&(i.classList.add("selected","row-focus"),i.querySelectorAll(".cell-focus").forEach(l=>l.classList.remove("cell-focus")))}),t==="range"&&this.ranges.length>0){const i=this.activeRange?$(this.activeRange):null;e.querySelectorAll(".cell[data-row][data-col]").forEach(a=>{const l=parseInt(a.getAttribute("data-row")??"-1",10),d=parseInt(a.getAttribute("data-col")??"-1",10);l>=0&&d>=0&&pe(l,d,this.ranges)&&(a.classList.add("selected"),a.classList.remove("cell-focus"),i&&(l===i.startRow&&a.classList.add("top"),l===i.endRow&&a.classList.add("bottom"),d===i.startCol&&a.classList.add("first"),d===i.endCol&&a.classList.add("last")))})}t==="cell"&&this.selectedCell&&e.querySelectorAll(".cell-focus").forEach(i=>i.classList.remove("cell-focus"))}afterRender(){const e=this.shadowRoot;if(!e)return;const t=e.children[0],{mode:n}=this.config;this.grid.setAttribute("data-selection-mode",n),t&&t.classList.toggle("selecting",this.isDragging),this.#n()}onScrollRender(){this.#n()}getSelectedCell(){return this.selectedCell}getSelectedRows(){return[...this.selected]}getRanges(){return X(this.ranges)}getSelectedCells(){return lt(this.ranges)}isCellSelected(e,t){return pe(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:X(this.ranges)}),this.requestAfterRender()}#i(){return ct(this.config.mode,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges},this.columns.length)}styles=at}function j(o,e,t){return o.id!==void 0?String(o.id):t?`${t}-${e}`:String(e)}function be(o,e,t,n=null,s=0){const i=e.childrenField??"children",r=[];for(let a=0;a<o.length;a++){const l=o[a],d=j(l,a,n),u=l[i],g=Array.isArray(u)&&u.length>0,h=t.has(d);if(r.push({key:d,data:l,depth:s,hasChildren:g,isExpanded:h,parentKey:n}),g&&h){const c=be(u,e,t,d,s+1);r.push(...c)}}return r}function we(o,e){const t=new Set(o);return t.has(e)?t.delete(e):t.add(e),t}function Y(o,e,t=null,n=0){const s=e.childrenField??"children",i=new Set;for(let r=0;r<o.length;r++){const a=o[r],l=j(a,r,t),d=a[s];if(Array.isArray(d)&&d.length>0){i.add(l);const u=Y(d,e,l,n+1);for(const g of u)i.add(g)}}return i}function ht(){return new Set}function me(o,e,t,n=null,s=0){const i=t.childrenField??"children";for(let r=0;r<o.length;r++){const a=o[r],l=j(a,r,n);if(l===e)return[l];const d=a[i];if(Array.isArray(d)&&d.length>0){const u=me(d,e,t,l,s+1);if(u)return[l,...u]}}return null}function ut(o,e,t,n){const s=me(o,e,t);if(!s)return n;const i=new Set(n);for(let r=0;r<s.length-1;r++)i.add(s[r]);return i}function ve(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 ft(o){if(!Array.isArray(o)||o.length===0)return null;const e=["children","items","nodes","subRows","nested"];for(const t of o)if(!(!t||typeof t!="object")){for(const n of e)if(Array.isArray(t[n])&&t[n].length>0)return n}return null}const pt=".tree-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;transition:transform .2s}.tree-toggle:hover{color:var(--tbw-tree-accent, var(--tbw-color-accent))}";class gt extends U{name="tree";version="1.0.0";get defaultConfig(){return{childrenField:"children",autoDetect:!0,defaultExpanded:!1,indentWidth:20,showExpandIcons:!0}}expandedKeys=new Set;initialExpansionDone=!1;flattenedRows=[];rowKeyMap=new Map;detach(){this.expandedKeys.clear(),this.initialExpansionDone=!1,this.flattenedRows=[],this.rowKeyMap.clear()}detect(e){if(!this.config.autoDetect)return!1;const t=this.config.childrenField??ft(e)??"children";return ve(e,t)}processRows(e){const t=this.config.childrenField??"children";if(!ve(e,t))return this.flattenedRows=[],this.rowKeyMap.clear(),[...e];this.config.defaultExpanded&&!this.initialExpansionDone&&(this.expandedKeys=Y(e,this.config),this.initialExpansionDone=!0),this.flattenedRows=be(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,s=[...e];if(s.length>0){const i={...s[0]},r=i.viewRenderer;if(r?.__treeWrapped)return s;const a=l=>{const{value:d,row:u,column:g}=l,h=u.__treeDepth??0,c=u.__treeHasChildren??!1,f=u.__treeExpanded??!1,p=document.createElement("span");if(p.style.display="flex",p.style.alignItems="center",p.style.paddingLeft=`${h*t}px`,c&&n){const m=document.createElement("span");m.className="tree-toggle",this.setIcon(m,this.resolveIcon(f?"collapse":"expand")),m.style.cursor="pointer",m.style.marginRight="4px",m.style.fontSize="10px",m.setAttribute("data-tree-key",u.__treeKey),p.appendChild(m)}else if(n){const m=document.createElement("span");m.style.width="14px",m.style.display="inline-block",p.appendChild(m)}const b=document.createElement("span");if(r){const m=r(l);m instanceof Node?b.appendChild(m):b.textContent=String(m??d??"")}else b.textContent=String(d??"");return p.appendChild(b),p};a.__treeWrapped=!0,i.viewRenderer=a,s[0]=i}return s}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 s=this.rowKeyMap.get(n);return s?(this.expandedKeys=we(this.expandedKeys,n),this.emit("tree-expand",{key:n,row:s.data,expanded:this.expandedKeys.has(n),depth:s.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=we(this.expandedKeys,e),this.requestRender()}expandAll(){this.expandedKeys=Y(this.rows,this.config),this.requestRender()}collapseAll(){this.expandedKeys=ht(),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=ut(this.rows,e,this.config,this.expandedKeys),this.requestRender()}styles=pt}const R={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"},N={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"},bt={ROOT:`.${R.ROOT}`,HEADER:`.${R.HEADER}`,HEADER_ROW:`.${R.HEADER_ROW}`,HEADER_CELL:`.${R.HEADER_CELL}`,ROWS_VIEWPORT:`.${R.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${R.ROWS_CONTAINER}`,DATA_ROW:`.${R.DATA_ROW}`,DATA_CELL:`.${R.DATA_CELL}`,GROUP_ROW:`.${R.GROUP_ROW}`,ROW_BY_INDEX:o=>`.${R.DATA_ROW}[${N.ROW_INDEX}="${o}"]`,CELL_BY_FIELD:o=>`.${R.DATA_CELL}[${N.FIELD}="${o}"]`,CELL_AT:(o,e)=>`.${R.DATA_ROW}[${N.ROW_INDEX}="${o}"] .${R.DATA_CELL}[${N.COL_INDEX}="${e}"]`,SELECTED_ROWS:`.${R.DATA_ROW}.${R.SELECTED}`,EDITING_CELL:`.${R.DATA_CELL}.${R.EDITING}`},wt={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"},mt={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"},vt={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"},Z={sum:(o,e)=>o.reduce((t,n)=>t+(Number(n[e])||0),0),avg:(o,e)=>{const t=o.reduce((n,s)=>n+(Number(s[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]},q=new Map,T={register(o,e){q.set(o,e)},unregister(o){q.delete(o)},get(o){if(o!==void 0)return typeof o=="function"?o:q.get(o)??Z[o]},run(o,e,t,n){const s=this.get(o);return s?s(e,t,n):void 0},has(o){return q.has(o)||o in Z},list(){return[...Object.keys(Z),...q.keys()]}},ye={sum:o=>o.reduce((e,t)=>e+t,0),avg:o=>o.length?o.reduce((e,t)=>e+t,0)/o.length:0,count:o=>o.length,min:o=>o.length?Math.min(...o):0,max:o=>o.length?Math.max(...o):0,first:o=>o[0]??0,last:o=>o[o.length-1]??0};function Ce(o){return ye[o]??ye.sum}function yt(o,e){return Ce(o)(e)}const Ct=T.register.bind(T),Et=T.unregister.bind(T),Rt=T.get.bind(T),_t=T.run.bind(T),St=T.list.bind(T);y.BaseGridPlugin=U,y.DEFAULT_GRID_ICONS=S,y.DGEvents=mt,y.DataGridElement=D,y.FitModeEnum=P,y.GridCSSVars=wt,y.GridClasses=R,y.GridDataAttrs=N,y.GridElement=D,y.GridSelectors=bt,y.PluginEvents=vt,y.PluginManager=fe,y.SelectionPlugin=dt,y.TreePlugin=gt,y.aggregatorRegistry=T,y.getAggregator=Rt,y.getValueAggregator=Ce,y.listAggregators=St,y.registerAggregator=Ct,y.runAggregator=_t,y.runValueAggregator=yt,y.unregisterAggregator=Et,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})}));
105
74
  //# sourceMappingURL=grid.umd.js.map