@toolbox-web/grid 1.1.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +80 -22
  2. package/all.d.ts +1 -0
  3. package/all.d.ts.map +1 -1
  4. package/all.js +557 -365
  5. package/all.js.map +1 -1
  6. package/index.d.ts +1 -1
  7. package/index.d.ts.map +1 -1
  8. package/index.js +903 -769
  9. package/index.js.map +1 -1
  10. package/lib/core/grid.d.ts +102 -3
  11. package/lib/core/grid.d.ts.map +1 -1
  12. package/lib/core/internal/row-animation.d.ts +37 -0
  13. package/lib/core/internal/row-animation.d.ts.map +1 -0
  14. package/lib/core/internal/rows.d.ts.map +1 -1
  15. package/lib/core/internal/shell.d.ts.map +1 -1
  16. package/lib/core/plugin/base-plugin.d.ts +65 -3
  17. package/lib/core/plugin/base-plugin.d.ts.map +1 -1
  18. package/lib/core/plugin/index.d.ts +1 -1
  19. package/lib/core/plugin/index.d.ts.map +1 -1
  20. package/lib/core/plugin/plugin-manager.d.ts +25 -1
  21. package/lib/core/plugin/plugin-manager.d.ts.map +1 -1
  22. package/lib/core/plugin/types.d.ts +62 -0
  23. package/lib/core/plugin/types.d.ts.map +1 -1
  24. package/lib/core/types.d.ts +64 -1
  25. package/lib/core/types.d.ts.map +1 -1
  26. package/lib/plugins/clipboard/index.js +73 -69
  27. package/lib/plugins/clipboard/index.js.map +1 -1
  28. package/lib/plugins/clipboard/types.d.ts +1 -0
  29. package/lib/plugins/clipboard/types.d.ts.map +1 -1
  30. package/lib/plugins/column-virtualization/index.js.map +1 -1
  31. package/lib/plugins/context-menu/index.js.map +1 -1
  32. package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
  33. package/lib/plugins/editing/index.js +69 -40
  34. package/lib/plugins/editing/index.js.map +1 -1
  35. package/lib/plugins/export/index.js.map +1 -1
  36. package/lib/plugins/filtering/index.js.map +1 -1
  37. package/lib/plugins/grouping-columns/index.js.map +1 -1
  38. package/lib/plugins/grouping-rows/index.js.map +1 -1
  39. package/lib/plugins/master-detail/MasterDetailPlugin.d.ts.map +1 -1
  40. package/lib/plugins/master-detail/index.js +14 -12
  41. package/lib/plugins/master-detail/index.js.map +1 -1
  42. package/lib/plugins/multi-sort/index.js.map +1 -1
  43. package/lib/plugins/pinned-columns/index.js.map +1 -1
  44. package/lib/plugins/pinned-rows/index.js.map +1 -1
  45. package/lib/plugins/pivot/index.js.map +1 -1
  46. package/lib/plugins/reorder/index.js.map +1 -1
  47. package/lib/plugins/responsive/index.js.map +1 -1
  48. package/lib/plugins/row-reorder/RowReorderPlugin.d.ts +155 -0
  49. package/lib/plugins/row-reorder/RowReorderPlugin.d.ts.map +1 -0
  50. package/lib/plugins/row-reorder/index.d.ts +9 -0
  51. package/lib/plugins/row-reorder/index.d.ts.map +1 -0
  52. package/lib/plugins/row-reorder/index.js +597 -0
  53. package/lib/plugins/row-reorder/index.js.map +1 -0
  54. package/lib/plugins/row-reorder/types.d.ts +80 -0
  55. package/lib/plugins/row-reorder/types.d.ts.map +1 -0
  56. package/lib/plugins/selection/SelectionPlugin.d.ts +13 -0
  57. package/lib/plugins/selection/SelectionPlugin.d.ts.map +1 -1
  58. package/lib/plugins/selection/index.d.ts +1 -1
  59. package/lib/plugins/selection/index.d.ts.map +1 -1
  60. package/lib/plugins/selection/index.js +95 -64
  61. package/lib/plugins/selection/index.js.map +1 -1
  62. package/lib/plugins/selection/types.d.ts +50 -6
  63. package/lib/plugins/selection/types.d.ts.map +1 -1
  64. package/lib/plugins/server-side/index.js.map +1 -1
  65. package/lib/plugins/tree/index.js.map +1 -1
  66. package/lib/plugins/undo-redo/index.js.map +1 -1
  67. package/lib/plugins/visibility/index.js.map +1 -1
  68. package/package.json +21 -4
  69. package/public.d.ts +15 -2
  70. package/public.d.ts.map +1 -1
  71. package/umd/grid.all.umd.js +23 -23
  72. package/umd/grid.all.umd.js.map +1 -1
  73. package/umd/grid.umd.js +15 -15
  74. package/umd/grid.umd.js.map +1 -1
  75. package/umd/plugins/clipboard.umd.js +5 -5
  76. package/umd/plugins/clipboard.umd.js.map +1 -1
  77. package/umd/plugins/editing.umd.js +1 -1
  78. package/umd/plugins/editing.umd.js.map +1 -1
  79. package/umd/plugins/master-detail.umd.js +1 -1
  80. package/umd/plugins/master-detail.umd.js.map +1 -1
  81. package/umd/plugins/row-reorder.umd.js +2 -0
  82. package/umd/plugins/row-reorder.umd.js.map +1 -0
  83. package/umd/plugins/selection.umd.js +2 -2
  84. package/umd/plugins/selection.umd.js.map +1 -1
@@ -1,4 +1,4 @@
1
- (function(x,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(x=typeof globalThis<"u"?globalThis:x||self,j(x.TbwGrid={}))})(this,(function(x){"use strict";const j='@layer tbw-base,tbw-plugins,tbw-theme;@layer tbw-base{:root{color-scheme:light dark}tbw-grid{--tbw-base-icon-size: 1em;--tbw-base-radius: .25em;--tbw-font-size: 1em;--tbw-font-size-sm: .9285em;--tbw-font-size-xs: .7857em;--tbw-font-size-2xs: .7142em;--tbw-spacing-xs: .25em;--tbw-spacing-sm: .375em;--tbw-spacing-md: .5em;--tbw-spacing-lg: .75em;--tbw-spacing-xl: 1em;--tbw-icon-size: var(--tbw-base-icon-size);--tbw-icon-size-sm: .875em;--tbw-checkbox-size: var(--tbw-base-icon-size);--tbw-toggle-size: 1.25em;--tbw-border-radius: var(--tbw-base-radius);--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-error: light-dark(hsl(0, 65%, 51%), hsl(0, 65%, 55%));--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, #666666);--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-header: var(--tbw-font-size);--tbw-font-weight-header: bold;--tbw-cell-padding-header: var(--tbw-spacing-xs) var(--tbw-spacing-md);--tbw-cell-padding: var(--tbw-spacing-xs) var(--tbw-spacing-md);--tbw-cell-padding-input: var(--tbw-spacing-xs) var(--tbw-spacing-sm);--tbw-row-height: 1.75em;--tbw-header-height: 1.875em;--tbw-cell-white-space: nowrap;--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: var(--tbw-spacing-sm);--tbw-resize-handle-color: transparent;--tbw-resize-handle-color-hover: var(--tbw-color-accent);--tbw-resize-handle-border-radius: 0;--tbw-resize-indicator-width: 2px;--tbw-resize-indicator-color: var(--tbw-color-accent);--tbw-resize-indicator-opacity: .6;--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-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-density-scale: 1;--tbw-shell-header-height: 2.75em;--tbw-shell-header-bg: var(--tbw-color-panel-bg);--tbw-shell-header-border: var(--tbw-color-border);--tbw-shell-title-font-size: var(--tbw-font-size);--tbw-shell-title-font-weight: 600;--tbw-tool-panel-width: 17.5em;--tbw-tool-panel-bg: var(--tbw-color-panel-bg);--tbw-tool-panel-border: var(--tbw-color-border);--tbw-tool-panel-header-height: 2.5em;--tbw-tool-panel-transition: var(--tbw-animation-duration) var(--tbw-animation-easing);--tbw-toolbar-button-size: 2em;--tbw-toolbar-button-gap: var(--tbw-spacing-xs);--tbw-panel-padding: var(--tbw-spacing-lg);--tbw-panel-gap: var(--tbw-spacing-md);--tbw-menu-item-padding: var(--tbw-spacing-sm) var(--tbw-spacing-lg);--tbw-menu-item-gap: var(--tbw-spacing-md);--tbw-menu-min-width: 10rem;--tbw-button-padding: var(--tbw-spacing-sm) var(--tbw-spacing-lg);--tbw-button-padding-sm: var(--tbw-spacing-xs) var(--tbw-spacing-md);--tbw-input-height: var(--tbw-row-height);--tbw-input-padding: 0 var(--tbw-spacing-md);--tbw-detail-padding: var(--tbw-spacing-xl);--tbw-detail-max-height: 31.25rem;--tbw-indicator-size: var(--tbw-spacing-sm);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}tbw-grid,tbw-grid *{box-sizing:border-box}tbw-grid .header{display:block;flex-shrink:0;z-index:var(--tbw-z-layer-header, 30);background:var(--tbw-color-header-bg);overflow:visible}tbw-grid .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)}tbw-grid .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))}tbw-grid .header-group-cell:not(:last-child){border-right:2px solid var(--tbw-color-border)}tbw-grid .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)}tbw-grid .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:visible;min-width:0}tbw-grid .header-row>.cell>span:first-child{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}tbw-grid .header-row>.cell>span[part~=sort-indicator]{flex-shrink:0;opacity:.6}tbw-grid .header-row>.cell:last-child{border-right:0}tbw-grid .header-row>.cell.grouped.group-end:not(:last-child){border-right:2px solid var(--tbw-color-border)}tbw-grid .header-row>.cell.resizable{position:relative}tbw-grid .header-row>.cell.sticky-left,tbw-grid .header-row>.cell.sticky-right{background:var(--tbw-color-header-bg);z-index:35}tbw-grid .tbw-grid-root{display:flex;flex-direction:column;height:100%}tbw-grid .tbw-grid-root.has-shell{display:flex;flex-direction:column;height:100%}tbw-grid .rows-body-wrapper{flex:1;min-height:0;display:flex;flex-direction:row;width:100%;min-width:fit-content}tbw-grid .rows-body{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow:visible}tbw-grid .rows-container{display:flex;flex-direction:row;flex:1;min-height:0;overflow:visible}tbw-grid .rows-viewport{flex:1;min-width:0;position:relative;display:block;overflow:clip}tbw-grid .rows-viewport .rows{position:absolute;top:0;left:0;min-width:100%;will-change:transform;z-index:var(--tbw-z-layer-rows, 1)}tbw-grid .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)}tbw-grid .faux-vscroll-spacer{width:1px}tbw-grid .data-grid-row{display:grid;grid-template-columns:var(--tbw-column-template);contain:layout style;content-visibility:auto;contain-intrinsic-size:auto var(--tbw-row-height)}tbw-grid .data-grid-row:nth-child(2n){background:var(--tbw-color-row-alt)}tbw-grid .data-grid-row:hover{background:var(--tbw-color-row-hover)}tbw-grid .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}tbw-grid .data-grid-row>.cell>*{overflow:hidden;text-overflow:ellipsis;white-space:inherit;min-width:0}tbw-grid .data-grid-row>.cell:last-child{border-right:0}tbw-grid .data-grid-row>.cell[data-type=boolean]{text-align:center}tbw-grid .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}tbw-grid .data-grid-row>.cell.selected:focus-visible,tbw-grid .data-grid-row>.cell:focus-visible:not(.cell-focus){outline:none}tbw-grid .data-grid-row>.cell.sticky-left,tbw-grid .data-grid-row>.cell.sticky-right{background:var(--tbw-color-panel-bg)}tbw-grid .selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}tbw-grid .sortable{cursor:pointer;-webkit-user-select:none;user-select:none}tbw-grid .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)}tbw-grid .resize-handle:after{content:"";position:absolute;top:100%;left:50%;transform:translate(-50%);width:var(--tbw-resize-indicator-width, 2px);height:0;background:var(--tbw-resize-indicator-color, var(--tbw-color-accent));opacity:0;pointer-events:none;transition:opacity .12s ease,height 0s .12s;z-index:1000}tbw-grid .resize-handle:hover{background:var(--tbw-resize-handle-color-hover)}tbw-grid .resize-handle:hover:after{height:100vh;opacity:var(--tbw-resize-indicator-opacity, .6);transition:opacity .12s ease,height 0s}tbw-grid[data-has-focus] .cell-focus,tbw-grid[data-has-focus] .row-focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}tbw-grid .sticky-left,tbw-grid .sticky-right{position:sticky;z-index:25}tbw-grid .sticky-left{box-shadow:1px 0 0 var(--tbw-color-border)}tbw-grid .sticky-right{box-shadow:-1px 0 0 var(--tbw-color-border)}tbw-grid .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}tbw-grid .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}tbw-grid .tbw-shell-content{flex:1;display:flex;align-items:center;gap:12px;min-width:0;overflow:hidden}tbw-grid .tbw-shell-toolbar{display:flex;align-items:center;gap:var(--tbw-toolbar-button-gap);flex-shrink:0}tbw-grid .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)}tbw-grid .tbw-toolbar-btn:hover{background:var(--tbw-color-row-hover)}tbw-grid .tbw-toolbar-btn:focus-visible{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}tbw-grid .tbw-toolbar-btn.active{background:var(--tbw-focus-background);border-color:var(--tbw-color-accent)}tbw-grid .tbw-toolbar-btn:disabled{opacity:.5;cursor:not-allowed}tbw-grid .tbw-toolbar-separator{width:1px;height:20px;background:var(--tbw-color-border);margin:0 4px}tbw-grid .tbw-shell-body{position:relative;display:flex;flex:1;min-height:0;overflow:visible}tbw-grid .tbw-grid-content{flex:1;min-width:0;min-height:0;display:flex;flex-direction:row;overflow:hidden}tbw-grid .tbw-scroll-area{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow-x:auto;overflow-y:hidden;overflow-anchor:none}tbw-grid .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)}tbw-grid .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)}tbw-grid .tbw-tool-panel.open{width:var(--tbw-tool-panel-width)}tbw-grid .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)}tbw-grid .tbw-tool-panel-resize[data-handle-position=left]{left:0}tbw-grid .tbw-tool-panel-resize[data-handle-position=right]{right:0}tbw-grid .tbw-tool-panel-resize:hover,tbw-grid .tbw-tool-panel-resize.resizing{background:var(--tbw-color-accent)}tbw-grid .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}tbw-grid .tbw-tool-panel-title{font-weight:600;font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}tbw-grid .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}tbw-grid .tbw-tool-panel-close:hover{background:var(--tbw-color-row-hover);color:var(--tbw-color-fg)}tbw-grid .tbw-tool-panel-content{flex:1;overflow:auto}tbw-grid .tbw-accordion{display:flex;flex-direction:column;gap:0}tbw-grid .tbw-accordion-section{border-bottom:1px solid var(--tbw-tool-panel-border)}tbw-grid .tbw-accordion-section:last-child{border-bottom:none}tbw-grid .tbw-accordion-section.single .tbw-accordion-header{cursor:default}tbw-grid .tbw-accordion-section.single .tbw-accordion-header:hover{background:transparent}tbw-grid .tbw-accordion-section.expanded .tbw-accordion-chevron{transform:rotate(90deg)}tbw-grid .tbw-accordion-section.expanded .tbw-accordion-content{display:block}tbw-grid .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}tbw-grid .tbw-accordion-header:hover{background:var(--tbw-color-row-hover)}tbw-grid .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}tbw-grid .tbw-accordion-icon{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:14px;flex-shrink:0}tbw-grid .tbw-accordion-title{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}tbw-grid .tbw-accordion-content{display:none}tbw-grid .tbw-expanding{animation:tbw-expand var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}tbw-grid .tbw-collapsing{animation:tbw-collapse var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}tbw-grid[data-animation-mode=off]{--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms}@media(forced-colors:active){tbw-grid{--tbw-color-border: CanvasText;--tbw-color-border-strong: CanvasText;--tbw-color-border-cell: CanvasText;--tbw-color-border-header: CanvasText;--tbw-color-fg: CanvasText;--tbw-color-bg: Canvas;--tbw-color-panel-bg: Canvas;--tbw-color-header-bg: Canvas;--tbw-color-header-fg: CanvasText;--tbw-color-accent: Highlight;--tbw-color-accent-fg: HighlightText;--tbw-color-selection: Highlight;--tbw-color-row-hover: Highlight;--tbw-focus-outline: 2px solid Highlight;--tbw-range-border-color: Highlight}tbw-grid .cell:focus,tbw-grid .cell.active-cell{outline:2px solid Highlight!important;outline-offset:-2px}tbw-grid .data-grid-row[aria-selected=true]{background:Highlight!important;color:HighlightText!important}}@media(prefers-reduced-motion:reduce){tbw-grid[data-animation-mode=reduced-motion]{--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms}}@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)}}}',Y={STRETCH:"stretch",FIXED:"fixed"},We={mode:"reduced-motion",duration:200,easing:"ease-out"},q={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰"};function ui(n){return Array.from(n.querySelectorAll("tbw-grid-column")).map(t=>{const i=t.getAttribute("field")||"";if(!i)return null;const o=t.getAttribute("type")||void 0,s=o&&new Set(["number","string","date","boolean","select"]).has(o)?o:void 0,l=t.getAttribute("header")||void 0,a=t.hasAttribute("sortable"),c=t.hasAttribute("editable"),d={field:i,type:s,header:l,sortable:a,editable:c},u=t.getAttribute("width");if(u){const y=parseFloat(u);!isNaN(y)&&/^\d+(\.\d+)?$/.test(u.trim())?d.width=y:d.width=u}const h=t.getAttribute("minWidth")||t.getAttribute("min-width");if(h){const y=parseFloat(h);isNaN(y)||(d.minWidth=y)}t.hasAttribute("resizable")&&(d.resizable=!0),t.hasAttribute("sizable")&&(d.resizable=!0);const g=t.getAttribute("editor"),f=t.getAttribute("renderer");g&&(d.__editorName=g),f&&(d.__rendererName=f);const p=t.getAttribute("options");p&&(d.options=p.split(",").map(y=>{const[E,A]=y.includes(":")?y.split(":"):[y.trim(),y.trim()];return{value:E.trim(),label:A?.trim()||E.trim()}}));const w=t.querySelector("tbw-grid-column-view"),m=t.querySelector("tbw-grid-column-editor"),C=t.querySelector("tbw-grid-column-header");w&&(d.__viewTemplate=w),m&&(d.__editorTemplate=m),C&&(d.__headerTemplate=C);const b=globalThis.DataGridElement?.getAdapters?.()??[],R=w??t,_=b.find(y=>y.canHandle(R));if(_){const y=_.createRenderer(R);y&&(d.viewRenderer=y)}const S=m??t,O=b.find(y=>y.canHandle(S));if(O){const y=O.createEditor(S);y&&(d.editor=y)}return d}).filter(t=>!!t)}function $e(n,e){if((!n||!n.length)&&(!e||!e.length))return[];if(!n||!n.length)return e||[];if(!e||!e.length)return n;const t={};e.forEach(o=>{const r=t[o.field];if(r){o.header&&!r.header&&(r.header=o.header),o.type&&!r.type&&(r.type=o.type),o.sortable&&(r.sortable=!0),o.editable&&(r.editable=!0),o.resizable&&(r.resizable=!0),o.width!=null&&r.width==null&&(r.width=o.width),o.minWidth!=null&&r.minWidth==null&&(r.minWidth=o.minWidth),o.__viewTemplate&&(r.__viewTemplate=o.__viewTemplate),o.__editorTemplate&&(r.__editorTemplate=o.__editorTemplate),o.__headerTemplate&&(r.__headerTemplate=o.__headerTemplate);const s=o.renderer||o.viewRenderer,l=r.renderer||r.viewRenderer;s&&!l&&(r.viewRenderer=s,o.renderer&&(r.renderer=s)),o.editor&&!r.editor&&(r.editor=o.editor)}else t[o.field]={...o}});const i=n.map(o=>{const r=t[o.field];if(!r)return o;const s={...o};r.header&&!s.header&&(s.header=r.header),r.type&&!s.type&&(s.type=r.type),s.sortable=o.sortable||r.sortable,(o.resizable===!0||r.resizable===!0)&&(s.resizable=!0),s.editable=o.editable||r.editable,r.width!=null&&s.width==null&&(s.width=r.width),r.minWidth!=null&&s.minWidth==null&&(s.minWidth=r.minWidth),r.__viewTemplate&&(s.__viewTemplate=r.__viewTemplate),r.__editorTemplate&&(s.__editorTemplate=r.__editorTemplate),r.__headerTemplate&&(s.__headerTemplate=r.__headerTemplate);const l=r.renderer||r.viewRenderer,a=s.renderer||s.viewRenderer;return l&&!a&&(s.viewRenderer=l,r.renderer&&(s.renderer=l)),r.editor&&!s.editor&&(s.editor=r.editor),delete t[o.field],s});return Object.keys(t).forEach(o=>i.push(t[o])),i}function Ue(n,e){try{n.part?.add?.(e)}catch{}const t=n.getAttribute("part");t?t.split(/\s+/).includes(e)||n.setAttribute("part",t+" "+e):n.setAttribute("part",e)}function je(n){const e=n.effectiveConfig?.fitMode||n.fitMode||Y.STRETCH;if(e!==Y.STRETCH&&e!==Y.FIXED||n.__didInitialAutoSize||!n.isConnected)return;const t=Array.from(n._headerRowEl?.children||[]);if(!t.length)return;let i=!1;n._visibleColumns.forEach((o,r)=>{if(o.width)return;const s=t[r];let l=s?s.scrollWidth:0;for(const a of n._rowPool){const c=a.children[r];if(c){const d=c.scrollWidth;d>l&&(l=d)}}l>0&&(o.width=l+2,o.__autoSized=!0,i=!0)}),i&&te(n),n.__didInitialAutoSize=!0}function te(n){(n.effectiveConfig?.fitMode||n.fitMode||Y.STRETCH)===Y.STRETCH?n._gridTemplate=n._visibleColumns.map(t=>{if(t.width)return`${t.width}px`;const i=t.minWidth;return i!=null?`minmax(${i}px, 1fr)`:"1fr"}).join(" ").trim():n._gridTemplate=n._visibleColumns.map(t=>t.width?`${t.width}px`:"max-content").join(" "),n.style.setProperty("--tbw-column-template",n._gridTemplate)}function hi(n){return n==null?"string":typeof n=="number"?"number":typeof n=="boolean"?"boolean":n instanceof Date||typeof n=="string"&&/\d{4}-\d{2}-\d{2}/.test(n)&&!isNaN(Date.parse(n))?"date":"string"}function fi(n,e){const t=n[0]||{},i=Object.keys(t).map(r=>{const s=t[r],l=hi(s);return{field:r,header:r.charAt(0).toUpperCase()+r.slice(1),type:l}}),o={};return i.forEach(r=>{o[r.field]=r.type||"string"}),{columns:i,typeMap:o}}const gi=/{{\s*([^}]+)\s*}}/g,N="__DG_EMPTY__",pi=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,wi=/__(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/;function mi(n){return!n||typeof n!="string"?"":n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}const bi=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"]),Ye=/^on\w+$/i,vi=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),yi=/^\s*(javascript|vbscript|data|blob):/i;function ie(n){if(!n||typeof n!="string")return"";if(n.indexOf("<")===-1)return n;const e=document.createElement("template");return e.innerHTML=n,Ci(e.content),e.innerHTML}function Ci(n){const e=[],t=n.querySelectorAll("*");for(const i of t){const o=i.tagName.toLowerCase();if(bi.has(o)){e.push(i);continue}if((o==="svg"||i.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(i.attributes).some(l=>Ye.test(l.name)||l.name==="href"||l.name==="xlink:href")){e.push(i);continue}const r=[];for(const s of i.attributes){const l=s.name.toLowerCase();if(Ye.test(l)){r.push(s.name);continue}if(vi.has(l)&&yi.test(s.value)){r.push(s.name);continue}if(l==="style"&&/expression\s*\(|javascript:|behavior\s*:/i.test(s.value)){r.push(s.name);continue}}r.forEach(s=>i.removeAttribute(s))}e.forEach(i=>i.remove())}function we(n,e){if(!n||n.indexOf("{{")===-1)return n;const t=[],i=n.replace(gi,(l,a)=>{const c=xi(a,e);return t.push({expr:a.trim(),result:c}),c}),o=Ei(i),r=t.length&&t.every(l=>l.result===""||l.result===N);return/Reflect\.|\bProxy\b|ownKeys\(/.test(n)||r?"":o}function xi(n,e){if(n=(n||"").trim(),!n||/\b(Reflect|Proxy|ownKeys)\b/.test(n))return N;if(n==="value")return e.value==null?N:String(e.value);if(n.startsWith("row.")&&!/[()?]/.test(n)&&!n.includes(":")){const i=n.slice(4),o=e.row?e.row[i]:void 0;return o==null?N:String(o)}if(n.length>80||!pi.test(n)||wi.test(n))return N;const t=n.match(/\./g);if(t&&t.length>1)return N;try{const o=new Function("value","row",`return (${n});`)(e.value,e.row),r=o==null?"":String(o);return/Reflect|Proxy|ownKeys/.test(r)?N:r||N}catch{return N}}function Ei(n){return n&&n.replace(new RegExp(N,"g"),"").replace(/Reflect\.[^<>{}\s]+/g,"").replace(/\bProxy\b/g,"").replace(/ownKeys\([^)]*\)/g,"")}function Ri(n){if(/Reflect|Proxy|ownKeys/.test(n.textContent||"")){if(Array.from(n.childNodes).forEach(e=>{e.nodeType===Node.TEXT_NODE&&/Reflect|Proxy|ownKeys/.test(e.textContent||"")&&(e.textContent="")}),/Reflect|Proxy|ownKeys/.test(n.textContent||"")){if(/Reflect|Proxy|ownKeys/.test(n.textContent||""))for(;n.firstChild;)n.removeChild(n.firstChild);n.textContent=(n.textContent||"").replace(/Reflect|Proxy|ownKeys/g,"")}(n.textContent||"").trim().length===0&&(n.textContent="")}}function Xe(n){const e=/Reflect\.|\bProxy\b|ownKeys\(/.test(n),t=(i=>e?"":we(n,i));return t.__blocked=e,t}const Si=100;class _i{#e;#n;#d;#c;#s;#i={};#h={};#u=!0;#p=[];#l;#w;#m;#a;#b;constructor(e){this.#a=e}get original(){return this.#i}get effective(){return this.#h}get columns(){return this.#h.columns??[]}set columns(e){this.#h.columns=e}get lightDomColumnsCache(){return this.#c}set lightDomColumnsCache(e){this.#c=e}get originalColumnNodes(){return this.#s}set originalColumnNodes(e){this.#s=e}get lightDomTitle(){return this.#b}set lightDomTitle(e){this.#b=e}get initialColumnState(){return this.#m}set initialColumnState(e){this.#m=e}get sourcesChanged(){return this.#u}markSourcesChanged(){this.#u=!0}setGridConfig(e){this.#e=e,this.#u=!0,this.#c=void 0}getGridConfig(){return this.#e}setColumns(e){this.#n=e,this.#u=!0}getColumns(){return this.#n}setFitMode(e){this.#d=e,this.#u=!0}getFitMode(){return this.#d}merge(){const e=(this.#h.columns?.length??0)>0;if(!this.#u&&e)return;const t=this.#y();this.#u=!1,this.#i=t,Object.freeze(this.#i),this.#i.columns&&Object.freeze(this.#i.columns),this.#h=this.#v(this.#i),this.#g()}#v(e){const t={...e};return e.columns&&(t.columns=e.columns.map(i=>({...i}))),e.shell&&(t.shell={...e.shell,header:e.shell.header?{...e.shell.header}:void 0,toolPanel:e.shell.toolPanel?{...e.shell.toolPanel}:void 0,toolPanels:e.shell.toolPanels?.map(i=>({...i})),headerContents:e.shell.headerContents?.map(i=>({...i}))}),t}#g(){const e=this.#h;e.rowHeight&&e.rowHeight>0&&this.#a.setRowHeight(e.rowHeight),e.fitMode==="fixed"&&this.columns.forEach(i=>{i.width==null&&(i.width=80)}),this.#a.applyAnimationConfig(e)}#y(){const e=this.#e?{...this.#e}:{},t=Array.isArray(e.columns)?[...e.columns]:[],i=(this.#c??[]).map(s=>({...s}));let o=$e(t,i);this.#n&&this.#n.length&&(o=$e(this.#n,i));const r=this.#a.getRows();return o.length===0&&r.length&&(o=fi(r).columns),o.length&&(o.forEach(s=>{s.sortable===void 0&&(s.sortable=!0),s.resizable===void 0&&(s.resizable=!0),s.__originalWidth===void 0&&typeof s.width=="number"&&(s.__originalWidth=s.width)}),o.forEach(s=>{s.__viewTemplate&&!s.__compiledView&&(s.__compiledView=Xe(s.__viewTemplate.innerHTML)),s.__editorTemplate&&!s.__compiledEditor&&(s.__compiledEditor=Xe(s.__editorTemplate.innerHTML))}),e.columns=o),this.#d&&(e.fitMode=this.#d),e.fitMode||(e.fitMode="stretch"),this.#x(e),e.columnState&&!this.#m&&(this.#m=e.columnState),e}#x(e){e.shell=e.shell?{...e.shell}:{},e.shell.header=e.shell.header?{...e.shell.header}:{};const t=this.#a.getShellLightDomTitle();t&&(this.#b=t),this.#b&&!e.shell.header.title&&(e.shell.header.title=this.#b);const i=this.#a.getShellLightDomHeaderContent();i?.length>0&&(e.shell.header.lightDomContent=i),this.#a.getShellHasToolButtonsContainer()&&(e.shell.header.hasToolButtonsContainer=!0);const o=this.#a.getShellToolPanels();if(o.size>0){const u=Array.from(o.values());u.sort((h,g)=>(h.order??100)-(g.order??100)),e.shell.toolPanels=u}const r=this.#a.getShellHeaderContents();if(r.size>0){const u=Array.from(r.values());u.sort((h,g)=>(h.order??100)-(g.order??100)),e.shell.headerContents=u}const s=this.#a.getShellToolbarContents(),l=Array.from(s.values()),a=this.#e?.shell?.header?.toolbarContents??[],c=new Set(a.map(u=>u.id)),d=[...a];for(const u of l)c.has(u.id)||d.push(u);d.sort((u,h)=>(u.order??0)-(h.order??0)),e.shell.header.toolbarContents=d}collectState(e){const t=this.columns,i=this.#C();return{columns:t.map((o,r)=>{const s={field:o.field,order:r,visible:!o.hidden},l=o;l.__renderedWidth!==void 0?s.width=l.__renderedWidth:o.width!==void 0&&(s.width=typeof o.width=="string"?parseFloat(o.width):o.width);const a=i.get(o.field);a&&(s.sort=a);for(const c of e)if(c.getColumnState){const d=c.getColumnState(o.field);d&&Object.assign(s,d)}return s})}}applyState(e,t){if(!e.columns||e.columns.length===0)return;const i=this.columns,o=new Map(e.columns.map(l=>[l.field,l])),r=i.map(l=>{const a=o.get(l.field);if(!a)return l;const c={...l};return a.width!==void 0&&(c.width=a.width,c.__renderedWidth=a.width),a.visible!==void 0&&(c.hidden=!a.visible),c});r.sort((l,a)=>{const c=o.get(l.field)?.order??1/0,d=o.get(a.field)?.order??1/0;return c-d}),this.columns=r;const s=e.columns.filter(l=>l.sort!==void 0).sort((l,a)=>(l.sort?.priority??0)-(a.sort?.priority??0));if(s.length>0){const l=s[0];l.sort&&this.#a.setSortState({field:l.field,direction:l.sort.direction==="asc"?1:-1})}else this.#a.setSortState(null);for(const l of t)if(l.applyColumnState)for(const a of e.columns)l.applyColumnState(a.field,a)}resetState(e){this.#m=void 0,this.#a.setSortState(null),this.#h=this.#v(this.#i),this.#g();for(const t of e)if(t.applyColumnState)for(const i of this.columns)t.applyColumnState(i.field,{field:i.field,order:0,visible:!0});this.requestStateChange(e)}#C(){const e=new Map,t=this.#a.getSortState();return t&&e.set(t.field,{direction:t.direction===1?"asc":"desc",priority:0}),e}requestStateChange(e){this.#w&&clearTimeout(this.#w),this.#w=setTimeout(()=>{this.#w=void 0;const t=this.collectState(e);this.#a.emit("column-state-change",t)},Si)}setColumnVisible(e,t){const i=this.columns,o=i.find(s=>s.field===e);return!o||!t&&o.lockVisible||!t&&i.filter(l=>!l.hidden&&l.field!==e).length===0||!!o.hidden===!t?!1:(o.hidden=!t,this.#a.emit("column-visibility",{field:e,visible:t,visibleColumns:i.filter(s=>!s.hidden).map(s=>s.field)}),this.#a.clearRowPool(),this.#a.setup(),!0)}toggleColumnVisibility(e){const t=this.columns.find(i=>i.field===e);return t?this.setColumnVisible(e,!!t.hidden):!1}isColumnVisible(e){const t=this.columns.find(i=>i.field===e);return t?!t.hidden:!1}showAllColumns(){const e=this.columns;e.some(t=>t.hidden)&&(e.forEach(t=>t.hidden=!1),this.#a.emit("column-visibility",{visibleColumns:e.map(t=>t.field)}),this.#a.clearRowPool(),this.#a.setup())}getAllColumns(){return this.columns.map(e=>({field:e.field,header:e.header||e.field,visible:!e.hidden,lockVisible:e.lockVisible,utility:e.meta?.utility===!0}))}getColumnOrder(){return this.columns.map(e=>e.field)}setColumnOrder(e){if(!e.length)return;const t=new Map(this.columns.map(o=>[o.field,o])),i=[];for(const o of e){const r=t.get(o);r&&(i.push(r),t.delete(o))}for(const o of t.values())i.push(o);this.columns=i,this.#a.renderHeader(),this.#a.updateTemplate(),this.#a.refreshVirtualWindow()}parseLightDomColumns(e){this.#c||(this.#s=Array.from(e.querySelectorAll("tbw-grid-column")),this.#c=this.#s.length?ui(e):[])}clearLightDomCache(){this.#c=void 0}#E=new Map;registerLightDomHandler(e,t){this.#E.set(e.toLowerCase(),t)}unregisterLightDomHandler(e){this.#E.delete(e.toLowerCase())}observeLightDOM(e){this.#l&&this.#l.disconnect();const t=new Set;let i=null;const o=()=>{i=null;for(const r of t)this.#E.get(r)?.();t.clear()};this.#l=new MutationObserver(r=>{for(const s of r){for(const l of s.addedNodes){if(l.nodeType!==Node.ELEMENT_NODE)continue;const c=l.tagName.toLowerCase();this.#E.has(c)&&t.add(c)}if(s.type==="attributes"&&s.target.nodeType===Node.ELEMENT_NODE){const a=s.target.tagName.toLowerCase();this.#E.has(a)&&t.add(a)}}t.size>0&&!i&&(i=setTimeout(o,0))}),this.#l.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["title","field","header","width","hidden","id","icon","tooltip","order"]})}onChange(e){this.#p.push(e)}notifyChange(){for(const e of this.#p)e()}dispose(){this.#l?.disconnect(),this.#p=[],this.#w&&clearTimeout(this.#w)}}function Ze(n){return`<span role="checkbox" aria-checked="${n}" aria-label="${n}">${n?"&#x1F5F9;":"&#9744;"}</span>`}function Je(n){if(n==null||n==="")return"";if(n instanceof Date)return isNaN(n.getTime())?"":n.toLocaleDateString();if(typeof n=="number"||typeof n=="string"){const e=new Date(n);return isNaN(e.getTime())?"":e.toLocaleDateString()}return""}function me(n){if(!n)return-1;const e=n.getAttribute("data-row");if(e)return parseInt(e,10);const t=n.closest(".data-grid-row");if(!t)return-1;const i=t.parentElement;if(!i)return-1;const o=i.querySelectorAll(":scope > .data-grid-row");for(let r=0;r<o.length;r++)if(o[r]===t)return r;return-1}function Ai(n){if(!n)return-1;const e=n.getAttribute("data-col");return e?parseInt(e,10):-1}function ne(n){n&&n.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function Qe(n,e){const t=e.renderer||e.viewRenderer;if(t)return t;if(!e.type)return;const i=n.effectiveConfig?.typeDefaults;if(i?.[e.type]?.renderer)return i[e.type].renderer;const o=n.__frameworkAdapter;if(o?.getTypeDefault){const r=o.getTypeDefault(e.type);if(r?.renderer)return r.renderer}}const et='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function be(n){return(n.__editingCellCount??0)>0}function ve(n){n.__editingCellCount=0,n.removeAttribute("data-has-editing"),n.querySelectorAll(".cell.editing").forEach(t=>t.classList.remove("editing"))}const tt=document.createElement("template");tt.innerHTML='<div class="cell" role="gridcell" part="cell"></div>';const it=document.createElement("template");it.innerHTML='<div class="data-grid-row" role="row" part="row"></div>';function Ti(){return tt.content.firstElementChild.cloneNode(!0)}function ki(){return it.content.firstElementChild.cloneNode(!0)}function de(n){n.__cellDisplayCache=void 0,n.__cellCacheEpoch=void 0,n.__hasSpecialColumns=void 0}function Pi(n,e,t,i,o){const r=Math.max(0,t-e),s=n._bodyEl,l=n._visibleColumns,a=l.length;let c=n.__cachedHeaderRowCount;for(c===void 0&&(c=n.querySelector(".header-group-row")?2:1,n.__cachedHeaderRowCount=c);n._rowPool.length<r;){const u=ki();n._rowPool.push(u)}if(n._rowPool.length>r){for(let u=r;u<n._rowPool.length;u++){const h=n._rowPool[u];h.parentNode===s&&h.remove()}n._rowPool.length=r}const d=o&&n.__hasRenderRowPlugins!==!1;for(let u=0;u<r;u++){const h=e+u,g=n._rows[h],f=n._rowPool[u];if(f.setAttribute("aria-rowindex",String(h+c+1)),d&&o(g,f,h)){f.__epoch=i,f.__rowDataRef=g,f.parentNode!==s&&s.appendChild(f);continue}const p=f.__epoch,w=f.__rowDataRef,m=f.children.length,v=p===i&&m===a,b=w!==g;let R=!1;if(v&&b){for(let E=0;E<a;E++)if(l[E].externalView&&!f.querySelector(`.cell[data-col="${E}"] [data-external-view]`)){R=!0;break}}if(!v||R){const E=be(f),A=n._activeEditRows===h;E&&!A?(f.__isCustomRow&&(f.className="data-grid-row",f.setAttribute("role","row"),f.__isCustomRow=!1),ve(f),oe(n,f,g,h),f.__epoch=i,f.__rowDataRef=g):E&&A?(ye(n,f,g,h),f.__rowDataRef=g):(f.__isCustomRow&&(f.className="data-grid-row",f.setAttribute("role","row"),f.__isCustomRow=!1),oe(n,f,g,h),f.__epoch=i,f.__rowDataRef=g)}else if(b){const E=be(f),A=n._activeEditRows===h;E&&!A?(ve(f),oe(n,f,g,h),f.__epoch=i,f.__rowDataRef=g):(ye(n,f,g,h),f.__rowDataRef=g)}else{const E=be(f),A=n._activeEditRows===h;E&&!A?(ve(f),oe(n,f,g,h),f.__epoch=i,f.__rowDataRef=g):ye(n,f,g,h)}let _=!1;const S=n.changedRowIds;if(S&&S.length>0)try{const E=n.getRowId?.(g);E&&(_=S.includes(E))}catch{}const O=f.classList.contains("changed");_!==O&&f.classList.toggle("changed",_);const y=n.effectiveConfig?.rowClass;if(y){const E=f.getAttribute("data-dynamic-classes");E&&E.split(" ").forEach(A=>A&&f.classList.remove(A));try{const A=y(g);if(A&&A.length>0){const k=A.filter(T=>T&&typeof T=="string");k.forEach(T=>f.classList.add(T)),f.setAttribute("data-dynamic-classes",k.join(" "))}else f.removeAttribute("data-dynamic-classes")}catch(A){console.warn("[tbw-grid] rowClass callback error:",A),f.removeAttribute("data-dynamic-classes")}}f.parentNode!==s&&s.appendChild(f)}}function ye(n,e,t,i){const o=e.children,r=n._visibleColumns,s=r.length,l=o.length,a=s<l?s:l,c=n._focusRow,d=n._focusCol;let u=n.__hasSpecialColumns;if(u===void 0){u=!1;const g=n.effectiveConfig?.typeDefaults,f=n.__frameworkAdapter;for(let p=0;p<s;p++){const w=r[p];if(w.__viewTemplate||w.__compiledView||w.renderer||w.viewRenderer||w.externalView||w.format||w.type==="date"||w.type==="boolean"||w.type&&g?.[w.type]?.renderer||w.type&&f?.getTypeDefault?.(w.type)?.renderer){u=!0;break}}n.__hasSpecialColumns=u}const h=String(i);if(!u){for(let g=0;g<a;g++){const f=o[g];if(f.classList.contains("editing"))continue;const p=t[r[g].field];f.textContent=p==null?"":String(p),f.getAttribute("data-row")!==h&&f.setAttribute("data-row",h);const w=c===i&&d===g,m=f.classList.contains("cell-focus");w!==m&&(f.classList.toggle("cell-focus",w),f.setAttribute("aria-selected",String(w)))}return}for(let g=0;g<a;g++)if(r[g].externalView&&!o[g].querySelector("[data-external-view]")){oe(n,e,t,i);return}for(let g=0;g<a;g++){const f=r[g],p=o[g];p.getAttribute("data-row")!==h&&p.setAttribute("data-row",h);const w=c===i&&d===g,m=p.classList.contains("cell-focus");w!==m&&(p.classList.toggle("cell-focus",w),p.setAttribute("aria-selected",String(w)));const C=f.cellClass;if(C){const _=p.getAttribute("data-dynamic-classes");_&&_.split(" ").forEach(S=>S&&p.classList.remove(S));try{const S=t[f.field],O=C(S,t,f);if(O&&O.length>0){const y=O.filter(E=>E&&typeof E=="string");y.forEach(E=>p.classList.add(E)),p.setAttribute("data-dynamic-classes",y.join(" "))}else p.removeAttribute("data-dynamic-classes")}catch(S){console.warn(`[tbw-grid] cellClass callback error for column '${f.field}':`,S),p.removeAttribute("data-dynamic-classes")}}if(p.classList.contains("editing"))continue;const v=Qe(n,f);if(v){const _=t[f.field],S=v({row:t,value:_,field:f.field,column:f,cellEl:p});typeof S=="string"?p.innerHTML=ie(S):S instanceof Node?S.parentElement!==p&&(p.innerHTML="",p.appendChild(S)):S==null&&(p.textContent=_==null?"":String(_));continue}if(f.__viewTemplate||f.__compiledView||f.externalView)continue;const b=t[f.field];let R;if(f.format)try{const _=f.format(b,t);R=_==null?"":String(_)}catch(_){console.warn(`[tbw-grid] Format error in column '${f.field}':`,_),R=b==null?"":String(b)}else f.type==="date"?(R=Je(b),p.textContent=R):f.type==="boolean"?p.innerHTML=Ze(!!b):(R=b==null?"":String(b),p.textContent=R)}}function oe(n,e,t,i){e.innerHTML="";const o=n._visibleColumns,r=o.length,s=n._focusRow,l=n._focusCol,a=n,c=document.createDocumentFragment();for(let d=0;d<r;d++){const u=o[d],h=Ti();h.setAttribute("aria-colindex",String(d+1)),h.setAttribute("data-col",String(d)),h.setAttribute("data-row",String(i)),h.setAttribute("data-field",u.field),h.setAttribute("data-header",u.header??u.field),u.type&&h.setAttribute("data-type",u.type);let g=t[u.field];if(u.format)try{g=u.format(g,t)}catch(b){console.warn(`[tbw-grid] Format error in column '${u.field}':`,b)}const f=u.__compiledView,p=u.__viewTemplate,w=Qe(n,u),m=u.externalView;let C=!1;if(w){const b=w({row:t,value:g,field:u.field,column:u,cellEl:h});typeof b=="string"?(h.innerHTML=ie(b),C=!0):b instanceof Node?b.parentElement!==h&&(h.textContent="",h.appendChild(b)):b==null&&(h.textContent=g==null?"":String(g))}else if(m){const b=m,R=document.createElement("div");R.setAttribute("data-external-view",""),R.setAttribute("data-field",u.field),h.appendChild(R);const _={row:t,value:g,field:u.field,column:u};if(b.mount)try{b.mount({placeholder:R,context:_,spec:b})}catch(S){console.warn(`[tbw-grid] External view mount error for column '${u.field}':`,S)}else queueMicrotask(()=>{try{a.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:R,spec:b,context:_}}))}catch(S){console.warn(`[tbw-grid] External view event dispatch error for column '${u.field}':`,S)}});R.setAttribute("data-mounted","")}else if(f){const b=f({row:t,value:g,field:u.field,column:u}),R=f.__blocked;h.innerHTML=R?"":ie(b),C=!0,R&&(h.textContent="",h.setAttribute("data-blocked-template",""))}else if(p){const b=p.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(b)?(h.textContent="",h.setAttribute("data-blocked-template","")):(h.innerHTML=ie(we(b,{row:t,value:g})),C=!0)}else u.type==="date"?h.textContent=Je(g):u.type==="boolean"?h.innerHTML=Ze(!!g):h.textContent=g==null?"":String(g);if(C){Ri(h);const b=h.textContent||"";/Proxy|Reflect\.ownKeys/.test(b)&&(h.textContent=b.replace(/Proxy|Reflect\.ownKeys/g,"").trim(),/Proxy|Reflect\.ownKeys/.test(h.textContent||"")&&(h.textContent=""))}h.hasAttribute("data-blocked-template")&&(h.textContent||"").trim().length&&(h.textContent=""),u.editable?h.tabIndex=0:u.type==="boolean"&&(h.hasAttribute("tabindex")||(h.tabIndex=0)),s===i&&l===d?(h.classList.add("cell-focus"),h.setAttribute("aria-selected","true")):h.setAttribute("aria-selected","false");const v=u.cellClass;if(v)try{const b=t[u.field],R=v(b,t,u);if(R&&R.length>0){const _=R.filter(S=>S&&typeof S=="string");_.forEach(S=>h.classList.add(S)),h.setAttribute("data-dynamic-classes",_.join(" "))}}catch(b){console.warn(`[tbw-grid] cellClass callback error for column '${u.field}':`,b)}c.appendChild(h)}e.appendChild(c)}function nt(n,e,t){if(e.target?.closest(".resize-handle"))return;const i=t.querySelector(".cell[data-row]"),o=me(i);if(o<0)return;const r=n._rows[o];if(!r||n._dispatchRowClick?.(e,o,r,t))return;const s=e.target?.closest(".cell[data-col]");if(s){const l=Number(s.getAttribute("data-col"));if(!isNaN(l)){if(n._dispatchCellClick?.(e,o,l,s))return;const a=n._focusRow!==o||n._focusCol!==l;if(n._focusRow=o,n._focusCol=l,s.classList.contains("editing")){a&&(ne(n._bodyEl??n),s.classList.add("cell-focus"));const c=s.querySelector(et);try{c?.focus({preventScroll:!0})}catch{}return}M(n)}}}function Li(n,e){if(n._dispatchKeyDown?.(e))return;const t=n._rows.length-1,i=n._visibleColumns.length-1,o=n._activeEditRows!==void 0&&n._activeEditRows!==-1,s=n._visibleColumns[n._focusCol]?.type,l=e.composedPath?.()??[],a=l.length?l[0]:e.target,c=d=>{if(!d)return!1;const u=d.tagName;return!!(u==="INPUT"||u==="SELECT"||u==="TEXTAREA"||d.isContentEditable)};if(!(c(a)&&(e.key==="Home"||e.key==="End"))&&!(c(a)&&(e.key==="ArrowUp"||e.key==="ArrowDown")&&a.tagName==="INPUT"&&a.type==="number")&&!(c(a)&&(e.key==="ArrowLeft"||e.key==="ArrowRight"))&&!(c(a)&&(e.key==="Enter"||e.key==="Escape"))&&!(o&&s==="select"&&(e.key==="ArrowDown"||e.key==="ArrowUp"))){switch(e.key){case"Tab":{e.preventDefault(),!e.shiftKey?n._focusCol<i?n._focusCol+=1:(typeof n.commitActiveRowEdit=="function"&&n.commitActiveRowEdit(),n._focusRow<t&&(n._focusRow+=1,n._focusCol=0)):n._focusCol>0?n._focusCol-=1:n._focusRow>0&&(typeof n.commitActiveRowEdit=="function"&&n._activeEditRows===n._focusRow&&n.commitActiveRowEdit(),n._focusRow-=1,n._focusCol=i),M(n);return}case"ArrowDown":o&&typeof n.commitActiveRowEdit=="function"&&n.commitActiveRowEdit(),n._focusRow=Math.min(t,n._focusRow+1),e.preventDefault();break;case"ArrowUp":o&&typeof n.commitActiveRowEdit=="function"&&n.commitActiveRowEdit(),n._focusRow=Math.max(0,n._focusRow-1),e.preventDefault();break;case"ArrowRight":n._focusCol=Math.min(i,n._focusCol+1),e.preventDefault();break;case"ArrowLeft":n._focusCol=Math.max(0,n._focusCol-1),e.preventDefault();break;case"Home":(e.ctrlKey||e.metaKey)&&(o&&typeof n.commitActiveRowEdit=="function"&&n.commitActiveRowEdit(),n._focusRow=0),n._focusCol=0,e.preventDefault(),M(n,{forceScrollLeft:!0});return;case"End":(e.ctrlKey||e.metaKey)&&(o&&typeof n.commitActiveRowEdit=="function"&&n.commitActiveRowEdit(),n._focusRow=t),n._focusCol=i,e.preventDefault(),M(n,{forceScrollRight:!0});return;case"PageDown":n._focusRow=Math.min(t,n._focusRow+20),e.preventDefault();break;case"PageUp":n._focusRow=Math.max(0,n._focusRow-20),e.preventDefault();break;case"Enter":{const d=n._focusRow,u=n._focusCol,h=n._visibleColumns[u],g=n._rows[d],f=h?.field??"",p=f&&g?g[f]:void 0,w=n.querySelector(`[data-row="${d}"][data-col="${u}"]`),m={rowIndex:d,colIndex:u,field:f,value:p,row:g,cellEl:w,trigger:"keyboard",originalEvent:e},C=new CustomEvent("cell-activate",{cancelable:!0,detail:m});n.dispatchEvent(C);const v=new CustomEvent("activate-cell",{cancelable:!0,detail:{row:d,col:u}});if(n.dispatchEvent(v),C.defaultPrevented||v.defaultPrevented){e.preventDefault();return}break}default:return}M(n)}}function M(n,e){if(n._virtualization?.enabled){const{rowHeight:s,container:l,viewportEl:a}=n._virtualization,c=l,d=a?.clientHeight??c?.clientHeight??0;if(c&&d>0){const u=n._focusRow*s;u<c.scrollTop?c.scrollTop=u:u+s>c.scrollTop+d&&(c.scrollTop=u-d+s)}}const t=n._activeEditRows!==void 0&&n._activeEditRows!==-1;t||n.refreshVirtualWindow(!1),ne(n._bodyEl),Array.from(n._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(s=>{s.setAttribute("aria-selected","false")});const i=n._focusRow,o=n._virtualization.start??0,r=n._virtualization.end??n._rows.length;if(i>=o&&i<r){const s=n._bodyEl.querySelectorAll(".data-grid-row")[i-o];let l=s?.children[n._focusCol];if((!l||!l.classList?.contains("cell"))&&(l=s?.querySelector(`.cell[data-col="${n._focusCol}"]`)??s?.querySelector(".cell[data-col]")),l){l.classList.add("cell-focus"),l.setAttribute("aria-selected","true");const a=n.querySelector(".tbw-scroll-area");if(a&&l&&!t)if(e?.forceScrollLeft)a.scrollLeft=0;else if(e?.forceScrollRight)a.scrollLeft=a.scrollWidth-a.clientWidth;else{const c=n._getHorizontalScrollOffsets?.(s??void 0,l)??{left:0,right:0};if(!c.skipScroll){const d=l.getBoundingClientRect(),u=a.getBoundingClientRect(),h=d.left-u.left+a.scrollLeft,g=h+d.width,f=a.scrollLeft+c.left,p=a.scrollLeft+a.clientWidth-c.right;h<f?a.scrollLeft=h-c.left:g>p&&(a.scrollLeft=g-a.clientWidth+c.right)}}if(n._activeEditRows!==void 0&&n._activeEditRows!==-1&&l.classList.contains("editing")){const c=l.querySelector(et);if(c&&document.activeElement!==c)try{c.focus({preventScroll:!0})}catch{}}else if(!l.contains(document.activeElement)){l.hasAttribute("tabindex")||l.setAttribute("tabindex","-1");try{l.focus({preventScroll:!0})}catch{}}}}}const ue=new WeakMap;function Ii(n,e){const t=me(e),i=Ai(e);t<0||i<0||(n._focusRow=t,n._focusCol=i,ne(n._bodyEl),e.classList.add("cell-focus"),e.setAttribute("aria-selected","true"))}function Ce(n,e,t,i){let o=null;const r=t.composedPath?.();if(r&&r.length>0?o=r[0]:o=t.target,o&&!e.contains(o)){const p=document.elementFromPoint(t.clientX,t.clientY);p&&(o=p)}const s=o?.closest?.("[data-col]"),l=o?.closest?.(".data-grid-row"),a=o?.closest?.(".header-row");let c,d,u,h,g,f;return s&&(c=parseInt(s.getAttribute("data-row")??"-1",10),d=parseInt(s.getAttribute("data-col")??"-1",10),c>=0&&d>=0&&(u=n._rows[c],f=n._columns[d],h=f?.field,g=u&&h?u[h]:void 0)),{type:i,row:u,rowIndex:c!==void 0&&c>=0?c:void 0,colIndex:d!==void 0&&d>=0?d:void 0,field:h,value:g,column:f,originalEvent:t,cellElement:s??void 0,rowElement:l??void 0,isHeader:!!a,cell:c!==void 0&&d!==void 0&&c>=0&&d>=0?{row:c,col:d}:void 0}}function Di(n,e,t){const i=Ce(n,e,t,"mousedown");(n._dispatchCellMouseDown?.(i)??!1)&&ue.set(n,!0)}function Hi(n,e,t){if(!ue.get(n))return;const i=Ce(n,e,t,"mousemove");n._dispatchCellMouseMove?.(i)}function Mi(n,e,t){if(!ue.get(n))return;const i=Ce(n,e,t,"mouseup");n._dispatchCellMouseUp?.(i),ue.set(n,!1)}function Oi(n,e,t){e.addEventListener("mousedown",i=>{const o=i.target.closest(".cell[data-col]");o&&(o.classList.contains("editing")||Ii(n,o))},{signal:t}),e.addEventListener("click",i=>{const o=i.target.closest(".data-grid-row");o&&nt(n,i,o)},{signal:t}),e.addEventListener("dblclick",i=>{const o=i.target.closest(".data-grid-row");o&&nt(n,i,o)},{signal:t})}function Ni(n,e,t,i){e.addEventListener("keydown",o=>Li(n,o),{signal:i}),t.addEventListener("mousedown",o=>Di(n,t,o),{signal:i}),document.addEventListener("mousemove",o=>Hi(n,t,o),{signal:i}),document.addEventListener("mouseup",o=>Mi(n,t,o),{signal:i})}function ot(n,e){return n==null&&e==null?0:n==null?-1:e==null||n>e?1:n<e?-1:0}function rt(n,e,t){const o=t.find(l=>l.field===e.field)?.sortComparator??ot,{field:r,direction:s}=e;return[...n].sort((l,a)=>o(l[r],a[r],l,a)*s)}function st(n,e,t,i){n._rows=e,n.__rowRenderEpoch++,n._rowPool.forEach(o=>o.__epoch=-1),he(n),n.refreshVirtualWindow(!0),n.dispatchEvent(new CustomEvent("sort-change",{detail:{field:t.field,direction:i}})),n.requestStateChange?.()}function lt(n,e){!n._sortState||n._sortState.field!==e.field?(n._sortState||(n.__originalOrder=n._rows.slice()),at(n,e,1)):n._sortState.direction===1?at(n,e,-1):(n._sortState=null,n.__rowRenderEpoch++,n._rowPool.forEach(i=>i.__epoch=-1),n._rows=n.__originalOrder.slice(),he(n),n._headerRowEl?.querySelectorAll('[role="columnheader"].sortable')?.forEach(i=>{i.getAttribute("aria-sort")?(i.getAttribute("aria-sort")==="ascending"||i.getAttribute("aria-sort")==="descending")&&(n._sortState||i.setAttribute("aria-sort","none")):i.setAttribute("aria-sort","none")}),n.refreshVirtualWindow(!0),n.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:0}})),n.requestStateChange?.())}function at(n,e,t){n._sortState={field:e.field,direction:t};const i={field:e.field,direction:t},o=n._columns,s=(n.effectiveConfig?.sortHandler??rt)(n._rows,i,o);s&&typeof s.then=="function"?s.then(l=>{st(n,l,e,t)}):st(n,s,e,t)}function zi(n,e){typeof e=="string"?n.textContent=e:e instanceof HTMLElement&&(n.innerHTML="",n.appendChild(e.cloneNode(!0)))}function he(n){n._headerRowEl=n.findHeaderRow();const e=n._headerRowEl;e&&(e.innerHTML="",n._visibleColumns.forEach((t,i)=>{const o=document.createElement("div");o.className="cell",Ue(o,"header-cell"),o.setAttribute("role","columnheader"),o.setAttribute("aria-colindex",String(i+1)),o.setAttribute("data-field",t.field),o.setAttribute("data-col",String(i));const r=t.__headerTemplate;if(r)Array.from(r.childNodes).forEach(s=>o.appendChild(s.cloneNode(!0)));else{const s=t.header??t.field,l=document.createElement("span");l.textContent=s,o.appendChild(l)}if(t.sortable){o.classList.add("sortable"),o.tabIndex=0;const s=document.createElement("span");Ue(s,"sort-indicator");const l=n._sortState?.field===t.field?n._sortState.direction:0,a={...q,...n.icons},c=l===1?a.sortAsc:l===-1?a.sortDesc:a.sortNone;zi(s,c),o.appendChild(s),o.setAttribute("aria-sort",l===0?"none":l===1?"ascending":"descending"),o.addEventListener("click",d=>{n._resizeController?.isResizing||n._dispatchHeaderClick?.(d,i,o)||lt(n,t)}),o.addEventListener("keydown",d=>{if(d.key==="Enter"||d.key===" "){if(d.preventDefault(),n._dispatchHeaderClick?.(d,i,o))return;lt(n,t)}})}if(t.resizable){o.classList.add("resizable");const s=document.createElement("div");s.className="resize-handle",s.setAttribute("aria-hidden","true"),s.addEventListener("mousedown",l=>{l.stopPropagation(),l.preventDefault(),n._resizeController.start(l,i,o)}),s.addEventListener("dblclick",l=>{l.stopPropagation(),l.preventDefault(),n._resizeController.resetColumn(i)}),o.appendChild(s)}e.appendChild(o)}),e.querySelectorAll(".cell.sortable").forEach(t=>{t.getAttribute("aria-sort")||t.setAttribute("aria-sort","none")}),e.children.length>0?(e.setAttribute("role","row"),e.setAttribute("aria-rowindex","1")):(e.removeAttribute("role"),e.removeAttribute("aria-rowindex")))}const ct=typeof requestIdleCallback=="function";function qi(n,e){return ct?requestIdleCallback(n,e):window.setTimeout(()=>{const t=Date.now();n({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})},1)}function dt(n){ct?cancelIdleCallback(n):clearTimeout(n)}var L=(n=>(n[n.STYLE=1]="STYLE",n[n.VIRTUALIZATION=2]="VIRTUALIZATION",n[n.HEADER=3]="HEADER",n[n.ROWS=4]="ROWS",n[n.COLUMNS=5]="COLUMNS",n[n.FULL=6]="FULL",n))(L||{});class Fi{#e;#n=0;#d=0;#c=null;#s=null;#i=null;#h=!1;constructor(e){this.#e=e}requestPhase(e,t){e>this.#n&&(this.#n=e),this.#d===0&&(this.#u(),this.#d=requestAnimationFrame(()=>this.#p()))}whenReady(){return this.#c?this.#c:Promise.resolve()}setInitialReadyResolver(e){this.#i=e}cancel(){this.#d!==0&&(cancelAnimationFrame(this.#d),this.#d=0),this.#n=0,this.#s&&(this.#s(),this.#s=null,this.#c=null)}get isPending(){return this.#n!==0}get pendingPhase(){return this.#n}#u(){this.#c||(this.#c=new Promise(e=>{this.#s=e}))}#p(){if(this.#d=0,!this.#e.isConnected()){this.#n=0,this.#s&&(this.#s(),this.#s=null,this.#c=null);return}const e=this.#n;this.#n=0,e>=5&&this.#e.mergeConfig(),e>=4&&this.#e.processRows(),e>=5&&(this.#e.processColumns(),this.#e.updateTemplate()),e>=3&&this.#e.renderHeader(),e>=2&&this.#e.renderVirtualWindow(),e>=1&&this.#e.afterRender(),!this.#h&&this.#i&&(this.#h=!0,this.#i()),this.#s&&(this.#s(),this.#s=null,this.#c=null)}}function ut(n){let e=null,t=null,i=null,o=null;const r=a=>{if(!e)return;const c=a.clientX-e.startX,d=Math.max(40,e.startWidth+c),u=n._visibleColumns[e.colIndex];u.width=d,u.__userResized=!0,u.__renderedWidth=d,t==null&&(t=requestAnimationFrame(()=>{t=null,n.updateTemplate?.()})),n.dispatchEvent(new CustomEvent("column-resize",{detail:{field:u.field,width:d}}))};let s=!1;const l=()=>{const a=e!==null;a&&(s=!0,requestAnimationFrame(()=>{s=!1})),window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",l),i!==null&&(document.documentElement.style.cursor=i,i=null),o!==null&&(document.body.style.userSelect=o,o=null),e=null,a&&n.requestStateChange&&n.requestStateChange()};return{get isResizing(){return e!==null||s},start(a,c,d){a.preventDefault();const u=n._visibleColumns[c],h=typeof u?.width=="number"?u.width:void 0,g=u?.__renderedWidth??h??d.getBoundingClientRect().width;e={startX:a.clientX,colIndex:c,startWidth:g},window.addEventListener("mousemove",r),window.addEventListener("mouseup",l),i===null&&(i=document.documentElement.style.cursor),document.documentElement.style.cursor="e-resize",o===null&&(o=document.body.style.userSelect),document.body.style.userSelect="none"},resetColumn(a){const c=n._visibleColumns[a];c&&(c.__userResized=!1,c.__renderedWidth=void 0,c.width=c.__originalWidth,n.updateTemplate?.(),n.requestStateChange?.(),n.dispatchEvent(new CustomEvent("column-resize-reset",{detail:{field:c.field,width:c.width}})))},dispose(){l()}}}function fe(n,e,t){const i=document.createElement(n);if(e)for(const o in e){const r=e[o];r!=null&&i.setAttribute(o,r)}return i}function H(n,e){const t=document.createElement("div");if(n&&(t.className=n),e)for(const i in e){const o=e[i];o!=null&&t.setAttribute(i,o)}return t}function ht(n,e,t){const i=document.createElement("button");if(n&&(i.className=n),e)for(const o in e){const r=e[o];r!=null&&i.setAttribute(o,r)}return i}const ft=document.createElement("template");ft.innerHTML=`
1
+ (function(C,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(C=typeof globalThis<"u"?globalThis:C||self,j(C.TbwGrid={}))})(this,(function(C){"use strict";const j='@layer tbw-base,tbw-plugins,tbw-theme;@layer tbw-base{:root{color-scheme:light dark}tbw-grid{--tbw-base-icon-size: 1em;--tbw-base-radius: .25em;--tbw-font-size: 1em;--tbw-font-size-sm: .9285em;--tbw-font-size-xs: .7857em;--tbw-font-size-2xs: .7142em;--tbw-spacing-xs: .25em;--tbw-spacing-sm: .375em;--tbw-spacing-md: .5em;--tbw-spacing-lg: .75em;--tbw-spacing-xl: 1em;--tbw-icon-size: var(--tbw-base-icon-size);--tbw-icon-size-sm: .875em;--tbw-checkbox-size: var(--tbw-base-icon-size);--tbw-toggle-size: 1.25em;--tbw-border-radius: var(--tbw-base-radius);--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-error: light-dark(hsl(0, 65%, 51%), hsl(0, 65%, 55%));--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, #666666);--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-header: var(--tbw-font-size);--tbw-font-weight-header: bold;--tbw-cell-padding-header: var(--tbw-spacing-xs) var(--tbw-spacing-md);--tbw-cell-padding: var(--tbw-spacing-xs) var(--tbw-spacing-md);--tbw-cell-padding-input: var(--tbw-spacing-xs) var(--tbw-spacing-sm);--tbw-row-height: 1.75em;--tbw-header-height: 1.875em;--tbw-cell-white-space: nowrap;--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: var(--tbw-spacing-sm);--tbw-resize-handle-color: transparent;--tbw-resize-handle-color-hover: var(--tbw-color-accent);--tbw-resize-handle-border-radius: 0;--tbw-resize-indicator-width: 2px;--tbw-resize-indicator-color: var(--tbw-color-accent);--tbw-resize-indicator-opacity: .6;--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-row-change-duration: .5s;--tbw-row-insert-duration: .3s;--tbw-row-remove-duration: .2s;--tbw-row-change-color: rgba(from var(--tbw-color-accent) r g b / 25%);--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-density-scale: 1;--tbw-shell-header-height: 2.75em;--tbw-shell-header-bg: var(--tbw-color-panel-bg);--tbw-shell-header-border: var(--tbw-color-border);--tbw-shell-title-font-size: var(--tbw-font-size);--tbw-shell-title-font-weight: 600;--tbw-tool-panel-width: 17.5em;--tbw-tool-panel-bg: var(--tbw-color-panel-bg);--tbw-tool-panel-border: var(--tbw-color-border);--tbw-tool-panel-header-height: 2.5em;--tbw-tool-panel-transition: var(--tbw-animation-duration) var(--tbw-animation-easing);--tbw-toolbar-button-size: 2em;--tbw-toolbar-button-gap: var(--tbw-spacing-xs);--tbw-panel-padding: var(--tbw-spacing-lg);--tbw-panel-gap: var(--tbw-spacing-md);--tbw-menu-item-padding: var(--tbw-spacing-sm) var(--tbw-spacing-lg);--tbw-menu-item-gap: var(--tbw-spacing-md);--tbw-menu-min-width: 10rem;--tbw-button-padding: var(--tbw-spacing-sm) var(--tbw-spacing-lg);--tbw-button-padding-sm: var(--tbw-spacing-xs) var(--tbw-spacing-md);--tbw-input-height: var(--tbw-row-height);--tbw-input-padding: 0 var(--tbw-spacing-md);--tbw-detail-padding: var(--tbw-spacing-xl);--tbw-detail-max-height: 31.25rem;--tbw-indicator-size: var(--tbw-spacing-sm);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}tbw-grid,tbw-grid *{box-sizing:border-box}tbw-grid .header{display:block;flex-shrink:0;z-index:var(--tbw-z-layer-header, 30);background:var(--tbw-color-header-bg);overflow:visible}tbw-grid .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)}tbw-grid .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))}tbw-grid .header-group-cell:not(:last-child){border-right:2px solid var(--tbw-color-border)}tbw-grid .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)}tbw-grid .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:visible;min-width:0}tbw-grid .header-row>.cell>span:first-child{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}tbw-grid .header-row>.cell>span[part~=sort-indicator]{flex-shrink:0;opacity:.6}tbw-grid .header-row>.cell:last-child{border-right:0}tbw-grid .header-row>.cell.grouped.group-end:not(:last-child){border-right:2px solid var(--tbw-color-border)}tbw-grid .header-row>.cell.resizable{position:relative}tbw-grid .header-row>.cell.sticky-left,tbw-grid .header-row>.cell.sticky-right{background:var(--tbw-color-header-bg);z-index:35}tbw-grid .tbw-grid-root{display:flex;flex-direction:column;height:100%}tbw-grid .tbw-grid-root.has-shell{display:flex;flex-direction:column;height:100%}tbw-grid .rows-body-wrapper{flex:1;min-height:0;display:flex;flex-direction:row;width:100%;min-width:fit-content}tbw-grid .rows-body{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow:visible}tbw-grid .rows-container{display:flex;flex-direction:row;flex:1;min-height:0;overflow:visible}tbw-grid .rows-viewport{flex:1;min-width:0;position:relative;display:block;overflow:clip}tbw-grid .rows-viewport .rows{position:absolute;top:0;left:0;min-width:100%;will-change:transform;z-index:var(--tbw-z-layer-rows, 1)}tbw-grid .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)}tbw-grid .faux-vscroll-spacer{width:1px}tbw-grid .data-grid-row{display:grid;grid-template-columns:var(--tbw-column-template);contain:layout style;content-visibility:auto;contain-intrinsic-size:auto var(--tbw-row-height)}tbw-grid .data-grid-row:nth-child(2n){background:var(--tbw-color-row-alt)}tbw-grid .data-grid-row:hover{background:var(--tbw-color-row-hover)}tbw-grid .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}tbw-grid .data-grid-row>.cell>*{overflow:hidden;text-overflow:ellipsis;white-space:inherit;min-width:0}tbw-grid .data-grid-row>.cell:last-child{border-right:0}tbw-grid .data-grid-row>.cell[data-type=boolean]{text-align:center}tbw-grid .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}tbw-grid .data-grid-row>.cell.selected:focus-visible,tbw-grid .data-grid-row>.cell:focus-visible:not(.cell-focus){outline:none}tbw-grid .data-grid-row>.cell.sticky-left,tbw-grid .data-grid-row>.cell.sticky-right{background:var(--tbw-color-panel-bg)}tbw-grid .selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}tbw-grid .sortable{cursor:pointer;-webkit-user-select:none;user-select:none}tbw-grid .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)}tbw-grid .resize-handle:after{content:"";position:absolute;top:100%;left:50%;transform:translate(-50%);width:var(--tbw-resize-indicator-width, 2px);height:0;background:var(--tbw-resize-indicator-color, var(--tbw-color-accent));opacity:0;pointer-events:none;transition:opacity .12s ease,height 0s .12s;z-index:1000}tbw-grid .resize-handle:hover{background:var(--tbw-resize-handle-color-hover)}tbw-grid .resize-handle:hover:after{height:100vh;opacity:var(--tbw-resize-indicator-opacity, .6);transition:opacity .12s ease,height 0s}tbw-grid[data-has-focus] .cell-focus,tbw-grid[data-has-focus] .row-focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}tbw-grid .sticky-left,tbw-grid .sticky-right{position:sticky;z-index:25}tbw-grid .sticky-left{box-shadow:1px 0 0 var(--tbw-color-border)}tbw-grid .sticky-right{box-shadow:-1px 0 0 var(--tbw-color-border)}tbw-grid .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}tbw-grid .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}tbw-grid .tbw-shell-content{flex:1;display:flex;align-items:center;gap:12px;min-width:0;overflow:hidden}tbw-grid .tbw-shell-toolbar{display:flex;align-items:center;gap:var(--tbw-toolbar-button-gap);flex-shrink:0}tbw-grid .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)}tbw-grid .tbw-toolbar-btn:hover{background:var(--tbw-color-row-hover)}tbw-grid .tbw-toolbar-btn:focus-visible{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}tbw-grid .tbw-toolbar-btn.active{background:var(--tbw-focus-background);border-color:var(--tbw-color-accent)}tbw-grid .tbw-toolbar-btn:disabled{opacity:.5;cursor:not-allowed}tbw-grid .tbw-toolbar-separator{width:1px;height:20px;background:var(--tbw-color-border);margin:0 4px}tbw-grid .tbw-shell-body{position:relative;display:flex;flex:1;min-height:0;overflow:visible}tbw-grid .tbw-grid-content{flex:1;min-width:0;min-height:0;display:flex;flex-direction:row;overflow:hidden}tbw-grid .tbw-scroll-area{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow-x:auto;overflow-y:hidden;overflow-anchor:none}tbw-grid .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)}tbw-grid .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)}tbw-grid .tbw-tool-panel.open{width:var(--tbw-tool-panel-width)}tbw-grid .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)}tbw-grid .tbw-tool-panel-resize[data-handle-position=left]{left:0}tbw-grid .tbw-tool-panel-resize[data-handle-position=right]{right:0}tbw-grid .tbw-tool-panel-resize:hover,tbw-grid .tbw-tool-panel-resize.resizing{background:var(--tbw-color-accent)}tbw-grid .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}tbw-grid .tbw-tool-panel-title{font-weight:600;font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}tbw-grid .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}tbw-grid .tbw-tool-panel-close:hover{background:var(--tbw-color-row-hover);color:var(--tbw-color-fg)}tbw-grid .tbw-tool-panel-content{flex:1;overflow:auto}tbw-grid .tbw-accordion{display:flex;flex-direction:column;gap:0}tbw-grid .tbw-accordion-section{border-bottom:1px solid var(--tbw-tool-panel-border)}tbw-grid .tbw-accordion-section:last-child{border-bottom:none}tbw-grid .tbw-accordion-section.single .tbw-accordion-header{cursor:default}tbw-grid .tbw-accordion-section.single .tbw-accordion-header:hover{background:transparent}tbw-grid .tbw-accordion-section.expanded .tbw-accordion-chevron{transform:rotate(90deg)}tbw-grid .tbw-accordion-section.expanded .tbw-accordion-content{display:block}tbw-grid .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}tbw-grid .tbw-accordion-header:hover{background:var(--tbw-color-row-hover)}tbw-grid .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}tbw-grid .tbw-accordion-icon{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:14px;flex-shrink:0}tbw-grid .tbw-accordion-title{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}tbw-grid .tbw-accordion-content{display:none}tbw-grid .tbw-expanding{animation:tbw-expand var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}tbw-grid .tbw-collapsing{animation:tbw-collapse var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}tbw-grid[data-animation-mode=off]{--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms}tbw-grid[data-animation-mode=off] .data-grid-row[data-animating]{animation:none}@media(forced-colors:active){tbw-grid{--tbw-color-border: CanvasText;--tbw-color-border-strong: CanvasText;--tbw-color-border-cell: CanvasText;--tbw-color-border-header: CanvasText;--tbw-color-fg: CanvasText;--tbw-color-bg: Canvas;--tbw-color-panel-bg: Canvas;--tbw-color-header-bg: Canvas;--tbw-color-header-fg: CanvasText;--tbw-color-accent: Highlight;--tbw-color-accent-fg: HighlightText;--tbw-color-selection: Highlight;--tbw-color-row-hover: Highlight;--tbw-focus-outline: 2px solid Highlight;--tbw-range-border-color: Highlight}tbw-grid .cell:focus,tbw-grid .cell.active-cell{outline:2px solid Highlight!important;outline-offset:-2px}tbw-grid .data-grid-row[aria-selected=true]{background:Highlight!important;color:HighlightText!important}}@media(prefers-reduced-motion:reduce){tbw-grid[data-animation-mode=reduced-motion]{--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms}tbw-grid[data-animation-mode=reduced-motion] .data-grid-row[data-animating]{animation:none}}@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)}}@keyframes tbw-row-change{0%{background-color:transparent}20%{background-color:var(--tbw-row-change-color)}to{background-color:transparent}}@keyframes tbw-row-insert{0%{opacity:0;max-height:0;overflow:hidden}to{opacity:1;max-height:var(--tbw-row-height, 28px);overflow:hidden}}@keyframes tbw-row-remove{0%{opacity:1;transform:translateY(0);max-height:var(--tbw-row-height, 28px)}to{opacity:0;max-height:0;transform:translateY(-8px)}}tbw-grid .data-grid-row[data-animating=change]{animation:tbw-row-change var(--tbw-row-change-duration) ease-out}tbw-grid .data-grid-row[data-animating=insert]{animation:tbw-row-insert var(--tbw-row-insert-duration) ease-out;will-change:max-height,opacity}tbw-grid .data-grid-row[data-animating=remove]{animation:tbw-row-remove var(--tbw-row-remove-duration) ease-out forwards;will-change:max-height,opacity,transform;pointer-events:none}}',Y={STRETCH:"stretch",FIXED:"fixed"},Ue={mode:"reduced-motion",duration:200,easing:"ease-out"},F={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰"};function pi(o){return Array.from(o.querySelectorAll("tbw-grid-column")).map(t=>{const i=t.getAttribute("field")||"";if(!i)return null;const n=t.getAttribute("type")||void 0,s=n&&new Set(["number","string","date","boolean","select"]).has(n)?n:void 0,l=t.getAttribute("header")||void 0,a=t.hasAttribute("sortable"),c=t.hasAttribute("editable"),d={field:i,type:s,header:l,sortable:a,editable:c},u=t.getAttribute("width");if(u){const v=parseFloat(u);!isNaN(v)&&/^\d+(\.\d+)?$/.test(u.trim())?d.width=v:d.width=u}const h=t.getAttribute("minWidth")||t.getAttribute("min-width");if(h){const v=parseFloat(h);isNaN(v)||(d.minWidth=v)}t.hasAttribute("resizable")&&(d.resizable=!0),t.hasAttribute("sizable")&&(d.resizable=!0);const f=t.getAttribute("editor"),p=t.getAttribute("renderer");f&&(d.__editorName=f),p&&(d.__rendererName=p);const g=t.getAttribute("options");g&&(d.options=g.split(",").map(v=>{const[k,S]=v.includes(":")?v.split(":"):[v.trim(),v.trim()];return{value:k.trim(),label:S?.trim()||k.trim()}}));const w=t.querySelector("tbw-grid-column-view"),m=t.querySelector("tbw-grid-column-editor"),y=t.querySelector("tbw-grid-column-header");w&&(d.__viewTemplate=w),m&&(d.__editorTemplate=m),y&&(d.__headerTemplate=y);const _=globalThis.DataGridElement?.getAdapters?.()??[],x=w??t,A=_.find(v=>v.canHandle(x));if(A){const v=A.createRenderer(x);v&&(d.viewRenderer=v)}const T=m??t,E=_.find(v=>v.canHandle(T));if(E){const v=E.createEditor(T);v&&(d.editor=v)}return d}).filter(t=>!!t)}function je(o,e){if((!o||!o.length)&&(!e||!e.length))return[];if(!o||!o.length)return e||[];if(!e||!e.length)return o;const t={};e.forEach(n=>{const r=t[n.field];if(r){n.header&&!r.header&&(r.header=n.header),n.type&&!r.type&&(r.type=n.type),n.sortable&&(r.sortable=!0),n.editable&&(r.editable=!0),n.resizable&&(r.resizable=!0),n.width!=null&&r.width==null&&(r.width=n.width),n.minWidth!=null&&r.minWidth==null&&(r.minWidth=n.minWidth),n.__viewTemplate&&(r.__viewTemplate=n.__viewTemplate),n.__editorTemplate&&(r.__editorTemplate=n.__editorTemplate),n.__headerTemplate&&(r.__headerTemplate=n.__headerTemplate);const s=n.renderer||n.viewRenderer,l=r.renderer||r.viewRenderer;s&&!l&&(r.viewRenderer=s,n.renderer&&(r.renderer=s)),n.editor&&!r.editor&&(r.editor=n.editor)}else t[n.field]={...n}});const i=o.map(n=>{const r=t[n.field];if(!r)return n;const s={...n};r.header&&!s.header&&(s.header=r.header),r.type&&!s.type&&(s.type=r.type),s.sortable=n.sortable||r.sortable,(n.resizable===!0||r.resizable===!0)&&(s.resizable=!0),s.editable=n.editable||r.editable,r.width!=null&&s.width==null&&(s.width=r.width),r.minWidth!=null&&s.minWidth==null&&(s.minWidth=r.minWidth),r.__viewTemplate&&(s.__viewTemplate=r.__viewTemplate),r.__editorTemplate&&(s.__editorTemplate=r.__editorTemplate),r.__headerTemplate&&(s.__headerTemplate=r.__headerTemplate);const l=r.renderer||r.viewRenderer,a=s.renderer||s.viewRenderer;return l&&!a&&(s.viewRenderer=l,r.renderer&&(s.renderer=l)),r.editor&&!s.editor&&(s.editor=r.editor),delete t[n.field],s});return Object.keys(t).forEach(n=>i.push(t[n])),i}function Ye(o,e){try{o.part?.add?.(e)}catch{}const t=o.getAttribute("part");t?t.split(/\s+/).includes(e)||o.setAttribute("part",t+" "+e):o.setAttribute("part",e)}function Xe(o){const e=o.effectiveConfig?.fitMode||o.fitMode||Y.STRETCH;if(e!==Y.STRETCH&&e!==Y.FIXED||o.__didInitialAutoSize||!o.isConnected)return;const t=Array.from(o._headerRowEl?.children||[]);if(!t.length)return;let i=!1;o._visibleColumns.forEach((n,r)=>{if(n.width)return;const s=t[r];let l=s?s.scrollWidth:0;for(const a of o._rowPool){const c=a.children[r];if(c){const d=c.scrollWidth;d>l&&(l=d)}}l>0&&(n.width=l+2,n.__autoSized=!0,i=!0)}),i&&te(o),o.__didInitialAutoSize=!0}function te(o){(o.effectiveConfig?.fitMode||o.fitMode||Y.STRETCH)===Y.STRETCH?o._gridTemplate=o._visibleColumns.map(t=>{if(t.width)return`${t.width}px`;const i=t.minWidth;return i!=null?`minmax(${i}px, 1fr)`:"1fr"}).join(" ").trim():o._gridTemplate=o._visibleColumns.map(t=>t.width?`${t.width}px`:"max-content").join(" "),o.style.setProperty("--tbw-column-template",o._gridTemplate)}function wi(o){return o==null?"string":typeof o=="number"?"number":typeof o=="boolean"?"boolean":o instanceof Date||typeof o=="string"&&/\d{4}-\d{2}-\d{2}/.test(o)&&!isNaN(Date.parse(o))?"date":"string"}function mi(o,e){const t=o[0]||{},i=Object.keys(t).map(r=>{const s=t[r],l=wi(s);return{field:r,header:r.charAt(0).toUpperCase()+r.slice(1),type:l}}),n={};return i.forEach(r=>{n[r.field]=r.type||"string"}),{columns:i,typeMap:n}}const bi=/{{\s*([^}]+)\s*}}/g,z="__DG_EMPTY__",vi=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,yi=/__(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/;function Ci(o){return!o||typeof o!="string"?"":o.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}const xi=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"]),Ze=/^on\w+$/i,Ri=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),Ei=/^\s*(javascript|vbscript|data|blob):/i;function ie(o){if(!o||typeof o!="string")return"";if(o.indexOf("<")===-1)return o;const e=document.createElement("template");return e.innerHTML=o,Si(e.content),e.innerHTML}function Si(o){const e=[],t=o.querySelectorAll("*");for(const i of t){const n=i.tagName.toLowerCase();if(xi.has(n)){e.push(i);continue}if((n==="svg"||i.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(i.attributes).some(l=>Ze.test(l.name)||l.name==="href"||l.name==="xlink:href")){e.push(i);continue}const r=[];for(const s of i.attributes){const l=s.name.toLowerCase();if(Ze.test(l)){r.push(s.name);continue}if(Ri.has(l)&&Ei.test(s.value)){r.push(s.name);continue}if(l==="style"&&/expression\s*\(|javascript:|behavior\s*:/i.test(s.value)){r.push(s.name);continue}}r.forEach(s=>i.removeAttribute(s))}e.forEach(i=>i.remove())}function we(o,e){if(!o||o.indexOf("{{")===-1)return o;const t=[],i=o.replace(bi,(l,a)=>{const c=_i(a,e);return t.push({expr:a.trim(),result:c}),c}),n=Ai(i),r=t.length&&t.every(l=>l.result===""||l.result===z);return/Reflect\.|\bProxy\b|ownKeys\(/.test(o)||r?"":n}function _i(o,e){if(o=(o||"").trim(),!o||/\b(Reflect|Proxy|ownKeys)\b/.test(o))return z;if(o==="value")return e.value==null?z:String(e.value);if(o.startsWith("row.")&&!/[()?]/.test(o)&&!o.includes(":")){const i=o.slice(4),n=e.row?e.row[i]:void 0;return n==null?z:String(n)}if(o.length>80||!vi.test(o)||yi.test(o))return z;const t=o.match(/\./g);if(t&&t.length>1)return z;try{const n=new Function("value","row",`return (${o});`)(e.value,e.row),r=n==null?"":String(n);return/Reflect|Proxy|ownKeys/.test(r)?z:r||z}catch{return z}}function Ai(o){return o&&o.replace(new RegExp(z,"g"),"").replace(/Reflect\.[^<>{}\s]+/g,"").replace(/\bProxy\b/g,"").replace(/ownKeys\([^)]*\)/g,"")}function Ti(o){if(/Reflect|Proxy|ownKeys/.test(o.textContent||"")){if(Array.from(o.childNodes).forEach(e=>{e.nodeType===Node.TEXT_NODE&&/Reflect|Proxy|ownKeys/.test(e.textContent||"")&&(e.textContent="")}),/Reflect|Proxy|ownKeys/.test(o.textContent||"")){if(/Reflect|Proxy|ownKeys/.test(o.textContent||""))for(;o.firstChild;)o.removeChild(o.firstChild);o.textContent=(o.textContent||"").replace(/Reflect|Proxy|ownKeys/g,"")}(o.textContent||"").trim().length===0&&(o.textContent="")}}function Je(o){const e=/Reflect\.|\bProxy\b|ownKeys\(/.test(o),t=(i=>e?"":we(o,i));return t.__blocked=e,t}const ki=100;class Pi{#e;#o;#d;#c;#s;#i={};#h={};#u=!0;#p=[];#l;#w;#m;#a;#b;constructor(e){this.#a=e}get original(){return this.#i}get effective(){return this.#h}get columns(){return this.#h.columns??[]}set columns(e){this.#h.columns=e}get lightDomColumnsCache(){return this.#c}set lightDomColumnsCache(e){this.#c=e}get originalColumnNodes(){return this.#s}set originalColumnNodes(e){this.#s=e}get lightDomTitle(){return this.#b}set lightDomTitle(e){this.#b=e}get initialColumnState(){return this.#m}set initialColumnState(e){this.#m=e}get sourcesChanged(){return this.#u}markSourcesChanged(){this.#u=!0}setGridConfig(e){this.#e=e,this.#u=!0,this.#c=void 0}getGridConfig(){return this.#e}setColumns(e){this.#o=e,this.#u=!0}getColumns(){return this.#o}setFitMode(e){this.#d=e,this.#u=!0}getFitMode(){return this.#d}merge(){const e=(this.#h.columns?.length??0)>0;if(!this.#u&&e)return;const t=this.#y();this.#u=!1,this.#i=t,Object.freeze(this.#i),this.#i.columns&&Object.freeze(this.#i.columns),this.#h=this.#v(this.#i),this.#g()}#v(e){const t={...e};return e.columns&&(t.columns=e.columns.map(i=>({...i}))),e.shell&&(t.shell={...e.shell,header:e.shell.header?{...e.shell.header}:void 0,toolPanel:e.shell.toolPanel?{...e.shell.toolPanel}:void 0,toolPanels:e.shell.toolPanels?.map(i=>({...i})),headerContents:e.shell.headerContents?.map(i=>({...i}))}),t}#g(){const e=this.#h;e.rowHeight&&e.rowHeight>0&&this.#a.setRowHeight(e.rowHeight),e.fitMode==="fixed"&&this.columns.forEach(i=>{i.width==null&&(i.width=80)}),this.#a.applyAnimationConfig(e)}#y(){const e=this.#e?{...this.#e}:{},t=Array.isArray(e.columns)?[...e.columns]:[],i=(this.#c??[]).map(s=>({...s}));let n=je(t,i);this.#o&&this.#o.length&&(n=je(this.#o,i));const r=this.#a.getRows();return n.length===0&&r.length&&(n=mi(r).columns),n.length&&(n.forEach(s=>{s.sortable===void 0&&(s.sortable=!0),s.resizable===void 0&&(s.resizable=!0),s.__originalWidth===void 0&&typeof s.width=="number"&&(s.__originalWidth=s.width)}),n.forEach(s=>{s.__viewTemplate&&!s.__compiledView&&(s.__compiledView=Je(s.__viewTemplate.innerHTML)),s.__editorTemplate&&!s.__compiledEditor&&(s.__compiledEditor=Je(s.__editorTemplate.innerHTML))}),e.columns=n),this.#d&&(e.fitMode=this.#d),e.fitMode||(e.fitMode="stretch"),this.#x(e),e.columnState&&!this.#m&&(this.#m=e.columnState),e}#x(e){e.shell=e.shell?{...e.shell}:{},e.shell.header=e.shell.header?{...e.shell.header}:{};const t=this.#a.getShellLightDomTitle();t&&(this.#b=t),this.#b&&!e.shell.header.title&&(e.shell.header.title=this.#b);const i=this.#a.getShellLightDomHeaderContent();i?.length>0&&(e.shell.header.lightDomContent=i),this.#a.getShellHasToolButtonsContainer()&&(e.shell.header.hasToolButtonsContainer=!0);const n=this.#a.getShellToolPanels();if(n.size>0){const u=Array.from(n.values());u.sort((h,f)=>(h.order??100)-(f.order??100)),e.shell.toolPanels=u}const r=this.#a.getShellHeaderContents();if(r.size>0){const u=Array.from(r.values());u.sort((h,f)=>(h.order??100)-(f.order??100)),e.shell.headerContents=u}const s=this.#a.getShellToolbarContents(),l=Array.from(s.values()),a=this.#e?.shell?.header?.toolbarContents??[],c=new Set(a.map(u=>u.id)),d=[...a];for(const u of l)c.has(u.id)||d.push(u);d.sort((u,h)=>(u.order??0)-(h.order??0)),e.shell.header.toolbarContents=d}collectState(e){const t=this.columns,i=this.#C();return{columns:t.map((n,r)=>{const s={field:n.field,order:r,visible:!n.hidden},l=n;l.__renderedWidth!==void 0?s.width=l.__renderedWidth:n.width!==void 0&&(s.width=typeof n.width=="string"?parseFloat(n.width):n.width);const a=i.get(n.field);a&&(s.sort=a);for(const c of e)if(c.getColumnState){const d=c.getColumnState(n.field);d&&Object.assign(s,d)}return s})}}applyState(e,t){if(!e.columns||e.columns.length===0)return;const i=this.columns,n=new Map(e.columns.map(l=>[l.field,l])),r=i.map(l=>{const a=n.get(l.field);if(!a)return l;const c={...l};return a.width!==void 0&&(c.width=a.width,c.__renderedWidth=a.width),a.visible!==void 0&&(c.hidden=!a.visible),c});r.sort((l,a)=>{const c=n.get(l.field)?.order??1/0,d=n.get(a.field)?.order??1/0;return c-d}),this.columns=r;const s=e.columns.filter(l=>l.sort!==void 0).sort((l,a)=>(l.sort?.priority??0)-(a.sort?.priority??0));if(s.length>0){const l=s[0];l.sort&&this.#a.setSortState({field:l.field,direction:l.sort.direction==="asc"?1:-1})}else this.#a.setSortState(null);for(const l of t)if(l.applyColumnState)for(const a of e.columns)l.applyColumnState(a.field,a)}resetState(e){this.#m=void 0,this.#a.setSortState(null),this.#h=this.#v(this.#i),this.#g();for(const t of e)if(t.applyColumnState)for(const i of this.columns)t.applyColumnState(i.field,{field:i.field,order:0,visible:!0});this.requestStateChange(e)}#C(){const e=new Map,t=this.#a.getSortState();return t&&e.set(t.field,{direction:t.direction===1?"asc":"desc",priority:0}),e}requestStateChange(e){this.#w&&clearTimeout(this.#w),this.#w=setTimeout(()=>{this.#w=void 0;const t=this.collectState(e);this.#a.emit("column-state-change",t)},ki)}setColumnVisible(e,t){const i=this.columns,n=i.find(s=>s.field===e);return!n||!t&&n.lockVisible||!t&&i.filter(l=>!l.hidden&&l.field!==e).length===0||!!n.hidden===!t?!1:(n.hidden=!t,this.#a.emit("column-visibility",{field:e,visible:t,visibleColumns:i.filter(s=>!s.hidden).map(s=>s.field)}),this.#a.clearRowPool(),this.#a.setup(),!0)}toggleColumnVisibility(e){const t=this.columns.find(i=>i.field===e);return t?this.setColumnVisible(e,!!t.hidden):!1}isColumnVisible(e){const t=this.columns.find(i=>i.field===e);return t?!t.hidden:!1}showAllColumns(){const e=this.columns;e.some(t=>t.hidden)&&(e.forEach(t=>t.hidden=!1),this.#a.emit("column-visibility",{visibleColumns:e.map(t=>t.field)}),this.#a.clearRowPool(),this.#a.setup())}getAllColumns(){return this.columns.map(e=>({field:e.field,header:e.header||e.field,visible:!e.hidden,lockVisible:e.lockVisible,utility:e.meta?.utility===!0}))}getColumnOrder(){return this.columns.map(e=>e.field)}setColumnOrder(e){if(!e.length)return;const t=new Map(this.columns.map(n=>[n.field,n])),i=[];for(const n of e){const r=t.get(n);r&&(i.push(r),t.delete(n))}for(const n of t.values())i.push(n);this.columns=i,this.#a.renderHeader(),this.#a.updateTemplate(),this.#a.refreshVirtualWindow()}parseLightDomColumns(e){this.#c||(this.#s=Array.from(e.querySelectorAll("tbw-grid-column")),this.#c=this.#s.length?pi(e):[])}clearLightDomCache(){this.#c=void 0}#R=new Map;registerLightDomHandler(e,t){this.#R.set(e.toLowerCase(),t)}unregisterLightDomHandler(e){this.#R.delete(e.toLowerCase())}observeLightDOM(e){this.#l&&this.#l.disconnect();const t=new Set;let i=null;const n=()=>{i=null;for(const r of t)this.#R.get(r)?.();t.clear()};this.#l=new MutationObserver(r=>{for(const s of r){for(const l of s.addedNodes){if(l.nodeType!==Node.ELEMENT_NODE)continue;const c=l.tagName.toLowerCase();this.#R.has(c)&&t.add(c)}if(s.type==="attributes"&&s.target.nodeType===Node.ELEMENT_NODE){const a=s.target.tagName.toLowerCase();this.#R.has(a)&&t.add(a)}}t.size>0&&!i&&(i=setTimeout(n,0))}),this.#l.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["title","field","header","width","hidden","id","icon","tooltip","order"]})}onChange(e){this.#p.push(e)}notifyChange(){for(const e of this.#p)e()}dispose(){this.#l?.disconnect(),this.#p=[],this.#w&&clearTimeout(this.#w)}}function Qe(o){return`<span role="checkbox" aria-checked="${o}" aria-label="${o}">${o?"&#x1F5F9;":"&#9744;"}</span>`}function et(o){if(o==null||o==="")return"";if(o instanceof Date)return isNaN(o.getTime())?"":o.toLocaleDateString();if(typeof o=="number"||typeof o=="string"){const e=new Date(o);return isNaN(e.getTime())?"":e.toLocaleDateString()}return""}function me(o){if(!o)return-1;const e=o.getAttribute("data-row");if(e)return parseInt(e,10);const t=o.closest(".data-grid-row");if(!t)return-1;const i=t.parentElement;if(!i)return-1;const n=i.querySelectorAll(":scope > .data-grid-row");for(let r=0;r<n.length;r++)if(n[r]===t)return r;return-1}function Li(o){if(!o)return-1;const e=o.getAttribute("data-col");return e?parseInt(e,10):-1}function oe(o){o&&o.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function tt(o,e){const t=e.renderer||e.viewRenderer;if(t)return t;if(!e.type)return;const i=o.effectiveConfig?.typeDefaults;if(i?.[e.type]?.renderer)return i[e.type].renderer;const n=o.__frameworkAdapter;if(n?.getTypeDefault){const r=n.getTypeDefault(e.type);if(r?.renderer)return r.renderer}}const it='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function be(o){return(o.__editingCellCount??0)>0}function ve(o){o.__editingCellCount=0,o.removeAttribute("data-has-editing"),o.querySelectorAll(".cell.editing").forEach(t=>t.classList.remove("editing"))}const ot=document.createElement("template");ot.innerHTML='<div class="cell" role="gridcell" part="cell"></div>';const nt=document.createElement("template");nt.innerHTML='<div class="data-grid-row" role="row" part="row"></div>';function Di(){return ot.content.firstElementChild.cloneNode(!0)}function Hi(){return nt.content.firstElementChild.cloneNode(!0)}function de(o){o.__cellDisplayCache=void 0,o.__cellCacheEpoch=void 0,o.__hasSpecialColumns=void 0}function Ii(o,e,t,i,n){const r=Math.max(0,t-e),s=o._bodyEl,l=o._visibleColumns,a=l.length;let c=o.__cachedHeaderRowCount;for(c===void 0&&(c=o.querySelector(".header-group-row")?2:1,o.__cachedHeaderRowCount=c);o._rowPool.length<r;){const h=Hi();o._rowPool.push(h)}if(o._rowPool.length>r){for(let h=r;h<o._rowPool.length;h++){const f=o._rowPool[h];f.parentNode===s&&f.remove()}o._rowPool.length=r}const d=n&&o.__hasRenderRowPlugins!==!1,u=o._hasAfterRowRenderHook?.()??!1;for(let h=0;h<r;h++){const f=e+h,p=o._rows[f],g=o._rowPool[h];if(g.setAttribute("aria-rowindex",String(f+c+1)),d&&n(p,g,f)){g.__epoch=i,g.__rowDataRef=p,g.parentNode!==s&&s.appendChild(g);continue}const w=g.__epoch,m=g.__rowDataRef,y=g.children.length,_=w===i&&y===a,x=m!==p;let A=!1;if(_&&x){for(let S=0;S<a;S++)if(l[S].externalView&&!g.querySelector(`.cell[data-col="${S}"] [data-external-view]`)){A=!0;break}}if(!_||A){const S=be(g),R=o._activeEditRows===f;S&&!R?(g.__isCustomRow&&(g.className="data-grid-row",g.setAttribute("role","row"),g.__isCustomRow=!1),ve(g),ne(o,g,p,f),g.__epoch=i,g.__rowDataRef=p):S&&R?(ye(o,g,p,f),g.__rowDataRef=p):(g.__isCustomRow&&(g.className="data-grid-row",g.setAttribute("role","row"),g.__isCustomRow=!1),ne(o,g,p,f),g.__epoch=i,g.__rowDataRef=p)}else if(x){const S=be(g),R=o._activeEditRows===f;S&&!R?(ve(g),ne(o,g,p,f),g.__epoch=i,g.__rowDataRef=p):(ye(o,g,p,f),g.__rowDataRef=p)}else{const S=be(g),R=o._activeEditRows===f;S&&!R?(ve(g),ne(o,g,p,f),g.__epoch=i,g.__rowDataRef=p):ye(o,g,p,f)}let T=!1;const E=o.changedRowIds;if(E&&E.length>0)try{const S=o.getRowId?.(p);S&&(T=E.includes(S))}catch{}const v=g.classList.contains("changed");T!==v&&g.classList.toggle("changed",T);const k=o.effectiveConfig?.rowClass;if(k){const S=g.getAttribute("data-dynamic-classes");S&&S.split(" ").forEach(R=>R&&g.classList.remove(R));try{const R=k(p);if(R&&R.length>0){const P=R.filter(O=>O&&typeof O=="string");P.forEach(O=>g.classList.add(O)),g.setAttribute("data-dynamic-classes",P.join(" "))}else g.removeAttribute("data-dynamic-classes")}catch(R){console.warn("[tbw-grid] rowClass callback error:",R),g.removeAttribute("data-dynamic-classes")}}u&&o._afterRowRender?.({row:p,rowIndex:f,rowElement:g}),g.parentNode!==s&&s.appendChild(g)}}function ye(o,e,t,i){const n=e.children,r=o._visibleColumns,s=r.length,l=n.length,a=s<l?s:l,c=o._focusRow,d=o._focusCol,u=o._hasAfterCellRenderHook?.()??!1;let h=o.__hasSpecialColumns;if(h===void 0){h=!1;const p=o.effectiveConfig?.typeDefaults,g=o.__frameworkAdapter;for(let w=0;w<s;w++){const m=r[w];if(m.__viewTemplate||m.__compiledView||m.renderer||m.viewRenderer||m.externalView||m.format||m.type==="date"||m.type==="boolean"||m.type&&p?.[m.type]?.renderer||m.type&&g?.getTypeDefault?.(m.type)?.renderer){h=!0;break}}o.__hasSpecialColumns=h}const f=String(i);if(!h){for(let p=0;p<a;p++){const g=n[p];if(g.classList.contains("editing"))continue;const w=r[p],m=t[w.field];g.textContent=m==null?"":String(m),g.getAttribute("data-row")!==f&&g.setAttribute("data-row",f);const y=c===i&&d===p,b=g.classList.contains("cell-focus");y!==b&&(g.classList.toggle("cell-focus",y),g.setAttribute("aria-selected",String(y))),u&&o._afterCellRender?.({row:t,rowIndex:i,column:w,colIndex:p,value:m,cellElement:g,rowElement:e})}return}for(let p=0;p<a;p++)if(r[p].externalView&&!n[p].querySelector("[data-external-view]")){ne(o,e,t,i);return}for(let p=0;p<a;p++){const g=r[p],w=n[p];w.getAttribute("data-row")!==f&&w.setAttribute("data-row",f);const m=c===i&&d===p,y=w.classList.contains("cell-focus");m!==y&&(w.classList.toggle("cell-focus",m),w.setAttribute("aria-selected",String(m)));const b=g.cellClass;if(b){const T=w.getAttribute("data-dynamic-classes");T&&T.split(" ").forEach(E=>E&&w.classList.remove(E));try{const E=t[g.field],v=b(E,t,g);if(v&&v.length>0){const k=v.filter(S=>S&&typeof S=="string");k.forEach(S=>w.classList.add(S)),w.setAttribute("data-dynamic-classes",k.join(" "))}else w.removeAttribute("data-dynamic-classes")}catch(E){console.warn(`[tbw-grid] cellClass callback error for column '${g.field}':`,E),w.removeAttribute("data-dynamic-classes")}}if(w.classList.contains("editing"))continue;const _=tt(o,g);if(_){const T=t[g.field],E=_({row:t,value:T,field:g.field,column:g,cellEl:w});typeof E=="string"?w.innerHTML=ie(E):E instanceof Node?E.parentElement!==w&&(w.innerHTML="",w.appendChild(E)):E==null&&(w.textContent=T==null?"":String(T)),u&&o._afterCellRender?.({row:t,rowIndex:i,column:g,colIndex:p,value:T,cellElement:w,rowElement:e});continue}if(g.__viewTemplate||g.__compiledView||g.externalView)continue;const x=t[g.field];let A;if(g.format)try{const T=g.format(x,t);A=T==null?"":String(T)}catch(T){console.warn(`[tbw-grid] Format error in column '${g.field}':`,T),A=x==null?"":String(x)}else g.type==="date"?(A=et(x),w.textContent=A):g.type==="boolean"?w.innerHTML=Qe(!!x):(A=x==null?"":String(x),w.textContent=A);u&&o._afterCellRender?.({row:t,rowIndex:i,column:g,colIndex:p,value:x,cellElement:w,rowElement:e})}}function ne(o,e,t,i){e.innerHTML="";const n=o._visibleColumns,r=n.length,s=o._focusRow,l=o._focusCol,a=o,c=o._hasAfterCellRenderHook?.()??!1,d=document.createDocumentFragment();for(let u=0;u<r;u++){const h=n[u],f=Di();f.setAttribute("aria-colindex",String(u+1)),f.setAttribute("data-col",String(u)),f.setAttribute("data-row",String(i)),f.setAttribute("data-field",h.field),f.setAttribute("data-header",h.header??h.field),h.type&&f.setAttribute("data-type",h.type);let p=t[h.field];if(h.format)try{p=h.format(p,t)}catch(x){console.warn(`[tbw-grid] Format error in column '${h.field}':`,x)}const g=h.__compiledView,w=h.__viewTemplate,m=tt(o,h),y=h.externalView;let b=!1;if(m){const x=m({row:t,value:p,field:h.field,column:h,cellEl:f});typeof x=="string"?(f.innerHTML=ie(x),b=!0):x instanceof Node?x.parentElement!==f&&(f.textContent="",f.appendChild(x)):x==null&&(f.textContent=p==null?"":String(p))}else if(y){const x=y,A=document.createElement("div");A.setAttribute("data-external-view",""),A.setAttribute("data-field",h.field),f.appendChild(A);const T={row:t,value:p,field:h.field,column:h};if(x.mount)try{x.mount({placeholder:A,context:T,spec:x})}catch(E){console.warn(`[tbw-grid] External view mount error for column '${h.field}':`,E)}else queueMicrotask(()=>{try{a.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:A,spec:x,context:T}}))}catch(E){console.warn(`[tbw-grid] External view event dispatch error for column '${h.field}':`,E)}});A.setAttribute("data-mounted","")}else if(g){const x=g({row:t,value:p,field:h.field,column:h}),A=g.__blocked;f.innerHTML=A?"":ie(x),b=!0,A&&(f.textContent="",f.setAttribute("data-blocked-template",""))}else if(w){const x=w.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(x)?(f.textContent="",f.setAttribute("data-blocked-template","")):(f.innerHTML=ie(we(x,{row:t,value:p})),b=!0)}else h.type==="date"?f.textContent=et(p):h.type==="boolean"?f.innerHTML=Qe(!!p):f.textContent=p==null?"":String(p);if(b){Ti(f);const x=f.textContent||"";/Proxy|Reflect\.ownKeys/.test(x)&&(f.textContent=x.replace(/Proxy|Reflect\.ownKeys/g,"").trim(),/Proxy|Reflect\.ownKeys/.test(f.textContent||"")&&(f.textContent=""))}f.hasAttribute("data-blocked-template")&&(f.textContent||"").trim().length&&(f.textContent=""),h.editable?f.tabIndex=0:h.type==="boolean"&&(f.hasAttribute("tabindex")||(f.tabIndex=0)),s===i&&l===u?(f.classList.add("cell-focus"),f.setAttribute("aria-selected","true")):f.setAttribute("aria-selected","false");const _=h.cellClass;if(_)try{const x=t[h.field],A=_(x,t,h);if(A&&A.length>0){const T=A.filter(E=>E&&typeof E=="string");T.forEach(E=>f.classList.add(E)),f.setAttribute("data-dynamic-classes",T.join(" "))}}catch(x){console.warn(`[tbw-grid] cellClass callback error for column '${h.field}':`,x)}c&&o._afterCellRender?.({row:t,rowIndex:i,column:h,colIndex:u,value:p,cellElement:f,rowElement:e}),d.appendChild(f)}e.appendChild(d)}function rt(o,e,t){if(e.target?.closest(".resize-handle"))return;const i=t.querySelector(".cell[data-row]"),n=me(i);if(n<0)return;const r=o._rows[n];if(!r||o._dispatchRowClick?.(e,n,r,t))return;const s=e.target?.closest(".cell[data-col]");if(s){const l=Number(s.getAttribute("data-col"));if(!isNaN(l)){if(o._dispatchCellClick?.(e,n,l,s))return;const a=o._focusRow!==n||o._focusCol!==l;if(o._focusRow=n,o._focusCol=l,s.classList.contains("editing")){a&&(oe(o._bodyEl??o),s.classList.add("cell-focus"));const c=s.querySelector(it);try{c?.focus({preventScroll:!0})}catch{}return}N(o)}}}function Mi(o,e){if(o._dispatchKeyDown?.(e))return;const t=o._rows.length-1,i=o._visibleColumns.length-1,n=o._activeEditRows!==void 0&&o._activeEditRows!==-1,s=o._visibleColumns[o._focusCol]?.type,l=e.composedPath?.()??[],a=l.length?l[0]:e.target,c=d=>{if(!d)return!1;const u=d.tagName;return!!(u==="INPUT"||u==="SELECT"||u==="TEXTAREA"||d.isContentEditable)};if(!(c(a)&&(e.key==="Home"||e.key==="End"))&&!(c(a)&&(e.key==="ArrowUp"||e.key==="ArrowDown")&&a.tagName==="INPUT"&&a.type==="number")&&!(c(a)&&(e.key==="ArrowLeft"||e.key==="ArrowRight"))&&!(c(a)&&(e.key==="Enter"||e.key==="Escape"))&&!(n&&s==="select"&&(e.key==="ArrowDown"||e.key==="ArrowUp"))){switch(e.key){case"Tab":{e.preventDefault(),!e.shiftKey?o._focusCol<i?o._focusCol+=1:(typeof o.commitActiveRowEdit=="function"&&o.commitActiveRowEdit(),o._focusRow<t&&(o._focusRow+=1,o._focusCol=0)):o._focusCol>0?o._focusCol-=1:o._focusRow>0&&(typeof o.commitActiveRowEdit=="function"&&o._activeEditRows===o._focusRow&&o.commitActiveRowEdit(),o._focusRow-=1,o._focusCol=i),N(o);return}case"ArrowDown":n&&typeof o.commitActiveRowEdit=="function"&&o.commitActiveRowEdit(),o._focusRow=Math.min(t,o._focusRow+1),e.preventDefault();break;case"ArrowUp":n&&typeof o.commitActiveRowEdit=="function"&&o.commitActiveRowEdit(),o._focusRow=Math.max(0,o._focusRow-1),e.preventDefault();break;case"ArrowRight":o._focusCol=Math.min(i,o._focusCol+1),e.preventDefault();break;case"ArrowLeft":o._focusCol=Math.max(0,o._focusCol-1),e.preventDefault();break;case"Home":(e.ctrlKey||e.metaKey)&&(n&&typeof o.commitActiveRowEdit=="function"&&o.commitActiveRowEdit(),o._focusRow=0),o._focusCol=0,e.preventDefault(),N(o,{forceScrollLeft:!0});return;case"End":(e.ctrlKey||e.metaKey)&&(n&&typeof o.commitActiveRowEdit=="function"&&o.commitActiveRowEdit(),o._focusRow=t),o._focusCol=i,e.preventDefault(),N(o,{forceScrollRight:!0});return;case"PageDown":o._focusRow=Math.min(t,o._focusRow+20),e.preventDefault();break;case"PageUp":o._focusRow=Math.max(0,o._focusRow-20),e.preventDefault();break;case"Enter":{const d=o._focusRow,u=o._focusCol,h=o._visibleColumns[u],f=o._rows[d],p=h?.field??"",g=p&&f?f[p]:void 0,w=o.querySelector(`[data-row="${d}"][data-col="${u}"]`),m={rowIndex:d,colIndex:u,field:p,value:g,row:f,cellEl:w,trigger:"keyboard",originalEvent:e},y=new CustomEvent("cell-activate",{cancelable:!0,detail:m});o.dispatchEvent(y);const b=new CustomEvent("activate-cell",{cancelable:!0,detail:{row:d,col:u}});if(o.dispatchEvent(b),y.defaultPrevented||b.defaultPrevented){e.preventDefault();return}break}default:return}N(o)}}function N(o,e){if(o._virtualization?.enabled){const{rowHeight:s,container:l,viewportEl:a}=o._virtualization,c=l,d=a?.clientHeight??c?.clientHeight??0;if(c&&d>0){const u=o._focusRow*s;u<c.scrollTop?c.scrollTop=u:u+s>c.scrollTop+d&&(c.scrollTop=u-d+s)}}const t=o._activeEditRows!==void 0&&o._activeEditRows!==-1;t||o.refreshVirtualWindow(!1),oe(o._bodyEl),Array.from(o._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(s=>{s.setAttribute("aria-selected","false")});const i=o._focusRow,n=o._virtualization.start??0,r=o._virtualization.end??o._rows.length;if(i>=n&&i<r){const s=o._bodyEl.querySelectorAll(".data-grid-row")[i-n];let l=s?.children[o._focusCol];if((!l||!l.classList?.contains("cell"))&&(l=s?.querySelector(`.cell[data-col="${o._focusCol}"]`)??s?.querySelector(".cell[data-col]")),l){l.classList.add("cell-focus"),l.setAttribute("aria-selected","true");const a=o.querySelector(".tbw-scroll-area");if(a&&l&&!t)if(e?.forceScrollLeft)a.scrollLeft=0;else if(e?.forceScrollRight)a.scrollLeft=a.scrollWidth-a.clientWidth;else{const c=o._getHorizontalScrollOffsets?.(s??void 0,l)??{left:0,right:0};if(!c.skipScroll){const d=l.getBoundingClientRect(),u=a.getBoundingClientRect(),h=d.left-u.left+a.scrollLeft,f=h+d.width,p=a.scrollLeft+c.left,g=a.scrollLeft+a.clientWidth-c.right;h<p?a.scrollLeft=h-c.left:f>g&&(a.scrollLeft=f-a.clientWidth+c.right)}}if(o._activeEditRows!==void 0&&o._activeEditRows!==-1&&l.classList.contains("editing")){const c=l.querySelector(it);if(c&&document.activeElement!==c)try{c.focus({preventScroll:!0})}catch{}}else if(!l.contains(document.activeElement)){l.hasAttribute("tabindex")||l.setAttribute("tabindex","-1");try{l.focus({preventScroll:!0})}catch{}}}}}const ue=new WeakMap;function Oi(o,e){const t=me(e),i=Li(e);t<0||i<0||(o._focusRow=t,o._focusCol=i,oe(o._bodyEl),e.classList.add("cell-focus"),e.setAttribute("aria-selected","true"))}function Ce(o,e,t,i){let n=null;const r=t.composedPath?.();if(r&&r.length>0?n=r[0]:n=t.target,n&&!e.contains(n)){const g=document.elementFromPoint(t.clientX,t.clientY);g&&(n=g)}const s=n?.closest?.("[data-col]"),l=n?.closest?.(".data-grid-row"),a=n?.closest?.(".header-row");let c,d,u,h,f,p;return s&&(c=parseInt(s.getAttribute("data-row")??"-1",10),d=parseInt(s.getAttribute("data-col")??"-1",10),c>=0&&d>=0&&(u=o._rows[c],p=o._columns[d],h=p?.field,f=u&&h?u[h]:void 0)),{type:i,row:u,rowIndex:c!==void 0&&c>=0?c:void 0,colIndex:d!==void 0&&d>=0?d:void 0,field:h,value:f,column:p,originalEvent:t,cellElement:s??void 0,rowElement:l??void 0,isHeader:!!a,cell:c!==void 0&&d!==void 0&&c>=0&&d>=0?{row:c,col:d}:void 0}}function Ni(o,e,t){const i=Ce(o,e,t,"mousedown");(o._dispatchCellMouseDown?.(i)??!1)&&ue.set(o,!0)}function zi(o,e,t){if(!ue.get(o))return;const i=Ce(o,e,t,"mousemove");o._dispatchCellMouseMove?.(i)}function qi(o,e,t){if(!ue.get(o))return;const i=Ce(o,e,t,"mouseup");o._dispatchCellMouseUp?.(i),ue.set(o,!1)}function Fi(o,e,t){e.addEventListener("mousedown",i=>{const n=i.target.closest(".cell[data-col]");n&&(n.classList.contains("editing")||Oi(o,n))},{signal:t}),e.addEventListener("click",i=>{const n=i.target.closest(".data-grid-row");n&&rt(o,i,n)},{signal:t}),e.addEventListener("dblclick",i=>{const n=i.target.closest(".data-grid-row");n&&rt(o,i,n)},{signal:t})}function Gi(o,e,t,i){e.addEventListener("keydown",n=>Mi(o,n),{signal:i}),t.addEventListener("mousedown",n=>Ni(o,t,n),{signal:i}),document.addEventListener("mousemove",n=>zi(o,t,n),{signal:i}),document.addEventListener("mouseup",n=>qi(o,t,n),{signal:i})}function st(o,e){return o==null&&e==null?0:o==null?-1:e==null||o>e?1:o<e?-1:0}function lt(o,e,t){const n=t.find(l=>l.field===e.field)?.sortComparator??st,{field:r,direction:s}=e;return[...o].sort((l,a)=>n(l[r],a[r],l,a)*s)}function at(o,e,t,i){o._rows=e,o.__rowRenderEpoch++,o._rowPool.forEach(n=>n.__epoch=-1),he(o),o.refreshVirtualWindow(!0),o.dispatchEvent(new CustomEvent("sort-change",{detail:{field:t.field,direction:i}})),o.requestStateChange?.()}function ct(o,e){!o._sortState||o._sortState.field!==e.field?(o._sortState||(o.__originalOrder=o._rows.slice()),dt(o,e,1)):o._sortState.direction===1?dt(o,e,-1):(o._sortState=null,o.__rowRenderEpoch++,o._rowPool.forEach(i=>i.__epoch=-1),o._rows=o.__originalOrder.slice(),he(o),o._headerRowEl?.querySelectorAll('[role="columnheader"].sortable')?.forEach(i=>{i.getAttribute("aria-sort")?(i.getAttribute("aria-sort")==="ascending"||i.getAttribute("aria-sort")==="descending")&&(o._sortState||i.setAttribute("aria-sort","none")):i.setAttribute("aria-sort","none")}),o.refreshVirtualWindow(!0),o.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:0}})),o.requestStateChange?.())}function dt(o,e,t){o._sortState={field:e.field,direction:t};const i={field:e.field,direction:t},n=o._columns,s=(o.effectiveConfig?.sortHandler??lt)(o._rows,i,n);s&&typeof s.then=="function"?s.then(l=>{at(o,l,e,t)}):at(o,s,e,t)}function Ki(o,e){typeof e=="string"?o.textContent=e:e instanceof HTMLElement&&(o.innerHTML="",o.appendChild(e.cloneNode(!0)))}function he(o){o._headerRowEl=o.findHeaderRow();const e=o._headerRowEl;e&&(e.innerHTML="",o._visibleColumns.forEach((t,i)=>{const n=document.createElement("div");n.className="cell",Ye(n,"header-cell"),n.setAttribute("role","columnheader"),n.setAttribute("aria-colindex",String(i+1)),n.setAttribute("data-field",t.field),n.setAttribute("data-col",String(i));const r=t.__headerTemplate;if(r)Array.from(r.childNodes).forEach(s=>n.appendChild(s.cloneNode(!0)));else{const s=t.header??t.field,l=document.createElement("span");l.textContent=s,n.appendChild(l)}if(t.sortable){n.classList.add("sortable"),n.tabIndex=0;const s=document.createElement("span");Ye(s,"sort-indicator");const l=o._sortState?.field===t.field?o._sortState.direction:0,a={...F,...o.icons},c=l===1?a.sortAsc:l===-1?a.sortDesc:a.sortNone;Ki(s,c),n.appendChild(s),n.setAttribute("aria-sort",l===0?"none":l===1?"ascending":"descending"),n.addEventListener("click",d=>{o._resizeController?.isResizing||o._dispatchHeaderClick?.(d,i,n)||ct(o,t)}),n.addEventListener("keydown",d=>{if(d.key==="Enter"||d.key===" "){if(d.preventDefault(),o._dispatchHeaderClick?.(d,i,n))return;ct(o,t)}})}if(t.resizable){n.classList.add("resizable");const s=document.createElement("div");s.className="resize-handle",s.setAttribute("aria-hidden","true"),s.addEventListener("mousedown",l=>{l.stopPropagation(),l.preventDefault(),o._resizeController.start(l,i,n)}),s.addEventListener("dblclick",l=>{l.stopPropagation(),l.preventDefault(),o._resizeController.resetColumn(i)}),n.appendChild(s)}e.appendChild(n)}),e.querySelectorAll(".cell.sortable").forEach(t=>{t.getAttribute("aria-sort")||t.setAttribute("aria-sort","none")}),e.children.length>0?(e.setAttribute("role","row"),e.setAttribute("aria-rowindex","1")):(e.removeAttribute("role"),e.removeAttribute("aria-rowindex")))}const ut=typeof requestIdleCallback=="function";function Bi(o,e){return ut?requestIdleCallback(o,e):window.setTimeout(()=>{const t=Date.now();o({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})},1)}function ht(o){ut?cancelIdleCallback(o):clearTimeout(o)}var D=(o=>(o[o.STYLE=1]="STYLE",o[o.VIRTUALIZATION=2]="VIRTUALIZATION",o[o.HEADER=3]="HEADER",o[o.ROWS=4]="ROWS",o[o.COLUMNS=5]="COLUMNS",o[o.FULL=6]="FULL",o))(D||{});class Wi{#e;#o=0;#d=0;#c=null;#s=null;#i=null;#h=!1;constructor(e){this.#e=e}requestPhase(e,t){e>this.#o&&(this.#o=e),this.#d===0&&(this.#u(),this.#d=requestAnimationFrame(()=>this.#p()))}whenReady(){return this.#c?this.#c:Promise.resolve()}setInitialReadyResolver(e){this.#i=e}cancel(){this.#d!==0&&(cancelAnimationFrame(this.#d),this.#d=0),this.#o=0,this.#s&&(this.#s(),this.#s=null,this.#c=null)}get isPending(){return this.#o!==0}get pendingPhase(){return this.#o}#u(){this.#c||(this.#c=new Promise(e=>{this.#s=e}))}#p(){if(this.#d=0,!this.#e.isConnected()){this.#o=0,this.#s&&(this.#s(),this.#s=null,this.#c=null);return}const e=this.#o;this.#o=0,e>=5&&this.#e.mergeConfig(),e>=4&&this.#e.processRows(),e>=5&&(this.#e.processColumns(),this.#e.updateTemplate()),e>=3&&this.#e.renderHeader(),e>=2&&this.#e.renderVirtualWindow(),e>=1&&this.#e.afterRender(),!this.#h&&this.#i&&(this.#h=!0,this.#i()),this.#s&&(this.#s(),this.#s=null,this.#c=null)}}function ft(o){let e=null,t=null,i=null,n=null;const r=a=>{if(!e)return;const c=a.clientX-e.startX,d=Math.max(40,e.startWidth+c),u=o._visibleColumns[e.colIndex];u.width=d,u.__userResized=!0,u.__renderedWidth=d,t==null&&(t=requestAnimationFrame(()=>{t=null,o.updateTemplate?.()})),o.dispatchEvent(new CustomEvent("column-resize",{detail:{field:u.field,width:d}}))};let s=!1;const l=()=>{const a=e!==null;a&&(s=!0,requestAnimationFrame(()=>{s=!1})),window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",l),i!==null&&(document.documentElement.style.cursor=i,i=null),n!==null&&(document.body.style.userSelect=n,n=null),e=null,a&&o.requestStateChange&&o.requestStateChange()};return{get isResizing(){return e!==null||s},start(a,c,d){a.preventDefault();const u=o._visibleColumns[c],h=typeof u?.width=="number"?u.width:void 0,f=u?.__renderedWidth??h??d.getBoundingClientRect().width;e={startX:a.clientX,colIndex:c,startWidth:f},window.addEventListener("mousemove",r),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 c=o._visibleColumns[a];c&&(c.__userResized=!1,c.__renderedWidth=void 0,c.width=c.__originalWidth,o.updateTemplate?.(),o.requestStateChange?.(),o.dispatchEvent(new CustomEvent("column-resize-reset",{detail:{field:c.field,width:c.width}})))},dispose(){l()}}}const xe="data-animating",Vi={change:"--tbw-row-change-duration",insert:"--tbw-row-insert-duration",remove:"--tbw-row-remove-duration"},$i={change:500,insert:300,remove:200};function Ui(o){const e=o.trim().toLowerCase();return e.endsWith("ms")?parseFloat(e):e.endsWith("s")?parseFloat(e)*1e3:parseFloat(e)}function ji(o,e){const t=Vi[e],i=getComputedStyle(o).getPropertyValue(t);if(i){const n=Ui(i);if(!isNaN(n)&&n>0)return n}return $i[e]}function gt(o,e,t){o.removeAttribute(xe),o.offsetWidth,o.setAttribute(xe,e);const i=ji(o,e);setTimeout(()=>{e!=="remove"&&o.removeAttribute(xe)},i)}function Re(o,e,t){if(e<0)return!1;const i=o.findRenderedRowElement?.(e);return i?(gt(i,t),!0):!1}function Yi(o,e,t){let i=0;for(const n of e)Re(o,n,t)&&i++;return i}function Xi(o,e,t){const i=o._rows??[],n=o.getRowId;if(!n)return!1;const r=i.findIndex(s=>n(s)===e);return r<0?!1:Re(o,r,t)}function fe(o,e,t){const i=document.createElement(o);if(e)for(const n in e){const r=e[n];r!=null&&i.setAttribute(n,r)}return i}function M(o,e){const t=document.createElement("div");if(o&&(t.className=o),e)for(const i in e){const n=e[i];n!=null&&t.setAttribute(i,n)}return t}function pt(o,e,t){const i=document.createElement("button");if(o&&(i.className=o),e)for(const n in e){const r=e[n];r!=null&&i.setAttribute(n,r)}return i}const wt=document.createElement("template");wt.innerHTML=`
2
2
  <div class="tbw-scroll-area">
3
3
  <div class="rows-body-wrapper">
4
4
  <div class="rows-body" role="grid">
@@ -16,18 +16,18 @@
16
16
  <div class="faux-vscroll">
17
17
  <div class="faux-vscroll-spacer"></div>
18
18
  </div>
19
- `;function gt(){return ft.content.cloneNode(!0)}function pt(n){const e=document.createDocumentFragment(),t=H(n.hasShell?"tbw-grid-root has-shell":"tbw-grid-root");if(n.hasShell&&n.shellHeader&&n.shellBody)t.appendChild(n.shellHeader),t.appendChild(n.shellBody);else{const i=H("tbw-grid-content");i.appendChild(gt()),t.appendChild(i)}return e.appendChild(t),e}function Gi(n){const e=H("tbw-shell-header",{part:"shell-header",role:"presentation"});if(n.title){const r=H("tbw-shell-title");r.textContent=n.title,e.appendChild(r)}const t=H("tbw-shell-content",{part:"shell-content",role:"presentation","data-light-dom-header-content":""});e.appendChild(t);const i=H("tbw-shell-toolbar",{part:"shell-toolbar",role:"presentation"});for(const r of n.configButtons)r.hasRender&&i.appendChild(H("tbw-toolbar-content-slot",{"data-toolbar-content":r.id}));for(const r of n.apiButtons)r.hasRender&&i.appendChild(H("tbw-toolbar-content-slot",{"data-toolbar-content":r.id}));if((n.configButtons.some(r=>r.hasRender)||n.apiButtons.some(r=>r.hasRender))&&n.hasPanels&&i.appendChild(H("tbw-toolbar-separator")),n.hasPanels){const r=ht(n.isPanelOpen?"tbw-toolbar-btn active":"tbw-toolbar-btn",{"data-panel-toggle":"",title:"Settings","aria-label":"Toggle settings panel","aria-pressed":String(n.isPanelOpen),"aria-controls":"tbw-tool-panel"});r.innerHTML=n.toolPanelIcon,i.appendChild(r)}return e.appendChild(i),e}function Ki(n){const e=H("tbw-shell-body"),t=n.panels.length>0,i=n.panels.length===1,o=H("tbw-grid-content");o.appendChild(gt());let r=null;if(t){r=fe("aside",{class:n.isPanelOpen?"tbw-tool-panel open":"tbw-tool-panel",part:"tool-panel","data-position":n.position,role:"presentation",id:"tbw-tool-panel"});const s=n.position==="left"?"right":"left";r.appendChild(H("tbw-tool-panel-resize",{"data-resize-handle":"","data-handle-position":s,"aria-hidden":"true"}));const l=H("tbw-tool-panel-content",{role:"presentation"}),a=H("tbw-accordion");for(const c of n.panels){const d=`tbw-accordion-section${c.isExpanded?" expanded":""}${i?" single":""}`,u=H(d,{"data-section":c.id}),h=ht("tbw-accordion-header",{"aria-expanded":String(c.isExpanded),"aria-controls":`tbw-section-${c.id}`});if(i&&h.setAttribute("aria-disabled","true"),c.icon){const f=fe("span",{class:"tbw-accordion-icon"});f.innerHTML=c.icon,h.appendChild(f)}const g=fe("span",{class:"tbw-accordion-title"});if(g.textContent=c.title,h.appendChild(g),!i){const f=fe("span",{class:"tbw-accordion-chevron"});f.innerHTML=c.isExpanded?n.collapseIcon:n.expandIcon,h.appendChild(f)}u.appendChild(h),u.appendChild(H("tbw-accordion-content",{id:`tbw-section-${c.id}`,role:"presentation"})),a.appendChild(u)}l.appendChild(a),r.appendChild(l)}return n.position==="left"&&r?(e.appendChild(r),e.appendChild(o)):(e.appendChild(o),r&&e.appendChild(r)),e}function W(n){return n?typeof n=="string"?n:n.outerHTML:""}function Bi(){return{toolPanels:new Map,headerContents:new Map,toolbarContents:new Map,hasToolButtonsContainer:!1,lightDomHeaderContent:[],lightDomTitle:null,lightDomToolPanelIds:new Set,lightDomToolbarContentIds:new Set,apiToolPanelIds:new Set,isPanelOpen:!1,expandedSections:new Set,headerContentCleanups:new Map,panelCleanups:new Map,toolbarContentCleanups:new Map,lightDomContentMoved:!1}}function wt(n){return!!(n?.header?.title||n?.header?.toolbarContents?.length||n?.toolPanels?.length||n?.headerContents?.length||n?.header?.lightDomContent?.length||n?.header?.hasToolButtonsContainer)}function mt(n,e,t="☰"){const i=n?.header?.title??e.lightDomTitle??"",o=!!i,r=W(t),s=n?.header?.toolbarContents??[],l=[...e.toolbarContents.values()],a=new Set(s.map(p=>p.id)),c=[...s];for(const p of l)a.has(p.id)||c.push(p);const d=c.length>0,u=e.toolPanels.size>0,h=d&&u,g=[...c].sort((p,w)=>(p.order??0)-(w.order??0));let f="";for(const p of g)f+=`<div class="tbw-toolbar-content-slot" data-toolbar-content="${p.id}"></div>`;if(h&&(f+='<div class="tbw-toolbar-separator"></div>'),u){const p=e.isPanelOpen;f+=`<button class="${p?"tbw-toolbar-btn active":"tbw-toolbar-btn"}" data-panel-toggle title="Settings" aria-label="Toggle settings panel" aria-pressed="${p}" aria-controls="tbw-tool-panel">${r}</button>`}return`
19
+ `;function mt(){return wt.content.cloneNode(!0)}function bt(o){const e=document.createDocumentFragment(),t=M(o.hasShell?"tbw-grid-root has-shell":"tbw-grid-root");if(o.hasShell&&o.shellHeader&&o.shellBody)t.appendChild(o.shellHeader),t.appendChild(o.shellBody);else{const i=M("tbw-grid-content");i.appendChild(mt()),t.appendChild(i)}return e.appendChild(t),e}function Zi(o){const e=M("tbw-shell-header",{part:"shell-header",role:"presentation"});if(o.title){const r=M("tbw-shell-title");r.textContent=o.title,e.appendChild(r)}const t=M("tbw-shell-content",{part:"shell-content",role:"presentation","data-light-dom-header-content":""});e.appendChild(t);const i=M("tbw-shell-toolbar",{part:"shell-toolbar",role:"presentation"});for(const r of o.configButtons)r.hasRender&&i.appendChild(M("tbw-toolbar-content-slot",{"data-toolbar-content":r.id}));for(const r of o.apiButtons)r.hasRender&&i.appendChild(M("tbw-toolbar-content-slot",{"data-toolbar-content":r.id}));if((o.configButtons.some(r=>r.hasRender)||o.apiButtons.some(r=>r.hasRender))&&o.hasPanels&&i.appendChild(M("tbw-toolbar-separator")),o.hasPanels){const r=pt(o.isPanelOpen?"tbw-toolbar-btn active":"tbw-toolbar-btn",{"data-panel-toggle":"",title:"Settings","aria-label":"Toggle settings panel","aria-pressed":String(o.isPanelOpen),"aria-controls":"tbw-tool-panel"});r.innerHTML=o.toolPanelIcon,i.appendChild(r)}return e.appendChild(i),e}function Ji(o){const e=M("tbw-shell-body"),t=o.panels.length>0,i=o.panels.length===1,n=M("tbw-grid-content");n.appendChild(mt());let r=null;if(t){r=fe("aside",{class:o.isPanelOpen?"tbw-tool-panel open":"tbw-tool-panel",part:"tool-panel","data-position":o.position,role:"presentation",id:"tbw-tool-panel"});const s=o.position==="left"?"right":"left";r.appendChild(M("tbw-tool-panel-resize",{"data-resize-handle":"","data-handle-position":s,"aria-hidden":"true"}));const l=M("tbw-tool-panel-content",{role:"presentation"}),a=M("tbw-accordion");for(const c of o.panels){const d=`tbw-accordion-section${c.isExpanded?" expanded":""}${i?" single":""}`,u=M(d,{"data-section":c.id}),h=pt("tbw-accordion-header",{"aria-expanded":String(c.isExpanded),"aria-controls":`tbw-section-${c.id}`});if(i&&h.setAttribute("aria-disabled","true"),c.icon){const p=fe("span",{class:"tbw-accordion-icon"});p.innerHTML=c.icon,h.appendChild(p)}const f=fe("span",{class:"tbw-accordion-title"});if(f.textContent=c.title,h.appendChild(f),!i){const p=fe("span",{class:"tbw-accordion-chevron"});p.innerHTML=c.isExpanded?o.collapseIcon:o.expandIcon,h.appendChild(p)}u.appendChild(h),u.appendChild(M("tbw-accordion-content",{id:`tbw-section-${c.id}`,role:"presentation"})),a.appendChild(u)}l.appendChild(a),r.appendChild(l)}return o.position==="left"&&r?(e.appendChild(r),e.appendChild(n)):(e.appendChild(n),r&&e.appendChild(r)),e}function V(o){return o?typeof o=="string"?o:o.outerHTML:""}function Qi(){return{toolPanels:new Map,headerContents:new Map,toolbarContents:new Map,hasToolButtonsContainer:!1,lightDomHeaderContent:[],lightDomTitle:null,lightDomToolPanelIds:new Set,lightDomToolbarContentIds:new Set,apiToolPanelIds:new Set,isPanelOpen:!1,expandedSections:new Set,headerContentCleanups:new Map,panelCleanups:new Map,toolbarContentCleanups:new Map,lightDomContentMoved:!1}}function vt(o){return!!(o?.header?.title||o?.header?.toolbarContents?.length||o?.toolPanels?.length||o?.headerContents?.length||o?.header?.lightDomContent?.length||o?.header?.hasToolButtonsContainer)}function yt(o,e,t="☰"){const i=o?.header?.title??e.lightDomTitle??"",n=!!i,r=V(t),s=o?.header?.toolbarContents??[],l=[...e.toolbarContents.values()],a=new Set(s.map(g=>g.id)),c=[...s];for(const g of l)a.has(g.id)||c.push(g);const d=c.length>0,u=e.toolPanels.size>0,h=d&&u,f=[...c].sort((g,w)=>(g.order??0)-(w.order??0));let p="";for(const g of f)p+=`<div class="tbw-toolbar-content-slot" data-toolbar-content="${g.id}"></div>`;if(h&&(p+='<div class="tbw-toolbar-separator"></div>'),u){const g=e.isPanelOpen;p+=`<button class="${g?"tbw-toolbar-btn active":"tbw-toolbar-btn"}" data-panel-toggle title="Settings" aria-label="Toggle settings panel" aria-pressed="${g}" aria-controls="tbw-tool-panel">${r}</button>`}return`
20
20
  <div class="tbw-shell-header" part="shell-header" role="presentation">
21
- ${o?`<div class="tbw-shell-title">${mi(i)}</div>`:""}
21
+ ${n?`<div class="tbw-shell-title">${Ci(i)}</div>`:""}
22
22
  <div class="tbw-shell-content" part="shell-content" role="presentation" data-light-dom-header-content></div>
23
23
  <div class="tbw-shell-toolbar" part="shell-toolbar" role="presentation">
24
- ${f}
24
+ ${p}
25
25
  </div>
26
26
  </div>
27
- `}function X(n,e){const t=n.querySelector("tbw-grid-header");if(!t)return;if(!e.lightDomTitle){const o=t.getAttribute("title");o&&(e.lightDomTitle=o)}const i=t.querySelectorAll("tbw-grid-header-content");i.length>0&&e.lightDomHeaderContent.length===0&&(e.lightDomHeaderContent=Array.from(i)),t.style.display="none"}function Z(n,e,t){const i=n.querySelector(":scope > tbw-grid-tool-buttons");if(!i)return;e.hasToolButtonsContainer=!0;const o="light-dom-toolbar-content";if(e.lightDomToolbarContentIds.has(o))return;const r={id:o,order:0,render:(s=>{for(;i.firstChild;)s.appendChild(i.firstChild)})};e.toolbarContents.set(o,r),e.lightDomToolbarContentIds.add(o),i.style.display="none"}function J(n,e,t){n.querySelectorAll(":scope > tbw-grid-tool-panel").forEach(o=>{const r=o,s=r.getAttribute("id"),l=r.getAttribute("title");if(!s||!l){console.warn(`[parseLightDomToolPanels] Tool panel missing required id or title attribute: id="${s??""}", title="${l??""}"`);return}const a=r.getAttribute("icon")??void 0,c=r.getAttribute("tooltip")??void 0,d=parseInt(r.getAttribute("order")??"100",10);let u;const h=t?.(r);if(h)u=h;else{const p=r.innerHTML.trim();u=w=>{const m=document.createElement("div");return m.innerHTML=p,w.appendChild(m),()=>m.remove()}}const g=e.toolPanels.get(s);if(g){if(h){g.render=u,g.order=d,g.icon=a,g.tooltip=c;const p=e.panelCleanups.get(s);p&&(p(),e.panelCleanups.delete(s))}return}const f={id:s,title:l,icon:a,tooltip:c,order:d,render:u};e.toolPanels.set(s,f),e.lightDomToolPanelIds.add(s),r.style.display="none"})}function Vi(n,e,t,i){const o=n.querySelector(".tbw-shell-toolbar");o&&o.addEventListener("click",s=>{if(s.target.closest("[data-panel-toggle]")){i.onPanelToggle();return}});const r=n.querySelector(".tbw-accordion");r&&r.addEventListener("click",s=>{const a=s.target.closest(".tbw-accordion-header");if(a){const d=a.closest("[data-section]")?.getAttribute("data-section");d&&i.onSectionToggle(d)}})}function Wi(n,e,t){const i=n.querySelector(".tbw-tool-panel"),o=n.querySelector("[data-resize-handle]"),r=n.querySelector(".tbw-shell-body");if(!i||!o||!r)return()=>{};const s=e?.toolPanel?.position??"right",l=200;let a=0,c=0,d=0,u=!1;const h=p=>{if(!u)return;p.preventDefault();const w=s==="left"?p.clientX-a:a-p.clientX,m=Math.min(d,Math.max(l,c+w));i.style.width=`${m}px`},g=()=>{if(!u)return;u=!1,o.classList.remove("resizing"),i.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const p=i.getBoundingClientRect().width;t(p),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",g)},f=p=>{p.preventDefault(),u=!0,a=p.clientX,c=i.getBoundingClientRect().width,d=r.getBoundingClientRect().width-20,o.classList.add("resizing"),i.style.transition="none",document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",h),document.addEventListener("mouseup",g)};return o.addEventListener("mousedown",f),()=>{o.removeEventListener("mousedown",f),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",g)}}function bt(n,e,t){const i=e?.header?.toolbarContents??[],o=[...t.toolbarContents.values()],r=new Set(i.map(l=>l.id)),s=[...i];for(const l of o)r.has(l.id)||s.push(l);for(const l of s){if(t.toolbarContentCleanups.has(l.id)||!l.render)continue;const a=n.querySelector(`[data-toolbar-content="${l.id}"]`);if(!a)continue;const c=l.render(a);c&&t.toolbarContentCleanups.set(l.id,c)}}function xe(n,e){const t=e.lightDomHeaderContent.length>0&&!e.lightDomContentMoved,i=e.headerContents.size>0;if(!t&&!i)return;const o=n.querySelector(".tbw-shell-content");if(!o)return;if(t){for(const s of e.lightDomHeaderContent)s.style.display="",o.appendChild(s);e.lightDomContentMoved=!0}const r=[...e.headerContents.values()].sort((s,l)=>(s.order??100)-(l.order??100));for(const s of r){const l=e.headerContentCleanups.get(s.id);l&&(l(),e.headerContentCleanups.delete(s.id));let a=o.querySelector(`[data-header-content="${s.id}"]`);a||(a=document.createElement("div"),a.setAttribute("data-header-content",s.id),o.appendChild(a));const c=s.render(a);c&&e.headerContentCleanups.set(s.id,c)}}function $i(n,e,t){if(!e.isPanelOpen)return;const i=W(t?.expand??q.expand),o=W(t?.collapse??q.collapse);for(const[r,s]of e.toolPanels){const l=e.expandedSections.has(r),a=n.querySelector(`[data-section="${r}"]`),c=a?.querySelector(".tbw-accordion-content");if(!a||!c)continue;a.classList.toggle("expanded",l);const d=a.querySelector(".tbw-accordion-header");d&&d.setAttribute("aria-expanded",String(l));const u=a.querySelector(".tbw-accordion-chevron");if(u&&(u.innerHTML=l?o:i),l){if(c.children.length===0){const h=s.render(c);h&&e.panelCleanups.set(r,h)}}else{const h=e.panelCleanups.get(r);h&&(h(),e.panelCleanups.delete(r)),c.innerHTML=""}}}function vt(n,e){const t=n.querySelector("[data-panel-toggle]");t&&(t.classList.toggle("active",e.isPanelOpen),t.setAttribute("aria-pressed",String(e.isPanelOpen)))}function yt(n,e){const t=n.querySelector(".tbw-tool-panel");t&&(t.classList.toggle("open",e.isPanelOpen),e.isPanelOpen||(t.style.width=""))}function Ui(n){for(const e of n.headerContentCleanups.values())e();n.headerContentCleanups.clear();for(const e of n.panelCleanups.values())e();n.panelCleanups.clear();for(const e of n.toolbarContentCleanups.values())e();n.toolbarContentCleanups.clear();for(const e of n.toolbarContents.values())e.onDestroy?.();if(n.isPanelOpen)for(const e of n.expandedSections)n.toolPanels.get(e)?.onClose?.();n.isPanelOpen=!1,n.expandedSections.clear(),n.toolPanels.clear(),n.headerContents.clear(),n.toolbarContents.clear(),n.lightDomHeaderContent=[],n.lightDomToolPanelIds.clear(),n.lightDomToolbarContentIds.clear(),n.lightDomContentMoved=!1}function ji(n,e){let t=!1;const i={get isInitialized(){return t},setInitialized(o){t=o},get isPanelOpen(){return n.isPanelOpen},get activePanel(){return n.isPanelOpen&&n.expandedSections.size>0?[...n.expandedSections][0]:null},get expandedSections(){return[...n.expandedSections]},openToolPanel(){if(n.isPanelOpen)return;if(n.toolPanels.size===0){console.warn("[tbw-grid] No tool panels registered");return}if(n.isPanelOpen=!0,n.expandedSections.size===0&&n.toolPanels.size>0){const s=[...n.toolPanels.values()].sort((l,a)=>(l.order??100)-(a.order??100))[0];s&&n.expandedSections.add(s.id)}const o=e.getShadow();vt(o,n),yt(o,n),$i(o,n,e.getAccordionIcons()),e.emit("tool-panel-open",{sections:i.expandedSections})},closeToolPanel(){if(!n.isPanelOpen)return;for(const r of n.panelCleanups.values())r();n.panelCleanups.clear();for(const r of n.toolPanels.values())r.onClose?.();n.isPanelOpen=!1;const o=e.getShadow();vt(o,n),yt(o,n),e.emit("tool-panel-close",{})},toggleToolPanel(){n.isPanelOpen?i.closeToolPanel():i.openToolPanel()},toggleToolPanelSection(o){const r=n.toolPanels.get(o);if(!r){console.warn(`[tbw-grid] Tool panel section "${o}" not found`);return}if(n.toolPanels.size===1)return;const s=e.getShadow(),l=n.expandedSections.has(o);if(l){const a=n.panelCleanups.get(o);a&&(a(),n.panelCleanups.delete(o)),r.onClose?.(),n.expandedSections.delete(o),Ee(s,o,!1)}else{for(const[a,c]of n.toolPanels)if(a!==o&&n.expandedSections.has(a)){const d=n.panelCleanups.get(a);d&&(d(),n.panelCleanups.delete(a)),c.onClose?.(),n.expandedSections.delete(a),Ee(s,a,!1);const u=s.querySelector(`[data-section="${a}"] .tbw-accordion-content`);u&&(u.innerHTML="")}n.expandedSections.add(o),Ee(s,o,!0),Yi(s,n,o)}e.emit("tool-panel-section-toggle",{id:o,expanded:!l})},getToolPanels(){return[...n.toolPanels.values()]},registerToolPanel(o){if(n.toolPanels.has(o.id)){console.warn(`[tbw-grid] Tool panel "${o.id}" already registered`);return}n.toolPanels.set(o.id,o),t&&e.refreshShellHeader()},unregisterToolPanel(o){if(n.expandedSections.has(o)){const r=n.panelCleanups.get(o);r&&(r(),n.panelCleanups.delete(o)),n.expandedSections.delete(o)}n.toolPanels.delete(o),t&&e.refreshShellHeader()},getHeaderContents(){return[...n.headerContents.values()]},registerHeaderContent(o){if(n.headerContents.has(o.id)){console.warn(`[tbw-grid] Header content "${o.id}" already registered`);return}n.headerContents.set(o.id,o),t&&xe(e.getShadow(),n)},unregisterHeaderContent(o){const r=n.headerContentCleanups.get(o);r&&(r(),n.headerContentCleanups.delete(o)),n.headerContents.get(o)?.onDestroy?.(),n.headerContents.delete(o),e.getShadow().querySelector(`[data-header-content="${o}"]`)?.remove()},getToolbarContents(){return[...n.toolbarContents.values()].sort((o,r)=>(o.order??0)-(r.order??0))},registerToolbarContent(o){if(n.toolbarContents.has(o.id)){console.warn(`[tbw-grid] Toolbar content "${o.id}" already registered`);return}n.toolbarContents.set(o.id,o),t&&e.refreshShellHeader()},unregisterToolbarContent(o){const r=n.toolbarContentCleanups.get(o);r&&(r(),n.toolbarContentCleanups.delete(o));const s=n.toolbarContents.get(o);s?.onDestroy&&s.onDestroy(),n.toolbarContents.delete(o),t&&e.refreshShellHeader()}};return i}function Ee(n,e,t){const i=n.querySelector(`[data-section="${e}"]`);i&&i.classList.toggle("expanded",t)}function Yi(n,e,t){const i=e.toolPanels.get(t);if(!i?.render)return;const o=n.querySelector(`[data-section="${t}"] .tbw-accordion-content`);if(!o)return;const r=i.render(o);r&&e.panelCleanups.set(t,r)}function Xi(n,e,t,i){const o=wt(e),r=[],s=["tbw-grid-header","tbw-grid-tool-buttons","tbw-grid-tool-panel","tbw-grid-column"];for(const l of s)n.querySelectorAll(`:scope > ${l}`).forEach(c=>r.push(c));n.replaceChildren();for(const l of r)n.appendChild(l);if(o){const l=W(i?.toolPanel??q.toolPanel),a=W(i?.expand??q.expand),c=W(i?.collapse??q.collapse),u=[...e?.header?.toolbarContents??[]].sort((v,b)=>(v.order??0)-(b.order??0)),g=[...e?.toolPanels??[]].sort((v,b)=>(v.order??100)-(b.order??100)),f={title:e?.header?.title??void 0,hasPanels:g.length>0,isPanelOpen:t.isPanelOpen,toolPanelIcon:l,configButtons:u.map(v=>({id:v.id,hasElement:!1,hasRender:!!v.render})),apiButtons:[]},p={position:e?.toolPanel?.position??"right",isPanelOpen:t.isPanelOpen,expandIcon:a,collapseIcon:c,panels:g.map(v=>({id:v.id,title:v.title,icon:W(v.icon),isExpanded:t.expandedSections.has(v.id)}))},w=Gi(f),m=Ki(p),C=pt({hasShell:!0,shellHeader:w,shellBody:m});n.appendChild(C)}else{const l=pt({hasShell:!1});n.appendChild(l)}return o}function Zi(){return{startY:null,startX:null,scrollTop:null,scrollLeft:null,lastY:null,lastX:null,lastTime:null,velocityY:0,velocityX:0,momentumRaf:0}}function Ji(n){n.startY=null,n.startX=null,n.scrollTop=null,n.scrollLeft=null,n.lastY=null,n.lastX=null,n.lastTime=null}function Ct(n){n.momentumRaf&&(cancelAnimationFrame(n.momentumRaf),n.momentumRaf=0)}function Qi(n,e,t){if(n.touches.length!==1)return;Ct(e);const i=n.touches[0];e.startY=i.clientY,e.startX=i.clientX,e.lastY=i.clientY,e.lastX=i.clientX,e.lastTime=performance.now(),e.scrollTop=t.fauxScrollbar.scrollTop,e.scrollLeft=t.scrollArea?.scrollLeft??0,e.velocityY=0,e.velocityX=0}function en(n,e,t){if(n.touches.length!==1||e.startY===null||e.startX===null||e.scrollTop===null||e.scrollLeft===null)return!1;const i=n.touches[0],o=i.clientY,r=i.clientX,s=performance.now(),l=e.startY-o,a=e.startX-r;if(e.lastTime!==null&&e.lastY!==null&&e.lastX!==null){const p=s-e.lastTime;p>0&&(e.velocityY=(e.lastY-o)/p,e.velocityX=(e.lastX-r)/p)}e.lastY=o,e.lastX=r,e.lastTime=s;const{scrollTop:c,scrollHeight:d,clientHeight:u}=t.fauxScrollbar,h=d-u,g=l>0&&c<h||l<0&&c>0;let f=!1;if(t.scrollArea){const{scrollLeft:p,scrollWidth:w,clientWidth:m}=t.scrollArea,C=w-m;f=a>0&&p<C||a<0&&p>0}return g&&(t.fauxScrollbar.scrollTop=e.scrollTop+l),f&&t.scrollArea&&(t.scrollArea.scrollLeft=e.scrollLeft+a),g||f}function tn(n,e){(Math.abs(n.velocityY)>.1||Math.abs(n.velocityX)>.1)&&nn(n,e),Ji(n)}function nn(n,e){const o=()=>{n.velocityY*=.95,n.velocityX*=.95;const r=n.velocityY*16,s=n.velocityX*16;Math.abs(n.velocityY)>.01&&(e.fauxScrollbar.scrollTop+=r),Math.abs(n.velocityX)>.01&&e.scrollArea&&(e.scrollArea.scrollLeft+=s),Math.abs(n.velocityY)>.01||Math.abs(n.velocityX)>.01?n.momentumRaf=requestAnimationFrame(o):n.momentumRaf=0};n.momentumRaf=requestAnimationFrame(o)}function on(n,e,t,i){n.addEventListener("touchstart",o=>Qi(o,e,t),{passive:!0,signal:i}),n.addEventListener("touchmove",o=>{en(o,e,t)&&o.preventDefault()},{passive:!1,signal:i}),n.addEventListener("touchend",()=>tn(e,t),{passive:!0,signal:i})}const rn=[{property:"editable",pluginName:"editing",level:"column",description:'the "editable" column property',importHint:"import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';",isUsed:n=>n===!0},{property:"editor",pluginName:"editing",level:"column",description:'the "editor" column property',importHint:"import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';"},{property:"editorParams",pluginName:"editing",level:"column",description:'the "editorParams" column property',importHint:"import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';"},{property:"group",pluginName:"groupingColumns",level:"column",description:'the "group" column property',importHint:"import { GroupingColumnsPlugin } from '@toolbox-web/grid/plugins/grouping-columns';"},{property:"sticky",pluginName:"pinnedColumns",level:"column",description:'the "sticky" column property',importHint:"import { PinnedColumnsPlugin } from '@toolbox-web/grid/plugins/pinned-columns';",isUsed:n=>n==="left"||n==="right"}],sn=[{property:"columnGroups",pluginName:"groupingColumns",level:"config",description:'the "columnGroups" config property',importHint:"import { GroupingColumnsPlugin } from '@toolbox-web/grid/plugins/grouping-columns';",isUsed:n=>Array.isArray(n)&&n.length>0}],ln={editing:"import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';",selection:"import { SelectionPlugin } from '@toolbox-web/grid/plugins/selection';",reorder:"import { ReorderPlugin } from '@toolbox-web/grid/plugins/reorder';",clipboard:"import { ClipboardPlugin } from '@toolbox-web/grid/plugins/clipboard';",filtering:"import { FilteringPlugin } from '@toolbox-web/grid/plugins/filtering';",multiSort:"import { MultiSortPlugin } from '@toolbox-web/grid/plugins/multi-sort';",groupingRows:"import { GroupingRowsPlugin } from '@toolbox-web/grid/plugins/grouping-rows';",groupingColumns:"import { GroupingColumnsPlugin } from '@toolbox-web/grid/plugins/grouping-columns';",tree:"import { TreePlugin } from '@toolbox-web/grid/plugins/tree';",masterDetail:"import { MasterDetailPlugin } from '@toolbox-web/grid/plugins/master-detail';",pinnedColumns:"import { PinnedColumnsPlugin } from '@toolbox-web/grid/plugins/pinned-columns';",pinnedRows:"import { PinnedRowsPlugin } from '@toolbox-web/grid/plugins/pinned-rows';",visibility:"import { VisibilityPlugin } from '@toolbox-web/grid/plugins/visibility';",undoRedo:"import { UndoRedoPlugin } from '@toolbox-web/grid/plugins/undo-redo';",export:"import { ExportPlugin } from '@toolbox-web/grid/plugins/export';",contextMenu:"import { ContextMenuPlugin } from '@toolbox-web/grid/plugins/context-menu';",pivot:"import { PivotPlugin } from '@toolbox-web/grid/plugins/pivot';",serverSide:"import { ServerSidePlugin } from '@toolbox-web/grid/plugins/server-side';",columnVirtualization:"import { ColumnVirtualizationPlugin } from '@toolbox-web/grid/plugins/column-virtualization';"};function Re(n){return ln[n]??`import { ${G(n)}Plugin } from '@toolbox-web/grid/plugins/${n}';`}function xt(){if(typeof window<"u"&&window.location){const n=window.location.hostname;if(n==="localhost"||n==="127.0.0.1"||n==="::1")return!0}return typeof process<"u"&&process.env?.NODE_ENV!=="production"}function G(n){return n.charAt(0).toUpperCase()+n.slice(1)}function Et(n,e){return n.some(t=>t.name===e)}function an(n,e){const t=rn,i=sn,o=new Map;function r(l,a,c,d,u=!1){o.has(l)||o.set(l,{description:a,importHint:c,fields:[],isConfigProperty:u});const h=o.get(l);h.fields.includes(d)||h.fields.push(d)}for(const l of i){const a=n[l.property];(l.isUsed?l.isUsed(a):a!==void 0)&&!Et(e,l.pluginName)&&r(l.pluginName,l.description,l.importHint??Re(l.pluginName),l.property,!0)}const s=n.columns;if(s&&s.length>0)for(const l of s)for(const a of t){const c=l[a.property];if((a.isUsed?a.isUsed(c):c!==void 0)&&!Et(e,a.pluginName)){const u=l.field||"<unknown>";r(a.pluginName,a.description,a.importHint??Re(a.pluginName),u)}}if(o.size>0){const l=[];for(const[a,{description:c,importHint:d,fields:u,isConfigProperty:h}]of o)if(h)l.push(`Config uses ${c}, but the required plugin is not loaded.
27
+ `}function X(o,e){const t=o.querySelector("tbw-grid-header");if(!t)return;if(!e.lightDomTitle){const n=t.getAttribute("title");n&&(e.lightDomTitle=n)}const i=t.querySelectorAll("tbw-grid-header-content");i.length>0&&e.lightDomHeaderContent.length===0&&(e.lightDomHeaderContent=Array.from(i)),t.style.display="none"}function Z(o,e,t){const i=o.querySelector(":scope > tbw-grid-tool-buttons");if(!i)return;e.hasToolButtonsContainer=!0;const n="light-dom-toolbar-content";if(e.lightDomToolbarContentIds.has(n))return;const r={id:n,order:0,render:(s=>{for(;i.firstChild;)s.appendChild(i.firstChild)})};e.toolbarContents.set(n,r),e.lightDomToolbarContentIds.add(n),i.style.display="none"}function J(o,e,t){o.querySelectorAll(":scope > tbw-grid-tool-panel").forEach(n=>{const r=n,s=r.getAttribute("id"),l=r.getAttribute("title");if(!s||!l){console.warn(`[parseLightDomToolPanels] Tool panel missing required id or title attribute: id="${s??""}", title="${l??""}"`);return}const a=r.getAttribute("icon")??void 0,c=r.getAttribute("tooltip")??void 0,d=parseInt(r.getAttribute("order")??"100",10);let u;const h=t?.(r);if(h)u=h;else{const g=r.innerHTML.trim();u=w=>{const m=document.createElement("div");return m.innerHTML=g,w.appendChild(m),()=>m.remove()}}const f=e.toolPanels.get(s);if(f){if(h){f.render=u,f.order=d,f.icon=a,f.tooltip=c;const g=e.panelCleanups.get(s);g&&(g(),e.panelCleanups.delete(s))}return}const p={id:s,title:l,icon:a,tooltip:c,order:d,render:u};e.toolPanels.set(s,p),e.lightDomToolPanelIds.add(s),r.style.display="none"})}function eo(o,e,t,i){const n=o.querySelector(".tbw-shell-toolbar");n&&n.addEventListener("click",s=>{if(s.target.closest("[data-panel-toggle]")){i.onPanelToggle();return}});const r=o.querySelector(".tbw-accordion");r&&r.addEventListener("click",s=>{const a=s.target.closest(".tbw-accordion-header");if(a){const d=a.closest("[data-section]")?.getAttribute("data-section");d&&i.onSectionToggle(d)}})}function to(o,e,t){const i=o.querySelector(".tbw-tool-panel"),n=o.querySelector("[data-resize-handle]"),r=o.querySelector(".tbw-shell-body");if(!i||!n||!r)return()=>{};const s=e?.toolPanel?.position??"right",l=200;let a=0,c=0,d=0,u=!1;const h=g=>{if(!u)return;g.preventDefault();const w=s==="left"?g.clientX-a:a-g.clientX,m=Math.min(d,Math.max(l,c+w));i.style.width=`${m}px`},f=()=>{if(!u)return;u=!1,n.classList.remove("resizing"),i.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const g=i.getBoundingClientRect().width;t(g),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",f)},p=g=>{g.preventDefault(),u=!0,a=g.clientX,c=i.getBoundingClientRect().width,d=r.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",h),document.addEventListener("mouseup",f)};return n.addEventListener("mousedown",p),()=>{n.removeEventListener("mousedown",p),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",f)}}function Ct(o,e,t){const i=e?.header?.toolbarContents??[],n=[...t.toolbarContents.values()],r=new Set(i.map(l=>l.id)),s=[...i];for(const l of n)r.has(l.id)||s.push(l);for(const l of s){if(t.toolbarContentCleanups.has(l.id)||!l.render)continue;const a=o.querySelector(`[data-toolbar-content="${l.id}"]`);if(!a)continue;const c=l.render(a);c&&t.toolbarContentCleanups.set(l.id,c)}}function Ee(o,e){const t=e.lightDomHeaderContent.length>0&&!e.lightDomContentMoved,i=e.headerContents.size>0;if(!t&&!i)return;const n=o.querySelector(".tbw-shell-content");if(!n)return;if(t){for(const s of e.lightDomHeaderContent)s.style.display="",n.appendChild(s);e.lightDomContentMoved=!0}const r=[...e.headerContents.values()].sort((s,l)=>(s.order??100)-(l.order??100));for(const s of r){const l=e.headerContentCleanups.get(s.id);l&&(l(),e.headerContentCleanups.delete(s.id));let a=n.querySelector(`[data-header-content="${s.id}"]`);a||(a=document.createElement("div"),a.setAttribute("data-header-content",s.id),n.appendChild(a));const c=s.render(a);c&&e.headerContentCleanups.set(s.id,c)}}function io(o,e,t){if(!e.isPanelOpen)return;const i=V(t?.expand??F.expand),n=V(t?.collapse??F.collapse);for(const[r,s]of e.toolPanels){const l=e.expandedSections.has(r),a=o.querySelector(`[data-section="${r}"]`),c=a?.querySelector(".tbw-accordion-content");if(!a||!c)continue;a.classList.toggle("expanded",l);const d=a.querySelector(".tbw-accordion-header");d&&d.setAttribute("aria-expanded",String(l));const u=a.querySelector(".tbw-accordion-chevron");if(u&&(u.innerHTML=l?n:i),l){if(c.children.length===0){const h=s.render(c);h&&e.panelCleanups.set(r,h)}}else{const h=e.panelCleanups.get(r);h&&(h(),e.panelCleanups.delete(r)),c.innerHTML=""}}}function xt(o,e){const t=o.querySelector("[data-panel-toggle]");t&&(t.classList.toggle("active",e.isPanelOpen),t.setAttribute("aria-pressed",String(e.isPanelOpen)))}function Rt(o,e){const t=o.querySelector(".tbw-tool-panel");t&&(t.classList.toggle("open",e.isPanelOpen),e.isPanelOpen||(t.style.width=""))}function oo(o){for(const e of o.headerContentCleanups.values())e();o.headerContentCleanups.clear();for(const e of o.panelCleanups.values())e();o.panelCleanups.clear();for(const e of o.toolbarContentCleanups.values())e();o.toolbarContentCleanups.clear();for(const e of o.toolbarContents.values())e.onDestroy?.();if(o.isPanelOpen)for(const e of o.expandedSections)o.toolPanels.get(e)?.onClose?.();o.isPanelOpen=!1,o.expandedSections.clear(),o.toolPanels.clear(),o.headerContents.clear(),o.toolbarContents.clear(),o.lightDomHeaderContent=[],o.lightDomToolPanelIds.clear(),o.lightDomToolbarContentIds.clear(),o.lightDomContentMoved=!1}function no(o,e){let t=!1;const i={get isInitialized(){return t},setInitialized(n){t=n},get isPanelOpen(){return o.isPanelOpen},get activePanel(){return o.isPanelOpen&&o.expandedSections.size>0?[...o.expandedSections][0]:null},get expandedSections(){return[...o.expandedSections]},openToolPanel(){if(o.isPanelOpen)return;if(o.toolPanels.size===0){console.warn("[tbw-grid] No tool panels registered");return}if(o.isPanelOpen=!0,o.expandedSections.size===0&&o.toolPanels.size>0){const s=[...o.toolPanels.values()].sort((l,a)=>(l.order??100)-(a.order??100))[0];s&&o.expandedSections.add(s.id)}const n=e.getShadow();xt(n,o),Rt(n,o),io(n,o,e.getAccordionIcons()),e.emit("tool-panel-open",{sections:i.expandedSections})},closeToolPanel(){if(!o.isPanelOpen)return;for(const r of o.panelCleanups.values())r();o.panelCleanups.clear();for(const r of o.toolPanels.values())r.onClose?.();o.isPanelOpen=!1;const n=e.getShadow();xt(n,o),Rt(n,o),e.emit("tool-panel-close",{})},toggleToolPanel(){o.isPanelOpen?i.closeToolPanel():i.openToolPanel()},toggleToolPanelSection(n){const r=o.toolPanels.get(n);if(!r){console.warn(`[tbw-grid] Tool panel section "${n}" not found`);return}if(o.toolPanels.size===1)return;const s=e.getShadow(),l=o.expandedSections.has(n);if(l){const a=o.panelCleanups.get(n);a&&(a(),o.panelCleanups.delete(n)),r.onClose?.(),o.expandedSections.delete(n),Se(s,n,!1)}else{for(const[a,c]of o.toolPanels)if(a!==n&&o.expandedSections.has(a)){const d=o.panelCleanups.get(a);d&&(d(),o.panelCleanups.delete(a)),c.onClose?.(),o.expandedSections.delete(a),Se(s,a,!1);const u=s.querySelector(`[data-section="${a}"] .tbw-accordion-content`);u&&(u.innerHTML="")}o.expandedSections.add(n),Se(s,n,!0),ro(s,o,n)}e.emit("tool-panel-section-toggle",{id:n,expanded:!l})},getToolPanels(){return[...o.toolPanels.values()]},registerToolPanel(n){if(o.toolPanels.has(n.id)){console.warn(`[tbw-grid] Tool panel "${n.id}" already registered`);return}o.toolPanels.set(n.id,n),t&&e.refreshShellHeader()},unregisterToolPanel(n){if(o.expandedSections.has(n)){const r=o.panelCleanups.get(n);r&&(r(),o.panelCleanups.delete(n)),o.expandedSections.delete(n)}o.toolPanels.delete(n),t&&e.refreshShellHeader()},getHeaderContents(){return[...o.headerContents.values()]},registerHeaderContent(n){if(o.headerContents.has(n.id)){console.warn(`[tbw-grid] Header content "${n.id}" already registered`);return}o.headerContents.set(n.id,n),t&&Ee(e.getShadow(),o)},unregisterHeaderContent(n){const r=o.headerContentCleanups.get(n);r&&(r(),o.headerContentCleanups.delete(n)),o.headerContents.get(n)?.onDestroy?.(),o.headerContents.delete(n),e.getShadow().querySelector(`[data-header-content="${n}"]`)?.remove()},getToolbarContents(){return[...o.toolbarContents.values()].sort((n,r)=>(n.order??0)-(r.order??0))},registerToolbarContent(n){if(o.toolbarContents.has(n.id)){console.warn(`[tbw-grid] Toolbar content "${n.id}" already registered`);return}o.toolbarContents.set(n.id,n),t&&e.refreshShellHeader()},unregisterToolbarContent(n){const r=o.toolbarContentCleanups.get(n);r&&(r(),o.toolbarContentCleanups.delete(n));const s=o.toolbarContents.get(n);s?.onDestroy&&s.onDestroy(),o.toolbarContents.delete(n),t&&e.refreshShellHeader()}};return i}function Se(o,e,t){const i=o.querySelector(`[data-section="${e}"]`);i&&i.classList.toggle("expanded",t)}function ro(o,e,t){const i=e.toolPanels.get(t);if(!i?.render)return;const n=o.querySelector(`[data-section="${t}"] .tbw-accordion-content`);if(!n)return;const r=i.render(n);r&&e.panelCleanups.set(t,r)}function so(o,e,t,i){const n=vt(e),r=[],s=["tbw-grid-header","tbw-grid-tool-buttons","tbw-grid-tool-panel","tbw-grid-column","tbw-grid-detail","tbw-grid-responsive-card"];for(const l of s)o.querySelectorAll(`:scope > ${l}`).forEach(c=>r.push(c));o.replaceChildren();for(const l of r)o.appendChild(l);if(n){const l=V(i?.toolPanel??F.toolPanel),a=V(i?.expand??F.expand),c=V(i?.collapse??F.collapse),u=[...e?.header?.toolbarContents??[]].sort((b,_)=>(b.order??0)-(_.order??0)),f=[...e?.toolPanels??[]].sort((b,_)=>(b.order??100)-(_.order??100)),p={title:e?.header?.title??void 0,hasPanels:f.length>0,isPanelOpen:t.isPanelOpen,toolPanelIcon:l,configButtons:u.map(b=>({id:b.id,hasElement:!1,hasRender:!!b.render})),apiButtons:[]},g={position:e?.toolPanel?.position??"right",isPanelOpen:t.isPanelOpen,expandIcon:a,collapseIcon:c,panels:f.map(b=>({id:b.id,title:b.title,icon:V(b.icon),isExpanded:t.expandedSections.has(b.id)}))},w=Zi(p),m=Ji(g),y=bt({hasShell:!0,shellHeader:w,shellBody:m});o.appendChild(y)}else{const l=bt({hasShell:!1});o.appendChild(l)}return n}function lo(){return{startY:null,startX:null,scrollTop:null,scrollLeft:null,lastY:null,lastX:null,lastTime:null,velocityY:0,velocityX:0,momentumRaf:0}}function ao(o){o.startY=null,o.startX=null,o.scrollTop=null,o.scrollLeft=null,o.lastY=null,o.lastX=null,o.lastTime=null}function Et(o){o.momentumRaf&&(cancelAnimationFrame(o.momentumRaf),o.momentumRaf=0)}function co(o,e,t){if(o.touches.length!==1)return;Et(e);const i=o.touches[0];e.startY=i.clientY,e.startX=i.clientX,e.lastY=i.clientY,e.lastX=i.clientX,e.lastTime=performance.now(),e.scrollTop=t.fauxScrollbar.scrollTop,e.scrollLeft=t.scrollArea?.scrollLeft??0,e.velocityY=0,e.velocityX=0}function uo(o,e,t){if(o.touches.length!==1||e.startY===null||e.startX===null||e.scrollTop===null||e.scrollLeft===null)return!1;const i=o.touches[0],n=i.clientY,r=i.clientX,s=performance.now(),l=e.startY-n,a=e.startX-r;if(e.lastTime!==null&&e.lastY!==null&&e.lastX!==null){const g=s-e.lastTime;g>0&&(e.velocityY=(e.lastY-n)/g,e.velocityX=(e.lastX-r)/g)}e.lastY=n,e.lastX=r,e.lastTime=s;const{scrollTop:c,scrollHeight:d,clientHeight:u}=t.fauxScrollbar,h=d-u,f=l>0&&c<h||l<0&&c>0;let p=!1;if(t.scrollArea){const{scrollLeft:g,scrollWidth:w,clientWidth:m}=t.scrollArea,y=w-m;p=a>0&&g<y||a<0&&g>0}return f&&(t.fauxScrollbar.scrollTop=e.scrollTop+l),p&&t.scrollArea&&(t.scrollArea.scrollLeft=e.scrollLeft+a),f||p}function ho(o,e){(Math.abs(o.velocityY)>.1||Math.abs(o.velocityX)>.1)&&fo(o,e),ao(o)}function fo(o,e){const n=()=>{o.velocityY*=.95,o.velocityX*=.95;const r=o.velocityY*16,s=o.velocityX*16;Math.abs(o.velocityY)>.01&&(e.fauxScrollbar.scrollTop+=r),Math.abs(o.velocityX)>.01&&e.scrollArea&&(e.scrollArea.scrollLeft+=s),Math.abs(o.velocityY)>.01||Math.abs(o.velocityX)>.01?o.momentumRaf=requestAnimationFrame(n):o.momentumRaf=0};o.momentumRaf=requestAnimationFrame(n)}function go(o,e,t,i){o.addEventListener("touchstart",n=>co(n,e,t),{passive:!0,signal:i}),o.addEventListener("touchmove",n=>{uo(n,e,t)&&n.preventDefault()},{passive:!1,signal:i}),o.addEventListener("touchend",()=>ho(e,t),{passive:!0,signal:i})}const po=[{property:"editable",pluginName:"editing",level:"column",description:'the "editable" column property',importHint:"import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';",isUsed:o=>o===!0},{property:"editor",pluginName:"editing",level:"column",description:'the "editor" column property',importHint:"import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';"},{property:"editorParams",pluginName:"editing",level:"column",description:'the "editorParams" column property',importHint:"import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';"},{property:"group",pluginName:"groupingColumns",level:"column",description:'the "group" column property',importHint:"import { GroupingColumnsPlugin } from '@toolbox-web/grid/plugins/grouping-columns';"},{property:"sticky",pluginName:"pinnedColumns",level:"column",description:'the "sticky" column property',importHint:"import { PinnedColumnsPlugin } from '@toolbox-web/grid/plugins/pinned-columns';",isUsed:o=>o==="left"||o==="right"}],wo=[{property:"columnGroups",pluginName:"groupingColumns",level:"config",description:'the "columnGroups" config property',importHint:"import { GroupingColumnsPlugin } from '@toolbox-web/grid/plugins/grouping-columns';",isUsed:o=>Array.isArray(o)&&o.length>0}],mo={editing:"import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';",selection:"import { SelectionPlugin } from '@toolbox-web/grid/plugins/selection';",reorder:"import { ReorderPlugin } from '@toolbox-web/grid/plugins/reorder';",clipboard:"import { ClipboardPlugin } from '@toolbox-web/grid/plugins/clipboard';",filtering:"import { FilteringPlugin } from '@toolbox-web/grid/plugins/filtering';",multiSort:"import { MultiSortPlugin } from '@toolbox-web/grid/plugins/multi-sort';",groupingRows:"import { GroupingRowsPlugin } from '@toolbox-web/grid/plugins/grouping-rows';",groupingColumns:"import { GroupingColumnsPlugin } from '@toolbox-web/grid/plugins/grouping-columns';",tree:"import { TreePlugin } from '@toolbox-web/grid/plugins/tree';",masterDetail:"import { MasterDetailPlugin } from '@toolbox-web/grid/plugins/master-detail';",pinnedColumns:"import { PinnedColumnsPlugin } from '@toolbox-web/grid/plugins/pinned-columns';",pinnedRows:"import { PinnedRowsPlugin } from '@toolbox-web/grid/plugins/pinned-rows';",visibility:"import { VisibilityPlugin } from '@toolbox-web/grid/plugins/visibility';",undoRedo:"import { UndoRedoPlugin } from '@toolbox-web/grid/plugins/undo-redo';",export:"import { ExportPlugin } from '@toolbox-web/grid/plugins/export';",contextMenu:"import { ContextMenuPlugin } from '@toolbox-web/grid/plugins/context-menu';",pivot:"import { PivotPlugin } from '@toolbox-web/grid/plugins/pivot';",serverSide:"import { ServerSidePlugin } from '@toolbox-web/grid/plugins/server-side';",columnVirtualization:"import { ColumnVirtualizationPlugin } from '@toolbox-web/grid/plugins/column-virtualization';"};function _e(o){return mo[o]??`import { ${G(o)}Plugin } from '@toolbox-web/grid/plugins/${o}';`}function St(){if(typeof window<"u"&&window.location){const o=window.location.hostname;if(o==="localhost"||o==="127.0.0.1"||o==="::1")return!0}return typeof process<"u"&&process.env?.NODE_ENV!=="production"}function G(o){return o.charAt(0).toUpperCase()+o.slice(1)}function _t(o,e){return o.some(t=>t.name===e)}function bo(o,e){const t=po,i=wo,n=new Map;function r(l,a,c,d,u=!1){n.has(l)||n.set(l,{description:a,importHint:c,fields:[],isConfigProperty:u});const h=n.get(l);h.fields.includes(d)||h.fields.push(d)}for(const l of i){const a=o[l.property];(l.isUsed?l.isUsed(a):a!==void 0)&&!_t(e,l.pluginName)&&r(l.pluginName,l.description,l.importHint??_e(l.pluginName),l.property,!0)}const s=o.columns;if(s&&s.length>0)for(const l of s)for(const a of t){const c=l[a.property];if((a.isUsed?a.isUsed(c):c!==void 0)&&!_t(e,a.pluginName)){const u=l.field||"<unknown>";r(a.pluginName,a.description,a.importHint??_e(a.pluginName),u)}}if(n.size>0){const l=[];for(const[a,{description:c,importHint:d,fields:u,isConfigProperty:h}]of n)if(h)l.push(`Config uses ${c}, but the required plugin is not loaded.
28
28
  → Add the plugin to your gridConfig.plugins array:
29
29
  ${d}
30
- plugins: [new ${a.charAt(0).toUpperCase()+a.slice(1)}Plugin(), ...]`);else{const g=u.slice(0,3).join(", ")+(u.length>3?`, ... (${u.length} total)`:"");l.push(`Column(s) [${g}] use ${c}, but the required plugin is not loaded.
30
+ plugins: [new ${a.charAt(0).toUpperCase()+a.slice(1)}Plugin(), ...]`);else{const f=u.slice(0,3).join(", ")+(u.length>3?`, ... (${u.length} total)`:"");l.push(`Column(s) [${f}] use ${c}, but the required plugin is not loaded.
31
31
  → Add the plugin to your gridConfig.plugins array:
32
32
  ${d}
33
33
  plugins: [new ${a.charAt(0).toUpperCase()+a.slice(1)}Plugin(), ...]`)}throw new Error(`[tbw-grid] Configuration error:
@@ -36,45 +36,45 @@ ${l.join(`
36
36
 
37
37
  `)}
38
38
 
39
- This validation helps catch misconfigurations early. The properties listed above require their respective plugins to function.`)}}function cn(n){const e=[],t=[];for(const i of n){const r=i.constructor.manifest;if(r?.configRules)for(const s of r.configRules){const l=i.config;if(s.check(l)){const c=`${`[tbw-grid:${G(i.name)}Plugin]`} Configuration warning: ${s.message}`;s.severity==="error"?e.push(c):t.push(c)}}}if(t.length>0&&xt())for(const i of t)console.warn(i);if(e.length>0)throw new Error(`[tbw-grid] Configuration error:
39
+ This validation helps catch misconfigurations early. The properties listed above require their respective plugins to function.`)}}function vo(o){const e=[],t=[];for(const i of o){const r=i.constructor.manifest;if(r?.configRules)for(const s of r.configRules){const l=i.config;if(s.check(l)){const c=`${`[tbw-grid:${G(i.name)}Plugin]`} Configuration warning: ${s.message}`;s.severity==="error"?e.push(c):t.push(c)}}}if(t.length>0&&St())for(const i of t)console.warn(i);if(e.length>0)throw new Error(`[tbw-grid] Configuration error:
40
40
 
41
41
  ${e.join(`
42
42
 
43
- `)}`)}function dn(n,e){const t=n.name,o=n.constructor.dependencies??[];for(const r of o){const s=r.name,l=r.required??!0,a=r.reason;if(!e.some(d=>d.name===s)){const d=a??`${G(t)}Plugin requires ${G(s)}Plugin`,u=Re(s);if(l)throw new Error(`[tbw-grid] Plugin dependency error:
43
+ `)}`)}function yo(o,e){const t=o.name,n=o.constructor.dependencies??[];for(const r of n){const s=r.name,l=r.required??!0,a=r.reason;if(!e.some(d=>d.name===s)){const d=a??`${G(t)}Plugin requires ${G(s)}Plugin`,u=_e(s);if(l)throw new Error(`[tbw-grid] Plugin dependency error:
44
44
 
45
45
  ${d}.
46
46
 
47
47
  → Add the plugin to your gridConfig.plugins array BEFORE ${G(t)}Plugin:
48
48
  ${u}
49
- plugins: [new ${G(s)}Plugin(), new ${G(t)}Plugin()]`);console.info(`[tbw-grid] ${G(t)}Plugin: Optional "${s}" plugin not found. Some features may be unavailable.`)}}}function un(n){if(!xt())return;const e=new Set(n.map(i=>i.name)),t=new Set;for(const i of n){const r=i.constructor.manifest;if(r?.incompatibleWith){for(const s of r.incompatibleWith)if(e.has(s.name)){const l=[i.name,s.name].sort().join("↔");if(t.has(l))continue;t.add(l),console.warn(`[tbw-grid] Plugin incompatibility warning:
49
+ plugins: [new ${G(s)}Plugin(), new ${G(t)}Plugin()]`);console.info(`[tbw-grid] ${G(t)}Plugin: Optional "${s}" plugin not found. Some features may be unavailable.`)}}}function Co(o){if(!St())return;const e=new Set(o.map(i=>i.name)),t=new Set;for(const i of o){const r=i.constructor.manifest;if(r?.incompatibleWith){for(const s of r.incompatibleWith)if(e.has(s.name)){const l=[i.name,s.name].sort().join("↔");if(t.has(l))continue;t.add(l),console.warn(`[tbw-grid] Plugin incompatibility warning:
50
50
 
51
51
  ${G(i.name)}Plugin and ${G(s.name)}Plugin are both loaded, but they are currently incompatible.
52
52
 
53
53
  → ${s.reason}
54
54
 
55
- Consider removing one of these plugins to avoid unexpected behavior.`)}}}}class Rt{constructor(e){this.grid=e}plugins=[];getPlugins(){return this.plugins}pluginMap=new Map;cellRenderers=new Map;headerRenderers=new Map;cellEditors=new Map;attachAll(e){for(const t of e)this.attach(t)}attach(e){if(dn(e,this.plugins),this.pluginMap.set(e.constructor,e),this.plugins.push(e),e.cellRenderers)for(const[t,i]of Object.entries(e.cellRenderers))this.cellRenderers.set(t,i);if(e.headerRenderers)for(const[t,i]of Object.entries(e.headerRenderers))this.headerRenderers.set(t,i);if(e.cellEditors)for(const[t,i]of Object.entries(e.cellEditors))this.cellEditors.set(t,i);e.attach(this.grid);for(const t of this.plugins)t!==e&&t.onPluginAttached&&t.onPluginAttached(e.name,e)}detachAll(){for(const e of this.plugins)for(const t of this.plugins)t!==e&&t.onPluginDetached&&t.onPluginDetached(e.name);for(let e=this.plugins.length-1;e>=0;e--)this.plugins[e].detach();this.plugins=[],this.pluginMap.clear(),this.cellRenderers.clear(),this.headerRenderers.clear(),this.cellEditors.clear()}getPlugin(e){return this.pluginMap.get(e)}getPluginByName(e){return this.plugins.find(t=>t.name===e)}hasPlugin(e){return this.pluginMap.has(e)}getAll(){return this.plugins}getRegisteredPluginNames(){return this.plugins.map(e=>e.name)}getCellRenderer(e){return this.cellRenderers.get(e)}getHeaderRenderer(e){return this.headerRenderers.get(e)}getCellEditor(e){return this.cellEditors.get(e)}getPluginStyles(){return this.plugins.filter(e=>e.styles).map(e=>({name:e.name,styles:e.styles}))}processRows(e){let t=[...e];for(const i of this.plugins)i.processRows&&(t=i.processRows(t));return t}processColumns(e){let t=[...e];for(const i of this.plugins)i.processColumns&&(t=i.processColumns(t));return t}beforeRender(){for(const e of this.plugins)e.beforeRender?.()}afterRender(){for(const e of this.plugins)e.afterRender?.()}onScrollRender(){for(const e of this.plugins)e.onScrollRender?.()}getExtraHeight(){let e=0;for(const t of this.plugins)typeof t.getExtraHeight=="function"&&(e+=t.getExtraHeight());return e}hasExtraHeight(){for(const e of this.plugins)if(typeof e.getExtraHeight=="function"&&e.getExtraHeight()>0)return!0;return!1}getExtraHeightBefore(e){let t=0;for(const i of this.plugins)typeof i.getExtraHeightBefore=="function"&&(t+=i.getExtraHeightBefore(e));return t}adjustVirtualStart(e,t,i){let o=e;for(const r of this.plugins)if(typeof r.adjustVirtualStart=="function"){const s=r.adjustVirtualStart(e,t,i);s<o&&(o=s)}return o}renderRow(e,t,i){for(const o of this.plugins)if(o.renderRow?.(e,t,i))return!0;return!1}queryPlugins(e){const t=[];for(const i of this.plugins){const o=i.onPluginQuery?.(e);o!==void 0&&t.push(o)}return t}onKeyDown(e){for(const t of this.plugins)if(t.onKeyDown?.(e))return!0;return!1}onCellClick(e){for(const t of this.plugins)if(t.onCellClick?.(e))return!0;return!1}onRowClick(e){for(const t of this.plugins)if(t.onRowClick?.(e))return!0;return!1}onHeaderClick(e){for(const t of this.plugins)if(t.onHeaderClick?.(e))return!0;return!1}onScroll(e){for(const t of this.plugins)t.onScroll?.(e)}onCellMouseDown(e){for(const t of this.plugins)if(t.onCellMouseDown?.(e))return!0;return!1}onCellMouseMove(e){for(const t of this.plugins)if(t.onCellMouseMove?.(e))return!0;return!1}onCellMouseUp(e){for(const t of this.plugins)if(t.onCellMouseUp?.(e))return!0;return!1}getHorizontalScrollOffsets(e,t){let i=0,o=0,r=!1;for(const s of this.plugins){const l=s.getHorizontalScrollOffsets?.(e,t);l&&(i+=l.left,o+=l.right,l.skipScroll&&(r=!0))}return{left:i,right:o,skipScroll:r}}getToolPanels(){const e=[];for(const t of this.plugins){const i=t.getToolPanel?.();i&&e.push({plugin:t,panel:i})}return e.sort((t,i)=>(t.panel.order??0)-(i.panel.order??0))}getHeaderContents(){const e=[];for(const t of this.plugins){const i=t.getHeaderContent?.();i&&e.push({plugin:t,content:i})}return e.sort((t,i)=>(t.content.order??0)-(i.content.order??0))}}class D extends HTMLElement{static tagName="tbw-grid";static version=typeof __GRID_VERSION__<"u"?__GRID_VERSION__:"dev";static adapters=[];static registerAdapter(e){this.adapters.push(e)}static getAdapters(){return this.adapters}static clearAdapters(){this.adapters=[]}static get observedAttributes(){return["rows","columns","grid-config","fit-mode"]}get#e(){return this}#n=!1;#d;#c;#s=[];get#i(){return this.#o?.effective??{}}#h=!1;#u=!1;#p={rows:!1,columns:!1,gridConfig:!1,fitMode:!1};#l;#w=0;#m=null;#a=!1;#b;#v=Zi();#g;#y;#x;#C;#E={scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0};#r;#R;#S=!1;#_;#L;#o;#t=Bi();#f;#D;#I=new Map;_rows=[];#z=[];get _columns(){return this.#i.columns??[]}set _columns(e){this.#i.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;_restoreFocusAfterRender=!1;_sortState=null;_gridTemplate="";__rowRenderEpoch=0;__didInitialAutoSize=!1;get __lightDomColumnsCache(){return this.#o?.lightDomColumnsCache}set __lightDomColumnsCache(e){this.#o&&(this.#o.lightDomColumnsCache=e)}get __originalColumnNodes(){return this.#o?.originalColumnNodes}set __originalColumnNodes(e){this.#o&&(this.#o.originalColumnNodes=e)}__originalOrder=[];__frameworkAdapter;__rowsBodyEl=null;get rows(){return this._rows}set rows(e){const t=this.#s;this.#s=e,t!==e&&this.#N("rows")}get sourceRows(){return this.#s}get columns(){return[...this._columns]}set columns(e){const t=this.#o?.getColumns();this.#o?.setColumns(e),t!==e&&this.#N("columns")}get gridConfig(){return this.#i}set gridConfig(e){const t=this.#o?.getGridConfig();this.#o?.setGridConfig(e),t!==e&&(this.#o.clearLightDomCache(),this.#N("gridConfig"))}get fitMode(){return this.#i.fitMode??"stretch"}set fitMode(e){const t=this.#o?.getFitMode();this.#o?.setFitMode(e),t!==e&&this.#N("fitMode")}get effectiveConfig(){return this.#i}get disconnectSignal(){return this.#g||(this.#g=new AbortController),this.#g.signal}constructor(){super(),this.#le(),this.#d=new Promise(e=>this.#c=e),this.#l=new Fi({mergeConfig:()=>{this.#o.parseLightDomColumns(this),this.#o.merge(),this.#X(),an(this.#i,this.#r?.getPlugins()??[]),cn(this.#r?.getPlugins()??[]),un(this.#r?.getPlugins()??[]),this.#z=[...this._columns]},processColumns:()=>this.#me(),processRows:()=>this.#be(),renderHeader:()=>he(this),updateTemplate:()=>te(this),renderVirtualWindow:()=>this.refreshVirtualWindow(!0,!0),afterRender:()=>{this.#r?.afterRender(),this.#i.fitMode==="fixed"&&!this.__didInitialAutoSize&&(this.__didInitialAutoSize=!0,je(this)),this._restoreFocusAfterRender&&(this._restoreFocusAfterRender=!1,M(this)),this._virtualization.enabled&&!this.#O&&this.#ce()},isConnected:()=>this.isConnected&&this.#h}),this.#l.setInitialReadyResolver(()=>this.#c?.()),this.#f=ji(this.#t,{getShadow:()=>this.#e,getShellConfig:()=>this.#i?.shell,getAccordionIcons:()=>({expand:this.#i?.icons?.expand??q.expand,collapse:this.#i?.icons?.collapse??q.collapse}),emit:(e,t)=>this.#k(e,t),refreshShellHeader:()=>this.refreshShellHeader()}),this.#o=new _i({getRows:()=>this.#s,getSortState:()=>this._sortState,setSortState:e=>{this._sortState=e},onConfigChange:()=>{this.#l.requestPhase(L.FULL,"configChange")},emit:(e,t)=>this.#k(e,t),clearRowPool:()=>{this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++},setup:()=>this.#P(),renderHeader:()=>he(this),updateTemplate:()=>te(this),refreshVirtualWindow:()=>this.#l.requestPhase(L.VIRTUALIZATION,"configManager"),getVirtualization:()=>this._virtualization,setRowHeight:e=>{this._virtualization.rowHeight=e},applyAnimationConfig:e=>this.#ve(e),getShellLightDomTitle:()=>this.#t.lightDomTitle,getShellToolPanels:()=>this.#t.toolPanels,getShellHeaderContents:()=>this.#t.headerContents,getShellToolbarContents:()=>this.#t.toolbarContents,getShellLightDomHeaderContent:()=>this.#t.lightDomHeaderContent,getShellHasToolButtonsContainer:()=>this.#t.hasToolButtonsContainer})}static#j="tbw-grid-styles";static#H="";static#q=new Map;static#se(){let e=document.getElementById(this.#j);return e||(e=document.createElement("style"),e.id=this.#j,e.setAttribute("data-tbw-grid","true"),document.head.appendChild(e)),e}static#F(){const e=this.#se(),t=Array.from(this.#q.values()).join(`
56
- `);e.textContent=`${this.#H}
55
+ Consider removing one of these plugins to avoid unexpected behavior.`)}}}}class At{constructor(e){this.grid=e}plugins=[];getPlugins(){return this.plugins}pluginMap=new Map;cellRenderers=new Map;headerRenderers=new Map;cellEditors=new Map;attachAll(e){for(const t of e)this.attach(t)}attach(e){if(yo(e,this.plugins),this.pluginMap.set(e.constructor,e),this.plugins.push(e),e.cellRenderers)for(const[t,i]of Object.entries(e.cellRenderers))this.cellRenderers.set(t,i);if(e.headerRenderers)for(const[t,i]of Object.entries(e.headerRenderers))this.headerRenderers.set(t,i);if(e.cellEditors)for(const[t,i]of Object.entries(e.cellEditors))this.cellEditors.set(t,i);e.attach(this.grid);for(const t of this.plugins)t!==e&&t.onPluginAttached&&t.onPluginAttached(e.name,e)}detachAll(){for(const e of this.plugins)for(const t of this.plugins)t!==e&&t.onPluginDetached&&t.onPluginDetached(e.name);for(let e=this.plugins.length-1;e>=0;e--)this.plugins[e].detach();this.plugins=[],this.pluginMap.clear(),this.cellRenderers.clear(),this.headerRenderers.clear(),this.cellEditors.clear()}getPlugin(e){return this.pluginMap.get(e)}getPluginByName(e){return this.plugins.find(t=>t.name===e)}hasPlugin(e){return this.pluginMap.has(e)}getAll(){return this.plugins}getRegisteredPluginNames(){return this.plugins.map(e=>e.name)}getCellRenderer(e){return this.cellRenderers.get(e)}getHeaderRenderer(e){return this.headerRenderers.get(e)}getCellEditor(e){return this.cellEditors.get(e)}getPluginStyles(){return this.plugins.filter(e=>e.styles).map(e=>({name:e.name,styles:e.styles}))}processRows(e){let t=[...e];for(const i of this.plugins)i.processRows&&(t=i.processRows(t));return t}processColumns(e){let t=[...e];for(const i of this.plugins)i.processColumns&&(t=i.processColumns(t));return t}beforeRender(){for(const e of this.plugins)e.beforeRender?.()}afterRender(){for(const e of this.plugins)e.afterRender?.()}afterCellRender(e){for(const t of this.plugins)t.afterCellRender?.(e)}hasAfterCellRenderHook(){return this.plugins.some(e=>typeof e.afterCellRender=="function")}afterRowRender(e){for(const t of this.plugins)t.afterRowRender?.(e)}hasAfterRowRenderHook(){return this.plugins.some(e=>typeof e.afterRowRender=="function")}onScrollRender(){for(const e of this.plugins)e.onScrollRender?.()}getExtraHeight(){let e=0;for(const t of this.plugins)typeof t.getExtraHeight=="function"&&(e+=t.getExtraHeight());return e}hasExtraHeight(){for(const e of this.plugins)if(typeof e.getExtraHeight=="function"&&e.getExtraHeight()>0)return!0;return!1}getExtraHeightBefore(e){let t=0;for(const i of this.plugins)typeof i.getExtraHeightBefore=="function"&&(t+=i.getExtraHeightBefore(e));return t}adjustVirtualStart(e,t,i){let n=e;for(const r of this.plugins)if(typeof r.adjustVirtualStart=="function"){const s=r.adjustVirtualStart(e,t,i);s<n&&(n=s)}return n}renderRow(e,t,i){for(const n of this.plugins)if(n.renderRow?.(e,t,i))return!0;return!1}queryPlugins(e){const t=[];for(const i of this.plugins){const n=i.onPluginQuery?.(e);n!==void 0&&t.push(n)}return t}onKeyDown(e){for(const t of this.plugins)if(t.onKeyDown?.(e))return!0;return!1}onCellClick(e){for(const t of this.plugins)if(t.onCellClick?.(e))return!0;return!1}onRowClick(e){for(const t of this.plugins)if(t.onRowClick?.(e))return!0;return!1}onHeaderClick(e){for(const t of this.plugins)if(t.onHeaderClick?.(e))return!0;return!1}onScroll(e){for(const t of this.plugins)t.onScroll?.(e)}onCellMouseDown(e){for(const t of this.plugins)if(t.onCellMouseDown?.(e))return!0;return!1}onCellMouseMove(e){for(const t of this.plugins)if(t.onCellMouseMove?.(e))return!0;return!1}onCellMouseUp(e){for(const t of this.plugins)if(t.onCellMouseUp?.(e))return!0;return!1}getHorizontalScrollOffsets(e,t){let i=0,n=0,r=!1;for(const s of this.plugins){const l=s.getHorizontalScrollOffsets?.(e,t);l&&(i+=l.left,n+=l.right,l.skipScroll&&(r=!0))}return{left:i,right:n,skipScroll:r}}getToolPanels(){const e=[];for(const t of this.plugins){const i=t.getToolPanel?.();i&&e.push({plugin:t,panel:i})}return e.sort((t,i)=>(t.panel.order??0)-(i.panel.order??0))}getHeaderContents(){const e=[];for(const t of this.plugins){const i=t.getHeaderContent?.();i&&e.push({plugin:t,content:i})}return e.sort((t,i)=>(t.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 adapters=[];static registerAdapter(e){this.adapters.push(e)}static getAdapters(){return this.adapters}static clearAdapters(){this.adapters=[]}static get observedAttributes(){return["rows","columns","grid-config","fit-mode"]}get#e(){return this}#o=!1;#d;#c;#s=[];get#i(){return this.#n?.effective??{}}#h=!1;#u=!1;#p={rows:!1,columns:!1,gridConfig:!1,fitMode:!1};#l;#w=0;#m=null;#a=!1;#b;#v=lo();#g;#y;#x;#C;#R={scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0};#r;#E;#S=!1;#_;#L;#n;#t=Qi();#f;#H;#D=new Map;_rows=[];#z=[];get _columns(){return this.#i.columns??[]}set _columns(e){this.#i.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;_restoreFocusAfterRender=!1;_sortState=null;_gridTemplate="";__rowRenderEpoch=0;__didInitialAutoSize=!1;get __lightDomColumnsCache(){return this.#n?.lightDomColumnsCache}set __lightDomColumnsCache(e){this.#n&&(this.#n.lightDomColumnsCache=e)}get __originalColumnNodes(){return this.#n?.originalColumnNodes}set __originalColumnNodes(e){this.#n&&(this.#n.originalColumnNodes=e)}__originalOrder=[];__frameworkAdapter;__rowsBodyEl=null;get rows(){return this._rows}set rows(e){const t=this.#s;this.#s=e,t!==e&&this.#N("rows")}get sourceRows(){return this.#s}get columns(){return[...this._columns]}set columns(e){const t=this.#n?.getColumns();this.#n?.setColumns(e),t!==e&&this.#N("columns")}get gridConfig(){return this.#i}set gridConfig(e){const t=this.#n?.getGridConfig();this.#n?.setGridConfig(e),t!==e&&(this.#n.clearLightDomCache(),this.#N("gridConfig"))}get fitMode(){return this.#i.fitMode??"stretch"}set fitMode(e){const t=this.#n?.getFitMode();this.#n?.setFitMode(e),t!==e&&this.#N("fitMode")}get effectiveConfig(){return this.#i}get disconnectSignal(){return this.#g||(this.#g=new AbortController),this.#g.signal}constructor(){super(),this.#le(),this.#d=new Promise(e=>this.#c=e),this.#l=new Wi({mergeConfig:()=>{this.#n.parseLightDomColumns(this),this.#n.merge(),this.#X(),bo(this.#i,this.#r?.getPlugins()??[]),vo(this.#r?.getPlugins()??[]),Co(this.#r?.getPlugins()??[]),this.#z=[...this._columns]},processColumns:()=>this.#me(),processRows:()=>this.#be(),renderHeader:()=>he(this),updateTemplate:()=>te(this),renderVirtualWindow:()=>this.refreshVirtualWindow(!0,!0),afterRender:()=>{this.#r?.afterRender(),this.#i.fitMode==="fixed"&&!this.__didInitialAutoSize&&(this.__didInitialAutoSize=!0,Xe(this)),this._restoreFocusAfterRender&&(this._restoreFocusAfterRender=!1,N(this)),this._virtualization.enabled&&!this.#O&&this.#ce()},isConnected:()=>this.isConnected&&this.#h}),this.#l.setInitialReadyResolver(()=>this.#c?.()),this.#f=no(this.#t,{getShadow:()=>this.#e,getShellConfig:()=>this.#i?.shell,getAccordionIcons:()=>({expand:this.#i?.icons?.expand??F.expand,collapse:this.#i?.icons?.collapse??F.collapse}),emit:(e,t)=>this.#k(e,t),refreshShellHeader:()=>this.refreshShellHeader()}),this.#n=new Pi({getRows:()=>this.#s,getSortState:()=>this._sortState,setSortState:e=>{this._sortState=e},onConfigChange:()=>{this.#l.requestPhase(D.FULL,"configChange")},emit:(e,t)=>this.#k(e,t),clearRowPool:()=>{this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++},setup:()=>this.#P(),renderHeader:()=>he(this),updateTemplate:()=>te(this),refreshVirtualWindow:()=>this.#l.requestPhase(D.VIRTUALIZATION,"configManager"),getVirtualization:()=>this._virtualization,setRowHeight:e=>{this._virtualization.rowHeight=e},applyAnimationConfig:e=>this.#ve(e),getShellLightDomTitle:()=>this.#t.lightDomTitle,getShellToolPanels:()=>this.#t.toolPanels,getShellHeaderContents:()=>this.#t.headerContents,getShellToolbarContents:()=>this.#t.toolbarContents,getShellLightDomHeaderContent:()=>this.#t.lightDomHeaderContent,getShellHasToolButtonsContainer:()=>this.#t.hasToolButtonsContainer})}static#j="tbw-grid-styles";static#I="";static#q=new Map;static#se(){let e=document.getElementById(this.#j);return e||(e=document.createElement("style"),e.id=this.#j,e.setAttribute("data-tbw-grid","true"),document.head.appendChild(e)),e}static#F(){const e=this.#se(),t=Array.from(this.#q.values()).join(`
56
+ `);e.textContent=`${this.#I}
57
57
 
58
58
  /* Plugin Styles */
59
- ${t}`}async#le(){if(!D.#H){if(j.length>0){D.#H=j,D.#F();return}await new Promise(e=>setTimeout(e,50));try{let e="";for(const t of Array.from(document.styleSheets))try{const o=Array.from(t.cssRules||[]).map(r=>r.cssText).join(`
60
- `);if(o.includes(".tbw-grid-root")&&o.includes("tbw-grid")){e=o;break}}catch{continue}e?(D.#H=e,D.#F()):(typeof process>"u"||process.env?.NODE_ENV!=="test")&&console.warn("[tbw-grid] Could not find grid.css in document.styleSheets. Grid styling will not work.","Available stylesheets:",Array.from(document.styleSheets).map(t=>t.href||"(inline)"))}catch(e){console.warn("[tbw-grid] Failed to extract grid.css from document stylesheets:",e)}}}getPlugin(e){return this.#r?.getPlugin(e)}getPluginByName(e){return this.#r?.getPluginByName(e)}requestRender(){this.#l.requestPhase(L.ROWS,"plugin:requestRender")}requestRenderWithFocus(){this._restoreFocusAfterRender=!0,this.#l.requestPhase(L.ROWS,"plugin:requestRenderWithFocus")}updateTemplate(){te(this)}requestAfterRender(){this.#l.requestPhase(L.STYLE,"plugin:requestAfterRender")}#Y(){this.#r=new Rt(this);const e=this.#i?.plugins,t=Array.isArray(e)?e:[];this.#r.attachAll(t)}#M(){const e=this.#r?.getPluginStyles()??[];let t=!1;for(const{name:i,styles:o}of e)D.#q.has(i)||(D.#q.set(i,o),t=!0);t&&D.#F()}#X(){const e=this.#i?.plugins,t=Array.isArray(e)?e:[];if(this.#R!==t){if(this.#R&&this.#R.length===t.length&&this.#R.every((i,o)=>i===t[o])){this.#R=t;return}this.#r&&this.#r.detachAll();for(const i of this.#t.toolPanels.keys()){const o=this.#t.lightDomToolPanelIds.has(i),r=this.#t.apiToolPanelIds.has(i);if(!o&&!r){const s=this.#t.panelCleanups.get(i);s&&(s(),this.#t.panelCleanups.delete(i)),this.#t.toolPanels.delete(i)}}for(const i of this.#t.headerContents.keys()){const o=this.#t.headerContentCleanups.get(i);o&&(o(),this.#t.headerContentCleanups.delete(i)),this.#t.headerContents.delete(i)}this.#Y(),this.#M(),this.#R=t,this.#Z(),this.#a=this.#r?.getAll().some(i=>i.onScroll)??!1}}#ae(){this.#r?.detachAll()}#Z(){if(!this.#r)return;const e=this.#r.getToolPanels();for(const{panel:i}of e)this.#t.toolPanels.has(i.id)||this.#t.toolPanels.set(i.id,i);const t=this.#r.getHeaderContents();for(const{content:i}of t)this.#t.headerContents.has(i.id)||this.#t.headerContents.set(i.id,i)}#T(){const e=D.getAdapters();if(e.length===0&&!this.__frameworkAdapter)return;const t=this.__frameworkAdapter;return i=>{if(t?.createToolPanelRenderer){const o=t.createToolPanelRenderer(i);if(o)return o}for(const o of e)if(o.createToolPanelRenderer){const r=o.createToolPanelRenderer(i);if(r)return r}}}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.hasAttribute("version")||this.setAttribute("version",D.version),this._rows=Array.isArray(this.#s)?[...this.#s]:[],this.#g&&(this.#g.abort(),this.#S=!1),this.#g=new AbortController,this.#C&&(dt(this.#C),this.#C=void 0),X(this,this.#t),Z(this,this.#t),J(this,this.#t,this.#T()),this.#o.parseLightDomColumns(this),this.#o.merge(),this.#Y();const e=this.#i?.plugins;this.#R=Array.isArray(e)?e:[],this.#Z(),this.#n||(this.#$(),this.#M(),this.#n=!0),this.#J(),this.#C=qi(()=>{this.#Ee()},{timeout:100})}disconnectedCallback(){this.#C&&(dt(this.#C),this.#C=void 0),this.#ae(),Ui(this.#t),this.#f.setInitialized(!1),this.#D?.(),this.#D=void 0,Ct(this.#v),this.#g&&(this.#g.abort(),this.#g=void 0),this.#_?.abort(),this.#_=void 0,this.#S=!1,this._resizeController&&this._resizeController.dispose(),this.#y&&(this.#y.disconnect(),this.#y=void 0),this.#x&&(this.#x.disconnect(),this.#x=void 0,this.#O=!1),de(this),this.#A.clear(),this.#R=void 0;for(const e of this._rowPool)e.remove();this._rowPool.length=0,this.__rowsBodyEl=null,this.#h=!1}attributeChangedCallback(e,t,i){if(!(t===i||!i||i==="null"||i==="undefined"))if(e==="rows"||e==="columns"||e==="grid-config")try{const o=JSON.parse(i);e==="rows"?this.rows=o:e==="columns"?this.columns=o:e==="grid-config"&&(this.gridConfig=o)}catch{console.warn(`[tbw-grid] Invalid JSON for '${e}' attribute:`,i)}else e==="fit-mode"&&(this.fitMode=i)}#J(){const t=this.#e.querySelector(".tbw-grid-content")??this.#e.querySelector(".tbw-grid-root");if(this._headerRowEl=t?.querySelector(".header-row"),this._virtualization.totalHeightEl=t?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=t?.querySelector(".rows-viewport"),this._bodyEl=t?.querySelector(".rows"),this.__rowsBodyEl=t?.querySelector(".rows-body"),this.#f.isInitialized){xe(this.#e,this.#t),bt(this.#e,this.#i?.shell,this.#t);const r=this.#i?.shell?.toolPanel?.defaultOpen;r&&this.#t.toolPanels.has(r)&&(this.openToolPanel(),this.#t.expandedSections.add(r))}if(this.setAttribute("data-upgraded",""),this.#h=!0,this._resizeController=ut(this),this.#P(),this.#ee(t),this.#S)return;this.#S=!0;const i=this.disconnectSignal;Ni(this,this,this.#e,i);const o=this.#i.rowHeight;o&&o>0?this._virtualization.rowHeight=o:requestAnimationFrame(()=>this.#Q()),queueMicrotask(()=>this.#de()),this.#l.requestPhase(L.FULL,"afterConnect")}#Q(){if(this.#r.hasExtraHeight())return;const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const t=e.querySelectorAll(".cell");let i=0;t.forEach(s=>{const l=s.offsetHeight;l>i&&(i=l)});const o=e.getBoundingClientRect(),r=Math.max(o.height,i);r>0&&Math.abs(r-this._virtualization.rowHeight)>1&&(this._virtualization.rowHeight=r,this.#l.requestPhase(L.VIRTUALIZATION,"measureRowHeight"))}#ee(e){this.#_?.abort(),this.#_=new AbortController;const t=this.#_.signal,i=e?.querySelector(".faux-vscroll"),o=e?.querySelector(".rows");if(this._virtualization.container=i??this,this.#a=this.#r?.getAll().some(r=>r.onScroll)??!1,i&&o){i.addEventListener("scroll",()=>{if(!this._virtualization.enabled&&!this.#a)return;const l=i.scrollTop,a=this._virtualization.rowHeight;if(this._rows.length<=this._virtualization.bypassThreshold)o.style.transform=`translateY(${-l}px)`;else{const c=Math.floor(l/a),d=c-c%2,u=-(l-d*a);o.style.transform=`translateY(${u}px)`}this.#m=l,this.#w||(this.#w=requestAnimationFrame(()=>{this.#w=0,this.#m!==null&&(this.#ye(this.#m),this.#m=null)}))},{passive:!0,signal:t});const r=this.#e.querySelector(".tbw-grid-content"),s=this.#e.querySelector(".tbw-scroll-area");r&&(r.addEventListener("wheel",l=>{const a=l.shiftKey||Math.abs(l.deltaX)>Math.abs(l.deltaY);if(a&&s){const c=l.shiftKey?l.deltaY:l.deltaX,{scrollLeft:d,scrollWidth:u,clientWidth:h}=s;(c>0&&d<u-h||c<0&&d>0)&&(l.preventDefault(),s.scrollLeft+=c)}else if(!a){const{scrollTop:c,scrollHeight:d,clientHeight:u}=i;(l.deltaY>0&&c<d-u||l.deltaY<0&&c>0)&&(l.preventDefault(),i.scrollTop+=l.deltaY)}},{passive:!1,signal:t}),on(r,this.#v,{fauxScrollbar:i,scrollArea:s},t))}this._bodyEl&&Oi(this,this._bodyEl,t),this.#y?.disconnect(),this._virtualization.viewportEl&&(this.#y=new ResizeObserver(()=>{this.#l.requestPhase(L.VIRTUALIZATION,"resize-observer")}),this.#y.observe(this._virtualization.viewportEl)),this.#e.addEventListener("focusin",()=>{this.dataset.hasFocus=""},{signal:t}),this.#e.addEventListener("focusout",r=>{const s=r.relatedTarget;(!s||!this.#e.contains(s))&&delete this.dataset.hasFocus},{signal:t})}#O=!1;#ce(){if(this.#O)return;const e=this._bodyEl?.querySelector(".data-grid-row");e&&(this.#O=!0,this.#x?.disconnect(),this.#x=new ResizeObserver(()=>{this.#Q()}),this.#x.observe(e))}#k(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}#de(){this._bodyEl?.querySelectorAll(".data-grid-row")?.forEach((t,i)=>{const o=i===this._focusRow;t.setAttribute("aria-selected",String(o)),t.querySelectorAll(".cell").forEach((r,s)=>{r.setAttribute("aria-selected",String(o&&s===this._focusCol))})})}#N(e){this.#p[e]=!0,!this.#u&&(this.#u=!0,queueMicrotask(()=>this.#ue()))}#ue(){if(!this.#u||!this.#h){this.#u=!1;return}const e=this.#p;if(this.#u=!1,this.#p={rows:!1,columns:!1,gridConfig:!1,fitMode:!1},e.gridConfig){this.#pe(),e.rows&&this.#te();return}e.columns&&this.#fe(),e.rows&&this.#te(),e.fitMode&&this.#ge()}#te(){this._rows=Array.isArray(this.#s)?[...this.#s]:[],this.#G(),this.#l.requestPhase(L.ROWS,"applyRowsUpdate")}#G(){this.#I.clear();const e=this.#i.getRowId;this._rows.forEach((t,i)=>{const o=this.#ie(t,e);o!==void 0&&this.#I.set(o,{row:t,index:i})})}#ie(e,t){if(t)return t(e);const i=e;if("id"in i&&i.id!=null)return String(i.id);if("_id"in i&&i._id!=null)return String(i._id)}#he(e,t){const i=this.#ie(e,t);if(i===void 0)throw new Error('[tbw-grid] Cannot determine row ID. Configure getRowId in gridConfig or ensure rows have an "id" property.');return i}#fe(){de(this),this.#o.merge(),this.#P()}#ge(){this.#o.merge(),this.#i.fitMode==="fixed"?(this.__didInitialAutoSize=!1,je(this)):(this._columns.forEach(t=>{!t.__userResized&&t.__autoSized&&delete t.width}),te(this))}#pe(){X(this,this.#t),Z(this,this.#t);const e=!!this.#e.querySelector(".has-shell"),t=!!this.#e.querySelector(".tbw-tool-panel"),i=this.#e.querySelectorAll(".tbw-accordion-section").length;this.#o.parseLightDomColumns(this),this.#o.merge(),this.#X(),J(this,this.#t,this.#T()),this.#o.markSourcesChanged(),this.#o.merge();const o=wt(this.#i?.shell),r=(this.#i?.shell?.toolPanels?.length??0)>0,s=(this.#i?.shell?.toolPanels?.length??0)!==i;if(e!==o||!e&&o||!t&&r||t&&s){this.#$(),this.#M(),this.#J(),this.#G();return}e&&this.#we(),this.#G(),this.#l.requestPhase(L.COLUMNS,"applyGridConfigUpdate")}#we(){const e=this.#e.querySelector(".tbw-shell-header");if(!e)return;const t=this.#i.shell?.header?.title??this.#t.lightDomTitle;let i=e.querySelector(".tbw-shell-title");t?(i||(i=document.createElement("h2"),i.className="tbw-shell-title",i.setAttribute("part","shell-title"),e.insertBefore(i,e.firstChild)),i.textContent=t):i&&i.remove()}#me(){if(this.#r){const e=this.#z.length>0?this.#z:this._columns,t=e.filter(r=>!r.hidden),i=e.filter(r=>r.hidden),o=this.#r.processColumns([...t]);if(o!==t){new Set(t.map(l=>l.field));const r=new Set(o.map(l=>l.field));!t.some(l=>r.has(l.field))&&o.length>0?this._columns=[...o,...i]:this._columns=[...o,...i]}else this._columns=[...e]}}#be(){de(this);const e=Array.isArray(this.#s)?[...this.#s]:[],t=this.#r?.processRows(e)??e;this._rows=t}#ve(e){const t={...We,...e.animation},i=t.mode??"reduced-motion";let o=1;i===!1||i==="off"?o=0:(i===!0||i==="on")&&(o=1),this.style.setProperty("--tbw-animation-duration",`${t.duration}ms`),this.style.setProperty("--tbw-animation-easing",t.easing??"ease-out"),this.style.setProperty("--tbw-animation-enabled",String(o)),this.dataset.animationMode=typeof i=="boolean"?i?"on":"off":i}#K(e,t,i=this.__rowRenderEpoch){this.#b||(this.#b=(o,r,s)=>this.#r?.renderRow(o,r,s)??!1),Pi(this,e,t,i,this.#b)}#B=-1;#ne=-1;#oe(e,t){if(e===this.#B&&t===this.#ne)return;const i=this.#B;this.#B=e,this.#ne=t,this.__rowsBodyEl&&(this.__rowsBodyEl.setAttribute("aria-rowcount",String(e)),this.__rowsBodyEl.setAttribute("aria-colcount",String(t))),e!==i&&this._bodyEl&&(e>0?this._bodyEl.setAttribute("role","rowgroup"):this._bodyEl.removeAttribute("role"))}#P(){if(this.isConnected&&!(!this._headerRowEl||!this._bodyEl)){if(this.#o.parseLightDomColumns(this),this.#L){const e=this.#L;this.#L=void 0,this.#o.merge();const t=this.#r?.getAll()??[];this.#o.applyState(e,t)}this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),this.#l.requestPhase(L.FULL,"setup")}}#ye(e){if(this.refreshVirtualWindow(!1),this.#r?.onScrollRender(),this.#a){const t=this._virtualization.container,i=this.#E;i.scrollTop=e,i.scrollLeft=t?.scrollLeft??0,i.scrollHeight=t?.scrollHeight??0,i.scrollWidth=t?.scrollWidth??0,i.clientHeight=t?.clientHeight??0,i.clientWidth=t?.clientWidth??0,this.#r?.onScroll(i)}}findHeaderRow(){return this.#e.querySelector(".header-row")}findRenderedRowElement(e){return Array.from(this._bodyEl.querySelectorAll(".data-grid-row")).find(t=>{const i=t.querySelector(".cell[data-row]");return i&&Number(i.getAttribute("data-row"))===e})||null}_dispatchCellClick(e,t,i,o){const r=this._rows[t],s=this._columns[i];if(!r||!s)return!1;const l=s.field,a=r[l],c=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,composed:!0,detail:{rowIndex:t,colIndex:i,field:l,value:a,row:r,cellEl:o,trigger:"pointer",originalEvent:e}});if(this.dispatchEvent(c),c.defaultPrevented)return!0;const d={row:r,rowIndex:t,colIndex:i,field:l,value:a,cellEl:o,originalEvent:e},u=this.#r?.onCellClick(d)??!1;return this.#k("cell-click",d),u}_dispatchRowClick(e,t,i,o){if(!i)return!1;const r={rowIndex:t,row:i,rowEl:o,originalEvent:e},s=this.#r?.onRowClick(r)??!1;return this.#k("row-click",r),s}_dispatchHeaderClick(e,t,i){const o=this._columns[t];if(!o)return!1;const r={colIndex:t,field:o.field,column:o,headerEl:i,originalEvent:e};return this.#r?.onHeaderClick(r)??!1}_dispatchKeyDown(e){return this.#r?.onKeyDown(e)??!1}_getHorizontalScrollOffsets(e,t){return this.#r?.getHorizontalScrollOffsets(e,t)??{left:0,right:0}}queryPlugins(e){return this.#r?.queryPlugins(e)??[]}_dispatchCellMouseDown(e){return this.#r?.onCellMouseDown(e)??!1}_dispatchCellMouseMove(e){this.#r?.onCellMouseMove(e)}_dispatchCellMouseUp(e){this.#r?.onCellMouseUp(e)}async ready(){return this.#d}async forceLayout(){return this.#l.requestPhase(L.FULL,"forceLayout"),this.#l.whenReady()}async getConfig(){return Object.freeze({...this.#i||{}})}getRowId(e){return this.#he(e,this.#i.getRowId)}getRow(e){return this.#I.get(e)?.row}updateRow(e,t,i="api"){const o=this.#I.get(e);if(!o)throw new Error(`[tbw-grid] Row with ID "${e}" not found. Ensure the row exists and getRowId is correctly configured.`);const{row:r,index:s}=o,l=[];for(const[a,c]of Object.entries(t)){const d=r[a];d!==c&&(l.push({field:a,oldValue:d,newValue:c}),r[a]=c)}for(const{field:a,oldValue:c,newValue:d}of l)this.#k("cell-change",{row:r,rowId:e,rowIndex:s,field:a,oldValue:c,newValue:d,changes:t,source:i});l.length>0&&this.#l.requestPhase(L.ROWS,"updateRow")}updateRows(e,t="api"){let i=!1;for(const{id:o,changes:r}of e){const s=this.#I.get(o);if(!s)throw new Error(`[tbw-grid] Row with ID "${o}" not found. Ensure the row exists and getRowId is correctly configured.`);const{row:l,index:a}=s;for(const[c,d]of Object.entries(r)){const u=l[c];u!==d&&(i=!0,l[c]=d,this.#k("cell-change",{row:l,rowId:o,rowIndex:a,field:c,oldValue:u,newValue:d,changes:r,source:t}))}}i&&this.#l.requestPhase(L.ROWS,"updateRows")}setColumnVisible(e,t){const i=this.#o.setColumnVisible(e,t);return i&&this.requestStateChange(),i}toggleColumnVisibility(e){const t=this.#o.toggleColumnVisibility(e);return t&&this.requestStateChange(),t}isColumnVisible(e){return this.#o.isColumnVisible(e)}showAllColumns(){this.#o.showAllColumns(),this.requestStateChange()}getAllColumns(){return this.#o.getAllColumns()}setColumnOrder(e){this.#o.setColumnOrder(e),this.requestStateChange()}getColumnOrder(){return this.#o.getColumnOrder()}getColumnState(){const e=this.#r?.getAll()??[];return this.#o.collectState(e)}set columnState(e){e&&(this.#L=e,this.#o.initialColumnState=e,this.#n&&this.#Ce(e))}get columnState(){return this.getColumnState()}#Ce(e){const t=this.#r?.getAll()??[];this.#o.applyState(e,t),this.#P()}requestStateChange(){const e=this.#r?.getAll()??[];this.#o.requestStateChange(e)}resetColumnState(){this.#L=void 0,this.__originalOrder=[];const e=this.#r?.getAll()??[];this.#o.resetState(e),this.#o.merge(),this.#P()}get isToolPanelOpen(){return this.#f.isPanelOpen}get expandedToolPanelSections(){return this.#f.expandedSections}openToolPanel(){this.#f.openToolPanel()}closeToolPanel(){this.#f.closeToolPanel()}toggleToolPanel(){this.#f.toggleToolPanel()}toggleToolPanelSection(e){this.#f.toggleToolPanelSection(e)}getToolPanels(){return this.#f.getToolPanels()}registerToolPanel(e){this.#t.apiToolPanelIds.add(e.id),this.#f.registerToolPanel(e)}unregisterToolPanel(e){this.#t.apiToolPanelIds.delete(e),this.#f.unregisterToolPanel(e)}getHeaderContents(){return this.#f.getHeaderContents()}registerHeaderContent(e){this.#f.registerHeaderContent(e)}unregisterHeaderContent(e){this.#f.unregisterHeaderContent(e)}getToolbarContents(){return this.#f.getToolbarContents()}registerToolbarContent(e){this.#f.registerToolbarContent(e)}unregisterToolbarContent(e){this.#f.unregisterToolbarContent(e)}#V=!1;refreshShellHeader(){this.#V||(this.#V=!0,queueMicrotask(()=>{this.#V=!1,this.isConnected&&(X(this,this.#t),Z(this,this.#t),J(this,this.#t,this.#T()),this.#o.markSourcesChanged(),this.#o.merge(),this.#$(),this.#M(),this.#xe())}))}#xe(){const t=this.#e.querySelector(".tbw-grid-content")??this.#e.querySelector(".tbw-grid-root");if(this._headerRowEl=t?.querySelector(".header-row"),this._virtualization.totalHeightEl=t?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=t?.querySelector(".rows-viewport"),this._bodyEl=t?.querySelector(".rows"),this.__rowsBodyEl=t?.querySelector(".rows-body"),this.#f.isInitialized){xe(this.#e,this.#t),bt(this.#e,this.#i?.shell,this.#t);const i=this.#i?.shell?.toolPanel?.defaultOpen;i&&this.#t.toolPanels.has(i)&&(this.openToolPanel(),this.#t.expandedSections.add(i))}this._resizeController=ut(this),this.#ee(t),this.#l.requestPhase(L.VIRTUALIZATION,"shellRefresh")}#A=new Map;registerStyles(e,t){let i=this.#A.get(e);i||(i=new CSSStyleSheet,this.#A.set(e,i)),i.replaceSync(t),this.#re()}unregisterStyles(e){this.#A.delete(e)&&this.#re()}getRegisteredStyles(){return Array.from(this.#A.keys())}#re(){const e=Array.from(this.#A.values()),t=document.adoptedStyleSheets.filter(i=>!Array.from(this.#A.values()).includes(i));document.adoptedStyleSheets=[...t,...e]}#Ee(){const e=()=>{const i=this.#t.lightDomTitle,o=this.#t.hasToolButtonsContainer;X(this,this.#t),Z(this,this.#t),J(this,this.#t,this.#T());const r=this.#t.lightDomTitle,s=this.#t.hasToolButtonsContainer;if(r&&!i||s&&!o){this.#o.markSourcesChanged(),this.#o.merge();const l=this.#e.querySelector(".tbw-shell-header");if(l){const a=mt(this.#i.shell,this.#t,this.#i.icons?.toolPanel),c=document.createElement("div");c.innerHTML=a;const d=c.firstElementChild;d&&(l.replaceWith(d),this.#U())}}},t=()=>{this.__lightDomColumnsCache=void 0,this.#P()};this.#o.registerLightDomHandler("tbw-grid-header",e),this.#o.registerLightDomHandler("tbw-grid-tool-buttons",e),this.#o.registerLightDomHandler("tbw-grid-tool-panel",e),this.#o.registerLightDomHandler("tbw-grid-column",t),this.#o.registerLightDomHandler("tbw-grid-detail",t),this.#o.observeLightDOM(this)}refreshColumns(){this.__lightDomColumnsCache=void 0,de(this),this.#o.parseLightDomColumns(this);const e=this.#t.lightDomTitle,t=this.#t.hasToolButtonsContainer;X(this,this.#t),Z(this,this.#t),J(this,this.#t,this.#T());const i=this.#t.lightDomTitle,o=this.#t.hasToolButtonsContainer;if(i&&!e||o&&!t){this.#o.markSourcesChanged(),this.#o.merge();const s=this.#e.querySelector(".tbw-shell-header");if(s){const l=mt(this.#i.shell,this.#t,this.#i.icons?.toolPanel),a=document.createElement("div");a.innerHTML=l;const c=a.firstElementChild;c&&(s.replaceWith(c),this.#U())}}this.#l.requestPhase(L.COLUMNS,"refreshColumns")}#W(e){const t=this._virtualization.rowHeight,i=this._virtualization.container??this,o=this._virtualization.viewportEl??i,r=i.clientHeight,s=o.clientHeight,a=this.shadowRoot?.querySelector(".tbw-scroll-area"),c=a?a.clientHeight:r,u=c-s,h=this.#r?.getExtraHeight()??0,g=Math.max(0,r-c);return e*t+u+h+g}refreshVirtualWindow(e=!1,t=!1){if(!this._bodyEl)return;const i=this._rows.length;if(!this._virtualization.enabled){this.#K(0,i),t||this.#r?.afterRender();return}if(this._rows.length<=this._virtualization.bypassThreshold){this._virtualization.start=0,this._virtualization.end=i,e&&(this._bodyEl.style.transform="translateY(0px)"),this.#K(0,i,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${this.#W(i)}px`),this.#oe(i,this._visibleColumns.length),t||this.#r?.afterRender();return}const o=this._virtualization.container??this,r=this._virtualization.viewportEl??o,s=r.clientHeight,l=this._virtualization.rowHeight,a=o.scrollTop;let c=Math.floor(a/l),d=0;const u=10;for(;d<u;){const v=this.#r?.getExtraHeightBefore?.(c)??0,b=Math.floor((a-v)/l);if(b>=c||b<0)break;c=b,d++}c=c-c%2,c<0&&(c=0);const h=this.#r?.adjustVirtualStart(c,a,l);h!==void 0&&h<c&&(c=h,c=c-c%2,c<0&&(c=0));const g=Math.ceil(s/l)+3;let f=c+g;if(f>i&&(f=i),this._virtualization.start=c,this._virtualization.end=f,o.clientHeight===0&&s>0){this.#l.requestPhase(L.VIRTUALIZATION,"stale-refs-retry");return}const w=this.#W(i);this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${w}px`);const m=this.#r?.getExtraHeightBefore?.(c)??0,C=-(a-c*l-m);this._bodyEl.style.transform=`translateY(${C}px)`,this.#K(c,f,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),this.#oe(i,this._visibleColumns.length),e&&!t&&(this.#r?.afterRender(),queueMicrotask(()=>{const v=o.clientHeight,b=r.clientHeight;if(v===0&&b>0)return;const R=this.#W(i);this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${R}px`)}))}#$(){X(this,this.#t),Z(this,this.#t),J(this,this.#t,this.#T()),this.#o.markSourcesChanged(),this.#o.merge();const e=this.#i?.shell;Xi(this.#e,e,{isPanelOpen:this.#t.isPanelOpen,expandedSections:this.#t.expandedSections},this.#i?.icons)&&(this.#U(),this.#f.setInitialized(!0))}#U(){Vi(this.#e,this.#i?.shell,this.#t,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e)}),this.#D?.(),this.#D=Wi(this.#e,this.#i?.shell,e=>{this.style.setProperty("--tbw-tool-panel-width",`${e}px`)})}}customElements.get(D.tagName)||customElements.define(D.tagName,D),globalThis.DataGridElement=D;const Se={CAN_MOVE_COLUMN:"canMoveColumn",GET_CONTEXT_MENU_ITEMS:"getContextMenuItems"};class P{static dependencies;static manifest;version=typeof __GRID_VERSION__<"u"?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const i=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.defaultPrevented}requestRender(){this.grid?.requestRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}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 gridElement(){return this.grid}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...q,...e}}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(e===!1||e==="off")return!1;if(e===!0||e==="on")return!0;const t=this.gridElement;return t?getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()!=="0":!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(t,10);if(!isNaN(i))return i}return 200}resolveIcon(e,t){return t!==void 0?t:this.gridIcons[e]}setIcon(e,t){typeof t=="string"?e.innerHTML=t:t instanceof HTMLElement&&(e.innerHTML="",e.appendChild(t.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}const I={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"},re={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"},hn={ROOT:`.${I.ROOT}`,HEADER:`.${I.HEADER}`,HEADER_ROW:`.${I.HEADER_ROW}`,HEADER_CELL:`.${I.HEADER_CELL}`,ROWS_VIEWPORT:`.${I.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${I.ROWS_CONTAINER}`,DATA_ROW:`.${I.DATA_ROW}`,DATA_CELL:`.${I.DATA_CELL}`,GROUP_ROW:`.${I.GROUP_ROW}`,ROW_BY_INDEX:n=>`.${I.DATA_ROW}[${re.ROW_INDEX}="${n}"]`,CELL_BY_FIELD:n=>`.${I.DATA_CELL}[${re.FIELD}="${n}"]`,CELL_AT:(n,e)=>`.${I.DATA_ROW}[${re.ROW_INDEX}="${n}"] .${I.DATA_CELL}[${re.COL_INDEX}="${e}"]`,SELECTED_ROWS:`.${I.DATA_ROW}.${I.SELECTED}`,EDITING_CELL:`.${I.DATA_CELL}.${I.EDITING}`},fn={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"};function gn(n){const e=document.createElement("tbw-grid");return n&&(e.gridConfig=n),e}function pn(n,e=document){return e.querySelector(n)}const wn={CELL_CHANGE:"cell-change",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",CELL_ACTIVATE:"cell-activate",GROUP_TOGGLE:"group-toggle",COLUMN_STATE_CHANGE:"column-state-change"},mn={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"},St="__tbw_expander",bn=32;function _e(n){return n.field===St}function B(n){return n.meta?.utility===!0}function vn(n){return n.find(_e)}function yn(n){return{field:St,header:"",width:bn,resizable:!1,sortable:!1,filterable:!1,meta:{lockPosition:!0,suppressMovable:!0,expanderColumn:!0,expanderPlugin:n,utility:!0}}}async function Ae(n){try{return await navigator.clipboard.writeText(n),!0}catch{const e=document.createElement("textarea");e.value=n,e.style.position="fixed",e.style.opacity="0",e.style.pointerEvents="none",document.body.appendChild(e),e.select();const t=document.execCommand("copy");return document.body.removeChild(e),t}}function _t(n,e){const t=e.delimiter??" ",i=e.newline??`
61
- `,o=n.replace(/\r\n/g,`
59
+ ${t}`}async#le(){if(!I.#I){if(j.length>0){I.#I=j,I.#F();return}await new Promise(e=>setTimeout(e,50));try{let e="";for(const t of Array.from(document.styleSheets))try{const n=Array.from(t.cssRules||[]).map(r=>r.cssText).join(`
60
+ `);if(n.includes(".tbw-grid-root")&&n.includes("tbw-grid")){e=n;break}}catch{continue}e?(I.#I=e,I.#F()):(typeof process>"u"||process.env?.NODE_ENV!=="test")&&console.warn("[tbw-grid] Could not find grid.css in document.styleSheets. Grid styling will not work.","Available stylesheets:",Array.from(document.styleSheets).map(t=>t.href||"(inline)"))}catch(e){console.warn("[tbw-grid] Failed to extract grid.css from document stylesheets:",e)}}}getPlugin(e){return this.#r?.getPlugin(e)}getPluginByName(e){return this.#r?.getPluginByName(e)}requestRender(){this.#l.requestPhase(D.ROWS,"plugin:requestRender")}requestRenderWithFocus(){this._restoreFocusAfterRender=!0,this.#l.requestPhase(D.ROWS,"plugin:requestRenderWithFocus")}updateTemplate(){te(this)}requestAfterRender(){this.#l.requestPhase(D.STYLE,"plugin:requestAfterRender")}#Y(){this.#r=new At(this);const e=this.#i?.plugins,t=Array.isArray(e)?e:[];this.#r.attachAll(t)}#M(){const e=this.#r?.getPluginStyles()??[];let t=!1;for(const{name:i,styles:n}of e)I.#q.has(i)||(I.#q.set(i,n),t=!0);t&&I.#F()}#X(){const e=this.#i?.plugins,t=Array.isArray(e)?e:[];if(this.#E!==t){if(this.#E&&this.#E.length===t.length&&this.#E.every((i,n)=>i===t[n])){this.#E=t;return}this.#r&&this.#r.detachAll();for(const i of this.#t.toolPanels.keys()){const n=this.#t.lightDomToolPanelIds.has(i),r=this.#t.apiToolPanelIds.has(i);if(!n&&!r){const s=this.#t.panelCleanups.get(i);s&&(s(),this.#t.panelCleanups.delete(i)),this.#t.toolPanels.delete(i)}}for(const i of this.#t.headerContents.keys()){const n=this.#t.headerContentCleanups.get(i);n&&(n(),this.#t.headerContentCleanups.delete(i)),this.#t.headerContents.delete(i)}this.#Y(),this.#M(),this.#E=t,this.#Z(),this.#a=this.#r?.getAll().some(i=>i.onScroll)??!1}}#ae(){this.#r?.detachAll()}#Z(){if(!this.#r)return;const e=this.#r.getToolPanels();for(const{panel:i}of e)this.#t.toolPanels.has(i.id)||this.#t.toolPanels.set(i.id,i);const t=this.#r.getHeaderContents();for(const{content:i}of t)this.#t.headerContents.has(i.id)||this.#t.headerContents.set(i.id,i)}#T(){const e=I.getAdapters();if(e.length===0&&!this.__frameworkAdapter)return;const t=this.__frameworkAdapter;return i=>{if(t?.createToolPanelRenderer){const n=t.createToolPanelRenderer(i);if(n)return n}for(const n of e)if(n.createToolPanelRenderer){const r=n.createToolPanelRenderer(i);if(r)return r}}}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.hasAttribute("version")||this.setAttribute("version",I.version),this._rows=Array.isArray(this.#s)?[...this.#s]:[],this.#g&&(this.#g.abort(),this.#S=!1),this.#g=new AbortController,this.#C&&(ht(this.#C),this.#C=void 0),X(this,this.#t),Z(this,this.#t),J(this,this.#t,this.#T()),this.#n.parseLightDomColumns(this),this.#n.merge(),this.#Y();const e=this.#i?.plugins;this.#E=Array.isArray(e)?e:[],this.#Z(),this.#o||(this.#$(),this.#M(),this.#o=!0),this.#J(),this.#C=Bi(()=>{this.#Re()},{timeout:100})}disconnectedCallback(){this.#C&&(ht(this.#C),this.#C=void 0),this.#ae(),oo(this.#t),this.#f.setInitialized(!1),this.#H?.(),this.#H=void 0,Et(this.#v),this.#g&&(this.#g.abort(),this.#g=void 0),this.#_?.abort(),this.#_=void 0,this.#S=!1,this._resizeController&&this._resizeController.dispose(),this.#y&&(this.#y.disconnect(),this.#y=void 0),this.#x&&(this.#x.disconnect(),this.#x=void 0,this.#O=!1),de(this),this.#A.clear(),this.#E=void 0;for(const e of this._rowPool)e.remove();this._rowPool.length=0,this.__rowsBodyEl=null,this.#h=!1}attributeChangedCallback(e,t,i){if(!(t===i||!i||i==="null"||i==="undefined"))if(e==="rows"||e==="columns"||e==="grid-config")try{const n=JSON.parse(i);e==="rows"?this.rows=n:e==="columns"?this.columns=n:e==="grid-config"&&(this.gridConfig=n)}catch{console.warn(`[tbw-grid] Invalid JSON for '${e}' attribute:`,i)}else e==="fit-mode"&&(this.fitMode=i)}#J(){const t=this.#e.querySelector(".tbw-grid-content")??this.#e.querySelector(".tbw-grid-root");if(this._headerRowEl=t?.querySelector(".header-row"),this._virtualization.totalHeightEl=t?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=t?.querySelector(".rows-viewport"),this._bodyEl=t?.querySelector(".rows"),this.__rowsBodyEl=t?.querySelector(".rows-body"),this.#f.isInitialized){Ee(this.#e,this.#t),Ct(this.#e,this.#i?.shell,this.#t);const r=this.#i?.shell?.toolPanel?.defaultOpen;r&&this.#t.toolPanels.has(r)&&(this.openToolPanel(),this.#t.expandedSections.add(r))}if(this.setAttribute("data-upgraded",""),this.#h=!0,this._resizeController=ft(this),this.#P(),this.#ee(t),this.#S)return;this.#S=!0;const i=this.disconnectSignal;Gi(this,this,this.#e,i);const n=this.#i.rowHeight;n&&n>0?this._virtualization.rowHeight=n:requestAnimationFrame(()=>this.#Q()),queueMicrotask(()=>this.#de()),this.#l.requestPhase(D.FULL,"afterConnect")}#Q(){if(this.#r.hasExtraHeight())return;const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const t=e.querySelectorAll(".cell");let i=0;t.forEach(s=>{const l=s.offsetHeight;l>i&&(i=l)});const n=e.getBoundingClientRect(),r=Math.max(n.height,i);r>0&&Math.abs(r-this._virtualization.rowHeight)>1&&(this._virtualization.rowHeight=r,this.#l.requestPhase(D.VIRTUALIZATION,"measureRowHeight"))}#ee(e){this.#_?.abort(),this.#_=new AbortController;const t=this.#_.signal,i=e?.querySelector(".faux-vscroll"),n=e?.querySelector(".rows");if(this._virtualization.container=i??this,this.#a=this.#r?.getAll().some(r=>r.onScroll)??!1,i&&n){i.addEventListener("scroll",()=>{if(!this._virtualization.enabled&&!this.#a)return;const l=i.scrollTop,a=this._virtualization.rowHeight;if(this._rows.length<=this._virtualization.bypassThreshold)n.style.transform=`translateY(${-l}px)`;else{const c=Math.floor(l/a),d=c-c%2,u=-(l-d*a);n.style.transform=`translateY(${u}px)`}this.#m=l,this.#w||(this.#w=requestAnimationFrame(()=>{this.#w=0,this.#m!==null&&(this.#ye(this.#m),this.#m=null)}))},{passive:!0,signal:t});const r=this.#e.querySelector(".tbw-grid-content"),s=this.#e.querySelector(".tbw-scroll-area");r&&(r.addEventListener("wheel",l=>{const a=l.shiftKey||Math.abs(l.deltaX)>Math.abs(l.deltaY);if(a&&s){const c=l.shiftKey?l.deltaY:l.deltaX,{scrollLeft:d,scrollWidth:u,clientWidth:h}=s;(c>0&&d<u-h||c<0&&d>0)&&(l.preventDefault(),s.scrollLeft+=c)}else if(!a){const{scrollTop:c,scrollHeight:d,clientHeight:u}=i;(l.deltaY>0&&c<d-u||l.deltaY<0&&c>0)&&(l.preventDefault(),i.scrollTop+=l.deltaY)}},{passive:!1,signal:t}),go(r,this.#v,{fauxScrollbar:i,scrollArea:s},t))}this._bodyEl&&Fi(this,this._bodyEl,t),this.#y?.disconnect(),this._virtualization.viewportEl&&(this.#y=new ResizeObserver(()=>{this.#l.requestPhase(D.VIRTUALIZATION,"resize-observer")}),this.#y.observe(this._virtualization.viewportEl)),this.#e.addEventListener("focusin",()=>{this.dataset.hasFocus=""},{signal:t}),this.#e.addEventListener("focusout",r=>{const s=r.relatedTarget;(!s||!this.#e.contains(s))&&delete this.dataset.hasFocus},{signal:t})}#O=!1;#ce(){if(this.#O)return;const e=this._bodyEl?.querySelector(".data-grid-row");e&&(this.#O=!0,this.#x?.disconnect(),this.#x=new ResizeObserver(()=>{this.#Q()}),this.#x.observe(e))}#k(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}#de(){this._bodyEl?.querySelectorAll(".data-grid-row")?.forEach((t,i)=>{const n=i===this._focusRow;t.setAttribute("aria-selected",String(n)),t.querySelectorAll(".cell").forEach((r,s)=>{r.setAttribute("aria-selected",String(n&&s===this._focusCol))})})}#N(e){this.#p[e]=!0,!this.#u&&(this.#u=!0,queueMicrotask(()=>this.#ue()))}#ue(){if(!this.#u||!this.#h){this.#u=!1;return}const e=this.#p;if(this.#u=!1,this.#p={rows:!1,columns:!1,gridConfig:!1,fitMode:!1},e.gridConfig){this.#pe(),e.rows&&this.#te();return}e.columns&&this.#fe(),e.rows&&this.#te(),e.fitMode&&this.#ge()}#te(){this._rows=Array.isArray(this.#s)?[...this.#s]:[],this.#G(),this.#l.requestPhase(D.ROWS,"applyRowsUpdate")}#G(){this.#D.clear();const e=this.#i.getRowId;this._rows.forEach((t,i)=>{const n=this.#ie(t,e);n!==void 0&&this.#D.set(n,{row:t,index:i})})}#ie(e,t){if(t)return t(e);const i=e;if("id"in i&&i.id!=null)return String(i.id);if("_id"in i&&i._id!=null)return String(i._id)}#he(e,t){const i=this.#ie(e,t);if(i===void 0)throw new Error('[tbw-grid] Cannot determine row ID. Configure getRowId in gridConfig or ensure rows have an "id" property.');return i}#fe(){de(this),this.#n.merge(),this.#P()}#ge(){this.#n.merge(),this.#i.fitMode==="fixed"?(this.__didInitialAutoSize=!1,Xe(this)):(this._columns.forEach(t=>{!t.__userResized&&t.__autoSized&&delete t.width}),te(this))}#pe(){X(this,this.#t),Z(this,this.#t);const e=!!this.#e.querySelector(".has-shell"),t=!!this.#e.querySelector(".tbw-tool-panel"),i=this.#e.querySelectorAll(".tbw-accordion-section").length;this.#n.parseLightDomColumns(this),this.#n.merge(),this.#X(),J(this,this.#t,this.#T()),this.#n.markSourcesChanged(),this.#n.merge();const n=vt(this.#i?.shell),r=(this.#i?.shell?.toolPanels?.length??0)>0,s=(this.#i?.shell?.toolPanels?.length??0)!==i;if(e!==n||!e&&n||!t&&r||t&&s){this.#$(),this.#M(),this.#J(),this.#G();return}e&&this.#we(),this.#G(),this.#l.requestPhase(D.COLUMNS,"applyGridConfigUpdate")}#we(){const e=this.#e.querySelector(".tbw-shell-header");if(!e)return;const t=this.#i.shell?.header?.title??this.#t.lightDomTitle;let i=e.querySelector(".tbw-shell-title");t?(i||(i=document.createElement("h2"),i.className="tbw-shell-title",i.setAttribute("part","shell-title"),e.insertBefore(i,e.firstChild)),i.textContent=t):i&&i.remove()}#me(){if(this.#r){const e=this.#z.length>0?this.#z:this._columns,t=e.filter(r=>!r.hidden),i=e.filter(r=>r.hidden),n=this.#r.processColumns([...t]);if(n!==t){new Set(t.map(l=>l.field));const r=new Set(n.map(l=>l.field));!t.some(l=>r.has(l.field))&&n.length>0?this._columns=[...n,...i]:this._columns=[...n,...i]}else this._columns=[...e]}}#be(){de(this);const e=Array.isArray(this.#s)?[...this.#s]:[],t=this.#r?.processRows(e)??e;this._rows=t}#ve(e){const t={...Ue,...e.animation},i=t.mode??"reduced-motion";let n=1;i===!1||i==="off"?n=0:(i===!0||i==="on")&&(n=1),this.style.setProperty("--tbw-animation-duration",`${t.duration}ms`),this.style.setProperty("--tbw-animation-easing",t.easing??"ease-out"),this.style.setProperty("--tbw-animation-enabled",String(n)),this.dataset.animationMode=typeof i=="boolean"?i?"on":"off":i}#K(e,t,i=this.__rowRenderEpoch){this.#b||(this.#b=(n,r,s)=>this.#r?.renderRow(n,r,s)??!1),Ii(this,e,t,i,this.#b)}#B=-1;#oe=-1;#ne(e,t){if(e===this.#B&&t===this.#oe)return;const i=this.#B;this.#B=e,this.#oe=t,this.__rowsBodyEl&&(this.__rowsBodyEl.setAttribute("aria-rowcount",String(e)),this.__rowsBodyEl.setAttribute("aria-colcount",String(t))),e!==i&&this._bodyEl&&(e>0?this._bodyEl.setAttribute("role","rowgroup"):this._bodyEl.removeAttribute("role"))}#P(){if(this.isConnected&&!(!this._headerRowEl||!this._bodyEl)){if(this.#n.parseLightDomColumns(this),this.#L){const e=this.#L;this.#L=void 0,this.#n.merge();const t=this.#r?.getAll()??[];this.#n.applyState(e,t)}this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),this.#l.requestPhase(D.FULL,"setup")}}#ye(e){if(this.refreshVirtualWindow(!1),this.#r?.onScrollRender(),this.#a){const t=this._virtualization.container,i=this.#R;i.scrollTop=e,i.scrollLeft=t?.scrollLeft??0,i.scrollHeight=t?.scrollHeight??0,i.scrollWidth=t?.scrollWidth??0,i.clientHeight=t?.clientHeight??0,i.clientWidth=t?.clientWidth??0,this.#r?.onScroll(i)}}findHeaderRow(){return this.#e.querySelector(".header-row")}findRenderedRowElement(e){return Array.from(this._bodyEl.querySelectorAll(".data-grid-row")).find(t=>{const i=t.querySelector(".cell[data-row]");return i&&Number(i.getAttribute("data-row"))===e})||null}_dispatchCellClick(e,t,i,n){const r=this._rows[t],s=this._columns[i];if(!r||!s)return!1;const l=s.field,a=r[l],c=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,composed:!0,detail:{rowIndex:t,colIndex:i,field:l,value:a,row:r,cellEl:n,trigger:"pointer",originalEvent:e}});if(this.dispatchEvent(c),c.defaultPrevented)return!0;const d={row:r,rowIndex:t,colIndex:i,field:l,value:a,cellEl:n,originalEvent:e},u=this.#r?.onCellClick(d)??!1;return this.#k("cell-click",d),u}_dispatchRowClick(e,t,i,n){if(!i)return!1;const r={rowIndex:t,row:i,rowEl:n,originalEvent:e},s=this.#r?.onRowClick(r)??!1;return this.#k("row-click",r),s}_dispatchHeaderClick(e,t,i){const n=this._columns[t];if(!n)return!1;const r={colIndex:t,field:n.field,column:n,headerEl:i,originalEvent:e};return this.#r?.onHeaderClick(r)??!1}_dispatchKeyDown(e){return this.#r?.onKeyDown(e)??!1}_getHorizontalScrollOffsets(e,t){return this.#r?.getHorizontalScrollOffsets(e,t)??{left:0,right:0}}queryPlugins(e){return this.#r?.queryPlugins(e)??[]}_dispatchCellMouseDown(e){return this.#r?.onCellMouseDown(e)??!1}_dispatchCellMouseMove(e){this.#r?.onCellMouseMove(e)}_dispatchCellMouseUp(e){this.#r?.onCellMouseUp(e)}_afterCellRender(e){this.#r?.afterCellRender(e)}_hasAfterCellRenderHook(){return this.#r?.hasAfterCellRenderHook()??!1}_afterRowRender(e){this.#r?.afterRowRender(e)}_hasAfterRowRenderHook(){return this.#r?.hasAfterRowRenderHook()??!1}async ready(){return this.#d}async forceLayout(){return this.#l.requestPhase(D.FULL,"forceLayout"),this.#l.whenReady()}async getConfig(){return Object.freeze({...this.#i||{}})}getRowId(e){return this.#he(e,this.#i.getRowId)}getRow(e){return this.#D.get(e)?.row}updateRow(e,t,i="api"){const n=this.#D.get(e);if(!n)throw new Error(`[tbw-grid] Row with ID "${e}" not found. Ensure the row exists and getRowId is correctly configured.`);const{row:r,index:s}=n,l=[];for(const[a,c]of Object.entries(t)){const d=r[a];d!==c&&(l.push({field:a,oldValue:d,newValue:c}),r[a]=c)}for(const{field:a,oldValue:c,newValue:d}of l)this.#k("cell-change",{row:r,rowId:e,rowIndex:s,field:a,oldValue:c,newValue:d,changes:t,source:i});l.length>0&&this.#l.requestPhase(D.ROWS,"updateRow")}updateRows(e,t="api"){let i=!1;for(const{id:n,changes:r}of e){const s=this.#D.get(n);if(!s)throw new Error(`[tbw-grid] Row with ID "${n}" not found. Ensure the row exists and getRowId is correctly configured.`);const{row:l,index:a}=s;for(const[c,d]of Object.entries(r)){const u=l[c];u!==d&&(i=!0,l[c]=d,this.#k("cell-change",{row:l,rowId:n,rowIndex:a,field:c,oldValue:u,newValue:d,changes:r,source:t}))}}i&&this.#l.requestPhase(D.ROWS,"updateRows")}animateRow(e,t){Re(this,e,t)}animateRows(e,t){Yi(this,e,t)}animateRowById(e,t){return Xi(this,e,t)}setColumnVisible(e,t){const i=this.#n.setColumnVisible(e,t);return i&&this.requestStateChange(),i}toggleColumnVisibility(e){const t=this.#n.toggleColumnVisibility(e);return t&&this.requestStateChange(),t}isColumnVisible(e){return this.#n.isColumnVisible(e)}showAllColumns(){this.#n.showAllColumns(),this.requestStateChange()}getAllColumns(){return this.#n.getAllColumns()}setColumnOrder(e){this.#n.setColumnOrder(e),this.requestStateChange()}getColumnOrder(){return this.#n.getColumnOrder()}getColumnState(){const e=this.#r?.getAll()??[];return this.#n.collectState(e)}set columnState(e){e&&(this.#L=e,this.#n.initialColumnState=e,this.#o&&this.#Ce(e))}get columnState(){return this.getColumnState()}#Ce(e){const t=this.#r?.getAll()??[];this.#n.applyState(e,t),this.#P()}requestStateChange(){const e=this.#r?.getAll()??[];this.#n.requestStateChange(e)}resetColumnState(){this.#L=void 0,this.__originalOrder=[];const e=this.#r?.getAll()??[];this.#n.resetState(e),this.#n.merge(),this.#P()}get isToolPanelOpen(){return this.#f.isPanelOpen}get expandedToolPanelSections(){return this.#f.expandedSections}openToolPanel(){this.#f.openToolPanel()}closeToolPanel(){this.#f.closeToolPanel()}toggleToolPanel(){this.#f.toggleToolPanel()}toggleToolPanelSection(e){this.#f.toggleToolPanelSection(e)}getToolPanels(){return this.#f.getToolPanels()}registerToolPanel(e){this.#t.apiToolPanelIds.add(e.id),this.#f.registerToolPanel(e)}unregisterToolPanel(e){this.#t.apiToolPanelIds.delete(e),this.#f.unregisterToolPanel(e)}getHeaderContents(){return this.#f.getHeaderContents()}registerHeaderContent(e){this.#f.registerHeaderContent(e)}unregisterHeaderContent(e){this.#f.unregisterHeaderContent(e)}getToolbarContents(){return this.#f.getToolbarContents()}registerToolbarContent(e){this.#f.registerToolbarContent(e)}unregisterToolbarContent(e){this.#f.unregisterToolbarContent(e)}#W=!1;refreshShellHeader(){this.#W||(this.#W=!0,queueMicrotask(()=>{this.#W=!1,this.isConnected&&(X(this,this.#t),Z(this,this.#t),J(this,this.#t,this.#T()),this.#n.markSourcesChanged(),this.#n.merge(),this.#$(),this.#M(),this.#xe())}))}#xe(){const t=this.#e.querySelector(".tbw-grid-content")??this.#e.querySelector(".tbw-grid-root");if(this._headerRowEl=t?.querySelector(".header-row"),this._virtualization.totalHeightEl=t?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=t?.querySelector(".rows-viewport"),this._bodyEl=t?.querySelector(".rows"),this.__rowsBodyEl=t?.querySelector(".rows-body"),this.#f.isInitialized){Ee(this.#e,this.#t),Ct(this.#e,this.#i?.shell,this.#t);const i=this.#i?.shell?.toolPanel?.defaultOpen;i&&this.#t.toolPanels.has(i)&&(this.openToolPanel(),this.#t.expandedSections.add(i))}this._resizeController=ft(this),this.#ee(t),this.#l.requestPhase(D.COLUMNS,"shellRefresh")}#A=new Map;registerStyles(e,t){let i=this.#A.get(e);i||(i=new CSSStyleSheet,this.#A.set(e,i)),i.replaceSync(t),this.#re()}unregisterStyles(e){this.#A.delete(e)&&this.#re()}getRegisteredStyles(){return Array.from(this.#A.keys())}#re(){const e=Array.from(this.#A.values()),t=document.adoptedStyleSheets.filter(i=>!Array.from(this.#A.values()).includes(i));document.adoptedStyleSheets=[...t,...e]}#Re(){const e=()=>{const i=this.#t.lightDomTitle,n=this.#t.hasToolButtonsContainer;X(this,this.#t),Z(this,this.#t),J(this,this.#t,this.#T());const r=this.#t.lightDomTitle,s=this.#t.hasToolButtonsContainer;if(r&&!i||s&&!n){this.#n.markSourcesChanged(),this.#n.merge();const l=this.#e.querySelector(".tbw-shell-header");if(l){const a=yt(this.#i.shell,this.#t,this.#i.icons?.toolPanel),c=document.createElement("div");c.innerHTML=a;const d=c.firstElementChild;d&&(l.replaceWith(d),this.#U())}}},t=()=>{this.__lightDomColumnsCache=void 0,this.#P()};this.#n.registerLightDomHandler("tbw-grid-header",e),this.#n.registerLightDomHandler("tbw-grid-tool-buttons",e),this.#n.registerLightDomHandler("tbw-grid-tool-panel",e),this.#n.registerLightDomHandler("tbw-grid-column",t),this.#n.registerLightDomHandler("tbw-grid-detail",t),this.#n.observeLightDOM(this)}refreshColumns(){this.__lightDomColumnsCache=void 0,de(this),this.#n.parseLightDomColumns(this);const e=this.#t.lightDomTitle,t=this.#t.hasToolButtonsContainer;X(this,this.#t),Z(this,this.#t),J(this,this.#t,this.#T());const i=this.#t.lightDomTitle,n=this.#t.hasToolButtonsContainer;if(i&&!e||n&&!t){this.#n.markSourcesChanged(),this.#n.merge();const s=this.#e.querySelector(".tbw-shell-header");if(s){const l=yt(this.#i.shell,this.#t,this.#i.icons?.toolPanel),a=document.createElement("div");a.innerHTML=l;const c=a.firstElementChild;c&&(s.replaceWith(c),this.#U())}}this.#l.requestPhase(D.COLUMNS,"refreshColumns")}#V(e){const t=this._virtualization.rowHeight,i=this._virtualization.container??this,n=this._virtualization.viewportEl??i,r=i.clientHeight,s=n.clientHeight,a=this.shadowRoot?.querySelector(".tbw-scroll-area"),c=a?a.clientHeight:r,u=c-s,h=this.#r?.getExtraHeight()??0,f=Math.max(0,r-c);return e*t+u+h+f}refreshVirtualWindow(e=!1,t=!1){if(!this._bodyEl)return;const i=this._rows.length;if(!this._virtualization.enabled){this.#K(0,i),t||this.#r?.afterRender();return}if(this._rows.length<=this._virtualization.bypassThreshold){this._virtualization.start=0,this._virtualization.end=i,e&&(this._bodyEl.style.transform="translateY(0px)"),this.#K(0,i,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${this.#V(i)}px`),this.#ne(i,this._visibleColumns.length),t||this.#r?.afterRender();return}const n=this._virtualization.container??this,r=this._virtualization.viewportEl??n,s=r.clientHeight,l=this._virtualization.rowHeight,a=n.scrollTop;let c=Math.floor(a/l),d=0;const u=10;for(;d<u;){const b=this.#r?.getExtraHeightBefore?.(c)??0,_=Math.floor((a-b)/l);if(_>=c||_<0)break;c=_,d++}c=c-c%2,c<0&&(c=0);const h=this.#r?.adjustVirtualStart(c,a,l);h!==void 0&&h<c&&(c=h,c=c-c%2,c<0&&(c=0));const f=Math.ceil(s/l)+3;let p=c+f;if(p>i&&(p=i),this._virtualization.start=c,this._virtualization.end=p,n.clientHeight===0&&s>0){this.#l.requestPhase(D.VIRTUALIZATION,"stale-refs-retry");return}const w=this.#V(i);this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${w}px`);const m=this.#r?.getExtraHeightBefore?.(c)??0,y=-(a-c*l-m);this._bodyEl.style.transform=`translateY(${y}px)`,this.#K(c,p,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),this.#ne(i,this._visibleColumns.length),e&&!t&&(this.#r?.afterRender(),queueMicrotask(()=>{const b=n.clientHeight,_=r.clientHeight;if(b===0&&_>0)return;const x=this.#V(i);this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${x}px`)}))}#$(){X(this,this.#t),Z(this,this.#t),J(this,this.#t,this.#T()),this.#n.markSourcesChanged(),this.#n.merge();const e=this.#i?.shell;so(this.#e,e,{isPanelOpen:this.#t.isPanelOpen,expandedSections:this.#t.expandedSections},this.#i?.icons)&&(this.#U(),this.#f.setInitialized(!0))}#U(){eo(this.#e,this.#i?.shell,this.#t,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e)}),this.#H?.(),this.#H=to(this.#e,this.#i?.shell,e=>{this.style.setProperty("--tbw-tool-panel-width",`${e}px`)})}}customElements.get(I.tagName)||customElements.define(I.tagName,I),globalThis.DataGridElement=I;const Ae={CAN_MOVE_COLUMN:"canMoveColumn",GET_CONTEXT_MENU_ITEMS:"getContextMenuItems"};class L{static dependencies;static manifest;version=typeof __GRID_VERSION__<"u"?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const i=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.defaultPrevented}requestRender(){this.grid?.requestRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}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 gridElement(){return this.grid}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...F,...e}}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(e===!1||e==="off")return!1;if(e===!0||e==="on")return!0;const t=this.gridElement;return t?getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()!=="0":!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(t,10);if(!isNaN(i))return i}return 200}resolveIcon(e,t){return t!==void 0?t:this.gridIcons[e]}setIcon(e,t){typeof t=="string"?e.innerHTML=t:t instanceof HTMLElement&&(e.innerHTML="",e.appendChild(t.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}const H={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"},re={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"},xo={ROOT:`.${H.ROOT}`,HEADER:`.${H.HEADER}`,HEADER_ROW:`.${H.HEADER_ROW}`,HEADER_CELL:`.${H.HEADER_CELL}`,ROWS_VIEWPORT:`.${H.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${H.ROWS_CONTAINER}`,DATA_ROW:`.${H.DATA_ROW}`,DATA_CELL:`.${H.DATA_CELL}`,GROUP_ROW:`.${H.GROUP_ROW}`,ROW_BY_INDEX:o=>`.${H.DATA_ROW}[${re.ROW_INDEX}="${o}"]`,CELL_BY_FIELD:o=>`.${H.DATA_CELL}[${re.FIELD}="${o}"]`,CELL_AT:(o,e)=>`.${H.DATA_ROW}[${re.ROW_INDEX}="${o}"] .${H.DATA_CELL}[${re.COL_INDEX}="${e}"]`,SELECTED_ROWS:`.${H.DATA_ROW}.${H.SELECTED}`,EDITING_CELL:`.${H.DATA_CELL}.${H.EDITING}`},Ro={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"};function Eo(o){const e=document.createElement("tbw-grid");return o&&(e.gridConfig=o),e}function So(o,e=document){return e.querySelector(o)}const _o={CELL_CHANGE:"cell-change",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",CELL_ACTIVATE:"cell-activate",GROUP_TOGGLE:"group-toggle",COLUMN_STATE_CHANGE:"column-state-change"},Ao={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"},Tt="__tbw_expander",To=32;function Te(o){return o.field===Tt}function B(o){return o.meta?.utility===!0}function ko(o){return o.find(Te)}function Po(o){return{field:Tt,header:"",width:To,resizable:!1,sortable:!1,filterable:!1,meta:{lockPosition:!0,suppressMovable:!0,expanderColumn:!0,expanderPlugin:o,utility:!0}}}async function ke(o){try{return await navigator.clipboard.writeText(o),!0}catch{const e=document.createElement("textarea");e.value=o,e.style.position="fixed",e.style.opacity="0",e.style.pointerEvents="none",document.body.appendChild(e),e.select();const t=document.execCommand("copy");return document.body.removeChild(e),t}}function kt(o,e){const t=e.delimiter??" ",i=e.newline??`
61
+ `,n=o.replace(/\r\n/g,`
62
62
  `).replace(/\r/g,`
63
- `),r=[];let s=[],l="",a=!1;for(let c=0;c<o.length;c++){const d=o[c];d==='"'&&!a?a=!0:d==='"'&&a?o[c+1]==='"'?(l+='"',c++):a=!1:d===t&&!a?(s.push(l),l=""):d===i&&!a?(s.push(l),l="",(s.length>1||s.some(u=>u.trim()!==""))&&r.push(s),s=[]):l+=d}return s.push(l),(s.length>1||s.some(c=>c.trim()!==""))&&r.push(s),r}async function Cn(){try{return await navigator.clipboard.readText()}catch{return""}}function At(n,e){const{rows:t,target:i,fields:o}=n;if(!i)return;const r=e.rows,l=(e.effectiveConfig.columns??[]).map(d=>d.field),a=[...r],c=i.bounds?i.bounds.endRow:1/0;t.forEach((d,u)=>{const h=i.row+u;if(!(h>c)){if(i.bounds){if(h>=a.length)return}else for(;h>=a.length;){const g={};l.forEach(f=>g[f]=""),a.push(g)}a[h]={...a[h]},d.forEach((g,f)=>{const p=o[f];p&&(a[h][p]=g)})}}),e.rows=a}class xn extends P{static dependencies=[{name:"selection",required:!1,reason:"Enables copy/paste of selected cells instead of entire grid"}];name="clipboard";get defaultConfig(){return{includeHeaders:!1,delimiter:" ",newline:`
64
- `,quoteStrings:!1}}lastCopied=null;attach(e){super.attach(e),e.addEventListener("paste",t=>this.#n(t),{signal:this.disconnectSignal})}detach(){this.lastCopied=null}onKeyDown(e){return(e.ctrlKey||e.metaKey)&&e.key==="c"?(this.#e(e.target),!0):!1}#e(e){const t=this.#c(),i=t?.getSelection(),o=this.columns.length-1,r=this.rows.length-1;let s;if(i&&i.ranges.length>0){const{mode:a,ranges:c}=i,d=c[c.length-1];a==="row"?s={startRow:d.from.row,startCol:0,endRow:d.to.row,endCol:o}:s={startRow:d.from.row,startCol:d.from.col,endRow:d.to.row,endCol:d.to.col}}else if(!t)s={startRow:0,startCol:0,endRow:r,endCol:o};else{const a=this.#i(e);if(!a)return;s={startRow:a.row,startCol:a.col,endRow:a.row,endCol:a.col}}const l=this.#s(s);Ae(l.text).then(()=>{this.lastCopied={text:l.text,timestamp:Date.now()},this.emit("copy",{text:l.text,rowCount:l.rowCount,columnCount:l.columnCount})})}#n(e){const t=e.clipboardData?.getData("text/plain");if(!t)return;e.preventDefault();const i=_t(t,this.config),r=this.#c()?.getSelection(),s=r?.ranges?.[0],l=s?.from.row??0,a=s?.from.col??0,d=s&&(r?.mode==="range"||r?.mode==="row")&&(s.from.row!==s.to.row||s.from.col!==s.to.col)?{endRow:s.to.row,endCol:s.to.col}:null,u=d?.endCol??this.columns.length-1,h=this.columns[a],g=h?{row:l,col:a,field:h.field,bounds:d}:null,f=[],p=i[0]?.length??0;for(let m=0;m<p&&a+m<=u;m++){const C=this.columns[a+m];C&&!C.hidden&&f.push(C.field)}const w={rows:i,text:t,target:g,fields:f};this.emit("paste",w),this.#d(w)}#d(e){if(!this.grid)return;const{pasteHandler:t}=this.config;if(t===null)return;(t??At)(e,this.grid)}#c(){try{const e=this.grid?.getPluginByName("selection");if(e)return e}catch{}}#s(e){const{startRow:t,startCol:i,endRow:o,endCol:r}=e,s=Math.min(t,o),l=Math.max(t,o),a=Math.min(i,r),c=Math.max(i,r),d=this.config.delimiter??" ",u=this.config.newline??`
65
- `,h=[],g=this.columns.slice(a,c+1).filter(f=>!B(f));if(this.config.includeHeaders){const f=g.map(p=>p.header||p.field);h.push(f.join(d))}for(let f=s;f<=l;f++){const p=this.rows[f];if(!p)continue;const w=g.map(m=>{const C=p[m.field];return C==null?"":C instanceof Date?C.toISOString():String(C)});h.push(w.join(d))}return{text:h.join(u),rowCount:l-s+1,columnCount:c-a+1}}#i(e){const t=e.closest("[data-field-cache]");if(!t)return null;const i=t.dataset.fieldCache,o=t.dataset.row;if(!i||!o)return null;const r=parseInt(o,10);if(isNaN(r))return null;const s=this.columns.findIndex(l=>l.field===i);return s===-1?null:{row:r,col:s}}async copy(){const t=this.#c()?.getSelection(),i=this.columns.length-1;let o={startRow:0,startCol:0,endRow:this.rows.length-1,endCol:i};if(t&&t.ranges.length>0){const s=t.ranges[t.ranges.length-1];t.mode==="row"?o={startRow:s.from.row,startCol:0,endRow:s.to.row,endCol:i}:o={startRow:s.from.row,startCol:s.from.col,endRow:s.to.row,endCol:s.to.col}}const r=this.#s(o);return await Ae(r.text),this.lastCopied={text:r.text,timestamp:Date.now()},r.text}async copyRows(e){if(e.length===0)return"";const t=[...e].sort((s,l)=>s-l),i=this.columns.length-1,o={startRow:t[0],startCol:0,endRow:t[t.length-1],endCol:i},r=this.#s(o);return await Ae(r.text),this.lastCopied={text:r.text,timestamp:Date.now()},r.text}async paste(){const e=await Cn();return e?_t(e,this.config):null}getLastCopied(){return this.lastCopied}}const Tt=100;function Te(n){if(n==null)return Tt;if(typeof n=="number")return n;const e=parseFloat(n);return isNaN(e)?Tt:e}function kt(n){return n.map(e=>Te(e.width))}function Pt(n){const e=[];let t=0;for(const i of n)e.push(t),t+=Te(i.width);return e}function Lt(n){return n.reduce((e,t)=>e+Te(t.width),0)}function En(n,e,t,i,o){const r=t.length;if(r===0)return{startCol:0,endCol:0,visibleColumns:[]};let s=Rn(n,t,i);s=Math.max(0,s-o);const l=n+e;let a=s;for(let d=s;d<r;d++){if(t[d]>=l){a=d-1;break}a=d}a=Math.min(r-1,a+o);const c=[];for(let d=s;d<=a;d++)c.push(d);return{startCol:s,endCol:a,visibleColumns:c}}function Rn(n,e,t){let i=0,o=e.length-1;for(;i<o;){const r=Math.floor((i+o)/2);e[r]+t[r]<=n?i=r+1:o=r}return i}function Sn(n,e,t){return t?n>e:!1}class _n extends P{name="columnVirtualization";get defaultConfig(){return{autoEnable:!0,threshold:30,overscan:3}}isVirtualized=!1;startCol=0;endCol=0;scrollLeft=0;totalWidth=0;columnWidths=[];columnOffsets=[];attach(e){super.attach(e);const t=this.columns;this.columnWidths=kt(t),this.columnOffsets=Pt(t),this.totalWidth=Lt(t),this.endCol=t.length-1}detach(){this.columnWidths=[],this.columnOffsets=[],this.isVirtualized=!1,this.startCol=0,this.endCol=0,this.scrollLeft=0,this.totalWidth=0}processColumns(e){const t=Sn(e.length,this.config.threshold??30,this.config.autoEnable??!0);if(this.isVirtualized=t??!1,this.columnWidths=kt(e),this.columnOffsets=Pt(e),this.totalWidth=Lt(e),!t)return this.startCol=0,this.endCol=e.length-1,[...e];const i=this.grid.clientWidth||800,o=En(this.scrollLeft,i,this.columnOffsets,this.columnWidths,this.config.overscan??3);return this.startCol=o.startCol,this.endCol=o.endCol,o.visibleColumns.map(r=>e[r])}afterRender(){if(!this.isVirtualized)return;const e=this.gridElement;if(!e)return;const t=this.columnOffsets[this.startCol]??0,i=e.querySelector(".header-row"),o=e.querySelectorAll(".data-grid-row");i&&(i.style.paddingLeft=`${t}px`),o.forEach(s=>{s.style.paddingLeft=`${t}px`});const r=e.querySelector(".rows-viewport .rows");r&&(r.style.width=`${this.totalWidth}px`)}onScroll(e){!this.isVirtualized||Math.abs(e.scrollLeft-this.scrollLeft)<1||(this.scrollLeft=e.scrollLeft,this.requestRender())}getIsVirtualized(){return this.isVirtualized}getVisibleColumnRange(){return{start:this.startCol,end:this.endCol}}scrollToColumn(e){const t=this.columnOffsets[e]??0,i=this.grid;i.scrollLeft=t}getColumnOffset(e){return this.columnOffsets[e]??0}getTotalWidth(){return this.totalWidth}}const ke="@layer tbw-plugins{.tbw-context-menu{position:fixed;background:var(--tbw-context-menu-bg, var(--tbw-color-panel-bg, light-dark(#f5f5f5, #2a2a2a)));color:var(--tbw-context-menu-fg, var(--tbw-color-fg, light-dark(#222, #eee)));border:1px solid var(--tbw-context-menu-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-border-radius, .25rem);box-shadow:0 2px 10px var(--tbw-color-shadow, rgba(0, 0, 0, .15));min-width:var(--tbw-menu-min-width, 10rem);padding:var(--tbw-spacing-xs, .25rem) 0;z-index:10000;font-size:var(--tbw-font-size-sm, .8125rem);font-family:var(--tbw-font-family, system-ui, sans-serif)}.tbw-context-menu-item{display:flex;align-items:center;padding:var(--tbw-menu-item-padding, .375rem .75rem);cursor:pointer;gap:var(--tbw-menu-item-gap, .5rem)}.tbw-context-menu-item:hover:not(.disabled){background:var(--tbw-context-menu-hover, var(--tbw-color-row-hover, light-dark(#e8e8e8, #3a3a3a)))}.tbw-context-menu-item.disabled{opacity:.5;cursor:default}.tbw-context-menu-item.danger{color:light-dark(#c00,#f66)}.tbw-context-menu-icon{width:var(--tbw-icon-size, 1rem);text-align:center}.tbw-context-menu-label{flex:1}.tbw-context-menu-shortcut{color:var(--tbw-color-fg-muted, light-dark(#888, #888));font-size:var(--tbw-font-size-xs, .6875rem)}.tbw-context-menu-arrow{font-size:var(--tbw-font-size-2xs, .625rem);color:var(--tbw-color-fg-muted, light-dark(#888, #888))}.tbw-context-menu-separator{height:1px;background:var(--tbw-context-menu-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));margin:var(--tbw-spacing-xs, .25rem) 0}}";function Pe(n,e){return(typeof n=="function"?n(e):n).filter(i=>!(i.hidden===!0||typeof i.hidden=="function"&&i.hidden(e)))}function An(n,e){return n.disabled===!0?!0:typeof n.disabled=="function"?n.disabled(e):!1}function Le(n,e,t,i=q.submenuArrow){const o=document.createElement("div");o.className="tbw-context-menu",o.setAttribute("role","menu");for(const r of n){if(r.separator){const c=document.createElement("div");c.className="tbw-context-menu-separator",c.setAttribute("role","separator"),o.appendChild(c);continue}const s=document.createElement("div");s.className="tbw-context-menu-item",r.cssClass&&s.classList.add(r.cssClass),s.setAttribute("role","menuitem"),s.setAttribute("data-id",r.id);const l=An(r,e);if(l&&(s.classList.add("disabled"),s.setAttribute("aria-disabled","true")),r.icon){const c=document.createElement("span");c.className="tbw-context-menu-icon",c.innerHTML=r.icon,s.appendChild(c)}const a=document.createElement("span");if(a.className="tbw-context-menu-label",a.textContent=r.name,s.appendChild(a),r.shortcut){const c=document.createElement("span");c.className="tbw-context-menu-shortcut",c.textContent=r.shortcut,s.appendChild(c)}if(r.subMenu?.length){const c=document.createElement("span");c.className="tbw-context-menu-arrow",typeof i=="string"?c.innerHTML=i:i instanceof HTMLElement&&c.appendChild(i.cloneNode(!0)),s.appendChild(c),s.addEventListener("mouseenter",()=>{if(s.querySelector(".tbw-context-menu")||!r.subMenu)return;const u=Pe(r.subMenu,e),h=Le(u,e,t,i);h.classList.add("tbw-context-submenu"),h.style.position="absolute",h.style.left="100%",h.style.top="0",s.style.position="relative",s.appendChild(h)}),s.addEventListener("mouseleave",()=>{const d=s.querySelector(".tbw-context-menu");d&&d.remove()})}!l&&r.action&&!r.subMenu&&s.addEventListener("click",c=>{c.stopPropagation(),t(r)}),o.appendChild(s)}return o}function It(n,e,t){n.style.position="fixed",n.style.left=`${e}px`,n.style.top=`${t}px`,n.style.visibility="hidden",n.style.zIndex="10000";const i=n.getBoundingClientRect(),o=window.innerWidth,r=window.innerHeight;let s=e,l=t;e+i.width>o&&(s=e-i.width),t+i.height>r&&(l=t-i.height),s=Math.max(0,s),l=Math.max(0,l),n.style.left=`${s}px`,n.style.top=`${l}px`,n.style.visibility="visible"}let Q=null,ee=null,V=null,Ie=0;const De=[{id:"copy",name:"Copy",shortcut:"Ctrl+C",action:n=>{n.grid?.plugins?.clipboard?.copy?.()}},{separator:!0,id:"sep1",name:""},{id:"export-csv",name:"Export CSV",action:n=>{n.grid?.plugins?.export?.exportCsv?.()}}];class Tn extends P{name="contextMenu";get defaultConfig(){return{items:De}}isOpen=!1;position={x:0,y:0};params=null;menuElement=null;attach(e){super.attach(e),this.installGlobalHandlers(),Ie++}detach(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null),this.isOpen=!1,this.params=null,this.uninstallGlobalHandlers()}installGlobalHandlers(){!V&&typeof document<"u"&&typeof ke=="string"&&ke&&(V=document.createElement("style"),V.id="tbw-context-menu-styles",V.textContent=ke,document.head.appendChild(V)),Q||(Q=()=>{document.querySelectorAll(".tbw-context-menu").forEach(t=>t.remove())},document.addEventListener("click",Q)),ee||(ee=e=>{e.key==="Escape"&&document.querySelectorAll(".tbw-context-menu").forEach(i=>i.remove())},document.addEventListener("keydown",ee))}uninstallGlobalHandlers(){Ie--,!(Ie>0)&&(Q&&(document.removeEventListener("click",Q),Q=null),ee&&(document.removeEventListener("keydown",ee),ee=null),V&&(V.remove(),V=null))}afterRender(){const e=this.gridElement;if(!e)return;const t=e.children[0];t&&t.getAttribute("data-context-menu-bound")!=="true"&&(t.setAttribute("data-context-menu-bound","true"),t.addEventListener("contextmenu",i=>{const o=i;o.preventDefault();const r=o.target,s=r.closest("[data-row][data-col]"),l=r.closest(".header-cell");let a;if(s){const d=parseInt(s.getAttribute("data-row")??"-1",10),u=parseInt(s.getAttribute("data-col")??"-1",10),h=this.columns[u],g=this.rows[d];a={row:g,rowIndex:d,column:h,columnIndex:u,field:h?.field??"",value:g?.[h?.field]??null,isHeader:!1,event:o}}else if(l){const d=parseInt(l.getAttribute("data-col")??"-1",10),u=this.columns[d];a={row:null,rowIndex:-1,column:u,columnIndex:d,field:u?.field??"",value:null,isHeader:!0,event:o}}else return;this.params=a,this.position={x:o.clientX,y:o.clientY};const c=Pe(this.config.items??De,a);c.length&&(this.menuElement&&this.menuElement.remove(),this.menuElement=Le(c,a,d=>{d.action&&d.action(a),this.menuElement?.remove(),this.menuElement=null,this.isOpen=!1},this.gridIcons.submenuArrow),document.body.appendChild(this.menuElement),It(this.menuElement,o.clientX,o.clientY),this.isOpen=!0,this.emit("context-menu-open",{params:a,items:c}))}))}showMenu(e,t,i){const o={row:i.row??null,rowIndex:i.rowIndex??-1,column:i.column??null,columnIndex:i.columnIndex??-1,field:i.field??"",value:i.value??null,isHeader:i.isHeader??!1,event:i.event??new MouseEvent("contextmenu")},r=Pe(this.config.items??De,o);this.menuElement&&this.menuElement.remove(),this.menuElement=Le(r,o,s=>{s.action&&s.action(o),this.menuElement?.remove(),this.menuElement=null,this.isOpen=!1},this.gridIcons.submenuArrow),document.body.appendChild(this.menuElement),It(this.menuElement,e,t),this.isOpen=!0}hideMenu(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null,this.isOpen=!1)}isMenuOpen(){return this.isOpen}}const kn="@layer tbw-plugins{tbw-grid{--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-row-bg: var(--tbw-editing-bg);--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-editing-row-outline-color: var(--tbw-color-accent);--tbw-editing-row-outline-width: 1px}tbw-grid .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}tbw-grid .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex;min-height:calc(var(--tbw-row-height) + 2px);align-items:center;justify-content:center}tbw-grid .data-grid-row>.cell.editing input:not([type=checkbox]),tbw-grid .data-grid-row>.cell.editing select,tbw-grid .data-grid-row>.cell.editing textarea{width:100%;height: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)}tbw-grid .tbw-editor-host{display:contents}}";function Pn(n){const e=n.options;return e?typeof e=="function"?e():e:[]}function Ln(n){return e=>{const t=n.editorParams,i=document.createElement("input");i.type="number",i.value=e.value!=null?String(e.value):"",t?.min!==void 0&&(i.min=String(t.min)),t?.max!==void 0&&(i.max=String(t.max)),t?.step!==void 0&&(i.step=String(t.step)),t?.placeholder&&(i.placeholder=t.placeholder);const o=()=>e.commit(i.value===""?null:Number(i.value));return i.addEventListener("blur",o),i.addEventListener("keydown",r=>{r.key==="Enter"&&o(),r.key==="Escape"&&e.cancel()}),i}}function In(){return n=>{const e=document.createElement("input");return e.type="checkbox",e.checked=!!n.value,e.addEventListener("change",()=>n.commit(e.checked)),e}}function Dn(n){return e=>{const t=n.editorParams,i=document.createElement("input");return i.type="date",e.value instanceof Date&&(i.valueAsDate=e.value),t?.min&&(i.min=t.min),t?.max&&(i.max=t.max),t?.placeholder&&(i.placeholder=t.placeholder),i.addEventListener("change",()=>e.commit(i.valueAsDate)),i.addEventListener("keydown",o=>{o.key==="Escape"&&e.cancel()}),i}}function Hn(n){return e=>{const t=n.editorParams,i=document.createElement("select");if(n.multi&&(i.multiple=!0),t?.includeEmpty){const s=document.createElement("option");s.value="",s.textContent=t.emptyLabel??"",i.appendChild(s)}Pn(n).forEach(s=>{const l=document.createElement("option");l.value=String(s.value),l.textContent=s.label,(n.multi&&Array.isArray(e.value)&&e.value.includes(s.value)||!n.multi&&e.value===s.value)&&(l.selected=!0),i.appendChild(l)});const r=()=>{if(n.multi){const s=Array.from(i.selectedOptions).map(l=>l.value);e.commit(s)}else e.commit(i.value)};return i.addEventListener("change",r),i.addEventListener("blur",r),i.addEventListener("keydown",s=>{s.key==="Escape"&&e.cancel()}),i}}function Mn(n){return e=>{const t=n.editorParams,i=document.createElement("input");return i.type="text",i.value=e.value!=null?String(e.value):"",t?.maxLength!==void 0&&(i.maxLength=t.maxLength),t?.pattern&&(i.pattern=t.pattern),t?.placeholder&&(i.placeholder=t.placeholder),i.addEventListener("blur",()=>e.commit(i.value)),i.addEventListener("keydown",o=>{o.key==="Enter"&&e.commit(i.value),o.key==="Escape"&&e.cancel()}),i}}function Dt(n){switch(n.type){case"number":return Ln(n);case"boolean":return In();case"date":return Dn(n);case"select":return Hn(n);default:return Mn(n)}}const He='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function On(n,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=n.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const o=n.__frameworkAdapter;if(o?.getTypeDefault){const r=o.getTypeDefault(e.type);if(r?.editor)return r.editor}}function se(n){return!(typeof n!="string"||n==="__proto__"||n==="constructor"||n==="prototype")}function Nn(n){const e=(n.__editingCellCount??0)+1;n.__editingCellCount=e,n.setAttribute("data-has-editing","")}function zn(n){n.__editingCellCount=0,n.removeAttribute("data-has-editing")}function le(n,e){return n instanceof HTMLInputElement?n.type==="checkbox"?n.checked:n.type==="number"?n.value===""?null:Number(n.value):n.type==="date"?n.valueAsDate:n.value:e?.type==="number"&&n.value!==""?Number(n.value):n.value}function Ht(n){}function qn(n,e,t){const i=n.querySelector("input,textarea,select");i&&(i.addEventListener("blur",()=>{t(le(i,e))}),i instanceof HTMLInputElement&&i.type==="checkbox"?i.addEventListener("change",()=>t(i.checked)):i instanceof HTMLSelectElement&&i.addEventListener("change",()=>t(le(i,e))))}class Fn extends P{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:e=>e===!0},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'}]};name="editing";styles=kn;get defaultConfig(){return{editOn:"click"}}#e=-1;#n=-1;#d=new Map;#c=new Set;#s=new Set;#i=!1;attach(e){super.attach(e);const t=this.disconnectSignal,i=e;i._activeEditRows=-1,i._rowEditSnapshots=new Map,Object.defineProperty(e,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(e,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),e.resetChangedRows=o=>this.resetChangedRows(o),e.beginBulkEdit=(o,r)=>{r&&this.beginCellEdit(o,r)},document.addEventListener("keydown",o=>{o.key==="Escape"&&this.#e!==-1&&this.#l(this.#e,!0)},{capture:!0,signal:t}),document.addEventListener("mousedown",o=>{if(this.#e===-1)return;const r=i.findRenderedRowElement?.(this.#e);!r||(o.composedPath&&o.composedPath()||[]).includes(r)||this.#l(this.#e,!1)},{signal:t})}detach(){this.#e=-1,this.#n=-1,this.#d.clear(),this.#c.clear(),this.#s.clear(),super.detach()}onCellClick(e){const t=this.grid,i=this.config.editOn??t.effectiveConfig?.editOn;if(i===!1||i==="manual"||i!=="click"&&i!=="dblclick")return!1;const o=e.originalEvent.type==="dblclick";if(i==="click"&&o||i==="dblclick"&&!o)return!1;const{rowIndex:r}=e;return t._columns?.some(l=>l.editable)?(e.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0):!1}onKeyDown(e){const t=this.grid;if(e.key==="Escape"&&this.#e!==-1)return this.#l(this.#e,!0),!0;if(e.key===" "||e.key==="Spacebar"){const i=t._focusRow,o=t._focusCol;if(i>=0&&o>=0){const r=t._visibleColumns[o],s=t._rows[i];if(r?.editable&&r.type==="boolean"&&s){const l=r.field;if(se(l)){const c=!s[l];return this.#w(i,r,c,s),e.preventDefault(),this.requestRender(),!0}}}return!1}if(e.key==="Enter"&&!e.shiftKey){if(this.#e!==-1)return!1;const i=this.config.editOn??t.effectiveConfig?.editOn;if(i===!1||i==="manual")return!1;const o=t._focusRow,r=t._focusCol;if(o>=0&&t._columns?.some(l=>l.editable)){const l=t._visibleColumns[r],a=t._rows[o],c=l?.field??"",d=c&&a?a[c]:void 0,u=this.gridElement.querySelector(`[data-row="${o}"][data-col="${r}"]`),h=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:o,colIndex:r,field:c,value:d,row:a,cellEl:u,trigger:"keyboard",originalEvent:e}});this.gridElement.dispatchEvent(h);const g=new CustomEvent("activate-cell",{cancelable:!0,bubbles:!0,detail:{row:o,col:r}});return this.gridElement.dispatchEvent(g),h.defaultPrevented||g.defaultPrevented?(e.preventDefault(),!0):(this.beginBulkEdit(o),!0)}return!1}return!1}processColumns(e){const t=this.grid,i=t.effectiveConfig?.typeDefaults,o=t.__frameworkAdapter;return!i&&!o?.getTypeDefault?e:e.map(r=>{if(!r.type)return r;let s;if(i?.[r.type]?.editorParams&&(s=i[r.type].editorParams),!s&&o?.getTypeDefault){const l=o.getTypeDefault(r.type);l?.editorParams&&(s=l.editorParams)}return s?{...r,editorParams:{...s,...r.editorParams}}:r})}afterRender(){const e=this.grid;if(this.#i&&(this.#i=!1,this.#b(e)),this.#s.size!==0)for(const t of this.#s){const[i,o]=t.split(":"),r=parseInt(i,10),s=parseInt(o,10),l=e.findRenderedRowElement?.(r);if(!l)continue;const a=l.querySelector(`.cell[data-col="${s}"]`);if(!a||a.classList.contains("editing"))continue;const c=e._rows[r],d=e._visibleColumns[s];c&&d&&this.#m(c,r,d,s,a,!0)}}onScrollRender(){this.afterRender()}get changedRows(){const e=[];for(const t of this.#c){const i=this.grid.getRow(t);i&&e.push(i)}return e}get changedRowIds(){return Array.from(this.#c)}get activeEditRow(){return this.#e}get activeEditCol(){return this.#n}isRowEditing(e){return this.#e===e}isCellEditing(e,t){return this.#s.has(`${e}:${t}`)}isRowChanged(e){const t=this.grid,i=t._rows[e];if(!i)return!1;try{const o=t.getRowId?.(i);return o?this.#c.has(o):!1}catch{return!1}}isRowChangedById(e){return this.#c.has(e)}resetChangedRows(e){const t=this.changedRows,i=this.changedRowIds;this.#c.clear(),this.#u(),e||this.emit("changed-rows-reset",{rows:t,ids:i}),this.grid._rowPool?.forEach(r=>r.classList.remove("changed"))}beginCellEdit(e,t){const i=this.grid,o=i._visibleColumns.findIndex(a=>a.field===t);if(o===-1||!i._visibleColumns[o]?.editable)return;const l=i.findRenderedRowElement?.(e)?.querySelector(`.cell[data-col="${o}"]`);l&&this.#h(e,o,l)}beginBulkEdit(e){const t=this.grid;if((this.config.editOn??t.effectiveConfig?.editOn)===!1||!t._columns?.some(l=>l.editable))return;const r=t.findRenderedRowElement?.(e);if(!r)return;const s=t._rows[e];this.#p(e,s),Array.from(r.children).forEach((l,a)=>{const c=t._visibleColumns[a];if(c?.editable){const d=l;d.classList.contains("editing")||this.#m(s,e,c,a,d,!0)}}),setTimeout(()=>{let l=r.querySelector(`.cell[data-col="${t._focusCol}"]`);if(l?.classList.contains("editing")||(l=r.querySelector(".cell.editing")),l?.classList.contains("editing")){const a=l.querySelector(He);try{a?.focus({preventScroll:!0})}catch{}}},0)}commitActiveRowEdit(){this.#e!==-1&&this.#l(this.#e,!1)}cancelActiveRowEdit(){this.#e!==-1&&this.#l(this.#e,!0)}#h(e,t,i){const o=this.grid,r=o._rows[e],s=o._visibleColumns[t];!r||!s?.editable||i.classList.contains("editing")||(this.#e!==e&&this.#p(e,r),this.#n=t,this.#m(r,e,s,t,i,!1))}#u(){const e=this.grid;e._activeEditRows=this.#e,e._rowEditSnapshots=this.#d}#p(e,t){this.#e!==e&&(this.#d.set(e,{...t}),this.#e=e,this.#u())}#l(e,t){if(this.#e!==e)return;const i=this.grid,o=this.#d.get(e),r=i._rows[e],s=i.findRenderedRowElement?.(e);let l;if(r)try{l=i.getRowId?.(r)}catch{}if(!t&&s&&r&&s.querySelectorAll(".cell.editing").forEach(c=>{const d=Number(c.getAttribute("data-col"));if(isNaN(d))return;const u=i._visibleColumns[d];if(!u)return;const h=c.querySelector("input,textarea,select");if(h){const g=le(h,u);r[u.field]!==g&&this.#w(e,u,g,r)}}),t&&o&&r)Object.keys(o).forEach(a=>{r[a]=o[a]}),l&&this.#c.delete(l);else if(!t&&r){const a=l?this.#c.has(l):!1;this.emit("row-commit",{rowIndex:e,rowId:l??"",row:r,changed:a,changedRows:this.changedRows,changedRowIds:this.changedRowIds})}this.#d.delete(e),this.#e=-1,this.#n=-1,this.#u();for(const a of this.#s)a.startsWith(`${e}:`)&&this.#s.delete(a);s&&(s.querySelectorAll(".cell.editing").forEach(a=>{a.classList.remove("editing"),zn(a.parentElement)}),this.requestRender()),this.#i=!0,s||(this.#b(i),this.#i=!1)}#w(e,t,i,o){const r=t.field;if(!se(r))return;const s=o[r];if(s===i)return;const l=this.grid;let a;try{a=this.grid.getRowId(o)}catch{}const c=a?!this.#c.has(a):!0,d=a?g=>this.grid.updateRow(a,g,"cascade"):Ht;if(this.emitCancelable("cell-commit",{row:o,rowId:a??"",field:r,oldValue:s,value:i,rowIndex:e,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:c,updateRow:d}))return;o[r]=i,a&&this.#c.add(a),this.#u();const h=l.findRenderedRowElement?.(e);h&&h.classList.add("changed")}#m(e,t,i,o,r,s){if(!i.editable||r.classList.contains("editing"))return;let l;try{l=this.grid.getRowId(e)}catch{}const a=l?v=>this.grid.updateRow(l,v,"cascade"):Ht,c=se(i.field)?e[i.field]:void 0;r.classList.add("editing"),this.#s.add(`${t}:${o}`);const d=r.parentElement;d&&Nn(d);let u=!1;const h=v=>{u||this.#e===-1||this.#w(t,i,v,e)},g=()=>{u=!0,se(i.field)&&(e[i.field]=c)},f=document.createElement("div");f.className="tbw-editor-host",r.innerHTML="",r.appendChild(f),f.addEventListener("keydown",v=>{v.key==="Enter"&&(v.stopPropagation(),v.preventDefault(),u=!0,this.#l(t,!1)),v.key==="Escape"&&(v.stopPropagation(),v.preventDefault(),g(),this.#l(t,!0))});const p=i,w=p.__editorTemplate,m=On(this.grid,p)??Dt(i),C=c;if(m==="template"&&w)this.#a(f,p,e,c,h,g,s,t);else if(typeof m=="string"){const v=document.createElement(m);v.value=C,v.addEventListener("change",()=>h(v.value)),f.appendChild(v),s||queueMicrotask(()=>{f.querySelector(He)?.focus({preventScroll:!0})})}else if(typeof m=="function"){const v={row:e,rowId:l??"",value:C,field:i.field,column:i,commit:h,cancel:g,updateRow:a},b=m(v);typeof b=="string"?(f.innerHTML=b,qn(f,i,h)):b instanceof Node&&f.appendChild(b),s||queueMicrotask(()=>{f.querySelector(He)?.focus({preventScroll:!0})})}else if(m&&typeof m=="object"){const v=document.createElement("div");v.setAttribute("data-external-editor",""),v.setAttribute("data-field",i.field),f.appendChild(v);const b={row:e,rowId:l??"",value:C,field:i.field,column:i,commit:h,cancel:g,updateRow:a};if(m.mount)try{m.mount({placeholder:v,context:b,spec:m})}catch(R){console.warn(`[tbw-grid] External editor mount error for column '${i.field}':`,R)}else this.grid.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:v,spec:m,context:b}}))}}#a(e,t,i,o,r,s,l,a){const c=t.__editorTemplate;if(!c)return;const d=c.cloneNode(!0),u=t.__compiledEditor;u?d.innerHTML=u({row:i,value:o,field:t.field,column:t,commit:r,cancel:s}):d.querySelectorAll("*").forEach(g=>{g.childNodes.length===1&&g.firstChild?.nodeType===Node.TEXT_NODE&&(g.textContent=g.textContent?.replace(/{{\s*value\s*}}/g,o==null?"":String(o)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(f,p)=>{if(!se(p))return"";const w=i[p];return w==null?"":String(w)})||"")});const h=d.querySelector("input,textarea,select");if(h){h instanceof HTMLInputElement&&h.type==="checkbox"?h.checked=!!o:h.value=String(o??"");let g=!1;h.addEventListener("blur",()=>{g||r(le(h,t))}),h.addEventListener("keydown",f=>{const p=f;p.key==="Enter"&&(p.stopPropagation(),p.preventDefault(),g=!0,r(le(h,t)),this.#l(a,!1)),p.key==="Escape"&&(p.stopPropagation(),p.preventDefault(),s(),this.#l(a,!0))}),h instanceof HTMLInputElement&&h.type==="checkbox"&&h.addEventListener("change",()=>r(h.checked)),l||setTimeout(()=>h.focus({preventScroll:!0}),0)}e.appendChild(d)}#b(e){queueMicrotask(()=>{try{const t=e._focusRow,i=e._focusCol,o=e.findRenderedRowElement?.(t);if(o){Array.from(e._bodyEl.querySelectorAll(".cell-focus")).forEach(s=>s.classList.remove("cell-focus"));const r=o.querySelector(`.cell[data-row="${t}"][data-col="${i}"]`);r&&(r.classList.add("cell-focus"),r.setAttribute("aria-selected","true"),r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1"),r.focus({preventScroll:!0}))}}catch{}})}}function Mt(n,e=!0){if(n==null)return"";if(n instanceof Date)return n.toISOString();if(typeof n=="object")return JSON.stringify(n);const t=String(n);return e&&(t.includes(",")||t.includes('"')||t.includes(`
66
- `)||t.includes("\r"))?`"${t.replace(/"/g,'""')}"`:t}function Gn(n,e,t,i={}){const o=i.delimiter??",",r=i.newline??`
67
- `,s=[],l=i.bom?"\uFEFF":"";if(t.includeHeaders!==!1){const a=e.map(c=>{const d=c.header||c.field,u=t.processHeader?t.processHeader(d,c.field):d;return Mt(u)});s.push(a.join(o))}for(const a of n){const c=e.map(d=>{let u=a[d.field];return t.processCell&&(u=t.processCell(u,d.field,a)),Mt(u)});s.push(c.join(o))}return l+s.join(r)}function Me(n,e){const t=URL.createObjectURL(n),i=document.createElement("a");i.href=t,i.download=e,i.style.display="none",document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(t)}function Kn(n,e){const t=new Blob([n],{type:"text/csv;charset=utf-8;"});Me(t,e)}function Ot(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}function Bn(n,e,t){let i=`<?xml version="1.0" encoding="UTF-8"?>
63
+ `),r=[];let s=[],l="",a=!1;for(let c=0;c<n.length;c++){const d=n[c];d==='"'&&!a?a=!0:d==='"'&&a?n[c+1]==='"'?(l+='"',c++):a=!1:d===t&&!a?(s.push(l),l=""):d===i&&!a?(s.push(l),l="",(s.length>1||s.some(u=>u.trim()!==""))&&r.push(s),s=[]):l+=d}return s.push(l),(s.length>1||s.some(c=>c.trim()!==""))&&r.push(s),r}async function Lo(){try{return await navigator.clipboard.readText()}catch{return""}}function Pt(o,e){const{rows:t,target:i,fields:n}=o;if(!i)return;const r=e.rows,s=e.effectiveConfig.columns??[],l=s.map(u=>u.field),a=new Map;s.forEach(u=>{a.set(u.field,u.editable===!0)});const c=[...r],d=i.bounds?i.bounds.endRow:1/0;t.forEach((u,h)=>{const f=i.row+h;if(!(f>d)){if(i.bounds){if(f>=c.length)return}else for(;f>=c.length;){const p={};l.forEach(g=>p[g]=""),c.push(p)}c[f]={...c[f]},u.forEach((p,g)=>{const w=n[g];w&&a.get(w)&&(c[f][w]=p)})}}),e.rows=c}class Do extends L{static dependencies=[{name:"selection",required:!1,reason:"Enables copy/paste of selected cells instead of entire grid"}];name="clipboard";get defaultConfig(){return{includeHeaders:!1,delimiter:" ",newline:`
64
+ `,quoteStrings:!1}}lastCopied=null;attach(e){super.attach(e),e.addEventListener("paste",t=>this.#o(t),{signal:this.disconnectSignal})}detach(){this.lastCopied=null}onKeyDown(e){return(e.ctrlKey||e.metaKey)&&e.key==="c"?(this.#e(e.target),!0):!1}#e(e){const t=this.#c(),i=t?.getSelection(),n=this.columns.length-1,r=this.rows.length-1;let s;if(i&&i.ranges.length>0){const{mode:a,ranges:c}=i,d=c[c.length-1];a==="row"?s={startRow:d.from.row,startCol:0,endRow:d.to.row,endCol:n}:s={startRow:d.from.row,startCol:d.from.col,endRow:d.to.row,endCol:d.to.col}}else if(!t)s={startRow:0,startCol:0,endRow:r,endCol:n};else{const a=this.#i(e);if(!a)return;s={startRow:a.row,startCol:a.col,endRow:a.row,endCol:a.col}}const l=this.#s(s);ke(l.text).then(()=>{this.lastCopied={text:l.text,timestamp:Date.now()},this.emit("copy",{text:l.text,rowCount:l.rowCount,columnCount:l.columnCount})})}#o(e){const t=e.clipboardData?.getData("text/plain");if(!t)return;e.preventDefault();const i=kt(t,this.config),r=this.#c()?.getSelection(),s=r?.ranges?.[0],l=s?.from.row??0,a=s?.from.col??0,d=s&&(r?.mode==="range"||r?.mode==="row")&&(s.from.row!==s.to.row||s.from.col!==s.to.col)?{endRow:s.to.row,endCol:s.to.col}:null,u=d?.endCol??this.columns.length-1,h=this.columns[a],f=h?{row:l,col:a,field:h.field,bounds:d}:null,p=[],g=i[0]?.length??0;for(let m=0;m<g&&a+m<=u;m++){const y=this.columns[a+m];y&&!y.hidden&&p.push(y.field)}const w={rows:i,text:t,target:f,fields:p};this.emit("paste",w),this.#d(w)}#d(e){if(!this.grid)return;const{pasteHandler:t}=this.config;if(t===null)return;(t??Pt)(e,this.grid)}#c(){try{const e=this.grid?.getPluginByName("selection");if(e)return e}catch{}}#s(e){const{startRow:t,startCol:i,endRow:n,endCol:r}=e,s=Math.min(t,n),l=Math.max(t,n),a=Math.min(i,r),c=Math.max(i,r),d=this.config.delimiter??" ",u=this.config.newline??`
65
+ `,h=[],f=this.columns.slice(a,c+1).filter(p=>!B(p));if(this.config.includeHeaders){const p=f.map(g=>g.header||g.field);h.push(p.join(d))}for(let p=s;p<=l;p++){const g=this.rows[p];if(!g)continue;const w=f.map(m=>{const y=g[m.field];return y==null?"":y instanceof Date?y.toISOString():String(y)});h.push(w.join(d))}return{text:h.join(u),rowCount:l-s+1,columnCount:c-a+1}}#i(e){const t=e.closest("[data-field-cache]");if(!t)return null;const i=t.dataset.fieldCache,n=t.dataset.row;if(!i||!n)return null;const r=parseInt(n,10);if(isNaN(r))return null;const s=this.columns.findIndex(l=>l.field===i);return s===-1?null:{row:r,col:s}}async copy(){const t=this.#c()?.getSelection(),i=this.columns.length-1;let n={startRow:0,startCol:0,endRow:this.rows.length-1,endCol:i};if(t&&t.ranges.length>0){const s=t.ranges[t.ranges.length-1];t.mode==="row"?n={startRow:s.from.row,startCol:0,endRow:s.to.row,endCol:i}:n={startRow:s.from.row,startCol:s.from.col,endRow:s.to.row,endCol:s.to.col}}const r=this.#s(n);return await ke(r.text),this.lastCopied={text:r.text,timestamp:Date.now()},r.text}async copyRows(e){if(e.length===0)return"";const t=[...e].sort((s,l)=>s-l),i=this.columns.length-1,n={startRow:t[0],startCol:0,endRow:t[t.length-1],endCol:i},r=this.#s(n);return await ke(r.text),this.lastCopied={text:r.text,timestamp:Date.now()},r.text}async paste(){const e=await Lo();return e?kt(e,this.config):null}getLastCopied(){return this.lastCopied}}const Lt=100;function Pe(o){if(o==null)return Lt;if(typeof o=="number")return o;const e=parseFloat(o);return isNaN(e)?Lt:e}function Dt(o){return o.map(e=>Pe(e.width))}function Ht(o){const e=[];let t=0;for(const i of o)e.push(t),t+=Pe(i.width);return e}function It(o){return o.reduce((e,t)=>e+Pe(t.width),0)}function Ho(o,e,t,i,n){const r=t.length;if(r===0)return{startCol:0,endCol:0,visibleColumns:[]};let s=Io(o,t,i);s=Math.max(0,s-n);const l=o+e;let a=s;for(let d=s;d<r;d++){if(t[d]>=l){a=d-1;break}a=d}a=Math.min(r-1,a+n);const c=[];for(let d=s;d<=a;d++)c.push(d);return{startCol:s,endCol:a,visibleColumns:c}}function Io(o,e,t){let i=0,n=e.length-1;for(;i<n;){const r=Math.floor((i+n)/2);e[r]+t[r]<=o?i=r+1:n=r}return i}function Mo(o,e,t){return t?o>e:!1}class Oo extends L{name="columnVirtualization";get defaultConfig(){return{autoEnable:!0,threshold:30,overscan:3}}isVirtualized=!1;startCol=0;endCol=0;scrollLeft=0;totalWidth=0;columnWidths=[];columnOffsets=[];attach(e){super.attach(e);const t=this.columns;this.columnWidths=Dt(t),this.columnOffsets=Ht(t),this.totalWidth=It(t),this.endCol=t.length-1}detach(){this.columnWidths=[],this.columnOffsets=[],this.isVirtualized=!1,this.startCol=0,this.endCol=0,this.scrollLeft=0,this.totalWidth=0}processColumns(e){const t=Mo(e.length,this.config.threshold??30,this.config.autoEnable??!0);if(this.isVirtualized=t??!1,this.columnWidths=Dt(e),this.columnOffsets=Ht(e),this.totalWidth=It(e),!t)return this.startCol=0,this.endCol=e.length-1,[...e];const i=this.grid.clientWidth||800,n=Ho(this.scrollLeft,i,this.columnOffsets,this.columnWidths,this.config.overscan??3);return this.startCol=n.startCol,this.endCol=n.endCol,n.visibleColumns.map(r=>e[r])}afterRender(){if(!this.isVirtualized)return;const e=this.gridElement;if(!e)return;const t=this.columnOffsets[this.startCol]??0,i=e.querySelector(".header-row"),n=e.querySelectorAll(".data-grid-row");i&&(i.style.paddingLeft=`${t}px`),n.forEach(s=>{s.style.paddingLeft=`${t}px`});const r=e.querySelector(".rows-viewport .rows");r&&(r.style.width=`${this.totalWidth}px`)}onScroll(e){!this.isVirtualized||Math.abs(e.scrollLeft-this.scrollLeft)<1||(this.scrollLeft=e.scrollLeft,this.requestRender())}getIsVirtualized(){return this.isVirtualized}getVisibleColumnRange(){return{start:this.startCol,end:this.endCol}}scrollToColumn(e){const t=this.columnOffsets[e]??0,i=this.grid;i.scrollLeft=t}getColumnOffset(e){return this.columnOffsets[e]??0}getTotalWidth(){return this.totalWidth}}const Le="@layer tbw-plugins{.tbw-context-menu{position:fixed;background:var(--tbw-context-menu-bg, var(--tbw-color-panel-bg, light-dark(#f5f5f5, #2a2a2a)));color:var(--tbw-context-menu-fg, var(--tbw-color-fg, light-dark(#222, #eee)));border:1px solid var(--tbw-context-menu-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-border-radius, .25rem);box-shadow:0 2px 10px var(--tbw-color-shadow, rgba(0, 0, 0, .15));min-width:var(--tbw-menu-min-width, 10rem);padding:var(--tbw-spacing-xs, .25rem) 0;z-index:10000;font-size:var(--tbw-font-size-sm, .8125rem);font-family:var(--tbw-font-family, system-ui, sans-serif)}.tbw-context-menu-item{display:flex;align-items:center;padding:var(--tbw-menu-item-padding, .375rem .75rem);cursor:pointer;gap:var(--tbw-menu-item-gap, .5rem)}.tbw-context-menu-item:hover:not(.disabled){background:var(--tbw-context-menu-hover, var(--tbw-color-row-hover, light-dark(#e8e8e8, #3a3a3a)))}.tbw-context-menu-item.disabled{opacity:.5;cursor:default}.tbw-context-menu-item.danger{color:light-dark(#c00,#f66)}.tbw-context-menu-icon{width:var(--tbw-icon-size, 1rem);text-align:center}.tbw-context-menu-label{flex:1}.tbw-context-menu-shortcut{color:var(--tbw-color-fg-muted, light-dark(#888, #888));font-size:var(--tbw-font-size-xs, .6875rem)}.tbw-context-menu-arrow{font-size:var(--tbw-font-size-2xs, .625rem);color:var(--tbw-color-fg-muted, light-dark(#888, #888))}.tbw-context-menu-separator{height:1px;background:var(--tbw-context-menu-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));margin:var(--tbw-spacing-xs, .25rem) 0}}";function De(o,e){return(typeof o=="function"?o(e):o).filter(i=>!(i.hidden===!0||typeof i.hidden=="function"&&i.hidden(e)))}function No(o,e){return o.disabled===!0?!0:typeof o.disabled=="function"?o.disabled(e):!1}function He(o,e,t,i=F.submenuArrow){const n=document.createElement("div");n.className="tbw-context-menu",n.setAttribute("role","menu");for(const r of o){if(r.separator){const c=document.createElement("div");c.className="tbw-context-menu-separator",c.setAttribute("role","separator"),n.appendChild(c);continue}const s=document.createElement("div");s.className="tbw-context-menu-item",r.cssClass&&s.classList.add(r.cssClass),s.setAttribute("role","menuitem"),s.setAttribute("data-id",r.id);const l=No(r,e);if(l&&(s.classList.add("disabled"),s.setAttribute("aria-disabled","true")),r.icon){const c=document.createElement("span");c.className="tbw-context-menu-icon",c.innerHTML=r.icon,s.appendChild(c)}const a=document.createElement("span");if(a.className="tbw-context-menu-label",a.textContent=r.name,s.appendChild(a),r.shortcut){const c=document.createElement("span");c.className="tbw-context-menu-shortcut",c.textContent=r.shortcut,s.appendChild(c)}if(r.subMenu?.length){const c=document.createElement("span");c.className="tbw-context-menu-arrow",typeof i=="string"?c.innerHTML=i:i instanceof HTMLElement&&c.appendChild(i.cloneNode(!0)),s.appendChild(c),s.addEventListener("mouseenter",()=>{if(s.querySelector(".tbw-context-menu")||!r.subMenu)return;const u=De(r.subMenu,e),h=He(u,e,t,i);h.classList.add("tbw-context-submenu"),h.style.position="absolute",h.style.left="100%",h.style.top="0",s.style.position="relative",s.appendChild(h)}),s.addEventListener("mouseleave",()=>{const d=s.querySelector(".tbw-context-menu");d&&d.remove()})}!l&&r.action&&!r.subMenu&&s.addEventListener("click",c=>{c.stopPropagation(),t(r)}),n.appendChild(s)}return n}function Mt(o,e,t){o.style.position="fixed",o.style.left=`${e}px`,o.style.top=`${t}px`,o.style.visibility="hidden",o.style.zIndex="10000";const i=o.getBoundingClientRect(),n=window.innerWidth,r=window.innerHeight;let s=e,l=t;e+i.width>n&&(s=e-i.width),t+i.height>r&&(l=t-i.height),s=Math.max(0,s),l=Math.max(0,l),o.style.left=`${s}px`,o.style.top=`${l}px`,o.style.visibility="visible"}let Q=null,ee=null,W=null,Ie=0;const Me=[{id:"copy",name:"Copy",shortcut:"Ctrl+C",action:o=>{o.grid?.plugins?.clipboard?.copy?.()}},{separator:!0,id:"sep1",name:""},{id:"export-csv",name:"Export CSV",action:o=>{o.grid?.plugins?.export?.exportCsv?.()}}];class zo extends L{name="contextMenu";get defaultConfig(){return{items:Me}}isOpen=!1;position={x:0,y:0};params=null;menuElement=null;attach(e){super.attach(e),this.installGlobalHandlers(),Ie++}detach(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null),this.isOpen=!1,this.params=null,this.uninstallGlobalHandlers()}installGlobalHandlers(){!W&&typeof document<"u"&&typeof Le=="string"&&Le&&(W=document.createElement("style"),W.id="tbw-context-menu-styles",W.textContent=Le,document.head.appendChild(W)),Q||(Q=()=>{document.querySelectorAll(".tbw-context-menu").forEach(t=>t.remove())},document.addEventListener("click",Q)),ee||(ee=e=>{e.key==="Escape"&&document.querySelectorAll(".tbw-context-menu").forEach(i=>i.remove())},document.addEventListener("keydown",ee))}uninstallGlobalHandlers(){Ie--,!(Ie>0)&&(Q&&(document.removeEventListener("click",Q),Q=null),ee&&(document.removeEventListener("keydown",ee),ee=null),W&&(W.remove(),W=null))}afterRender(){const e=this.gridElement;if(!e)return;const t=e.children[0];t&&t.getAttribute("data-context-menu-bound")!=="true"&&(t.setAttribute("data-context-menu-bound","true"),t.addEventListener("contextmenu",i=>{const n=i;n.preventDefault();const r=n.target,s=r.closest("[data-row][data-col]"),l=r.closest(".header-cell");let a;if(s){const d=parseInt(s.getAttribute("data-row")??"-1",10),u=parseInt(s.getAttribute("data-col")??"-1",10),h=this.columns[u],f=this.rows[d];a={row:f,rowIndex:d,column:h,columnIndex:u,field:h?.field??"",value:f?.[h?.field]??null,isHeader:!1,event:n}}else if(l){const d=parseInt(l.getAttribute("data-col")??"-1",10),u=this.columns[d];a={row:null,rowIndex:-1,column:u,columnIndex:d,field:u?.field??"",value:null,isHeader:!0,event:n}}else return;this.params=a,this.position={x:n.clientX,y:n.clientY};const c=De(this.config.items??Me,a);c.length&&(this.menuElement&&this.menuElement.remove(),this.menuElement=He(c,a,d=>{d.action&&d.action(a),this.menuElement?.remove(),this.menuElement=null,this.isOpen=!1},this.gridIcons.submenuArrow),document.body.appendChild(this.menuElement),Mt(this.menuElement,n.clientX,n.clientY),this.isOpen=!0,this.emit("context-menu-open",{params:a,items:c}))}))}showMenu(e,t,i){const n={row:i.row??null,rowIndex:i.rowIndex??-1,column:i.column??null,columnIndex:i.columnIndex??-1,field:i.field??"",value:i.value??null,isHeader:i.isHeader??!1,event:i.event??new MouseEvent("contextmenu")},r=De(this.config.items??Me,n);this.menuElement&&this.menuElement.remove(),this.menuElement=He(r,n,s=>{s.action&&s.action(n),this.menuElement?.remove(),this.menuElement=null,this.isOpen=!1},this.gridIcons.submenuArrow),document.body.appendChild(this.menuElement),Mt(this.menuElement,e,t),this.isOpen=!0}hideMenu(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null,this.isOpen=!1)}isMenuOpen(){return this.isOpen}}const qo="@layer tbw-plugins{tbw-grid{--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-row-bg: var(--tbw-editing-bg);--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-editing-row-outline-color: var(--tbw-color-accent);--tbw-editing-row-outline-width: 1px}tbw-grid .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}tbw-grid .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex;min-height:calc(var(--tbw-row-height) + 2px);align-items:center;justify-content:center}tbw-grid .data-grid-row>.cell.editing input:not([type=checkbox]),tbw-grid .data-grid-row>.cell.editing select,tbw-grid .data-grid-row>.cell.editing textarea{width:100%;height: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)}tbw-grid .tbw-editor-host{display:contents}}";function Fo(o){const e=o.options;return e?typeof e=="function"?e():e:[]}function Go(o){return e=>{const t=o.editorParams,i=document.createElement("input");i.type="number",i.value=e.value!=null?String(e.value):"",t?.min!==void 0&&(i.min=String(t.min)),t?.max!==void 0&&(i.max=String(t.max)),t?.step!==void 0&&(i.step=String(t.step)),t?.placeholder&&(i.placeholder=t.placeholder);const n=()=>e.commit(i.value===""?null:Number(i.value));return i.addEventListener("blur",n),i.addEventListener("keydown",r=>{r.key==="Enter"&&n(),r.key==="Escape"&&e.cancel()}),i}}function Ko(){return o=>{const e=document.createElement("input");return e.type="checkbox",e.checked=!!o.value,e.addEventListener("change",()=>o.commit(e.checked)),e}}function Bo(o){return e=>{const t=o.editorParams,i=document.createElement("input");return i.type="date",e.value instanceof Date&&(i.valueAsDate=e.value),t?.min&&(i.min=t.min),t?.max&&(i.max=t.max),t?.placeholder&&(i.placeholder=t.placeholder),i.addEventListener("change",()=>e.commit(i.valueAsDate)),i.addEventListener("keydown",n=>{n.key==="Escape"&&e.cancel()}),i}}function Wo(o){return e=>{const t=o.editorParams,i=document.createElement("select");if(o.multi&&(i.multiple=!0),t?.includeEmpty){const s=document.createElement("option");s.value="",s.textContent=t.emptyLabel??"",i.appendChild(s)}Fo(o).forEach(s=>{const l=document.createElement("option");l.value=String(s.value),l.textContent=s.label,(o.multi&&Array.isArray(e.value)&&e.value.includes(s.value)||!o.multi&&e.value===s.value)&&(l.selected=!0),i.appendChild(l)});const r=()=>{if(o.multi){const s=Array.from(i.selectedOptions).map(l=>l.value);e.commit(s)}else e.commit(i.value)};return i.addEventListener("change",r),i.addEventListener("blur",r),i.addEventListener("keydown",s=>{s.key==="Escape"&&e.cancel()}),i}}function Vo(o){return e=>{const t=o.editorParams,i=document.createElement("input");return i.type="text",i.value=e.value!=null?String(e.value):"",t?.maxLength!==void 0&&(i.maxLength=t.maxLength),t?.pattern&&(i.pattern=t.pattern),t?.placeholder&&(i.placeholder=t.placeholder),i.addEventListener("blur",()=>e.commit(i.value)),i.addEventListener("keydown",n=>{n.key==="Enter"&&e.commit(i.value),n.key==="Escape"&&e.cancel()}),i}}function Ot(o){switch(o.type){case"number":return Go(o);case"boolean":return Ko();case"date":return Bo(o);case"select":return Wo(o);default:return Vo(o)}}const Oe='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function $o(o,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=o.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const n=o.__frameworkAdapter;if(n?.getTypeDefault){const r=n.getTypeDefault(e.type);if(r?.editor)return r.editor}}function se(o){return!(typeof o!="string"||o==="__proto__"||o==="constructor"||o==="prototype")}function Uo(o){const e=(o.__editingCellCount??0)+1;o.__editingCellCount=e,o.setAttribute("data-has-editing","")}function jo(o){o.__editingCellCount=0,o.removeAttribute("data-has-editing")}function le(o,e){return o instanceof HTMLInputElement?o.type==="checkbox"?o.checked:o.type==="number"?o.value===""?null:Number(o.value):o.type==="date"?o.valueAsDate:o.value:e?.type==="number"&&o.value!==""?Number(o.value):o.value}function Nt(o){}function Yo(o,e,t){const i=o.querySelector("input,textarea,select");i&&(i.addEventListener("blur",()=>{t(le(i,e))}),i instanceof HTMLInputElement&&i.type==="checkbox"?i.addEventListener("change",()=>t(i.checked)):i instanceof HTMLSelectElement&&i.addEventListener("change",()=>t(le(i,e))))}class Xo extends L{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:e=>e===!0},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'}]};name="editing";styles=qo;get defaultConfig(){return{editOn:"click"}}#e=-1;#o=-1;#d=new Map;#c=new Set;#s=new Set;#i=!1;attach(e){super.attach(e);const t=this.disconnectSignal,i=e;i._activeEditRows=-1,i._rowEditSnapshots=new Map,Object.defineProperty(e,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(e,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),e.resetChangedRows=n=>this.resetChangedRows(n),e.beginBulkEdit=(n,r)=>{r&&this.beginCellEdit(n,r)},document.addEventListener("keydown",n=>{n.key==="Escape"&&this.#e!==-1&&this.#l(this.#e,!0)},{capture:!0,signal:t}),document.addEventListener("mousedown",n=>{if(this.#e===-1)return;const r=i.findRenderedRowElement?.(this.#e);!r||(n.composedPath&&n.composedPath()||[]).includes(r)||this.#l(this.#e,!1)},{signal:t})}detach(){this.#e=-1,this.#o=-1,this.#d.clear(),this.#c.clear(),this.#s.clear(),super.detach()}onCellClick(e){const t=this.grid,i=this.config.editOn??t.effectiveConfig?.editOn;if(i===!1||i==="manual"||i!=="click"&&i!=="dblclick")return!1;const n=e.originalEvent.type==="dblclick";if(i==="click"&&n||i==="dblclick"&&!n)return!1;const{rowIndex:r}=e;return t._columns?.some(l=>l.editable)?(e.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0):!1}onKeyDown(e){const t=this.grid;if(e.key==="Escape"&&this.#e!==-1)return this.#l(this.#e,!0),!0;if(e.key===" "||e.key==="Spacebar"){const i=t._focusRow,n=t._focusCol;if(i>=0&&n>=0){const r=t._visibleColumns[n],s=t._rows[i];if(r?.editable&&r.type==="boolean"&&s){const l=r.field;if(se(l)){const c=!s[l];return this.#w(i,r,c,s),e.preventDefault(),this.requestRender(),!0}}}return!1}if(e.key==="Enter"&&!e.shiftKey){if(this.#e!==-1)return!1;const i=this.config.editOn??t.effectiveConfig?.editOn;if(i===!1||i==="manual")return!1;const n=t._focusRow,r=t._focusCol;if(n>=0&&t._columns?.some(l=>l.editable)){const l=t._visibleColumns[r],a=t._rows[n],c=l?.field??"",d=c&&a?a[c]:void 0,u=this.gridElement.querySelector(`[data-row="${n}"][data-col="${r}"]`),h=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:n,colIndex:r,field:c,value:d,row:a,cellEl:u,trigger:"keyboard",originalEvent:e}});this.gridElement.dispatchEvent(h);const f=new CustomEvent("activate-cell",{cancelable:!0,bubbles:!0,detail:{row:n,col:r}});return this.gridElement.dispatchEvent(f),h.defaultPrevented||f.defaultPrevented?(e.preventDefault(),!0):(this.beginBulkEdit(n),!0)}return!1}return!1}processColumns(e){const t=this.grid,i=t.effectiveConfig?.typeDefaults,n=t.__frameworkAdapter;return!i&&!n?.getTypeDefault?e:e.map(r=>{if(!r.type)return r;let s;if(i?.[r.type]?.editorParams&&(s=i[r.type].editorParams),!s&&n?.getTypeDefault){const l=n.getTypeDefault(r.type);l?.editorParams&&(s=l.editorParams)}return s?{...r,editorParams:{...s,...r.editorParams}}:r})}afterRender(){const e=this.grid;if(this.#i&&(this.#i=!1,this.#b(e)),this.#s.size!==0)for(const t of this.#s){const[i,n]=t.split(":"),r=parseInt(i,10),s=parseInt(n,10),l=e.findRenderedRowElement?.(r);if(!l)continue;const a=l.querySelector(`.cell[data-col="${s}"]`);if(!a||a.classList.contains("editing"))continue;const c=e._rows[r],d=e._visibleColumns[s];c&&d&&this.#m(c,r,d,s,a,!0)}}onScrollRender(){this.afterRender()}get changedRows(){const e=[];for(const t of this.#c){const i=this.grid.getRow(t);i&&e.push(i)}return e}get changedRowIds(){return Array.from(this.#c)}get activeEditRow(){return this.#e}get activeEditCol(){return this.#o}isRowEditing(e){return this.#e===e}isCellEditing(e,t){return this.#s.has(`${e}:${t}`)}isRowChanged(e){const t=this.grid,i=t._rows[e];if(!i)return!1;try{const n=t.getRowId?.(i);return n?this.#c.has(n):!1}catch{return!1}}isRowChangedById(e){return this.#c.has(e)}resetChangedRows(e){const t=this.changedRows,i=this.changedRowIds;this.#c.clear(),this.#u(),e||this.emit("changed-rows-reset",{rows:t,ids:i}),this.grid._rowPool?.forEach(r=>r.classList.remove("changed"))}beginCellEdit(e,t){const i=this.grid,n=i._visibleColumns.findIndex(a=>a.field===t);if(n===-1||!i._visibleColumns[n]?.editable)return;const l=i.findRenderedRowElement?.(e)?.querySelector(`.cell[data-col="${n}"]`);l&&this.#h(e,n,l)}beginBulkEdit(e){const t=this.grid;if((this.config.editOn??t.effectiveConfig?.editOn)===!1||!t._columns?.some(l=>l.editable))return;const r=t.findRenderedRowElement?.(e);if(!r)return;const s=t._rows[e];this.#p(e,s),Array.from(r.children).forEach((l,a)=>{const c=t._visibleColumns[a];if(c?.editable){const d=l;d.classList.contains("editing")||this.#m(s,e,c,a,d,!0)}}),setTimeout(()=>{let l=r.querySelector(`.cell[data-col="${t._focusCol}"]`);if(l?.classList.contains("editing")||(l=r.querySelector(".cell.editing")),l?.classList.contains("editing")){const a=l.querySelector(Oe);try{a?.focus({preventScroll:!0})}catch{}}},0)}commitActiveRowEdit(){this.#e!==-1&&this.#l(this.#e,!1)}cancelActiveRowEdit(){this.#e!==-1&&this.#l(this.#e,!0)}#h(e,t,i){const n=this.grid,r=n._rows[e],s=n._visibleColumns[t];!r||!s?.editable||i.classList.contains("editing")||(this.#e!==e&&this.#p(e,r),this.#o=t,this.#m(r,e,s,t,i,!1))}#u(){const e=this.grid;e._activeEditRows=this.#e,e._rowEditSnapshots=this.#d}#p(e,t){this.#e!==e&&(this.#d.set(e,{...t}),this.#e=e,this.#u())}#l(e,t){if(this.#e!==e)return;const i=this.grid,n=this.#d.get(e),r=i._rows[e],s=i.findRenderedRowElement?.(e);let l;if(r)try{l=i.getRowId?.(r)}catch{}if(!t&&s&&r&&s.querySelectorAll(".cell.editing").forEach(c=>{const d=Number(c.getAttribute("data-col"));if(isNaN(d))return;const u=i._visibleColumns[d];if(!u)return;const h=c.querySelector("input,textarea,select");if(h){const f=le(h,u);r[u.field]!==f&&this.#w(e,u,f,r)}}),t&&n&&r)Object.keys(n).forEach(a=>{r[a]=n[a]}),l&&this.#c.delete(l);else if(!t&&r){const a=l?this.#c.has(l):!1;this.emit("row-commit",{rowIndex:e,rowId:l??"",row:r,changed:a,changedRows:this.changedRows,changedRowIds:this.changedRowIds}),a&&this.isAnimationEnabled&&i.animateRow?.(e,"change")}this.#d.delete(e),this.#e=-1,this.#o=-1,this.#u();for(const a of this.#s)a.startsWith(`${e}:`)&&this.#s.delete(a);s&&(s.querySelectorAll(".cell.editing").forEach(a=>{a.classList.remove("editing"),jo(a.parentElement)}),this.requestRender()),this.#i=!0,s||(this.#b(i),this.#i=!1)}#w(e,t,i,n){const r=t.field;if(!se(r))return;const s=n[r];if(s===i)return;const l=this.grid;let a;try{a=this.grid.getRowId(n)}catch{}const c=a?!this.#c.has(a):!0,d=a?f=>this.grid.updateRow(a,f,"cascade"):Nt;if(this.emitCancelable("cell-commit",{row:n,rowId:a??"",field:r,oldValue:s,value:i,rowIndex:e,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:c,updateRow:d}))return;n[r]=i,a&&this.#c.add(a),this.#u();const h=l.findRenderedRowElement?.(e);h&&(h.classList.add("changed"),gt(h,"change"))}#m(e,t,i,n,r,s){if(!i.editable||r.classList.contains("editing"))return;let l;try{l=this.grid.getRowId(e)}catch{}const a=l?b=>this.grid.updateRow(l,b,"cascade"):Nt,c=se(i.field)?e[i.field]:void 0;r.classList.add("editing"),this.#s.add(`${t}:${n}`);const d=r.parentElement;d&&Uo(d);let u=!1;const h=b=>{u||this.#e===-1||this.#w(t,i,b,e)},f=()=>{u=!0,se(i.field)&&(e[i.field]=c)},p=document.createElement("div");p.className="tbw-editor-host",r.innerHTML="",r.appendChild(p),p.addEventListener("keydown",b=>{b.key==="Enter"&&(b.stopPropagation(),b.preventDefault(),u=!0,this.#l(t,!1)),b.key==="Escape"&&(b.stopPropagation(),b.preventDefault(),f(),this.#l(t,!0))});const g=i,w=g.__editorTemplate,m=$o(this.grid,g)??Ot(i),y=c;if(m==="template"&&w)this.#a(p,g,e,c,h,f,s,t);else if(typeof m=="string"){const b=document.createElement(m);b.value=y,b.addEventListener("change",()=>h(b.value)),p.appendChild(b),s||queueMicrotask(()=>{p.querySelector(Oe)?.focus({preventScroll:!0})})}else if(typeof m=="function"){const b={row:e,rowId:l??"",value:y,field:i.field,column:i,commit:h,cancel:f,updateRow:a},_=m(b);typeof _=="string"?(p.innerHTML=_,Yo(p,i,h)):_ instanceof Node&&p.appendChild(_),s||queueMicrotask(()=>{p.querySelector(Oe)?.focus({preventScroll:!0})})}else if(m&&typeof m=="object"){const b=document.createElement("div");b.setAttribute("data-external-editor",""),b.setAttribute("data-field",i.field),p.appendChild(b);const _={row:e,rowId:l??"",value:y,field:i.field,column:i,commit:h,cancel:f,updateRow:a};if(m.mount)try{m.mount({placeholder:b,context:_,spec:m})}catch(x){console.warn(`[tbw-grid] External editor mount error for column '${i.field}':`,x)}else this.grid.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:b,spec:m,context:_}}))}}#a(e,t,i,n,r,s,l,a){const c=t.__editorTemplate;if(!c)return;const d=c.cloneNode(!0),u=t.__compiledEditor;u?d.innerHTML=u({row:i,value:n,field:t.field,column:t,commit:r,cancel:s}):d.querySelectorAll("*").forEach(f=>{f.childNodes.length===1&&f.firstChild?.nodeType===Node.TEXT_NODE&&(f.textContent=f.textContent?.replace(/{{\s*value\s*}}/g,n==null?"":String(n)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(p,g)=>{if(!se(g))return"";const w=i[g];return w==null?"":String(w)})||"")});const h=d.querySelector("input,textarea,select");if(h){h instanceof HTMLInputElement&&h.type==="checkbox"?h.checked=!!n:h.value=String(n??"");let f=!1;h.addEventListener("blur",()=>{f||r(le(h,t))}),h.addEventListener("keydown",p=>{const g=p;g.key==="Enter"&&(g.stopPropagation(),g.preventDefault(),f=!0,r(le(h,t)),this.#l(a,!1)),g.key==="Escape"&&(g.stopPropagation(),g.preventDefault(),s(),this.#l(a,!0))}),h instanceof HTMLInputElement&&h.type==="checkbox"&&h.addEventListener("change",()=>r(h.checked)),l||setTimeout(()=>h.focus({preventScroll:!0}),0)}e.appendChild(d)}#b(e){queueMicrotask(()=>{try{const t=e._focusRow,i=e._focusCol,n=e.findRenderedRowElement?.(t);if(n){Array.from(e._bodyEl.querySelectorAll(".cell-focus")).forEach(s=>s.classList.remove("cell-focus"));const r=n.querySelector(`.cell[data-row="${t}"][data-col="${i}"]`);r&&(r.classList.add("cell-focus"),r.setAttribute("aria-selected","true"),r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1"),r.focus({preventScroll:!0}))}}catch{}})}}function zt(o,e=!0){if(o==null)return"";if(o instanceof Date)return o.toISOString();if(typeof o=="object")return JSON.stringify(o);const t=String(o);return e&&(t.includes(",")||t.includes('"')||t.includes(`
66
+ `)||t.includes("\r"))?`"${t.replace(/"/g,'""')}"`:t}function Zo(o,e,t,i={}){const n=i.delimiter??",",r=i.newline??`
67
+ `,s=[],l=i.bom?"\uFEFF":"";if(t.includeHeaders!==!1){const a=e.map(c=>{const d=c.header||c.field,u=t.processHeader?t.processHeader(d,c.field):d;return zt(u)});s.push(a.join(n))}for(const a of o){const c=e.map(d=>{let u=a[d.field];return t.processCell&&(u=t.processCell(u,d.field,a)),zt(u)});s.push(c.join(n))}return l+s.join(r)}function Ne(o,e){const t=URL.createObjectURL(o),i=document.createElement("a");i.href=t,i.download=e,i.style.display="none",document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(t)}function Jo(o,e){const t=new Blob([o],{type:"text/csv;charset=utf-8;"});Ne(t,e)}function qt(o){return o.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}function Qo(o,e,t){let i=`<?xml version="1.0" encoding="UTF-8"?>
68
68
  <?mso-application progid="Excel.Sheet"?>
69
69
  <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
70
70
  xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
71
71
  <Worksheet ss:Name="Sheet1">
72
72
  <Table>`;if(t.includeHeaders!==!1){i+=`
73
- <Row>`;for(const o of e){const r=o.header||o.field,s=t.processHeader?t.processHeader(r,o.field):r;i+=`<Cell><Data ss:Type="String">${Ot(s)}</Data></Cell>`}i+="</Row>"}for(const o of n){i+=`
74
- <Row>`;for(const r of e){let s=o[r.field];t.processCell&&(s=t.processCell(s,r.field,o));let l="String",a="";s==null?a="":typeof s=="number"&&!isNaN(s)?(l="Number",a=String(s)):s instanceof Date?(l="DateTime",a=s.toISOString()):a=Ot(String(s)),i+=`<Cell><Data ss:Type="${l}">${a}</Data></Cell>`}i+="</Row>"}return i+=`
73
+ <Row>`;for(const n of e){const r=n.header||n.field,s=t.processHeader?t.processHeader(r,n.field):r;i+=`<Cell><Data ss:Type="String">${qt(s)}</Data></Cell>`}i+="</Row>"}for(const n of o){i+=`
74
+ <Row>`;for(const r of e){let s=n[r.field];t.processCell&&(s=t.processCell(s,r.field,n));let l="String",a="";s==null?a="":typeof s=="number"&&!isNaN(s)?(l="Number",a=String(s)):s instanceof Date?(l="DateTime",a=s.toISOString()):a=qt(String(s)),i+=`<Cell><Data ss:Type="${l}">${a}</Data></Cell>`}i+="</Row>"}return i+=`
75
75
  </Table>
76
76
  </Worksheet>
77
- </Workbook>`,i}function Vn(n,e){const t=e.endsWith(".xls")?e:`${e}.xls`,i=new Blob([n],{type:"application/vnd.ms-excel;charset=utf-8;"});Me(i,t)}class Wn extends P{name="export";get defaultConfig(){return{fileName:"export",includeHeaders:!0,onlyVisible:!0,onlySelected:!1}}isExportingFlag=!1;lastExportInfo=null;performExport(e,t){const i=this.config,o={format:e,fileName:t?.fileName??i.fileName??"export",includeHeaders:t?.includeHeaders??i.includeHeaders,processCell:t?.processCell,processHeader:t?.processHeader,columns:t?.columns,rowIndices:t?.rowIndices};let r=[...this.columns];if(i.onlyVisible&&(r=r.filter(a=>!a.hidden&&!a.field.startsWith("__"))),t?.columns){const a=new Set(t.columns);r=r.filter(c=>a.has(c.field))}let s=[...this.rows];if(i.onlySelected){const a=this.getSelectionState();a?.selected?.size&&(s=[...a.selected].sort((d,u)=>d-u).map(d=>this.rows[d]).filter(Boolean))}t?.rowIndices&&(s=t.rowIndices.map(a=>this.rows[a]).filter(Boolean)),this.isExportingFlag=!0;let l=o.fileName;try{switch(e){case"csv":{const a=Gn(s,r,o,{bom:!0});l=l.endsWith(".csv")?l:`${l}.csv`,Kn(a,l);break}case"excel":{const a=Bn(s,r,o);l=l.endsWith(".xls")?l:`${l}.xls`,Vn(a,l);break}case"json":{const a=s.map(u=>{const h={};for(const g of r){let f=u[g.field];o.processCell&&(f=o.processCell(f,g.field,u)),h[g.field]=f}return h}),c=JSON.stringify(a,null,2);l=l.endsWith(".json")?l:`${l}.json`;const d=new Blob([c],{type:"application/json"});Me(d,l);break}}this.lastExportInfo={format:e,timestamp:new Date},this.emit("export-complete",{format:e,fileName:l,rowCount:s.length,columnCount:r.length})}finally{this.isExportingFlag=!1}}getSelectionState(){try{return this.grid?.getPluginState?.("selection")??null}catch{return null}}exportCsv(e){this.performExport("csv",e)}exportExcel(e){this.performExport("excel",e)}exportJson(e){this.performExport("json",e)}isExporting(){return this.isExportingFlag}getLastExport(){return this.lastExportInfo}}function $n(n){const{totalRows:e,viewportHeight:t,scrollTop:i,rowHeight:o,overscan:r}=n,s=Math.ceil(t/o);let l=Math.floor(i/o)-r;l<0&&(l=0);let a=l+s+r*2;return a>e&&(a=e),a===e&&l>0&&(l=Math.max(0,a-s-r*2)),{start:l,end:a,offsetY:l*o,totalHeight:e*o}}function Un(n,e){return n<=e}function jn(n,e,t=!1){const i=n[e.field];if(e.operator==="blank")return i==null||i==="";if(e.operator==="notBlank")return i!=null&&i!=="";if(i==null)return!1;const o=String(i),r=t?o:o.toLowerCase(),s=t?String(e.value):String(e.value).toLowerCase();switch(e.operator){case"contains":return r.includes(s);case"notContains":return!r.includes(s);case"equals":return r===s;case"notEquals":return r!==s;case"startsWith":return r.startsWith(s);case"endsWith":return r.endsWith(s);case"lessThan":return Number(i)<Number(e.value);case"lessThanOrEqual":return Number(i)<=Number(e.value);case"greaterThan":return Number(i)>Number(e.value);case"greaterThanOrEqual":return Number(i)>=Number(e.value);case"between":return Number(i)>=Number(e.value)&&Number(i)<=Number(e.valueTo);case"in":return Array.isArray(e.value)&&e.value.includes(i);case"notIn":return Array.isArray(e.value)&&!e.value.includes(i);default:return!0}}function Yn(n,e,t=!1){return e.length?n.filter(i=>e.every(o=>jn(i,o,t))):n}function Xn(n){return JSON.stringify(n.map(e=>({field:e.field,operator:e.operator,value:e.value,valueTo:e.valueTo})))}function Nt(n,e){const t=new Set;for(const i of n){const o=i[e];o!=null&&t.add(o)}return[...t].sort((i,o)=>typeof i=="number"&&typeof o=="number"?i-o:String(i).localeCompare(String(o)))}const Zn='@layer tbw-plugins{tbw-grid .tbw-quick-filter-input{flex:1;max-width:300px;height:var(--tbw-input-height, 1.75rem);padding:var(--tbw-input-padding, 0 .5rem);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:var(--tbw-font-size-sm, .8125rem)}tbw-grid .tbw-quick-filter-input:focus{outline:none;border-color:var(--tbw-color-accent)}tbw-grid .header-cell.filtered:before{content:"";position:absolute;top:var(--tbw-spacing-xs, .25rem);right:var(--tbw-spacing-xs, .25rem);width:var(--tbw-indicator-size, .375rem);height:var(--tbw-indicator-size, .375rem);background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border-radius:50%}tbw-grid .tbw-filter-btn{display:inline-flex;align-items:center;justify-content:center;background:transparent;border:none;cursor:pointer;padding:2px;margin-left:var(--tbw-spacing-xs, .25rem);opacity:.4;transition:opacity .15s;color:inherit;vertical-align:middle}tbw-grid .tbw-filter-btn:hover,tbw-grid .tbw-filter-btn.active{opacity:1}tbw-grid .tbw-filter-btn.active{color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6))}}',Jn="@layer tbw-plugins{.tbw-filter-panel{position:fixed;background:var(--tbw-filter-panel-bg, var(--tbw-color-panel-bg, light-dark(#eeeeee, #222222)));color:var(--tbw-filter-panel-fg, var(--tbw-color-fg, light-dark(#222222, #eeeeee)));border:1px solid var(--tbw-filter-panel-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-filter-panel-radius, var(--tbw-border-radius, .25rem));box-shadow:0 4px 16px var(--tbw-filter-panel-shadow, var(--tbw-color-shadow, light-dark(rgba(0, 0, 0, .1), rgba(0, 0, 0, .3))));padding:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));z-index:10000;min-width:200px;max-width:280px;max-height:350px;display:flex;flex-direction:column;font-family:var(--tbw-font-family, system-ui, sans-serif);font-size:var(--tbw-font-size, .8125rem);transform-origin:top center}.tbw-filter-panel.tbw-filter-panel-above{transform-origin:bottom center}.tbw-filter-panel.tbw-filter-panel-animated{animation:tbw-filter-panel-enter var(--tbw-animation-duration, .15s) var(--tbw-animation-easing, ease-out)}.tbw-filter-panel.tbw-filter-panel-above.tbw-filter-panel-animated{animation:tbw-filter-panel-enter-above var(--tbw-animation-duration, .15s) var(--tbw-animation-easing, ease-out)}@keyframes tbw-filter-panel-enter{0%{opacity:0;transform:scaleY(.3) translateY(-10px)}to{opacity:1;transform:scaleY(1) translateY(0)}}@keyframes tbw-filter-panel-enter-above{0%{opacity:0;transform:scaleY(.3) translateY(10px)}to{opacity:1;transform:scaleY(1) translateY(0)}}@supports (anchor-name: --test){.tbw-filter-panel{position-anchor:--tbw-filter-anchor;top:anchor(bottom);left:anchor(left);margin-top:4px;position-try-fallbacks:flip-inline,flip-block,flip-block flip-inline}}.tbw-filter-search{margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-filter-search-input{width:100%;padding:var(--tbw-button-padding, .375rem .625rem);background:var(--tbw-filter-input-bg, var(--tbw-color-bg, transparent));color:inherit;border:1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-filter-input-radius, var(--tbw-border-radius, .25rem));font-size:inherit;box-sizing:border-box}.tbw-filter-search-input:focus{outline:none;border-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));box-shadow:0 0 0 2px rgba(from var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6)) r g b / 15%)}.tbw-filter-actions{display:flex;padding:var(--tbw-button-padding-sm, .25rem .125rem);margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border-bottom:1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)))}.tbw-filter-action-btn{background:transparent;border:none;color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));cursor:pointer;font-size:var(--tbw-font-size-xs, .75rem);padding:2px 0}.tbw-filter-action-btn:hover{text-decoration:underline}.tbw-filter-values{flex:1;overflow-y:auto;margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));max-height:180px;position:relative}.tbw-filter-values-spacer{width:1px}.tbw-filter-values-content{position:absolute;top:0;left:0;right:0}.tbw-filter-value-item{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding:var(--tbw-button-padding-sm, .25rem .125rem);cursor:pointer;border-radius:3px}.tbw-filter-value-item:hover{background:var(--tbw-filter-hover, var(--tbw-color-row-hover, light-dark(#f0f6ff, #1c1c1c)))}.tbw-filter-checkbox{margin:0;cursor:pointer;accent-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6))}.tbw-filter-no-match{color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem)) 0;text-align:center;font-style:italic}.tbw-filter-buttons{display:flex;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding-top:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border-top:1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)))}.tbw-filter-apply-btn{flex:1;padding:var(--tbw-button-padding, .375rem .75rem);background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));color:var(--tbw-filter-accent-fg, var(--tbw-color-accent-fg, light-dark(#ffffff, #000000)));border:none;border-radius:var(--tbw-border-radius, .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem)}.tbw-filter-apply-btn:hover{filter:brightness(.9)}.tbw-filter-clear-btn{flex:1;padding:var(--tbw-button-padding, .375rem .75rem);background:transparent;color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));border:1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-border-radius, .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem)}.tbw-filter-clear-btn:hover{background:var(--tbw-filter-hover, var(--tbw-color-row-hover, light-dark(#f0f6ff, #1c1c1c)))}}";class z extends P{name="filtering";styles=Zn;get defaultConfig(){return{debounceMs:300,caseSensitive:!1,trimInput:!0,useWorker:!0}}filters=new Map;cachedResult=null;cacheKey=null;openPanelField=null;panelElement=null;panelAnchorElement=null;searchText=new Map;excludedValues=new Map;panelAbortController=null;globalStylesInjected=!1;static LIST_ITEM_HEIGHT=28;static LIST_OVERSCAN=3;static LIST_BYPASS_THRESHOLD=50;syncExcludedValues(e,t){t?t.type==="set"&&t.operator==="notIn"&&Array.isArray(t.value)?this.excludedValues.set(e,new Set(t.value)):t.type==="set"&&this.excludedValues.delete(e):this.excludedValues.delete(e)}attach(e){super.attach(e),this.injectGlobalStyles()}detach(){this.filters.clear(),this.cachedResult=null,this.cacheKey=null,this.openPanelField=null,this.panelElement&&(this.panelElement.remove(),this.panelElement=null),this.searchText.clear(),this.excludedValues.clear(),this.panelAbortController?.abort(),this.panelAbortController=null}processRows(e){const t=[...this.filters.values()];if(!t.length)return[...e];if(this.config.filterHandler)return this.cachedResult?this.cachedResult:[...e];const i=Xn(t);if(this.cacheKey===i&&this.cachedResult)return this.cachedResult;const o=Yn([...e],t,this.config.caseSensitive);return this.cachedResult=o,this.cacheKey=i,o}afterRender(){const e=this.gridElement;if(!e)return;e.querySelectorAll('[part~="header-cell"]').forEach(i=>{const o=i.getAttribute("data-col");if(o===null)return;const r=this.visibleColumns[parseInt(o,10)];if(!r||r.filterable===!1||B(r))return;const s=r.field;if(!s)return;const l=this.filters.has(s);let a=i.querySelector(".tbw-filter-btn");if(a){a.classList.toggle("active",l),i.classList.toggle("filtered",l);return}a=document.createElement("button"),a.className="tbw-filter-btn",a.setAttribute("aria-label",`Filter ${r.header??s}`),a.innerHTML='<svg viewBox="0 0 16 16" width="12" height="12"><path fill="currentColor" d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></svg>',l&&(a.classList.add("active"),i.classList.add("filtered")),a.addEventListener("click",d=>{d.stopPropagation(),this.toggleFilterPanel(s,r,a)});const c=i.querySelector(".resize-handle");c?i.insertBefore(a,c):i.appendChild(a)})}setFilter(e,t){if(t===null)this.filters.delete(e),this.syncExcludedValues(e,null);else{const i={...t,field:e};this.filters.set(e,i),this.syncExcludedValues(e,i)}this.cachedResult=null,this.cacheKey=null,this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0}),this.requestRender()}getFilter(e){return this.filters.get(e)}getFilters(){return[...this.filters.values()]}getFilterModel(){return this.getFilters()}setFilterModel(e){this.filters.clear(),this.excludedValues.clear();for(const t of e)this.filters.set(t.field,t),this.syncExcludedValues(t.field,t);this.cachedResult=null,this.cacheKey=null,this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0}),this.requestRender()}clearAllFilters(){this.filters.clear(),this.excludedValues.clear(),this.searchText.clear(),this.applyFiltersInternal()}clearFieldFilter(e){this.filters.delete(e),this.excludedValues.delete(e),this.searchText.delete(e),this.applyFiltersInternal()}isFieldFiltered(e){return this.filters.has(e)}getFilteredRowCount(){return this.cachedResult?.length??this.rows.length}getActiveFilters(){return this.getFilters()}getUniqueValues(e){return Nt(this.sourceRows,e)}injectGlobalStyles(){if(this.globalStylesInjected)return;if(document.getElementById("tbw-filter-panel-styles")){this.globalStylesInjected=!0;return}const e=document.createElement("style");e.id="tbw-filter-panel-styles",e.textContent=Jn,document.head.appendChild(e),this.globalStylesInjected=!0}toggleFilterPanel(e,t,i){if(this.openPanelField===e){this.closeFilterPanel();return}this.closeFilterPanel();const o=document.createElement("div");if(o.className="tbw-filter-panel",this.isAnimationEnabled&&o.classList.add("tbw-filter-panel-animated"),this.panelElement=o,this.openPanelField=e,this.config.valuesHandler){o.innerHTML='<div class="tbw-filter-loading">Loading...</div>',document.body.appendChild(o),this.positionPanel(o,i),this.setupPanelCloseHandler(o,i),this.config.valuesHandler(e,t).then(s=>{this.openPanelField!==e||!this.panelElement||(o.innerHTML="",this.renderPanelContent(e,t,o,s))});return}const r=Nt(this.sourceRows,e);this.renderPanelContent(e,t,o,r),document.body.appendChild(o),this.positionPanel(o,i),this.setupPanelCloseHandler(o,i)}renderPanelContent(e,t,i,o){let r=this.excludedValues.get(e);r||(r=new Set,this.excludedValues.set(e,r));const s=this.searchText.get(e)??"",l={field:e,column:t,uniqueValues:o,excludedValues:r,searchText:s,applySetFilter:c=>{this.applySetFilter(e,c),this.closeFilterPanel()},applyTextFilter:(c,d,u)=>{this.applyTextFilter(e,c,d,u),this.closeFilterPanel()},clearFilter:()=>{this.clearFieldFilter(e),this.closeFilterPanel()},closePanel:()=>this.closeFilterPanel()};let a=!1;this.config.filterPanelRenderer&&(this.config.filterPanelRenderer(i,l),a=i.children.length>0),a||this.renderDefaultFilterPanel(i,l,o,r)}setupPanelCloseHandler(e,t){this.panelAbortController=new AbortController,setTimeout(()=>{document.addEventListener("click",i=>{!e.contains(i.target)&&i.target!==t&&this.closeFilterPanel()},{signal:this.panelAbortController?.signal})},0)}closeFilterPanel(){const e=this.panelElement;e&&(e.remove(),this.panelElement=null),this.panelAnchorElement&&(this.panelAnchorElement.style.anchorName="",this.panelAnchorElement=null),this.openPanelField=null,this.panelAbortController?.abort(),this.panelAbortController=null}static supportsAnchorPositioning=null;static checkAnchorPositioningSupport(){return z.supportsAnchorPositioning===null&&(z.supportsAnchorPositioning=CSS.supports("anchor-name","--test")),z.supportsAnchorPositioning}positionPanel(e,t){const o=t.closest(".cell")??t;if(o.style.anchorName="--tbw-filter-anchor",this.panelAnchorElement=o,z.checkAnchorPositioningSupport()){requestAnimationFrame(()=>{const s=e.getBoundingClientRect(),l=o.getBoundingClientRect();s.top<l.top&&e.classList.add("tbw-filter-panel-above")});return}const r=o.getBoundingClientRect();e.style.position="fixed",e.style.top=`${r.bottom+4}px`,e.style.left=`${r.left}px`,requestAnimationFrame(()=>{const s=e.getBoundingClientRect();s.right>window.innerWidth-8&&(e.style.left=`${r.right-s.width}px`),s.bottom>window.innerHeight-8&&(e.style.top=`${r.top-s.height-4}px`,e.classList.add("tbw-filter-panel-above"))})}renderDefaultFilterPanel(e,t,i,o){const{field:r}=t,s=document.createElement("div");s.className="tbw-filter-search";const l=document.createElement("input");l.type="text",l.placeholder="Search...",l.className="tbw-filter-search-input",l.value=this.searchText.get(r)??"",s.appendChild(l),e.appendChild(s);const a=document.createElement("div");a.className="tbw-filter-actions";const c=document.createElement("label");c.className="tbw-filter-value-item",c.style.padding="0",c.style.margin="0";const d=document.createElement("input");d.type="checkbox",d.className="tbw-filter-checkbox";const u=document.createElement("span");u.textContent="Select All",c.appendChild(d),c.appendChild(u),a.appendChild(c);const h=()=>{const y=[...w.values()],E=y.every(k=>k),A=y.every(k=>!k);d.checked=E,d.indeterminate=!E&&!A};d.addEventListener("change",()=>{const y=d.checked;for(const E of w.keys())w.set(E,y);h(),v()}),e.appendChild(a);const g=document.createElement("div");g.className="tbw-filter-values";const f=document.createElement("div");f.className="tbw-filter-values-spacer",g.appendChild(f);const p=document.createElement("div");p.className="tbw-filter-values-content",g.appendChild(p);const w=new Map;i.forEach(y=>{const E=y==null?"__null__":String(y);w.set(E,!o.has(y))}),h();let m=[];const C=(y,E)=>{const A=y==null?"(Blank)":String(y),k=y==null?"__null__":String(y),T=document.createElement("label");T.className="tbw-filter-value-item",T.style.position="absolute",T.style.top=`${E*z.LIST_ITEM_HEIGHT}px`,T.style.left="0",T.style.right="0",T.style.height=`${z.LIST_ITEM_HEIGHT}px`,T.style.boxSizing="border-box";const F=document.createElement("input");F.type="checkbox",F.className="tbw-filter-checkbox",F.checked=w.get(k)??!0,F.dataset.value=k,F.addEventListener("change",()=>{w.set(k,F.checked),h()});const di=document.createElement("span");return di.textContent=A,T.appendChild(F),T.appendChild(di),T},v=()=>{const y=m.length,E=g.clientHeight,A=g.scrollTop;if(f.style.height=`${y*z.LIST_ITEM_HEIGHT}px`,Un(y,z.LIST_BYPASS_THRESHOLD/3)){p.innerHTML="",p.style.transform="translateY(0px)",m.forEach((T,F)=>{p.appendChild(C(T,F))});return}const k=$n({totalRows:y,viewportHeight:E,scrollTop:A,rowHeight:z.LIST_ITEM_HEIGHT,overscan:z.LIST_OVERSCAN});p.style.transform=`translateY(${k.offsetY}px)`,p.innerHTML="";for(let T=k.start;T<k.end;T++)p.appendChild(C(m[T],T-k.start))},b=y=>{const E=this.config.caseSensitive??!1,A=E?y:y.toLowerCase();if(m=i.filter(k=>{const T=k==null?"(Blank)":String(k),F=E?T:T.toLowerCase();return!y||F.includes(A)}),m.length===0){f.style.height="0px",p.innerHTML="";const k=document.createElement("div");k.className="tbw-filter-no-match",k.textContent="No matching values",p.appendChild(k);return}v()};g.addEventListener("scroll",()=>{m.length>0&&v()},{passive:!0}),b(l.value),e.appendChild(g);let R;l.addEventListener("input",()=>{clearTimeout(R),R=setTimeout(()=>{this.searchText.set(r,l.value),b(l.value)},this.config.debounceMs??150)});const _=document.createElement("div");_.className="tbw-filter-buttons";const S=document.createElement("button");S.className="tbw-filter-apply-btn",S.textContent="Apply",S.addEventListener("click",()=>{const y=[];for(const[E,A]of w)if(!A)if(E==="__null__")y.push(null);else{const k=i.find(T=>String(T)===E);y.push(k!==void 0?k:E)}t.applySetFilter(y)}),_.appendChild(S);const O=document.createElement("button");O.className="tbw-filter-clear-btn",O.textContent="Clear Filter",O.addEventListener("click",()=>{t.clearFilter()}),_.appendChild(O),e.appendChild(_)}applySetFilter(e,t){this.excludedValues.set(e,new Set(t)),t.length===0?this.filters.delete(e):this.filters.set(e,{field:e,type:"set",operator:"notIn",value:t}),this.applyFiltersInternal()}applyTextFilter(e,t,i,o){this.filters.set(e,{field:e,type:"text",operator:t,value:i,valueTo:o}),this.applyFiltersInternal()}applyFiltersInternal(){this.cachedResult=null,this.cacheKey=null;const e=[...this.filters.values()];if(this.config.filterHandler){const t=this.grid;t.setAttribute("aria-busy","true");const i=this.config.filterHandler(e,this.sourceRows),o=r=>{t.removeAttribute("aria-busy"),this.cachedResult=r,this.grid.rows=r,this.emit("filter-change",{filters:e,filteredRowCount:r.length}),this.requestRender()};i&&typeof i.then=="function"?i.then(o):o(i);return}this.emit("filter-change",{filters:e,filteredRowCount:0}),this.requestRender()}getColumnState(e){const t=this.filters.get(e);if(t)return{filter:{type:t.type,operator:t.operator,value:t.value,valueTo:t.valueTo}}}applyColumnState(e,t){if(!t.filter){this.filters.delete(e);return}const i={field:e,type:t.filter.type,operator:t.filter.operator,value:t.filter.value,valueTo:t.filter.valueTo};this.filters.set(e,i),this.cachedResult=null,this.cacheKey=null}}function zt(n){if(!n.length)return[];const e=new Map,t=[],i=(s,l)=>{if(!l.length)return;const a=t[t.length-1];if(a&&a.implicit&&a.firstIndex+a.columns.length===s){a.columns.push(...l);return}t.push({id:"__implicit__"+s,label:void 0,columns:l,firstIndex:s,implicit:!0})};let o=[],r=0;return n.forEach((s,l)=>{const a=s.group;if(!a){o.length===0&&(r=l),o.push(s);return}o.length&&(i(r,o.slice()),o=[]);const c=typeof a=="string"?a:a.id;let d=e.get(c);d||(d={id:c,label:typeof a=="string"?void 0:a.label,columns:[],firstIndex:l},e.set(c,d),t.push(d)),d.columns.push(s)}),o.length&&i(r,o),t.length===1&&t[0].implicit&&t[0].columns.length===n.length?[]:t}function Qn(n,e,t){if(!e.length||!n)return;const i=new Map;for(const r of e)for(const s of r.columns)s.field&&i.set(s.field,r.id);const o=Array.from(n.querySelectorAll(".cell[data-field]"));o.forEach(r=>{const s=r.getAttribute("data-field")||"",l=i.get(s);l&&(r.classList.add("grouped"),r.getAttribute("data-group")||r.setAttribute("data-group",l))});for(const r of e){const s=r.columns[r.columns.length-1],l=o.find(a=>a.getAttribute("data-field")===s.field);l&&l.classList.add("group-end")}}function eo(n,e){if(n.length===0)return null;const t=document.createElement("div");t.className="header-group-row",t.setAttribute("role","row");for(const i of n){const o=i.columns[0],r=o?e.findIndex(c=>c.field===o.field):-1;if(r===-1)continue;const s=String(i.id).startsWith("__implicit__"),l=s?"":i.label||i.id,a=document.createElement("div");a.className="cell header-group-cell",s&&a.classList.add("implicit-group"),a.setAttribute("data-group",String(i.id)),a.style.gridColumn=`${r+1} / span ${i.columns.length}`,a.textContent=l,t.appendChild(a)}return t}function to(n){return n.some(e=>e.group!=null)}const io="@layer tbw-plugins{.header-group-row{display:grid;grid-auto-flow:column;background:var(--tbw-grouping-columns-header-bg, var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-grouping-columns-border, var(--tbw-color-border))}.header-group-cell{display:flex;align-items:center;justify-content:center;padding:var(--tbw-button-padding-sm, .25rem .5rem);font-weight:600;font-size:var(--tbw-font-size-sm, .9em);text-transform:uppercase;letter-spacing:.5px;border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-group-cell:last-child{border-right:none}.header-row .cell.grouped{border-top:none}.header-row .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-row .cell.group-end:last-child{border-right:none}.rows .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.rows .cell.group-end:last-child{border-right:none}.header-group-row.no-borders{border-bottom:none}.header-group-row.no-borders .header-group-cell{border-right:none}.header-row.no-group-borders .cell.group-end{border-right:1px solid var(--tbw-color-border)}}";class no extends P{static manifest={ownedProperties:[{property:"group",level:"column",description:'the "group" column property'},{property:"columnGroups",level:"config",description:'the "columnGroups" config property',isUsed:e=>Array.isArray(e)&&e.length>0}]};name="groupingColumns";styles=io;get defaultConfig(){return{showGroupBorders:!0}}groups=[];isActive=!1;detach(){this.groups=[],this.isActive=!1}static detect(e,t){if(t?.columnGroups&&Array.isArray(t.columnGroups)&&t.columnGroups.length>0)return!0;const i=t?.columns;return Array.isArray(i)?to(i):!1}processColumns(e){const t=this.grid?.gridConfig?.columnGroups;let i;if(t&&Array.isArray(t)&&t.length>0){const r=new Map;for(const s of t)for(const l of s.children)r.set(l,{id:s.id,label:s.header});i=e.map(s=>{const l=r.get(s.field);return l&&!s.group?{...s,group:l}:s})}else i=[...e];const o=zt(i);return o.length===0?(this.isActive=!1,this.groups=[],i):(this.isActive=!0,this.groups=o,i)}afterRender(){if(!this.isActive){const a=this.gridElement?.querySelector(".header")?.querySelector(".header-group-row");a&&a.remove();return}const e=this.gridElement?.querySelector(".header");if(!e)return;const t=e.querySelector(".header-group-row");t&&t.remove();const i=this.columns,o=zt(i);if(o.length===0)return;const r=eo(o,i);if(r){r.classList.toggle("no-borders",!this.config.showGroupBorders);const l=e.querySelector(".header-row");l?e.insertBefore(r,l):e.appendChild(r)}const s=e.querySelector(".header-row");s&&(s.classList.toggle("no-group-borders",!this.config.showGroupBorders),Qn(s,o)),this.#e(o)}#e(e){if(!this.config.showGroupBorders)return;const t=this.gridElement;if(!t)return;const i=new Set;for(const r of e){const s=r.columns[r.columns.length-1];s?.field&&i.add(s.field)}const o=t.querySelectorAll(".rows .cell[data-field]");for(const r of o){const s=r.getAttribute("data-field");s&&i.has(s)?r.classList.add("group-end"):r.classList.remove("group-end")}}isGroupingActive(){return this.isActive}getGroups(){return this.groups}getGroupColumns(e){const t=this.groups.find(i=>i.id===e);return t?t.columns:[]}refresh(){this.requestRender()}}const Oe={sum:(n,e)=>n.reduce((t,i)=>t+(Number(i[e])||0),0),avg:(n,e)=>{const t=n.reduce((i,o)=>i+(Number(o[e])||0),0);return n.length?t/n.length:0},count:n=>n.length,min:(n,e)=>Math.min(...n.map(t=>Number(t[e])||1/0)),max:(n,e)=>Math.max(...n.map(t=>Number(t[e])||-1/0)),first:(n,e)=>n[0]?.[e],last:(n,e)=>n[n.length-1]?.[e]},ae=new Map,K={register(n,e){ae.set(n,e)},unregister(n){ae.delete(n)},get(n){if(n!==void 0)return typeof n=="function"?n:ae.get(n)??Oe[n]},run(n,e,t,i){const o=this.get(n);return o?o(e,t,i):void 0},has(n){return ae.has(n)||n in Oe},list(){return[...Object.keys(Oe),...ae.keys()]}},qt={sum:n=>n.reduce((e,t)=>e+t,0),avg:n=>n.length?n.reduce((e,t)=>e+t,0)/n.length:0,count:n=>n.length,min:n=>n.length?Math.min(...n):0,max:n=>n.length?Math.max(...n):0,first:n=>n[0]??0,last:n=>n[n.length-1]??0};function oo(n){return qt[n]??qt.sum}K.register.bind(K),K.unregister.bind(K);const Ft=K.get.bind(K),Gt=K.run.bind(K);K.list.bind(K);function ro({rows:n,config:e,expanded:t}){const i=e.groupOn;if(typeof i!="function")return[];const o={key:"__root__",value:null,depth:-1,rows:[],children:new Map};if(n.forEach(l=>{let a=i(l);a==null||a===!1?a=["__ungrouped__"]:Array.isArray(a)||(a=[a]);let c=o;a.forEach((d,u)=>{const h=d==null?"∅":String(d),g=c.key==="__root__"?h:c.key+"||"+h;let f=c.children.get(h);f||(f={key:g,value:d,depth:u,rows:[],children:new Map,parent:c},c.children.set(h,f)),c=f}),c.rows.push(l)}),o.children.size===1&&o.children.has("__ungrouped__")&&o.children.get("__ungrouped__").rows.length===n.length)return[];const r=[],s=l=>{if(l===o){l.children.forEach(c=>s(c));return}const a=t.has(l.key);r.push({kind:"group",key:l.key,value:l.value,depth:l.depth,rows:l.rows,expanded:a}),a&&(l.children.size?l.children.forEach(c=>s(c)):l.rows.forEach(c=>r.push({kind:"data",row:c,rowIndex:n.indexOf(c)})))};return s(o),r}function so(n,e){const t=new Set(n);return t.has(e)?t.delete(e):t.add(e),t}function lo(n){const e=new Set;for(const t of n)t.kind==="group"&&e.add(t.key);return e}function ao(){return new Set}function co(n){return n.kind!=="group"?0:n.rows.length}const uo="@layer tbw-plugins{.group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-grouping-rows-bg, var(--tbw-color-panel-bg));font-weight:500;border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height)}.group-row .cell{display:flex;align-items:center;padding:var(--tbw-cell-padding, .125rem .5rem)}.group-row:hover{background:var(--tbw-grouping-rows-bg-hover, var(--tbw-color-row-hover))}.group-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-toggle-size, 1.25rem);height:var(--tbw-toggle-size, 1.25rem);margin-right:.25rem;background:none;border:0;font:inherit}.group-toggle:hover{background:var(--tbw-grouping-rows-toggle-hover, var(--tbw-color-row-hover));border-radius:var(--tbw-border-radius, .125rem)}.group-label{display:inline-flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.group-count{color:var(--tbw-grouping-rows-count-color, var(--tbw-color-fg-muted));font-size:var(--tbw-font-size-xs, .85em);font-weight:400}.group-row{padding-left:calc(var(--tbw-group-depth, 0) * var(--tbw-group-indent-width, 1.25em))}.data-grid-row.tbw-group-slide-in{animation:tbw-group-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-group-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.data-grid-row.tbw-group-fade-in{animation:tbw-group-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-group-fade-in{0%{opacity:0}to{opacity:1}}}";class ho extends P{name="groupingRows";styles=uo;get defaultConfig(){return{defaultExpanded:!1,showRowCount:!0,indentWidth:20,aggregators:{},animation:"slide"}}expandedKeys=new Set;flattenedRows=[];isActive=!1;previousVisibleKeys=new Set;keysToAnimate=new Set;get animationStyle(){return this.isAnimationEnabled?this.config.animation??"slide":!1}detach(){this.expandedKeys.clear(),this.flattenedRows=[],this.isActive=!1,this.previousVisibleKeys.clear(),this.keysToAnimate.clear()}static detect(e,t){return typeof t?.groupOn=="function"||typeof t?.enableRowGrouping=="boolean"}processRows(e){const t=this.config;if(typeof t.groupOn!="function")return this.isActive=!1,this.flattenedRows=[],[...e];const i=ro({rows:[...e],config:t,expanded:this.expandedKeys});if(i.length===0)return this.isActive=!1,this.flattenedRows=[],[...e];this.isActive=!0,this.flattenedRows=i,this.keysToAnimate.clear();const o=new Set;return i.forEach((r,s)=>{if(r.kind==="data"){const l=`data-${s}`;o.add(l),this.previousVisibleKeys.has(l)||this.keysToAnimate.add(l)}}),this.previousVisibleKeys=o,i.map(r=>r.kind==="group"?{__isGroupRow:!0,__groupKey:r.key,__groupValue:r.value,__groupDepth:r.depth,__groupRows:r.rows,__groupExpanded:r.expanded,__groupRowCount:co(r)}:r.row)}onCellClick(e){const t=e.row;if(t?.__isGroupRow&&e.originalEvent.target?.closest(".group-toggle"))return this.toggle(t.__groupKey),!0}onKeyDown(e){if(e.key!==" ")return;const t=this.grid._focusRow,i=this.rows[t];if(i?.__isGroupRow)return e.preventDefault(),this.toggle(i.__groupKey),this.requestRenderWithFocus(),!0}renderRow(e,t,i){if(!e?.__isGroupRow)return!1;const o=this.config;if(o.groupRowRenderer){const l=()=>{this.toggle(e.__groupKey)},a=o.groupRowRenderer({key:e.__groupKey,value:e.__groupValue,depth:e.__groupDepth,rows:e.__groupRows,expanded:e.__groupExpanded,toggleExpand:l});if(a)return t.className="data-grid-row group-row",t.__isCustomRow=!0,t.setAttribute("data-group-depth",String(e.__groupDepth)),typeof a=="string"?t.innerHTML=a:(t.innerHTML="",t.appendChild(a)),!0}const r=()=>{this.toggle(e.__groupKey)};return t.className="data-grid-row group-row",t.__isCustomRow=!0,t.setAttribute("data-group-depth",String(e.__groupDepth)),t.setAttribute("role","row"),t.setAttribute("aria-expanded",String(e.__groupExpanded)),t.style.setProperty("--tbw-group-depth",String(e.__groupDepth||0)),o.indentWidth!==void 0&&t.style.setProperty("--tbw-group-indent-width",`${o.indentWidth}px`),t.style.height="",t.innerHTML="",o.fullWidth!==!1?this.renderFullWidthGroupRow(e,t,r):this.renderPerColumnGroupRow(e,t,r),!0}afterRender(){const e=this.animationStyle;if(e===!1||this.keysToAnimate.size===0)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const i=e==="fade"?"tbw-group-fade-in":"tbw-group-slide-in";for(const o of t.querySelectorAll(".data-grid-row:not(.group-row)")){const r=o.querySelector(".cell[data-row]"),s=r?parseInt(r.getAttribute("data-row")??"-1",10):-1,a=this.flattenedRows[s]?.kind==="data"?`data-${s}`:void 0;a&&this.keysToAnimate.has(a)&&(o.classList.add(i),o.addEventListener("animationend",()=>o.classList.remove(i),{once:!0}))}this.keysToAnimate.clear()}createToggleButton(e,t){const i=document.createElement("button");return i.type="button",i.className=`group-toggle${e?" expanded":""}`,i.setAttribute("aria-label",e?"Collapse group":"Expand group"),this.setIcon(i,this.resolveIcon(e?"collapse":"expand")),i.addEventListener("click",o=>{o.stopPropagation(),t()}),i}getGroupLabelText(e,t,i){const o=this.config;return o.formatLabel?o.formatLabel(e,t,i):String(e)}renderFullWidthGroupRow(e,t,i){const o=this.config,r=document.createElement("div");r.className="cell group-full",r.style.gridColumn="1 / -1",r.setAttribute("role","gridcell"),r.setAttribute("data-col","0"),r.appendChild(this.createToggleButton(e.__groupExpanded,i));const s=document.createElement("span");if(s.className="group-label",s.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey),r.appendChild(s),o.showRowCount!==!1){const l=document.createElement("span");l.className="group-count",l.textContent=`(${e.__groupRowCount??e.__groupRows?.length??0})`,r.appendChild(l)}t.appendChild(r)}renderPerColumnGroupRow(e,t,i){const o=this.config,r=o.aggregators??{},s=this.columns,l=e.__groupRows??[],c=this.gridElement?.querySelector(".body")?.style.gridTemplateColumns||"";c&&(t.style.display="grid",t.style.gridTemplateColumns=c);let d=!1;s.forEach((u,h)=>{const g=document.createElement("div");if(g.className="cell group-cell",g.setAttribute("data-col",String(h)),g.setAttribute("role","gridcell"),_e(u)){g.setAttribute("data-field",u.field),t.appendChild(g);return}if(d){const f=r[u.field];if(f){const p=Gt(f,l,u.field,u);g.textContent=p!=null?String(p):""}else g.textContent=""}else{d=!0,g.appendChild(this.createToggleButton(e.__groupExpanded,i));const f=document.createElement("span"),p=r[u.field];if(p){const w=Gt(p,l,u.field,u);f.textContent=w!=null?String(w):String(e.__groupValue)}else f.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey);if(g.appendChild(f),o.showRowCount!==!1){const w=document.createElement("span");w.className="group-count",w.textContent=` (${l.length})`,g.appendChild(w)}}t.appendChild(g)})}expandAll(){this.expandedKeys=lo(this.flattenedRows),this.requestRender()}collapseAll(){this.expandedKeys=ao(),this.requestRender()}toggle(e){this.expandedKeys=so(this.expandedKeys,e);const t=this.flattenedRows.find(i=>i.kind==="group"&&i.key===e);this.emit("group-toggle",{key:e,expanded:this.expandedKeys.has(e),value:t?.value,depth:t?.depth??0}),this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}expand(e){this.expandedKeys.has(e)||(this.expandedKeys=new Set([...this.expandedKeys,e]),this.requestRender())}collapse(e){if(this.expandedKeys.has(e)){const t=new Set(this.expandedKeys);t.delete(e),this.expandedKeys=t,this.requestRender()}}getGroupState(){const e=this.flattenedRows.filter(t=>t.kind==="group");return{isActive:this.isActive,expandedCount:this.expandedKeys.size,totalGroups:e.length,expandedKeys:[...this.expandedKeys]}}getRowCount(){return this.flattenedRows.length}refreshGroups(){this.requestRender()}getExpandedGroups(){return[...this.expandedKeys]}getFlattenedRows(){return this.flattenedRows}isGroupingActive(){return this.isActive}setGroupOn(e){this.config.groupOn=e,this.requestRender()}}function Kt(n,e){const t=new Set(n);return t.has(e)?t.delete(e):t.add(e),t}function fo(n,e){const t=new Set(n);return t.add(e),t}function go(n,e){const t=new Set(n);return t.delete(e),t}function po(n,e){return n.has(e)}function wo(n,e,t,i){const o=document.createElement("div");o.className="master-detail-row",o.setAttribute("data-detail-for",String(e)),o.setAttribute("role","row");const r=document.createElement("div");r.className="master-detail-cell",r.setAttribute("role","cell"),r.style.gridColumn=`1 / ${i+1}`;const s=t(n,e);return typeof s=="string"?r.innerHTML=s:s instanceof HTMLElement&&r.appendChild(s),o.appendChild(r),o}const mo="@layer tbw-plugins{tbw-grid .cell[data-field=__tbw_expander]{border-right:none!important;padding:0;display:flex;align-items:center;justify-content:center}tbw-grid .header-row .cell[data-field=__tbw_expander]{display:none}tbw-grid .header-row .cell[data-field=__tbw_expander]+.cell{grid-column:1 / 3}tbw-grid .master-detail-expander{display:flex;align-items:center;justify-content:center;width:100%;height:100%}tbw-grid .master-detail-toggle{cursor:pointer;opacity:.7;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center}tbw-grid .master-detail-toggle:hover{opacity:1}tbw-grid .master-detail-row{grid-column:1 / -1;display:grid;background:var(--tbw-master-detail-bg, var(--tbw-color-row-alt));border-bottom:1px solid var(--tbw-master-detail-border, var(--tbw-color-border));overflow:hidden}tbw-grid .master-detail-cell{padding:var(--tbw-detail-padding, var(--tbw-spacing-xl, 1rem));overflow:auto}tbw-grid .master-detail-row.tbw-expanding{animation:tbw-detail-expand var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}tbw-grid .master-detail-row.tbw-collapsing{animation:tbw-detail-collapse var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-detail-expand{0%{opacity:0;max-height:0;padding-top:0;padding-bottom:0}to{opacity:1;max-height:var(--tbw-detail-max-height, 31.25rem);padding-top:var(--tbw-detail-padding, var(--tbw-spacing-xl, 1rem));padding-bottom:var(--tbw-detail-padding, var(--tbw-spacing-xl, 1rem))}}@keyframes tbw-detail-collapse{0%{opacity:1;max-height:var(--tbw-detail-max-height, 31.25rem)}to{opacity:0;max-height:0}}}";class Ne extends P{name="masterDetail";styles=mo;get defaultConfig(){return{detailHeight:"auto",expandOnRowClick:!1,collapseOnClickOutside:!1,showExpandColumn:!0,animation:"slide"}}attach(e){super.attach(e),this.parseLightDomDetail()}parseLightDomDetail(){const e=this.grid;if(!e||typeof e.querySelector!="function")return;const t=e.querySelector("tbw-grid-detail");if(!t)return;const i=e;if(i.__frameworkAdapter?.parseDetailElement){const u=i.__frameworkAdapter.parseDetailElement(t);if(u){this.config={...this.config,detailRenderer:u};return}}const o=t.getAttribute("animation"),r=t.getAttribute("show-expand-column"),s=t.getAttribute("expand-on-row-click"),l=t.getAttribute("collapse-on-click-outside"),a=t.getAttribute("height"),c={};o!==null&&(c.animation=o==="false"?!1:o),r!==null&&(c.showExpandColumn=r!=="false"),s!==null&&(c.expandOnRowClick=s==="true"),l!==null&&(c.collapseOnClickOutside=l==="true"),a!==null&&(c.detailHeight=a==="auto"?"auto":parseInt(a,10));const d=t.innerHTML.trim();d&&!this.config.detailRenderer&&(c.detailRenderer=(u,h)=>{const g=we(d,{value:u,row:u});return ie(g)}),Object.keys(c).length>0&&(this.config={...this.config,...c})}get animationStyle(){return this.isAnimationEnabled?this.config.animation??"slide":!1}animateExpand(e){!this.isAnimationEnabled||this.animationStyle===!1||(e.classList.add("tbw-expanding"),e.addEventListener("animationend",()=>{e.classList.remove("tbw-expanding")},{once:!0}))}animateCollapse(e,t){if(!this.isAnimationEnabled||this.animationStyle===!1){t();return}e.classList.add("tbw-collapsing");const i=()=>{e.classList.remove("tbw-collapsing"),t()};e.addEventListener("animationend",i,{once:!0}),setTimeout(i,this.animationDuration+50)}expandedRows=new Set;detailElements=new Map;static DEFAULT_DETAIL_HEIGHT=150;getDetailHeight(e){const t=this.detailElements.get(e);return t?t.offsetHeight:typeof this.config?.detailHeight=="number"?this.config.detailHeight:Ne.DEFAULT_DETAIL_HEIGHT}toggleAndEmit(e,t){this.expandedRows=Kt(this.expandedRows,e),this.emit("detail-expand",{rowIndex:t,row:e,expanded:this.expandedRows.has(e)}),this.requestRender()}detach(){this.expandedRows.clear(),this.detailElements.clear()}processColumns(e){if(!this.config.detailRenderer||this.config.showExpandColumn===!1)return[...e];const t=[...e];if(vn(t))return t;const o=yn(this.name);return o.viewRenderer=r=>{const{row:s}=r,l=this.expandedRows.has(s),a=document.createElement("span");a.className="master-detail-expander expander-cell";const c=document.createElement("span");return c.className=`master-detail-toggle${l?" expanded":""}`,this.setIcon(c,this.resolveIcon(l?"collapse":"expand")),c.setAttribute("role","button"),c.setAttribute("tabindex","0"),c.setAttribute("aria-expanded",String(l)),c.setAttribute("aria-label",l?"Collapse details":"Expand details"),a.appendChild(c),a},[o,...t]}onRowClick(e){if(!(!this.config.expandOnRowClick||!this.config.detailRenderer))return this.toggleAndEmit(e.row,e.rowIndex),!1}onCellClick(e){if(e.originalEvent?.target?.classList.contains("master-detail-toggle"))return this.toggleAndEmit(e.row,e.rowIndex),!0;this.expandedRows.size>0&&queueMicrotask(()=>this.#e())}onKeyDown(e){if(e.key!==" ")return;const t=this.grid._focusCol,i=this.grid._focusRow,o=this.columns[t];if(!o||!_e(o))return;const r=this.rows[i];if(r)return e.preventDefault(),this.toggleAndEmit(r,i),this.requestRenderWithFocus(),!0}afterRender(){this.#e()}onScrollRender(){!this.config.detailRenderer||this.expandedRows.size===0||this.#e()}#e(){if(!this.config.detailRenderer)return;const e=this.gridElement?.querySelector(".rows");if(!e)return;const t=new Map,i=e.querySelectorAll(".data-grid-row"),o=this.columns.length;for(const s of i){const l=s.querySelector(".cell[data-row]"),a=l?parseInt(l.getAttribute("data-row")??"-1",10):-1;a>=0&&t.set(a,s)}const r=e.querySelectorAll(".master-detail-row");for(const s of r){const l=parseInt(s.getAttribute("data-detail-for")??"-1",10),a=l>=0?this.rows[l]:void 0,c=a&&this.expandedRows.has(a),d=t.has(l);(!c||!d)&&(s.remove(),a&&this.detailElements.delete(a))}for(const[s,l]of t){const a=this.rows[s];if(!a||!this.expandedRows.has(a))continue;const c=this.detailElements.get(a);if(c){c.previousElementSibling!==l&&l.after(c);continue}const d=wo(a,s,this.config.detailRenderer,o);typeof this.config.detailHeight=="number"&&(d.style.height=`${this.config.detailHeight}px`),l.after(d),this.detailElements.set(a,d),this.animateExpand(d)}}getExtraHeight(){let e=0;for(const t of this.expandedRows)e+=this.getDetailHeight(t);return e}getExtraHeightBefore(e){let t=0;for(const i of this.expandedRows){const o=this.rows.indexOf(i);o>=0&&o<e&&(t+=this.getDetailHeight(i))}return t}adjustVirtualStart(e,t,i){if(this.expandedRows.size===0)return e;const o=[];for(const l of this.expandedRows){const a=this.rows.indexOf(l);a>=0&&o.push({index:a,row:l})}o.sort((l,a)=>l.index-a.index);let r=e,s=0;for(const{index:l,row:a}of o){const c=l*i+s,d=this.getDetailHeight(a),u=c+i+d;s+=d,!(l>=e)&&u>t&&l<r&&(r=l)}return r}expand(e){const t=this.rows[e];t&&(this.expandedRows=fo(this.expandedRows,t),this.requestRender())}collapse(e){const t=this.rows[e];t&&(this.expandedRows=go(this.expandedRows,t),this.requestRender())}toggle(e){const t=this.rows[e];t&&(this.expandedRows=Kt(this.expandedRows,t),this.requestRender())}isExpanded(e){const t=this.rows[e];return t?po(this.expandedRows,t):!1}expandAll(){for(const e of this.rows)this.expandedRows.add(e);this.requestRender()}collapseAll(){this.expandedRows.clear(),this.requestRender()}getExpandedRows(){const e=[];for(const t of this.expandedRows){const i=this.rows.indexOf(t);i>=0&&e.push(i)}return e}getDetailElement(e){const t=this.rows[e];return t?this.detailElements.get(t):void 0}refreshDetailRenderer(){const e=this.config.detailRenderer;if(this.config={...this.config,detailRenderer:void 0},this.parseLightDomDetail(),!this.config.detailRenderer&&e&&(this.config={...this.config,detailRenderer:e}),this.config.detailRenderer){const t=this.grid;typeof t.refreshColumns=="function"?t.refreshColumns():this.requestRender()}}}function bo(n,e,t){return e.length?[...n].sort((i,o)=>{for(const r of e){const l=t.find(u=>u.field===r.field)?.sortComparator??vo,a=i[r.field],c=o[r.field],d=l(a,c,i,o);if(d!==0)return r.direction==="asc"?d:-d}return 0}):[...n]}function vo(n,e){return n==null&&e==null?0:n==null?1:e==null?-1:typeof n=="number"&&typeof e=="number"?n-e:n instanceof Date&&e instanceof Date?n.getTime()-e.getTime():typeof n=="boolean"&&typeof e=="boolean"?n===e?0:n?-1:1:String(n).localeCompare(String(e))}function yo(n,e,t,i){const o=n.find(r=>r.field===e);return t?o?o.direction==="asc"?n.map(r=>r.field===e?{...r,direction:"desc"}:r):n.filter(r=>r.field!==e):n.length<i?[...n,{field:e,direction:"asc"}]:n:o?.direction==="asc"?[{field:e,direction:"desc"}]:o?.direction==="desc"?[]:[{field:e,direction:"asc"}]}function Bt(n,e){const t=n.findIndex(i=>i.field===e);return t>=0?t+1:void 0}function Vt(n,e){return n.find(t=>t.field===e)?.direction}const Co='@layer tbw-plugins{.header-cell[data-sort=asc]:after{content:"↑";margin-left:4px;opacity:.8}.header-cell[data-sort=desc]:after{content:"↓";margin-left:4px;opacity:.8}.sort-indicator{margin-left:4px;opacity:.8}.sort-index{font-size:10px;background:var(--tbw-multi-sort-badge-bg, var(--tbw-color-panel-bg));color:var(--tbw-multi-sort-badge-color, var(--tbw-color-fg));border-radius:50%;width:14px;height:14px;display:inline-flex;align-items:center;justify-content:center;margin-left:2px;font-weight:600}}';class xo extends P{name="multiSort";styles=Co;get defaultConfig(){return{maxSortColumns:3,showSortIndex:!0}}sortModel=[];detach(){this.sortModel=[]}processRows(e){return this.sortModel.length===0?[...e]:bo([...e],this.sortModel,[...this.columns])}onHeaderClick(e){if(!this.columns.find(r=>r.field===e.field)?.sortable)return!1;const i=e.originalEvent.shiftKey,o=this.config.maxSortColumns??3;return this.sortModel=yo(this.sortModel,e.field,i,o),this.emit("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),!0}afterRender(){const e=this.gridElement;if(!e)return;const t=this.config.showSortIndex!==!1;e.querySelectorAll(".header-row .cell[data-field]").forEach(o=>{const r=o.getAttribute("data-field");if(!r)return;const s=Bt(this.sortModel,r),l=Vt(this.sortModel,r);if(o.querySelector(".sort-index")?.remove(),l){o.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove(),o.setAttribute("data-sort",l);const d=document.createElement("span");d.className="sort-indicator",this.setIcon(d,this.resolveIcon(l==="asc"?"sortAsc":"sortDesc"));const u=o.querySelector(".tbw-filter-btn"),h=o.querySelector(".resize-handle"),g=u??h;if(g?o.insertBefore(d,g):o.appendChild(d),t&&this.sortModel.length>1&&s!==void 0){const f=document.createElement("span");f.className="sort-index",f.textContent=String(s),d.nextSibling?o.insertBefore(f,d.nextSibling):o.appendChild(f)}}else o.removeAttribute("data-sort")})}getSortModel(){return[...this.sortModel]}setSortModel(e){this.sortModel=[...e],this.emit("sort-change",{sortModel:[...e]}),this.requestRender()}clearSort(){this.sortModel=[],this.emit("sort-change",{sortModel:[]}),this.requestRender()}getSortIndex(e){return Bt(this.sortModel,e)}getSortDirection(e){return Vt(this.sortModel,e)}getColumnState(e){const t=this.sortModel.findIndex(o=>o.field===e);return t===-1?void 0:{sort:{direction:this.sortModel[t].direction,priority:t}}}applyColumnState(e,t){if(!t.sort){this.sortModel=this.sortModel.filter(r=>r.field!==e);return}const i=this.sortModel.findIndex(r=>r.field===e),o={field:e,direction:t.sort.direction};i!==-1?this.sortModel[i]=o:this.sortModel.splice(t.sort.priority,0,o)}}function Eo(n){return n.filter(e=>e.sticky==="left")}function Ro(n){return n.filter(e=>e.sticky==="right")}function ze(n){return n.some(e=>e.sticky==="left"||e.sticky==="right")}function Wt(n,e){const t=Array.from(n.querySelectorAll(".header-row .cell"));if(!t.length)return;const i=new Map;e.forEach((s,l)=>{s.field&&i.set(s.field,l)});let o=0;for(const s of e)if(s.sticky==="left"){const l=i.get(s.field),a=t.find(c=>c.getAttribute("data-field")===s.field);a&&(a.classList.add("sticky-left"),a.style.position="sticky",a.style.left=o+"px",l!==void 0&&n.querySelectorAll(`.data-grid-row .cell[data-col="${l}"]`).forEach(c=>{c.classList.add("sticky-left"),c.style.position="sticky",c.style.left=o+"px"}),o+=a.offsetWidth)}let r=0;for(const s of[...e].reverse())if(s.sticky==="right"){const l=i.get(s.field),a=t.find(c=>c.getAttribute("data-field")===s.field);a&&(a.classList.add("sticky-right"),a.style.position="sticky",a.style.right=r+"px",l!==void 0&&n.querySelectorAll(`.data-grid-row .cell[data-col="${l}"]`).forEach(c=>{c.classList.add("sticky-right"),c.style.position="sticky",c.style.right=r+"px"}),r+=a.offsetWidth)}}function $t(n){n.querySelectorAll(".sticky-left, .sticky-right").forEach(t=>{t.classList.remove("sticky-left","sticky-right"),t.style.position="",t.style.left="",t.style.right=""})}class So extends P{static manifest={ownedProperties:[{property:"sticky",level:"column",description:'the "sticky" column property',isUsed:e=>e==="left"||e==="right"}]};name="pinnedColumns";get defaultConfig(){return{}}isApplied=!1;leftOffsets=new Map;rightOffsets=new Map;detach(){this.leftOffsets.clear(),this.rightOffsets.clear(),this.isApplied=!1}static detect(e,t){const i=t?.columns;return Array.isArray(i)?ze(i):!1}processColumns(e){return this.isApplied=ze([...e]),[...e]}afterRender(){if(!this.isApplied)return;const e=this.grid,t=[...this.columns];if(!ze(t)){$t(e),this.isApplied=!1;return}queueMicrotask(()=>{Wt(e,t)})}onPluginQuery(e){switch(e.type){case Se.CAN_MOVE_COLUMN:{const t=e.context,i=t.sticky;if(i==="left"||i==="right")return!1;const o=t.meta?.sticky;return o==="left"||o==="right"?!1:void 0}default:return}}refreshStickyOffsets(){const e=[...this.columns];Wt(this.grid,e)}getLeftPinnedColumns(){const e=[...this.columns];return Eo(e)}getRightPinnedColumns(){const e=[...this.columns];return Ro(e)}clearStickyPositions(){$t(this.grid)}getHorizontalScrollOffsets(e,t){if(!this.isApplied)return;let i=0,o=0;if(e){const s=e.querySelectorAll(".sticky-left"),l=e.querySelectorAll(".sticky-right");s.forEach(a=>{i+=a.offsetWidth}),l.forEach(a=>{o+=a.offsetWidth})}else this.grid.querySelectorAll(".header-row .cell").forEach(a=>{a.classList.contains("sticky-left")?i+=a.offsetWidth:a.classList.contains("sticky-right")&&(o+=a.offsetWidth)});const r=t?.classList.contains("sticky-left")||t?.classList.contains("sticky-right");return{left:i,right:o,skipScroll:r}}}function _o(n){return typeof n=="object"&&n!==null&&"aggFunc"in n}function qe(n,e){const t=document.createElement("div");t.className="tbw-pinned-rows",t.setAttribute("role","presentation"),t.setAttribute("aria-live","polite");const i=document.createElement("div");i.className="tbw-pinned-rows-left";const o=document.createElement("div");o.className="tbw-pinned-rows-center";const r=document.createElement("div");if(r.className="tbw-pinned-rows-right",n.showRowCount!==!1){const s=document.createElement("span");s.className="tbw-status-panel tbw-status-panel-row-count",s.textContent=`Total: ${e.totalRows} rows`,i.appendChild(s)}if(n.showFilteredCount&&e.filteredRows!==e.totalRows){const s=document.createElement("span");s.className="tbw-status-panel tbw-status-panel-filtered-count",s.textContent=`Filtered: ${e.filteredRows}`,i.appendChild(s)}if(n.showSelectedCount&&e.selectedRows>0){const s=document.createElement("span");s.className="tbw-status-panel tbw-status-panel-selected-count",s.textContent=`Selected: ${e.selectedRows}`,r.appendChild(s)}if(n.customPanels)for(const s of n.customPanels){const l=Ao(s,e);switch(s.position){case"left":i.appendChild(l);break;case"center":o.appendChild(l);break;case"right":r.appendChild(l);break}}return t.appendChild(i),t.appendChild(o),t.appendChild(r),t}function Ut(n){const e=document.createElement("div");return e.className=`tbw-aggregation-rows tbw-aggregation-rows-${n}`,e.setAttribute("role","presentation"),e}function jt(n,e,t,i){n.innerHTML="";for(const o of e){const r=document.createElement("div");if(r.className="tbw-aggregation-row",r.setAttribute("role","presentation"),o.id&&r.setAttribute("data-aggregation-id",o.id),o.fullWidth){const s=document.createElement("div");s.className="tbw-aggregation-cell tbw-aggregation-cell-full",s.style.gridColumn="1 / -1",s.textContent=o.label||"",r.appendChild(s)}else for(const s of t){const l=document.createElement("div");l.className="tbw-aggregation-cell",l.setAttribute("data-field",s.field);let a,c;const d=o.aggregators?.[s.field];if(d)if(_o(d)){const u=Ft(d.aggFunc);u&&(a=u(i,s.field,s)),c=d.formatter}else{const u=Ft(d);u&&(a=u(i,s.field,s))}else if(o.cells&&Object.prototype.hasOwnProperty.call(o.cells,s.field)){const u=o.cells[s.field];typeof u=="function"?a=u(i,s.field,s):a=u}a!=null?l.textContent=c?c(a,s.field,s):String(a):l.textContent="",r.appendChild(l)}n.appendChild(r)}}function Ao(n,e){const t=document.createElement("div");t.className="tbw-status-panel tbw-status-panel-custom",t.id=`status-panel-${n.id}`;const i=n.render(e);return typeof i=="string"?t.innerHTML=i:t.appendChild(i),t}function Yt(n,e,t,i,o){return{totalRows:n.length,filteredRows:o?.cachedResult?.length??n.length,selectedRows:i?.selected?.size??0,columns:e,rows:n,grid:t}}const To="@layer tbw-plugins{.tbw-footer{flex-shrink:0;z-index:var(--tbw-z-layer-pinned-rows, 20);background:var(--tbw-color-panel-bg)}.tbw-pinned-rows{display:flex;align-items:center;justify-content:space-between;padding:var(--tbw-button-padding, var(--tbw-spacing-md, .5rem) var(--tbw-spacing-lg, .75rem));background:var(--tbw-pinned-rows-bg, var(--tbw-color-panel-bg));border-top:1px solid var(--tbw-pinned-rows-border, var(--tbw-color-border));font-size:var(--tbw-font-size-xs, .75rem);color:var(--tbw-pinned-rows-color, var(--tbw-color-fg-muted));min-height:32px;box-sizing:border-box;min-width:fit-content}.tbw-pinned-rows-left,.tbw-pinned-rows-center,.tbw-pinned-rows-right{display:flex;align-items:center;gap:var(--tbw-spacing-xl, 1rem)}.tbw-pinned-rows-left{justify-content:flex-start}.tbw-pinned-rows-center{justify-content:center;flex:1}.tbw-pinned-rows-right{justify-content:flex-end}.tbw-status-panel{white-space:nowrap}.tbw-aggregation-rows{min-width:fit-content;background:var(--tbw-aggregation-bg, var(--tbw-color-header-bg))}.tbw-aggregation-rows-top{border-bottom:1px solid var(--tbw-aggregation-border, var(--tbw-color-border))}.tbw-aggregation-rows-bottom{border-top:1px solid var(--tbw-aggregation-border, var(--tbw-color-border))}.tbw-aggregation-row{display:grid;grid-template-columns:var(--tbw-column-template);font-size:var(--tbw-aggregation-font-size, .8em);font-weight:var(--tbw-aggregation-font-weight, 600)}.tbw-aggregation-cell{padding:var(--tbw-cell-padding, .125rem .5rem);min-height:var(--tbw-row-height, 1.75rem);display:flex;align-items:center;border-right:1px solid var(--tbw-color-border-cell)}.tbw-aggregation-cell:last-child{border-right:0}.tbw-aggregation-cell-full{grid-column:1 / -1;border-right:0}}";class ko extends P{name="pinnedRows";styles=To;get defaultConfig(){return{position:"bottom",showRowCount:!0,showSelectedCount:!0,showFilteredCount:!0}}infoBarElement=null;topAggregationContainer=null;bottomAggregationContainer=null;footerWrapper=null;detach(){this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null),this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null)}afterRender(){const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-scroll-area")??e.querySelector(".tbw-grid-content")??e.children[0];if(!t)return;this.footerWrapper&&!t.contains(this.footerWrapper)&&(this.footerWrapper=null,this.bottomAggregationContainer=null,this.infoBarElement=null),this.topAggregationContainer&&!t.contains(this.topAggregationContainer)&&(this.topAggregationContainer=null),this.infoBarElement&&!t.contains(this.infoBarElement)&&(this.infoBarElement=null);const i=this.getSelectionState(),o=this.getFilterState(),r=Yt(this.rows,this.columns,this.grid,i,o),s=this.config.aggregationRows||[],l=s.filter(h=>h.position==="top"),a=s.filter(h=>h.position!=="top");if(l.length>0){if(!this.topAggregationContainer){this.topAggregationContainer=Ut("top");const h=e.querySelector(".header");h&&h.nextSibling?t.insertBefore(this.topAggregationContainer,h.nextSibling):t.appendChild(this.topAggregationContainer)}jt(this.topAggregationContainer,l,this.visibleColumns,this.rows)}else this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null);const c=this.config.showRowCount!==!1||this.config.showSelectedCount&&r.selectedRows>0||this.config.showFilteredCount&&r.filteredRows!==r.totalRows||this.config.customPanels&&this.config.customPanels.length>0,d=c&&this.config.position!=="top",u=a.length>0||d;if(c&&this.config.position==="top")if(!this.infoBarElement)this.infoBarElement=qe(this.config,r),t.insertBefore(this.infoBarElement,t.firstChild);else{const h=qe(this.config,r);this.infoBarElement.replaceWith(h),this.infoBarElement=h}else this.config.position==="top"&&this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null);u?(this.footerWrapper||(this.footerWrapper=document.createElement("div"),this.footerWrapper.className="tbw-footer",t.appendChild(this.footerWrapper)),this.footerWrapper.innerHTML="",a.length>0&&(this.bottomAggregationContainer||(this.bottomAggregationContainer=Ut("bottom")),this.footerWrapper.appendChild(this.bottomAggregationContainer),jt(this.bottomAggregationContainer,a,this.visibleColumns,this.rows)),d&&(this.infoBarElement=qe(this.config,r),this.footerWrapper.appendChild(this.infoBarElement))):this.cleanupFooter()}cleanup(){this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null),this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null)}cleanupFooter(){this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.infoBarElement&&this.config.position!=="top"&&(this.infoBarElement.remove(),this.infoBarElement=null)}getSelectionState(){try{return this.grid?.getPluginState?.("selection")??null}catch{return null}}getFilterState(){try{return this.grid?.getPluginState?.("filtering")??null}catch{return null}}refresh(){this.requestRender()}getContext(){const e=this.getSelectionState(),t=this.getFilterState();return Yt(this.rows,this.columns,this.grid,e,t)}addPanel(e){this.config.customPanels||(this.config.customPanels=[]),this.config.customPanels.push(e),this.requestRender()}removePanel(e){this.config.customPanels&&(this.config.customPanels=this.config.customPanels.filter(t=>t.id!==e),this.requestRender())}addAggregationRow(e){this.config.aggregationRows||(this.config.aggregationRows=[]),this.config.aggregationRows.push(e),this.requestRender()}removeAggregationRow(e){this.config.aggregationRows&&(this.config.aggregationRows=this.config.aggregationRows.filter(t=>t.id!==e),this.requestRender())}}const Po=oo;function Lo(n){const e=[];return!n.rowGroupFields?.length&&!n.columnGroupFields?.length&&e.push("At least one row or column group field is required"),n.valueFields?.length||e.push("At least one value field is required"),e}function Fe(n,e){return[...n,e].join("|")}function Io(n,e){const t=e.rowGroupFields??[],i=e.columnGroupFields??[],o=e.valueFields??[],r=Do(n,i),s=Xt(n,t,i,r,o,0,""),l=Mo(s,r,o),a=Object.values(l).reduce((c,d)=>c+d,0);return{rows:s,columnKeys:r,totals:l,grandTotal:a}}function Do(n,e){if(e.length===0)return["value"];const t=new Set;for(const i of n){const o=e.map(r=>String(i[r]??"")).join("|");t.add(o)}return[...t].sort()}function Ho(n,e){const t=new Map;for(const i of n){const o=String(i[e]??""),r=t.get(o);r?r.push(i):t.set(o,[i])}return t}function Xt(n,e,t,i,o,r,s){const l=[];if(e.length===0){const h=Zt(n,t,i,o),g=Jt(h);return l.push({rowKey:s||"all",rowLabel:s||"All",depth:r,values:h,total:g,isGroup:!1,rowCount:n.length}),l}const a=e[0],c=e.slice(1),d=c.length>0,u=Ho(n,a);for(const[h,g]of u){const f=s?`${s}|${h}`:h,p=Zt(g,t,i,o),w=Jt(p);let m;d&&(m=Xt(g,c,t,i,o,r+1,f)),l.push({rowKey:f,rowLabel:h||"(blank)",depth:r,values:p,total:w,isGroup:d,children:m,rowCount:g.length})}return l}function Zt(n,e,t,i){const o={};for(const r of t)for(const s of i){const a=(e.length>0?n.filter(h=>e.map(g=>String(h[g]??"")).join("|")===r):n).map(h=>Number(h[s.field])||0),c=Po(s.aggFunc),d=a.length>0?c(a):null,u=Fe([r],s.field);o[u]=d}return o}function Jt(n){let e=0;for(const t of Object.values(n))e+=t??0;return e}function Mo(n,e,t){const i={};function o(r){for(const s of r)if(!s.isGroup||!s.children?.length)for(const l of e)for(const a of t){const c=Fe([l],a.field);i[c]=(i[c]??0)+(s.values[c]??0)}else s.children&&o(s.children)}return o(n),i}function Oo(n,e,t=!0){const i=[];function o(r){i.push(r);const s=e?e.has(r.rowKey):t;if(r.children&&s)for(const l of r.children)o(l)}for(const r of n)o(r);return i}function No(n){const e=[];function t(i){if(i.isGroup&&e.push(i.rowKey),i.children)for(const o of i.children)t(o)}for(const i of n)t(i);return e}const zo=["sum","avg","count","min","max","first","last"];function qo(n,e,t,i){const o=new AbortController,r={config:e,callbacks:i,signal:o.signal},s=document.createElement("div");return s.className="tbw-pivot-panel",s.appendChild(ce("Options",()=>Vo(t,r))),s.appendChild(ce("Row Groups",()=>Qt("rowGroups",r))),s.appendChild(ce("Column Groups",()=>Qt("columnGroups",r))),s.appendChild(ce("Values",()=>Go(r))),s.appendChild(ce("Available Fields",()=>Bo(r))),n.appendChild(s),()=>{o.abort(),s.remove()}}function ce(n,e){const t=document.createElement("div");t.className="tbw-pivot-section";const i=document.createElement("div");i.className="tbw-pivot-section-header",i.textContent=n;const o=document.createElement("div");return o.className="tbw-pivot-section-content",o.appendChild(e()),t.appendChild(i),t.appendChild(o),t}function Qt(n,e){const{config:t,callbacks:i,signal:o}=e,r=document.createElement("div");r.className="tbw-pivot-drop-zone",r.setAttribute("data-zone",n);const s=n==="rowGroups"?t.rowGroupFields??[]:t.columnGroupFields??[];if(s.length===0){const l=document.createElement("div");l.className="tbw-pivot-placeholder",l.textContent="Drag fields here or click to add",r.appendChild(l)}else for(const l of s)r.appendChild(Fo(l,n,e));return r.addEventListener("dragover",l=>{l.preventDefault(),r.classList.add("drag-over")},{signal:o}),r.addEventListener("dragleave",()=>{r.classList.remove("drag-over")},{signal:o}),r.addEventListener("drop",l=>{l.preventDefault(),r.classList.remove("drag-over");const a=l.dataTransfer?.getData("text/plain");a&&i.onAddFieldToZone(a,n)},{signal:o}),r}function Fo(n,e,t){const{callbacks:i,signal:o}=t,r=document.createElement("div");r.className="tbw-pivot-field-chip",r.draggable=!0;const s=i.getAvailableFields().find(c=>c.field===n),l=document.createElement("span");l.className="tbw-pivot-chip-label",l.textContent=s?.header??n;const a=document.createElement("button");return a.className="tbw-pivot-chip-remove",a.innerHTML="×",a.title="Remove field",a.addEventListener("click",c=>{c.stopPropagation(),i.onRemoveFieldFromZone(n,e)},{signal:o}),r.appendChild(l),r.appendChild(a),r.addEventListener("dragstart",c=>{c.dataTransfer?.setData("text/plain",n),c.dataTransfer?.setData("source-zone",e),r.classList.add("dragging")},{signal:o}),r.addEventListener("dragend",()=>{r.classList.remove("dragging")},{signal:o}),r}function Go(n){const{config:e,callbacks:t,signal:i}=n,o=document.createElement("div");o.className="tbw-pivot-drop-zone tbw-pivot-values-zone",o.setAttribute("data-zone","values");const r=e.valueFields??[];if(r.length===0){const s=document.createElement("div");s.className="tbw-pivot-placeholder",s.textContent="Drag numeric fields here for aggregation",o.appendChild(s)}else for(const s of r)o.appendChild(Ko(s,n));return o.addEventListener("dragover",s=>{s.preventDefault(),o.classList.add("drag-over")},{signal:i}),o.addEventListener("dragleave",()=>{o.classList.remove("drag-over")},{signal:i}),o.addEventListener("drop",s=>{s.preventDefault(),o.classList.remove("drag-over");const l=s.dataTransfer?.getData("text/plain");l&&t.onAddValueField(l,"sum")},{signal:i}),o}function Ko(n,e){const{callbacks:t,signal:i}=e,o=document.createElement("div");o.className="tbw-pivot-field-chip tbw-pivot-value-chip";const r=t.getAvailableFields().find(d=>d.field===n.field),s=document.createElement("div");s.className="tbw-pivot-value-label-wrapper";const l=document.createElement("span");l.className="tbw-pivot-chip-label",l.textContent=r?.header??n.field;const a=document.createElement("select");a.className="tbw-pivot-agg-select",a.title="Aggregation function";for(const d of zo){const u=document.createElement("option");u.value=d,u.textContent=d.toUpperCase(),u.selected=d===n.aggFunc,a.appendChild(u)}a.addEventListener("change",()=>{t.onUpdateValueAggFunc(n.field,a.value)},{signal:i});const c=document.createElement("button");return c.className="tbw-pivot-chip-remove",c.innerHTML="×",c.title="Remove value field",c.addEventListener("click",d=>{d.stopPropagation(),t.onRemoveValueField(n.field)},{signal:i}),s.appendChild(l),s.appendChild(a),o.appendChild(s),o.appendChild(c),o}function Bo(n){const{config:e,callbacks:t,signal:i}=n,o=document.createElement("div");o.className="tbw-pivot-available-fields";const r=t.getAvailableFields(),s=new Set([...e.rowGroupFields??[],...e.columnGroupFields??[],...e.valueFields?.map(a=>a.field)??[]]),l=r.filter(a=>!s.has(a.field));if(l.length===0){const a=document.createElement("div");a.className="tbw-pivot-placeholder",a.textContent="All fields are in use",o.appendChild(a)}else for(const a of l){const c=document.createElement("div");c.className="tbw-pivot-field-chip available",c.textContent=a.header,c.draggable=!0,c.title=`Drag to add "${a.field}" to a zone`,c.addEventListener("dragstart",d=>{d.dataTransfer?.setData("text/plain",a.field),c.classList.add("dragging")},{signal:i}),c.addEventListener("dragend",()=>{c.classList.remove("dragging")},{signal:i}),o.appendChild(c)}return o}function Vo(n,e){const{config:t,callbacks:i,signal:o}=e,r=document.createElement("div");return r.className="tbw-pivot-options",r.appendChild(Ge("Enable Pivot View",n,s=>{i.onTogglePivot(s)},o)),r.appendChild(Ge("Show Row Totals",t.showTotals??!0,s=>{i.onOptionChange("showTotals",s)},o)),r.appendChild(Ge("Show Grand Total",t.showGrandTotal??!0,s=>{i.onOptionChange("showGrandTotal",s)},o)),r}function Ge(n,e,t,i){const o=document.createElement("label");o.className="tbw-pivot-checkbox";const r=document.createElement("input");r.type="checkbox",r.checked=e,r.addEventListener("change",()=>t(r.checked),{signal:i});const s=document.createElement("span");return s.textContent=n,o.appendChild(r),o.appendChild(s),o}function Wo(n,e,t){return e.className="data-grid-row pivot-group-row",e.setAttribute("data-pivot-depth",String(n.__pivotDepth??0)),e.setAttribute("data-pivot-key",String(n.__pivotRowKey??"")),e.setAttribute("role","row"),e.innerHTML="",t.columns.forEach((i,o)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(o)),r.setAttribute("data-row",String(t.rowIndex)),r.setAttribute("role","gridcell"),o===0){const s=Number(n.__pivotIndent)||0;r.style.paddingLeft=`${s}px`;const l=String(n.__pivotRowKey),a=document.createElement("button");a.type="button",a.className="pivot-toggle",a.setAttribute("aria-label",n.__pivotExpanded?"Collapse group":"Expand group"),t.setIcon(a,t.resolveIcon(n.__pivotExpanded?"collapse":"expand")),a.addEventListener("click",u=>{u.stopPropagation(),t.onToggle(l)}),r.appendChild(a);const c=document.createElement("span");c.className="pivot-label",c.textContent=String(n.__pivotLabel??""),r.appendChild(c);const d=document.createElement("span");d.className="pivot-count",d.textContent=` (${Number(n.__pivotRowCount)||0})`,r.appendChild(d)}else{const s=n[i.field];r.textContent=s!=null?String(s):""}e.appendChild(r)}),!0}function $o(n,e,t,i){return e.className="data-grid-row pivot-leaf-row",e.setAttribute("data-pivot-depth",String(n.__pivotDepth??0)),e.setAttribute("data-pivot-key",String(n.__pivotRowKey??"")),e.innerHTML="",t.forEach((o,r)=>{const s=document.createElement("div");if(s.className="cell",s.setAttribute("data-col",String(r)),s.setAttribute("data-row",String(i)),s.setAttribute("role","gridcell"),r===0){const l=Number(n.__pivotIndent)||0;s.style.paddingLeft=`${l+20}px`;const a=document.createElement("span");a.className="pivot-label",a.textContent=String(n.__pivotLabel??""),s.appendChild(a)}else{const l=n[o.field];s.textContent=l!=null?String(l):""}e.appendChild(s)}),!0}function Uo(n,e,t){return e.className="pivot-grand-total-row",e.setAttribute("role","presentation"),e.innerHTML="",t.forEach((i,o)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(o)),o===0){const s=document.createElement("span");s.className="pivot-label",s.textContent="Grand Total",r.appendChild(s)}else{const s=n[i.field];r.textContent=s!=null?String(s):""}e.appendChild(r)}),!0}const jo='@layer tbw-plugins{.pivot-group-row{display:grid;grid-template-columns:var(--tbw-column-template);font-weight:600;background:var(--tbw-pivot-group-bg, var(--tbw-color-row-alt));min-height:var(--tbw-row-height);border-bottom:var(--tbw-row-divider)}.pivot-group-row:hover{background:var(--tbw-pivot-group-hover, var(--tbw-color-row-hover))}.pivot-leaf-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-pivot-leaf-bg, var(--tbw-color-bg));min-height:var(--tbw-row-height);border-bottom:var(--tbw-row-divider)}.pivot-grand-total-row{display:grid;grid-template-columns:var(--tbw-column-template);font-weight:700;background:var(--tbw-pivot-grand-total-bg, var(--tbw-color-header-bg));min-height:var(--tbw-row-height);border-top:2px solid var(--tbw-color-border-strong)}.pivot-grand-total-row>.cell{display:flex;align-items:center;padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}.pivot-grand-total-row>.cell:last-child{border-right:0}.pivot-grand-total-footer{position:sticky;bottom:0;z-index:var(--tbw-z-layer-pinned-rows, 20);background:var(--tbw-pivot-grand-total-bg, var(--tbw-color-header-bg));min-width:fit-content}.pivot-group-row>.cell,.pivot-leaf-row>.cell{display:flex;align-items:center;padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}.pivot-group-row>.cell:last-child,.pivot-leaf-row>.cell:last-child{border-right:0}.pivot-toggle{display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;margin-right:6px;border:none;background:transparent;cursor:pointer;color:var(--tbw-pivot-toggle-color, var(--tbw-color-fg-muted));border-radius:var(--tbw-border-radius);transition:background .15s,color .15s}.pivot-toggle:hover{background:var(--tbw-pivot-toggle-hover-bg, var(--tbw-color-row-hover));color:var(--tbw-pivot-toggle-hover-color, var(--tbw-color-fg))}.pivot-toggle:focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}.pivot-label{font-weight:inherit}.pivot-count{color:var(--tbw-pivot-count-color, var(--tbw-color-fg-muted));font-size:.9em;font-weight:400}.pivot-total-row{font-weight:700;border-top:2px solid var(--tbw-pivot-border, var(--tbw-color-border-strong))}[data-pivot-depth="1"]{--tbw-pivot-depth: 1}[data-pivot-depth="2"]{--tbw-pivot-depth: 2}[data-pivot-depth="3"]{--tbw-pivot-depth: 3}[data-pivot-depth="4"]{--tbw-pivot-depth: 4}.tbw-pivot-panel{display:flex;flex-direction:column;gap:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));padding:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));height:100%;overflow-y:auto;font-size:var(--tbw-font-size-sm, .8125rem)}.tbw-pivot-section{border:1px solid var(--tbw-pivot-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);background:var(--tbw-pivot-section-bg, var(--tbw-color-bg))}.tbw-pivot-section-header{padding:var(--tbw-button-padding, var(--tbw-spacing-md, .5rem) var(--tbw-spacing-lg, .75rem));font-weight:600;background:var(--tbw-pivot-header-bg, var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-pivot-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius) var(--tbw-border-radius) 0 0}.tbw-pivot-section-content{padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-pivot-toggle-wrapper{display:flex;align-items:center}.tbw-pivot-toggle-label{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));cursor:pointer}.tbw-pivot-toggle-label input{width:var(--tbw-icon-size, 1rem);height:var(--tbw-icon-size, 1rem);cursor:pointer}.tbw-pivot-drop-zone{min-height:60px;padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border:2px dashed var(--tbw-pivot-drop-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);background:var(--tbw-pivot-drop-bg, var(--tbw-color-row-alt));display:flex;flex-wrap:wrap;gap:var(--tbw-spacing-sm, .375rem);align-content:flex-start;transition:all .15s ease}.tbw-pivot-drop-zone.drag-over{border-color:var(--tbw-color-accent);background:var(--tbw-pivot-drop-active, var(--tbw-focus-background))}.tbw-pivot-placeholder{color:var(--tbw-color-fg-muted);font-style:italic;padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));text-align:center;width:100%}.tbw-pivot-field-chip{display:inline-flex;align-items:center;gap:var(--tbw-spacing-sm, .375rem);padding:var(--tbw-button-padding-sm, var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-md, .5rem));background:var(--tbw-pivot-chip-bg, var(--tbw-color-header-bg));border:1px solid var(--tbw-pivot-chip-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);cursor:grab;font-size:var(--tbw-font-size-xs, .75rem);transition:all .15s ease}.tbw-pivot-field-chip:hover{background:var(--tbw-pivot-chip-hover, var(--tbw-color-row-hover));border-color:var(--tbw-color-accent)}.tbw-pivot-field-chip.available{background:var(--tbw-color-bg)}.tbw-pivot-field-chip.dragging{opacity:.5;cursor:grabbing}.tbw-pivot-chip-label{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:120px}.tbw-pivot-chip-remove{display:flex;align-items:center;justify-content:center;width:var(--tbw-icon-size, 1rem);height:var(--tbw-icon-size, 1rem);padding:0;border:none;background:transparent;color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-sm, .875rem);font-weight:700;cursor:pointer;border-radius:50%;transition:all .15s ease}.tbw-pivot-chip-remove:hover{background:var(--tbw-pivot-chip-remove-hover-bg, var(--tbw-color-accent));color:var(--tbw-pivot-chip-remove-hover-fg, var(--tbw-color-accent-fg))}.tbw-pivot-value-chip{padding:var(--tbw-button-padding-sm, var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-md, .5rem))}.tbw-pivot-value-label-wrapper{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));flex:1;min-width:0}.tbw-pivot-agg-select{padding:var(--tbw-spacing-xs, .125rem) var(--tbw-spacing-xs, .25rem);font-size:var(--tbw-font-size-xs, .6875rem);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);background:var(--tbw-color-bg);cursor:pointer}.tbw-pivot-available-fields{display:flex;flex-wrap:wrap;gap:var(--tbw-spacing-sm, .375rem);min-height:40px}.tbw-pivot-options{display:flex;flex-direction:column;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-pivot-checkbox{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));cursor:pointer}.tbw-pivot-checkbox input{width:var(--tbw-icon-size-sm, .875rem);height:var(--tbw-icon-size-sm, .875rem);cursor:pointer}.pivot-group-row.tbw-pivot-slide-in,.pivot-leaf-row.tbw-pivot-slide-in{animation:tbw-pivot-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-pivot-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.pivot-group-row.tbw-pivot-fade-in,.pivot-leaf-row.tbw-pivot-fade-in{animation:tbw-pivot-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-pivot-fade-in{0%{opacity:0}to{opacity:1}}}';class $ extends P{name="pivot";styles=jo;static PANEL_ID="pivot";get defaultConfig(){return{active:!0,showTotals:!0,showGrandTotal:!0,showToolPanel:!0,animation:"slide"}}isActive=!1;hasInitialized=!1;pivotResult=null;fieldHeaderMap=new Map;expandedKeys=new Set;defaultExpanded=!0;originalColumns=[];panelContainer=null;grandTotalFooter=null;previousVisibleKeys=new Set;keysToAnimate=new Set;hasValidPivotConfig(){return(this.config.valueFields?.length??0)>0}get animationStyle(){return this.isAnimationEnabled?this.config.animation??"slide":!1}detach(){this.isActive=!1,this.hasInitialized=!1,this.pivotResult=null,this.fieldHeaderMap.clear(),this.originalColumns=[],this.panelContainer=null,this.cleanupGrandTotalFooter(),this.previousVisibleKeys.clear(),this.keysToAnimate.clear()}getToolPanel(){if((this.config?.showToolPanel??this.userConfig?.showToolPanel??!0)!==!1)return{id:$.PANEL_ID,title:"Pivot",icon:"⊞",tooltip:"Configure pivot table",order:90,render:t=>this.renderPanel(t)}}processRows(e){if(!this.hasInitialized&&this.config.active!==!1&&this.hasValidPivotConfig()&&(this.hasInitialized=!0,this.isActive=!0),!this.isActive)return[...e];const t=Lo(this.config);if(t.length>0)return this.warn(`Config errors: ${t.join(", ")}`),[...e];this.buildFieldHeaderMap(),this.defaultExpanded=this.config.defaultExpanded??!0,this.expandedKeys.size===0&&this.defaultExpanded&&this.pivotResult&&this.expandAllKeys(),this.pivotResult=Io(e,this.config),this.expandedKeys.size===0&&this.defaultExpanded&&this.expandAllKeys();const i=this.config.indentWidth??20,o=Oo(this.pivotResult.rows,this.expandedKeys,this.defaultExpanded).map(s=>({__pivotRowKey:s.rowKey,__pivotLabel:s.rowLabel,__pivotDepth:s.depth,__pivotIsGroup:s.isGroup,__pivotHasChildren:!!s.children?.length,__pivotExpanded:this.expandedKeys.has(s.rowKey),__pivotRowCount:s.rowCount??0,__pivotIndent:s.depth*i,__pivotTotal:s.total,...s.values}));this.keysToAnimate.clear();const r=new Set;for(const s of o){const l=s.__pivotRowKey;r.add(l),!this.previousVisibleKeys.has(l)&&s.__pivotDepth>0&&this.keysToAnimate.add(l)}return this.previousVisibleKeys=r,o}processColumns(e){if(!this.isActive||!this.pivotResult)return[...e];const t=[],i=(this.config.rowGroupFields??[]).map(o=>this.fieldHeaderMap.get(o)??o).join(" / ");t.push({field:"__pivotLabel",header:i||"Group",width:200});for(const o of this.pivotResult.columnKeys)for(const r of this.config.valueFields??[]){const s=Fe([o],r.field),l=r.header||this.fieldHeaderMap.get(r.field)||r.field;t.push({field:s,header:`${o} - ${l} (${r.aggFunc})`,width:120,type:"number"})}return this.config.showTotals&&t.push({field:"__pivotTotal",header:"Total",width:100,type:"number"}),t}renderRow(e,t,i){const o=e;return o.__pivotRowKey&&o.__pivotHasChildren?Wo(o,t,{columns:this.gridColumns,rowIndex:i,onToggle:r=>this.toggle(r),resolveIcon:r=>this.resolveIcon(r),setIcon:(r,s)=>this.setIcon(r,s)}):o.__pivotRowKey!==void 0&&this.isActive?$o(o,t,this.gridColumns,i):(this.cleanupPivotStyling(t),!1)}cleanupPivotStyling(e){(e.classList.contains("pivot-group-row")||e.classList.contains("pivot-leaf-row")||e.classList.contains("pivot-grand-total-row"))&&(e.classList.remove("pivot-group-row","pivot-leaf-row","pivot-grand-total-row"),e.classList.add("data-grid-row"),e.removeAttribute("data-pivot-depth"),e.innerHTML="")}onKeyDown(e){if(e.key!==" "||!this.isActive)return;const t=this.grid._focusRow,i=this.rows[t];if(!(!i?.__pivotIsGroup||!i.__pivotHasChildren))return e.preventDefault(),this.toggle(i.__pivotRowKey),this.requestRenderWithFocus(),!0}afterRender(){this.isActive&&this.config.showGrandTotal&&this.pivotResult?this.renderGrandTotalFooter():this.cleanupGrandTotalFooter();const e=this.animationStyle;if(e===!1||this.keysToAnimate.size===0)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const i=e==="fade"?"tbw-pivot-fade-in":"tbw-pivot-slide-in";for(const o of t.querySelectorAll(".pivot-group-row, .pivot-leaf-row")){const r=o.dataset.pivotKey;r&&this.keysToAnimate.has(r)&&(o.classList.add(i),o.addEventListener("animationend",()=>o.classList.remove(i),{once:!0}))}this.keysToAnimate.clear()}renderGrandTotalFooter(){if(!this.pivotResult)return;const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-scroll-area")??e.querySelector(".tbw-grid-content")??e.children[0];if(!t)return;this.grandTotalFooter||(this.grandTotalFooter=document.createElement("div"),this.grandTotalFooter.className="pivot-grand-total-footer",t.appendChild(this.grandTotalFooter));const i={__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals};Uo(i,this.grandTotalFooter,this.gridColumns)}cleanupGrandTotalFooter(){this.grandTotalFooter&&(this.grandTotalFooter.remove(),this.grandTotalFooter=null)}toggle(e){this.expandedKeys.has(e)?this.expandedKeys.delete(e):this.expandedKeys.add(e),this.requestRender()}expand(e){this.expandedKeys.add(e),this.requestRender()}collapse(e){this.expandedKeys.delete(e),this.requestRender()}expandAll(){this.expandAllKeys(),this.requestRender()}collapseAll(){this.expandedKeys.clear(),this.requestRender()}expandAllKeys(){if(!this.pivotResult)return;const e=No(this.pivotResult.rows);for(const t of e)this.expandedKeys.add(t)}isExpanded(e){return this.expandedKeys.has(e)}enablePivot(){this.originalColumns.length===0&&this.captureOriginalColumns(),this.isActive=!0,this.requestRender()}disablePivot(){this.isActive=!1,this.pivotResult=null,this.requestRender()}isPivotActive(){return this.isActive}getPivotResult(){return this.pivotResult}setRowGroupFields(e){this.config.rowGroupFields=e,this.requestRender()}setColumnGroupFields(e){this.config.columnGroupFields=e,this.requestRender()}setValueFields(e){this.config.valueFields=e,this.requestRender()}refresh(){this.pivotResult=null,this.requestRender()}showPanel(){this.grid.openToolPanel(),this.grid.expandedToolPanelSections.includes($.PANEL_ID)||this.grid.toggleToolPanelSection($.PANEL_ID)}hidePanel(){this.grid.closeToolPanel()}togglePanel(){this.grid.isToolPanelOpen||this.grid.openToolPanel(),this.grid.toggleToolPanelSection($.PANEL_ID)}isPanelVisible(){return this.grid.isToolPanelOpen&&this.grid.expandedToolPanelSections.includes($.PANEL_ID)}get gridColumns(){return this.grid.columns??[]}refreshIfActive(){this.isActive&&this.refresh(),this.refreshPanel()}buildFieldHeaderMap(){const e=this.getAvailableFields();this.fieldHeaderMap.clear();for(const t of e)this.fieldHeaderMap.set(t.field,t.header)}getAvailableFields(){return this.originalColumns.length>0?this.originalColumns:this.captureOriginalColumns()}captureOriginalColumns(){try{const e=this.grid.getAllColumns?.()??this.grid.columns??[];return this.originalColumns=e.filter(t=>!t.field.startsWith("__pivot")).map(t=>({field:t.field,header:t.header??t.field})),this.originalColumns}catch{return[]}}renderPanel(e){this.panelContainer=e,this.originalColumns.length===0&&this.captureOriginalColumns();const t={onTogglePivot:i=>{i?this.enablePivot():this.disablePivot(),this.refreshPanel()},onAddFieldToZone:(i,o)=>this.addFieldToZone(i,o),onRemoveFieldFromZone:(i,o)=>this.removeFieldFromZone(i,o),onAddValueField:(i,o)=>this.addValueField(i,o),onRemoveValueField:i=>this.removeValueField(i),onUpdateValueAggFunc:(i,o)=>this.updateValueAggFunc(i,o),onOptionChange:(i,o)=>{this.config[i]=o,this.isActive&&this.refresh()},getAvailableFields:()=>this.getAvailableFields()};return qo(e,this.config,this.isActive,t)}refreshPanel(){this.panelContainer&&(this.panelContainer.innerHTML="",this.renderPanel(this.panelContainer))}addFieldToZone(e,t){if(t==="rowGroups"){const i=this.config.rowGroupFields??[];i.includes(e)||(this.config.rowGroupFields=[...i,e])}else{const i=this.config.columnGroupFields??[];i.includes(e)||(this.config.columnGroupFields=[...i,e])}this.removeFromOtherZones(e,t),this.refreshIfActive()}removeFieldFromZone(e,t){t==="rowGroups"?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(i=>i!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(i=>i!==e),this.refreshIfActive()}removeFromOtherZones(e,t){t!=="rowGroups"&&(this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(i=>i!==e)),t!=="columnGroups"&&(this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(i=>i!==e)),t!=="values"&&(this.config.valueFields=(this.config.valueFields??[]).filter(i=>i.field!==e))}addValueField(e,t){const i=this.config.valueFields??[];i.some(o=>o.field===e)||(this.config.valueFields=[...i,{field:e,aggFunc:t}]),this.removeFromOtherZones(e,"values"),this.refreshIfActive()}removeValueField(e){this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e),this.refreshIfActive()}updateValueAggFunc(e,t){const i=this.config.valueFields??[],o=i.findIndex(r=>r.field===e);o>=0&&(i[o]={...i[o],aggFunc:t},this.config.valueFields=[...i]),this.isActive&&this.refresh()}}function Yo(n){const e=n.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}function ei(n,e,t){if(e===t||e<0||e>=n.length||t<0||t>n.length)return n;const i=[...n],[o]=i.splice(e,1);return i.splice(t,0,o),i}const Xo='@layer tbw-plugins{.header-row>.cell[draggable=true]{cursor:grab;position:relative}.header-row>.cell.dragging{opacity:.5;cursor:grabbing}.header-row>.cell.drop-before:before{content:"";position:absolute;left:0;top:0;bottom:0;width:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent));z-index:1}.header-row>.cell.drop-after:after{content:"";position:absolute;right:0;top:0;bottom:0;width:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent));z-index:1}.cell.flip-animating{transition:transform var(--tbw-animation-duration, .2s) ease-out;will-change:transform;z-index:1}@keyframes reorder-fade-in{0%{opacity:0}to{opacity:1}}.cell.fade-animating{animation:reorder-fade-in var(--tbw-animation-duration, .2s) ease-out backwards}}';class Zo extends P{name="reorder";styles=Xo;get defaultConfig(){return{animation:"flip"}}get animationType(){return this.isAnimationEnabled?this.config.animation!==void 0?this.config.animation:"flip":!1}get animationDuration(){return this.config.animationDuration!==void 0?this.config.animationDuration:super.animationDuration}isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;canMoveColumnWithPlugins(e){return!e||!Yo(e)?!1:!this.grid.queryPlugins({type:Se.CAN_MOVE_COLUMN,context:e}).includes(!1)}clearDragClasses(){this.gridElement?.querySelectorAll(".header-row > .cell").forEach(e=>{e.classList.remove("dragging","drop-target","drop-before","drop-after")})}attach(e){super.attach(e),e.addEventListener("column-reorder-request",t=>{const i=t.detail;i?.field&&typeof i.toIndex=="number"&&this.moveColumn(i.field,i.toIndex)},{signal:this.disconnectSignal})}detach(){this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null}afterRender(){const e=this.gridElement;if(!e)return;e.querySelectorAll(".header-row > .cell").forEach(i=>{const o=i,r=o.getAttribute("data-field");if(!r)return;const s=this.columns.find(l=>l.field===r);if(!this.canMoveColumnWithPlugins(s)){o.draggable=!1;return}o.draggable=!0,!o.getAttribute("data-dragstart-bound")&&(o.setAttribute("data-dragstart-bound","true"),o.addEventListener("dragstart",l=>{const c=this.getColumnOrder().indexOf(r);this.isDragging=!0,this.draggedField=r,this.draggedIndex=c,l.dataTransfer&&(l.dataTransfer.effectAllowed="move",l.dataTransfer.setData("text/plain",r)),o.classList.add("dragging")}),o.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.clearDragClasses()}),o.addEventListener("dragover",l=>{if(l.preventDefault(),!this.isDragging||this.draggedField===r)return;const a=o.getBoundingClientRect(),c=a.left+a.width/2,u=this.getColumnOrder().indexOf(r);this.dropIndex=l.clientX<c?u:u+1,o.classList.add("drop-target"),o.classList.toggle("drop-before",l.clientX<c),o.classList.toggle("drop-after",l.clientX>=c)}),o.addEventListener("dragleave",()=>{o.classList.remove("drop-target","drop-before","drop-after")}),o.addEventListener("drop",l=>{l.preventDefault();const a=this.draggedField,c=this.draggedIndex,d=this.dropIndex;if(!this.isDragging||a===null||c===null||d===null)return;const u=d>c?d-1:d,h=this.getColumnOrder(),g=ei(h,c,u),f={field:a,fromIndex:c,toIndex:u,columnOrder:g};this.emitCancelable("column-move",f)||this.updateColumnOrder(g)}))})}onKeyDown(e){if(!e.altKey||e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;const t=this.grid,i=t._focusCol,o=t._visibleColumns;if(i<0||i>=o.length)return;const r=o[i];if(!this.canMoveColumnWithPlugins(r))return;const s=this.getColumnOrder(),l=s.indexOf(r.field);if(l===-1)return;const a=e.key==="ArrowLeft"?l-1:l+1;if(a<0||a>=s.length)return;const c=o.find(d=>d.field===s[a]);if(this.canMoveColumnWithPlugins(c))return this.moveColumn(r.field,a),t._focusCol=a,M(this.grid),e.preventDefault(),e.stopPropagation(),!0}getColumnOrder(){return this.grid.getColumnOrder()}moveColumn(e,t){const i=this.getColumnOrder(),o=i.indexOf(e);if(o===-1)return;const r=ei(i,o,t);this.emitCancelable("column-move",{field:e,fromIndex:o,toIndex:t,columnOrder:r})||this.updateColumnOrder(r)}setColumnOrder(e){this.updateColumnOrder(e)}resetColumnOrder(){const e=this.columns.map(t=>t.field);this.updateColumnOrder(e)}captureHeaderPositions(){const e=new Map;return this.gridElement?.querySelectorAll(".header-row > .cell[data-field]").forEach(t=>{const i=t.getAttribute("data-field");i&&e.set(i,t.getBoundingClientRect().left)}),e}animateFLIP(e){const t=this.gridElement;if(!t||e.size===0)return;const i=new Map;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(s=>{const l=s.getAttribute("data-field");if(!l)return;const a=e.get(l);if(a===void 0)return;const c=a-s.getBoundingClientRect().left;Math.abs(c)>1&&i.set(l,c)}),i.size===0)return;const o=[];if(t.querySelectorAll(".cell[data-field]").forEach(s=>{const l=i.get(s.getAttribute("data-field")??"");if(l!==void 0){const a=s;a.style.transform=`translateX(${l}px)`,o.push(a)}}),o.length===0)return;this.gridElement.offsetHeight;const r=this.animationDuration;requestAnimationFrame(()=>{o.forEach(s=>{s.classList.add("flip-animating"),s.style.transform=""}),setTimeout(()=>{o.forEach(s=>{s.style.transform="",s.classList.remove("flip-animating")})},r+50)})}animateFade(e){const t=this.gridElement;if(!t){e();return}const i=this.captureHeaderPositions();e();const o=new Set;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(l=>{const a=l.getAttribute("data-field");if(!a)return;const c=i.get(a);if(c===void 0)return;const d=l.getBoundingClientRect().left;Math.abs(c-d)>1&&o.add(a)}),o.size===0)return;const r=[];if(t.querySelectorAll(".cell[data-field]").forEach(l=>{const a=l.getAttribute("data-field");if(a&&o.has(a)){const c=l;c.classList.add("fade-animating"),r.push(c)}}),r.length===0)return;const s=this.animationDuration;setTimeout(()=>{r.forEach(l=>l.classList.remove("fade-animating"))},s+50)}updateColumnOrder(e){const t=this.animationType;if(t==="flip"&&this.gridElement){const i=this.captureHeaderPositions();this.grid.setColumnOrder(e),requestAnimationFrame(()=>{this.gridElement.offsetHeight,this.animateFLIP(i)})}else t==="fade"?this.animateFade(()=>this.grid.setColumnOrder(e)):this.grid.setColumnOrder(e);this.grid.requestStateChange?.()}}const Jo='tbw-grid[data-responsive-animate] .data-grid-row,tbw-grid[data-responsive-animate] .data-grid-row>.cell{transition:opacity var(--tbw-responsive-duration, .2s) ease-out,transform var(--tbw-responsive-duration, .2s) ease-out}tbw-grid[data-responsive][data-responsive-animate] .data-grid-row{animation:responsive-card-enter var(--tbw-responsive-duration, .2s) ease-out}@keyframes responsive-card-enter{0%{opacity:0;transform:translateY(-10px)}to{opacity:1;transform:translateY(0)}}tbw-grid[data-responsive] .header{display:none!important}tbw-grid[data-responsive] .footer-row{display:none}tbw-grid[data-responsive] .tbw-scroll-area{overflow-x:hidden;min-width:0!important}tbw-grid[data-responsive] .rows-body-wrapper{min-width:0!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row){display:block!important;grid-template-columns:none!important;padding:var(--tbw-cell-padding);padding-left:var(--tbw-spacing-xl);border-bottom:1px solid var(--tbw-color-border);min-height:auto!important;height:auto!important;contain:none!important;content-visibility:visible!important;background:var(--tbw-color-bg);position:relative}tbw-grid[data-responsive] .data-grid-row:not(.group-row):nth-child(2n){background:var(--tbw-color-row-alt)}tbw-grid[data-responsive] .data-grid-row:not(.group-row):hover{background:var(--tbw-color-row-hover)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)[aria-selected=true]{background:var(--tbw-color-selection)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)[aria-selected=true]:before{content:"";position:absolute;left:0;top:0;bottom:0;width:4px;background:var(--tbw-color-accent)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell{display:flex!important;justify-content:space-between;align-items:center;padding:var(--tbw-spacing-xs) var(--tbw-spacing-md);width:100%!important;min-width:0!important;min-height:auto!important;height:auto!important;line-height:1.5!important;position:static!important;left:auto!important;right:auto!important;border:none!important;border-bottom:none!important;border-right:none!important;background:transparent!important;white-space:normal!important;overflow:visible!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell:before{content:attr(data-header) ": ";font-weight:600;color:var(--tbw-color-header-fg);flex-shrink:0;margin-right:var(--tbw-spacing-md);min-width:100px}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell:after{content:none}tbw-grid[data-responsive] .cell[data-utility]{display:none!important}tbw-grid[data-responsive] .cell[data-responsive-hidden]{display:none!important}tbw-grid[data-responsive] .cell[data-responsive-value-only]{justify-content:flex-start!important;font-weight:500}tbw-grid[data-responsive] .cell[data-responsive-value-only]:before{display:none!important}tbw-grid:not([data-responsive]) .cell[data-responsive-hidden]{display:none!important}tbw-grid[data-responsive] .tbw-footer,tbw-grid[data-responsive] .tbw-pinned-rows,tbw-grid[data-responsive] .tbw-aggregation-rows{display:none!important}tbw-grid[data-responsive] .tbw-pinned-rows,tbw-grid[data-responsive] .tbw-aggregation-rows,tbw-grid[data-responsive] .tbw-aggregation-row{min-width:0!important}tbw-grid[data-responsive] .data-grid-row.responsive-card{display:block!important;padding:var(--tbw-cell-padding);border-bottom:1px solid var(--tbw-color-border)}tbw-grid[data-responsive] .data-grid-row.responsive-card>*{width:100%}tbw-grid[data-responsive] .data-grid-row.responsive-card .cell:before{display:none}';class Qo extends P{name="responsive";version="1.0.0";styles=Jo;static manifest={incompatibleWith:[{name:"groupingRows",reason:"Responsive card layout does not yet support row grouping. The variable row heights (cards vs group headers) cause scroll calculation issues."}]};#e;#n=!1;#d;#c=!1;#s=0;#i=new Set;#h=new Set;#u=null;#p=[];isResponsive(){return this.#n}setResponsive(e){e!==this.#n&&(this.#n=e,this.#b(),this.emit("responsive-change",{isResponsive:e,width:this.#s,breakpoint:this.config.breakpoint??0}))}setBreakpoint(e){this.config.breakpoint=e,this.#w(this.#s)}setCardRenderer(e){this.config.cardRenderer=e,this.#n&&this.requestRender()}getWidth(){return this.#s}getActiveBreakpoint(){return this.#u}attach(e){super.attach(e),this.#l(this.config.hiddenColumns),this.config.breakpoints?.length&&(this.#p=[...this.config.breakpoints].sort((t,i)=>i.maxWidth-t.maxWidth)),this.#e=new ResizeObserver(t=>{const i=t[0]?.contentRect.width??0;this.#s=i,clearTimeout(this.#d),this.#d=setTimeout(()=>{this.#w(i)},this.config.debounceMs??100)}),this.#e.observe(this.gridElement)}#l(e){if(this.#i.clear(),this.#h.clear(),!!e)for(const t of e)typeof t=="string"?this.#i.add(t):t.showValue?this.#h.add(t.field):this.#i.add(t.field)}detach(){this.#e?.disconnect(),this.#e=void 0,clearTimeout(this.#d),this.#d=void 0,this.gridElement&&this.gridElement.removeAttribute("data-responsive"),super.detach()}afterRender(){if(this.#_(),!(this.#p.length>0?this.#u!==null:this.#n))return;const t=this.#i.size>0,i=this.#h.size>0;if(!t&&!i)return;const o=this.gridElement.querySelectorAll(".cell[data-field]");for(const r of o){const s=r.getAttribute("data-field");s&&(this.#i.has(s)?(r.setAttribute("data-responsive-hidden",""),r.removeAttribute("data-responsive-value-only")):this.#h.has(s)?(r.setAttribute("data-responsive-value-only",""),r.removeAttribute("data-responsive-hidden")):(r.removeAttribute("data-responsive-hidden"),r.removeAttribute("data-responsive-value-only")))}}#w(e){if(this.#p.length>0){this.#m(e);return}const t=this.config.breakpoint??0;t===0&&!this.#c&&(this.#c=!0,console.warn("[tbw-grid:ResponsivePlugin] No breakpoint configured. Responsive mode is disabled. Set a breakpoint based on your grid's column count."));const i=t>0&&e<t;i!==this.#n&&(this.#n=i,this.#b(),this.emit("responsive-change",{isResponsive:i,width:e,breakpoint:t}),this.requestRender())}#m(e){let t=null;for(const o of this.#p)e<=o.maxWidth&&(t=o);if(t!==this.#u){this.#u=t,t?.hiddenColumns?this.#l(t.hiddenColumns):this.#l(this.config.hiddenColumns);const o=t?.cardLayout===!0;o!==this.#n&&(this.#n=o,this.#b()),this.emit("responsive-change",{isResponsive:this.#n,width:e,breakpoint:t?.maxWidth??0}),this.requestRender()}}#a;#b(){this.gridElement.toggleAttribute("data-responsive",this.#n);const e=this.config.animate!==!1;this.gridElement.toggleAttribute("data-responsive-animate",e),this.config.animationDuration&&this.gridElement.style.setProperty("--tbw-responsive-duration",`${this.config.animationDuration}ms`);const t=this.grid;if(this.#n){t._virtualization&&(this.#a=t._virtualization.rowHeight);const i=this.gridElement.querySelector(".tbw-scroll-area");i&&(i.scrollLeft=0)}else{const i=this.gridElement.querySelectorAll(".data-grid-row");for(const o of i)o.style.height="",o.classList.remove("responsive-card");this.#a&&this.#a>0&&t._virtualization&&(t._virtualization.rowHeight=this.#a,this.#a=void 0),this.#v=void 0,this.#g=void 0,this.#y=void 0}}renderRow(e,t,i){if(!this.#n||!this.config.cardRenderer||e.__isGroupRow)return;t.replaceChildren();const o=this.config.cardRenderer(e,i);t.className="data-grid-row responsive-card";const r=this.config.cardRowHeight??"auto";return r!=="auto"?t.style.height=`${r}px`:t.style.height="auto",t.appendChild(o),!0}onKeyDown(e){if(!this.#n||this.config.cardRenderer&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(e.key))return!1;const t=this.rows.length-1,i=this.visibleColumns.length-1;switch(e.key){case"ArrowDown":if(this.grid._focusCol<i)return this.grid._focusCol+=1,e.preventDefault(),M(this.grid),!0;if(this.grid._focusRow<t)return this.grid._focusRow+=1,this.grid._focusCol=0,e.preventDefault(),M(this.grid),!0;break;case"ArrowUp":if(this.grid._focusCol>0)return this.grid._focusCol-=1,e.preventDefault(),M(this.grid),!0;if(this.grid._focusRow>0)return this.grid._focusRow-=1,this.grid._focusCol=i,e.preventDefault(),M(this.grid),!0;break;case"ArrowRight":if(this.grid._focusRow<t)return this.grid._focusRow+=1,e.preventDefault(),M(this.grid),!0;break;case"ArrowLeft":if(this.grid._focusRow>0)return this.grid._focusRow-=1,e.preventDefault(),M(this.grid),!0;break}return!1}#v;#g;#y;#x(){if(this.#v&&this.#v>0)return this.#v;const e=this.config.cardRowHeight;return typeof e=="number"&&e>0?e:80}#C(){return this.#g&&this.#g>0?this.#g:this.#a??28}#E(){for(const e of this.rows)if(e.__isGroupRow)return!0;return!1}#r(){let e=0,t=0;for(const i of this.rows)i.__isGroupRow?e++:t++;return{groupCount:e,cardCount:t}}getExtraHeight(){if(!this.#n||!this.config.cardRenderer||!this.#E())return 0;const e=this.#a??28,t=this.#C(),i=this.#x(),{groupCount:o,cardCount:r}=this.#r(),s=o*Math.max(0,t-e),l=r*Math.max(0,i-e);return s+l}getExtraHeightBefore(e){if(!this.#n||!this.config.cardRenderer||!this.#E())return 0;const t=this.#a??28,i=this.#C(),o=this.#x(),r=Math.max(0,i-t),s=Math.max(0,o-t);let l=0,a=0;const c=this.rows,d=Math.min(e,c.length);for(let u=0;u<d;u++)c[u].__isGroupRow?l++:a++;return l*r+a*s}#R(){let e=0;for(const t of this.rows)t.__isGroupRow||e++;return e}#S=!1;#_(){if(!this.#n||!this.config.cardRenderer)return;let e=!1;const t=this.grid,i=this.#E(),o=this.#R();if(o!==this.#y&&(this.#y=o,e=!0),i){const s=this.gridElement.querySelector(".data-grid-row.group-row");if(s){const l=s.getBoundingClientRect().height;l>0&&l!==this.#g&&(this.#g=l,e=!0)}}const r=this.gridElement.querySelector(".data-grid-row.responsive-card");if(r){const s=r.getBoundingClientRect().height;s>0&&s!==this.#v&&(this.#v=s,e=!0,!i&&t._virtualization&&(t._virtualization.rowHeight=s))}e&&!this.#S&&(this.#S=!0,queueMicrotask(()=>{this.#S=!1,this.grid&&this.#n&&this.grid.refreshVirtualWindow?.(!0,!0)}))}}function ge(n){return{startRow:Math.min(n.startRow,n.endRow),startCol:Math.min(n.startCol,n.endCol),endRow:Math.max(n.startRow,n.endRow),endCol:Math.max(n.startCol,n.endCol)}}function er(n){const e=ge(n);return{from:{row:e.startRow,col:e.startCol},to:{row:e.endRow,col:e.endCol}}}function ti(n){return n.map(er)}function tr(n,e,t){const i=ge(t);return n>=i.startRow&&n<=i.endRow&&e>=i.startCol&&e<=i.endCol}function ii(n,e,t){return t.some(i=>tr(n,e,i))}function ir(n){const e=[],t=ge(n);for(let i=t.startRow;i<=t.endRow;i++)for(let o=t.startCol;o<=t.endCol;o++)e.push({row:i,col:o});return e}function nr(n){const e=new Map;for(const t of n)for(const i of ir(t))e.set(`${i.row},${i.col}`,i);return[...e.values()]}function Ke(n,e){return{startRow:n.row,startCol:n.col,endRow:e.row,endCol:e.col}}const or="@layer tbw-plugins{tbw-grid.selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}tbw-grid[data-has-focus] .data-grid-row.row-focus{background-color:var(--tbw-focus-background, rgba(from var(--tbw-color-accent) r g b / 12%))}tbw-grid[data-selection-mode=row] .cell-focus{outline:none}tbw-grid .data-grid-row>.cell.selected{background-color:var(--tbw-range-selection-bg)}tbw-grid .data-grid-row>.cell.selected.top{border-top:2px solid var(--tbw-range-border-color)}tbw-grid .data-grid-row>.cell.selected.bottom{border-bottom:2px solid var(--tbw-range-border-color)}tbw-grid .data-grid-row>.cell.selected.first{border-left:2px solid var(--tbw-range-border-color)}tbw-grid .data-grid-row>.cell.selected.last{border-right:2px solid var(--tbw-range-border-color)}tbw-grid .tbw-selection-summary{font-size:var(--tbw-font-size-sm, .8125rem);color:var(--tbw-color-fg-muted);white-space:nowrap}}";function rr(n,e,t){if(n==="cell"&&e.selectedCell)return{mode:n,ranges:[{from:{row:e.selectedCell.row,col:e.selectedCell.col},to:{row:e.selectedCell.row,col:e.selectedCell.col}}]};if(n==="row"&&e.selected.size>0){const i=[...e.selected].map(o=>({from:{row:o,col:0},to:{row:o,col:t-1}}));return{mode:n,ranges:i}}return n==="range"&&e.ranges.length>0?{mode:n,ranges:ti(e.ranges)}:{mode:n,ranges:[]}}class sr extends P{static manifest={configRules:[{id:"selection/range-dblclick",severity:"warn",message:`"triggerOn: 'dblclick'" has no effect when mode is "range".
77
+ </Workbook>`,i}function en(o,e){const t=e.endsWith(".xls")?e:`${e}.xls`,i=new Blob([o],{type:"application/vnd.ms-excel;charset=utf-8;"});Ne(i,t)}class tn extends L{name="export";get defaultConfig(){return{fileName:"export",includeHeaders:!0,onlyVisible:!0,onlySelected:!1}}isExportingFlag=!1;lastExportInfo=null;performExport(e,t){const i=this.config,n={format:e,fileName:t?.fileName??i.fileName??"export",includeHeaders:t?.includeHeaders??i.includeHeaders,processCell:t?.processCell,processHeader:t?.processHeader,columns:t?.columns,rowIndices:t?.rowIndices};let r=[...this.columns];if(i.onlyVisible&&(r=r.filter(a=>!a.hidden&&!a.field.startsWith("__"))),t?.columns){const a=new Set(t.columns);r=r.filter(c=>a.has(c.field))}let s=[...this.rows];if(i.onlySelected){const a=this.getSelectionState();a?.selected?.size&&(s=[...a.selected].sort((d,u)=>d-u).map(d=>this.rows[d]).filter(Boolean))}t?.rowIndices&&(s=t.rowIndices.map(a=>this.rows[a]).filter(Boolean)),this.isExportingFlag=!0;let l=n.fileName;try{switch(e){case"csv":{const a=Zo(s,r,n,{bom:!0});l=l.endsWith(".csv")?l:`${l}.csv`,Jo(a,l);break}case"excel":{const a=Qo(s,r,n);l=l.endsWith(".xls")?l:`${l}.xls`,en(a,l);break}case"json":{const a=s.map(u=>{const h={};for(const f of r){let p=u[f.field];n.processCell&&(p=n.processCell(p,f.field,u)),h[f.field]=p}return h}),c=JSON.stringify(a,null,2);l=l.endsWith(".json")?l:`${l}.json`;const d=new Blob([c],{type:"application/json"});Ne(d,l);break}}this.lastExportInfo={format:e,timestamp:new Date},this.emit("export-complete",{format:e,fileName:l,rowCount:s.length,columnCount:r.length})}finally{this.isExportingFlag=!1}}getSelectionState(){try{return this.grid?.getPluginState?.("selection")??null}catch{return null}}exportCsv(e){this.performExport("csv",e)}exportExcel(e){this.performExport("excel",e)}exportJson(e){this.performExport("json",e)}isExporting(){return this.isExportingFlag}getLastExport(){return this.lastExportInfo}}function on(o){const{totalRows:e,viewportHeight:t,scrollTop:i,rowHeight:n,overscan:r}=o,s=Math.ceil(t/n);let l=Math.floor(i/n)-r;l<0&&(l=0);let a=l+s+r*2;return a>e&&(a=e),a===e&&l>0&&(l=Math.max(0,a-s-r*2)),{start:l,end:a,offsetY:l*n,totalHeight:e*n}}function nn(o,e){return o<=e}function rn(o,e,t=!1){const i=o[e.field];if(e.operator==="blank")return i==null||i==="";if(e.operator==="notBlank")return i!=null&&i!=="";if(i==null)return!1;const n=String(i),r=t?n:n.toLowerCase(),s=t?String(e.value):String(e.value).toLowerCase();switch(e.operator){case"contains":return r.includes(s);case"notContains":return!r.includes(s);case"equals":return r===s;case"notEquals":return r!==s;case"startsWith":return r.startsWith(s);case"endsWith":return r.endsWith(s);case"lessThan":return Number(i)<Number(e.value);case"lessThanOrEqual":return Number(i)<=Number(e.value);case"greaterThan":return Number(i)>Number(e.value);case"greaterThanOrEqual":return Number(i)>=Number(e.value);case"between":return Number(i)>=Number(e.value)&&Number(i)<=Number(e.valueTo);case"in":return Array.isArray(e.value)&&e.value.includes(i);case"notIn":return Array.isArray(e.value)&&!e.value.includes(i);default:return!0}}function sn(o,e,t=!1){return e.length?o.filter(i=>e.every(n=>rn(i,n,t))):o}function ln(o){return JSON.stringify(o.map(e=>({field:e.field,operator:e.operator,value:e.value,valueTo:e.valueTo})))}function Ft(o,e){const t=new Set;for(const i of o){const n=i[e];n!=null&&t.add(n)}return[...t].sort((i,n)=>typeof i=="number"&&typeof n=="number"?i-n:String(i).localeCompare(String(n)))}const an='@layer tbw-plugins{tbw-grid .tbw-quick-filter-input{flex:1;max-width:300px;height:var(--tbw-input-height, 1.75rem);padding:var(--tbw-input-padding, 0 .5rem);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:var(--tbw-font-size-sm, .8125rem)}tbw-grid .tbw-quick-filter-input:focus{outline:none;border-color:var(--tbw-color-accent)}tbw-grid .header-cell.filtered:before{content:"";position:absolute;top:var(--tbw-spacing-xs, .25rem);right:var(--tbw-spacing-xs, .25rem);width:var(--tbw-indicator-size, .375rem);height:var(--tbw-indicator-size, .375rem);background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border-radius:50%}tbw-grid .tbw-filter-btn{display:inline-flex;align-items:center;justify-content:center;background:transparent;border:none;cursor:pointer;padding:2px;margin-left:var(--tbw-spacing-xs, .25rem);opacity:.4;transition:opacity .15s;color:inherit;vertical-align:middle}tbw-grid .tbw-filter-btn:hover,tbw-grid .tbw-filter-btn.active{opacity:1}tbw-grid .tbw-filter-btn.active{color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6))}}',cn="@layer tbw-plugins{.tbw-filter-panel{position:fixed;background:var(--tbw-filter-panel-bg, var(--tbw-color-panel-bg, light-dark(#eeeeee, #222222)));color:var(--tbw-filter-panel-fg, var(--tbw-color-fg, light-dark(#222222, #eeeeee)));border:1px solid var(--tbw-filter-panel-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-filter-panel-radius, var(--tbw-border-radius, .25rem));box-shadow:0 4px 16px var(--tbw-filter-panel-shadow, var(--tbw-color-shadow, light-dark(rgba(0, 0, 0, .1), rgba(0, 0, 0, .3))));padding:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));z-index:10000;min-width:200px;max-width:280px;max-height:350px;display:flex;flex-direction:column;font-family:var(--tbw-font-family, system-ui, sans-serif);font-size:var(--tbw-font-size, .8125rem);transform-origin:top center}.tbw-filter-panel.tbw-filter-panel-above{transform-origin:bottom center}.tbw-filter-panel.tbw-filter-panel-animated{animation:tbw-filter-panel-enter var(--tbw-animation-duration, .15s) var(--tbw-animation-easing, ease-out)}.tbw-filter-panel.tbw-filter-panel-above.tbw-filter-panel-animated{animation:tbw-filter-panel-enter-above var(--tbw-animation-duration, .15s) var(--tbw-animation-easing, ease-out)}@keyframes tbw-filter-panel-enter{0%{opacity:0;transform:scaleY(.3) translateY(-10px)}to{opacity:1;transform:scaleY(1) translateY(0)}}@keyframes tbw-filter-panel-enter-above{0%{opacity:0;transform:scaleY(.3) translateY(10px)}to{opacity:1;transform:scaleY(1) translateY(0)}}@supports (anchor-name: --test){.tbw-filter-panel{position-anchor:--tbw-filter-anchor;top:anchor(bottom);left:anchor(left);margin-top:4px;position-try-fallbacks:flip-inline,flip-block,flip-block flip-inline}}.tbw-filter-search{margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-filter-search-input{width:100%;padding:var(--tbw-button-padding, .375rem .625rem);background:var(--tbw-filter-input-bg, var(--tbw-color-bg, transparent));color:inherit;border:1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-filter-input-radius, var(--tbw-border-radius, .25rem));font-size:inherit;box-sizing:border-box}.tbw-filter-search-input:focus{outline:none;border-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));box-shadow:0 0 0 2px rgba(from var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6)) r g b / 15%)}.tbw-filter-actions{display:flex;padding:var(--tbw-button-padding-sm, .25rem .125rem);margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border-bottom:1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)))}.tbw-filter-action-btn{background:transparent;border:none;color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));cursor:pointer;font-size:var(--tbw-font-size-xs, .75rem);padding:2px 0}.tbw-filter-action-btn:hover{text-decoration:underline}.tbw-filter-values{flex:1;overflow-y:auto;margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));max-height:180px;position:relative}.tbw-filter-values-spacer{width:1px}.tbw-filter-values-content{position:absolute;top:0;left:0;right:0}.tbw-filter-value-item{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding:var(--tbw-button-padding-sm, .25rem .125rem);cursor:pointer;border-radius:3px}.tbw-filter-value-item:hover{background:var(--tbw-filter-hover, var(--tbw-color-row-hover, light-dark(#f0f6ff, #1c1c1c)))}.tbw-filter-checkbox{margin:0;cursor:pointer;accent-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6))}.tbw-filter-no-match{color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem)) 0;text-align:center;font-style:italic}.tbw-filter-buttons{display:flex;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding-top:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border-top:1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)))}.tbw-filter-apply-btn{flex:1;padding:var(--tbw-button-padding, .375rem .75rem);background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));color:var(--tbw-filter-accent-fg, var(--tbw-color-accent-fg, light-dark(#ffffff, #000000)));border:none;border-radius:var(--tbw-border-radius, .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem)}.tbw-filter-apply-btn:hover{filter:brightness(.9)}.tbw-filter-clear-btn{flex:1;padding:var(--tbw-button-padding, .375rem .75rem);background:transparent;color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));border:1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-border-radius, .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem)}.tbw-filter-clear-btn:hover{background:var(--tbw-filter-hover, var(--tbw-color-row-hover, light-dark(#f0f6ff, #1c1c1c)))}}";class q extends L{name="filtering";styles=an;get defaultConfig(){return{debounceMs:300,caseSensitive:!1,trimInput:!0,useWorker:!0}}filters=new Map;cachedResult=null;cacheKey=null;openPanelField=null;panelElement=null;panelAnchorElement=null;searchText=new Map;excludedValues=new Map;panelAbortController=null;globalStylesInjected=!1;static LIST_ITEM_HEIGHT=28;static LIST_OVERSCAN=3;static LIST_BYPASS_THRESHOLD=50;syncExcludedValues(e,t){t?t.type==="set"&&t.operator==="notIn"&&Array.isArray(t.value)?this.excludedValues.set(e,new Set(t.value)):t.type==="set"&&this.excludedValues.delete(e):this.excludedValues.delete(e)}attach(e){super.attach(e),this.injectGlobalStyles()}detach(){this.filters.clear(),this.cachedResult=null,this.cacheKey=null,this.openPanelField=null,this.panelElement&&(this.panelElement.remove(),this.panelElement=null),this.searchText.clear(),this.excludedValues.clear(),this.panelAbortController?.abort(),this.panelAbortController=null}processRows(e){const t=[...this.filters.values()];if(!t.length)return[...e];if(this.config.filterHandler)return this.cachedResult?this.cachedResult:[...e];const i=ln(t);if(this.cacheKey===i&&this.cachedResult)return this.cachedResult;const n=sn([...e],t,this.config.caseSensitive);return this.cachedResult=n,this.cacheKey=i,n}afterRender(){const e=this.gridElement;if(!e)return;e.querySelectorAll('[part~="header-cell"]').forEach(i=>{const n=i.getAttribute("data-col");if(n===null)return;const r=this.visibleColumns[parseInt(n,10)];if(!r||r.filterable===!1||B(r))return;const s=r.field;if(!s)return;const l=this.filters.has(s);let a=i.querySelector(".tbw-filter-btn");if(a){a.classList.toggle("active",l),i.classList.toggle("filtered",l);return}a=document.createElement("button"),a.className="tbw-filter-btn",a.setAttribute("aria-label",`Filter ${r.header??s}`),a.innerHTML='<svg viewBox="0 0 16 16" width="12" height="12"><path fill="currentColor" d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></svg>',l&&(a.classList.add("active"),i.classList.add("filtered")),a.addEventListener("click",d=>{d.stopPropagation(),this.toggleFilterPanel(s,r,a)});const c=i.querySelector(".resize-handle");c?i.insertBefore(a,c):i.appendChild(a)})}setFilter(e,t){if(t===null)this.filters.delete(e),this.syncExcludedValues(e,null);else{const i={...t,field:e};this.filters.set(e,i),this.syncExcludedValues(e,i)}this.cachedResult=null,this.cacheKey=null,this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0}),this.requestRender()}getFilter(e){return this.filters.get(e)}getFilters(){return[...this.filters.values()]}getFilterModel(){return this.getFilters()}setFilterModel(e){this.filters.clear(),this.excludedValues.clear();for(const t of e)this.filters.set(t.field,t),this.syncExcludedValues(t.field,t);this.cachedResult=null,this.cacheKey=null,this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0}),this.requestRender()}clearAllFilters(){this.filters.clear(),this.excludedValues.clear(),this.searchText.clear(),this.applyFiltersInternal()}clearFieldFilter(e){this.filters.delete(e),this.excludedValues.delete(e),this.searchText.delete(e),this.applyFiltersInternal()}isFieldFiltered(e){return this.filters.has(e)}getFilteredRowCount(){return this.cachedResult?.length??this.rows.length}getActiveFilters(){return this.getFilters()}getUniqueValues(e){return Ft(this.sourceRows,e)}injectGlobalStyles(){if(this.globalStylesInjected)return;if(document.getElementById("tbw-filter-panel-styles")){this.globalStylesInjected=!0;return}const e=document.createElement("style");e.id="tbw-filter-panel-styles",e.textContent=cn,document.head.appendChild(e),this.globalStylesInjected=!0}toggleFilterPanel(e,t,i){if(this.openPanelField===e){this.closeFilterPanel();return}this.closeFilterPanel();const n=document.createElement("div");if(n.className="tbw-filter-panel",this.isAnimationEnabled&&n.classList.add("tbw-filter-panel-animated"),this.panelElement=n,this.openPanelField=e,this.config.valuesHandler){n.innerHTML='<div class="tbw-filter-loading">Loading...</div>',document.body.appendChild(n),this.positionPanel(n,i),this.setupPanelCloseHandler(n,i),this.config.valuesHandler(e,t).then(s=>{this.openPanelField!==e||!this.panelElement||(n.innerHTML="",this.renderPanelContent(e,t,n,s))});return}const r=Ft(this.sourceRows,e);this.renderPanelContent(e,t,n,r),document.body.appendChild(n),this.positionPanel(n,i),this.setupPanelCloseHandler(n,i)}renderPanelContent(e,t,i,n){let r=this.excludedValues.get(e);r||(r=new Set,this.excludedValues.set(e,r));const s=this.searchText.get(e)??"",l={field:e,column:t,uniqueValues:n,excludedValues:r,searchText:s,applySetFilter:c=>{this.applySetFilter(e,c),this.closeFilterPanel()},applyTextFilter:(c,d,u)=>{this.applyTextFilter(e,c,d,u),this.closeFilterPanel()},clearFilter:()=>{this.clearFieldFilter(e),this.closeFilterPanel()},closePanel:()=>this.closeFilterPanel()};let a=!1;this.config.filterPanelRenderer&&(this.config.filterPanelRenderer(i,l),a=i.children.length>0),a||this.renderDefaultFilterPanel(i,l,n,r)}setupPanelCloseHandler(e,t){this.panelAbortController=new AbortController,setTimeout(()=>{document.addEventListener("click",i=>{!e.contains(i.target)&&i.target!==t&&this.closeFilterPanel()},{signal:this.panelAbortController?.signal})},0)}closeFilterPanel(){const e=this.panelElement;e&&(e.remove(),this.panelElement=null),this.panelAnchorElement&&(this.panelAnchorElement.style.anchorName="",this.panelAnchorElement=null),this.openPanelField=null,this.panelAbortController?.abort(),this.panelAbortController=null}static supportsAnchorPositioning=null;static checkAnchorPositioningSupport(){return q.supportsAnchorPositioning===null&&(q.supportsAnchorPositioning=CSS.supports("anchor-name","--test")),q.supportsAnchorPositioning}positionPanel(e,t){const n=t.closest(".cell")??t;if(n.style.anchorName="--tbw-filter-anchor",this.panelAnchorElement=n,q.checkAnchorPositioningSupport()){requestAnimationFrame(()=>{const s=e.getBoundingClientRect(),l=n.getBoundingClientRect();s.top<l.top&&e.classList.add("tbw-filter-panel-above")});return}const r=n.getBoundingClientRect();e.style.position="fixed",e.style.top=`${r.bottom+4}px`,e.style.left=`${r.left}px`,requestAnimationFrame(()=>{const s=e.getBoundingClientRect();s.right>window.innerWidth-8&&(e.style.left=`${r.right-s.width}px`),s.bottom>window.innerHeight-8&&(e.style.top=`${r.top-s.height-4}px`,e.classList.add("tbw-filter-panel-above"))})}renderDefaultFilterPanel(e,t,i,n){const{field:r}=t,s=document.createElement("div");s.className="tbw-filter-search";const l=document.createElement("input");l.type="text",l.placeholder="Search...",l.className="tbw-filter-search-input",l.value=this.searchText.get(r)??"",s.appendChild(l),e.appendChild(s);const a=document.createElement("div");a.className="tbw-filter-actions";const c=document.createElement("label");c.className="tbw-filter-value-item",c.style.padding="0",c.style.margin="0";const d=document.createElement("input");d.type="checkbox",d.className="tbw-filter-checkbox";const u=document.createElement("span");u.textContent="Select All",c.appendChild(d),c.appendChild(u),a.appendChild(c);const h=()=>{const v=[...w.values()],k=v.every(R=>R),S=v.every(R=>!R);d.checked=k,d.indeterminate=!k&&!S};d.addEventListener("change",()=>{const v=d.checked;for(const k of w.keys())w.set(k,v);h(),b()}),e.appendChild(a);const f=document.createElement("div");f.className="tbw-filter-values";const p=document.createElement("div");p.className="tbw-filter-values-spacer",f.appendChild(p);const g=document.createElement("div");g.className="tbw-filter-values-content",f.appendChild(g);const w=new Map;i.forEach(v=>{const k=v==null?"__null__":String(v);w.set(k,!n.has(v))}),h();let m=[];const y=(v,k)=>{const S=v==null?"(Blank)":String(v),R=v==null?"__null__":String(v),P=document.createElement("label");P.className="tbw-filter-value-item",P.style.position="absolute",P.style.top=`${k*q.LIST_ITEM_HEIGHT}px`,P.style.left="0",P.style.right="0",P.style.height=`${q.LIST_ITEM_HEIGHT}px`,P.style.boxSizing="border-box";const O=document.createElement("input");O.type="checkbox",O.className="tbw-filter-checkbox",O.checked=w.get(R)??!0,O.dataset.value=R,O.addEventListener("change",()=>{w.set(R,O.checked),h()});const gi=document.createElement("span");return gi.textContent=S,P.appendChild(O),P.appendChild(gi),P},b=()=>{const v=m.length,k=f.clientHeight,S=f.scrollTop;if(p.style.height=`${v*q.LIST_ITEM_HEIGHT}px`,nn(v,q.LIST_BYPASS_THRESHOLD/3)){g.innerHTML="",g.style.transform="translateY(0px)",m.forEach((P,O)=>{g.appendChild(y(P,O))});return}const R=on({totalRows:v,viewportHeight:k,scrollTop:S,rowHeight:q.LIST_ITEM_HEIGHT,overscan:q.LIST_OVERSCAN});g.style.transform=`translateY(${R.offsetY}px)`,g.innerHTML="";for(let P=R.start;P<R.end;P++)g.appendChild(y(m[P],P-R.start))},_=v=>{const k=this.config.caseSensitive??!1,S=k?v:v.toLowerCase();if(m=i.filter(R=>{const P=R==null?"(Blank)":String(R),O=k?P:P.toLowerCase();return!v||O.includes(S)}),m.length===0){p.style.height="0px",g.innerHTML="";const R=document.createElement("div");R.className="tbw-filter-no-match",R.textContent="No matching values",g.appendChild(R);return}b()};f.addEventListener("scroll",()=>{m.length>0&&b()},{passive:!0}),_(l.value),e.appendChild(f);let x;l.addEventListener("input",()=>{clearTimeout(x),x=setTimeout(()=>{this.searchText.set(r,l.value),_(l.value)},this.config.debounceMs??150)});const A=document.createElement("div");A.className="tbw-filter-buttons";const T=document.createElement("button");T.className="tbw-filter-apply-btn",T.textContent="Apply",T.addEventListener("click",()=>{const v=[];for(const[k,S]of w)if(!S)if(k==="__null__")v.push(null);else{const R=i.find(P=>String(P)===k);v.push(R!==void 0?R:k)}t.applySetFilter(v)}),A.appendChild(T);const E=document.createElement("button");E.className="tbw-filter-clear-btn",E.textContent="Clear Filter",E.addEventListener("click",()=>{t.clearFilter()}),A.appendChild(E),e.appendChild(A)}applySetFilter(e,t){this.excludedValues.set(e,new Set(t)),t.length===0?this.filters.delete(e):this.filters.set(e,{field:e,type:"set",operator:"notIn",value:t}),this.applyFiltersInternal()}applyTextFilter(e,t,i,n){this.filters.set(e,{field:e,type:"text",operator:t,value:i,valueTo:n}),this.applyFiltersInternal()}applyFiltersInternal(){this.cachedResult=null,this.cacheKey=null;const e=[...this.filters.values()];if(this.config.filterHandler){const t=this.grid;t.setAttribute("aria-busy","true");const i=this.config.filterHandler(e,this.sourceRows),n=r=>{t.removeAttribute("aria-busy"),this.cachedResult=r,this.grid.rows=r,this.emit("filter-change",{filters:e,filteredRowCount:r.length}),this.requestRender()};i&&typeof i.then=="function"?i.then(n):n(i);return}this.emit("filter-change",{filters:e,filteredRowCount:0}),this.requestRender()}getColumnState(e){const t=this.filters.get(e);if(t)return{filter:{type:t.type,operator:t.operator,value:t.value,valueTo:t.valueTo}}}applyColumnState(e,t){if(!t.filter){this.filters.delete(e);return}const i={field:e,type:t.filter.type,operator:t.filter.operator,value:t.filter.value,valueTo:t.filter.valueTo};this.filters.set(e,i),this.cachedResult=null,this.cacheKey=null}}function Gt(o){if(!o.length)return[];const e=new Map,t=[],i=(s,l)=>{if(!l.length)return;const a=t[t.length-1];if(a&&a.implicit&&a.firstIndex+a.columns.length===s){a.columns.push(...l);return}t.push({id:"__implicit__"+s,label:void 0,columns:l,firstIndex:s,implicit:!0})};let n=[],r=0;return o.forEach((s,l)=>{const a=s.group;if(!a){n.length===0&&(r=l),n.push(s);return}n.length&&(i(r,n.slice()),n=[]);const c=typeof a=="string"?a:a.id;let d=e.get(c);d||(d={id:c,label:typeof a=="string"?void 0:a.label,columns:[],firstIndex:l},e.set(c,d),t.push(d)),d.columns.push(s)}),n.length&&i(r,n),t.length===1&&t[0].implicit&&t[0].columns.length===o.length?[]:t}function dn(o,e,t){if(!e.length||!o)return;const i=new Map;for(const r of e)for(const s of r.columns)s.field&&i.set(s.field,r.id);const n=Array.from(o.querySelectorAll(".cell[data-field]"));n.forEach(r=>{const s=r.getAttribute("data-field")||"",l=i.get(s);l&&(r.classList.add("grouped"),r.getAttribute("data-group")||r.setAttribute("data-group",l))});for(const r of e){const s=r.columns[r.columns.length-1],l=n.find(a=>a.getAttribute("data-field")===s.field);l&&l.classList.add("group-end")}}function un(o,e){if(o.length===0)return null;const t=document.createElement("div");t.className="header-group-row",t.setAttribute("role","row");for(const i of o){const n=i.columns[0],r=n?e.findIndex(c=>c.field===n.field):-1;if(r===-1)continue;const s=String(i.id).startsWith("__implicit__"),l=s?"":i.label||i.id,a=document.createElement("div");a.className="cell header-group-cell",s&&a.classList.add("implicit-group"),a.setAttribute("data-group",String(i.id)),a.style.gridColumn=`${r+1} / span ${i.columns.length}`,a.textContent=l,t.appendChild(a)}return t}function hn(o){return o.some(e=>e.group!=null)}const fn="@layer tbw-plugins{.header-group-row{display:grid;grid-auto-flow:column;background:var(--tbw-grouping-columns-header-bg, var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-grouping-columns-border, var(--tbw-color-border))}.header-group-cell{display:flex;align-items:center;justify-content:center;padding:var(--tbw-button-padding-sm, .25rem .5rem);font-weight:600;font-size:var(--tbw-font-size-sm, .9em);text-transform:uppercase;letter-spacing:.5px;border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-group-cell:last-child{border-right:none}.header-row .cell.grouped{border-top:none}.header-row .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-row .cell.group-end:last-child{border-right:none}.rows .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.rows .cell.group-end:last-child{border-right:none}.header-group-row.no-borders{border-bottom:none}.header-group-row.no-borders .header-group-cell{border-right:none}.header-row.no-group-borders .cell.group-end{border-right:1px solid var(--tbw-color-border)}}";class gn extends L{static manifest={ownedProperties:[{property:"group",level:"column",description:'the "group" column property'},{property:"columnGroups",level:"config",description:'the "columnGroups" config property',isUsed:e=>Array.isArray(e)&&e.length>0}]};name="groupingColumns";styles=fn;get defaultConfig(){return{showGroupBorders:!0}}groups=[];isActive=!1;detach(){this.groups=[],this.isActive=!1}static detect(e,t){if(t?.columnGroups&&Array.isArray(t.columnGroups)&&t.columnGroups.length>0)return!0;const i=t?.columns;return Array.isArray(i)?hn(i):!1}processColumns(e){const t=this.grid?.gridConfig?.columnGroups;let i;if(t&&Array.isArray(t)&&t.length>0){const r=new Map;for(const s of t)for(const l of s.children)r.set(l,{id:s.id,label:s.header});i=e.map(s=>{const l=r.get(s.field);return l&&!s.group?{...s,group:l}:s})}else i=[...e];const n=Gt(i);return n.length===0?(this.isActive=!1,this.groups=[],i):(this.isActive=!0,this.groups=n,i)}afterRender(){if(!this.isActive){const a=this.gridElement?.querySelector(".header")?.querySelector(".header-group-row");a&&a.remove();return}const e=this.gridElement?.querySelector(".header");if(!e)return;const t=e.querySelector(".header-group-row");t&&t.remove();const i=this.columns,n=Gt(i);if(n.length===0)return;const r=un(n,i);if(r){r.classList.toggle("no-borders",!this.config.showGroupBorders);const l=e.querySelector(".header-row");l?e.insertBefore(r,l):e.appendChild(r)}const s=e.querySelector(".header-row");s&&(s.classList.toggle("no-group-borders",!this.config.showGroupBorders),dn(s,n)),this.#e(n)}#e(e){if(!this.config.showGroupBorders)return;const t=this.gridElement;if(!t)return;const i=new Set;for(const r of e){const s=r.columns[r.columns.length-1];s?.field&&i.add(s.field)}const n=t.querySelectorAll(".rows .cell[data-field]");for(const r of n){const s=r.getAttribute("data-field");s&&i.has(s)?r.classList.add("group-end"):r.classList.remove("group-end")}}isGroupingActive(){return this.isActive}getGroups(){return this.groups}getGroupColumns(e){const t=this.groups.find(i=>i.id===e);return t?t.columns:[]}refresh(){this.requestRender()}}const ze={sum:(o,e)=>o.reduce((t,i)=>t+(Number(i[e])||0),0),avg:(o,e)=>{const t=o.reduce((i,n)=>i+(Number(n[e])||0),0);return o.length?t/o.length:0},count:o=>o.length,min:(o,e)=>Math.min(...o.map(t=>Number(t[e])||1/0)),max:(o,e)=>Math.max(...o.map(t=>Number(t[e])||-1/0)),first:(o,e)=>o[0]?.[e],last:(o,e)=>o[o.length-1]?.[e]},ae=new Map,K={register(o,e){ae.set(o,e)},unregister(o){ae.delete(o)},get(o){if(o!==void 0)return typeof o=="function"?o:ae.get(o)??ze[o]},run(o,e,t,i){const n=this.get(o);return n?n(e,t,i):void 0},has(o){return ae.has(o)||o in ze},list(){return[...Object.keys(ze),...ae.keys()]}},Kt={sum:o=>o.reduce((e,t)=>e+t,0),avg:o=>o.length?o.reduce((e,t)=>e+t,0)/o.length:0,count:o=>o.length,min:o=>o.length?Math.min(...o):0,max:o=>o.length?Math.max(...o):0,first:o=>o[0]??0,last:o=>o[o.length-1]??0};function pn(o){return Kt[o]??Kt.sum}K.register.bind(K),K.unregister.bind(K);const Bt=K.get.bind(K),Wt=K.run.bind(K);K.list.bind(K);function wn({rows:o,config:e,expanded:t}){const i=e.groupOn;if(typeof i!="function")return[];const n={key:"__root__",value:null,depth:-1,rows:[],children:new Map};if(o.forEach(l=>{let a=i(l);a==null||a===!1?a=["__ungrouped__"]:Array.isArray(a)||(a=[a]);let c=n;a.forEach((d,u)=>{const h=d==null?"∅":String(d),f=c.key==="__root__"?h:c.key+"||"+h;let p=c.children.get(h);p||(p={key:f,value:d,depth:u,rows:[],children:new Map,parent:c},c.children.set(h,p)),c=p}),c.rows.push(l)}),n.children.size===1&&n.children.has("__ungrouped__")&&n.children.get("__ungrouped__").rows.length===o.length)return[];const r=[],s=l=>{if(l===n){l.children.forEach(c=>s(c));return}const a=t.has(l.key);r.push({kind:"group",key:l.key,value:l.value,depth:l.depth,rows:l.rows,expanded:a}),a&&(l.children.size?l.children.forEach(c=>s(c)):l.rows.forEach(c=>r.push({kind:"data",row:c,rowIndex:o.indexOf(c)})))};return s(n),r}function mn(o,e){const t=new Set(o);return t.has(e)?t.delete(e):t.add(e),t}function bn(o){const e=new Set;for(const t of o)t.kind==="group"&&e.add(t.key);return e}function vn(){return new Set}function yn(o){return o.kind!=="group"?0:o.rows.length}const Cn="@layer tbw-plugins{.group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-grouping-rows-bg, var(--tbw-color-panel-bg));font-weight:500;border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height)}.group-row .cell{display:flex;align-items:center;padding:var(--tbw-cell-padding, .125rem .5rem)}.group-row:hover{background:var(--tbw-grouping-rows-bg-hover, var(--tbw-color-row-hover))}.group-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-toggle-size, 1.25rem);height:var(--tbw-toggle-size, 1.25rem);margin-right:.25rem;background:none;border:0;font:inherit}.group-toggle:hover{background:var(--tbw-grouping-rows-toggle-hover, var(--tbw-color-row-hover));border-radius:var(--tbw-border-radius, .125rem)}.group-label{display:inline-flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.group-count{color:var(--tbw-grouping-rows-count-color, var(--tbw-color-fg-muted));font-size:var(--tbw-font-size-xs, .85em);font-weight:400}.group-row{padding-left:calc(var(--tbw-group-depth, 0) * var(--tbw-group-indent-width, 1.25em))}.data-grid-row.tbw-group-slide-in{animation:tbw-group-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-group-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.data-grid-row.tbw-group-fade-in{animation:tbw-group-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-group-fade-in{0%{opacity:0}to{opacity:1}}}";class xn extends L{name="groupingRows";styles=Cn;get defaultConfig(){return{defaultExpanded:!1,showRowCount:!0,indentWidth:20,aggregators:{},animation:"slide"}}expandedKeys=new Set;flattenedRows=[];isActive=!1;previousVisibleKeys=new Set;keysToAnimate=new Set;get animationStyle(){return this.isAnimationEnabled?this.config.animation??"slide":!1}detach(){this.expandedKeys.clear(),this.flattenedRows=[],this.isActive=!1,this.previousVisibleKeys.clear(),this.keysToAnimate.clear()}static detect(e,t){return typeof t?.groupOn=="function"||typeof t?.enableRowGrouping=="boolean"}processRows(e){const t=this.config;if(typeof t.groupOn!="function")return this.isActive=!1,this.flattenedRows=[],[...e];const i=wn({rows:[...e],config:t,expanded:this.expandedKeys});if(i.length===0)return this.isActive=!1,this.flattenedRows=[],[...e];this.isActive=!0,this.flattenedRows=i,this.keysToAnimate.clear();const n=new Set;return i.forEach((r,s)=>{if(r.kind==="data"){const l=`data-${s}`;n.add(l),this.previousVisibleKeys.has(l)||this.keysToAnimate.add(l)}}),this.previousVisibleKeys=n,i.map(r=>r.kind==="group"?{__isGroupRow:!0,__groupKey:r.key,__groupValue:r.value,__groupDepth:r.depth,__groupRows:r.rows,__groupExpanded:r.expanded,__groupRowCount:yn(r)}:r.row)}onCellClick(e){const t=e.row;if(t?.__isGroupRow&&e.originalEvent.target?.closest(".group-toggle"))return this.toggle(t.__groupKey),!0}onKeyDown(e){if(e.key!==" ")return;const t=this.grid._focusRow,i=this.rows[t];if(i?.__isGroupRow)return e.preventDefault(),this.toggle(i.__groupKey),this.requestRenderWithFocus(),!0}renderRow(e,t,i){if(!e?.__isGroupRow)return!1;const n=this.config;if(n.groupRowRenderer){const l=()=>{this.toggle(e.__groupKey)},a=n.groupRowRenderer({key:e.__groupKey,value:e.__groupValue,depth:e.__groupDepth,rows:e.__groupRows,expanded:e.__groupExpanded,toggleExpand:l});if(a)return t.className="data-grid-row group-row",t.__isCustomRow=!0,t.setAttribute("data-group-depth",String(e.__groupDepth)),typeof a=="string"?t.innerHTML=a:(t.innerHTML="",t.appendChild(a)),!0}const r=()=>{this.toggle(e.__groupKey)};return t.className="data-grid-row group-row",t.__isCustomRow=!0,t.setAttribute("data-group-depth",String(e.__groupDepth)),t.setAttribute("role","row"),t.setAttribute("aria-expanded",String(e.__groupExpanded)),t.style.setProperty("--tbw-group-depth",String(e.__groupDepth||0)),n.indentWidth!==void 0&&t.style.setProperty("--tbw-group-indent-width",`${n.indentWidth}px`),t.style.height="",t.innerHTML="",n.fullWidth!==!1?this.renderFullWidthGroupRow(e,t,r):this.renderPerColumnGroupRow(e,t,r),!0}afterRender(){const e=this.animationStyle;if(e===!1||this.keysToAnimate.size===0)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const i=e==="fade"?"tbw-group-fade-in":"tbw-group-slide-in";for(const n of t.querySelectorAll(".data-grid-row:not(.group-row)")){const r=n.querySelector(".cell[data-row]"),s=r?parseInt(r.getAttribute("data-row")??"-1",10):-1,a=this.flattenedRows[s]?.kind==="data"?`data-${s}`:void 0;a&&this.keysToAnimate.has(a)&&(n.classList.add(i),n.addEventListener("animationend",()=>n.classList.remove(i),{once:!0}))}this.keysToAnimate.clear()}createToggleButton(e,t){const i=document.createElement("button");return i.type="button",i.className=`group-toggle${e?" expanded":""}`,i.setAttribute("aria-label",e?"Collapse group":"Expand group"),this.setIcon(i,this.resolveIcon(e?"collapse":"expand")),i.addEventListener("click",n=>{n.stopPropagation(),t()}),i}getGroupLabelText(e,t,i){const n=this.config;return n.formatLabel?n.formatLabel(e,t,i):String(e)}renderFullWidthGroupRow(e,t,i){const n=this.config,r=document.createElement("div");r.className="cell group-full",r.style.gridColumn="1 / -1",r.setAttribute("role","gridcell"),r.setAttribute("data-col","0"),r.appendChild(this.createToggleButton(e.__groupExpanded,i));const s=document.createElement("span");if(s.className="group-label",s.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey),r.appendChild(s),n.showRowCount!==!1){const l=document.createElement("span");l.className="group-count",l.textContent=`(${e.__groupRowCount??e.__groupRows?.length??0})`,r.appendChild(l)}t.appendChild(r)}renderPerColumnGroupRow(e,t,i){const n=this.config,r=n.aggregators??{},s=this.columns,l=e.__groupRows??[],c=this.gridElement?.querySelector(".body")?.style.gridTemplateColumns||"";c&&(t.style.display="grid",t.style.gridTemplateColumns=c);let d=!1;s.forEach((u,h)=>{const f=document.createElement("div");if(f.className="cell group-cell",f.setAttribute("data-col",String(h)),f.setAttribute("role","gridcell"),Te(u)){f.setAttribute("data-field",u.field),t.appendChild(f);return}if(d){const p=r[u.field];if(p){const g=Wt(p,l,u.field,u);f.textContent=g!=null?String(g):""}else f.textContent=""}else{d=!0,f.appendChild(this.createToggleButton(e.__groupExpanded,i));const p=document.createElement("span"),g=r[u.field];if(g){const w=Wt(g,l,u.field,u);p.textContent=w!=null?String(w):String(e.__groupValue)}else p.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey);if(f.appendChild(p),n.showRowCount!==!1){const w=document.createElement("span");w.className="group-count",w.textContent=` (${l.length})`,f.appendChild(w)}}t.appendChild(f)})}expandAll(){this.expandedKeys=bn(this.flattenedRows),this.requestRender()}collapseAll(){this.expandedKeys=vn(),this.requestRender()}toggle(e){this.expandedKeys=mn(this.expandedKeys,e);const t=this.flattenedRows.find(i=>i.kind==="group"&&i.key===e);this.emit("group-toggle",{key:e,expanded:this.expandedKeys.has(e),value:t?.value,depth:t?.depth??0}),this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}expand(e){this.expandedKeys.has(e)||(this.expandedKeys=new Set([...this.expandedKeys,e]),this.requestRender())}collapse(e){if(this.expandedKeys.has(e)){const t=new Set(this.expandedKeys);t.delete(e),this.expandedKeys=t,this.requestRender()}}getGroupState(){const e=this.flattenedRows.filter(t=>t.kind==="group");return{isActive:this.isActive,expandedCount:this.expandedKeys.size,totalGroups:e.length,expandedKeys:[...this.expandedKeys]}}getRowCount(){return this.flattenedRows.length}refreshGroups(){this.requestRender()}getExpandedGroups(){return[...this.expandedKeys]}getFlattenedRows(){return this.flattenedRows}isGroupingActive(){return this.isActive}setGroupOn(e){this.config.groupOn=e,this.requestRender()}}function Vt(o,e){const t=new Set(o);return t.has(e)?t.delete(e):t.add(e),t}function Rn(o,e){const t=new Set(o);return t.add(e),t}function En(o,e){const t=new Set(o);return t.delete(e),t}function Sn(o,e){return o.has(e)}function _n(o,e,t,i){const n=document.createElement("div");n.className="master-detail-row",n.setAttribute("data-detail-for",String(e)),n.setAttribute("role","row");const r=document.createElement("div");r.className="master-detail-cell",r.setAttribute("role","cell"),r.style.gridColumn=`1 / ${i+1}`;const s=t(o,e);return typeof s=="string"?r.innerHTML=s:s instanceof HTMLElement&&r.appendChild(s),n.appendChild(r),n}const An="@layer tbw-plugins{tbw-grid .cell[data-field=__tbw_expander]{border-right:none!important;padding:0;display:flex;align-items:center;justify-content:center}tbw-grid .header-row .cell[data-field=__tbw_expander]{display:none}tbw-grid .header-row .cell[data-field=__tbw_expander]+.cell{grid-column:1 / 3}tbw-grid .master-detail-expander{display:flex;align-items:center;justify-content:center;width:100%;height:100%}tbw-grid .master-detail-toggle{cursor:pointer;opacity:.7;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center}tbw-grid .master-detail-toggle:hover{opacity:1}tbw-grid .master-detail-row{grid-column:1 / -1;display:grid;background:var(--tbw-master-detail-bg, var(--tbw-color-row-alt));border-bottom:1px solid var(--tbw-master-detail-border, var(--tbw-color-border));overflow:hidden}tbw-grid .master-detail-cell{padding:var(--tbw-detail-padding, var(--tbw-spacing-xl, 1rem));overflow:auto}tbw-grid .master-detail-row.tbw-expanding{animation:tbw-detail-expand var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}tbw-grid .master-detail-row.tbw-collapsing{animation:tbw-detail-collapse var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-detail-expand{0%{opacity:0;max-height:0;padding-top:0;padding-bottom:0}to{opacity:1;max-height:var(--tbw-detail-max-height, 31.25rem);padding-top:var(--tbw-detail-padding, var(--tbw-spacing-xl, 1rem));padding-bottom:var(--tbw-detail-padding, var(--tbw-spacing-xl, 1rem))}}@keyframes tbw-detail-collapse{0%{opacity:1;max-height:var(--tbw-detail-max-height, 31.25rem)}to{opacity:0;max-height:0}}}";class qe extends L{name="masterDetail";styles=An;get defaultConfig(){return{detailHeight:"auto",expandOnRowClick:!1,collapseOnClickOutside:!1,animation:"slide"}}attach(e){super.attach(e),this.parseLightDomDetail()}parseLightDomDetail(){const e=this.grid;if(!e||typeof e.querySelector!="function")return;const t=e.querySelector("tbw-grid-detail");if(!t)return;const i=e;if(i.__frameworkAdapter?.parseDetailElement){const u=i.__frameworkAdapter.parseDetailElement(t);if(u){this.config={...this.config,detailRenderer:u};return}}const n=t.getAttribute("animation"),r=t.getAttribute("show-expand-column"),s=t.getAttribute("expand-on-row-click"),l=t.getAttribute("collapse-on-click-outside"),a=t.getAttribute("height"),c={};n!==null&&(c.animation=n==="false"?!1:n),r!==null&&(c.showExpandColumn=r!=="false"),s!==null&&(c.expandOnRowClick=s==="true"),l!==null&&(c.collapseOnClickOutside=l==="true"),a!==null&&(c.detailHeight=a==="auto"?"auto":parseInt(a,10));const d=t.innerHTML.trim();d&&!this.config.detailRenderer&&(c.detailRenderer=(u,h)=>{const f=we(d,{value:u,row:u});return ie(f)}),Object.keys(c).length>0&&(this.config={...this.config,...c})}get animationStyle(){return this.isAnimationEnabled?this.config.animation??"slide":!1}animateExpand(e){!this.isAnimationEnabled||this.animationStyle===!1||(e.classList.add("tbw-expanding"),e.addEventListener("animationend",()=>{e.classList.remove("tbw-expanding")},{once:!0}))}animateCollapse(e,t){if(!this.isAnimationEnabled||this.animationStyle===!1){t();return}e.classList.add("tbw-collapsing");const i=()=>{e.classList.remove("tbw-collapsing"),t()};e.addEventListener("animationend",i,{once:!0}),setTimeout(i,this.animationDuration+50)}expandedRows=new Set;detailElements=new Map;static DEFAULT_DETAIL_HEIGHT=150;getDetailHeight(e){const t=this.detailElements.get(e);return t?t.offsetHeight:typeof this.config?.detailHeight=="number"?this.config.detailHeight:qe.DEFAULT_DETAIL_HEIGHT}toggleAndEmit(e,t){this.expandedRows=Vt(this.expandedRows,e),this.emit("detail-expand",{rowIndex:t,row:e,expanded:this.expandedRows.has(e)}),this.requestRender()}detach(){this.expandedRows.clear(),this.detailElements.clear()}processColumns(e){if(!(this.config.showExpandColumn===!0||this.config.showExpandColumn!==!1&&!!this.config.detailRenderer))return[...e];const i=[...e];if(ko(i))return i;const r=Po(this.name);return r.viewRenderer=s=>{const{row:l}=s,a=this.expandedRows.has(l),c=document.createElement("span");c.className="master-detail-expander expander-cell";const d=document.createElement("span");return d.className=`master-detail-toggle${a?" expanded":""}`,this.setIcon(d,this.resolveIcon(a?"collapse":"expand")),d.setAttribute("role","button"),d.setAttribute("tabindex","0"),d.setAttribute("aria-expanded",String(a)),d.setAttribute("aria-label",a?"Collapse details":"Expand details"),c.appendChild(d),c},[r,...i]}onRowClick(e){if(!(!this.config.expandOnRowClick||!this.config.detailRenderer))return this.toggleAndEmit(e.row,e.rowIndex),!1}onCellClick(e){if(e.originalEvent?.target?.classList.contains("master-detail-toggle"))return this.toggleAndEmit(e.row,e.rowIndex),!0;this.expandedRows.size>0&&queueMicrotask(()=>this.#e())}onKeyDown(e){if(e.key!==" ")return;const t=this.grid._focusCol,i=this.grid._focusRow,n=this.columns[t];if(!n||!Te(n))return;const r=this.rows[i];if(r)return e.preventDefault(),this.toggleAndEmit(r,i),this.requestRenderWithFocus(),!0}afterRender(){this.#e()}onScrollRender(){!this.config.detailRenderer||this.expandedRows.size===0||this.#e()}#e(){if(!this.config.detailRenderer)return;const e=this.gridElement?.querySelector(".rows");if(!e)return;const t=new Map,i=e.querySelectorAll(".data-grid-row"),n=this.columns.length;for(const s of i){const l=s.querySelector(".cell[data-row]"),a=l?parseInt(l.getAttribute("data-row")??"-1",10):-1;a>=0&&t.set(a,s)}const r=e.querySelectorAll(".master-detail-row");for(const s of r){const l=parseInt(s.getAttribute("data-detail-for")??"-1",10),a=l>=0?this.rows[l]:void 0,c=a&&this.expandedRows.has(a),d=t.has(l);(!c||!d)&&(s.remove(),a&&this.detailElements.delete(a))}for(const[s,l]of t){const a=this.rows[s];if(!a||!this.expandedRows.has(a))continue;const c=this.detailElements.get(a);if(c){c.previousElementSibling!==l&&l.after(c);continue}const d=_n(a,s,this.config.detailRenderer,n);typeof this.config.detailHeight=="number"&&(d.style.height=`${this.config.detailHeight}px`),l.after(d),this.detailElements.set(a,d),this.animateExpand(d)}}getExtraHeight(){let e=0;for(const t of this.expandedRows)e+=this.getDetailHeight(t);return e}getExtraHeightBefore(e){let t=0;for(const i of this.expandedRows){const n=this.rows.indexOf(i);n>=0&&n<e&&(t+=this.getDetailHeight(i))}return t}adjustVirtualStart(e,t,i){if(this.expandedRows.size===0)return e;const n=[];for(const l of this.expandedRows){const a=this.rows.indexOf(l);a>=0&&n.push({index:a,row:l})}n.sort((l,a)=>l.index-a.index);let r=e,s=0;for(const{index:l,row:a}of n){const c=l*i+s,d=this.getDetailHeight(a),u=c+i+d;s+=d,!(l>=e)&&u>t&&l<r&&(r=l)}return r}expand(e){const t=this.rows[e];t&&(this.expandedRows=Rn(this.expandedRows,t),this.requestRender())}collapse(e){const t=this.rows[e];t&&(this.expandedRows=En(this.expandedRows,t),this.requestRender())}toggle(e){const t=this.rows[e];t&&(this.expandedRows=Vt(this.expandedRows,t),this.requestRender())}isExpanded(e){const t=this.rows[e];return t?Sn(this.expandedRows,t):!1}expandAll(){for(const e of this.rows)this.expandedRows.add(e);this.requestRender()}collapseAll(){this.expandedRows.clear(),this.requestRender()}getExpandedRows(){const e=[];for(const t of this.expandedRows){const i=this.rows.indexOf(t);i>=0&&e.push(i)}return e}getDetailElement(e){const t=this.rows[e];return t?this.detailElements.get(t):void 0}refreshDetailRenderer(){const e=this.config.detailRenderer;if(this.config={...this.config,detailRenderer:void 0},this.parseLightDomDetail(),!this.config.detailRenderer&&e&&(this.config={...this.config,detailRenderer:e}),this.config.detailRenderer){const t=this.grid;typeof t.refreshColumns=="function"?t.refreshColumns():this.requestRender()}}}function Tn(o,e,t){return e.length?[...o].sort((i,n)=>{for(const r of e){const l=t.find(u=>u.field===r.field)?.sortComparator??kn,a=i[r.field],c=n[r.field],d=l(a,c,i,n);if(d!==0)return r.direction==="asc"?d:-d}return 0}):[...o]}function kn(o,e){return o==null&&e==null?0:o==null?1:e==null?-1:typeof o=="number"&&typeof e=="number"?o-e:o instanceof Date&&e instanceof Date?o.getTime()-e.getTime():typeof o=="boolean"&&typeof e=="boolean"?o===e?0:o?-1:1:String(o).localeCompare(String(e))}function Pn(o,e,t,i){const n=o.find(r=>r.field===e);return t?n?n.direction==="asc"?o.map(r=>r.field===e?{...r,direction:"desc"}:r):o.filter(r=>r.field!==e):o.length<i?[...o,{field:e,direction:"asc"}]:o:n?.direction==="asc"?[{field:e,direction:"desc"}]:n?.direction==="desc"?[]:[{field:e,direction:"asc"}]}function $t(o,e){const t=o.findIndex(i=>i.field===e);return t>=0?t+1:void 0}function Ut(o,e){return o.find(t=>t.field===e)?.direction}const Ln='@layer tbw-plugins{.header-cell[data-sort=asc]:after{content:"↑";margin-left:4px;opacity:.8}.header-cell[data-sort=desc]:after{content:"↓";margin-left:4px;opacity:.8}.sort-indicator{margin-left:4px;opacity:.8}.sort-index{font-size:10px;background:var(--tbw-multi-sort-badge-bg, var(--tbw-color-panel-bg));color:var(--tbw-multi-sort-badge-color, var(--tbw-color-fg));border-radius:50%;width:14px;height:14px;display:inline-flex;align-items:center;justify-content:center;margin-left:2px;font-weight:600}}';class Dn extends L{name="multiSort";styles=Ln;get defaultConfig(){return{maxSortColumns:3,showSortIndex:!0}}sortModel=[];detach(){this.sortModel=[]}processRows(e){return this.sortModel.length===0?[...e]:Tn([...e],this.sortModel,[...this.columns])}onHeaderClick(e){if(!this.columns.find(r=>r.field===e.field)?.sortable)return!1;const i=e.originalEvent.shiftKey,n=this.config.maxSortColumns??3;return this.sortModel=Pn(this.sortModel,e.field,i,n),this.emit("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),!0}afterRender(){const e=this.gridElement;if(!e)return;const t=this.config.showSortIndex!==!1;e.querySelectorAll(".header-row .cell[data-field]").forEach(n=>{const r=n.getAttribute("data-field");if(!r)return;const s=$t(this.sortModel,r),l=Ut(this.sortModel,r);if(n.querySelector(".sort-index")?.remove(),l){n.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove(),n.setAttribute("data-sort",l);const d=document.createElement("span");d.className="sort-indicator",this.setIcon(d,this.resolveIcon(l==="asc"?"sortAsc":"sortDesc"));const u=n.querySelector(".tbw-filter-btn"),h=n.querySelector(".resize-handle"),f=u??h;if(f?n.insertBefore(d,f):n.appendChild(d),t&&this.sortModel.length>1&&s!==void 0){const p=document.createElement("span");p.className="sort-index",p.textContent=String(s),d.nextSibling?n.insertBefore(p,d.nextSibling):n.appendChild(p)}}else n.removeAttribute("data-sort")})}getSortModel(){return[...this.sortModel]}setSortModel(e){this.sortModel=[...e],this.emit("sort-change",{sortModel:[...e]}),this.requestRender()}clearSort(){this.sortModel=[],this.emit("sort-change",{sortModel:[]}),this.requestRender()}getSortIndex(e){return $t(this.sortModel,e)}getSortDirection(e){return Ut(this.sortModel,e)}getColumnState(e){const t=this.sortModel.findIndex(n=>n.field===e);return t===-1?void 0:{sort:{direction:this.sortModel[t].direction,priority:t}}}applyColumnState(e,t){if(!t.sort){this.sortModel=this.sortModel.filter(r=>r.field!==e);return}const i=this.sortModel.findIndex(r=>r.field===e),n={field:e,direction:t.sort.direction};i!==-1?this.sortModel[i]=n:this.sortModel.splice(t.sort.priority,0,n)}}function Hn(o){return o.filter(e=>e.sticky==="left")}function In(o){return o.filter(e=>e.sticky==="right")}function Fe(o){return o.some(e=>e.sticky==="left"||e.sticky==="right")}function jt(o,e){const t=Array.from(o.querySelectorAll(".header-row .cell"));if(!t.length)return;const i=new Map;e.forEach((s,l)=>{s.field&&i.set(s.field,l)});let n=0;for(const s of e)if(s.sticky==="left"){const l=i.get(s.field),a=t.find(c=>c.getAttribute("data-field")===s.field);a&&(a.classList.add("sticky-left"),a.style.position="sticky",a.style.left=n+"px",l!==void 0&&o.querySelectorAll(`.data-grid-row .cell[data-col="${l}"]`).forEach(c=>{c.classList.add("sticky-left"),c.style.position="sticky",c.style.left=n+"px"}),n+=a.offsetWidth)}let r=0;for(const s of[...e].reverse())if(s.sticky==="right"){const l=i.get(s.field),a=t.find(c=>c.getAttribute("data-field")===s.field);a&&(a.classList.add("sticky-right"),a.style.position="sticky",a.style.right=r+"px",l!==void 0&&o.querySelectorAll(`.data-grid-row .cell[data-col="${l}"]`).forEach(c=>{c.classList.add("sticky-right"),c.style.position="sticky",c.style.right=r+"px"}),r+=a.offsetWidth)}}function Yt(o){o.querySelectorAll(".sticky-left, .sticky-right").forEach(t=>{t.classList.remove("sticky-left","sticky-right"),t.style.position="",t.style.left="",t.style.right=""})}class Mn extends L{static manifest={ownedProperties:[{property:"sticky",level:"column",description:'the "sticky" column property',isUsed:e=>e==="left"||e==="right"}]};name="pinnedColumns";get defaultConfig(){return{}}isApplied=!1;leftOffsets=new Map;rightOffsets=new Map;detach(){this.leftOffsets.clear(),this.rightOffsets.clear(),this.isApplied=!1}static detect(e,t){const i=t?.columns;return Array.isArray(i)?Fe(i):!1}processColumns(e){return this.isApplied=Fe([...e]),[...e]}afterRender(){if(!this.isApplied)return;const e=this.grid,t=[...this.columns];if(!Fe(t)){Yt(e),this.isApplied=!1;return}queueMicrotask(()=>{jt(e,t)})}onPluginQuery(e){switch(e.type){case Ae.CAN_MOVE_COLUMN:{const t=e.context,i=t.sticky;if(i==="left"||i==="right")return!1;const n=t.meta?.sticky;return n==="left"||n==="right"?!1:void 0}default:return}}refreshStickyOffsets(){const e=[...this.columns];jt(this.grid,e)}getLeftPinnedColumns(){const e=[...this.columns];return Hn(e)}getRightPinnedColumns(){const e=[...this.columns];return In(e)}clearStickyPositions(){Yt(this.grid)}getHorizontalScrollOffsets(e,t){if(!this.isApplied)return;let i=0,n=0;if(e){const s=e.querySelectorAll(".sticky-left"),l=e.querySelectorAll(".sticky-right");s.forEach(a=>{i+=a.offsetWidth}),l.forEach(a=>{n+=a.offsetWidth})}else this.grid.querySelectorAll(".header-row .cell").forEach(a=>{a.classList.contains("sticky-left")?i+=a.offsetWidth:a.classList.contains("sticky-right")&&(n+=a.offsetWidth)});const r=t?.classList.contains("sticky-left")||t?.classList.contains("sticky-right");return{left:i,right:n,skipScroll:r}}}function On(o){return typeof o=="object"&&o!==null&&"aggFunc"in o}function Ge(o,e){const t=document.createElement("div");t.className="tbw-pinned-rows",t.setAttribute("role","presentation"),t.setAttribute("aria-live","polite");const i=document.createElement("div");i.className="tbw-pinned-rows-left";const n=document.createElement("div");n.className="tbw-pinned-rows-center";const r=document.createElement("div");if(r.className="tbw-pinned-rows-right",o.showRowCount!==!1){const s=document.createElement("span");s.className="tbw-status-panel tbw-status-panel-row-count",s.textContent=`Total: ${e.totalRows} rows`,i.appendChild(s)}if(o.showFilteredCount&&e.filteredRows!==e.totalRows){const s=document.createElement("span");s.className="tbw-status-panel tbw-status-panel-filtered-count",s.textContent=`Filtered: ${e.filteredRows}`,i.appendChild(s)}if(o.showSelectedCount&&e.selectedRows>0){const s=document.createElement("span");s.className="tbw-status-panel tbw-status-panel-selected-count",s.textContent=`Selected: ${e.selectedRows}`,r.appendChild(s)}if(o.customPanels)for(const s of o.customPanels){const l=Nn(s,e);switch(s.position){case"left":i.appendChild(l);break;case"center":n.appendChild(l);break;case"right":r.appendChild(l);break}}return t.appendChild(i),t.appendChild(n),t.appendChild(r),t}function Xt(o){const e=document.createElement("div");return e.className=`tbw-aggregation-rows tbw-aggregation-rows-${o}`,e.setAttribute("role","presentation"),e}function Zt(o,e,t,i){o.innerHTML="";for(const n of e){const r=document.createElement("div");if(r.className="tbw-aggregation-row",r.setAttribute("role","presentation"),n.id&&r.setAttribute("data-aggregation-id",n.id),n.fullWidth){const s=document.createElement("div");s.className="tbw-aggregation-cell tbw-aggregation-cell-full",s.style.gridColumn="1 / -1",s.textContent=n.label||"",r.appendChild(s)}else for(const s of t){const l=document.createElement("div");l.className="tbw-aggregation-cell",l.setAttribute("data-field",s.field);let a,c;const d=n.aggregators?.[s.field];if(d)if(On(d)){const u=Bt(d.aggFunc);u&&(a=u(i,s.field,s)),c=d.formatter}else{const u=Bt(d);u&&(a=u(i,s.field,s))}else if(n.cells&&Object.prototype.hasOwnProperty.call(n.cells,s.field)){const u=n.cells[s.field];typeof u=="function"?a=u(i,s.field,s):a=u}a!=null?l.textContent=c?c(a,s.field,s):String(a):l.textContent="",r.appendChild(l)}o.appendChild(r)}}function Nn(o,e){const t=document.createElement("div");t.className="tbw-status-panel tbw-status-panel-custom",t.id=`status-panel-${o.id}`;const i=o.render(e);return typeof i=="string"?t.innerHTML=i:t.appendChild(i),t}function Jt(o,e,t,i,n){return{totalRows:o.length,filteredRows:n?.cachedResult?.length??o.length,selectedRows:i?.selected?.size??0,columns:e,rows:o,grid:t}}const zn="@layer tbw-plugins{.tbw-footer{flex-shrink:0;z-index:var(--tbw-z-layer-pinned-rows, 20);background:var(--tbw-color-panel-bg)}.tbw-pinned-rows{display:flex;align-items:center;justify-content:space-between;padding:var(--tbw-button-padding, var(--tbw-spacing-md, .5rem) var(--tbw-spacing-lg, .75rem));background:var(--tbw-pinned-rows-bg, var(--tbw-color-panel-bg));border-top:1px solid var(--tbw-pinned-rows-border, var(--tbw-color-border));font-size:var(--tbw-font-size-xs, .75rem);color:var(--tbw-pinned-rows-color, var(--tbw-color-fg-muted));min-height:32px;box-sizing:border-box;min-width:fit-content}.tbw-pinned-rows-left,.tbw-pinned-rows-center,.tbw-pinned-rows-right{display:flex;align-items:center;gap:var(--tbw-spacing-xl, 1rem)}.tbw-pinned-rows-left{justify-content:flex-start}.tbw-pinned-rows-center{justify-content:center;flex:1}.tbw-pinned-rows-right{justify-content:flex-end}.tbw-status-panel{white-space:nowrap}.tbw-aggregation-rows{min-width:fit-content;background:var(--tbw-aggregation-bg, var(--tbw-color-header-bg))}.tbw-aggregation-rows-top{border-bottom:1px solid var(--tbw-aggregation-border, var(--tbw-color-border))}.tbw-aggregation-rows-bottom{border-top:1px solid var(--tbw-aggregation-border, var(--tbw-color-border))}.tbw-aggregation-row{display:grid;grid-template-columns:var(--tbw-column-template);font-size:var(--tbw-aggregation-font-size, .8em);font-weight:var(--tbw-aggregation-font-weight, 600)}.tbw-aggregation-cell{padding:var(--tbw-cell-padding, .125rem .5rem);min-height:var(--tbw-row-height, 1.75rem);display:flex;align-items:center;border-right:1px solid var(--tbw-color-border-cell)}.tbw-aggregation-cell:last-child{border-right:0}.tbw-aggregation-cell-full{grid-column:1 / -1;border-right:0}}";class qn extends L{name="pinnedRows";styles=zn;get defaultConfig(){return{position:"bottom",showRowCount:!0,showSelectedCount:!0,showFilteredCount:!0}}infoBarElement=null;topAggregationContainer=null;bottomAggregationContainer=null;footerWrapper=null;detach(){this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null),this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null)}afterRender(){const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-scroll-area")??e.querySelector(".tbw-grid-content")??e.children[0];if(!t)return;this.footerWrapper&&!t.contains(this.footerWrapper)&&(this.footerWrapper=null,this.bottomAggregationContainer=null,this.infoBarElement=null),this.topAggregationContainer&&!t.contains(this.topAggregationContainer)&&(this.topAggregationContainer=null),this.infoBarElement&&!t.contains(this.infoBarElement)&&(this.infoBarElement=null);const i=this.getSelectionState(),n=this.getFilterState(),r=Jt(this.rows,this.columns,this.grid,i,n),s=this.config.aggregationRows||[],l=s.filter(h=>h.position==="top"),a=s.filter(h=>h.position!=="top");if(l.length>0){if(!this.topAggregationContainer){this.topAggregationContainer=Xt("top");const h=e.querySelector(".header");h&&h.nextSibling?t.insertBefore(this.topAggregationContainer,h.nextSibling):t.appendChild(this.topAggregationContainer)}Zt(this.topAggregationContainer,l,this.visibleColumns,this.rows)}else this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null);const c=this.config.showRowCount!==!1||this.config.showSelectedCount&&r.selectedRows>0||this.config.showFilteredCount&&r.filteredRows!==r.totalRows||this.config.customPanels&&this.config.customPanels.length>0,d=c&&this.config.position!=="top",u=a.length>0||d;if(c&&this.config.position==="top")if(!this.infoBarElement)this.infoBarElement=Ge(this.config,r),t.insertBefore(this.infoBarElement,t.firstChild);else{const h=Ge(this.config,r);this.infoBarElement.replaceWith(h),this.infoBarElement=h}else this.config.position==="top"&&this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null);u?(this.footerWrapper||(this.footerWrapper=document.createElement("div"),this.footerWrapper.className="tbw-footer",t.appendChild(this.footerWrapper)),this.footerWrapper.innerHTML="",a.length>0&&(this.bottomAggregationContainer||(this.bottomAggregationContainer=Xt("bottom")),this.footerWrapper.appendChild(this.bottomAggregationContainer),Zt(this.bottomAggregationContainer,a,this.visibleColumns,this.rows)),d&&(this.infoBarElement=Ge(this.config,r),this.footerWrapper.appendChild(this.infoBarElement))):this.cleanupFooter()}cleanup(){this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null),this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null)}cleanupFooter(){this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.infoBarElement&&this.config.position!=="top"&&(this.infoBarElement.remove(),this.infoBarElement=null)}getSelectionState(){try{return this.grid?.getPluginState?.("selection")??null}catch{return null}}getFilterState(){try{return this.grid?.getPluginState?.("filtering")??null}catch{return null}}refresh(){this.requestRender()}getContext(){const e=this.getSelectionState(),t=this.getFilterState();return Jt(this.rows,this.columns,this.grid,e,t)}addPanel(e){this.config.customPanels||(this.config.customPanels=[]),this.config.customPanels.push(e),this.requestRender()}removePanel(e){this.config.customPanels&&(this.config.customPanels=this.config.customPanels.filter(t=>t.id!==e),this.requestRender())}addAggregationRow(e){this.config.aggregationRows||(this.config.aggregationRows=[]),this.config.aggregationRows.push(e),this.requestRender()}removeAggregationRow(e){this.config.aggregationRows&&(this.config.aggregationRows=this.config.aggregationRows.filter(t=>t.id!==e),this.requestRender())}}const Fn=pn;function Gn(o){const e=[];return!o.rowGroupFields?.length&&!o.columnGroupFields?.length&&e.push("At least one row or column group field is required"),o.valueFields?.length||e.push("At least one value field is required"),e}function Ke(o,e){return[...o,e].join("|")}function Kn(o,e){const t=e.rowGroupFields??[],i=e.columnGroupFields??[],n=e.valueFields??[],r=Bn(o,i),s=Qt(o,t,i,r,n,0,""),l=Vn(s,r,n),a=Object.values(l).reduce((c,d)=>c+d,0);return{rows:s,columnKeys:r,totals:l,grandTotal:a}}function Bn(o,e){if(e.length===0)return["value"];const t=new Set;for(const i of o){const n=e.map(r=>String(i[r]??"")).join("|");t.add(n)}return[...t].sort()}function Wn(o,e){const t=new Map;for(const i of o){const n=String(i[e]??""),r=t.get(n);r?r.push(i):t.set(n,[i])}return t}function Qt(o,e,t,i,n,r,s){const l=[];if(e.length===0){const h=ei(o,t,i,n),f=ti(h);return l.push({rowKey:s||"all",rowLabel:s||"All",depth:r,values:h,total:f,isGroup:!1,rowCount:o.length}),l}const a=e[0],c=e.slice(1),d=c.length>0,u=Wn(o,a);for(const[h,f]of u){const p=s?`${s}|${h}`:h,g=ei(f,t,i,n),w=ti(g);let m;d&&(m=Qt(f,c,t,i,n,r+1,p)),l.push({rowKey:p,rowLabel:h||"(blank)",depth:r,values:g,total:w,isGroup:d,children:m,rowCount:f.length})}return l}function ei(o,e,t,i){const n={};for(const r of t)for(const s of i){const a=(e.length>0?o.filter(h=>e.map(f=>String(h[f]??"")).join("|")===r):o).map(h=>Number(h[s.field])||0),c=Fn(s.aggFunc),d=a.length>0?c(a):null,u=Ke([r],s.field);n[u]=d}return n}function ti(o){let e=0;for(const t of Object.values(o))e+=t??0;return e}function Vn(o,e,t){const i={};function n(r){for(const s of r)if(!s.isGroup||!s.children?.length)for(const l of e)for(const a of t){const c=Ke([l],a.field);i[c]=(i[c]??0)+(s.values[c]??0)}else s.children&&n(s.children)}return n(o),i}function $n(o,e,t=!0){const i=[];function n(r){i.push(r);const s=e?e.has(r.rowKey):t;if(r.children&&s)for(const l of r.children)n(l)}for(const r of o)n(r);return i}function Un(o){const e=[];function t(i){if(i.isGroup&&e.push(i.rowKey),i.children)for(const n of i.children)t(n)}for(const i of o)t(i);return e}const jn=["sum","avg","count","min","max","first","last"];function Yn(o,e,t,i){const n=new AbortController,r={config:e,callbacks:i,signal:n.signal},s=document.createElement("div");return s.className="tbw-pivot-panel",s.appendChild(ce("Options",()=>er(t,r))),s.appendChild(ce("Row Groups",()=>ii("rowGroups",r))),s.appendChild(ce("Column Groups",()=>ii("columnGroups",r))),s.appendChild(ce("Values",()=>Zn(r))),s.appendChild(ce("Available Fields",()=>Qn(r))),o.appendChild(s),()=>{n.abort(),s.remove()}}function ce(o,e){const t=document.createElement("div");t.className="tbw-pivot-section";const i=document.createElement("div");i.className="tbw-pivot-section-header",i.textContent=o;const n=document.createElement("div");return n.className="tbw-pivot-section-content",n.appendChild(e()),t.appendChild(i),t.appendChild(n),t}function ii(o,e){const{config:t,callbacks:i,signal:n}=e,r=document.createElement("div");r.className="tbw-pivot-drop-zone",r.setAttribute("data-zone",o);const s=o==="rowGroups"?t.rowGroupFields??[]:t.columnGroupFields??[];if(s.length===0){const l=document.createElement("div");l.className="tbw-pivot-placeholder",l.textContent="Drag fields here or click to add",r.appendChild(l)}else for(const l of s)r.appendChild(Xn(l,o,e));return r.addEventListener("dragover",l=>{l.preventDefault(),r.classList.add("drag-over")},{signal:n}),r.addEventListener("dragleave",()=>{r.classList.remove("drag-over")},{signal:n}),r.addEventListener("drop",l=>{l.preventDefault(),r.classList.remove("drag-over");const a=l.dataTransfer?.getData("text/plain");a&&i.onAddFieldToZone(a,o)},{signal:n}),r}function Xn(o,e,t){const{callbacks:i,signal:n}=t,r=document.createElement("div");r.className="tbw-pivot-field-chip",r.draggable=!0;const s=i.getAvailableFields().find(c=>c.field===o),l=document.createElement("span");l.className="tbw-pivot-chip-label",l.textContent=s?.header??o;const a=document.createElement("button");return a.className="tbw-pivot-chip-remove",a.innerHTML="×",a.title="Remove field",a.addEventListener("click",c=>{c.stopPropagation(),i.onRemoveFieldFromZone(o,e)},{signal:n}),r.appendChild(l),r.appendChild(a),r.addEventListener("dragstart",c=>{c.dataTransfer?.setData("text/plain",o),c.dataTransfer?.setData("source-zone",e),r.classList.add("dragging")},{signal:n}),r.addEventListener("dragend",()=>{r.classList.remove("dragging")},{signal:n}),r}function Zn(o){const{config:e,callbacks:t,signal:i}=o,n=document.createElement("div");n.className="tbw-pivot-drop-zone tbw-pivot-values-zone",n.setAttribute("data-zone","values");const r=e.valueFields??[];if(r.length===0){const s=document.createElement("div");s.className="tbw-pivot-placeholder",s.textContent="Drag numeric fields here for aggregation",n.appendChild(s)}else for(const s of r)n.appendChild(Jn(s,o));return n.addEventListener("dragover",s=>{s.preventDefault(),n.classList.add("drag-over")},{signal:i}),n.addEventListener("dragleave",()=>{n.classList.remove("drag-over")},{signal:i}),n.addEventListener("drop",s=>{s.preventDefault(),n.classList.remove("drag-over");const l=s.dataTransfer?.getData("text/plain");l&&t.onAddValueField(l,"sum")},{signal:i}),n}function Jn(o,e){const{callbacks:t,signal:i}=e,n=document.createElement("div");n.className="tbw-pivot-field-chip tbw-pivot-value-chip";const r=t.getAvailableFields().find(d=>d.field===o.field),s=document.createElement("div");s.className="tbw-pivot-value-label-wrapper";const l=document.createElement("span");l.className="tbw-pivot-chip-label",l.textContent=r?.header??o.field;const a=document.createElement("select");a.className="tbw-pivot-agg-select",a.title="Aggregation function";for(const d of jn){const u=document.createElement("option");u.value=d,u.textContent=d.toUpperCase(),u.selected=d===o.aggFunc,a.appendChild(u)}a.addEventListener("change",()=>{t.onUpdateValueAggFunc(o.field,a.value)},{signal:i});const c=document.createElement("button");return c.className="tbw-pivot-chip-remove",c.innerHTML="×",c.title="Remove value field",c.addEventListener("click",d=>{d.stopPropagation(),t.onRemoveValueField(o.field)},{signal:i}),s.appendChild(l),s.appendChild(a),n.appendChild(s),n.appendChild(c),n}function Qn(o){const{config:e,callbacks:t,signal:i}=o,n=document.createElement("div");n.className="tbw-pivot-available-fields";const r=t.getAvailableFields(),s=new Set([...e.rowGroupFields??[],...e.columnGroupFields??[],...e.valueFields?.map(a=>a.field)??[]]),l=r.filter(a=>!s.has(a.field));if(l.length===0){const a=document.createElement("div");a.className="tbw-pivot-placeholder",a.textContent="All fields are in use",n.appendChild(a)}else for(const a of l){const c=document.createElement("div");c.className="tbw-pivot-field-chip available",c.textContent=a.header,c.draggable=!0,c.title=`Drag to add "${a.field}" to a zone`,c.addEventListener("dragstart",d=>{d.dataTransfer?.setData("text/plain",a.field),c.classList.add("dragging")},{signal:i}),c.addEventListener("dragend",()=>{c.classList.remove("dragging")},{signal:i}),n.appendChild(c)}return n}function er(o,e){const{config:t,callbacks:i,signal:n}=e,r=document.createElement("div");return r.className="tbw-pivot-options",r.appendChild(Be("Enable Pivot View",o,s=>{i.onTogglePivot(s)},n)),r.appendChild(Be("Show Row Totals",t.showTotals??!0,s=>{i.onOptionChange("showTotals",s)},n)),r.appendChild(Be("Show Grand Total",t.showGrandTotal??!0,s=>{i.onOptionChange("showGrandTotal",s)},n)),r}function Be(o,e,t,i){const n=document.createElement("label");n.className="tbw-pivot-checkbox";const r=document.createElement("input");r.type="checkbox",r.checked=e,r.addEventListener("change",()=>t(r.checked),{signal:i});const s=document.createElement("span");return s.textContent=o,n.appendChild(r),n.appendChild(s),n}function tr(o,e,t){return e.className="data-grid-row pivot-group-row",e.setAttribute("data-pivot-depth",String(o.__pivotDepth??0)),e.setAttribute("data-pivot-key",String(o.__pivotRowKey??"")),e.setAttribute("role","row"),e.innerHTML="",t.columns.forEach((i,n)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(n)),r.setAttribute("data-row",String(t.rowIndex)),r.setAttribute("role","gridcell"),n===0){const s=Number(o.__pivotIndent)||0;r.style.paddingLeft=`${s}px`;const l=String(o.__pivotRowKey),a=document.createElement("button");a.type="button",a.className="pivot-toggle",a.setAttribute("aria-label",o.__pivotExpanded?"Collapse group":"Expand group"),t.setIcon(a,t.resolveIcon(o.__pivotExpanded?"collapse":"expand")),a.addEventListener("click",u=>{u.stopPropagation(),t.onToggle(l)}),r.appendChild(a);const c=document.createElement("span");c.className="pivot-label",c.textContent=String(o.__pivotLabel??""),r.appendChild(c);const d=document.createElement("span");d.className="pivot-count",d.textContent=` (${Number(o.__pivotRowCount)||0})`,r.appendChild(d)}else{const s=o[i.field];r.textContent=s!=null?String(s):""}e.appendChild(r)}),!0}function ir(o,e,t,i){return e.className="data-grid-row pivot-leaf-row",e.setAttribute("data-pivot-depth",String(o.__pivotDepth??0)),e.setAttribute("data-pivot-key",String(o.__pivotRowKey??"")),e.innerHTML="",t.forEach((n,r)=>{const s=document.createElement("div");if(s.className="cell",s.setAttribute("data-col",String(r)),s.setAttribute("data-row",String(i)),s.setAttribute("role","gridcell"),r===0){const l=Number(o.__pivotIndent)||0;s.style.paddingLeft=`${l+20}px`;const a=document.createElement("span");a.className="pivot-label",a.textContent=String(o.__pivotLabel??""),s.appendChild(a)}else{const l=o[n.field];s.textContent=l!=null?String(l):""}e.appendChild(s)}),!0}function or(o,e,t){return e.className="pivot-grand-total-row",e.setAttribute("role","presentation"),e.innerHTML="",t.forEach((i,n)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(n)),n===0){const s=document.createElement("span");s.className="pivot-label",s.textContent="Grand Total",r.appendChild(s)}else{const s=o[i.field];r.textContent=s!=null?String(s):""}e.appendChild(r)}),!0}const nr='@layer tbw-plugins{.pivot-group-row{display:grid;grid-template-columns:var(--tbw-column-template);font-weight:600;background:var(--tbw-pivot-group-bg, var(--tbw-color-row-alt));min-height:var(--tbw-row-height);border-bottom:var(--tbw-row-divider)}.pivot-group-row:hover{background:var(--tbw-pivot-group-hover, var(--tbw-color-row-hover))}.pivot-leaf-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-pivot-leaf-bg, var(--tbw-color-bg));min-height:var(--tbw-row-height);border-bottom:var(--tbw-row-divider)}.pivot-grand-total-row{display:grid;grid-template-columns:var(--tbw-column-template);font-weight:700;background:var(--tbw-pivot-grand-total-bg, var(--tbw-color-header-bg));min-height:var(--tbw-row-height);border-top:2px solid var(--tbw-color-border-strong)}.pivot-grand-total-row>.cell{display:flex;align-items:center;padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}.pivot-grand-total-row>.cell:last-child{border-right:0}.pivot-grand-total-footer{position:sticky;bottom:0;z-index:var(--tbw-z-layer-pinned-rows, 20);background:var(--tbw-pivot-grand-total-bg, var(--tbw-color-header-bg));min-width:fit-content}.pivot-group-row>.cell,.pivot-leaf-row>.cell{display:flex;align-items:center;padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}.pivot-group-row>.cell:last-child,.pivot-leaf-row>.cell:last-child{border-right:0}.pivot-toggle{display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;margin-right:6px;border:none;background:transparent;cursor:pointer;color:var(--tbw-pivot-toggle-color, var(--tbw-color-fg-muted));border-radius:var(--tbw-border-radius);transition:background .15s,color .15s}.pivot-toggle:hover{background:var(--tbw-pivot-toggle-hover-bg, var(--tbw-color-row-hover));color:var(--tbw-pivot-toggle-hover-color, var(--tbw-color-fg))}.pivot-toggle:focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}.pivot-label{font-weight:inherit}.pivot-count{color:var(--tbw-pivot-count-color, var(--tbw-color-fg-muted));font-size:.9em;font-weight:400}.pivot-total-row{font-weight:700;border-top:2px solid var(--tbw-pivot-border, var(--tbw-color-border-strong))}[data-pivot-depth="1"]{--tbw-pivot-depth: 1}[data-pivot-depth="2"]{--tbw-pivot-depth: 2}[data-pivot-depth="3"]{--tbw-pivot-depth: 3}[data-pivot-depth="4"]{--tbw-pivot-depth: 4}.tbw-pivot-panel{display:flex;flex-direction:column;gap:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));padding:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));height:100%;overflow-y:auto;font-size:var(--tbw-font-size-sm, .8125rem)}.tbw-pivot-section{border:1px solid var(--tbw-pivot-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);background:var(--tbw-pivot-section-bg, var(--tbw-color-bg))}.tbw-pivot-section-header{padding:var(--tbw-button-padding, var(--tbw-spacing-md, .5rem) var(--tbw-spacing-lg, .75rem));font-weight:600;background:var(--tbw-pivot-header-bg, var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-pivot-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius) var(--tbw-border-radius) 0 0}.tbw-pivot-section-content{padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-pivot-toggle-wrapper{display:flex;align-items:center}.tbw-pivot-toggle-label{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));cursor:pointer}.tbw-pivot-toggle-label input{width:var(--tbw-icon-size, 1rem);height:var(--tbw-icon-size, 1rem);cursor:pointer}.tbw-pivot-drop-zone{min-height:60px;padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border:2px dashed var(--tbw-pivot-drop-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);background:var(--tbw-pivot-drop-bg, var(--tbw-color-row-alt));display:flex;flex-wrap:wrap;gap:var(--tbw-spacing-sm, .375rem);align-content:flex-start;transition:all .15s ease}.tbw-pivot-drop-zone.drag-over{border-color:var(--tbw-color-accent);background:var(--tbw-pivot-drop-active, var(--tbw-focus-background))}.tbw-pivot-placeholder{color:var(--tbw-color-fg-muted);font-style:italic;padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));text-align:center;width:100%}.tbw-pivot-field-chip{display:inline-flex;align-items:center;gap:var(--tbw-spacing-sm, .375rem);padding:var(--tbw-button-padding-sm, var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-md, .5rem));background:var(--tbw-pivot-chip-bg, var(--tbw-color-header-bg));border:1px solid var(--tbw-pivot-chip-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);cursor:grab;font-size:var(--tbw-font-size-xs, .75rem);transition:all .15s ease}.tbw-pivot-field-chip:hover{background:var(--tbw-pivot-chip-hover, var(--tbw-color-row-hover));border-color:var(--tbw-color-accent)}.tbw-pivot-field-chip.available{background:var(--tbw-color-bg)}.tbw-pivot-field-chip.dragging{opacity:.5;cursor:grabbing}.tbw-pivot-chip-label{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:120px}.tbw-pivot-chip-remove{display:flex;align-items:center;justify-content:center;width:var(--tbw-icon-size, 1rem);height:var(--tbw-icon-size, 1rem);padding:0;border:none;background:transparent;color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-sm, .875rem);font-weight:700;cursor:pointer;border-radius:50%;transition:all .15s ease}.tbw-pivot-chip-remove:hover{background:var(--tbw-pivot-chip-remove-hover-bg, var(--tbw-color-accent));color:var(--tbw-pivot-chip-remove-hover-fg, var(--tbw-color-accent-fg))}.tbw-pivot-value-chip{padding:var(--tbw-button-padding-sm, var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-md, .5rem))}.tbw-pivot-value-label-wrapper{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));flex:1;min-width:0}.tbw-pivot-agg-select{padding:var(--tbw-spacing-xs, .125rem) var(--tbw-spacing-xs, .25rem);font-size:var(--tbw-font-size-xs, .6875rem);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);background:var(--tbw-color-bg);cursor:pointer}.tbw-pivot-available-fields{display:flex;flex-wrap:wrap;gap:var(--tbw-spacing-sm, .375rem);min-height:40px}.tbw-pivot-options{display:flex;flex-direction:column;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-pivot-checkbox{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));cursor:pointer}.tbw-pivot-checkbox input{width:var(--tbw-icon-size-sm, .875rem);height:var(--tbw-icon-size-sm, .875rem);cursor:pointer}.pivot-group-row.tbw-pivot-slide-in,.pivot-leaf-row.tbw-pivot-slide-in{animation:tbw-pivot-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-pivot-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.pivot-group-row.tbw-pivot-fade-in,.pivot-leaf-row.tbw-pivot-fade-in{animation:tbw-pivot-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-pivot-fade-in{0%{opacity:0}to{opacity:1}}}';class $ extends L{name="pivot";styles=nr;static PANEL_ID="pivot";get defaultConfig(){return{active:!0,showTotals:!0,showGrandTotal:!0,showToolPanel:!0,animation:"slide"}}isActive=!1;hasInitialized=!1;pivotResult=null;fieldHeaderMap=new Map;expandedKeys=new Set;defaultExpanded=!0;originalColumns=[];panelContainer=null;grandTotalFooter=null;previousVisibleKeys=new Set;keysToAnimate=new Set;hasValidPivotConfig(){return(this.config.valueFields?.length??0)>0}get animationStyle(){return this.isAnimationEnabled?this.config.animation??"slide":!1}detach(){this.isActive=!1,this.hasInitialized=!1,this.pivotResult=null,this.fieldHeaderMap.clear(),this.originalColumns=[],this.panelContainer=null,this.cleanupGrandTotalFooter(),this.previousVisibleKeys.clear(),this.keysToAnimate.clear()}getToolPanel(){if((this.config?.showToolPanel??this.userConfig?.showToolPanel??!0)!==!1)return{id:$.PANEL_ID,title:"Pivot",icon:"⊞",tooltip:"Configure pivot table",order:90,render:t=>this.renderPanel(t)}}processRows(e){if(!this.hasInitialized&&this.config.active!==!1&&this.hasValidPivotConfig()&&(this.hasInitialized=!0,this.isActive=!0),!this.isActive)return[...e];const t=Gn(this.config);if(t.length>0)return this.warn(`Config errors: ${t.join(", ")}`),[...e];this.buildFieldHeaderMap(),this.defaultExpanded=this.config.defaultExpanded??!0,this.expandedKeys.size===0&&this.defaultExpanded&&this.pivotResult&&this.expandAllKeys(),this.pivotResult=Kn(e,this.config),this.expandedKeys.size===0&&this.defaultExpanded&&this.expandAllKeys();const i=this.config.indentWidth??20,n=$n(this.pivotResult.rows,this.expandedKeys,this.defaultExpanded).map(s=>({__pivotRowKey:s.rowKey,__pivotLabel:s.rowLabel,__pivotDepth:s.depth,__pivotIsGroup:s.isGroup,__pivotHasChildren:!!s.children?.length,__pivotExpanded:this.expandedKeys.has(s.rowKey),__pivotRowCount:s.rowCount??0,__pivotIndent:s.depth*i,__pivotTotal:s.total,...s.values}));this.keysToAnimate.clear();const r=new Set;for(const s of n){const l=s.__pivotRowKey;r.add(l),!this.previousVisibleKeys.has(l)&&s.__pivotDepth>0&&this.keysToAnimate.add(l)}return this.previousVisibleKeys=r,n}processColumns(e){if(!this.isActive||!this.pivotResult)return[...e];const t=[],i=(this.config.rowGroupFields??[]).map(n=>this.fieldHeaderMap.get(n)??n).join(" / ");t.push({field:"__pivotLabel",header:i||"Group",width:200});for(const n of this.pivotResult.columnKeys)for(const r of this.config.valueFields??[]){const s=Ke([n],r.field),l=r.header||this.fieldHeaderMap.get(r.field)||r.field;t.push({field:s,header:`${n} - ${l} (${r.aggFunc})`,width:120,type:"number"})}return this.config.showTotals&&t.push({field:"__pivotTotal",header:"Total",width:100,type:"number"}),t}renderRow(e,t,i){const n=e;return n.__pivotRowKey&&n.__pivotHasChildren?tr(n,t,{columns:this.gridColumns,rowIndex:i,onToggle:r=>this.toggle(r),resolveIcon:r=>this.resolveIcon(r),setIcon:(r,s)=>this.setIcon(r,s)}):n.__pivotRowKey!==void 0&&this.isActive?ir(n,t,this.gridColumns,i):(this.cleanupPivotStyling(t),!1)}cleanupPivotStyling(e){(e.classList.contains("pivot-group-row")||e.classList.contains("pivot-leaf-row")||e.classList.contains("pivot-grand-total-row"))&&(e.classList.remove("pivot-group-row","pivot-leaf-row","pivot-grand-total-row"),e.classList.add("data-grid-row"),e.removeAttribute("data-pivot-depth"),e.innerHTML="")}onKeyDown(e){if(e.key!==" "||!this.isActive)return;const t=this.grid._focusRow,i=this.rows[t];if(!(!i?.__pivotIsGroup||!i.__pivotHasChildren))return e.preventDefault(),this.toggle(i.__pivotRowKey),this.requestRenderWithFocus(),!0}afterRender(){this.isActive&&this.config.showGrandTotal&&this.pivotResult?this.renderGrandTotalFooter():this.cleanupGrandTotalFooter();const e=this.animationStyle;if(e===!1||this.keysToAnimate.size===0)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const i=e==="fade"?"tbw-pivot-fade-in":"tbw-pivot-slide-in";for(const n of t.querySelectorAll(".pivot-group-row, .pivot-leaf-row")){const r=n.dataset.pivotKey;r&&this.keysToAnimate.has(r)&&(n.classList.add(i),n.addEventListener("animationend",()=>n.classList.remove(i),{once:!0}))}this.keysToAnimate.clear()}renderGrandTotalFooter(){if(!this.pivotResult)return;const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-scroll-area")??e.querySelector(".tbw-grid-content")??e.children[0];if(!t)return;this.grandTotalFooter||(this.grandTotalFooter=document.createElement("div"),this.grandTotalFooter.className="pivot-grand-total-footer",t.appendChild(this.grandTotalFooter));const i={__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals};or(i,this.grandTotalFooter,this.gridColumns)}cleanupGrandTotalFooter(){this.grandTotalFooter&&(this.grandTotalFooter.remove(),this.grandTotalFooter=null)}toggle(e){this.expandedKeys.has(e)?this.expandedKeys.delete(e):this.expandedKeys.add(e),this.requestRender()}expand(e){this.expandedKeys.add(e),this.requestRender()}collapse(e){this.expandedKeys.delete(e),this.requestRender()}expandAll(){this.expandAllKeys(),this.requestRender()}collapseAll(){this.expandedKeys.clear(),this.requestRender()}expandAllKeys(){if(!this.pivotResult)return;const e=Un(this.pivotResult.rows);for(const t of e)this.expandedKeys.add(t)}isExpanded(e){return this.expandedKeys.has(e)}enablePivot(){this.originalColumns.length===0&&this.captureOriginalColumns(),this.isActive=!0,this.requestRender()}disablePivot(){this.isActive=!1,this.pivotResult=null,this.requestRender()}isPivotActive(){return this.isActive}getPivotResult(){return this.pivotResult}setRowGroupFields(e){this.config.rowGroupFields=e,this.requestRender()}setColumnGroupFields(e){this.config.columnGroupFields=e,this.requestRender()}setValueFields(e){this.config.valueFields=e,this.requestRender()}refresh(){this.pivotResult=null,this.requestRender()}showPanel(){this.grid.openToolPanel(),this.grid.expandedToolPanelSections.includes($.PANEL_ID)||this.grid.toggleToolPanelSection($.PANEL_ID)}hidePanel(){this.grid.closeToolPanel()}togglePanel(){this.grid.isToolPanelOpen||this.grid.openToolPanel(),this.grid.toggleToolPanelSection($.PANEL_ID)}isPanelVisible(){return this.grid.isToolPanelOpen&&this.grid.expandedToolPanelSections.includes($.PANEL_ID)}get gridColumns(){return this.grid.columns??[]}refreshIfActive(){this.isActive&&this.refresh(),this.refreshPanel()}buildFieldHeaderMap(){const e=this.getAvailableFields();this.fieldHeaderMap.clear();for(const t of e)this.fieldHeaderMap.set(t.field,t.header)}getAvailableFields(){return this.originalColumns.length>0?this.originalColumns:this.captureOriginalColumns()}captureOriginalColumns(){try{const e=this.grid.getAllColumns?.()??this.grid.columns??[];return this.originalColumns=e.filter(t=>!t.field.startsWith("__pivot")).map(t=>({field:t.field,header:t.header??t.field})),this.originalColumns}catch{return[]}}renderPanel(e){this.panelContainer=e,this.originalColumns.length===0&&this.captureOriginalColumns();const t={onTogglePivot:i=>{i?this.enablePivot():this.disablePivot(),this.refreshPanel()},onAddFieldToZone:(i,n)=>this.addFieldToZone(i,n),onRemoveFieldFromZone:(i,n)=>this.removeFieldFromZone(i,n),onAddValueField:(i,n)=>this.addValueField(i,n),onRemoveValueField:i=>this.removeValueField(i),onUpdateValueAggFunc:(i,n)=>this.updateValueAggFunc(i,n),onOptionChange:(i,n)=>{this.config[i]=n,this.isActive&&this.refresh()},getAvailableFields:()=>this.getAvailableFields()};return Yn(e,this.config,this.isActive,t)}refreshPanel(){this.panelContainer&&(this.panelContainer.innerHTML="",this.renderPanel(this.panelContainer))}addFieldToZone(e,t){if(t==="rowGroups"){const i=this.config.rowGroupFields??[];i.includes(e)||(this.config.rowGroupFields=[...i,e])}else{const i=this.config.columnGroupFields??[];i.includes(e)||(this.config.columnGroupFields=[...i,e])}this.removeFromOtherZones(e,t),this.refreshIfActive()}removeFieldFromZone(e,t){t==="rowGroups"?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(i=>i!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(i=>i!==e),this.refreshIfActive()}removeFromOtherZones(e,t){t!=="rowGroups"&&(this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(i=>i!==e)),t!=="columnGroups"&&(this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(i=>i!==e)),t!=="values"&&(this.config.valueFields=(this.config.valueFields??[]).filter(i=>i.field!==e))}addValueField(e,t){const i=this.config.valueFields??[];i.some(n=>n.field===e)||(this.config.valueFields=[...i,{field:e,aggFunc:t}]),this.removeFromOtherZones(e,"values"),this.refreshIfActive()}removeValueField(e){this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e),this.refreshIfActive()}updateValueAggFunc(e,t){const i=this.config.valueFields??[],n=i.findIndex(r=>r.field===e);n>=0&&(i[n]={...i[n],aggFunc:t},this.config.valueFields=[...i]),this.isActive&&this.refresh()}}function rr(o){const e=o.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}function oi(o,e,t){if(e===t||e<0||e>=o.length||t<0||t>o.length)return o;const i=[...o],[n]=i.splice(e,1);return i.splice(t,0,n),i}const sr='@layer tbw-plugins{.header-row>.cell[draggable=true]{cursor:grab;position:relative}.header-row>.cell.dragging{opacity:.5;cursor:grabbing}.header-row>.cell.drop-before:before{content:"";position:absolute;left:0;top:0;bottom:0;width:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent));z-index:1}.header-row>.cell.drop-after:after{content:"";position:absolute;right:0;top:0;bottom:0;width:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent));z-index:1}.cell.flip-animating{transition:transform var(--tbw-animation-duration, .2s) ease-out;will-change:transform;z-index:1}@keyframes reorder-fade-in{0%{opacity:0}to{opacity:1}}.cell.fade-animating{animation:reorder-fade-in var(--tbw-animation-duration, .2s) ease-out backwards}}';class lr extends L{name="reorder";styles=sr;get defaultConfig(){return{animation:"flip"}}get animationType(){return this.isAnimationEnabled?this.config.animation!==void 0?this.config.animation:"flip":!1}get animationDuration(){return this.config.animationDuration!==void 0?this.config.animationDuration:super.animationDuration}isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;canMoveColumnWithPlugins(e){return!e||!rr(e)?!1:!this.grid.queryPlugins({type:Ae.CAN_MOVE_COLUMN,context:e}).includes(!1)}clearDragClasses(){this.gridElement?.querySelectorAll(".header-row > .cell").forEach(e=>{e.classList.remove("dragging","drop-target","drop-before","drop-after")})}attach(e){super.attach(e),e.addEventListener("column-reorder-request",t=>{const i=t.detail;i?.field&&typeof i.toIndex=="number"&&this.moveColumn(i.field,i.toIndex)},{signal:this.disconnectSignal})}detach(){this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null}afterRender(){const e=this.gridElement;if(!e)return;e.querySelectorAll(".header-row > .cell").forEach(i=>{const n=i,r=n.getAttribute("data-field");if(!r)return;const s=this.columns.find(l=>l.field===r);if(!this.canMoveColumnWithPlugins(s)){n.draggable=!1;return}n.draggable=!0,!n.getAttribute("data-dragstart-bound")&&(n.setAttribute("data-dragstart-bound","true"),n.addEventListener("dragstart",l=>{const c=this.getColumnOrder().indexOf(r);this.isDragging=!0,this.draggedField=r,this.draggedIndex=c,l.dataTransfer&&(l.dataTransfer.effectAllowed="move",l.dataTransfer.setData("text/plain",r)),n.classList.add("dragging")}),n.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.clearDragClasses()}),n.addEventListener("dragover",l=>{if(l.preventDefault(),!this.isDragging||this.draggedField===r)return;const a=n.getBoundingClientRect(),c=a.left+a.width/2,u=this.getColumnOrder().indexOf(r);this.dropIndex=l.clientX<c?u:u+1,n.classList.add("drop-target"),n.classList.toggle("drop-before",l.clientX<c),n.classList.toggle("drop-after",l.clientX>=c)}),n.addEventListener("dragleave",()=>{n.classList.remove("drop-target","drop-before","drop-after")}),n.addEventListener("drop",l=>{l.preventDefault();const a=this.draggedField,c=this.draggedIndex,d=this.dropIndex;if(!this.isDragging||a===null||c===null||d===null)return;const u=d>c?d-1:d,h=this.getColumnOrder(),f=oi(h,c,u),p={field:a,fromIndex:c,toIndex:u,columnOrder:f};this.emitCancelable("column-move",p)||this.updateColumnOrder(f)}))})}onKeyDown(e){if(!e.altKey||e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;const t=this.grid,i=t._focusCol,n=t._visibleColumns;if(i<0||i>=n.length)return;const r=n[i];if(!this.canMoveColumnWithPlugins(r))return;const s=this.getColumnOrder(),l=s.indexOf(r.field);if(l===-1)return;const a=e.key==="ArrowLeft"?l-1:l+1;if(a<0||a>=s.length)return;const c=n.find(d=>d.field===s[a]);if(this.canMoveColumnWithPlugins(c))return this.moveColumn(r.field,a),t._focusCol=a,N(this.grid),e.preventDefault(),e.stopPropagation(),!0}getColumnOrder(){return this.grid.getColumnOrder()}moveColumn(e,t){const i=this.getColumnOrder(),n=i.indexOf(e);if(n===-1)return;const r=oi(i,n,t);this.emitCancelable("column-move",{field:e,fromIndex:n,toIndex:t,columnOrder:r})||this.updateColumnOrder(r)}setColumnOrder(e){this.updateColumnOrder(e)}resetColumnOrder(){const e=this.columns.map(t=>t.field);this.updateColumnOrder(e)}captureHeaderPositions(){const e=new Map;return this.gridElement?.querySelectorAll(".header-row > .cell[data-field]").forEach(t=>{const i=t.getAttribute("data-field");i&&e.set(i,t.getBoundingClientRect().left)}),e}animateFLIP(e){const t=this.gridElement;if(!t||e.size===0)return;const i=new Map;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(s=>{const l=s.getAttribute("data-field");if(!l)return;const a=e.get(l);if(a===void 0)return;const c=a-s.getBoundingClientRect().left;Math.abs(c)>1&&i.set(l,c)}),i.size===0)return;const n=[];if(t.querySelectorAll(".cell[data-field]").forEach(s=>{const l=i.get(s.getAttribute("data-field")??"");if(l!==void 0){const a=s;a.style.transform=`translateX(${l}px)`,n.push(a)}}),n.length===0)return;this.gridElement.offsetHeight;const r=this.animationDuration;requestAnimationFrame(()=>{n.forEach(s=>{s.classList.add("flip-animating"),s.style.transform=""}),setTimeout(()=>{n.forEach(s=>{s.style.transform="",s.classList.remove("flip-animating")})},r+50)})}animateFade(e){const t=this.gridElement;if(!t){e();return}const i=this.captureHeaderPositions();e();const n=new Set;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(l=>{const a=l.getAttribute("data-field");if(!a)return;const c=i.get(a);if(c===void 0)return;const d=l.getBoundingClientRect().left;Math.abs(c-d)>1&&n.add(a)}),n.size===0)return;const r=[];if(t.querySelectorAll(".cell[data-field]").forEach(l=>{const a=l.getAttribute("data-field");if(a&&n.has(a)){const c=l;c.classList.add("fade-animating"),r.push(c)}}),r.length===0)return;const s=this.animationDuration;setTimeout(()=>{r.forEach(l=>l.classList.remove("fade-animating"))},s+50)}updateColumnOrder(e){const t=this.animationType;if(t==="flip"&&this.gridElement){const i=this.captureHeaderPositions();this.grid.setColumnOrder(e),requestAnimationFrame(()=>{this.gridElement.offsetHeight,this.animateFLIP(i)})}else t==="fade"?this.animateFade(()=>this.grid.setColumnOrder(e)):this.grid.setColumnOrder(e);this.grid.requestStateChange?.()}}const ar='tbw-grid[data-responsive-animate] .data-grid-row,tbw-grid[data-responsive-animate] .data-grid-row>.cell{transition:opacity var(--tbw-responsive-duration, .2s) ease-out,transform var(--tbw-responsive-duration, .2s) ease-out}tbw-grid[data-responsive][data-responsive-animate] .data-grid-row{animation:responsive-card-enter var(--tbw-responsive-duration, .2s) ease-out}@keyframes responsive-card-enter{0%{opacity:0;transform:translateY(-10px)}to{opacity:1;transform:translateY(0)}}tbw-grid[data-responsive] .header{display:none!important}tbw-grid[data-responsive] .footer-row{display:none}tbw-grid[data-responsive] .tbw-scroll-area{overflow-x:hidden;min-width:0!important}tbw-grid[data-responsive] .rows-body-wrapper{min-width:0!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row){display:block!important;grid-template-columns:none!important;padding:var(--tbw-cell-padding);padding-left:var(--tbw-spacing-xl);border-bottom:1px solid var(--tbw-color-border);min-height:auto!important;height:auto!important;contain:none!important;content-visibility:visible!important;background:var(--tbw-color-bg);position:relative}tbw-grid[data-responsive] .data-grid-row:not(.group-row):nth-child(2n){background:var(--tbw-color-row-alt)}tbw-grid[data-responsive] .data-grid-row:not(.group-row):hover{background:var(--tbw-color-row-hover)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)[aria-selected=true]{background:var(--tbw-color-selection)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)[aria-selected=true]:before{content:"";position:absolute;left:0;top:0;bottom:0;width:4px;background:var(--tbw-color-accent)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell{display:flex!important;justify-content:space-between;align-items:center;padding:var(--tbw-spacing-xs) var(--tbw-spacing-md);width:100%!important;min-width:0!important;min-height:auto!important;height:auto!important;line-height:1.5!important;position:static!important;left:auto!important;right:auto!important;border:none!important;border-bottom:none!important;border-right:none!important;background:transparent!important;white-space:normal!important;overflow:visible!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell:before{content:attr(data-header) ": ";font-weight:600;color:var(--tbw-color-header-fg);flex-shrink:0;margin-right:var(--tbw-spacing-md);min-width:100px}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell:after{content:none}tbw-grid[data-responsive] .cell[data-utility]{display:none!important}tbw-grid[data-responsive] .cell[data-responsive-hidden]{display:none!important}tbw-grid[data-responsive] .cell[data-responsive-value-only]{justify-content:flex-start!important;font-weight:500}tbw-grid[data-responsive] .cell[data-responsive-value-only]:before{display:none!important}tbw-grid:not([data-responsive]) .cell[data-responsive-hidden]{display:none!important}tbw-grid[data-responsive] .tbw-footer,tbw-grid[data-responsive] .tbw-pinned-rows,tbw-grid[data-responsive] .tbw-aggregation-rows{display:none!important}tbw-grid[data-responsive] .tbw-pinned-rows,tbw-grid[data-responsive] .tbw-aggregation-rows,tbw-grid[data-responsive] .tbw-aggregation-row{min-width:0!important}tbw-grid[data-responsive] .data-grid-row.responsive-card{display:block!important;padding:var(--tbw-cell-padding);border-bottom:1px solid var(--tbw-color-border)}tbw-grid[data-responsive] .data-grid-row.responsive-card>*{width:100%}tbw-grid[data-responsive] .data-grid-row.responsive-card .cell:before{display:none}';class cr extends L{name="responsive";version="1.0.0";styles=ar;static manifest={incompatibleWith:[{name:"groupingRows",reason:"Responsive card layout does not yet support row grouping. The variable row heights (cards vs group headers) cause scroll calculation issues."}]};#e;#o=!1;#d;#c=!1;#s=0;#i=new Set;#h=new Set;#u=null;#p=[];isResponsive(){return this.#o}setResponsive(e){e!==this.#o&&(this.#o=e,this.#b(),this.emit("responsive-change",{isResponsive:e,width:this.#s,breakpoint:this.config.breakpoint??0}))}setBreakpoint(e){this.config.breakpoint=e,this.#w(this.#s)}setCardRenderer(e){this.config.cardRenderer=e,this.#o&&this.requestRender()}getWidth(){return this.#s}getActiveBreakpoint(){return this.#u}attach(e){super.attach(e),this.#l(this.config.hiddenColumns),this.config.breakpoints?.length&&(this.#p=[...this.config.breakpoints].sort((t,i)=>i.maxWidth-t.maxWidth)),this.#e=new ResizeObserver(t=>{const i=t[0]?.contentRect.width??0;this.#s=i,clearTimeout(this.#d),this.#d=setTimeout(()=>{this.#w(i)},this.config.debounceMs??100)}),this.#e.observe(this.gridElement)}#l(e){if(this.#i.clear(),this.#h.clear(),!!e)for(const t of e)typeof t=="string"?this.#i.add(t):t.showValue?this.#h.add(t.field):this.#i.add(t.field)}detach(){this.#e?.disconnect(),this.#e=void 0,clearTimeout(this.#d),this.#d=void 0,this.gridElement&&this.gridElement.removeAttribute("data-responsive"),super.detach()}afterRender(){if(this.#_(),!(this.#p.length>0?this.#u!==null:this.#o))return;const t=this.#i.size>0,i=this.#h.size>0;if(!t&&!i)return;const n=this.gridElement.querySelectorAll(".cell[data-field]");for(const r of n){const s=r.getAttribute("data-field");s&&(this.#i.has(s)?(r.setAttribute("data-responsive-hidden",""),r.removeAttribute("data-responsive-value-only")):this.#h.has(s)?(r.setAttribute("data-responsive-value-only",""),r.removeAttribute("data-responsive-hidden")):(r.removeAttribute("data-responsive-hidden"),r.removeAttribute("data-responsive-value-only")))}}#w(e){if(this.#p.length>0){this.#m(e);return}const t=this.config.breakpoint??0;t===0&&!this.#c&&(this.#c=!0,console.warn("[tbw-grid:ResponsivePlugin] No breakpoint configured. Responsive mode is disabled. Set a breakpoint based on your grid's column count."));const i=t>0&&e<t;i!==this.#o&&(this.#o=i,this.#b(),this.emit("responsive-change",{isResponsive:i,width:e,breakpoint:t}),this.requestRender())}#m(e){let t=null;for(const n of this.#p)e<=n.maxWidth&&(t=n);if(t!==this.#u){this.#u=t,t?.hiddenColumns?this.#l(t.hiddenColumns):this.#l(this.config.hiddenColumns);const n=t?.cardLayout===!0;n!==this.#o&&(this.#o=n,this.#b()),this.emit("responsive-change",{isResponsive:this.#o,width:e,breakpoint:t?.maxWidth??0}),this.requestRender()}}#a;#b(){this.gridElement.toggleAttribute("data-responsive",this.#o);const e=this.config.animate!==!1;this.gridElement.toggleAttribute("data-responsive-animate",e),this.config.animationDuration&&this.gridElement.style.setProperty("--tbw-responsive-duration",`${this.config.animationDuration}ms`);const t=this.grid;if(this.#o){t._virtualization&&(this.#a=t._virtualization.rowHeight);const i=this.gridElement.querySelector(".tbw-scroll-area");i&&(i.scrollLeft=0)}else{const i=this.gridElement.querySelectorAll(".data-grid-row");for(const n of i)n.style.height="",n.classList.remove("responsive-card");this.#a&&this.#a>0&&t._virtualization&&(t._virtualization.rowHeight=this.#a,this.#a=void 0),this.#v=void 0,this.#g=void 0,this.#y=void 0}}renderRow(e,t,i){if(!this.#o||!this.config.cardRenderer||e.__isGroupRow)return;t.replaceChildren();const n=this.config.cardRenderer(e,i);t.className="data-grid-row responsive-card";const r=this.config.cardRowHeight??"auto";return r!=="auto"?t.style.height=`${r}px`:t.style.height="auto",t.appendChild(n),!0}onKeyDown(e){if(!this.#o||this.config.cardRenderer&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(e.key))return!1;const t=this.rows.length-1,i=this.visibleColumns.length-1;switch(e.key){case"ArrowDown":if(this.grid._focusCol<i)return this.grid._focusCol+=1,e.preventDefault(),N(this.grid),!0;if(this.grid._focusRow<t)return this.grid._focusRow+=1,this.grid._focusCol=0,e.preventDefault(),N(this.grid),!0;break;case"ArrowUp":if(this.grid._focusCol>0)return this.grid._focusCol-=1,e.preventDefault(),N(this.grid),!0;if(this.grid._focusRow>0)return this.grid._focusRow-=1,this.grid._focusCol=i,e.preventDefault(),N(this.grid),!0;break;case"ArrowRight":if(this.grid._focusRow<t)return this.grid._focusRow+=1,e.preventDefault(),N(this.grid),!0;break;case"ArrowLeft":if(this.grid._focusRow>0)return this.grid._focusRow-=1,e.preventDefault(),N(this.grid),!0;break}return!1}#v;#g;#y;#x(){if(this.#v&&this.#v>0)return this.#v;const e=this.config.cardRowHeight;return typeof e=="number"&&e>0?e:80}#C(){return this.#g&&this.#g>0?this.#g:this.#a??28}#R(){for(const e of this.rows)if(e.__isGroupRow)return!0;return!1}#r(){let e=0,t=0;for(const i of this.rows)i.__isGroupRow?e++:t++;return{groupCount:e,cardCount:t}}getExtraHeight(){if(!this.#o||!this.config.cardRenderer||!this.#R())return 0;const e=this.#a??28,t=this.#C(),i=this.#x(),{groupCount:n,cardCount:r}=this.#r(),s=n*Math.max(0,t-e),l=r*Math.max(0,i-e);return s+l}getExtraHeightBefore(e){if(!this.#o||!this.config.cardRenderer||!this.#R())return 0;const t=this.#a??28,i=this.#C(),n=this.#x(),r=Math.max(0,i-t),s=Math.max(0,n-t);let l=0,a=0;const c=this.rows,d=Math.min(e,c.length);for(let u=0;u<d;u++)c[u].__isGroupRow?l++:a++;return l*r+a*s}#E(){let e=0;for(const t of this.rows)t.__isGroupRow||e++;return e}#S=!1;#_(){if(!this.#o||!this.config.cardRenderer)return;let e=!1;const t=this.grid,i=this.#R(),n=this.#E();if(n!==this.#y&&(this.#y=n,e=!0),i){const s=this.gridElement.querySelector(".data-grid-row.group-row");if(s){const l=s.getBoundingClientRect().height;l>0&&l!==this.#g&&(this.#g=l,e=!0)}}const r=this.gridElement.querySelector(".data-grid-row.responsive-card");if(r){const s=r.getBoundingClientRect().height;s>0&&s!==this.#v&&(this.#v=s,e=!0,!i&&t._virtualization&&(t._virtualization.rowHeight=s))}e&&!this.#S&&(this.#S=!0,queueMicrotask(()=>{this.#S=!1,this.grid&&this.#o&&this.grid.refreshVirtualWindow?.(!0,!0)}))}}const dr='.dg-row-drag-handle{display:flex;align-items:center;justify-content:center;cursor:grab;-webkit-user-select:none;user-select:none;color:var(--tbw-color-fg-muted, #999);transition:color .15s ease;font-size:14px;letter-spacing:-2px}.dg-row-drag-handle:hover{color:var(--tbw-color-fg, #333)}.dg-row-drag-handle:active{cursor:grabbing}.data-grid-row.dragging{opacity:.6}.data-grid-row.drop-target{position:relative}.data-grid-row.drop-target.drop-before:before{content:"";position:absolute;top:0;left:0;right:0;height:2px;background-color:var(--tbw-color-accent, #1976d2);z-index:10}.data-grid-row.drop-target.drop-after:after{content:"";position:absolute;bottom:0;left:0;right:0;height:2px;background-color:var(--tbw-color-accent, #1976d2);z-index:10}.data-grid-row.keyboard-moving{background-color:var(--tbw-color-bg-selected, #e3f2fd);box-shadow:0 0 0 1px var(--tbw-color-accent, #1976d2) inset}.data-grid-row.animate-flip{transition:transform var(--tbw-animation-duration, .2s) ease-out}',ni="__tbw_row_drag";class ur extends L{name="rowReorder";styles=dr;get defaultConfig(){return{enableKeyboard:!0,showDragHandle:!0,dragHandlePosition:"left",dragHandleWidth:40,debounceMs:150,animation:"flip"}}isDragging=!1;draggedRowIndex=null;dropRowIndex=null;pendingMove=null;debounceTimer=null;lastFocusCol=0;detach(){this.clearDebounceTimer(),this.isDragging=!1,this.draggedRowIndex=null,this.dropRowIndex=null,this.pendingMove=null}processColumns(e){if(!this.config.showDragHandle)return[...e];const t={field:ni,header:"",width:this.config.dragHandleWidth??40,resizable:!1,sortable:!1,filterable:!1,meta:{lockPosition:!0,suppressMovable:!0,utility:!0},viewRenderer:()=>{const i=document.createElement("div");return i.className="dg-row-drag-handle",i.setAttribute("aria-label","Drag to reorder"),i.setAttribute("role","button"),i.setAttribute("tabindex","-1"),i.draggable=!0,this.setIcon(i,this.resolveIcon("dragHandle")),i}};return this.config.dragHandlePosition==="right"?[...e,t]:[t,...e]}afterRender(){if(!this.config.showDragHandle)return;const e=this.gridElement;if(!e)return;e.querySelectorAll(".dg-row-drag-handle").forEach(n=>{const r=n;if(r.getAttribute("data-drag-bound"))return;r.setAttribute("data-drag-bound","true");const s=r.closest(".data-grid-row");s&&this.setupHandleDragListeners(r,s)}),e.querySelectorAll(".data-grid-row").forEach(n=>{const r=n;r.getAttribute("data-drop-bound")||(r.setAttribute("data-drop-bound","true"),this.setupRowDropListeners(r))})}onKeyDown(e){if(!this.config.enableKeyboard||!e.ctrlKey||e.key!=="ArrowUp"&&e.key!=="ArrowDown")return;const t=this.grid,i=t._focusRow,n=t._rows??this.sourceRows;if(i<0||i>=n.length)return;const r=e.key==="ArrowUp"?"up":"down",s=r==="up"?i-1:i+1;if(s<0||s>=n.length)return;const l=n[i];if(!(this.config.canMove&&!this.config.canMove(l,i,s,r)))return this.handleKeyboardMove(l,i,s,r,t._focusCol),e.preventDefault(),e.stopPropagation(),!0}onCellClick(){this.flushPendingMove()}moveRow(e,t){const i=[...this.sourceRows];if(e<0||e>=i.length||t<0||t>=i.length||e===t)return;const n=t<e?"up":"down",r=i[e];this.config.canMove&&!this.config.canMove(r,e,t,n)||this.executeMove(r,e,t,"keyboard")}canMoveRow(e,t){const i=this.sourceRows;if(e<0||e>=i.length||t<0||t>=i.length||e===t)return!1;if(!this.config.canMove)return!0;const n=t<e?"up":"down";return this.config.canMove(i[e],e,t,n)}setupHandleDragListeners(e,t){e.addEventListener("dragstart",i=>{const n=this.getRowIndex(t);n<0||(this.isDragging=!0,this.draggedRowIndex=n,i.dataTransfer&&(i.dataTransfer.effectAllowed="move",i.dataTransfer.setData("text/plain",String(n))),t.classList.add("dragging"))}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedRowIndex=null,this.dropRowIndex=null,this.clearDragClasses()})}setupRowDropListeners(e){e.addEventListener("dragover",t=>{if(t.preventDefault(),!this.isDragging||this.draggedRowIndex===null)return;const i=this.getRowIndex(e);if(i<0||i===this.draggedRowIndex)return;const n=e.getBoundingClientRect(),r=n.top+n.height/2,s=t.clientY<r;this.dropRowIndex=s?i:i+1,e.classList.add("drop-target"),e.classList.toggle("drop-before",s),e.classList.toggle("drop-after",!s)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",t=>{t.preventDefault();const i=this.draggedRowIndex;let n=this.dropRowIndex;if(!(!this.isDragging||i===null||n===null)&&(n>i&&n--,i!==n)){const s=this.sourceRows[i],l=n<i?"up":"down";(!this.config.canMove||this.config.canMove(s,i,n,l))&&this.executeMove(s,i,n,"drag")}})}handleKeyboardMove(e,t,i,n,r){this.pendingMove?this.pendingMove.currentIndex=i:this.pendingMove={originalIndex:t,currentIndex:i,row:e},this.lastFocusCol=r;const s=this.grid,l=[...s._rows??this.sourceRows],[a]=l.splice(t,1);l.splice(i,0,a),s._rows=l,s._focusRow=i,s._focusCol=r,s.refreshVirtualWindow(!0),N(s),this.clearDebounceTimer(),this.debounceTimer=setTimeout(()=>{this.flushPendingMove()},this.config.debounceMs??300)}flushPendingMove(){if(this.clearDebounceTimer(),!this.pendingMove)return;const{originalIndex:e,currentIndex:t,row:i}=this.pendingMove;if(this.pendingMove=null,e===t)return;const n={row:i,fromIndex:e,toIndex:t,rows:[...this.sourceRows],source:"keyboard"};if(this.emitCancelable("row-move",n)){const s=[...this.sourceRows],[l]=s.splice(t,1);s.splice(e,0,l);const a=this.grid;a._rows=s,a._focusRow=e,a._focusCol=this.lastFocusCol,a.refreshVirtualWindow(!0),N(a)}}executeMove(e,t,i,n){const r=[...this.sourceRows],[s]=r.splice(t,1);r.splice(i,0,s);const l={row:e,fromIndex:t,toIndex:i,rows:r,source:n};this.emitCancelable("row-move",l)||(this.grid.rows=r)}getRowIndex(e){const t=e.querySelector(".cell[data-row]");return t?parseInt(t.getAttribute("data-row")??"-1",10):-1}clearDragClasses(){this.gridElement?.querySelectorAll(".data-grid-row").forEach(e=>{e.classList.remove("dragging","drop-target","drop-before","drop-after")})}clearDebounceTimer(){this.debounceTimer&&(clearTimeout(this.debounceTimer),this.debounceTimer=null)}}function ge(o){return{startRow:Math.min(o.startRow,o.endRow),startCol:Math.min(o.startCol,o.endCol),endRow:Math.max(o.startRow,o.endRow),endCol:Math.max(o.startCol,o.endCol)}}function hr(o){const e=ge(o);return{from:{row:e.startRow,col:e.startCol},to:{row:e.endRow,col:e.endCol}}}function ri(o){return o.map(hr)}function fr(o,e,t){const i=ge(t);return o>=i.startRow&&o<=i.endRow&&e>=i.startCol&&e<=i.endCol}function si(o,e,t){return t.some(i=>fr(o,e,i))}function gr(o){const e=[],t=ge(o);for(let i=t.startRow;i<=t.endRow;i++)for(let n=t.startCol;n<=t.endCol;n++)e.push({row:i,col:n});return e}function pr(o){const e=new Map;for(const t of o)for(const i of gr(t))e.set(`${i.row},${i.col}`,i);return[...e.values()]}function We(o,e){return{startRow:o.row,startCol:o.col,endRow:e.row,endCol:e.col}}const wr="@layer tbw-plugins{tbw-grid.selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}tbw-grid[data-has-focus] .data-grid-row.row-focus{background-color:var(--tbw-focus-background, rgba(from var(--tbw-color-accent) r g b / 12%))}tbw-grid[data-selection-mode=row] .cell-focus{outline:none}tbw-grid .data-grid-row>.cell.selected{background-color:var(--tbw-range-selection-bg)}tbw-grid .data-grid-row>.cell.selected.top{border-top:2px solid var(--tbw-range-border-color)}tbw-grid .data-grid-row>.cell.selected.bottom{border-bottom:2px solid var(--tbw-range-border-color)}tbw-grid .data-grid-row>.cell.selected.first{border-left:2px solid var(--tbw-range-border-color)}tbw-grid .data-grid-row>.cell.selected.last{border-right:2px solid var(--tbw-range-border-color)}tbw-grid .data-grid-row[data-selectable=false]{cursor:not-allowed;opacity:.6}tbw-grid .data-grid-row[data-selectable=false].row-focus{background-color:var(--tbw-color-row-alt)}tbw-grid .data-grid-row>.cell[data-selectable=false]{cursor:not-allowed;opacity:.6}tbw-grid .data-grid-row>.cell[data-selectable=false].selected{background-color:var(--tbw-color-warning-bg, rgba(255, 243, 205, .5))}tbw-grid .tbw-selection-summary{font-size:var(--tbw-font-size-sm, .8125rem);color:var(--tbw-color-fg-muted);white-space:nowrap}}";function mr(o,e,t){if(o==="cell"&&e.selectedCell)return{mode:o,ranges:[{from:{row:e.selectedCell.row,col:e.selectedCell.col},to:{row:e.selectedCell.row,col:e.selectedCell.col}}]};if(o==="row"&&e.selected.size>0){const i=[...e.selected].map(n=>({from:{row:n,col:0},to:{row:n,col:t-1}}));return{mode:o,ranges:i}}return o==="range"&&e.ranges.length>0?{mode:o,ranges:ri(e.ranges)}:{mode:o,ranges:[]}}class br extends L{static manifest={configRules:[{id:"selection/range-dblclick",severity:"warn",message:`"triggerOn: 'dblclick'" has no effect when mode is "range".
78
78
  → Range selection uses drag interaction (mousedown → mousemove), not click events.
79
- → The "triggerOn" option only affects "cell" and "row" selection modes.`,check:e=>e.mode==="range"&&e.triggerOn==="dblclick"}]};name="selection";styles=or;get defaultConfig(){return{mode:"cell",triggerOn:"click"}}selected=new Set;lastSelected=null;anchor=null;ranges=[];activeRange=null;cellAnchor=null;isDragging=!1;pendingKeyboardUpdate=null;selectedCell=null;detach(){this.selected.clear(),this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.isDragging=!1,this.selectedCell=null,this.pendingKeyboardUpdate=null}onCellClick(e){const{rowIndex:t,colIndex:i,originalEvent:o}=e,{mode:r,triggerOn:s="click"}=this.config;if(o.type!==s)return!1;const l=this.columns[i],a=l&&B(l);if(r==="cell")return a||(this.selectedCell={row:t,col:i},this.emit("selection-change",this.#n()),this.requestAfterRender()),!1;if(r==="row")return this.selected.clear(),this.selected.add(t),this.lastSelected=t,this.emit("selection-change",this.#n()),this.requestAfterRender(),!1;if(r==="range"){if(a)return!1;const c=o.shiftKey,d=o.ctrlKey||o.metaKey;if(c&&this.cellAnchor){const u=Ke(this.cellAnchor,{row:t,col:i});d?this.ranges.length>0?this.ranges[this.ranges.length-1]=u:this.ranges.push(u):this.ranges=[u],this.activeRange=u}else if(d){const u={startRow:t,startCol:i,endRow:t,endCol:i};this.ranges.push(u),this.activeRange=u,this.cellAnchor={row:t,col:i}}else{const u={startRow:t,startCol:i,endRow:t,endCol:i};this.ranges=[u],this.activeRange=u,this.cellAnchor={row:t,col:i}}return this.emit("selection-change",this.#n()),this.requestAfterRender(),!1}return!1}onKeyDown(e){const{mode:t}=this.config,o=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Tab","Home","End","PageUp","PageDown"].includes(e.key);if(e.key==="Escape")return t==="cell"?this.selectedCell=null:t==="row"?(this.selected.clear(),this.anchor=null):t==="range"&&(this.ranges=[],this.activeRange=null,this.cellAnchor=null),this.emit("selection-change",this.#n()),this.requestAfterRender(),!0;if(t==="cell"&&o)return queueMicrotask(()=>{this.selectedCell={row:this.grid._focusRow,col:this.grid._focusCol},this.emit("selection-change",this.#n()),this.requestAfterRender()}),!1;if(t==="row"&&(e.key==="ArrowUp"||e.key==="ArrowDown"))return queueMicrotask(()=>{this.selected.clear(),this.selected.add(this.grid._focusRow),this.lastSelected=this.grid._focusRow,this.emit("selection-change",this.#n()),this.requestAfterRender()}),!1;if(t==="range"&&o){const r=e.key==="Tab",s=e.shiftKey&&!r;return s&&!this.cellAnchor&&(this.cellAnchor={row:this.grid._focusRow,col:this.grid._focusCol}),this.pendingKeyboardUpdate={shiftKey:s},queueMicrotask(()=>this.requestAfterRender()),!1}if(t==="range"&&e.key==="a"&&(e.ctrlKey||e.metaKey)){const r=this.rows.length,s=this.columns.length;if(r>0&&s>0){const l={startRow:0,startCol:0,endRow:r-1,endCol:s-1};return this.ranges=[l],this.activeRange=l,this.emit("selection-change",this.#n()),this.requestAfterRender(),!0}}return!1}onCellMouseDown(e){if(this.config.mode!=="range"||e.rowIndex===void 0||e.colIndex===void 0||e.rowIndex<0)return;const t=this.columns[e.colIndex];if(t&&B(t)||e.originalEvent.shiftKey&&this.cellAnchor)return;this.isDragging=!0;const i=e.rowIndex,o=e.colIndex;this.cellAnchor={row:i,col:o},e.originalEvent.ctrlKey||e.originalEvent.metaKey||(this.ranges=[]);const s={startRow:i,startCol:o,endRow:i,endCol:o};return this.ranges.push(s),this.activeRange=s,this.emit("selection-change",this.#n()),this.requestAfterRender(),!0}onCellMouseMove(e){if(this.config.mode!=="range"||!this.isDragging||!this.cellAnchor||e.rowIndex===void 0||e.colIndex===void 0||e.rowIndex<0)return;let t=e.colIndex;const i=this.columns[t];if(i&&B(i)){const r=this.columns.findIndex(s=>!B(s));r>=0&&(t=r)}const o=Ke(this.cellAnchor,{row:e.rowIndex,col:t});return this.ranges.length>0?this.ranges[this.ranges.length-1]=o:this.ranges.push(o),this.activeRange=o,this.emit("selection-change",this.#n()),this.requestAfterRender(),!0}onCellMouseUp(e){if(this.config.mode==="range"&&this.isDragging)return this.isDragging=!1,!0}#e(){const e=this.gridElement;if(!e)return;const{mode:t}=this.config;e.querySelectorAll(".cell").forEach(r=>{r.classList.remove("selected","top","bottom","first","last")});const o=e.querySelectorAll(".data-grid-row");if(o.forEach(r=>{r.classList.remove("selected","row-focus")}),t==="row"&&(ne(e),o.forEach(r=>{const s=r.querySelector(".cell[data-row]"),l=me(s);l>=0&&this.selected.has(l)&&r.classList.add("selected","row-focus")})),t==="range"&&this.ranges.length>0){ne(e);const r=this.activeRange?ge(this.activeRange):null,s=this.columns.findIndex(a=>!B(a));this.columns.length-1,e.querySelectorAll(".cell[data-row][data-col]").forEach(a=>{const c=parseInt(a.getAttribute("data-row")??"-1",10),d=parseInt(a.getAttribute("data-col")??"-1",10);if(c>=0&&d>=0){const u=this.columns[d];if(u&&B(u))return;if(ii(c,d,this.ranges)&&(a.classList.add("selected"),r)){c===r.startRow&&a.classList.add("top"),c===r.endRow&&a.classList.add("bottom");const g=Math.max(r.startCol,s);d===g&&a.classList.add("first"),d===r.endCol&&a.classList.add("last")}}})}}afterRender(){const e=this.gridElement;if(!e)return;const t=e.children[0],{mode:i}=this.config;if(this.pendingKeyboardUpdate&&i==="range"){const{shiftKey:o}=this.pendingKeyboardUpdate;this.pendingKeyboardUpdate=null;const r=this.grid._focusRow,s=this.grid._focusCol;if(o&&this.cellAnchor){const l=Ke(this.cellAnchor,{row:r,col:s});this.ranges=[l],this.activeRange=l}else o||(this.ranges=[],this.activeRange=null,this.cellAnchor={row:r,col:s});this.emit("selection-change",this.#n())}this.grid.setAttribute("data-selection-mode",i),t&&t.classList.toggle("selecting",this.isDragging),this.#e()}onScrollRender(){this.#e()}getSelection(){return{mode:this.config.mode,ranges:this.#n().ranges,anchor:this.cellAnchor}}getSelectedCells(){return nr(this.ranges)}isCellSelected(e,t){return ii(e,t,this.ranges)}clearSelection(){this.selectedCell=null,this.selected.clear(),this.anchor=null,this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.emit("selection-change",{mode:this.config.mode,ranges:[]}),this.requestAfterRender()}setRanges(e){this.ranges=e.map(t=>({startRow:t.from.row,startCol:t.from.col,endRow:t.to.row,endCol:t.to.col})),this.activeRange=this.ranges.length>0?this.ranges[this.ranges.length-1]:null,this.emit("selection-change",{mode:this.config.mode,ranges:ti(this.ranges)}),this.requestAfterRender()}#n(){return rr(this.config.mode,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges},this.columns.length)}}function pe(n,e){return Math.floor(n/e)}function lr(n,e){return{start:n*e,end:(n+1)*e}}function ar(n,e,t){const i=pe(n,t),o=pe(e-1,t),r=[];for(let s=i;s<=o;s++)r.push(s);return r}async function ni(n,e,t,i){const o=lr(e,t);return n.getRows({startRow:o.start,endRow:o.end,sortModel:i.sortModel,filterModel:i.filterModel})}function cr(n,e,t){const i=pe(n,e),o=t.get(i);if(!o)return;const r=n%e;return o[r]}const dr=100;class ur extends P{name="serverSide";get defaultConfig(){return{pageSize:100,cacheBlockSize:100,maxConcurrentRequests:2}}dataSource=null;totalRowCount=0;loadedBlocks=new Map;loadingBlocks=new Set;lastRequestId=0;scrollDebounceTimer;detach(){this.dataSource=null,this.totalRowCount=0,this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.lastRequestId=0,this.scrollDebounceTimer&&(clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=void 0)}loadRequiredBlocks(){if(!this.dataSource)return;const e=this.grid,t=this.config.cacheBlockSize??100,i={startRow:e._virtualization.start,endRow:e._virtualization.end},o=ar(i.startRow,i.endRow,t);for(const r of o)if(!(this.loadedBlocks.has(r)||this.loadingBlocks.has(r))){if(this.loadingBlocks.size>=(this.config.maxConcurrentRequests??2))break;this.loadingBlocks.add(r),ni(this.dataSource,r,t,{}).then(s=>{this.loadedBlocks.set(r,s.rows),this.totalRowCount=s.totalRowCount,this.loadingBlocks.delete(r),this.requestRender(),this.loadRequiredBlocks()}).catch(()=>{this.loadingBlocks.delete(r)})}}processRows(e){if(!this.dataSource)return[...e];const t=[];for(let i=0;i<this.totalRowCount;i++){const o=cr(i,this.config.cacheBlockSize??100,this.loadedBlocks);t.push(o??{__loading:!0,__index:i})}return t}onScroll(e){this.dataSource&&(this.loadRequiredBlocks(),this.scrollDebounceTimer&&clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=setTimeout(()=>{this.loadRequiredBlocks()},dr))}setDataSource(e){this.dataSource=e,this.loadedBlocks.clear(),this.loadingBlocks.clear();const t=this.config.cacheBlockSize??100;ni(e,0,t,{}).then(i=>{this.loadedBlocks.set(0,i.rows),this.totalRowCount=i.totalRowCount,this.requestRender()})}refresh(){this.dataSource&&(this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.requestRender())}purgeCache(){this.loadedBlocks.clear()}getTotalRowCount(){return this.totalRowCount}isRowLoaded(e){const t=this.config.cacheBlockSize??100,i=pe(e,t);return this.loadedBlocks.has(i)}getLoadedBlockCount(){return this.loadedBlocks.size}}function oi(n,e,t){return n.id!==void 0?String(n.id):t?`${t}-${e}`:String(e)}function Be(n,e){const t=new Set(n);return t.has(e)?t.delete(e):t.add(e),t}function Ve(n,e,t=null,i=0){const o=e.childrenField??"children",r=new Set;for(let s=0;s<n.length;s++){const l=n[s],a=oi(l,s,t),c=l[o];if(Array.isArray(c)&&c.length>0){r.add(a);const d=Ve(c,e,a,i+1);for(const u of d)r.add(u)}}return r}function hr(){return new Set}function ri(n,e,t,i=null,o=0){const r=t.childrenField??"children";for(let s=0;s<n.length;s++){const l=n[s],a=oi(l,s,i);if(a===e)return[a];const c=l[r];if(Array.isArray(c)&&c.length>0){const d=ri(c,e,t,a,o+1);if(d)return[a,...d]}}return null}function fr(n,e,t,i){const o=ri(n,e,t);if(!o)return i;const r=new Set(i);for(let s=0;s<o.length-1;s++)r.add(o[s]);return r}function si(n,e="children"){if(!Array.isArray(n)||n.length===0)return!1;for(const t of n){if(!t)continue;const i=t[e];if(Array.isArray(i)&&i.length>0)return!0}return!1}function gr(n){if(!Array.isArray(n)||n.length===0)return null;const e=["children","items","nodes","subRows","nested"];for(const t of n)if(!(!t||typeof t!="object"))for(const i of e){const o=t[i];if(Array.isArray(o)&&o.length>0)return i}return null}const pr="@layer tbw-plugins{tbw-grid .cell[data-field=__tbw_expander]{border-right:none!important;padding:0;display:flex;align-items:center;justify-content:flex-start}tbw-grid .header-row .cell[data-field=__tbw_expander]{display:none}tbw-grid .header-row .cell[data-field=__tbw_expander]+.cell{grid-column:1 / 3}tbw-grid .tree-cell-wrapper{display:inline-flex;align-items:center;padding-left:calc(var(--tbw-tree-depth, 0) * var(--tbw-tree-indent-width, var(--tbw-tree-toggle-size, 1.25em)))}tbw-grid .tree-expander{display:flex;align-items:center;justify-content:flex-start;width:100%;height:100%;box-sizing:border-box}tbw-grid .tree-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-tree-toggle-size, 1.25em);height:var(--tbw-tree-toggle-size, 1.25em);flex-shrink:0}tbw-grid .tree-toggle:hover{color:var(--tbw-tree-accent, var(--tbw-color-accent))}tbw-grid .tree-spacer{width:var(--tbw-tree-toggle-size, 1.25em);display:inline-block;flex-shrink:0}tbw-grid .data-grid-row.tbw-tree-slide-in{animation:tbw-tree-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}tbw-grid .data-grid-row.tbw-tree-fade-in{animation:tbw-tree-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-tree-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}@keyframes tbw-tree-fade-in{0%{opacity:0}to{opacity:1}}}";class wr extends P{name="tree";styles=pr;get defaultConfig(){return{childrenField:"children",autoDetect:!0,defaultExpanded:!1,indentWidth:20,showExpandIcons:!0,animation:"slide"}}expandedKeys=new Set;initialExpansionDone=!1;flattenedRows=[];rowKeyMap=new Map;previousVisibleKeys=new Set;keysToAnimate=new Set;sortState=null;detach(){this.expandedKeys.clear(),this.initialExpansionDone=!1,this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.sortState=null}get animationStyle(){return this.isAnimationEnabled?this.config.animation??"slide":!1}detect(e){if(!this.config.autoDetect)return!1;const t=e,i=this.config.childrenField??gr(t)??"children";return si(t,i)}processRows(e){const t=this.config.childrenField??"children",i=e;if(!si(i,t))return this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),[...e];let o=this.withStableKeys(i);this.sortState&&(o=this.sortTree(o,this.sortState.field,this.sortState.direction)),this.config.defaultExpanded&&!this.initialExpansionDone&&(this.expandedKeys=Ve(o,this.config),this.initialExpansionDone=!0),this.flattenedRows=this.flattenTree(o,this.expandedKeys),this.rowKeyMap.clear(),this.keysToAnimate.clear();const r=new Set;for(const s of this.flattenedRows)this.rowKeyMap.set(s.key,s),r.add(s.key),!this.previousVisibleKeys.has(s.key)&&s.depth>0&&this.keysToAnimate.add(s.key);return this.previousVisibleKeys=r,this.flattenedRows.map(s=>({...s.data,__treeKey:s.key,__treeDepth:s.depth,__treeHasChildren:s.hasChildren,__treeExpanded:s.isExpanded}))}withStableKeys(e,t=null){const i=this.config.childrenField??"children";return e.map((o,r)=>{const s=o.__stableKey,l=o.id!==void 0?String(o.id):s??(t?`${t}-${r}`:String(r)),a=o[i],c=Array.isArray(a)&&a.length>0;return{...o,__stableKey:l,...c?{[i]:this.withStableKeys(a,l)}:{}}})}flattenTree(e,t,i=0){const o=this.config.childrenField??"children",r=[];for(const s of e){const a=s.__stableKey??String(s.id??"?"),c=s[o],d=Array.isArray(c)&&c.length>0,u=t.has(a);r.push({key:a,data:s,depth:i,hasChildren:d,isExpanded:u,parentKey:i>0&&a.substring(0,a.lastIndexOf("-"))||null}),d&&u&&r.push(...this.flattenTree(c,t,i+1))}return r}sortTree(e,t,i){const o=this.config.childrenField??"children";return[...e].sort((s,l)=>{const a=s[t],c=l[t];return a==null&&c==null?0:a==null?-1:c==null?1:a>c?i:a<c?-i:0}).map(s=>{const l=s[o];return Array.isArray(l)&&l.length>0?{...s,[o]:this.sortTree(l,t,i)}:s})}processColumns(e){if(this.flattenedRows.length===0)return[...e];const t=[...e];if(t.length===0)return t;const i=t[0],o=i.viewRenderer,r=()=>this.config,s=this.setIcon.bind(this),l=this.resolveIcon.bind(this),a=c=>{const{row:d,value:u}=c,{showExpandIcons:h=!0,indentWidth:g}=r(),f=d,p=f.__treeDepth??0,w=document.createElement("span");if(w.className="tree-cell-wrapper",w.style.setProperty("--tbw-tree-depth",String(p)),g!==void 0&&w.style.setProperty("--tbw-tree-indent-width",`${g}px`),h)if(f.__treeHasChildren){const C=document.createElement("span");C.className=`tree-toggle${f.__treeExpanded?" expanded":""}`,s(C,l(f.__treeExpanded?"collapse":"expand")),C.setAttribute("data-tree-key",String(f.__treeKey??"")),w.appendChild(C)}else{const C=document.createElement("span");C.className="tree-spacer",w.appendChild(C)}const m=document.createElement("span");if(m.className="tree-content",o){const C=o(c);C instanceof Node?m.appendChild(C):typeof C=="string"&&(m.innerHTML=C)}else m.textContent=u!=null?String(u):"";return w.appendChild(m),w};return t[0]={...i,viewRenderer:a},t}onCellClick(e){const t=e.originalEvent?.target;if(!t?.classList.contains("tree-toggle"))return!1;const i=t.getAttribute("data-tree-key");if(!i)return!1;const o=this.rowKeyMap.get(i);return o?(this.expandedKeys=Be(this.expandedKeys,i),this.emit("tree-expand",{key:i,row:o.data,expanded:this.expandedKeys.has(i),depth:o.depth}),this.requestRender(),!0):!1}onKeyDown(e){if(e.key!==" ")return;const t=this.grid._focusRow,i=this.flattenedRows[t];if(i?.hasChildren)return e.preventDefault(),this.expandedKeys=Be(this.expandedKeys,i.key),this.emit("tree-expand",{key:i.key,row:i.data,expanded:this.expandedKeys.has(i.key),depth:i.depth}),this.requestRenderWithFocus(),!0}onHeaderClick(e){if(this.flattenedRows.length===0||!e.column.sortable)return!1;const{field:t}=e.column;!this.sortState||this.sortState.field!==t?this.sortState={field:t,direction:1}:this.sortState.direction===1?this.sortState={field:t,direction:-1}:this.sortState=null;const i=this.grid;return i._sortState!==void 0&&(i._sortState=this.sortState?{...this.sortState}:null),this.emit("sort-change",{field:t,direction:this.sortState?.direction??0}),this.requestRender(),!0}afterRender(){const e=this.animationStyle;if(e===!1||this.keysToAnimate.size===0)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const i=e==="fade"?"tbw-tree-fade-in":"tbw-tree-slide-in";for(const o of t.querySelectorAll(".data-grid-row")){const r=o.querySelector(".cell[data-row]"),s=r?parseInt(r.getAttribute("data-row")??"-1",10):-1,l=this.flattenedRows[s]?.key;l&&this.keysToAnimate.has(l)&&(o.classList.add(i),o.addEventListener("animationend",()=>o.classList.remove(i),{once:!0}))}this.keysToAnimate.clear()}expand(e){this.expandedKeys.add(e),this.requestRender()}collapse(e){this.expandedKeys.delete(e),this.requestRender()}toggle(e){this.expandedKeys=Be(this.expandedKeys,e),this.requestRender()}expandAll(){this.expandedKeys=Ve(this.rows,this.config),this.requestRender()}collapseAll(){this.expandedKeys=hr(),this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}getExpandedKeys(){return[...this.expandedKeys]}getFlattenedRows(){return[...this.flattenedRows]}getRowByKey(e){return this.rowKeyMap.get(e)?.data}expandToKey(e){this.expandedKeys=fr(this.rows,e,this.config,this.expandedKeys),this.requestRender()}}function mr(n,e,t){const i=[...n.undoStack,e];for(;i.length>t;)i.shift();return{undoStack:i,redoStack:[]}}function li(n){if(n.undoStack.length===0)return{newState:n,action:null};const e=[...n.undoStack],t=e.pop();return t?{newState:{undoStack:e,redoStack:[...n.redoStack,t]},action:t}:{newState:n,action:null}}function ai(n){if(n.redoStack.length===0)return{newState:n,action:null};const e=[...n.redoStack],t=e.pop();return t?{newState:{undoStack:[...n.undoStack,t],redoStack:e},action:t}:{newState:n,action:null}}function br(n){return n.undoStack.length>0}function vr(n){return n.redoStack.length>0}function yr(){return{undoStack:[],redoStack:[]}}function Cr(n,e,t,i){return{type:"cell-edit",rowIndex:n,field:e,oldValue:t,newValue:i,timestamp:Date.now()}}class xr extends P{static dependencies=[{name:"editing",required:!0,reason:"UndoRedoPlugin tracks cell edit history"}];name="undoRedo";get defaultConfig(){return{maxHistorySize:100}}undoStack=[];redoStack=[];detach(){this.undoStack=[],this.redoStack=[]}onKeyDown(e){const t=(e.ctrlKey||e.metaKey)&&e.key==="z"&&!e.shiftKey,i=(e.ctrlKey||e.metaKey)&&(e.key==="y"||e.key==="z"&&e.shiftKey);if(t){const o=li({undoStack:this.undoStack,redoStack:this.redoStack});if(o.action){const r=this.rows;r[o.action.rowIndex]&&(r[o.action.rowIndex][o.action.field]=o.action.oldValue),this.undoStack=o.newState.undoStack,this.redoStack=o.newState.redoStack,this.emit("undo",{action:o.action,type:"undo"}),this.requestRender()}return!0}if(i){const o=ai({undoStack:this.undoStack,redoStack:this.redoStack});if(o.action){const r=this.rows;r[o.action.rowIndex]&&(r[o.action.rowIndex][o.action.field]=o.action.newValue),this.undoStack=o.newState.undoStack,this.redoStack=o.newState.redoStack,this.emit("redo",{action:o.action,type:"redo"}),this.requestRender()}return!0}return!1}recordEdit(e,t,i,o){const r=Cr(e,t,i,o),s=mr({undoStack:this.undoStack,redoStack:this.redoStack},r,this.config.maxHistorySize??100);this.undoStack=s.undoStack,this.redoStack=s.redoStack}undo(){const e=li({undoStack:this.undoStack,redoStack:this.redoStack});if(e.action){const t=this.rows;t[e.action.rowIndex]&&(t[e.action.rowIndex][e.action.field]=e.action.oldValue),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.requestRender()}return e.action}redo(){const e=ai({undoStack:this.undoStack,redoStack:this.redoStack});if(e.action){const t=this.rows;t[e.action.rowIndex]&&(t[e.action.rowIndex][e.action.field]=e.action.newValue),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.requestRender()}return e.action}canUndo(){return br({undoStack:this.undoStack,redoStack:this.redoStack})}canRedo(){return vr({undoStack:this.undoStack,redoStack:this.redoStack})}clearHistory(){const e=yr();this.undoStack=e.undoStack,this.redoStack=e.redoStack}getUndoStack(){return[...this.undoStack]}getRedoStack(){return[...this.redoStack]}}const Er='@layer tbw-plugins{.tbw-visibility-content{display:flex;flex-direction:column;height:100%}.tbw-visibility-list{flex:1;overflow-y:auto;padding:var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem))}.tbw-visibility-row{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding:var(--tbw-menu-item-padding, .375rem .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem);border-radius:var(--tbw-border-radius, .25rem);position:relative}.tbw-visibility-row:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover, #f3f4f6))}.tbw-visibility-row input[type=checkbox]{cursor:pointer}.tbw-visibility-row.locked span{color:var(--tbw-color-fg-muted, #888)}.tbw-visibility-handle{cursor:grab;color:var(--tbw-color-fg-muted, #888);font-size:var(--tbw-font-size-2xs, .625rem);letter-spacing:-2px;-webkit-user-select:none;user-select:none;flex-shrink:0}.tbw-visibility-row.reorderable:hover .tbw-visibility-handle{color:var(--tbw-color-fg, #1f2937)}.tbw-visibility-label{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));flex:1;cursor:pointer}.tbw-visibility-row.dragging{opacity:.5;cursor:grabbing}.tbw-visibility-row.drop-before:before{content:"";position:absolute;left:0;right:0;top:0;height:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent, #3b82f6))}.tbw-visibility-row.drop-after:after{content:"";position:absolute;left:0;right:0;bottom:0;height:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent, #3b82f6))}.tbw-visibility-show-all{margin:var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem));padding:var(--tbw-button-padding, .5rem .75rem);border:1px solid var(--tbw-visibility-border, var(--tbw-color-border, #e5e7eb));border-radius:var(--tbw-border-radius, .25rem);background:var(--tbw-visibility-btn-bg, var(--tbw-color-header-bg, #f9fafb));color:var(--tbw-color-fg, #1f2937);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem)}.tbw-visibility-show-all:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover, #f3f4f6))}}';function ci(n){const e=n.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}class U extends P{static dependencies=[{name:"reorder",required:!1,reason:"Enables drag-to-reorder columns in visibility panel"}];name="visibility";static PANEL_ID="columns";styles=Er;get defaultConfig(){return{allowHideAll:!1}}columnListElement=null;isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;clearDragClasses(e){e.querySelectorAll(".tbw-visibility-row").forEach(t=>{t.classList.remove("dragging","drop-target","drop-before","drop-after")})}detach(){this.columnListElement=null,this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null}getToolPanel(){return{id:U.PANEL_ID,title:"Columns",icon:"☰",tooltip:"Column visibility",order:100,render:e=>this.renderPanelContent(e)}}show(){this.grid.openToolPanel(),this.grid.expandedToolPanelSections.includes(U.PANEL_ID)||this.grid.toggleToolPanelSection(U.PANEL_ID)}hide(){this.grid.closeToolPanel()}toggle(){this.grid.isToolPanelOpen||this.grid.openToolPanel(),this.grid.toggleToolPanelSection(U.PANEL_ID)}isColumnVisible(e){return this.grid.isColumnVisible(e)}setColumnVisible(e,t){this.grid.setColumnVisible(e,t)}getVisibleColumns(){return this.grid.getAllColumns().filter(e=>e.visible).map(e=>e.field)}getHiddenColumns(){return this.grid.getAllColumns().filter(e=>!e.visible).map(e=>e.field)}showAll(){this.grid.showAllColumns()}toggleColumn(e){this.grid.toggleColumnVisibility(e)}showColumn(e){this.setColumnVisible(e,!0)}hideColumn(e){this.setColumnVisible(e,!1)}getAllColumns(){return this.grid.getAllColumns()}isPanelVisible(){return this.grid.isToolPanelOpen&&this.grid.expandedToolPanelSections.includes(U.PANEL_ID)}renderPanelContent(e){const t=document.createElement("div");t.className="tbw-visibility-content";const i=document.createElement("div");i.className="tbw-visibility-list",t.appendChild(i);const o=document.createElement("button");return o.className="tbw-visibility-show-all",o.textContent="Show All",o.addEventListener("click",()=>{this.grid.showAllColumns(),this.rebuildToggles(i)}),t.appendChild(o),this.columnListElement=i,this.rebuildToggles(i),e.appendChild(t),()=>{this.columnListElement=null,t.remove()}}hasReorderPlugin(){const e=this.grid?.getPluginByName?.("reorder");return!!(e&&typeof e.moveColumn=="function")}rebuildToggles(e){const t=this.hasReorderPlugin();e.innerHTML="";const i=this.grid.getAllColumns().filter(o=>!o.utility);for(let o=0;o<i.length;o++){const r=i[o],s=r.header||r.field,l=document.createElement("div");l.className=r.lockVisible?"tbw-visibility-row locked":"tbw-visibility-row",l.setAttribute("data-field",r.field),l.setAttribute("data-index",String(o)),t&&ci(r)&&(l.draggable=!0,l.classList.add("reorderable"),this.setupDragListeners(l,r.field,o,e));const a=document.createElement("label");a.className="tbw-visibility-label";const c=document.createElement("input");c.type="checkbox",c.checked=r.visible,c.disabled=r.lockVisible??!1,c.addEventListener("change",()=>{this.grid.toggleColumnVisibility(r.field),setTimeout(()=>this.rebuildToggles(e),0)});const d=document.createElement("span");if(d.textContent=s,a.appendChild(c),a.appendChild(d),t&&ci(r)){const u=document.createElement("span");u.className="tbw-visibility-handle",this.setIcon(u,this.resolveIcon("dragHandle")),u.title="Drag to reorder",l.appendChild(u)}l.appendChild(a),e.appendChild(l)}}setupDragListeners(e,t,i,o){e.addEventListener("dragstart",r=>{this.isDragging=!0,this.draggedField=t,this.draggedIndex=i,r.dataTransfer&&(r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",t)),e.classList.add("dragging")}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.clearDragClasses(o)}),e.addEventListener("dragover",r=>{if(r.preventDefault(),!this.isDragging||this.draggedField===t)return;const s=e.getBoundingClientRect(),l=s.top+s.height/2;this.dropIndex=r.clientY<l?i:i+1,o.querySelectorAll(".tbw-visibility-row").forEach(a=>{a!==e&&a.classList.remove("drop-target","drop-before","drop-after")}),e.classList.add("drop-target"),e.classList.toggle("drop-before",r.clientY<l),e.classList.toggle("drop-after",r.clientY>=l)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",r=>{r.preventDefault();const s=this.draggedField,l=this.draggedIndex,a=this.dropIndex;if(!this.isDragging||s===null||l===null||a===null)return;const c=a>l?a-1:a;if(c!==l){const d=this.grid.getAllColumns(),h=d.filter(p=>!p.utility)[c]?.field,g=h?d.findIndex(p=>p.field===h):d.length,f={field:s,fromIndex:l,toIndex:g};this.emit("column-reorder-request",f),setTimeout(()=>{this.rebuildToggles(o)},0)}})}}x.BaseGridPlugin=P,x.ClipboardPlugin=xn,x.ColumnVirtualizationPlugin=_n,x.ContextMenuPlugin=Tn,x.DEFAULT_ANIMATION_CONFIG=We,x.DEFAULT_GRID_ICONS=q,x.DGEvents=wn,x.DataGridElement=D,x.EditingPlugin=Fn,x.ExportPlugin=Wn,x.FilteringPlugin=z,x.FitModeEnum=Y,x.GridCSSVars=fn,x.GridClasses=I,x.GridDataAttrs=re,x.GridElement=D,x.GridSelectors=hn,x.GroupingColumnsPlugin=no,x.GroupingRowsPlugin=ho,x.MasterDetailPlugin=Ne,x.MultiSortPlugin=xo,x.PLUGIN_QUERIES=Se,x.PinnedColumnsPlugin=So,x.PinnedRowsPlugin=ko,x.PivotPlugin=$,x.PluginEvents=mn,x.PluginManager=Rt,x.RenderPhase=L,x.ReorderPlugin=Zo,x.ResponsivePlugin=Qo,x.SelectionPlugin=sr,x.ServerSidePlugin=ur,x.TreePlugin=wr,x.UndoRedoPlugin=xr,x.VisibilityPlugin=U,x.builtInSort=rt,x.createGrid=gn,x.defaultComparator=ot,x.defaultEditorFor=Dt,x.defaultPasteHandler=At,x.queryGrid=pn,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})}));
79
+ → The "triggerOn" option only affects "cell" and "row" selection modes.`,check:e=>e.mode==="range"&&e.triggerOn==="dblclick"}]};name="selection";styles=wr;get defaultConfig(){return{mode:"cell",triggerOn:"click"}}selected=new Set;lastSelected=null;anchor=null;ranges=[];activeRange=null;cellAnchor=null;isDragging=!1;pendingKeyboardUpdate=null;selectedCell=null;checkSelectable(e,t){const{isSelectable:i}=this.config;if(!i)return!0;const n=this.rows[e];if(!n)return!1;const r=t!==void 0?this.columns[t]:void 0;return i(n,e,r,t)}isRowSelectable(e){return this.checkSelectable(e)}isCellSelectable(e,t){return this.checkSelectable(e,t)}detach(){this.selected.clear(),this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.isDragging=!1,this.selectedCell=null,this.pendingKeyboardUpdate=null}onCellClick(e){const{rowIndex:t,colIndex:i,originalEvent:n}=e,{mode:r,triggerOn:s="click"}=this.config;if(n.type!==s)return!1;const l=this.columns[i],a=l&&B(l);if(r==="cell")return a||!this.isCellSelectable(t,i)||(this.selectedCell={row:t,col:i},this.emit("selection-change",this.#o()),this.requestAfterRender()),!1;if(r==="row")return this.isRowSelectable(t)&&(this.selected.clear(),this.selected.add(t),this.lastSelected=t,this.emit("selection-change",this.#o()),this.requestAfterRender()),!1;if(r==="range"){if(a||!this.isCellSelectable(t,i))return!1;const c=n.shiftKey,d=n.ctrlKey||n.metaKey;if(c&&this.cellAnchor){const u=We(this.cellAnchor,{row:t,col:i});d?this.ranges.length>0?this.ranges[this.ranges.length-1]=u:this.ranges.push(u):this.ranges=[u],this.activeRange=u}else if(d){const u={startRow:t,startCol:i,endRow:t,endCol:i};this.ranges.push(u),this.activeRange=u,this.cellAnchor={row:t,col:i}}else{const u={startRow:t,startCol:i,endRow:t,endCol:i};this.ranges=[u],this.activeRange=u,this.cellAnchor={row:t,col:i}}return this.emit("selection-change",this.#o()),this.requestAfterRender(),!1}return!1}onKeyDown(e){const{mode:t}=this.config,n=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Tab","Home","End","PageUp","PageDown"].includes(e.key);if(e.key==="Escape")return t==="cell"?this.selectedCell=null:t==="row"?(this.selected.clear(),this.anchor=null):t==="range"&&(this.ranges=[],this.activeRange=null,this.cellAnchor=null),this.emit("selection-change",this.#o()),this.requestAfterRender(),!0;if(t==="cell"&&n)return queueMicrotask(()=>{const r=this.grid._focusRow,s=this.grid._focusCol;this.isCellSelectable(r,s)?this.selectedCell={row:r,col:s}:this.selectedCell=null,this.emit("selection-change",this.#o()),this.requestAfterRender()}),!1;if(t==="row"&&(e.key==="ArrowUp"||e.key==="ArrowDown"))return queueMicrotask(()=>{const r=this.grid._focusRow;this.isRowSelectable(r)?(this.selected.clear(),this.selected.add(r),this.lastSelected=r):this.selected.clear(),this.emit("selection-change",this.#o()),this.requestAfterRender()}),!1;if(t==="range"&&n){const r=e.key==="Tab",s=e.shiftKey&&!r;return s&&!this.cellAnchor&&(this.cellAnchor={row:this.grid._focusRow,col:this.grid._focusCol}),this.pendingKeyboardUpdate={shiftKey:s},queueMicrotask(()=>this.requestAfterRender()),!1}if(t==="range"&&e.key==="a"&&(e.ctrlKey||e.metaKey)){const r=this.rows.length,s=this.columns.length;if(r>0&&s>0){const l={startRow:0,startCol:0,endRow:r-1,endCol:s-1};return this.ranges=[l],this.activeRange=l,this.emit("selection-change",this.#o()),this.requestAfterRender(),!0}}return!1}onCellMouseDown(e){if(this.config.mode!=="range"||e.rowIndex===void 0||e.colIndex===void 0||e.rowIndex<0)return;const t=this.columns[e.colIndex];if(t&&B(t)||!this.isCellSelectable(e.rowIndex,e.colIndex)||e.originalEvent.shiftKey&&this.cellAnchor)return;this.isDragging=!0;const i=e.rowIndex,n=e.colIndex;this.cellAnchor={row:i,col:n},e.originalEvent.ctrlKey||e.originalEvent.metaKey||(this.ranges=[]);const s={startRow:i,startCol:n,endRow:i,endCol:n};return this.ranges.push(s),this.activeRange=s,this.emit("selection-change",this.#o()),this.requestAfterRender(),!0}onCellMouseMove(e){if(this.config.mode!=="range"||!this.isDragging||!this.cellAnchor||e.rowIndex===void 0||e.colIndex===void 0||e.rowIndex<0)return;let t=e.colIndex;const i=this.columns[t];if(i&&B(i)){const r=this.columns.findIndex(s=>!B(s));r>=0&&(t=r)}const n=We(this.cellAnchor,{row:e.rowIndex,col:t});return this.ranges.length>0?this.ranges[this.ranges.length-1]=n:this.ranges.push(n),this.activeRange=n,this.emit("selection-change",this.#o()),this.requestAfterRender(),!0}onCellMouseUp(e){if(this.config.mode==="range"&&this.isDragging)return this.isDragging=!1,!0}#e(){const e=this.gridElement;if(!e)return;const{mode:t}=this.config,i=!!this.config.isSelectable;e.querySelectorAll(".cell").forEach(s=>{s.classList.remove("selected","top","bottom","first","last"),i&&s.removeAttribute("data-selectable")});const r=e.querySelectorAll(".data-grid-row");if(r.forEach(s=>{s.classList.remove("selected","row-focus"),i&&s.removeAttribute("data-selectable")}),t==="row"&&(oe(e),r.forEach(s=>{const l=s.querySelector(".cell[data-row]"),a=me(l);a>=0&&(i&&!this.isRowSelectable(a)&&s.setAttribute("data-selectable","false"),this.selected.has(a)&&s.classList.add("selected","row-focus"))})),(t==="cell"||t==="range")&&i&&e.querySelectorAll(".cell[data-row][data-col]").forEach(l=>{const a=parseInt(l.getAttribute("data-row")??"-1",10),c=parseInt(l.getAttribute("data-col")??"-1",10);a>=0&&c>=0&&(this.isCellSelectable(a,c)||l.setAttribute("data-selectable","false"))}),t==="range"&&this.ranges.length>0){oe(e);const s=this.activeRange?ge(this.activeRange):null,l=this.columns.findIndex(c=>!B(c));this.columns.length-1,e.querySelectorAll(".cell[data-row][data-col]").forEach(c=>{const d=parseInt(c.getAttribute("data-row")??"-1",10),u=parseInt(c.getAttribute("data-col")??"-1",10);if(d>=0&&u>=0){const h=this.columns[u];if(h&&B(h))return;if(si(d,u,this.ranges)&&(c.classList.add("selected"),s)){d===s.startRow&&c.classList.add("top"),d===s.endRow&&c.classList.add("bottom");const p=Math.max(s.startCol,l);u===p&&c.classList.add("first"),u===s.endCol&&c.classList.add("last")}}})}}afterRender(){const e=this.gridElement;if(!e)return;const t=e.children[0],{mode:i}=this.config;if(this.pendingKeyboardUpdate&&i==="range"){const{shiftKey:n}=this.pendingKeyboardUpdate;this.pendingKeyboardUpdate=null;const r=this.grid._focusRow,s=this.grid._focusCol;if(n&&this.cellAnchor){const l=We(this.cellAnchor,{row:r,col:s});this.ranges=[l],this.activeRange=l}else n||(this.ranges=[],this.activeRange=null,this.cellAnchor={row:r,col:s});this.emit("selection-change",this.#o())}this.grid.setAttribute("data-selection-mode",i),t&&t.classList.toggle("selecting",this.isDragging),this.#e()}onScrollRender(){this.#e()}getSelection(){return{mode:this.config.mode,ranges:this.#o().ranges,anchor:this.cellAnchor}}getSelectedCells(){return pr(this.ranges)}isCellSelected(e,t){return si(e,t,this.ranges)}clearSelection(){this.selectedCell=null,this.selected.clear(),this.anchor=null,this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.emit("selection-change",{mode:this.config.mode,ranges:[]}),this.requestAfterRender()}setRanges(e){this.ranges=e.map(t=>({startRow:t.from.row,startCol:t.from.col,endRow:t.to.row,endCol:t.to.col})),this.activeRange=this.ranges.length>0?this.ranges[this.ranges.length-1]:null,this.emit("selection-change",{mode:this.config.mode,ranges:ri(this.ranges)}),this.requestAfterRender()}#o(){return mr(this.config.mode,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges},this.columns.length)}}function pe(o,e){return Math.floor(o/e)}function vr(o,e){return{start:o*e,end:(o+1)*e}}function yr(o,e,t){const i=pe(o,t),n=pe(e-1,t),r=[];for(let s=i;s<=n;s++)r.push(s);return r}async function li(o,e,t,i){const n=vr(e,t);return o.getRows({startRow:n.start,endRow:n.end,sortModel:i.sortModel,filterModel:i.filterModel})}function Cr(o,e,t){const i=pe(o,e),n=t.get(i);if(!n)return;const r=o%e;return n[r]}const xr=100;class Rr extends L{name="serverSide";get defaultConfig(){return{pageSize:100,cacheBlockSize:100,maxConcurrentRequests:2}}dataSource=null;totalRowCount=0;loadedBlocks=new Map;loadingBlocks=new Set;lastRequestId=0;scrollDebounceTimer;detach(){this.dataSource=null,this.totalRowCount=0,this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.lastRequestId=0,this.scrollDebounceTimer&&(clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=void 0)}loadRequiredBlocks(){if(!this.dataSource)return;const e=this.grid,t=this.config.cacheBlockSize??100,i={startRow:e._virtualization.start,endRow:e._virtualization.end},n=yr(i.startRow,i.endRow,t);for(const r of n)if(!(this.loadedBlocks.has(r)||this.loadingBlocks.has(r))){if(this.loadingBlocks.size>=(this.config.maxConcurrentRequests??2))break;this.loadingBlocks.add(r),li(this.dataSource,r,t,{}).then(s=>{this.loadedBlocks.set(r,s.rows),this.totalRowCount=s.totalRowCount,this.loadingBlocks.delete(r),this.requestRender(),this.loadRequiredBlocks()}).catch(()=>{this.loadingBlocks.delete(r)})}}processRows(e){if(!this.dataSource)return[...e];const t=[];for(let i=0;i<this.totalRowCount;i++){const n=Cr(i,this.config.cacheBlockSize??100,this.loadedBlocks);t.push(n??{__loading:!0,__index:i})}return t}onScroll(e){this.dataSource&&(this.loadRequiredBlocks(),this.scrollDebounceTimer&&clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=setTimeout(()=>{this.loadRequiredBlocks()},xr))}setDataSource(e){this.dataSource=e,this.loadedBlocks.clear(),this.loadingBlocks.clear();const t=this.config.cacheBlockSize??100;li(e,0,t,{}).then(i=>{this.loadedBlocks.set(0,i.rows),this.totalRowCount=i.totalRowCount,this.requestRender()})}refresh(){this.dataSource&&(this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.requestRender())}purgeCache(){this.loadedBlocks.clear()}getTotalRowCount(){return this.totalRowCount}isRowLoaded(e){const t=this.config.cacheBlockSize??100,i=pe(e,t);return this.loadedBlocks.has(i)}getLoadedBlockCount(){return this.loadedBlocks.size}}function ai(o,e,t){return o.id!==void 0?String(o.id):t?`${t}-${e}`:String(e)}function Ve(o,e){const t=new Set(o);return t.has(e)?t.delete(e):t.add(e),t}function $e(o,e,t=null,i=0){const n=e.childrenField??"children",r=new Set;for(let s=0;s<o.length;s++){const l=o[s],a=ai(l,s,t),c=l[n];if(Array.isArray(c)&&c.length>0){r.add(a);const d=$e(c,e,a,i+1);for(const u of d)r.add(u)}}return r}function Er(){return new Set}function ci(o,e,t,i=null,n=0){const r=t.childrenField??"children";for(let s=0;s<o.length;s++){const l=o[s],a=ai(l,s,i);if(a===e)return[a];const c=l[r];if(Array.isArray(c)&&c.length>0){const d=ci(c,e,t,a,n+1);if(d)return[a,...d]}}return null}function Sr(o,e,t,i){const n=ci(o,e,t);if(!n)return i;const r=new Set(i);for(let s=0;s<n.length-1;s++)r.add(n[s]);return r}function di(o,e="children"){if(!Array.isArray(o)||o.length===0)return!1;for(const t of o){if(!t)continue;const i=t[e];if(Array.isArray(i)&&i.length>0)return!0}return!1}function _r(o){if(!Array.isArray(o)||o.length===0)return null;const e=["children","items","nodes","subRows","nested"];for(const t of o)if(!(!t||typeof t!="object"))for(const i of e){const n=t[i];if(Array.isArray(n)&&n.length>0)return i}return null}const Ar="@layer tbw-plugins{tbw-grid .cell[data-field=__tbw_expander]{border-right:none!important;padding:0;display:flex;align-items:center;justify-content:flex-start}tbw-grid .header-row .cell[data-field=__tbw_expander]{display:none}tbw-grid .header-row .cell[data-field=__tbw_expander]+.cell{grid-column:1 / 3}tbw-grid .tree-cell-wrapper{display:inline-flex;align-items:center;padding-left:calc(var(--tbw-tree-depth, 0) * var(--tbw-tree-indent-width, var(--tbw-tree-toggle-size, 1.25em)))}tbw-grid .tree-expander{display:flex;align-items:center;justify-content:flex-start;width:100%;height:100%;box-sizing:border-box}tbw-grid .tree-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-tree-toggle-size, 1.25em);height:var(--tbw-tree-toggle-size, 1.25em);flex-shrink:0}tbw-grid .tree-toggle:hover{color:var(--tbw-tree-accent, var(--tbw-color-accent))}tbw-grid .tree-spacer{width:var(--tbw-tree-toggle-size, 1.25em);display:inline-block;flex-shrink:0}tbw-grid .data-grid-row.tbw-tree-slide-in{animation:tbw-tree-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}tbw-grid .data-grid-row.tbw-tree-fade-in{animation:tbw-tree-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-tree-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}@keyframes tbw-tree-fade-in{0%{opacity:0}to{opacity:1}}}";class Tr extends L{name="tree";styles=Ar;get defaultConfig(){return{childrenField:"children",autoDetect:!0,defaultExpanded:!1,indentWidth:20,showExpandIcons:!0,animation:"slide"}}expandedKeys=new Set;initialExpansionDone=!1;flattenedRows=[];rowKeyMap=new Map;previousVisibleKeys=new Set;keysToAnimate=new Set;sortState=null;detach(){this.expandedKeys.clear(),this.initialExpansionDone=!1,this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.sortState=null}get animationStyle(){return this.isAnimationEnabled?this.config.animation??"slide":!1}detect(e){if(!this.config.autoDetect)return!1;const t=e,i=this.config.childrenField??_r(t)??"children";return di(t,i)}processRows(e){const t=this.config.childrenField??"children",i=e;if(!di(i,t))return this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),[...e];let n=this.withStableKeys(i);this.sortState&&(n=this.sortTree(n,this.sortState.field,this.sortState.direction)),this.config.defaultExpanded&&!this.initialExpansionDone&&(this.expandedKeys=$e(n,this.config),this.initialExpansionDone=!0),this.flattenedRows=this.flattenTree(n,this.expandedKeys),this.rowKeyMap.clear(),this.keysToAnimate.clear();const r=new Set;for(const s of this.flattenedRows)this.rowKeyMap.set(s.key,s),r.add(s.key),!this.previousVisibleKeys.has(s.key)&&s.depth>0&&this.keysToAnimate.add(s.key);return this.previousVisibleKeys=r,this.flattenedRows.map(s=>({...s.data,__treeKey:s.key,__treeDepth:s.depth,__treeHasChildren:s.hasChildren,__treeExpanded:s.isExpanded}))}withStableKeys(e,t=null){const i=this.config.childrenField??"children";return e.map((n,r)=>{const s=n.__stableKey,l=n.id!==void 0?String(n.id):s??(t?`${t}-${r}`:String(r)),a=n[i],c=Array.isArray(a)&&a.length>0;return{...n,__stableKey:l,...c?{[i]:this.withStableKeys(a,l)}:{}}})}flattenTree(e,t,i=0){const n=this.config.childrenField??"children",r=[];for(const s of e){const a=s.__stableKey??String(s.id??"?"),c=s[n],d=Array.isArray(c)&&c.length>0,u=t.has(a);r.push({key:a,data:s,depth:i,hasChildren:d,isExpanded:u,parentKey:i>0&&a.substring(0,a.lastIndexOf("-"))||null}),d&&u&&r.push(...this.flattenTree(c,t,i+1))}return r}sortTree(e,t,i){const n=this.config.childrenField??"children";return[...e].sort((s,l)=>{const a=s[t],c=l[t];return a==null&&c==null?0:a==null?-1:c==null?1:a>c?i:a<c?-i:0}).map(s=>{const l=s[n];return Array.isArray(l)&&l.length>0?{...s,[n]:this.sortTree(l,t,i)}:s})}processColumns(e){if(this.flattenedRows.length===0)return[...e];const t=[...e];if(t.length===0)return t;const i=t[0],n=i.viewRenderer,r=()=>this.config,s=this.setIcon.bind(this),l=this.resolveIcon.bind(this),a=c=>{const{row:d,value:u}=c,{showExpandIcons:h=!0,indentWidth:f}=r(),p=d,g=p.__treeDepth??0,w=document.createElement("span");if(w.className="tree-cell-wrapper",w.style.setProperty("--tbw-tree-depth",String(g)),f!==void 0&&w.style.setProperty("--tbw-tree-indent-width",`${f}px`),h)if(p.__treeHasChildren){const y=document.createElement("span");y.className=`tree-toggle${p.__treeExpanded?" expanded":""}`,s(y,l(p.__treeExpanded?"collapse":"expand")),y.setAttribute("data-tree-key",String(p.__treeKey??"")),w.appendChild(y)}else{const y=document.createElement("span");y.className="tree-spacer",w.appendChild(y)}const m=document.createElement("span");if(m.className="tree-content",n){const y=n(c);y instanceof Node?m.appendChild(y):typeof y=="string"&&(m.innerHTML=y)}else m.textContent=u!=null?String(u):"";return w.appendChild(m),w};return t[0]={...i,viewRenderer:a},t}onCellClick(e){const t=e.originalEvent?.target;if(!t?.classList.contains("tree-toggle"))return!1;const i=t.getAttribute("data-tree-key");if(!i)return!1;const n=this.rowKeyMap.get(i);return n?(this.expandedKeys=Ve(this.expandedKeys,i),this.emit("tree-expand",{key:i,row:n.data,expanded:this.expandedKeys.has(i),depth:n.depth}),this.requestRender(),!0):!1}onKeyDown(e){if(e.key!==" ")return;const t=this.grid._focusRow,i=this.flattenedRows[t];if(i?.hasChildren)return e.preventDefault(),this.expandedKeys=Ve(this.expandedKeys,i.key),this.emit("tree-expand",{key:i.key,row:i.data,expanded:this.expandedKeys.has(i.key),depth:i.depth}),this.requestRenderWithFocus(),!0}onHeaderClick(e){if(this.flattenedRows.length===0||!e.column.sortable)return!1;const{field:t}=e.column;!this.sortState||this.sortState.field!==t?this.sortState={field:t,direction:1}:this.sortState.direction===1?this.sortState={field:t,direction:-1}:this.sortState=null;const i=this.grid;return i._sortState!==void 0&&(i._sortState=this.sortState?{...this.sortState}:null),this.emit("sort-change",{field:t,direction:this.sortState?.direction??0}),this.requestRender(),!0}afterRender(){const e=this.animationStyle;if(e===!1||this.keysToAnimate.size===0)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const i=e==="fade"?"tbw-tree-fade-in":"tbw-tree-slide-in";for(const n of t.querySelectorAll(".data-grid-row")){const r=n.querySelector(".cell[data-row]"),s=r?parseInt(r.getAttribute("data-row")??"-1",10):-1,l=this.flattenedRows[s]?.key;l&&this.keysToAnimate.has(l)&&(n.classList.add(i),n.addEventListener("animationend",()=>n.classList.remove(i),{once:!0}))}this.keysToAnimate.clear()}expand(e){this.expandedKeys.add(e),this.requestRender()}collapse(e){this.expandedKeys.delete(e),this.requestRender()}toggle(e){this.expandedKeys=Ve(this.expandedKeys,e),this.requestRender()}expandAll(){this.expandedKeys=$e(this.rows,this.config),this.requestRender()}collapseAll(){this.expandedKeys=Er(),this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}getExpandedKeys(){return[...this.expandedKeys]}getFlattenedRows(){return[...this.flattenedRows]}getRowByKey(e){return this.rowKeyMap.get(e)?.data}expandToKey(e){this.expandedKeys=Sr(this.rows,e,this.config,this.expandedKeys),this.requestRender()}}function kr(o,e,t){const i=[...o.undoStack,e];for(;i.length>t;)i.shift();return{undoStack:i,redoStack:[]}}function ui(o){if(o.undoStack.length===0)return{newState:o,action:null};const e=[...o.undoStack],t=e.pop();return t?{newState:{undoStack:e,redoStack:[...o.redoStack,t]},action:t}:{newState:o,action:null}}function hi(o){if(o.redoStack.length===0)return{newState:o,action:null};const e=[...o.redoStack],t=e.pop();return t?{newState:{undoStack:[...o.undoStack,t],redoStack:e},action:t}:{newState:o,action:null}}function Pr(o){return o.undoStack.length>0}function Lr(o){return o.redoStack.length>0}function Dr(){return{undoStack:[],redoStack:[]}}function Hr(o,e,t,i){return{type:"cell-edit",rowIndex:o,field:e,oldValue:t,newValue:i,timestamp:Date.now()}}class Ir extends L{static dependencies=[{name:"editing",required:!0,reason:"UndoRedoPlugin tracks cell edit history"}];name="undoRedo";get defaultConfig(){return{maxHistorySize:100}}undoStack=[];redoStack=[];detach(){this.undoStack=[],this.redoStack=[]}onKeyDown(e){const t=(e.ctrlKey||e.metaKey)&&e.key==="z"&&!e.shiftKey,i=(e.ctrlKey||e.metaKey)&&(e.key==="y"||e.key==="z"&&e.shiftKey);if(t){const n=ui({undoStack:this.undoStack,redoStack:this.redoStack});if(n.action){const r=this.rows;r[n.action.rowIndex]&&(r[n.action.rowIndex][n.action.field]=n.action.oldValue),this.undoStack=n.newState.undoStack,this.redoStack=n.newState.redoStack,this.emit("undo",{action:n.action,type:"undo"}),this.requestRender()}return!0}if(i){const n=hi({undoStack:this.undoStack,redoStack:this.redoStack});if(n.action){const r=this.rows;r[n.action.rowIndex]&&(r[n.action.rowIndex][n.action.field]=n.action.newValue),this.undoStack=n.newState.undoStack,this.redoStack=n.newState.redoStack,this.emit("redo",{action:n.action,type:"redo"}),this.requestRender()}return!0}return!1}recordEdit(e,t,i,n){const r=Hr(e,t,i,n),s=kr({undoStack:this.undoStack,redoStack:this.redoStack},r,this.config.maxHistorySize??100);this.undoStack=s.undoStack,this.redoStack=s.redoStack}undo(){const e=ui({undoStack:this.undoStack,redoStack:this.redoStack});if(e.action){const t=this.rows;t[e.action.rowIndex]&&(t[e.action.rowIndex][e.action.field]=e.action.oldValue),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.requestRender()}return e.action}redo(){const e=hi({undoStack:this.undoStack,redoStack:this.redoStack});if(e.action){const t=this.rows;t[e.action.rowIndex]&&(t[e.action.rowIndex][e.action.field]=e.action.newValue),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.requestRender()}return e.action}canUndo(){return Pr({undoStack:this.undoStack,redoStack:this.redoStack})}canRedo(){return Lr({undoStack:this.undoStack,redoStack:this.redoStack})}clearHistory(){const e=Dr();this.undoStack=e.undoStack,this.redoStack=e.redoStack}getUndoStack(){return[...this.undoStack]}getRedoStack(){return[...this.redoStack]}}const Mr='@layer tbw-plugins{.tbw-visibility-content{display:flex;flex-direction:column;height:100%}.tbw-visibility-list{flex:1;overflow-y:auto;padding:var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem))}.tbw-visibility-row{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding:var(--tbw-menu-item-padding, .375rem .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem);border-radius:var(--tbw-border-radius, .25rem);position:relative}.tbw-visibility-row:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover, #f3f4f6))}.tbw-visibility-row input[type=checkbox]{cursor:pointer}.tbw-visibility-row.locked span{color:var(--tbw-color-fg-muted, #888)}.tbw-visibility-handle{cursor:grab;color:var(--tbw-color-fg-muted, #888);font-size:var(--tbw-font-size-2xs, .625rem);letter-spacing:-2px;-webkit-user-select:none;user-select:none;flex-shrink:0}.tbw-visibility-row.reorderable:hover .tbw-visibility-handle{color:var(--tbw-color-fg, #1f2937)}.tbw-visibility-label{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));flex:1;cursor:pointer}.tbw-visibility-row.dragging{opacity:.5;cursor:grabbing}.tbw-visibility-row.drop-before:before{content:"";position:absolute;left:0;right:0;top:0;height:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent, #3b82f6))}.tbw-visibility-row.drop-after:after{content:"";position:absolute;left:0;right:0;bottom:0;height:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent, #3b82f6))}.tbw-visibility-show-all{margin:var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem));padding:var(--tbw-button-padding, .5rem .75rem);border:1px solid var(--tbw-visibility-border, var(--tbw-color-border, #e5e7eb));border-radius:var(--tbw-border-radius, .25rem);background:var(--tbw-visibility-btn-bg, var(--tbw-color-header-bg, #f9fafb));color:var(--tbw-color-fg, #1f2937);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem)}.tbw-visibility-show-all:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover, #f3f4f6))}}';function fi(o){const e=o.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}class U extends L{static dependencies=[{name:"reorder",required:!1,reason:"Enables drag-to-reorder columns in visibility panel"}];name="visibility";static PANEL_ID="columns";styles=Mr;get defaultConfig(){return{allowHideAll:!1}}columnListElement=null;isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;clearDragClasses(e){e.querySelectorAll(".tbw-visibility-row").forEach(t=>{t.classList.remove("dragging","drop-target","drop-before","drop-after")})}detach(){this.columnListElement=null,this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null}getToolPanel(){return{id:U.PANEL_ID,title:"Columns",icon:"☰",tooltip:"Column visibility",order:100,render:e=>this.renderPanelContent(e)}}show(){this.grid.openToolPanel(),this.grid.expandedToolPanelSections.includes(U.PANEL_ID)||this.grid.toggleToolPanelSection(U.PANEL_ID)}hide(){this.grid.closeToolPanel()}toggle(){this.grid.isToolPanelOpen||this.grid.openToolPanel(),this.grid.toggleToolPanelSection(U.PANEL_ID)}isColumnVisible(e){return this.grid.isColumnVisible(e)}setColumnVisible(e,t){this.grid.setColumnVisible(e,t)}getVisibleColumns(){return this.grid.getAllColumns().filter(e=>e.visible).map(e=>e.field)}getHiddenColumns(){return this.grid.getAllColumns().filter(e=>!e.visible).map(e=>e.field)}showAll(){this.grid.showAllColumns()}toggleColumn(e){this.grid.toggleColumnVisibility(e)}showColumn(e){this.setColumnVisible(e,!0)}hideColumn(e){this.setColumnVisible(e,!1)}getAllColumns(){return this.grid.getAllColumns()}isPanelVisible(){return this.grid.isToolPanelOpen&&this.grid.expandedToolPanelSections.includes(U.PANEL_ID)}renderPanelContent(e){const t=document.createElement("div");t.className="tbw-visibility-content";const i=document.createElement("div");i.className="tbw-visibility-list",t.appendChild(i);const n=document.createElement("button");return n.className="tbw-visibility-show-all",n.textContent="Show All",n.addEventListener("click",()=>{this.grid.showAllColumns(),this.rebuildToggles(i)}),t.appendChild(n),this.columnListElement=i,this.rebuildToggles(i),e.appendChild(t),()=>{this.columnListElement=null,t.remove()}}hasReorderPlugin(){const e=this.grid?.getPluginByName?.("reorder");return!!(e&&typeof e.moveColumn=="function")}rebuildToggles(e){const t=this.hasReorderPlugin();e.innerHTML="";const i=this.grid.getAllColumns().filter(n=>!n.utility);for(let n=0;n<i.length;n++){const r=i[n],s=r.header||r.field,l=document.createElement("div");l.className=r.lockVisible?"tbw-visibility-row locked":"tbw-visibility-row",l.setAttribute("data-field",r.field),l.setAttribute("data-index",String(n)),t&&fi(r)&&(l.draggable=!0,l.classList.add("reorderable"),this.setupDragListeners(l,r.field,n,e));const a=document.createElement("label");a.className="tbw-visibility-label";const c=document.createElement("input");c.type="checkbox",c.checked=r.visible,c.disabled=r.lockVisible??!1,c.addEventListener("change",()=>{this.grid.toggleColumnVisibility(r.field),setTimeout(()=>this.rebuildToggles(e),0)});const d=document.createElement("span");if(d.textContent=s,a.appendChild(c),a.appendChild(d),t&&fi(r)){const u=document.createElement("span");u.className="tbw-visibility-handle",this.setIcon(u,this.resolveIcon("dragHandle")),u.title="Drag to reorder",l.appendChild(u)}l.appendChild(a),e.appendChild(l)}}setupDragListeners(e,t,i,n){e.addEventListener("dragstart",r=>{this.isDragging=!0,this.draggedField=t,this.draggedIndex=i,r.dataTransfer&&(r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",t)),e.classList.add("dragging")}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.clearDragClasses(n)}),e.addEventListener("dragover",r=>{if(r.preventDefault(),!this.isDragging||this.draggedField===t)return;const s=e.getBoundingClientRect(),l=s.top+s.height/2;this.dropIndex=r.clientY<l?i:i+1,n.querySelectorAll(".tbw-visibility-row").forEach(a=>{a!==e&&a.classList.remove("drop-target","drop-before","drop-after")}),e.classList.add("drop-target"),e.classList.toggle("drop-before",r.clientY<l),e.classList.toggle("drop-after",r.clientY>=l)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",r=>{r.preventDefault();const s=this.draggedField,l=this.draggedIndex,a=this.dropIndex;if(!this.isDragging||s===null||l===null||a===null)return;const c=a>l?a-1:a;if(c!==l){const d=this.grid.getAllColumns(),h=d.filter(g=>!g.utility)[c]?.field,f=h?d.findIndex(g=>g.field===h):d.length,p={field:s,fromIndex:l,toIndex:f};this.emit("column-reorder-request",p),setTimeout(()=>{this.rebuildToggles(n)},0)}})}}C.BaseGridPlugin=L,C.ClipboardPlugin=Do,C.ColumnVirtualizationPlugin=Oo,C.ContextMenuPlugin=zo,C.DEFAULT_ANIMATION_CONFIG=Ue,C.DEFAULT_GRID_ICONS=F,C.DGEvents=_o,C.DataGridElement=I,C.EditingPlugin=Xo,C.ExportPlugin=tn,C.FilteringPlugin=q,C.FitModeEnum=Y,C.GridCSSVars=Ro,C.GridClasses=H,C.GridDataAttrs=re,C.GridElement=I,C.GridSelectors=xo,C.GroupingColumnsPlugin=gn,C.GroupingRowsPlugin=xn,C.MasterDetailPlugin=qe,C.MultiSortPlugin=Dn,C.PLUGIN_QUERIES=Ae,C.PinnedColumnsPlugin=Mn,C.PinnedRowsPlugin=qn,C.PivotPlugin=$,C.PluginEvents=Ao,C.PluginManager=At,C.ROW_DRAG_HANDLE_FIELD=ni,C.RenderPhase=D,C.ReorderPlugin=lr,C.ResponsivePlugin=cr,C.RowReorderPlugin=ur,C.SelectionPlugin=br,C.ServerSidePlugin=Rr,C.TreePlugin=Tr,C.UndoRedoPlugin=Ir,C.VisibilityPlugin=U,C.builtInSort=lt,C.createGrid=Eo,C.defaultComparator=st,C.defaultEditorFor=Ot,C.defaultPasteHandler=Pt,C.queryGrid=So,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})}));
80
80
  //# sourceMappingURL=grid.all.umd.js.map