@toolbox-web/grid 0.2.5 → 0.2.7

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 (71) hide show
  1. package/all.d.ts +486 -80
  2. package/all.js +1364 -1029
  3. package/all.js.map +1 -1
  4. package/index-DG2CZ_Zo.js +3229 -0
  5. package/index-DG2CZ_Zo.js.map +1 -0
  6. package/index.d.ts +222 -11
  7. package/index.js +25 -3143
  8. package/index.js.map +1 -1
  9. package/lib/plugins/clipboard/index.js +1 -1
  10. package/lib/plugins/clipboard/index.js.map +1 -1
  11. package/lib/plugins/column-virtualization/index.js +1 -1
  12. package/lib/plugins/column-virtualization/index.js.map +1 -1
  13. package/lib/plugins/context-menu/index.js +1 -1
  14. package/lib/plugins/context-menu/index.js.map +1 -1
  15. package/lib/plugins/export/index.js +1 -1
  16. package/lib/plugins/export/index.js.map +1 -1
  17. package/lib/plugins/filtering/index.js +184 -149
  18. package/lib/plugins/filtering/index.js.map +1 -1
  19. package/lib/plugins/grouping-columns/index.js +46 -45
  20. package/lib/plugins/grouping-columns/index.js.map +1 -1
  21. package/lib/plugins/grouping-rows/index.js +117 -83
  22. package/lib/plugins/grouping-rows/index.js.map +1 -1
  23. package/lib/plugins/master-detail/index.js +140 -82
  24. package/lib/plugins/master-detail/index.js.map +1 -1
  25. package/lib/plugins/multi-sort/index.js +18 -18
  26. package/lib/plugins/multi-sort/index.js.map +1 -1
  27. package/lib/plugins/pinned-columns/index.js +1 -1
  28. package/lib/plugins/pinned-columns/index.js.map +1 -1
  29. package/lib/plugins/pinned-rows/index.js +55 -47
  30. package/lib/plugins/pinned-rows/index.js.map +1 -1
  31. package/lib/plugins/pivot/index.js +385 -351
  32. package/lib/plugins/pivot/index.js.map +1 -1
  33. package/lib/plugins/reorder/index.js +278 -85
  34. package/lib/plugins/reorder/index.js.map +1 -1
  35. package/lib/plugins/selection/index.js +28 -27
  36. package/lib/plugins/selection/index.js.map +1 -1
  37. package/lib/plugins/server-side/index.js +2 -2
  38. package/lib/plugins/server-side/index.js.map +1 -1
  39. package/lib/plugins/tree/index.js +181 -170
  40. package/lib/plugins/tree/index.js.map +1 -1
  41. package/lib/plugins/undo-redo/index.js +1 -1
  42. package/lib/plugins/undo-redo/index.js.map +1 -1
  43. package/lib/plugins/visibility/index.js +1 -1
  44. package/lib/plugins/visibility/index.js.map +1 -1
  45. package/package.json +1 -1
  46. package/umd/grid.all.umd.js +22 -22
  47. package/umd/grid.all.umd.js.map +1 -1
  48. package/umd/grid.umd.js +12 -12
  49. package/umd/grid.umd.js.map +1 -1
  50. package/umd/plugins/filtering.umd.js +1 -1
  51. package/umd/plugins/filtering.umd.js.map +1 -1
  52. package/umd/plugins/grouping-columns.umd.js +1 -1
  53. package/umd/plugins/grouping-columns.umd.js.map +1 -1
  54. package/umd/plugins/grouping-rows.umd.js +1 -1
  55. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  56. package/umd/plugins/master-detail.umd.js +1 -1
  57. package/umd/plugins/master-detail.umd.js.map +1 -1
  58. package/umd/plugins/multi-sort.umd.js +1 -1
  59. package/umd/plugins/multi-sort.umd.js.map +1 -1
  60. package/umd/plugins/pinned-rows.umd.js +1 -1
  61. package/umd/plugins/pinned-rows.umd.js.map +1 -1
  62. package/umd/plugins/pivot.umd.js +1 -1
  63. package/umd/plugins/pivot.umd.js.map +1 -1
  64. package/umd/plugins/reorder.umd.js +1 -1
  65. package/umd/plugins/reorder.umd.js.map +1 -1
  66. package/umd/plugins/selection.umd.js +1 -1
  67. package/umd/plugins/selection.umd.js.map +1 -1
  68. package/umd/plugins/server-side.umd.js +1 -1
  69. package/umd/plugins/server-side.umd.js.map +1 -1
  70. package/umd/plugins/tree.umd.js +1 -1
  71. package/umd/plugins/tree.umd.js.map +1 -1
