@toolbox-web/grid 0.2.1 → 0.2.2

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 (67) hide show
  1. package/README.md +50 -59
  2. package/all.d.ts +1 -47
  3. package/all.js +195 -239
  4. package/all.js.map +1 -1
  5. package/index.d.ts +1 -47
  6. package/index.js +129 -118
  7. package/index.js.map +1 -1
  8. package/lib/plugins/clipboard/index.js +11 -5
  9. package/lib/plugins/clipboard/index.js.map +1 -1
  10. package/lib/plugins/column-virtualization/index.js +9 -4
  11. package/lib/plugins/column-virtualization/index.js.map +1 -1
  12. package/lib/plugins/context-menu/index.js +11 -5
  13. package/lib/plugins/context-menu/index.js.map +1 -1
  14. package/lib/plugins/export/index.js +7 -3
  15. package/lib/plugins/export/index.js.map +1 -1
  16. package/lib/plugins/filtering/index.js +16 -149
  17. package/lib/plugins/filtering/index.js.map +1 -1
  18. package/lib/plugins/grouping-columns/index.js +13 -6
  19. package/lib/plugins/grouping-columns/index.js.map +1 -1
  20. package/lib/plugins/grouping-rows/index.js +13 -6
  21. package/lib/plugins/grouping-rows/index.js.map +1 -1
  22. package/lib/plugins/master-detail/index.js +11 -5
  23. package/lib/plugins/master-detail/index.js.map +1 -1
  24. package/lib/plugins/multi-sort/index.js +13 -6
  25. package/lib/plugins/multi-sort/index.js.map +1 -1
  26. package/lib/plugins/pinned-columns/index.js +11 -5
  27. package/lib/plugins/pinned-columns/index.js.map +1 -1
  28. package/lib/plugins/pinned-rows/index.js +13 -6
  29. package/lib/plugins/pinned-rows/index.js.map +1 -1
  30. package/lib/plugins/pivot/index.js +19 -9
  31. package/lib/plugins/pivot/index.js.map +1 -1
  32. package/lib/plugins/reorder/index.js +11 -5
  33. package/lib/plugins/reorder/index.js.map +1 -1
  34. package/lib/plugins/selection/index.js +13 -6
  35. package/lib/plugins/selection/index.js.map +1 -1
  36. package/lib/plugins/server-side/index.js +11 -5
  37. package/lib/plugins/server-side/index.js.map +1 -1
  38. package/lib/plugins/tree/index.js +15 -7
  39. package/lib/plugins/tree/index.js.map +1 -1
  40. package/lib/plugins/undo-redo/index.js +3 -1
  41. package/lib/plugins/undo-redo/index.js.map +1 -1
  42. package/lib/plugins/visibility/index.js +13 -6
  43. package/lib/plugins/visibility/index.js.map +1 -1
  44. package/package.json +1 -1
  45. package/umd/grid.all.umd.js +15 -156
  46. package/umd/grid.all.umd.js.map +1 -1
  47. package/umd/grid.umd.js +6 -6
  48. package/umd/grid.umd.js.map +1 -1
  49. package/umd/plugins/clipboard.umd.js.map +1 -1
  50. package/umd/plugins/column-virtualization.umd.js.map +1 -1
  51. package/umd/plugins/context-menu.umd.js.map +1 -1
  52. package/umd/plugins/export.umd.js.map +1 -1
  53. package/umd/plugins/filtering.umd.js +1 -142
  54. package/umd/plugins/filtering.umd.js.map +1 -1
  55. package/umd/plugins/grouping-columns.umd.js.map +1 -1
  56. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  57. package/umd/plugins/master-detail.umd.js.map +1 -1
  58. package/umd/plugins/multi-sort.umd.js.map +1 -1
  59. package/umd/plugins/pinned-columns.umd.js.map +1 -1
  60. package/umd/plugins/pinned-rows.umd.js.map +1 -1
  61. package/umd/plugins/pivot.umd.js.map +1 -1
  62. package/umd/plugins/reorder.umd.js.map +1 -1
  63. package/umd/plugins/selection.umd.js.map +1 -1
  64. package/umd/plugins/server-side.umd.js.map +1 -1
  65. package/umd/plugins/tree.umd.js.map +1 -1
  66. package/umd/plugins/undo-redo.umd.js.map +1 -1
  67. package/umd/plugins/visibility.umd.js.map +1 -1
