@toolbox-web/grid 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/all.js +46 -22
- package/all.js.map +1 -1
- package/index.js +516 -451
- package/index.js.map +1 -1
- package/lib/core/internal/editing.d.ts +76 -0
- package/lib/core/internal/editing.d.ts.map +1 -0
- package/lib/core/internal/validate-config.d.ts +14 -0
- package/lib/core/internal/validate-config.d.ts.map +1 -1
- package/lib/core/plugin/base-plugin.d.ts +48 -0
- package/lib/core/plugin/base-plugin.d.ts.map +1 -1
- package/lib/core/plugin/index.d.ts +1 -0
- package/lib/core/plugin/index.d.ts.map +1 -1
- package/lib/core/plugin/plugin-manager.d.ts +1 -1
- package/lib/core/plugin/plugin-manager.d.ts.map +1 -1
- package/lib/plugins/clipboard/ClipboardPlugin.d.ts +7 -1
- package/lib/plugins/clipboard/ClipboardPlugin.d.ts.map +1 -1
- package/lib/plugins/clipboard/index.js +28 -4
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js +20 -4
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js +30 -14
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/editing/index.js +24 -8
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/export/index.js +44 -28
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/index.js +16 -0
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/index.js +22 -6
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/index.js +16 -0
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/index.js +16 -0
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/multi-sort/index.js +16 -0
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js +16 -0
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/index.js +16 -0
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/index.js +16 -0
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/reorder/index.js +16 -0
- package/lib/plugins/reorder/index.js.map +1 -1
- package/lib/plugins/selection/index.js +16 -0
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js +20 -4
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/tree/index.js +16 -0
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts +7 -1
- package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts.map +1 -1
- package/lib/plugins/undo-redo/index.js +29 -5
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/VisibilityPlugin.d.ts +7 -1
- package/lib/plugins/visibility/VisibilityPlugin.d.ts.map +1 -1
- package/lib/plugins/visibility/index.js +24 -0
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/umd/grid.all.umd.js +23 -17
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +14 -8
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/clipboard.umd.js +1 -1
- package/umd/plugins/clipboard.umd.js.map +1 -1
- package/umd/plugins/editing.umd.js +1 -1
- package/umd/plugins/editing.umd.js.map +1 -1
- package/umd/plugins/undo-redo.umd.js +1 -1
- package/umd/plugins/undo-redo.umd.js.map +1 -1
- package/umd/plugins/visibility.umd.js +1 -1
- package/umd/plugins/visibility.umd.js.map +1 -1
package/umd/grid.all.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(v,K){typeof exports=="object"&&typeof module<"u"?K(exports):typeof define=="function"&&define.amd?define(["exports"],K):(v=typeof globalThis<"u"?globalThis:v||self,K(v.TbwGrid={}))})(this,(function(v){"use strict";const K=':root{color-scheme:light dark}:host{--tbw-color-bg: transparent;--tbw-color-panel-bg: light-dark(#eeeeee, #222222);--tbw-color-fg: light-dark(#222222, #eeeeee);--tbw-color-fg-muted: light-dark(#555555, #aaaaaa);--tbw-color-accent: light-dark(#3b82f6, #3b82f6);--tbw-color-accent-fg: light-dark(#ffffff, #000000);--tbw-color-success: light-dark(hsl(122, 39%, 40%), hsl(122, 39%, 49%));--tbw-color-selection: light-dark(#fff7d6, #333333);--tbw-color-row-alt: var(--tbw-color-bg);--tbw-color-row-hover: light-dark(#f0f6ff, #1c1c1c);--tbw-color-header-bg: color-mix(in hsl, var(--tbw-color-panel-bg) 85%, var(--tbw-color-fg));--tbw-color-header-fg: color-mix(in hsl, var(--tbw-color-fg) 75%, var(--tbw-color-panel-bg));--tbw-color-border: light-dark(#d0d0d4, #454545);--tbw-color-border-strong: light-dark(#777777, #adacac);--tbw-color-border-cell: var(--tbw-color-border);--tbw-color-border-header: var(--tbw-color-border);--tbw-color-shadow: light-dark(rgba(0, 0, 0, .1), rgba(0, 0, 0, .3));--tbw-font-family: inherit;--tbw-font-size: inherit;--tbw-font-size-header: var(--tbw-font-size);--tbw-font-weight-header: bold;--tbw-cell-padding-header: 2px 8px;--tbw-cell-padding: 2px 8px;--tbw-cell-padding-input: 2px 6px;--tbw-row-height: 28px;--tbw-header-height: 30px;--tbw-cell-white-space: nowrap;--tbw-border-radius: 4px;--tbw-border-input: 1px solid var(--tbw-color-border-strong);--tbw-border-header: 1px solid var(--tbw-color-border-header);--tbw-row-divider: 1px solid var(--tbw-color-border-cell);--tbw-row-hover-outline: 0;--tbw-color-active-row-bg: var(--tbw-color-selection);--tbw-active-row-outline: 0;--tbw-focus-outline: 2px solid var(--tbw-color-accent);--tbw-focus-outline-offset: -2px;--tbw-focus-background: rgba(from var(--tbw-color-accent) r g b / 12%);--tbw-range-border-color: var(--tbw-color-accent);--tbw-range-selection-bg: rgba(from var(--tbw-range-border-color) r g b / 12%);--tbw-resize-handle-width: 6px;--tbw-resize-handle-color: transparent;--tbw-resize-handle-color-hover: var(--tbw-color-accent);--tbw-resize-handle-border-radius: 0;--tbw-scrollbar-thumb: var(--tbw-color-border-strong);--tbw-scrollbar-track: var(--tbw-color-bg);--tbw-transition-duration: .12s;--tbw-transition-ease: ease;--tbw-animation-duration: .2s;--tbw-animation-easing: ease-out;--tbw-animation-enabled: 1;--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-border: var(--tbw-border-input, 1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input: var(--tbw-cell-padding-input, 2px 6px);--tbw-font-size-editor: inherit;--tbw-editing-row-bg: var(--tbw-editing-bg);--tbw-editing-row-outline-color: var(--tbw-color-accent);--tbw-editing-row-outline-width: 1px;--tbw-sort-indicator-color: var(--tbw-color-fg-muted);--tbw-sort-indicator-active-color: var(--tbw-color-accent);--tbw-header-text-transform: none;--tbw-header-letter-spacing: normal;--tbw-color-header-separator: var(--tbw-color-border-cell);--tbw-checkbox-size: 16px;--tbw-density-scale: 1}:host{position:relative;display:block;width:100%;height:100%;min-height:0;contain:content;font-family:var(--tbw-font-family);font-size:var(--tbw-font-size);background:var(--tbw-color-bg);color:var(--tbw-color-fg);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);overflow:clip;outline:none}:host,:host *{box-sizing:border-box}:host .header{display:block;flex-shrink:0;z-index:var(--tbw-z-layer-header, 30);background:var(--tbw-color-header-bg);overflow:visible}:host .header-group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-color-header-bg);z-index:var(--tbw-z-layer-header, 30)}:host .header-group-cell{display:flex;align-items:center;justify-content:flex-start;padding:var(--tbw-cell-padding-header, 2px 8px);color:var(--tbw-color-header-group-fg, var(--tbw-color-header-fg));font-weight:var(--tbw-font-weight-header-group, var(--tbw-font-weight-header));justify-content:var(--tbw-align-header-group, var(--tbw-align-header, flex-start))}:host .header-row{display:grid;grid-template-columns:var(--tbw-column-template);color:var(--tbw-color-header-fg);font-size:var(--tbw-font-size-header);min-height:var(--tbw-header-height);border-bottom:var(--tbw-border-header);z-index:var(--tbw-z-layer-header, 30)}:host .header-row>.cell{display:flex;align-items:center;gap:4px;padding:var(--tbw-cell-padding-header, 2px 8px);background-color:var(--tbw-color-header-bg);font-weight:var(--tbw-font-weight-header);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}:host .header-row>.cell>span:first-child{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}:host .header-row>.cell>span[part~=sort-indicator]{flex-shrink:0;opacity:.6}:host .header-row>.cell:last-child{border-right:0}:host .header-group-cell:not(:last-child),:host .header-row>.cell.grouped.group-end:not(:last-child){border-right:2px solid var(--tbw-color-border)}:host .tbw-grid-root{display:flex;flex-direction:column;height:100%}:host .rows-body-wrapper{flex:1;min-height:0;display:flex;flex-direction:row;width:100%;min-width:fit-content}:host .rows-body{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow:visible}:host .rows-container{display:flex;flex-direction:row;flex:1;min-height:0;overflow:visible}:host .rows-viewport{flex:1;min-width:0;position:relative;display:block;overflow:clip}:host .faux-vscroll{position:sticky;inset-inline-end:0;flex-shrink:0;width:auto;overflow-y:auto;overflow-x:hidden;z-index:var(--tbw-z-layer-header, 30)}:host .faux-vscroll-spacer{width:1px}:host .rows-viewport .rows{position:absolute;top:0;left:0;min-width:100%;will-change:transform;z-index:var(--tbw-z-layer-rows, 1)}:host .data-grid-row{display:grid;grid-template-columns:var(--tbw-column-template);contain:layout style;content-visibility:auto;contain-intrinsic-size:auto var(--tbw-row-height)}:host .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))}:host .selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}:host .data-grid-row>.cell.selected:focus-visible,:host .data-grid-row>.cell:focus-visible:not(.cell-focus){outline:none}:host .data-grid-row>.cell{display:block;padding:var(--tbw-cell-padding, 2px 8px);border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height);line-height:calc(var(--tbw-row-height) - 5px);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0;white-space:var(--tbw-cell-white-space, nowrap);text-overflow:ellipsis}:host .data-grid-row>.cell>*{overflow:hidden;text-overflow:ellipsis;white-space:inherit;min-width:0}:host .data-grid-row>.cell:last-child{border-right:0}:host .data-grid-row>.cell[data-type=boolean]{text-align:center}:host .data-grid-row>.cell[data-type=boolean] input[type=checkbox]{margin:0;width:var(--tbw-checkbox-size);height:var(--tbw-checkbox-size);vertical-align:middle}:host .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex;min-height:calc(var(--tbw-row-height) + 2px)}:host .data-grid-row>.cell.editing input:not([type=checkbox]),:host .data-grid-row>.cell.editing select,:host .data-grid-row>.cell.editing textarea{width:100%;height:100%;flex:1 1 auto;min-width:0;border:var(--tbw-editing-border);padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor)}:host .data-grid-row:nth-child(2n){background:var(--tbw-color-row-alt)}:host .data-grid-row:hover{background:var(--tbw-color-row-hover)}:host .sortable{cursor:pointer;-webkit-user-select:none;user-select:none}:host .resize-handle{position:absolute;top:0;right:calc(var(--tbw-resize-handle-width) / -2);width:var(--tbw-resize-handle-width);height:100%;cursor:e-resize;-webkit-user-select:none;user-select:none;touch-action:none;z-index:20;background:var(--tbw-resize-handle-color);transition:background .12s ease;border-radius:var(--tbw-resize-handle-border-radius)}:host .resize-handle:hover{background:var(--tbw-resize-handle-color-hover)}:host .cell-focus,:host .row-focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}:host .sticky-left,:host .sticky-right{position:sticky;z-index:25}:host .header-row>.cell.sticky-left,:host .header-row>.cell.sticky-right{background:var(--tbw-color-header-bg);z-index:35}:host .data-grid-row>.cell.sticky-left,:host .data-grid-row>.cell.sticky-right{background:var(--tbw-color-panel-bg)}:host .sticky-left{box-shadow:1px 0 0 var(--tbw-color-border)}:host .sticky-right{box-shadow:-1px 0 0 var(--tbw-color-border)}.grid-container{position:relative;width:100%;height:100%}.grid-placeholder{padding:2rem;text-align:center;color:var(--tbw-color-fg);opacity:.6}:host{--tbw-shell-header-height: 44px;--tbw-shell-header-bg: var(--tbw-color-panel-bg);--tbw-shell-header-border: var(--tbw-color-border);--tbw-shell-title-font-size: 14px;--tbw-shell-title-font-weight: 600;--tbw-tool-panel-width: 280px;--tbw-tool-panel-bg: var(--tbw-color-panel-bg);--tbw-tool-panel-border: var(--tbw-color-border);--tbw-tool-panel-header-height: 40px;--tbw-tool-panel-transition: var(--tbw-animation-duration) var(--tbw-animation-easing);--tbw-toolbar-button-size: 32px;--tbw-toolbar-button-gap: 4px}:host .tbw-grid-root.has-shell{display:flex;flex-direction:column;height:100%}:host .tbw-shell-header{display:flex;align-items:center;gap:8px;min-height:var(--tbw-shell-header-height);padding:0 8px;background:var(--tbw-shell-header-bg);border-bottom:1px solid var(--tbw-shell-header-border);flex-shrink:0}:host .tbw-shell-title{font-size:var(--tbw-shell-title-font-size);font-weight:var(--tbw-shell-title-font-weight);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host .tbw-shell-content{flex:1;display:flex;align-items:center;gap:12px;min-width:0;overflow:hidden}:host .tbw-shell-toolbar{display:flex;align-items:center;gap:var(--tbw-toolbar-button-gap);flex-shrink:0}:host .tbw-toolbar-btn{display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-toolbar-button-size);height:var(--tbw-toolbar-button-size);padding:0;border:1px solid transparent;border-radius:var(--tbw-border-radius);background:transparent;color:var(--tbw-color-fg);cursor:pointer;font-size:16px;transition:background var(--tbw-transition-duration) var(--tbw-transition-ease),border-color var(--tbw-transition-duration) var(--tbw-transition-ease)}:host .tbw-toolbar-btn:hover{background:var(--tbw-color-row-hover)}:host .tbw-toolbar-btn:focus-visible{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}:host .tbw-toolbar-btn.active{background:var(--tbw-focus-background);border-color:var(--tbw-color-accent)}:host .tbw-toolbar-btn:disabled{opacity:.5;cursor:not-allowed}:host .tbw-toolbar-separator{width:1px;height:20px;background:var(--tbw-color-border);margin:0 4px}:host .tbw-shell-body{position:relative;display:flex;flex:1;min-height:0;overflow:visible}:host .tbw-grid-content{flex:1;min-width:0;min-height:0;display:flex;flex-direction:row;overflow:hidden}:host .tbw-scroll-area{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow-x:auto;overflow-y:hidden;overflow-anchor:none}:host .tbw-tool-panel{position:absolute;top:0;bottom:0;right:0;width:0;overflow:hidden;background:var(--tbw-tool-panel-bg);border-left:1px solid var(--tbw-tool-panel-border);transition:width var(--tbw-tool-panel-transition);display:flex;flex-direction:column;z-index:30;box-shadow:-2px 0 8px var(--tbw-color-shadow)}:host .tbw-tool-panel[data-position=left]{right:auto;left:0;border-left:none;border-right:1px solid var(--tbw-tool-panel-border);box-shadow:2px 0 8px var(--tbw-color-shadow)}:host .tbw-tool-panel.open{width:var(--tbw-tool-panel-width)}:host .tbw-tool-panel-resize{position:absolute;top:0;bottom:0;width:6px;cursor:col-resize;background:transparent;z-index:10;transition:background var(--tbw-transition-duration) var(--tbw-transition-ease)}:host .tbw-tool-panel-resize[data-handle-position=left]{left:0}:host .tbw-tool-panel-resize[data-handle-position=right]{right:0}:host .tbw-tool-panel-resize:hover,:host .tbw-tool-panel-resize.resizing{background:var(--tbw-color-accent)}:host .tbw-tool-panel-header{display:flex;align-items:center;justify-content:space-between;min-height:var(--tbw-tool-panel-header-height);padding:0 12px;border-bottom:1px solid var(--tbw-tool-panel-border);flex-shrink:0}:host .tbw-tool-panel-title{font-weight:600;font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host .tbw-tool-panel-close{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;padding:0;border:none;border-radius:var(--tbw-border-radius);background:transparent;color:var(--tbw-color-fg-muted);cursor:pointer;font-size:14px}:host .tbw-tool-panel-close:hover{background:var(--tbw-color-row-hover);color:var(--tbw-color-fg)}:host .tbw-tool-panel-content{flex:1;overflow:auto}:host .tbw-accordion{display:flex;flex-direction:column;gap:0}:host .tbw-accordion-section{border-bottom:1px solid var(--tbw-tool-panel-border)}:host .tbw-accordion-section:last-child{border-bottom:none}:host .tbw-accordion-header{display:flex;align-items:center;gap:8px;width:100%;padding:10px 12px;border:none;background:transparent;color:var(--tbw-color-fg);font-size:13px;font-weight:600;text-align:left;cursor:pointer;-webkit-user-select:none;user-select:none}:host .tbw-accordion-header:hover{background:var(--tbw-color-row-hover)}:host .tbw-accordion-section.single .tbw-accordion-header{cursor:default}:host .tbw-accordion-section.single .tbw-accordion-header:hover{background:transparent}:host .tbw-accordion-chevron{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:10px;color:var(--tbw-color-fg-muted);transition:transform .15s ease;flex-shrink:0}:host .tbw-accordion-section.expanded .tbw-accordion-chevron{transform:rotate(90deg)}:host .tbw-accordion-icon{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:14px;flex-shrink:0}:host .tbw-accordion-title{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}:host .tbw-accordion-content{display:none}:host .tbw-accordion-section.expanded .tbw-accordion-content{display:block}@media(forced-colors:active){:host{--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}:host .cell:focus,:host .cell.active-cell{outline:2px solid Highlight!important;outline-offset:-2px}:host .data-grid-row[aria-selected=true]{background:Highlight!important;color:HighlightText!important}}@media(prefers-reduced-motion:reduce){:host([data-animation-mode="reduced-motion"]){--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms}}:host([data-animation-mode="off"]){--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms}:host .tbw-expanding{animation:tbw-expand var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}:host .tbw-collapsing{animation:tbw-collapse var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}@keyframes tbw-expand{0%{opacity:0;max-height:0;transform:translateY(-8px)}to{opacity:1;max-height:500px;transform:translateY(0)}}@keyframes tbw-collapse{0%{opacity:1;max-height:500px;transform:translateY(0)}to{opacity:0;max-height:0;transform:translateY(-8px)}}:host .tbw-fade-in{animation:tbw-fade-in var(--tbw-animation-duration) var(--tbw-animation-easing) forwards}:host .tbw-fade-out{animation:tbw-fade-out var(--tbw-animation-duration) var(--tbw-animation-easing) forwards}@keyframes tbw-fade-in{0%{opacity:0}to{opacity:1}}@keyframes tbw-fade-out{0%{opacity:1}to{opacity:0}}@keyframes tbw-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}:host .tbw-slide-in{animation:tbw-slide-in var(--tbw-animation-duration) var(--tbw-animation-easing) forwards}:host .tbw-dragging{opacity:.5;cursor:grabbing}:host .tbw-toggle-btn{cursor:pointer;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center;background:transparent;border:none;padding:0;font:inherit;color:inherit}:host .tbw-floating-panel{position:fixed;background:var(--tbw-color-panel-bg);color:var(--tbw-color-fg);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);box-shadow:0 4px 16px var(--tbw-color-shadow);z-index:10000;font-size:13px}:host .tbw-drop-before:before,:host .tbw-drop-after:after{content:"";position:absolute;background:var(--tbw-drop-indicator-color, var(--tbw-color-accent));pointer-events:none}:host .tbw-drop-before-v:before{left:0;top:0;bottom:0;width:2px}:host .tbw-drop-after-v:after{right:0;top:0;bottom:0;width:2px}:host .tbw-drop-before-h:before{left:0;right:0;top:0;height:2px}:host .tbw-drop-after-h:after{left:0;right:0;bottom:0;height:2px}:host .tbw-flip-animating{will-change:transform;z-index:1}:host .tbw-toggle-icon{display:inline-flex;align-items:center;justify-content:center;transition:transform var(--tbw-animation-duration) var(--tbw-animation-easing)}:host .tbw-toggle-icon.tbw-expanded{transform:rotate(90deg)}',V={STRETCH:"stretch",FIXED:"fixed"},ze={mode:"reduced-motion",duration:200,easing:"ease-out"},O={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰"};function io(n){return Array.from(n.querySelectorAll("tbw-grid-column")).map(t=>{const o=t.getAttribute("field")||"";if(!o)return null;const i=t.getAttribute("type")||void 0,s=i&&new Set(["number","string","date","boolean","select","typeahead"]).has(i)?i:void 0,l=t.getAttribute("header")||void 0,a=t.hasAttribute("sortable"),c=t.hasAttribute("editable"),d={field:o,type:s,header:l,sortable:a,editable:c},u=t.getAttribute("width");if(u){const b=parseFloat(u);!isNaN(b)&&/^\d+(\.\d+)?$/.test(u.trim())?d.width=b:d.width=u}const h=t.getAttribute("minWidth")||t.getAttribute("min-width");if(h){const b=parseFloat(h);isNaN(b)||(d.minWidth=b)}t.hasAttribute("resizable")&&(d.resizable=!0),t.hasAttribute("sizable")&&(d.resizable=!0);const p=t.getAttribute("editor"),f=t.getAttribute("renderer");p&&(d.__editorName=p),f&&(d.__rendererName=f);const g=t.getAttribute("options");g&&(d.options=g.split(",").map(b=>{const[_,M]=b.includes(":")?b.split(":"):[b.trim(),b.trim()];return{value:_.trim(),label:M?.trim()||_.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 x=globalThis.DataGridElement?.getAdapters?.()??[],R=w??t,E=x.find(b=>b.canHandle(R));if(E){const b=E.createRenderer(R);b&&(d.viewRenderer=b)}const q=m??t,A=x.find(b=>b.canHandle(q));if(A){const b=A.createEditor(q);b&&(d.editor=b)}return d}).filter(t=>!!t)}function Be(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(i=>{const r=t[i.field];if(r){i.header&&!r.header&&(r.header=i.header),i.type&&!r.type&&(r.type=i.type),i.sortable&&(r.sortable=!0),i.editable&&(r.editable=!0),i.resizable&&(r.resizable=!0),i.width!=null&&r.width==null&&(r.width=i.width),i.minWidth!=null&&r.minWidth==null&&(r.minWidth=i.minWidth),i.__viewTemplate&&(r.__viewTemplate=i.__viewTemplate),i.__editorTemplate&&(r.__editorTemplate=i.__editorTemplate),i.__headerTemplate&&(r.__headerTemplate=i.__headerTemplate);const s=i.renderer||i.viewRenderer,l=r.renderer||r.viewRenderer;s&&!l&&(r.viewRenderer=s,i.renderer&&(r.renderer=s)),i.editor&&!r.editor&&(r.editor=i.editor)}else t[i.field]={...i}});const o=n.map(i=>{const r=t[i.field];if(!r)return i;const s={...i};r.header&&!s.header&&(s.header=r.header),r.type&&!s.type&&(s.type=r.type),s.sortable=i.sortable||r.sortable,(i.resizable===!0||r.resizable===!0)&&(s.resizable=!0),s.editable=i.editable||r.editable,r.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[i.field],s});return Object.keys(t).forEach(i=>o.push(t[i])),o}function Ge(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 Ke(n){const e=n.effectiveConfig?.fitMode||n.fitMode||V.STRETCH;if(e!==V.STRETCH&&e!==V.FIXED||n.__didInitialAutoSize||!n.isConnected)return;const t=Array.from(n._headerRowEl?.children||[]);if(!t.length)return;let o=!1;n._visibleColumns.forEach((i,r)=>{if(i.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&&(i.width=l+2,i.__autoSized=!0,o=!0)}),o&&ee(n),n.__didInitialAutoSize=!0}function ee(n){(n.effectiveConfig?.fitMode||n.fitMode||V.STRETCH)===V.STRETCH?n._gridTemplate=n._visibleColumns.map(t=>{if(t.width)return`${t.width}px`;const o=t.minWidth;return o!=null?`minmax(${o}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 ro(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 so(n,e){const t=n[0]||{},o=Object.keys(t).map(r=>{const s=t[r],l=ro(s);return{field:r,header:r.charAt(0).toUpperCase()+r.slice(1),type:l}}),i={};return o.forEach(r=>{i[r.field]=r.type||"string"}),{columns:o,typeMap:i}}const lo=/{{\s*([^}]+)\s*}}/g,I="__DG_EMPTY__",ao=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,co=/__(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 uo(n){return!n||typeof n!="string"?"":n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const ho=new Set(["script","iframe","object","embed","form","input","button","textarea","select","link","meta","base","style","template","slot","portal","frame","frameset","applet","noscript","noembed","plaintext","xmp","listing"]),Ve=/^on\w+$/i,fo=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),po=/^\s*(javascript|vbscript|data|blob):/i;function te(n){if(!n||typeof n!="string")return"";if(n.indexOf("<")===-1)return n;const e=document.createElement("template");return e.innerHTML=n,go(e.content),e.innerHTML}function go(n){const e=[],t=n.querySelectorAll("*");for(const o of t){const i=o.tagName.toLowerCase();if(ho.has(i)){e.push(o);continue}if((i==="svg"||o.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(o.attributes).some(l=>Ve.test(l.name)||l.name==="href"||l.name==="xlink:href")){e.push(o);continue}const r=[];for(const s of o.attributes){const l=s.name.toLowerCase();if(Ve.test(l)){r.push(s.name);continue}if(fo.has(l)&&po.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=>o.removeAttribute(s))}e.forEach(o=>o.remove())}function pe(n,e){if(!n||n.indexOf("{{")===-1)return n;const t=[],o=n.replace(lo,(l,a)=>{const c=mo(a,e);return t.push({expr:a.trim(),result:c}),c}),i=wo(o),r=t.length&&t.every(l=>l.result===""||l.result===I);return/Reflect\.|\bProxy\b|ownKeys\(/.test(n)||r?"":i}function mo(n,e){if(n=(n||"").trim(),!n||/\b(Reflect|Proxy|ownKeys)\b/.test(n))return I;if(n==="value")return e.value==null?I:String(e.value);if(n.startsWith("row.")&&!/[()?]/.test(n)&&!n.includes(":")){const o=n.slice(4),i=e.row?e.row[o]:void 0;return i==null?I:String(i)}if(n.length>80||!ao.test(n)||co.test(n))return I;const t=n.match(/\./g);if(t&&t.length>1)return I;try{const i=new Function("value","row",`return (${n});`)(e.value,e.row),r=i==null?"":String(i);return/Reflect|Proxy|ownKeys/.test(r)?I:r||I}catch{return I}}function wo(n){return n&&n.replace(new RegExp(I,"g"),"").replace(/Reflect\.[^<>{}\s]+/g,"").replace(/\bProxy\b/g,"").replace(/ownKeys\([^)]*\)/g,"")}function bo(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 We(n){const e=/Reflect\.|\bProxy\b|ownKeys\(/.test(n),t=(o=>e?"":pe(n,o));return t.__blocked=e,t}const vo=100;class yo{#e;#s;#d;#c;#r;#n;#f={};#h={};#p=!0;#l=[];#m;#g;#w;#a;#v;constructor(e){this.#a=e}get original(){return this.#f}get effective(){return this.#h}get columns(){return this.#h.columns??[]}set columns(e){this.#h.columns=e}get lightDomColumnsCache(){return this.#r}set lightDomColumnsCache(e){this.#r=e}get originalColumnNodes(){return this.#n}set originalColumnNodes(e){this.#n=e}get lightDomTitle(){return this.#v}set lightDomTitle(e){this.#v=e}get initialColumnState(){return this.#w}set initialColumnState(e){this.#w=e}get sourcesChanged(){return this.#p}markSourcesChanged(){this.#p=!0}setGridConfig(e){this.#e=e,this.#p=!0,this.#r=void 0}getGridConfig(){return this.#e}setColumns(e){this.#s=e,this.#p=!0}getColumns(){return this.#s}setFitMode(e){this.#d=e,this.#p=!0}getFitMode(){return this.#d}setEditOn(e){this.#c=e,this.#p=!0}getEditOn(){return this.#c}merge(){const e=(this.#h.columns?.length??0)>0;if(!this.#p&&e)return;const t=this.#C();this.#p=!1,this.#f=t,Object.freeze(this.#f),this.#f.columns&&Object.freeze(this.#f.columns),this.#h=this.#T(this.#f),this.#b()}#T(e){const t={...e};return e.columns&&(t.columns=e.columns.map(o=>({...o}))),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(o=>({...o})),headerContents:e.shell.headerContents?.map(o=>({...o}))}),t}#b(){const e=this.#h;e.rowHeight&&e.rowHeight>0&&this.#a.setRowHeight(e.rowHeight),e.fitMode==="fixed"&&this.columns.forEach(o=>{o.width==null&&(o.width=80)}),this.#a.applyAnimationConfig(e)}#C(){const e=this.#e?{...this.#e}:{},t=Array.isArray(e.columns)?[...e.columns]:[],o=(this.#r??[]).map(s=>({...s}));let i=Be(t,o);this.#s&&this.#s.length&&(i=Be(this.#s,o));const r=this.#a.getRows();return i.length===0&&r.length&&(i=so(r).columns),i.length&&(i.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)}),i.forEach(s=>{s.__viewTemplate&&!s.__compiledView&&(s.__compiledView=We(s.__viewTemplate.innerHTML)),s.__editorTemplate&&!s.__compiledEditor&&(s.__compiledEditor=We(s.__editorTemplate.innerHTML))}),e.columns=i),this.#d&&(e.fitMode=this.#d),e.fitMode||(e.fitMode="stretch"),this.#c&&(e.editOn=this.#c),this.#x(e),e.columnState&&!this.#w&&(this.#w=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.#v=t),this.#v&&!e.shell.header.title&&(e.shell.header.title=this.#v);const o=this.#a.getShellLightDomHeaderContent();o?.length>0&&(e.shell.header.lightDomContent=o),this.#a.getShellHasToolButtonsContainer()&&(e.shell.header.hasToolButtonsContainer=!0);const i=this.#a.getShellToolPanels();if(i.size>0){const u=Array.from(i.values());u.sort((h,p)=>(h.order??100)-(p.order??100)),e.shell.toolPanels=u}const r=this.#a.getShellHeaderContents();if(r.size>0){const u=Array.from(r.values());u.sort((h,p)=>(h.order??100)-(p.order??100)),e.shell.headerContents=u}const s=this.#a.getShellToolbarButtons(),l=Array.from(s.values()),a=this.#e?.shell?.header?.toolbarButtons??[],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??100)-(h.order??100)),e.shell.header.toolbarButtons=d}collectState(e){const t=this.columns,o=this.#y();return{columns:t.map((i,r)=>{const s={field:i.field,order:r,visible:!i.hidden},l=i;l.__renderedWidth!==void 0?s.width=l.__renderedWidth:i.width!==void 0&&(s.width=typeof i.width=="string"?parseFloat(i.width):i.width);const a=o.get(i.field);a&&(s.sort=a);for(const c of e)if(c.getColumnState){const d=c.getColumnState(i.field);d&&Object.assign(s,d)}return s})}}applyState(e,t){if(!e.columns||e.columns.length===0)return;const o=this.columns,i=new Map(e.columns.map(l=>[l.field,l])),r=o.map(l=>{const a=i.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=i.get(l.field)?.order??1/0,d=i.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.#w=void 0,this.#a.setSortState(null),this.#h=this.#T(this.#f),this.#b();for(const t of e)if(t.applyColumnState)for(const o of this.columns)t.applyColumnState(o.field,{field:o.field,order:0,visible:!0});this.requestStateChange(e)}#y(){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.#g&&clearTimeout(this.#g),this.#g=setTimeout(()=>{this.#g=void 0;const t=this.collectState(e);this.#a.emit("column-state-change",t)},vo)}setColumnVisible(e,t){const o=this.columns,i=o.find(s=>s.field===e);return!i||!t&&i.lockVisible||!t&&o.filter(l=>!l.hidden&&l.field!==e).length===0||!!i.hidden===!t?!1:(i.hidden=!t,this.#a.emit("column-visibility",{field:e,visible:t,visibleColumns:o.filter(s=>!s.hidden).map(s=>s.field)}),this.#a.clearRowPool(),this.#a.setup(),!0)}toggleColumnVisibility(e){const t=this.columns.find(o=>o.field===e);return t?this.setColumnVisible(e,!!t.hidden):!1}isColumnVisible(e){const t=this.columns.find(o=>o.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}))}getColumnOrder(){return this.columns.map(e=>e.field)}setColumnOrder(e){if(!e.length)return;const t=new Map(this.columns.map(i=>[i.field,i])),o=[];for(const i of e){const r=t.get(i);r&&(o.push(r),t.delete(i))}for(const i of t.values())o.push(i);this.columns=o,this.#a.renderHeader(),this.#a.updateTemplate(),this.#a.refreshVirtualWindow()}parseLightDomColumns(e){this.#r||(this.#n=Array.from(e.querySelectorAll("tbw-grid-column")),this.#r=this.#n.length?io(e):[])}clearLightDomCache(){this.#r=void 0}#S=new Map;registerLightDomHandler(e,t){this.#S.set(e.toLowerCase(),t)}unregisterLightDomHandler(e){this.#S.delete(e.toLowerCase())}observeLightDOM(e){this.#m&&this.#m.disconnect();const t=new Set;let o=null;const i=()=>{o=null;for(const r of t)this.#S.get(r)?.();t.clear()};this.#m=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.#S.has(c)&&t.add(c)}if(s.type==="attributes"&&s.target.nodeType===Node.ELEMENT_NODE){const a=s.target.tagName.toLowerCase();this.#S.has(a)&&t.add(a)}}t.size>0&&!o&&(o=setTimeout(i,0))}),this.#m.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["title","field","header","width","hidden","id","icon","tooltip","order"]})}onChange(e){this.#l.push(e)}notifyChange(){for(const e of this.#l)e()}dispose(){this.#m?.disconnect(),this.#l=[],this.#g&&clearTimeout(this.#g)}}function $e(n){return`<span role="checkbox" aria-checked="${n}" aria-label="${n}">${n?"🗹":"☐"}</span>`}function Ue(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 ge(n){if(!n)return-1;const e=n.getAttribute("data-row");return e?parseInt(e,10):-1}function Co(n){if(!n)return-1;const e=n.getAttribute("data-col");return e?parseInt(e,10):-1}function W(n){n&&n.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function xo(n,e){const t=ge(e),o=Co(e);t<0||o<0||(n._focusRow=t,n._focusCol=o,W(n._bodyEl),e.classList.add("cell-focus"),e.setAttribute("aria-selected","true"))}function Eo(n,e,t){e.addEventListener("mousedown",o=>{const i=o.target.closest(".cell[data-col]");i&&(i.classList.contains("editing")||xo(n,i))},{signal:t})}function je(n,e){return n==null&&e==null?0:n==null?-1:e==null||n>e?1:n<e?-1:0}function Xe(n,e,t){const i=t.find(l=>l.field===e.field)?.sortComparator??je,{field:r,direction:s}=e;return[...n].sort((l,a)=>i(l[r],a[r],l,a)*s)}function Ye(n,e,t,o){n._rows=e,n.__rowRenderEpoch++,n._rowPool.forEach(i=>i.__epoch=-1),ae(n),n.refreshVirtualWindow(!0),n.dispatchEvent(new CustomEvent("sort-change",{detail:{field:t.field,direction:o}})),n.requestStateChange?.()}function Ze(n,e){!n._sortState||n._sortState.field!==e.field?(n._sortState||(n.__originalOrder=n._rows.slice()),Je(n,e,1)):n._sortState.direction===1?Je(n,e,-1):(n._sortState=null,n.__rowRenderEpoch++,n._rowPool.forEach(o=>o.__epoch=-1),n._rows=n.__originalOrder.slice(),ae(n),n._headerRowEl?.querySelectorAll('[role="columnheader"].sortable')?.forEach(o=>{o.getAttribute("aria-sort")?(o.getAttribute("aria-sort")==="ascending"||o.getAttribute("aria-sort")==="descending")&&(n._sortState||o.setAttribute("aria-sort","none")):o.setAttribute("aria-sort","none")}),n.refreshVirtualWindow(!0),n.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:0}})),n.requestStateChange?.())}function Je(n,e,t){n._sortState={field:e.field,direction:t};const o={field:e.field,direction:t},i=n._columns,s=(n.effectiveConfig?.sortHandler??Xe)(n._rows,o,i);s&&typeof s.then=="function"?s.then(l=>{Ye(n,l,e,t)}):Ye(n,s,e,t)}function So(n,e){typeof e=="string"?n.textContent=e:e instanceof HTMLElement&&(n.innerHTML="",n.appendChild(e.cloneNode(!0)))}function ae(n){n._headerRowEl=n.findHeaderRow();const e=n._headerRowEl;e.innerHTML="",n._visibleColumns.forEach((t,o)=>{const i=document.createElement("div");i.className="cell",Ge(i,"header-cell"),i.setAttribute("role","columnheader"),i.setAttribute("aria-colindex",String(o+1)),i.setAttribute("data-field",t.field),i.setAttribute("data-col",String(o));const r=t.__headerTemplate;if(r)Array.from(r.childNodes).forEach(s=>i.appendChild(s.cloneNode(!0)));else{const s=t.header||t.field,l=document.createElement("span");l.textContent=s,i.appendChild(l)}if(t.sortable){i.classList.add("sortable"),i.tabIndex=0;const s=document.createElement("span");Ge(s,"sort-indicator");const l=n._sortState?.field===t.field?n._sortState.direction:0,a={...O,...n.icons},c=l===1?a.sortAsc:l===-1?a.sortDesc:a.sortNone;So(s,c),i.appendChild(s),i.setAttribute("aria-sort",l===0?"none":l===1?"ascending":"descending"),i.addEventListener("click",d=>{n._resizeController?.isResizing||n._dispatchHeaderClick?.(d,o,i)||Ze(n,t)}),i.addEventListener("keydown",d=>{if(d.key==="Enter"||d.key===" "){if(d.preventDefault(),n._dispatchHeaderClick?.(d,o,i))return;Ze(n,t)}})}if(t.resizable){i.style.position="relative";const s=document.createElement("div");s.className="resize-handle",s.setAttribute("aria-hidden","true"),s.addEventListener("mousedown",l=>{l.stopPropagation(),l.preventDefault(),n._resizeController.start(l,o,i)}),s.addEventListener("dblclick",l=>{l.stopPropagation(),l.preventDefault(),n._resizeController.resetColumn(o)}),i.appendChild(s)}e.appendChild(i)}),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 Qe=typeof requestIdleCallback=="function";function Ro(n,e){return Qe?requestIdleCallback(n,e):window.setTimeout(()=>{const t=Date.now();n({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})},1)}function et(n){Qe?cancelIdleCallback(n):clearTimeout(n)}const tt='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function me(n){return(n.__editingCellCount??0)>0}function we(n){n.__editingCellCount=0,n.removeAttribute("data-has-editing"),n.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 _o(){return ot.content.firstElementChild.cloneNode(!0)}function Ao(){return nt.content.firstElementChild.cloneNode(!0)}function ce(n){n.__cellDisplayCache=void 0,n.__cellCacheEpoch=void 0,n.__hasSpecialColumns=void 0}function To(n,e,t,o,i){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.shadowRoot?.querySelector(".header-group-row")?2:1,n.__cachedHeaderRowCount=c);n._rowPool.length<r;){const u=Ao();u.addEventListener("click",h=>it(n,h,u)),u.addEventListener("dblclick",h=>it(n,h,u)),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=i&&n.__hasRenderRowPlugins!==!1;for(let u=0;u<r;u++){const h=e+u,p=n._rows[h],f=n._rowPool[u];if(f.setAttribute("aria-rowindex",String(h+c+1)),d&&i(p,f,h)){f.__epoch=o,f.__rowDataRef=p,f.parentNode!==s&&s.appendChild(f);continue}const g=f.__epoch,w=f.__rowDataRef,m=f.children.length,y=g===o&&m===a,x=w!==p;let R=!1;if(y&&x){for(let A=0;A<a;A++)if(l[A].externalView&&!f.querySelector(`.cell[data-col="${A}"] [data-external-view]`)){R=!0;break}}if(!y||R){const A=me(f),b=n._activeEditRows===h;A&&!b?(f.__isCustomRow&&(f.className="data-grid-row",f.setAttribute("role","row"),f.__isCustomRow=!1),we(f),oe(n,f,p,h),f.__epoch=o,f.__rowDataRef=p):A&&b?(be(n,f,p,h),f.__rowDataRef=p):(f.__isCustomRow&&(f.className="data-grid-row",f.setAttribute("role","row"),f.__isCustomRow=!1),oe(n,f,p,h),f.__epoch=o,f.__rowDataRef=p)}else if(x){const A=me(f),b=n._activeEditRows===h;A&&!b?(we(f),oe(n,f,p,h),f.__epoch=o,f.__rowDataRef=p):(be(n,f,p,h),f.__rowDataRef=p)}else{const A=me(f),b=n._activeEditRows===h;A&&!b?(we(f),oe(n,f,p,h),f.__epoch=o,f.__rowDataRef=p):be(n,f,p,h)}const E=n._changedRowIndices?.has(h)??!1,q=f.classList.contains("changed");E!==q&&f.classList.toggle("changed",E),f.parentNode!==s&&s.appendChild(f)}}function be(n,e,t,o){const i=e.children,r=n._visibleColumns,s=r.length,l=i.length,a=s<l?s:l,c=n._focusRow,d=n._focusCol;let u=n.__hasSpecialColumns;if(u===void 0){u=!1;for(let p=0;p<s;p++){const f=r[p];if(f.__viewTemplate||f.__compiledView||f.renderer||f.viewRenderer||f.externalView||f.format||f.type==="date"||f.type==="boolean"){u=!0;break}}n.__hasSpecialColumns=u}const h=String(o);if(!u){for(let p=0;p<a;p++){const f=i[p],g=t[r[p].field];f.textContent=g==null?"":String(g),f.getAttribute("data-row")!==h&&f.setAttribute("data-row",h);const w=c===o&&d===p,m=f.classList.contains("cell-focus");w!==m&&(f.classList.toggle("cell-focus",w),f.setAttribute("aria-selected",String(w)))}return}for(let p=0;p<a;p++)if(r[p].externalView&&!i[p].querySelector("[data-external-view]")){oe(n,e,t,o);return}for(let p=0;p<a;p++){const f=r[p],g=i[p];g.getAttribute("data-row")!==h&&g.setAttribute("data-row",h);const w=c===o&&d===p,m=g.classList.contains("cell-focus");if(w!==m&&(g.classList.toggle("cell-focus",w),g.setAttribute("aria-selected",String(w))),g.classList.contains("editing"))continue;const C=f.renderer||f.viewRenderer;if(C){const R=t[f.field],E=C({row:t,value:R,field:f.field,column:f,cellEl:g});typeof E=="string"?g.innerHTML=te(E):E instanceof Node?E.parentElement!==g&&(g.innerHTML="",g.appendChild(E)):E==null&&(g.textContent=R==null?"":String(R));continue}if(f.__viewTemplate||f.__compiledView||f.externalView)continue;const y=t[f.field];let x;if(f.format)try{const R=f.format(y,t);x=R==null?"":String(R)}catch(R){console.warn(`[tbw-grid] Format error in column '${f.field}':`,R),x=y==null?"":String(y)}else f.type==="date"?(x=Ue(y),g.textContent=x):f.type==="boolean"?g.innerHTML=$e(!!y):(x=y==null?"":String(y),g.textContent=x)}}function oe(n,e,t,o){e.innerHTML="";const i=n._visibleColumns,r=i.length,s=n._focusRow,l=n._focusCol,a=n,c=document.createDocumentFragment();for(let d=0;d<r;d++){const u=i[d],h=_o();h.setAttribute("aria-colindex",String(d+1)),h.setAttribute("data-col",String(d)),h.setAttribute("data-row",String(o)),h.setAttribute("data-field",u.field),u.type&&h.setAttribute("data-type",u.type);let p=t[u.field];if(u.format)try{p=u.format(p,t)}catch(y){console.warn(`[tbw-grid] Format error in column '${u.field}':`,y)}const f=u.__compiledView,g=u.__viewTemplate,w=u.renderer||u.viewRenderer,m=u.externalView;let C=!1;if(w){const y=w({row:t,value:p,field:u.field,column:u,cellEl:h});typeof y=="string"?(h.innerHTML=te(y),C=!0):y instanceof Node?y.parentElement!==h&&(h.textContent="",h.appendChild(y)):y==null&&(h.textContent=p==null?"":String(p))}else if(m){const y=m,x=document.createElement("div");x.setAttribute("data-external-view",""),x.setAttribute("data-field",u.field),h.appendChild(x);const R={row:t,value:p,field:u.field,column:u};if(y.mount)try{y.mount({placeholder:x,context:R,spec:y})}catch(E){console.warn(`[tbw-grid] External view mount error for column '${u.field}':`,E)}else queueMicrotask(()=>{try{a.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:x,spec:y,context:R}}))}catch(E){console.warn(`[tbw-grid] External view event dispatch error for column '${u.field}':`,E)}});x.setAttribute("data-mounted","")}else if(f){const y=f({row:t,value:p,field:u.field,column:u}),x=f.__blocked;h.innerHTML=x?"":te(y),C=!0,x&&(h.textContent="",h.setAttribute("data-blocked-template",""))}else if(g){const y=g.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(y)?(h.textContent="",h.setAttribute("data-blocked-template","")):(h.innerHTML=te(pe(y,{row:t,value:p})),C=!0)}else u.type==="date"?h.textContent=Ue(p):u.type==="boolean"?h.innerHTML=$e(!!p):h.textContent=p==null?"":String(p);if(C){bo(h);const y=h.textContent||"";/Proxy|Reflect\.ownKeys/.test(y)&&(h.textContent=y.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===o&&l===d?(h.classList.add("cell-focus"),h.setAttribute("aria-selected","true")):h.setAttribute("aria-selected","false"),c.appendChild(h)}e.appendChild(c)}function it(n,e,t,o){if(e.target?.closest(".resize-handle"))return;const i=t.querySelector(".cell[data-row]"),r=ge(i);if(r<0)return;const s=n._rows[r];if(!s||n._dispatchRowClick?.(e,r,s,t))return;const l=e.target?.closest(".cell[data-col]");if(l){const a=Number(l.getAttribute("data-col"));if(!isNaN(a)){if(n._dispatchCellClick?.(e,r,a,l))return;const c=n._focusRow!==r||n._focusCol!==a;if(n._focusRow=r,n._focusCol=a,l.classList.contains("editing")){c&&(W(n.shadowRoot??n._bodyEl),l.classList.add("cell-focus"));const d=l.querySelector(tt);try{d?.focus({preventScroll:!0})}catch{}return}$(n)}}}function ko(n,e){if(n._dispatchKeyDown?.(e))return;const t=n._rows.length-1,o=n._visibleColumns.length-1,i=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"))&&!(i&&(s==="select"||s==="typeahead")&&(e.key==="ArrowDown"||e.key==="ArrowUp"))){switch(e.key){case"Tab":{e.preventDefault(),!e.shiftKey?n._focusCol<o?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=o),$(n);return}case"ArrowDown":i&&typeof n.commitActiveRowEdit=="function"&&n.commitActiveRowEdit(),n._focusRow=Math.min(t,n._focusRow+1),e.preventDefault();break;case"ArrowUp":i&&typeof n.commitActiveRowEdit=="function"&&n.commitActiveRowEdit(),n._focusRow=Math.max(0,n._focusRow-1),e.preventDefault();break;case"ArrowRight":n._focusCol=Math.min(o,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)&&(i&&typeof n.commitActiveRowEdit=="function"&&n.commitActiveRowEdit(),n._focusRow=0),n._focusCol=0,e.preventDefault(),$(n,{forceScrollLeft:!0});return;case"End":(e.ctrlKey||e.metaKey)&&(i&&typeof n.commitActiveRowEdit=="function"&&n.commitActiveRowEdit(),n._focusRow=t),n._focusCol=o,e.preventDefault(),$(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":n.dispatchEvent(new CustomEvent("activate-cell",{detail:{row:n._focusRow,col:n._focusCol}}));break;default:return}$(n)}}function $(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),W(n._bodyEl),Array.from(n._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(s=>{s.setAttribute("aria-selected","false")});const o=n._focusRow,i=n._virtualization.start??0,r=n._virtualization.end??n._rows.length;if(o>=i&&o<r){const s=n._bodyEl.querySelectorAll(".data-grid-row")[o-i],l=s?.children[n._focusCol];if(l){l.classList.add("cell-focus"),l.setAttribute("aria-selected","true");const a=n.shadowRoot?.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,p=h+d.width,f=a.scrollLeft+c.left,g=a.scrollLeft+a.clientWidth-c.right;h<f?a.scrollLeft=h-c.left:p>g&&(a.scrollLeft=p-a.clientWidth+c.right)}}if(n._activeEditRows!==void 0&&n._activeEditRows!==-1&&l.classList.contains("editing")){const c=l.querySelector(tt);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{}}}}}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 Lo{#e;#s=0;#d=0;#c=null;#r=null;#n=null;#f=!1;constructor(e){this.#e=e}requestPhase(e,t){e>this.#s&&(this.#s=e),this.#d===0&&(this.#h(),this.#d=requestAnimationFrame(()=>this.#p()))}whenReady(){return this.#c?this.#c:Promise.resolve()}setInitialReadyResolver(e){this.#n=e}cancel(){this.#d!==0&&(cancelAnimationFrame(this.#d),this.#d=0),this.#s=0,this.#r&&(this.#r(),this.#r=null,this.#c=null)}get isPending(){return this.#s!==0}get pendingPhase(){return this.#s}#h(){this.#c||(this.#c=new Promise(e=>{this.#r=e}))}#p(){if(this.#d=0,!this.#e.isConnected()){this.#s=0,this.#r&&(this.#r(),this.#r=null,this.#c=null);return}const e=this.#s;this.#s=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.#f&&this.#n&&(this.#f=!0,this.#n()),this.#r&&(this.#r(),this.#r=null,this.#c=null)}}function Po(n){let e=null,t=null,o=null,i=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),o!==null&&(document.documentElement.style.cursor=o,o=null),i!==null&&(document.body.style.userSelect=i,i=null),e=null,a&&n.requestStateChange&&n.requestStateChange()};return{get isResizing(){return e!==null||s},start(a,c,d){a.preventDefault();const u=d.getBoundingClientRect();e={startX:a.clientX,colIndex:c,startWidth:u.width},window.addEventListener("mousemove",r),window.addEventListener("mouseup",l),o===null&&(o=document.documentElement.style.cursor),document.documentElement.style.cursor="e-resize",i===null&&(i=document.body.style.userSelect),document.body.style.userSelect="none"},resetColumn(a){const 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 de(n,e,t){const o=document.createElement(n);if(e)for(const i in e){const r=e[i];r!=null&&o.setAttribute(i,r)}return o}function H(n,e){const t=document.createElement("div");if(n&&(t.className=n),e)for(const o in e){const i=e[o];i!=null&&t.setAttribute(o,i)}return t}function rt(n,e,t){const o=document.createElement("button");if(n&&(o.className=n),e)for(const i in e){const r=e[i];r!=null&&o.setAttribute(i,r)}return o}function st(n){const e=document.createElement("slot");return n&&(e.name=n),e}const lt=document.createElement("template");lt.innerHTML=`
|
|
1
|
+
(function(v,V){typeof exports=="object"&&typeof module<"u"?V(exports):typeof define=="function"&&define.amd?define(["exports"],V):(v=typeof globalThis<"u"?globalThis:v||self,V(v.TbwGrid={}))})(this,(function(v){"use strict";const V=':root{color-scheme:light dark}:host{--tbw-color-bg: transparent;--tbw-color-panel-bg: light-dark(#eeeeee, #222222);--tbw-color-fg: light-dark(#222222, #eeeeee);--tbw-color-fg-muted: light-dark(#555555, #aaaaaa);--tbw-color-accent: light-dark(#3b82f6, #3b82f6);--tbw-color-accent-fg: light-dark(#ffffff, #000000);--tbw-color-success: light-dark(hsl(122, 39%, 40%), hsl(122, 39%, 49%));--tbw-color-selection: light-dark(#fff7d6, #333333);--tbw-color-row-alt: var(--tbw-color-bg);--tbw-color-row-hover: light-dark(#f0f6ff, #1c1c1c);--tbw-color-header-bg: color-mix(in hsl, var(--tbw-color-panel-bg) 85%, var(--tbw-color-fg));--tbw-color-header-fg: color-mix(in hsl, var(--tbw-color-fg) 75%, var(--tbw-color-panel-bg));--tbw-color-border: light-dark(#d0d0d4, #454545);--tbw-color-border-strong: light-dark(#777777, #adacac);--tbw-color-border-cell: var(--tbw-color-border);--tbw-color-border-header: var(--tbw-color-border);--tbw-color-shadow: light-dark(rgba(0, 0, 0, .1), rgba(0, 0, 0, .3));--tbw-font-family: inherit;--tbw-font-size: inherit;--tbw-font-size-header: var(--tbw-font-size);--tbw-font-weight-header: bold;--tbw-cell-padding-header: 2px 8px;--tbw-cell-padding: 2px 8px;--tbw-cell-padding-input: 2px 6px;--tbw-row-height: 28px;--tbw-header-height: 30px;--tbw-cell-white-space: nowrap;--tbw-border-radius: 4px;--tbw-border-input: 1px solid var(--tbw-color-border-strong);--tbw-border-header: 1px solid var(--tbw-color-border-header);--tbw-row-divider: 1px solid var(--tbw-color-border-cell);--tbw-row-hover-outline: 0;--tbw-color-active-row-bg: var(--tbw-color-selection);--tbw-active-row-outline: 0;--tbw-focus-outline: 2px solid var(--tbw-color-accent);--tbw-focus-outline-offset: -2px;--tbw-focus-background: rgba(from var(--tbw-color-accent) r g b / 12%);--tbw-range-border-color: var(--tbw-color-accent);--tbw-range-selection-bg: rgba(from var(--tbw-range-border-color) r g b / 12%);--tbw-resize-handle-width: 6px;--tbw-resize-handle-color: transparent;--tbw-resize-handle-color-hover: var(--tbw-color-accent);--tbw-resize-handle-border-radius: 0;--tbw-scrollbar-thumb: var(--tbw-color-border-strong);--tbw-scrollbar-track: var(--tbw-color-bg);--tbw-transition-duration: .12s;--tbw-transition-ease: ease;--tbw-animation-duration: .2s;--tbw-animation-easing: ease-out;--tbw-animation-enabled: 1;--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-border: var(--tbw-border-input, 1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input: var(--tbw-cell-padding-input, 2px 6px);--tbw-font-size-editor: inherit;--tbw-editing-row-bg: var(--tbw-editing-bg);--tbw-editing-row-outline-color: var(--tbw-color-accent);--tbw-editing-row-outline-width: 1px;--tbw-sort-indicator-color: var(--tbw-color-fg-muted);--tbw-sort-indicator-active-color: var(--tbw-color-accent);--tbw-header-text-transform: none;--tbw-header-letter-spacing: normal;--tbw-color-header-separator: var(--tbw-color-border-cell);--tbw-checkbox-size: 16px;--tbw-density-scale: 1}:host{position:relative;display:block;width:100%;height:100%;min-height:0;contain:content;font-family:var(--tbw-font-family);font-size:var(--tbw-font-size);background:var(--tbw-color-bg);color:var(--tbw-color-fg);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);overflow:clip;outline:none}:host,:host *{box-sizing:border-box}:host .header{display:block;flex-shrink:0;z-index:var(--tbw-z-layer-header, 30);background:var(--tbw-color-header-bg);overflow:visible}:host .header-group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-color-header-bg);z-index:var(--tbw-z-layer-header, 30)}:host .header-group-cell{display:flex;align-items:center;justify-content:flex-start;padding:var(--tbw-cell-padding-header, 2px 8px);color:var(--tbw-color-header-group-fg, var(--tbw-color-header-fg));font-weight:var(--tbw-font-weight-header-group, var(--tbw-font-weight-header));justify-content:var(--tbw-align-header-group, var(--tbw-align-header, flex-start))}:host .header-row{display:grid;grid-template-columns:var(--tbw-column-template);color:var(--tbw-color-header-fg);font-size:var(--tbw-font-size-header);min-height:var(--tbw-header-height);border-bottom:var(--tbw-border-header);z-index:var(--tbw-z-layer-header, 30)}:host .header-row>.cell{display:flex;align-items:center;gap:4px;padding:var(--tbw-cell-padding-header, 2px 8px);background-color:var(--tbw-color-header-bg);font-weight:var(--tbw-font-weight-header);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}:host .header-row>.cell>span:first-child{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}:host .header-row>.cell>span[part~=sort-indicator]{flex-shrink:0;opacity:.6}:host .header-row>.cell:last-child{border-right:0}:host .header-group-cell:not(:last-child),:host .header-row>.cell.grouped.group-end:not(:last-child){border-right:2px solid var(--tbw-color-border)}:host .tbw-grid-root{display:flex;flex-direction:column;height:100%}:host .rows-body-wrapper{flex:1;min-height:0;display:flex;flex-direction:row;width:100%;min-width:fit-content}:host .rows-body{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow:visible}:host .rows-container{display:flex;flex-direction:row;flex:1;min-height:0;overflow:visible}:host .rows-viewport{flex:1;min-width:0;position:relative;display:block;overflow:clip}:host .faux-vscroll{position:sticky;inset-inline-end:0;flex-shrink:0;width:auto;overflow-y:auto;overflow-x:hidden;z-index:var(--tbw-z-layer-header, 30)}:host .faux-vscroll-spacer{width:1px}:host .rows-viewport .rows{position:absolute;top:0;left:0;min-width:100%;will-change:transform;z-index:var(--tbw-z-layer-rows, 1)}:host .data-grid-row{display:grid;grid-template-columns:var(--tbw-column-template);contain:layout style;content-visibility:auto;contain-intrinsic-size:auto var(--tbw-row-height)}:host .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))}:host .selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}:host .data-grid-row>.cell.selected:focus-visible,:host .data-grid-row>.cell:focus-visible:not(.cell-focus){outline:none}:host .data-grid-row>.cell{display:block;padding:var(--tbw-cell-padding, 2px 8px);border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height);line-height:calc(var(--tbw-row-height) - 5px);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0;white-space:var(--tbw-cell-white-space, nowrap);text-overflow:ellipsis}:host .data-grid-row>.cell>*{overflow:hidden;text-overflow:ellipsis;white-space:inherit;min-width:0}:host .data-grid-row>.cell:last-child{border-right:0}:host .data-grid-row>.cell[data-type=boolean]{text-align:center}:host .data-grid-row>.cell[data-type=boolean] input[type=checkbox]{margin:0;width:var(--tbw-checkbox-size);height:var(--tbw-checkbox-size);vertical-align:middle}:host .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex;min-height:calc(var(--tbw-row-height) + 2px)}:host .data-grid-row>.cell.editing input:not([type=checkbox]),:host .data-grid-row>.cell.editing select,:host .data-grid-row>.cell.editing textarea{width:100%;height:100%;flex:1 1 auto;min-width:0;border:var(--tbw-editing-border);padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor)}:host .data-grid-row:nth-child(2n){background:var(--tbw-color-row-alt)}:host .data-grid-row:hover{background:var(--tbw-color-row-hover)}:host .sortable{cursor:pointer;-webkit-user-select:none;user-select:none}:host .header-row>.cell.resizable{position:relative}:host .tbw-editor-host{display:contents}:host .resize-handle{position:absolute;top:0;right:calc(var(--tbw-resize-handle-width) / -2);width:var(--tbw-resize-handle-width);height:100%;cursor:e-resize;-webkit-user-select:none;user-select:none;touch-action:none;z-index:20;background:var(--tbw-resize-handle-color);transition:background .12s ease;border-radius:var(--tbw-resize-handle-border-radius)}:host .resize-handle:hover{background:var(--tbw-resize-handle-color-hover)}:host .cell-focus,:host .row-focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}:host .sticky-left,:host .sticky-right{position:sticky;z-index:25}:host .header-row>.cell.sticky-left,:host .header-row>.cell.sticky-right{background:var(--tbw-color-header-bg);z-index:35}:host .data-grid-row>.cell.sticky-left,:host .data-grid-row>.cell.sticky-right{background:var(--tbw-color-panel-bg)}:host .sticky-left{box-shadow:1px 0 0 var(--tbw-color-border)}:host .sticky-right{box-shadow:-1px 0 0 var(--tbw-color-border)}:host{--tbw-shell-header-height: 44px;--tbw-shell-header-bg: var(--tbw-color-panel-bg);--tbw-shell-header-border: var(--tbw-color-border);--tbw-shell-title-font-size: 14px;--tbw-shell-title-font-weight: 600;--tbw-tool-panel-width: 280px;--tbw-tool-panel-bg: var(--tbw-color-panel-bg);--tbw-tool-panel-border: var(--tbw-color-border);--tbw-tool-panel-header-height: 40px;--tbw-tool-panel-transition: var(--tbw-animation-duration) var(--tbw-animation-easing);--tbw-toolbar-button-size: 32px;--tbw-toolbar-button-gap: 4px}:host .tbw-grid-root.has-shell{display:flex;flex-direction:column;height:100%}:host .tbw-shell-header{display:flex;align-items:center;gap:8px;min-height:var(--tbw-shell-header-height);padding:0 8px;background:var(--tbw-shell-header-bg);border-bottom:1px solid var(--tbw-shell-header-border);flex-shrink:0}:host .tbw-shell-title{font-size:var(--tbw-shell-title-font-size);font-weight:var(--tbw-shell-title-font-weight);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host .tbw-shell-content{flex:1;display:flex;align-items:center;gap:12px;min-width:0;overflow:hidden}:host .tbw-shell-toolbar{display:flex;align-items:center;gap:var(--tbw-toolbar-button-gap);flex-shrink:0}:host .tbw-toolbar-btn{display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-toolbar-button-size);height:var(--tbw-toolbar-button-size);padding:0;border:1px solid transparent;border-radius:var(--tbw-border-radius);background:transparent;color:var(--tbw-color-fg);cursor:pointer;font-size:16px;transition:background var(--tbw-transition-duration) var(--tbw-transition-ease),border-color var(--tbw-transition-duration) var(--tbw-transition-ease)}:host .tbw-toolbar-btn:hover{background:var(--tbw-color-row-hover)}:host .tbw-toolbar-btn:focus-visible{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}:host .tbw-toolbar-btn.active{background:var(--tbw-focus-background);border-color:var(--tbw-color-accent)}:host .tbw-toolbar-btn:disabled{opacity:.5;cursor:not-allowed}:host .tbw-toolbar-separator{width:1px;height:20px;background:var(--tbw-color-border);margin:0 4px}:host .tbw-shell-body{position:relative;display:flex;flex:1;min-height:0;overflow:visible}:host .tbw-grid-content{flex:1;min-width:0;min-height:0;display:flex;flex-direction:row;overflow:hidden}:host .tbw-scroll-area{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow-x:auto;overflow-y:hidden;overflow-anchor:none}:host .tbw-tool-panel{position:absolute;top:0;bottom:0;right:0;width:0;overflow:hidden;background:var(--tbw-tool-panel-bg);border-left:1px solid var(--tbw-tool-panel-border);transition:width var(--tbw-tool-panel-transition);display:flex;flex-direction:column;z-index:30;box-shadow:-2px 0 8px var(--tbw-color-shadow)}:host .tbw-tool-panel[data-position=left]{right:auto;left:0;border-left:none;border-right:1px solid var(--tbw-tool-panel-border);box-shadow:2px 0 8px var(--tbw-color-shadow)}:host .tbw-tool-panel.open{width:var(--tbw-tool-panel-width)}:host .tbw-tool-panel-resize{position:absolute;top:0;bottom:0;width:6px;cursor:col-resize;background:transparent;z-index:10;transition:background var(--tbw-transition-duration) var(--tbw-transition-ease)}:host .tbw-tool-panel-resize[data-handle-position=left]{left:0}:host .tbw-tool-panel-resize[data-handle-position=right]{right:0}:host .tbw-tool-panel-resize:hover,:host .tbw-tool-panel-resize.resizing{background:var(--tbw-color-accent)}:host .tbw-tool-panel-header{display:flex;align-items:center;justify-content:space-between;min-height:var(--tbw-tool-panel-header-height);padding:0 12px;border-bottom:1px solid var(--tbw-tool-panel-border);flex-shrink:0}:host .tbw-tool-panel-title{font-weight:600;font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host .tbw-tool-panel-close{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;padding:0;border:none;border-radius:var(--tbw-border-radius);background:transparent;color:var(--tbw-color-fg-muted);cursor:pointer;font-size:14px}:host .tbw-tool-panel-close:hover{background:var(--tbw-color-row-hover);color:var(--tbw-color-fg)}:host .tbw-tool-panel-content{flex:1;overflow:auto}:host .tbw-accordion{display:flex;flex-direction:column;gap:0}:host .tbw-accordion-section{border-bottom:1px solid var(--tbw-tool-panel-border)}:host .tbw-accordion-section:last-child{border-bottom:none}:host .tbw-accordion-header{display:flex;align-items:center;gap:8px;width:100%;padding:10px 12px;border:none;background:transparent;color:var(--tbw-color-fg);font-size:13px;font-weight:600;text-align:left;cursor:pointer;-webkit-user-select:none;user-select:none}:host .tbw-accordion-header:hover{background:var(--tbw-color-row-hover)}:host .tbw-accordion-section.single .tbw-accordion-header{cursor:default}:host .tbw-accordion-section.single .tbw-accordion-header:hover{background:transparent}:host .tbw-accordion-chevron{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:10px;color:var(--tbw-color-fg-muted);transition:transform .15s ease;flex-shrink:0}:host .tbw-accordion-section.expanded .tbw-accordion-chevron{transform:rotate(90deg)}:host .tbw-accordion-icon{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:14px;flex-shrink:0}:host .tbw-accordion-title{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}:host .tbw-accordion-content{display:none}:host .tbw-accordion-section.expanded .tbw-accordion-content{display:block}@media(forced-colors:active){:host{--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}:host .cell:focus,:host .cell.active-cell{outline:2px solid Highlight!important;outline-offset:-2px}:host .data-grid-row[aria-selected=true]{background:Highlight!important;color:HighlightText!important}}@media(prefers-reduced-motion:reduce){:host([data-animation-mode="reduced-motion"]){--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms}}:host([data-animation-mode="off"]){--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms}:host .tbw-expanding{animation:tbw-expand var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}:host .tbw-collapsing{animation:tbw-collapse var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}@keyframes tbw-expand{0%{opacity:0;max-height:0;transform:translateY(-8px)}to{opacity:1;max-height:500px;transform:translateY(0)}}@keyframes tbw-collapse{0%{opacity:1;max-height:500px;transform:translateY(0)}to{opacity:0;max-height:0;transform:translateY(-8px)}}',$={STRETCH:"stretch",FIXED:"fixed"},Be={mode:"reduced-motion",duration:200,easing:"ease-out"},O={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰"};function ro(n){return Array.from(n.querySelectorAll("tbw-grid-column")).map(t=>{const o=t.getAttribute("field")||"";if(!o)return null;const i=t.getAttribute("type")||void 0,s=i&&new Set(["number","string","date","boolean","select","typeahead"]).has(i)?i:void 0,l=t.getAttribute("header")||void 0,a=t.hasAttribute("sortable"),c=t.hasAttribute("editable"),d={field:o,type:s,header:l,sortable:a,editable:c},u=t.getAttribute("width");if(u){const b=parseFloat(u);!isNaN(b)&&/^\d+(\.\d+)?$/.test(u.trim())?d.width=b:d.width=u}const h=t.getAttribute("minWidth")||t.getAttribute("min-width");if(h){const b=parseFloat(h);isNaN(b)||(d.minWidth=b)}t.hasAttribute("resizable")&&(d.resizable=!0),t.hasAttribute("sizable")&&(d.resizable=!0);const p=t.getAttribute("editor"),f=t.getAttribute("renderer");p&&(d.__editorName=p),f&&(d.__rendererName=f);const g=t.getAttribute("options");g&&(d.options=g.split(",").map(b=>{const[_,M]=b.includes(":")?b.split(":"):[b.trim(),b.trim()];return{value:_.trim(),label:M?.trim()||_.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 x=globalThis.DataGridElement?.getAdapters?.()??[],R=w??t,E=x.find(b=>b.canHandle(R));if(E){const b=E.createRenderer(R);b&&(d.viewRenderer=b)}const q=m??t,A=x.find(b=>b.canHandle(q));if(A){const b=A.createEditor(q);b&&(d.editor=b)}return d}).filter(t=>!!t)}function Ge(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(i=>{const r=t[i.field];if(r){i.header&&!r.header&&(r.header=i.header),i.type&&!r.type&&(r.type=i.type),i.sortable&&(r.sortable=!0),i.editable&&(r.editable=!0),i.resizable&&(r.resizable=!0),i.width!=null&&r.width==null&&(r.width=i.width),i.minWidth!=null&&r.minWidth==null&&(r.minWidth=i.minWidth),i.__viewTemplate&&(r.__viewTemplate=i.__viewTemplate),i.__editorTemplate&&(r.__editorTemplate=i.__editorTemplate),i.__headerTemplate&&(r.__headerTemplate=i.__headerTemplate);const s=i.renderer||i.viewRenderer,l=r.renderer||r.viewRenderer;s&&!l&&(r.viewRenderer=s,i.renderer&&(r.renderer=s)),i.editor&&!r.editor&&(r.editor=i.editor)}else t[i.field]={...i}});const o=n.map(i=>{const r=t[i.field];if(!r)return i;const s={...i};r.header&&!s.header&&(s.header=r.header),r.type&&!s.type&&(s.type=r.type),s.sortable=i.sortable||r.sortable,(i.resizable===!0||r.resizable===!0)&&(s.resizable=!0),s.editable=i.editable||r.editable,r.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[i.field],s});return Object.keys(t).forEach(i=>o.push(t[i])),o}function Ke(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 Ve(n){const e=n.effectiveConfig?.fitMode||n.fitMode||$.STRETCH;if(e!==$.STRETCH&&e!==$.FIXED||n.__didInitialAutoSize||!n.isConnected)return;const t=Array.from(n._headerRowEl?.children||[]);if(!t.length)return;let o=!1;n._visibleColumns.forEach((i,r)=>{if(i.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&&(i.width=l+2,i.__autoSized=!0,o=!0)}),o&&te(n),n.__didInitialAutoSize=!0}function te(n){(n.effectiveConfig?.fitMode||n.fitMode||$.STRETCH)===$.STRETCH?n._gridTemplate=n._visibleColumns.map(t=>{if(t.width)return`${t.width}px`;const o=t.minWidth;return o!=null?`minmax(${o}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 so(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 lo(n,e){const t=n[0]||{},o=Object.keys(t).map(r=>{const s=t[r],l=so(s);return{field:r,header:r.charAt(0).toUpperCase()+r.slice(1),type:l}}),i={};return o.forEach(r=>{i[r.field]=r.type||"string"}),{columns:o,typeMap:i}}const ao=/{{\s*([^}]+)\s*}}/g,I="__DG_EMPTY__",co=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,uo=/__(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 ho(n){return!n||typeof n!="string"?"":n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const fo=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"]),$e=/^on\w+$/i,po=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),go=/^\s*(javascript|vbscript|data|blob):/i;function oe(n){if(!n||typeof n!="string")return"";if(n.indexOf("<")===-1)return n;const e=document.createElement("template");return e.innerHTML=n,mo(e.content),e.innerHTML}function mo(n){const e=[],t=n.querySelectorAll("*");for(const o of t){const i=o.tagName.toLowerCase();if(fo.has(i)){e.push(o);continue}if((i==="svg"||o.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(o.attributes).some(l=>$e.test(l.name)||l.name==="href"||l.name==="xlink:href")){e.push(o);continue}const r=[];for(const s of o.attributes){const l=s.name.toLowerCase();if($e.test(l)){r.push(s.name);continue}if(po.has(l)&&go.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=>o.removeAttribute(s))}e.forEach(o=>o.remove())}function ge(n,e){if(!n||n.indexOf("{{")===-1)return n;const t=[],o=n.replace(ao,(l,a)=>{const c=wo(a,e);return t.push({expr:a.trim(),result:c}),c}),i=bo(o),r=t.length&&t.every(l=>l.result===""||l.result===I);return/Reflect\.|\bProxy\b|ownKeys\(/.test(n)||r?"":i}function wo(n,e){if(n=(n||"").trim(),!n||/\b(Reflect|Proxy|ownKeys)\b/.test(n))return I;if(n==="value")return e.value==null?I:String(e.value);if(n.startsWith("row.")&&!/[()?]/.test(n)&&!n.includes(":")){const o=n.slice(4),i=e.row?e.row[o]:void 0;return i==null?I:String(i)}if(n.length>80||!co.test(n)||uo.test(n))return I;const t=n.match(/\./g);if(t&&t.length>1)return I;try{const i=new Function("value","row",`return (${n});`)(e.value,e.row),r=i==null?"":String(i);return/Reflect|Proxy|ownKeys/.test(r)?I:r||I}catch{return I}}function bo(n){return n&&n.replace(new RegExp(I,"g"),"").replace(/Reflect\.[^<>{}\s]+/g,"").replace(/\bProxy\b/g,"").replace(/ownKeys\([^)]*\)/g,"")}function vo(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 We(n){const e=/Reflect\.|\bProxy\b|ownKeys\(/.test(n),t=(o=>e?"":ge(n,o));return t.__blocked=e,t}const yo=100;class Co{#e;#s;#d;#c;#r;#n;#f={};#h={};#p=!0;#l=[];#m;#g;#w;#a;#v;constructor(e){this.#a=e}get original(){return this.#f}get effective(){return this.#h}get columns(){return this.#h.columns??[]}set columns(e){this.#h.columns=e}get lightDomColumnsCache(){return this.#r}set lightDomColumnsCache(e){this.#r=e}get originalColumnNodes(){return this.#n}set originalColumnNodes(e){this.#n=e}get lightDomTitle(){return this.#v}set lightDomTitle(e){this.#v=e}get initialColumnState(){return this.#w}set initialColumnState(e){this.#w=e}get sourcesChanged(){return this.#p}markSourcesChanged(){this.#p=!0}setGridConfig(e){this.#e=e,this.#p=!0,this.#r=void 0}getGridConfig(){return this.#e}setColumns(e){this.#s=e,this.#p=!0}getColumns(){return this.#s}setFitMode(e){this.#d=e,this.#p=!0}getFitMode(){return this.#d}setEditOn(e){this.#c=e,this.#p=!0}getEditOn(){return this.#c}merge(){const e=(this.#h.columns?.length??0)>0;if(!this.#p&&e)return;const t=this.#C();this.#p=!1,this.#f=t,Object.freeze(this.#f),this.#f.columns&&Object.freeze(this.#f.columns),this.#h=this.#T(this.#f),this.#b()}#T(e){const t={...e};return e.columns&&(t.columns=e.columns.map(o=>({...o}))),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(o=>({...o})),headerContents:e.shell.headerContents?.map(o=>({...o}))}),t}#b(){const e=this.#h;e.rowHeight&&e.rowHeight>0&&this.#a.setRowHeight(e.rowHeight),e.fitMode==="fixed"&&this.columns.forEach(o=>{o.width==null&&(o.width=80)}),this.#a.applyAnimationConfig(e)}#C(){const e=this.#e?{...this.#e}:{},t=Array.isArray(e.columns)?[...e.columns]:[],o=(this.#r??[]).map(s=>({...s}));let i=Ge(t,o);this.#s&&this.#s.length&&(i=Ge(this.#s,o));const r=this.#a.getRows();return i.length===0&&r.length&&(i=lo(r).columns),i.length&&(i.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)}),i.forEach(s=>{s.__viewTemplate&&!s.__compiledView&&(s.__compiledView=We(s.__viewTemplate.innerHTML)),s.__editorTemplate&&!s.__compiledEditor&&(s.__compiledEditor=We(s.__editorTemplate.innerHTML))}),e.columns=i),this.#d&&(e.fitMode=this.#d),e.fitMode||(e.fitMode="stretch"),this.#c&&(e.editOn=this.#c),this.#x(e),e.columnState&&!this.#w&&(this.#w=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.#v=t),this.#v&&!e.shell.header.title&&(e.shell.header.title=this.#v);const o=this.#a.getShellLightDomHeaderContent();o?.length>0&&(e.shell.header.lightDomContent=o),this.#a.getShellHasToolButtonsContainer()&&(e.shell.header.hasToolButtonsContainer=!0);const i=this.#a.getShellToolPanels();if(i.size>0){const u=Array.from(i.values());u.sort((h,p)=>(h.order??100)-(p.order??100)),e.shell.toolPanels=u}const r=this.#a.getShellHeaderContents();if(r.size>0){const u=Array.from(r.values());u.sort((h,p)=>(h.order??100)-(p.order??100)),e.shell.headerContents=u}const s=this.#a.getShellToolbarButtons(),l=Array.from(s.values()),a=this.#e?.shell?.header?.toolbarButtons??[],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??100)-(h.order??100)),e.shell.header.toolbarButtons=d}collectState(e){const t=this.columns,o=this.#y();return{columns:t.map((i,r)=>{const s={field:i.field,order:r,visible:!i.hidden},l=i;l.__renderedWidth!==void 0?s.width=l.__renderedWidth:i.width!==void 0&&(s.width=typeof i.width=="string"?parseFloat(i.width):i.width);const a=o.get(i.field);a&&(s.sort=a);for(const c of e)if(c.getColumnState){const d=c.getColumnState(i.field);d&&Object.assign(s,d)}return s})}}applyState(e,t){if(!e.columns||e.columns.length===0)return;const o=this.columns,i=new Map(e.columns.map(l=>[l.field,l])),r=o.map(l=>{const a=i.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=i.get(l.field)?.order??1/0,d=i.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.#w=void 0,this.#a.setSortState(null),this.#h=this.#T(this.#f),this.#b();for(const t of e)if(t.applyColumnState)for(const o of this.columns)t.applyColumnState(o.field,{field:o.field,order:0,visible:!0});this.requestStateChange(e)}#y(){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.#g&&clearTimeout(this.#g),this.#g=setTimeout(()=>{this.#g=void 0;const t=this.collectState(e);this.#a.emit("column-state-change",t)},yo)}setColumnVisible(e,t){const o=this.columns,i=o.find(s=>s.field===e);return!i||!t&&i.lockVisible||!t&&o.filter(l=>!l.hidden&&l.field!==e).length===0||!!i.hidden===!t?!1:(i.hidden=!t,this.#a.emit("column-visibility",{field:e,visible:t,visibleColumns:o.filter(s=>!s.hidden).map(s=>s.field)}),this.#a.clearRowPool(),this.#a.setup(),!0)}toggleColumnVisibility(e){const t=this.columns.find(o=>o.field===e);return t?this.setColumnVisible(e,!!t.hidden):!1}isColumnVisible(e){const t=this.columns.find(o=>o.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}))}getColumnOrder(){return this.columns.map(e=>e.field)}setColumnOrder(e){if(!e.length)return;const t=new Map(this.columns.map(i=>[i.field,i])),o=[];for(const i of e){const r=t.get(i);r&&(o.push(r),t.delete(i))}for(const i of t.values())o.push(i);this.columns=o,this.#a.renderHeader(),this.#a.updateTemplate(),this.#a.refreshVirtualWindow()}parseLightDomColumns(e){this.#r||(this.#n=Array.from(e.querySelectorAll("tbw-grid-column")),this.#r=this.#n.length?ro(e):[])}clearLightDomCache(){this.#r=void 0}#S=new Map;registerLightDomHandler(e,t){this.#S.set(e.toLowerCase(),t)}unregisterLightDomHandler(e){this.#S.delete(e.toLowerCase())}observeLightDOM(e){this.#m&&this.#m.disconnect();const t=new Set;let o=null;const i=()=>{o=null;for(const r of t)this.#S.get(r)?.();t.clear()};this.#m=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.#S.has(c)&&t.add(c)}if(s.type==="attributes"&&s.target.nodeType===Node.ELEMENT_NODE){const a=s.target.tagName.toLowerCase();this.#S.has(a)&&t.add(a)}}t.size>0&&!o&&(o=setTimeout(i,0))}),this.#m.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["title","field","header","width","hidden","id","icon","tooltip","order"]})}onChange(e){this.#l.push(e)}notifyChange(){for(const e of this.#l)e()}dispose(){this.#m?.disconnect(),this.#l=[],this.#g&&clearTimeout(this.#g)}}function Ue(n){return`<span role="checkbox" aria-checked="${n}" aria-label="${n}">${n?"🗹":"☐"}</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");return e?parseInt(e,10):-1}function xo(n){if(!n)return-1;const e=n.getAttribute("data-col");return e?parseInt(e,10):-1}function W(n){n&&n.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function Eo(n,e){const t=me(e),o=xo(e);t<0||o<0||(n._focusRow=t,n._focusCol=o,W(n._bodyEl),e.classList.add("cell-focus"),e.setAttribute("aria-selected","true"))}function So(n,e,t){e.addEventListener("mousedown",o=>{const i=o.target.closest(".cell[data-col]");i&&(i.classList.contains("editing")||Eo(n,i))},{signal:t})}function Xe(n,e){return n==null&&e==null?0:n==null?-1:e==null||n>e?1:n<e?-1:0}function Ye(n,e,t){const i=t.find(l=>l.field===e.field)?.sortComparator??Xe,{field:r,direction:s}=e;return[...n].sort((l,a)=>i(l[r],a[r],l,a)*s)}function Ze(n,e,t,o){n._rows=e,n.__rowRenderEpoch++,n._rowPool.forEach(i=>i.__epoch=-1),ce(n),n.refreshVirtualWindow(!0),n.dispatchEvent(new CustomEvent("sort-change",{detail:{field:t.field,direction:o}})),n.requestStateChange?.()}function Je(n,e){!n._sortState||n._sortState.field!==e.field?(n._sortState||(n.__originalOrder=n._rows.slice()),Qe(n,e,1)):n._sortState.direction===1?Qe(n,e,-1):(n._sortState=null,n.__rowRenderEpoch++,n._rowPool.forEach(o=>o.__epoch=-1),n._rows=n.__originalOrder.slice(),ce(n),n._headerRowEl?.querySelectorAll('[role="columnheader"].sortable')?.forEach(o=>{o.getAttribute("aria-sort")?(o.getAttribute("aria-sort")==="ascending"||o.getAttribute("aria-sort")==="descending")&&(n._sortState||o.setAttribute("aria-sort","none")):o.setAttribute("aria-sort","none")}),n.refreshVirtualWindow(!0),n.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:0}})),n.requestStateChange?.())}function Qe(n,e,t){n._sortState={field:e.field,direction:t};const o={field:e.field,direction:t},i=n._columns,s=(n.effectiveConfig?.sortHandler??Ye)(n._rows,o,i);s&&typeof s.then=="function"?s.then(l=>{Ze(n,l,e,t)}):Ze(n,s,e,t)}function Ro(n,e){typeof e=="string"?n.textContent=e:e instanceof HTMLElement&&(n.innerHTML="",n.appendChild(e.cloneNode(!0)))}function ce(n){n._headerRowEl=n.findHeaderRow();const e=n._headerRowEl;e.innerHTML="",n._visibleColumns.forEach((t,o)=>{const i=document.createElement("div");i.className="cell",Ke(i,"header-cell"),i.setAttribute("role","columnheader"),i.setAttribute("aria-colindex",String(o+1)),i.setAttribute("data-field",t.field),i.setAttribute("data-col",String(o));const r=t.__headerTemplate;if(r)Array.from(r.childNodes).forEach(s=>i.appendChild(s.cloneNode(!0)));else{const s=t.header||t.field,l=document.createElement("span");l.textContent=s,i.appendChild(l)}if(t.sortable){i.classList.add("sortable"),i.tabIndex=0;const s=document.createElement("span");Ke(s,"sort-indicator");const l=n._sortState?.field===t.field?n._sortState.direction:0,a={...O,...n.icons},c=l===1?a.sortAsc:l===-1?a.sortDesc:a.sortNone;Ro(s,c),i.appendChild(s),i.setAttribute("aria-sort",l===0?"none":l===1?"ascending":"descending"),i.addEventListener("click",d=>{n._resizeController?.isResizing||n._dispatchHeaderClick?.(d,o,i)||Je(n,t)}),i.addEventListener("keydown",d=>{if(d.key==="Enter"||d.key===" "){if(d.preventDefault(),n._dispatchHeaderClick?.(d,o,i))return;Je(n,t)}})}if(t.resizable){i.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,o,i)}),s.addEventListener("dblclick",l=>{l.stopPropagation(),l.preventDefault(),n._resizeController.resetColumn(o)}),i.appendChild(s)}e.appendChild(i)}),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 et=typeof requestIdleCallback=="function";function _o(n,e){return et?requestIdleCallback(n,e):window.setTimeout(()=>{const t=Date.now();n({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})},1)}function tt(n){et?cancelIdleCallback(n):clearTimeout(n)}const ot='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function we(n){return(n.__editingCellCount??0)>0}function be(n){n.__editingCellCount=0,n.removeAttribute("data-has-editing"),n.querySelectorAll(".cell.editing").forEach(t=>t.classList.remove("editing"))}const nt=document.createElement("template");nt.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 Ao(){return nt.content.firstElementChild.cloneNode(!0)}function To(){return it.content.firstElementChild.cloneNode(!0)}function de(n){n.__cellDisplayCache=void 0,n.__cellCacheEpoch=void 0,n.__hasSpecialColumns=void 0}function ko(n,e,t,o,i){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.shadowRoot?.querySelector(".header-group-row")?2:1,n.__cachedHeaderRowCount=c);n._rowPool.length<r;){const u=To();u.addEventListener("click",h=>rt(n,h,u)),u.addEventListener("dblclick",h=>rt(n,h,u)),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=i&&n.__hasRenderRowPlugins!==!1;for(let u=0;u<r;u++){const h=e+u,p=n._rows[h],f=n._rowPool[u];if(f.setAttribute("aria-rowindex",String(h+c+1)),d&&i(p,f,h)){f.__epoch=o,f.__rowDataRef=p,f.parentNode!==s&&s.appendChild(f);continue}const g=f.__epoch,w=f.__rowDataRef,m=f.children.length,y=g===o&&m===a,x=w!==p;let R=!1;if(y&&x){for(let A=0;A<a;A++)if(l[A].externalView&&!f.querySelector(`.cell[data-col="${A}"] [data-external-view]`)){R=!0;break}}if(!y||R){const A=we(f),b=n._activeEditRows===h;A&&!b?(f.__isCustomRow&&(f.className="data-grid-row",f.setAttribute("role","row"),f.__isCustomRow=!1),be(f),ne(n,f,p,h),f.__epoch=o,f.__rowDataRef=p):A&&b?(ve(n,f,p,h),f.__rowDataRef=p):(f.__isCustomRow&&(f.className="data-grid-row",f.setAttribute("role","row"),f.__isCustomRow=!1),ne(n,f,p,h),f.__epoch=o,f.__rowDataRef=p)}else if(x){const A=we(f),b=n._activeEditRows===h;A&&!b?(be(f),ne(n,f,p,h),f.__epoch=o,f.__rowDataRef=p):(ve(n,f,p,h),f.__rowDataRef=p)}else{const A=we(f),b=n._activeEditRows===h;A&&!b?(be(f),ne(n,f,p,h),f.__epoch=o,f.__rowDataRef=p):ve(n,f,p,h)}const E=n._changedRowIndices?.has(h)??!1,q=f.classList.contains("changed");E!==q&&f.classList.toggle("changed",E),f.parentNode!==s&&s.appendChild(f)}}function ve(n,e,t,o){const i=e.children,r=n._visibleColumns,s=r.length,l=i.length,a=s<l?s:l,c=n._focusRow,d=n._focusCol;let u=n.__hasSpecialColumns;if(u===void 0){u=!1;for(let p=0;p<s;p++){const f=r[p];if(f.__viewTemplate||f.__compiledView||f.renderer||f.viewRenderer||f.externalView||f.format||f.type==="date"||f.type==="boolean"){u=!0;break}}n.__hasSpecialColumns=u}const h=String(o);if(!u){for(let p=0;p<a;p++){const f=i[p],g=t[r[p].field];f.textContent=g==null?"":String(g),f.getAttribute("data-row")!==h&&f.setAttribute("data-row",h);const w=c===o&&d===p,m=f.classList.contains("cell-focus");w!==m&&(f.classList.toggle("cell-focus",w),f.setAttribute("aria-selected",String(w)))}return}for(let p=0;p<a;p++)if(r[p].externalView&&!i[p].querySelector("[data-external-view]")){ne(n,e,t,o);return}for(let p=0;p<a;p++){const f=r[p],g=i[p];g.getAttribute("data-row")!==h&&g.setAttribute("data-row",h);const w=c===o&&d===p,m=g.classList.contains("cell-focus");if(w!==m&&(g.classList.toggle("cell-focus",w),g.setAttribute("aria-selected",String(w))),g.classList.contains("editing"))continue;const C=f.renderer||f.viewRenderer;if(C){const R=t[f.field],E=C({row:t,value:R,field:f.field,column:f,cellEl:g});typeof E=="string"?g.innerHTML=oe(E):E instanceof Node?E.parentElement!==g&&(g.innerHTML="",g.appendChild(E)):E==null&&(g.textContent=R==null?"":String(R));continue}if(f.__viewTemplate||f.__compiledView||f.externalView)continue;const y=t[f.field];let x;if(f.format)try{const R=f.format(y,t);x=R==null?"":String(R)}catch(R){console.warn(`[tbw-grid] Format error in column '${f.field}':`,R),x=y==null?"":String(y)}else f.type==="date"?(x=je(y),g.textContent=x):f.type==="boolean"?g.innerHTML=Ue(!!y):(x=y==null?"":String(y),g.textContent=x)}}function ne(n,e,t,o){e.innerHTML="";const i=n._visibleColumns,r=i.length,s=n._focusRow,l=n._focusCol,a=n,c=document.createDocumentFragment();for(let d=0;d<r;d++){const u=i[d],h=Ao();h.setAttribute("aria-colindex",String(d+1)),h.setAttribute("data-col",String(d)),h.setAttribute("data-row",String(o)),h.setAttribute("data-field",u.field),u.type&&h.setAttribute("data-type",u.type);let p=t[u.field];if(u.format)try{p=u.format(p,t)}catch(y){console.warn(`[tbw-grid] Format error in column '${u.field}':`,y)}const f=u.__compiledView,g=u.__viewTemplate,w=u.renderer||u.viewRenderer,m=u.externalView;let C=!1;if(w){const y=w({row:t,value:p,field:u.field,column:u,cellEl:h});typeof y=="string"?(h.innerHTML=oe(y),C=!0):y instanceof Node?y.parentElement!==h&&(h.textContent="",h.appendChild(y)):y==null&&(h.textContent=p==null?"":String(p))}else if(m){const y=m,x=document.createElement("div");x.setAttribute("data-external-view",""),x.setAttribute("data-field",u.field),h.appendChild(x);const R={row:t,value:p,field:u.field,column:u};if(y.mount)try{y.mount({placeholder:x,context:R,spec:y})}catch(E){console.warn(`[tbw-grid] External view mount error for column '${u.field}':`,E)}else queueMicrotask(()=>{try{a.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:x,spec:y,context:R}}))}catch(E){console.warn(`[tbw-grid] External view event dispatch error for column '${u.field}':`,E)}});x.setAttribute("data-mounted","")}else if(f){const y=f({row:t,value:p,field:u.field,column:u}),x=f.__blocked;h.innerHTML=x?"":oe(y),C=!0,x&&(h.textContent="",h.setAttribute("data-blocked-template",""))}else if(g){const y=g.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(y)?(h.textContent="",h.setAttribute("data-blocked-template","")):(h.innerHTML=oe(ge(y,{row:t,value:p})),C=!0)}else u.type==="date"?h.textContent=je(p):u.type==="boolean"?h.innerHTML=Ue(!!p):h.textContent=p==null?"":String(p);if(C){vo(h);const y=h.textContent||"";/Proxy|Reflect\.ownKeys/.test(y)&&(h.textContent=y.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===o&&l===d?(h.classList.add("cell-focus"),h.setAttribute("aria-selected","true")):h.setAttribute("aria-selected","false"),c.appendChild(h)}e.appendChild(c)}function rt(n,e,t,o){if(e.target?.closest(".resize-handle"))return;const i=t.querySelector(".cell[data-row]"),r=me(i);if(r<0)return;const s=n._rows[r];if(!s||n._dispatchRowClick?.(e,r,s,t))return;const l=e.target?.closest(".cell[data-col]");if(l){const a=Number(l.getAttribute("data-col"));if(!isNaN(a)){if(n._dispatchCellClick?.(e,r,a,l))return;const c=n._focusRow!==r||n._focusCol!==a;if(n._focusRow=r,n._focusCol=a,l.classList.contains("editing")){c&&(W(n.shadowRoot??n._bodyEl),l.classList.add("cell-focus"));const d=l.querySelector(ot);try{d?.focus({preventScroll:!0})}catch{}return}U(n)}}}function Lo(n,e){if(n._dispatchKeyDown?.(e))return;const t=n._rows.length-1,o=n._visibleColumns.length-1,i=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"))&&!(i&&(s==="select"||s==="typeahead")&&(e.key==="ArrowDown"||e.key==="ArrowUp"))){switch(e.key){case"Tab":{e.preventDefault(),!e.shiftKey?n._focusCol<o?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=o),U(n);return}case"ArrowDown":i&&typeof n.commitActiveRowEdit=="function"&&n.commitActiveRowEdit(),n._focusRow=Math.min(t,n._focusRow+1),e.preventDefault();break;case"ArrowUp":i&&typeof n.commitActiveRowEdit=="function"&&n.commitActiveRowEdit(),n._focusRow=Math.max(0,n._focusRow-1),e.preventDefault();break;case"ArrowRight":n._focusCol=Math.min(o,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)&&(i&&typeof n.commitActiveRowEdit=="function"&&n.commitActiveRowEdit(),n._focusRow=0),n._focusCol=0,e.preventDefault(),U(n,{forceScrollLeft:!0});return;case"End":(e.ctrlKey||e.metaKey)&&(i&&typeof n.commitActiveRowEdit=="function"&&n.commitActiveRowEdit(),n._focusRow=t),n._focusCol=o,e.preventDefault(),U(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":n.dispatchEvent(new CustomEvent("activate-cell",{detail:{row:n._focusRow,col:n._focusCol}}));break;default:return}U(n)}}function U(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),W(n._bodyEl),Array.from(n._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(s=>{s.setAttribute("aria-selected","false")});const o=n._focusRow,i=n._virtualization.start??0,r=n._virtualization.end??n._rows.length;if(o>=i&&o<r){const s=n._bodyEl.querySelectorAll(".data-grid-row")[o-i],l=s?.children[n._focusCol];if(l){l.classList.add("cell-focus"),l.setAttribute("aria-selected","true");const a=n.shadowRoot?.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,p=h+d.width,f=a.scrollLeft+c.left,g=a.scrollLeft+a.clientWidth-c.right;h<f?a.scrollLeft=h-c.left:p>g&&(a.scrollLeft=p-a.clientWidth+c.right)}}if(n._activeEditRows!==void 0&&n._activeEditRows!==-1&&l.classList.contains("editing")){const c=l.querySelector(ot);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{}}}}}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 Po{#e;#s=0;#d=0;#c=null;#r=null;#n=null;#f=!1;constructor(e){this.#e=e}requestPhase(e,t){e>this.#s&&(this.#s=e),this.#d===0&&(this.#h(),this.#d=requestAnimationFrame(()=>this.#p()))}whenReady(){return this.#c?this.#c:Promise.resolve()}setInitialReadyResolver(e){this.#n=e}cancel(){this.#d!==0&&(cancelAnimationFrame(this.#d),this.#d=0),this.#s=0,this.#r&&(this.#r(),this.#r=null,this.#c=null)}get isPending(){return this.#s!==0}get pendingPhase(){return this.#s}#h(){this.#c||(this.#c=new Promise(e=>{this.#r=e}))}#p(){if(this.#d=0,!this.#e.isConnected()){this.#s=0,this.#r&&(this.#r(),this.#r=null,this.#c=null);return}const e=this.#s;this.#s=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.#f&&this.#n&&(this.#f=!0,this.#n()),this.#r&&(this.#r(),this.#r=null,this.#c=null)}}function Ho(n){let e=null,t=null,o=null,i=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),o!==null&&(document.documentElement.style.cursor=o,o=null),i!==null&&(document.body.style.userSelect=i,i=null),e=null,a&&n.requestStateChange&&n.requestStateChange()};return{get isResizing(){return e!==null||s},start(a,c,d){a.preventDefault();const u=d.getBoundingClientRect();e={startX:a.clientX,colIndex:c,startWidth:u.width},window.addEventListener("mousemove",r),window.addEventListener("mouseup",l),o===null&&(o=document.documentElement.style.cursor),document.documentElement.style.cursor="e-resize",i===null&&(i=document.body.style.userSelect),document.body.style.userSelect="none"},resetColumn(a){const 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 ue(n,e,t){const o=document.createElement(n);if(e)for(const i in e){const r=e[i];r!=null&&o.setAttribute(i,r)}return o}function H(n,e){const t=document.createElement("div");if(n&&(t.className=n),e)for(const o in e){const i=e[o];i!=null&&t.setAttribute(o,i)}return t}function st(n,e,t){const o=document.createElement("button");if(n&&(o.className=n),e)for(const i in e){const r=e[i];r!=null&&o.setAttribute(i,r)}return o}function lt(n){const e=document.createElement("slot");return n&&(e.name=n),e}const at=document.createElement("template");at.innerHTML=`
|
|
2
2
|
<div class="tbw-scroll-area">
|
|
3
3
|
<div class="rows-body-wrapper">
|
|
4
4
|
<div class="rows-body" role="grid">
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
<div class="faux-vscroll">
|
|
17
17
|
<div class="faux-vscroll-spacer"></div>
|
|
18
18
|
</div>
|
|
19
|
-
`;function
|
|
19
|
+
`;function ct(){return at.content.cloneNode(!0)}function dt(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 o=H("tbw-grid-content");o.appendChild(ct()),t.appendChild(o)}return e.appendChild(t),e}function Mo(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"});t.appendChild(lt("header-content")),e.appendChild(t);const o=H("tbw-shell-toolbar",{part:"shell-toolbar",role:"presentation"});for(const r of n.configButtons)(r.hasElement||r.hasRender)&&o.appendChild(H("tbw-toolbar-btn-slot",{"data-btn-slot":r.id}));for(const r of n.apiButtons)(r.hasElement||r.hasRender)&&o.appendChild(H("tbw-toolbar-btn-slot",{"data-btn-slot":r.id}));if(o.appendChild(lt("toolbar")),(n.configButtons.some(r=>r.hasElement||r.hasRender)||n.apiButtons.some(r=>r.hasElement||r.hasRender))&&n.hasPanels&&o.appendChild(H("tbw-toolbar-separator")),n.hasPanels){const r=st(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,o.appendChild(r)}return e.appendChild(o),e}function Io(n){const e=H("tbw-shell-body"),t=n.panels.length>0,o=n.panels.length===1,i=H("tbw-grid-content");i.appendChild(ct());let r=null;if(t){r=ue("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":""}${o?" single":""}`,u=H(d,{"data-section":c.id}),h=st("tbw-accordion-header",{"aria-expanded":String(c.isExpanded),"aria-controls":`tbw-section-${c.id}`});if(o&&h.setAttribute("aria-disabled","true"),c.icon){const f=ue("span",{class:"tbw-accordion-icon"});f.innerHTML=c.icon,h.appendChild(f)}const p=ue("span",{class:"tbw-accordion-title"});if(p.textContent=c.title,h.appendChild(p),!o){const f=ue("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(i)):(e.appendChild(i),r&&e.appendChild(r)),e}function G(n){return n?typeof n=="string"?n:n.outerHTML:""}function Oo(){return{toolPanels:new Map,headerContents:new Map,toolbarButtons:new Map,hasToolButtonsContainer:!1,lightDomHeaderContent:[],lightDomTitle:null,lightDomToolPanelIds:new Set,apiToolPanelIds:new Set,isPanelOpen:!1,expandedSections:new Set,headerContentCleanups:new Map,panelCleanups:new Map,toolbarButtonCleanups:new Map}}function ut(n){return!!(n?.header?.title||n?.header?.toolbarButtons?.length||n?.toolPanels?.length||n?.headerContents?.length||n?.header?.lightDomContent?.length||n?.header?.hasToolButtonsContainer)}function ht(n,e,t="☰"){const o=n?.header?.title??e.lightDomTitle??"",i=!!o,r=G(t),s=n?.header?.toolbarButtons??[],l=s.some(g=>g.element||g.render),a=[...e.toolbarButtons.values()].some(g=>g.element||g.render),c=e.toolPanels.size>0,u=(l||a)&&c,h=[...s].sort((g,w)=>(g.order??100)-(w.order??100)),p=[...e.toolbarButtons.values()].sort((g,w)=>(g.order??100)-(w.order??100));let f="";for(const g of h)(g.element||g.render)&&(f+=`<div class="tbw-toolbar-btn-slot" data-btn-slot="${g.id}"></div>`);for(const g of p)(g.element||g.render)&&(f+=`<div class="tbw-toolbar-btn-slot" data-btn-slot="${g.id}"></div>`);if(f+='<slot name="toolbar"></slot>',u&&(f+='<div class="tbw-toolbar-separator"></div>'),c){const g=e.isPanelOpen;f+=`<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
|
-
${i?`<div class="tbw-shell-title">${
|
|
21
|
+
${i?`<div class="tbw-shell-title">${ho(o)}</div>`:""}
|
|
22
22
|
<div class="tbw-shell-content" part="shell-content" role="presentation">
|
|
23
23
|
<slot name="header-content"></slot>
|
|
24
24
|
</div>
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
${f}
|
|
27
27
|
</div>
|
|
28
28
|
</div>
|
|
29
|
-
`}function U(n,e){const t=n.querySelector("tbw-grid-header");if(!t)return;if(!e.lightDomTitle){const i=t.getAttribute("title");i&&(e.lightDomTitle=i)}const o=t.querySelectorAll("tbw-grid-header-content");o.length>0&&e.lightDomHeaderContent.length===0&&(e.lightDomHeaderContent=Array.from(o),e.lightDomHeaderContent.forEach(i=>{i.setAttribute("slot","header-content")})),t.style.display="none"}function j(n,e){const t=n.querySelector(":scope > tbw-grid-tool-buttons");t&&(e.hasToolButtonsContainer=!0,t.setAttribute("slot","toolbar"))}function X(n,e,t){n.querySelectorAll(":scope > tbw-grid-tool-panel").forEach(i=>{const r=i,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 p=e.toolPanels.get(s);if(p){if(h){p.render=u,p.order=d,p.icon=a,p.tooltip=c;const g=e.panelCleanups.get(s);g&&(g(),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 Oo(n,e,t,o){const i=n.querySelector(".tbw-shell-toolbar");i&&i.addEventListener("click",s=>{const l=s.target;if(l.closest("[data-panel-toggle]")){o.onPanelToggle();return}const c=l.closest("[data-btn]");if(c){const d=c.getAttribute("data-btn");d&&o.onToolbarButtonClick(d)}});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&&o.onSectionToggle(d)}})}function Do(n,e,t){const o=n.querySelector(".tbw-tool-panel"),i=n.querySelector("[data-resize-handle]"),r=n.querySelector(".tbw-shell-body");if(!o||!i||!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));o.style.width=`${m}px`},p=()=>{if(!u)return;u=!1,i.classList.remove("resizing"),o.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const g=o.getBoundingClientRect().width;t(g),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",p)},f=g=>{g.preventDefault(),u=!0,a=g.clientX,c=o.getBoundingClientRect().width,d=r.getBoundingClientRect().width-20,i.classList.add("resizing"),o.style.transition="none",document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",h),document.addEventListener("mouseup",p)};return i.addEventListener("mousedown",f),()=>{i.removeEventListener("mousedown",f),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",p)}}function No(n,e,t){const o=[...e?.header?.toolbarButtons??[],...t.toolbarButtons.values()];for(const i of o){const r=n.querySelector(`[data-btn-slot="${i.id}"]`);if(!r)continue;const s=t.toolbarButtonCleanups.get(i.id);if(s&&(s(),t.toolbarButtonCleanups.delete(i.id)),i.element)r.appendChild(i.element);else if(i.render){const l=i.render(r);l&&t.toolbarButtonCleanups.set(i.id,l)}}}function ht(n,e){const t=n.querySelector(".tbw-shell-content");if(!t)return;const o=[...e.headerContents.values()].sort((r,s)=>(r.order??100)-(s.order??100)),i=t.querySelector('slot[name="header-content"]');for(const r of o){const s=e.headerContentCleanups.get(r.id);s&&(s(),e.headerContentCleanups.delete(r.id));let l=t.querySelector(`[data-header-content="${r.id}"]`);l||(l=document.createElement("div"),l.setAttribute("data-header-content",r.id),i?t.insertBefore(l,i):t.appendChild(l));const a=r.render(l);a&&e.headerContentCleanups.set(r.id,a)}}function qo(n,e,t){if(!e.isPanelOpen)return;const o=G(t?.expand??O.expand),i=G(t?.collapse??O.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?i:o),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 ft(n,e){const t=n.querySelector("[data-panel-toggle]");t&&(t.classList.toggle("active",e.isPanelOpen),t.setAttribute("aria-pressed",String(e.isPanelOpen)))}function pt(n,e){const t=n.querySelector(".tbw-tool-panel");t&&(t.classList.toggle("open",e.isPanelOpen),e.isPanelOpen||(t.style.width=""))}function Fo(n,e){const t=[];for(const o of n?.header?.toolbarButtons??[])t.push({id:o.id,label:o.label??"",source:"config"});for(const o of e.toolbarButtons.values())t.push({id:o.id,label:o.label??"",source:"config"});for(const o of e.toolPanels.values())t.push({id:`panel-toggle-${o.id}`,label:o.tooltip??o.title,source:"panel-toggle",panelId:o.id});return t}function zo(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.toolbarButtonCleanups.values())e();if(n.toolbarButtonCleanups.clear(),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.toolbarButtons.clear(),n.lightDomHeaderContent=[]}function Bo(n,e){let t=!1;const o={get isInitialized(){return t},setInitialized(i){t=i},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 i=e.getShadow();ft(i,n),pt(i,n),qo(i,n,e.getAccordionIcons()),e.emit("tool-panel-open",{sections:o.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 i=e.getShadow();ft(i,n),pt(i,n),e.emit("tool-panel-close",{})},toggleToolPanel(){n.isPanelOpen?o.closeToolPanel():o.openToolPanel()},toggleToolPanelSection(i){const r=n.toolPanels.get(i);if(!r){console.warn(`[tbw-grid] Tool panel section "${i}" not found`);return}if(n.toolPanels.size===1)return;const s=e.getShadow(),l=n.expandedSections.has(i);if(l){const a=n.panelCleanups.get(i);a&&(a(),n.panelCleanups.delete(i)),r.onClose?.(),n.expandedSections.delete(i),ve(s,i,!1)}else{for(const[a,c]of n.toolPanels)if(a!==i&&n.expandedSections.has(a)){const d=n.panelCleanups.get(a);d&&(d(),n.panelCleanups.delete(a)),c.onClose?.(),n.expandedSections.delete(a),ve(s,a,!1);const u=s.querySelector(`[data-section="${a}"] .tbw-accordion-content`);u&&(u.innerHTML="")}n.expandedSections.add(i),ve(s,i,!0),Go(s,n,i)}e.emit("tool-panel-section-toggle",{id:i,expanded:!l})},getToolPanels(){return[...n.toolPanels.values()]},registerToolPanel(i){if(n.toolPanels.has(i.id)){console.warn(`[tbw-grid] Tool panel "${i.id}" already registered`);return}n.toolPanels.set(i.id,i),t&&e.refreshShellHeader()},unregisterToolPanel(i){if(n.expandedSections.has(i)){const r=n.panelCleanups.get(i);r&&(r(),n.panelCleanups.delete(i)),n.expandedSections.delete(i)}n.toolPanels.delete(i),t&&e.refreshShellHeader()},getHeaderContents(){return[...n.headerContents.values()]},registerHeaderContent(i){if(n.headerContents.has(i.id)){console.warn(`[tbw-grid] Header content "${i.id}" already registered`);return}n.headerContents.set(i.id,i),t&&ht(e.getShadow(),n)},unregisterHeaderContent(i){const r=n.headerContentCleanups.get(i);r&&(r(),n.headerContentCleanups.delete(i)),n.headerContents.get(i)?.onDestroy?.(),n.headerContents.delete(i),e.getShadow().querySelector(`[data-header-content="${i}"]`)?.remove()},getToolbarButtons(){return Fo(e.getShellConfig(),n)},registerToolbarButton(i){if(n.toolbarButtons.has(i.id)){console.warn(`[tbw-grid] Toolbar button "${i.id}" already registered`);return}n.toolbarButtons.set(i.id,i),t&&e.refreshShellHeader()},unregisterToolbarButton(i){const r=n.toolbarButtonCleanups.get(i);r&&(r(),n.toolbarButtonCleanups.delete(i)),n.toolbarButtons.delete(i),t&&e.refreshShellHeader()},setToolbarButtonDisabled(i,r){}};return o}function ve(n,e,t){const o=n.querySelector(`[data-section="${e}"]`);o&&o.classList.toggle("expanded",t)}function Go(n,e,t){const o=e.toolPanels.get(t);if(!o?.render)return;const i=n.querySelector(`[data-section="${t}"] .tbw-accordion-content`);if(!i)return;const r=o.render(i);r&&e.panelCleanups.set(t,r)}function Ko(n,e,t,o){const i=dt(e);if(n.replaceChildren(),i){const r=G(o?.toolPanel??O.toolPanel),s=G(o?.expand??O.expand),l=G(o?.collapse??O.collapse),c=[...e?.header?.toolbarButtons??[]].sort((m,C)=>(m.order??100)-(C.order??100)),u=[...e?.toolPanels??[]].sort((m,C)=>(m.order??100)-(C.order??100)),h={title:e?.header?.title??void 0,hasPanels:u.length>0,isPanelOpen:t.isPanelOpen,toolPanelIcon:r,configButtons:c.map(m=>({id:m.id,hasElement:!!m.element,hasRender:!!m.render})),apiButtons:[]},p={position:e?.toolPanel?.position??"right",isPanelOpen:t.isPanelOpen,expandIcon:s,collapseIcon:l,panels:u.map(m=>({id:m.id,title:m.title,icon:G(m.icon),isExpanded:t.expandedSections.has(m.id)}))},f=Ho(h),g=Mo(p),w=ct({hasShell:!0,shellHeader:f,shellBody:g});n.appendChild(w)}else{const r=ct({hasShell:!1});n.appendChild(r)}return i}function Vo(){return{startY:null,startX:null,scrollTop:null,scrollLeft:null,lastY:null,lastX:null,lastTime:null,velocityY:0,velocityX:0,momentumRaf:0}}function Wo(n){n.startY=null,n.startX=null,n.scrollTop=null,n.scrollLeft=null,n.lastY=null,n.lastX=null,n.lastTime=null}function gt(n){n.momentumRaf&&(cancelAnimationFrame(n.momentumRaf),n.momentumRaf=0)}function $o(n,e,t){if(n.touches.length!==1)return;gt(e);const o=n.touches[0];e.startY=o.clientY,e.startX=o.clientX,e.lastY=o.clientY,e.lastX=o.clientX,e.lastTime=performance.now(),e.scrollTop=t.fauxScrollbar.scrollTop,e.scrollLeft=t.scrollArea?.scrollLeft??0,e.velocityY=0,e.velocityX=0}function Uo(n,e,t){if(n.touches.length!==1||e.startY===null||e.startX===null||e.scrollTop===null||e.scrollLeft===null)return!1;const o=n.touches[0],i=o.clientY,r=o.clientX,s=performance.now(),l=e.startY-i,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-i)/g,e.velocityX=(e.lastX-r)/g)}e.lastY=i,e.lastX=r,e.lastTime=s;const{scrollTop:c,scrollHeight:d,clientHeight:u}=t.fauxScrollbar,h=d-u,p=l>0&&c<h||l<0&&c>0;let f=!1;if(t.scrollArea){const{scrollLeft:g,scrollWidth:w,clientWidth:m}=t.scrollArea,C=w-m;f=a>0&&g<C||a<0&&g>0}return p&&(t.fauxScrollbar.scrollTop=e.scrollTop+l),f&&t.scrollArea&&(t.scrollArea.scrollLeft=e.scrollLeft+a),p||f}function jo(n,e){(Math.abs(n.velocityY)>.1||Math.abs(n.velocityX)>.1)&&Xo(n,e),Wo(n)}function Xo(n,e){const i=()=>{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(i):n.momentumRaf=0};n.momentumRaf=requestAnimationFrame(i)}function Yo(n,e,t,o){n.addEventListener("touchstart",i=>$o(i,e,t),{passive:!0,signal:o}),n.addEventListener("touchmove",i=>{Uo(i,e,t)&&i.preventDefault()},{passive:!1,signal:o}),n.addEventListener("touchend",()=>jo(e,t),{passive:!0,signal:o})}const Zo=[{property:"editable",pluginName:"editing",description:'the "editable" column property',importHint:"import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';",isUsed:n=>n===!0},{property:"editor",pluginName:"editing",description:'the "editor" column property',importHint:"import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';"},{property:"group",pluginName:"groupingColumns",description:'the "group" column property',importHint:"import { GroupingColumnsPlugin } from '@toolbox-web/grid/plugins/grouping-columns';"},{property:"sticky",pluginName:"pinnedColumns",description:'the "sticky" column property',importHint:"import { PinnedColumnsPlugin } from '@toolbox-web/grid/plugins/pinned-columns';",isUsed:n=>n==="left"||n==="right"}],Jo=[{property:"columnGroups",pluginName:"groupingColumns",description:'the "columnGroups" config property',importHint:"import { GroupingColumnsPlugin } from '@toolbox-web/grid/plugins/grouping-columns';",isUsed:n=>Array.isArray(n)&&n.length>0}];function mt(n,e){return n.some(t=>t.name===e)}function Qo(n,e){const t=new Map;function o(r,s,l,a,c=!1){t.has(r)||t.set(r,{description:s,importHint:l,fields:[],isConfigProperty:c});const d=t.get(r);d.fields.includes(a)||d.fields.push(a)}for(const r of Jo){const s=n[r.property];(r.isUsed?r.isUsed(s):s!==void 0)&&!mt(e,r.pluginName)&&o(r.pluginName,r.description,r.importHint,r.property,!0)}const i=n.columns;if(i&&i.length>0)for(const r of i)for(const s of Zo){const l=r[s.property];if((s.isUsed?s.isUsed(l):l!==void 0)&&!mt(e,s.pluginName)){const c=r.field||"<unknown>";o(s.pluginName,s.description,s.importHint,c)}}if(t.size>0){const r=[];for(const[s,{description:l,importHint:a,fields:c,isConfigProperty:d}]of t)if(d)r.push(`Config uses ${l}, but the required plugin is not loaded.
|
|
29
|
+
`}function j(n,e){const t=n.querySelector("tbw-grid-header");if(!t)return;if(!e.lightDomTitle){const i=t.getAttribute("title");i&&(e.lightDomTitle=i)}const o=t.querySelectorAll("tbw-grid-header-content");o.length>0&&e.lightDomHeaderContent.length===0&&(e.lightDomHeaderContent=Array.from(o),e.lightDomHeaderContent.forEach(i=>{i.setAttribute("slot","header-content")})),t.style.display="none"}function X(n,e){const t=n.querySelector(":scope > tbw-grid-tool-buttons");t&&(e.hasToolButtonsContainer=!0,t.setAttribute("slot","toolbar"))}function Y(n,e,t){n.querySelectorAll(":scope > tbw-grid-tool-panel").forEach(i=>{const r=i,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 p=e.toolPanels.get(s);if(p){if(h){p.render=u,p.order=d,p.icon=a,p.tooltip=c;const g=e.panelCleanups.get(s);g&&(g(),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 Do(n,e,t,o){const i=n.querySelector(".tbw-shell-toolbar");i&&i.addEventListener("click",s=>{const l=s.target;if(l.closest("[data-panel-toggle]")){o.onPanelToggle();return}const c=l.closest("[data-btn]");if(c){const d=c.getAttribute("data-btn");d&&o.onToolbarButtonClick(d)}});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&&o.onSectionToggle(d)}})}function No(n,e,t){const o=n.querySelector(".tbw-tool-panel"),i=n.querySelector("[data-resize-handle]"),r=n.querySelector(".tbw-shell-body");if(!o||!i||!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));o.style.width=`${m}px`},p=()=>{if(!u)return;u=!1,i.classList.remove("resizing"),o.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const g=o.getBoundingClientRect().width;t(g),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",p)},f=g=>{g.preventDefault(),u=!0,a=g.clientX,c=o.getBoundingClientRect().width,d=r.getBoundingClientRect().width-20,i.classList.add("resizing"),o.style.transition="none",document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",h),document.addEventListener("mouseup",p)};return i.addEventListener("mousedown",f),()=>{i.removeEventListener("mousedown",f),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",p)}}function qo(n,e,t){const o=[...e?.header?.toolbarButtons??[],...t.toolbarButtons.values()];for(const i of o){const r=n.querySelector(`[data-btn-slot="${i.id}"]`);if(!r)continue;const s=t.toolbarButtonCleanups.get(i.id);if(s&&(s(),t.toolbarButtonCleanups.delete(i.id)),i.element)r.appendChild(i.element);else if(i.render){const l=i.render(r);l&&t.toolbarButtonCleanups.set(i.id,l)}}}function ft(n,e){const t=n.querySelector(".tbw-shell-content");if(!t)return;const o=[...e.headerContents.values()].sort((r,s)=>(r.order??100)-(s.order??100)),i=t.querySelector('slot[name="header-content"]');for(const r of o){const s=e.headerContentCleanups.get(r.id);s&&(s(),e.headerContentCleanups.delete(r.id));let l=t.querySelector(`[data-header-content="${r.id}"]`);l||(l=document.createElement("div"),l.setAttribute("data-header-content",r.id),i?t.insertBefore(l,i):t.appendChild(l));const a=r.render(l);a&&e.headerContentCleanups.set(r.id,a)}}function Fo(n,e,t){if(!e.isPanelOpen)return;const o=G(t?.expand??O.expand),i=G(t?.collapse??O.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?i:o),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 pt(n,e){const t=n.querySelector("[data-panel-toggle]");t&&(t.classList.toggle("active",e.isPanelOpen),t.setAttribute("aria-pressed",String(e.isPanelOpen)))}function gt(n,e){const t=n.querySelector(".tbw-tool-panel");t&&(t.classList.toggle("open",e.isPanelOpen),e.isPanelOpen||(t.style.width=""))}function zo(n,e){const t=[];for(const o of n?.header?.toolbarButtons??[])t.push({id:o.id,label:o.label??"",source:"config"});for(const o of e.toolbarButtons.values())t.push({id:o.id,label:o.label??"",source:"config"});for(const o of e.toolPanels.values())t.push({id:`panel-toggle-${o.id}`,label:o.tooltip??o.title,source:"panel-toggle",panelId:o.id});return t}function Bo(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.toolbarButtonCleanups.values())e();if(n.toolbarButtonCleanups.clear(),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.toolbarButtons.clear(),n.lightDomHeaderContent=[]}function Go(n,e){let t=!1;const o={get isInitialized(){return t},setInitialized(i){t=i},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 i=e.getShadow();pt(i,n),gt(i,n),Fo(i,n,e.getAccordionIcons()),e.emit("tool-panel-open",{sections:o.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 i=e.getShadow();pt(i,n),gt(i,n),e.emit("tool-panel-close",{})},toggleToolPanel(){n.isPanelOpen?o.closeToolPanel():o.openToolPanel()},toggleToolPanelSection(i){const r=n.toolPanels.get(i);if(!r){console.warn(`[tbw-grid] Tool panel section "${i}" not found`);return}if(n.toolPanels.size===1)return;const s=e.getShadow(),l=n.expandedSections.has(i);if(l){const a=n.panelCleanups.get(i);a&&(a(),n.panelCleanups.delete(i)),r.onClose?.(),n.expandedSections.delete(i),ye(s,i,!1)}else{for(const[a,c]of n.toolPanels)if(a!==i&&n.expandedSections.has(a)){const d=n.panelCleanups.get(a);d&&(d(),n.panelCleanups.delete(a)),c.onClose?.(),n.expandedSections.delete(a),ye(s,a,!1);const u=s.querySelector(`[data-section="${a}"] .tbw-accordion-content`);u&&(u.innerHTML="")}n.expandedSections.add(i),ye(s,i,!0),Ko(s,n,i)}e.emit("tool-panel-section-toggle",{id:i,expanded:!l})},getToolPanels(){return[...n.toolPanels.values()]},registerToolPanel(i){if(n.toolPanels.has(i.id)){console.warn(`[tbw-grid] Tool panel "${i.id}" already registered`);return}n.toolPanels.set(i.id,i),t&&e.refreshShellHeader()},unregisterToolPanel(i){if(n.expandedSections.has(i)){const r=n.panelCleanups.get(i);r&&(r(),n.panelCleanups.delete(i)),n.expandedSections.delete(i)}n.toolPanels.delete(i),t&&e.refreshShellHeader()},getHeaderContents(){return[...n.headerContents.values()]},registerHeaderContent(i){if(n.headerContents.has(i.id)){console.warn(`[tbw-grid] Header content "${i.id}" already registered`);return}n.headerContents.set(i.id,i),t&&ft(e.getShadow(),n)},unregisterHeaderContent(i){const r=n.headerContentCleanups.get(i);r&&(r(),n.headerContentCleanups.delete(i)),n.headerContents.get(i)?.onDestroy?.(),n.headerContents.delete(i),e.getShadow().querySelector(`[data-header-content="${i}"]`)?.remove()},getToolbarButtons(){return zo(e.getShellConfig(),n)},registerToolbarButton(i){if(n.toolbarButtons.has(i.id)){console.warn(`[tbw-grid] Toolbar button "${i.id}" already registered`);return}n.toolbarButtons.set(i.id,i),t&&e.refreshShellHeader()},unregisterToolbarButton(i){const r=n.toolbarButtonCleanups.get(i);r&&(r(),n.toolbarButtonCleanups.delete(i)),n.toolbarButtons.delete(i),t&&e.refreshShellHeader()},setToolbarButtonDisabled(i,r){}};return o}function ye(n,e,t){const o=n.querySelector(`[data-section="${e}"]`);o&&o.classList.toggle("expanded",t)}function Ko(n,e,t){const o=e.toolPanels.get(t);if(!o?.render)return;const i=n.querySelector(`[data-section="${t}"] .tbw-accordion-content`);if(!i)return;const r=o.render(i);r&&e.panelCleanups.set(t,r)}function Vo(n,e,t,o){const i=ut(e);if(n.replaceChildren(),i){const r=G(o?.toolPanel??O.toolPanel),s=G(o?.expand??O.expand),l=G(o?.collapse??O.collapse),c=[...e?.header?.toolbarButtons??[]].sort((m,C)=>(m.order??100)-(C.order??100)),u=[...e?.toolPanels??[]].sort((m,C)=>(m.order??100)-(C.order??100)),h={title:e?.header?.title??void 0,hasPanels:u.length>0,isPanelOpen:t.isPanelOpen,toolPanelIcon:r,configButtons:c.map(m=>({id:m.id,hasElement:!!m.element,hasRender:!!m.render})),apiButtons:[]},p={position:e?.toolPanel?.position??"right",isPanelOpen:t.isPanelOpen,expandIcon:s,collapseIcon:l,panels:u.map(m=>({id:m.id,title:m.title,icon:G(m.icon),isExpanded:t.expandedSections.has(m.id)}))},f=Mo(h),g=Io(p),w=dt({hasShell:!0,shellHeader:f,shellBody:g});n.appendChild(w)}else{const r=dt({hasShell:!1});n.appendChild(r)}return i}function $o(){return{startY:null,startX:null,scrollTop:null,scrollLeft:null,lastY:null,lastX:null,lastTime:null,velocityY:0,velocityX:0,momentumRaf:0}}function Wo(n){n.startY=null,n.startX=null,n.scrollTop=null,n.scrollLeft=null,n.lastY=null,n.lastX=null,n.lastTime=null}function mt(n){n.momentumRaf&&(cancelAnimationFrame(n.momentumRaf),n.momentumRaf=0)}function Uo(n,e,t){if(n.touches.length!==1)return;mt(e);const o=n.touches[0];e.startY=o.clientY,e.startX=o.clientX,e.lastY=o.clientY,e.lastX=o.clientX,e.lastTime=performance.now(),e.scrollTop=t.fauxScrollbar.scrollTop,e.scrollLeft=t.scrollArea?.scrollLeft??0,e.velocityY=0,e.velocityX=0}function jo(n,e,t){if(n.touches.length!==1||e.startY===null||e.startX===null||e.scrollTop===null||e.scrollLeft===null)return!1;const o=n.touches[0],i=o.clientY,r=o.clientX,s=performance.now(),l=e.startY-i,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-i)/g,e.velocityX=(e.lastX-r)/g)}e.lastY=i,e.lastX=r,e.lastTime=s;const{scrollTop:c,scrollHeight:d,clientHeight:u}=t.fauxScrollbar,h=d-u,p=l>0&&c<h||l<0&&c>0;let f=!1;if(t.scrollArea){const{scrollLeft:g,scrollWidth:w,clientWidth:m}=t.scrollArea,C=w-m;f=a>0&&g<C||a<0&&g>0}return p&&(t.fauxScrollbar.scrollTop=e.scrollTop+l),f&&t.scrollArea&&(t.scrollArea.scrollLeft=e.scrollLeft+a),p||f}function Xo(n,e){(Math.abs(n.velocityY)>.1||Math.abs(n.velocityX)>.1)&&Yo(n,e),Wo(n)}function Yo(n,e){const i=()=>{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(i):n.momentumRaf=0};n.momentumRaf=requestAnimationFrame(i)}function Zo(n,e,t,o){n.addEventListener("touchstart",i=>Uo(i,e,t),{passive:!0,signal:o}),n.addEventListener("touchmove",i=>{jo(i,e,t)&&i.preventDefault()},{passive:!1,signal:o}),n.addEventListener("touchend",()=>Xo(e,t),{passive:!0,signal:o})}const Jo=[{property:"editable",pluginName:"editing",description:'the "editable" column property',importHint:"import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';",isUsed:n=>n===!0},{property:"editor",pluginName:"editing",description:'the "editor" column property',importHint:"import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';"},{property:"group",pluginName:"groupingColumns",description:'the "group" column property',importHint:"import { GroupingColumnsPlugin } from '@toolbox-web/grid/plugins/grouping-columns';"},{property:"sticky",pluginName:"pinnedColumns",description:'the "sticky" column property',importHint:"import { PinnedColumnsPlugin } from '@toolbox-web/grid/plugins/pinned-columns';",isUsed:n=>n==="left"||n==="right"}],Qo=[{property:"columnGroups",pluginName:"groupingColumns",description:'the "columnGroups" config property',importHint:"import { GroupingColumnsPlugin } from '@toolbox-web/grid/plugins/grouping-columns';",isUsed:n=>Array.isArray(n)&&n.length>0}];function K(n){return n.charAt(0).toUpperCase()+n.slice(1)}function wt(n,e){return n.some(t=>t.name===e)}function en(n,e){const t=new Map;function o(r,s,l,a,c=!1){t.has(r)||t.set(r,{description:s,importHint:l,fields:[],isConfigProperty:c});const d=t.get(r);d.fields.includes(a)||d.fields.push(a)}for(const r of Qo){const s=n[r.property];(r.isUsed?r.isUsed(s):s!==void 0)&&!wt(e,r.pluginName)&&o(r.pluginName,r.description,r.importHint,r.property,!0)}const i=n.columns;if(i&&i.length>0)for(const r of i)for(const s of Jo){const l=r[s.property];if((s.isUsed?s.isUsed(l):l!==void 0)&&!wt(e,s.pluginName)){const c=r.field||"<unknown>";o(s.pluginName,s.description,s.importHint,c)}}if(t.size>0){const r=[];for(const[s,{description:l,importHint:a,fields:c,isConfigProperty:d}]of t)if(d)r.push(`Config uses ${l}, but the required plugin is not loaded.
|
|
30
30
|
→ Add the plugin to your gridConfig.plugins array:
|
|
31
31
|
${a}
|
|
32
32
|
plugins: [new ${s.charAt(0).toUpperCase()+s.slice(1)}Plugin(), ...]`);else{const u=c.slice(0,3).join(", ")+(c.length>3?`, ... (${c.length} total)`:"");r.push(`Column(s) [${u}] use ${l}, but the required plugin is not loaded.
|
|
@@ -38,26 +38,32 @@ ${r.join(`
|
|
|
38
38
|
|
|
39
39
|
`)}
|
|
40
40
|
|
|
41
|
-
This validation helps catch misconfigurations early. The properties listed above require their respective plugins to function.`)}}
|
|
42
|
-
|
|
43
|
-
`);if(r.includes(".tbw-grid-root")&&r.includes(":host")){t=r;break}}catch{continue}t?(e.replaceSync(t),this.#e.adoptedStyleSheets=[e]):(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(o=>o.href||"(inline)"))}catch(t){console.warn("[tbw-grid] Failed to extract grid.css from document stylesheets:",t)}}getPlugin(e){return this.#i?.getPlugin(e)}getPluginByName(e){return this.#i?.getPluginByName(e)}requestRender(){this.#l.requestPhase(L.ROWS,"plugin:requestRender")}updateTemplate(){ee(this)}requestAfterRender(){this.#l.requestPhase(L.STYLE,"plugin:requestAfterRender")}#V(){this.#i=new wt(this);const e=this.#n?.plugins,t=Array.isArray(e)?e:[];this.#i.attachAll(t)}#I(){const e=this.#i?.getAllStyles()??"";if(e){const t=document.createElement("style");t.setAttribute("data-plugin","all"),t.textContent=e,this.#e.appendChild(t)}}#W(){const e=this.#n?.plugins,t=Array.isArray(e)?e:[];if(this.#E!==t){if(this.#E&&this.#E.length===t.length&&this.#E.every((o,i)=>o===t[i])){this.#E=t;return}this.#i&&this.#i.detachAll();for(const o of this.#t.toolPanels.keys()){const i=this.#t.lightDomToolPanelIds.has(o),r=this.#t.apiToolPanelIds.has(o);if(!i&&!r){const s=this.#t.panelCleanups.get(o);s&&(s(),this.#t.panelCleanups.delete(o)),this.#t.toolPanels.delete(o)}}for(const o of this.#t.headerContents.keys()){const i=this.#t.headerContentCleanups.get(o);i&&(i(),this.#t.headerContentCleanups.delete(o)),this.#t.headerContents.delete(o)}this.#V(),this.#I(),this.#E=t,this.#$(),this.#w=this.#i?.getAll().some(o=>o.onScroll)??!1}}#Q(){this.#i?.detachAll()}#$(){if(!this.#i)return;const e=this.#i.getToolPanels();for(const{panel:o}of e)this.#t.toolPanels.has(o.id)||this.#t.toolPanels.set(o.id,o);const t=this.#i.getHeaderContents();for(const{content:o}of t)this.#t.headerContents.has(o.id)||this.#t.headerContents.set(o.id,o)}#R(){const e=N.getAdapters();if(e.length===0&&!this.__frameworkAdapter)return;const t=this.__frameworkAdapter;return o=>{if(t?.createToolPanelRenderer){const i=t.createToolPanelRenderer(o);if(i)return i}for(const i of e)if(i.createToolPanelRenderer){const r=i.createToolPanelRenderer(o);if(r)return r}}}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.hasAttribute("version")||this.setAttribute("version",N.version),this._rows=Array.isArray(this.#r)?[...this.#r]:[],this.#b&&(this.#b.abort(),this.#H=!1),this.#b=new AbortController,this.#y&&(et(this.#y),this.#y=void 0),U(this,this.#t),j(this,this.#t),X(this,this.#t,this.#R()),this.#o.parseLightDomColumns(this),this.#o.merge(),this.#V();const e=this.#n?.plugins;this.#E=Array.isArray(e)?e:[],this.#$(),this.#s||(this.#G(),this.#I(),this.#s=!0),this.#D(),this.#y=Ro(()=>{this.#be()},{timeout:100})}disconnectedCallback(){this.#y&&(et(this.#y),this.#y=void 0),this.#Q(),zo(this.#t),this.#u.setInitialized(!1),this.#M?.(),this.#M=void 0,gt(this.#T),this.#b&&(this.#b.abort(),this.#b=void 0),this.#k?.abort(),this.#k=void 0,this.#H=!1,this._resizeController&&this._resizeController.dispose(),this.#C&&(this.#C.disconnect(),this.#C=void 0),this.#x&&(this.#x.disconnect(),this.#x=void 0,this.#N=!1),ce(this),this.#A.clear(),this.#E=void 0;for(const e of this._rowPool)e.remove();this._rowPool.length=0,this.__rowsBodyEl=null,this.#f=!1}attributeChangedCallback(e,t,o){if(!(t===o||!o||o==="null"||o==="undefined"))if(e==="rows"||e==="columns"||e==="grid-config")try{const i=JSON.parse(o);e==="rows"?this.rows=i:e==="columns"?this.columns=i:e==="grid-config"&&(this.gridConfig=i)}catch{console.warn(`[tbw-grid] Invalid JSON for '${e}' attribute:`,o)}else e==="fit-mode"?this.fitMode=o:e==="edit-on"&&(this.editOn=o)}#D(){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.#u.isInitialized){ht(this.#e,this.#t),No(this.#e,this.#n?.shell,this.#t);const r=this.#n?.shell?.toolPanel?.defaultOpen;r&&this.#t.toolPanels.has(r)&&(this.openToolPanel(),this.#t.expandedSections.add(r))}if(this.setAttribute("data-upgraded",""),this.#f=!0,this._resizeController=Po(this),this.#_(),this.#ee(t),this.#H)return;this.#H=!0;const o=this.disconnectSignal;this.addEventListener("keydown",r=>ko(this,r),{signal:o}),this.#e.addEventListener("mousedown",r=>this.#pe(r),{signal:o}),document.addEventListener("mousemove",r=>this.#ge(r),{signal:o}),document.addEventListener("mouseup",r=>this.#me(r),{signal:o});const i=this.#n.rowHeight;i&&i>0?this._virtualization.rowHeight=i:requestAnimationFrame(()=>this.#U()),queueMicrotask(()=>this.#oe()),this.#l.requestPhase(L.FULL,"afterConnect")}#U(){const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const t=e.querySelectorAll(".cell");let o=0;t.forEach(s=>{const l=s.offsetHeight;l>o&&(o=l)});const i=e.getBoundingClientRect(),r=Math.max(i.height,o);r>0&&r!==this._virtualization.rowHeight&&(this._virtualization.rowHeight=r,this.#l.requestPhase(L.VIRTUALIZATION,"measureRowHeight"))}#ee(e){this.#k?.abort(),this.#k=new AbortController;const t=this.#k.signal,o=e?.querySelector(".faux-vscroll"),i=e?.querySelector(".rows");if(this._virtualization.container=o??this,this.#w=this.#i?.getAll().some(r=>r.onScroll)??!1,o&&i){o.addEventListener("scroll",()=>{if(!this._virtualization.enabled&&!this.#w)return;const l=o.scrollTop,a=this._virtualization.rowHeight;if(this._rows.length<=this._virtualization.bypassThreshold)i.style.transform=`translateY(${-l}px)`;else{const c=Math.floor(l/a),d=c-c%2,u=-(l-d*a);i.style.transform=`translateY(${u}px)`}this.#g=l,this.#m||(this.#m=requestAnimationFrame(()=>{this.#m=0,this.#g!==null&&(this.#fe(this.#g),this.#g=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}=o;(l.deltaY>0&&c<d-u||l.deltaY<0&&c>0)&&(l.preventDefault(),o.scrollTop+=l.deltaY)}},{passive:!1,signal:t}),Yo(r,this.#T,{fauxScrollbar:o,scrollArea:s},t))}this._bodyEl&&Eo(this,this._bodyEl,t),this.#C?.disconnect(),this._virtualization.viewportEl&&(this.#C=new ResizeObserver(()=>{this.#l.requestPhase(L.VIRTUALIZATION,"resize-observer")}),this.#C.observe(this._virtualization.viewportEl)),this._virtualization.enabled&&(this.#l.requestPhase(L.VIRTUALIZATION,"init-virtualization"),queueMicrotask(()=>this.#te()))}#N=!1;#te(){if(this.#N)return;const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;this.#N=!0,this.#x?.disconnect();const t=e.querySelectorAll(".cell");t.length>0&&(this.#x=new ResizeObserver(()=>{this.#U()}),t.forEach(o=>this.#x.observe(o)))}#j(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}#oe(){this._bodyEl?.querySelectorAll(".data-grid-row")?.forEach((t,o)=>{const i=o===this._focusRow;t.setAttribute("aria-selected",String(i)),t.querySelectorAll(".cell").forEach((r,s)=>{r.setAttribute("aria-selected",String(i&&s===this._focusCol))})})}#P(e){this.#p[e]=!0,!this.#h&&(this.#h=!0,queueMicrotask(()=>this.#ne()))}#ne(){if(!this.#h||!this.#f){this.#h=!1;return}const e=this.#p;if(this.#h=!1,this.#p={rows:!1,columns:!1,gridConfig:!1,fitMode:!1,editMode:!1},e.gridConfig){this.#ae();return}e.columns&&this.#re(),e.rows&&this.#ie(),e.fitMode&&this.#se(),e.editMode&&this.#le()}#ie(){this._rows=Array.isArray(this.#r)?[...this.#r]:[],this.#l.requestPhase(L.ROWS,"applyRowsUpdate")}#re(){ce(this),this.#o.merge(),this.#_()}#se(){this.#o.merge(),this.#n.fitMode==="fixed"?(this.__didInitialAutoSize=!1,Ke(this)):(this._columns.forEach(t=>{!t.__userResized&&t.__autoSized&&delete t.width}),ee(this))}#le(){this.#o.merge(),this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.#l.requestPhase(L.VIRTUALIZATION,"applyEditModeUpdate")}#ae(){U(this,this.#t),j(this,this.#t);const e=!!this.#e.querySelector(".has-shell"),t=!!this.#e.querySelector(".tbw-tool-panel"),o=this.#e.querySelectorAll(".tbw-accordion-section").length;this.#o.parseLightDomColumns(this),this.#o.merge(),this.#W(),X(this,this.#t,this.#R()),this.#o.markSourcesChanged(),this.#o.merge();const i=dt(this.#n?.shell),r=(this.#n?.shell?.toolPanels?.length??0)>0,s=(this.#n?.shell?.toolPanels?.length??0)!==o;if(e!==i||!e&&i||!t&&r||t&&s){this.#G(),this.#I(),this.#D();return}e&&this.#ce(),this.#l.requestPhase(L.COLUMNS,"applyGridConfigUpdate")}#ce(){const e=this.#e.querySelector(".tbw-shell-header");if(!e)return;const t=this.#n.shell?.header?.title??this.#t.lightDomTitle;let o=e.querySelector(".tbw-shell-title");t?(o||(o=document.createElement("h2"),o.className="tbw-shell-title",o.setAttribute("part","shell-title"),e.insertBefore(o,e.firstChild)),o.textContent=t):o&&o.remove()}#de(){if(this.#i){const e=this.#O.length>0?this.#O:this._columns,t=e.filter(r=>!r.hidden),o=e.filter(r=>r.hidden),i=this.#i.processColumns([...t]);if(i!==t){const r=new Map(i.map((l,a)=>[l.field,{col:l,order:a}]));if(!t.some(l=>r.has(l.field))&&i.length>0)this._columns=[...i,...o];else{const l=e.map(a=>{if(a.hidden)return a;const c=r.get(a.field);return c?c.col:a});this._columns=l}}else this._columns=[...e]}}#ue(){ce(this);const e=Array.isArray(this.#r)?[...this.#r]:[],t=this.#i?.processRows(e)??e;this._rows=t}#he(e){const t={...ze,...e.animation},o=t.mode??"reduced-motion";let i=1;o===!1||o==="off"?i=0:(o===!0||o==="on")&&(i=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(i)),this.dataset.animationMode=typeof o=="boolean"?o?"on":"off":o}#q(e,t,o=this.__rowRenderEpoch){this.#a||(this.#a=(i,r,s)=>this.#i?.renderRow(i,r,s)??!1),To(this,e,t,o,this.#a)}#F=-1;#X=-1;#Y(e,t){if(e===this.#F&&t===this.#X)return;const o=this.#F;this.#F=e,this.#X=t,this.__rowsBodyEl&&(this.__rowsBodyEl.setAttribute("aria-rowcount",String(e)),this.__rowsBodyEl.setAttribute("aria-colcount",String(t))),e!==o&&this._bodyEl&&(e>0?this._bodyEl.setAttribute("role","rowgroup"):this._bodyEl.removeAttribute("role"))}#_(){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.#i?.getAll()??[];this.#o.applyState(e,t)}this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),this.#l.requestPhase(L.FULL,"setup")}}#fe(e){if(this.refreshVirtualWindow(!1),this.#i?.onScrollRender(),this.#w){const t=this._virtualization.container,o=this.#S;o.scrollTop=e,o.scrollLeft=t?.scrollLeft??0,o.scrollHeight=t?.scrollHeight??0,o.scrollWidth=t?.scrollWidth??0,o.clientHeight=t?.clientHeight??0,o.clientWidth=t?.clientWidth??0,this.#i?.onScroll(o)}}findHeaderRow(){return this.#e.querySelector(".header-row")}findRenderedRowElement(e){return Array.from(this._bodyEl.querySelectorAll(".data-grid-row")).find(t=>{const o=t.querySelector(".cell[data-row]");return o&&Number(o.getAttribute("data-row"))===e})||null}_dispatchCellClick(e,t,o,i){const r=this._rows[t],s=this._columns[o];if(!r||!s)return!1;const l={row:r,rowIndex:t,colIndex:o,field:s.field,value:r[s.field],cellEl:i,originalEvent:e};return this.#i?.onCellClick(l)??!1}_dispatchRowClick(e,t,o,i){if(!o)return!1;const r={rowIndex:t,row:o,rowEl:i,originalEvent:e};return this.#i?.onRowClick(r)??!1}_dispatchHeaderClick(e,t,o){const i=this._columns[t];if(!i)return!1;const r={colIndex:t,field:i.field,column:i,headerEl:o,originalEvent:e};return this.#i?.onHeaderClick(r)??!1}_dispatchKeyDown(e){return this.#i?.onKeyDown(e)??!1}_getHorizontalScrollOffsets(e,t){return this.#i?.getHorizontalScrollOffsets(e,t)??{left:0,right:0}}queryPlugins(e){return this.#i?.queryPlugins(e)??[]}#z(e,t){let o=null;const i=e.composedPath?.();if(i&&i.length>0?o=i[0]:o=e.target,o&&!this.#e.contains(o)){const f=this.#e.elementFromPoint(e.clientX,e.clientY);f&&(o=f)}const r=o?.closest?.("[data-col]"),s=o?.closest?.(".data-grid-row"),l=o?.closest?.(".header-row");let a,c,d,u,h,p;return r&&(a=parseInt(r.getAttribute("data-row")??"-1",10),c=parseInt(r.getAttribute("data-col")??"-1",10),a>=0&&c>=0&&(d=this._rows[a],p=this._columns[c],u=p?.field,h=d&&u?d[u]:void 0)),{type:t,row:d,rowIndex:a!==void 0&&a>=0?a:void 0,colIndex:c!==void 0&&c>=0?c:void 0,field:u,value:h,column:p,originalEvent:e,cellElement:r??void 0,rowElement:s??void 0,isHeader:!!l,cell:a!==void 0&&c!==void 0&&a>=0&&c>=0?{row:a,col:c}:void 0}}#pe(e){const t=this.#z(e,"mousedown");(this.#i?.onCellMouseDown(t)??!1)&&(this.#v=!0)}#ge(e){if(!this.#v)return;const t=this.#z(e,"mousemove");this.#i?.onCellMouseMove(t)}#me(e){if(!this.#v)return;const t=this.#z(e,"mouseup");this.#i?.onCellMouseUp(t),this.#v=!1}async ready(){return this.#d}async forceLayout(){return this.#l.requestPhase(L.FULL,"forceLayout"),this.#l.whenReady()}async getConfig(){return Object.freeze({...this.#n||{}})}setColumnVisible(e,t){const o=this.#o.setColumnVisible(e,t);return o&&this.requestStateChange(),o}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.#i?.getAll()??[];return this.#o.collectState(e)}set columnState(e){e&&(this.#L=e,this.#o.initialColumnState=e,this.#s&&this.#we(e))}get columnState(){return this.getColumnState()}#we(e){const t=this.#i?.getAll()??[];this.#o.applyState(e,t),this.#_()}requestStateChange(){const e=this.#i?.getAll()??[];this.#o.requestStateChange(e)}resetColumnState(){this.#L=void 0,this.__originalOrder=[];const e=this.#i?.getAll()??[];this.#o.resetState(e),this.#o.merge(),this.#_()}get isToolPanelOpen(){return this.#u.isPanelOpen}get activeToolPanel(){return this.#u.activePanel}get expandedToolPanelSections(){return this.#u.expandedSections}openToolPanel(){this.#u.openToolPanel()}closeToolPanel(){this.#u.closeToolPanel()}toggleToolPanel(){this.#u.toggleToolPanel()}toggleToolPanelSection(e){this.#u.toggleToolPanelSection(e)}getToolPanels(){return this.#u.getToolPanels()}registerToolPanel(e){this.#t.apiToolPanelIds.add(e.id),this.#u.registerToolPanel(e)}unregisterToolPanel(e){this.#t.apiToolPanelIds.delete(e),this.#u.unregisterToolPanel(e)}getHeaderContents(){return this.#u.getHeaderContents()}registerHeaderContent(e){this.#u.registerHeaderContent(e)}unregisterHeaderContent(e){this.#u.unregisterHeaderContent(e)}getToolbarButtons(){return this.#u.getToolbarButtons()}registerToolbarButton(e){this.#u.registerToolbarButton(e)}unregisterToolbarButton(e){this.#u.unregisterToolbarButton(e)}setToolbarButtonDisabled(e,t){this.#u.setToolbarButtonDisabled(e,t)}refreshShellHeader(){U(this,this.#t),j(this,this.#t),X(this,this.#t,this.#R()),this.#o.markSourcesChanged(),this.#o.merge(),this.#G(),this.#I(),this.#D()}#A=new Map;registerStyles(e,t){let o=this.#A.get(e);o||(o=new CSSStyleSheet,this.#A.set(e,o)),o.replaceSync(t),this.#Z()}unregisterStyles(e){this.#A.delete(e)&&this.#Z()}getRegisteredStyles(){return Array.from(this.#A.keys())}#Z(){const e=this.#e.adoptedStyleSheets[0],t=Array.from(this.#A.values());this.#e.adoptedStyleSheets=e?[e,...t]:t}#be(){const e=()=>{const o=this.#t.lightDomTitle,i=this.#t.hasToolButtonsContainer;U(this,this.#t),j(this,this.#t),X(this,this.#t,this.#R());const r=this.#t.lightDomTitle,s=this.#t.hasToolButtonsContainer;if(r&&!o||s&&!i){this.#o.markSourcesChanged(),this.#o.merge();const l=this.#e.querySelector(".tbw-shell-header");if(l){const a=ut(this.#n.shell,this.#t,this.#n.icons?.toolPanel),c=document.createElement("div");c.innerHTML=a;const d=c.firstElementChild;d&&(l.replaceWith(d),this.#K())}}},t=()=>{this.__lightDomColumnsCache=void 0,this.#_()};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,ce(this),this.#o.parseLightDomColumns(this);const e=this.#t.lightDomTitle,t=this.#t.hasToolButtonsContainer;U(this,this.#t),j(this,this.#t),X(this,this.#t,this.#R());const o=this.#t.lightDomTitle,i=this.#t.hasToolButtonsContainer;if(o&&!e||i&&!t){this.#o.markSourcesChanged(),this.#o.merge();const s=this.#e.querySelector(".tbw-shell-header");if(s){const l=ut(this.#n.shell,this.#t,this.#n.icons?.toolPanel),a=document.createElement("div");a.innerHTML=l;const c=a.firstElementChild;c&&(s.replaceWith(c),this.#K())}}this.#l.requestPhase(L.COLUMNS,"refreshColumns")}#B(e){const t=this._virtualization.rowHeight,o=this._virtualization.container??this,i=this._virtualization.viewportEl??o,r=o.clientHeight,s=i.clientHeight,a=this.shadowRoot?.querySelector(".tbw-scroll-area"),c=a?a.clientHeight:r,u=c-s,h=this.#i?.getExtraHeight()??0,p=Math.max(0,r-c);return e*t+u+h+p}refreshVirtualWindow(e=!1){if(!this._bodyEl)return;const t=this._rows.length;if(!this._virtualization.enabled){this.#q(0,t),this.#i?.afterRender();return}if(this._rows.length<=this._virtualization.bypassThreshold){this._virtualization.start=0,this._virtualization.end=t,e&&(this._bodyEl.style.transform="translateY(0px)"),this.#q(0,t,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${this.#B(t)}px`),this.#Y(t,this._visibleColumns.length),this.#i?.afterRender();return}const o=this._virtualization.container??this,i=this._virtualization.viewportEl??o,r=i.clientHeight,s=this._virtualization.rowHeight,l=o.scrollTop;let a=Math.floor(l/s),c=0;const d=10;for(;c<d;){const C=this.#i?.getExtraHeightBefore?.(a)??0,y=Math.floor((l-C)/s);if(y>=a||y<0)break;a=y,c++}a=a-a%2,a<0&&(a=0);const u=this.#i?.adjustVirtualStart(a,l,s);u!==void 0&&u<a&&(a=u,a=a-a%2,a<0&&(a=0));const h=Math.ceil(r/s)+3;let p=a+h;if(p>t&&(p=t),this._virtualization.start=a,this._virtualization.end=p,o.clientHeight===0&&r>0){this.#l.requestPhase(L.VIRTUALIZATION,"stale-refs-retry");return}const g=this.#B(t);this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${g}px`);const w=this.#i?.getExtraHeightBefore?.(a)??0,m=-(l-a*s-w);this._bodyEl.style.transform=`translateY(${m}px)`,this.#q(a,p,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),this.#Y(t,this._visibleColumns.length),e&&(this.#i?.afterRender(),queueMicrotask(()=>{const C=o.clientHeight,y=i.clientHeight;if(C===0&&y>0)return;const x=this.#B(t);this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${x}px`)}))}#G(){U(this,this.#t),j(this,this.#t),X(this,this.#t,this.#R()),this.#o.markSourcesChanged(),this.#o.merge();const e=this.#n?.shell;Ko(this.#e,e,{isPanelOpen:this.#t.isPanelOpen,expandedSections:this.#t.expandedSections},this.#n?.icons)&&(this.#K(),this.#u.setInitialized(!0))}#K(){Oo(this.#e,this.#n?.shell,this.#t,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e),onToolbarButtonClick:e=>this.#ve(e)}),this.#M?.(),this.#M=Do(this.#e,this.#n?.shell,e=>{this.style.setProperty("--tbw-tool-panel-width",`${e}px`)})}#ve(e){}}customElements.get(N.tagName)||customElements.define(N.tagName,N),globalThis.DataGridElement=N;const ne={CAN_MOVE_COLUMN:"canMoveColumn",GET_CONTEXT_MENU_ITEMS:"getContextMenuItems"};class S{version="1.0.0";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}))}requestRender(){this.grid?.requestRender?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get shadowRoot(){return this.grid?.shadowRoot??null}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...O,...e}}resolveIcon(e,t){return t!==void 0?t:this.gridIcons[e]}setIcon(e,t){typeof t=="string"?e.innerHTML=t:t instanceof HTMLElement&&(e.innerHTML="",e.appendChild(t.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}const k={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"},ie={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"},en={ROOT:`.${k.ROOT}`,HEADER:`.${k.HEADER}`,HEADER_ROW:`.${k.HEADER_ROW}`,HEADER_CELL:`.${k.HEADER_CELL}`,ROWS_VIEWPORT:`.${k.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${k.ROWS_CONTAINER}`,DATA_ROW:`.${k.DATA_ROW}`,DATA_CELL:`.${k.DATA_CELL}`,GROUP_ROW:`.${k.GROUP_ROW}`,ROW_BY_INDEX:n=>`.${k.DATA_ROW}[${ie.ROW_INDEX}="${n}"]`,CELL_BY_FIELD:n=>`.${k.DATA_CELL}[${ie.FIELD}="${n}"]`,CELL_AT:(n,e)=>`.${k.DATA_ROW}[${ie.ROW_INDEX}="${n}"] .${k.DATA_CELL}[${ie.COL_INDEX}="${e}"]`,SELECTED_ROWS:`.${k.DATA_ROW}.${k.SELECTED}`,EDITING_CELL:`.${k.DATA_CELL}.${k.EDITING}`},tn={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"},on={CELL_COMMIT:"cell-commit",ROW_COMMIT:"row-commit",CHANGED_ROWS_RESET:"changed-rows-reset",MOUNT_EXTERNAL_VIEW:"mount-external-view",MOUNT_EXTERNAL_EDITOR:"mount-external-editor",SORT_CHANGE:"sort-change",COLUMN_RESIZE:"column-resize",ACTIVATE_CELL:"activate-cell",GROUP_TOGGLE:"group-toggle",COLUMN_STATE_CHANGE:"column-state-change"},nn={SELECTION_CHANGE:"selection-change",TREE_EXPAND:"tree-expand",FILTER_CHANGE:"filter-change",SORT_MODEL_CHANGE:"sort-model-change",EXPORT_START:"export-start",EXPORT_COMPLETE:"export-complete",CLIPBOARD_COPY:"clipboard-copy",CLIPBOARD_PASTE:"clipboard-paste",CONTEXT_MENU_OPEN:"context-menu-open",CONTEXT_MENU_CLOSE:"context-menu-close",HISTORY_CHANGE:"history-change",SERVER_LOADING:"server-loading",SERVER_ERROR:"server-error",COLUMN_VISIBILITY_CHANGE:"column-visibility-change",COLUMN_REORDER:"column-reorder",DETAIL_EXPAND:"detail-expand",GROUP_EXPAND:"group-expand"};function rn(n,e,t,o){if(o.processCell)return o.processCell(n,e,t);if(n==null)return"";if(n instanceof Date)return n.toISOString();if(typeof n=="object")return JSON.stringify(n);const i=String(n),r=o.delimiter??" ",s=o.newline??`
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
This validation helps catch misconfigurations early. The properties listed above require their respective plugins to function.`)}}const tn={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 on(n){return tn[n]??`import { ${K(n)}Plugin } from '@toolbox-web/grid/plugins/${n}';`}function nn(n,e){const t=n.name,i=n.constructor.dependencies??[];for(const r of i){const s=r.name,l=r.required??!0,a=r.reason;if(!e.some(d=>d.name===s)){const d=a??`${K(t)}Plugin requires ${K(s)}Plugin`,u=on(s);if(l)throw new Error(`[tbw-grid] Plugin dependency error:
|
|
42
|
+
|
|
43
|
+
${d}.
|
|
44
|
+
|
|
45
|
+
→ Add the plugin to your gridConfig.plugins array BEFORE ${K(t)}Plugin:
|
|
46
|
+
${u}
|
|
47
|
+
plugins: [new ${K(s)}Plugin(), new ${K(t)}Plugin()]`);console.info(`[tbw-grid] ${K(t)}Plugin: Optional "${s}" plugin not found. Some features may be unavailable.`)}}}class bt{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(nn(e,this.plugins),this.pluginMap.set(e.constructor,e),this.plugins.push(e),e.cellRenderers)for(const[t,o]of Object.entries(e.cellRenderers))this.cellRenderers.set(t,o);if(e.headerRenderers)for(const[t,o]of Object.entries(e.headerRenderers))this.headerRenderers.set(t,o);if(e.cellEditors)for(const[t,o]of Object.entries(e.cellEditors))this.cellEditors.set(t,o);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)}getAllStyles(){return this.plugins.filter(e=>e.styles).map(e=>e.styles).join(`
|
|
48
|
+
`)}processRows(e){let t=[...e];for(const o of this.plugins)o.processRows&&(t=o.processRows(t));return t}processColumns(e){let t=[...e];for(const o of this.plugins)o.processColumns&&(t=o.processColumns(t));return t}beforeRender(){for(const e of this.plugins)e.beforeRender?.()}afterRender(){for(const e of this.plugins)e.afterRender?.()}onScrollRender(){for(const e of this.plugins)e.onScrollRender?.()}getExtraHeight(){let e=0;for(const t of this.plugins)typeof t.getExtraHeight=="function"&&(e+=t.getExtraHeight());return e}getExtraHeightBefore(e){let t=0;for(const o of this.plugins)typeof o.getExtraHeightBefore=="function"&&(t+=o.getExtraHeightBefore(e));return t}adjustVirtualStart(e,t,o){let i=e;for(const r of this.plugins)if(typeof r.adjustVirtualStart=="function"){const s=r.adjustVirtualStart(e,t,o);s<i&&(i=s)}return i}renderRow(e,t,o){for(const i of this.plugins)if(i.renderRow?.(e,t,o))return!0;return!1}queryPlugins(e){const t=[];for(const o of this.plugins){const i=o.onPluginQuery?.(e);i!==void 0&&t.push(i)}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 o=0,i=0,r=!1;for(const s of this.plugins){const l=s.getHorizontalScrollOffsets?.(e,t);l&&(o+=l.left,i+=l.right,l.skipScroll&&(r=!0))}return{left:o,right:i,skipScroll:r}}getToolPanels(){const e=[];for(const t of this.plugins){const o=t.getToolPanel?.();o&&e.push({plugin:t,panel:o})}return e.sort((t,o)=>(t.panel.order??0)-(o.panel.order??0))}getHeaderContents(){const e=[];for(const t of this.plugins){const o=t.getHeaderContent?.();o&&e.push({plugin:t,content:o})}return e.sort((t,o)=>(t.content.order??0)-(o.content.order??0))}}class N 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","edit-on"]}#e;#s=!1;#d;#c;#r=[];get#n(){return this.#o?.effective??{}}#f=!1;#h=!1;#p={rows:!1,columns:!1,gridConfig:!1,fitMode:!1,editMode:!1};#l;#m=0;#g=null;#w=!1;#a;#v=!1;#T=$o();#b;#C;#x;#y;#S={scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0};#i;#E;#H=!1;#k;#L;#o;#t=Oo();#u;#M;_rows=[];#O=[];get _columns(){return this.#n.columns??[]}set _columns(e){this.#n.columns=e}get _visibleColumns(){return this._columns.filter(e=>!e.hidden)}_headerRowEl;_bodyEl;_rowPool=[];_resizeController;_virtualization={enabled:!0,rowHeight:28,bypassThreshold:24,start:0,end:0,container:null,viewportEl:null,totalHeightEl:null};_focusRow=0;_focusCol=0;_sortState=null;_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.#r;this.#r=e,t!==e&&this.#P("rows")}get sourceRows(){return this.#r}get columns(){return[...this._columns]}set columns(e){const t=this.#o?.getColumns();this.#o?.setColumns(e),t!==e&&this.#P("columns")}get gridConfig(){return this.#n}set gridConfig(e){const t=this.#o?.getGridConfig();this.#o?.setGridConfig(e),t!==e&&(this.#o.clearLightDomCache(),this.#P("gridConfig"))}get fitMode(){return this.#n.fitMode??"stretch"}set fitMode(e){const t=this.#o?.getFitMode();this.#o?.setFitMode(e),t!==e&&this.#P("fitMode")}get editOn(){return this.#n.editOn}set editOn(e){const t=this.#o?.getEditOn();this.#o?.setEditOn(e),t!==e&&this.#P("editMode")}get effectiveConfig(){return this.#n}get disconnectSignal(){return this.#b||(this.#b=new AbortController),this.#b.signal}constructor(){super(),this.#e=this.attachShadow({mode:"open"}),this.#J(),this.#d=new Promise(e=>this.#c=e),this.#l=new Po({mergeConfig:()=>{this.#o.parseLightDomColumns(this),this.#o.merge(),this.#$(),en(this.#n,this.#i?.getPlugins()??[]),this.#O=[...this._columns]},processColumns:()=>this.#de(),processRows:()=>this.#ue(),renderHeader:()=>ce(this),updateTemplate:()=>te(this),renderVirtualWindow:()=>this.refreshVirtualWindow(!0),afterRender:()=>{this.#i?.afterRender(),this.#n.fitMode==="fixed"&&!this.__didInitialAutoSize&&(this.__didInitialAutoSize=!0,Ve(this))},isConnected:()=>this.isConnected&&this.#f}),this.#l.setInitialReadyResolver(()=>this.#c?.()),this.#u=Go(this.#t,{getShadow:()=>this.#e,getShellConfig:()=>this.#n?.shell,getAccordionIcons:()=>({expand:this.#n?.icons?.expand??O.expand,collapse:this.#n?.icons?.collapse??O.collapse}),emit:(e,t)=>this.#j(e,t),refreshShellHeader:()=>this.refreshShellHeader()}),this.#o=new Co({getRows:()=>this.#r,getSortState:()=>this._sortState,setSortState:e=>{this._sortState=e},onConfigChange:()=>{this.#l.requestPhase(L.FULL,"configChange")},emit:(e,t)=>this.#j(e,t),clearRowPool:()=>{this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++},setup:()=>this.#_(),renderHeader:()=>ce(this),updateTemplate:()=>te(this),refreshVirtualWindow:()=>this.#l.requestPhase(L.VIRTUALIZATION,"configManager"),getVirtualization:()=>this._virtualization,setRowHeight:e=>{this._virtualization.rowHeight=e},applyAnimationConfig:e=>this.#he(e),getShellLightDomTitle:()=>this.#t.lightDomTitle,getShellToolPanels:()=>this.#t.toolPanels,getShellHeaderContents:()=>this.#t.headerContents,getShellToolbarButtons:()=>this.#t.toolbarButtons,getShellLightDomHeaderContent:()=>this.#t.lightDomHeaderContent,getShellHasToolButtonsContainer:()=>this.#t.hasToolButtonsContainer})}async#J(){const e=new CSSStyleSheet;if(V.length>0){e.replaceSync(V),this.#e.adoptedStyleSheets=[e];return}await new Promise(t=>setTimeout(t,50));try{let t="";for(const o of Array.from(document.styleSheets))try{const r=Array.from(o.cssRules||[]).map(s=>s.cssText).join(`
|
|
49
|
+
`);if(r.includes(".tbw-grid-root")&&r.includes(":host")){t=r;break}}catch{continue}t?(e.replaceSync(t),this.#e.adoptedStyleSheets=[e]):(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(o=>o.href||"(inline)"))}catch(t){console.warn("[tbw-grid] Failed to extract grid.css from document stylesheets:",t)}}getPlugin(e){return this.#i?.getPlugin(e)}getPluginByName(e){return this.#i?.getPluginByName(e)}requestRender(){this.#l.requestPhase(L.ROWS,"plugin:requestRender")}updateTemplate(){te(this)}requestAfterRender(){this.#l.requestPhase(L.STYLE,"plugin:requestAfterRender")}#V(){this.#i=new bt(this);const e=this.#n?.plugins,t=Array.isArray(e)?e:[];this.#i.attachAll(t)}#I(){const e=this.#i?.getAllStyles()??"";if(e){const t=document.createElement("style");t.setAttribute("data-plugin","all"),t.textContent=e,this.#e.appendChild(t)}}#$(){const e=this.#n?.plugins,t=Array.isArray(e)?e:[];if(this.#E!==t){if(this.#E&&this.#E.length===t.length&&this.#E.every((o,i)=>o===t[i])){this.#E=t;return}this.#i&&this.#i.detachAll();for(const o of this.#t.toolPanels.keys()){const i=this.#t.lightDomToolPanelIds.has(o),r=this.#t.apiToolPanelIds.has(o);if(!i&&!r){const s=this.#t.panelCleanups.get(o);s&&(s(),this.#t.panelCleanups.delete(o)),this.#t.toolPanels.delete(o)}}for(const o of this.#t.headerContents.keys()){const i=this.#t.headerContentCleanups.get(o);i&&(i(),this.#t.headerContentCleanups.delete(o)),this.#t.headerContents.delete(o)}this.#V(),this.#I(),this.#E=t,this.#W(),this.#w=this.#i?.getAll().some(o=>o.onScroll)??!1}}#Q(){this.#i?.detachAll()}#W(){if(!this.#i)return;const e=this.#i.getToolPanels();for(const{panel:o}of e)this.#t.toolPanels.has(o.id)||this.#t.toolPanels.set(o.id,o);const t=this.#i.getHeaderContents();for(const{content:o}of t)this.#t.headerContents.has(o.id)||this.#t.headerContents.set(o.id,o)}#R(){const e=N.getAdapters();if(e.length===0&&!this.__frameworkAdapter)return;const t=this.__frameworkAdapter;return o=>{if(t?.createToolPanelRenderer){const i=t.createToolPanelRenderer(o);if(i)return i}for(const i of e)if(i.createToolPanelRenderer){const r=i.createToolPanelRenderer(o);if(r)return r}}}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.hasAttribute("version")||this.setAttribute("version",N.version),this._rows=Array.isArray(this.#r)?[...this.#r]:[],this.#b&&(this.#b.abort(),this.#H=!1),this.#b=new AbortController,this.#y&&(tt(this.#y),this.#y=void 0),j(this,this.#t),X(this,this.#t),Y(this,this.#t,this.#R()),this.#o.parseLightDomColumns(this),this.#o.merge(),this.#V();const e=this.#n?.plugins;this.#E=Array.isArray(e)?e:[],this.#W(),this.#s||(this.#G(),this.#I(),this.#s=!0),this.#D(),this.#y=_o(()=>{this.#be()},{timeout:100})}disconnectedCallback(){this.#y&&(tt(this.#y),this.#y=void 0),this.#Q(),Bo(this.#t),this.#u.setInitialized(!1),this.#M?.(),this.#M=void 0,mt(this.#T),this.#b&&(this.#b.abort(),this.#b=void 0),this.#k?.abort(),this.#k=void 0,this.#H=!1,this._resizeController&&this._resizeController.dispose(),this.#C&&(this.#C.disconnect(),this.#C=void 0),this.#x&&(this.#x.disconnect(),this.#x=void 0,this.#N=!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.#f=!1}attributeChangedCallback(e,t,o){if(!(t===o||!o||o==="null"||o==="undefined"))if(e==="rows"||e==="columns"||e==="grid-config")try{const i=JSON.parse(o);e==="rows"?this.rows=i:e==="columns"?this.columns=i:e==="grid-config"&&(this.gridConfig=i)}catch{console.warn(`[tbw-grid] Invalid JSON for '${e}' attribute:`,o)}else e==="fit-mode"?this.fitMode=o:e==="edit-on"&&(this.editOn=o)}#D(){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.#u.isInitialized){ft(this.#e,this.#t),qo(this.#e,this.#n?.shell,this.#t);const r=this.#n?.shell?.toolPanel?.defaultOpen;r&&this.#t.toolPanels.has(r)&&(this.openToolPanel(),this.#t.expandedSections.add(r))}if(this.setAttribute("data-upgraded",""),this.#f=!0,this._resizeController=Ho(this),this.#_(),this.#ee(t),this.#H)return;this.#H=!0;const o=this.disconnectSignal;this.addEventListener("keydown",r=>Lo(this,r),{signal:o}),this.#e.addEventListener("mousedown",r=>this.#pe(r),{signal:o}),document.addEventListener("mousemove",r=>this.#ge(r),{signal:o}),document.addEventListener("mouseup",r=>this.#me(r),{signal:o});const i=this.#n.rowHeight;i&&i>0?this._virtualization.rowHeight=i:requestAnimationFrame(()=>this.#U()),queueMicrotask(()=>this.#oe()),this.#l.requestPhase(L.FULL,"afterConnect")}#U(){const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const t=e.querySelectorAll(".cell");let o=0;t.forEach(s=>{const l=s.offsetHeight;l>o&&(o=l)});const i=e.getBoundingClientRect(),r=Math.max(i.height,o);r>0&&r!==this._virtualization.rowHeight&&(this._virtualization.rowHeight=r,this.#l.requestPhase(L.VIRTUALIZATION,"measureRowHeight"))}#ee(e){this.#k?.abort(),this.#k=new AbortController;const t=this.#k.signal,o=e?.querySelector(".faux-vscroll"),i=e?.querySelector(".rows");if(this._virtualization.container=o??this,this.#w=this.#i?.getAll().some(r=>r.onScroll)??!1,o&&i){o.addEventListener("scroll",()=>{if(!this._virtualization.enabled&&!this.#w)return;const l=o.scrollTop,a=this._virtualization.rowHeight;if(this._rows.length<=this._virtualization.bypassThreshold)i.style.transform=`translateY(${-l}px)`;else{const c=Math.floor(l/a),d=c-c%2,u=-(l-d*a);i.style.transform=`translateY(${u}px)`}this.#g=l,this.#m||(this.#m=requestAnimationFrame(()=>{this.#m=0,this.#g!==null&&(this.#fe(this.#g),this.#g=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}=o;(l.deltaY>0&&c<d-u||l.deltaY<0&&c>0)&&(l.preventDefault(),o.scrollTop+=l.deltaY)}},{passive:!1,signal:t}),Zo(r,this.#T,{fauxScrollbar:o,scrollArea:s},t))}this._bodyEl&&So(this,this._bodyEl,t),this.#C?.disconnect(),this._virtualization.viewportEl&&(this.#C=new ResizeObserver(()=>{this.#l.requestPhase(L.VIRTUALIZATION,"resize-observer")}),this.#C.observe(this._virtualization.viewportEl)),this._virtualization.enabled&&(this.#l.requestPhase(L.VIRTUALIZATION,"init-virtualization"),queueMicrotask(()=>this.#te()))}#N=!1;#te(){if(this.#N)return;const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;this.#N=!0,this.#x?.disconnect();const t=e.querySelectorAll(".cell");t.length>0&&(this.#x=new ResizeObserver(()=>{this.#U()}),t.forEach(o=>this.#x.observe(o)))}#j(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}#oe(){this._bodyEl?.querySelectorAll(".data-grid-row")?.forEach((t,o)=>{const i=o===this._focusRow;t.setAttribute("aria-selected",String(i)),t.querySelectorAll(".cell").forEach((r,s)=>{r.setAttribute("aria-selected",String(i&&s===this._focusCol))})})}#P(e){this.#p[e]=!0,!this.#h&&(this.#h=!0,queueMicrotask(()=>this.#ne()))}#ne(){if(!this.#h||!this.#f){this.#h=!1;return}const e=this.#p;if(this.#h=!1,this.#p={rows:!1,columns:!1,gridConfig:!1,fitMode:!1,editMode:!1},e.gridConfig){this.#ae();return}e.columns&&this.#re(),e.rows&&this.#ie(),e.fitMode&&this.#se(),e.editMode&&this.#le()}#ie(){this._rows=Array.isArray(this.#r)?[...this.#r]:[],this.#l.requestPhase(L.ROWS,"applyRowsUpdate")}#re(){de(this),this.#o.merge(),this.#_()}#se(){this.#o.merge(),this.#n.fitMode==="fixed"?(this.__didInitialAutoSize=!1,Ve(this)):(this._columns.forEach(t=>{!t.__userResized&&t.__autoSized&&delete t.width}),te(this))}#le(){this.#o.merge(),this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.#l.requestPhase(L.VIRTUALIZATION,"applyEditModeUpdate")}#ae(){j(this,this.#t),X(this,this.#t);const e=!!this.#e.querySelector(".has-shell"),t=!!this.#e.querySelector(".tbw-tool-panel"),o=this.#e.querySelectorAll(".tbw-accordion-section").length;this.#o.parseLightDomColumns(this),this.#o.merge(),this.#$(),Y(this,this.#t,this.#R()),this.#o.markSourcesChanged(),this.#o.merge();const i=ut(this.#n?.shell),r=(this.#n?.shell?.toolPanels?.length??0)>0,s=(this.#n?.shell?.toolPanels?.length??0)!==o;if(e!==i||!e&&i||!t&&r||t&&s){this.#G(),this.#I(),this.#D();return}e&&this.#ce(),this.#l.requestPhase(L.COLUMNS,"applyGridConfigUpdate")}#ce(){const e=this.#e.querySelector(".tbw-shell-header");if(!e)return;const t=this.#n.shell?.header?.title??this.#t.lightDomTitle;let o=e.querySelector(".tbw-shell-title");t?(o||(o=document.createElement("h2"),o.className="tbw-shell-title",o.setAttribute("part","shell-title"),e.insertBefore(o,e.firstChild)),o.textContent=t):o&&o.remove()}#de(){if(this.#i){const e=this.#O.length>0?this.#O:this._columns,t=e.filter(r=>!r.hidden),o=e.filter(r=>r.hidden),i=this.#i.processColumns([...t]);if(i!==t){const r=new Map(i.map((l,a)=>[l.field,{col:l,order:a}]));if(!t.some(l=>r.has(l.field))&&i.length>0)this._columns=[...i,...o];else{const l=e.map(a=>{if(a.hidden)return a;const c=r.get(a.field);return c?c.col:a});this._columns=l}}else this._columns=[...e]}}#ue(){de(this);const e=Array.isArray(this.#r)?[...this.#r]:[],t=this.#i?.processRows(e)??e;this._rows=t}#he(e){const t={...Be,...e.animation},o=t.mode??"reduced-motion";let i=1;o===!1||o==="off"?i=0:(o===!0||o==="on")&&(i=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(i)),this.dataset.animationMode=typeof o=="boolean"?o?"on":"off":o}#q(e,t,o=this.__rowRenderEpoch){this.#a||(this.#a=(i,r,s)=>this.#i?.renderRow(i,r,s)??!1),ko(this,e,t,o,this.#a)}#F=-1;#X=-1;#Y(e,t){if(e===this.#F&&t===this.#X)return;const o=this.#F;this.#F=e,this.#X=t,this.__rowsBodyEl&&(this.__rowsBodyEl.setAttribute("aria-rowcount",String(e)),this.__rowsBodyEl.setAttribute("aria-colcount",String(t))),e!==o&&this._bodyEl&&(e>0?this._bodyEl.setAttribute("role","rowgroup"):this._bodyEl.removeAttribute("role"))}#_(){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.#i?.getAll()??[];this.#o.applyState(e,t)}this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),this.#l.requestPhase(L.FULL,"setup")}}#fe(e){if(this.refreshVirtualWindow(!1),this.#i?.onScrollRender(),this.#w){const t=this._virtualization.container,o=this.#S;o.scrollTop=e,o.scrollLeft=t?.scrollLeft??0,o.scrollHeight=t?.scrollHeight??0,o.scrollWidth=t?.scrollWidth??0,o.clientHeight=t?.clientHeight??0,o.clientWidth=t?.clientWidth??0,this.#i?.onScroll(o)}}findHeaderRow(){return this.#e.querySelector(".header-row")}findRenderedRowElement(e){return Array.from(this._bodyEl.querySelectorAll(".data-grid-row")).find(t=>{const o=t.querySelector(".cell[data-row]");return o&&Number(o.getAttribute("data-row"))===e})||null}_dispatchCellClick(e,t,o,i){const r=this._rows[t],s=this._columns[o];if(!r||!s)return!1;const l={row:r,rowIndex:t,colIndex:o,field:s.field,value:r[s.field],cellEl:i,originalEvent:e};return this.#i?.onCellClick(l)??!1}_dispatchRowClick(e,t,o,i){if(!o)return!1;const r={rowIndex:t,row:o,rowEl:i,originalEvent:e};return this.#i?.onRowClick(r)??!1}_dispatchHeaderClick(e,t,o){const i=this._columns[t];if(!i)return!1;const r={colIndex:t,field:i.field,column:i,headerEl:o,originalEvent:e};return this.#i?.onHeaderClick(r)??!1}_dispatchKeyDown(e){return this.#i?.onKeyDown(e)??!1}_getHorizontalScrollOffsets(e,t){return this.#i?.getHorizontalScrollOffsets(e,t)??{left:0,right:0}}queryPlugins(e){return this.#i?.queryPlugins(e)??[]}#z(e,t){let o=null;const i=e.composedPath?.();if(i&&i.length>0?o=i[0]:o=e.target,o&&!this.#e.contains(o)){const f=this.#e.elementFromPoint(e.clientX,e.clientY);f&&(o=f)}const r=o?.closest?.("[data-col]"),s=o?.closest?.(".data-grid-row"),l=o?.closest?.(".header-row");let a,c,d,u,h,p;return r&&(a=parseInt(r.getAttribute("data-row")??"-1",10),c=parseInt(r.getAttribute("data-col")??"-1",10),a>=0&&c>=0&&(d=this._rows[a],p=this._columns[c],u=p?.field,h=d&&u?d[u]:void 0)),{type:t,row:d,rowIndex:a!==void 0&&a>=0?a:void 0,colIndex:c!==void 0&&c>=0?c:void 0,field:u,value:h,column:p,originalEvent:e,cellElement:r??void 0,rowElement:s??void 0,isHeader:!!l,cell:a!==void 0&&c!==void 0&&a>=0&&c>=0?{row:a,col:c}:void 0}}#pe(e){const t=this.#z(e,"mousedown");(this.#i?.onCellMouseDown(t)??!1)&&(this.#v=!0)}#ge(e){if(!this.#v)return;const t=this.#z(e,"mousemove");this.#i?.onCellMouseMove(t)}#me(e){if(!this.#v)return;const t=this.#z(e,"mouseup");this.#i?.onCellMouseUp(t),this.#v=!1}async ready(){return this.#d}async forceLayout(){return this.#l.requestPhase(L.FULL,"forceLayout"),this.#l.whenReady()}async getConfig(){return Object.freeze({...this.#n||{}})}setColumnVisible(e,t){const o=this.#o.setColumnVisible(e,t);return o&&this.requestStateChange(),o}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.#i?.getAll()??[];return this.#o.collectState(e)}set columnState(e){e&&(this.#L=e,this.#o.initialColumnState=e,this.#s&&this.#we(e))}get columnState(){return this.getColumnState()}#we(e){const t=this.#i?.getAll()??[];this.#o.applyState(e,t),this.#_()}requestStateChange(){const e=this.#i?.getAll()??[];this.#o.requestStateChange(e)}resetColumnState(){this.#L=void 0,this.__originalOrder=[];const e=this.#i?.getAll()??[];this.#o.resetState(e),this.#o.merge(),this.#_()}get isToolPanelOpen(){return this.#u.isPanelOpen}get activeToolPanel(){return this.#u.activePanel}get expandedToolPanelSections(){return this.#u.expandedSections}openToolPanel(){this.#u.openToolPanel()}closeToolPanel(){this.#u.closeToolPanel()}toggleToolPanel(){this.#u.toggleToolPanel()}toggleToolPanelSection(e){this.#u.toggleToolPanelSection(e)}getToolPanels(){return this.#u.getToolPanels()}registerToolPanel(e){this.#t.apiToolPanelIds.add(e.id),this.#u.registerToolPanel(e)}unregisterToolPanel(e){this.#t.apiToolPanelIds.delete(e),this.#u.unregisterToolPanel(e)}getHeaderContents(){return this.#u.getHeaderContents()}registerHeaderContent(e){this.#u.registerHeaderContent(e)}unregisterHeaderContent(e){this.#u.unregisterHeaderContent(e)}getToolbarButtons(){return this.#u.getToolbarButtons()}registerToolbarButton(e){this.#u.registerToolbarButton(e)}unregisterToolbarButton(e){this.#u.unregisterToolbarButton(e)}setToolbarButtonDisabled(e,t){this.#u.setToolbarButtonDisabled(e,t)}refreshShellHeader(){j(this,this.#t),X(this,this.#t),Y(this,this.#t,this.#R()),this.#o.markSourcesChanged(),this.#o.merge(),this.#G(),this.#I(),this.#D()}#A=new Map;registerStyles(e,t){let o=this.#A.get(e);o||(o=new CSSStyleSheet,this.#A.set(e,o)),o.replaceSync(t),this.#Z()}unregisterStyles(e){this.#A.delete(e)&&this.#Z()}getRegisteredStyles(){return Array.from(this.#A.keys())}#Z(){const e=this.#e.adoptedStyleSheets[0],t=Array.from(this.#A.values());this.#e.adoptedStyleSheets=e?[e,...t]:t}#be(){const e=()=>{const o=this.#t.lightDomTitle,i=this.#t.hasToolButtonsContainer;j(this,this.#t),X(this,this.#t),Y(this,this.#t,this.#R());const r=this.#t.lightDomTitle,s=this.#t.hasToolButtonsContainer;if(r&&!o||s&&!i){this.#o.markSourcesChanged(),this.#o.merge();const l=this.#e.querySelector(".tbw-shell-header");if(l){const a=ht(this.#n.shell,this.#t,this.#n.icons?.toolPanel),c=document.createElement("div");c.innerHTML=a;const d=c.firstElementChild;d&&(l.replaceWith(d),this.#K())}}},t=()=>{this.__lightDomColumnsCache=void 0,this.#_()};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;j(this,this.#t),X(this,this.#t),Y(this,this.#t,this.#R());const o=this.#t.lightDomTitle,i=this.#t.hasToolButtonsContainer;if(o&&!e||i&&!t){this.#o.markSourcesChanged(),this.#o.merge();const s=this.#e.querySelector(".tbw-shell-header");if(s){const l=ht(this.#n.shell,this.#t,this.#n.icons?.toolPanel),a=document.createElement("div");a.innerHTML=l;const c=a.firstElementChild;c&&(s.replaceWith(c),this.#K())}}this.#l.requestPhase(L.COLUMNS,"refreshColumns")}#B(e){const t=this._virtualization.rowHeight,o=this._virtualization.container??this,i=this._virtualization.viewportEl??o,r=o.clientHeight,s=i.clientHeight,a=this.shadowRoot?.querySelector(".tbw-scroll-area"),c=a?a.clientHeight:r,u=c-s,h=this.#i?.getExtraHeight()??0,p=Math.max(0,r-c);return e*t+u+h+p}refreshVirtualWindow(e=!1){if(!this._bodyEl)return;const t=this._rows.length;if(!this._virtualization.enabled){this.#q(0,t),this.#i?.afterRender();return}if(this._rows.length<=this._virtualization.bypassThreshold){this._virtualization.start=0,this._virtualization.end=t,e&&(this._bodyEl.style.transform="translateY(0px)"),this.#q(0,t,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${this.#B(t)}px`),this.#Y(t,this._visibleColumns.length),this.#i?.afterRender();return}const o=this._virtualization.container??this,i=this._virtualization.viewportEl??o,r=i.clientHeight,s=this._virtualization.rowHeight,l=o.scrollTop;let a=Math.floor(l/s),c=0;const d=10;for(;c<d;){const C=this.#i?.getExtraHeightBefore?.(a)??0,y=Math.floor((l-C)/s);if(y>=a||y<0)break;a=y,c++}a=a-a%2,a<0&&(a=0);const u=this.#i?.adjustVirtualStart(a,l,s);u!==void 0&&u<a&&(a=u,a=a-a%2,a<0&&(a=0));const h=Math.ceil(r/s)+3;let p=a+h;if(p>t&&(p=t),this._virtualization.start=a,this._virtualization.end=p,o.clientHeight===0&&r>0){this.#l.requestPhase(L.VIRTUALIZATION,"stale-refs-retry");return}const g=this.#B(t);this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${g}px`);const w=this.#i?.getExtraHeightBefore?.(a)??0,m=-(l-a*s-w);this._bodyEl.style.transform=`translateY(${m}px)`,this.#q(a,p,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),this.#Y(t,this._visibleColumns.length),e&&(this.#i?.afterRender(),queueMicrotask(()=>{const C=o.clientHeight,y=i.clientHeight;if(C===0&&y>0)return;const x=this.#B(t);this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${x}px`)}))}#G(){j(this,this.#t),X(this,this.#t),Y(this,this.#t,this.#R()),this.#o.markSourcesChanged(),this.#o.merge();const e=this.#n?.shell;Vo(this.#e,e,{isPanelOpen:this.#t.isPanelOpen,expandedSections:this.#t.expandedSections},this.#n?.icons)&&(this.#K(),this.#u.setInitialized(!0))}#K(){Do(this.#e,this.#n?.shell,this.#t,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e),onToolbarButtonClick:e=>this.#ve(e)}),this.#M?.(),this.#M=No(this.#e,this.#n?.shell,e=>{this.style.setProperty("--tbw-tool-panel-width",`${e}px`)})}#ve(e){}}customElements.get(N.tagName)||customElements.define(N.tagName,N),globalThis.DataGridElement=N;const ie={CAN_MOVE_COLUMN:"canMoveColumn",GET_CONTEXT_MENU_ITEMS:"getContextMenuItems"};class S{static dependencies;version="1.0.0";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}))}requestRender(){this.grid?.requestRender?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get shadowRoot(){return this.grid?.shadowRoot??null}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...O,...e}}resolveIcon(e,t){return t!==void 0?t:this.gridIcons[e]}setIcon(e,t){typeof t=="string"?e.innerHTML=t:t instanceof HTMLElement&&(e.innerHTML="",e.appendChild(t.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}const k={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"},rn={ROOT:`.${k.ROOT}`,HEADER:`.${k.HEADER}`,HEADER_ROW:`.${k.HEADER_ROW}`,HEADER_CELL:`.${k.HEADER_CELL}`,ROWS_VIEWPORT:`.${k.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${k.ROWS_CONTAINER}`,DATA_ROW:`.${k.DATA_ROW}`,DATA_CELL:`.${k.DATA_CELL}`,GROUP_ROW:`.${k.GROUP_ROW}`,ROW_BY_INDEX:n=>`.${k.DATA_ROW}[${re.ROW_INDEX}="${n}"]`,CELL_BY_FIELD:n=>`.${k.DATA_CELL}[${re.FIELD}="${n}"]`,CELL_AT:(n,e)=>`.${k.DATA_ROW}[${re.ROW_INDEX}="${n}"] .${k.DATA_CELL}[${re.COL_INDEX}="${e}"]`,SELECTED_ROWS:`.${k.DATA_ROW}.${k.SELECTED}`,EDITING_CELL:`.${k.DATA_CELL}.${k.EDITING}`},sn={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"},ln={CELL_COMMIT:"cell-commit",ROW_COMMIT:"row-commit",CHANGED_ROWS_RESET:"changed-rows-reset",MOUNT_EXTERNAL_VIEW:"mount-external-view",MOUNT_EXTERNAL_EDITOR:"mount-external-editor",SORT_CHANGE:"sort-change",COLUMN_RESIZE:"column-resize",ACTIVATE_CELL:"activate-cell",GROUP_TOGGLE:"group-toggle",COLUMN_STATE_CHANGE:"column-state-change"},an={SELECTION_CHANGE:"selection-change",TREE_EXPAND:"tree-expand",FILTER_CHANGE:"filter-change",SORT_MODEL_CHANGE:"sort-model-change",EXPORT_START:"export-start",EXPORT_COMPLETE:"export-complete",CLIPBOARD_COPY:"clipboard-copy",CLIPBOARD_PASTE:"clipboard-paste",CONTEXT_MENU_OPEN:"context-menu-open",CONTEXT_MENU_CLOSE:"context-menu-close",HISTORY_CHANGE:"history-change",SERVER_LOADING:"server-loading",SERVER_ERROR:"server-error",COLUMN_VISIBILITY_CHANGE:"column-visibility-change",COLUMN_REORDER:"column-reorder",DETAIL_EXPAND:"detail-expand",GROUP_EXPAND:"group-expand"};function cn(n,e,t,o){if(o.processCell)return o.processCell(n,e,t);if(n==null)return"";if(n instanceof Date)return n.toISOString();if(typeof n=="object")return JSON.stringify(n);const i=String(n),r=o.delimiter??" ",s=o.newline??`
|
|
50
|
+
`;return o.quoteStrings||i.includes(r)||i.includes(s)||i.includes('"')?`"${i.replace(/"/g,'""')}"`:i}function Ce(n){const{rows:e,columns:t,selectedIndices:o,config:i}=n,r=i.delimiter??" ",s=i.newline??`
|
|
51
|
+
`,l=t.filter(u=>!u.hidden&&!u.field.startsWith("__")),a=[];if(i.includeHeaders){const u=l.map(h=>{const p=h.header||h.field;return p.includes(r)||p.includes(s)||p.includes('"')?`"${p.replace(/"/g,'""')}"`:p});a.push(u.join(r))}const d=[...o instanceof Set?[...o]:o].sort((u,h)=>u-h);for(const u of d){const h=e[u];if(!h)continue;const p=l.map(f=>cn(h[f.field],f.field,h,i));a.push(p.join(r))}return a.join(s)}async function xe(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 vt(n,e){const t=e.delimiter??" ",o=e.newline??`
|
|
46
52
|
`,i=n.replace(/\r\n/g,`
|
|
47
53
|
`).replace(/\r/g,`
|
|
48
|
-
`),r=[];let s=[],l="",a=!1;for(let c=0;c<i.length;c++){const d=i[c];d==='"'&&!a?a=!0:d==='"'&&a?i[c+1]==='"'?(l+='"',c++):a=!1:d===t&&!a?(s.push(l),l=""):d===o&&!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
|
|
49
|
-
`,quoteStrings:!1}}lastCopied=null;detach(){this.lastCopied=null}onKeyDown(e){const t=(e.ctrlKey||e.metaKey)&&e.key==="c",o=(e.ctrlKey||e.metaKey)&&e.key==="v";return t?(this.#e(e.target),!0):o?(this.#s(),!0):!1}#e(e){const t=this.#d(),o=t?.getSelectedRows()??[],i=o.length>0,r=t?.getRanges()??[],s=r.length>0,l=t?.getSelectedCell()!=null;let a,c,d;if(i&&t)a=
|
|
50
|
-
`,h=[],p=this.columns.slice(a,c+1);if(this.config.includeHeaders){const f=p.map(g=>g.header||g.field);h.push(f.join(d))}for(let f=s;f<=l;f++){const g=this.rows[f];if(!g)continue;const w=p.map(m=>{const C=g[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}}#n(e){const t=e.closest("[data-field-cache]");if(!t)return null;const o=t.dataset.fieldCache;if(!o)return null;const i=t.dataset.row;if(!i)return null;const r=parseInt(i,10);if(isNaN(r))return null;const s=this.rows[r];if(!s)return null;const l=s[o],c=this.columns.find(u=>u.field===o)?.header||o;let d;if(this.config.includeHeaders){const u=l==null?"":String(l);d=`${c}: ${u}`}else d=l==null?"":String(l);return{text:d,field:o,value:l}}async copy(){const t=this.#d()?.getSelectedRows()??[],o=ye({rows:this.rows,columns:[...this.columns],selectedIndices:t,config:this.config});return await Ce(o),this.lastCopied={text:o,timestamp:Date.now()},o}async copyRows(e){const t=ye({rows:this.rows,columns:[...this.columns],selectedIndices:e,config:this.config});return await Ce(t),this.lastCopied={text:t,timestamp:Date.now()},t}async paste(){const e=await vt();return e?bt(e,this.config):null}getLastCopied(){return this.lastCopied}}const yt=100;function xe(n){if(n==null)return yt;if(typeof n=="number")return n;const e=parseFloat(n);return isNaN(e)?yt:e}function Ct(n){return n.map(e=>xe(e.width))}function xt(n){const e=[];let t=0;for(const o of n)e.push(t),t+=xe(o.width);return e}function Et(n){return n.reduce((e,t)=>e+xe(t.width),0)}function ln(n,e,t,o,i){const r=t.length;if(r===0)return{startCol:0,endCol:0,visibleColumns:[]};let s=an(n,t,o);s=Math.max(0,s-i);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+i);const c=[];for(let d=s;d<=a;d++)c.push(d);return{startCol:s,endCol:a,visibleColumns:c}}function an(n,e,t){let o=0,i=e.length-1;for(;o<i;){const r=Math.floor((o+i)/2);e[r]+t[r]<=n?o=r+1:i=r}return o}function cn(n,e,t){return t?n>e:!1}class dn extends S{name="columnVirtualization";version="1.0.0";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=Ct(t),this.columnOffsets=xt(t),this.totalWidth=Et(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=cn(e.length,this.config.threshold??30,this.config.autoEnable??!0);if(this.isVirtualized=t??!1,this.columnWidths=Ct(e),this.columnOffsets=xt(e),this.totalWidth=Et(e),!t)return this.startCol=0,this.endCol=e.length-1,[...e];const o=this.grid.clientWidth||800,i=ln(this.scrollLeft,o,this.columnOffsets,this.columnWidths,this.config.overscan??3);return this.startCol=i.startCol,this.endCol=i.endCol,i.visibleColumns.map(r=>e[r])}afterRender(){if(!this.isVirtualized)return;const e=this.shadowRoot;if(!e)return;const t=this.columnOffsets[this.startCol]??0,o=e.querySelector(".header-row"),i=e.querySelectorAll(".data-grid-row");o&&(o.style.paddingLeft=`${t}px`),i.forEach(s=>{s.style.paddingLeft=`${t}px`});const r=e.querySelector(".rows-viewport .rows");r&&(r.style.width=`${this.totalWidth}px`)}onScroll(e){!this.isVirtualized||Math.abs(e.scrollLeft-this.scrollLeft)<1||(this.scrollLeft=e.scrollLeft,this.requestRender())}getIsVirtualized(){return this.isVirtualized}getVisibleColumnRange(){return{start:this.startCol,end:this.endCol}}scrollToColumn(e){const t=this.columnOffsets[e]??0,o=this.grid;o.scrollLeft=t}getColumnOffset(e){return this.columnOffsets[e]??0}getTotalWidth(){return this.totalWidth}}const Ee=".tbw-context-menu{position:fixed;background:light-dark(#f5f5f5,#2a2a2a);color:light-dark(#222,#eee);border:1px solid light-dark(#d0d0d4,#454545);border-radius:4px;box-shadow:0 2px 10px #00000026;min-width:160px;padding:4px 0;z-index:10000;font-size:13px;font-family:system-ui,sans-serif}.tbw-context-menu-item{display:flex;align-items:center;padding:6px 12px;cursor:pointer;gap:8px}.tbw-context-menu-item:hover:not(.disabled){background: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:16px;text-align:center}.tbw-context-menu-label{flex:1}.tbw-context-menu-shortcut{color:light-dark(#888,#888);font-size:11px}.tbw-context-menu-arrow{font-size:10px;color:light-dark(#888,#888)}.tbw-context-menu-separator{height:1px;background:light-dark(#d0d0d4,#454545);margin:4px 0}";function Se(n,e){return(typeof n=="function"?n(e):n).filter(o=>!(o.hidden===!0||typeof o.hidden=="function"&&o.hidden(e)))}function un(n,e){return n.disabled===!0?!0:typeof n.disabled=="function"?n.disabled(e):!1}function Re(n,e,t,o=O.submenuArrow){const i=document.createElement("div");i.className="tbw-context-menu",i.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"),i.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=un(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 o=="string"?c.innerHTML=o:o instanceof HTMLElement&&c.appendChild(o.cloneNode(!0)),s.appendChild(c),s.addEventListener("mouseenter",()=>{if(s.querySelector(".tbw-context-menu")||!r.subMenu)return;const u=Se(r.subMenu,e),h=Re(u,e,t,o);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)}),i.appendChild(s)}return i}function St(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 o=n.getBoundingClientRect(),i=window.innerWidth,r=window.innerHeight;let s=e,l=t;e+o.width>i&&(s=e-o.width),t+o.height>r&&(l=t-o.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 Y=null,Z=null,z=null,_e=0;const Ae=[{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 hn extends S{name="contextMenu";version="1.0.0";get defaultConfig(){return{items:Ae}}isOpen=!1;position={x:0,y:0};params=null;menuElement=null;attach(e){super.attach(e),this.installGlobalHandlers(),_e++}detach(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null),this.isOpen=!1,this.params=null,this.uninstallGlobalHandlers()}installGlobalHandlers(){!z&&typeof document<"u"&&typeof Ee=="string"&&Ee&&(z=document.createElement("style"),z.id="tbw-context-menu-styles",z.textContent=Ee,document.head.appendChild(z)),Y||(Y=()=>{document.querySelectorAll(".tbw-context-menu").forEach(t=>t.remove())},document.addEventListener("click",Y)),Z||(Z=e=>{e.key==="Escape"&&document.querySelectorAll(".tbw-context-menu").forEach(o=>o.remove())},document.addEventListener("keydown",Z))}uninstallGlobalHandlers(){_e--,!(_e>0)&&(Y&&(document.removeEventListener("click",Y),Y=null),Z&&(document.removeEventListener("keydown",Z),Z=null),z&&(z.remove(),z=null))}afterRender(){const e=this.shadowRoot;if(!e)return;const t=e.children[0];t&&t.getAttribute("data-context-menu-bound")!=="true"&&(t.setAttribute("data-context-menu-bound","true"),t.addEventListener("contextmenu",o=>{const i=o;i.preventDefault();const r=i.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],p=this.rows[d];a={row:p,rowIndex:d,column:h,columnIndex:u,field:h?.field??"",value:p?.[h?.field]??null,isHeader:!1,event:i}}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:i}}else return;this.params=a,this.position={x:i.clientX,y:i.clientY};const c=Se(this.config.items??Ae,a);c.length&&(this.menuElement&&this.menuElement.remove(),this.menuElement=Re(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),St(this.menuElement,i.clientX,i.clientY),this.isOpen=!0,this.emit("context-menu-open",{params:a,items:c}))}))}showMenu(e,t,o){const i={row:o.row??null,rowIndex:o.rowIndex??-1,column:o.column??null,columnIndex:o.columnIndex??-1,field:o.field??"",value:o.value??null,isHeader:o.isHeader??!1,event:o.event??new MouseEvent("contextmenu")},r=Se(this.config.items??Ae,i);this.menuElement&&this.menuElement.remove(),this.menuElement=Re(r,i,s=>{s.action&&s.action(i),this.menuElement?.remove(),this.menuElement=null,this.isOpen=!1},this.gridIcons.submenuArrow),document.body.appendChild(this.menuElement),St(this.menuElement,e,t),this.isOpen=!0}hideMenu(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null,this.isOpen=!1)}isMenuOpen(){return this.isOpen}}function Rt(n){switch(n.type){case"number":return e=>{const t=document.createElement("input");return t.type="number",t.value=e.value!=null?String(e.value):"",t.addEventListener("blur",()=>e.commit(t.value===""?null:Number(t.value))),t.addEventListener("keydown",o=>{o.key==="Enter"&&e.commit(t.value===""?null:Number(t.value)),o.key==="Escape"&&e.cancel()}),t};case"boolean":return e=>{const t=document.createElement("input");return t.type="checkbox",t.checked=!!e.value,t.addEventListener("change",()=>e.commit(t.checked)),t};case"date":return e=>{const t=document.createElement("input");return t.type="date",e.value instanceof Date&&(t.valueAsDate=e.value),t.addEventListener("change",()=>e.commit(t.valueAsDate)),t.addEventListener("keydown",o=>{o.key==="Escape"&&e.cancel()}),t};case"select":case"typeahead":return e=>{const t=document.createElement("select"),o=e.column;o.multi&&(t.multiple=!0);const i=o.options;(typeof i=="function"?i():i||[]).forEach(l=>{const a=document.createElement("option");a.value=String(l.value),a.textContent=l.label,(o.multi&&Array.isArray(e.value)&&e.value.includes(l.value)||!o.multi&&e.value===l.value)&&(a.selected=!0),t.appendChild(a)});const s=()=>{if(o.multi){const l=[];Array.from(t.selectedOptions).forEach(a=>{l.push(a.value)}),e.commit(l)}else e.commit(t.value)};return t.addEventListener("change",s),t.addEventListener("blur",s),t.addEventListener("keydown",l=>{l.key==="Escape"&&e.cancel()}),t};default:return e=>{const t=document.createElement("input");return t.type="text",t.value=e.value!=null?String(e.value):"",t.addEventListener("blur",()=>e.commit(t.value)),t.addEventListener("keydown",o=>{o.key==="Enter"&&e.commit(t.value),o.key==="Escape"&&e.cancel()}),t}}}const ue='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function re(n){return!(typeof n!="string"||n==="__proto__"||n==="constructor"||n==="prototype")}function fn(n){return(n.__editingCellCount??0)>0}function pn(n){const e=(n.__editingCellCount??0)+1;n.__editingCellCount=e,n.setAttribute("data-has-editing","")}function _t(n){n.__editingCellCount=0,n.removeAttribute("data-has-editing")}function gn(n,e,t){const o=n.querySelector("input,textarea,select");if(!o)return;const i=()=>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;o.addEventListener("blur",()=>{t(i())}),o instanceof HTMLInputElement&&o.type==="checkbox"?o.addEventListener("change",()=>t(o.checked)):o instanceof HTMLSelectElement&&o.addEventListener("change",()=>t(i()))}class mn extends S{name="editing";version="1.0.0";get defaultConfig(){return{editOn:"click"}}#e=-1;#s=-1;#d=new Map;#c=new Set;#r=new Set;#n=!1;attach(e){super.attach(e);const t=this.disconnectSignal,o=e;o._activeEditRows=-1,o._rowEditSnapshots=new Map,o._changedRowIndices=new Set,Object.defineProperty(e,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(e,"changedRowIndices",{get:()=>this.changedRowIndices,configurable:!0}),e.resetChangedRows=i=>this.resetChangedRows(i),e.beginBulkEdit=(i,r)=>{r&&this.beginCellEdit(i,r)},document.addEventListener("keydown",i=>{i.key==="Escape"&&this.#e!==-1&&this.#l(this.#e,!0)},{capture:!0,signal:t}),document.addEventListener("mousedown",i=>{if(this.#e===-1)return;const r=o.findRenderedRowElement?.(this.#e);!r||(i.composedPath&&i.composedPath()||[]).includes(r)||this.#l(this.#e,!1)},{signal:t})}detach(){this.#e=-1,this.#s=-1,this.#d.clear(),this.#c.clear(),this.#r.clear(),super.detach()}processColumns(e){return e}onCellClick(e){const t=this.grid,o=this.config.editOn??t.effectiveConfig?.editOn;if(o===!1||o==="manual"||o!=="click"&&o!=="dblclick")return!1;const i=e.originalEvent.type==="dblclick";if(o==="click"&&i||o==="dblclick"&&!i)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 o=t._focusRow,i=t._focusCol;if(o>=0&&i>=0){const r=t._visibleColumns[i],s=t._rows[o];if(r?.editable&&r.type==="boolean"&&s){const l=r.field;if(re(l)){const c=!s[l];return this.#m(o,r,c,s),e.preventDefault(),this.requestRender(),!0}}}return!1}if(e.key==="Enter"&&!e.shiftKey){if(this.#e!==-1)return!1;const o=this.config.editOn??t.effectiveConfig?.editOn;if(o===!1||o==="manual")return!1;const i=t._focusRow;return i>=0&&t._columns?.some(s=>s.editable)?(this.beginBulkEdit(i),!0):!1}return!1}afterRender(){const e=this.grid;if(this.#n&&(this.#n=!1,this.#a(e)),this.#r.size!==0)for(const t of this.#r){const[o,i]=t.split(":"),r=parseInt(o,10),s=parseInt(i,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.#g(c,r,d,s,a,!0)}}onScrollRender(){this.afterRender()}get changedRows(){const e=this.grid;return Array.from(this.#c).map(t=>e._rows[t])}get changedRowIndices(){return Array.from(this.#c)}get activeEditRow(){return this.#e}get activeEditCol(){return this.#s}isRowEditing(e){return this.#e===e}isCellEditing(e,t){return this.#r.has(`${e}:${t}`)}isRowChanged(e){return this.#c.has(e)}resetChangedRows(e){const t=this.changedRows,o=this.changedRowIndices;this.#c.clear(),this.#h(),e||this.emit("changed-rows-reset",{rows:t,indices:o}),this.grid._rowPool?.forEach(r=>r.classList.remove("changed"))}beginCellEdit(e,t){const o=this.grid,i=o._visibleColumns.findIndex(a=>a.field===t);if(i===-1||!o._visibleColumns[i]?.editable)return;const l=o.findRenderedRowElement?.(e)?.querySelector(`.cell[data-col="${i}"]`);l&&this.#f(e,i,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.#g(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(ue);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)}#f(e,t,o){const i=this.grid,r=i._rows[e],s=i._visibleColumns[t];!r||!s?.editable||o.classList.contains("editing")||(this.#e!==e&&this.#p(e,r),this.#s=t,this.#g(r,e,s,t,o,!1))}#h(){const e=this.grid;e._activeEditRows=this.#e,e._rowEditSnapshots=this.#d,e._changedRowIndices=this.#c}#p(e,t){this.#e!==e&&(this.#d.set(e,{...t}),this.#e=e,this.#h())}#l(e,t){if(this.#e!==e)return;const o=this.grid,i=this.#d.get(e),r=o._rows[e],s=o.findRenderedRowElement?.(e);if(!t&&s&&r&&s.querySelectorAll(".cell.editing").forEach(a=>{const c=Number(a.getAttribute("data-col"));if(isNaN(c))return;const d=o._visibleColumns[c];if(!d)return;const u=a.querySelector("input,textarea,select");if(u){let h;u instanceof HTMLInputElement&&u.type==="checkbox"?h=u.checked:(h=u.value,d.type==="number"&&h!==""&&(h=Number(h))),r[d.field]!==h&&this.#m(e,d,h,r)}}),t&&i&&r)Object.keys(i).forEach(l=>{r[l]=i[l]}),this.#c.delete(e);else if(!t){const l=this.#c.has(e);this.emit("row-commit",{rowIndex:e,row:r,changed:l,changedRows:this.changedRows,changedRowIndices:this.changedRowIndices})}this.#d.delete(e),this.#e=-1,this.#s=-1,this.#h();for(const l of this.#r)l.startsWith(`${e}:`)&&this.#r.delete(l);s&&(s.querySelectorAll(".cell.editing").forEach(l=>{l.classList.remove("editing"),_t(l.parentElement)}),this.requestRender()),this.#n=!0,s||(this.#a(o),this.#n=!1)}#m(e,t,o,i){const r=t.field;if(!re(r)||i[r]===o)return;i[r]=o;const l=!this.#c.has(e);this.#c.add(e),this.#h();const c=this.grid.findRenderedRowElement?.(e);c&&c.classList.add("changed"),this.emit("cell-commit",{row:i,field:r,value:o,rowIndex:e,changedRows:this.changedRows,changedRowIndices:this.changedRowIndices,firstTimeForRow:l})}#g(e,t,o,i,r,s){if(!o.editable||r.classList.contains("editing"))return;const l=re(o.field)?e[o.field]:void 0;r.classList.add("editing"),this.#r.add(`${t}:${i}`);const a=r.parentElement;a&&pn(a);let c=!1;const d=m=>{c||this.#e===-1||this.#m(t,o,m,e)},u=()=>{c=!0,re(o.field)&&(e[o.field]=l)},h=document.createElement("div");h.style.display="contents",r.innerHTML="",r.appendChild(h),h.addEventListener("keydown",m=>{m.key==="Enter"&&(m.stopPropagation(),m.preventDefault(),c=!0,this.#l(t,!1)),m.key==="Escape"&&(m.stopPropagation(),m.preventDefault(),u(),this.#l(t,!0))});const p=o,f=p.__editorTemplate,g=p.editor||(f?"template":Rt(o)),w=l;if(g==="template"&&f)this.#w(h,p,e,l,d,u,s,t);else if(typeof g=="string"){const m=document.createElement(g);m.value=w,m.addEventListener("change",()=>d(m.value)),h.appendChild(m),s||queueMicrotask(()=>{h.querySelector(ue)?.focus({preventScroll:!0})})}else if(typeof g=="function"){const m={row:e,value:w,field:o.field,column:o,commit:d,cancel:u},C=g(m);typeof C=="string"?(h.innerHTML=C,gn(h,o,d)):C instanceof Node&&h.appendChild(C),s||queueMicrotask(()=>{h.querySelector(ue)?.focus({preventScroll:!0})})}else if(g&&typeof g=="object"){const m=this.grid,C=document.createElement("div");C.setAttribute("data-external-editor",""),C.setAttribute("data-field",o.field),h.appendChild(C);const y={row:e,value:w,field:o.field,column:o,commit:d,cancel:u};if(g.mount)try{g.mount({placeholder:C,context:y,spec:g})}catch(x){console.warn(`[tbw-grid] External editor mount error for column '${o.field}':`,x)}else m.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:C,spec:g,context:y}}))}}#w(e,t,o,i,r,s,l,a){const c=t.__editorTemplate;if(!c)return;const d=c.cloneNode(!0),u=t.__compiledEditor;u?d.innerHTML=u({row:o,value:i,field:t.field,column:t,commit:r,cancel:s}):d.querySelectorAll("*").forEach(p=>{p.childNodes.length===1&&p.firstChild?.nodeType===Node.TEXT_NODE&&(p.textContent=p.textContent?.replace(/{{\s*value\s*}}/g,i==null?"":String(i)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(f,g)=>{if(!re(g))return"";const w=o[g];return w==null?"":String(w)})||"")});const h=d.querySelector("input,textarea,select");if(h){h instanceof HTMLInputElement&&h.type==="checkbox"?h.checked=!!i:h.value=String(i??"");let p=!1;h.addEventListener("blur",()=>{if(p)return;const f=h instanceof HTMLInputElement&&h.type==="checkbox"?h.checked:h.value;r(f)}),h.addEventListener("keydown",f=>{const g=f;if(g.key==="Enter"){g.stopPropagation(),g.preventDefault(),p=!0;const w=h instanceof HTMLInputElement&&h.type==="checkbox"?h.checked:h.value;r(w),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)}#a(e){queueMicrotask(()=>{try{const t=e._focusRow,o=e._focusCol,i=e.findRenderedRowElement?.(t);if(i){Array.from(e._bodyEl.querySelectorAll(".cell-focus")).forEach(s=>s.classList.remove("cell-focus"));const r=i.querySelector(`.cell[data-row="${t}"][data-col="${o}"]`);r&&(r.classList.add("cell-focus"),r.setAttribute("aria-selected","true"),r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1"),r.focus({preventScroll:!0}))}}catch{}})}}function At(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(`
|
|
51
|
-
`)||t.includes("\r"))?`"${t.replace(/"/g,'""')}"`:t}function
|
|
52
|
-
`,s=[],l=o.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
|
|
54
|
+
`),r=[];let s=[],l="",a=!1;for(let c=0;c<i.length;c++){const d=i[c];d==='"'&&!a?a=!0:d==='"'&&a?i[c+1]==='"'?(l+='"',c++):a=!1:d===t&&!a?(s.push(l),l=""):d===o&&!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 yt(){try{return await navigator.clipboard.readText()}catch{return""}}class dn extends S{static dependencies=[{name:"selection",required:!0,reason:"ClipboardPlugin needs selection to determine what cells to copy"}];name="clipboard";version="1.0.0";get defaultConfig(){return{includeHeaders:!1,delimiter:" ",newline:`
|
|
55
|
+
`,quoteStrings:!1}}lastCopied=null;detach(){this.lastCopied=null}onKeyDown(e){const t=(e.ctrlKey||e.metaKey)&&e.key==="c",o=(e.ctrlKey||e.metaKey)&&e.key==="v";return t?(this.#e(e.target),!0):o?(this.#s(),!0):!1}#e(e){const t=this.#d(),o=t?.getSelectedRows()??[],i=o.length>0,r=t?.getRanges()??[],s=r.length>0,l=t?.getSelectedCell()!=null;let a,c,d;if(i&&t)a=Ce({rows:this.rows,columns:[...this.columns],selectedIndices:o,config:this.config}),c=o.length,d=this.columns.filter(u=>!u.hidden&&!u.field.startsWith("__")).length;else if(s&&t){const u=r[r.length-1],h=this.#r({startRow:u.from.row,startCol:u.from.col,endRow:u.to.row,endCol:u.to.col});a=h.text,c=h.rowCount,d=h.columnCount}else if(l&&t){const u=t.getSelectedCell(),h=this.#c(u.row,u.col);if(!h)return;a=h.text,c=1,d=1}else{const u=this.#n(e);if(!u)return;a=u.text,c=1,d=1}xe(a).then(()=>{this.lastCopied={text:a,timestamp:Date.now()},this.emit("copy",{text:a,rowCount:c,columnCount:d})})}#s(){yt().then(e=>{if(!e)return;const t=vt(e,this.config);this.emit("paste",{rows:t,text:e})})}#d(){try{const e=this.grid?.getPluginByName("selection");if(e)return e}catch{}}#c(e,t){const o=this.rows[e];if(!o)return null;const i=this.columns[t];if(!i)return null;const r=o[i.field],s=i.header||i.field;let l;if(this.config.includeHeaders){const a=r==null?"":String(r);l=`${s}: ${a}`}else l=r==null?"":String(r);return{text:l}}#r(e){const{startRow:t,startCol:o,endRow:i,endCol:r}=e,s=Math.min(t,i),l=Math.max(t,i),a=Math.min(o,r),c=Math.max(o,r),d=this.config.delimiter??" ",u=this.config.newline??`
|
|
56
|
+
`,h=[],p=this.columns.slice(a,c+1);if(this.config.includeHeaders){const f=p.map(g=>g.header||g.field);h.push(f.join(d))}for(let f=s;f<=l;f++){const g=this.rows[f];if(!g)continue;const w=p.map(m=>{const C=g[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}}#n(e){const t=e.closest("[data-field-cache]");if(!t)return null;const o=t.dataset.fieldCache;if(!o)return null;const i=t.dataset.row;if(!i)return null;const r=parseInt(i,10);if(isNaN(r))return null;const s=this.rows[r];if(!s)return null;const l=s[o],c=this.columns.find(u=>u.field===o)?.header||o;let d;if(this.config.includeHeaders){const u=l==null?"":String(l);d=`${c}: ${u}`}else d=l==null?"":String(l);return{text:d,field:o,value:l}}async copy(){const t=this.#d()?.getSelectedRows()??[],o=Ce({rows:this.rows,columns:[...this.columns],selectedIndices:t,config:this.config});return await xe(o),this.lastCopied={text:o,timestamp:Date.now()},o}async copyRows(e){const t=Ce({rows:this.rows,columns:[...this.columns],selectedIndices:e,config:this.config});return await xe(t),this.lastCopied={text:t,timestamp:Date.now()},t}async paste(){const e=await yt();return e?vt(e,this.config):null}getLastCopied(){return this.lastCopied}}const Ct=100;function Ee(n){if(n==null)return Ct;if(typeof n=="number")return n;const e=parseFloat(n);return isNaN(e)?Ct:e}function xt(n){return n.map(e=>Ee(e.width))}function Et(n){const e=[];let t=0;for(const o of n)e.push(t),t+=Ee(o.width);return e}function St(n){return n.reduce((e,t)=>e+Ee(t.width),0)}function un(n,e,t,o,i){const r=t.length;if(r===0)return{startCol:0,endCol:0,visibleColumns:[]};let s=hn(n,t,o);s=Math.max(0,s-i);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+i);const c=[];for(let d=s;d<=a;d++)c.push(d);return{startCol:s,endCol:a,visibleColumns:c}}function hn(n,e,t){let o=0,i=e.length-1;for(;o<i;){const r=Math.floor((o+i)/2);e[r]+t[r]<=n?o=r+1:i=r}return o}function fn(n,e,t){return t?n>e:!1}class pn extends S{name="columnVirtualization";version="1.0.0";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=xt(t),this.columnOffsets=Et(t),this.totalWidth=St(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=fn(e.length,this.config.threshold??30,this.config.autoEnable??!0);if(this.isVirtualized=t??!1,this.columnWidths=xt(e),this.columnOffsets=Et(e),this.totalWidth=St(e),!t)return this.startCol=0,this.endCol=e.length-1,[...e];const o=this.grid.clientWidth||800,i=un(this.scrollLeft,o,this.columnOffsets,this.columnWidths,this.config.overscan??3);return this.startCol=i.startCol,this.endCol=i.endCol,i.visibleColumns.map(r=>e[r])}afterRender(){if(!this.isVirtualized)return;const e=this.shadowRoot;if(!e)return;const t=this.columnOffsets[this.startCol]??0,o=e.querySelector(".header-row"),i=e.querySelectorAll(".data-grid-row");o&&(o.style.paddingLeft=`${t}px`),i.forEach(s=>{s.style.paddingLeft=`${t}px`});const r=e.querySelector(".rows-viewport .rows");r&&(r.style.width=`${this.totalWidth}px`)}onScroll(e){!this.isVirtualized||Math.abs(e.scrollLeft-this.scrollLeft)<1||(this.scrollLeft=e.scrollLeft,this.requestRender())}getIsVirtualized(){return this.isVirtualized}getVisibleColumnRange(){return{start:this.startCol,end:this.endCol}}scrollToColumn(e){const t=this.columnOffsets[e]??0,o=this.grid;o.scrollLeft=t}getColumnOffset(e){return this.columnOffsets[e]??0}getTotalWidth(){return this.totalWidth}}const Se=".tbw-context-menu{position:fixed;background:light-dark(#f5f5f5,#2a2a2a);color:light-dark(#222,#eee);border:1px solid light-dark(#d0d0d4,#454545);border-radius:4px;box-shadow:0 2px 10px #00000026;min-width:160px;padding:4px 0;z-index:10000;font-size:13px;font-family:system-ui,sans-serif}.tbw-context-menu-item{display:flex;align-items:center;padding:6px 12px;cursor:pointer;gap:8px}.tbw-context-menu-item:hover:not(.disabled){background: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:16px;text-align:center}.tbw-context-menu-label{flex:1}.tbw-context-menu-shortcut{color:light-dark(#888,#888);font-size:11px}.tbw-context-menu-arrow{font-size:10px;color:light-dark(#888,#888)}.tbw-context-menu-separator{height:1px;background:light-dark(#d0d0d4,#454545);margin:4px 0}";function Re(n,e){return(typeof n=="function"?n(e):n).filter(o=>!(o.hidden===!0||typeof o.hidden=="function"&&o.hidden(e)))}function gn(n,e){return n.disabled===!0?!0:typeof n.disabled=="function"?n.disabled(e):!1}function _e(n,e,t,o=O.submenuArrow){const i=document.createElement("div");i.className="tbw-context-menu",i.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"),i.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=gn(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 o=="string"?c.innerHTML=o:o instanceof HTMLElement&&c.appendChild(o.cloneNode(!0)),s.appendChild(c),s.addEventListener("mouseenter",()=>{if(s.querySelector(".tbw-context-menu")||!r.subMenu)return;const u=Re(r.subMenu,e),h=_e(u,e,t,o);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)}),i.appendChild(s)}return i}function Rt(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 o=n.getBoundingClientRect(),i=window.innerWidth,r=window.innerHeight;let s=e,l=t;e+o.width>i&&(s=e-o.width),t+o.height>r&&(l=t-o.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 Z=null,J=null,z=null,Ae=0;const Te=[{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 mn extends S{name="contextMenu";version="1.0.0";get defaultConfig(){return{items:Te}}isOpen=!1;position={x:0,y:0};params=null;menuElement=null;attach(e){super.attach(e),this.installGlobalHandlers(),Ae++}detach(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null),this.isOpen=!1,this.params=null,this.uninstallGlobalHandlers()}installGlobalHandlers(){!z&&typeof document<"u"&&typeof Se=="string"&&Se&&(z=document.createElement("style"),z.id="tbw-context-menu-styles",z.textContent=Se,document.head.appendChild(z)),Z||(Z=()=>{document.querySelectorAll(".tbw-context-menu").forEach(t=>t.remove())},document.addEventListener("click",Z)),J||(J=e=>{e.key==="Escape"&&document.querySelectorAll(".tbw-context-menu").forEach(o=>o.remove())},document.addEventListener("keydown",J))}uninstallGlobalHandlers(){Ae--,!(Ae>0)&&(Z&&(document.removeEventListener("click",Z),Z=null),J&&(document.removeEventListener("keydown",J),J=null),z&&(z.remove(),z=null))}afterRender(){const e=this.shadowRoot;if(!e)return;const t=e.children[0];t&&t.getAttribute("data-context-menu-bound")!=="true"&&(t.setAttribute("data-context-menu-bound","true"),t.addEventListener("contextmenu",o=>{const i=o;i.preventDefault();const r=i.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],p=this.rows[d];a={row:p,rowIndex:d,column:h,columnIndex:u,field:h?.field??"",value:p?.[h?.field]??null,isHeader:!1,event:i}}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:i}}else return;this.params=a,this.position={x:i.clientX,y:i.clientY};const c=Re(this.config.items??Te,a);c.length&&(this.menuElement&&this.menuElement.remove(),this.menuElement=_e(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),Rt(this.menuElement,i.clientX,i.clientY),this.isOpen=!0,this.emit("context-menu-open",{params:a,items:c}))}))}showMenu(e,t,o){const i={row:o.row??null,rowIndex:o.rowIndex??-1,column:o.column??null,columnIndex:o.columnIndex??-1,field:o.field??"",value:o.value??null,isHeader:o.isHeader??!1,event:o.event??new MouseEvent("contextmenu")},r=Re(this.config.items??Te,i);this.menuElement&&this.menuElement.remove(),this.menuElement=_e(r,i,s=>{s.action&&s.action(i),this.menuElement?.remove(),this.menuElement=null,this.isOpen=!1},this.gridIcons.submenuArrow),document.body.appendChild(this.menuElement),Rt(this.menuElement,e,t),this.isOpen=!0}hideMenu(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null,this.isOpen=!1)}isMenuOpen(){return this.isOpen}}function _t(n){switch(n.type){case"number":return e=>{const t=document.createElement("input");return t.type="number",t.value=e.value!=null?String(e.value):"",t.addEventListener("blur",()=>e.commit(t.value===""?null:Number(t.value))),t.addEventListener("keydown",o=>{o.key==="Enter"&&e.commit(t.value===""?null:Number(t.value)),o.key==="Escape"&&e.cancel()}),t};case"boolean":return e=>{const t=document.createElement("input");return t.type="checkbox",t.checked=!!e.value,t.addEventListener("change",()=>e.commit(t.checked)),t};case"date":return e=>{const t=document.createElement("input");return t.type="date",e.value instanceof Date&&(t.valueAsDate=e.value),t.addEventListener("change",()=>e.commit(t.valueAsDate)),t.addEventListener("keydown",o=>{o.key==="Escape"&&e.cancel()}),t};case"select":case"typeahead":return e=>{const t=document.createElement("select"),o=e.column;o.multi&&(t.multiple=!0);const i=o.options;(typeof i=="function"?i():i||[]).forEach(l=>{const a=document.createElement("option");a.value=String(l.value),a.textContent=l.label,(o.multi&&Array.isArray(e.value)&&e.value.includes(l.value)||!o.multi&&e.value===l.value)&&(a.selected=!0),t.appendChild(a)});const s=()=>{if(o.multi){const l=[];Array.from(t.selectedOptions).forEach(a=>{l.push(a.value)}),e.commit(l)}else e.commit(t.value)};return t.addEventListener("change",s),t.addEventListener("blur",s),t.addEventListener("keydown",l=>{l.key==="Escape"&&e.cancel()}),t};default:return e=>{const t=document.createElement("input");return t.type="text",t.value=e.value!=null?String(e.value):"",t.addEventListener("blur",()=>e.commit(t.value)),t.addEventListener("keydown",o=>{o.key==="Enter"&&e.commit(t.value),o.key==="Escape"&&e.cancel()}),t}}}const he='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function se(n){return!(typeof n!="string"||n==="__proto__"||n==="constructor"||n==="prototype")}function wn(n){return(n.__editingCellCount??0)>0}function bn(n){const e=(n.__editingCellCount??0)+1;n.__editingCellCount=e,n.setAttribute("data-has-editing","")}function At(n){n.__editingCellCount=0,n.removeAttribute("data-has-editing")}function vn(n,e,t){const o=n.querySelector("input,textarea,select");if(!o)return;const i=()=>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;o.addEventListener("blur",()=>{t(i())}),o instanceof HTMLInputElement&&o.type==="checkbox"?o.addEventListener("change",()=>t(o.checked)):o instanceof HTMLSelectElement&&o.addEventListener("change",()=>t(i()))}class yn extends S{name="editing";version="1.0.0";get defaultConfig(){return{editOn:"click"}}#e=-1;#s=-1;#d=new Map;#c=new Set;#r=new Set;#n=!1;attach(e){super.attach(e);const t=this.disconnectSignal,o=e;o._activeEditRows=-1,o._rowEditSnapshots=new Map,o._changedRowIndices=new Set,Object.defineProperty(e,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(e,"changedRowIndices",{get:()=>this.changedRowIndices,configurable:!0}),e.resetChangedRows=i=>this.resetChangedRows(i),e.beginBulkEdit=(i,r)=>{r&&this.beginCellEdit(i,r)},document.addEventListener("keydown",i=>{i.key==="Escape"&&this.#e!==-1&&this.#l(this.#e,!0)},{capture:!0,signal:t}),document.addEventListener("mousedown",i=>{if(this.#e===-1)return;const r=o.findRenderedRowElement?.(this.#e);!r||(i.composedPath&&i.composedPath()||[]).includes(r)||this.#l(this.#e,!1)},{signal:t})}detach(){this.#e=-1,this.#s=-1,this.#d.clear(),this.#c.clear(),this.#r.clear(),super.detach()}processColumns(e){return e}onCellClick(e){const t=this.grid,o=this.config.editOn??t.effectiveConfig?.editOn;if(o===!1||o==="manual"||o!=="click"&&o!=="dblclick")return!1;const i=e.originalEvent.type==="dblclick";if(o==="click"&&i||o==="dblclick"&&!i)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 o=t._focusRow,i=t._focusCol;if(o>=0&&i>=0){const r=t._visibleColumns[i],s=t._rows[o];if(r?.editable&&r.type==="boolean"&&s){const l=r.field;if(se(l)){const c=!s[l];return this.#m(o,r,c,s),e.preventDefault(),this.requestRender(),!0}}}return!1}if(e.key==="Enter"&&!e.shiftKey){if(this.#e!==-1)return!1;const o=this.config.editOn??t.effectiveConfig?.editOn;if(o===!1||o==="manual")return!1;const i=t._focusRow;return i>=0&&t._columns?.some(s=>s.editable)?(this.beginBulkEdit(i),!0):!1}return!1}afterRender(){const e=this.grid;if(this.#n&&(this.#n=!1,this.#a(e)),this.#r.size!==0)for(const t of this.#r){const[o,i]=t.split(":"),r=parseInt(o,10),s=parseInt(i,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.#g(c,r,d,s,a,!0)}}onScrollRender(){this.afterRender()}get changedRows(){const e=this.grid;return Array.from(this.#c).map(t=>e._rows[t])}get changedRowIndices(){return Array.from(this.#c)}get activeEditRow(){return this.#e}get activeEditCol(){return this.#s}isRowEditing(e){return this.#e===e}isCellEditing(e,t){return this.#r.has(`${e}:${t}`)}isRowChanged(e){return this.#c.has(e)}resetChangedRows(e){const t=this.changedRows,o=this.changedRowIndices;this.#c.clear(),this.#h(),e||this.emit("changed-rows-reset",{rows:t,indices:o}),this.grid._rowPool?.forEach(r=>r.classList.remove("changed"))}beginCellEdit(e,t){const o=this.grid,i=o._visibleColumns.findIndex(a=>a.field===t);if(i===-1||!o._visibleColumns[i]?.editable)return;const l=o.findRenderedRowElement?.(e)?.querySelector(`.cell[data-col="${i}"]`);l&&this.#f(e,i,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.#g(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)}#f(e,t,o){const i=this.grid,r=i._rows[e],s=i._visibleColumns[t];!r||!s?.editable||o.classList.contains("editing")||(this.#e!==e&&this.#p(e,r),this.#s=t,this.#g(r,e,s,t,o,!1))}#h(){const e=this.grid;e._activeEditRows=this.#e,e._rowEditSnapshots=this.#d,e._changedRowIndices=this.#c}#p(e,t){this.#e!==e&&(this.#d.set(e,{...t}),this.#e=e,this.#h())}#l(e,t){if(this.#e!==e)return;const o=this.grid,i=this.#d.get(e),r=o._rows[e],s=o.findRenderedRowElement?.(e);if(!t&&s&&r&&s.querySelectorAll(".cell.editing").forEach(a=>{const c=Number(a.getAttribute("data-col"));if(isNaN(c))return;const d=o._visibleColumns[c];if(!d)return;const u=a.querySelector("input,textarea,select");if(u){let h;u instanceof HTMLInputElement&&u.type==="checkbox"?h=u.checked:(h=u.value,d.type==="number"&&h!==""&&(h=Number(h))),r[d.field]!==h&&this.#m(e,d,h,r)}}),t&&i&&r)Object.keys(i).forEach(l=>{r[l]=i[l]}),this.#c.delete(e);else if(!t){const l=this.#c.has(e);this.emit("row-commit",{rowIndex:e,row:r,changed:l,changedRows:this.changedRows,changedRowIndices:this.changedRowIndices})}this.#d.delete(e),this.#e=-1,this.#s=-1,this.#h();for(const l of this.#r)l.startsWith(`${e}:`)&&this.#r.delete(l);s&&(s.querySelectorAll(".cell.editing").forEach(l=>{l.classList.remove("editing"),At(l.parentElement)}),this.requestRender()),this.#n=!0,s||(this.#a(o),this.#n=!1)}#m(e,t,o,i){const r=t.field;if(!se(r)||i[r]===o)return;i[r]=o;const l=!this.#c.has(e);this.#c.add(e),this.#h();const c=this.grid.findRenderedRowElement?.(e);c&&c.classList.add("changed"),this.emit("cell-commit",{row:i,field:r,value:o,rowIndex:e,changedRows:this.changedRows,changedRowIndices:this.changedRowIndices,firstTimeForRow:l})}#g(e,t,o,i,r,s){if(!o.editable||r.classList.contains("editing"))return;const l=se(o.field)?e[o.field]:void 0;r.classList.add("editing"),this.#r.add(`${t}:${i}`);const a=r.parentElement;a&&bn(a);let c=!1;const d=m=>{c||this.#e===-1||this.#m(t,o,m,e)},u=()=>{c=!0,se(o.field)&&(e[o.field]=l)},h=document.createElement("div");h.className="tbw-editor-host",r.innerHTML="",r.appendChild(h),h.addEventListener("keydown",m=>{m.key==="Enter"&&(m.stopPropagation(),m.preventDefault(),c=!0,this.#l(t,!1)),m.key==="Escape"&&(m.stopPropagation(),m.preventDefault(),u(),this.#l(t,!0))});const p=o,f=p.__editorTemplate,g=p.editor||(f?"template":_t(o)),w=l;if(g==="template"&&f)this.#w(h,p,e,l,d,u,s,t);else if(typeof g=="string"){const m=document.createElement(g);m.value=w,m.addEventListener("change",()=>d(m.value)),h.appendChild(m),s||queueMicrotask(()=>{h.querySelector(he)?.focus({preventScroll:!0})})}else if(typeof g=="function"){const m={row:e,value:w,field:o.field,column:o,commit:d,cancel:u},C=g(m);typeof C=="string"?(h.innerHTML=C,vn(h,o,d)):C instanceof Node&&h.appendChild(C),s||queueMicrotask(()=>{h.querySelector(he)?.focus({preventScroll:!0})})}else if(g&&typeof g=="object"){const m=this.grid,C=document.createElement("div");C.setAttribute("data-external-editor",""),C.setAttribute("data-field",o.field),h.appendChild(C);const y={row:e,value:w,field:o.field,column:o,commit:d,cancel:u};if(g.mount)try{g.mount({placeholder:C,context:y,spec:g})}catch(x){console.warn(`[tbw-grid] External editor mount error for column '${o.field}':`,x)}else m.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:C,spec:g,context:y}}))}}#w(e,t,o,i,r,s,l,a){const c=t.__editorTemplate;if(!c)return;const d=c.cloneNode(!0),u=t.__compiledEditor;u?d.innerHTML=u({row:o,value:i,field:t.field,column:t,commit:r,cancel:s}):d.querySelectorAll("*").forEach(p=>{p.childNodes.length===1&&p.firstChild?.nodeType===Node.TEXT_NODE&&(p.textContent=p.textContent?.replace(/{{\s*value\s*}}/g,i==null?"":String(i)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(f,g)=>{if(!se(g))return"";const w=o[g];return w==null?"":String(w)})||"")});const h=d.querySelector("input,textarea,select");if(h){h instanceof HTMLInputElement&&h.type==="checkbox"?h.checked=!!i:h.value=String(i??"");let p=!1;h.addEventListener("blur",()=>{if(p)return;const f=h instanceof HTMLInputElement&&h.type==="checkbox"?h.checked:h.value;r(f)}),h.addEventListener("keydown",f=>{const g=f;if(g.key==="Enter"){g.stopPropagation(),g.preventDefault(),p=!0;const w=h instanceof HTMLInputElement&&h.type==="checkbox"?h.checked:h.value;r(w),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)}#a(e){queueMicrotask(()=>{try{const t=e._focusRow,o=e._focusCol,i=e.findRenderedRowElement?.(t);if(i){Array.from(e._bodyEl.querySelectorAll(".cell-focus")).forEach(s=>s.classList.remove("cell-focus"));const r=i.querySelector(`.cell[data-row="${t}"][data-col="${o}"]`);r&&(r.classList.add("cell-focus"),r.setAttribute("aria-selected","true"),r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1"),r.focus({preventScroll:!0}))}}catch{}})}}function Tt(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(`
|
|
57
|
+
`)||t.includes("\r"))?`"${t.replace(/"/g,'""')}"`:t}function Cn(n,e,t,o={}){const i=o.delimiter??",",r=o.newline??`
|
|
58
|
+
`,s=[],l=o.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 Tt(u)});s.push(a.join(i))}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)),Tt(u)});s.push(c.join(i))}return l+s.join(r)}function ke(n,e){const t=URL.createObjectURL(n),o=document.createElement("a");o.href=t,o.download=e,o.style.display="none",document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(t)}function xn(n,e){const t=new Blob([n],{type:"text/csv;charset=utf-8;"});ke(t,e)}function kt(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function En(n,e,t){let o=`<?xml version="1.0" encoding="UTF-8"?>
|
|
53
59
|
<?mso-application progid="Excel.Sheet"?>
|
|
54
60
|
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
|
|
55
61
|
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
|
|
56
62
|
<Worksheet ss:Name="Sheet1">
|
|
57
63
|
<Table>`;if(t.includeHeaders!==!1){o+=`
|
|
58
|
-
<Row>`;for(const i of e){const r=i.header||i.field,s=t.processHeader?t.processHeader(r,i.field):r;o+=`<Cell><Data ss:Type="String">${
|
|
59
|
-
<Row>`;for(const r of e){let s=i[r.field];t.processCell&&(s=t.processCell(s,r.field,i));let l="String",a="";s==null?a="":typeof s=="number"&&!isNaN(s)?(l="Number",a=String(s)):s instanceof Date?(l="DateTime",a=s.toISOString()):a=
|
|
64
|
+
<Row>`;for(const i of e){const r=i.header||i.field,s=t.processHeader?t.processHeader(r,i.field):r;o+=`<Cell><Data ss:Type="String">${kt(s)}</Data></Cell>`}o+="</Row>"}for(const i of n){o+=`
|
|
65
|
+
<Row>`;for(const r of e){let s=i[r.field];t.processCell&&(s=t.processCell(s,r.field,i));let l="String",a="";s==null?a="":typeof s=="number"&&!isNaN(s)?(l="Number",a=String(s)):s instanceof Date?(l="DateTime",a=s.toISOString()):a=kt(String(s)),o+=`<Cell><Data ss:Type="${l}">${a}</Data></Cell>`}o+="</Row>"}return o+=`
|
|
60
66
|
</Table>
|
|
61
67
|
</Worksheet>
|
|
62
|
-
</Workbook>`,o}function yn(n,e){const t=e.endsWith(".xls")?e:`${e}.xls`,o=new Blob([n],{type:"application/vnd.ms-excel;charset=utf-8;"});Te(o,t)}class Cn extends S{name="export";version="1.0.0";get defaultConfig(){return{fileName:"export",includeHeaders:!0,onlyVisible:!0,onlySelected:!1}}isExportingFlag=!1;lastExportInfo=null;performExport(e,t){const o=this.config,i={format:e,fileName:t?.fileName??o.fileName??"export",includeHeaders:t?.includeHeaders??o.includeHeaders,processCell:t?.processCell,processHeader:t?.processHeader,columns:t?.columns,rowIndices:t?.rowIndices};let r=[...this.columns];if(o.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(o.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=i.fileName;try{switch(e){case"csv":{const a=wn(s,r,i,{bom:!0});l=l.endsWith(".csv")?l:`${l}.csv`,bn(a,l);break}case"excel":{const a=vn(s,r,i);l=l.endsWith(".xls")?l:`${l}.xls`,yn(a,l);break}case"json":{const a=s.map(u=>{const h={};for(const p of r){let f=u[p.field];i.processCell&&(f=i.processCell(f,p.field,u)),h[p.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"});Te(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 xn(n){const{totalRows:e,viewportHeight:t,scrollTop:o,rowHeight:i,overscan:r}=n,s=Math.ceil(t/i);let l=Math.floor(o/i)-r;l<0&&(l=0);let a=l+s+r*2;return a>e&&(a=e),a===e&&l>0&&(l=Math.max(0,a-s-r*2)),{start:l,end:a,offsetY:l*i,totalHeight:e*i}}function En(n,e){return n<=e}function Sn(n,e,t=!1){const o=n[e.field];if(e.operator==="blank")return o==null||o==="";if(e.operator==="notBlank")return o!=null&&o!=="";if(o==null)return!1;const i=String(o),r=t?i:i.toLowerCase(),s=t?String(e.value):String(e.value).toLowerCase();switch(e.operator){case"contains":return r.includes(s);case"notContains":return!r.includes(s);case"equals":return r===s;case"notEquals":return r!==s;case"startsWith":return r.startsWith(s);case"endsWith":return r.endsWith(s);case"lessThan":return Number(o)<Number(e.value);case"lessThanOrEqual":return Number(o)<=Number(e.value);case"greaterThan":return Number(o)>Number(e.value);case"greaterThanOrEqual":return Number(o)>=Number(e.value);case"between":return Number(o)>=Number(e.value)&&Number(o)<=Number(e.valueTo);case"in":return Array.isArray(e.value)&&e.value.includes(o);case"notIn":return Array.isArray(e.value)&&!e.value.includes(o);default:return!0}}function Rn(n,e,t=!1){return e.length?n.filter(o=>e.every(i=>Sn(o,i,t))):n}function _n(n){return JSON.stringify(n.map(e=>({field:e.field,operator:e.operator,value:e.value,valueTo:e.valueTo})))}function kt(n,e){const t=new Set;for(const o of n){const i=o[e];i!=null&&t.add(i)}return[...t].sort((o,i)=>typeof o=="number"&&typeof i=="number"?o-i:String(o).localeCompare(String(i)))}const An=':host .tbw-quick-filter-input{flex:1;max-width:300px;height:28px;padding:0 8px;border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);background:var(--tbw-color-bg);color:var(--tbw-color-fg);font-size:13px}:host .tbw-quick-filter-input:focus{outline:none;border-color:var(--tbw-color-accent)}:host .header-cell.filtered:before{content:"";position:absolute;top:4px;right:4px;width:6px;height:6px;background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border-radius:50%}:host .tbw-filter-btn{display:inline-flex;align-items:center;justify-content:center;background:transparent;border:none;cursor:pointer;padding:2px;margin-left:4px;opacity:.4;transition:opacity .15s;color:inherit;vertical-align:middle}:host .tbw-filter-btn:hover,:host .tbw-filter-btn.active{opacity:1}:host .tbw-filter-btn.active{color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6))}',Tn=".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, 4px));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:12px;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, 13px)}.tbw-filter-search{margin-bottom:8px}.tbw-filter-search-input{width:100%;padding:6px 10px;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, 4px);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:4px 2px;margin-bottom:8px;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:12px;padding:2px 0}.tbw-filter-action-btn:hover{text-decoration:underline}.tbw-filter-values{flex:1;overflow-y:auto;margin-bottom:8px;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:8px;padding:4px 2px;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:8px 0;text-align:center;font-style:italic}.tbw-filter-buttons{display:flex;gap:8px;padding-top:8px;border-top:1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)))}.tbw-filter-apply-btn{flex:1;padding:6px 12px;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:4px;cursor:pointer;font-size:13px}.tbw-filter-apply-btn:hover{filter:brightness(.9)}.tbw-filter-clear-btn{flex:1;padding:6px 12px;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:4px;cursor:pointer;font-size:13px}.tbw-filter-clear-btn:hover{background:var(--tbw-filter-hover, var(--tbw-color-row-hover, light-dark(#f0f6ff, #1c1c1c)))}";class B extends S{name="filtering";version="1.0.0";get defaultConfig(){return{debounceMs:300,caseSensitive:!1,trimInput:!0,useWorker:!0}}filters=new Map;cachedResult=null;cacheKey=null;openPanelField=null;panelElement=null;searchText=new Map;excludedValues=new Map;panelAbortController=null;globalStylesInjected=!1;static LIST_ITEM_HEIGHT=28;static LIST_OVERSCAN=3;static LIST_BYPASS_THRESHOLD=50;attach(e){super.attach(e),this.injectGlobalStyles()}detach(){this.filters.clear(),this.cachedResult=null,this.cacheKey=null,this.openPanelField=null,this.panelElement&&(this.panelElement.remove(),this.panelElement=null),this.searchText.clear(),this.excludedValues.clear(),this.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 o=_n(t);if(this.cacheKey===o&&this.cachedResult)return this.cachedResult;const i=Rn([...e],t,this.config.caseSensitive);return this.cachedResult=i,this.cacheKey=o,i}afterRender(){const e=this.shadowRoot;if(!e)return;e.querySelectorAll('[part~="header-cell"]').forEach(o=>{const i=o.getAttribute("data-col");if(i===null)return;const r=this.visibleColumns[parseInt(i,10)];if(!r||r.filterable===!1)return;const s=r.field;if(!s)return;const l=this.filters.has(s);let a=o.querySelector(".tbw-filter-btn");if(a){a.classList.toggle("active",l),o.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"),o.classList.add("filtered")),a.addEventListener("click",d=>{d.stopPropagation(),this.toggleFilterPanel(s,r,a)});const c=o.querySelector(".resize-handle");c?o.insertBefore(a,c):o.appendChild(a)})}setFilter(e,t){t===null?(this.filters.delete(e),this.excludedValues.delete(e)):(this.filters.set(e,{...t,field:e}),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.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),t.type==="set"&&t.operator==="notIn"&&Array.isArray(t.value)&&this.excludedValues.set(t.field,new Set(t.value));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 kt(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=Tn,document.head.appendChild(e),this.globalStylesInjected=!0}toggleFilterPanel(e,t,o){if(this.openPanelField===e){this.closeFilterPanel();return}this.closeFilterPanel();const i=document.createElement("div");if(i.className="tbw-filter-panel",this.panelElement=i,this.openPanelField=e,this.config.valuesHandler){i.innerHTML='<div class="tbw-filter-loading">Loading...</div>',document.body.appendChild(i),this.positionPanel(i,o),this.setupPanelCloseHandler(i,o),this.config.valuesHandler(e,t).then(s=>{this.openPanelField!==e||!this.panelElement||(i.innerHTML="",this.renderPanelContent(e,t,i,s))});return}const r=kt(this.sourceRows,e);this.renderPanelContent(e,t,i,r),document.body.appendChild(i),this.positionPanel(i,o),this.setupPanelCloseHandler(i,o)}renderPanelContent(e,t,o,i){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:i,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(o,l),a=o.children.length>0),a||this.renderDefaultFilterPanel(o,l,i,r)}setupPanelCloseHandler(e,t){this.panelAbortController=new AbortController,setTimeout(()=>{document.addEventListener("click",o=>{!e.contains(o.target)&&o.target!==t&&this.closeFilterPanel()},{signal:this.panelAbortController?.signal})},0)}closeFilterPanel(){this.panelElement&&(this.panelElement.remove(),this.panelElement=null),this.openPanelField=null,this.panelAbortController?.abort(),this.panelAbortController=null}positionPanel(e,t){const o=t.getBoundingClientRect();e.style.position="fixed",e.style.top=`${o.bottom+4}px`,e.style.left=`${o.left}px`,requestAnimationFrame(()=>{const i=e.getBoundingClientRect();i.right>window.innerWidth-8&&(e.style.left=`${window.innerWidth-i.width-8}px`),i.bottom>window.innerHeight-8&&(e.style.top=`${o.top-i.height-4}px`)})}renderDefaultFilterPanel(e,t,o,i){const{field:r}=t,s=document.createElement("div");s.className="tbw-filter-search";const l=document.createElement("input");l.type="text",l.placeholder="Search...",l.className="tbw-filter-search-input",l.value=this.searchText.get(r)??"",s.appendChild(l),e.appendChild(s);const a=document.createElement("div");a.className="tbw-filter-actions";const 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 b=[...w.values()],_=b.every(P=>P),M=b.every(P=>!P);d.checked=_,d.indeterminate=!_&&!M};d.addEventListener("change",()=>{const b=d.checked;for(const _ of w.keys())w.set(_,b);h(),y()}),e.appendChild(a);const p=document.createElement("div");p.className="tbw-filter-values";const f=document.createElement("div");f.className="tbw-filter-values-spacer",p.appendChild(f);const g=document.createElement("div");g.className="tbw-filter-values-content",p.appendChild(g);const w=new Map;o.forEach(b=>{const _=b==null?"__null__":String(b);w.set(_,!i.has(b))}),h();let m=[];const C=(b,_)=>{const M=b==null?"(Blank)":String(b),P=b==null?"__null__":String(b),T=document.createElement("label");T.className="tbw-filter-value-item",T.style.position="absolute",T.style.top=`${_*B.LIST_ITEM_HEIGHT}px`,T.style.left="0",T.style.right="0",T.style.height=`${B.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(P)??!0,F.dataset.value=P,F.addEventListener("change",()=>{w.set(P,F.checked),h()});const no=document.createElement("span");return no.textContent=M,T.appendChild(F),T.appendChild(no),T},y=()=>{const b=m.length,_=p.clientHeight,M=p.scrollTop;if(f.style.height=`${b*B.LIST_ITEM_HEIGHT}px`,En(b,B.LIST_BYPASS_THRESHOLD/3)){g.innerHTML="",g.style.transform="translateY(0px)",m.forEach((T,F)=>{g.appendChild(C(T,F))});return}const P=xn({totalRows:b,viewportHeight:_,scrollTop:M,rowHeight:B.LIST_ITEM_HEIGHT,overscan:B.LIST_OVERSCAN});g.style.transform=`translateY(${P.offsetY}px)`,g.innerHTML="";for(let T=P.start;T<P.end;T++)g.appendChild(C(m[T],T-P.start))},x=b=>{const _=b.toLowerCase();if(m=o.filter(M=>{const P=M==null?"(Blank)":String(M);return!b||P.toLowerCase().includes(_)}),m.length===0){f.style.height="0px",g.innerHTML="";const M=document.createElement("div");M.className="tbw-filter-no-match",M.textContent="No matching values",g.appendChild(M);return}y()};p.addEventListener("scroll",()=>{m.length>0&&y()},{passive:!0}),x(l.value),e.appendChild(p);let R;l.addEventListener("input",()=>{clearTimeout(R),R=setTimeout(()=>{this.searchText.set(r,l.value),x(l.value)},this.config.debounceMs??150)});const E=document.createElement("div");E.className="tbw-filter-buttons";const q=document.createElement("button");q.className="tbw-filter-apply-btn",q.textContent="Apply",q.addEventListener("click",()=>{const b=[];for(const[_,M]of w)if(!M)if(_==="__null__")b.push(null);else{const P=o.find(T=>String(T)===_);b.push(P!==void 0?P:_)}t.applySetFilter(b)}),E.appendChild(q);const A=document.createElement("button");A.className="tbw-filter-clear-btn",A.textContent="Clear Filter",A.addEventListener("click",()=>{t.clearFilter()}),E.appendChild(A),e.appendChild(E)}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,o,i){this.filters.set(e,{field:e,type:"text",operator:t,value:o,valueTo:i}),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 o=this.config.filterHandler(e,this.sourceRows),i=r=>{t.removeAttribute("aria-busy"),this.cachedResult=r,this.grid.rows=r,this.emit("filter-change",{filters:e,filteredRowCount:r.length}),this.requestRender()};o&&typeof o.then=="function"?o.then(i):i(o);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 o={field:e,type:t.filter.type,operator:t.filter.operator,value:t.filter.value,valueTo:t.filter.valueTo};this.filters.set(e,o),this.cachedResult=null,this.cacheKey=null}styles=An}function kn(n){if(!n.length)return[];const e=new Map,t=[],o=(s,l)=>{if(!l.length)return;const a=t[t.length-1];if(a&&a.implicit&&a.firstIndex+a.columns.length===s){a.columns.push(...l);return}t.push({id:"__implicit__"+s,label:void 0,columns:l,firstIndex:s,implicit:!0})};let i=[],r=0;return n.forEach((s,l)=>{const a=s.group;if(!a){i.length===0&&(r=l),i.push(s);return}i.length&&(o(r,i.slice()),i=[]);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)}),i.length&&o(r,i),t.length===1&&t[0].implicit&&t[0].columns.length===n.length?[]:t}function Ln(n,e,t){if(!e.length||!n)return;const o=new Map;for(const r of e)for(const s of r.columns)s.field&&o.set(s.field,r.id);const i=Array.from(n.querySelectorAll(".cell[data-field]"));i.forEach(r=>{const s=r.getAttribute("data-field")||"",l=o.get(s);l&&(r.classList.add("grouped"),r.getAttribute("data-group")||r.setAttribute("data-group",l))});for(const r of e){const s=r.columns[r.columns.length-1],l=i.find(a=>a.getAttribute("data-field")===s.field);l&&l.classList.add("group-end")}}function Pn(n,e){if(n.length===0)return null;const t=document.createElement("div");t.className="header-group-row",t.setAttribute("role","row");for(const o of n){const i=o.firstIndex!=null?o.firstIndex:e.findIndex(a=>o.columns.includes(a)),r=String(o.id).startsWith("__implicit__"),s=r?"":o.label||o.id,l=document.createElement("div");l.className="cell header-group-cell",r&&l.classList.add("implicit-group"),l.setAttribute("data-group",String(o.id)),l.style.gridColumn=`${i+1} / span ${o.columns.length}`,l.textContent=s,t.appendChild(l)}return t}function Hn(n){return n.some(e=>e.group!=null)}const Mn=".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:4px 8px;font-weight:600;font-size:.9em;text-transform:uppercase;letter-spacing:.5px;border-right:1px solid var(--tbw-grouping-columns-border, 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))}.header-row .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 In extends S{name="groupingColumns";version="1.0.0";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 o=t?.columns;return Array.isArray(o)?Hn(o):!1}processColumns(e){const t=this.grid?.gridConfig?.columnGroups;let o;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});o=e.map(s=>{const l=r.get(s.field);return l&&!s.group?{...s,group:l}:s})}else o=[...e];const i=kn(o);return i.length===0?(this.isActive=!1,this.groups=[],o):(this.isActive=!0,this.groups=i,o)}afterRender(){if(!this.isActive||this.groups.length===0){const s=this.shadowRoot?.querySelector(".header")?.querySelector(".header-group-row");s&&s.remove();return}const e=this.shadowRoot?.querySelector(".header");if(!e)return;const t=e.querySelector(".header-group-row");t&&t.remove();const o=Pn(this.groups,this.columns);if(o){o.classList.toggle("no-borders",!this.config.showGroupBorders);const r=e.querySelector(".header-row");r?e.insertBefore(o,r):e.appendChild(o)}const i=e.querySelector(".header-row");i&&(i.classList.toggle("no-group-borders",!this.config.showGroupBorders),Ln(i,this.groups,this.columns))}isGroupingActive(){return this.isActive}getGroups(){return this.groups}getGroupColumns(e){const t=this.groups.find(o=>o.id===e);return t?t.columns:[]}refresh(){this.requestRender()}styles=Mn}const ke={sum:(n,e)=>n.reduce((t,o)=>t+(Number(o[e])||0),0),avg:(n,e)=>{const t=n.reduce((o,i)=>o+(Number(i[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]},se=new Map,D={register(n,e){se.set(n,e)},unregister(n){se.delete(n)},get(n){if(n!==void 0)return typeof n=="function"?n:se.get(n)??ke[n]},run(n,e,t,o){const i=this.get(n);return i?i(e,t,o):void 0},has(n){return se.has(n)||n in ke},list(){return[...Object.keys(ke),...se.keys()]}},Lt={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 On(n){return Lt[n]??Lt.sum}D.register.bind(D),D.unregister.bind(D);const Pt=D.get.bind(D),Ht=D.run.bind(D);D.list.bind(D);function Dn({rows:n,config:e,expanded:t}){const o=e.groupOn;if(typeof o!="function")return[];const i={key:"__root__",value:null,depth:-1,rows:[],children:new Map};if(n.forEach(l=>{let a=o(l);a==null||a===!1?a=["__ungrouped__"]:Array.isArray(a)||(a=[a]);let c=i;a.forEach((d,u)=>{const h=d==null?"∅":String(d),p=c.key==="__root__"?h:c.key+"||"+h;let f=c.children.get(h);f||(f={key:p,value:d,depth:u,rows:[],children:new Map,parent:c},c.children.set(h,f)),c=f}),c.rows.push(l)}),i.children.size===1&&i.children.has("__ungrouped__")&&i.children.get("__ungrouped__").rows.length===n.length)return[];const r=[],s=l=>{if(l===i){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(i),r}function Nn(n,e){const t=new Set(n);return t.has(e)?t.delete(e):t.add(e),t}function qn(n){const e=new Set;for(const t of n)t.kind==="group"&&e.add(t.key);return e}function Fn(){return new Set}function zn(n){return n.kind!=="group"?0:n.rows.length}const Bn='.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, 2px 8px)}.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:20px;height:20px;margin-right:4px;background:none;border:0;font:inherit}.group-toggle:hover{background:var(--tbw-grouping-rows-toggle-hover, var(--tbw-color-row-hover));border-radius:2px}.group-label{display:inline-flex;align-items:center;gap:8px}.group-count{color:var(--tbw-grouping-rows-count-color, var(--tbw-color-fg-muted));font-size:.85em;font-weight:400}[data-group-depth="0"] .group-label{padding-left:0}[data-group-depth="1"] .group-label{padding-left:20px}[data-group-depth="2"] .group-label{padding-left:40px}[data-group-depth="3"] .group-label{padding-left:60px}[data-group-depth="4"] .group-label{padding-left:80px}.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 Gn extends S{name="groupingRows";version="1.0.0";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(){const t=this.grid.effectiveConfig?.animation?.mode??"reduced-motion";if(t===!1||t==="off")return!1;if(t!==!0&&t!=="on"){const o=this.shadowRoot?.host;if(o&&getComputedStyle(o).getPropertyValue("--tbw-animation-enabled").trim()==="0")return!1}return this.config.animation??"slide"}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 o=Dn({rows:[...e],config:t,expanded:this.expandedKeys});if(o.length===0)return this.isActive=!1,this.flattenedRows=[],[...e];this.isActive=!0,this.flattenedRows=o,this.keysToAnimate.clear();const i=new Set;return o.forEach((r,s)=>{if(r.kind==="data"){const l=`data-${s}`;i.add(l),this.previousVisibleKeys.has(l)||this.keysToAnimate.add(l)}}),this.previousVisibleKeys=i,o.map(r=>r.kind==="group"?{__isGroupRow:!0,__groupKey:r.key,__groupValue:r.value,__groupDepth:r.depth,__groupRows:r.rows,__groupExpanded:r.expanded,__groupRowCount:zn(r)}:r.row)}onCellClick(e){const t=e.row;if(t?.__isGroupRow&&e.originalEvent.target?.closest(".group-toggle"))return this.toggle(t.__groupKey),!0}renderRow(e,t,o){if(!e?.__isGroupRow)return!1;const i=this.config;if(i.groupRowRenderer){const l=()=>{this.toggle(e.__groupKey)},a=i.groupRowRenderer({key:e.__groupKey,value:e.__groupValue,depth:e.__groupDepth,rows:e.__groupRows,expanded:e.__groupExpanded,toggleExpand:l});if(a)return t.className="group-row",t.__isCustomRow=!0,t.setAttribute("data-group-depth",String(e.__groupDepth)),typeof a=="string"?t.innerHTML=a:(t.innerHTML="",t.appendChild(a)),!0}const r=()=>{this.toggle(e.__groupKey)};return t.className="group-row",t.__isCustomRow=!0,t.setAttribute("data-group-depth",String(e.__groupDepth)),t.setAttribute("role","row"),t.setAttribute("aria-expanded",String(e.__groupExpanded)),t.style.paddingLeft=`${(e.__groupDepth||0)*(i.indentWidth??20)}px`,t.innerHTML="",i.fullWidth!==!1?this.renderFullWidthGroupRow(e,t,r):this.renderPerColumnGroupRow(e,t,r),!0}afterRender(){const e=this.animationStyle;if(e===!1||this.keysToAnimate.size===0)return;const t=this.shadowRoot?.querySelector(".rows");if(!t)return;const o=e==="fade"?"tbw-group-fade-in":"tbw-group-slide-in";for(const i of t.querySelectorAll(".data-grid-row:not(.group-row)")){const r=i.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)&&(i.classList.add(o),i.addEventListener("animationend",()=>i.classList.remove(o),{once:!0}))}this.keysToAnimate.clear()}renderFullWidthGroupRow(e,t,o){const i=this.config,r=document.createElement("div");r.className="cell group-full",r.style.gridColumn="1 / -1",r.setAttribute("role","gridcell");const s=document.createElement("button");s.type="button",s.className=`group-toggle${e.__groupExpanded?" expanded":""}`,s.setAttribute("aria-label",e.__groupExpanded?"Collapse group":"Expand group"),this.setIcon(s,this.resolveIcon(e.__groupExpanded?"collapse":"expand")),s.addEventListener("click",c=>{c.stopPropagation(),o()}),r.appendChild(s);const l=document.createElement("span");l.className="group-label";const a=i.formatLabel?i.formatLabel(e.__groupValue,e.__groupDepth||0,e.__groupKey):String(e.__groupValue);if(l.textContent=a,r.appendChild(l),i.showRowCount!==!1){const c=document.createElement("span");c.className="group-count",c.textContent=`(${e.__groupRowCount??e.__groupRows?.length??0})`,r.appendChild(c)}t.appendChild(r)}renderPerColumnGroupRow(e,t,o){const i=this.config,r=i.aggregators??{},s=this.columns,l=e.__groupRows??[],c=this.shadowRoot?.querySelector(".body")?.style.gridTemplateColumns||"";c&&(t.style.display="grid",t.style.gridTemplateColumns=c),s.forEach((d,u)=>{const h=document.createElement("div");if(h.className="cell group-cell",h.setAttribute("data-col",String(u)),h.setAttribute("role","gridcell"),u===0){const p=document.createElement("button");p.type="button",p.className=`group-toggle${e.__groupExpanded?" expanded":""}`,p.setAttribute("aria-label",e.__groupExpanded?"Collapse group":"Expand group"),this.setIcon(p,this.resolveIcon(e.__groupExpanded?"collapse":"expand")),p.addEventListener("click",w=>{w.stopPropagation(),o()}),h.appendChild(p);const f=document.createElement("span"),g=r[d.field];if(g){const w=Ht(g,l,d.field,d);f.textContent=w!=null?String(w):String(e.__groupValue)}else{const w=i.formatLabel?i.formatLabel(e.__groupValue,e.__groupDepth||0,e.__groupKey):String(e.__groupValue);f.textContent=w}if(h.appendChild(f),i.showRowCount!==!1){const w=document.createElement("span");w.className="group-count",w.textContent=` (${l.length})`,h.appendChild(w)}}else{const p=r[d.field];if(p){const f=Ht(p,l,d.field,d);h.textContent=f!=null?String(f):""}else h.textContent=""}t.appendChild(h)})}expandAll(){this.expandedKeys=qn(this.flattenedRows),this.requestRender()}collapseAll(){this.expandedKeys=Fn(),this.requestRender()}toggle(e){this.expandedKeys=Nn(this.expandedKeys,e);const t=this.flattenedRows.find(o=>o.kind==="group"&&o.key===e);this.emit("group-toggle",{key:e,expanded:this.expandedKeys.has(e),value:t?.value,depth:t?.depth??0}),this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}expand(e){this.expandedKeys.has(e)||(this.expandedKeys=new Set([...this.expandedKeys,e]),this.requestRender())}collapse(e){if(this.expandedKeys.has(e)){const t=new Set(this.expandedKeys);t.delete(e),this.expandedKeys=t,this.requestRender()}}getGroupState(){const e=this.flattenedRows.filter(t=>t.kind==="group");return{isActive:this.isActive,expandedCount:this.expandedKeys.size,totalGroups:e.length,expandedKeys:[...this.expandedKeys]}}getRowCount(){return this.flattenedRows.length}refreshGroups(){this.requestRender()}getExpandedGroups(){return[...this.expandedKeys]}getFlattenedRows(){return this.flattenedRows}isGroupingActive(){return this.isActive}setGroupOn(e){this.config.groupOn=e,this.requestRender()}styles=Bn}function Le(n,e){const t=new Set(n);return t.has(e)?t.delete(e):t.add(e),t}function Kn(n,e){const t=new Set(n);return t.add(e),t}function Vn(n,e){const t=new Set(n);return t.delete(e),t}function Wn(n,e){return n.has(e)}function $n(n,e,t,o){const i=document.createElement("div");i.className="master-detail-row",i.setAttribute("data-detail-for",String(e)),i.setAttribute("role","row");const r=document.createElement("div");r.className="master-detail-cell",r.setAttribute("role","cell"),r.style.gridColumn=`1 / ${o+1}`;const s=t(n,e);return typeof s=="string"?r.innerHTML=s:s instanceof HTMLElement&&r.appendChild(s),i.appendChild(r),i}const Un=".master-detail-cell-wrapper{display:flex;align-items:center;gap:4px}.master-detail-toggle{cursor:pointer;opacity:.7;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center}.master-detail-toggle:hover{opacity:1}.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}.master-detail-cell{padding:16px;overflow:auto}.master-detail-row.tbw-expanding{animation:tbw-detail-expand var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}.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:500px;padding-top:16px;padding-bottom:16px}}@keyframes tbw-detail-collapse{0%{opacity:1;max-height:500px}to{opacity:0;max-height:0}}";class jn extends S{name="masterDetail";version="1.0.0";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 o=e;if(o.__frameworkAdapter?.parseDetailElement){const u=o.__frameworkAdapter.parseDetailElement(t);if(u){this.config={...this.config,detailRenderer:u};return}}const i=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={};i!==null&&(c.animation=i==="false"?!1:i),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 p=pe(d,{value:u,row:u});return te(p)}),Object.keys(c).length>0&&(this.config={...this.config,...c})}get isAnimationEnabled(){const t=this.grid.effectiveConfig?.animation?.mode??"reduced-motion";if(t===!1||t==="off")return!1;if(t===!0||t==="on")return!0;const o=this.shadowRoot?.host;return o?getComputedStyle(o).getPropertyValue("--tbw-animation-enabled").trim()!=="0":!0}get animationStyle(){return this.isAnimationEnabled?this.config.animation??"slide":!1}get animationDuration(){const e=this.shadowRoot?.host;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),o=parseInt(t,10);if(!isNaN(o))return o}return 200}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 o=()=>{e.classList.remove("tbw-collapsing"),t()};e.addEventListener("animationend",o,{once:!0}),setTimeout(o,this.animationDuration+50)}expandedRows=new Set;detailElements=new Map;detach(){this.expandedRows.clear(),this.detailElements.clear()}processColumns(e){if(!this.config.detailRenderer)return[...e];const t=[...e];if(t.length>0){const o={...t[0]},i=o.viewRenderer;if(i?.__masterDetailWrapped)return t;const r=s=>{const{value:l,row:a}=s,c=this.expandedRows.has(a),d=document.createElement("span");d.className="master-detail-cell-wrapper";const u=document.createElement("span");u.className=`master-detail-toggle${c?" expanded":""}`,this.setIcon(u,this.resolveIcon(c?"collapse":"expand")),u.setAttribute("role","button"),u.setAttribute("tabindex","0"),u.setAttribute("aria-expanded",String(c)),u.setAttribute("aria-label",c?"Collapse details":"Expand details"),d.appendChild(u);const h=document.createElement("span");if(i){const p=i(s);p instanceof Node?h.appendChild(p):h.textContent=String(p??l??"")}else h.textContent=String(l??"");return d.appendChild(h),d};r.__masterDetailWrapped=!0,o.viewRenderer=r,t[0]=o}return t}onRowClick(e){if(!(!this.config.expandOnRowClick||!this.config.detailRenderer))return this.expandedRows=Le(this.expandedRows,e.row),this.emit("detail-expand",{rowIndex:e.rowIndex,row:e.row,expanded:this.expandedRows.has(e.row)}),this.requestRender(),!1}onCellClick(e){if(e.originalEvent?.target?.classList.contains("master-detail-toggle")){const o=e.row,i=e.rowIndex;return this.expandedRows=Le(this.expandedRows,o),this.emit("detail-expand",{rowIndex:i,row:o,expanded:this.expandedRows.has(o)}),this.requestRender(),!0}this.expandedRows.size>0&&queueMicrotask(()=>this.#e())}afterRender(){this.#e()}onScrollRender(){!this.config.detailRenderer||this.expandedRows.size===0||this.#e()}#e(){if(!this.config.detailRenderer)return;const e=this.shadowRoot?.querySelector(".rows");if(!e)return;const t=new Map,o=e.querySelectorAll(".data-grid-row"),i=this.columns.length;for(const s of o){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,i);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){const o=this.detailElements.get(t);if(o)e+=o.offsetHeight;else{const i=this.config?.detailHeight;e+=typeof i=="number"?i:150}}return e}getExtraHeightBefore(e){let t=0;for(const o of this.expandedRows){const i=this.rows.indexOf(o);if(i>=0&&i<e){const r=this.detailElements.get(o);if(r)t+=r.offsetHeight;else{const s=this.config?.detailHeight;t+=typeof s=="number"?s:150}}}return t}adjustVirtualStart(e,t,o){if(this.expandedRows.size===0)return e;const i=[];for(const l of this.expandedRows){const a=this.rows.indexOf(l);a>=0&&i.push({index:a,row:l})}i.sort((l,a)=>l.index-a.index);let r=e,s=0;for(const{index:l,row:a}of i){const c=l*o+s,u=this.detailElements.get(a)?.offsetHeight??(typeof this.config?.detailHeight=="number"?this.config.detailHeight:150),h=c+o+u;s+=u,!(l>=e)&&h>t&&l<r&&(r=l)}return r}expand(e){const t=this.rows[e];t&&(this.expandedRows=Kn(this.expandedRows,t),this.requestRender())}collapse(e){const t=this.rows[e];t&&(this.expandedRows=Vn(this.expandedRows,t),this.requestRender())}toggle(e){const t=this.rows[e];t&&(this.expandedRows=Le(this.expandedRows,t),this.requestRender())}isExpanded(e){const t=this.rows[e];return t?Wn(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 o=this.rows.indexOf(t);o>=0&&e.push(o)}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()}}styles=Un}function Xn(n,e,t){return e.length?[...n].sort((o,i)=>{for(const r of e){const l=t.find(u=>u.field===r.field)?.sortComparator??Yn,a=o[r.field],c=i[r.field],d=l(a,c,o,i);if(d!==0)return r.direction==="asc"?d:-d}return 0}):[...n]}function Yn(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 Zn(n,e,t,o){const i=n.find(r=>r.field===e);return t?i?i.direction==="asc"?n.map(r=>r.field===e?{...r,direction:"desc"}:r):n.filter(r=>r.field!==e):n.length<o?[...n,{field:e,direction:"asc"}]:n:i?.direction==="asc"?[{field:e,direction:"desc"}]:i?.direction==="desc"?[]:[{field:e,direction:"asc"}]}function Mt(n,e){const t=n.findIndex(o=>o.field===e);return t>=0?t+1:void 0}function It(n,e){return n.find(t=>t.field===e)?.direction}const Jn='.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 Qn extends S{name="multiSort";version="1.0.0";get defaultConfig(){return{maxSortColumns:3,showSortIndex:!0}}sortModel=[];detach(){this.sortModel=[]}processRows(e){return this.sortModel.length===0?[...e]:Xn([...e],this.sortModel,[...this.columns])}onHeaderClick(e){if(!this.columns.find(r=>r.field===e.field)?.sortable)return!1;const o=e.originalEvent.shiftKey,i=this.config.maxSortColumns??3;return this.sortModel=Zn(this.sortModel,e.field,o,i),this.emit("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),!0}afterRender(){const e=this.shadowRoot;if(!e)return;const t=this.config.showSortIndex!==!1;e.querySelectorAll(".header-row .cell[data-field]").forEach(i=>{const r=i.getAttribute("data-field");if(!r)return;const s=Mt(this.sortModel,r),l=It(this.sortModel,r);if(i.querySelector(".sort-index")?.remove(),l){i.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove(),i.setAttribute("data-sort",l);const d=document.createElement("span");d.className="sort-indicator",this.setIcon(d,this.resolveIcon(l==="asc"?"sortAsc":"sortDesc"));const u=i.querySelector(".tbw-filter-btn"),h=i.querySelector(".resize-handle"),p=u??h;if(p?i.insertBefore(d,p):i.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?i.insertBefore(f,d.nextSibling):i.appendChild(f)}}else i.removeAttribute("data-sort")})}getSortModel(){return[...this.sortModel]}setSortModel(e){this.sortModel=[...e],this.emit("sort-change",{sortModel:[...e]}),this.requestRender()}clearSort(){this.sortModel=[],this.emit("sort-change",{sortModel:[]}),this.requestRender()}getSortIndex(e){return Mt(this.sortModel,e)}getSortDirection(e){return It(this.sortModel,e)}getColumnState(e){const t=this.sortModel.findIndex(i=>i.field===e);return t===-1?void 0:{sort:{direction:this.sortModel[t].direction,priority:t}}}applyColumnState(e,t){if(!t.sort){this.sortModel=this.sortModel.filter(r=>r.field!==e);return}const o=this.sortModel.findIndex(r=>r.field===e),i={field:e,direction:t.sort.direction};o!==-1?this.sortModel[o]=i:this.sortModel.splice(t.sort.priority,0,i)}styles=Jn}function ei(n){return n.filter(e=>e.sticky==="left")}function ti(n){return n.filter(e=>e.sticky==="right")}function Pe(n){return n.some(e=>e.sticky==="left"||e.sticky==="right")}function Ot(n,e){const t=n.shadowRoot;if(!t)return;const o=Array.from(t.querySelectorAll(".header-row .cell"));if(!o.length)return;const i=new Map;e.forEach((l,a)=>{l.field&&i.set(l.field,a)});let r=0;for(const l of e)if(l.sticky==="left"){const a=i.get(l.field),c=o.find(d=>d.getAttribute("data-field")===l.field);c&&(c.classList.add("sticky-left"),c.style.position="sticky",c.style.left=r+"px",a!==void 0&&t.querySelectorAll(`.data-grid-row .cell[data-col="${a}"]`).forEach(d=>{d.classList.add("sticky-left"),d.style.position="sticky",d.style.left=r+"px"}),r+=c.offsetWidth)}let s=0;for(const l of[...e].reverse())if(l.sticky==="right"){const a=i.get(l.field),c=o.find(d=>d.getAttribute("data-field")===l.field);c&&(c.classList.add("sticky-right"),c.style.position="sticky",c.style.right=s+"px",a!==void 0&&t.querySelectorAll(`.data-grid-row .cell[data-col="${a}"]`).forEach(d=>{d.classList.add("sticky-right"),d.style.position="sticky",d.style.right=s+"px"}),s+=c.offsetWidth)}}function Dt(n){const e=n.shadowRoot;if(!e)return;e.querySelectorAll(".sticky-left, .sticky-right").forEach(o=>{o.classList.remove("sticky-left","sticky-right"),o.style.position="",o.style.left="",o.style.right=""})}class oi extends S{name="pinnedColumns";version="1.0.0";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 o=t?.columns;return Array.isArray(o)?Pe(o):!1}processColumns(e){return this.isApplied=Pe([...e]),[...e]}afterRender(){if(!this.isApplied)return;const e=this.grid,t=[...this.columns];if(!Pe(t)){Dt(e),this.isApplied=!1;return}queueMicrotask(()=>{Ot(e,t)})}onPluginQuery(e){switch(e.type){case ne.CAN_MOVE_COLUMN:{const t=e.context,o=t.sticky;if(o==="left"||o==="right")return!1;const i=t.meta?.sticky;return i==="left"||i==="right"?!1:void 0}default:return}}refreshStickyOffsets(){const e=[...this.columns];Ot(this.grid,e)}getLeftPinnedColumns(){const e=[...this.columns];return ei(e)}getRightPinnedColumns(){const e=[...this.columns];return ti(e)}clearStickyPositions(){Dt(this.grid)}getHorizontalScrollOffsets(e,t){if(!this.isApplied)return;let o=0,i=0;if(e){const s=e.querySelectorAll(".sticky-left"),l=e.querySelectorAll(".sticky-right");s.forEach(a=>{o+=a.offsetWidth}),l.forEach(a=>{i+=a.offsetWidth})}else{const l=this.grid.shadowRoot;l&&l.querySelectorAll(".header-row .cell").forEach(c=>{c.classList.contains("sticky-left")?o+=c.offsetWidth:c.classList.contains("sticky-right")&&(i+=c.offsetWidth)})}const r=t?.classList.contains("sticky-left")||t?.classList.contains("sticky-right");return{left:o,right:i,skipScroll:r}}}function ni(n){return typeof n=="object"&&n!==null&&"aggFunc"in n}function He(n,e){const t=document.createElement("div");t.className="tbw-pinned-rows",t.setAttribute("role","presentation"),t.setAttribute("aria-live","polite");const o=document.createElement("div");o.className="tbw-pinned-rows-left";const i=document.createElement("div");i.className="tbw-pinned-rows-center";const r=document.createElement("div");if(r.className="tbw-pinned-rows-right",n.showRowCount!==!1){const s=document.createElement("span");s.className="tbw-status-panel tbw-status-panel-row-count",s.textContent=`Total: ${e.totalRows} rows`,o.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}`,o.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=ii(s,e);switch(s.position){case"left":o.appendChild(l);break;case"center":i.appendChild(l);break;case"right":r.appendChild(l);break}}return t.appendChild(o),t.appendChild(i),t.appendChild(r),t}function Nt(n){const e=document.createElement("div");return e.className=`tbw-aggregation-rows tbw-aggregation-rows-${n}`,e.setAttribute("role","presentation"),e}function qt(n,e,t,o){n.innerHTML="";for(const i of e){const r=document.createElement("div");if(r.className="tbw-aggregation-row",r.setAttribute("role","presentation"),i.id&&r.setAttribute("data-aggregation-id",i.id),i.fullWidth){const s=document.createElement("div");s.className="tbw-aggregation-cell tbw-aggregation-cell-full",s.style.gridColumn="1 / -1",s.textContent=i.label||"",r.appendChild(s)}else for(const s of t){const l=document.createElement("div");l.className="tbw-aggregation-cell",l.setAttribute("data-field",s.field);let a,c;const d=i.aggregators?.[s.field];if(d)if(ni(d)){const u=Pt(d.aggFunc);u&&(a=u(o,s.field,s)),c=d.formatter}else{const u=Pt(d);u&&(a=u(o,s.field,s))}else if(i.cells&&Object.prototype.hasOwnProperty.call(i.cells,s.field)){const u=i.cells[s.field];typeof u=="function"?a=u(o,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 ii(n,e){const t=document.createElement("div");t.className="tbw-status-panel tbw-status-panel-custom",t.id=`status-panel-${n.id}`;const o=n.render(e);return typeof o=="string"?t.innerHTML=o:t.appendChild(o),t}function Ft(n,e,t,o,i){return{totalRows:n.length,filteredRows:i?.cachedResult?.length??n.length,selectedRows:o?.selected?.size??0,columns:e,rows:n,grid:t}}const ri=".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:8px 12px;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:12px;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:16px}.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, 2px 8px);min-height:var(--tbw-row-height, 28px);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 si extends S{name="pinnedRows";version="1.0.0";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.shadowRoot;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 o=this.getSelectionState(),i=this.getFilterState(),r=Ft(this.rows,this.columns,this.grid,o,i),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=Nt("top");const h=e.querySelector(".header");h&&h.nextSibling?t.insertBefore(this.topAggregationContainer,h.nextSibling):t.appendChild(this.topAggregationContainer)}qt(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=He(this.config,r),t.insertBefore(this.infoBarElement,t.firstChild);else{const h=He(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=Nt("bottom")),this.footerWrapper.appendChild(this.bottomAggregationContainer),qt(this.bottomAggregationContainer,a,this.visibleColumns,this.rows)),d&&(this.infoBarElement=He(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 Ft(this.rows,this.columns,this.grid,e,t)}addPanel(e){this.config.customPanels||(this.config.customPanels=[]),this.config.customPanels.push(e),this.requestRender()}removePanel(e){this.config.customPanels&&(this.config.customPanels=this.config.customPanels.filter(t=>t.id!==e),this.requestRender())}addAggregationRow(e){this.config.aggregationRows||(this.config.aggregationRows=[]),this.config.aggregationRows.push(e),this.requestRender()}removeAggregationRow(e){this.config.aggregationRows&&(this.config.aggregationRows=this.config.aggregationRows.filter(t=>t.id!==e),this.requestRender())}styles=ri}const li=On;function ai(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 Me(n,e){return[...n,e].join("|")}function ci(n,e){const t=e.rowGroupFields??[],o=e.columnGroupFields??[],i=e.valueFields??[],r=di(n,o),s=zt(n,t,o,r,i,0,""),l=hi(s,r,i),a=Object.values(l).reduce((c,d)=>c+d,0);return{rows:s,columnKeys:r,totals:l,grandTotal:a}}function di(n,e){if(e.length===0)return["value"];const t=new Set;for(const o of n){const i=e.map(r=>String(o[r]??"")).join("|");t.add(i)}return[...t].sort()}function ui(n,e){const t=new Map;for(const o of n){const i=String(o[e]??""),r=t.get(i);r?r.push(o):t.set(i,[o])}return t}function zt(n,e,t,o,i,r,s){const l=[];if(e.length===0){const h=Bt(n,t,o,i),p=Gt(h);return l.push({rowKey:s||"all",rowLabel:s||"All",depth:r,values:h,total:p,isGroup:!1,rowCount:n.length}),l}const a=e[0],c=e.slice(1),d=c.length>0,u=ui(n,a);for(const[h,p]of u){const f=s?`${s}|${h}`:h,g=Bt(p,t,o,i),w=Gt(g);let m;d&&(m=zt(p,c,t,o,i,r+1,f)),l.push({rowKey:f,rowLabel:h||"(blank)",depth:r,values:g,total:w,isGroup:d,children:m,rowCount:p.length})}return l}function Bt(n,e,t,o){const i={};for(const r of t)for(const s of o){const a=(e.length>0?n.filter(h=>e.map(p=>String(h[p]??"")).join("|")===r):n).map(h=>Number(h[s.field])||0),c=li(s.aggFunc),d=a.length>0?c(a):null,u=Me([r],s.field);i[u]=d}return i}function Gt(n){let e=0;for(const t of Object.values(n))e+=t??0;return e}function hi(n,e,t){const o={};function i(r){for(const s of r)if(!s.isGroup||!s.children?.length)for(const l of e)for(const a of t){const c=Me([l],a.field);o[c]=(o[c]??0)+(s.values[c]??0)}else s.children&&i(s.children)}return i(n),o}function fi(n,e,t=!0){const o=[];function i(r){o.push(r);const s=e?e.has(r.rowKey):t;if(r.children&&s)for(const l of r.children)i(l)}for(const r of n)i(r);return o}function Ie(n){const e=[];function t(o){if(o.isGroup&&e.push(o.rowKey),o.children)for(const i of o.children)t(i)}for(const o of n)t(o);return e}const pi=["sum","avg","count","min","max","first","last"];function gi(n,e,t,o){const i=new AbortController,r={config:e,callbacks:o,signal:i.signal},s=document.createElement("div");return s.className="tbw-pivot-panel",s.appendChild(le("Options",()=>yi(t,r))),s.appendChild(le("Row Groups",()=>Kt("rowGroups",r))),s.appendChild(le("Column Groups",()=>Kt("columnGroups",r))),s.appendChild(le("Values",()=>wi(r))),s.appendChild(le("Available Fields",()=>vi(r))),n.appendChild(s),()=>{i.abort(),s.remove()}}function le(n,e){const t=document.createElement("div");t.className="tbw-pivot-section";const o=document.createElement("div");o.className="tbw-pivot-section-header",o.textContent=n;const i=document.createElement("div");return i.className="tbw-pivot-section-content",i.appendChild(e()),t.appendChild(o),t.appendChild(i),t}function Kt(n,e){const{config:t,callbacks:o,signal:i}=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(mi(l,n,e));return r.addEventListener("dragover",l=>{l.preventDefault(),r.classList.add("drag-over")},{signal:i}),r.addEventListener("dragleave",()=>{r.classList.remove("drag-over")},{signal:i}),r.addEventListener("drop",l=>{l.preventDefault(),r.classList.remove("drag-over");const a=l.dataTransfer?.getData("text/plain");a&&o.onAddFieldToZone(a,n)},{signal:i}),r}function mi(n,e,t){const{callbacks:o,signal:i}=t,r=document.createElement("div");r.className="tbw-pivot-field-chip",r.draggable=!0;const s=o.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(),o.onRemoveFieldFromZone(n,e)},{signal:i}),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:i}),r.addEventListener("dragend",()=>{r.classList.remove("dragging")},{signal:i}),r}function wi(n){const{config:e,callbacks:t,signal:o}=n,i=document.createElement("div");i.className="tbw-pivot-drop-zone tbw-pivot-values-zone",i.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",i.appendChild(s)}else for(const s of r)i.appendChild(bi(s,n));return i.addEventListener("dragover",s=>{s.preventDefault(),i.classList.add("drag-over")},{signal:o}),i.addEventListener("dragleave",()=>{i.classList.remove("drag-over")},{signal:o}),i.addEventListener("drop",s=>{s.preventDefault(),i.classList.remove("drag-over");const l=s.dataTransfer?.getData("text/plain");l&&t.onAddValueField(l,"sum")},{signal:o}),i}function bi(n,e){const{callbacks:t,signal:o}=e,i=document.createElement("div");i.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 pi){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:o});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:o}),s.appendChild(l),s.appendChild(a),i.appendChild(s),i.appendChild(c),i}function vi(n){const{config:e,callbacks:t,signal:o}=n,i=document.createElement("div");i.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",i.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:o}),c.addEventListener("dragend",()=>{c.classList.remove("dragging")},{signal:o}),i.appendChild(c)}return i}function yi(n,e){const{config:t,callbacks:o,signal:i}=e,r=document.createElement("div");return r.className="tbw-pivot-options",r.appendChild(Oe("Enable Pivot View",n,s=>{o.onTogglePivot(s)},i)),r.appendChild(Oe("Show Row Totals",t.showTotals??!0,s=>{o.onOptionChange("showTotals",s)},i)),r.appendChild(Oe("Show Grand Total",t.showGrandTotal??!0,s=>{o.onOptionChange("showGrandTotal",s)},i)),r}function Oe(n,e,t,o){const i=document.createElement("label");i.className="tbw-pivot-checkbox";const r=document.createElement("input");r.type="checkbox",r.checked=e,r.addEventListener("change",()=>t(r.checked),{signal:o});const s=document.createElement("span");return s.textContent=n,i.appendChild(r),i.appendChild(s),i}function Ci(n,e,t){return e.className="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((o,i)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(i)),r.setAttribute("role","gridcell"),i===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[o.field];r.textContent=s!=null?String(s):""}e.appendChild(r)}),!0}function xi(n,e,t){return e.className="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,i)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(i)),r.setAttribute("role","gridcell"),i===0){const s=Number(n.__pivotIndent)||0;r.style.paddingLeft=`${s+20}px`;const l=document.createElement("span");l.className="pivot-label",l.textContent=String(n.__pivotLabel??""),r.appendChild(l)}else{const s=n[o.field];r.textContent=s!=null?String(s):""}e.appendChild(r)}),!0}function Ei(n,e,t){return e.className="pivot-grand-total-row",e.setAttribute("role","presentation"),e.innerHTML="",t.forEach((o,i)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(i)),i===0){const s=document.createElement("span");s.className="pivot-label",s.textContent="Grand Total",r.appendChild(s)}else{const s=n[o.field];r.textContent=s!=null?String(s):""}e.appendChild(r)}),!0}const Si='.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:12px;padding:12px;height:100%;overflow-y:auto;font-size:13px}.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:8px 12px;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:8px}.tbw-pivot-toggle-wrapper{display:flex;align-items:center}.tbw-pivot-toggle-label{display:flex;align-items:center;gap:8px;cursor:pointer}.tbw-pivot-toggle-label input{width:16px;height:16px;cursor:pointer}.tbw-pivot-drop-zone{min-height:60px;padding:8px;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:6px;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:8px;text-align:center;width:100%}.tbw-pivot-field-chip{display:inline-flex;align-items:center;gap:6px;padding:4px 8px;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:12px;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:16px;height:16px;padding:0;border:none;background:transparent;color:var(--tbw-color-fg-muted);font-size:14px;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:4px 8px}.tbw-pivot-value-label-wrapper{display:flex;align-items:center;gap:8px;flex:1;min-width:0}.tbw-pivot-agg-select{padding:2px 4px;font-size:11px;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:6px;min-height:40px}.tbw-pivot-options{display:flex;flex-direction:column;gap:8px}.tbw-pivot-checkbox{display:flex;align-items:center;gap:8px;cursor:pointer}.tbw-pivot-checkbox input{width:14px;height:14px;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 J extends S{name="pivot";version="1.0.0";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(){const t=this.grid.effectiveConfig?.animation?.mode??"reduced-motion";if(t===!1||t==="off")return!1;if(t!==!0&&t!=="on"){const o=this.shadowRoot?.host;if(o&&getComputedStyle(o).getPropertyValue("--tbw-animation-enabled").trim()==="0")return!1}return this.config.animation??"slide"}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:J.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=ai(this.config);if(t.length>0)return this.warn(`Config errors: ${t.join(", ")}`),[...e];if(this.buildFieldHeaderMap(),this.defaultExpanded=this.config.defaultExpanded??!0,this.expandedKeys.size===0&&this.defaultExpanded&&this.pivotResult){const s=Ie(this.pivotResult.rows);for(const l of s)this.expandedKeys.add(l)}if(this.pivotResult=ci(e,this.config),this.expandedKeys.size===0&&this.defaultExpanded){const s=Ie(this.pivotResult.rows);for(const l of s)this.expandedKeys.add(l)}const o=this.config.indentWidth??20,i=fi(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*o,__pivotTotal:s.total,...s.values}));this.keysToAnimate.clear();const r=new Set;for(const s of i){const l=s.__pivotRowKey;r.add(l),!this.previousVisibleKeys.has(l)&&s.__pivotDepth>0&&this.keysToAnimate.add(l)}return this.previousVisibleKeys=r,i}processColumns(e){if(!this.isActive||!this.pivotResult)return[...e];const t=[],o=(this.config.rowGroupFields??[]).map(i=>this.fieldHeaderMap.get(i)??i).join(" / ");t.push({field:"__pivotLabel",header:o||"Group",width:200});for(const i of this.pivotResult.columnKeys)for(const r of this.config.valueFields??[]){const s=Me([i],r.field),l=r.header||this.fieldHeaderMap.get(r.field)||r.field;t.push({field:s,header:`${i} - ${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){const o=e;return o.__pivotRowKey&&o.__pivotHasChildren?Ci(o,t,{columns:this.gridColumns,onToggle:i=>this.toggle(i),resolveIcon:i=>this.resolveIcon(i),setIcon:(i,r)=>this.setIcon(i,r)}):o.__pivotRowKey!==void 0&&this.isActive?xi(o,t,this.gridColumns):(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="")}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.shadowRoot?.querySelector(".rows");if(!t)return;const o=e==="fade"?"tbw-pivot-fade-in":"tbw-pivot-slide-in";for(const i of t.querySelectorAll(".pivot-group-row, .pivot-leaf-row")){const r=i.dataset.pivotKey;r&&this.keysToAnimate.has(r)&&(i.classList.add(o),i.addEventListener("animationend",()=>i.classList.remove(o),{once:!0}))}this.keysToAnimate.clear()}renderGrandTotalFooter(){if(!this.pivotResult)return;const e=this.shadowRoot;if(!e)return;const t=e.querySelector(".tbw-scroll-area")??e.querySelector(".tbw-grid-content")??e.children[0];if(!t)return;this.grandTotalFooter||(this.grandTotalFooter=document.createElement("div"),this.grandTotalFooter.className="pivot-grand-total-footer",t.appendChild(this.grandTotalFooter));const o={__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals};Ei(o,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(){if(this.pivotResult){const e=Ie(this.pivotResult.rows);for(const t of e)this.expandedKeys.add(t);this.requestRender()}}collapseAll(){this.expandedKeys.clear(),this.requestRender()}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(J.PANEL_ID)}hidePanel(){this.grid.closeToolPanel()}togglePanel(){this.grid.toggleToolPanel(J.PANEL_ID)}isPanelVisible(){return this.grid.activeToolPanel===J.PANEL_ID}get gridColumns(){return this.grid.columns??[]}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(){const e=this.grid;try{const t=e.getAllColumns?.()??e.columns??[];return this.originalColumns=t.filter(o=>!o.field.startsWith("__pivot")).map(o=>({field:o.field,header:o.header??o.field})),this.originalColumns}catch{return[]}}renderPanel(e){this.panelContainer=e,this.originalColumns.length===0&&this.captureOriginalColumns();const t={onTogglePivot:o=>{o?this.enablePivot():this.disablePivot(),this.refreshPanel()},onAddFieldToZone:(o,i)=>this.addFieldToZone(o,i),onRemoveFieldFromZone:(o,i)=>this.removeFieldFromZone(o,i),onAddValueField:(o,i)=>this.addValueField(o,i),onRemoveValueField:o=>this.removeValueField(o),onUpdateValueAggFunc:(o,i)=>this.updateValueAggFunc(o,i),onOptionChange:(o,i)=>{this.config[o]=i,this.isActive&&this.refresh()},getAvailableFields:()=>this.getAvailableFields()};return gi(e,this.config,this.isActive,t)}refreshPanel(){this.panelContainer&&(this.panelContainer.innerHTML="",this.renderPanel(this.panelContainer))}addFieldToZone(e,t){if(t==="rowGroups"){const o=this.config.rowGroupFields??[];o.includes(e)||(this.config.rowGroupFields=[...o,e])}else{const o=this.config.columnGroupFields??[];o.includes(e)||(this.config.columnGroupFields=[...o,e])}this.removeFromOtherZones(e,t),this.isActive&&this.refresh(),this.refreshPanel()}removeFieldFromZone(e,t){t==="rowGroups"?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(o=>o!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(o=>o!==e),this.isActive&&this.refresh(),this.refreshPanel()}removeFromOtherZones(e,t){t!=="rowGroups"&&(this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(o=>o!==e)),t!=="columnGroups"&&(this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(o=>o!==e)),t!=="values"&&(this.config.valueFields=(this.config.valueFields??[]).filter(o=>o.field!==e))}addValueField(e,t){const o=this.config.valueFields??[];o.some(i=>i.field===e)||(this.config.valueFields=[...o,{field:e,aggFunc:t}]),this.removeFromOtherZones(e,"values"),this.isActive&&this.refresh(),this.refreshPanel()}removeValueField(e){this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e),this.isActive&&this.refresh(),this.refreshPanel()}updateValueAggFunc(e,t){const o=this.config.valueFields??[],i=o.findIndex(r=>r.field===e);i>=0&&(o[i]={...o[i],aggFunc:t},this.config.valueFields=[...o]),this.isActive&&this.refresh()}styles=Si}function Vt(n){const e=n.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}function Wt(n,e,t){if(e===t||e<0||e>=n.length||t<0||t>n.length)return n;const o=[...n],[i]=o.splice(e,1);return o.splice(t,0,i),o}const Ri='.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 _i extends S{name="reorder";version="1.0.0";get defaultConfig(){return{animation:"flip"}}get animationType(){return this.isAnimationEnabled?this.config.animation!==void 0?this.config.animation:this.config.viewTransition===!1?!1:(this.config.viewTransition===!0,"flip"):!1}get isAnimationEnabled(){const t=this.grid.effectiveConfig?.animation?.mode??"reduced-motion";if(t===!1||t==="off")return!1;if(t===!0||t==="on")return!0;const o=this.shadowRoot?.host;return o?getComputedStyle(o).getPropertyValue("--tbw-animation-enabled").trim()!=="0":!0}get animationDuration(){if(this.config.animationDuration!==void 0)return this.config.animationDuration;const e=this.shadowRoot?.host;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),o=parseInt(t,10);if(!isNaN(o))return o}return 200}isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;attach(e){super.attach(e),e.addEventListener("column-reorder-request",t=>{const o=t.detail;o?.field&&typeof o.toIndex=="number"&&this.moveColumn(o.field,o.toIndex)},{signal:this.disconnectSignal})}detach(){this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null}afterRender(){const e=this.shadowRoot;if(!e)return;e.querySelectorAll(".header-row > .cell").forEach(o=>{const i=o,r=i.getAttribute("data-field");if(!r)return;const s=this.columns.find(d=>d.field===r),c=!this.grid.queryPlugins({type:ne.CAN_MOVE_COLUMN,context:s}).includes(!1);if(!s||!Vt(s)||!c){i.draggable=!1;return}i.draggable=!0,!i.getAttribute("data-dragstart-bound")&&(i.setAttribute("data-dragstart-bound","true"),i.addEventListener("dragstart",d=>{const h=this.getColumnOrder().indexOf(r);this.isDragging=!0,this.draggedField=r,this.draggedIndex=h,d.dataTransfer&&(d.dataTransfer.effectAllowed="move",d.dataTransfer.setData("text/plain",r)),i.classList.add("dragging")}),i.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,e.querySelectorAll(".header-row > .cell").forEach(d=>{d.classList.remove("dragging","drop-target","drop-before","drop-after")})}),i.addEventListener("dragover",d=>{if(d.preventDefault(),!this.isDragging||this.draggedField===r)return;const u=i.getBoundingClientRect(),h=u.left+u.width/2,f=this.getColumnOrder().indexOf(r);this.dropIndex=d.clientX<h?f:f+1,i.classList.add("drop-target"),i.classList.toggle("drop-before",d.clientX<h),i.classList.toggle("drop-after",d.clientX>=h)}),i.addEventListener("dragleave",()=>{i.classList.remove("drop-target","drop-before","drop-after")}),i.addEventListener("drop",d=>{d.preventDefault();const u=this.draggedField,h=this.draggedIndex,p=this.dropIndex;if(!this.isDragging||u===null||h===null||p===null)return;const f=p>h?p-1:p,g=this.getColumnOrder(),w=Wt(g,h,f),m={field:u,fromIndex:h,toIndex:f,columnOrder:w};this.updateColumnOrder(w),this.emit("column-move",m)}))})}onKeyDown(e){if(!e.altKey||e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;const t=this.grid,o=t._focusCol,i=t._visibleColumns;if(o<0||o>=i.length)return;const r=i[o];if(!r||!Vt(r))return;const s=this.grid;if(s.queryPlugins({type:ne.CAN_MOVE_COLUMN,context:r}).includes(!1))return;const a=this.getColumnOrder(),c=a.indexOf(r.field);if(c===-1)return;const d=e.key==="ArrowLeft"?c-1:c+1;if(d<0||d>=a.length)return;const u=i.find(h=>h.field===a[d]);if(!(u&&s.queryPlugins({type:ne.CAN_MOVE_COLUMN,context:u}).includes(!1)))return this.moveColumn(r.field,d),t._focusCol=d,$(this.grid),e.preventDefault(),e.stopPropagation(),!0}getColumnOrder(){return this.grid.getColumnOrder()}moveColumn(e,t){const o=this.getColumnOrder(),i=o.indexOf(e);if(i===-1)return;const r=Wt(o,i,t);this.updateColumnOrder(r),this.emit("column-move",{field:e,fromIndex:i,toIndex:t,columnOrder: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.shadowRoot?.querySelectorAll(".header-row > .cell[data-field]").forEach(t=>{const o=t.getAttribute("data-field");o&&e.set(o,t.getBoundingClientRect().left)}),e}animateFLIP(e){const t=this.shadowRoot;if(!t||e.size===0)return;const o=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&&o.set(l,c)}),o.size===0)return;const i=[];if(t.querySelectorAll(".cell[data-field]").forEach(s=>{const l=o.get(s.getAttribute("data-field")??"");if(l!==void 0){const a=s;a.style.transform=`translateX(${l}px)`,i.push(a)}}),i.length===0)return;t.host.offsetHeight;const r=this.animationDuration;requestAnimationFrame(()=>{i.forEach(s=>{s.classList.add("flip-animating"),s.style.transform=""}),setTimeout(()=>{i.forEach(s=>{s.style.transform="",s.classList.remove("flip-animating")})},r+50)})}animateFade(e){const t=this.shadowRoot;if(!t){e();return}const o=this.captureHeaderPositions();e();const i=new Set;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(l=>{const a=l.getAttribute("data-field");if(!a)return;const c=o.get(a);if(c===void 0)return;const d=l.getBoundingClientRect().left;Math.abs(c-d)>1&&i.add(a)}),i.size===0)return;const r=[];if(t.querySelectorAll(".cell[data-field]").forEach(l=>{const a=l.getAttribute("data-field");if(a&&i.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.grid,o=this.animationType;if(o==="flip"&&this.shadowRoot){const i=this.captureHeaderPositions();t.setColumnOrder(e),requestAnimationFrame(()=>{this.shadowRoot?.host?.offsetHeight,this.animateFLIP(i)})}else o==="fade"?this.animateFade(()=>t.setColumnOrder(e)):t.setColumnOrder(e);t.requestStateChange?.()}styles=Ri}function he(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 Ai(n){const e=he(n);return{from:{row:e.startRow,col:e.startCol},to:{row:e.endRow,col:e.endCol}}}function De(n){return n.map(Ai)}function Ti(n,e,t){const o=he(t);return n>=o.startRow&&n<=o.endRow&&e>=o.startCol&&e<=o.endCol}function $t(n,e,t){return t.some(o=>Ti(n,e,o))}function ki(n){const e=[],t=he(n);for(let o=t.startRow;o<=t.endRow;o++)for(let i=t.startCol;i<=t.endCol;i++)e.push({row:o,col:i});return e}function Li(n){const e=new Map;for(const t of n)for(const o of ki(t))e.set(`${o.row},${o.col}`,o);return[...e.values()]}function Ne(n,e){return{startRow:n.row,startCol:n.col,endRow:e.row,endCol:e.col}}const Pi=':host .selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}:host .data-grid-row.row-focus{background-color:var(--tbw-focus-background, rgba(from var(--tbw-color-accent) r g b / 12%))}:host([data-selection-mode="row"]) .cell-focus{outline:none}:host .data-grid-row>.cell.selected{background-color:var(--tbw-range-selection-bg)}:host .data-grid-row>.cell.selected.top{border-top:2px solid var(--tbw-range-border-color)}:host .data-grid-row>.cell.selected.bottom{border-bottom:2px solid var(--tbw-range-border-color)}:host .data-grid-row>.cell.selected.first{border-left:2px solid var(--tbw-range-border-color)}:host .data-grid-row>.cell.selected.last{border-right:2px solid var(--tbw-range-border-color)}:host .tbw-selection-summary{font-size:13px;color:var(--tbw-color-fg-muted);white-space:nowrap}';function Hi(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 o=[...e.selected].map(i=>({from:{row:i,col:0},to:{row:i,col:t-1}}));return{mode:n,ranges:o}}return n==="range"&&e.ranges.length>0?{mode:n,ranges:De(e.ranges)}:{mode:n,ranges:[]}}class Mi extends S{name="selection";version="1.0.0";get defaultConfig(){return{mode:"cell"}}selected=new Set;lastSelected=null;anchor=null;ranges=[];activeRange=null;cellAnchor=null;isDragging=!1;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:o,originalEvent:i}=e,{mode:r}=this.config;if(r==="cell")return this.selectedCell={row:t,col:o},this.emit("selection-change",this.#s()),this.requestAfterRender(),!1;if(r==="row")return this.selected.clear(),this.selected.add(t),this.lastSelected=t,this.emit("selection-change",this.#s()),this.requestAfterRender(),!1;if(r==="range"){const s=i.shiftKey,l=i.ctrlKey||i.metaKey;if(s&&this.cellAnchor){const a=Ne(this.cellAnchor,{row:t,col:o});l?this.ranges.length>0?this.ranges[this.ranges.length-1]=a:this.ranges.push(a):this.ranges=[a],this.activeRange=a}else if(l){const a={startRow:t,startCol:o,endRow:t,endCol:o};this.ranges.push(a),this.activeRange=a,this.cellAnchor={row:t,col:o}}else{const a={startRow:t,startCol:o,endRow:t,endCol:o};this.ranges=[a],this.activeRange=a,this.cellAnchor={row:t,col:o}}return this.emit("selection-change",this.#s()),this.requestAfterRender(),!1}return!1}onKeyDown(e){const{mode:t}=this.config,i=["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.#s()),this.requestAfterRender(),!0;if(t==="cell"&&i)return queueMicrotask(()=>{this.selectedCell={row:this.grid._focusRow,col:this.grid._focusCol},this.emit("selection-change",this.#s()),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.#s()),this.requestAfterRender()}),!1;if(t==="range"&&i){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.#s()),this.requestAfterRender(),!0}}return!1}onCellMouseDown(e){if(this.config.mode!=="range"||e.rowIndex===void 0||e.colIndex===void 0||e.rowIndex<0||e.originalEvent.shiftKey&&this.cellAnchor)return;this.isDragging=!0;const t=e.rowIndex,o=e.colIndex;this.cellAnchor={row:t,col:o},e.originalEvent.ctrlKey||e.originalEvent.metaKey||(this.ranges=[]);const r={startRow:t,startCol:o,endRow:t,endCol:o};return this.ranges.push(r),this.activeRange=r,this.emit("selection-change",this.#s()),this.requestAfterRender(),!0}onCellMouseMove(e){if(this.config.mode!=="range"||!this.isDragging||!this.cellAnchor||e.rowIndex===void 0||e.colIndex===void 0||e.rowIndex<0)return;const t=Ne(this.cellAnchor,{row:e.rowIndex,col:e.colIndex});return this.ranges.length>0?this.ranges[this.ranges.length-1]=t:this.ranges.push(t),this.activeRange=t,this.emit("selection-change",this.#s()),this.requestAfterRender(),!0}onCellMouseUp(e){if(this.config.mode==="range"&&this.isDragging)return this.isDragging=!1,!0}#e(){const e=this.shadowRoot;if(!e)return;const{mode:t}=this.config;e.querySelectorAll(".cell").forEach(r=>{r.classList.remove("selected","top","bottom","first","last")});const i=e.querySelectorAll(".data-grid-row");if(i.forEach(r=>{r.classList.remove("selected","row-focus")}),t==="row"&&(W(e),i.forEach(r=>{const s=r.querySelector(".cell[data-row]"),l=ge(s);l>=0&&this.selected.has(l)&&r.classList.add("selected","row-focus")})),t==="range"&&this.ranges.length>0){W(e);const r=this.activeRange?he(this.activeRange):null;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&&$t(a,c,this.ranges)&&(l.classList.add("selected"),r&&(a===r.startRow&&l.classList.add("top"),a===r.endRow&&l.classList.add("bottom"),c===r.startCol&&l.classList.add("first"),c===r.endCol&&l.classList.add("last")))})}t==="cell"&&this.selectedCell&&W(e)}afterRender(){const e=this.shadowRoot;if(!e)return;const t=e.children[0],{mode:o}=this.config;if(this.pendingKeyboardUpdate&&o==="range"){const{shiftKey:i}=this.pendingKeyboardUpdate;this.pendingKeyboardUpdate=null;const r=this.grid._focusRow,s=this.grid._focusCol;if(i&&this.cellAnchor){const l=Ne(this.cellAnchor,{row:r,col:s});this.ranges=[l],this.activeRange=l}else i||(this.ranges=[],this.activeRange=null,this.cellAnchor={row:r,col:s});this.emit("selection-change",this.#s())}this.grid.setAttribute("data-selection-mode",o),t&&t.classList.toggle("selecting",this.isDragging),this.#e()}onScrollRender(){this.#e()}getSelectedCell(){return this.selectedCell}getSelectedRows(){return[...this.selected]}getRanges(){return De(this.ranges)}getSelectedCells(){return Li(this.ranges)}isCellSelected(e,t){return $t(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:De(this.ranges)}),this.requestAfterRender()}#s(){return Hi(this.config.mode,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges},this.columns.length)}styles=Pi}function Ii(n,e,t,o){const i=new Set(n.selected);let r=n.anchor;if(t==="single")i.clear(),i.add(e),r=e;else if(t==="multiple"){const s=o.ctrlKey||o.metaKey;if(o.shiftKey&&n.anchor!==null){const l=Math.min(n.anchor,e),a=Math.max(n.anchor,e);for(let c=l;c<=a;c++)i.add(c)}else s?(i.has(e)?i.delete(e):i.add(e),r=e):(i.clear(),i.add(e),r=e)}return{selected:i,lastSelected:e,anchor:r}}function Oi(n){const e=new Set;for(let t=0;t<n;t++)e.add(t);return e}function Di(n,e){const t=[],o=[];for(const i of e)n.has(i)||t.push(i);for(const i of n)e.has(i)||o.push(i);return{added:t,removed:o}}function fe(n,e){return Math.floor(n/e)}function Ni(n,e){return{start:n*e,end:(n+1)*e}}function qi(n,e,t){const o=fe(n,t),i=fe(e-1,t),r=[];for(let s=o;s<=i;s++)r.push(s);return r}async function Ut(n,e,t,o){const i=Ni(e,t);return n.getRows({startRow:i.start,endRow:i.end,sortModel:o.sortModel,filterModel:o.filterModel})}function Fi(n,e,t){const o=fe(n,e),i=t.get(o);if(!i)return;const r=n%e;return i[r]}const zi=100;class Bi extends S{name="serverSide";version="1.0.0";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,o={startRow:e._virtualization.start,endRow:e._virtualization.end},i=qi(o.startRow,o.endRow,t);for(const r of i)if(!(this.loadedBlocks.has(r)||this.loadingBlocks.has(r))){if(this.loadingBlocks.size>=(this.config.maxConcurrentRequests??2))break;this.loadingBlocks.add(r),Ut(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 o=0;o<this.totalRowCount;o++){const i=Fi(o,this.config.cacheBlockSize??100,this.loadedBlocks);t.push(i??{__loading:!0,__index:o})}return t}onScroll(e){this.dataSource&&(this.loadRequiredBlocks(),this.scrollDebounceTimer&&clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=setTimeout(()=>{this.loadRequiredBlocks()},zi))}setDataSource(e){this.dataSource=e,this.loadedBlocks.clear(),this.loadingBlocks.clear();const t=this.config.cacheBlockSize??100;Ut(e,0,t,{}).then(o=>{this.loadedBlocks.set(0,o.rows),this.totalRowCount=o.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,o=fe(e,t);return this.loadedBlocks.has(o)}getLoadedBlockCount(){return this.loadedBlocks.size}}function jt(n,e,t){return n.id!==void 0?String(n.id):t?`${t}-${e}`:String(e)}function Xt(n,e){const t=new Set(n);return t.has(e)?t.delete(e):t.add(e),t}function qe(n,e,t=null,o=0){const i=e.childrenField??"children",r=new Set;for(let s=0;s<n.length;s++){const l=n[s],a=jt(l,s,t),c=l[i];if(Array.isArray(c)&&c.length>0){r.add(a);const d=qe(c,e,a,o+1);for(const u of d)r.add(u)}}return r}function Gi(){return new Set}function Yt(n,e,t,o=null,i=0){const r=t.childrenField??"children";for(let s=0;s<n.length;s++){const l=n[s],a=jt(l,s,o);if(a===e)return[a];const c=l[r];if(Array.isArray(c)&&c.length>0){const d=Yt(c,e,t,a,i+1);if(d)return[a,...d]}}return null}function Ki(n,e,t,o){const i=Yt(n,e,t);if(!i)return o;const r=new Set(o);for(let s=0;s<i.length-1;s++)r.add(i[s]);return r}function Fe(n,e="children"){if(!Array.isArray(n)||n.length===0)return!1;for(const t of n){if(!t)continue;const o=t[e];if(Array.isArray(o)&&o.length>0)return!0}return!1}function Zt(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 o of e){const i=t[o];if(Array.isArray(i)&&i.length>0)return o}return null}function Jt(n,e="children",t=0){if(!Array.isArray(n)||n.length===0)return t;let o=t;for(const i of n){if(!i)continue;const r=i[e];if(Array.isArray(r)&&r.length>0){const s=Jt(r,e,t+1);s>o&&(o=s)}}return o}function Qt(n,e="children"){if(!Array.isArray(n))return 0;let t=0;for(const o of n){if(!o)continue;t++;const i=o[e];Array.isArray(i)&&(t+=Qt(i,e))}return t}const Vi=".tree-cell{display:flex;align-items:center;padding-left:calc(var(--tree-depth, 0) * var(--tbw-tree-indent, 20px))}.tree-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center;margin-right:4px}.tree-toggle:hover{color:var(--tbw-tree-accent, var(--tbw-color-accent))}.tree-spacer{width:14px;display:inline-block}.data-grid-row.tbw-tree-slide-in{animation:tbw-tree-slide-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)}}.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-fade-in{0%{opacity:0}to{opacity:1}}";class Wi extends S{name="tree";version="1.0.0";styles=Vi;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(){const t=this.grid.effectiveConfig?.animation?.mode??"reduced-motion";if(t===!1||t==="off")return!1;if(t!==!0&&t!=="on"){const o=this.shadowRoot?.host;if(o&&getComputedStyle(o).getPropertyValue("--tbw-animation-enabled").trim()==="0")return!1}return this.config.animation??"slide"}detect(e){if(!this.config.autoDetect)return!1;const t=e,o=this.config.childrenField??Zt(t)??"children";return Fe(t,o)}processRows(e){const t=this.config.childrenField??"children",o=e;if(!Fe(o,t))return this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),[...e];let i=this.withStableKeys(o);this.sortState&&(i=this.sortTree(i,this.sortState.field,this.sortState.direction)),this.config.defaultExpanded&&!this.initialExpansionDone&&(this.expandedKeys=qe(i,this.config),this.initialExpansionDone=!0),this.flattenedRows=this.flattenTree(i,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 o=this.config.childrenField??"children";return e.map((i,r)=>{const s=i.__stableKey,l=i.id!==void 0?String(i.id):s??(t?`${t}-${r}`:String(r)),a=i[o],c=Array.isArray(a)&&a.length>0;return{...i,__stableKey:l,...c?{[o]:this.withStableKeys(a,l)}:{}}})}flattenTree(e,t,o=0){const i=this.config.childrenField??"children",r=[];for(const s of e){const a=s.__stableKey??String(s.id??"?"),c=s[i],d=Array.isArray(c)&&c.length>0,u=t.has(a);r.push({key:a,data:s,depth:o,hasChildren:d,isExpanded:u,parentKey:o>0&&a.substring(0,a.lastIndexOf("-"))||null}),d&&u&&r.push(...this.flattenTree(c,t,o+1))}return r}sortTree(e,t,o){const i=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?o:a<c?-o:0}).map(s=>{const l=s[i];return Array.isArray(l)&&l.length>0?{...s,[i]:this.sortTree(l,t,o)}:s})}processColumns(e){if(this.flattenedRows.length===0)return[...e];const t=[...e];if(t.length===0)return t;const o={...t[0]},i=o.viewRenderer;if(i?.__treeWrapped)return t;const r=()=>this.config,s=this.setIcon.bind(this),l=this.resolveIcon.bind(this),a=c=>{const{value:d,row:u}=c,{indentWidth:h=20,showExpandIcons:p=!0}=r(),f=u,g=document.createElement("span");if(g.className="tree-cell",g.style.setProperty("--tree-depth",String(f.__treeDepth??0)),g.style.setProperty("--tbw-tree-indent",`${h}px`),f.__treeHasChildren&&p){const m=document.createElement("span");m.className=`tree-toggle${f.__treeExpanded?" expanded":""}`,s(m,l(f.__treeExpanded?"collapse":"expand")),m.setAttribute("data-tree-key",String(f.__treeKey??"")),g.appendChild(m)}else if(p){const m=document.createElement("span");m.className="tree-spacer",g.appendChild(m)}const w=document.createElement("span");if(i){const m=i(c);m instanceof Node?w.appendChild(m):w.textContent=String(m??d??"")}else w.textContent=String(d??"");return g.appendChild(w),g};return a.__treeWrapped=!0,o.viewRenderer=a,t[0]=o,t}onCellClick(e){const t=e.originalEvent?.target;if(!t?.classList.contains("tree-toggle"))return!1;const o=t.getAttribute("data-tree-key"),i=o?this.rowKeyMap.get(o):null;return i?(this.expandedKeys=Xt(this.expandedKeys,o),this.emit("tree-expand",{key:o,row:i.data,expanded:this.expandedKeys.has(o),depth:i.depth}),this.requestRender(),!0):!1}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 o=this.grid;return o._sortState!==void 0&&(o._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.shadowRoot?.querySelector(".rows");if(!t)return;const o=e==="fade"?"tbw-tree-fade-in":"tbw-tree-slide-in";for(const i of t.querySelectorAll(".data-grid-row")){const r=i.querySelector(".cell[data-row]"),s=r?parseInt(r.getAttribute("data-row")??"-1",10):-1,l=this.flattenedRows[s]?.key;l&&this.keysToAnimate.has(l)&&(i.classList.add(o),i.addEventListener("animationend",()=>i.classList.remove(o),{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=Xt(this.expandedKeys,e),this.requestRender()}expandAll(){this.expandedKeys=qe(this.rows,this.config),this.requestRender()}collapseAll(){this.expandedKeys=Gi(),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=Ki(this.rows,e,this.config,this.expandedKeys),this.requestRender()}}function $i(n,e,t){const o=[...n.undoStack,e];for(;o.length>t;)o.shift();return{undoStack:o,redoStack:[]}}function eo(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 to(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 Ui(n){return n.undoStack.length>0}function ji(n){return n.redoStack.length>0}function Xi(){return{undoStack:[],redoStack:[]}}function Yi(n,e,t,o){return{type:"cell-edit",rowIndex:n,field:e,oldValue:t,newValue:o,timestamp:Date.now()}}class Zi extends S{name="undoRedo";version="1.0.0";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,o=(e.ctrlKey||e.metaKey)&&(e.key==="y"||e.key==="z"&&e.shiftKey);if(t){const i=eo({undoStack:this.undoStack,redoStack:this.redoStack});if(i.action){const r=this.rows;r[i.action.rowIndex]&&(r[i.action.rowIndex][i.action.field]=i.action.oldValue),this.undoStack=i.newState.undoStack,this.redoStack=i.newState.redoStack,this.emit("undo",{action:i.action,type:"undo"}),this.requestRender()}return!0}if(o){const i=to({undoStack:this.undoStack,redoStack:this.redoStack});if(i.action){const r=this.rows;r[i.action.rowIndex]&&(r[i.action.rowIndex][i.action.field]=i.action.newValue),this.undoStack=i.newState.undoStack,this.redoStack=i.newState.redoStack,this.emit("redo",{action:i.action,type:"redo"}),this.requestRender()}return!0}return!1}recordEdit(e,t,o,i){const r=Yi(e,t,o,i),s=$i({undoStack:this.undoStack,redoStack:this.redoStack},r,this.config.maxHistorySize??100);this.undoStack=s.undoStack,this.redoStack=s.redoStack}undo(){const e=eo({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=to({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 Ui({undoStack:this.undoStack,redoStack:this.redoStack})}canRedo(){return ji({undoStack:this.undoStack,redoStack:this.redoStack})}clearHistory(){const e=Xi();this.undoStack=e.undoStack,this.redoStack=e.redoStack}getUndoStack(){return[...this.undoStack]}getRedoStack(){return[...this.redoStack]}}const Ji='.tbw-visibility-content{display:flex;flex-direction:column;height:100%}.tbw-visibility-list{flex:1;overflow-y:auto;padding:8px}.tbw-visibility-row{display:flex;align-items:center;gap:8px;padding:6px 4px;cursor:pointer;font-size:13px;border-radius:var(--tbw-border-radius, 4px);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:10px;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:8px;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:8px;padding:8px 12px;border:1px solid var(--tbw-visibility-border, var(--tbw-color-border, #e5e7eb));border-radius:var(--tbw-border-radius, 4px);background:var(--tbw-visibility-btn-bg, var(--tbw-color-header-bg, #f9fafb));color:var(--tbw-color-fg, #1f2937);cursor:pointer;font-size:13px}.tbw-visibility-show-all:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover, #f3f4f6))}';function oo(n){const e=n.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}class Q extends S{name="visibility";version="1.0.0";static PANEL_ID="columns";get defaultConfig(){return{allowHideAll:!1}}columnListElement=null;isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;detach(){this.columnListElement=null,this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null}getToolPanel(){return{id:Q.PANEL_ID,title:"Columns",icon:"☰",tooltip:"Column visibility",order:100,render:e=>this.renderPanelContent(e)}}show(){this.grid.openToolPanel(Q.PANEL_ID)}hide(){this.grid.closeToolPanel()}toggle(){this.grid.toggleToolPanel(Q.PANEL_ID)}isColumnVisible(e){return this.grid.isColumnVisible(e)}setColumnVisible(e,t){this.grid.setColumnVisible(e,t)}getVisibleColumns(){return this.grid.getAllColumns().filter(t=>t.visible).map(t=>t.field)}getHiddenColumns(){return this.grid.getAllColumns().filter(t=>!t.visible).map(t=>t.field)}showAll(){this.grid.showAllColumns()}toggleColumn(e){this.grid.toggleColumnVisibility(e)}showColumn(e){this.grid.setColumnVisible(e,!0)}hideColumn(e){this.grid.setColumnVisible(e,!1)}getAllColumns(){return this.grid.getAllColumns()}isPanelVisible(){return this.grid.activeToolPanel===Q.PANEL_ID}renderPanelContent(e){const t=this.grid,o=document.createElement("div");o.className="tbw-visibility-content";const i=document.createElement("div");i.className="tbw-visibility-list",o.appendChild(i);const r=document.createElement("button");return r.className="tbw-visibility-show-all",r.textContent="Show All",r.addEventListener("click",()=>{t.showAllColumns(),this.rebuildToggles(i)}),o.appendChild(r),this.columnListElement=i,this.rebuildToggles(i),e.appendChild(o),()=>{this.columnListElement=null,o.remove()}}hasReorderPlugin(){const e=this.grid?.getPluginByName?.("reorder");return!!(e&&typeof e.moveColumn=="function")}rebuildToggles(e){const t=this.grid,o=this.hasReorderPlugin();e.innerHTML="";const i=t.getAllColumns();for(let r=0;r<i.length;r++){const s=i[r],l=s.header||s.field,a=document.createElement("div");a.className=s.lockVisible?"tbw-visibility-row locked":"tbw-visibility-row",a.setAttribute("data-field",s.field),a.setAttribute("data-index",String(r)),o&&oo(s)&&(a.draggable=!0,a.classList.add("reorderable"),this.setupDragListeners(a,s.field,r,e));const c=document.createElement("label");c.className="tbw-visibility-label";const d=document.createElement("input");d.type="checkbox",d.checked=s.visible,d.disabled=s.lockVisible??!1,d.addEventListener("change",()=>{t.toggleColumnVisibility(s.field),setTimeout(()=>this.rebuildToggles(e),0)});const u=document.createElement("span");if(u.textContent=l,c.appendChild(d),c.appendChild(u),o&&oo(s)){const h=document.createElement("span");h.className="tbw-visibility-handle",this.setIcon(h,this.resolveIcon("dragHandle")),h.title="Drag to reorder",a.appendChild(h)}a.appendChild(c),e.appendChild(a)}}setupDragListeners(e,t,o,i){e.addEventListener("dragstart",r=>{this.isDragging=!0,this.draggedField=t,this.draggedIndex=o,r.dataTransfer&&(r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",t)),e.classList.add("dragging")}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,i.querySelectorAll(".tbw-visibility-row").forEach(r=>{r.classList.remove("dragging","drop-target","drop-before","drop-after")})}),e.addEventListener("dragover",r=>{if(r.preventDefault(),!this.isDragging||this.draggedField===t)return;const s=e.getBoundingClientRect(),l=s.top+s.height/2;this.dropIndex=r.clientY<l?o:o+1,i.querySelectorAll(".tbw-visibility-row").forEach(a=>{a!==e&&a.classList.remove("drop-target","drop-before","drop-after")}),e.classList.add("drop-target"),e.classList.toggle("drop-before",r.clientY<l),e.classList.toggle("drop-after",r.clientY>=l)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",r=>{r.preventDefault();const s=this.draggedField,l=this.draggedIndex,a=this.dropIndex;if(!this.isDragging||s===null||l===null||a===null)return;const c=a>l?a-1:a;if(c!==l){const d={field:s,fromIndex:l,toIndex:c};this.emit("column-reorder-request",d),setTimeout(()=>{this.rebuildToggles(i)},0)}})}styles=Ji}v.BaseGridPlugin=S,v.ClipboardPlugin=sn,v.ColumnVirtualizationPlugin=dn,v.ContextMenuPlugin=hn,v.DEFAULT_ANIMATION_CONFIG=ze,v.DEFAULT_GRID_ICONS=O,v.DGEvents=on,v.DataGridElement=N,v.EditingPlugin=mn,v.ExportPlugin=Cn,v.FOCUSABLE_EDITOR_SELECTOR=ue,v.FilteringPlugin=B,v.FitModeEnum=V,v.GridCSSVars=tn,v.GridClasses=k,v.GridDataAttrs=ie,v.GridElement=N,v.GridSelectors=en,v.GroupingColumnsPlugin=In,v.GroupingRowsPlugin=Gn,v.MasterDetailPlugin=jn,v.MultiSortPlugin=Qn,v.PLUGIN_QUERIES=ne,v.PinnedColumnsPlugin=oi,v.PinnedRowsPlugin=si,v.PivotPlugin=J,v.PluginEvents=nn,v.PluginManager=wt,v.RenderPhase=L,v.ReorderPlugin=_i,v.SelectionPlugin=Mi,v.ServerSidePlugin=Bi,v.TreePlugin=Wi,v.UndoRedoPlugin=Zi,v.VisibilityPlugin=Q,v.builtInSort=Xe,v.clearEditingState=_t,v.computeSelectionDiff=Di,v.countNodes=Qt,v.defaultComparator=je,v.defaultEditorFor=Rt,v.detectTreeStructure=Fe,v.getMaxDepth=Jt,v.handleRowClick=Ii,v.hasEditingCells=fn,v.inferChildrenField=Zt,v.selectAll=Oi,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
|
|
68
|
+
</Workbook>`,o}function Sn(n,e){const t=e.endsWith(".xls")?e:`${e}.xls`,o=new Blob([n],{type:"application/vnd.ms-excel;charset=utf-8;"});ke(o,t)}class Rn extends S{name="export";version="1.0.0";get defaultConfig(){return{fileName:"export",includeHeaders:!0,onlyVisible:!0,onlySelected:!1}}isExportingFlag=!1;lastExportInfo=null;performExport(e,t){const o=this.config,i={format:e,fileName:t?.fileName??o.fileName??"export",includeHeaders:t?.includeHeaders??o.includeHeaders,processCell:t?.processCell,processHeader:t?.processHeader,columns:t?.columns,rowIndices:t?.rowIndices};let r=[...this.columns];if(o.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(o.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=i.fileName;try{switch(e){case"csv":{const a=Cn(s,r,i,{bom:!0});l=l.endsWith(".csv")?l:`${l}.csv`,xn(a,l);break}case"excel":{const a=En(s,r,i);l=l.endsWith(".xls")?l:`${l}.xls`,Sn(a,l);break}case"json":{const a=s.map(u=>{const h={};for(const p of r){let f=u[p.field];i.processCell&&(f=i.processCell(f,p.field,u)),h[p.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"});ke(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:o,rowHeight:i,overscan:r}=n,s=Math.ceil(t/i);let l=Math.floor(o/i)-r;l<0&&(l=0);let a=l+s+r*2;return a>e&&(a=e),a===e&&l>0&&(l=Math.max(0,a-s-r*2)),{start:l,end:a,offsetY:l*i,totalHeight:e*i}}function An(n,e){return n<=e}function Tn(n,e,t=!1){const o=n[e.field];if(e.operator==="blank")return o==null||o==="";if(e.operator==="notBlank")return o!=null&&o!=="";if(o==null)return!1;const i=String(o),r=t?i:i.toLowerCase(),s=t?String(e.value):String(e.value).toLowerCase();switch(e.operator){case"contains":return r.includes(s);case"notContains":return!r.includes(s);case"equals":return r===s;case"notEquals":return r!==s;case"startsWith":return r.startsWith(s);case"endsWith":return r.endsWith(s);case"lessThan":return Number(o)<Number(e.value);case"lessThanOrEqual":return Number(o)<=Number(e.value);case"greaterThan":return Number(o)>Number(e.value);case"greaterThanOrEqual":return Number(o)>=Number(e.value);case"between":return Number(o)>=Number(e.value)&&Number(o)<=Number(e.valueTo);case"in":return Array.isArray(e.value)&&e.value.includes(o);case"notIn":return Array.isArray(e.value)&&!e.value.includes(o);default:return!0}}function kn(n,e,t=!1){return e.length?n.filter(o=>e.every(i=>Tn(o,i,t))):n}function Ln(n){return JSON.stringify(n.map(e=>({field:e.field,operator:e.operator,value:e.value,valueTo:e.valueTo})))}function Lt(n,e){const t=new Set;for(const o of n){const i=o[e];i!=null&&t.add(i)}return[...t].sort((o,i)=>typeof o=="number"&&typeof i=="number"?o-i:String(o).localeCompare(String(i)))}const Pn=':host .tbw-quick-filter-input{flex:1;max-width:300px;height:28px;padding:0 8px;border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);background:var(--tbw-color-bg);color:var(--tbw-color-fg);font-size:13px}:host .tbw-quick-filter-input:focus{outline:none;border-color:var(--tbw-color-accent)}:host .header-cell.filtered:before{content:"";position:absolute;top:4px;right:4px;width:6px;height:6px;background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border-radius:50%}:host .tbw-filter-btn{display:inline-flex;align-items:center;justify-content:center;background:transparent;border:none;cursor:pointer;padding:2px;margin-left:4px;opacity:.4;transition:opacity .15s;color:inherit;vertical-align:middle}:host .tbw-filter-btn:hover,:host .tbw-filter-btn.active{opacity:1}:host .tbw-filter-btn.active{color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6))}',Hn=".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, 4px));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:12px;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, 13px)}.tbw-filter-search{margin-bottom:8px}.tbw-filter-search-input{width:100%;padding:6px 10px;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, 4px);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:4px 2px;margin-bottom:8px;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:12px;padding:2px 0}.tbw-filter-action-btn:hover{text-decoration:underline}.tbw-filter-values{flex:1;overflow-y:auto;margin-bottom:8px;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:8px;padding:4px 2px;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:8px 0;text-align:center;font-style:italic}.tbw-filter-buttons{display:flex;gap:8px;padding-top:8px;border-top:1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)))}.tbw-filter-apply-btn{flex:1;padding:6px 12px;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:4px;cursor:pointer;font-size:13px}.tbw-filter-apply-btn:hover{filter:brightness(.9)}.tbw-filter-clear-btn{flex:1;padding:6px 12px;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:4px;cursor:pointer;font-size:13px}.tbw-filter-clear-btn:hover{background:var(--tbw-filter-hover, var(--tbw-color-row-hover, light-dark(#f0f6ff, #1c1c1c)))}";class B extends S{name="filtering";version="1.0.0";get defaultConfig(){return{debounceMs:300,caseSensitive:!1,trimInput:!0,useWorker:!0}}filters=new Map;cachedResult=null;cacheKey=null;openPanelField=null;panelElement=null;searchText=new Map;excludedValues=new Map;panelAbortController=null;globalStylesInjected=!1;static LIST_ITEM_HEIGHT=28;static LIST_OVERSCAN=3;static LIST_BYPASS_THRESHOLD=50;attach(e){super.attach(e),this.injectGlobalStyles()}detach(){this.filters.clear(),this.cachedResult=null,this.cacheKey=null,this.openPanelField=null,this.panelElement&&(this.panelElement.remove(),this.panelElement=null),this.searchText.clear(),this.excludedValues.clear(),this.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 o=Ln(t);if(this.cacheKey===o&&this.cachedResult)return this.cachedResult;const i=kn([...e],t,this.config.caseSensitive);return this.cachedResult=i,this.cacheKey=o,i}afterRender(){const e=this.shadowRoot;if(!e)return;e.querySelectorAll('[part~="header-cell"]').forEach(o=>{const i=o.getAttribute("data-col");if(i===null)return;const r=this.visibleColumns[parseInt(i,10)];if(!r||r.filterable===!1)return;const s=r.field;if(!s)return;const l=this.filters.has(s);let a=o.querySelector(".tbw-filter-btn");if(a){a.classList.toggle("active",l),o.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"),o.classList.add("filtered")),a.addEventListener("click",d=>{d.stopPropagation(),this.toggleFilterPanel(s,r,a)});const c=o.querySelector(".resize-handle");c?o.insertBefore(a,c):o.appendChild(a)})}setFilter(e,t){t===null?(this.filters.delete(e),this.excludedValues.delete(e)):(this.filters.set(e,{...t,field:e}),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.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),t.type==="set"&&t.operator==="notIn"&&Array.isArray(t.value)&&this.excludedValues.set(t.field,new Set(t.value));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 Lt(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=Hn,document.head.appendChild(e),this.globalStylesInjected=!0}toggleFilterPanel(e,t,o){if(this.openPanelField===e){this.closeFilterPanel();return}this.closeFilterPanel();const i=document.createElement("div");if(i.className="tbw-filter-panel",this.panelElement=i,this.openPanelField=e,this.config.valuesHandler){i.innerHTML='<div class="tbw-filter-loading">Loading...</div>',document.body.appendChild(i),this.positionPanel(i,o),this.setupPanelCloseHandler(i,o),this.config.valuesHandler(e,t).then(s=>{this.openPanelField!==e||!this.panelElement||(i.innerHTML="",this.renderPanelContent(e,t,i,s))});return}const r=Lt(this.sourceRows,e);this.renderPanelContent(e,t,i,r),document.body.appendChild(i),this.positionPanel(i,o),this.setupPanelCloseHandler(i,o)}renderPanelContent(e,t,o,i){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:i,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(o,l),a=o.children.length>0),a||this.renderDefaultFilterPanel(o,l,i,r)}setupPanelCloseHandler(e,t){this.panelAbortController=new AbortController,setTimeout(()=>{document.addEventListener("click",o=>{!e.contains(o.target)&&o.target!==t&&this.closeFilterPanel()},{signal:this.panelAbortController?.signal})},0)}closeFilterPanel(){this.panelElement&&(this.panelElement.remove(),this.panelElement=null),this.openPanelField=null,this.panelAbortController?.abort(),this.panelAbortController=null}positionPanel(e,t){const o=t.getBoundingClientRect();e.style.position="fixed",e.style.top=`${o.bottom+4}px`,e.style.left=`${o.left}px`,requestAnimationFrame(()=>{const i=e.getBoundingClientRect();i.right>window.innerWidth-8&&(e.style.left=`${window.innerWidth-i.width-8}px`),i.bottom>window.innerHeight-8&&(e.style.top=`${o.top-i.height-4}px`)})}renderDefaultFilterPanel(e,t,o,i){const{field:r}=t,s=document.createElement("div");s.className="tbw-filter-search";const l=document.createElement("input");l.type="text",l.placeholder="Search...",l.className="tbw-filter-search-input",l.value=this.searchText.get(r)??"",s.appendChild(l),e.appendChild(s);const a=document.createElement("div");a.className="tbw-filter-actions";const 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 b=[...w.values()],_=b.every(P=>P),M=b.every(P=>!P);d.checked=_,d.indeterminate=!_&&!M};d.addEventListener("change",()=>{const b=d.checked;for(const _ of w.keys())w.set(_,b);h(),y()}),e.appendChild(a);const p=document.createElement("div");p.className="tbw-filter-values";const f=document.createElement("div");f.className="tbw-filter-values-spacer",p.appendChild(f);const g=document.createElement("div");g.className="tbw-filter-values-content",p.appendChild(g);const w=new Map;o.forEach(b=>{const _=b==null?"__null__":String(b);w.set(_,!i.has(b))}),h();let m=[];const C=(b,_)=>{const M=b==null?"(Blank)":String(b),P=b==null?"__null__":String(b),T=document.createElement("label");T.className="tbw-filter-value-item",T.style.position="absolute",T.style.top=`${_*B.LIST_ITEM_HEIGHT}px`,T.style.left="0",T.style.right="0",T.style.height=`${B.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(P)??!0,F.dataset.value=P,F.addEventListener("change",()=>{w.set(P,F.checked),h()});const io=document.createElement("span");return io.textContent=M,T.appendChild(F),T.appendChild(io),T},y=()=>{const b=m.length,_=p.clientHeight,M=p.scrollTop;if(f.style.height=`${b*B.LIST_ITEM_HEIGHT}px`,An(b,B.LIST_BYPASS_THRESHOLD/3)){g.innerHTML="",g.style.transform="translateY(0px)",m.forEach((T,F)=>{g.appendChild(C(T,F))});return}const P=_n({totalRows:b,viewportHeight:_,scrollTop:M,rowHeight:B.LIST_ITEM_HEIGHT,overscan:B.LIST_OVERSCAN});g.style.transform=`translateY(${P.offsetY}px)`,g.innerHTML="";for(let T=P.start;T<P.end;T++)g.appendChild(C(m[T],T-P.start))},x=b=>{const _=b.toLowerCase();if(m=o.filter(M=>{const P=M==null?"(Blank)":String(M);return!b||P.toLowerCase().includes(_)}),m.length===0){f.style.height="0px",g.innerHTML="";const M=document.createElement("div");M.className="tbw-filter-no-match",M.textContent="No matching values",g.appendChild(M);return}y()};p.addEventListener("scroll",()=>{m.length>0&&y()},{passive:!0}),x(l.value),e.appendChild(p);let R;l.addEventListener("input",()=>{clearTimeout(R),R=setTimeout(()=>{this.searchText.set(r,l.value),x(l.value)},this.config.debounceMs??150)});const E=document.createElement("div");E.className="tbw-filter-buttons";const q=document.createElement("button");q.className="tbw-filter-apply-btn",q.textContent="Apply",q.addEventListener("click",()=>{const b=[];for(const[_,M]of w)if(!M)if(_==="__null__")b.push(null);else{const P=o.find(T=>String(T)===_);b.push(P!==void 0?P:_)}t.applySetFilter(b)}),E.appendChild(q);const A=document.createElement("button");A.className="tbw-filter-clear-btn",A.textContent="Clear Filter",A.addEventListener("click",()=>{t.clearFilter()}),E.appendChild(A),e.appendChild(E)}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,o,i){this.filters.set(e,{field:e,type:"text",operator:t,value:o,valueTo:i}),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 o=this.config.filterHandler(e,this.sourceRows),i=r=>{t.removeAttribute("aria-busy"),this.cachedResult=r,this.grid.rows=r,this.emit("filter-change",{filters:e,filteredRowCount:r.length}),this.requestRender()};o&&typeof o.then=="function"?o.then(i):i(o);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 o={field:e,type:t.filter.type,operator:t.filter.operator,value:t.filter.value,valueTo:t.filter.valueTo};this.filters.set(e,o),this.cachedResult=null,this.cacheKey=null}styles=Pn}function Mn(n){if(!n.length)return[];const e=new Map,t=[],o=(s,l)=>{if(!l.length)return;const a=t[t.length-1];if(a&&a.implicit&&a.firstIndex+a.columns.length===s){a.columns.push(...l);return}t.push({id:"__implicit__"+s,label:void 0,columns:l,firstIndex:s,implicit:!0})};let i=[],r=0;return n.forEach((s,l)=>{const a=s.group;if(!a){i.length===0&&(r=l),i.push(s);return}i.length&&(o(r,i.slice()),i=[]);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)}),i.length&&o(r,i),t.length===1&&t[0].implicit&&t[0].columns.length===n.length?[]:t}function In(n,e,t){if(!e.length||!n)return;const o=new Map;for(const r of e)for(const s of r.columns)s.field&&o.set(s.field,r.id);const i=Array.from(n.querySelectorAll(".cell[data-field]"));i.forEach(r=>{const s=r.getAttribute("data-field")||"",l=o.get(s);l&&(r.classList.add("grouped"),r.getAttribute("data-group")||r.setAttribute("data-group",l))});for(const r of e){const s=r.columns[r.columns.length-1],l=i.find(a=>a.getAttribute("data-field")===s.field);l&&l.classList.add("group-end")}}function On(n,e){if(n.length===0)return null;const t=document.createElement("div");t.className="header-group-row",t.setAttribute("role","row");for(const o of n){const i=o.firstIndex!=null?o.firstIndex:e.findIndex(a=>o.columns.includes(a)),r=String(o.id).startsWith("__implicit__"),s=r?"":o.label||o.id,l=document.createElement("div");l.className="cell header-group-cell",r&&l.classList.add("implicit-group"),l.setAttribute("data-group",String(o.id)),l.style.gridColumn=`${i+1} / span ${o.columns.length}`,l.textContent=s,t.appendChild(l)}return t}function Dn(n){return n.some(e=>e.group!=null)}const Nn=".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:4px 8px;font-weight:600;font-size:.9em;text-transform:uppercase;letter-spacing:.5px;border-right:1px solid var(--tbw-grouping-columns-border, 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))}.header-row .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 qn extends S{name="groupingColumns";version="1.0.0";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 o=t?.columns;return Array.isArray(o)?Dn(o):!1}processColumns(e){const t=this.grid?.gridConfig?.columnGroups;let o;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});o=e.map(s=>{const l=r.get(s.field);return l&&!s.group?{...s,group:l}:s})}else o=[...e];const i=Mn(o);return i.length===0?(this.isActive=!1,this.groups=[],o):(this.isActive=!0,this.groups=i,o)}afterRender(){if(!this.isActive||this.groups.length===0){const s=this.shadowRoot?.querySelector(".header")?.querySelector(".header-group-row");s&&s.remove();return}const e=this.shadowRoot?.querySelector(".header");if(!e)return;const t=e.querySelector(".header-group-row");t&&t.remove();const o=On(this.groups,this.columns);if(o){o.classList.toggle("no-borders",!this.config.showGroupBorders);const r=e.querySelector(".header-row");r?e.insertBefore(o,r):e.appendChild(o)}const i=e.querySelector(".header-row");i&&(i.classList.toggle("no-group-borders",!this.config.showGroupBorders),In(i,this.groups,this.columns))}isGroupingActive(){return this.isActive}getGroups(){return this.groups}getGroupColumns(e){const t=this.groups.find(o=>o.id===e);return t?t.columns:[]}refresh(){this.requestRender()}styles=Nn}const Le={sum:(n,e)=>n.reduce((t,o)=>t+(Number(o[e])||0),0),avg:(n,e)=>{const t=n.reduce((o,i)=>o+(Number(i[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]},le=new Map,D={register(n,e){le.set(n,e)},unregister(n){le.delete(n)},get(n){if(n!==void 0)return typeof n=="function"?n:le.get(n)??Le[n]},run(n,e,t,o){const i=this.get(n);return i?i(e,t,o):void 0},has(n){return le.has(n)||n in Le},list(){return[...Object.keys(Le),...le.keys()]}},Pt={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 Fn(n){return Pt[n]??Pt.sum}D.register.bind(D),D.unregister.bind(D);const Ht=D.get.bind(D),Mt=D.run.bind(D);D.list.bind(D);function zn({rows:n,config:e,expanded:t}){const o=e.groupOn;if(typeof o!="function")return[];const i={key:"__root__",value:null,depth:-1,rows:[],children:new Map};if(n.forEach(l=>{let a=o(l);a==null||a===!1?a=["__ungrouped__"]:Array.isArray(a)||(a=[a]);let c=i;a.forEach((d,u)=>{const h=d==null?"∅":String(d),p=c.key==="__root__"?h:c.key+"||"+h;let f=c.children.get(h);f||(f={key:p,value:d,depth:u,rows:[],children:new Map,parent:c},c.children.set(h,f)),c=f}),c.rows.push(l)}),i.children.size===1&&i.children.has("__ungrouped__")&&i.children.get("__ungrouped__").rows.length===n.length)return[];const r=[],s=l=>{if(l===i){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(i),r}function Bn(n,e){const t=new Set(n);return t.has(e)?t.delete(e):t.add(e),t}function Gn(n){const e=new Set;for(const t of n)t.kind==="group"&&e.add(t.key);return e}function Kn(){return new Set}function Vn(n){return n.kind!=="group"?0:n.rows.length}const $n='.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, 2px 8px)}.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:20px;height:20px;margin-right:4px;background:none;border:0;font:inherit}.group-toggle:hover{background:var(--tbw-grouping-rows-toggle-hover, var(--tbw-color-row-hover));border-radius:2px}.group-label{display:inline-flex;align-items:center;gap:8px}.group-count{color:var(--tbw-grouping-rows-count-color, var(--tbw-color-fg-muted));font-size:.85em;font-weight:400}[data-group-depth="0"] .group-label{padding-left:0}[data-group-depth="1"] .group-label{padding-left:20px}[data-group-depth="2"] .group-label{padding-left:40px}[data-group-depth="3"] .group-label{padding-left:60px}[data-group-depth="4"] .group-label{padding-left:80px}.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 Wn extends S{name="groupingRows";version="1.0.0";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(){const t=this.grid.effectiveConfig?.animation?.mode??"reduced-motion";if(t===!1||t==="off")return!1;if(t!==!0&&t!=="on"){const o=this.shadowRoot?.host;if(o&&getComputedStyle(o).getPropertyValue("--tbw-animation-enabled").trim()==="0")return!1}return this.config.animation??"slide"}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 o=zn({rows:[...e],config:t,expanded:this.expandedKeys});if(o.length===0)return this.isActive=!1,this.flattenedRows=[],[...e];this.isActive=!0,this.flattenedRows=o,this.keysToAnimate.clear();const i=new Set;return o.forEach((r,s)=>{if(r.kind==="data"){const l=`data-${s}`;i.add(l),this.previousVisibleKeys.has(l)||this.keysToAnimate.add(l)}}),this.previousVisibleKeys=i,o.map(r=>r.kind==="group"?{__isGroupRow:!0,__groupKey:r.key,__groupValue:r.value,__groupDepth:r.depth,__groupRows:r.rows,__groupExpanded:r.expanded,__groupRowCount:Vn(r)}:r.row)}onCellClick(e){const t=e.row;if(t?.__isGroupRow&&e.originalEvent.target?.closest(".group-toggle"))return this.toggle(t.__groupKey),!0}renderRow(e,t,o){if(!e?.__isGroupRow)return!1;const i=this.config;if(i.groupRowRenderer){const l=()=>{this.toggle(e.__groupKey)},a=i.groupRowRenderer({key:e.__groupKey,value:e.__groupValue,depth:e.__groupDepth,rows:e.__groupRows,expanded:e.__groupExpanded,toggleExpand:l});if(a)return t.className="group-row",t.__isCustomRow=!0,t.setAttribute("data-group-depth",String(e.__groupDepth)),typeof a=="string"?t.innerHTML=a:(t.innerHTML="",t.appendChild(a)),!0}const r=()=>{this.toggle(e.__groupKey)};return t.className="group-row",t.__isCustomRow=!0,t.setAttribute("data-group-depth",String(e.__groupDepth)),t.setAttribute("role","row"),t.setAttribute("aria-expanded",String(e.__groupExpanded)),t.style.paddingLeft=`${(e.__groupDepth||0)*(i.indentWidth??20)}px`,t.innerHTML="",i.fullWidth!==!1?this.renderFullWidthGroupRow(e,t,r):this.renderPerColumnGroupRow(e,t,r),!0}afterRender(){const e=this.animationStyle;if(e===!1||this.keysToAnimate.size===0)return;const t=this.shadowRoot?.querySelector(".rows");if(!t)return;const o=e==="fade"?"tbw-group-fade-in":"tbw-group-slide-in";for(const i of t.querySelectorAll(".data-grid-row:not(.group-row)")){const r=i.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)&&(i.classList.add(o),i.addEventListener("animationend",()=>i.classList.remove(o),{once:!0}))}this.keysToAnimate.clear()}renderFullWidthGroupRow(e,t,o){const i=this.config,r=document.createElement("div");r.className="cell group-full",r.style.gridColumn="1 / -1",r.setAttribute("role","gridcell");const s=document.createElement("button");s.type="button",s.className=`group-toggle${e.__groupExpanded?" expanded":""}`,s.setAttribute("aria-label",e.__groupExpanded?"Collapse group":"Expand group"),this.setIcon(s,this.resolveIcon(e.__groupExpanded?"collapse":"expand")),s.addEventListener("click",c=>{c.stopPropagation(),o()}),r.appendChild(s);const l=document.createElement("span");l.className="group-label";const a=i.formatLabel?i.formatLabel(e.__groupValue,e.__groupDepth||0,e.__groupKey):String(e.__groupValue);if(l.textContent=a,r.appendChild(l),i.showRowCount!==!1){const c=document.createElement("span");c.className="group-count",c.textContent=`(${e.__groupRowCount??e.__groupRows?.length??0})`,r.appendChild(c)}t.appendChild(r)}renderPerColumnGroupRow(e,t,o){const i=this.config,r=i.aggregators??{},s=this.columns,l=e.__groupRows??[],c=this.shadowRoot?.querySelector(".body")?.style.gridTemplateColumns||"";c&&(t.style.display="grid",t.style.gridTemplateColumns=c),s.forEach((d,u)=>{const h=document.createElement("div");if(h.className="cell group-cell",h.setAttribute("data-col",String(u)),h.setAttribute("role","gridcell"),u===0){const p=document.createElement("button");p.type="button",p.className=`group-toggle${e.__groupExpanded?" expanded":""}`,p.setAttribute("aria-label",e.__groupExpanded?"Collapse group":"Expand group"),this.setIcon(p,this.resolveIcon(e.__groupExpanded?"collapse":"expand")),p.addEventListener("click",w=>{w.stopPropagation(),o()}),h.appendChild(p);const f=document.createElement("span"),g=r[d.field];if(g){const w=Mt(g,l,d.field,d);f.textContent=w!=null?String(w):String(e.__groupValue)}else{const w=i.formatLabel?i.formatLabel(e.__groupValue,e.__groupDepth||0,e.__groupKey):String(e.__groupValue);f.textContent=w}if(h.appendChild(f),i.showRowCount!==!1){const w=document.createElement("span");w.className="group-count",w.textContent=` (${l.length})`,h.appendChild(w)}}else{const p=r[d.field];if(p){const f=Mt(p,l,d.field,d);h.textContent=f!=null?String(f):""}else h.textContent=""}t.appendChild(h)})}expandAll(){this.expandedKeys=Gn(this.flattenedRows),this.requestRender()}collapseAll(){this.expandedKeys=Kn(),this.requestRender()}toggle(e){this.expandedKeys=Bn(this.expandedKeys,e);const t=this.flattenedRows.find(o=>o.kind==="group"&&o.key===e);this.emit("group-toggle",{key:e,expanded:this.expandedKeys.has(e),value:t?.value,depth:t?.depth??0}),this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}expand(e){this.expandedKeys.has(e)||(this.expandedKeys=new Set([...this.expandedKeys,e]),this.requestRender())}collapse(e){if(this.expandedKeys.has(e)){const t=new Set(this.expandedKeys);t.delete(e),this.expandedKeys=t,this.requestRender()}}getGroupState(){const e=this.flattenedRows.filter(t=>t.kind==="group");return{isActive:this.isActive,expandedCount:this.expandedKeys.size,totalGroups:e.length,expandedKeys:[...this.expandedKeys]}}getRowCount(){return this.flattenedRows.length}refreshGroups(){this.requestRender()}getExpandedGroups(){return[...this.expandedKeys]}getFlattenedRows(){return this.flattenedRows}isGroupingActive(){return this.isActive}setGroupOn(e){this.config.groupOn=e,this.requestRender()}styles=$n}function Pe(n,e){const t=new Set(n);return t.has(e)?t.delete(e):t.add(e),t}function Un(n,e){const t=new Set(n);return t.add(e),t}function jn(n,e){const t=new Set(n);return t.delete(e),t}function Xn(n,e){return n.has(e)}function Yn(n,e,t,o){const i=document.createElement("div");i.className="master-detail-row",i.setAttribute("data-detail-for",String(e)),i.setAttribute("role","row");const r=document.createElement("div");r.className="master-detail-cell",r.setAttribute("role","cell"),r.style.gridColumn=`1 / ${o+1}`;const s=t(n,e);return typeof s=="string"?r.innerHTML=s:s instanceof HTMLElement&&r.appendChild(s),i.appendChild(r),i}const Zn=".master-detail-cell-wrapper{display:flex;align-items:center;gap:4px}.master-detail-toggle{cursor:pointer;opacity:.7;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center}.master-detail-toggle:hover{opacity:1}.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}.master-detail-cell{padding:16px;overflow:auto}.master-detail-row.tbw-expanding{animation:tbw-detail-expand var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}.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:500px;padding-top:16px;padding-bottom:16px}}@keyframes tbw-detail-collapse{0%{opacity:1;max-height:500px}to{opacity:0;max-height:0}}";class Jn extends S{name="masterDetail";version="1.0.0";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 o=e;if(o.__frameworkAdapter?.parseDetailElement){const u=o.__frameworkAdapter.parseDetailElement(t);if(u){this.config={...this.config,detailRenderer:u};return}}const i=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={};i!==null&&(c.animation=i==="false"?!1:i),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 p=ge(d,{value:u,row:u});return oe(p)}),Object.keys(c).length>0&&(this.config={...this.config,...c})}get isAnimationEnabled(){const t=this.grid.effectiveConfig?.animation?.mode??"reduced-motion";if(t===!1||t==="off")return!1;if(t===!0||t==="on")return!0;const o=this.shadowRoot?.host;return o?getComputedStyle(o).getPropertyValue("--tbw-animation-enabled").trim()!=="0":!0}get animationStyle(){return this.isAnimationEnabled?this.config.animation??"slide":!1}get animationDuration(){const e=this.shadowRoot?.host;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),o=parseInt(t,10);if(!isNaN(o))return o}return 200}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 o=()=>{e.classList.remove("tbw-collapsing"),t()};e.addEventListener("animationend",o,{once:!0}),setTimeout(o,this.animationDuration+50)}expandedRows=new Set;detailElements=new Map;detach(){this.expandedRows.clear(),this.detailElements.clear()}processColumns(e){if(!this.config.detailRenderer)return[...e];const t=[...e];if(t.length>0){const o={...t[0]},i=o.viewRenderer;if(i?.__masterDetailWrapped)return t;const r=s=>{const{value:l,row:a}=s,c=this.expandedRows.has(a),d=document.createElement("span");d.className="master-detail-cell-wrapper";const u=document.createElement("span");u.className=`master-detail-toggle${c?" expanded":""}`,this.setIcon(u,this.resolveIcon(c?"collapse":"expand")),u.setAttribute("role","button"),u.setAttribute("tabindex","0"),u.setAttribute("aria-expanded",String(c)),u.setAttribute("aria-label",c?"Collapse details":"Expand details"),d.appendChild(u);const h=document.createElement("span");if(i){const p=i(s);p instanceof Node?h.appendChild(p):h.textContent=String(p??l??"")}else h.textContent=String(l??"");return d.appendChild(h),d};r.__masterDetailWrapped=!0,o.viewRenderer=r,t[0]=o}return t}onRowClick(e){if(!(!this.config.expandOnRowClick||!this.config.detailRenderer))return this.expandedRows=Pe(this.expandedRows,e.row),this.emit("detail-expand",{rowIndex:e.rowIndex,row:e.row,expanded:this.expandedRows.has(e.row)}),this.requestRender(),!1}onCellClick(e){if(e.originalEvent?.target?.classList.contains("master-detail-toggle")){const o=e.row,i=e.rowIndex;return this.expandedRows=Pe(this.expandedRows,o),this.emit("detail-expand",{rowIndex:i,row:o,expanded:this.expandedRows.has(o)}),this.requestRender(),!0}this.expandedRows.size>0&&queueMicrotask(()=>this.#e())}afterRender(){this.#e()}onScrollRender(){!this.config.detailRenderer||this.expandedRows.size===0||this.#e()}#e(){if(!this.config.detailRenderer)return;const e=this.shadowRoot?.querySelector(".rows");if(!e)return;const t=new Map,o=e.querySelectorAll(".data-grid-row"),i=this.columns.length;for(const s of o){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=Yn(a,s,this.config.detailRenderer,i);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){const o=this.detailElements.get(t);if(o)e+=o.offsetHeight;else{const i=this.config?.detailHeight;e+=typeof i=="number"?i:150}}return e}getExtraHeightBefore(e){let t=0;for(const o of this.expandedRows){const i=this.rows.indexOf(o);if(i>=0&&i<e){const r=this.detailElements.get(o);if(r)t+=r.offsetHeight;else{const s=this.config?.detailHeight;t+=typeof s=="number"?s:150}}}return t}adjustVirtualStart(e,t,o){if(this.expandedRows.size===0)return e;const i=[];for(const l of this.expandedRows){const a=this.rows.indexOf(l);a>=0&&i.push({index:a,row:l})}i.sort((l,a)=>l.index-a.index);let r=e,s=0;for(const{index:l,row:a}of i){const c=l*o+s,u=this.detailElements.get(a)?.offsetHeight??(typeof this.config?.detailHeight=="number"?this.config.detailHeight:150),h=c+o+u;s+=u,!(l>=e)&&h>t&&l<r&&(r=l)}return r}expand(e){const t=this.rows[e];t&&(this.expandedRows=Un(this.expandedRows,t),this.requestRender())}collapse(e){const t=this.rows[e];t&&(this.expandedRows=jn(this.expandedRows,t),this.requestRender())}toggle(e){const t=this.rows[e];t&&(this.expandedRows=Pe(this.expandedRows,t),this.requestRender())}isExpanded(e){const t=this.rows[e];return t?Xn(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 o=this.rows.indexOf(t);o>=0&&e.push(o)}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()}}styles=Zn}function Qn(n,e,t){return e.length?[...n].sort((o,i)=>{for(const r of e){const l=t.find(u=>u.field===r.field)?.sortComparator??ei,a=o[r.field],c=i[r.field],d=l(a,c,o,i);if(d!==0)return r.direction==="asc"?d:-d}return 0}):[...n]}function ei(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 ti(n,e,t,o){const i=n.find(r=>r.field===e);return t?i?i.direction==="asc"?n.map(r=>r.field===e?{...r,direction:"desc"}:r):n.filter(r=>r.field!==e):n.length<o?[...n,{field:e,direction:"asc"}]:n:i?.direction==="asc"?[{field:e,direction:"desc"}]:i?.direction==="desc"?[]:[{field:e,direction:"asc"}]}function It(n,e){const t=n.findIndex(o=>o.field===e);return t>=0?t+1:void 0}function Ot(n,e){return n.find(t=>t.field===e)?.direction}const oi='.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 ni extends S{name="multiSort";version="1.0.0";get defaultConfig(){return{maxSortColumns:3,showSortIndex:!0}}sortModel=[];detach(){this.sortModel=[]}processRows(e){return this.sortModel.length===0?[...e]:Qn([...e],this.sortModel,[...this.columns])}onHeaderClick(e){if(!this.columns.find(r=>r.field===e.field)?.sortable)return!1;const o=e.originalEvent.shiftKey,i=this.config.maxSortColumns??3;return this.sortModel=ti(this.sortModel,e.field,o,i),this.emit("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),!0}afterRender(){const e=this.shadowRoot;if(!e)return;const t=this.config.showSortIndex!==!1;e.querySelectorAll(".header-row .cell[data-field]").forEach(i=>{const r=i.getAttribute("data-field");if(!r)return;const s=It(this.sortModel,r),l=Ot(this.sortModel,r);if(i.querySelector(".sort-index")?.remove(),l){i.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove(),i.setAttribute("data-sort",l);const d=document.createElement("span");d.className="sort-indicator",this.setIcon(d,this.resolveIcon(l==="asc"?"sortAsc":"sortDesc"));const u=i.querySelector(".tbw-filter-btn"),h=i.querySelector(".resize-handle"),p=u??h;if(p?i.insertBefore(d,p):i.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?i.insertBefore(f,d.nextSibling):i.appendChild(f)}}else i.removeAttribute("data-sort")})}getSortModel(){return[...this.sortModel]}setSortModel(e){this.sortModel=[...e],this.emit("sort-change",{sortModel:[...e]}),this.requestRender()}clearSort(){this.sortModel=[],this.emit("sort-change",{sortModel:[]}),this.requestRender()}getSortIndex(e){return It(this.sortModel,e)}getSortDirection(e){return Ot(this.sortModel,e)}getColumnState(e){const t=this.sortModel.findIndex(i=>i.field===e);return t===-1?void 0:{sort:{direction:this.sortModel[t].direction,priority:t}}}applyColumnState(e,t){if(!t.sort){this.sortModel=this.sortModel.filter(r=>r.field!==e);return}const o=this.sortModel.findIndex(r=>r.field===e),i={field:e,direction:t.sort.direction};o!==-1?this.sortModel[o]=i:this.sortModel.splice(t.sort.priority,0,i)}styles=oi}function ii(n){return n.filter(e=>e.sticky==="left")}function ri(n){return n.filter(e=>e.sticky==="right")}function He(n){return n.some(e=>e.sticky==="left"||e.sticky==="right")}function Dt(n,e){const t=n.shadowRoot;if(!t)return;const o=Array.from(t.querySelectorAll(".header-row .cell"));if(!o.length)return;const i=new Map;e.forEach((l,a)=>{l.field&&i.set(l.field,a)});let r=0;for(const l of e)if(l.sticky==="left"){const a=i.get(l.field),c=o.find(d=>d.getAttribute("data-field")===l.field);c&&(c.classList.add("sticky-left"),c.style.position="sticky",c.style.left=r+"px",a!==void 0&&t.querySelectorAll(`.data-grid-row .cell[data-col="${a}"]`).forEach(d=>{d.classList.add("sticky-left"),d.style.position="sticky",d.style.left=r+"px"}),r+=c.offsetWidth)}let s=0;for(const l of[...e].reverse())if(l.sticky==="right"){const a=i.get(l.field),c=o.find(d=>d.getAttribute("data-field")===l.field);c&&(c.classList.add("sticky-right"),c.style.position="sticky",c.style.right=s+"px",a!==void 0&&t.querySelectorAll(`.data-grid-row .cell[data-col="${a}"]`).forEach(d=>{d.classList.add("sticky-right"),d.style.position="sticky",d.style.right=s+"px"}),s+=c.offsetWidth)}}function Nt(n){const e=n.shadowRoot;if(!e)return;e.querySelectorAll(".sticky-left, .sticky-right").forEach(o=>{o.classList.remove("sticky-left","sticky-right"),o.style.position="",o.style.left="",o.style.right=""})}class si extends S{name="pinnedColumns";version="1.0.0";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 o=t?.columns;return Array.isArray(o)?He(o):!1}processColumns(e){return this.isApplied=He([...e]),[...e]}afterRender(){if(!this.isApplied)return;const e=this.grid,t=[...this.columns];if(!He(t)){Nt(e),this.isApplied=!1;return}queueMicrotask(()=>{Dt(e,t)})}onPluginQuery(e){switch(e.type){case ie.CAN_MOVE_COLUMN:{const t=e.context,o=t.sticky;if(o==="left"||o==="right")return!1;const i=t.meta?.sticky;return i==="left"||i==="right"?!1:void 0}default:return}}refreshStickyOffsets(){const e=[...this.columns];Dt(this.grid,e)}getLeftPinnedColumns(){const e=[...this.columns];return ii(e)}getRightPinnedColumns(){const e=[...this.columns];return ri(e)}clearStickyPositions(){Nt(this.grid)}getHorizontalScrollOffsets(e,t){if(!this.isApplied)return;let o=0,i=0;if(e){const s=e.querySelectorAll(".sticky-left"),l=e.querySelectorAll(".sticky-right");s.forEach(a=>{o+=a.offsetWidth}),l.forEach(a=>{i+=a.offsetWidth})}else{const l=this.grid.shadowRoot;l&&l.querySelectorAll(".header-row .cell").forEach(c=>{c.classList.contains("sticky-left")?o+=c.offsetWidth:c.classList.contains("sticky-right")&&(i+=c.offsetWidth)})}const r=t?.classList.contains("sticky-left")||t?.classList.contains("sticky-right");return{left:o,right:i,skipScroll:r}}}function li(n){return typeof n=="object"&&n!==null&&"aggFunc"in n}function Me(n,e){const t=document.createElement("div");t.className="tbw-pinned-rows",t.setAttribute("role","presentation"),t.setAttribute("aria-live","polite");const o=document.createElement("div");o.className="tbw-pinned-rows-left";const i=document.createElement("div");i.className="tbw-pinned-rows-center";const r=document.createElement("div");if(r.className="tbw-pinned-rows-right",n.showRowCount!==!1){const s=document.createElement("span");s.className="tbw-status-panel tbw-status-panel-row-count",s.textContent=`Total: ${e.totalRows} rows`,o.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}`,o.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=ai(s,e);switch(s.position){case"left":o.appendChild(l);break;case"center":i.appendChild(l);break;case"right":r.appendChild(l);break}}return t.appendChild(o),t.appendChild(i),t.appendChild(r),t}function qt(n){const e=document.createElement("div");return e.className=`tbw-aggregation-rows tbw-aggregation-rows-${n}`,e.setAttribute("role","presentation"),e}function Ft(n,e,t,o){n.innerHTML="";for(const i of e){const r=document.createElement("div");if(r.className="tbw-aggregation-row",r.setAttribute("role","presentation"),i.id&&r.setAttribute("data-aggregation-id",i.id),i.fullWidth){const s=document.createElement("div");s.className="tbw-aggregation-cell tbw-aggregation-cell-full",s.style.gridColumn="1 / -1",s.textContent=i.label||"",r.appendChild(s)}else for(const s of t){const l=document.createElement("div");l.className="tbw-aggregation-cell",l.setAttribute("data-field",s.field);let a,c;const d=i.aggregators?.[s.field];if(d)if(li(d)){const u=Ht(d.aggFunc);u&&(a=u(o,s.field,s)),c=d.formatter}else{const u=Ht(d);u&&(a=u(o,s.field,s))}else if(i.cells&&Object.prototype.hasOwnProperty.call(i.cells,s.field)){const u=i.cells[s.field];typeof u=="function"?a=u(o,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 ai(n,e){const t=document.createElement("div");t.className="tbw-status-panel tbw-status-panel-custom",t.id=`status-panel-${n.id}`;const o=n.render(e);return typeof o=="string"?t.innerHTML=o:t.appendChild(o),t}function zt(n,e,t,o,i){return{totalRows:n.length,filteredRows:i?.cachedResult?.length??n.length,selectedRows:o?.selected?.size??0,columns:e,rows:n,grid:t}}const ci=".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:8px 12px;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:12px;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:16px}.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, 2px 8px);min-height:var(--tbw-row-height, 28px);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 di extends S{name="pinnedRows";version="1.0.0";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.shadowRoot;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 o=this.getSelectionState(),i=this.getFilterState(),r=zt(this.rows,this.columns,this.grid,o,i),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=qt("top");const h=e.querySelector(".header");h&&h.nextSibling?t.insertBefore(this.topAggregationContainer,h.nextSibling):t.appendChild(this.topAggregationContainer)}Ft(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=Me(this.config,r),t.insertBefore(this.infoBarElement,t.firstChild);else{const h=Me(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=qt("bottom")),this.footerWrapper.appendChild(this.bottomAggregationContainer),Ft(this.bottomAggregationContainer,a,this.visibleColumns,this.rows)),d&&(this.infoBarElement=Me(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 zt(this.rows,this.columns,this.grid,e,t)}addPanel(e){this.config.customPanels||(this.config.customPanels=[]),this.config.customPanels.push(e),this.requestRender()}removePanel(e){this.config.customPanels&&(this.config.customPanels=this.config.customPanels.filter(t=>t.id!==e),this.requestRender())}addAggregationRow(e){this.config.aggregationRows||(this.config.aggregationRows=[]),this.config.aggregationRows.push(e),this.requestRender()}removeAggregationRow(e){this.config.aggregationRows&&(this.config.aggregationRows=this.config.aggregationRows.filter(t=>t.id!==e),this.requestRender())}styles=ci}const ui=Fn;function hi(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 Ie(n,e){return[...n,e].join("|")}function fi(n,e){const t=e.rowGroupFields??[],o=e.columnGroupFields??[],i=e.valueFields??[],r=pi(n,o),s=Bt(n,t,o,r,i,0,""),l=mi(s,r,i),a=Object.values(l).reduce((c,d)=>c+d,0);return{rows:s,columnKeys:r,totals:l,grandTotal:a}}function pi(n,e){if(e.length===0)return["value"];const t=new Set;for(const o of n){const i=e.map(r=>String(o[r]??"")).join("|");t.add(i)}return[...t].sort()}function gi(n,e){const t=new Map;for(const o of n){const i=String(o[e]??""),r=t.get(i);r?r.push(o):t.set(i,[o])}return t}function Bt(n,e,t,o,i,r,s){const l=[];if(e.length===0){const h=Gt(n,t,o,i),p=Kt(h);return l.push({rowKey:s||"all",rowLabel:s||"All",depth:r,values:h,total:p,isGroup:!1,rowCount:n.length}),l}const a=e[0],c=e.slice(1),d=c.length>0,u=gi(n,a);for(const[h,p]of u){const f=s?`${s}|${h}`:h,g=Gt(p,t,o,i),w=Kt(g);let m;d&&(m=Bt(p,c,t,o,i,r+1,f)),l.push({rowKey:f,rowLabel:h||"(blank)",depth:r,values:g,total:w,isGroup:d,children:m,rowCount:p.length})}return l}function Gt(n,e,t,o){const i={};for(const r of t)for(const s of o){const a=(e.length>0?n.filter(h=>e.map(p=>String(h[p]??"")).join("|")===r):n).map(h=>Number(h[s.field])||0),c=ui(s.aggFunc),d=a.length>0?c(a):null,u=Ie([r],s.field);i[u]=d}return i}function Kt(n){let e=0;for(const t of Object.values(n))e+=t??0;return e}function mi(n,e,t){const o={};function i(r){for(const s of r)if(!s.isGroup||!s.children?.length)for(const l of e)for(const a of t){const c=Ie([l],a.field);o[c]=(o[c]??0)+(s.values[c]??0)}else s.children&&i(s.children)}return i(n),o}function wi(n,e,t=!0){const o=[];function i(r){o.push(r);const s=e?e.has(r.rowKey):t;if(r.children&&s)for(const l of r.children)i(l)}for(const r of n)i(r);return o}function Oe(n){const e=[];function t(o){if(o.isGroup&&e.push(o.rowKey),o.children)for(const i of o.children)t(i)}for(const o of n)t(o);return e}const bi=["sum","avg","count","min","max","first","last"];function vi(n,e,t,o){const i=new AbortController,r={config:e,callbacks:o,signal:i.signal},s=document.createElement("div");return s.className="tbw-pivot-panel",s.appendChild(ae("Options",()=>Si(t,r))),s.appendChild(ae("Row Groups",()=>Vt("rowGroups",r))),s.appendChild(ae("Column Groups",()=>Vt("columnGroups",r))),s.appendChild(ae("Values",()=>Ci(r))),s.appendChild(ae("Available Fields",()=>Ei(r))),n.appendChild(s),()=>{i.abort(),s.remove()}}function ae(n,e){const t=document.createElement("div");t.className="tbw-pivot-section";const o=document.createElement("div");o.className="tbw-pivot-section-header",o.textContent=n;const i=document.createElement("div");return i.className="tbw-pivot-section-content",i.appendChild(e()),t.appendChild(o),t.appendChild(i),t}function Vt(n,e){const{config:t,callbacks:o,signal:i}=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(yi(l,n,e));return r.addEventListener("dragover",l=>{l.preventDefault(),r.classList.add("drag-over")},{signal:i}),r.addEventListener("dragleave",()=>{r.classList.remove("drag-over")},{signal:i}),r.addEventListener("drop",l=>{l.preventDefault(),r.classList.remove("drag-over");const a=l.dataTransfer?.getData("text/plain");a&&o.onAddFieldToZone(a,n)},{signal:i}),r}function yi(n,e,t){const{callbacks:o,signal:i}=t,r=document.createElement("div");r.className="tbw-pivot-field-chip",r.draggable=!0;const s=o.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(),o.onRemoveFieldFromZone(n,e)},{signal:i}),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:i}),r.addEventListener("dragend",()=>{r.classList.remove("dragging")},{signal:i}),r}function Ci(n){const{config:e,callbacks:t,signal:o}=n,i=document.createElement("div");i.className="tbw-pivot-drop-zone tbw-pivot-values-zone",i.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",i.appendChild(s)}else for(const s of r)i.appendChild(xi(s,n));return i.addEventListener("dragover",s=>{s.preventDefault(),i.classList.add("drag-over")},{signal:o}),i.addEventListener("dragleave",()=>{i.classList.remove("drag-over")},{signal:o}),i.addEventListener("drop",s=>{s.preventDefault(),i.classList.remove("drag-over");const l=s.dataTransfer?.getData("text/plain");l&&t.onAddValueField(l,"sum")},{signal:o}),i}function xi(n,e){const{callbacks:t,signal:o}=e,i=document.createElement("div");i.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 bi){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:o});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:o}),s.appendChild(l),s.appendChild(a),i.appendChild(s),i.appendChild(c),i}function Ei(n){const{config:e,callbacks:t,signal:o}=n,i=document.createElement("div");i.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",i.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:o}),c.addEventListener("dragend",()=>{c.classList.remove("dragging")},{signal:o}),i.appendChild(c)}return i}function Si(n,e){const{config:t,callbacks:o,signal:i}=e,r=document.createElement("div");return r.className="tbw-pivot-options",r.appendChild(De("Enable Pivot View",n,s=>{o.onTogglePivot(s)},i)),r.appendChild(De("Show Row Totals",t.showTotals??!0,s=>{o.onOptionChange("showTotals",s)},i)),r.appendChild(De("Show Grand Total",t.showGrandTotal??!0,s=>{o.onOptionChange("showGrandTotal",s)},i)),r}function De(n,e,t,o){const i=document.createElement("label");i.className="tbw-pivot-checkbox";const r=document.createElement("input");r.type="checkbox",r.checked=e,r.addEventListener("change",()=>t(r.checked),{signal:o});const s=document.createElement("span");return s.textContent=n,i.appendChild(r),i.appendChild(s),i}function Ri(n,e,t){return e.className="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((o,i)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(i)),r.setAttribute("role","gridcell"),i===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[o.field];r.textContent=s!=null?String(s):""}e.appendChild(r)}),!0}function _i(n,e,t){return e.className="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,i)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(i)),r.setAttribute("role","gridcell"),i===0){const s=Number(n.__pivotIndent)||0;r.style.paddingLeft=`${s+20}px`;const l=document.createElement("span");l.className="pivot-label",l.textContent=String(n.__pivotLabel??""),r.appendChild(l)}else{const s=n[o.field];r.textContent=s!=null?String(s):""}e.appendChild(r)}),!0}function Ai(n,e,t){return e.className="pivot-grand-total-row",e.setAttribute("role","presentation"),e.innerHTML="",t.forEach((o,i)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(i)),i===0){const s=document.createElement("span");s.className="pivot-label",s.textContent="Grand Total",r.appendChild(s)}else{const s=n[o.field];r.textContent=s!=null?String(s):""}e.appendChild(r)}),!0}const Ti='.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:12px;padding:12px;height:100%;overflow-y:auto;font-size:13px}.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:8px 12px;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:8px}.tbw-pivot-toggle-wrapper{display:flex;align-items:center}.tbw-pivot-toggle-label{display:flex;align-items:center;gap:8px;cursor:pointer}.tbw-pivot-toggle-label input{width:16px;height:16px;cursor:pointer}.tbw-pivot-drop-zone{min-height:60px;padding:8px;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:6px;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:8px;text-align:center;width:100%}.tbw-pivot-field-chip{display:inline-flex;align-items:center;gap:6px;padding:4px 8px;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:12px;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:16px;height:16px;padding:0;border:none;background:transparent;color:var(--tbw-color-fg-muted);font-size:14px;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:4px 8px}.tbw-pivot-value-label-wrapper{display:flex;align-items:center;gap:8px;flex:1;min-width:0}.tbw-pivot-agg-select{padding:2px 4px;font-size:11px;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:6px;min-height:40px}.tbw-pivot-options{display:flex;flex-direction:column;gap:8px}.tbw-pivot-checkbox{display:flex;align-items:center;gap:8px;cursor:pointer}.tbw-pivot-checkbox input{width:14px;height:14px;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 Q extends S{name="pivot";version="1.0.0";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(){const t=this.grid.effectiveConfig?.animation?.mode??"reduced-motion";if(t===!1||t==="off")return!1;if(t!==!0&&t!=="on"){const o=this.shadowRoot?.host;if(o&&getComputedStyle(o).getPropertyValue("--tbw-animation-enabled").trim()==="0")return!1}return this.config.animation??"slide"}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:Q.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=hi(this.config);if(t.length>0)return this.warn(`Config errors: ${t.join(", ")}`),[...e];if(this.buildFieldHeaderMap(),this.defaultExpanded=this.config.defaultExpanded??!0,this.expandedKeys.size===0&&this.defaultExpanded&&this.pivotResult){const s=Oe(this.pivotResult.rows);for(const l of s)this.expandedKeys.add(l)}if(this.pivotResult=fi(e,this.config),this.expandedKeys.size===0&&this.defaultExpanded){const s=Oe(this.pivotResult.rows);for(const l of s)this.expandedKeys.add(l)}const o=this.config.indentWidth??20,i=wi(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*o,__pivotTotal:s.total,...s.values}));this.keysToAnimate.clear();const r=new Set;for(const s of i){const l=s.__pivotRowKey;r.add(l),!this.previousVisibleKeys.has(l)&&s.__pivotDepth>0&&this.keysToAnimate.add(l)}return this.previousVisibleKeys=r,i}processColumns(e){if(!this.isActive||!this.pivotResult)return[...e];const t=[],o=(this.config.rowGroupFields??[]).map(i=>this.fieldHeaderMap.get(i)??i).join(" / ");t.push({field:"__pivotLabel",header:o||"Group",width:200});for(const i of this.pivotResult.columnKeys)for(const r of this.config.valueFields??[]){const s=Ie([i],r.field),l=r.header||this.fieldHeaderMap.get(r.field)||r.field;t.push({field:s,header:`${i} - ${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){const o=e;return o.__pivotRowKey&&o.__pivotHasChildren?Ri(o,t,{columns:this.gridColumns,onToggle:i=>this.toggle(i),resolveIcon:i=>this.resolveIcon(i),setIcon:(i,r)=>this.setIcon(i,r)}):o.__pivotRowKey!==void 0&&this.isActive?_i(o,t,this.gridColumns):(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="")}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.shadowRoot?.querySelector(".rows");if(!t)return;const o=e==="fade"?"tbw-pivot-fade-in":"tbw-pivot-slide-in";for(const i of t.querySelectorAll(".pivot-group-row, .pivot-leaf-row")){const r=i.dataset.pivotKey;r&&this.keysToAnimate.has(r)&&(i.classList.add(o),i.addEventListener("animationend",()=>i.classList.remove(o),{once:!0}))}this.keysToAnimate.clear()}renderGrandTotalFooter(){if(!this.pivotResult)return;const e=this.shadowRoot;if(!e)return;const t=e.querySelector(".tbw-scroll-area")??e.querySelector(".tbw-grid-content")??e.children[0];if(!t)return;this.grandTotalFooter||(this.grandTotalFooter=document.createElement("div"),this.grandTotalFooter.className="pivot-grand-total-footer",t.appendChild(this.grandTotalFooter));const o={__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals};Ai(o,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(){if(this.pivotResult){const e=Oe(this.pivotResult.rows);for(const t of e)this.expandedKeys.add(t);this.requestRender()}}collapseAll(){this.expandedKeys.clear(),this.requestRender()}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(Q.PANEL_ID)}hidePanel(){this.grid.closeToolPanel()}togglePanel(){this.grid.toggleToolPanel(Q.PANEL_ID)}isPanelVisible(){return this.grid.activeToolPanel===Q.PANEL_ID}get gridColumns(){return this.grid.columns??[]}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(){const e=this.grid;try{const t=e.getAllColumns?.()??e.columns??[];return this.originalColumns=t.filter(o=>!o.field.startsWith("__pivot")).map(o=>({field:o.field,header:o.header??o.field})),this.originalColumns}catch{return[]}}renderPanel(e){this.panelContainer=e,this.originalColumns.length===0&&this.captureOriginalColumns();const t={onTogglePivot:o=>{o?this.enablePivot():this.disablePivot(),this.refreshPanel()},onAddFieldToZone:(o,i)=>this.addFieldToZone(o,i),onRemoveFieldFromZone:(o,i)=>this.removeFieldFromZone(o,i),onAddValueField:(o,i)=>this.addValueField(o,i),onRemoveValueField:o=>this.removeValueField(o),onUpdateValueAggFunc:(o,i)=>this.updateValueAggFunc(o,i),onOptionChange:(o,i)=>{this.config[o]=i,this.isActive&&this.refresh()},getAvailableFields:()=>this.getAvailableFields()};return vi(e,this.config,this.isActive,t)}refreshPanel(){this.panelContainer&&(this.panelContainer.innerHTML="",this.renderPanel(this.panelContainer))}addFieldToZone(e,t){if(t==="rowGroups"){const o=this.config.rowGroupFields??[];o.includes(e)||(this.config.rowGroupFields=[...o,e])}else{const o=this.config.columnGroupFields??[];o.includes(e)||(this.config.columnGroupFields=[...o,e])}this.removeFromOtherZones(e,t),this.isActive&&this.refresh(),this.refreshPanel()}removeFieldFromZone(e,t){t==="rowGroups"?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(o=>o!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(o=>o!==e),this.isActive&&this.refresh(),this.refreshPanel()}removeFromOtherZones(e,t){t!=="rowGroups"&&(this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(o=>o!==e)),t!=="columnGroups"&&(this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(o=>o!==e)),t!=="values"&&(this.config.valueFields=(this.config.valueFields??[]).filter(o=>o.field!==e))}addValueField(e,t){const o=this.config.valueFields??[];o.some(i=>i.field===e)||(this.config.valueFields=[...o,{field:e,aggFunc:t}]),this.removeFromOtherZones(e,"values"),this.isActive&&this.refresh(),this.refreshPanel()}removeValueField(e){this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e),this.isActive&&this.refresh(),this.refreshPanel()}updateValueAggFunc(e,t){const o=this.config.valueFields??[],i=o.findIndex(r=>r.field===e);i>=0&&(o[i]={...o[i],aggFunc:t},this.config.valueFields=[...o]),this.isActive&&this.refresh()}styles=Ti}function $t(n){const e=n.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}function Wt(n,e,t){if(e===t||e<0||e>=n.length||t<0||t>n.length)return n;const o=[...n],[i]=o.splice(e,1);return o.splice(t,0,i),o}const ki='.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 Li extends S{name="reorder";version="1.0.0";get defaultConfig(){return{animation:"flip"}}get animationType(){return this.isAnimationEnabled?this.config.animation!==void 0?this.config.animation:this.config.viewTransition===!1?!1:(this.config.viewTransition===!0,"flip"):!1}get isAnimationEnabled(){const t=this.grid.effectiveConfig?.animation?.mode??"reduced-motion";if(t===!1||t==="off")return!1;if(t===!0||t==="on")return!0;const o=this.shadowRoot?.host;return o?getComputedStyle(o).getPropertyValue("--tbw-animation-enabled").trim()!=="0":!0}get animationDuration(){if(this.config.animationDuration!==void 0)return this.config.animationDuration;const e=this.shadowRoot?.host;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),o=parseInt(t,10);if(!isNaN(o))return o}return 200}isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;attach(e){super.attach(e),e.addEventListener("column-reorder-request",t=>{const o=t.detail;o?.field&&typeof o.toIndex=="number"&&this.moveColumn(o.field,o.toIndex)},{signal:this.disconnectSignal})}detach(){this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null}afterRender(){const e=this.shadowRoot;if(!e)return;e.querySelectorAll(".header-row > .cell").forEach(o=>{const i=o,r=i.getAttribute("data-field");if(!r)return;const s=this.columns.find(d=>d.field===r),c=!this.grid.queryPlugins({type:ie.CAN_MOVE_COLUMN,context:s}).includes(!1);if(!s||!$t(s)||!c){i.draggable=!1;return}i.draggable=!0,!i.getAttribute("data-dragstart-bound")&&(i.setAttribute("data-dragstart-bound","true"),i.addEventListener("dragstart",d=>{const h=this.getColumnOrder().indexOf(r);this.isDragging=!0,this.draggedField=r,this.draggedIndex=h,d.dataTransfer&&(d.dataTransfer.effectAllowed="move",d.dataTransfer.setData("text/plain",r)),i.classList.add("dragging")}),i.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,e.querySelectorAll(".header-row > .cell").forEach(d=>{d.classList.remove("dragging","drop-target","drop-before","drop-after")})}),i.addEventListener("dragover",d=>{if(d.preventDefault(),!this.isDragging||this.draggedField===r)return;const u=i.getBoundingClientRect(),h=u.left+u.width/2,f=this.getColumnOrder().indexOf(r);this.dropIndex=d.clientX<h?f:f+1,i.classList.add("drop-target"),i.classList.toggle("drop-before",d.clientX<h),i.classList.toggle("drop-after",d.clientX>=h)}),i.addEventListener("dragleave",()=>{i.classList.remove("drop-target","drop-before","drop-after")}),i.addEventListener("drop",d=>{d.preventDefault();const u=this.draggedField,h=this.draggedIndex,p=this.dropIndex;if(!this.isDragging||u===null||h===null||p===null)return;const f=p>h?p-1:p,g=this.getColumnOrder(),w=Wt(g,h,f),m={field:u,fromIndex:h,toIndex:f,columnOrder:w};this.updateColumnOrder(w),this.emit("column-move",m)}))})}onKeyDown(e){if(!e.altKey||e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;const t=this.grid,o=t._focusCol,i=t._visibleColumns;if(o<0||o>=i.length)return;const r=i[o];if(!r||!$t(r))return;const s=this.grid;if(s.queryPlugins({type:ie.CAN_MOVE_COLUMN,context:r}).includes(!1))return;const a=this.getColumnOrder(),c=a.indexOf(r.field);if(c===-1)return;const d=e.key==="ArrowLeft"?c-1:c+1;if(d<0||d>=a.length)return;const u=i.find(h=>h.field===a[d]);if(!(u&&s.queryPlugins({type:ie.CAN_MOVE_COLUMN,context:u}).includes(!1)))return this.moveColumn(r.field,d),t._focusCol=d,U(this.grid),e.preventDefault(),e.stopPropagation(),!0}getColumnOrder(){return this.grid.getColumnOrder()}moveColumn(e,t){const o=this.getColumnOrder(),i=o.indexOf(e);if(i===-1)return;const r=Wt(o,i,t);this.updateColumnOrder(r),this.emit("column-move",{field:e,fromIndex:i,toIndex:t,columnOrder: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.shadowRoot?.querySelectorAll(".header-row > .cell[data-field]").forEach(t=>{const o=t.getAttribute("data-field");o&&e.set(o,t.getBoundingClientRect().left)}),e}animateFLIP(e){const t=this.shadowRoot;if(!t||e.size===0)return;const o=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&&o.set(l,c)}),o.size===0)return;const i=[];if(t.querySelectorAll(".cell[data-field]").forEach(s=>{const l=o.get(s.getAttribute("data-field")??"");if(l!==void 0){const a=s;a.style.transform=`translateX(${l}px)`,i.push(a)}}),i.length===0)return;t.host.offsetHeight;const r=this.animationDuration;requestAnimationFrame(()=>{i.forEach(s=>{s.classList.add("flip-animating"),s.style.transform=""}),setTimeout(()=>{i.forEach(s=>{s.style.transform="",s.classList.remove("flip-animating")})},r+50)})}animateFade(e){const t=this.shadowRoot;if(!t){e();return}const o=this.captureHeaderPositions();e();const i=new Set;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(l=>{const a=l.getAttribute("data-field");if(!a)return;const c=o.get(a);if(c===void 0)return;const d=l.getBoundingClientRect().left;Math.abs(c-d)>1&&i.add(a)}),i.size===0)return;const r=[];if(t.querySelectorAll(".cell[data-field]").forEach(l=>{const a=l.getAttribute("data-field");if(a&&i.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.grid,o=this.animationType;if(o==="flip"&&this.shadowRoot){const i=this.captureHeaderPositions();t.setColumnOrder(e),requestAnimationFrame(()=>{this.shadowRoot?.host?.offsetHeight,this.animateFLIP(i)})}else o==="fade"?this.animateFade(()=>t.setColumnOrder(e)):t.setColumnOrder(e);t.requestStateChange?.()}styles=ki}function fe(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 Pi(n){const e=fe(n);return{from:{row:e.startRow,col:e.startCol},to:{row:e.endRow,col:e.endCol}}}function Ne(n){return n.map(Pi)}function Hi(n,e,t){const o=fe(t);return n>=o.startRow&&n<=o.endRow&&e>=o.startCol&&e<=o.endCol}function Ut(n,e,t){return t.some(o=>Hi(n,e,o))}function Mi(n){const e=[],t=fe(n);for(let o=t.startRow;o<=t.endRow;o++)for(let i=t.startCol;i<=t.endCol;i++)e.push({row:o,col:i});return e}function Ii(n){const e=new Map;for(const t of n)for(const o of Mi(t))e.set(`${o.row},${o.col}`,o);return[...e.values()]}function qe(n,e){return{startRow:n.row,startCol:n.col,endRow:e.row,endCol:e.col}}const Oi=':host .selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}:host .data-grid-row.row-focus{background-color:var(--tbw-focus-background, rgba(from var(--tbw-color-accent) r g b / 12%))}:host([data-selection-mode="row"]) .cell-focus{outline:none}:host .data-grid-row>.cell.selected{background-color:var(--tbw-range-selection-bg)}:host .data-grid-row>.cell.selected.top{border-top:2px solid var(--tbw-range-border-color)}:host .data-grid-row>.cell.selected.bottom{border-bottom:2px solid var(--tbw-range-border-color)}:host .data-grid-row>.cell.selected.first{border-left:2px solid var(--tbw-range-border-color)}:host .data-grid-row>.cell.selected.last{border-right:2px solid var(--tbw-range-border-color)}:host .tbw-selection-summary{font-size:13px;color:var(--tbw-color-fg-muted);white-space:nowrap}';function Di(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 o=[...e.selected].map(i=>({from:{row:i,col:0},to:{row:i,col:t-1}}));return{mode:n,ranges:o}}return n==="range"&&e.ranges.length>0?{mode:n,ranges:Ne(e.ranges)}:{mode:n,ranges:[]}}class Ni extends S{name="selection";version="1.0.0";get defaultConfig(){return{mode:"cell"}}selected=new Set;lastSelected=null;anchor=null;ranges=[];activeRange=null;cellAnchor=null;isDragging=!1;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:o,originalEvent:i}=e,{mode:r}=this.config;if(r==="cell")return this.selectedCell={row:t,col:o},this.emit("selection-change",this.#s()),this.requestAfterRender(),!1;if(r==="row")return this.selected.clear(),this.selected.add(t),this.lastSelected=t,this.emit("selection-change",this.#s()),this.requestAfterRender(),!1;if(r==="range"){const s=i.shiftKey,l=i.ctrlKey||i.metaKey;if(s&&this.cellAnchor){const a=qe(this.cellAnchor,{row:t,col:o});l?this.ranges.length>0?this.ranges[this.ranges.length-1]=a:this.ranges.push(a):this.ranges=[a],this.activeRange=a}else if(l){const a={startRow:t,startCol:o,endRow:t,endCol:o};this.ranges.push(a),this.activeRange=a,this.cellAnchor={row:t,col:o}}else{const a={startRow:t,startCol:o,endRow:t,endCol:o};this.ranges=[a],this.activeRange=a,this.cellAnchor={row:t,col:o}}return this.emit("selection-change",this.#s()),this.requestAfterRender(),!1}return!1}onKeyDown(e){const{mode:t}=this.config,i=["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.#s()),this.requestAfterRender(),!0;if(t==="cell"&&i)return queueMicrotask(()=>{this.selectedCell={row:this.grid._focusRow,col:this.grid._focusCol},this.emit("selection-change",this.#s()),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.#s()),this.requestAfterRender()}),!1;if(t==="range"&&i){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.#s()),this.requestAfterRender(),!0}}return!1}onCellMouseDown(e){if(this.config.mode!=="range"||e.rowIndex===void 0||e.colIndex===void 0||e.rowIndex<0||e.originalEvent.shiftKey&&this.cellAnchor)return;this.isDragging=!0;const t=e.rowIndex,o=e.colIndex;this.cellAnchor={row:t,col:o},e.originalEvent.ctrlKey||e.originalEvent.metaKey||(this.ranges=[]);const r={startRow:t,startCol:o,endRow:t,endCol:o};return this.ranges.push(r),this.activeRange=r,this.emit("selection-change",this.#s()),this.requestAfterRender(),!0}onCellMouseMove(e){if(this.config.mode!=="range"||!this.isDragging||!this.cellAnchor||e.rowIndex===void 0||e.colIndex===void 0||e.rowIndex<0)return;const t=qe(this.cellAnchor,{row:e.rowIndex,col:e.colIndex});return this.ranges.length>0?this.ranges[this.ranges.length-1]=t:this.ranges.push(t),this.activeRange=t,this.emit("selection-change",this.#s()),this.requestAfterRender(),!0}onCellMouseUp(e){if(this.config.mode==="range"&&this.isDragging)return this.isDragging=!1,!0}#e(){const e=this.shadowRoot;if(!e)return;const{mode:t}=this.config;e.querySelectorAll(".cell").forEach(r=>{r.classList.remove("selected","top","bottom","first","last")});const i=e.querySelectorAll(".data-grid-row");if(i.forEach(r=>{r.classList.remove("selected","row-focus")}),t==="row"&&(W(e),i.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){W(e);const r=this.activeRange?fe(this.activeRange):null;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&&Ut(a,c,this.ranges)&&(l.classList.add("selected"),r&&(a===r.startRow&&l.classList.add("top"),a===r.endRow&&l.classList.add("bottom"),c===r.startCol&&l.classList.add("first"),c===r.endCol&&l.classList.add("last")))})}t==="cell"&&this.selectedCell&&W(e)}afterRender(){const e=this.shadowRoot;if(!e)return;const t=e.children[0],{mode:o}=this.config;if(this.pendingKeyboardUpdate&&o==="range"){const{shiftKey:i}=this.pendingKeyboardUpdate;this.pendingKeyboardUpdate=null;const r=this.grid._focusRow,s=this.grid._focusCol;if(i&&this.cellAnchor){const l=qe(this.cellAnchor,{row:r,col:s});this.ranges=[l],this.activeRange=l}else i||(this.ranges=[],this.activeRange=null,this.cellAnchor={row:r,col:s});this.emit("selection-change",this.#s())}this.grid.setAttribute("data-selection-mode",o),t&&t.classList.toggle("selecting",this.isDragging),this.#e()}onScrollRender(){this.#e()}getSelectedCell(){return this.selectedCell}getSelectedRows(){return[...this.selected]}getRanges(){return Ne(this.ranges)}getSelectedCells(){return Ii(this.ranges)}isCellSelected(e,t){return Ut(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:Ne(this.ranges)}),this.requestAfterRender()}#s(){return Di(this.config.mode,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges},this.columns.length)}styles=Oi}function qi(n,e,t,o){const i=new Set(n.selected);let r=n.anchor;if(t==="single")i.clear(),i.add(e),r=e;else if(t==="multiple"){const s=o.ctrlKey||o.metaKey;if(o.shiftKey&&n.anchor!==null){const l=Math.min(n.anchor,e),a=Math.max(n.anchor,e);for(let c=l;c<=a;c++)i.add(c)}else s?(i.has(e)?i.delete(e):i.add(e),r=e):(i.clear(),i.add(e),r=e)}return{selected:i,lastSelected:e,anchor:r}}function Fi(n){const e=new Set;for(let t=0;t<n;t++)e.add(t);return e}function zi(n,e){const t=[],o=[];for(const i of e)n.has(i)||t.push(i);for(const i of n)e.has(i)||o.push(i);return{added:t,removed:o}}function pe(n,e){return Math.floor(n/e)}function Bi(n,e){return{start:n*e,end:(n+1)*e}}function Gi(n,e,t){const o=pe(n,t),i=pe(e-1,t),r=[];for(let s=o;s<=i;s++)r.push(s);return r}async function jt(n,e,t,o){const i=Bi(e,t);return n.getRows({startRow:i.start,endRow:i.end,sortModel:o.sortModel,filterModel:o.filterModel})}function Ki(n,e,t){const o=pe(n,e),i=t.get(o);if(!i)return;const r=n%e;return i[r]}const Vi=100;class $i extends S{name="serverSide";version="1.0.0";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,o={startRow:e._virtualization.start,endRow:e._virtualization.end},i=Gi(o.startRow,o.endRow,t);for(const r of i)if(!(this.loadedBlocks.has(r)||this.loadingBlocks.has(r))){if(this.loadingBlocks.size>=(this.config.maxConcurrentRequests??2))break;this.loadingBlocks.add(r),jt(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 o=0;o<this.totalRowCount;o++){const i=Ki(o,this.config.cacheBlockSize??100,this.loadedBlocks);t.push(i??{__loading:!0,__index:o})}return t}onScroll(e){this.dataSource&&(this.loadRequiredBlocks(),this.scrollDebounceTimer&&clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=setTimeout(()=>{this.loadRequiredBlocks()},Vi))}setDataSource(e){this.dataSource=e,this.loadedBlocks.clear(),this.loadingBlocks.clear();const t=this.config.cacheBlockSize??100;jt(e,0,t,{}).then(o=>{this.loadedBlocks.set(0,o.rows),this.totalRowCount=o.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,o=pe(e,t);return this.loadedBlocks.has(o)}getLoadedBlockCount(){return this.loadedBlocks.size}}function Xt(n,e,t){return n.id!==void 0?String(n.id):t?`${t}-${e}`:String(e)}function Yt(n,e){const t=new Set(n);return t.has(e)?t.delete(e):t.add(e),t}function Fe(n,e,t=null,o=0){const i=e.childrenField??"children",r=new Set;for(let s=0;s<n.length;s++){const l=n[s],a=Xt(l,s,t),c=l[i];if(Array.isArray(c)&&c.length>0){r.add(a);const d=Fe(c,e,a,o+1);for(const u of d)r.add(u)}}return r}function Wi(){return new Set}function Zt(n,e,t,o=null,i=0){const r=t.childrenField??"children";for(let s=0;s<n.length;s++){const l=n[s],a=Xt(l,s,o);if(a===e)return[a];const c=l[r];if(Array.isArray(c)&&c.length>0){const d=Zt(c,e,t,a,i+1);if(d)return[a,...d]}}return null}function Ui(n,e,t,o){const i=Zt(n,e,t);if(!i)return o;const r=new Set(o);for(let s=0;s<i.length-1;s++)r.add(i[s]);return r}function ze(n,e="children"){if(!Array.isArray(n)||n.length===0)return!1;for(const t of n){if(!t)continue;const o=t[e];if(Array.isArray(o)&&o.length>0)return!0}return!1}function Jt(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 o of e){const i=t[o];if(Array.isArray(i)&&i.length>0)return o}return null}function Qt(n,e="children",t=0){if(!Array.isArray(n)||n.length===0)return t;let o=t;for(const i of n){if(!i)continue;const r=i[e];if(Array.isArray(r)&&r.length>0){const s=Qt(r,e,t+1);s>o&&(o=s)}}return o}function eo(n,e="children"){if(!Array.isArray(n))return 0;let t=0;for(const o of n){if(!o)continue;t++;const i=o[e];Array.isArray(i)&&(t+=eo(i,e))}return t}const ji=".tree-cell{display:flex;align-items:center;padding-left:calc(var(--tree-depth, 0) * var(--tbw-tree-indent, 20px))}.tree-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center;margin-right:4px}.tree-toggle:hover{color:var(--tbw-tree-accent, var(--tbw-color-accent))}.tree-spacer{width:14px;display:inline-block}.data-grid-row.tbw-tree-slide-in{animation:tbw-tree-slide-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)}}.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-fade-in{0%{opacity:0}to{opacity:1}}";class Xi extends S{name="tree";version="1.0.0";styles=ji;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(){const t=this.grid.effectiveConfig?.animation?.mode??"reduced-motion";if(t===!1||t==="off")return!1;if(t!==!0&&t!=="on"){const o=this.shadowRoot?.host;if(o&&getComputedStyle(o).getPropertyValue("--tbw-animation-enabled").trim()==="0")return!1}return this.config.animation??"slide"}detect(e){if(!this.config.autoDetect)return!1;const t=e,o=this.config.childrenField??Jt(t)??"children";return ze(t,o)}processRows(e){const t=this.config.childrenField??"children",o=e;if(!ze(o,t))return this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),[...e];let i=this.withStableKeys(o);this.sortState&&(i=this.sortTree(i,this.sortState.field,this.sortState.direction)),this.config.defaultExpanded&&!this.initialExpansionDone&&(this.expandedKeys=Fe(i,this.config),this.initialExpansionDone=!0),this.flattenedRows=this.flattenTree(i,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 o=this.config.childrenField??"children";return e.map((i,r)=>{const s=i.__stableKey,l=i.id!==void 0?String(i.id):s??(t?`${t}-${r}`:String(r)),a=i[o],c=Array.isArray(a)&&a.length>0;return{...i,__stableKey:l,...c?{[o]:this.withStableKeys(a,l)}:{}}})}flattenTree(e,t,o=0){const i=this.config.childrenField??"children",r=[];for(const s of e){const a=s.__stableKey??String(s.id??"?"),c=s[i],d=Array.isArray(c)&&c.length>0,u=t.has(a);r.push({key:a,data:s,depth:o,hasChildren:d,isExpanded:u,parentKey:o>0&&a.substring(0,a.lastIndexOf("-"))||null}),d&&u&&r.push(...this.flattenTree(c,t,o+1))}return r}sortTree(e,t,o){const i=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?o:a<c?-o:0}).map(s=>{const l=s[i];return Array.isArray(l)&&l.length>0?{...s,[i]:this.sortTree(l,t,o)}:s})}processColumns(e){if(this.flattenedRows.length===0)return[...e];const t=[...e];if(t.length===0)return t;const o={...t[0]},i=o.viewRenderer;if(i?.__treeWrapped)return t;const r=()=>this.config,s=this.setIcon.bind(this),l=this.resolveIcon.bind(this),a=c=>{const{value:d,row:u}=c,{indentWidth:h=20,showExpandIcons:p=!0}=r(),f=u,g=document.createElement("span");if(g.className="tree-cell",g.style.setProperty("--tree-depth",String(f.__treeDepth??0)),g.style.setProperty("--tbw-tree-indent",`${h}px`),f.__treeHasChildren&&p){const m=document.createElement("span");m.className=`tree-toggle${f.__treeExpanded?" expanded":""}`,s(m,l(f.__treeExpanded?"collapse":"expand")),m.setAttribute("data-tree-key",String(f.__treeKey??"")),g.appendChild(m)}else if(p){const m=document.createElement("span");m.className="tree-spacer",g.appendChild(m)}const w=document.createElement("span");if(i){const m=i(c);m instanceof Node?w.appendChild(m):w.textContent=String(m??d??"")}else w.textContent=String(d??"");return g.appendChild(w),g};return a.__treeWrapped=!0,o.viewRenderer=a,t[0]=o,t}onCellClick(e){const t=e.originalEvent?.target;if(!t?.classList.contains("tree-toggle"))return!1;const o=t.getAttribute("data-tree-key"),i=o?this.rowKeyMap.get(o):null;return i?(this.expandedKeys=Yt(this.expandedKeys,o),this.emit("tree-expand",{key:o,row:i.data,expanded:this.expandedKeys.has(o),depth:i.depth}),this.requestRender(),!0):!1}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 o=this.grid;return o._sortState!==void 0&&(o._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.shadowRoot?.querySelector(".rows");if(!t)return;const o=e==="fade"?"tbw-tree-fade-in":"tbw-tree-slide-in";for(const i of t.querySelectorAll(".data-grid-row")){const r=i.querySelector(".cell[data-row]"),s=r?parseInt(r.getAttribute("data-row")??"-1",10):-1,l=this.flattenedRows[s]?.key;l&&this.keysToAnimate.has(l)&&(i.classList.add(o),i.addEventListener("animationend",()=>i.classList.remove(o),{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=Yt(this.expandedKeys,e),this.requestRender()}expandAll(){this.expandedKeys=Fe(this.rows,this.config),this.requestRender()}collapseAll(){this.expandedKeys=Wi(),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=Ui(this.rows,e,this.config,this.expandedKeys),this.requestRender()}}function Yi(n,e,t){const o=[...n.undoStack,e];for(;o.length>t;)o.shift();return{undoStack:o,redoStack:[]}}function to(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 oo(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 Zi(n){return n.undoStack.length>0}function Ji(n){return n.redoStack.length>0}function Qi(){return{undoStack:[],redoStack:[]}}function er(n,e,t,o){return{type:"cell-edit",rowIndex:n,field:e,oldValue:t,newValue:o,timestamp:Date.now()}}class tr extends S{static dependencies=[{name:"editing",required:!0,reason:"UndoRedoPlugin tracks cell edit history"}];name="undoRedo";version="1.0.0";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,o=(e.ctrlKey||e.metaKey)&&(e.key==="y"||e.key==="z"&&e.shiftKey);if(t){const i=to({undoStack:this.undoStack,redoStack:this.redoStack});if(i.action){const r=this.rows;r[i.action.rowIndex]&&(r[i.action.rowIndex][i.action.field]=i.action.oldValue),this.undoStack=i.newState.undoStack,this.redoStack=i.newState.redoStack,this.emit("undo",{action:i.action,type:"undo"}),this.requestRender()}return!0}if(o){const i=oo({undoStack:this.undoStack,redoStack:this.redoStack});if(i.action){const r=this.rows;r[i.action.rowIndex]&&(r[i.action.rowIndex][i.action.field]=i.action.newValue),this.undoStack=i.newState.undoStack,this.redoStack=i.newState.redoStack,this.emit("redo",{action:i.action,type:"redo"}),this.requestRender()}return!0}return!1}recordEdit(e,t,o,i){const r=er(e,t,o,i),s=Yi({undoStack:this.undoStack,redoStack:this.redoStack},r,this.config.maxHistorySize??100);this.undoStack=s.undoStack,this.redoStack=s.redoStack}undo(){const e=to({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=oo({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 Zi({undoStack:this.undoStack,redoStack:this.redoStack})}canRedo(){return Ji({undoStack:this.undoStack,redoStack:this.redoStack})}clearHistory(){const e=Qi();this.undoStack=e.undoStack,this.redoStack=e.redoStack}getUndoStack(){return[...this.undoStack]}getRedoStack(){return[...this.redoStack]}}const or='.tbw-visibility-content{display:flex;flex-direction:column;height:100%}.tbw-visibility-list{flex:1;overflow-y:auto;padding:8px}.tbw-visibility-row{display:flex;align-items:center;gap:8px;padding:6px 4px;cursor:pointer;font-size:13px;border-radius:var(--tbw-border-radius, 4px);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:10px;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:8px;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:8px;padding:8px 12px;border:1px solid var(--tbw-visibility-border, var(--tbw-color-border, #e5e7eb));border-radius:var(--tbw-border-radius, 4px);background:var(--tbw-visibility-btn-bg, var(--tbw-color-header-bg, #f9fafb));color:var(--tbw-color-fg, #1f2937);cursor:pointer;font-size:13px}.tbw-visibility-show-all:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover, #f3f4f6))}';function no(n){const e=n.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}class ee extends S{static dependencies=[{name:"reorder",required:!1,reason:"Enables drag-to-reorder columns in visibility panel"}];name="visibility";version="1.0.0";static PANEL_ID="columns";get defaultConfig(){return{allowHideAll:!1}}columnListElement=null;isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;detach(){this.columnListElement=null,this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null}getToolPanel(){return{id:ee.PANEL_ID,title:"Columns",icon:"☰",tooltip:"Column visibility",order:100,render:e=>this.renderPanelContent(e)}}show(){this.grid.openToolPanel(ee.PANEL_ID)}hide(){this.grid.closeToolPanel()}toggle(){this.grid.toggleToolPanel(ee.PANEL_ID)}isColumnVisible(e){return this.grid.isColumnVisible(e)}setColumnVisible(e,t){this.grid.setColumnVisible(e,t)}getVisibleColumns(){return this.grid.getAllColumns().filter(t=>t.visible).map(t=>t.field)}getHiddenColumns(){return this.grid.getAllColumns().filter(t=>!t.visible).map(t=>t.field)}showAll(){this.grid.showAllColumns()}toggleColumn(e){this.grid.toggleColumnVisibility(e)}showColumn(e){this.grid.setColumnVisible(e,!0)}hideColumn(e){this.grid.setColumnVisible(e,!1)}getAllColumns(){return this.grid.getAllColumns()}isPanelVisible(){return this.grid.activeToolPanel===ee.PANEL_ID}renderPanelContent(e){const t=this.grid,o=document.createElement("div");o.className="tbw-visibility-content";const i=document.createElement("div");i.className="tbw-visibility-list",o.appendChild(i);const r=document.createElement("button");return r.className="tbw-visibility-show-all",r.textContent="Show All",r.addEventListener("click",()=>{t.showAllColumns(),this.rebuildToggles(i)}),o.appendChild(r),this.columnListElement=i,this.rebuildToggles(i),e.appendChild(o),()=>{this.columnListElement=null,o.remove()}}hasReorderPlugin(){const e=this.grid?.getPluginByName?.("reorder");return!!(e&&typeof e.moveColumn=="function")}rebuildToggles(e){const t=this.grid,o=this.hasReorderPlugin();e.innerHTML="";const i=t.getAllColumns();for(let r=0;r<i.length;r++){const s=i[r],l=s.header||s.field,a=document.createElement("div");a.className=s.lockVisible?"tbw-visibility-row locked":"tbw-visibility-row",a.setAttribute("data-field",s.field),a.setAttribute("data-index",String(r)),o&&no(s)&&(a.draggable=!0,a.classList.add("reorderable"),this.setupDragListeners(a,s.field,r,e));const c=document.createElement("label");c.className="tbw-visibility-label";const d=document.createElement("input");d.type="checkbox",d.checked=s.visible,d.disabled=s.lockVisible??!1,d.addEventListener("change",()=>{t.toggleColumnVisibility(s.field),setTimeout(()=>this.rebuildToggles(e),0)});const u=document.createElement("span");if(u.textContent=l,c.appendChild(d),c.appendChild(u),o&&no(s)){const h=document.createElement("span");h.className="tbw-visibility-handle",this.setIcon(h,this.resolveIcon("dragHandle")),h.title="Drag to reorder",a.appendChild(h)}a.appendChild(c),e.appendChild(a)}}setupDragListeners(e,t,o,i){e.addEventListener("dragstart",r=>{this.isDragging=!0,this.draggedField=t,this.draggedIndex=o,r.dataTransfer&&(r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",t)),e.classList.add("dragging")}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,i.querySelectorAll(".tbw-visibility-row").forEach(r=>{r.classList.remove("dragging","drop-target","drop-before","drop-after")})}),e.addEventListener("dragover",r=>{if(r.preventDefault(),!this.isDragging||this.draggedField===t)return;const s=e.getBoundingClientRect(),l=s.top+s.height/2;this.dropIndex=r.clientY<l?o:o+1,i.querySelectorAll(".tbw-visibility-row").forEach(a=>{a!==e&&a.classList.remove("drop-target","drop-before","drop-after")}),e.classList.add("drop-target"),e.classList.toggle("drop-before",r.clientY<l),e.classList.toggle("drop-after",r.clientY>=l)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",r=>{r.preventDefault();const s=this.draggedField,l=this.draggedIndex,a=this.dropIndex;if(!this.isDragging||s===null||l===null||a===null)return;const c=a>l?a-1:a;if(c!==l){const d={field:s,fromIndex:l,toIndex:c};this.emit("column-reorder-request",d),setTimeout(()=>{this.rebuildToggles(i)},0)}})}styles=or}v.BaseGridPlugin=S,v.ClipboardPlugin=dn,v.ColumnVirtualizationPlugin=pn,v.ContextMenuPlugin=mn,v.DEFAULT_ANIMATION_CONFIG=Be,v.DEFAULT_GRID_ICONS=O,v.DGEvents=ln,v.DataGridElement=N,v.EditingPlugin=yn,v.ExportPlugin=Rn,v.FOCUSABLE_EDITOR_SELECTOR=he,v.FilteringPlugin=B,v.FitModeEnum=$,v.GridCSSVars=sn,v.GridClasses=k,v.GridDataAttrs=re,v.GridElement=N,v.GridSelectors=rn,v.GroupingColumnsPlugin=qn,v.GroupingRowsPlugin=Wn,v.MasterDetailPlugin=Jn,v.MultiSortPlugin=ni,v.PLUGIN_QUERIES=ie,v.PinnedColumnsPlugin=si,v.PinnedRowsPlugin=di,v.PivotPlugin=Q,v.PluginEvents=an,v.PluginManager=bt,v.RenderPhase=L,v.ReorderPlugin=Li,v.SelectionPlugin=Ni,v.ServerSidePlugin=$i,v.TreePlugin=Xi,v.UndoRedoPlugin=tr,v.VisibilityPlugin=ee,v.builtInSort=Ye,v.clearEditingState=At,v.computeSelectionDiff=zi,v.countNodes=eo,v.defaultComparator=Xe,v.defaultEditorFor=_t,v.detectTreeStructure=ze,v.getMaxDepth=Qt,v.handleRowClick=qi,v.hasEditingCells=wn,v.inferChildrenField=Jt,v.selectAll=Fi,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
|
|
63
69
|
//# sourceMappingURL=grid.all.umd.js.map
|