package/umd/grid.umd.js CHANGED
@@ -1,6 +1,6 @@
1
- (function(E,G){typeof exports=="object"&&typeof module<"u"?G(exports):typeof define=="function"&&define.amd?define(["exports"],G):(E=typeof globalThis<"u"?globalThis:E||self,G(E.TbwGrid={}))})(this,(function(E){"use strict";const G=":root{color-scheme:light dark}:host{--tbw-color-bg: transparent;--tbw-color-panel-bg: light-dark(#eeeeee, #222222);--tbw-color-fg: light-dark(#222222, #eeeeee);--tbw-color-fg-muted: light-dark(#555555, #aaaaaa);--tbw-color-accent: light-dark(#3b82f6, #3b82f6);--tbw-color-accent-fg: light-dark(#ffffff, #000000);--tbw-color-success: light-dark(hsl(122, 39%, 40%), hsl(122, 39%, 49%));--tbw-color-selection: light-dark(#fff7d6, #333333);--tbw-color-row-alt: var(--tbw-color-bg);--tbw-color-row-hover: light-dark(#f0f6ff, #1c1c1c);--tbw-color-header-bg: color-mix(in hsl, var(--tbw-color-panel-bg) 85%, var(--tbw-color-fg));--tbw-color-header-fg: color-mix(in hsl, var(--tbw-color-fg) 75%, var(--tbw-color-panel-bg));--tbw-color-border: light-dark(#d0d0d4, #454545);--tbw-color-border-strong: light-dark(#777777, #adacac);--tbw-color-border-cell: var(--tbw-color-border);--tbw-color-border-header: var(--tbw-color-border);--tbw-color-shadow: light-dark(rgba(0, 0, 0, .1), rgba(0, 0, 0, .3));--tbw-font-family: inherit;--tbw-font-size: inherit;--tbw-font-size-header: var(--tbw-font-size);--tbw-font-weight-header: bold;--tbw-cell-padding-header: 2px 8px;--tbw-cell-padding: 2px 8px;--tbw-cell-padding-input: 2px 6px;--tbw-row-height: 28px;--tbw-header-height: 30px;--tbw-cell-white-space: nowrap;--tbw-border-radius: 4px;--tbw-border-input: 1px solid var(--tbw-color-border-strong);--tbw-border-header: 1px solid var(--tbw-color-border-header);--tbw-row-divider: 1px solid var(--tbw-color-border-cell);--tbw-row-hover-outline: 0;--tbw-color-active-row-bg: var(--tbw-color-selection);--tbw-active-row-outline: 0;--tbw-focus-outline: 2px solid var(--tbw-color-accent);--tbw-focus-outline-offset: -2px;--tbw-focus-background: rgba(from var(--tbw-color-accent) r g b / 12%);--tbw-range-border-color: var(--tbw-color-accent);--tbw-range-selection-bg: rgba(from var(--tbw-range-border-color) r g b / 12%);--tbw-resize-handle-width: 6px;--tbw-resize-handle-color: transparent;--tbw-resize-handle-color-hover: var(--tbw-color-accent);--tbw-resize-handle-border-radius: 0;--tbw-scrollbar-thumb: var(--tbw-color-border-strong);--tbw-scrollbar-track: var(--tbw-color-bg);--tbw-transition-duration: .12s;--tbw-transition-ease: ease;--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-border: var(--tbw-border-input, 1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input: var(--tbw-cell-padding-input, 2px 6px);--tbw-font-size-editor: inherit;--tbw-sort-indicator-color: var(--tbw-color-fg-muted);--tbw-sort-indicator-active-color: var(--tbw-color-accent);--tbw-header-text-transform: none;--tbw-header-letter-spacing: normal;--tbw-color-header-separator: var(--tbw-color-border-cell);--tbw-checkbox-size: 16px;--tbw-density-scale: 1}:host{position:relative;display:block;width:100%;height:100%;min-height:0;contain:content;font-family:var(--tbw-font-family);font-size:var(--tbw-font-size);background:var(--tbw-color-bg);color:var(--tbw-color-fg);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);overflow:clip;outline:none}:host,:host *{box-sizing:border-box}:host .header{display:block;flex-shrink:0;z-index:var(--tbw-z-layer-header, 30);background:var(--tbw-color-header-bg);overflow:visible}:host .header-group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-color-header-bg);z-index:var(--tbw-z-layer-header, 30)}:host .header-group-cell{display:flex;align-items:center;justify-content:flex-start;padding:var(--tbw-cell-padding-header, 2px 8px);color:var(--tbw-color-header-group-fg, var(--tbw-color-header-fg));font-weight:var(--tbw-font-weight-header-group, var(--tbw-font-weight-header));justify-content:var(--tbw-align-header-group, var(--tbw-align-header, flex-start))}:host .header-row{display:grid;grid-template-columns:var(--tbw-column-template);color:var(--tbw-color-header-fg);font-size:var(--tbw-font-size-header);min-height:var(--tbw-header-height);border-bottom:var(--tbw-border-header);z-index:var(--tbw-z-layer-header, 30)}:host .header-row>.cell{display:flex;align-items:center;gap:4px;padding:var(--tbw-cell-padding-header, 2px 8px);background-color:var(--tbw-color-header-bg);font-weight:var(--tbw-font-weight-header);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}:host .header-row>.cell>span:first-child{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}:host .header-row>.cell>span[part~=sort-indicator]{flex-shrink:0}:host .header-row>.cell:last-child{border-right:0}:host .header-group-cell,:host .header-row>.cell.grouped.group-end{border-right:2px solid var(--tbw-color-border)}:host .tbw-grid-root{display:flex;flex-direction:column;height:100%}:host .rows-body-wrapper{flex:1;min-height:0;display:flex;flex-direction:row;width:100%;min-width:fit-content}:host .rows-body{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow:visible}:host .rows-container{display:flex;flex-direction:row;flex:1;min-height:0;overflow:visible}:host .rows-viewport{flex:1;min-width:0;position:relative;display:block;overflow:clip}:host .faux-vscroll{position:sticky;inset-inline-end:0;flex-shrink:0;width:auto;overflow-y:auto;overflow-x:hidden;z-index:var(--tbw-z-layer-header, 30)}:host .faux-vscroll-spacer{width:1px}:host .rows-viewport .rows{position:absolute;top:0;left:0;min-width:100%;will-change:transform;z-index:var(--tbw-z-layer-rows, 1)}:host .data-grid-row{display:grid;grid-template-columns:var(--tbw-column-template);contain:layout style}:host .data-grid-row:has(.editing){background:var(--tbw-editing-bg)}:host .selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}:host .data-grid-row>.cell.selected:focus-visible,:host .data-grid-row>.cell:focus-visible:not(.cell-focus){outline:none}:host .data-grid-row>.cell{display:block;padding:var(--tbw-cell-padding, 2px 8px);border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height);line-height:calc(var(--tbw-row-height) - 5px);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0;white-space:var(--tbw-cell-white-space, nowrap);text-overflow:ellipsis}:host .data-grid-row>.cell>*{overflow:hidden;text-overflow:ellipsis;white-space:inherit;min-width:0}:host .data-grid-row>.cell:last-child{border-right:0}:host .data-grid-row>.cell[data-type=boolean]{text-align:center}:host .data-grid-row>.cell[data-type=boolean] input[type=checkbox]{margin:0;width:var(--tbw-checkbox-size);height:var(--tbw-checkbox-size);vertical-align:middle}:host .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex}:host .data-grid-row>.cell.editing input:not([type=checkbox]),:host .data-grid-row>.cell.editing select,:host .data-grid-row>.cell.editing textarea{width:100%;height:100%;max-width:100%;flex:1 1 auto;min-width:0;border:var(--tbw-editing-border);padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor)}:host .data-grid-row:nth-child(2n){background:var(--tbw-color-row-alt)}:host .data-grid-row:hover{background:var(--tbw-color-row-hover)}:host .sortable{cursor:pointer;-webkit-user-select:none;user-select:none}:host .resize-handle{position:absolute;top:0;right:calc(var(--tbw-resize-handle-width) / -2);width:var(--tbw-resize-handle-width);height:100%;cursor:e-resize;-webkit-user-select:none;user-select:none;touch-action:none;z-index:20;background:var(--tbw-resize-handle-color);transition:background .12s ease;border-radius:var(--tbw-resize-handle-border-radius)}:host .resize-handle:hover{background:var(--tbw-resize-handle-color-hover)}:host .cell-focus,:host .row-focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}:host .group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-color-row-alt);font-weight:500;border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height)}:host .group-row .cell{display:flex;align-items:center;padding:var(--tbw-cell-padding, 2px 8px)}:host .group-row .group-toggle{background:none;border:0;cursor:pointer;padding:0 4px 0 0;font:inherit}:host .group-row .group-count{margin-left:4px;opacity:.7}:host .sticky-left,:host .sticky-right{position:sticky;z-index:25}:host .header-row>.cell.sticky-left,:host .header-row>.cell.sticky-right{background:var(--tbw-color-header-bg);z-index:35}:host .data-grid-row>.cell.sticky-left,:host .data-grid-row>.cell.sticky-right{background:var(--tbw-color-panel-bg)}:host .sticky-left{box-shadow:1px 0 0 var(--tbw-color-border)}:host .sticky-right{box-shadow:-1px 0 0 var(--tbw-color-border)}.grid-container{position:relative;width:100%;height:100%}.grid-placeholder{padding:2rem;text-align:center;color:var(--tbw-color-fg);opacity:.6}:host{--tbw-shell-header-height: 44px;--tbw-shell-header-bg: var(--tbw-color-panel-bg);--tbw-shell-header-border: var(--tbw-color-border);--tbw-shell-title-font-size: 14px;--tbw-shell-title-font-weight: 600;--tbw-tool-panel-width: 280px;--tbw-tool-panel-bg: var(--tbw-color-panel-bg);--tbw-tool-panel-border: var(--tbw-color-border);--tbw-tool-panel-header-height: 40px;--tbw-tool-panel-transition: .2s ease-out;--tbw-toolbar-button-size: 32px;--tbw-toolbar-button-gap: 4px}:host .tbw-grid-root.has-shell{display:flex;flex-direction:column;height:100%}:host .tbw-shell-header{display:flex;align-items:center;gap:8px;min-height:var(--tbw-shell-header-height);padding:0 8px;background:var(--tbw-shell-header-bg);border-bottom:1px solid var(--tbw-shell-header-border);flex-shrink:0}:host .tbw-shell-title{font-size:var(--tbw-shell-title-font-size);font-weight:var(--tbw-shell-title-font-weight);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host .tbw-shell-content{flex:1;display:flex;align-items:center;gap:12px;min-width:0;overflow:hidden}:host .tbw-shell-toolbar{display:flex;align-items:center;gap:var(--tbw-toolbar-button-gap);flex-shrink:0}:host .tbw-toolbar-btn{display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-toolbar-button-size);height:var(--tbw-toolbar-button-size);padding:0;border:1px solid transparent;border-radius:var(--tbw-border-radius);background:transparent;color:var(--tbw-color-fg);cursor:pointer;font-size:16px;transition:background var(--tbw-transition-duration) var(--tbw-transition-ease),border-color var(--tbw-transition-duration) var(--tbw-transition-ease)}:host .tbw-toolbar-btn:hover{background:var(--tbw-color-row-hover)}:host .tbw-toolbar-btn:focus-visible{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}:host .tbw-toolbar-btn.active{background:var(--tbw-focus-background);border-color:var(--tbw-color-accent)}:host .tbw-toolbar-btn:disabled{opacity:.5;cursor:not-allowed}:host .tbw-toolbar-separator{width:1px;height:20px;background:var(--tbw-color-border);margin:0 4px}:host .tbw-shell-body{position:relative;display:flex;flex:1;min-height:0;overflow:visible}:host .tbw-grid-content{flex:1;min-width:0;min-height:0;display:flex;flex-direction:row;overflow:hidden}:host .tbw-scroll-area{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow-x:auto;overflow-y:hidden}:host .tbw-tool-panel{position:absolute;top:0;bottom:0;right:0;width:0;overflow:hidden;background:var(--tbw-tool-panel-bg);border-left:1px solid var(--tbw-tool-panel-border);transition:width var(--tbw-tool-panel-transition);display:flex;flex-direction:column;z-index:30;box-shadow:-2px 0 8px var(--tbw-color-shadow)}:host .tbw-tool-panel[data-position=left]{right:auto;left:0;border-left:none;border-right:1px solid var(--tbw-tool-panel-border);box-shadow:2px 0 8px var(--tbw-color-shadow)}:host .tbw-tool-panel.open{width:var(--tbw-tool-panel-width)}:host .tbw-tool-panel-resize{position:absolute;top:0;bottom:0;width:6px;cursor:col-resize;background:transparent;z-index:10;transition:background .15s ease}:host .tbw-tool-panel-resize[data-handle-position=left]{left:0}:host .tbw-tool-panel-resize[data-handle-position=right]{right:0}:host .tbw-tool-panel-resize:hover,:host .tbw-tool-panel-resize.resizing{background:var(--tbw-color-accent)}:host .tbw-tool-panel-header{display:flex;align-items:center;justify-content:space-between;min-height:var(--tbw-tool-panel-header-height);padding:0 12px;border-bottom:1px solid var(--tbw-tool-panel-border);flex-shrink:0}:host .tbw-tool-panel-title{font-weight:600;font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host .tbw-tool-panel-close{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;padding:0;border:none;border-radius:var(--tbw-border-radius);background:transparent;color:var(--tbw-color-fg-muted);cursor:pointer;font-size:14px}:host .tbw-tool-panel-close:hover{background:var(--tbw-color-row-hover);color:var(--tbw-color-fg)}:host .tbw-tool-panel-content{flex:1;overflow:auto}:host .tbw-accordion{display:flex;flex-direction:column;gap:0}:host .tbw-accordion-section{border-bottom:1px solid var(--tbw-tool-panel-border)}:host .tbw-accordion-section:last-child{border-bottom:none}:host .tbw-accordion-header{display:flex;align-items:center;gap:8px;width:100%;padding:10px 12px;border:none;background:transparent;color:var(--tbw-color-fg);font-size:13px;font-weight:600;text-align:left;cursor:pointer;-webkit-user-select:none;user-select:none}:host .tbw-accordion-header:hover{background:var(--tbw-color-row-hover)}:host .tbw-accordion-section.single .tbw-accordion-header{cursor:default}:host .tbw-accordion-section.single .tbw-accordion-header:hover{background:transparent}:host .tbw-accordion-chevron{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:10px;color:var(--tbw-color-fg-muted);transition:transform .15s ease;flex-shrink:0}:host .tbw-accordion-section.expanded .tbw-accordion-chevron{transform:rotate(90deg)}:host .tbw-accordion-icon{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:14px;flex-shrink:0}:host .tbw-accordion-title{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}:host .tbw-accordion-content{display:none}:host .tbw-accordion-section.expanded .tbw-accordion-content{display:block}:host .tbw-quick-filter-input{flex:1;max-width:300px;height:28px;padding:0 8px;border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);background:var(--tbw-color-bg);color:var(--tbw-color-fg);font-size:13px}:host .tbw-quick-filter-input:focus{outline:none;border-color:var(--tbw-color-accent)}:host .tbw-selection-summary{font-size:13px;color:var(--tbw-color-fg-muted);white-space:nowrap}";function ge(t){const e=new Map;return t._sortState&&e.set(t._sortState.field,{direction:t._sortState.direction===1?"asc":"desc",priority:0}),e}function te(t,e){const o=t._columns,i=ge(t);return{columns:o.map((n,s)=>{const r={field:n.field,order:s,visible:!0},l=n;l.__renderedWidth!==void 0?r.width=l.__renderedWidth:n.width!==void 0&&(r.width=typeof n.width=="string"?parseFloat(n.width):n.width);const a=i.get(n.field);a&&(r.sort=a);for(const d of e)if(d.getColumnState){const f=d.getColumnState(n.field);f&&Object.assign(r,f)}return r})}}function me(t,e,o,i){if(!e.columns||e.columns.length===0)return;const n=new Map(e.columns.map(l=>[l.field,l])),s=o.map(l=>{const a=n.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=n.get(l.field)?.order??1/0,f=n.get(a.field)?.order??1/0;return d-f}),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 i)if(l.applyColumnState)for(const a of e.columns)l.applyColumnState(a.field,a)}function ve(t,e,o){let i=null;return()=>{i!==null&&clearTimeout(i),i=setTimeout(()=>{i=null;const n=te(t,e());o(n)},100)}}const q={STRETCH:"stretch",FIXED:"fixed"},P={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰"};function _e(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 oe(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]||{},i=Object.keys(o).map(s=>{const r=o[s],l=_e(r);return{field:s,header:s.charAt(0).toUpperCase()+s.slice(1),type:l}}),n={};return i.forEach(s=>{n[s.field]=s.type||"string"}),{columns:i,typeMap:n}}const Ee=/{{\s*([^}]+)\s*}}/g,H="__DG_EMPTY__",Ce=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,ye=/__(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/,Re=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"]),ne=/^on\w+$/i,Se=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),Ae=/^\s*(javascript|vbscript|data|blob):/i;function X(t){if(!t||typeof t!="string")return"";if(t.indexOf("<")===-1)return t;const e=document.createElement("template");return e.innerHTML=t,xe(e.content),e.innerHTML}function xe(t){const e=[],o=t.querySelectorAll("*");for(const i of o){const n=i.tagName.toLowerCase();if(Re.has(n)){e.push(i);continue}if((n==="svg"||i.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(i.attributes).some(l=>ne.test(l.name)||l.name==="href"||l.name==="xlink:href")){e.push(i);continue}const s=[];for(const r of i.attributes){const l=r.name.toLowerCase();if(ne.test(l)){s.push(r.name);continue}if(Se.has(l)&&Ae.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=>i.removeAttribute(r))}e.forEach(i=>i.remove())}function ie(t,e){if(!t||t.indexOf("{{")===-1)return t;const o=[],i=t.replace(Ee,(l,a)=>{const d=Te(a,e);return o.push({expr:a.trim(),result:d}),d}),n=Le(i),s=o.length&&o.every(l=>l.result===""||l.result===H);return/Reflect\.|\bProxy\b|ownKeys\(/.test(t)||s?"":n}function Te(t,e){if(t=(t||"").trim(),!t||/\b(Reflect|Proxy|ownKeys)\b/.test(t))return H;if(t==="value")return e.value==null?H:String(e.value);if(t.startsWith("row.")&&!/[()?]/.test(t)&&!t.includes(":")){const i=t.slice(4),n=e.row?e.row[i]:void 0;return n==null?H:String(n)}if(t.length>80||!Ce.test(t)||ye.test(t))return H;const o=t.match(/\./g);if(o&&o.length>1)return H;try{const n=new Function("value","row",`return (${t});`)(e.value,e.row),s=n==null?"":String(n);return/Reflect|Proxy|ownKeys/.test(s)?H:s||H}catch{return H}}function Le(t){return t&&t.replace(new RegExp(H,"g"),"").replace(/Reflect\.[^<>{}\s]+/g,"").replace(/\bProxy\b/g,"").replace(/ownKeys\([^)]*\)/g,"")}function Pe(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 se(t){const e=/Reflect\.|\bProxy\b|ownKeys\(/.test(t),o=i=>e?"":ie(t,i);return o.__blocked=e,o}function He(t){return Array.from(t.querySelectorAll("tbw-grid-column")).map(o=>{const i=o.getAttribute("field")||"";if(!i)return null;const n=o.getAttribute("type")||void 0,r=n&&new Set(["number","string","date","boolean","select","typeahead"]).has(n)?n:void 0,l=o.getAttribute("header")||void 0,a=o.hasAttribute("sortable"),d=o.hasAttribute("editable"),f={field:i,type:r,header:l,sortable:a,editable:d};o.hasAttribute("resizable")&&(f.resizable=!0),o.hasAttribute("sizable")&&(f.resizable=!0);const h=o.getAttribute("options");h&&(f.options=h.split(",").map(b=>{const[w,v]=b.includes(":")?b.split(":"):[b.trim(),b.trim()];return{value:w.trim(),label:v?.trim()||w.trim()}}));const p=o.querySelector("tbw-grid-column-view"),c=o.querySelector("tbw-grid-column-editor"),u=o.querySelector("tbw-grid-column-header");return p&&(f.__viewTemplate=p),c&&(f.__editorTemplate=c),u&&(f.__headerTemplate=u),f}).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(n=>o[n.field]=n);const i=t.map(n=>{const s=o[n.field];if(!s)return n;const r={...n};return s.header&&!r.header&&(r.header=s.header),s.type&&!r.type&&(r.type=s.type),r.sortable=n.sortable||s.sortable,(n.resizable===!0||s.resizable===!0)&&(r.resizable=!0),r.editable=n.editable||s.editable,s.__viewTemplate&&(r.__viewTemplate=s.__viewTemplate),s.__editorTemplate&&(r.__editorTemplate=s.__editorTemplate),s.__headerTemplate&&(r.__headerTemplate=s.__headerTemplate),delete o[n.field],r});return Object.keys(o).forEach(n=>i.push(o[n])),i}function j(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 Oe(t){t.__lightDomColumnsCache||(t.__originalColumnNodes=Array.from(t.querySelectorAll("tbw-grid-column")),t.__lightDomColumnsCache=t.__originalColumnNodes.length?He(t):[]);const e=t.__lightDomColumnsCache,o=ke(t._columns,e);o.forEach(n=>{n.__viewTemplate&&!n.__compiledView&&(n.__compiledView=se(n.__viewTemplate.innerHTML)),n.__editorTemplate&&!n.__compiledEditor&&(n.__compiledEditor=se(n.__editorTemplate.innerHTML))});const{columns:i}=oe(t._rows,o);t._columns=i}function re(t){const e=t.effectiveConfig?.fitMode||t.fitMode||q.STRETCH;if(e!==q.STRETCH&&e!==q.FIXED||t.__didInitialAutoSize||!t.isConnected)return;const o=t._headerRowEl?.children||[];if(!o.length)return;let i=!1;t._visibleColumns.forEach((n,s)=>{if(n.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 f=d.scrollWidth;f>l&&(l=f)}}l>0&&(n.width=l+2,n.__autoSized=!0,i=!0)}),i&&D(t),t.__didInitialAutoSize=!0}function D(t){(t.effectiveConfig?.fitMode||t.fitMode||q.STRETCH)===q.STRETCH?t._gridTemplate=t._visibleColumns.map(o=>{if(o.width)return`${o.width}px`;const i=o.minWidth;return i!=null?`minmax(${i}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 ze(t){switch(t.type){case"number":return e=>{const o=document.createElement("input");return o.type="number",o.value=e.value!=null?String(e.value):"",o.addEventListener("blur",()=>e.commit(o.value===""?null:Number(o.value))),o.addEventListener("keydown",i=>{i.key==="Enter"&&e.commit(o.value===""?null:Number(o.value)),i.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",i=>{i.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 n=()=>{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",n),o.addEventListener("blur",n),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!=null?String(e.value):"",o.addEventListener("blur",()=>e.commit(o.value)),o.addEventListener("keydown",i=>{i.key==="Enter"&&e.commit(o.value),i.key==="Escape"&&e.cancel()}),o.focus(),o}}}function Me(t,e){if(t._dispatchKeyDown?.(e))return;const o=t._rows.length-1,i=t._visibleColumns.length-1,n=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=f=>{if(!f)return!1;const h=f.tagName;return!!(h==="INPUT"||h==="SELECT"||h==="TEXTAREA"||f.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"))&&!(n&&(r==="select"||r==="typeahead")&&(e.key==="ArrowDown"||e.key==="ArrowUp"))){switch(e.key){case"Tab":{e.preventDefault(),!e.shiftKey?t._focusCol<i?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=i),M(t);return}case"ArrowDown":n&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=Math.min(o,t._focusRow+1),e.preventDefault();break;case"ArrowUp":n&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=Math.max(0,t._focusRow-1),e.preventDefault();break;case"ArrowRight":t._focusCol=Math.min(i,t._focusCol+1),e.preventDefault();break;case"ArrowLeft":t._focusCol=Math.max(0,t._focusCol-1),e.preventDefault();break;case"Home":(e.ctrlKey||e.metaKey)&&(n&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=0),t._focusCol=0,e.preventDefault(),M(t,{forceScrollLeft:!0});return;case"End":(e.ctrlKey||e.metaKey)&&(n&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=o),t._focusCol=i,e.preventDefault(),M(t,{forceScrollRight:!0});return;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}})),M(t);default:return}M(t)}}function M(t,e){if(t._virtualization?.enabled){const{rowHeight:r,container:l,viewportEl:a}=t._virtualization,d=l,f=a?.clientHeight??d?.clientHeight??0;if(d&&f>0){const h=t._focusRow*r;h<d.scrollTop?d.scrollTop=h:h+r>d.scrollTop+f&&(d.scrollTop=h-f+r)}}t._activeEditRows!==void 0&&t._activeEditRows!==-1||t.refreshVirtualWindow(!1),Array.from(t._bodyEl.querySelectorAll(".cell-focus")).forEach(r=>r.classList.remove("cell-focus")),Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(r=>{r.setAttribute("aria-selected","false")});const i=t._focusRow,n=t._virtualization.start??0,s=t._virtualization.end??t._rows.length;if(i>=n&&i<s){const r=t._bodyEl.querySelectorAll(".data-grid-row")[i-n],l=r?.children[t._focusCol];if(l){l.classList.add("cell-focus"),l.setAttribute("aria-selected","true");const a=t.shadowRoot?.querySelector(".tbw-scroll-area");if(a&&l)if(e?.forceScrollLeft)a.scrollLeft=0;else if(e?.forceScrollRight)a.scrollLeft=a.scrollWidth-a.clientWidth;else{const d=t._getHorizontalScrollOffsets?.(r??void 0,l)??{left:0,right:0};if(!d.skipScroll){const f=l.getBoundingClientRect(),h=a.getBoundingClientRect(),p=f.left-h.left+a.scrollLeft,c=p+f.width,u=a.scrollLeft+d.left,b=a.scrollLeft+a.clientWidth-d.right;p<u?a.scrollLeft=p-d.left:c>b&&(a.scrollLeft=c-a.clientWidth+d.right)}}if(t._activeEditRows!==void 0&&t._activeEditRows!==-1&&l.classList.contains("editing")){const d=l.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(d&&document.activeElement!==d)try{d.focus()}catch{}}else if(!l.contains(document.activeElement)){l.hasAttribute("tabindex")||l.setAttribute("tabindex","-1");try{l.focus({preventScroll:!0})}catch{}}}}}const De="__cellDisplayCache",Ne="__cellCacheEpoch";function K(t){t[De]=void 0,t[Ne]=void 0,t.__hasSpecialColumns=void 0}function Ie(t,e,o,i,n){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 h=document.createElement("div");h.className="data-grid-row",h.setAttribute("role","row"),h.addEventListener("click",p=>le(t,p,h,!1)),h.addEventListener("dblclick",p=>le(t,p,h,!0)),t._rowPool.push(h)}if(t._rowPool.length>s){for(let h=s;h<t._rowPool.length;h++){const p=t._rowPool[h];p.parentNode===r&&p.remove()}t._rowPool.length=s}const f=n&&t.__hasRenderRowPlugins!==!1;for(let h=0;h<s;h++){const p=e+h,c=t._rows[p],u=t._rowPool[h];if(u.setAttribute("aria-rowindex",String(p+d+1)),f&&n(c,u,p)){u.__epoch=i,u.__rowDataRef=c,u.parentNode!==r&&r.appendChild(u);continue}const b=u.__epoch,w=u.__rowDataRef,v=u.children.length,x=b===i&&v===a,S=w!==c;let g=!1;if(x&&S){for(let _=0;_<a;_++)if(l[_].externalView&&!u.querySelector(`.cell[data-col="${_}"] [data-external-view]`)){g=!0;break}}if(!x||g){const _=u.querySelector(".cell.editing"),C=t._activeEditRows===p;if(_&&!C)u.__isCustomRow&&(u.className="data-grid-row",u.setAttribute("role","row"),u.__isCustomRow=!1),B(t,u,c,p),u.__epoch=i,u.__rowDataRef=c;else if(_&&C)Y(t,u,c,p),u.__rowDataRef=c;else if(u.__isCustomRow&&(u.className="data-grid-row",u.setAttribute("role","row"),u.__isCustomRow=!1),B(t,u,c,p),u.__epoch=i,u.__rowDataRef=c,C){const A=u.children;for(let L=0;L<A.length;L++){const O=t._visibleColumns[L];O&&O.editable&&z(t,c,p,O,A[L])}}}else if(S){const _=u.querySelector(".cell.editing"),C=t._activeEditRows===p;if(_&&!C)B(t,u,c,p),u.__epoch=i,u.__rowDataRef=c;else if(Y(t,u,c,p),u.__rowDataRef=c,C&&!_){const A=u.children;for(let L=0;L<A.length;L++){const O=t._visibleColumns[L];O&&O.editable&&z(t,c,p,O,A[L])}}}else{const _=u.querySelector(".cell.editing"),C=t._activeEditRows===p;if(_&&!C)B(t,u,c,p),u.__epoch=i,u.__rowDataRef=c;else if(Y(t,u,c,p),C&&!_){const A=u.children;for(let L=0;L<A.length;L++){const O=t._visibleColumns[L];O&&O.editable&&z(t,c,p,O,A[L])}}}const m=t._changedRowIndices.has(p),y=u.classList.contains("changed");m!==y&&u.classList.toggle("changed",m),u.parentNode!==r&&r.appendChild(u)}}function Y(t,e,o,i){const n=e.children,s=t._visibleColumns,r=s.length,l=n.length,a=r<l?r:l,d=t._focusRow,f=t._focusCol;let h=t.__hasSpecialColumns;if(h===void 0){h=!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"){h=!0;break}}t.__hasSpecialColumns=h}const p=String(i);if(!h){for(let c=0;c<a;c++){const u=n[c],b=o[s[c].field];u.textContent=b==null?"":String(b),u.getAttribute("data-row")!==p&&u.setAttribute("data-row",p);const w=d===i&&f===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&&!n[c].querySelector("[data-external-view]")){B(t,e,o,i);return}for(let c=0;c<a;c++){const u=s[c],b=n[c];b.getAttribute("data-row")!==p&&b.setAttribute("data-row",p);const w=d===i&&f===c,v=b.classList.contains("cell-focus");if(w!==v&&(b.classList.toggle("cell-focus",w),b.setAttribute("aria-selected",String(w))),b.classList.contains("editing"))continue;if(u.viewRenderer){const S=o[u.field],g=u.viewRenderer({row:o,value:S,field:u.field,column:u});typeof g=="string"?b.innerHTML=X(g):g?(b.innerHTML="",b.appendChild(g)):b.textContent=S==null?"":String(S);continue}if(u.__viewTemplate||u.__compiledView||u.externalView)continue;const R=o[u.field];let x;if(u.format)try{const S=u.format(R,o);x=S==null?"":String(S)}catch{x=R==null?"":String(R)}else if(u.type==="date"){if(R==null||R==="")x="";else if(R instanceof Date)x=isNaN(R.getTime())?"":R.toLocaleDateString();else{const S=new Date(R);x=isNaN(S.getTime())?"":S.toLocaleDateString()}b.textContent=x}else if(u.type==="boolean"){const S=!!R;b.innerHTML=`<span role="checkbox" aria-checked="${S}" aria-label="${S}">${S?"&#x1F5F9;":"&#9744;"}</span>`}else x=R==null?"":String(R),b.textContent=x}}function B(t,e,o,i){e.innerHTML="";const n=t._visibleColumns,s=n.length,r=t._focusRow,l=t._focusCol,a=t.effectiveConfig?.editOn||t.editOn,d=t,f=document.createDocumentFragment();for(let h=0;h<s;h++){const p=n[h],c=document.createElement("div");c.className="cell",j(c,"cell"),c.setAttribute("role","gridcell"),c.setAttribute("aria-colindex",String(h+1)),c.setAttribute("data-col",String(h)),c.setAttribute("data-row",String(i)),p.type,p.type&&c.setAttribute("data-type",p.type);let u=o[p.field];const b=p.format;if(b)try{u=b(u,o)}catch{}const w=p.__compiledView,v=p.__viewTemplate,R=p.viewRenderer,x=p.externalView;let S=!1;if(R){const g=R({row:o,value:u,field:p.field,column:p});typeof g=="string"?(c.innerHTML=X(g),S=!0):g?c.appendChild(g):c.textContent=u==null?"":String(u)}else if(x){const g=x,m=document.createElement("div");m.setAttribute("data-external-view",""),m.setAttribute("data-field",p.field),c.appendChild(m);const y={row:o,value:u,field:p.field,column:p};if(g.mount)try{g.mount({placeholder:m,context:y,spec:g})}catch{}else queueMicrotask(()=>{try{d.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:m,spec:g,context:y}}))}catch{}});m.setAttribute("data-mounted","")}else if(w){const g=w({row:o,value:u,field:p.field,column:p}),m=w.__blocked;c.innerHTML=m?"":X(g),S=!0,m&&(c.textContent="",c.setAttribute("data-blocked-template",""))}else if(v){const g=v.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(g)?(c.textContent="",c.setAttribute("data-blocked-template","")):(c.innerHTML=X(ie(g,{row:o,value:u})),S=!0)}else if(p.type==="date")if(u==null||u==="")c.textContent="";else{let g=null;if(u instanceof Date)g=u;else if(typeof u=="number"||typeof u=="string"){const m=new Date(u);isNaN(m.getTime())||(g=m)}c.textContent=g?g.toLocaleDateString():""}else if(p.type==="boolean"){const g=!!u;c.innerHTML=`<span role="checkbox" aria-checked="${g}" aria-label="${g}">${g?"&#x1F5F9;":"&#9744;"}</span>`}else c.textContent=u==null?"":String(u);if(S){Pe(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=""),p.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,M(t))}),a==="click"?c.addEventListener("click",g=>{if(c.classList.contains("editing"))return;g.stopPropagation();const m=Number(c.getAttribute("data-row")),y=Number(c.getAttribute("data-col"));if(isNaN(m)||isNaN(y))return;const _=t._rows[m],C=t._visibleColumns[y];!_||!C||(t._focusRow=m,t._focusCol=y,z(t,_,m,C,c))}):c.addEventListener("dblclick",g=>{g.stopPropagation();const m=Number(c.getAttribute("data-row"));if(isNaN(m))return;const y=t._rows[m];if(!y)return;$(t,m,y);const _=t.findRenderedRowElement?.(m);if(_){const C=_.children;for(let A=0;A<C.length;A++){const L=t._visibleColumns[A];L&&L.editable&&z(t,y,m,L,C[A])}}}),c.addEventListener("keydown",g=>{const m=Number(c.getAttribute("data-row")),y=Number(c.getAttribute("data-col"));if(isNaN(m)||isNaN(y))return;const _=t._rows[m],C=t._visibleColumns[y];if(!(!_||!C)){if((C.type==="select"||C.type==="typeahead")&&!c.classList.contains("editing")&&g.key==="Enter"){g.preventDefault(),t._activeEditRows!==m&&$(t,m,_),z(t,_,m,C,c),setTimeout(()=>{const A=c.querySelector("select");try{A?.showPicker?.()}catch{}A?.focus()},0);return}if(C.type==="boolean"&&g.key===" "&&!c.classList.contains("editing")){g.preventDefault(),t._activeEditRows!==m&&$(t,m,_);const A=!_[C.field];Q(t,m,C,A,_),c.innerHTML=`<span role="checkbox" aria-checked="${A}" aria-label="${A}">${A?"&#x1F5F9;":"&#9744;"}</span>`;return}if(g.key==="Enter"&&!c.classList.contains("editing")){g.preventDefault(),g.stopPropagation(),t._focusRow=m,t._focusCol=y,typeof t.beginBulkEdit=="function"?t.beginBulkEdit(m):z(t,_,m,C,c);return}if(g.key==="F2"&&!c.classList.contains("editing")){g.preventDefault(),z(t,_,m,C,c);return}}})):p.type==="boolean"&&(c.hasAttribute("tabindex")||(c.tabIndex=0)),r===i&&l===h?(c.classList.add("cell-focus"),c.setAttribute("aria-selected","true")):c.setAttribute("aria-selected","false"),f.appendChild(c)}e.appendChild(f)}function le(t,e,o,i){if(e.target?.closest(".resize-handle"))return;const n=o.querySelector(".cell[data-row]");if(!n)return;const s=Number(n.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,M(t)}}if(o.querySelector(".cell.editing")){const d=o.querySelectorAll(".cell.editing");if(!i)return;d.forEach(f=>f.classList.remove("editing"))}const a=t.effectiveConfig?.editOn||t.editOn||"doubleClick";if(a==="click"||a==="doubleClick"&&i)$(t,s,r);else return;Array.from(o.children).forEach((d,f)=>{const h=t._visibleColumns[f];h&&h.editable&&z(t,r,s,h,d)}),l&&queueMicrotask(()=>{const d=o.querySelector(`.cell[data-col="${t._focusCol}"]`);if(d?.classList.contains("editing")){const f=d.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');try{f?.focus()}catch{}}})}function Z(t){return!(t==="__proto__"||t==="constructor"||t==="prototype")}function $(t,e,o){t._activeEditRows!==e&&(t._rowEditSnapshots.set(e,{...o}),t._activeEditRows=e)}function N(t,e,o){if(t._activeEditRows!==e)return;const i=t._rowEditSnapshots.get(e),n=t._rows[e],s=t.findRenderedRowElement?.(e);if(!o&&s&&n&&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 f=l.querySelector("input,textarea,select");if(f){let h;f instanceof HTMLInputElement&&f.type==="checkbox"?h=f.checked:(h=f.value,d.type==="number"&&h!==""&&(h=Number(h))),n[d.field]!==h&&Q(t,e,d,h,n)}}),o&&i&&n)Object.keys(i).forEach(r=>n[r]=i[r]),t._changedRowIndices.delete(e),K(t);else if(!o){const r=t._changedRowIndices.has(e);t.dispatchEvent(new CustomEvent("row-commit",{detail:{rowIndex:e,row:n,changed:r,changedRows:t.changedRows,changedRowIndices:t.changedRowIndices}}))}t._rowEditSnapshots.delete(e),t._activeEditRows=-1,s&&(B(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(f=>f.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 Q(t,e,o,i,n){const s=o.field;if(!Z(s)||n[s]===i)return;n[s]=i;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:n,field:s,value:i,rowIndex:e,changedRows:t.changedRows,changedRowIndices:t.changedRowIndices,firstTimeForRow:l}}))}function z(t,e,o,i,n){if(!i.editable||(t._activeEditRows!==o&&$(t,o,e),n.classList.contains("editing")))return;const s=Z(i.field)?e[i.field]:void 0;n.classList.add("editing");let r=!1;const l=c=>{r||t._activeEditRows===-1||Q(t,o,i,c,e)},a=()=>{r=!0,e[i.field]=Z(i.field)?s:void 0;const c=n.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",n.innerHTML="",n.appendChild(d),d.addEventListener("keydown",c=>{c.key==="Enter"&&(c.stopPropagation(),c.preventDefault(),r=!0,N(t,o,!1)),c.key==="Escape"&&(c.stopPropagation(),c.preventDefault(),a(),N(t,o,!0))});const f=i.__editorTemplate,h=i.editor||(f?"template":ze(i)),p=s;if(h==="template"&&f){const c=f.cloneNode(!0),u=i.__compiledEditor;u?c.innerHTML=u({row:e,value:s,field:i.field,column:i}):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,R)=>{const x=e[R];return x==null?"":String(x)})||"")});const b=c.querySelector("input,textarea,select");if(b){const w=typeof HTMLInputElement<"u";w&&b instanceof HTMLInputElement&&b.type==="checkbox"?b.checked=!!s:"value"in b&&(b.value=s??""),b.addEventListener("blur",()=>{const v=w&&b instanceof HTMLInputElement&&b.type==="checkbox"?b.checked:b.value;l(v)}),b.addEventListener("keydown",v=>{if(v.key==="Enter"){v.stopPropagation(),v.preventDefault(),r=!0;const R=w&&b instanceof HTMLInputElement&&b.type==="checkbox"?b.checked:b.value;l(R),N(t,o,!1)}v.key==="Escape"&&(v.stopPropagation(),v.preventDefault(),a(),N(t,o,!0))}),w&&b instanceof HTMLInputElement&&b.type==="checkbox"&&b.addEventListener("change",()=>{const v=b.checked;l(v)}),setTimeout(()=>b.focus(),0)}d.appendChild(c)}else if(typeof h=="string"){const c=document.createElement(h);c.value=p,c.addEventListener("change",()=>l(c.value)),d.appendChild(c)}else if(typeof h=="function"){const c=h({row:e,value:p,field:i.field,column:i,commit:l,cancel:a});typeof c=="string"?d.innerHTML=c:d.appendChild(c)}else if(h&&typeof h=="object"){const c=document.createElement("div");c.setAttribute("data-external-editor",""),c.setAttribute("data-field",i.field),d.appendChild(c);const u={row:e,value:p,field:i.field,column:i,commit:l,cancel:a};if(h.mount)try{h.mount({placeholder:c,context:u,spec:h})}catch{}else t.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:c,spec:h,context:u}}))}}function ae(t,e){!t._sortState||t._sortState.field!==e.field?(t._sortState||(t.__originalOrder=t._rows.slice()),ce(t,e,1)):t._sortState.direction===1?ce(t,e,-1):(t._sortState=null,t.__rowRenderEpoch++,t._rowPool.forEach(i=>i.__epoch=-1),t._rows=t.__originalOrder.slice(),W(t),t._headerRowEl?.querySelectorAll('[role="columnheader"].sortable')?.forEach(i=>{i.getAttribute("aria-sort")?(i.getAttribute("aria-sort")==="ascending"||i.getAttribute("aria-sort")==="descending")&&(t._sortState||i.setAttribute("aria-sort","none")):i.setAttribute("aria-sort","none")}),t.refreshVirtualWindow(!0),t.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:0}})),t.requestStateChange?.())}function ce(t,e,o){t._sortState={field:e.field,direction:o};const i=e.sortComparator||((n,s)=>n==null&&s==null?0:n==null?-1:s==null||n>s?1:n<s?-1:0);t._rows.sort((n,s)=>i(n[e.field],s[e.field],n,s)*o),t.__rowRenderEpoch++,t._rowPool.forEach(n=>n.__epoch=-1),W(t),t.refreshVirtualWindow(!0),t.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:o}})),t.requestStateChange?.()}function qe(t,e){typeof e=="string"?t.textContent=e:e instanceof HTMLElement&&(t.innerHTML="",t.appendChild(e.cloneNode(!0)))}function W(t){t._headerRowEl=t.findHeaderRow();const e=t._headerRowEl;e.innerHTML="",t._visibleColumns.forEach((o,i)=>{const n=document.createElement("div");n.className="cell",j(n,"header-cell"),n.setAttribute("role","columnheader"),n.setAttribute("aria-colindex",String(i+1)),n.setAttribute("data-field",o.field),n.setAttribute("data-col",String(i));const s=o.__headerTemplate;if(s)Array.from(s.childNodes).forEach(r=>n.appendChild(r.cloneNode(!0)));else{const r=o.header||o.field,l=document.createElement("span");l.textContent=r,n.appendChild(l)}if(o.sortable){n.classList.add("sortable"),n.tabIndex=0;const r=document.createElement("span");j(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;qe(r,d),n.appendChild(r),n.setAttribute("aria-sort",l===0?"none":l===1?"ascending":"descending"),n.addEventListener("click",f=>{t._resizeController?.isResizing||t._dispatchHeaderClick?.(f,i,n)||ae(t,o)}),n.addEventListener("keydown",f=>{if(f.key==="Enter"||f.key===" "){if(f.preventDefault(),t._dispatchHeaderClick?.(f,i,n))return;ae(t,o)}})}if(o.resizable){n.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,i,n)}),r.addEventListener("dblclick",l=>{l.stopPropagation(),l.preventDefault(),t._resizeController.resetColumn(i)}),n.appendChild(r)}e.appendChild(n)}),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 Be(t){let e=null,o=null,i=null,n=null;const s=a=>{if(!e)return;const d=a.clientX-e.startX,f=Math.max(40,e.startWidth+d),h=t._visibleColumns[e.colIndex];h.width=f,h.__userResized=!0,h.__renderedWidth=f,o==null&&(o=requestAnimationFrame(()=>{o=null,t.updateTemplate?.()})),t.dispatchEvent(new CustomEvent("column-resize",{detail:{field:h.field,width:f}}))};let r=!1;const l=()=>{const a=e!==null;a&&(r=!0,requestAnimationFrame(()=>{r=!1})),window.removeEventListener("mousemove",s),window.removeEventListener("mouseup",l),i!==null&&(document.documentElement.style.cursor=i,i=null),n!==null&&(document.body.style.userSelect=n,n=null),e=null,a&&t.requestStateChange&&t.requestStateChange()};return{get isResizing(){return e!==null||r},start(a,d,f){a.preventDefault();const h=f.getBoundingClientRect();e={startX:a.clientX,colIndex:d,startWidth:h.width},window.addEventListener("mousemove",s),window.addEventListener("mouseup",l),i===null&&(i=document.documentElement.style.cursor),document.documentElement.style.cursor="e-resize",n===null&&(n=document.body.style.userSelect),document.body.style.userSelect="none"},resetColumn(a){const d=t._visibleColumns[a];d&&(d.__userResized=!1,d.__renderedWidth=void 0,d.width=d.__originalWidth,t.updateTemplate?.(),t.requestStateChange?.(),t.dispatchEvent(new CustomEvent("column-resize-reset",{detail:{field:d.field,width:d.width}})))},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 We(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 Ge(t,e,o="☰"){const i=t?.header?.title??"",n=!!i,s=V(o),r=t?.header?.toolbarButtons??[],l=r.length>0,a=e.toolbarButtons.size>0,d=e.lightDomButtons.length>0,f=e.toolPanels.size>0,p=(l||a||d)&&f,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 b="";for(const w of c)w.icon&&w.action&&(b+=`<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&&(b+=`<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)&&(b+=`<div class="tbw-toolbar-btn-slot" data-btn-slot="${w.id}"></div>`);for(const w of u)(w.element||w.render)&&(b+=`<div class="tbw-toolbar-btn-slot" data-btn-slot="${w.id}"></div>`);if(d&&(b+='<slot name="toolbar"></slot>'),p&&(b+='<div class="tbw-toolbar-separator"></div>'),f){const w=e.isPanelOpen;b+=`<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(E,V){typeof exports=="object"&&typeof module<"u"?V(exports):typeof define=="function"&&define.amd?define(["exports"],V):(E=typeof globalThis<"u"?globalThis:E||self,V(E.TbwGrid={}))})(this,(function(E){"use strict";const V=':root{color-scheme:light dark}:host{--tbw-color-bg: transparent;--tbw-color-panel-bg: light-dark(#eeeeee, #222222);--tbw-color-fg: light-dark(#222222, #eeeeee);--tbw-color-fg-muted: light-dark(#555555, #aaaaaa);--tbw-color-accent: light-dark(#3b82f6, #3b82f6);--tbw-color-accent-fg: light-dark(#ffffff, #000000);--tbw-color-success: light-dark(hsl(122, 39%, 40%), hsl(122, 39%, 49%));--tbw-color-selection: light-dark(#fff7d6, #333333);--tbw-color-row-alt: var(--tbw-color-bg);--tbw-color-row-hover: light-dark(#f0f6ff, #1c1c1c);--tbw-color-header-bg: color-mix(in hsl, var(--tbw-color-panel-bg) 85%, var(--tbw-color-fg));--tbw-color-header-fg: color-mix(in hsl, var(--tbw-color-fg) 75%, var(--tbw-color-panel-bg));--tbw-color-border: light-dark(#d0d0d4, #454545);--tbw-color-border-strong: light-dark(#777777, #adacac);--tbw-color-border-cell: var(--tbw-color-border);--tbw-color-border-header: var(--tbw-color-border);--tbw-color-shadow: light-dark(rgba(0, 0, 0, .1), rgba(0, 0, 0, .3));--tbw-font-family: inherit;--tbw-font-size: inherit;--tbw-font-size-header: var(--tbw-font-size);--tbw-font-weight-header: bold;--tbw-cell-padding-header: 2px 8px;--tbw-cell-padding: 2px 8px;--tbw-cell-padding-input: 2px 6px;--tbw-row-height: 28px;--tbw-header-height: 30px;--tbw-cell-white-space: nowrap;--tbw-border-radius: 4px;--tbw-border-input: 1px solid var(--tbw-color-border-strong);--tbw-border-header: 1px solid var(--tbw-color-border-header);--tbw-row-divider: 1px solid var(--tbw-color-border-cell);--tbw-row-hover-outline: 0;--tbw-color-active-row-bg: var(--tbw-color-selection);--tbw-active-row-outline: 0;--tbw-focus-outline: 2px solid var(--tbw-color-accent);--tbw-focus-outline-offset: -2px;--tbw-focus-background: rgba(from var(--tbw-color-accent) r g b / 12%);--tbw-range-border-color: var(--tbw-color-accent);--tbw-range-selection-bg: rgba(from var(--tbw-range-border-color) r g b / 12%);--tbw-resize-handle-width: 6px;--tbw-resize-handle-color: transparent;--tbw-resize-handle-color-hover: var(--tbw-color-accent);--tbw-resize-handle-border-radius: 0;--tbw-scrollbar-thumb: var(--tbw-color-border-strong);--tbw-scrollbar-track: var(--tbw-color-bg);--tbw-transition-duration: .12s;--tbw-transition-ease: ease;--tbw-animation-duration: .2s;--tbw-animation-easing: ease-out;--tbw-animation-enabled: 1;--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;opacity:.6}:host .header-row>.cell:last-child{border-right:0}:host .header-group-cell:not(:last-child),:host .header-row>.cell.grouped.group-end:not(:last-child){border-right:2px solid var(--tbw-color-border)}:host .tbw-grid-root{display:flex;flex-direction:column;height:100%}:host .rows-body-wrapper{flex:1;min-height:0;display:flex;flex-direction:row;width:100%;min-width:fit-content}:host .rows-body{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow:visible}:host .rows-container{display:flex;flex-direction:row;flex:1;min-height:0;overflow:visible}:host .rows-viewport{flex:1;min-width:0;position:relative;display:block;overflow:clip}:host .faux-vscroll{position:sticky;inset-inline-end:0;flex-shrink:0;width:auto;overflow-y:auto;overflow-x:hidden;z-index:var(--tbw-z-layer-header, 30)}:host .faux-vscroll-spacer{width:1px}:host .rows-viewport .rows{position:absolute;top:0;left:0;min-width:100%;will-change:transform;z-index:var(--tbw-z-layer-rows, 1)}:host .data-grid-row{display:grid;grid-template-columns:var(--tbw-column-template);contain:layout style}:host .data-grid-row:has(.editing){background:var(--tbw-editing-bg)}:host .selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}:host .data-grid-row>.cell.selected:focus-visible,:host .data-grid-row>.cell:focus-visible:not(.cell-focus){outline:none}:host .data-grid-row>.cell{display:block;padding:var(--tbw-cell-padding, 2px 8px);border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height);line-height:calc(var(--tbw-row-height) - 5px);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0;white-space:var(--tbw-cell-white-space, nowrap);text-overflow:ellipsis}:host .data-grid-row>.cell>*{overflow:hidden;text-overflow:ellipsis;white-space:inherit;min-width:0}:host .data-grid-row>.cell:last-child{border-right:0}:host .data-grid-row>.cell[data-type=boolean]{text-align:center}:host .data-grid-row>.cell[data-type=boolean] input[type=checkbox]{margin:0;width:var(--tbw-checkbox-size);height:var(--tbw-checkbox-size);vertical-align:middle}:host .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex}:host .data-grid-row>.cell.editing input:not([type=checkbox]),:host .data-grid-row>.cell.editing select,:host .data-grid-row>.cell.editing textarea{width:100%;height:100%;max-width:100%;flex:1 1 auto;min-width:0;border:var(--tbw-editing-border);padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor)}:host .data-grid-row:nth-child(2n){background:var(--tbw-color-row-alt)}:host .data-grid-row:hover{background:var(--tbw-color-row-hover)}:host .sortable{cursor:pointer;-webkit-user-select:none;user-select:none}:host .resize-handle{position:absolute;top:0;right:calc(var(--tbw-resize-handle-width) / -2);width:var(--tbw-resize-handle-width);height:100%;cursor:e-resize;-webkit-user-select:none;user-select:none;touch-action:none;z-index:20;background:var(--tbw-resize-handle-color);transition:background .12s ease;border-radius:var(--tbw-resize-handle-border-radius)}:host .resize-handle:hover{background:var(--tbw-resize-handle-color-hover)}:host .cell-focus,:host .row-focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}:host .group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-color-row-alt);font-weight:500;border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height)}:host .group-row .cell{display:flex;align-items:center;padding:var(--tbw-cell-padding, 2px 8px)}:host .group-row .group-toggle{background:none;border:0;cursor:pointer;padding:0 4px 0 0;font:inherit}:host .group-row .group-count{margin-left:4px;opacity:.7}:host .sticky-left,:host .sticky-right{position:sticky;z-index:25}:host .header-row>.cell.sticky-left,:host .header-row>.cell.sticky-right{background:var(--tbw-color-header-bg);z-index:35}:host .data-grid-row>.cell.sticky-left,:host .data-grid-row>.cell.sticky-right{background:var(--tbw-color-panel-bg)}:host .sticky-left{box-shadow:1px 0 0 var(--tbw-color-border)}:host .sticky-right{box-shadow:-1px 0 0 var(--tbw-color-border)}.grid-container{position:relative;width:100%;height:100%}.grid-placeholder{padding:2rem;text-align:center;color:var(--tbw-color-fg);opacity:.6}:host{--tbw-shell-header-height: 44px;--tbw-shell-header-bg: var(--tbw-color-panel-bg);--tbw-shell-header-border: var(--tbw-color-border);--tbw-shell-title-font-size: 14px;--tbw-shell-title-font-weight: 600;--tbw-tool-panel-width: 280px;--tbw-tool-panel-bg: var(--tbw-color-panel-bg);--tbw-tool-panel-border: var(--tbw-color-border);--tbw-tool-panel-header-height: 40px;--tbw-tool-panel-transition: var(--tbw-animation-duration) var(--tbw-animation-easing);--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 var(--tbw-transition-duration) var(--tbw-transition-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}@media(prefers-reduced-motion:reduce){:host([data-animation-mode="reduced-motion"]){--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms}}:host([data-animation-mode="off"]){--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms}:host .tbw-expanding{animation:tbw-expand var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}:host .tbw-collapsing{animation:tbw-collapse var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}@keyframes tbw-expand{0%{opacity:0;max-height:0;transform:translateY(-8px)}to{opacity:1;max-height:500px;transform:translateY(0)}}@keyframes tbw-collapse{0%{opacity:1;max-height:500px;transform:translateY(0)}to{opacity:0;max-height:0;transform:translateY(-8px)}}:host .tbw-fade-in{animation:tbw-fade-in var(--tbw-animation-duration) var(--tbw-animation-easing) forwards}:host .tbw-fade-out{animation:tbw-fade-out var(--tbw-animation-duration) var(--tbw-animation-easing) forwards}@keyframes tbw-fade-in{0%{opacity:0}to{opacity:1}}@keyframes tbw-fade-out{0%{opacity:1}to{opacity:0}}:host .tbw-flip-animating{will-change:transform;z-index:1}:host .tbw-toggle-icon{display:inline-flex;align-items:center;justify-content:center;transition:transform var(--tbw-animation-duration) var(--tbw-animation-easing)}:host .tbw-toggle-icon.tbw-expanded{transform:rotate(90deg)}';function Ee(t){const e=new Map;return t._sortState&&e.set(t._sortState.field,{direction:t._sortState.direction===1?"asc":"desc",priority:0}),e}function te(t,e){const o=t._columns,n=Ee(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 f=d.getColumnState(i.field);f&&Object.assign(r,f)}return r})}}function Ce(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,f=i.get(a.field)?.order??1/0;return d-f}),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 ye(t,e,o){let n=null;return()=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{n=null;const i=te(t,e());o(i)},100)}}const q={STRETCH:"stretch",FIXED:"fixed"},oe={mode:"reduced-motion",duration:200,easing:"ease-out"},P={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰"};function Se(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 ne(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=Se(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 Re=/{{\s*([^}]+)\s*}}/g,H="__DG_EMPTY__",Ae=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,xe=/__(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/,Te=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"]),ie=/^on\w+$/i,Le=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),Pe=/^\s*(javascript|vbscript|data|blob):/i;function X(t){if(!t||typeof t!="string")return"";if(t.indexOf("<")===-1)return t;const e=document.createElement("template");return e.innerHTML=t,He(e.content),e.innerHTML}function He(t){const e=[],o=t.querySelectorAll("*");for(const n of o){const i=n.tagName.toLowerCase();if(Te.has(i)){e.push(n);continue}if((i==="svg"||n.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(n.attributes).some(l=>ie.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(ie.test(l)){s.push(r.name);continue}if(Le.has(l)&&Pe.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 se(t,e){if(!t||t.indexOf("{{")===-1)return t;const o=[],n=t.replace(Re,(l,a)=>{const d=ke(a,e);return o.push({expr:a.trim(),result:d}),d}),i=Oe(n),s=o.length&&o.every(l=>l.result===""||l.result===H);return/Reflect\.|\bProxy\b|ownKeys\(/.test(t)||s?"":i}function ke(t,e){if(t=(t||"").trim(),!t||/\b(Reflect|Proxy|ownKeys)\b/.test(t))return H;if(t==="value")return e.value==null?H: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?H:String(i)}if(t.length>80||!Ae.test(t)||xe.test(t))return H;const o=t.match(/\./g);if(o&&o.length>1)return H;try{const i=new Function("value","row",`return (${t});`)(e.value,e.row),s=i==null?"":String(i);return/Reflect|Proxy|ownKeys/.test(s)?H:s||H}catch{return H}}function Oe(t){return t&&t.replace(new RegExp(H,"g"),"").replace(/Reflect\.[^<>{}\s]+/g,"").replace(/\bProxy\b/g,"").replace(/ownKeys\([^)]*\)/g,"")}function Me(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 re(t){const e=/Reflect\.|\bProxy\b|ownKeys\(/.test(t),o=n=>e?"":se(t,n);return o.__blocked=e,o}function ze(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"),f={field:n,type:r,header:l,sortable:a,editable:d};o.hasAttribute("resizable")&&(f.resizable=!0),o.hasAttribute("sizable")&&(f.resizable=!0);const h=o.getAttribute("options");h&&(f.options=h.split(",").map(b=>{const[w,v]=b.includes(":")?b.split(":"):[b.trim(),b.trim()];return{value:w.trim(),label:v?.trim()||w.trim()}}));const p=o.querySelector("tbw-grid-column-view"),c=o.querySelector("tbw-grid-column-editor"),u=o.querySelector("tbw-grid-column-header");return p&&(f.__viewTemplate=p),c&&(f.__editorTemplate=c),u&&(f.__headerTemplate=u),f}).filter(o=>!!o)}function De(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 Y(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 Ne(t){t.__lightDomColumnsCache||(t.__originalColumnNodes=Array.from(t.querySelectorAll("tbw-grid-column")),t.__lightDomColumnsCache=t.__originalColumnNodes.length?ze(t):[]);const e=t.__lightDomColumnsCache,o=De(t._columns,e);o.forEach(i=>{i.__viewTemplate&&!i.__compiledView&&(i.__compiledView=re(i.__viewTemplate.innerHTML)),i.__editorTemplate&&!i.__compiledEditor&&(i.__compiledEditor=re(i.__editorTemplate.innerHTML))});const{columns:n}=ne(t._rows,o);t._columns=n}function le(t){const e=t.effectiveConfig?.fitMode||t.fitMode||q.STRETCH;if(e!==q.STRETCH&&e!==q.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 f=d.scrollWidth;f>l&&(l=f)}}l>0&&(i.width=l+2,i.__autoSized=!0,n=!0)}),n&&D(t),t.__didInitialAutoSize=!0}function D(t){(t.effectiveConfig?.fitMode||t.fitMode||q.STRETCH)===q.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 Ie(t){switch(t.type){case"number":return e=>{const o=document.createElement("input");return o.type="number",o.value=e.value!=null?String(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!=null?String(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 qe(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=f=>{if(!f)return!1;const h=f.tagName;return!!(h==="INPUT"||h==="SELECT"||h==="TEXTAREA"||f.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),z(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":(e.ctrlKey||e.metaKey)&&(i&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=0),t._focusCol=0,e.preventDefault(),z(t,{forceScrollLeft:!0});return;case"End":(e.ctrlKey||e.metaKey)&&(i&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=o),t._focusCol=n,e.preventDefault(),z(t,{forceScrollRight:!0});return;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}})),z(t);default:return}z(t)}}function z(t,e){if(t._virtualization?.enabled){const{rowHeight:r,container:l,viewportEl:a}=t._virtualization,d=l,f=a?.clientHeight??d?.clientHeight??0;if(d&&f>0){const h=t._focusRow*r;h<d.scrollTop?d.scrollTop=h:h+r>d.scrollTop+f&&(d.scrollTop=h-f+r)}}t._activeEditRows!==void 0&&t._activeEditRows!==-1||t.refreshVirtualWindow(!1),Array.from(t._bodyEl.querySelectorAll(".cell-focus")).forEach(r=>r.classList.remove("cell-focus")),Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(r=>{r.setAttribute("aria-selected","false")});const n=t._focusRow,i=t._virtualization.start??0,s=t._virtualization.end??t._rows.length;if(n>=i&&n<s){const r=t._bodyEl.querySelectorAll(".data-grid-row")[n-i],l=r?.children[t._focusCol];if(l){l.classList.add("cell-focus"),l.setAttribute("aria-selected","true");const a=t.shadowRoot?.querySelector(".tbw-scroll-area");if(a&&l)if(e?.forceScrollLeft)a.scrollLeft=0;else if(e?.forceScrollRight)a.scrollLeft=a.scrollWidth-a.clientWidth;else{const d=t._getHorizontalScrollOffsets?.(r??void 0,l)??{left:0,right:0};if(!d.skipScroll){const f=l.getBoundingClientRect(),h=a.getBoundingClientRect(),p=f.left-h.left+a.scrollLeft,c=p+f.width,u=a.scrollLeft+d.left,b=a.scrollLeft+a.clientWidth-d.right;p<u?a.scrollLeft=p-d.left:c>b&&(a.scrollLeft=c-a.clientWidth+d.right)}}if(t._activeEditRows!==void 0&&t._activeEditRows!==-1&&l.classList.contains("editing")){const d=l.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(d&&document.activeElement!==d)try{d.focus()}catch{}}else if(!l.contains(document.activeElement)){l.hasAttribute("tabindex")||l.setAttribute("tabindex","-1");try{l.focus({preventScroll:!0})}catch{}}}}}const Be="__cellDisplayCache",$e="__cellCacheEpoch";function j(t){t[Be]=void 0,t[$e]=void 0,t.__hasSpecialColumns=void 0}function We(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 h=document.createElement("div");h.className="data-grid-row",h.setAttribute("role","row"),h.addEventListener("click",p=>ae(t,p,h,!1)),h.addEventListener("dblclick",p=>ae(t,p,h,!0)),t._rowPool.push(h)}if(t._rowPool.length>s){for(let h=s;h<t._rowPool.length;h++){const p=t._rowPool[h];p.parentNode===r&&p.remove()}t._rowPool.length=s}const f=i&&t.__hasRenderRowPlugins!==!1;for(let h=0;h<s;h++){const p=e+h,c=t._rows[p],u=t._rowPool[h];if(u.setAttribute("aria-rowindex",String(p+d+1)),f&&i(c,u,p)){u.__epoch=n,u.__rowDataRef=c,u.parentNode!==r&&r.appendChild(u);continue}const b=u.__epoch,w=u.__rowDataRef,v=u.children.length,A=b===n&&v===a,C=w!==c;let g=!1;if(A&&C){for(let _=0;_<a;_++)if(l[_].externalView&&!u.querySelector(`.cell[data-col="${_}"] [data-external-view]`)){g=!0;break}}if(!A||g){const _=u.querySelector(".cell.editing"),S=t._activeEditRows===p;if(_&&!S)u.__isCustomRow&&(u.className="data-grid-row",u.setAttribute("role","row"),u.__isCustomRow=!1),B(t,u,c,p),u.__epoch=n,u.__rowDataRef=c;else if(_&&S)K(t,u,c,p),u.__rowDataRef=c;else if(u.__isCustomRow&&(u.className="data-grid-row",u.setAttribute("role","row"),u.__isCustomRow=!1),B(t,u,c,p),u.__epoch=n,u.__rowDataRef=c,S){const x=u.children;for(let L=0;L<x.length;L++){const O=t._visibleColumns[L];O&&O.editable&&M(t,c,p,O,x[L])}}}else if(C){const _=u.querySelector(".cell.editing"),S=t._activeEditRows===p;if(_&&!S)B(t,u,c,p),u.__epoch=n,u.__rowDataRef=c;else if(K(t,u,c,p),u.__rowDataRef=c,S&&!_){const x=u.children;for(let L=0;L<x.length;L++){const O=t._visibleColumns[L];O&&O.editable&&M(t,c,p,O,x[L])}}}else{const _=u.querySelector(".cell.editing"),S=t._activeEditRows===p;if(_&&!S)B(t,u,c,p),u.__epoch=n,u.__rowDataRef=c;else if(K(t,u,c,p),S&&!_){const x=u.children;for(let L=0;L<x.length;L++){const O=t._visibleColumns[L];O&&O.editable&&M(t,c,p,O,x[L])}}}const m=t._changedRowIndices.has(p),y=u.classList.contains("changed");m!==y&&u.classList.toggle("changed",m),u.parentNode!==r&&r.appendChild(u)}}function K(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,f=t._focusCol;let h=t.__hasSpecialColumns;if(h===void 0){h=!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"){h=!0;break}}t.__hasSpecialColumns=h}const p=String(n);if(!h){for(let c=0;c<a;c++){const u=i[c],b=o[s[c].field];u.textContent=b==null?"":String(b),u.getAttribute("data-row")!==p&&u.setAttribute("data-row",p);const w=d===n&&f===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]")){B(t,e,o,n);return}for(let c=0;c<a;c++){const u=s[c],b=i[c];b.getAttribute("data-row")!==p&&b.setAttribute("data-row",p);const w=d===n&&f===c,v=b.classList.contains("cell-focus");if(w!==v&&(b.classList.toggle("cell-focus",w),b.setAttribute("aria-selected",String(w))),b.classList.contains("editing"))continue;if(u.viewRenderer){const C=o[u.field],g=u.viewRenderer({row:o,value:C,field:u.field,column:u});typeof g=="string"?b.innerHTML=X(g):g?(b.innerHTML="",b.appendChild(g)):b.textContent=C==null?"":String(C);continue}if(u.__viewTemplate||u.__compiledView||u.externalView)continue;const R=o[u.field];let A;if(u.format)try{const C=u.format(R,o);A=C==null?"":String(C)}catch{A=R==null?"":String(R)}else if(u.type==="date"){if(R==null||R==="")A="";else if(R instanceof Date)A=isNaN(R.getTime())?"":R.toLocaleDateString();else{const C=new Date(R);A=isNaN(C.getTime())?"":C.toLocaleDateString()}b.textContent=A}else if(u.type==="boolean"){const C=!!R;b.innerHTML=`<span role="checkbox" aria-checked="${C}" aria-label="${C}">${C?"&#x1F5F9;":"&#9744;"}</span>`}else A=R==null?"":String(R),b.textContent=A}}function B(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,f=document.createDocumentFragment();for(let h=0;h<s;h++){const p=i[h],c=document.createElement("div");c.className="cell",Y(c,"cell"),c.setAttribute("role","gridcell"),c.setAttribute("aria-colindex",String(h+1)),c.setAttribute("data-col",String(h)),c.setAttribute("data-row",String(n)),c.setAttribute("data-field",p.field),p.type,p.type&&c.setAttribute("data-type",p.type);let u=o[p.field];const b=p.format;if(b)try{u=b(u,o)}catch{}const w=p.__compiledView,v=p.__viewTemplate,R=p.viewRenderer,A=p.externalView;let C=!1;if(R){const g=R({row:o,value:u,field:p.field,column:p});typeof g=="string"?(c.innerHTML=X(g),C=!0):g?c.appendChild(g):c.textContent=u==null?"":String(u)}else if(A){const g=A,m=document.createElement("div");m.setAttribute("data-external-view",""),m.setAttribute("data-field",p.field),c.appendChild(m);const y={row:o,value:u,field:p.field,column:p};if(g.mount)try{g.mount({placeholder:m,context:y,spec:g})}catch{}else queueMicrotask(()=>{try{d.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:m,spec:g,context:y}}))}catch{}});m.setAttribute("data-mounted","")}else if(w){const g=w({row:o,value:u,field:p.field,column:p}),m=w.__blocked;c.innerHTML=m?"":X(g),C=!0,m&&(c.textContent="",c.setAttribute("data-blocked-template",""))}else if(v){const g=v.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(g)?(c.textContent="",c.setAttribute("data-blocked-template","")):(c.innerHTML=X(se(g,{row:o,value:u})),C=!0)}else if(p.type==="date")if(u==null||u==="")c.textContent="";else{let g=null;if(u instanceof Date)g=u;else if(typeof u=="number"||typeof u=="string"){const m=new Date(u);isNaN(m.getTime())||(g=m)}c.textContent=g?g.toLocaleDateString():""}else if(p.type==="boolean"){const g=!!u;c.innerHTML=`<span role="checkbox" aria-checked="${g}" aria-label="${g}">${g?"&#x1F5F9;":"&#9744;"}</span>`}else c.textContent=u==null?"":String(u);if(C){Me(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=""),p.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,z(t))}),a==="click"?c.addEventListener("click",g=>{if(c.classList.contains("editing"))return;g.stopPropagation();const m=Number(c.getAttribute("data-row")),y=Number(c.getAttribute("data-col"));if(isNaN(m)||isNaN(y))return;const _=t._rows[m],S=t._visibleColumns[y];!_||!S||(t._focusRow=m,t._focusCol=y,M(t,_,m,S,c))}):c.addEventListener("dblclick",g=>{g.stopPropagation();const m=Number(c.getAttribute("data-row"));if(isNaN(m))return;const y=t._rows[m];if(!y)return;$(t,m,y);const _=t.findRenderedRowElement?.(m);if(_){const S=_.children;for(let x=0;x<S.length;x++){const L=t._visibleColumns[x];L&&L.editable&&M(t,y,m,L,S[x])}}}),c.addEventListener("keydown",g=>{const m=Number(c.getAttribute("data-row")),y=Number(c.getAttribute("data-col"));if(isNaN(m)||isNaN(y))return;const _=t._rows[m],S=t._visibleColumns[y];if(!(!_||!S)){if((S.type==="select"||S.type==="typeahead")&&!c.classList.contains("editing")&&g.key==="Enter"){g.preventDefault(),t._activeEditRows!==m&&$(t,m,_),M(t,_,m,S,c),setTimeout(()=>{const x=c.querySelector("select");try{x?.showPicker?.()}catch{}x?.focus()},0);return}if(S.type==="boolean"&&g.key===" "&&!c.classList.contains("editing")){g.preventDefault(),t._activeEditRows!==m&&$(t,m,_);const x=!_[S.field];Q(t,m,S,x,_),c.innerHTML=`<span role="checkbox" aria-checked="${x}" aria-label="${x}">${x?"&#x1F5F9;":"&#9744;"}</span>`;return}if(g.key==="Enter"&&!c.classList.contains("editing")){g.preventDefault(),g.stopPropagation(),t._focusRow=m,t._focusCol=y,typeof t.beginBulkEdit=="function"?t.beginBulkEdit(m):M(t,_,m,S,c);return}if(g.key==="F2"&&!c.classList.contains("editing")){g.preventDefault(),M(t,_,m,S,c);return}}})):p.type==="boolean"&&(c.hasAttribute("tabindex")||(c.tabIndex=0)),r===n&&l===h?(c.classList.add("cell-focus"),c.setAttribute("aria-selected","true")):c.setAttribute("aria-selected","false"),f.appendChild(c)}e.appendChild(f)}function ae(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||t._dispatchRowClick?.(e,s,r,o))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,z(t)}}if(o.querySelector(".cell.editing")){const d=o.querySelectorAll(".cell.editing");if(!n)return;d.forEach(f=>f.classList.remove("editing"))}const a=t.effectiveConfig?.editOn||t.editOn||"doubleClick";if(a==="click"||a==="doubleClick"&&n)$(t,s,r);else return;Array.from(o.children).forEach((d,f)=>{const h=t._visibleColumns[f];h&&h.editable&&M(t,r,s,h,d)}),l&&queueMicrotask(()=>{const d=o.querySelector(`.cell[data-col="${t._focusCol}"]`);if(d?.classList.contains("editing")){const f=d.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');try{f?.focus()}catch{}}})}function Z(t){return!(t==="__proto__"||t==="constructor"||t==="prototype")}function $(t,e,o){t._activeEditRows!==e&&(t._rowEditSnapshots.set(e,{...o}),t._activeEditRows=e)}function N(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 f=l.querySelector("input,textarea,select");if(f){let h;f instanceof HTMLInputElement&&f.type==="checkbox"?h=f.checked:(h=f.value,d.type==="number"&&h!==""&&(h=Number(h))),i[d.field]!==h&&Q(t,e,d,h,i)}}),o&&n&&i)Object.keys(n).forEach(r=>i[r]=n[r]),t._changedRowIndices.delete(e),j(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&&(B(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(f=>f.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 Q(t,e,o,n,i){const s=o.field;if(!Z(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&&$(t,o,e),i.classList.contains("editing")))return;const s=Z(n.field)?e[n.field]:void 0;i.classList.add("editing");let r=!1;const l=c=>{r||t._activeEditRows===-1||Q(t,o,n,c,e)},a=()=>{r=!0,e[n.field]=Z(n.field)?s:void 0;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,N(t,o,!1)),c.key==="Escape"&&(c.stopPropagation(),c.preventDefault(),a(),N(t,o,!0))});const f=n.__editorTemplate,h=n.editor||(f?"template":Ie(n)),p=s;if(h==="template"&&f){const c=f.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,R)=>{const A=e[R];return A==null?"":String(A)})||"")});const b=c.querySelector("input,textarea,select");if(b){const w=typeof HTMLInputElement<"u";w&&b instanceof HTMLInputElement&&b.type==="checkbox"?b.checked=!!s:"value"in b&&(b.value=s??""),b.addEventListener("blur",()=>{const v=w&&b instanceof HTMLInputElement&&b.type==="checkbox"?b.checked:b.value;l(v)}),b.addEventListener("keydown",v=>{if(v.key==="Enter"){v.stopPropagation(),v.preventDefault(),r=!0;const R=w&&b instanceof HTMLInputElement&&b.type==="checkbox"?b.checked:b.value;l(R),N(t,o,!1)}v.key==="Escape"&&(v.stopPropagation(),v.preventDefault(),a(),N(t,o,!0))}),w&&b instanceof HTMLInputElement&&b.type==="checkbox"&&b.addEventListener("change",()=>{const v=b.checked;l(v)}),setTimeout(()=>b.focus(),0)}d.appendChild(c)}else if(typeof h=="string"){const c=document.createElement(h);c.value=p,c.addEventListener("change",()=>l(c.value)),d.appendChild(c)}else if(typeof h=="function"){const c=h({row:e,value:p,field:n.field,column:n,commit:l,cancel:a});typeof c=="string"?d.innerHTML=c:d.appendChild(c)}else if(h&&typeof h=="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:p,field:n.field,column:n,commit:l,cancel:a};if(h.mount)try{h.mount({placeholder:c,context:u,spec:h})}catch{}else t.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:c,spec:h,context:u}}))}}function ce(t,e){return t==null&&e==null?0:t==null?-1:e==null||t>e?1:t<e?-1:0}function de(t,e,o){const i=o.find(l=>l.field===e.field)?.sortComparator??ce,{field:s,direction:r}=e;return[...t].sort((l,a)=>i(l[s],a[s],l,a)*r)}function ue(t,e,o,n){t._rows=e,t.__rowRenderEpoch++,t._rowPool.forEach(i=>i.__epoch=-1),W(t),t.refreshVirtualWindow(!0),t.dispatchEvent(new CustomEvent("sort-change",{detail:{field:o.field,direction:n}})),t.requestStateChange?.()}function he(t,e){!t._sortState||t._sortState.field!==e.field?(t._sortState||(t.__originalOrder=t._rows.slice()),fe(t,e,1)):t._sortState.direction===1?fe(t,e,-1):(t._sortState=null,t.__rowRenderEpoch++,t._rowPool.forEach(n=>n.__epoch=-1),t._rows=t.__originalOrder.slice(),W(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 fe(t,e,o){t._sortState={field:e.field,direction:o};const n={field:e.field,direction:o},i=t._columns,r=(t.effectiveConfig?.sortHandler??de)(t._rows,n,i);r&&typeof r.then=="function"?r.then(l=>{ue(t,l,e,o)}):ue(t,r,e,o)}function Ve(t,e){typeof e=="string"?t.textContent=e:e instanceof HTMLElement&&(t.innerHTML="",t.appendChild(e.cloneNode(!0)))}function W(t){t._headerRowEl=t.findHeaderRow();const e=t._headerRowEl;e.innerHTML="",t._visibleColumns.forEach((o,n)=>{const i=document.createElement("div");i.className="cell",Y(i,"header-cell"),i.setAttribute("role","columnheader"),i.setAttribute("aria-colindex",String(n+1)),i.setAttribute("data-field",o.field),i.setAttribute("data-col",String(n));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");Y(r,"sort-indicator");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;Ve(r,d),i.appendChild(r),i.setAttribute("aria-sort",l===0?"none":l===1?"ascending":"descending"),i.addEventListener("click",f=>{t._resizeController?.isResizing||t._dispatchHeaderClick?.(f,n,i)||he(t,o)}),i.addEventListener("keydown",f=>{if(f.key==="Enter"||f.key===" "){if(f.preventDefault(),t._dispatchHeaderClick?.(f,n,i))return;he(t,o)}})}if(o.resizable){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)}),r.addEventListener("dblclick",l=>{l.stopPropagation(),l.preventDefault(),t._resizeController.resetColumn(n)}),i.appendChild(r)}e.appendChild(i)}),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 Ge(t){let e=null,o=null,n=null,i=null;const s=a=>{if(!e)return;const d=a.clientX-e.startX,f=Math.max(40,e.startWidth+d),h=t._visibleColumns[e.colIndex];h.width=f,h.__userResized=!0,h.__renderedWidth=f,o==null&&(o=requestAnimationFrame(()=>{o=null,t.updateTemplate?.()})),t.dispatchEvent(new CustomEvent("column-resize",{detail:{field:h.field,width:f}}))};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,f){a.preventDefault();const h=f.getBoundingClientRect();e={startX:a.clientX,colIndex:d,startWidth:h.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"},resetColumn(a){const d=t._visibleColumns[a];d&&(d.__userResized=!1,d.__renderedWidth=void 0,d.width=d.__originalWidth,t.updateTemplate?.(),t.requestStateChange?.(),t.dispatchEvent(new CustomEvent("column-resize-reset",{detail:{field:d.field,width:d.width}})))},dispose(){l()}}}function G(t){return t?typeof t=="string"?t:t.outerHTML:""}function Fe(){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 Ue(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 Xe(t,e,o="☰"){const n=t?.header?.title??"",i=!!n,s=G(o),r=t?.header?.toolbarButtons??[],l=r.length>0,a=e.toolbarButtons.size>0,d=e.lightDomButtons.length>0,f=e.toolPanels.size>0,p=(l||a||d)&&f,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 b="";for(const w of c)w.icon&&w.action&&(b+=`<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&&(b+=`<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)&&(b+=`<div class="tbw-toolbar-btn-slot" data-btn-slot="${w.id}"></div>`);for(const w of u)(w.element||w.render)&&(b+=`<div class="tbw-toolbar-btn-slot" data-btn-slot="${w.id}"></div>`);if(d&&(b+='<slot name="toolbar"></slot>'),p&&(b+='<div class="tbw-toolbar-separator"></div>'),f){const w=e.isPanelOpen;b+=`<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
- ${n?`<div class="tbw-shell-title">${i}</div>`:""}
3
+ ${i?`<div class="tbw-shell-title">${n}</div>`:""}
4
4
  <div class="tbw-shell-content" part="shell-content" role="presentation">
5
5
  <slot name="header-content"></slot>
6
6
  </div>
@@ -8,7 +8,7 @@
8
8
  ${b}
9
9
  </div>
10
10
  </div>
11
- `}function Ve(t,e,o,i){const n=t?.toolPanel?.position??"right",s=e.toolPanels.size>0,r=e.isPanelOpen,l=V(i?.expand??P.expand),a=V(i?.collapse??P.collapse),d=[...e.toolPanels.values()].sort((u,b)=>(u.order??100)-(b.order??100)),f=d.length===1;let h="";for(const u of d){const b=e.expandedSections.has(u.id),w=u.icon?`<span class="tbw-accordion-icon">${u.icon}</span>`:"",v=f?"":`<span class="tbw-accordion-chevron">${b?a:l}</span>`;h+=`
11
+ `}function Ye(t,e,o,n){const i=t?.toolPanel?.position??"right",s=e.toolPanels.size>0,r=e.isPanelOpen,l=G(n?.expand??P.expand),a=G(n?.collapse??P.collapse),d=[...e.toolPanels.values()].sort((u,b)=>(u.order??100)-(b.order??100)),f=d.length===1;let h="";for(const u of d){const b=e.expandedSections.has(u.id),w=u.icon?`<span class="tbw-accordion-icon">${u.icon}</span>`:"",v=f?"":`<span class="tbw-accordion-chevron">${b?a:l}</span>`;h+=`
12
12
  <div class="${`tbw-accordion-section${b?" expanded":""}${f?" single":""}`}" data-section="${u.id}">
13
13
  <button class="tbw-accordion-header" aria-expanded="${b}" aria-controls="tbw-section-${u.id}"${f?' aria-disabled="true"':""}>
14
14
  ${w}
@@ -18,15 +18,15 @@
18
18
  <div class="tbw-accordion-content" id="tbw-section-${u.id}" role="presentation"></div>
19
19
  </div>
20
20
  `}const c=s?`
21
- <aside class="tbw-tool-panel${r?" open":""}" part="tool-panel" data-position="${n}" role="presentation" id="tbw-tool-panel">
22
- <div class="tbw-tool-panel-resize" data-resize-handle data-handle-position="${n==="left"?"right":"left"}" aria-hidden="true"></div>
21
+ <aside class="tbw-tool-panel${r?" open":""}" part="tool-panel" data-position="${i}" role="presentation" id="tbw-tool-panel">
22
+ <div class="tbw-tool-panel-resize" data-resize-handle data-handle-position="${i==="left"?"right":"left"}" aria-hidden="true"></div>
23
23
  <div class="tbw-tool-panel-content" role="presentation">
24
24
  <div class="tbw-accordion">
25
25
  ${h}
26
26
  </div>
27
27
  </div>
28
28
  </aside>
29
- `:"";return n==="left"?`
29
+ `:"";return i==="left"?`
30
30
  <div class="tbw-shell-body">
31
31
  ${c}
32
32
  <div class="tbw-grid-content">
@@ -40,8 +40,8 @@
40
40
  </div>
41
41
  ${c}
42
42
  </div>
43
- `}function de(t,e){const o=t.querySelector("tbw-grid-header");if(!o)return;o.style.display="none";const i=o.querySelectorAll("tbw-grid-header-content");e.lightDomHeaderContent=Array.from(i),e.lightDomHeaderContent.forEach(s=>{s.setAttribute("slot","header-content")});const n=o.querySelectorAll("tbw-grid-tool-button");e.lightDomButtons=Array.from(n),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 Fe(t,e,o,i){const n=t.querySelector(".tbw-shell-toolbar");n&&n.addEventListener("click",r=>{const l=r.target;if(l.closest("[data-panel-toggle]")){i.onPanelToggle();return}const d=l.closest("[data-btn]");if(d){const f=d.getAttribute("data-btn");f&&i.onToolbarButtonClick(f)}});const s=t.querySelector(".tbw-accordion");s&&s.addEventListener("click",r=>{const a=r.target.closest(".tbw-accordion-header");if(a){const f=a.closest("[data-section]")?.getAttribute("data-section");f&&i.onSectionToggle(f)}})}function Ue(t,e,o){const i=t.querySelector(".tbw-tool-panel"),n=t.querySelector("[data-resize-handle]"),s=t.querySelector(".tbw-shell-body");if(!i||!n||!s)return()=>{};const r=e?.toolPanel?.position??"right",l=200;let a=0,d=0,f=0,h=!1;const p=b=>{if(!h)return;b.preventDefault();const w=r==="left"?b.clientX-a:a-b.clientX,v=Math.min(f,Math.max(l,d+w));i.style.width=`${v}px`},c=()=>{if(!h)return;h=!1,n.classList.remove("resizing"),i.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const b=i.getBoundingClientRect().width;o(b),document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",c)},u=b=>{b.preventDefault(),h=!0,a=b.clientX,d=i.getBoundingClientRect().width,f=s.getBoundingClientRect().width-20,n.classList.add("resizing"),i.style.transition="none",document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",p),document.addEventListener("mouseup",c)};return n.addEventListener("mousedown",u),()=>{n.removeEventListener("mousedown",u),document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",c)}}function Xe(t,e,o){const i=[...e?.header?.toolbarButtons??[],...o.toolbarButtons.values()];for(const n of i){const s=t.querySelector(`[data-btn-slot="${n.id}"]`);if(!s)continue;const r=o.toolbarButtonCleanups.get(n.id);if(r&&(r(),o.toolbarButtonCleanups.delete(n.id)),n.element)s.appendChild(n.element);else if(n.render){const l=n.render(s);l&&o.toolbarButtonCleanups.set(n.id,l)}}}function ue(t,e){const o=t.querySelector(".tbw-shell-content");if(!o)return;const i=[...e.headerContents.values()].sort((s,r)=>(s.order??100)-(r.order??100)),n=o.querySelector('slot[name="header-content"]');for(const s of i){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),n?o.insertBefore(l,n):o.appendChild(l));const a=s.render(l);a&&e.headerContentCleanups.set(s.id,a)}}function je(t,e,o){if(!e.isPanelOpen)return;const i=V(o?.expand??P.expand),n=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 f=a.querySelector(".tbw-accordion-header");f&&f.setAttribute("aria-expanded",String(l));const h=a.querySelector(".tbw-accordion-chevron");if(h&&(h.innerHTML=l?n:i),l){if(d.children.length===0){const p=r.render(d);p&&e.panelCleanups.set(s,p)}}else{const p=e.panelCleanups.get(s);p&&(p(),e.panelCleanups.delete(s)),d.innerHTML=""}}}function he(t,e){const o=t.querySelector("[data-panel-toggle]");o&&(o.classList.toggle("active",e.isPanelOpen),o.setAttribute("aria-pressed",String(e.isPanelOpen)))}function fe(t,e){const o=t.querySelector(".tbw-tool-panel");o&&(o.classList.toggle("open",e.isPanelOpen),e.isPanelOpen||(o.style.width=""))}function Ke(t,e){const o=[];for(const i of t?.header?.toolbarButtons??[])o.push({id:i.id,label:i.label,disabled:i.disabled??!1,source:"config"});for(const i of e.toolbarButtons.values())o.push({id:i.id,label:i.label,disabled:i.disabled??!1,source:"config"});for(let i=0;i<e.lightDomButtons.length;i++){const s=e.lightDomButtons[i].querySelector("button");o.push({id:`light-dom-${i}`,label:s?.getAttribute("title")??s?.getAttribute("aria-label")??"",disabled:s?.disabled??!1,source:"light-dom"})}for(const i of e.toolPanels.values())o.push({id:`panel-toggle-${i.id}`,label:i.tooltip??i.title,disabled:!1,source:"panel-toggle",panelId:i.id});return o}function Ye(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}function Ze(t,e){let o=!1;const i={get isInitialized(){return o},setInitialized(n){o=n},get isPanelOpen(){return t.isPanelOpen},get activePanel(){return t.isPanelOpen&&t.expandedSections.size>0?[...t.expandedSections][0]:null},get expandedSections(){return[...t.expandedSections]},openToolPanel(){if(t.isPanelOpen)return;if(t.toolPanels.size===0){console.warn("[tbw-grid] No tool panels registered");return}if(t.isPanelOpen=!0,t.expandedSections.size===0&&t.toolPanels.size>0){const r=[...t.toolPanels.values()].sort((l,a)=>(l.order??100)-(a.order??100))[0];r&&t.expandedSections.add(r.id)}const n=e.getShadow();he(n,t),fe(n,t),je(n,t,e.getAccordionIcons()),e.emit("tool-panel-open",{sections:i.expandedSections})},closeToolPanel(){if(!t.isPanelOpen)return;for(const s of t.panelCleanups.values())s();t.panelCleanups.clear(),t.activePanelCleanup&&(t.activePanelCleanup(),t.activePanelCleanup=null);for(const s of t.toolPanels.values())s.onClose?.();t.isPanelOpen=!1;const n=e.getShadow();he(n,t),fe(n,t),e.emit("tool-panel-close",{})},toggleToolPanel(){t.isPanelOpen?i.closeToolPanel():i.openToolPanel()},toggleToolPanelSection(n){const s=t.toolPanels.get(n);if(!s){console.warn(`[tbw-grid] Tool panel section "${n}" not found`);return}if(t.toolPanels.size===1)return;const r=e.getShadow(),l=t.expandedSections.has(n);if(l){const a=t.panelCleanups.get(n);a&&(a(),t.panelCleanups.delete(n)),s.onClose?.(),t.expandedSections.delete(n),J(r,n,!1)}else{for(const[a,d]of t.toolPanels)if(a!==n&&t.expandedSections.has(a)){const f=t.panelCleanups.get(a);f&&(f(),t.panelCleanups.delete(a)),d.onClose?.(),t.expandedSections.delete(a),J(r,a,!1);const h=r.querySelector(`[data-section="${a}"] .tbw-accordion-content`);h&&(h.innerHTML="")}t.expandedSections.add(n),J(r,n,!0),Qe(r,t,n)}e.emit("tool-panel-section-toggle",{id:n,expanded:!l})},getToolPanels(){return[...t.toolPanels.values()]},registerToolPanel(n){if(t.toolPanels.has(n.id)){console.warn(`[tbw-grid] Tool panel "${n.id}" already registered`);return}t.toolPanels.set(n.id,n),o&&e.refreshShellHeader()},unregisterToolPanel(n){if(t.expandedSections.has(n)){const s=t.panelCleanups.get(n);s&&(s(),t.panelCleanups.delete(n)),t.expandedSections.delete(n)}t.toolPanels.delete(n),o&&e.refreshShellHeader()},getHeaderContents(){return[...t.headerContents.values()]},registerHeaderContent(n){if(t.headerContents.has(n.id)){console.warn(`[tbw-grid] Header content "${n.id}" already registered`);return}t.headerContents.set(n.id,n),o&&ue(e.getShadow(),t)},unregisterHeaderContent(n){const s=t.headerContentCleanups.get(n);s&&(s(),t.headerContentCleanups.delete(n)),t.headerContents.get(n)?.onDestroy?.(),t.headerContents.delete(n),e.getShadow().querySelector(`[data-header-content="${n}"]`)?.remove()},getToolbarButtons(){return Ke(e.getShellConfig(),t)},registerToolbarButton(n){if(t.toolbarButtons.has(n.id)){console.warn(`[tbw-grid] Toolbar button "${n.id}" already registered`);return}t.toolbarButtons.set(n.id,n),o&&e.refreshShellHeader()},unregisterToolbarButton(n){const s=t.toolbarButtonCleanups.get(n);s&&(s(),t.toolbarButtonCleanups.delete(n)),t.toolbarButtons.delete(n),o&&e.refreshShellHeader()},setToolbarButtonDisabled(n,s){const r=t.toolbarButtons.get(n);r&&(r.disabled=s);const l=e.getShadow().querySelector(`[data-btn="${n}"]`);l&&(l.disabled=s)}};return i}function J(t,e,o){const i=t.querySelector(`[data-section="${e}"]`);i&&i.classList.toggle("expanded",o)}function Qe(t,e,o){const i=e.toolPanels.get(o);if(!i?.render)return;const n=t.querySelector(`[data-section="${o}"] .tbw-accordion-content`);if(!n)return;const s=i.render(n);s&&e.panelCleanups.set(o,s)}class pe{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,i]of Object.entries(e.cellRenderers))this.cellRenderers.set(o,i);if(e.headerRenderers)for(const[o,i]of Object.entries(e.headerRenderers))this.headerRenderers.set(o,i);if(e.cellEditors)for(const[o,i]of Object.entries(e.cellEditors))this.cellEditors.set(o,i);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 i of this.plugins)i.processRows&&(o=i.processRows(o));return o}processColumns(e){let o=[...e];for(const i of this.plugins)i.processColumns&&(o=i.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 i of this.plugins)typeof i.getExtraHeightBefore=="function"&&(o+=i.getExtraHeightBefore(e));return o}adjustVirtualStart(e,o,i){let n=e;for(const s of this.plugins)if(typeof s.adjustVirtualStart=="function"){const r=s.adjustVirtualStart(e,o,i);r<n&&(n=r)}return n}renderRow(e,o,i){for(const n of this.plugins)if(n.renderRow?.(e,o,i))return!0;return!1}queryPlugins(e){const o=[];for(const i of this.plugins){const n=i.onPluginQuery?.(e);n!==void 0&&o.push(n)}return o}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}getHorizontalScrollOffsets(e,o){let i=0,n=0,s=!1;for(const r of this.plugins){const l=r.getHorizontalScrollOffsets?.(e,o);l&&(i+=l.left,n+=l.right,l.skipScroll&&(s=!0))}return{left:i,right:n,skipScroll:s}}getToolPanels(){const e=[];for(const o of this.plugins){const i=o.getToolPanel?.();i&&e.push({plugin:o,panel:i})}return e.sort((o,i)=>(o.panel.order??0)-(i.panel.order??0))}getHeaderContents(){const e=[];for(const o of this.plugins){const i=o.getHeaderContent?.();i&&e.push({plugin:o,content:i})}return e.sort((o,i)=>(o.content.order??0)-(i.content.order??0))}}class I extends HTMLElement{static tagName="tbw-grid";static version=typeof __GRID_VERSION__<"u"?__GRID_VERSION__:"dev";static get observedAttributes(){return["rows","columns","grid-config","fit-mode","edit-on"]}#o;#x=!1;#z;#M;#r=[];#l;#p;#w;#g;#t={};#h=!1;#f=0;#m=null;#v=!1;#T;#_=!1;#E=null;#C=null;#y=null;#R=null;#a;#b;#e;#L;#d;#i=$e();#n;#S;_rows=[];#P=[];get _columns(){return this.#t.columns??[]}set _columns(e){this.#t.columns=e}get _visibleColumns(){return this._columns.filter(e=>!e.hidden)}_headerRowEl;_bodyEl;_rowPool=[];_resizeController;_virtualization={enabled:!0,rowHeight:28,bypassThreshold:24,start:0,end:0,container:null,viewportEl:null,totalHeightEl:null};_focusRow=0;_focusCol=0;_sortState=null;_activeEditRows=-1;_rowEditSnapshots=new Map;_changedRowIndices=new Set;_gridTemplate="";__rowRenderEpoch=0;__didInitialAutoSize=!1;__lightDomColumnsCache;__originalColumnNodes;__originalOrder=[];get rows(){return this._rows}set rows(e){const o=this.#r;this.#r=e,o!==e&&this.#j()}get sourceRows(){return this.#r}get columns(){return[...this._columns]}set columns(e){const o=this.#l;this.#l=e,o!==e&&this.#K()}get gridConfig(){return this.#t}set gridConfig(e){const o=this.#p;this.#p=e,o!==e&&this.#Y()}get fitMode(){return this.#t.fitMode??"stretch"}set fitMode(e){const o=this.#w;this.#w=e,o!==e&&this.#U()}get editOn(){return this.#t.editOn}set editOn(e){const o=this.#g;this.#g=e,o!==e&&this.#X()}get effectiveConfig(){return this.#t}get disconnectSignal(){return this.#a||(this.#a=new AbortController),this.#a.signal}constructor(){super(),this.#o=this.attachShadow({mode:"open"}),this.#W(),this.#z=new Promise(e=>this.#M=e),this.#n=Ze(this.#i,{getShadow:()=>this.#o,getShellConfig:()=>this.#t?.shell,getAccordionIcons:()=>({expand:this.#t?.icons?.expand??P.expand,collapse:this.#t?.icons?.collapse??P.collapse}),emit:(e,o)=>this.#s(e,o),refreshShellHeader:()=>this.refreshShellHeader()})}#W(){const e=new CSSStyleSheet;e.replaceSync(G),this.#o.adoptedStyleSheets=[e]}getPlugin(e){return this.#e?.getPlugin(e)}getPluginByName(e){return this.#e?.getPluginByName(e)}requestRender(){this.#A(),this.#H(),W(this),D(this),this.refreshVirtualWindow(!0)}updateTemplate(){D(this)}requestAfterRender(){this.#e?.afterRender()}#D(){this.#e=new pe(this);const e=this.#t?.plugins,o=Array.isArray(e)?e:[];this.#e.attachAll(o)}#N(){const e=this.#e?.getAllStyles()??"";if(e){const o=document.createElement("style");o.setAttribute("data-plugin","all"),o.textContent=e,this.#o.appendChild(o)}}#I(){this.#e&&this.#e.detachAll(),this.#D(),this.#N(),this.#v=this.#e?.getAll().some(e=>e.onScroll)??!1}#G(){this.#e?.detachAll()}#V(){if(!this.#e)return;const e=this.#e.getToolPanels();for(const{panel:i}of e)this.#i.toolPanels.has(i.id)||this.#i.toolPanels.set(i.id,i);const o=this.#e.getHeaderContents();for(const{content:i}of o)this.#i.headerContents.has(i.id)||this.#i.headerContents.set(i.id,i)}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.hasAttribute("version")||this.setAttribute("version",I.version),this._rows=Array.isArray(this.#r)?[...this.#r]:[],this.#a?.abort(),this.#a=new AbortController,this.#u(),this.#D(),this.#V(),this.#x||(this.#$(),this.#N(),this.#x=!0),this.#q()}disconnectedCallback(){this.#G(),Ye(this.#i),this.#n.setInitialized(!1),this.#S?.(),this.#S=void 0,this.#a&&(this.#a.abort(),this.#a=void 0),this._resizeController&&this._resizeController.dispose(),this.#b&&(this.#b.disconnect(),this.#b=void 0),this.#h=!1}attributeChangedCallback(e,o,i){if(o===i||!i||i==="null"||i==="undefined")return;const s={rows:"rows",columns:"columns","grid-config":"gridConfig","fit-mode":"fitMode","edit-on":"editOn"}[e];if(s)if(e==="rows"||e==="columns"||e==="grid-config")try{this[s]=JSON.parse(i)}catch{console.warn(`[tbw-grid] Invalid JSON for '${e}' attribute:`,i)}else this[s]=i}#q(){const o=this.#o.querySelector(".tbw-grid-content")??this.#o.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.#n.isInitialized){ue(this.#o,this.#i),Xe(this.#o,this.#t?.shell,this.#i);const l=this.#t?.shell?.toolPanel?.defaultOpen;l&&this.#i.toolPanels.has(l)&&(this.openToolPanel(),this.#i.expandedSections.add(l))}this.setAttribute("data-upgraded",""),this.#h=!0;const i=this.disconnectSignal;this._resizeController=Be(this),this.#c(),this.addEventListener("keydown",l=>Me(this,l),{signal:i}),document.addEventListener("keydown",l=>{l.key==="Escape"&&this._activeEditRows!==-1&&N(this,this._activeEditRows,!0)},{capture:!0,signal:i}),document.addEventListener("mousedown",l=>{if(this._activeEditRows===-1)return;const a=this.findRenderedRowElement(this._activeEditRows);!a||(l.composedPath&&l.composedPath()||[]).includes(a)||N(this,this._activeEditRows,!1)},{signal:i});const n=o?.querySelector(".faux-vscroll"),s=o?.querySelector(".rows");if(this._virtualization.container=n??this,this.#v=this.#e?.getAll().some(l=>l.onScroll)??!1,n&&s){n.addEventListener("scroll",()=>{if(!this._virtualization.enabled&&!this.#v)return;const d=n.scrollTop,f=this._virtualization.rowHeight,h=Math.floor(d/f),p=h-h%2,c=-(d-p*f);s.style.transform=`translateY(${c}px)`,this.#m=d,this.#f||(this.#f=requestAnimationFrame(()=>{this.#f=0,this.#m!==null&&(this.#Z(this.#m),this.#m=null)}))},{passive:!0,signal:i});const l=this.#o.querySelector(".tbw-grid-content"),a=this.#o.querySelector(".tbw-scroll-area");l&&(l.addEventListener("wheel",d=>{d.preventDefault(),d.shiftKey||Math.abs(d.deltaX)>Math.abs(d.deltaY)?a&&(a.scrollLeft+=d.shiftKey?d.deltaY:d.deltaX):n.scrollTop+=d.deltaY},{passive:!1,signal:i}),l.addEventListener("touchstart",d=>{d.touches.length===1&&(this.#E=d.touches[0].clientY,this.#C=d.touches[0].clientX,this.#y=n.scrollTop,this.#R=a?.scrollLeft??0)},{passive:!0,signal:i}),l.addEventListener("touchmove",d=>{if(d.touches.length===1&&this.#E!==null&&this.#C!==null&&this.#y!==null&&this.#R!==null){const f=this.#E-d.touches[0].clientY,h=this.#C-d.touches[0].clientX;n.scrollTop=this.#y+f,a&&(a.scrollLeft=this.#R+h),d.preventDefault()}},{passive:!1,signal:i}),l.addEventListener("touchend",()=>{this.#E=null,this.#C=null,this.#y=null,this.#R=null},{passive:!0,signal:i}))}this.#o.addEventListener("mousedown",l=>this.#Q(l),{signal:i}),document.addEventListener("mousemove",l=>this.#J(l),{signal:i}),document.addEventListener("mouseup",l=>this.#ee(l),{signal:i}),this._virtualization.enabled&&requestAnimationFrame(()=>this.refreshVirtualWindow(!0));const r=this.#t.rowHeight;r&&r>0?this._virtualization.rowHeight=r:requestAnimationFrame(()=>{const l=this._bodyEl?.querySelector(".data-grid-row");if(l){const a=l.getBoundingClientRect().height;a>0&&(this._virtualization.rowHeight=a,this.refreshVirtualWindow(!0))}}),this._virtualization.viewportEl&&(this.#b=new ResizeObserver(()=>{this.#f||(this.#f=requestAnimationFrame(()=>{this.#f=0,this.refreshVirtualWindow(!0),M(this)}))}),this.#b.observe(this._virtualization.viewportEl)),queueMicrotask(()=>this.#F()),requestAnimationFrame(()=>requestAnimationFrame(()=>this.#M?.()))}#s(e,o){this.dispatchEvent(new CustomEvent(e,{detail:o,bubbles:!0,composed:!0}))}_emitCellCommit(e){this.#s("cell-commit",e)}_emitRowCommit(e){this.#s("row-commit",e)}_emitSortChange(e){this.#s("sort-change",e)}_emitColumnResize(e){this.#s("column-resize",e)}_emitActivateCell(e){this.#s("activate-cell",e)}#F(){this._bodyEl?.querySelectorAll(".data-grid-row")?.forEach((o,i)=>{const n=i===this._focusRow;o.setAttribute("aria-selected",String(n)),o.querySelectorAll(".cell").forEach((s,r)=>{s.setAttribute("aria-selected",String(n&&r===this._focusCol))})})}#U(){if(!this.#h)return;this.#u(),this.#t.fitMode==="fixed"?(this.__didInitialAutoSize=!1,re(this)):(this._columns.forEach(o=>{!o.__userResized&&o.__autoSized&&delete o.width}),D(this))}#X(){this.#h&&(this.#u(),this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.refreshVirtualWindow(!0))}#j(){this._rows=Array.isArray(this.#r)?[...this.#r]:[],this.#A(),!this.#l||Array.isArray(this.#l)&&this.#l.length===0?this.#c():this.refreshVirtualWindow(!0)}#K(){K(this),this.#h&&(this.#u(),this.#c())}#Y(){this.#h&&(this.#u(),this.#I(),this.#A(),this.#H(),W(this),D(this),this.refreshVirtualWindow(!0))}#H(){if(this.#e){const e=this.#P.length>0?this.#P:this._columns,o=e.filter(s=>!s.hidden),i=e.filter(s=>s.hidden),n=this.#e.processColumns([...o]);if(n!==o){const s=new Map(n.map((l,a)=>[l.field,{col:l,order:a}]));if(!o.some(l=>s.has(l.field))&&n.length>0)this._columns=[...n,...i];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]}}#A(){K(this);const e=Array.isArray(this.#r)?[...this.#r]:[],o=this.#e?.processRows(e)??e;this._rows=o}#u(){const e=this.#p?{...this.#p}:{};let o=Array.isArray(e.columns)?[...e.columns]:[];const i=(this.__lightDomColumnsCache||[]).map(n=>({...n}));if(i.length){const n={};o.forEach(s=>n[s.field]=s),i.forEach(s=>{const r=n[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),n[s.field]=s)})}if(this.#l&&this.#l.length&&(o=[...this.#l]),(!o||o.length===0)&&this._rows.length&&(o=oe(this._rows).columns),o.length){o.forEach(r=>{r.sortable===void 0&&(r.sortable=!0),r.resizable===void 0&&(r.resizable=!0);const l=r;l.__originalWidth===void 0&&typeof r.width=="number"&&(l.__originalWidth=r.width)});const n=this.#t.columns;n?.some(r=>r.__compiledView||r.__compiledEditor)?e.columns=n:e.columns=o}else{const n=this.#t.columns;n?.some(s=>s.__compiledView||s.__compiledEditor)&&(e.columns=n)}this.#w&&(e.fitMode=this.#w),e.fitMode||(e.fitMode="stretch"),this.#g&&(e.editOn=this.#g),e.rowHeight&&e.rowHeight>0&&(this._virtualization.rowHeight=e.rowHeight),e.columnState&&!this.#d&&(this.#d=e.columnState),this.#t=e,e.fitMode==="fixed"&&this._columns.forEach(n=>{n.width==null&&(n.width=80)})}#k(e,o,i=this.__rowRenderEpoch){this.#T||(this.#T=(n,s,r)=>this.#e?.renderRow(n,s,r)??!1),Ie(this,e,o,i,this.#T)}#c(){if(!this.isConnected||!this._headerRowEl||!this._bodyEl)return;const e=this.#p?.columns||this.#l||[];if(e.length){const i=new Map(this._columns.filter(s=>s.hidden).map(s=>[s.field,!0])),n=e.map(s=>({...s,hidden:i.get(s.field)??s.hidden}));this._columns=n}if(Oe(this),this.#u(),this.#I(),this.#P=[...this._columns],this.#A(),this.#H(),this.#d){const i=this.#d;this.#d=void 0,this.#B(i)}W(this),D(this),this.refreshVirtualWindow(!0),this.#t.fitMode==="fixed"&&!this.__didInitialAutoSize&&requestAnimationFrame(()=>re(this)),this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),queueMicrotask(()=>this.#e?.afterRender())}#B(e){const o=this.#t.columns??[],i=this.#e?.getAll()??[];me(this,e,o,i);for(const n of e.columns){const s=o.find(r=>r.field===n.field);s&&(s.hidden=!n.visible)}}#Z(e){if(this.refreshVirtualWindow(!1),this.#e?.onScrollRender(),this.#v){const o=this._virtualization.container,i={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.#e?.onScroll(i)}}findHeaderRow(){return this.#o.querySelector(".header-row")}findRenderedRowElement(e){return Array.from(this._bodyEl.querySelectorAll(".data-grid-row")).find(o=>{const i=o.querySelector(".cell[data-row]");return i&&Number(i.getAttribute("data-row"))===e})||null}_dispatchCellClick(e,o,i,n){const s=this._rows[o],r=this._columns[i];if(!s||!r)return!1;const l={row:s,rowIndex:o,colIndex:i,field:r.field,value:s[r.field],cellEl:n,originalEvent:e};return this.#e?.onCellClick(l)??!1}_dispatchHeaderClick(e,o,i){const n=this._columns[o];if(!n)return!1;const s={colIndex:o,field:n.field,column:n,headerEl:i,originalEvent:e};return this.#e?.onHeaderClick(s)??!1}_dispatchKeyDown(e){return this.#e?.onKeyDown(e)??!1}_getHorizontalScrollOffsets(e,o){return this.#e?.getHorizontalScrollOffsets(e,o)??{left:0,right:0}}queryPlugins(e){return this.#e?.queryPlugins(e)??[]}#O(e,o){let i=null;const n=e.composedPath?.();if(n&&n.length>0?i=n[0]:i=e.target,i&&!this.#o.contains(i)){const u=this.#o.elementFromPoint(e.clientX,e.clientY);u&&(i=u)}const s=i?.closest?.("[data-col]"),r=i?.closest?.(".data-grid-row"),l=i?.closest?.(".header-row");let a,d,f,h,p,c;return s&&(a=parseInt(s.getAttribute("data-row")??"-1",10),d=parseInt(s.getAttribute("data-col")??"-1",10),a>=0&&d>=0&&(f=this._rows[a],c=this._columns[d],h=c?.field,p=f&&h?f[h]:void 0)),{type:o,row:f,rowIndex:a!==void 0&&a>=0?a:void 0,colIndex:d!==void 0&&d>=0?d:void 0,field:h,value:p,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}}#Q(e){const o=this.#O(e,"mousedown");(this.#e?.onCellMouseDown(o)??!1)&&(this.#_=!0)}#J(e){if(!this.#_)return;const o=this.#O(e,"mousemove");this.#e?.onCellMouseMove(o)}#ee(e){if(!this.#_)return;const o=this.#O(e,"mouseup");this.#e?.onCellMouseUp(o),this.#_=!1}get changedRows(){return Array.from(this._changedRowIndices).map(e=>this._rows[e])}get changedRowIndices(){return Array.from(this._changedRowIndices)}async resetChangedRows(e){this._changedRowIndices.clear(),e||this.#s("changed-rows-reset",{rows:this.changedRows,indices:this.changedRowIndices}),this._rowPool.forEach(o=>o.classList.remove("changed"))}async beginBulkEdit(e){if(!this._columns.some(s=>s.editable))return;const i=this._rows[e];$(this,e,i);const n=this.findRenderedRowElement?.(e);n&&(Array.from(n.children).forEach((s,r)=>{const l=this._visibleColumns[r];if(l?.editable){const a=s;a.classList.contains("editing")||z(this,i,e,l,a)}}),queueMicrotask(()=>{const s=n.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&&N(this,this._activeEditRows,!1)}async ready(){return this.#z}async forceLayout(){this.#c(),await new Promise(e=>requestAnimationFrame(()=>requestAnimationFrame(e)))}async getConfig(){return Object.freeze({...this.#t||{}})}setColumnVisible(e,o){const i=this.#t.columns,n=i?.find(l=>l.field===e);if(!n||!o&&n.lockVisible||!o&&(i??[]).filter(a=>!a.hidden&&a.field!==e).length===0)return!1;const s=!!n.hidden,r=!o;return s!==r?(n.hidden=r,this.#s("column-visibility",{field:e,visible:o,visibleColumns:(i??[]).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 n=!!this.#t.columns?.find(s=>s.field===e)?.hidden;return this.setColumnVisible(e,n)}isColumnVisible(e){const i=this.#t.columns?.find(n=>n.field===e);return i?!i.hidden:!1}showAllColumns(){const e=this.#t.columns;e?.some(i=>i.hidden)&&(e?.forEach(i=>{i.hidden=!1}),this.#s("column-visibility",{visibleColumns:(e??[]).map(i=>i.field)}),this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.#c(),this.requestStateChange())}getAllColumns(){return(this.#t.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(n=>[n.field,n])),i=[];for(const n of e){const s=o.get(n);s&&(i.push(s),o.delete(n))}for(const n of o.values())i.push(n);this._columns=i,W(this),D(this),this.refreshVirtualWindow(!0)}getColumnOrder(){return this._columns.map(e=>e.field)}getColumnState(){const e=this.#e?.getAll()??[];return te(this,e)}set columnState(e){e&&(this.#d=e,this.#x&&this.#te(e))}get columnState(){return this.getColumnState()}#te(e){(this.#t.columns??[]).forEach(i=>{i.hidden=!1}),this.#B(e),this.#c()}requestStateChange(){this.#L||(this.#L=ve(this,()=>this.#e?.getAll()??[],e=>this.#s("column-state-change",e))),this.#L()}resetColumnState(){this.#d=void 0,(this.#t.columns??[]).forEach(i=>{i.hidden=!1}),this._sortState=null,this.__originalOrder=[],this.#u(),this.#c();const o=this.#e?.getAll()??[];for(const i of o)if(i.applyColumnState)for(const n of this._columns)i.applyColumnState(n.field,{field:n.field,order:0,visible:!0});this.requestStateChange()}get isToolPanelOpen(){return this.#n.isPanelOpen}get activeToolPanel(){return this.#n.activePanel}get expandedToolPanelSections(){return this.#n.expandedSections}openToolPanel(){this.#n.openToolPanel()}closeToolPanel(){this.#n.closeToolPanel()}toggleToolPanel(){this.#n.toggleToolPanel()}toggleToolPanelSection(e){this.#n.toggleToolPanelSection(e)}getToolPanels(){return this.#n.getToolPanels()}registerToolPanel(e){this.#n.registerToolPanel(e)}unregisterToolPanel(e){this.#n.unregisterToolPanel(e)}getHeaderContents(){return this.#n.getHeaderContents()}registerHeaderContent(e){this.#n.registerHeaderContent(e)}unregisterHeaderContent(e){this.#n.unregisterHeaderContent(e)}getToolbarButtons(){return this.#n.getToolbarButtons()}registerToolbarButton(e){this.#n.registerToolbarButton(e)}unregisterToolbarButton(e){this.#n.unregisterToolbarButton(e)}setToolbarButtonDisabled(e,o){this.#n.setToolbarButtonDisabled(e,o)}refreshShellHeader(){de(this,this.#i),this.#$(),this.#q()}refreshVirtualWindow(e=!1){if(!this._bodyEl)return;const o=this._rows.length;if(!this._virtualization.enabled){this.#k(0,o),this.#e?.afterRender();return}if(this._rows.length<=this._virtualization.bypassThreshold){if(this._virtualization.start=0,this._virtualization.end=o,this._bodyEl.style.transform="translateY(0px)",this.#k(0,o,this.__rowRenderEpoch),this._virtualization.totalHeightEl){const y=this.#o.querySelector(".tbw-scroll-area"),_=y?y.offsetHeight-y.clientHeight:0;this._virtualization.totalHeightEl.style.height=`${o*this._virtualization.rowHeight+_}px`}const m=this.#o.querySelector(".rows-body");m?.setAttribute("aria-rowcount",String(o)),m?.setAttribute("aria-colcount",String(this._visibleColumns.length)),this.#e?.afterRender();return}const i=this._virtualization.container??this,s=(this._virtualization.viewportEl??i).clientHeight,r=this._virtualization.rowHeight,l=i.scrollTop;let a=Math.floor(l/r),d=0;const f=10;for(;d<f;){const m=this.#e?.getExtraHeightBefore?.(a)??0,y=Math.floor((l-m)/r);if(y>=a||y<0)break;a=y,d++}a=a-a%2,a<0&&(a=0);const h=this.#e?.adjustVirtualStart(a,l,r);h!==void 0&&h<a&&(a=h,a=a-a%2,a<0&&(a=0));const p=Math.ceil(s/r)+3;let c=a+p;c>o&&(c=o),this._virtualization.start=a,this._virtualization.end=c;const b=this.#o.querySelector(".tbw-footer")?.offsetHeight??0,w=this.#e?.getExtraHeight()??0,v=this.#o.querySelector(".tbw-scroll-area"),R=v?v.offsetHeight-v.clientHeight:0;this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${o*r+r+b+w+R}px`);const x=this.#e?.getExtraHeightBefore?.(a)??0,S=-(l-a*r-x);this._bodyEl.style.transform=`translateY(${S}px)`,this.#k(a,c,e?++this.__rowRenderEpoch:this.__rowRenderEpoch);const g=this.#o.querySelector(".rows-body");g?.setAttribute("aria-rowcount",String(o)),g?.setAttribute("aria-colcount",String(this._visibleColumns.length)),e&&this.#e?.afterRender()}#$(){de(this,this.#i);const e=this.#t?.shell,o=We(e,this.#i),i=`
43
+ `}function pe(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 je(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 f=d.getAttribute("data-btn");f&&n.onToolbarButtonClick(f)}});const s=t.querySelector(".tbw-accordion");s&&s.addEventListener("click",r=>{const a=r.target.closest(".tbw-accordion-header");if(a){const f=a.closest("[data-section]")?.getAttribute("data-section");f&&n.onSectionToggle(f)}})}function Ke(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,f=0,h=!1;const p=b=>{if(!h)return;b.preventDefault();const w=r==="left"?b.clientX-a:a-b.clientX,v=Math.min(f,Math.max(l,d+w));n.style.width=`${v}px`},c=()=>{if(!h)return;h=!1,i.classList.remove("resizing"),n.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const b=n.getBoundingClientRect().width;o(b),document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",c)},u=b=>{b.preventDefault(),h=!0,a=b.clientX,d=n.getBoundingClientRect().width,f=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",p),document.addEventListener("mouseup",c)};return i.addEventListener("mousedown",u),()=>{i.removeEventListener("mousedown",u),document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",c)}}function Ze(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 be(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 Qe(t,e,o){if(!e.isPanelOpen)return;const n=G(o?.expand??P.expand),i=G(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 f=a.querySelector(".tbw-accordion-header");f&&f.setAttribute("aria-expanded",String(l));const h=a.querySelector(".tbw-accordion-chevron");if(h&&(h.innerHTML=l?i:n),l){if(d.children.length===0){const p=r.render(d);p&&e.panelCleanups.set(s,p)}}else{const p=e.panelCleanups.get(s);p&&(p(),e.panelCleanups.delete(s)),d.innerHTML=""}}}function we(t,e){const o=t.querySelector("[data-panel-toggle]");o&&(o.classList.toggle("active",e.isPanelOpen),o.setAttribute("aria-pressed",String(e.isPanelOpen)))}function ge(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 et(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}function tt(t,e){let o=!1;const n={get isInitialized(){return o},setInitialized(i){o=i},get isPanelOpen(){return t.isPanelOpen},get activePanel(){return t.isPanelOpen&&t.expandedSections.size>0?[...t.expandedSections][0]:null},get expandedSections(){return[...t.expandedSections]},openToolPanel(){if(t.isPanelOpen)return;if(t.toolPanels.size===0){console.warn("[tbw-grid] No tool panels registered");return}if(t.isPanelOpen=!0,t.expandedSections.size===0&&t.toolPanels.size>0){const r=[...t.toolPanels.values()].sort((l,a)=>(l.order??100)-(a.order??100))[0];r&&t.expandedSections.add(r.id)}const i=e.getShadow();we(i,t),ge(i,t),Qe(i,t,e.getAccordionIcons()),e.emit("tool-panel-open",{sections:n.expandedSections})},closeToolPanel(){if(!t.isPanelOpen)return;for(const s of t.panelCleanups.values())s();t.panelCleanups.clear(),t.activePanelCleanup&&(t.activePanelCleanup(),t.activePanelCleanup=null);for(const s of t.toolPanels.values())s.onClose?.();t.isPanelOpen=!1;const i=e.getShadow();we(i,t),ge(i,t),e.emit("tool-panel-close",{})},toggleToolPanel(){t.isPanelOpen?n.closeToolPanel():n.openToolPanel()},toggleToolPanelSection(i){const s=t.toolPanels.get(i);if(!s){console.warn(`[tbw-grid] Tool panel section "${i}" not found`);return}if(t.toolPanels.size===1)return;const r=e.getShadow(),l=t.expandedSections.has(i);if(l){const a=t.panelCleanups.get(i);a&&(a(),t.panelCleanups.delete(i)),s.onClose?.(),t.expandedSections.delete(i),J(r,i,!1)}else{for(const[a,d]of t.toolPanels)if(a!==i&&t.expandedSections.has(a)){const f=t.panelCleanups.get(a);f&&(f(),t.panelCleanups.delete(a)),d.onClose?.(),t.expandedSections.delete(a),J(r,a,!1);const h=r.querySelector(`[data-section="${a}"] .tbw-accordion-content`);h&&(h.innerHTML="")}t.expandedSections.add(i),J(r,i,!0),ot(r,t,i)}e.emit("tool-panel-section-toggle",{id:i,expanded:!l})},getToolPanels(){return[...t.toolPanels.values()]},registerToolPanel(i){if(t.toolPanels.has(i.id)){console.warn(`[tbw-grid] Tool panel "${i.id}" already registered`);return}t.toolPanels.set(i.id,i),o&&e.refreshShellHeader()},unregisterToolPanel(i){if(t.expandedSections.has(i)){const s=t.panelCleanups.get(i);s&&(s(),t.panelCleanups.delete(i)),t.expandedSections.delete(i)}t.toolPanels.delete(i),o&&e.refreshShellHeader()},getHeaderContents(){return[...t.headerContents.values()]},registerHeaderContent(i){if(t.headerContents.has(i.id)){console.warn(`[tbw-grid] Header content "${i.id}" already registered`);return}t.headerContents.set(i.id,i),o&&be(e.getShadow(),t)},unregisterHeaderContent(i){const s=t.headerContentCleanups.get(i);s&&(s(),t.headerContentCleanups.delete(i)),t.headerContents.get(i)?.onDestroy?.(),t.headerContents.delete(i),e.getShadow().querySelector(`[data-header-content="${i}"]`)?.remove()},getToolbarButtons(){return Je(e.getShellConfig(),t)},registerToolbarButton(i){if(t.toolbarButtons.has(i.id)){console.warn(`[tbw-grid] Toolbar button "${i.id}" already registered`);return}t.toolbarButtons.set(i.id,i),o&&e.refreshShellHeader()},unregisterToolbarButton(i){const s=t.toolbarButtonCleanups.get(i);s&&(s(),t.toolbarButtonCleanups.delete(i)),t.toolbarButtons.delete(i),o&&e.refreshShellHeader()},setToolbarButtonDisabled(i,s){const r=t.toolbarButtons.get(i);r&&(r.disabled=s);const l=e.getShadow().querySelector(`[data-btn="${i}"]`);l&&(l.disabled=s)}};return n}function J(t,e,o){const n=t.querySelector(`[data-section="${e}"]`);n&&n.classList.toggle("expanded",o)}function ot(t,e,o){const n=e.toolPanels.get(o);if(!n?.render)return;const i=t.querySelector(`[data-section="${o}"] .tbw-accordion-content`);if(!i)return;const s=n.render(i);s&&e.panelCleanups.set(o,s)}class me{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}queryPlugins(e){const o=[];for(const n of this.plugins){const i=n.onPluginQuery?.(e);i!==void 0&&o.push(i)}return o}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}getHorizontalScrollOffsets(e,o){let n=0,i=0,s=!1;for(const r of this.plugins){const l=r.getHorizontalScrollOffsets?.(e,o);l&&(n+=l.left,i+=l.right,l.skipScroll&&(s=!0))}return{left:n,right:i,skipScroll:s}}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 I extends HTMLElement{static tagName="tbw-grid";static version=typeof __GRID_VERSION__<"u"?__GRID_VERSION__:"dev";static get observedAttributes(){return["rows","columns","grid-config","fit-mode","edit-on"]}#o;#M=!1;#B;#$;#r=[];#l;#g;#C;#y;#t={};#p=!1;#b=0;#S=null;#R=!1;#z;#A=!1;#x=null;#T=null;#L=null;#P=null;#m=null;#v=null;#_=null;#d=0;#u=0;#w=0;#a;#E;#e;#D;#h;#i=Fe();#n;#H;_rows=[];#N=[];get _columns(){return this.#t.columns??[]}set _columns(e){this.#t.columns=e}get _visibleColumns(){return this._columns.filter(e=>!e.hidden)}_headerRowEl;_bodyEl;_rowPool=[];_resizeController;_virtualization={enabled:!0,rowHeight:28,bypassThreshold:24,start:0,end:0,container:null,viewportEl:null,totalHeightEl:null};_focusRow=0;_focusCol=0;_sortState=null;_activeEditRows=-1;_rowEditSnapshots=new Map;_changedRowIndices=new Set;_gridTemplate="";__rowRenderEpoch=0;__didInitialAutoSize=!1;__lightDomColumnsCache;__originalColumnNodes;__originalOrder=[];get rows(){return this._rows}set rows(e){const o=this.#r;this.#r=e,o!==e&&this.#ee()}get sourceRows(){return this.#r}get columns(){return[...this._columns]}set columns(e){const o=this.#l;this.#l=e,o!==e&&this.#te()}get gridConfig(){return this.#t}set gridConfig(e){const o=this.#g;this.#g=e,o!==e&&this.#oe()}get fitMode(){return this.#t.fitMode??"stretch"}set fitMode(e){const o=this.#C;this.#C=e,o!==e&&this.#Q()}get editOn(){return this.#t.editOn}set editOn(e){const o=this.#y;this.#y=e,o!==e&&this.#J()}get effectiveConfig(){return this.#t}get disconnectSignal(){return this.#a||(this.#a=new AbortController),this.#a.signal}constructor(){super(),this.#o=this.attachShadow({mode:"open"}),this.#Y(),this.#B=new Promise(e=>this.#$=e),this.#n=tt(this.#i,{getShadow:()=>this.#o,getShellConfig:()=>this.#t?.shell,getAccordionIcons:()=>({expand:this.#t?.icons?.expand??P.expand,collapse:this.#t?.icons?.collapse??P.collapse}),emit:(e,o)=>this.#s(e,o),refreshShellHeader:()=>this.refreshShellHeader()})}#Y(){const e=new CSSStyleSheet;e.replaceSync(V),this.#o.adoptedStyleSheets=[e]}getPlugin(e){return this.#e?.getPlugin(e)}getPluginByName(e){return this.#e?.getPluginByName(e)}requestRender(){this.#O(),this.#k(),W(this),D(this),this.refreshVirtualWindow(!0)}updateTemplate(){D(this)}requestAfterRender(){this.#e?.afterRender()}#W(){this.#e=new me(this);const e=this.#t?.plugins,o=Array.isArray(e)?e:[];this.#e.attachAll(o)}#V(){const e=this.#e?.getAllStyles()??"";if(e){const o=document.createElement("style");o.setAttribute("data-plugin","all"),o.textContent=e,this.#o.appendChild(o)}}#G(){this.#e&&this.#e.detachAll(),this.#W(),this.#V(),this.#R=this.#e?.getAll().some(e=>e.onScroll)??!1}#j(){this.#e?.detachAll()}#K(){if(!this.#e)return;const e=this.#e.getToolPanels();for(const{panel:n}of e)this.#i.toolPanels.has(n.id)||this.#i.toolPanels.set(n.id,n);const o=this.#e.getHeaderContents();for(const{content:n}of o)this.#i.headerContents.has(n.id)||this.#i.headerContents.set(n.id,n)}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.hasAttribute("version")||this.setAttribute("version",I.version),this._rows=Array.isArray(this.#r)?[...this.#r]:[],this.#a?.abort(),this.#a=new AbortController,this.#f(),this.#W(),this.#K(),this.#M||(this.#X(),this.#V(),this.#M=!0),this.#F()}disconnectedCallback(){this.#j(),et(this.#i),this.#n.setInitialized(!1),this.#H?.(),this.#H=void 0,this.#a&&(this.#a.abort(),this.#a=void 0),this._resizeController&&this._resizeController.dispose(),this.#E&&(this.#E.disconnect(),this.#E=void 0),this.#p=!1}attributeChangedCallback(e,o,n){if(o===n||!n||n==="null"||n==="undefined")return;const s={rows:"rows",columns:"columns","grid-config":"gridConfig","fit-mode":"fitMode","edit-on":"editOn"}[e];if(s)if(e==="rows"||e==="columns"||e==="grid-config")try{this[s]=JSON.parse(n)}catch{console.warn(`[tbw-grid] Invalid JSON for '${e}' attribute:`,n)}else this[s]=n}#F(){const o=this.#o.querySelector(".tbw-grid-content")??this.#o.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.#n.isInitialized){be(this.#o,this.#i),Ze(this.#o,this.#t?.shell,this.#i);const l=this.#t?.shell?.toolPanel?.defaultOpen;l&&this.#i.toolPanels.has(l)&&(this.openToolPanel(),this.#i.expandedSections.add(l))}this.setAttribute("data-upgraded",""),this.#p=!0;const n=this.disconnectSignal;this._resizeController=Ge(this),this.#c(),this.addEventListener("keydown",l=>qe(this,l),{signal:n}),document.addEventListener("keydown",l=>{l.key==="Escape"&&this._activeEditRows!==-1&&N(this,this._activeEditRows,!0)},{capture:!0,signal:n}),document.addEventListener("mousedown",l=>{if(this._activeEditRows===-1)return;const a=this.findRenderedRowElement(this._activeEditRows);!a||(l.composedPath&&l.composedPath()||[]).includes(a)||N(this,this._activeEditRows,!1)},{signal:n});const i=o?.querySelector(".faux-vscroll"),s=o?.querySelector(".rows");if(this._virtualization.container=i??this,this.#R=this.#e?.getAll().some(l=>l.onScroll)??!1,i&&s){i.addEventListener("scroll",()=>{if(!this._virtualization.enabled&&!this.#R)return;const d=i.scrollTop,f=this._virtualization.rowHeight,h=Math.floor(d/f),p=h-h%2,c=-(d-p*f);s.style.transform=`translateY(${c}px)`,this.#S=d,this.#b||(this.#b=requestAnimationFrame(()=>{this.#b=0,this.#S!==null&&(this.#ie(this.#S),this.#S=null)}))},{passive:!0,signal:n});const l=this.#o.querySelector(".tbw-grid-content"),a=this.#o.querySelector(".tbw-scroll-area");l&&(l.addEventListener("wheel",d=>{const f=d.shiftKey||Math.abs(d.deltaX)>Math.abs(d.deltaY);if(f&&a){const h=d.shiftKey?d.deltaY:d.deltaX,{scrollLeft:p,scrollWidth:c,clientWidth:u}=a;(h>0&&p<c-u||h<0&&p>0)&&(d.preventDefault(),a.scrollLeft+=h)}else if(!f){const{scrollTop:h,scrollHeight:p,clientHeight:c}=i;(d.deltaY>0&&h<p-c||d.deltaY<0&&h>0)&&(d.preventDefault(),i.scrollTop+=d.deltaY)}},{passive:!1,signal:n}),l.addEventListener("touchstart",d=>{d.touches.length===1&&(this.#w&&(cancelAnimationFrame(this.#w),this.#w=0),this.#x=d.touches[0].clientY,this.#T=d.touches[0].clientX,this.#m=d.touches[0].clientY,this.#v=d.touches[0].clientX,this.#_=performance.now(),this.#L=i.scrollTop,this.#P=a?.scrollLeft??0,this.#d=0,this.#u=0)},{passive:!0,signal:n}),l.addEventListener("touchmove",d=>{if(d.touches.length===1&&this.#x!==null&&this.#T!==null&&this.#L!==null&&this.#P!==null){const f=d.touches[0].clientY,h=d.touches[0].clientX,p=performance.now(),c=this.#x-f,u=this.#T-h;if(this.#_!==null&&this.#m!==null&&this.#v!==null){const g=p-this.#_;g>0&&(this.#d=(this.#m-f)/g,this.#u=(this.#v-h)/g)}this.#m=f,this.#v=h,this.#_=p;const{scrollTop:b,scrollHeight:w,clientHeight:v}=i,R=w-v,A=c>0&&b<R||c<0&&b>0;let C=!1;if(a){const{scrollLeft:g,scrollWidth:m,clientWidth:y}=a,_=m-y;C=u>0&&g<_||u<0&&g>0}A&&(i.scrollTop=this.#L+c),C&&a&&(a.scrollLeft=this.#P+u),(A||C)&&d.preventDefault()}},{passive:!1,signal:n}),l.addEventListener("touchend",()=>{(Math.abs(this.#d)>.1||Math.abs(this.#u)>.1)&&this.#se(i,a),this.#x=null,this.#T=null,this.#L=null,this.#P=null,this.#m=null,this.#v=null,this.#_=null},{passive:!0,signal:n}))}this.#o.addEventListener("mousedown",l=>this.#re(l),{signal:n}),document.addEventListener("mousemove",l=>this.#le(l),{signal:n}),document.addEventListener("mouseup",l=>this.#ae(l),{signal:n}),this._virtualization.enabled&&requestAnimationFrame(()=>this.refreshVirtualWindow(!0));const r=this.#t.rowHeight;r&&r>0?this._virtualization.rowHeight=r:requestAnimationFrame(()=>{const l=this._bodyEl?.querySelector(".data-grid-row");if(l){const a=l.getBoundingClientRect().height;a>0&&(this._virtualization.rowHeight=a,this.refreshVirtualWindow(!0))}}),this._virtualization.viewportEl&&(this.#E=new ResizeObserver(()=>{this.#b||(this.#b=requestAnimationFrame(()=>{this.#b=0,this.refreshVirtualWindow(!0),z(this)}))}),this.#E.observe(this._virtualization.viewportEl)),queueMicrotask(()=>this.#Z()),requestAnimationFrame(()=>requestAnimationFrame(()=>this.#$?.()))}#s(e,o){this.dispatchEvent(new CustomEvent(e,{detail:o,bubbles:!0,composed:!0}))}_emitCellCommit(e){this.#s("cell-commit",e)}_emitRowCommit(e){this.#s("row-commit",e)}_emitSortChange(e){this.#s("sort-change",e)}_emitColumnResize(e){this.#s("column-resize",e)}_emitActivateCell(e){this.#s("activate-cell",e)}#Z(){this._bodyEl?.querySelectorAll(".data-grid-row")?.forEach((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))})})}#Q(){if(!this.#p)return;this.#f(),this.#t.fitMode==="fixed"?(this.__didInitialAutoSize=!1,le(this)):(this._columns.forEach(o=>{!o.__userResized&&o.__autoSized&&delete o.width}),D(this))}#J(){this.#p&&(this.#f(),this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.refreshVirtualWindow(!0))}#ee(){this._rows=Array.isArray(this.#r)?[...this.#r]:[],this.#O(),this._columns.length>0||Array.isArray(this.#t?.columns)&&this.#t.columns.length>0||Array.isArray(this.#l)&&this.#l.length>0?(this.#k(),this.refreshVirtualWindow(!0)):this.#c()}#te(){j(this),this.#p&&(this.#f(),this.#c())}#oe(){this.#p&&(this.#f(),this.#G(),this.#O(),this.#k(),W(this),D(this),this.refreshVirtualWindow(!0))}#k(){if(this.#e){const e=this.#N.length>0?this.#N:this._columns,o=e.filter(s=>!s.hidden),n=e.filter(s=>s.hidden),i=this.#e.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]}}#O(){j(this);const e=Array.isArray(this.#r)?[...this.#r]:[],o=this.#e?.processRows(e)??e;this._rows=o}#f(){const e=this.#g?{...this.#g}:{};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.#l&&this.#l.length&&(o=[...this.#l]),(!o||o.length===0)&&this._rows.length&&(o=ne(this._rows).columns),o.length){o.forEach(r=>{r.sortable===void 0&&(r.sortable=!0),r.resizable===void 0&&(r.resizable=!0);const l=r;l.__originalWidth===void 0&&typeof r.width=="number"&&(l.__originalWidth=r.width)});const i=this.#t.columns;i?.some(r=>r.__compiledView||r.__compiledEditor)?e.columns=i:e.columns=o}else{const i=this.#t.columns;i?.some(s=>s.__compiledView||s.__compiledEditor)&&(e.columns=i)}this.#C&&(e.fitMode=this.#C),e.fitMode||(e.fitMode="stretch"),this.#y&&(e.editOn=this.#y),e.rowHeight&&e.rowHeight>0&&(this._virtualization.rowHeight=e.rowHeight),e.columnState&&!this.#h&&(this.#h=e.columnState),this.#t=e,e.fitMode==="fixed"&&this._columns.forEach(i=>{i.width==null&&(i.width=80)}),this.#ne()}#ne(){const e={...oe,...this.#t.animation},o=e.mode??"reduced-motion";let n=1;o===!1||o==="off"?n=0:(o===!0||o==="on")&&(n=1),this.style.setProperty("--tbw-animation-duration",`${e.duration}ms`),this.style.setProperty("--tbw-animation-easing",e.easing??"ease-out"),this.style.setProperty("--tbw-animation-enabled",String(n)),this.dataset.animationMode=typeof o=="boolean"?o?"on":"off":o}#I(e,o,n=this.__rowRenderEpoch){this.#z||(this.#z=(i,s,r)=>this.#e?.renderRow(i,s,r)??!1),We(this,e,o,n,this.#z)}#c(){if(!this.isConnected||!this._headerRowEl||!this._bodyEl)return;const e=this.#g?.columns||this.#l||[];if(e.length){const n=new Map(this._columns.filter(s=>s.hidden).map(s=>[s.field,!0])),i=e.map(s=>({...s,hidden:n.get(s.field)??s.hidden}));this._columns=i}if(Ne(this),this.#f(),this.#G(),this.#N=[...this._columns],this.#O(),this.#k(),this.#h){const n=this.#h;this.#h=void 0,this.#U(n)}W(this),D(this),this.refreshVirtualWindow(!0),this.#t.fitMode==="fixed"&&!this.__didInitialAutoSize&&requestAnimationFrame(()=>le(this)),this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),queueMicrotask(()=>this.#e?.afterRender())}#U(e){const o=this.#t.columns??[],n=this.#e?.getAll()??[];Ce(this,e,o,n);for(const i of e.columns){const s=o.find(r=>r.field===i.field);s&&(s.hidden=!i.visible)}}#ie(e){if(this.refreshVirtualWindow(!1),this.#e?.onScrollRender(),this.#R){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.#e?.onScroll(n)}}findHeaderRow(){return this.#o.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.#e?.onCellClick(l)??!1}_dispatchRowClick(e,o,n,i){if(!n)return!1;const s={rowIndex:o,row:n,rowEl:i,originalEvent:e};return this.#e?.onRowClick(s)??!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.#e?.onHeaderClick(s)??!1}_dispatchKeyDown(e){return this.#e?.onKeyDown(e)??!1}_getHorizontalScrollOffsets(e,o){return this.#e?.getHorizontalScrollOffsets(e,o)??{left:0,right:0}}queryPlugins(e){return this.#e?.queryPlugins(e)??[]}#q(e,o){let n=null;const i=e.composedPath?.();if(i&&i.length>0?n=i[0]:n=e.target,n&&!this.#o.contains(n)){const u=this.#o.elementFromPoint(e.clientX,e.clientY);u&&(n=u)}const s=n?.closest?.("[data-col]"),r=n?.closest?.(".data-grid-row"),l=n?.closest?.(".header-row");let a,d,f,h,p,c;return s&&(a=parseInt(s.getAttribute("data-row")??"-1",10),d=parseInt(s.getAttribute("data-col")??"-1",10),a>=0&&d>=0&&(f=this._rows[a],c=this._columns[d],h=c?.field,p=f&&h?f[h]:void 0)),{type:o,row:f,rowIndex:a!==void 0&&a>=0?a:void 0,colIndex:d!==void 0&&d>=0?d:void 0,field:h,value:p,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}}#se(e,o){const s=()=>{this.#d*=.95,this.#u*=.95;const r=this.#d*16,l=this.#u*16;Math.abs(this.#d)>.01&&(e.scrollTop+=r),Math.abs(this.#u)>.01&&o&&(o.scrollLeft+=l),Math.abs(this.#d)>.01||Math.abs(this.#u)>.01?this.#w=requestAnimationFrame(s):this.#w=0};this.#w=requestAnimationFrame(s)}#re(e){const o=this.#q(e,"mousedown");(this.#e?.onCellMouseDown(o)??!1)&&(this.#A=!0)}#le(e){if(!this.#A)return;const o=this.#q(e,"mousemove");this.#e?.onCellMouseMove(o)}#ae(e){if(!this.#A)return;const o=this.#q(e,"mouseup");this.#e?.onCellMouseUp(o),this.#A=!1}get changedRows(){return Array.from(this._changedRowIndices).map(e=>this._rows[e])}get changedRowIndices(){return Array.from(this._changedRowIndices)}async resetChangedRows(e){this._changedRowIndices.clear(),e||this.#s("changed-rows-reset",{rows:this.changedRows,indices:this.changedRowIndices}),this._rowPool.forEach(o=>o.classList.remove("changed"))}async beginBulkEdit(e){if(!this._columns.some(s=>s.editable))return;const n=this._rows[e];$(this,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&&N(this,this._activeEditRows,!1)}async ready(){return this.#B}async forceLayout(){this.#c(),await new Promise(e=>requestAnimationFrame(()=>requestAnimationFrame(e)))}async getConfig(){return Object.freeze({...this.#t||{}})}setColumnVisible(e,o){const n=this.#t.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.#s("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.#t.columns?.find(s=>s.field===e)?.hidden;return this.setColumnVisible(e,i)}isColumnVisible(e){const n=this.#t.columns?.find(i=>i.field===e);return n?!n.hidden:!1}showAllColumns(){const e=this.#t.columns;e?.some(n=>n.hidden)&&(e?.forEach(n=>{n.hidden=!1}),this.#s("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.#t.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,W(this),D(this),this.refreshVirtualWindow(!0)}getColumnOrder(){return this._columns.map(e=>e.field)}getColumnState(){const e=this.#e?.getAll()??[];return te(this,e)}set columnState(e){e&&(this.#h=e,this.#M&&this.#ce(e))}get columnState(){return this.getColumnState()}#ce(e){(this.#t.columns??[]).forEach(n=>{n.hidden=!1}),this.#U(e),this.#c()}requestStateChange(){this.#D||(this.#D=ye(this,()=>this.#e?.getAll()??[],e=>this.#s("column-state-change",e))),this.#D()}resetColumnState(){this.#h=void 0,(this.#t.columns??[]).forEach(n=>{n.hidden=!1}),this._sortState=null,this.__originalOrder=[],this.#f(),this.#c();const o=this.#e?.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.#n.isPanelOpen}get activeToolPanel(){return this.#n.activePanel}get expandedToolPanelSections(){return this.#n.expandedSections}openToolPanel(){this.#n.openToolPanel()}closeToolPanel(){this.#n.closeToolPanel()}toggleToolPanel(){this.#n.toggleToolPanel()}toggleToolPanelSection(e){this.#n.toggleToolPanelSection(e)}getToolPanels(){return this.#n.getToolPanels()}registerToolPanel(e){this.#n.registerToolPanel(e)}unregisterToolPanel(e){this.#n.unregisterToolPanel(e)}getHeaderContents(){return this.#n.getHeaderContents()}registerHeaderContent(e){this.#n.registerHeaderContent(e)}unregisterHeaderContent(e){this.#n.unregisterHeaderContent(e)}getToolbarButtons(){return this.#n.getToolbarButtons()}registerToolbarButton(e){this.#n.registerToolbarButton(e)}unregisterToolbarButton(e){this.#n.unregisterToolbarButton(e)}setToolbarButtonDisabled(e,o){this.#n.setToolbarButtonDisabled(e,o)}refreshShellHeader(){pe(this,this.#i),this.#X(),this.#F()}refreshVirtualWindow(e=!1){if(!this._bodyEl)return;const o=this._rows.length;if(!this._virtualization.enabled){this.#I(0,o),this.#e?.afterRender();return}if(this._rows.length<=this._virtualization.bypassThreshold){if(this._virtualization.start=0,this._virtualization.end=o,this._bodyEl.style.transform="translateY(0px)",this.#I(0,o,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),this._virtualization.totalHeightEl){const y=this.#o.querySelector(".tbw-scroll-area"),_=y?y.offsetHeight-y.clientHeight:0;this._virtualization.totalHeightEl.style.height=`${o*this._virtualization.rowHeight+_}px`}const m=this.#o.querySelector(".rows-body");m?.setAttribute("aria-rowcount",String(o)),m?.setAttribute("aria-colcount",String(this._visibleColumns.length)),this.#e?.afterRender();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 f=10;for(;d<f;){const m=this.#e?.getExtraHeightBefore?.(a)??0,y=Math.floor((l-m)/r);if(y>=a||y<0)break;a=y,d++}a=a-a%2,a<0&&(a=0);const h=this.#e?.adjustVirtualStart(a,l,r);h!==void 0&&h<a&&(a=h,a=a-a%2,a<0&&(a=0));const p=Math.ceil(s/r)+3;let c=a+p;c>o&&(c=o),this._virtualization.start=a,this._virtualization.end=c;const b=this.#o.querySelector(".tbw-footer")?.offsetHeight??0,w=this.#e?.getExtraHeight()??0,v=this.#o.querySelector(".tbw-scroll-area"),R=v?v.offsetHeight-v.clientHeight:0;this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${o*r+r+b+w+R}px`);const A=this.#e?.getExtraHeightBefore?.(a)??0,C=-(l-a*r-A);this._bodyEl.style.transform=`translateY(${C}px)`,this.#I(a,c,e?++this.__rowRenderEpoch:this.__rowRenderEpoch);const g=this.#o.querySelector(".rows-body");g?.setAttribute("aria-rowcount",String(o)),g?.setAttribute("aria-colcount",String(this._visibleColumns.length)),e&&this.#e?.afterRender()}#X(){pe(this,this.#i);const e=this.#t?.shell,o=Ue(e,this.#i),n=`
45
45
  <div class="tbw-scroll-area">
46
46
  <div class="rows-body-wrapper">
47
47
  <div class="rows-body" role="grid">
@@ -59,16 +59,16 @@
59
59
  <div class="faux-vscroll">
60
60
  <div class="faux-vscroll-spacer"></div>
61
61
  </div>
62
- `;if(o){const n=this.#t?.icons?.toolPanel??P.toolPanel,s={expand:this.#t?.icons?.expand??P.expand,collapse:this.#t?.icons?.collapse??P.collapse},r=Ge(e,this.#i,n),l=Ve(e,this.#i,i,s);this.#o.innerHTML=`
62
+ `;if(o){const i=this.#t?.icons?.toolPanel??P.toolPanel,s={expand:this.#t?.icons?.expand??P.expand,collapse:this.#t?.icons?.collapse??P.collapse},r=Xe(e,this.#i,i),l=Ye(e,this.#i,n,s);this.#o.innerHTML=`
63
63
  <div class="tbw-grid-root has-shell">
64
64
  ${r}
65
65
  ${l}
66
66
  </div>
67
- `,this.#oe(),this.#n.setInitialized(!0)}else this.#o.innerHTML=`
67
+ `,this.#de(),this.#n.setInitialized(!0)}else this.#o.innerHTML=`
68
68
  <div class="tbw-grid-root">
69
69
  <div class="tbw-grid-content">
70
- ${i}
70
+ ${n}
71
71
  </div>
72
72
  </div>
73
- `}#oe(){Fe(this.#o,this.#t?.shell,this.#i,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e),onToolbarButtonClick:e=>this.#ne(e)}),this.#S?.(),this.#S=Ue(this.#o,this.#t?.shell,e=>{this.style.setProperty("--tbw-tool-panel-width",`${e}px`)})}#ne(e){const i=(this.#t?.shell?.header?.toolbarButtons??[]).find(s=>s.id===e);if(i?.action){i.action();return}const n=this.#i.toolbarButtons.get(e);n?.action&&n.action()}}customElements.get(I.tagName)||customElements.define(I.tagName,I);const Je={CAN_MOVE_COLUMN:"canMoveColumn",GET_CONTEXT_MENU_ITEMS:"getContextMenuItems"};class et{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"},F={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"},tt={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}[${F.ROW_INDEX}="${t}"]`,CELL_BY_FIELD:t=>`.${T.DATA_CELL}[${F.FIELD}="${t}"]`,CELL_AT:(t,e)=>`.${T.DATA_ROW}[${F.ROW_INDEX}="${t}"] .${T.DATA_CELL}[${F.COL_INDEX}="${e}"]`,SELECTED_ROWS:`.${T.DATA_ROW}.${T.SELECTED}`,EDITING_CELL:`.${T.DATA_CELL}.${T.EDITING}`},ot={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"},nt={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"},it={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"},ee={sum:(t,e)=>t.reduce((o,i)=>o+(Number(i[e])||0),0),avg:(t,e)=>{const o=t.reduce((i,n)=>i+(Number(n[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]},U=new Map,k={register(t,e){U.set(t,e)},unregister(t){U.delete(t)},get(t){if(t!==void 0)return typeof t=="function"?t:U.get(t)??ee[t]},run(t,e,o,i){const n=this.get(t);return n?n(e,o,i):void 0},has(t){return U.has(t)||t in ee},list(){return[...Object.keys(ee),...U.keys()]}},be={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 we(t){return be[t]??be.sum}function st(t,e){return we(t)(e)}const rt=k.register.bind(k),lt=k.unregister.bind(k),at=k.get.bind(k),ct=k.run.bind(k),dt=k.list.bind(k);E.BaseGridPlugin=et,E.DEFAULT_GRID_ICONS=P,E.DGEvents=nt,E.DataGridElement=I,E.FitModeEnum=q,E.GridCSSVars=ot,E.GridClasses=T,E.GridDataAttrs=F,E.GridElement=I,E.GridSelectors=tt,E.PLUGIN_QUERIES=Je,E.PluginEvents=it,E.PluginManager=pe,E.aggregatorRegistry=k,E.getAggregator=at,E.getValueAggregator=we,E.listAggregators=dt,E.registerAggregator=rt,E.runAggregator=ct,E.runValueAggregator=st,E.unregisterAggregator=lt,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})}));
73
+ `}#de(){je(this.#o,this.#t?.shell,this.#i,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e),onToolbarButtonClick:e=>this.#ue(e)}),this.#H?.(),this.#H=Ke(this.#o,this.#t?.shell,e=>{this.style.setProperty("--tbw-tool-panel-width",`${e}px`)})}#ue(e){const n=(this.#t?.shell?.header?.toolbarButtons??[]).find(s=>s.id===e);if(n?.action){n.action();return}const i=this.#i.toolbarButtons.get(e);i?.action&&i.action()}}customElements.get(I.tagName)||customElements.define(I.tagName,I);const nt={CAN_MOVE_COLUMN:"canMoveColumn",GET_CONTEXT_MENU_ITEMS:"getContextMenuItems"};class it{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"},F={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"},st={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}[${F.ROW_INDEX}="${t}"]`,CELL_BY_FIELD:t=>`.${T.DATA_CELL}[${F.FIELD}="${t}"]`,CELL_AT:(t,e)=>`.${T.DATA_ROW}[${F.ROW_INDEX}="${t}"] .${T.DATA_CELL}[${F.COL_INDEX}="${e}"]`,SELECTED_ROWS:`.${T.DATA_ROW}.${T.SELECTED}`,EDITING_CELL:`.${T.DATA_CELL}.${T.EDITING}`},rt={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"},lt={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"},at={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"},ee={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]},U=new Map,k={register(t,e){U.set(t,e)},unregister(t){U.delete(t)},get(t){if(t!==void 0)return typeof t=="function"?t:U.get(t)??ee[t]},run(t,e,o,n){const i=this.get(t);return i?i(e,o,n):void 0},has(t){return U.has(t)||t in ee},list(){return[...Object.keys(ee),...U.keys()]}},ve={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 _e(t){return ve[t]??ve.sum}function ct(t,e){return _e(t)(e)}const dt=k.register.bind(k),ut=k.unregister.bind(k),ht=k.get.bind(k),ft=k.run.bind(k),pt=k.list.bind(k);E.BaseGridPlugin=it,E.DEFAULT_ANIMATION_CONFIG=oe,E.DEFAULT_GRID_ICONS=P,E.DGEvents=lt,E.DataGridElement=I,E.FitModeEnum=q,E.GridCSSVars=rt,E.GridClasses=T,E.GridDataAttrs=F,E.GridElement=I,E.GridSelectors=st,E.PLUGIN_QUERIES=nt,E.PluginEvents=at,E.PluginManager=me,E.aggregatorRegistry=k,E.builtInSort=de,E.defaultComparator=ce,E.getAggregator=ht,E.getValueAggregator=_e,E.listAggregators=pt,E.registerAggregator=dt,E.runAggregator=ft,E.runValueAggregator=ct,E.unregisterAggregator=ut,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})}));
74
74
  //# sourceMappingURL=grid.umd.js.map