package/umd/grid.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(y,q){typeof exports=="object"&&typeof module<"u"?q(exports):typeof define=="function"&&define.amd?define(["exports"],q):(y=typeof globalThis<"u"?globalThis:y||self,q(y.TbwGrid={}))})(this,(function(y){"use strict";const q=":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.selected:focus-visible,:host .data-grid-row>.cell:focus-visible:not(.cell-focus){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 pe(t){const e=new Map;return t.sortState&&e.set(t.sortState.field,{direction:t.sortState.direction===1?"asc":"desc",priority:0}),e}function J(t,e){const o=t._columns,n=pe(t);return{columns:o.map((i,s)=>{const r={field:i.field,order:s,visible:!0},l=i;l.__renderedWidth!==void 0?r.width=l.__renderedWidth:i.width!==void 0&&(r.width=typeof i.width=="string"?parseFloat(i.width):i.width);const a=n.get(i.field);a&&(r.sort=a);for(const d of e)if(d.getColumnState){const h=d.getColumnState(i.field);h&&Object.assign(r,h)}return r})}}function be(t,e,o,n){if(!e.columns||e.columns.length===0)return;const i=new Map(e.columns.map(l=>[l.field,l])),s=o.map(l=>{const a=i.get(l.field);if(!a)return l;const d={...l};return a.width!==void 0&&(d.width=a.width,d.__renderedWidth=a.width),a.visible!==void 0&&(d.hidden=!a.visible),d});s.sort((l,a)=>{const d=i.get(l.field)?.order??1/0,h=i.get(a.field)?.order??1/0;return d-h}),t._columns=s;const r=e.columns.filter(l=>l.sort!==void 0).sort((l,a)=>(l.sort?.priority??0)-(a.sort?.priority??0));if(r.length>0){const l=r[0];l.sort&&(t.sortState={field:l.field,direction:l.sort.direction==="asc"?1:-1})}else t.sortState=null;for(const l of n)if(l.applyColumnState)for(const a of e.columns)l.applyColumnState(a.field,a)}function we(t,e,o){let n=null;return()=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{n=null;const i=J(t,e());o(i)},100)}}const D={STRETCH:"stretch",FIXED:"fixed"},P={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰"};function ge(t){return t==null?"string":typeof t=="number"?"number":typeof t=="boolean"?"boolean":t instanceof Date||typeof t=="string"&&/\d{4}-\d{2}-\d{2}/.test(t)&&!isNaN(Date.parse(t))?"date":"string"}function Q(t,e){if(e&&e.length){const s={};return e.forEach(r=>{r.type&&(s[r.field]=r.type)}),{columns:e,typeMap:s}}const o=t[0]||{},n=Object.keys(o).map(s=>{const r=o[s],l=ge(r);return{field:s,header:s.charAt(0).toUpperCase()+s.slice(1),type:l}}),i={};return n.forEach(s=>{i[s.field]=s.type||"string"}),{columns:n,typeMap:i}}const me=/{{\s*([^}]+)\s*}}/g,O="__DG_EMPTY__",ve=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,Ee=/__(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/,Ce=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,ye=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),_e=/^\s*(javascript|vbscript|data|blob):/i;function F(t){if(!t||typeof t!="string")return"";if(t.indexOf("<")===-1)return t;const e=document.createElement("template");return e.innerHTML=t,Re(e.content),e.innerHTML}function Re(t){const e=[],o=t.querySelectorAll("*");for(const n of o){const i=n.tagName.toLowerCase();if(Ce.has(i)){e.push(n);continue}if((i==="svg"||n.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(n.attributes).some(l=>ee.test(l.name)||l.name==="href"||l.name==="xlink:href")){e.push(n);continue}const s=[];for(const r of n.attributes){const l=r.name.toLowerCase();if(ee.test(l)){s.push(r.name);continue}if(ye.has(l)&&_e.test(r.value)){s.push(r.name);continue}if(l==="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 te(t,e){if(!t||t.indexOf("{{")===-1)return t;const o=[],n=t.replace(me,(l,a)=>{const d=Se(a,e);return o.push({expr:a.trim(),result:d}),d}),i=Ae(n),s=o.length&&o.every(l=>l.result===""||l.result===O);return/Reflect\.|\bProxy\b|ownKeys\(/.test(t)||s?"":i}function Se(t,e){if(t=(t||"").trim(),!t||/\b(Reflect|Proxy|ownKeys)\b/.test(t))return O;if(t==="value")return e.value==null?O:String(e.value);if(t.startsWith("row.")&&!/[()?]/.test(t)&&!t.includes(":")){const n=t.slice(4),i=e.row?e.row[n]:void 0;return i==null?O:String(i)}if(t.length>80||!ve.test(t)||Ee.test(t))return O;const o=t.match(/\./g);if(o&&o.length>1)return O;try{const i=new Function("value","row",`return (${t});`)(e.value,e.row),s=i==null?"":String(i);return/Reflect|Proxy|ownKeys/.test(s)?O:s||O}catch{return O}}function Ae(t){return t&&t.replace(new RegExp(O,"g"),"").replace(/Reflect\.[^<>{}\s]+/g,"").replace(/\bProxy\b/g,"").replace(/ownKeys\([^)]*\)/g,"")}function xe(t){if(/Reflect|Proxy|ownKeys/.test(t.textContent||"")){if(Array.from(t.childNodes).forEach(e=>{e.nodeType===Node.TEXT_NODE&&/Reflect|Proxy|ownKeys/.test(e.textContent||"")&&(e.textContent="")}),/Reflect|Proxy|ownKeys/.test(t.textContent||"")){if(/Reflect|Proxy|ownKeys/.test(t.textContent||""))for(;t.firstChild;)t.removeChild(t.firstChild);t.textContent=(t.textContent||"").replace(/Reflect|Proxy|ownKeys/g,"")}(t.textContent||"").trim().length===0&&(t.textContent="")}}function oe(t){const e=/Reflect\.|\bProxy\b|ownKeys\(/.test(t),o=n=>e?"":te(t,n);return o.__blocked=e,o}function Te(t){return Array.from(t.querySelectorAll("tbw-grid-column")).map(o=>{const n=o.getAttribute("field")||"";if(!n)return null;const i=o.getAttribute("type")||void 0,r=i&&new Set(["number","string","date","boolean","select","typeahead"]).has(i)?i:void 0,l=o.getAttribute("header")||void 0,a=o.hasAttribute("sortable"),d=o.hasAttribute("editable"),h={field:n,type:r,header:l,sortable:a,editable:d};o.hasAttribute("resizable")&&(h.resizable=!0),o.hasAttribute("sizable")&&(h.resizable=!0);const p=o.getAttribute("options");p&&(h.options=p.split(",").map(f=>{const[w,v]=f.includes(":")?f.split(":"):[f.trim(),f.trim()];return{value:w.trim(),label:v?.trim()||w.trim()}}));const b=o.querySelector("tbw-grid-column-view"),c=o.querySelector("tbw-grid-column-editor"),u=o.querySelector("tbw-grid-column-header");return b&&(h.__viewTemplate=b),c&&(h.__editorTemplate=c),u&&(h.__headerTemplate=u),h}).filter(o=>!!o)}function Le(t,e){if((!t||!t.length)&&(!e||!e.length))return[];if(!t||!t.length)return e||[];if(!e||!e.length)return t;const o={};e.forEach(i=>o[i.field]=i);const n=t.map(i=>{const s=o[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 o[i.field],r});return Object.keys(o).forEach(i=>n.push(o[i])),n}function U(t,e){try{t.part?.add?.(e)}catch{}const o=t.getAttribute("part");o?o.split(/\s+/).includes(e)||t.setAttribute("part",o+" "+e):t.setAttribute("part",e)}function ke(t){t.__lightDomColumnsCache||(t.__originalColumnNodes=Array.from(t.querySelectorAll("tbw-grid-column")),t.__lightDomColumnsCache=t.__originalColumnNodes.length?Te(t):[]);const e=t.__lightDomColumnsCache,o=Le(t._columns,e);o.forEach(i=>{i.__viewTemplate&&!i.__compiledView&&(i.__compiledView=oe(i.__viewTemplate.innerHTML)),i.__editorTemplate&&!i.__compiledEditor&&(i.__compiledEditor=oe(i.__editorTemplate.innerHTML))});const{columns:n}=Q(t._rows,o);t._columns=n}function Pe(t){const e=t.effectiveConfig?.fitMode||t.fitMode||D.STRETCH;if(e!==D.STRETCH&&e!==D.FIXED||t.__didInitialAutoSize||!t.isConnected)return;const o=t.headerRowEl?.children||[];if(!o.length)return;let n=!1;t.visibleColumns.forEach((i,s)=>{if(i.width)return;const r=o[s];let l=r?r.scrollWidth:0;for(const a of t.rowPool){const d=a.children[s];if(d){const h=d.scrollWidth;h>l&&(l=h)}}l>0&&(i.width=l+2,i.__autoSized=!0,n=!0)}),n&&ne(t),t.__didInitialAutoSize=!0}function ne(t){(t.effectiveConfig?.fitMode||t.fitMode||D.STRETCH)===D.STRETCH?t.gridTemplate=t.visibleColumns.map(o=>{if(o.width)return`${o.width}px`;const n=o.minWidth;return n!=null?`minmax(${n}px, 1fr)`:"1fr"}).join(" ").trim():t.gridTemplate=t.visibleColumns.map(o=>o.width?`${o.width}px`:"max-content").join(" "),t.style.setProperty("--tbw-column-template",t.gridTemplate)}function Oe(t){switch(t.type){case"number":return e=>{const o=document.createElement("input");return o.type="number",o.value=e.value??"",o.addEventListener("blur",()=>e.commit(o.value===""?null:Number(o.value))),o.addEventListener("keydown",n=>{n.key==="Enter"&&e.commit(o.value===""?null:Number(o.value)),n.key==="Escape"&&e.cancel()}),o.focus(),o};case"boolean":return e=>{const o=document.createElement("input");return o.type="checkbox",o.checked=!!e.value,o.addEventListener("change",()=>e.commit(o.checked)),o.focus(),o};case"date":return e=>{const o=document.createElement("input");return o.type="date",e.value instanceof Date&&(o.valueAsDate=e.value),o.addEventListener("change",()=>e.commit(o.valueAsDate)),o.addEventListener("keydown",n=>{n.key==="Escape"&&e.cancel()}),o.focus(),o};case"select":case"typeahead":return e=>{const o=document.createElement("select");e.column.multi&&(o.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),o.appendChild(r)});const i=()=>{if(e.column.multi){const s=[];Array.from(o.selectedOptions).forEach(r=>{s.push(r.value)}),e.commit(s)}else e.commit(o.value)};return o.addEventListener("change",i),o.addEventListener("blur",i),o.addEventListener("keydown",s=>{s.key==="Escape"&&e.cancel()}),o.focus(),o};default:return e=>{const o=document.createElement("input");return o.type="text",o.value=e.value??"",o.addEventListener("blur",()=>e.commit(o.value)),o.addEventListener("keydown",n=>{n.key==="Enter"&&e.commit(o.value),n.key==="Escape"&&e.cancel()}),o.focus(),o}}}function He(t,e){if(t.dispatchKeyDown?.(e))return;const o=t._rows.length-1,n=t.visibleColumns.length-1,i=t.activeEditRows!==void 0&&t.activeEditRows!==-1,r=t.visibleColumns[t.focusCol]?.type,l=e.composedPath?e.composedPath():[],a=l&&l.length?l[0]:e.target,d=h=>{if(!h)return!1;const p=h.tagName;return!!(p==="INPUT"||p==="SELECT"||p==="TEXTAREA"||h.isContentEditable)};if(!(d(a)&&(e.key==="Home"||e.key==="End"))&&!(d(a)&&(e.key==="ArrowUp"||e.key==="ArrowDown")&&a.tagName==="INPUT"&&a.type==="number")&&!(d(a)&&(e.key==="ArrowLeft"||e.key==="ArrowRight"))&&!(d(a)&&(e.key==="Enter"||e.key==="Escape"))&&!(i&&(r==="select"||r==="typeahead")&&(e.key==="ArrowDown"||e.key==="ArrowUp"))){switch(e.key){case"Tab":{e.preventDefault(),!e.shiftKey?t.focusCol<n?t.focusCol+=1:(typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t.focusRow<o&&(t.focusRow+=1,t.focusCol=0)):t.focusCol>0?t.focusCol-=1:t.focusRow>0&&(typeof t.commitActiveRowEdit=="function"&&t.activeEditRows===t.focusRow&&t.commitActiveRowEdit(),t.focusRow-=1,t.focusCol=n),I(t);return}case"ArrowDown":i&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t.focusRow=Math.min(o,t.focusRow+1),e.preventDefault();break;case"ArrowUp":i&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t.focusRow=Math.max(0,t.focusRow-1),e.preventDefault();break;case"ArrowRight":t.focusCol=Math.min(n,t.focusCol+1),e.preventDefault();break;case"ArrowLeft":t.focusCol=Math.max(0,t.focusCol-1),e.preventDefault();break;case"Home":t.focusCol=0,e.preventDefault();break;case"End":t.focusCol=n,e.preventDefault();break;case"PageDown":t.focusRow=Math.min(o,t.focusRow+20),e.preventDefault();break;case"PageUp":t.focusRow=Math.max(0,t.focusRow-20),e.preventDefault();break;case"Enter":return typeof t.beginBulkEdit=="function"?t.beginBulkEdit(t.focusRow):t.dispatchEvent(new CustomEvent("activate-cell",{detail:{row:t.focusRow,col:t.focusCol}})),I(t);default:return}I(t)}}function I(t){if(t.virtualization?.enabled){const{rowHeight:s,container:r,viewportEl:l}=t.virtualization,a=r,d=l?.clientHeight??a?.clientHeight??0;if(a&&d>0){const h=t.focusRow*s;h<a.scrollTop?a.scrollTop=h:h+s>a.scrollTop+d&&(a.scrollTop=h-d+s)}}t.activeEditRows!==void 0&&t.activeEditRows!==-1||t.refreshVirtualWindow(!1),Array.from(t.bodyEl.querySelectorAll(".cell-focus")).forEach(s=>s.classList.remove("cell-focus")),Array.from(t.bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(s=>{s.setAttribute("aria-selected","false")});const o=t.focusRow,n=t.virtualization.start??0,i=t.virtualization.end??t._rows.length;if(o>=n&&o<i){const r=t.bodyEl.querySelectorAll(".data-grid-row")[o-n]?.children[t.focusCol];if(r){if(r.classList.add("cell-focus"),r.setAttribute("aria-selected","true"),t.activeEditRows!==void 0&&t.activeEditRows!==-1&&r.classList.contains("editing")){const l=r.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(l&&document.activeElement!==l)try{l.focus()}catch{}}else if(!r.contains(document.activeElement)){r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1");try{r.focus({preventScroll:!0})}catch{}}}}}const Me="__cellDisplayCache",De="__cellCacheEpoch";function X(t){t[Me]=void 0,t[De]=void 0,t.__hasSpecialColumns=void 0}function ze(t,e,o,n,i){const s=Math.max(0,o-e),r=t.bodyEl,l=t.visibleColumns,a=l.length;let d=t.__cachedHeaderRowCount;for(d===void 0&&(d=t.shadowRoot?.querySelector(".header-group-row")?2:1,t.__cachedHeaderRowCount=d);t.rowPool.length<s;){const p=document.createElement("div");p.className="data-grid-row",p.setAttribute("role","row"),p.addEventListener("click",b=>ie(t,b,p,!1)),p.addEventListener("dblclick",b=>ie(t,b,p,!0)),t.rowPool.push(p)}if(t.rowPool.length>s){for(let p=s;p<t.rowPool.length;p++){const b=t.rowPool[p];b.parentNode===r&&b.remove()}t.rowPool.length=s}const h=i&&t.__hasRenderRowPlugins!==!1;for(let p=0;p<s;p++){const b=e+p,c=t._rows[b],u=t.rowPool[p];if(u.setAttribute("aria-rowindex",String(b+d+1)),h&&i(c,u,b)){u.__epoch=n,u.__rowDataRef=c,u.parentNode!==r&&r.appendChild(u);continue}const f=u.__epoch,w=u.__rowDataRef,v=u.children.length,x=f===n&&v===a,S=w!==c;let L=!1;if(x&&S){for(let E=0;E<a;E++)if(l[E].externalView&&!u.querySelector(`.cell[data-col="${E}"] [data-external-view]`)){L=!0;break}}if(!x||L){const E=u.querySelector(".cell.editing"),_=t.activeEditRows===b;if(E&&!_)u.__isCustomRow&&(u.className="data-grid-row",u.setAttribute("role","row"),u.__isCustomRow=!1),z(t,u,c,b),u.__epoch=n,u.__rowDataRef=c;else if(E&&_)j(t,u,c,b),u.__rowDataRef=c;else if(u.__isCustomRow&&(u.className="data-grid-row",u.setAttribute("role","row"),u.__isCustomRow=!1),z(t,u,c,b),u.__epoch=n,u.__rowDataRef=c,_){const R=u.children;for(let C=0;C<R.length;C++){const k=t.visibleColumns[C];k&&k.editable&&M(t,c,b,k,R[C])}}}else if(S){const E=u.querySelector(".cell.editing"),_=t.activeEditRows===b;if(E&&!_)z(t,u,c,b),u.__epoch=n,u.__rowDataRef=c;else if(j(t,u,c,b),u.__rowDataRef=c,_&&!E){const R=u.children;for(let C=0;C<R.length;C++){const k=t.visibleColumns[C];k&&k.editable&&M(t,c,b,k,R[C])}}}else{const E=u.querySelector(".cell.editing"),_=t.activeEditRows===b;if(E&&!_)z(t,u,c,b),u.__epoch=n,u.__rowDataRef=c;else if(j(t,u,c,b),_&&!E){const R=u.children;for(let C=0;C<R.length;C++){const k=t.visibleColumns[C];k&&k.editable&&M(t,c,b,k,R[C])}}}const g=t._changedRowIndices.has(b),m=u.classList.contains("changed");g!==m&&u.classList.toggle("changed",g),u.parentNode!==r&&r.appendChild(u)}}function j(t,e,o,n){const i=e.children,s=t.visibleColumns,r=s.length,l=i.length,a=r<l?r:l,d=t.focusRow,h=t.focusCol;let p=t.__hasSpecialColumns;if(p===void 0){p=!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"){p=!0;break}}t.__hasSpecialColumns=p}const b=String(n);if(!p){for(let c=0;c<a;c++){const u=i[c],f=o[s[c].field];u.textContent=f==null?"":String(f),u.getAttribute("data-row")!==b&&u.setAttribute("data-row",b);const w=d===n&&h===c,v=u.classList.contains("cell-focus");w!==v&&(u.classList.toggle("cell-focus",w),u.setAttribute("aria-selected",String(w)))}return}for(let c=0;c<a;c++)if(s[c].externalView&&!i[c].querySelector("[data-external-view]")){z(t,e,o,n);return}for(let c=0;c<a;c++){const u=s[c],f=i[c];f.getAttribute("data-row")!==b&&f.setAttribute("data-row",b);const w=d===n&&h===c,v=f.classList.contains("cell-focus");if(w!==v&&(f.classList.toggle("cell-focus",w),f.setAttribute("aria-selected",String(w))),f.classList.contains("editing"))continue;if(u.viewRenderer){const S=o[u.field],L=u.viewRenderer({row:o,value:S,field:u.field,column:u});typeof L=="string"?f.innerHTML=F(L):L?(f.innerHTML="",f.appendChild(L)):f.textContent=S==null?"":String(S);continue}if(u.__viewTemplate||u.__compiledView||u.externalView)continue;const A=o[u.field];let x;if(u.format)try{const S=u.format(A,o);x=S==null?"":String(S)}catch{x=A==null?"":String(A)}else if(u.type==="date"){if(A==null||A==="")x="";else if(A instanceof Date)x=isNaN(A.getTime())?"":A.toLocaleDateString();else{const S=new Date(A);x=isNaN(S.getTime())?"":S.toLocaleDateString()}f.textContent=x}else if(u.type==="boolean"){const S=!!A;f.innerHTML=`<span role="checkbox" aria-checked="${S}" aria-label="${S}">${S?"&#x1F5F9;":"&#9744;"}</span>`}else x=A==null?"":String(A),f.textContent=x}}function z(t,e,o,n){e.innerHTML="";const i=t.visibleColumns,s=i.length,r=t.focusRow,l=t.focusCol,a=t.effectiveConfig?.editOn||t.editOn,d=t,h=document.createDocumentFragment();for(let p=0;p<s;p++){const b=i[p],c=document.createElement("div");c.className="cell",U(c,"cell"),c.setAttribute("role","gridcell"),c.setAttribute("aria-colindex",String(p+1)),c.setAttribute("data-col",String(p)),c.setAttribute("data-row",String(n)),b.type,b.type&&c.setAttribute("data-type",b.type);const u=b.sticky;u==="left"?c.classList.add("sticky-left"):u==="right"&&c.classList.add("sticky-right");let f=o[b.field];const w=b.format;if(w)try{f=w(f,o)}catch{}const v=b.__compiledView,A=b.__viewTemplate,x=b.viewRenderer,S=b.externalView;let L=!1;if(x){const g=x({row:o,value:f,field:b.field,column:b});typeof g=="string"?(c.innerHTML=F(g),L=!0):g?c.appendChild(g):c.textContent=f==null?"":String(f)}else if(S){const g=S,m=document.createElement("div");m.setAttribute("data-external-view",""),m.setAttribute("data-field",b.field),c.appendChild(m);const E={row:o,value:f,field:b.field,column:b};if(g.mount)try{g.mount({placeholder:m,context:E,spec:g})}catch{}else queueMicrotask(()=>{try{d.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:m,spec:g,context:E}}))}catch{}});m.setAttribute("data-mounted","")}else if(v){const g=v({row:o,value:f,field:b.field,column:b}),m=v.__blocked;c.innerHTML=m?"":F(g),L=!0,m&&(c.textContent="",c.setAttribute("data-blocked-template",""))}else if(A){const g=A.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(g)?(c.textContent="",c.setAttribute("data-blocked-template","")):(c.innerHTML=F(te(g,{row:o,value:f})),L=!0)}else if(b.type==="date")if(f==null||f==="")c.textContent="";else{let g=null;if(f instanceof Date)g=f;else if(typeof f=="number"||typeof f=="string"){const m=new Date(f);isNaN(m.getTime())||(g=m)}c.textContent=g?g.toLocaleDateString():""}else if(b.type==="boolean"){const g=!!f;c.innerHTML=`<span role="checkbox" aria-checked="${g}" aria-label="${g}">${g?"&#x1F5F9;":"&#9744;"}</span>`}else c.textContent=f==null?"":String(f);if(L){xe(c);const g=c.textContent||"";/Proxy|Reflect\.ownKeys/.test(g)&&(c.textContent=g.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=""),b.editable?(c.tabIndex=0,c.addEventListener("mousedown",()=>{if(c.classList.contains("editing"))return;const g=Number(c.getAttribute("data-row")),m=Number(c.getAttribute("data-col"));isNaN(g)||isNaN(m)||(t.focusRow=g,t.focusCol=m,I(t))}),a==="click"?c.addEventListener("click",g=>{if(c.classList.contains("editing"))return;g.stopPropagation();const m=Number(c.getAttribute("data-row")),E=Number(c.getAttribute("data-col"));if(isNaN(m)||isNaN(E))return;const _=t._rows[m],R=t.visibleColumns[E];!_||!R||(t.focusRow=m,t.focusCol=E,M(t,_,m,R,c))}):c.addEventListener("dblclick",g=>{g.stopPropagation();const m=Number(c.getAttribute("data-row"));if(isNaN(m))return;const E=t._rows[m];if(!E)return;N(t,m,E);const _=t.findRenderedRowElement?.(m);if(_){const R=_.children;for(let C=0;C<R.length;C++){const k=t.visibleColumns[C];k&&k.editable&&M(t,E,m,k,R[C])}}}),c.addEventListener("keydown",g=>{const m=Number(c.getAttribute("data-row")),E=Number(c.getAttribute("data-col"));if(isNaN(m)||isNaN(E))return;const _=t._rows[m],R=t.visibleColumns[E];if(!(!_||!R)){if((R.type==="select"||R.type==="typeahead")&&!c.classList.contains("editing")&&g.key==="Enter"){g.preventDefault(),t.activeEditRows!==m&&N(t,m,_),M(t,_,m,R,c),setTimeout(()=>{const C=c.querySelector("select");try{C?.showPicker?.()}catch{}C?.focus()},0);return}if(R.type==="boolean"&&g.key===" "&&!c.classList.contains("editing")){g.preventDefault(),t.activeEditRows!==m&&N(t,m,_);const C=!_[R.field];K(t,m,R,C,_),c.innerHTML=`<span role="checkbox" aria-checked="${C}" aria-label="${C}">${C?"&#x1F5F9;":"&#9744;"}</span>`;return}if(g.key==="Enter"&&!c.classList.contains("editing")){g.preventDefault(),g.stopPropagation(),t.focusRow=m,t.focusCol=E,typeof t.beginBulkEdit=="function"?t.beginBulkEdit(m):M(t,_,m,R,c);return}if(g.key==="F2"&&!c.classList.contains("editing")){g.preventDefault(),M(t,_,m,R,c);return}}})):b.type==="boolean"&&(c.hasAttribute("tabindex")||(c.tabIndex=0)),r===n&&l===p?c.setAttribute("aria-selected","true"):c.setAttribute("aria-selected","false"),h.appendChild(c)}e.appendChild(h)}function ie(t,e,o,n){if(e.target?.closest(".resize-handle"))return;const i=o.querySelector(".cell[data-row]");if(!i)return;const s=Number(i.getAttribute("data-row"));if(isNaN(s))return;const r=t._rows[s];if(!r)return;const l=e.target?.closest(".cell[data-col]");if(l){if(l.classList.contains("editing"))return;const d=Number(l.getAttribute("data-col"));if(!isNaN(d)){if(t.dispatchCellClick?.(e,s,d,l))return;t.focusRow=s,t.focusCol=d,I(t)}}if(o.querySelector(".cell.editing")){const d=o.querySelectorAll(".cell.editing");if(!n)return;d.forEach(h=>h.classList.remove("editing"))}const a=t.effectiveConfig?.editOn||t.editOn||"doubleClick";if(a==="click"||a==="doubleClick"&&n)N(t,s,r);else return;Array.from(o.children).forEach((d,h)=>{const p=t.visibleColumns[h];p&&p.editable&&M(t,r,s,p,d)}),l&&queueMicrotask(()=>{const d=o.querySelector(`.cell[data-col="${t.focusCol}"]`);if(d?.classList.contains("editing")){const h=d.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');try{h?.focus()}catch{}}})}function N(t,e,o){t.activeEditRows!==e&&(t.rowEditSnapshots.set(e,{...o}),t.activeEditRows=e)}function $(t,e,o){if(t.activeEditRows!==e)return;const n=t.rowEditSnapshots.get(e),i=t._rows[e],s=t.findRenderedRowElement?.(e);if(!o&&s&&i&&s.querySelectorAll(".cell.editing").forEach(l=>{const a=Number(l.getAttribute("data-col"));if(isNaN(a))return;const d=t.visibleColumns[a];if(!d)return;const h=l.querySelector("input,textarea,select");if(h){let p;h instanceof HTMLInputElement&&h.type==="checkbox"?p=h.checked:(p=h.value,d.type==="number"&&p!==""&&(p=Number(p))),i[d.field]!==p&&K(t,e,d,p,i)}}),o&&n&&i)Object.keys(n).forEach(r=>i[r]=n[r]),t._changedRowIndices.delete(e),X(t);else if(!o){const r=t._changedRowIndices.has(e);t.dispatchEvent(new CustomEvent("row-commit",{detail:{rowIndex:e,row:i,changed:r,changedRows:t.changedRows,changedRowIndices:t.changedRowIndices}}))}t.rowEditSnapshots.delete(e),t.activeEditRows=-1,s&&(z(t,s,t._rows[e],e),t._changedRowIndices.has(e)?s.classList.add("changed"):s.classList.remove("changed")),queueMicrotask(()=>{try{const r=t.focusRow,l=t.focusCol,a=t.findRenderedRowElement?.(r);if(a){Array.from(t.bodyEl.querySelectorAll(".cell-focus")).forEach(h=>h.classList.remove("cell-focus"));const d=a.querySelector(`.cell[data-row="${r}"][data-col="${l}"]`);d&&(d.classList.add("cell-focus"),d.setAttribute("aria-selected","true"),d.hasAttribute("tabindex")||d.setAttribute("tabindex","-1"),d.focus({preventScroll:!0}))}}catch{}})}function K(t,e,o,n,i){const s=o.field;if(i[s]===n)return;i[s]=n;const l=!t._changedRowIndices.has(e);t._changedRowIndices.add(e);const a=t.findRenderedRowElement?.(e);a&&a.classList.add("changed"),t.dispatchEvent(new CustomEvent("cell-commit",{detail:{row:i,field:s,value:n,rowIndex:e,changedRows:t.changedRows,changedRowIndices:t.changedRowIndices,firstTimeForRow:l}}))}function M(t,e,o,n,i){if(!n.editable||(t.activeEditRows!==o&&N(t,o,e),i.classList.contains("editing")))return;const s=e[n.field];i.classList.add("editing");let r=!1;const l=c=>{r||t.activeEditRows===-1||K(t,o,n,c,e)},a=()=>{r=!0,e[n.field]=s;const c=i.querySelector("input,textarea,select");c&&(typeof HTMLInputElement<"u"&&c instanceof HTMLInputElement&&c.type==="checkbox"?c.checked=!!s:"value"in c&&(c.value=s??""))},d=document.createElement("div");d.style.display="contents",i.innerHTML="",i.appendChild(d),d.addEventListener("keydown",c=>{c.key==="Enter"&&(c.stopPropagation(),c.preventDefault(),r=!0,$(t,o,!1)),c.key==="Escape"&&(c.stopPropagation(),c.preventDefault(),a(),$(t,o,!0))});const h=n.__editorTemplate,p=n.editor||(h?"template":Oe(n)),b=s;if(p==="template"&&h){const c=h.cloneNode(!0),u=n.__compiledEditor;u?c.innerHTML=u({row:e,value:s,field:n.field,column:n}):c.querySelectorAll("*").forEach(w=>{w.childNodes.length===1&&w.firstChild?.nodeType===Node.TEXT_NODE&&(w.textContent=w.textContent?.replace(/{{\s*value\s*}}/g,s==null?"":String(s)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(v,A)=>{const x=e[A];return x==null?"":String(x)})||"")});const f=c.querySelector("input,textarea,select");if(f){const w=typeof HTMLInputElement<"u";w&&f instanceof HTMLInputElement&&f.type==="checkbox"?f.checked=!!s:"value"in f&&(f.value=s??""),f.addEventListener("blur",()=>{const v=w&&f instanceof HTMLInputElement&&f.type==="checkbox"?f.checked:f.value;l(v)}),f.addEventListener("keydown",v=>{if(v.key==="Enter"){v.stopPropagation(),v.preventDefault(),r=!0;const A=w&&f instanceof HTMLInputElement&&f.type==="checkbox"?f.checked:f.value;l(A),$(t,o,!1)}v.key==="Escape"&&(v.stopPropagation(),v.preventDefault(),a(),$(t,o,!0))}),w&&f instanceof HTMLInputElement&&f.type==="checkbox"&&f.addEventListener("change",()=>{const v=f.checked;l(v)}),setTimeout(()=>f.focus(),0)}d.appendChild(c)}else if(typeof p=="string"){const c=document.createElement(p);c.value=b,c.addEventListener("change",()=>l(c.value)),d.appendChild(c)}else if(typeof p=="function"){const c=p({row:e,value:b,field:n.field,column:n,commit:l,cancel:a});typeof c=="string"?d.innerHTML=c:d.appendChild(c)}else if(p&&typeof p=="object"){const c=document.createElement("div");c.setAttribute("data-external-editor",""),c.setAttribute("data-field",n.field),d.appendChild(c);const u={row:e,value:b,field:n.field,column:n,commit:l,cancel:a};if(p.mount)try{p.mount({placeholder:c,context:u,spec:p})}catch{}else t.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:c,spec:p,context:u}}))}}function se(t,e){!t.sortState||t.sortState.field!==e.field?(t.sortState||(t.__originalOrder=t._rows.slice()),re(t,e,1)):t.sortState.direction===1?re(t,e,-1):(t.sortState=null,t.__rowRenderEpoch++,t.rowPool.forEach(n=>n.__epoch=-1),t._rows=t.__originalOrder.slice(),Y(t),t.headerRowEl?.querySelectorAll('[role="columnheader"].sortable')?.forEach(n=>{n.getAttribute("aria-sort")?(n.getAttribute("aria-sort")==="ascending"||n.getAttribute("aria-sort")==="descending")&&(t.sortState||n.setAttribute("aria-sort","none")):n.setAttribute("aria-sort","none")}),t.refreshVirtualWindow(!0),t.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:0}})),t.requestStateChange?.())}function re(t,e,o){t.sortState={field:e.field,direction:o};const n=e.sortComparator||((i,s)=>i==null&&s==null?0:i==null?-1:s==null||i>s?1:i<s?-1:0);t._rows.sort((i,s)=>n(i[e.field],s[e.field],i,s)*o),t.__rowRenderEpoch++,t.rowPool.forEach(i=>i.__epoch=-1),Y(t),t.refreshVirtualWindow(!0),t.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:o}})),t.requestStateChange?.()}function Ne(t,e){typeof e=="string"?t.textContent=e:e instanceof HTMLElement&&(t.innerHTML="",t.appendChild(e.cloneNode(!0)))}function Y(t){t.headerRowEl=t.findHeaderRow();const e=t.headerRowEl;e.innerHTML="",t.visibleColumns.forEach((o,n)=>{const i=document.createElement("div");i.className="cell",U(i,"header-cell"),i.setAttribute("role","columnheader"),i.setAttribute("aria-colindex",String(n+1)),i.setAttribute("data-field",o.field),i.setAttribute("data-col",String(n)),o.sticky==="left"?i.classList.add("sticky-left"):o.sticky==="right"&&i.classList.add("sticky-right");const s=o.__headerTemplate;if(s)Array.from(s.childNodes).forEach(r=>i.appendChild(r.cloneNode(!0)));else{const r=o.header||o.field,l=document.createElement("span");l.textContent=r,i.appendChild(l)}if(o.sortable){i.classList.add("sortable"),i.tabIndex=0;const r=document.createElement("span");U(r,"sort-indicator"),r.style.opacity="0.6";const l=t.sortState?.field===o.field?t.sortState.direction:0,a={...P,...t.icons},d=l===1?a.sortAsc:l===-1?a.sortDesc:a.sortNone;Ne(r,d),i.appendChild(r),i.setAttribute("aria-sort",l===0?"none":l===1?"ascending":"descending"),i.addEventListener("click",h=>{t.resizeController?.isResizing||t.dispatchHeaderClick?.(h,n,i)||se(t,o)}),i.addEventListener("keydown",h=>{if(h.key==="Enter"||h.key===" "){if(h.preventDefault(),t.dispatchHeaderClick?.(h,n,i))return;se(t,o)}})}if(o.resizable){o.sticky||(i.style.position="relative");const r=document.createElement("div");r.className="resize-handle",r.setAttribute("aria-hidden","true"),r.addEventListener("mousedown",l=>{l.stopPropagation(),l.preventDefault(),t.resizeController.start(l,n,i)}),i.appendChild(r)}e.appendChild(i)});try{const o=t.shadowRoot;o&&o.querySelectorAll(".header-group-row .cell").forEach(i=>{i.getAttribute("data-group")&&i.classList.add("grouped")})}catch{}e.querySelectorAll(".cell.sortable").forEach(o=>{o.getAttribute("aria-sort")||o.setAttribute("aria-sort","none")}),e.children.length>0?(e.setAttribute("role","row"),e.setAttribute("aria-rowindex","1")):(e.removeAttribute("role"),e.removeAttribute("aria-rowindex"))}function qe(t){let e=null,o=null,n=null,i=null;const s=a=>{if(!e)return;const d=a.clientX-e.startX,h=Math.max(40,e.startWidth+d),p=t.visibleColumns[e.colIndex];p.width=h,p.__userResized=!0,p.__renderedWidth=h,o==null&&(o=requestAnimationFrame(()=>{o=null,t.updateTemplate?.()})),t.dispatchEvent(new CustomEvent("column-resize",{detail:{field:p.field,width:h}}))};let r=!1;const l=()=>{const a=e!==null;a&&(r=!0,requestAnimationFrame(()=>{r=!1})),window.removeEventListener("mousemove",s),window.removeEventListener("mouseup",l),n!==null&&(document.documentElement.style.cursor=n,n=null),i!==null&&(document.body.style.userSelect=i,i=null),e=null,a&&t.requestStateChange&&t.requestStateChange()};return{get isResizing(){return e!==null||r},start(a,d,h){a.preventDefault();const p=h.getBoundingClientRect();e={startX:a.clientX,colIndex:d,startWidth:p.width},window.addEventListener("mousemove",s),window.addEventListener("mouseup",l),n===null&&(n=document.documentElement.style.cursor),document.documentElement.style.cursor="e-resize",i===null&&(i=document.body.style.userSelect),document.body.style.userSelect="none"},dispose(){l()}}}function B(t){return t?typeof t=="string"?t:t.outerHTML:""}function Ie(){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 $e(t,e){return!!(t?.header?.title||t?.header?.toolbarButtons?.length||e.toolPanels.size>0||e.headerContents.size>0||e.toolbarButtons.size>0||e.lightDomButtons.length>0||e.lightDomHeaderContent.length>0)}function Be(t,e,o="☰"){const n=t?.header?.title??"",i=!!n,s=B(o),r=t?.header?.toolbarButtons??[],l=r.length>0,a=e.toolbarButtons.size>0,d=e.lightDomButtons.length>0,h=e.toolPanels.size>0,b=(l||a||d)&&h,c=[...r].sort((w,v)=>(w.order??100)-(v.order??100)),u=[...e.toolbarButtons.values()].sort((w,v)=>(w.order??100)-(v.order??100));let f="";for(const w of c)w.icon&&w.action&&(f+=`<button class="tbw-toolbar-btn" data-btn="${w.id}" title="${w.label}" aria-label="${w.label}"${w.disabled?" disabled":""}>${w.icon}</button>`);for(const w of u)w.icon&&w.action&&(f+=`<button class="tbw-toolbar-btn" data-btn="${w.id}" title="${w.label}" aria-label="${w.label}"${w.disabled?" disabled":""}>${w.icon}</button>`);for(const w of c)(w.element||w.render)&&(f+=`<div class="tbw-toolbar-btn-slot" data-btn-slot="${w.id}"></div>`);for(const w of u)(w.element||w.render)&&(f+=`<div class="tbw-toolbar-btn-slot" data-btn-slot="${w.id}"></div>`);if(d&&(f+='<slot name="toolbar"></slot>'),b&&(f+='<div class="tbw-toolbar-separator"></div>'),h){const w=e.isPanelOpen;f+=`<button class="tbw-toolbar-btn${w?" active":""}" data-panel-toggle title="Settings" aria-label="Toggle settings panel" aria-pressed="${w}" aria-controls="tbw-tool-panel">${s}</button>`}return`
1
+ (function(y,q){typeof exports=="object"&&typeof module<"u"?q(exports):typeof define=="function"&&define.amd?define(["exports"],q):(y=typeof globalThis<"u"?globalThis:y||self,q(y.TbwGrid={}))})(this,(function(y){"use strict";const q=":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.selected:focus-visible,:host .data-grid-row>.cell:focus-visible:not(.cell-focus){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 be(t){const e=new Map;return t.sortState&&e.set(t.sortState.field,{direction:t.sortState.direction===1?"asc":"desc",priority:0}),e}function J(t,e){const o=t._columns,n=be(t);return{columns:o.map((i,s)=>{const r={field:i.field,order:s,visible:!0},l=i;l.__renderedWidth!==void 0?r.width=l.__renderedWidth:i.width!==void 0&&(r.width=typeof i.width=="string"?parseFloat(i.width):i.width);const a=n.get(i.field);a&&(r.sort=a);for(const d of e)if(d.getColumnState){const h=d.getColumnState(i.field);h&&Object.assign(r,h)}return r})}}function we(t,e,o,n){if(!e.columns||e.columns.length===0)return;const i=new Map(e.columns.map(l=>[l.field,l])),s=o.map(l=>{const a=i.get(l.field);if(!a)return l;const d={...l};return a.width!==void 0&&(d.width=a.width,d.__renderedWidth=a.width),a.visible!==void 0&&(d.hidden=!a.visible),d});s.sort((l,a)=>{const d=i.get(l.field)?.order??1/0,h=i.get(a.field)?.order??1/0;return d-h}),t._columns=s;const r=e.columns.filter(l=>l.sort!==void 0).sort((l,a)=>(l.sort?.priority??0)-(a.sort?.priority??0));if(r.length>0){const l=r[0];l.sort&&(t.sortState={field:l.field,direction:l.sort.direction==="asc"?1:-1})}else t.sortState=null;for(const l of n)if(l.applyColumnState)for(const a of e.columns)l.applyColumnState(a.field,a)}function ge(t,e,o){let n=null;return()=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{n=null;const i=J(t,e());o(i)},100)}}const z={STRETCH:"stretch",FIXED:"fixed"},P={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰"};function me(t){return t==null?"string":typeof t=="number"?"number":typeof t=="boolean"?"boolean":t instanceof Date||typeof t=="string"&&/\d{4}-\d{2}-\d{2}/.test(t)&&!isNaN(Date.parse(t))?"date":"string"}function Q(t,e){if(e&&e.length){const s={};return e.forEach(r=>{r.type&&(s[r.field]=r.type)}),{columns:e,typeMap:s}}const o=t[0]||{},n=Object.keys(o).map(s=>{const r=o[s],l=me(r);return{field:s,header:s.charAt(0).toUpperCase()+s.slice(1),type:l}}),i={};return n.forEach(s=>{i[s.field]=s.type||"string"}),{columns:n,typeMap:i}}const ve=/{{\s*([^}]+)\s*}}/g,O="__DG_EMPTY__",Ee=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,Ce=/__(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/,ye=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,_e=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),Re=/^\s*(javascript|vbscript|data|blob):/i;function F(t){if(!t||typeof t!="string")return"";if(t.indexOf("<")===-1)return t;const e=document.createElement("template");return e.innerHTML=t,Se(e.content),e.innerHTML}function Se(t){const e=[],o=t.querySelectorAll("*");for(const n of o){const i=n.tagName.toLowerCase();if(ye.has(i)){e.push(n);continue}if((i==="svg"||n.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(n.attributes).some(l=>ee.test(l.name)||l.name==="href"||l.name==="xlink:href")){e.push(n);continue}const s=[];for(const r of n.attributes){const l=r.name.toLowerCase();if(ee.test(l)){s.push(r.name);continue}if(_e.has(l)&&Re.test(r.value)){s.push(r.name);continue}if(l==="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 te(t,e){if(!t||t.indexOf("{{")===-1)return t;const o=[],n=t.replace(ve,(l,a)=>{const d=Ae(a,e);return o.push({expr:a.trim(),result:d}),d}),i=xe(n),s=o.length&&o.every(l=>l.result===""||l.result===O);return/Reflect\.|\bProxy\b|ownKeys\(/.test(t)||s?"":i}function Ae(t,e){if(t=(t||"").trim(),!t||/\b(Reflect|Proxy|ownKeys)\b/.test(t))return O;if(t==="value")return e.value==null?O:String(e.value);if(t.startsWith("row.")&&!/[()?]/.test(t)&&!t.includes(":")){const n=t.slice(4),i=e.row?e.row[n]:void 0;return i==null?O:String(i)}if(t.length>80||!Ee.test(t)||Ce.test(t))return O;const o=t.match(/\./g);if(o&&o.length>1)return O;try{const i=new Function("value","row",`return (${t});`)(e.value,e.row),s=i==null?"":String(i);return/Reflect|Proxy|ownKeys/.test(s)?O:s||O}catch{return O}}function xe(t){return t&&t.replace(new RegExp(O,"g"),"").replace(/Reflect\.[^<>{}\s]+/g,"").replace(/\bProxy\b/g,"").replace(/ownKeys\([^)]*\)/g,"")}function Te(t){if(/Reflect|Proxy|ownKeys/.test(t.textContent||"")){if(Array.from(t.childNodes).forEach(e=>{e.nodeType===Node.TEXT_NODE&&/Reflect|Proxy|ownKeys/.test(e.textContent||"")&&(e.textContent="")}),/Reflect|Proxy|ownKeys/.test(t.textContent||"")){if(/Reflect|Proxy|ownKeys/.test(t.textContent||""))for(;t.firstChild;)t.removeChild(t.firstChild);t.textContent=(t.textContent||"").replace(/Reflect|Proxy|ownKeys/g,"")}(t.textContent||"").trim().length===0&&(t.textContent="")}}function oe(t){const e=/Reflect\.|\bProxy\b|ownKeys\(/.test(t),o=n=>e?"":te(t,n);return o.__blocked=e,o}function Le(t){return Array.from(t.querySelectorAll("tbw-grid-column")).map(o=>{const n=o.getAttribute("field")||"";if(!n)return null;const i=o.getAttribute("type")||void 0,r=i&&new Set(["number","string","date","boolean","select","typeahead"]).has(i)?i:void 0,l=o.getAttribute("header")||void 0,a=o.hasAttribute("sortable"),d=o.hasAttribute("editable"),h={field:n,type:r,header:l,sortable:a,editable:d};o.hasAttribute("resizable")&&(h.resizable=!0),o.hasAttribute("sizable")&&(h.resizable=!0);const p=o.getAttribute("options");p&&(h.options=p.split(",").map(f=>{const[w,v]=f.includes(":")?f.split(":"):[f.trim(),f.trim()];return{value:w.trim(),label:v?.trim()||w.trim()}}));const b=o.querySelector("tbw-grid-column-view"),c=o.querySelector("tbw-grid-column-editor"),u=o.querySelector("tbw-grid-column-header");return b&&(h.__viewTemplate=b),c&&(h.__editorTemplate=c),u&&(h.__headerTemplate=u),h}).filter(o=>!!o)}function ke(t,e){if((!t||!t.length)&&(!e||!e.length))return[];if(!t||!t.length)return e||[];if(!e||!e.length)return t;const o={};e.forEach(i=>o[i.field]=i);const n=t.map(i=>{const s=o[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 o[i.field],r});return Object.keys(o).forEach(i=>n.push(o[i])),n}function U(t,e){try{t.part?.add?.(e)}catch{}const o=t.getAttribute("part");o?o.split(/\s+/).includes(e)||t.setAttribute("part",o+" "+e):t.setAttribute("part",e)}function Pe(t){t.__lightDomColumnsCache||(t.__originalColumnNodes=Array.from(t.querySelectorAll("tbw-grid-column")),t.__lightDomColumnsCache=t.__originalColumnNodes.length?Le(t):[]);const e=t.__lightDomColumnsCache,o=ke(t._columns,e);o.forEach(i=>{i.__viewTemplate&&!i.__compiledView&&(i.__compiledView=oe(i.__viewTemplate.innerHTML)),i.__editorTemplate&&!i.__compiledEditor&&(i.__compiledEditor=oe(i.__editorTemplate.innerHTML))});const{columns:n}=Q(t._rows,o);t._columns=n}function Oe(t){const e=t.effectiveConfig?.fitMode||t.fitMode||z.STRETCH;if(e!==z.STRETCH&&e!==z.FIXED||t.__didInitialAutoSize||!t.isConnected)return;const o=t.headerRowEl?.children||[];if(!o.length)return;let n=!1;t.visibleColumns.forEach((i,s)=>{if(i.width)return;const r=o[s];let l=r?r.scrollWidth:0;for(const a of t.rowPool){const d=a.children[s];if(d){const h=d.scrollWidth;h>l&&(l=h)}}l>0&&(i.width=l+2,i.__autoSized=!0,n=!0)}),n&&ne(t),t.__didInitialAutoSize=!0}function ne(t){(t.effectiveConfig?.fitMode||t.fitMode||z.STRETCH)===z.STRETCH?t.gridTemplate=t.visibleColumns.map(o=>{if(o.width)return`${o.width}px`;const n=o.minWidth;return n!=null?`minmax(${n}px, 1fr)`:"1fr"}).join(" ").trim():t.gridTemplate=t.visibleColumns.map(o=>o.width?`${o.width}px`:"max-content").join(" "),t.style.setProperty("--tbw-column-template",t.gridTemplate)}function He(t){switch(t.type){case"number":return e=>{const o=document.createElement("input");return o.type="number",o.value=e.value??"",o.addEventListener("blur",()=>e.commit(o.value===""?null:Number(o.value))),o.addEventListener("keydown",n=>{n.key==="Enter"&&e.commit(o.value===""?null:Number(o.value)),n.key==="Escape"&&e.cancel()}),o.focus(),o};case"boolean":return e=>{const o=document.createElement("input");return o.type="checkbox",o.checked=!!e.value,o.addEventListener("change",()=>e.commit(o.checked)),o.focus(),o};case"date":return e=>{const o=document.createElement("input");return o.type="date",e.value instanceof Date&&(o.valueAsDate=e.value),o.addEventListener("change",()=>e.commit(o.valueAsDate)),o.addEventListener("keydown",n=>{n.key==="Escape"&&e.cancel()}),o.focus(),o};case"select":case"typeahead":return e=>{const o=document.createElement("select");e.column.multi&&(o.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),o.appendChild(r)});const i=()=>{if(e.column.multi){const s=[];Array.from(o.selectedOptions).forEach(r=>{s.push(r.value)}),e.commit(s)}else e.commit(o.value)};return o.addEventListener("change",i),o.addEventListener("blur",i),o.addEventListener("keydown",s=>{s.key==="Escape"&&e.cancel()}),o.focus(),o};default:return e=>{const o=document.createElement("input");return o.type="text",o.value=e.value??"",o.addEventListener("blur",()=>e.commit(o.value)),o.addEventListener("keydown",n=>{n.key==="Enter"&&e.commit(o.value),n.key==="Escape"&&e.cancel()}),o.focus(),o}}}function Me(t,e){if(t.dispatchKeyDown?.(e))return;const o=t._rows.length-1,n=t.visibleColumns.length-1,i=t.activeEditRows!==void 0&&t.activeEditRows!==-1,r=t.visibleColumns[t.focusCol]?.type,l=e.composedPath?e.composedPath():[],a=l&&l.length?l[0]:e.target,d=h=>{if(!h)return!1;const p=h.tagName;return!!(p==="INPUT"||p==="SELECT"||p==="TEXTAREA"||h.isContentEditable)};if(!(d(a)&&(e.key==="Home"||e.key==="End"))&&!(d(a)&&(e.key==="ArrowUp"||e.key==="ArrowDown")&&a.tagName==="INPUT"&&a.type==="number")&&!(d(a)&&(e.key==="ArrowLeft"||e.key==="ArrowRight"))&&!(d(a)&&(e.key==="Enter"||e.key==="Escape"))&&!(i&&(r==="select"||r==="typeahead")&&(e.key==="ArrowDown"||e.key==="ArrowUp"))){switch(e.key){case"Tab":{e.preventDefault(),!e.shiftKey?t.focusCol<n?t.focusCol+=1:(typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t.focusRow<o&&(t.focusRow+=1,t.focusCol=0)):t.focusCol>0?t.focusCol-=1:t.focusRow>0&&(typeof t.commitActiveRowEdit=="function"&&t.activeEditRows===t.focusRow&&t.commitActiveRowEdit(),t.focusRow-=1,t.focusCol=n),$(t);return}case"ArrowDown":i&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t.focusRow=Math.min(o,t.focusRow+1),e.preventDefault();break;case"ArrowUp":i&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t.focusRow=Math.max(0,t.focusRow-1),e.preventDefault();break;case"ArrowRight":t.focusCol=Math.min(n,t.focusCol+1),e.preventDefault();break;case"ArrowLeft":t.focusCol=Math.max(0,t.focusCol-1),e.preventDefault();break;case"Home":t.focusCol=0,e.preventDefault();break;case"End":t.focusCol=n,e.preventDefault();break;case"PageDown":t.focusRow=Math.min(o,t.focusRow+20),e.preventDefault();break;case"PageUp":t.focusRow=Math.max(0,t.focusRow-20),e.preventDefault();break;case"Enter":return typeof t.beginBulkEdit=="function"?t.beginBulkEdit(t.focusRow):t.dispatchEvent(new CustomEvent("activate-cell",{detail:{row:t.focusRow,col:t.focusCol}})),$(t);default:return}$(t)}}function $(t){if(t.virtualization?.enabled){const{rowHeight:s,container:r,viewportEl:l}=t.virtualization,a=r,d=l?.clientHeight??a?.clientHeight??0;if(a&&d>0){const h=t.focusRow*s;h<a.scrollTop?a.scrollTop=h:h+s>a.scrollTop+d&&(a.scrollTop=h-d+s)}}t.activeEditRows!==void 0&&t.activeEditRows!==-1||t.refreshVirtualWindow(!1),Array.from(t.bodyEl.querySelectorAll(".cell-focus")).forEach(s=>s.classList.remove("cell-focus")),Array.from(t.bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(s=>{s.setAttribute("aria-selected","false")});const o=t.focusRow,n=t.virtualization.start??0,i=t.virtualization.end??t._rows.length;if(o>=n&&o<i){const r=t.bodyEl.querySelectorAll(".data-grid-row")[o-n]?.children[t.focusCol];if(r){if(r.classList.add("cell-focus"),r.setAttribute("aria-selected","true"),t.activeEditRows!==void 0&&t.activeEditRows!==-1&&r.classList.contains("editing")){const l=r.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(l&&document.activeElement!==l)try{l.focus()}catch{}}else if(!r.contains(document.activeElement)){r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1");try{r.focus({preventScroll:!0})}catch{}}}}}const De="__cellDisplayCache",ze="__cellCacheEpoch";function X(t){t[De]=void 0,t[ze]=void 0,t.__hasSpecialColumns=void 0}function Ne(t,e,o,n,i){const s=Math.max(0,o-e),r=t.bodyEl,l=t.visibleColumns,a=l.length;let d=t.__cachedHeaderRowCount;for(d===void 0&&(d=t.shadowRoot?.querySelector(".header-group-row")?2:1,t.__cachedHeaderRowCount=d);t.rowPool.length<s;){const p=document.createElement("div");p.className="data-grid-row",p.setAttribute("role","row"),p.addEventListener("click",b=>ie(t,b,p,!1)),p.addEventListener("dblclick",b=>ie(t,b,p,!0)),t.rowPool.push(p)}if(t.rowPool.length>s){for(let p=s;p<t.rowPool.length;p++){const b=t.rowPool[p];b.parentNode===r&&b.remove()}t.rowPool.length=s}const h=i&&t.__hasRenderRowPlugins!==!1;for(let p=0;p<s;p++){const b=e+p,c=t._rows[b],u=t.rowPool[p];if(u.setAttribute("aria-rowindex",String(b+d+1)),h&&i(c,u,b)){u.__epoch=n,u.__rowDataRef=c,u.parentNode!==r&&r.appendChild(u);continue}const f=u.__epoch,w=u.__rowDataRef,v=u.children.length,x=f===n&&v===a,S=w!==c;let L=!1;if(x&&S){for(let E=0;E<a;E++)if(l[E].externalView&&!u.querySelector(`.cell[data-col="${E}"] [data-external-view]`)){L=!0;break}}if(!x||L){const E=u.querySelector(".cell.editing"),_=t.activeEditRows===b;if(E&&!_)u.__isCustomRow&&(u.className="data-grid-row",u.setAttribute("role","row"),u.__isCustomRow=!1),N(t,u,c,b),u.__epoch=n,u.__rowDataRef=c;else if(E&&_)j(t,u,c,b),u.__rowDataRef=c;else if(u.__isCustomRow&&(u.className="data-grid-row",u.setAttribute("role","row"),u.__isCustomRow=!1),N(t,u,c,b),u.__epoch=n,u.__rowDataRef=c,_){const R=u.children;for(let C=0;C<R.length;C++){const k=t.visibleColumns[C];k&&k.editable&&M(t,c,b,k,R[C])}}}else if(S){const E=u.querySelector(".cell.editing"),_=t.activeEditRows===b;if(E&&!_)N(t,u,c,b),u.__epoch=n,u.__rowDataRef=c;else if(j(t,u,c,b),u.__rowDataRef=c,_&&!E){const R=u.children;for(let C=0;C<R.length;C++){const k=t.visibleColumns[C];k&&k.editable&&M(t,c,b,k,R[C])}}}else{const E=u.querySelector(".cell.editing"),_=t.activeEditRows===b;if(E&&!_)N(t,u,c,b),u.__epoch=n,u.__rowDataRef=c;else if(j(t,u,c,b),_&&!E){const R=u.children;for(let C=0;C<R.length;C++){const k=t.visibleColumns[C];k&&k.editable&&M(t,c,b,k,R[C])}}}const g=t._changedRowIndices.has(b),m=u.classList.contains("changed");g!==m&&u.classList.toggle("changed",g),u.parentNode!==r&&r.appendChild(u)}}function j(t,e,o,n){const i=e.children,s=t.visibleColumns,r=s.length,l=i.length,a=r<l?r:l,d=t.focusRow,h=t.focusCol;let p=t.__hasSpecialColumns;if(p===void 0){p=!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"){p=!0;break}}t.__hasSpecialColumns=p}const b=String(n);if(!p){for(let c=0;c<a;c++){const u=i[c],f=o[s[c].field];u.textContent=f==null?"":String(f),u.getAttribute("data-row")!==b&&u.setAttribute("data-row",b);const w=d===n&&h===c,v=u.classList.contains("cell-focus");w!==v&&(u.classList.toggle("cell-focus",w),u.setAttribute("aria-selected",String(w)))}return}for(let c=0;c<a;c++)if(s[c].externalView&&!i[c].querySelector("[data-external-view]")){N(t,e,o,n);return}for(let c=0;c<a;c++){const u=s[c],f=i[c];f.getAttribute("data-row")!==b&&f.setAttribute("data-row",b);const w=d===n&&h===c,v=f.classList.contains("cell-focus");if(w!==v&&(f.classList.toggle("cell-focus",w),f.setAttribute("aria-selected",String(w))),f.classList.contains("editing"))continue;if(u.viewRenderer){const S=o[u.field],L=u.viewRenderer({row:o,value:S,field:u.field,column:u});typeof L=="string"?f.innerHTML=F(L):L?(f.innerHTML="",f.appendChild(L)):f.textContent=S==null?"":String(S);continue}if(u.__viewTemplate||u.__compiledView||u.externalView)continue;const A=o[u.field];let x;if(u.format)try{const S=u.format(A,o);x=S==null?"":String(S)}catch{x=A==null?"":String(A)}else if(u.type==="date"){if(A==null||A==="")x="";else if(A instanceof Date)x=isNaN(A.getTime())?"":A.toLocaleDateString();else{const S=new Date(A);x=isNaN(S.getTime())?"":S.toLocaleDateString()}f.textContent=x}else if(u.type==="boolean"){const S=!!A;f.innerHTML=`<span role="checkbox" aria-checked="${S}" aria-label="${S}">${S?"&#x1F5F9;":"&#9744;"}</span>`}else x=A==null?"":String(A),f.textContent=x}}function N(t,e,o,n){e.innerHTML="";const i=t.visibleColumns,s=i.length,r=t.focusRow,l=t.focusCol,a=t.effectiveConfig?.editOn||t.editOn,d=t,h=document.createDocumentFragment();for(let p=0;p<s;p++){const b=i[p],c=document.createElement("div");c.className="cell",U(c,"cell"),c.setAttribute("role","gridcell"),c.setAttribute("aria-colindex",String(p+1)),c.setAttribute("data-col",String(p)),c.setAttribute("data-row",String(n)),b.type,b.type&&c.setAttribute("data-type",b.type);const u=b.sticky;u==="left"?c.classList.add("sticky-left"):u==="right"&&c.classList.add("sticky-right");let f=o[b.field];const w=b.format;if(w)try{f=w(f,o)}catch{}const v=b.__compiledView,A=b.__viewTemplate,x=b.viewRenderer,S=b.externalView;let L=!1;if(x){const g=x({row:o,value:f,field:b.field,column:b});typeof g=="string"?(c.innerHTML=F(g),L=!0):g?c.appendChild(g):c.textContent=f==null?"":String(f)}else if(S){const g=S,m=document.createElement("div");m.setAttribute("data-external-view",""),m.setAttribute("data-field",b.field),c.appendChild(m);const E={row:o,value:f,field:b.field,column:b};if(g.mount)try{g.mount({placeholder:m,context:E,spec:g})}catch{}else queueMicrotask(()=>{try{d.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:m,spec:g,context:E}}))}catch{}});m.setAttribute("data-mounted","")}else if(v){const g=v({row:o,value:f,field:b.field,column:b}),m=v.__blocked;c.innerHTML=m?"":F(g),L=!0,m&&(c.textContent="",c.setAttribute("data-blocked-template",""))}else if(A){const g=A.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(g)?(c.textContent="",c.setAttribute("data-blocked-template","")):(c.innerHTML=F(te(g,{row:o,value:f})),L=!0)}else if(b.type==="date")if(f==null||f==="")c.textContent="";else{let g=null;if(f instanceof Date)g=f;else if(typeof f=="number"||typeof f=="string"){const m=new Date(f);isNaN(m.getTime())||(g=m)}c.textContent=g?g.toLocaleDateString():""}else if(b.type==="boolean"){const g=!!f;c.innerHTML=`<span role="checkbox" aria-checked="${g}" aria-label="${g}">${g?"&#x1F5F9;":"&#9744;"}</span>`}else c.textContent=f==null?"":String(f);if(L){Te(c);const g=c.textContent||"";/Proxy|Reflect\.ownKeys/.test(g)&&(c.textContent=g.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=""),b.editable?(c.tabIndex=0,c.addEventListener("mousedown",()=>{if(c.classList.contains("editing"))return;const g=Number(c.getAttribute("data-row")),m=Number(c.getAttribute("data-col"));isNaN(g)||isNaN(m)||(t.focusRow=g,t.focusCol=m,$(t))}),a==="click"?c.addEventListener("click",g=>{if(c.classList.contains("editing"))return;g.stopPropagation();const m=Number(c.getAttribute("data-row")),E=Number(c.getAttribute("data-col"));if(isNaN(m)||isNaN(E))return;const _=t._rows[m],R=t.visibleColumns[E];!_||!R||(t.focusRow=m,t.focusCol=E,M(t,_,m,R,c))}):c.addEventListener("dblclick",g=>{g.stopPropagation();const m=Number(c.getAttribute("data-row"));if(isNaN(m))return;const E=t._rows[m];if(!E)return;I(t,m,E);const _=t.findRenderedRowElement?.(m);if(_){const R=_.children;for(let C=0;C<R.length;C++){const k=t.visibleColumns[C];k&&k.editable&&M(t,E,m,k,R[C])}}}),c.addEventListener("keydown",g=>{const m=Number(c.getAttribute("data-row")),E=Number(c.getAttribute("data-col"));if(isNaN(m)||isNaN(E))return;const _=t._rows[m],R=t.visibleColumns[E];if(!(!_||!R)){if((R.type==="select"||R.type==="typeahead")&&!c.classList.contains("editing")&&g.key==="Enter"){g.preventDefault(),t.activeEditRows!==m&&I(t,m,_),M(t,_,m,R,c),setTimeout(()=>{const C=c.querySelector("select");try{C?.showPicker?.()}catch{}C?.focus()},0);return}if(R.type==="boolean"&&g.key===" "&&!c.classList.contains("editing")){g.preventDefault(),t.activeEditRows!==m&&I(t,m,_);const C=!_[R.field];K(t,m,R,C,_),c.innerHTML=`<span role="checkbox" aria-checked="${C}" aria-label="${C}">${C?"&#x1F5F9;":"&#9744;"}</span>`;return}if(g.key==="Enter"&&!c.classList.contains("editing")){g.preventDefault(),g.stopPropagation(),t.focusRow=m,t.focusCol=E,typeof t.beginBulkEdit=="function"?t.beginBulkEdit(m):M(t,_,m,R,c);return}if(g.key==="F2"&&!c.classList.contains("editing")){g.preventDefault(),M(t,_,m,R,c);return}}})):b.type==="boolean"&&(c.hasAttribute("tabindex")||(c.tabIndex=0)),r===n&&l===p?c.setAttribute("aria-selected","true"):c.setAttribute("aria-selected","false"),h.appendChild(c)}e.appendChild(h)}function ie(t,e,o,n){if(e.target?.closest(".resize-handle"))return;const i=o.querySelector(".cell[data-row]");if(!i)return;const s=Number(i.getAttribute("data-row"));if(isNaN(s))return;const r=t._rows[s];if(!r)return;const l=e.target?.closest(".cell[data-col]");if(l){if(l.classList.contains("editing"))return;const d=Number(l.getAttribute("data-col"));if(!isNaN(d)){if(t.dispatchCellClick?.(e,s,d,l))return;t.focusRow=s,t.focusCol=d,$(t)}}if(o.querySelector(".cell.editing")){const d=o.querySelectorAll(".cell.editing");if(!n)return;d.forEach(h=>h.classList.remove("editing"))}const a=t.effectiveConfig?.editOn||t.editOn||"doubleClick";if(a==="click"||a==="doubleClick"&&n)I(t,s,r);else return;Array.from(o.children).forEach((d,h)=>{const p=t.visibleColumns[h];p&&p.editable&&M(t,r,s,p,d)}),l&&queueMicrotask(()=>{const d=o.querySelector(`.cell[data-col="${t.focusCol}"]`);if(d?.classList.contains("editing")){const h=d.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');try{h?.focus()}catch{}}})}function se(t){return!(t==="__proto__"||t==="constructor"||t==="prototype")}function I(t,e,o){t.activeEditRows!==e&&(t.rowEditSnapshots.set(e,{...o}),t.activeEditRows=e)}function B(t,e,o){if(t.activeEditRows!==e)return;const n=t.rowEditSnapshots.get(e),i=t._rows[e],s=t.findRenderedRowElement?.(e);if(!o&&s&&i&&s.querySelectorAll(".cell.editing").forEach(l=>{const a=Number(l.getAttribute("data-col"));if(isNaN(a))return;const d=t.visibleColumns[a];if(!d)return;const h=l.querySelector("input,textarea,select");if(h){let p;h instanceof HTMLInputElement&&h.type==="checkbox"?p=h.checked:(p=h.value,d.type==="number"&&p!==""&&(p=Number(p))),i[d.field]!==p&&K(t,e,d,p,i)}}),o&&n&&i)Object.keys(n).forEach(r=>i[r]=n[r]),t._changedRowIndices.delete(e),X(t);else if(!o){const r=t._changedRowIndices.has(e);t.dispatchEvent(new CustomEvent("row-commit",{detail:{rowIndex:e,row:i,changed:r,changedRows:t.changedRows,changedRowIndices:t.changedRowIndices}}))}t.rowEditSnapshots.delete(e),t.activeEditRows=-1,s&&(N(t,s,t._rows[e],e),t._changedRowIndices.has(e)?s.classList.add("changed"):s.classList.remove("changed")),queueMicrotask(()=>{try{const r=t.focusRow,l=t.focusCol,a=t.findRenderedRowElement?.(r);if(a){Array.from(t.bodyEl.querySelectorAll(".cell-focus")).forEach(h=>h.classList.remove("cell-focus"));const d=a.querySelector(`.cell[data-row="${r}"][data-col="${l}"]`);d&&(d.classList.add("cell-focus"),d.setAttribute("aria-selected","true"),d.hasAttribute("tabindex")||d.setAttribute("tabindex","-1"),d.focus({preventScroll:!0}))}}catch{}})}function K(t,e,o,n,i){const s=o.field;if(!se(s)||i[s]===n)return;i[s]=n;const l=!t._changedRowIndices.has(e);t._changedRowIndices.add(e);const a=t.findRenderedRowElement?.(e);a&&a.classList.add("changed"),t.dispatchEvent(new CustomEvent("cell-commit",{detail:{row:i,field:s,value:n,rowIndex:e,changedRows:t.changedRows,changedRowIndices:t.changedRowIndices,firstTimeForRow:l}}))}function M(t,e,o,n,i){if(!n.editable||(t.activeEditRows!==o&&I(t,o,e),i.classList.contains("editing")))return;const s=e[n.field];i.classList.add("editing");let r=!1;const l=c=>{r||t.activeEditRows===-1||K(t,o,n,c,e)},a=()=>{r=!0,se(n.field)&&(e[n.field]=s);const c=i.querySelector("input,textarea,select");c&&(typeof HTMLInputElement<"u"&&c instanceof HTMLInputElement&&c.type==="checkbox"?c.checked=!!s:"value"in c&&(c.value=s??""))},d=document.createElement("div");d.style.display="contents",i.innerHTML="",i.appendChild(d),d.addEventListener("keydown",c=>{c.key==="Enter"&&(c.stopPropagation(),c.preventDefault(),r=!0,B(t,o,!1)),c.key==="Escape"&&(c.stopPropagation(),c.preventDefault(),a(),B(t,o,!0))});const h=n.__editorTemplate,p=n.editor||(h?"template":He(n)),b=s;if(p==="template"&&h){const c=h.cloneNode(!0),u=n.__compiledEditor;u?c.innerHTML=u({row:e,value:s,field:n.field,column:n}):c.querySelectorAll("*").forEach(w=>{w.childNodes.length===1&&w.firstChild?.nodeType===Node.TEXT_NODE&&(w.textContent=w.textContent?.replace(/{{\s*value\s*}}/g,s==null?"":String(s)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(v,A)=>{const x=e[A];return x==null?"":String(x)})||"")});const f=c.querySelector("input,textarea,select");if(f){const w=typeof HTMLInputElement<"u";w&&f instanceof HTMLInputElement&&f.type==="checkbox"?f.checked=!!s:"value"in f&&(f.value=s??""),f.addEventListener("blur",()=>{const v=w&&f instanceof HTMLInputElement&&f.type==="checkbox"?f.checked:f.value;l(v)}),f.addEventListener("keydown",v=>{if(v.key==="Enter"){v.stopPropagation(),v.preventDefault(),r=!0;const A=w&&f instanceof HTMLInputElement&&f.type==="checkbox"?f.checked:f.value;l(A),B(t,o,!1)}v.key==="Escape"&&(v.stopPropagation(),v.preventDefault(),a(),B(t,o,!0))}),w&&f instanceof HTMLInputElement&&f.type==="checkbox"&&f.addEventListener("change",()=>{const v=f.checked;l(v)}),setTimeout(()=>f.focus(),0)}d.appendChild(c)}else if(typeof p=="string"){const c=document.createElement(p);c.value=b,c.addEventListener("change",()=>l(c.value)),d.appendChild(c)}else if(typeof p=="function"){const c=p({row:e,value:b,field:n.field,column:n,commit:l,cancel:a});typeof c=="string"?d.innerHTML=c:d.appendChild(c)}else if(p&&typeof p=="object"){const c=document.createElement("div");c.setAttribute("data-external-editor",""),c.setAttribute("data-field",n.field),d.appendChild(c);const u={row:e,value:b,field:n.field,column:n,commit:l,cancel:a};if(p.mount)try{p.mount({placeholder:c,context:u,spec:p})}catch{}else t.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:c,spec:p,context:u}}))}}function re(t,e){!t.sortState||t.sortState.field!==e.field?(t.sortState||(t.__originalOrder=t._rows.slice()),le(t,e,1)):t.sortState.direction===1?le(t,e,-1):(t.sortState=null,t.__rowRenderEpoch++,t.rowPool.forEach(n=>n.__epoch=-1),t._rows=t.__originalOrder.slice(),Y(t),t.headerRowEl?.querySelectorAll('[role="columnheader"].sortable')?.forEach(n=>{n.getAttribute("aria-sort")?(n.getAttribute("aria-sort")==="ascending"||n.getAttribute("aria-sort")==="descending")&&(t.sortState||n.setAttribute("aria-sort","none")):n.setAttribute("aria-sort","none")}),t.refreshVirtualWindow(!0),t.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:0}})),t.requestStateChange?.())}function le(t,e,o){t.sortState={field:e.field,direction:o};const n=e.sortComparator||((i,s)=>i==null&&s==null?0:i==null?-1:s==null||i>s?1:i<s?-1:0);t._rows.sort((i,s)=>n(i[e.field],s[e.field],i,s)*o),t.__rowRenderEpoch++,t.rowPool.forEach(i=>i.__epoch=-1),Y(t),t.refreshVirtualWindow(!0),t.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:o}})),t.requestStateChange?.()}function Ie(t,e){typeof e=="string"?t.textContent=e:e instanceof HTMLElement&&(t.innerHTML="",t.appendChild(e.cloneNode(!0)))}function Y(t){t.headerRowEl=t.findHeaderRow();const e=t.headerRowEl;e.innerHTML="",t.visibleColumns.forEach((o,n)=>{const i=document.createElement("div");i.className="cell",U(i,"header-cell"),i.setAttribute("role","columnheader"),i.setAttribute("aria-colindex",String(n+1)),i.setAttribute("data-field",o.field),i.setAttribute("data-col",String(n)),o.sticky==="left"?i.classList.add("sticky-left"):o.sticky==="right"&&i.classList.add("sticky-right");const s=o.__headerTemplate;if(s)Array.from(s.childNodes).forEach(r=>i.appendChild(r.cloneNode(!0)));else{const r=o.header||o.field,l=document.createElement("span");l.textContent=r,i.appendChild(l)}if(o.sortable){i.classList.add("sortable"),i.tabIndex=0;const r=document.createElement("span");U(r,"sort-indicator"),r.style.opacity="0.6";const l=t.sortState?.field===o.field?t.sortState.direction:0,a={...P,...t.icons},d=l===1?a.sortAsc:l===-1?a.sortDesc:a.sortNone;Ie(r,d),i.appendChild(r),i.setAttribute("aria-sort",l===0?"none":l===1?"ascending":"descending"),i.addEventListener("click",h=>{t.resizeController?.isResizing||t.dispatchHeaderClick?.(h,n,i)||re(t,o)}),i.addEventListener("keydown",h=>{if(h.key==="Enter"||h.key===" "){if(h.preventDefault(),t.dispatchHeaderClick?.(h,n,i))return;re(t,o)}})}if(o.resizable){o.sticky||(i.style.position="relative");const r=document.createElement("div");r.className="resize-handle",r.setAttribute("aria-hidden","true"),r.addEventListener("mousedown",l=>{l.stopPropagation(),l.preventDefault(),t.resizeController.start(l,n,i)}),i.appendChild(r)}e.appendChild(i)});try{const o=t.shadowRoot;o&&o.querySelectorAll(".header-group-row .cell").forEach(i=>{i.getAttribute("data-group")&&i.classList.add("grouped")})}catch{}e.querySelectorAll(".cell.sortable").forEach(o=>{o.getAttribute("aria-sort")||o.setAttribute("aria-sort","none")}),e.children.length>0?(e.setAttribute("role","row"),e.setAttribute("aria-rowindex","1")):(e.removeAttribute("role"),e.removeAttribute("aria-rowindex"))}function qe(t){let e=null,o=null,n=null,i=null;const s=a=>{if(!e)return;const d=a.clientX-e.startX,h=Math.max(40,e.startWidth+d),p=t.visibleColumns[e.colIndex];p.width=h,p.__userResized=!0,p.__renderedWidth=h,o==null&&(o=requestAnimationFrame(()=>{o=null,t.updateTemplate?.()})),t.dispatchEvent(new CustomEvent("column-resize",{detail:{field:p.field,width:h}}))};let r=!1;const l=()=>{const a=e!==null;a&&(r=!0,requestAnimationFrame(()=>{r=!1})),window.removeEventListener("mousemove",s),window.removeEventListener("mouseup",l),n!==null&&(document.documentElement.style.cursor=n,n=null),i!==null&&(document.body.style.userSelect=i,i=null),e=null,a&&t.requestStateChange&&t.requestStateChange()};return{get isResizing(){return e!==null||r},start(a,d,h){a.preventDefault();const p=h.getBoundingClientRect();e={startX:a.clientX,colIndex:d,startWidth:p.width},window.addEventListener("mousemove",s),window.addEventListener("mouseup",l),n===null&&(n=document.documentElement.style.cursor),document.documentElement.style.cursor="e-resize",i===null&&(i=document.body.style.userSelect),document.body.style.userSelect="none"},dispose(){l()}}}function V(t){return t?typeof t=="string"?t:t.outerHTML:""}function $e(){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 Be(t,e){return!!(t?.header?.title||t?.header?.toolbarButtons?.length||e.toolPanels.size>0||e.headerContents.size>0||e.toolbarButtons.size>0||e.lightDomButtons.length>0||e.lightDomHeaderContent.length>0)}function Ve(t,e,o="☰"){const n=t?.header?.title??"",i=!!n,s=V(o),r=t?.header?.toolbarButtons??[],l=r.length>0,a=e.toolbarButtons.size>0,d=e.lightDomButtons.length>0,h=e.toolPanels.size>0,b=(l||a||d)&&h,c=[...r].sort((w,v)=>(w.order??100)-(v.order??100)),u=[...e.toolbarButtons.values()].sort((w,v)=>(w.order??100)-(v.order??100));let f="";for(const w of c)w.icon&&w.action&&(f+=`<button class="tbw-toolbar-btn" data-btn="${w.id}" title="${w.label}" aria-label="${w.label}"${w.disabled?" disabled":""}>${w.icon}</button>`);for(const w of u)w.icon&&w.action&&(f+=`<button class="tbw-toolbar-btn" data-btn="${w.id}" title="${w.label}" aria-label="${w.label}"${w.disabled?" disabled":""}>${w.icon}</button>`);for(const w of c)(w.element||w.render)&&(f+=`<div class="tbw-toolbar-btn-slot" data-btn-slot="${w.id}"></div>`);for(const w of u)(w.element||w.render)&&(f+=`<div class="tbw-toolbar-btn-slot" data-btn-slot="${w.id}"></div>`);if(d&&(f+='<slot name="toolbar"></slot>'),b&&(f+='<div class="tbw-toolbar-separator"></div>'),h){const w=e.isPanelOpen;f+=`<button class="tbw-toolbar-btn${w?" active":""}" data-panel-toggle title="Settings" aria-label="Toggle settings panel" aria-pressed="${w}" aria-controls="tbw-tool-panel">${s}</button>`}return`
2
2
  <div class="tbw-shell-header" part="shell-header" role="presentation">
3
3
  ${i?`<div class="tbw-shell-title">${n}</div>`:""}
4
4
  <div class="tbw-shell-content" part="shell-content" role="presentation">
@@ -8,7 +8,7 @@
8
8
  ${f}
9
9
  </div>
10
10
  </div>
11
- `}function Ve(t,e,o,n){const i=t?.toolPanel?.position??"right",s=e.toolPanels.size>0,r=e.isPanelOpen,l=B(n?.expand??P.expand),a=B(n?.collapse??P.collapse),d=[...e.toolPanels.values()].sort((u,f)=>(u.order??100)-(f.order??100)),h=d.length===1;let p="";for(const u of d){const f=e.expandedSections.has(u.id),w=u.icon?`<span class="tbw-accordion-icon">${u.icon}</span>`:"",v=h?"":`<span class="tbw-accordion-chevron">${f?a:l}</span>`;p+=`
11
+ `}function Ge(t,e,o,n){const i=t?.toolPanel?.position??"right",s=e.toolPanels.size>0,r=e.isPanelOpen,l=V(n?.expand??P.expand),a=V(n?.collapse??P.collapse),d=[...e.toolPanels.values()].sort((u,f)=>(u.order??100)-(f.order??100)),h=d.length===1;let p="";for(const u of d){const f=e.expandedSections.has(u.id),w=u.icon?`<span class="tbw-accordion-icon">${u.icon}</span>`:"",v=h?"":`<span class="tbw-accordion-chevron">${f?a:l}</span>`;p+=`
12
12
  <div class="${`tbw-accordion-section${f?" expanded":""}${h?" single":""}`}" data-section="${u.id}">
13
13
  <button class="tbw-accordion-header" aria-expanded="${f}" aria-controls="tbw-section-${u.id}"${h?' aria-disabled="true"':""}>
14
14
  ${w}
@@ -40,8 +40,8 @@
40
40
  </div>
41
41
  ${c}
42
42
  </div>
43
- `}function le(t,e){const o=t.querySelector("tbw-grid-header");if(!o)return;o.style.display="none";const n=o.querySelectorAll("tbw-grid-header-content");e.lightDomHeaderContent=Array.from(n),e.lightDomHeaderContent.forEach(s=>{s.setAttribute("slot","header-content")});const i=o.querySelectorAll("tbw-grid-tool-button");e.lightDomButtons=Array.from(i),e.lightDomButtons.sort((s,r)=>{const l=parseInt(s.getAttribute("order")??"100",10),a=parseInt(r.getAttribute("order")??"100",10);return l-a}),e.lightDomButtons.forEach(s=>{s.setAttribute("slot","toolbar")})}function Ge(t,e,o,n){const i=t.querySelector(".tbw-shell-toolbar");i&&i.addEventListener("click",r=>{const l=r.target;if(l.closest("[data-panel-toggle]")){n.onPanelToggle();return}const d=l.closest("[data-btn]");if(d){const h=d.getAttribute("data-btn");h&&n.onToolbarButtonClick(h)}});const s=t.querySelector(".tbw-accordion");s&&s.addEventListener("click",r=>{const a=r.target.closest(".tbw-accordion-header");if(a){const h=a.closest("[data-section]")?.getAttribute("data-section");h&&n.onSectionToggle(h)}})}function We(t,e,o){const n=t.querySelector(".tbw-tool-panel"),i=t.querySelector("[data-resize-handle]"),s=t.querySelector(".tbw-shell-body");if(!n||!i||!s)return()=>{};const r=e?.toolPanel?.position??"right",l=200;let a=0,d=0,h=0,p=!1;const b=f=>{if(!p)return;f.preventDefault();const w=r==="left"?f.clientX-a:a-f.clientX,v=Math.min(h,Math.max(l,d+w));n.style.width=`${v}px`},c=()=>{if(!p)return;p=!1,i.classList.remove("resizing"),n.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const f=n.getBoundingClientRect().width;o(f),document.removeEventListener("mousemove",b),document.removeEventListener("mouseup",c)},u=f=>{f.preventDefault(),p=!0,a=f.clientX,d=n.getBoundingClientRect().width,h=s.getBoundingClientRect().width-20,i.classList.add("resizing"),n.style.transition="none",document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",b),document.addEventListener("mouseup",c)};return i.addEventListener("mousedown",u),()=>{i.removeEventListener("mousedown",u),document.removeEventListener("mousemove",b),document.removeEventListener("mouseup",c)}}function Fe(t,e,o){const n=[...e?.header?.toolbarButtons??[],...o.toolbarButtons.values()];for(const i of n){const s=t.querySelector(`[data-btn-slot="${i.id}"]`);if(!s)continue;const r=o.toolbarButtonCleanups.get(i.id);if(r&&(r(),o.toolbarButtonCleanups.delete(i.id)),i.element)s.appendChild(i.element);else if(i.render){const l=i.render(s);l&&o.toolbarButtonCleanups.set(i.id,l)}}}function ae(t,e){const o=t.querySelector(".tbw-shell-content");if(!o)return;const n=[...e.headerContents.values()].sort((s,r)=>(s.order??100)-(r.order??100)),i=o.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 l=o.querySelector(`[data-header-content="${s.id}"]`);l||(l=document.createElement("div"),l.setAttribute("data-header-content",s.id),i?o.insertBefore(l,i):o.appendChild(l));const a=s.render(l);a&&e.headerContentCleanups.set(s.id,a)}}function Ue(t,e,o){if(!e.isPanelOpen)return;const n=B(o?.expand??P.expand),i=B(o?.collapse??P.collapse);for(const[s,r]of e.toolPanels){const l=e.expandedSections.has(s),a=t.querySelector(`[data-section="${s}"]`),d=a?.querySelector(".tbw-accordion-content");if(!a||!d)continue;a.classList.toggle("expanded",l);const h=a.querySelector(".tbw-accordion-header");h&&h.setAttribute("aria-expanded",String(l));const p=a.querySelector(".tbw-accordion-chevron");if(p&&(p.innerHTML=l?i:n),l){if(d.children.length===0){const b=r.render(d);b&&e.panelCleanups.set(s,b)}}else{const b=e.panelCleanups.get(s);b&&(b(),e.panelCleanups.delete(s)),d.innerHTML=""}}}function ce(t,e){const o=t.querySelector("[data-panel-toggle]");o&&(o.classList.toggle("active",e.isPanelOpen),o.setAttribute("aria-pressed",String(e.isPanelOpen)))}function de(t,e){const o=t.querySelector(".tbw-tool-panel");o&&(o.classList.toggle("open",e.isPanelOpen),e.isPanelOpen||(o.style.width=""))}function Xe(t,e){const o=[];for(const n of t?.header?.toolbarButtons??[])o.push({id:n.id,label:n.label,disabled:n.disabled??!1,source:"config"});for(const n of e.toolbarButtons.values())o.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");o.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())o.push({id:`panel-toggle-${n.id}`,label:n.tooltip??n.title,disabled:!1,source:"panel-toggle",panelId:n.id});return o}function je(t){for(const e of t.headerContentCleanups.values())e();t.headerContentCleanups.clear(),t.activePanelCleanup&&(t.activePanelCleanup(),t.activePanelCleanup=null);for(const e of t.toolbarButtonCleanups.values())e();t.toolbarButtonCleanups.clear(),t.activePanel&&t.toolPanels.get(t.activePanel)?.onClose?.(),t.toolPanels.clear(),t.headerContents.clear(),t.toolbarButtons.clear(),t.lightDomButtons=[],t.lightDomHeaderContent=[],t.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 o of e)this.attach(o)}attach(e){if(this.pluginMap.set(e.constructor,e),this.plugins.push(e),e.cellRenderers)for(const[o,n]of Object.entries(e.cellRenderers))this.cellRenderers.set(o,n);if(e.headerRenderers)for(const[o,n]of Object.entries(e.headerRenderers))this.headerRenderers.set(o,n);if(e.cellEditors)for(const[o,n]of Object.entries(e.cellEditors))this.cellEditors.set(o,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(o=>o.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 o=[...e];for(const n of this.plugins)n.processRows&&(o=n.processRows(o));return o}processColumns(e){let o=[...e];for(const n of this.plugins)n.processColumns&&(o=n.processColumns(o));return o}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 o of this.plugins)typeof o.getExtraHeight=="function"&&(e+=o.getExtraHeight());return e}getExtraHeightBefore(e){let o=0;for(const n of this.plugins)typeof n.getExtraHeightBefore=="function"&&(o+=n.getExtraHeightBefore(e));return o}adjustVirtualStart(e,o,n){let i=e;for(const s of this.plugins)if(typeof s.adjustVirtualStart=="function"){const r=s.adjustVirtualStart(e,o,n);r<i&&(i=r)}return i}renderRow(e,o,n){for(const i of this.plugins)if(i.renderRow?.(e,o,n))return!0;return!1}onKeyDown(e){for(const o of this.plugins)if(o.onKeyDown?.(e))return!0;return!1}onCellClick(e){for(const o of this.plugins)if(o.onCellClick?.(e))return!0;return!1}onRowClick(e){for(const o of this.plugins)if(o.onRowClick?.(e))return!0;return!1}onHeaderClick(e){for(const o of this.plugins)if(o.onHeaderClick?.(e))return!0;return!1}onScroll(e){for(const o of this.plugins)o.onScroll?.(e)}onCellMouseDown(e){for(const o of this.plugins)if(o.onCellMouseDown?.(e))return!0;return!1}onCellMouseMove(e){for(const o of this.plugins)if(o.onCellMouseMove?.(e))return!0;return!1}onCellMouseUp(e){for(const o of this.plugins)if(o.onCellMouseUp?.(e))return!0;return!1}getContextMenuItems(e){const o=[];for(const n of this.plugins){const i=n.getContextMenuItems?.(e);i&&o.push(...i)}return o}getToolPanels(){const e=[];for(const o of this.plugins){const n=o.getToolPanel?.();n&&e.push({plugin:o,panel:n})}return e.sort((o,n)=>(o.panel.order??0)-(n.panel.order??0))}getHeaderContents(){const e=[];for(const o of this.plugins){const n=o.getHeaderContent?.();n&&e.push({plugin:o,content:n})}return e.sort((o,n)=>(o.content.order??0)-(n.content.order??0))}}class V extends HTMLElement{static tagName="tbw-grid";#n;#k=!1;#I;#$;#s=[];#r;#p;#m;#v;#o={};#h=!1;#f=0;#E=null;#C=!1;#P;#y=!1;#_=null;#R=null;#S=null;#A=null;#l;#b;#t;#O;#d;#e=Ie();#a=!1;#x;_rows=[];#H=[];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 o=this.#s;this.#s=e,o!==e&&this.#ee()}get sourceRows(){return this.#s}get columns(){return[...this._columns]}set columns(e){const o=this.#r;this.#r=e,o!==e&&this.#te()}get gridConfig(){return this.#o}set gridConfig(e){const o=this.#p;this.#p=e,o!==e&&this.#oe()}get fitMode(){return this.#o.fitMode??"stretch"}set fitMode(e){const o=this.#m;this.#m=e,o!==e&&this.#J()}get editOn(){return this.#o.editOn}set editOn(e){const o=this.#v;this.#v=e,o!==e&&this.#Q()}get effectiveConfig(){return this.#o}get disconnectSignal(){return this.#l||(this.#l=new AbortController),this.#l.signal}constructor(){super(),this.#n=this.attachShadow({mode:"open"}),this.#j(),this.#I=new Promise(e=>this.#$=e)}#j(){const e=new CSSStyleSheet;e.replaceSync(q),this.#n.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.#w()}#B(){this.#t=new ue(this);const e=this.#o?.plugins,o=Array.isArray(e)?e:[];this.#t.attachAll(o)}#V(){const e=this.#t?.getAllStyles()??"";if(e){const o=document.createElement("style");o.setAttribute("data-plugin","all"),o.textContent=e,this.#n.appendChild(o)}}#G(){this.#t&&this.#t.detachAll(),this.#B(),this.#V(),this.#C=this.#t?.getAll().some(e=>e.onScroll)??!1}#K(){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 o=this.#t.getHeaderContents();for(const{content:n}of o)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.#s)?[...this.#s]:[],this.#l?.abort(),this.#l=new AbortController,this.#u(),this.#B(),this.#Y(),this.#k||(this.#X(),this.#V(),this.#k=!0),this.#W()}disconnectedCallback(){this.#K(),je(this.#e),this.#a=!1,this.#x?.(),this.#x=void 0,this.#l&&(this.#l.abort(),this.#l=void 0),this.resizeController&&this.resizeController.dispose(),this.#b&&(this.#b.disconnect(),this.#b=void 0),this.#h=!1}#W(){const o=this.#n.querySelector(".tbw-grid-content")??this.#n.querySelector(".tbw-grid-root");if(this.headerRowEl=o?.querySelector(".header-row"),this.virtualization.totalHeightEl=o?.querySelector(".faux-vscroll-spacer"),this.virtualization.viewportEl=o?.querySelector(".rows-viewport"),this.bodyEl=o?.querySelector(".rows"),this.#a){ae(this.#n,this.#e),Fe(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.#h=!0;const n=this.disconnectSignal;this.#c(),this.addEventListener("keydown",r=>He(this,r),{signal:n}),document.addEventListener("keydown",r=>{r.key==="Escape"&&this.activeEditRows!==-1&&this.#z(this.activeEditRows,!0)},{capture:!0,signal:n}),document.addEventListener("mousedown",r=>{if(this.activeEditRows===-1)return;const l=this.findRenderedRowElement(this.activeEditRows);!l||(r.composedPath&&r.composedPath()||[]).includes(l)||this.#z(this.activeEditRows,!1)},{signal:n});const i=o?.querySelector(".faux-vscroll"),s=o?.querySelector(".rows");if(this.virtualization.container=i??this,this.#C=this.#t?.getAll().some(r=>r.onScroll)??!1,i&&s){i.addEventListener("scroll",()=>{if(!this.virtualization.enabled&&!this.#C)return;const a=i.scrollTop,d=this.virtualization.rowHeight,h=Math.floor(a/d),p=h-h%2,b=-(a-p*d);s.style.transform=`translateY(${b}px)`,this.#E=a,this.#f||(this.#f=requestAnimationFrame(()=>{this.#f=0,this.#E!==null&&(this.#re(this.#E),this.#E=null)}))},{passive:!0,signal:n});const r=this.#n.querySelector(".tbw-grid-content"),l=this.#n.querySelector(".tbw-scroll-area");r&&(r.addEventListener("wheel",a=>{a.preventDefault(),a.shiftKey||Math.abs(a.deltaX)>Math.abs(a.deltaY)?l&&(l.scrollLeft+=a.shiftKey?a.deltaY:a.deltaX):i.scrollTop+=a.deltaY},{passive:!1,signal:n}),r.addEventListener("touchstart",a=>{a.touches.length===1&&(this.#_=a.touches[0].clientY,this.#R=a.touches[0].clientX,this.#S=i.scrollTop,this.#A=l?.scrollLeft??0)},{passive:!0,signal:n}),r.addEventListener("touchmove",a=>{if(a.touches.length===1&&this.#_!==null&&this.#R!==null&&this.#S!==null&&this.#A!==null){const d=this.#_-a.touches[0].clientY,h=this.#R-a.touches[0].clientX;i.scrollTop=this.#S+d,l&&(l.scrollLeft=this.#A+h),a.preventDefault()}},{passive:!1,signal:n}),r.addEventListener("touchend",()=>{this.#_=null,this.#R=null,this.#S=null,this.#A=null},{passive:!0,signal:n}))}this.resizeController=qe(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 l=r.getBoundingClientRect().height;l&&Math.abs(l-this.virtualization.rowHeight)>.1&&(this.virtualization.rowHeight=l,this.refreshVirtualWindow(!0))}}),this.virtualization.viewportEl&&(this.#b=new ResizeObserver(()=>{this.#f||(this.#f=requestAnimationFrame(()=>{this.#f=0,this.refreshVirtualWindow(!0)}))}),this.#b.observe(this.virtualization.viewportEl)),queueMicrotask(()=>this.#Z()),requestAnimationFrame(()=>requestAnimationFrame(()=>this.#$?.()))}#i(e,o){this.dispatchEvent(new CustomEvent(e,{detail:o,bubbles:!0,composed:!0}))}emitCellCommit(e){this.#i("cell-commit",e)}emitRowCommit(e){this.#i("row-commit",e)}emitSortChange(e){this.#i("sort-change",e)}emitColumnResize(e){this.#i("column-resize",e)}emitActivateCell(e){this.#i("activate-cell",e)}#Z(){this.bodyEl?.querySelectorAll(".data-grid-row")?.forEach((o,n)=>{const i=n===this.focusRow;o.setAttribute("aria-selected",String(i)),o.querySelectorAll(".cell").forEach((s,r)=>{s.setAttribute("aria-selected",String(i&&r===this.focusCol))})})}#J(){if(!this.#h)return;this.#u(),this.#o.fitMode==="fixed"?(this.__didInitialAutoSize=!1,this.#F()):(this._columns.forEach(o=>{!o.__userResized&&o.__autoSized&&delete o.width}),this.updateTemplate())}#Q(){this.#h&&(this.#u(),this.rowPool.length=0,this.bodyEl&&(this.bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.refreshVirtualWindow(!0))}#ee(){this._rows=Array.isArray(this.#s)?[...this.#s]:[],this.#L(),!this.#r||Array.isArray(this.#r)&&this.#r.length===0?this.#c():this.refreshVirtualWindow(!0)}#te(){X(this),this.#h&&(this.#u(),this.#c())}#oe(){this.#h&&(this.#u(),this.#G(),this.#L(),this.#M(),this.#T(),this.updateTemplate(),this.refreshVirtualWindow(!0))}#ne(){ke(this)}#T(){Y(this)}updateTemplate(){ne(this)}#F(){Pe(this)}#M(){if(this.#t){const e=this.#H.length>0?this.#H:this._columns,o=e.filter(s=>!s.hidden),n=e.filter(s=>s.hidden),i=this.#t.processColumns([...o]);if(i!==o){const s=new Map(i.map((l,a)=>[l.field,{col:l,order:a}]));if(!o.some(l=>s.has(l.field))&&i.length>0)this._columns=[...i,...n];else{const l=e.map(a=>{if(a.hidden)return a;const d=s.get(a.field);return d?d.col:a});this._columns=l}}else this._columns=[...e]}}#w(){this.#t?.afterRender()}#L(){X(this);const e=Array.isArray(this.#s)?[...this.#s]:[],o=this.#t?.processRows(e)??e;this._rows=o}#u(){const e=this.#p?{...this.#p}:{};let o=Array.isArray(e.columns)?[...e.columns]:[];const n=(this.__lightDomColumnsCache||[]).map(i=>({...i}));if(n.length){const i={};o.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)):(o.push(s),i[s.field]=s)})}if(this.#r&&this.#r.length&&(o=[...this.#r]),(!o||o.length===0)&&this._rows.length&&(o=Q(this._rows).columns),o.length){o.forEach(r=>{r.sortable===void 0&&(r.sortable=!0),r.resizable===void 0&&(r.resizable=!0)});const i=this.#o.columns;i?.some(r=>r.__compiledView||r.__compiledEditor)?e.columns=i:e.columns=o}else{const i=this.#o.columns;i?.some(s=>s.__compiledView||s.__compiledEditor)&&(e.columns=i)}this.#m&&(e.fitMode=this.#m),e.fitMode||(e.fitMode="stretch"),this.#v&&(e.editOn=this.#v),e.columnState&&!this.#d&&(this.#d=e.columnState),this.#o=e,e.fitMode==="fixed"&&this._columns.forEach(i=>{i.width==null&&(i.width=80)})}#D(e,o,n=this.__rowRenderEpoch){this.#P||(this.#P=(i,s,r)=>this.#t?.renderRow(i,s,r)??!1),ze(this,e,o,n,this.#P)}#ie(e,o){N(this,e,o)}#z(e,o){$(this,e,o)}#c(){if(!this.isConnected||!this.headerRowEl||!this.bodyEl)return;const e=this.#p?.columns||this.#r||[];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.#ne(),this.#u(),this.#G(),this.#H=[...this._columns],this.#L(),this.#M(),this.#d){const n=this.#d;this.#d=void 0,this.#U(n)}this.#T(),this.updateTemplate(),this.refreshVirtualWindow(!0),this.#o.fitMode==="fixed"&&!this.__didInitialAutoSize&&requestAnimationFrame(()=>this.#F()),this.bodyEl&&(this.bodyEl.style.display="",this.bodyEl.style.gridTemplateColumns=""),queueMicrotask(()=>this.#w())}#U(e){const o=this.#o.columns??[],n=this.#t?.getAll()??[];be(this,e,o,n);for(const i of e.columns){const s=o.find(r=>r.field===i.field);s&&(s.hidden=!i.visible)}}#se(){return this._rows.length<=this.virtualization.bypassThreshold}#re(e){if(this.refreshVirtualWindow(!1),this.#t?.onScrollRender(),this.#C){const o=this.virtualization.container,n={scrollTop:e,scrollLeft:o?.scrollLeft??0,scrollHeight:o?.scrollHeight??0,scrollWidth:o?.scrollWidth??0,clientHeight:o?.clientHeight??0,clientWidth:o?.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(o=>{const n=o.querySelector(".cell[data-row]");return n&&Number(n.getAttribute("data-row"))===e})||null}dispatchCellClick(e,o,n,i){const s=this._rows[o],r=this._columns[n];if(!s||!r)return!1;const l={row:s,rowIndex:o,colIndex:n,field:r.field,value:s[r.field],cellEl:i,originalEvent:e};return this.#t?.onCellClick(l)??!1}dispatchHeaderClick(e,o,n){const i=this._columns[o];if(!i)return!1;const s={colIndex:o,field:i.field,column:i,headerEl:n,originalEvent:e};return this.#t?.onHeaderClick(s)??!1}dispatchKeyDown(e){return this.#t?.onKeyDown(e)??!1}#N(e,o){let n=null;const i=e.composedPath?.();if(i&&i.length>0?n=i[0]:n=e.target,n&&!this.#n.contains(n)){const u=this.#n.elementFromPoint(e.clientX,e.clientY);u&&(n=u)}const s=n?.closest?.("[data-col]"),r=n?.closest?.(".data-grid-row"),l=n?.closest?.(".header-row");let a,d,h,p,b,c;return s&&(a=parseInt(s.getAttribute("data-row")??"-1",10),d=parseInt(s.getAttribute("data-col")??"-1",10),a>=0&&d>=0&&(h=this._rows[a],c=this._columns[d],p=c?.field,b=h&&p?h[p]:void 0)),{type:o,row:h,rowIndex:a!==void 0&&a>=0?a:void 0,colIndex:d!==void 0&&d>=0?d:void 0,field:p,value:b,column:c,originalEvent:e,cellElement:s??void 0,rowElement:r??void 0,isHeader:!!l,cell:a!==void 0&&d!==void 0&&a>=0&&d>=0?{row:a,col:d}:void 0}}#le(e){const o=this.#N(e,"mousedown");(this.#t?.onCellMouseDown(o)??!1)&&(this.#y=!0)}#ae(e){if(!this.#y)return;const o=this.#N(e,"mousemove");this.#t?.onCellMouseMove(o)}#ce(e){if(!this.#y)return;const o=this.#N(e,"mouseup");this.#t?.onCellMouseUp(o),this.#y=!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.#i("changed-rows-reset",{rows:this.changedRows,indices:this.changedRowIndices}),this.rowPool.forEach(o=>o.classList.remove("changed"))}async beginBulkEdit(e){if(!this._columns.some(s=>s.editable))return;const n=this._rows[e];this.#ie(e,n);const i=this.findRenderedRowElement?.(e);i&&(Array.from(i.children).forEach((s,r)=>{const l=this.visibleColumns[r];if(l?.editable){const a=s;a.classList.contains("editing")||M(this,n,e,l,a)}}),queueMicrotask(()=>{const s=i.querySelector(`.cell[data-col="${this.focusCol}"]`);if(s?.classList.contains("editing")){const r=s.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');try{r?.focus()}catch{}}}))}async commitActiveRowEdit(){this.activeEditRows!==-1&&this.#z(this.activeEditRows,!1)}async ready(){return this.#I}async forceLayout(){this.#c(),await new Promise(e=>requestAnimationFrame(()=>requestAnimationFrame(e)))}async getConfig(){return Object.freeze({...this.#o||{}})}setColumnVisible(e,o){const n=this.#o.columns,i=n?.find(l=>l.field===e);if(!i||!o&&i.lockVisible||!o&&(n??[]).filter(a=>!a.hidden&&a.field!==e).length===0)return!1;const s=!!i.hidden,r=!o;return s!==r?(i.hidden=r,this.#i("column-visibility",{field:e,visible:o,visibleColumns:(n??[]).filter(l=>!l.hidden).map(l=>l.field)}),this.rowPool.length=0,this.bodyEl&&(this.bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.#c(),this.requestStateChange(),!0):!1}toggleColumnVisibility(e){const i=!!this.#o.columns?.find(s=>s.field===e)?.hidden;return this.setColumnVisible(e,i)}isColumnVisible(e){const n=this.#o.columns?.find(i=>i.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.#i("column-visibility",{visibleColumns:(e??[]).map(n=>n.field)}),this.rowPool.length=0,this.bodyEl&&(this.bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.#c(),this.requestStateChange())}getAllColumns(){return(this.#o.columns??[]).map(o=>({field:o.field,header:o.header||o.field,visible:!o.hidden,lockVisible:o.lockVisible}))}setColumnOrder(e){if(!e.length)return;const o=new Map(this._columns.map(i=>[i.field,i])),n=[];for(const i of e){const s=o.get(i);s&&(n.push(s),o.delete(i))}for(const i of o.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 J(this,e)}set columnState(e){e&&(this.#d=e,this.#k&&this.#de(e))}get columnState(){return this.getColumnState()}#de(e){(this.#o.columns??[]).forEach(n=>{n.hidden=!1}),this.#U(e),this.#c()}requestStateChange(){this.#O||(this.#O=we(this,()=>this.#t?.getAll()??[],e=>this.#i("column-state-change",e))),this.#O()}resetColumnState(){this.#d=void 0,(this.#o.columns??[]).forEach(n=>{n.hidden=!1}),this.sortState=null,this.__originalOrder=[],this.#u(),this.#c();const o=this.#t?.getAll()??[];for(const n of o)if(n.applyColumnState)for(const i of this._columns)n.applyColumnState(i.field,{field:i.field,order:0,visible:!0});this.requestStateChange()}get isToolPanelOpen(){return this.#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((i,s)=>(i.order??100)-(s.order??100))[0];n&&this.#e.expandedSections.add(n.id)}ce(this.#n,this.#e),de(this.#n,this.#e);const e={expand:this.#o?.icons?.expand??P.expand,collapse:this.#o?.icons?.collapse??P.collapse};Ue(this.#n,this.#e,e),this.#i("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,ce(this.#n,this.#e),de(this.#n,this.#e),this.#i("tool-panel-close",{})}}toggleToolPanel(){this.#e.isPanelOpen?this.closeToolPanel():this.openToolPanel()}toggleToolPanelSection(e){const o=this.#e.toolPanels.get(e);if(!o){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 i=this.#e.panelCleanups.get(e);i&&(i(),this.#e.panelCleanups.delete(e)),o.onClose?.(),this.#e.expandedSections.delete(e),this.#q(e,!1)}else{for(const[i,s]of this.#e.toolPanels)if(i!==e&&this.#e.expandedSections.has(i)){const r=this.#e.panelCleanups.get(i);r&&(r(),this.#e.panelCleanups.delete(i)),s.onClose?.(),this.#e.expandedSections.delete(i),this.#q(i,!1);const l=this.#n.querySelector(`[data-section="${i}"] .tbw-accordion-content`);l&&(l.innerHTML="")}this.#e.expandedSections.add(e),this.#q(e,!0),this.#ue(e)}this.#i("tool-panel-section-toggle",{id:e,expanded:!n})}#q(e,o){const n=this.#n.querySelector(`[data-section="${e}"]`);n&&n.classList.toggle("expanded",o)}#ue(e){const o=this.#e.toolPanels.get(e);if(!o?.render)return;const n=this.#n.querySelector(`[data-section="${e}"] .tbw-accordion-content`);if(!n)return;const i=o.render(n);i&&this.#e.panelCleanups.set(e,i)}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.#a&&this.#g()}unregisterToolPanel(e){this.#e.activePanel===e&&this.closeToolPanel(),this.#e.toolPanels.delete(e),this.#a&&this.#g()}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.#a&&ae(this.#n,this.#e)}unregisterHeaderContent(e){const o=this.#e.headerContentCleanups.get(e);o&&(o(),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 Xe(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.#a&&this.#g()}unregisterToolbarButton(e){const o=this.#e.toolbarButtonCleanups.get(e);o&&(o(),this.#e.toolbarButtonCleanups.delete(e)),this.#e.toolbarButtons.delete(e),this.#a&&this.#g()}setToolbarButtonDisabled(e,o){const n=this.#e.toolbarButtons.get(e);n&&(n.disabled=o);const i=this.#n.querySelector(`[data-btn="${e}"]`);i&&(i.disabled=o)}refreshShellHeader(){this.#g()}#g(){le(this,this.#e),this.#X(),this.#W()}refreshVirtualWindow(e=!1){if(!this.bodyEl)return;const o=this._rows.length;if(!this.virtualization.enabled){this.#D(0,o),this.#w();return}if(this.#se()){this.virtualization.start=0,this.virtualization.end=o,this.bodyEl.style.transform="translateY(0px)",this.#D(0,o,this.__rowRenderEpoch),this.virtualization.totalHeightEl&&(this.virtualization.totalHeightEl.style.height=`${o*this.virtualization.rowHeight}px`);const S=this.#n.querySelector(".rows-body");S?.setAttribute("aria-rowcount",String(o)),S?.setAttribute("aria-colcount",String(this.visibleColumns.length)),this.#w();return}const n=this.virtualization.container??this,s=(this.virtualization.viewportEl??n).clientHeight,r=this.virtualization.rowHeight,l=n.scrollTop;let a=Math.floor(l/r),d=0;const h=10;for(;d<h;){const S=this.#t?.getExtraHeightBefore?.(a)??0,L=Math.floor((l-S)/r);if(L>=a||L<0)break;a=L,d++}a=a-a%2,a<0&&(a=0);const p=this.#t?.adjustVirtualStart(a,l,r);p!==void 0&&p<a&&(a=p,a=a-a%2,a<0&&(a=0));const b=Math.ceil(s/r)+3;let c=a+b;c>o&&(c=o),this.virtualization.start=a,this.virtualization.end=c;const f=this.#n.querySelector(".tbw-footer")?.offsetHeight??0,w=this.#t?.getExtraHeight()??0;this.virtualization.totalHeightEl&&(this.virtualization.totalHeightEl.style.height=`${o*r+r+f+w}px`);const v=this.#t?.getExtraHeightBefore?.(a)??0,A=-(l-a*r-v);this.bodyEl.style.transform=`translateY(${A}px)`,this.#D(a,c,e?++this.__rowRenderEpoch:this.__rowRenderEpoch);const x=this.#n.querySelector(".rows-body");x?.setAttribute("aria-rowcount",String(o)),x?.setAttribute("aria-colcount",String(this.visibleColumns.length)),e&&this.#w()}#X(){le(this,this.#e);const e=this.#o?.shell,o=$e(e,this.#e),n=`
43
+ `}function ae(t,e){const o=t.querySelector("tbw-grid-header");if(!o)return;o.style.display="none";const n=o.querySelectorAll("tbw-grid-header-content");e.lightDomHeaderContent=Array.from(n),e.lightDomHeaderContent.forEach(s=>{s.setAttribute("slot","header-content")});const i=o.querySelectorAll("tbw-grid-tool-button");e.lightDomButtons=Array.from(i),e.lightDomButtons.sort((s,r)=>{const l=parseInt(s.getAttribute("order")??"100",10),a=parseInt(r.getAttribute("order")??"100",10);return l-a}),e.lightDomButtons.forEach(s=>{s.setAttribute("slot","toolbar")})}function We(t,e,o,n){const i=t.querySelector(".tbw-shell-toolbar");i&&i.addEventListener("click",r=>{const l=r.target;if(l.closest("[data-panel-toggle]")){n.onPanelToggle();return}const d=l.closest("[data-btn]");if(d){const h=d.getAttribute("data-btn");h&&n.onToolbarButtonClick(h)}});const s=t.querySelector(".tbw-accordion");s&&s.addEventListener("click",r=>{const a=r.target.closest(".tbw-accordion-header");if(a){const h=a.closest("[data-section]")?.getAttribute("data-section");h&&n.onSectionToggle(h)}})}function Fe(t,e,o){const n=t.querySelector(".tbw-tool-panel"),i=t.querySelector("[data-resize-handle]"),s=t.querySelector(".tbw-shell-body");if(!n||!i||!s)return()=>{};const r=e?.toolPanel?.position??"right",l=200;let a=0,d=0,h=0,p=!1;const b=f=>{if(!p)return;f.preventDefault();const w=r==="left"?f.clientX-a:a-f.clientX,v=Math.min(h,Math.max(l,d+w));n.style.width=`${v}px`},c=()=>{if(!p)return;p=!1,i.classList.remove("resizing"),n.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const f=n.getBoundingClientRect().width;o(f),document.removeEventListener("mousemove",b),document.removeEventListener("mouseup",c)},u=f=>{f.preventDefault(),p=!0,a=f.clientX,d=n.getBoundingClientRect().width,h=s.getBoundingClientRect().width-20,i.classList.add("resizing"),n.style.transition="none",document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",b),document.addEventListener("mouseup",c)};return i.addEventListener("mousedown",u),()=>{i.removeEventListener("mousedown",u),document.removeEventListener("mousemove",b),document.removeEventListener("mouseup",c)}}function Ue(t,e,o){const n=[...e?.header?.toolbarButtons??[],...o.toolbarButtons.values()];for(const i of n){const s=t.querySelector(`[data-btn-slot="${i.id}"]`);if(!s)continue;const r=o.toolbarButtonCleanups.get(i.id);if(r&&(r(),o.toolbarButtonCleanups.delete(i.id)),i.element)s.appendChild(i.element);else if(i.render){const l=i.render(s);l&&o.toolbarButtonCleanups.set(i.id,l)}}}function ce(t,e){const o=t.querySelector(".tbw-shell-content");if(!o)return;const n=[...e.headerContents.values()].sort((s,r)=>(s.order??100)-(r.order??100)),i=o.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 l=o.querySelector(`[data-header-content="${s.id}"]`);l||(l=document.createElement("div"),l.setAttribute("data-header-content",s.id),i?o.insertBefore(l,i):o.appendChild(l));const a=s.render(l);a&&e.headerContentCleanups.set(s.id,a)}}function Xe(t,e,o){if(!e.isPanelOpen)return;const n=V(o?.expand??P.expand),i=V(o?.collapse??P.collapse);for(const[s,r]of e.toolPanels){const l=e.expandedSections.has(s),a=t.querySelector(`[data-section="${s}"]`),d=a?.querySelector(".tbw-accordion-content");if(!a||!d)continue;a.classList.toggle("expanded",l);const h=a.querySelector(".tbw-accordion-header");h&&h.setAttribute("aria-expanded",String(l));const p=a.querySelector(".tbw-accordion-chevron");if(p&&(p.innerHTML=l?i:n),l){if(d.children.length===0){const b=r.render(d);b&&e.panelCleanups.set(s,b)}}else{const b=e.panelCleanups.get(s);b&&(b(),e.panelCleanups.delete(s)),d.innerHTML=""}}}function de(t,e){const o=t.querySelector("[data-panel-toggle]");o&&(o.classList.toggle("active",e.isPanelOpen),o.setAttribute("aria-pressed",String(e.isPanelOpen)))}function ue(t,e){const o=t.querySelector(".tbw-tool-panel");o&&(o.classList.toggle("open",e.isPanelOpen),e.isPanelOpen||(o.style.width=""))}function je(t,e){const o=[];for(const n of t?.header?.toolbarButtons??[])o.push({id:n.id,label:n.label,disabled:n.disabled??!1,source:"config"});for(const n of e.toolbarButtons.values())o.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");o.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())o.push({id:`panel-toggle-${n.id}`,label:n.tooltip??n.title,disabled:!1,source:"panel-toggle",panelId:n.id});return o}function Ke(t){for(const e of t.headerContentCleanups.values())e();t.headerContentCleanups.clear(),t.activePanelCleanup&&(t.activePanelCleanup(),t.activePanelCleanup=null);for(const e of t.toolbarButtonCleanups.values())e();t.toolbarButtonCleanups.clear(),t.activePanel&&t.toolPanels.get(t.activePanel)?.onClose?.(),t.toolPanels.clear(),t.headerContents.clear(),t.toolbarButtons.clear(),t.lightDomButtons=[],t.lightDomHeaderContent=[],t.activePanel=null}class he{constructor(e){this.grid=e}plugins=[];pluginMap=new Map;cellRenderers=new Map;headerRenderers=new Map;cellEditors=new Map;attachAll(e){for(const o of e)this.attach(o)}attach(e){if(this.pluginMap.set(e.constructor,e),this.plugins.push(e),e.cellRenderers)for(const[o,n]of Object.entries(e.cellRenderers))this.cellRenderers.set(o,n);if(e.headerRenderers)for(const[o,n]of Object.entries(e.headerRenderers))this.headerRenderers.set(o,n);if(e.cellEditors)for(const[o,n]of Object.entries(e.cellEditors))this.cellEditors.set(o,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(o=>o.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 o=[...e];for(const n of this.plugins)n.processRows&&(o=n.processRows(o));return o}processColumns(e){let o=[...e];for(const n of this.plugins)n.processColumns&&(o=n.processColumns(o));return o}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 o of this.plugins)typeof o.getExtraHeight=="function"&&(e+=o.getExtraHeight());return e}getExtraHeightBefore(e){let o=0;for(const n of this.plugins)typeof n.getExtraHeightBefore=="function"&&(o+=n.getExtraHeightBefore(e));return o}adjustVirtualStart(e,o,n){let i=e;for(const s of this.plugins)if(typeof s.adjustVirtualStart=="function"){const r=s.adjustVirtualStart(e,o,n);r<i&&(i=r)}return i}renderRow(e,o,n){for(const i of this.plugins)if(i.renderRow?.(e,o,n))return!0;return!1}onKeyDown(e){for(const o of this.plugins)if(o.onKeyDown?.(e))return!0;return!1}onCellClick(e){for(const o of this.plugins)if(o.onCellClick?.(e))return!0;return!1}onRowClick(e){for(const o of this.plugins)if(o.onRowClick?.(e))return!0;return!1}onHeaderClick(e){for(const o of this.plugins)if(o.onHeaderClick?.(e))return!0;return!1}onScroll(e){for(const o of this.plugins)o.onScroll?.(e)}onCellMouseDown(e){for(const o of this.plugins)if(o.onCellMouseDown?.(e))return!0;return!1}onCellMouseMove(e){for(const o of this.plugins)if(o.onCellMouseMove?.(e))return!0;return!1}onCellMouseUp(e){for(const o of this.plugins)if(o.onCellMouseUp?.(e))return!0;return!1}getContextMenuItems(e){const o=[];for(const n of this.plugins){const i=n.getContextMenuItems?.(e);i&&o.push(...i)}return o}getToolPanels(){const e=[];for(const o of this.plugins){const n=o.getToolPanel?.();n&&e.push({plugin:o,panel:n})}return e.sort((o,n)=>(o.panel.order??0)-(n.panel.order??0))}getHeaderContents(){const e=[];for(const o of this.plugins){const n=o.getHeaderContent?.();n&&e.push({plugin:o,content:n})}return e.sort((o,n)=>(o.content.order??0)-(n.content.order??0))}}class D extends HTMLElement{static tagName="tbw-grid";static version=typeof __GRID_VERSION__<"u"?__GRID_VERSION__:"dev";#n;#k=!1;#q;#$;#s=[];#r;#p;#m;#v;#o={};#h=!1;#f=0;#E=null;#C=!1;#P;#y=!1;#_=null;#R=null;#S=null;#A=null;#l;#b;#t;#O;#d;#e=$e();#a=!1;#x;_rows=[];#H=[];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 o=this.#s;this.#s=e,o!==e&&this.#ee()}get sourceRows(){return this.#s}get columns(){return[...this._columns]}set columns(e){const o=this.#r;this.#r=e,o!==e&&this.#te()}get gridConfig(){return this.#o}set gridConfig(e){const o=this.#p;this.#p=e,o!==e&&this.#oe()}get fitMode(){return this.#o.fitMode??"stretch"}set fitMode(e){const o=this.#m;this.#m=e,o!==e&&this.#J()}get editOn(){return this.#o.editOn}set editOn(e){const o=this.#v;this.#v=e,o!==e&&this.#Q()}get effectiveConfig(){return this.#o}get disconnectSignal(){return this.#l||(this.#l=new AbortController),this.#l.signal}constructor(){super(),this.#n=this.attachShadow({mode:"open"}),this.#j(),this.#q=new Promise(e=>this.#$=e)}#j(){const e=new CSSStyleSheet;e.replaceSync(q),this.#n.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.#w()}#B(){this.#t=new he(this);const e=this.#o?.plugins,o=Array.isArray(e)?e:[];this.#t.attachAll(o)}#V(){const e=this.#t?.getAllStyles()??"";if(e){const o=document.createElement("style");o.setAttribute("data-plugin","all"),o.textContent=e,this.#n.appendChild(o)}}#G(){this.#t&&this.#t.detachAll(),this.#B(),this.#V(),this.#C=this.#t?.getAll().some(e=>e.onScroll)??!1}#K(){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 o=this.#t.getHeaderContents();for(const{content:n}of o)this.#e.headerContents.has(n.id)||this.#e.headerContents.set(n.id,n)}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.hasAttribute("version")||this.setAttribute("version",D.version),this._rows=Array.isArray(this.#s)?[...this.#s]:[],this.#l?.abort(),this.#l=new AbortController,this.#u(),this.#B(),this.#Y(),this.#k||(this.#X(),this.#V(),this.#k=!0),this.#W()}disconnectedCallback(){this.#K(),Ke(this.#e),this.#a=!1,this.#x?.(),this.#x=void 0,this.#l&&(this.#l.abort(),this.#l=void 0),this.resizeController&&this.resizeController.dispose(),this.#b&&(this.#b.disconnect(),this.#b=void 0),this.#h=!1}#W(){const o=this.#n.querySelector(".tbw-grid-content")??this.#n.querySelector(".tbw-grid-root");if(this.headerRowEl=o?.querySelector(".header-row"),this.virtualization.totalHeightEl=o?.querySelector(".faux-vscroll-spacer"),this.virtualization.viewportEl=o?.querySelector(".rows-viewport"),this.bodyEl=o?.querySelector(".rows"),this.#a){ce(this.#n,this.#e),Ue(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.#h=!0;const n=this.disconnectSignal;this.#c(),this.addEventListener("keydown",r=>Me(this,r),{signal:n}),document.addEventListener("keydown",r=>{r.key==="Escape"&&this.activeEditRows!==-1&&this.#z(this.activeEditRows,!0)},{capture:!0,signal:n}),document.addEventListener("mousedown",r=>{if(this.activeEditRows===-1)return;const l=this.findRenderedRowElement(this.activeEditRows);!l||(r.composedPath&&r.composedPath()||[]).includes(l)||this.#z(this.activeEditRows,!1)},{signal:n});const i=o?.querySelector(".faux-vscroll"),s=o?.querySelector(".rows");if(this.virtualization.container=i??this,this.#C=this.#t?.getAll().some(r=>r.onScroll)??!1,i&&s){i.addEventListener("scroll",()=>{if(!this.virtualization.enabled&&!this.#C)return;const a=i.scrollTop,d=this.virtualization.rowHeight,h=Math.floor(a/d),p=h-h%2,b=-(a-p*d);s.style.transform=`translateY(${b}px)`,this.#E=a,this.#f||(this.#f=requestAnimationFrame(()=>{this.#f=0,this.#E!==null&&(this.#re(this.#E),this.#E=null)}))},{passive:!0,signal:n});const r=this.#n.querySelector(".tbw-grid-content"),l=this.#n.querySelector(".tbw-scroll-area");r&&(r.addEventListener("wheel",a=>{a.preventDefault(),a.shiftKey||Math.abs(a.deltaX)>Math.abs(a.deltaY)?l&&(l.scrollLeft+=a.shiftKey?a.deltaY:a.deltaX):i.scrollTop+=a.deltaY},{passive:!1,signal:n}),r.addEventListener("touchstart",a=>{a.touches.length===1&&(this.#_=a.touches[0].clientY,this.#R=a.touches[0].clientX,this.#S=i.scrollTop,this.#A=l?.scrollLeft??0)},{passive:!0,signal:n}),r.addEventListener("touchmove",a=>{if(a.touches.length===1&&this.#_!==null&&this.#R!==null&&this.#S!==null&&this.#A!==null){const d=this.#_-a.touches[0].clientY,h=this.#R-a.touches[0].clientX;i.scrollTop=this.#S+d,l&&(l.scrollLeft=this.#A+h),a.preventDefault()}},{passive:!1,signal:n}),r.addEventListener("touchend",()=>{this.#_=null,this.#R=null,this.#S=null,this.#A=null},{passive:!0,signal:n}))}this.resizeController=qe(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 l=r.getBoundingClientRect().height;l&&Math.abs(l-this.virtualization.rowHeight)>.1&&(this.virtualization.rowHeight=l,this.refreshVirtualWindow(!0))}}),this.virtualization.viewportEl&&(this.#b=new ResizeObserver(()=>{this.#f||(this.#f=requestAnimationFrame(()=>{this.#f=0,this.refreshVirtualWindow(!0)}))}),this.#b.observe(this.virtualization.viewportEl)),queueMicrotask(()=>this.#Z()),requestAnimationFrame(()=>requestAnimationFrame(()=>this.#$?.()))}#i(e,o){this.dispatchEvent(new CustomEvent(e,{detail:o,bubbles:!0,composed:!0}))}emitCellCommit(e){this.#i("cell-commit",e)}emitRowCommit(e){this.#i("row-commit",e)}emitSortChange(e){this.#i("sort-change",e)}emitColumnResize(e){this.#i("column-resize",e)}emitActivateCell(e){this.#i("activate-cell",e)}#Z(){this.bodyEl?.querySelectorAll(".data-grid-row")?.forEach((o,n)=>{const i=n===this.focusRow;o.setAttribute("aria-selected",String(i)),o.querySelectorAll(".cell").forEach((s,r)=>{s.setAttribute("aria-selected",String(i&&r===this.focusCol))})})}#J(){if(!this.#h)return;this.#u(),this.#o.fitMode==="fixed"?(this.__didInitialAutoSize=!1,this.#F()):(this._columns.forEach(o=>{!o.__userResized&&o.__autoSized&&delete o.width}),this.updateTemplate())}#Q(){this.#h&&(this.#u(),this.rowPool.length=0,this.bodyEl&&(this.bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.refreshVirtualWindow(!0))}#ee(){this._rows=Array.isArray(this.#s)?[...this.#s]:[],this.#L(),!this.#r||Array.isArray(this.#r)&&this.#r.length===0?this.#c():this.refreshVirtualWindow(!0)}#te(){X(this),this.#h&&(this.#u(),this.#c())}#oe(){this.#h&&(this.#u(),this.#G(),this.#L(),this.#M(),this.#T(),this.updateTemplate(),this.refreshVirtualWindow(!0))}#ne(){Pe(this)}#T(){Y(this)}updateTemplate(){ne(this)}#F(){Oe(this)}#M(){if(this.#t){const e=this.#H.length>0?this.#H:this._columns,o=e.filter(s=>!s.hidden),n=e.filter(s=>s.hidden),i=this.#t.processColumns([...o]);if(i!==o){const s=new Map(i.map((l,a)=>[l.field,{col:l,order:a}]));if(!o.some(l=>s.has(l.field))&&i.length>0)this._columns=[...i,...n];else{const l=e.map(a=>{if(a.hidden)return a;const d=s.get(a.field);return d?d.col:a});this._columns=l}}else this._columns=[...e]}}#w(){this.#t?.afterRender()}#L(){X(this);const e=Array.isArray(this.#s)?[...this.#s]:[],o=this.#t?.processRows(e)??e;this._rows=o}#u(){const e=this.#p?{...this.#p}:{};let o=Array.isArray(e.columns)?[...e.columns]:[];const n=(this.__lightDomColumnsCache||[]).map(i=>({...i}));if(n.length){const i={};o.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)):(o.push(s),i[s.field]=s)})}if(this.#r&&this.#r.length&&(o=[...this.#r]),(!o||o.length===0)&&this._rows.length&&(o=Q(this._rows).columns),o.length){o.forEach(r=>{r.sortable===void 0&&(r.sortable=!0),r.resizable===void 0&&(r.resizable=!0)});const i=this.#o.columns;i?.some(r=>r.__compiledView||r.__compiledEditor)?e.columns=i:e.columns=o}else{const i=this.#o.columns;i?.some(s=>s.__compiledView||s.__compiledEditor)&&(e.columns=i)}this.#m&&(e.fitMode=this.#m),e.fitMode||(e.fitMode="stretch"),this.#v&&(e.editOn=this.#v),e.columnState&&!this.#d&&(this.#d=e.columnState),this.#o=e,e.fitMode==="fixed"&&this._columns.forEach(i=>{i.width==null&&(i.width=80)})}#D(e,o,n=this.__rowRenderEpoch){this.#P||(this.#P=(i,s,r)=>this.#t?.renderRow(i,s,r)??!1),Ne(this,e,o,n,this.#P)}#ie(e,o){I(this,e,o)}#z(e,o){B(this,e,o)}#c(){if(!this.isConnected||!this.headerRowEl||!this.bodyEl)return;const e=this.#p?.columns||this.#r||[];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.#ne(),this.#u(),this.#G(),this.#H=[...this._columns],this.#L(),this.#M(),this.#d){const n=this.#d;this.#d=void 0,this.#U(n)}this.#T(),this.updateTemplate(),this.refreshVirtualWindow(!0),this.#o.fitMode==="fixed"&&!this.__didInitialAutoSize&&requestAnimationFrame(()=>this.#F()),this.bodyEl&&(this.bodyEl.style.display="",this.bodyEl.style.gridTemplateColumns=""),queueMicrotask(()=>this.#w())}#U(e){const o=this.#o.columns??[],n=this.#t?.getAll()??[];we(this,e,o,n);for(const i of e.columns){const s=o.find(r=>r.field===i.field);s&&(s.hidden=!i.visible)}}#se(){return this._rows.length<=this.virtualization.bypassThreshold}#re(e){if(this.refreshVirtualWindow(!1),this.#t?.onScrollRender(),this.#C){const o=this.virtualization.container,n={scrollTop:e,scrollLeft:o?.scrollLeft??0,scrollHeight:o?.scrollHeight??0,scrollWidth:o?.scrollWidth??0,clientHeight:o?.clientHeight??0,clientWidth:o?.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(o=>{const n=o.querySelector(".cell[data-row]");return n&&Number(n.getAttribute("data-row"))===e})||null}dispatchCellClick(e,o,n,i){const s=this._rows[o],r=this._columns[n];if(!s||!r)return!1;const l={row:s,rowIndex:o,colIndex:n,field:r.field,value:s[r.field],cellEl:i,originalEvent:e};return this.#t?.onCellClick(l)??!1}dispatchHeaderClick(e,o,n){const i=this._columns[o];if(!i)return!1;const s={colIndex:o,field:i.field,column:i,headerEl:n,originalEvent:e};return this.#t?.onHeaderClick(s)??!1}dispatchKeyDown(e){return this.#t?.onKeyDown(e)??!1}#N(e,o){let n=null;const i=e.composedPath?.();if(i&&i.length>0?n=i[0]:n=e.target,n&&!this.#n.contains(n)){const u=this.#n.elementFromPoint(e.clientX,e.clientY);u&&(n=u)}const s=n?.closest?.("[data-col]"),r=n?.closest?.(".data-grid-row"),l=n?.closest?.(".header-row");let a,d,h,p,b,c;return s&&(a=parseInt(s.getAttribute("data-row")??"-1",10),d=parseInt(s.getAttribute("data-col")??"-1",10),a>=0&&d>=0&&(h=this._rows[a],c=this._columns[d],p=c?.field,b=h&&p?h[p]:void 0)),{type:o,row:h,rowIndex:a!==void 0&&a>=0?a:void 0,colIndex:d!==void 0&&d>=0?d:void 0,field:p,value:b,column:c,originalEvent:e,cellElement:s??void 0,rowElement:r??void 0,isHeader:!!l,cell:a!==void 0&&d!==void 0&&a>=0&&d>=0?{row:a,col:d}:void 0}}#le(e){const o=this.#N(e,"mousedown");(this.#t?.onCellMouseDown(o)??!1)&&(this.#y=!0)}#ae(e){if(!this.#y)return;const o=this.#N(e,"mousemove");this.#t?.onCellMouseMove(o)}#ce(e){if(!this.#y)return;const o=this.#N(e,"mouseup");this.#t?.onCellMouseUp(o),this.#y=!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.#i("changed-rows-reset",{rows:this.changedRows,indices:this.changedRowIndices}),this.rowPool.forEach(o=>o.classList.remove("changed"))}async beginBulkEdit(e){if(!this._columns.some(s=>s.editable))return;const n=this._rows[e];this.#ie(e,n);const i=this.findRenderedRowElement?.(e);i&&(Array.from(i.children).forEach((s,r)=>{const l=this.visibleColumns[r];if(l?.editable){const a=s;a.classList.contains("editing")||M(this,n,e,l,a)}}),queueMicrotask(()=>{const s=i.querySelector(`.cell[data-col="${this.focusCol}"]`);if(s?.classList.contains("editing")){const r=s.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');try{r?.focus()}catch{}}}))}async commitActiveRowEdit(){this.activeEditRows!==-1&&this.#z(this.activeEditRows,!1)}async ready(){return this.#q}async forceLayout(){this.#c(),await new Promise(e=>requestAnimationFrame(()=>requestAnimationFrame(e)))}async getConfig(){return Object.freeze({...this.#o||{}})}setColumnVisible(e,o){const n=this.#o.columns,i=n?.find(l=>l.field===e);if(!i||!o&&i.lockVisible||!o&&(n??[]).filter(a=>!a.hidden&&a.field!==e).length===0)return!1;const s=!!i.hidden,r=!o;return s!==r?(i.hidden=r,this.#i("column-visibility",{field:e,visible:o,visibleColumns:(n??[]).filter(l=>!l.hidden).map(l=>l.field)}),this.rowPool.length=0,this.bodyEl&&(this.bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.#c(),this.requestStateChange(),!0):!1}toggleColumnVisibility(e){const i=!!this.#o.columns?.find(s=>s.field===e)?.hidden;return this.setColumnVisible(e,i)}isColumnVisible(e){const n=this.#o.columns?.find(i=>i.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.#i("column-visibility",{visibleColumns:(e??[]).map(n=>n.field)}),this.rowPool.length=0,this.bodyEl&&(this.bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.#c(),this.requestStateChange())}getAllColumns(){return(this.#o.columns??[]).map(o=>({field:o.field,header:o.header||o.field,visible:!o.hidden,lockVisible:o.lockVisible}))}setColumnOrder(e){if(!e.length)return;const o=new Map(this._columns.map(i=>[i.field,i])),n=[];for(const i of e){const s=o.get(i);s&&(n.push(s),o.delete(i))}for(const i of o.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 J(this,e)}set columnState(e){e&&(this.#d=e,this.#k&&this.#de(e))}get columnState(){return this.getColumnState()}#de(e){(this.#o.columns??[]).forEach(n=>{n.hidden=!1}),this.#U(e),this.#c()}requestStateChange(){this.#O||(this.#O=ge(this,()=>this.#t?.getAll()??[],e=>this.#i("column-state-change",e))),this.#O()}resetColumnState(){this.#d=void 0,(this.#o.columns??[]).forEach(n=>{n.hidden=!1}),this.sortState=null,this.__originalOrder=[],this.#u(),this.#c();const o=this.#t?.getAll()??[];for(const n of o)if(n.applyColumnState)for(const i of this._columns)n.applyColumnState(i.field,{field:i.field,order:0,visible:!0});this.requestStateChange()}get isToolPanelOpen(){return this.#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((i,s)=>(i.order??100)-(s.order??100))[0];n&&this.#e.expandedSections.add(n.id)}de(this.#n,this.#e),ue(this.#n,this.#e);const e={expand:this.#o?.icons?.expand??P.expand,collapse:this.#o?.icons?.collapse??P.collapse};Xe(this.#n,this.#e,e),this.#i("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,de(this.#n,this.#e),ue(this.#n,this.#e),this.#i("tool-panel-close",{})}}toggleToolPanel(){this.#e.isPanelOpen?this.closeToolPanel():this.openToolPanel()}toggleToolPanelSection(e){const o=this.#e.toolPanels.get(e);if(!o){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 i=this.#e.panelCleanups.get(e);i&&(i(),this.#e.panelCleanups.delete(e)),o.onClose?.(),this.#e.expandedSections.delete(e),this.#I(e,!1)}else{for(const[i,s]of this.#e.toolPanels)if(i!==e&&this.#e.expandedSections.has(i)){const r=this.#e.panelCleanups.get(i);r&&(r(),this.#e.panelCleanups.delete(i)),s.onClose?.(),this.#e.expandedSections.delete(i),this.#I(i,!1);const l=this.#n.querySelector(`[data-section="${i}"] .tbw-accordion-content`);l&&(l.innerHTML="")}this.#e.expandedSections.add(e),this.#I(e,!0),this.#ue(e)}this.#i("tool-panel-section-toggle",{id:e,expanded:!n})}#I(e,o){const n=this.#n.querySelector(`[data-section="${e}"]`);n&&n.classList.toggle("expanded",o)}#ue(e){const o=this.#e.toolPanels.get(e);if(!o?.render)return;const n=this.#n.querySelector(`[data-section="${e}"] .tbw-accordion-content`);if(!n)return;const i=o.render(n);i&&this.#e.panelCleanups.set(e,i)}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.#a&&this.#g()}unregisterToolPanel(e){this.#e.activePanel===e&&this.closeToolPanel(),this.#e.toolPanels.delete(e),this.#a&&this.#g()}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.#a&&ce(this.#n,this.#e)}unregisterHeaderContent(e){const o=this.#e.headerContentCleanups.get(e);o&&(o(),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 je(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.#a&&this.#g()}unregisterToolbarButton(e){const o=this.#e.toolbarButtonCleanups.get(e);o&&(o(),this.#e.toolbarButtonCleanups.delete(e)),this.#e.toolbarButtons.delete(e),this.#a&&this.#g()}setToolbarButtonDisabled(e,o){const n=this.#e.toolbarButtons.get(e);n&&(n.disabled=o);const i=this.#n.querySelector(`[data-btn="${e}"]`);i&&(i.disabled=o)}refreshShellHeader(){this.#g()}#g(){ae(this,this.#e),this.#X(),this.#W()}refreshVirtualWindow(e=!1){if(!this.bodyEl)return;const o=this._rows.length;if(!this.virtualization.enabled){this.#D(0,o),this.#w();return}if(this.#se()){this.virtualization.start=0,this.virtualization.end=o,this.bodyEl.style.transform="translateY(0px)",this.#D(0,o,this.__rowRenderEpoch),this.virtualization.totalHeightEl&&(this.virtualization.totalHeightEl.style.height=`${o*this.virtualization.rowHeight}px`);const S=this.#n.querySelector(".rows-body");S?.setAttribute("aria-rowcount",String(o)),S?.setAttribute("aria-colcount",String(this.visibleColumns.length)),this.#w();return}const n=this.virtualization.container??this,s=(this.virtualization.viewportEl??n).clientHeight,r=this.virtualization.rowHeight,l=n.scrollTop;let a=Math.floor(l/r),d=0;const h=10;for(;d<h;){const S=this.#t?.getExtraHeightBefore?.(a)??0,L=Math.floor((l-S)/r);if(L>=a||L<0)break;a=L,d++}a=a-a%2,a<0&&(a=0);const p=this.#t?.adjustVirtualStart(a,l,r);p!==void 0&&p<a&&(a=p,a=a-a%2,a<0&&(a=0));const b=Math.ceil(s/r)+3;let c=a+b;c>o&&(c=o),this.virtualization.start=a,this.virtualization.end=c;const f=this.#n.querySelector(".tbw-footer")?.offsetHeight??0,w=this.#t?.getExtraHeight()??0;this.virtualization.totalHeightEl&&(this.virtualization.totalHeightEl.style.height=`${o*r+r+f+w}px`);const v=this.#t?.getExtraHeightBefore?.(a)??0,A=-(l-a*r-v);this.bodyEl.style.transform=`translateY(${A}px)`,this.#D(a,c,e?++this.__rowRenderEpoch:this.__rowRenderEpoch);const x=this.#n.querySelector(".rows-body");x?.setAttribute("aria-rowcount",String(o)),x?.setAttribute("aria-colcount",String(this.visibleColumns.length)),e&&this.#w()}#X(){ae(this,this.#e);const e=this.#o?.shell,o=Be(e,this.#e),n=`
45
45
  <div class="tbw-scroll-area">
46
46
  <div class="rows-body-wrapper">
47
47
  <div class="rows-body" role="grid">
@@ -59,7 +59,7 @@
59
59
  <div class="faux-vscroll">
60
60
  <div class="faux-vscroll-spacer"></div>
61
61
  </div>
62
- `;if(o){const i=this.#o?.icons?.toolPanel??P.toolPanel,s={expand:this.#o?.icons?.expand??P.expand,collapse:this.#o?.icons?.collapse??P.collapse},r=Be(e,this.#e,i),l=Ve(e,this.#e,n,s);this.#n.innerHTML=`
62
+ `;if(o){const i=this.#o?.icons?.toolPanel??P.toolPanel,s={expand:this.#o?.icons?.expand??P.expand,collapse:this.#o?.icons?.collapse??P.collapse},r=Ve(e,this.#e,i),l=Ge(e,this.#e,n,s);this.#n.innerHTML=`
63
63
  <div class="tbw-grid-root has-shell">
64
64
  ${r}
65
65
  ${l}
@@ -70,5 +70,5 @@
70
70
  ${n}
71
71
  </div>
72
72
  </div>
73
- `}#he(){Ge(this.#n,this.#o?.shell,this.#e,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e),onToolbarButtonClick:e=>this.#fe(e)}),this.#x?.(),this.#x=We(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(s=>s.id===e);if(n?.action){n.action();return}const i=this.#e.toolbarButtons.get(e);i?.action&&i.action()}}customElements.get(V.tagName)||customElements.define(V.tagName,V);class Ke{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,o){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:o,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{...P,...e}}resolveIcon(e,o){return o!==void 0?o:this.gridIcons[e]}setIcon(e,o){typeof o=="string"?e.innerHTML=o:o instanceof HTMLElement&&(e.innerHTML="",e.appendChild(o.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}const T={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"},G={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"},Ye={ROOT:`.${T.ROOT}`,HEADER:`.${T.HEADER}`,HEADER_ROW:`.${T.HEADER_ROW}`,HEADER_CELL:`.${T.HEADER_CELL}`,ROWS_VIEWPORT:`.${T.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${T.ROWS_CONTAINER}`,DATA_ROW:`.${T.DATA_ROW}`,DATA_CELL:`.${T.DATA_CELL}`,GROUP_ROW:`.${T.GROUP_ROW}`,ROW_BY_INDEX:t=>`.${T.DATA_ROW}[${G.ROW_INDEX}="${t}"]`,CELL_BY_FIELD:t=>`.${T.DATA_CELL}[${G.FIELD}="${t}"]`,CELL_AT:(t,e)=>`.${T.DATA_ROW}[${G.ROW_INDEX}="${t}"] .${T.DATA_CELL}[${G.COL_INDEX}="${e}"]`,SELECTED_ROWS:`.${T.DATA_ROW}.${T.SELECTED}`,EDITING_CELL:`.${T.DATA_CELL}.${T.EDITING}`},Ze={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"},Je={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"},Qe={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:(t,e)=>t.reduce((o,n)=>o+(Number(n[e])||0),0),avg:(t,e)=>{const o=t.reduce((n,i)=>n+(Number(i[e])||0),0);return t.length?o/t.length:0},count:t=>t.length,min:(t,e)=>Math.min(...t.map(o=>Number(o[e])||1/0)),max:(t,e)=>Math.max(...t.map(o=>Number(o[e])||-1/0)),first:(t,e)=>t[0]?.[e],last:(t,e)=>t[t.length-1]?.[e]},W=new Map,H={register(t,e){W.set(t,e)},unregister(t){W.delete(t)},get(t){if(t!==void 0)return typeof t=="function"?t:W.get(t)??Z[t]},run(t,e,o,n){const i=this.get(t);return i?i(e,o,n):void 0},has(t){return W.has(t)||t in Z},list(){return[...Object.keys(Z),...W.keys()]}},he={sum:t=>t.reduce((e,o)=>e+o,0),avg:t=>t.length?t.reduce((e,o)=>e+o,0)/t.length:0,count:t=>t.length,min:t=>t.length?Math.min(...t):0,max:t=>t.length?Math.max(...t):0,first:t=>t[0]??0,last:t=>t[t.length-1]??0};function fe(t){return he[t]??he.sum}function et(t,e){return fe(t)(e)}const tt=H.register.bind(H),ot=H.unregister.bind(H),nt=H.get.bind(H),it=H.run.bind(H),st=H.list.bind(H);y.BaseGridPlugin=Ke,y.DEFAULT_GRID_ICONS=P,y.DGEvents=Je,y.DataGridElement=V,y.FitModeEnum=D,y.GridCSSVars=Ze,y.GridClasses=T,y.GridDataAttrs=G,y.GridElement=V,y.GridSelectors=Ye,y.PluginEvents=Qe,y.PluginManager=ue,y.aggregatorRegistry=H,y.getAggregator=nt,y.getValueAggregator=fe,y.listAggregators=st,y.registerAggregator=tt,y.runAggregator=it,y.runValueAggregator=et,y.unregisterAggregator=ot,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})}));
73
+ `}#he(){We(this.#n,this.#o?.shell,this.#e,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e),onToolbarButtonClick:e=>this.#fe(e)}),this.#x?.(),this.#x=Fe(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(s=>s.id===e);if(n?.action){n.action();return}const i=this.#e.toolbarButtons.get(e);i?.action&&i.action()}}customElements.get(D.tagName)||customElements.define(D.tagName,D);class Ye{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,o){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:o,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{...P,...e}}resolveIcon(e,o){return o!==void 0?o:this.gridIcons[e]}setIcon(e,o){typeof o=="string"?e.innerHTML=o:o instanceof HTMLElement&&(e.innerHTML="",e.appendChild(o.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}const T={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"},G={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"},Ze={ROOT:`.${T.ROOT}`,HEADER:`.${T.HEADER}`,HEADER_ROW:`.${T.HEADER_ROW}`,HEADER_CELL:`.${T.HEADER_CELL}`,ROWS_VIEWPORT:`.${T.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${T.ROWS_CONTAINER}`,DATA_ROW:`.${T.DATA_ROW}`,DATA_CELL:`.${T.DATA_CELL}`,GROUP_ROW:`.${T.GROUP_ROW}`,ROW_BY_INDEX:t=>`.${T.DATA_ROW}[${G.ROW_INDEX}="${t}"]`,CELL_BY_FIELD:t=>`.${T.DATA_CELL}[${G.FIELD}="${t}"]`,CELL_AT:(t,e)=>`.${T.DATA_ROW}[${G.ROW_INDEX}="${t}"] .${T.DATA_CELL}[${G.COL_INDEX}="${e}"]`,SELECTED_ROWS:`.${T.DATA_ROW}.${T.SELECTED}`,EDITING_CELL:`.${T.DATA_CELL}.${T.EDITING}`},Je={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"},Qe={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"},et={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:(t,e)=>t.reduce((o,n)=>o+(Number(n[e])||0),0),avg:(t,e)=>{const o=t.reduce((n,i)=>n+(Number(i[e])||0),0);return t.length?o/t.length:0},count:t=>t.length,min:(t,e)=>Math.min(...t.map(o=>Number(o[e])||1/0)),max:(t,e)=>Math.max(...t.map(o=>Number(o[e])||-1/0)),first:(t,e)=>t[0]?.[e],last:(t,e)=>t[t.length-1]?.[e]},W=new Map,H={register(t,e){W.set(t,e)},unregister(t){W.delete(t)},get(t){if(t!==void 0)return typeof t=="function"?t:W.get(t)??Z[t]},run(t,e,o,n){const i=this.get(t);return i?i(e,o,n):void 0},has(t){return W.has(t)||t in Z},list(){return[...Object.keys(Z),...W.keys()]}},fe={sum:t=>t.reduce((e,o)=>e+o,0),avg:t=>t.length?t.reduce((e,o)=>e+o,0)/t.length:0,count:t=>t.length,min:t=>t.length?Math.min(...t):0,max:t=>t.length?Math.max(...t):0,first:t=>t[0]??0,last:t=>t[t.length-1]??0};function pe(t){return fe[t]??fe.sum}function tt(t,e){return pe(t)(e)}const ot=H.register.bind(H),nt=H.unregister.bind(H),it=H.get.bind(H),st=H.run.bind(H),rt=H.list.bind(H);y.BaseGridPlugin=Ye,y.DEFAULT_GRID_ICONS=P,y.DGEvents=Qe,y.DataGridElement=D,y.FitModeEnum=z,y.GridCSSVars=Je,y.GridClasses=T,y.GridDataAttrs=G,y.GridElement=D,y.GridSelectors=Ze,y.PluginEvents=et,y.PluginManager=he,y.aggregatorRegistry=H,y.getAggregator=it,y.getValueAggregator=pe,y.listAggregators=rt,y.registerAggregator=ot,y.runAggregator=st,y.runValueAggregator=tt,y.unregisterAggregator=nt,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})}));
74
74
  //# sourceMappingURL=grid.umd.js.map