@toolbox-web/grid 0.3.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/all.d.ts +19 -19
- package/all.d.ts.map +1 -1
- package/all.js +1775 -1202
- package/all.js.map +1 -1
- package/index.js +2152 -2028
- package/index.js.map +1 -1
- package/lib/core/grid.d.ts +22 -12
- package/lib/core/grid.d.ts.map +1 -1
- package/lib/core/internal/columns.d.ts +0 -9
- package/lib/core/internal/columns.d.ts.map +1 -1
- package/lib/core/internal/config-manager.d.ts +236 -0
- package/lib/core/internal/config-manager.d.ts.map +1 -0
- package/lib/core/internal/event-delegation.d.ts.map +1 -1
- package/lib/core/internal/header.d.ts.map +1 -1
- package/lib/core/internal/keyboard.d.ts.map +1 -1
- package/lib/core/internal/render-scheduler.d.ts +123 -0
- package/lib/core/internal/render-scheduler.d.ts.map +1 -0
- package/lib/core/internal/rows.d.ts +8 -3
- package/lib/core/internal/rows.d.ts.map +1 -1
- package/lib/core/internal/sanitize.d.ts +2 -2
- package/lib/core/internal/sanitize.d.ts.map +1 -1
- package/lib/core/internal/shell.d.ts +40 -2
- package/lib/core/internal/shell.d.ts.map +1 -1
- package/lib/core/internal/validate-config.d.ts +11 -0
- package/lib/core/internal/validate-config.d.ts.map +1 -0
- package/lib/core/plugin/base-plugin.d.ts +70 -0
- package/lib/core/plugin/base-plugin.d.ts.map +1 -1
- package/lib/core/plugin/plugin-manager.d.ts +13 -2
- package/lib/core/plugin/plugin-manager.d.ts.map +1 -1
- package/lib/core/plugin/types.d.ts +17 -3
- package/lib/core/plugin/types.d.ts.map +1 -1
- package/lib/core/types.d.ts +112 -12
- package/lib/core/types.d.ts.map +1 -1
- package/lib/plugins/clipboard/ClipboardPlugin.d.ts.map +1 -1
- package/lib/plugins/clipboard/index.js +50 -18
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js +60 -25
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js +51 -16
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/editing/EditingPlugin.d.ts +117 -0
- package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -0
- package/lib/{core/internal → plugins/editing}/editors.d.ts +1 -1
- package/lib/plugins/editing/editors.d.ts.map +1 -0
- package/lib/plugins/editing/index.d.ts +8 -0
- package/lib/plugins/editing/index.d.ts.map +1 -0
- package/lib/plugins/editing/index.js +705 -0
- package/lib/plugins/editing/index.js.map +1 -0
- package/lib/plugins/editing/types.d.ts +45 -0
- package/lib/plugins/editing/types.d.ts.map +1 -0
- package/lib/plugins/export/ExportPlugin.d.ts.map +1 -1
- package/lib/plugins/export/index.js +74 -39
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
- package/lib/plugins/filtering/index.js +87 -50
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/grouping-columns.d.ts +4 -4
- package/lib/plugins/grouping-columns/grouping-columns.d.ts.map +1 -1
- package/lib/plugins/grouping-columns/index.js +59 -24
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts.map +1 -1
- package/lib/plugins/grouping-rows/grouping-rows.d.ts.map +1 -1
- package/lib/plugins/grouping-rows/index.js +46 -11
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/MasterDetailPlugin.d.ts +2 -2
- package/lib/plugins/master-detail/MasterDetailPlugin.d.ts.map +1 -1
- package/lib/plugins/master-detail/index.js +140 -102
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/master-detail/types.d.ts +12 -2
- package/lib/plugins/master-detail/types.d.ts.map +1 -1
- package/lib/plugins/multi-sort/MultiSortPlugin.d.ts.map +1 -1
- package/lib/plugins/multi-sort/index.js +59 -22
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js +41 -6
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts.map +1 -1
- package/lib/plugins/pinned-rows/index.js +45 -9
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/index.js +42 -7
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/reorder/ReorderPlugin.d.ts.map +1 -1
- package/lib/plugins/reorder/index.js +59 -19
- package/lib/plugins/reorder/index.js.map +1 -1
- package/lib/plugins/selection/index.js +41 -6
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js +48 -13
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/tree/TreePlugin.d.ts +3 -3
- package/lib/plugins/tree/TreePlugin.d.ts.map +1 -1
- package/lib/plugins/tree/index.js +165 -126
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/tree/tree-data.d.ts +6 -6
- package/lib/plugins/tree/tree-data.d.ts.map +1 -1
- package/lib/plugins/tree/tree-detect.d.ts +5 -9
- package/lib/plugins/tree/tree-detect.d.ts.map +1 -1
- package/lib/plugins/tree/types.d.ts +16 -4
- package/lib/plugins/tree/types.d.ts.map +1 -1
- package/lib/plugins/undo-redo/index.js +46 -11
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/index.js +37 -2
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/public.d.ts +104 -13
- package/public.d.ts.map +1 -1
- package/umd/grid.all.umd.js +31 -19
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +18 -6
- 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 +2 -0
- package/umd/plugins/editing.umd.js.map +1 -0
- package/umd/plugins/export.umd.js +2 -2
- package/umd/plugins/export.umd.js.map +1 -1
- package/umd/plugins/filtering.umd.js +1 -1
- package/umd/plugins/filtering.umd.js.map +1 -1
- package/umd/plugins/grouping-columns.umd.js +1 -1
- package/umd/plugins/grouping-columns.umd.js.map +1 -1
- package/umd/plugins/grouping-rows.umd.js +1 -1
- package/umd/plugins/grouping-rows.umd.js.map +1 -1
- package/umd/plugins/master-detail.umd.js +1 -1
- package/umd/plugins/master-detail.umd.js.map +1 -1
- package/umd/plugins/multi-sort.umd.js +1 -1
- package/umd/plugins/multi-sort.umd.js.map +1 -1
- package/umd/plugins/pinned-rows.umd.js +1 -1
- package/umd/plugins/pinned-rows.umd.js.map +1 -1
- package/umd/plugins/reorder.umd.js +1 -1
- package/umd/plugins/reorder.umd.js.map +1 -1
- package/umd/plugins/tree.umd.js +1 -1
- package/umd/plugins/tree.umd.js.map +1 -1
- package/lib/core/internal/column-state.d.ts +0 -124
- package/lib/core/internal/column-state.d.ts.map +0 -1
- package/lib/core/internal/editing.d.ts +0 -76
- package/lib/core/internal/editing.d.ts.map +0 -1
- package/lib/core/internal/editors.d.ts.map +0 -1
- package/lib/core/internal/grid-internals.d.ts +0 -83
- package/lib/core/internal/grid-internals.d.ts.map +0 -1
package/umd/grid.all.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(y,U){typeof exports=="object"&&typeof module<"u"?U(exports):typeof define=="function"&&define.amd?define(["exports"],U):(y=typeof globalThis<"u"?globalThis:y||self,U(y.TbwGrid={}))})(this,(function(y){"use strict";const U=':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}}:host .tbw-flip-animating{will-change:transform;z-index:1}:host .tbw-toggle-icon{display:inline-flex;align-items:center;justify-content:center;transition:transform var(--tbw-animation-duration) var(--tbw-animation-easing)}:host .tbw-toggle-icon.tbw-expanded{transform:rotate(90deg)}';function lo(o){const e=new Map;return o._sortState&&e.set(o._sortState.field,{direction:o._sortState.direction===1?"asc":"desc",priority:0}),e}function We(o,e){const t=o._columns,n=lo(o);return{columns:t.map((i,r)=>{const s={field:i.field,order:r,visible:!0},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=n.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})}}function ao(o,e,t,n){if(!e.columns||e.columns.length===0)return;const i=new Map(e.columns.map(l=>[l.field,l])),r=t.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}),o._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&&(o._sortState={field:l.field,direction:l.sort.direction==="asc"?1:-1})}else o._sortState=null;for(const l of n)if(l.applyColumnState)for(const a of e.columns)l.applyColumnState(a.field,a)}function co(o,e,t){let n=null;return()=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{n=null;const i=We(o,e());t(i)},100)}}function $e(o,e,t,n){const i=o.effectiveConfig?.columns??[],r=i.find(l=>l.field===e);return!r||!t&&r.lockVisible||!t&&i.filter(a=>!a.hidden&&a.field!==e).length===0||!!r.hidden===!t?!1:(r.hidden=!t,n.emit("column-visibility",{field:e,visible:t,visibleColumns:i.filter(l=>!l.hidden).map(l=>l.field)}),n.clearRowPool(),n.setup(),n.requestStateChange(),!0)}function uo(o,e,t){const i=(o.effectiveConfig?.columns??[]).find(r=>r.field===e);return i?$e(o,e,!!i.hidden,t):!1}function ho(o,e){const n=(o.effectiveConfig?.columns??[]).find(i=>i.field===e);return n?!n.hidden:!1}function fo(o,e){const t=o.effectiveConfig?.columns??[];t.some(n=>n.hidden)&&(t.forEach(n=>n.hidden=!1),e.emit("column-visibility",{visibleColumns:t.map(n=>n.field)}),e.clearRowPool(),e.setup(),e.requestStateChange())}function po(o){return(o.effectiveConfig?.columns??[]).map(t=>({field:t.field,header:t.header||t.field,visible:!t.hidden,lockVisible:t.lockVisible}))}function go(o){return o._columns.map(e=>e.field)}function wo(o,e,t){if(!e.length)return;const n=new Map(o._columns.map(r=>[r.field,r])),i=[];for(const r of e){const s=n.get(r);s&&(i.push(s),n.delete(r))}for(const r of n.values())i.push(r);o._columns=i,t.renderHeader(),t.updateTemplate(),t.refreshVirtualWindow()}const j={STRETCH:"stretch",FIXED:"fixed"},Ue={mode:"reduced-motion",duration:200,easing:"ease-out"},H={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰"};function mo(o){return o==null?"string":typeof o=="number"?"number":typeof o=="boolean"?"boolean":o instanceof Date||typeof o=="string"&&/\d{4}-\d{2}-\d{2}/.test(o)&&!isNaN(Date.parse(o))?"date":"string"}function je(o,e){if(e&&e.length){const r={};return e.forEach(s=>{s.type&&(r[s.field]=s.type)}),{columns:e,typeMap:r}}const t=o[0]||{},n=Object.keys(t).map(r=>{const s=t[r],l=mo(s);return{field:r,header:r.charAt(0).toUpperCase()+r.slice(1),type:l}}),i={};return n.forEach(r=>{i[r.field]=r.type||"string"}),{columns:n,typeMap:i}}const bo=/{{\s*([^}]+)\s*}}/g,I="__DG_EMPTY__",vo=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,yo=/__(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 Co(o){return!o||typeof o!="string"?"":o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const xo=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"]),Xe=/^on\w+$/i,Eo=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),Ro=/^\s*(javascript|vbscript|data|blob):/i;function se(o){if(!o||typeof o!="string")return"";if(o.indexOf("<")===-1)return o;const e=document.createElement("template");return e.innerHTML=o,_o(e.content),e.innerHTML}function _o(o){const e=[],t=o.querySelectorAll("*");for(const n of t){const i=n.tagName.toLowerCase();if(xo.has(i)){e.push(n);continue}if((i==="svg"||n.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(n.attributes).some(l=>Xe.test(l.name)||l.name==="href"||l.name==="xlink:href")){e.push(n);continue}const r=[];for(const s of n.attributes){const l=s.name.toLowerCase();if(Xe.test(l)){r.push(s.name);continue}if(Eo.has(l)&&Ro.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=>n.removeAttribute(s))}e.forEach(n=>n.remove())}function ve(o,e){if(!o||o.indexOf("{{")===-1)return o;const t=[],n=o.replace(bo,(l,a)=>{const c=So(a,e);return t.push({expr:a.trim(),result:c}),c}),i=Ao(n),r=t.length&&t.every(l=>l.result===""||l.result===I);return/Reflect\.|\bProxy\b|ownKeys\(/.test(o)||r?"":i}function So(o,e){if(o=(o||"").trim(),!o||/\b(Reflect|Proxy|ownKeys)\b/.test(o))return I;if(o==="value")return e.value==null?I:String(e.value);if(o.startsWith("row.")&&!/[()?]/.test(o)&&!o.includes(":")){const n=o.slice(4),i=e.row?e.row[n]:void 0;return i==null?I:String(i)}if(o.length>80||!vo.test(o)||yo.test(o))return I;const t=o.match(/\./g);if(t&&t.length>1)return I;try{const i=new Function("value","row",`return (${o});`)(e.value,e.row),r=i==null?"":String(i);return/Reflect|Proxy|ownKeys/.test(r)?I:r||I}catch{return I}}function Ao(o){return o&&o.replace(new RegExp(I,"g"),"").replace(/Reflect\.[^<>{}\s]+/g,"").replace(/\bProxy\b/g,"").replace(/ownKeys\([^)]*\)/g,"")}function To(o){if(/Reflect|Proxy|ownKeys/.test(o.textContent||"")){if(Array.from(o.childNodes).forEach(e=>{e.nodeType===Node.TEXT_NODE&&/Reflect|Proxy|ownKeys/.test(e.textContent||"")&&(e.textContent="")}),/Reflect|Proxy|ownKeys/.test(o.textContent||"")){if(/Reflect|Proxy|ownKeys/.test(o.textContent||""))for(;o.firstChild;)o.removeChild(o.firstChild);o.textContent=(o.textContent||"").replace(/Reflect|Proxy|ownKeys/g,"")}(o.textContent||"").trim().length===0&&(o.textContent="")}}function Ye(o){const e=/Reflect\.|\bProxy\b|ownKeys\(/.test(o),t=n=>e?"":ve(o,n);return t.__blocked=e,t}function ko(o){return Array.from(o.querySelectorAll("tbw-grid-column")).map(t=>{const n=t.getAttribute("field")||"";if(!n)return null;const i=t.getAttribute("type")||void 0,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:n,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 f=t.getAttribute("editor"),p=t.getAttribute("renderer");f&&(d.__editorName=f),p&&(d.__rendererName=p);const g=t.getAttribute("options");g&&(d.options=g.split(",").map(b=>{const[R,E]=b.includes(":")?b.split(":"):[b.trim(),b.trim()];return{value:R.trim(),label:E?.trim()||R.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 v=globalThis.DataGridElement?.getAdapters?.()??[],S=w??t,k=v.find(b=>b.canHandle(S));if(k){const b=k.createRenderer(S);b&&(d.viewRenderer=b)}const q=m??t,A=v.find(b=>b.canHandle(q));if(A){const b=A.createEditor(q);b&&(d.editor=b)}return d}).filter(t=>!!t)}function Lo(o,e){if((!o||!o.length)&&(!e||!e.length))return[];if(!o||!o.length)return e||[];if(!e||!e.length)return o;const t={};e.forEach(i=>{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 n=o.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=>n.push(t[i])),n}function Ze(o,e){try{o.part?.add?.(e)}catch{}const t=o.getAttribute("part");t?t.split(/\s+/).includes(e)||o.setAttribute("part",t+" "+e):o.setAttribute("part",e)}function Je(o){o.__lightDomColumnsCache||(o.__originalColumnNodes=Array.from(o.querySelectorAll("tbw-grid-column")),o.__lightDomColumnsCache=o.__originalColumnNodes.length?ko(o):[]);const e=o.__lightDomColumnsCache,t=Lo(o._columns,e);t.forEach(i=>{i.__viewTemplate&&!i.__compiledView&&(i.__compiledView=Ye(i.__viewTemplate.innerHTML)),i.__editorTemplate&&!i.__compiledEditor&&(i.__compiledEditor=Ye(i.__editorTemplate.innerHTML))});const{columns:n}=je(o._rows,t);o._columns=n}function Qe(o){const e=o.effectiveConfig?.fitMode||o.fitMode||j.STRETCH;if(e!==j.STRETCH&&e!==j.FIXED||o.__didInitialAutoSize||!o.isConnected)return;const t=o._headerRowEl?.children||[];if(!t.length)return;let n=!1;o._visibleColumns.forEach((i,r)=>{if(i.width)return;const s=t[r];let l=s?s.scrollWidth:0;for(const a of o._rowPool){const c=a.children[r];if(c){const d=c.scrollWidth;d>l&&(l=d)}}l>0&&(i.width=l+2,i.__autoSized=!0,n=!0)}),n&&G(o),o.__didInitialAutoSize=!0}function G(o){(o.effectiveConfig?.fitMode||o.fitMode||j.STRETCH)===j.STRETCH?o._gridTemplate=o._visibleColumns.map(t=>{if(t.width)return`${t.width}px`;const n=t.minWidth;return n!=null?`minmax(${n}px, 1fr)`:"1fr"}).join(" ").trim():o._gridTemplate=o._visibleColumns.map(t=>t.width?`${t.width}px`:"max-content").join(" "),o.style.setProperty("--tbw-column-template",o._gridTemplate)}function Po(o){switch(o.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",n=>{n.key==="Enter"&&e.commit(t.value===""?null:Number(t.value)),n.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",n=>{n.key==="Escape"&&e.cancel()}),t};case"select":case"typeahead":return e=>{const t=document.createElement("select");e.column.multi&&(t.multiple=!0),(typeof e.column.options=="function"?e.column.options():e.column.options||[]).forEach(r=>{const s=document.createElement("option");s.value=String(r.value),s.textContent=r.label,(e.column.multi&&Array.isArray(e.value)&&e.value.includes(r.value)||!e.column.multi&&e.value===r.value)&&(s.selected=!0),t.appendChild(s)});const i=()=>{if(e.column.multi){const r=[];Array.from(t.selectedOptions).forEach(s=>{r.push(s.value)}),e.commit(r)}else e.commit(t.value)};return t.addEventListener("change",i),t.addEventListener("blur",i),t.addEventListener("keydown",r=>{r.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",n=>{n.key==="Enter"&&e.commit(t.value),n.key==="Escape"&&e.cancel()}),t}}}function ye(o){return`<span role="checkbox" aria-checked="${o}" aria-label="${o}">${o?"🗹":"☐"}</span>`}function et(o){if(o==null||o==="")return"";if(o instanceof Date)return isNaN(o.getTime())?"":o.toLocaleDateString();if(typeof o=="number"||typeof o=="string"){const e=new Date(o);return isNaN(e.getTime())?"":e.toLocaleDateString()}return""}function Ce(o){if(!o)return-1;const e=o.getAttribute("data-row");return e?parseInt(e,10):-1}function le(o){if(!o)return-1;const e=o.getAttribute("data-col");return e?parseInt(e,10):-1}function X(o){o&&o.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function Mo(o,e){if(o._dispatchKeyDown?.(e))return;const t=o._rows.length-1,n=o._visibleColumns.length-1,i=o._activeEditRows!==void 0&&o._activeEditRows!==-1,s=o._visibleColumns[o._focusCol]?.type,l=e.composedPath?e.composedPath():[],a=l&&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?o._focusCol<n?o._focusCol+=1:(typeof o.commitActiveRowEdit=="function"&&o.commitActiveRowEdit(),o._focusRow<t&&(o._focusRow+=1,o._focusCol=0)):o._focusCol>0?o._focusCol-=1:o._focusRow>0&&(typeof o.commitActiveRowEdit=="function"&&o._activeEditRows===o._focusRow&&o.commitActiveRowEdit(),o._focusRow-=1,o._focusCol=n),N(o);return}case"ArrowDown":i&&typeof o.commitActiveRowEdit=="function"&&o.commitActiveRowEdit(),o._focusRow=Math.min(t,o._focusRow+1),e.preventDefault();break;case"ArrowUp":i&&typeof o.commitActiveRowEdit=="function"&&o.commitActiveRowEdit(),o._focusRow=Math.max(0,o._focusRow-1),e.preventDefault();break;case"ArrowRight":o._focusCol=Math.min(n,o._focusCol+1),e.preventDefault();break;case"ArrowLeft":o._focusCol=Math.max(0,o._focusCol-1),e.preventDefault();break;case"Home":(e.ctrlKey||e.metaKey)&&(i&&typeof o.commitActiveRowEdit=="function"&&o.commitActiveRowEdit(),o._focusRow=0),o._focusCol=0,e.preventDefault(),N(o,{forceScrollLeft:!0});return;case"End":(e.ctrlKey||e.metaKey)&&(i&&typeof o.commitActiveRowEdit=="function"&&o.commitActiveRowEdit(),o._focusRow=t),o._focusCol=n,e.preventDefault(),N(o,{forceScrollRight:!0});return;case"PageDown":o._focusRow=Math.min(t,o._focusRow+20),e.preventDefault();break;case"PageUp":o._focusRow=Math.max(0,o._focusRow-20),e.preventDefault();break;case"Enter":if(typeof o.beginBulkEdit=="function"){o.beginBulkEdit(o._focusRow);return}else o.dispatchEvent(new CustomEvent("activate-cell",{detail:{row:o._focusRow,col:o._focusCol}}));return N(o);default:return}N(o)}}function N(o,e){if(o._virtualization?.enabled){const{rowHeight:s,container:l,viewportEl:a}=o._virtualization,c=l,d=a?.clientHeight??c?.clientHeight??0;if(c&&d>0){const u=o._focusRow*s;u<c.scrollTop?c.scrollTop=u:u+s>c.scrollTop+d&&(c.scrollTop=u-d+s)}}const t=o._activeEditRows!==void 0&&o._activeEditRows!==-1;t||o.refreshVirtualWindow(!1),X(o._bodyEl),Array.from(o._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(s=>{s.setAttribute("aria-selected","false")});const n=o._focusRow,i=o._virtualization.start??0,r=o._virtualization.end??o._rows.length;if(n>=i&&n<r){const s=o._bodyEl.querySelectorAll(".data-grid-row")[n-i],l=s?.children[o._focusCol];if(l){l.classList.add("cell-focus"),l.setAttribute("aria-selected","true");const a=o.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=o._getHorizontalScrollOffsets?.(s??void 0,l)??{left:0,right:0};if(!c.skipScroll){const d=l.getBoundingClientRect(),u=a.getBoundingClientRect(),h=d.left-u.left+a.scrollLeft,f=h+d.width,p=a.scrollLeft+c.left,g=a.scrollLeft+a.clientWidth-c.right;h<p?a.scrollLeft=h-c.left:f>g&&(a.scrollLeft=f-a.clientWidth+c.right)}}if(o._activeEditRows!==void 0&&o._activeEditRows!==-1&&l.classList.contains("editing")){const c=l.querySelector(W);if(c&&document.activeElement!==c)try{c.focus({preventScroll:!0})}catch{}}else if(!l.contains(document.activeElement)){l.hasAttribute("tabindex")||l.setAttribute("tabindex","-1");try{l.focus({preventScroll:!0})}catch{}}}}}const tt=document.createElement("template");tt.innerHTML='<div class="cell" role="gridcell" part="cell"></div>';const ot=document.createElement("template");ot.innerHTML='<div class="data-grid-row" role="row" part="row"></div>';function Io(){return tt.content.firstElementChild.cloneNode(!0)}function Ho(){return ot.content.firstElementChild.cloneNode(!0)}const Do="__cellDisplayCache",Oo="__cellCacheEpoch";function ae(o){o[Do]=void 0,o[Oo]=void 0,o.__hasSpecialColumns=void 0}function No(o,e,t,n,i){const r=Math.max(0,t-e),s=o._bodyEl,l=o._visibleColumns,a=l.length;let c=o.__cachedHeaderRowCount;for(c===void 0&&(c=o.shadowRoot?.querySelector(".header-group-row")?2:1,o.__cachedHeaderRowCount=c);o._rowPool.length<r;){const u=Ho();u.addEventListener("click",h=>nt(o,h,u,!1)),u.addEventListener("dblclick",h=>nt(o,h,u,!0)),o._rowPool.push(u)}if(o._rowPool.length>r){for(let u=r;u<o._rowPool.length;u++){const h=o._rowPool[u];h.parentNode===s&&h.remove()}o._rowPool.length=r}const d=i&&o.__hasRenderRowPlugins!==!1;for(let u=0;u<r;u++){const h=e+u,f=o._rows[h],p=o._rowPool[u];if(p.setAttribute("aria-rowindex",String(h+c+1)),d&&i(f,p,h)){p.__epoch=n,p.__rowDataRef=f,p.parentNode!==s&&s.appendChild(p);continue}const g=p.__epoch,w=p.__rowDataRef,m=p.children.length,x=g===n&&m===a,v=w!==f;let S=!1;if(x&&v){for(let A=0;A<a;A++)if(l[A].externalView&&!p.querySelector(`.cell[data-col="${A}"] [data-external-view]`)){S=!0;break}}if(!x||S){const A=fe(p),b=o._activeEditRows===h;if(A&&!b)p.__isCustomRow&&(p.className="data-grid-row",p.setAttribute("role","row"),p.__isCustomRow=!1),pe(p),Y(o,p,f,h),p.__epoch=n,p.__rowDataRef=f;else if(A&&b)xe(o,p,f,h),p.__rowDataRef=f;else if(p.__isCustomRow&&(p.className="data-grid-row",p.setAttribute("role","row"),p.__isCustomRow=!1),Y(o,p,f,h),p.__epoch=n,p.__rowDataRef=f,b){const R=p.children;for(let E=0;E<R.length;E++){const _=o._visibleColumns[E];_&&_.editable&&D(o,f,h,_,R[E],!0)}}}else if(v){const A=fe(p),b=o._activeEditRows===h;if(A&&!b)pe(p),Y(o,p,f,h),p.__epoch=n,p.__rowDataRef=f;else if(xe(o,p,f,h),p.__rowDataRef=f,b&&!A){const R=p.children;for(let E=0;E<R.length;E++){const _=o._visibleColumns[E];_&&_.editable&&D(o,f,h,_,R[E],!0)}}}else{const A=fe(p),b=o._activeEditRows===h;if(A&&!b)pe(p),Y(o,p,f,h),p.__epoch=n,p.__rowDataRef=f;else if(xe(o,p,f,h),b&&!A){const R=p.children;for(let E=0;E<R.length;E++){const _=o._visibleColumns[E];_&&_.editable&&D(o,f,h,_,R[E],!0)}}}const k=o._changedRowIndices.has(h),q=p.classList.contains("changed");k!==q&&p.classList.toggle("changed",k),p.parentNode!==s&&s.appendChild(p)}}function xe(o,e,t,n){const i=e.children,r=o._visibleColumns,s=r.length,l=i.length,a=s<l?s:l,c=o._focusRow,d=o._focusCol;let u=o.__hasSpecialColumns;if(u===void 0){u=!1;for(let f=0;f<s;f++){const p=r[f];if(p.__viewTemplate||p.__compiledView||p.renderer||p.viewRenderer||p.externalView||p.format||p.type==="date"||p.type==="boolean"){u=!0;break}}o.__hasSpecialColumns=u}const h=String(n);if(!u){for(let f=0;f<a;f++){const p=i[f],g=t[r[f].field];p.textContent=g==null?"":String(g),p.getAttribute("data-row")!==h&&p.setAttribute("data-row",h);const w=c===n&&d===f,m=p.classList.contains("cell-focus");w!==m&&(p.classList.toggle("cell-focus",w),p.setAttribute("aria-selected",String(w)))}return}for(let f=0;f<a;f++)if(r[f].externalView&&!i[f].querySelector("[data-external-view]")){Y(o,e,t,n);return}for(let f=0;f<a;f++){const p=r[f],g=i[f];g.getAttribute("data-row")!==h&&g.setAttribute("data-row",h);const w=c===n&&d===f,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=p.renderer||p.viewRenderer;if(C){const S=t[p.field],k=C({row:t,value:S,field:p.field,column:p,cellEl:g});typeof k=="string"?g.innerHTML=se(k):k?k.parentElement!==g&&(g.innerHTML="",g.appendChild(k)):g.textContent=S==null?"":String(S);continue}if(p.__viewTemplate||p.__compiledView||p.externalView)continue;const x=t[p.field];let v;if(p.format)try{const S=p.format(x,t);v=S==null?"":String(S)}catch{v=x==null?"":String(x)}else p.type==="date"?(v=et(x),g.textContent=v):p.type==="boolean"?g.innerHTML=ye(!!x):(v=x==null?"":String(x),g.textContent=v)}}function Y(o,e,t,n){e.innerHTML="";const i=o._visibleColumns,r=i.length,s=o._focusRow,l=o._focusCol;o.effectiveConfig?.editOn||o.editOn;const a=o,c=document.createDocumentFragment();for(let d=0;d<r;d++){const u=i[d],h=Io();h.setAttribute("aria-colindex",String(d+1)),h.setAttribute("data-col",String(d)),h.setAttribute("data-row",String(n)),h.setAttribute("data-field",u.field),u.type,u.type&&h.setAttribute("data-type",u.type);let f=t[u.field];const p=u.format;if(p)try{f=p(f,t)}catch{}const g=u.__compiledView,w=u.__viewTemplate,m=u.renderer||u.viewRenderer,C=u.externalView;let x=!1;if(m){const v=m({row:t,value:f,field:u.field,column:u,cellEl:h});typeof v=="string"?(h.innerHTML=se(v),x=!0):v?v.parentElement!==h&&(h.textContent="",h.appendChild(v)):h.textContent=f==null?"":String(f)}else if(C){const v=C,S=document.createElement("div");S.setAttribute("data-external-view",""),S.setAttribute("data-field",u.field),h.appendChild(S);const k={row:t,value:f,field:u.field,column:u};if(v.mount)try{v.mount({placeholder:S,context:k,spec:v})}catch{}else queueMicrotask(()=>{try{a.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:S,spec:v,context:k}}))}catch{}});S.setAttribute("data-mounted","")}else if(g){const v=g({row:t,value:f,field:u.field,column:u}),S=g.__blocked;h.innerHTML=S?"":se(v),x=!0,S&&(h.textContent="",h.setAttribute("data-blocked-template",""))}else if(w){const v=w.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(v)?(h.textContent="",h.setAttribute("data-blocked-template","")):(h.innerHTML=se(ve(v,{row:t,value:f})),x=!0)}else u.type==="date"?h.textContent=et(f):u.type==="boolean"?h.innerHTML=ye(!!f):h.textContent=f==null?"":String(f);if(x){To(h);const v=h.textContent||"";/Proxy|Reflect\.ownKeys/.test(v)&&(h.textContent=v.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===n&&l===d?(h.classList.add("cell-focus"),h.setAttribute("aria-selected","true")):h.setAttribute("aria-selected","false"),c.appendChild(h)}e.appendChild(c)}function nt(o,e,t,n){if(e.target?.closest(".resize-handle"))return;const i=t.querySelector(".cell[data-row]"),r=Ce(i);if(r<0)return;const s=o._rows[r];if(!s||o._dispatchRowClick?.(e,r,s,t))return;const l=e.target?.closest(".cell[data-col]");if(l){const u=Number(l.getAttribute("data-col"));if(!isNaN(u)){if(o._dispatchCellClick?.(e,r,u,l))return;const h=o._focusRow!==r||o._focusCol!==u;if(o._focusRow=r,o._focusCol=u,l.classList.contains("editing")){h&&(X(o.shadowRoot??o._bodyEl),l.classList.add("cell-focus"));return}N(o)}}if(o._activeEditRows===r){l&&(X(o.shadowRoot??o._bodyEl),l.classList.add("cell-focus"),queueMicrotask(()=>{const u=Number(l.getAttribute("data-col")),h=o._visibleColumns[u];if(h&&h.editable&&l.classList.contains("editing")){const f=l.querySelector(W);try{f?.focus({preventScroll:!0})}catch{}}}));return}if(fe(t)){if(!n)return;const u=t.children;for(let h=0;h<u.length;h++)u[h].classList.remove("editing");pe(t)}const c=o.effectiveConfig?.editOn??o.editOn??"dblClick";if(c===!1)return;const d=c==="dblclick"?"dblClick":c;if(d==="click"||d==="dblClick"&&n){if(typeof o.beginBulkEdit=="function"){o.beginBulkEdit(r);return}Z(o,r,s)}else return;Array.from(t.children).forEach((u,h)=>{const f=o._visibleColumns[h];f&&f.editable&&D(o,s,r,f,u,!0)}),l&&queueMicrotask(()=>{const u=t.querySelector(`.cell[data-col="${o._focusCol}"]`);if(u?.classList.contains("editing")){const h=u.querySelector(W);try{h?.focus({preventScroll:!0})}catch{}}})}const W='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function Ee(o){return!(o==="__proto__"||o==="constructor"||o==="prototype")}function fe(o){return(o.__editingCellCount??0)>0}function Fo(o){const e=(o.__editingCellCount??0)+1;o.__editingCellCount=e,o.setAttribute("data-has-editing","")}function pe(o){o.__editingCellCount=0,o.removeAttribute("data-has-editing")}function qo(o,e,t,n,i){const r=o.querySelector("input,textarea,select");if(!r)return;const s=()=>{if(r instanceof HTMLInputElement){if(r.type==="checkbox")return r.checked;if(r.type==="number")return r.value===""?null:Number(r.value);if(r.type==="date")return r.valueAsDate}return e.type==="number"&&r.value!==""?Number(r.value):r.value};r.addEventListener("blur",()=>{t(s())}),r instanceof HTMLInputElement&&r.type==="checkbox"?r.addEventListener("change",()=>t(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>t(s()))}function Z(o,e,t){o._activeEditRows!==e&&(o._rowEditSnapshots.set(e,{...t}),o._activeEditRows=e)}function B(o,e,t){if(o._activeEditRows!==e)return;const n=o._rowEditSnapshots.get(e),i=o._rows[e],r=o.findRenderedRowElement?.(e);if(!t&&r&&i&&r.querySelectorAll(".cell.editing").forEach(l=>{const a=Number(l.getAttribute("data-col"));if(isNaN(a))return;const c=o._visibleColumns[a];if(!c)return;const d=l.querySelector("input,textarea,select");if(d){let u;d instanceof HTMLInputElement&&d.type==="checkbox"?u=d.checked:(u=d.value,c.type==="number"&&u!==""&&(u=Number(u))),i[c.field]!==u&&Re(o,e,c,u,i)}}),t&&n&&i)Object.keys(n).forEach(s=>i[s]=n[s]),o._changedRowIndices.delete(e),ae(o);else if(!t){const s=o._changedRowIndices.has(e);o.dispatchEvent(new CustomEvent("row-commit",{detail:{rowIndex:e,row:i,changed:s,changedRows:o.changedRows,changedRowIndices:o.changedRowIndices}}))}o._rowEditSnapshots.delete(e),o._activeEditRows=-1,r&&(Y(o,r,o._rows[e],e),o._changedRowIndices.has(e)?r.classList.add("changed"):r.classList.remove("changed")),queueMicrotask(()=>{try{const s=o._focusRow,l=o._focusCol,a=o.findRenderedRowElement?.(s);if(a){Array.from(o._bodyEl.querySelectorAll(".cell-focus")).forEach(d=>d.classList.remove("cell-focus"));const c=a.querySelector(`.cell[data-row="${s}"][data-col="${l}"]`);c&&(c.classList.add("cell-focus"),c.setAttribute("aria-selected","true"),c.hasAttribute("tabindex")||c.setAttribute("tabindex","-1"),c.focus({preventScroll:!0}))}}catch{}})}function Re(o,e,t,n,i){const r=t.field;if(!Ee(r)||i[r]===n)return;i[r]=n;const l=!o._changedRowIndices.has(e);o._changedRowIndices.add(e);const a=o.findRenderedRowElement?.(e);a&&a.classList.add("changed"),o.dispatchEvent(new CustomEvent("cell-commit",{detail:{row:i,field:r,value:n,rowIndex:e,changedRows:o.changedRows,changedRowIndices:o.changedRowIndices,firstTimeForRow:l}}))}function D(o,e,t,n,i,r=!1){if(!n.editable||(o._activeEditRows!==t&&Z(o,t,e),i.classList.contains("editing")))return;const s=Ee(n.field)?e[n.field]:void 0;i.classList.add("editing");const l=i.parentElement;l&&Fo(l);let a=!1;const c=g=>{a||o._activeEditRows===-1||Re(o,t,n,g,e)},d=()=>{a=!0,e[n.field]=Ee(n.field)?s:void 0;const g=i.querySelector("input,textarea,select");g&&(typeof HTMLInputElement<"u"&&g instanceof HTMLInputElement&&g.type==="checkbox"?g.checked=!!s:"value"in g&&(g.value=s??""))},u=document.createElement("div");u.style.display="contents",i.innerHTML="",i.appendChild(u),u.addEventListener("keydown",g=>{g.key==="Enter"&&(g.stopPropagation(),g.preventDefault(),a=!0,B(o,t,!1)),g.key==="Escape"&&(g.stopPropagation(),g.preventDefault(),d(),B(o,t,!0))});const h=n.__editorTemplate,f=n.editor||(h?"template":Po(n)),p=s;if(f==="template"&&h){const g=h.cloneNode(!0),w=n.__compiledEditor;w?g.innerHTML=w({row:e,value:s,field:n.field,column:n}):g.querySelectorAll("*").forEach(C=>{C.childNodes.length===1&&C.firstChild?.nodeType===Node.TEXT_NODE&&(C.textContent=C.textContent?.replace(/{{\s*value\s*}}/g,s==null?"":String(s)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(x,v)=>{const S=e[v];return S==null?"":String(S)})||"")});const m=g.querySelector("input,textarea,select");if(m){const C=typeof HTMLInputElement<"u";C&&m instanceof HTMLInputElement&&m.type==="checkbox"?m.checked=!!s:"value"in m&&(m.value=s??""),m.addEventListener("blur",()=>{const x=C&&m instanceof HTMLInputElement&&m.type==="checkbox"?m.checked:m.value;c(x)}),m.addEventListener("keydown",x=>{if(x.key==="Enter"){x.stopPropagation(),x.preventDefault(),a=!0;const v=C&&m instanceof HTMLInputElement&&m.type==="checkbox"?m.checked:m.value;c(v),B(o,t,!1)}x.key==="Escape"&&(x.stopPropagation(),x.preventDefault(),d(),B(o,t,!0))}),C&&m instanceof HTMLInputElement&&m.type==="checkbox"&&m.addEventListener("change",()=>{const x=m.checked;c(x)}),r||setTimeout(()=>m.focus({preventScroll:!0}),0)}u.appendChild(g)}else if(typeof f=="string"){const g=document.createElement(f);g.value=p,g.addEventListener("change",()=>c(g.value)),u.appendChild(g),r||queueMicrotask(()=>{u.querySelector(W)?.focus({preventScroll:!0})})}else if(typeof f=="function"){const g=f({row:e,value:p,field:n.field,column:n,commit:c,cancel:d});typeof g=="string"?(u.innerHTML=g,qo(u,n,c)):u.appendChild(g),r||queueMicrotask(()=>{u.querySelector(W)?.focus({preventScroll:!0})})}else if(f&&typeof f=="object"){const g=document.createElement("div");g.setAttribute("data-external-editor",""),g.setAttribute("data-field",n.field),u.appendChild(g);const w={row:e,value:p,field:n.field,column:n,commit:c,cancel:d};if(f.mount)try{f.mount({placeholder:g,context:w,spec:f})}catch{}else o.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:g,spec:f,context:w}}))}}function zo(o,e,t){o.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0}))}function it(o){return Array.from(o._changedRowIndices).map(e=>o._rows[e])}function rt(o){return Array.from(o._changedRowIndices)}function Bo(o,e){o._changedRowIndices.clear(),e||zo(o,"changed-rows-reset",{rows:it(o),indices:rt(o)}),o._rowPool.forEach(t=>t.classList.remove("changed"))}function Vo(o,e,t){if(o.effectiveConfig?.editOn===!1||!o._columns.some(s=>s.editable))return;const i=o._rows[e];Z(o,e,i);const r=t.findRenderedRowElement(e);r&&(Array.from(r.children).forEach((s,l)=>{const a=o._visibleColumns[l];if(a?.editable){const c=s;c.classList.contains("editing")||D(o,i,e,a,c,!0)}}),setTimeout(()=>{let s=r.querySelector(`.cell[data-col="${o._focusCol}"]`);if(s?.classList.contains("editing")||(s=r.querySelector(".cell.editing")),s?.classList.contains("editing")){const l=s.querySelector(W);try{l?.focus({preventScroll:!0})}catch{}}},0))}function Ko(o){o._activeEditRows!==-1&&B(o,o._activeEditRows,!1)}function Go(o){o._activeEditRows!==-1&&B(o,o._activeEditRows,!0)}function ge(o,e){const t=Ce(e),n=le(e);if(t<0||n<0)return null;const i=o._rows[t],r=o._visibleColumns[n];return!i||!r?null:{rowIndex:t,colIndex:n,rowData:i,col:r}}function Wo(o,e){if(e.classList.contains("editing"))return;const t=ge(o,e);t&&(o._focusRow=t.rowIndex,o._focusCol=t.colIndex,N(o))}function $o(o,e,t){if(e.classList.contains("editing"))return;const n=ge(o,e);n&&(t.stopPropagation(),o._focusRow=n.rowIndex,o._focusCol=n.colIndex,D(o,n.rowData,n.rowIndex,n.col,e))}function Uo(o,e,t){t.stopPropagation();const n=ge(o,e);if(!n)return;if(typeof o.beginBulkEdit=="function"){o._focusRow=n.rowIndex,o._focusCol=n.colIndex,o.beginBulkEdit(n.rowIndex);return}Z(o,n.rowIndex,n.rowData);const i=o.findRenderedRowElement?.(n.rowIndex);if(i){const r=i.children;for(let s=0;s<r.length;s++){const l=o._visibleColumns[s];l&&l.editable&&D(o,n.rowData,n.rowIndex,l,r[s],!0)}queueMicrotask(()=>{const s=i.querySelector(`.cell[data-col="${o._focusCol}"]`);if(s?.classList.contains("editing")){const l=s.querySelector(W);try{l?.focus({preventScroll:!0})}catch{}}})}}function jo(o,e,t){const n=ge(o,e);if(!n)return;const{rowIndex:i,colIndex:r,rowData:s,col:l}=n,a=e.classList.contains("editing");if((l.type==="select"||l.type==="typeahead")&&!a&&t.key==="Enter"){t.preventDefault(),o._activeEditRows!==i&&Z(o,i,s),D(o,s,i,l,e),setTimeout(()=>{const c=e.querySelector("select");try{c?.showPicker?.()}catch{}c?.focus({preventScroll:!0})},0);return}if(l.type==="boolean"&&t.key===" "&&!a){t.preventDefault(),o._activeEditRows!==i&&Z(o,i,s);const c=!s[l.field];Re(o,i,l,c,s),e.innerHTML=ye(!!c);return}if(t.key==="Enter"&&!a){t.preventDefault(),t.stopPropagation(),o._focusRow=i,o._focusCol=r,typeof o.beginBulkEdit=="function"?o.beginBulkEdit(i):D(o,s,i,l,e);return}if(t.key==="F2"&&!a){t.preventDefault(),D(o,s,i,l,e);return}}function Xo(o,e,t){const n=()=>o.effectiveConfig?.editOn||o.editOn;e.addEventListener("mousedown",i=>{const r=i.target.closest(".cell[data-col]");if(!r)return;const s=le(r);if(s<0)return;const l=o._visibleColumns[s];l&&l.editable&&Wo(o,r)},{signal:t}),e.addEventListener("click",i=>{if(n()!=="click")return;const s=i.target.closest(".cell[data-col]");if(!s)return;const l=le(s);if(l<0)return;const a=o._visibleColumns[l];a&&a.editable&&$o(o,s,i)},{signal:t}),e.addEventListener("dblclick",i=>{const r=n();if((r==="dblclick"?"dblClick":r)==="click"||r===!1)return;const l=i.target.closest(".cell[data-col]");if(!l)return;const a=le(l);if(a<0)return;const c=o._visibleColumns[a];c&&c.editable&&Uo(o,l,i)},{signal:t}),e.addEventListener("keydown",i=>{const r=i.target.closest(".cell[data-col]");if(!r)return;const s=le(r);if(s<0)return;const l=o._visibleColumns[s];l&&l.editable&&jo(o,r,i)},{signal:t})}function st(o,e){return o==null&&e==null?0:o==null?-1:e==null||o>e?1:o<e?-1:0}function lt(o,e,t){const i=t.find(l=>l.field===e.field)?.sortComparator??st,{field:r,direction:s}=e;return[...o].sort((l,a)=>i(l[r],a[r],l,a)*s)}function at(o,e,t,n){o._rows=e,o.__rowRenderEpoch++,o._rowPool.forEach(i=>i.__epoch=-1),J(o),o.refreshVirtualWindow(!0),o.dispatchEvent(new CustomEvent("sort-change",{detail:{field:t.field,direction:n}})),o.requestStateChange?.()}function ct(o,e){!o._sortState||o._sortState.field!==e.field?(o._sortState||(o.__originalOrder=o._rows.slice()),dt(o,e,1)):o._sortState.direction===1?dt(o,e,-1):(o._sortState=null,o.__rowRenderEpoch++,o._rowPool.forEach(n=>n.__epoch=-1),o._rows=o.__originalOrder.slice(),J(o),o._headerRowEl?.querySelectorAll('[role="columnheader"].sortable')?.forEach(n=>{n.getAttribute("aria-sort")?(n.getAttribute("aria-sort")==="ascending"||n.getAttribute("aria-sort")==="descending")&&(o._sortState||n.setAttribute("aria-sort","none")):n.setAttribute("aria-sort","none")}),o.refreshVirtualWindow(!0),o.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:0}})),o.requestStateChange?.())}function dt(o,e,t){o._sortState={field:e.field,direction:t};const n={field:e.field,direction:t},i=o._columns,s=(o.effectiveConfig?.sortHandler??lt)(o._rows,n,i);s&&typeof s.then=="function"?s.then(l=>{at(o,l,e,t)}):at(o,s,e,t)}function Yo(o,e){typeof e=="string"?o.textContent=e:e instanceof HTMLElement&&(o.innerHTML="",o.appendChild(e.cloneNode(!0)))}function J(o){o._headerRowEl=o.findHeaderRow();const e=o._headerRowEl;e.innerHTML="",o._visibleColumns.forEach((t,n)=>{const i=document.createElement("div");i.className="cell",Ze(i,"header-cell"),i.setAttribute("role","columnheader"),i.setAttribute("aria-colindex",String(n+1)),i.setAttribute("data-field",t.field),i.setAttribute("data-col",String(n));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");Ze(s,"sort-indicator");const l=o._sortState?.field===t.field?o._sortState.direction:0,a={...H,...o.icons},c=l===1?a.sortAsc:l===-1?a.sortDesc:a.sortNone;Yo(s,c),i.appendChild(s),i.setAttribute("aria-sort",l===0?"none":l===1?"ascending":"descending"),i.addEventListener("click",d=>{o._resizeController?.isResizing||o._dispatchHeaderClick?.(d,n,i)||ct(o,t)}),i.addEventListener("keydown",d=>{if(d.key==="Enter"||d.key===" "){if(d.preventDefault(),o._dispatchHeaderClick?.(d,n,i))return;ct(o,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(),o._resizeController.start(l,n,i)}),s.addEventListener("dblclick",l=>{l.stopPropagation(),l.preventDefault(),o._resizeController.resetColumn(n)}),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 ut=typeof requestIdleCallback=="function";function Zo(o,e){return ut?requestIdleCallback(o,e):window.setTimeout(()=>{const t=Date.now();o({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})},1)}function ht(o){ut?cancelIdleCallback(o):clearTimeout(o)}function Jo(o){let e=null,t=null,n=null,i=null;const r=a=>{if(!e)return;const c=a.clientX-e.startX,d=Math.max(40,e.startWidth+c),u=o._visibleColumns[e.colIndex];u.width=d,u.__userResized=!0,u.__renderedWidth=d,t==null&&(t=requestAnimationFrame(()=>{t=null,o.updateTemplate?.()})),o.dispatchEvent(new CustomEvent("column-resize",{detail:{field:u.field,width:d}}))};let s=!1;const l=()=>{const a=e!==null;a&&(s=!0,requestAnimationFrame(()=>{s=!1})),window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",l),n!==null&&(document.documentElement.style.cursor=n,n=null),i!==null&&(document.body.style.userSelect=i,i=null),e=null,a&&o.requestStateChange&&o.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),n===null&&(n=document.documentElement.style.cursor),document.documentElement.style.cursor="e-resize",i===null&&(i=document.body.style.userSelect),document.body.style.userSelect="none"},resetColumn(a){const c=o._visibleColumns[a];c&&(c.__userResized=!1,c.__renderedWidth=void 0,c.width=c.__originalWidth,o.updateTemplate?.(),o.requestStateChange?.(),o.dispatchEvent(new CustomEvent("column-resize-reset",{detail:{field:c.field,width:c.width}})))},dispose(){l()}}}function we(o,e,t){const n=document.createElement(o);if(e)for(const i in e){const r=e[i];r!=null&&n.setAttribute(i,r)}return n}function M(o,e){const t=document.createElement("div");if(o&&(t.className=o),e)for(const n in e){const i=e[n];i!=null&&t.setAttribute(n,i)}return t}function ft(o,e,t){const n=document.createElement("button");if(o&&(n.className=o),e)for(const i in e){const r=e[i];r!=null&&n.setAttribute(i,r)}return n}function pt(o){const e=document.createElement("slot");return o&&(e.name=o),e}const gt=document.createElement("template");gt.innerHTML=`
|
|
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=`
|
|
2
2
|
<div class="tbw-scroll-area">
|
|
3
3
|
<div class="rows-body-wrapper">
|
|
4
4
|
<div class="rows-body" role="grid">
|
|
@@ -16,36 +16,48 @@
|
|
|
16
16
|
<div class="faux-vscroll">
|
|
17
17
|
<div class="faux-vscroll-spacer"></div>
|
|
18
18
|
</div>
|
|
19
|
-
`;function
|
|
19
|
+
`;function at(){return lt.content.cloneNode(!0)}function ct(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(at()),t.appendChild(o)}return e.appendChild(t),e}function Ho(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(st("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(st("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=rt(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 Mo(n){const e=H("tbw-shell-body"),t=n.panels.length>0,o=n.panels.length===1,i=H("tbw-grid-content");i.appendChild(at());let r=null;if(t){r=de("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=rt("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=de("span",{class:"tbw-accordion-icon"});f.innerHTML=c.icon,h.appendChild(f)}const p=de("span",{class:"tbw-accordion-title"});if(p.textContent=c.title,h.appendChild(p),!o){const f=de("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 Io(){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 dt(n){return!!(n?.header?.title||n?.header?.toolbarButtons?.length||n?.toolPanels?.length||n?.headerContents?.length||n?.header?.lightDomContent?.length||n?.header?.hasToolButtonsContainer)}function ut(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">${uo(o)}</div>`:""}
|
|
22
22
|
<div class="tbw-shell-content" part="shell-content" role="presentation">
|
|
23
23
|
<slot name="header-content"></slot>
|
|
24
24
|
</div>
|
|
25
25
|
<div class="tbw-shell-toolbar" part="shell-toolbar" role="presentation">
|
|
26
|
-
${
|
|
26
|
+
${f}
|
|
27
27
|
</div>
|
|
28
28
|
</div>
|
|
29
|
-
`}function Q(o,e){const t=o.querySelector("tbw-grid-header");if(!t)return;if(!e.lightDomTitle){const i=t.getAttribute("title");i&&(e.lightDomTitle=i)}const n=t.querySelectorAll("tbw-grid-header-content");n.length>0&&e.lightDomHeaderContent.length===0&&(e.lightDomHeaderContent=Array.from(n),e.lightDomHeaderContent.forEach(i=>{i.setAttribute("slot","header-content")})),t.style.display="none"}function ee(o,e){const t=o.querySelector(":scope > tbw-grid-tool-buttons");t&&(e.hasToolButtonsContainer=!0,t.setAttribute("slot","toolbar"))}function te(o,e,t){o.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 f=e.toolPanels.get(s);if(f){if(h){f.render=u,f.order=d,f.icon=a,f.tooltip=c;const g=e.panelCleanups.get(s);g&&(g(),e.panelCleanups.delete(s))}return}const p={id:s,title:l,icon:a,tooltip:c,order:d,render:u};e.toolPanels.set(s,p),e.lightDomToolPanelIds.add(s),r.style.display="none"})}function on(o,e,t,n){const i=o.querySelector(".tbw-shell-toolbar");i&&i.addEventListener("click",s=>{const l=s.target;if(l.closest("[data-panel-toggle]")){n.onPanelToggle();return}const c=l.closest("[data-btn]");if(c){const d=c.getAttribute("data-btn");d&&n.onToolbarButtonClick(d)}});const r=o.querySelector(".tbw-accordion");r&&r.addEventListener("click",s=>{const a=s.target.closest(".tbw-accordion-header");if(a){const d=a.closest("[data-section]")?.getAttribute("data-section");d&&n.onSectionToggle(d)}})}function nn(o,e,t){const n=o.querySelector(".tbw-tool-panel"),i=o.querySelector("[data-resize-handle]"),r=o.querySelector(".tbw-shell-body");if(!n||!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));n.style.width=`${m}px`},f=()=>{if(!u)return;u=!1,i.classList.remove("resizing"),n.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const g=n.getBoundingClientRect().width;t(g),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",f)},p=g=>{g.preventDefault(),u=!0,a=g.clientX,c=n.getBoundingClientRect().width,d=r.getBoundingClientRect().width-20,i.classList.add("resizing"),n.style.transition="none",document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",h),document.addEventListener("mouseup",f)};return i.addEventListener("mousedown",p),()=>{i.removeEventListener("mousedown",p),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",f)}}function rn(o,e,t){const n=[...e?.header?.toolbarButtons??[],...t.toolbarButtons.values()];for(const i of n){const r=o.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 yt(o,e){const t=o.querySelector(".tbw-shell-content");if(!t)return;const n=[...e.headerContents.values()].sort((r,s)=>(r.order??100)-(s.order??100)),i=t.querySelector('slot[name="header-content"]');for(const r of n){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 sn(o,e,t){if(!e.isPanelOpen)return;const n=$(t?.expand??H.expand),i=$(t?.collapse??H.collapse);for(const[r,s]of e.toolPanels){const l=e.expandedSections.has(r),a=o.querySelector(`[data-section="${r}"]`),c=a?.querySelector(".tbw-accordion-content");if(!a||!c)continue;a.classList.toggle("expanded",l);const d=a.querySelector(".tbw-accordion-header");d&&d.setAttribute("aria-expanded",String(l));const u=a.querySelector(".tbw-accordion-chevron");if(u&&(u.innerHTML=l?i:n),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 Ct(o,e){const t=o.querySelector("[data-panel-toggle]");t&&(t.classList.toggle("active",e.isPanelOpen),t.setAttribute("aria-pressed",String(e.isPanelOpen)))}function xt(o,e){const t=o.querySelector(".tbw-tool-panel");t&&(t.classList.toggle("open",e.isPanelOpen),e.isPanelOpen||(t.style.width=""))}function ln(o,e){const t=[];for(const n of o?.header?.toolbarButtons??[])t.push({id:n.id,label:n.label??"",source:"config"});for(const n of e.toolbarButtons.values())t.push({id:n.id,label:n.label??"",source:"config"});for(const n of e.toolPanels.values())t.push({id:`panel-toggle-${n.id}`,label:n.tooltip??n.title,source:"panel-toggle",panelId:n.id});return t}function an(o){for(const e of o.headerContentCleanups.values())e();o.headerContentCleanups.clear();for(const e of o.panelCleanups.values())e();o.panelCleanups.clear();for(const e of o.toolbarButtonCleanups.values())e();if(o.toolbarButtonCleanups.clear(),o.isPanelOpen)for(const e of o.expandedSections)o.toolPanels.get(e)?.onClose?.();o.isPanelOpen=!1,o.expandedSections.clear(),o.toolPanels.clear(),o.headerContents.clear(),o.toolbarButtons.clear(),o.lightDomHeaderContent=[]}function cn(o,e){let t=!1;const n={get isInitialized(){return t},setInitialized(i){t=i},get isPanelOpen(){return o.isPanelOpen},get activePanel(){return o.isPanelOpen&&o.expandedSections.size>0?[...o.expandedSections][0]:null},get expandedSections(){return[...o.expandedSections]},openToolPanel(){if(o.isPanelOpen)return;if(o.toolPanels.size===0){console.warn("[tbw-grid] No tool panels registered");return}if(o.isPanelOpen=!0,o.expandedSections.size===0&&o.toolPanels.size>0){const s=[...o.toolPanels.values()].sort((l,a)=>(l.order??100)-(a.order??100))[0];s&&o.expandedSections.add(s.id)}const i=e.getShadow();Ct(i,o),xt(i,o),sn(i,o,e.getAccordionIcons()),e.emit("tool-panel-open",{sections:n.expandedSections})},closeToolPanel(){if(!o.isPanelOpen)return;for(const r of o.panelCleanups.values())r();o.panelCleanups.clear();for(const r of o.toolPanels.values())r.onClose?.();o.isPanelOpen=!1;const i=e.getShadow();Ct(i,o),xt(i,o),e.emit("tool-panel-close",{})},toggleToolPanel(){o.isPanelOpen?n.closeToolPanel():n.openToolPanel()},toggleToolPanelSection(i){const r=o.toolPanels.get(i);if(!r){console.warn(`[tbw-grid] Tool panel section "${i}" not found`);return}if(o.toolPanels.size===1)return;const s=e.getShadow(),l=o.expandedSections.has(i);if(l){const a=o.panelCleanups.get(i);a&&(a(),o.panelCleanups.delete(i)),r.onClose?.(),o.expandedSections.delete(i),_e(s,i,!1)}else{for(const[a,c]of o.toolPanels)if(a!==i&&o.expandedSections.has(a)){const d=o.panelCleanups.get(a);d&&(d(),o.panelCleanups.delete(a)),c.onClose?.(),o.expandedSections.delete(a),_e(s,a,!1);const u=s.querySelector(`[data-section="${a}"] .tbw-accordion-content`);u&&(u.innerHTML="")}o.expandedSections.add(i),_e(s,i,!0),dn(s,o,i)}e.emit("tool-panel-section-toggle",{id:i,expanded:!l})},getToolPanels(){return[...o.toolPanels.values()]},registerToolPanel(i){if(o.toolPanels.has(i.id)){console.warn(`[tbw-grid] Tool panel "${i.id}" already registered`);return}o.toolPanels.set(i.id,i),t&&e.refreshShellHeader()},unregisterToolPanel(i){if(o.expandedSections.has(i)){const r=o.panelCleanups.get(i);r&&(r(),o.panelCleanups.delete(i)),o.expandedSections.delete(i)}o.toolPanels.delete(i),t&&e.refreshShellHeader()},getHeaderContents(){return[...o.headerContents.values()]},registerHeaderContent(i){if(o.headerContents.has(i.id)){console.warn(`[tbw-grid] Header content "${i.id}" already registered`);return}o.headerContents.set(i.id,i),t&&yt(e.getShadow(),o)},unregisterHeaderContent(i){const r=o.headerContentCleanups.get(i);r&&(r(),o.headerContentCleanups.delete(i)),o.headerContents.get(i)?.onDestroy?.(),o.headerContents.delete(i),e.getShadow().querySelector(`[data-header-content="${i}"]`)?.remove()},getToolbarButtons(){return ln(e.getShellConfig(),o)},registerToolbarButton(i){if(o.toolbarButtons.has(i.id)){console.warn(`[tbw-grid] Toolbar button "${i.id}" already registered`);return}o.toolbarButtons.set(i.id,i),t&&e.refreshShellHeader()},unregisterToolbarButton(i){const r=o.toolbarButtonCleanups.get(i);r&&(r(),o.toolbarButtonCleanups.delete(i)),o.toolbarButtons.delete(i),t&&e.refreshShellHeader()},setToolbarButtonDisabled(i,r){}};return n}function _e(o,e,t){const n=o.querySelector(`[data-section="${e}"]`);n&&n.classList.toggle("expanded",t)}function dn(o,e,t){const n=e.toolPanels.get(t);if(!n?.render)return;const i=o.querySelector(`[data-section="${t}"] .tbw-accordion-content`);if(!i)return;const r=n.render(i);r&&e.panelCleanups.set(t,r)}function un(o,e,t,n){const i=bt(e,t);if(o.replaceChildren(),i){const r=$(n?.toolPanel??H.toolPanel),s=$(n?.expand??H.expand),l=$(n?.collapse??H.collapse),c=[...e?.header?.toolbarButtons??[]].sort((m,C)=>(m.order??100)-(C.order??100)),d=[...t.toolbarButtons.values()].sort((m,C)=>(m.order??100)-(C.order??100)),u={title:e?.header?.title??t.lightDomTitle??void 0,hasPanels:t.toolPanels.size>0,isPanelOpen:t.isPanelOpen,toolPanelIcon:r,configButtons:c.map(m=>({id:m.id,hasElement:!!m.element,hasRender:!!m.render})),apiButtons:d.map(m=>({id:m.id,hasElement:!!m.element,hasRender:!!m.render}))},h=[...t.toolPanels.values()].sort((m,C)=>(m.order??100)-(C.order??100)),f={position:e?.toolPanel?.position??"right",isPanelOpen:t.isPanelOpen,expandIcon:s,collapseIcon:l,panels:h.map(m=>({id:m.id,title:m.title,icon:$(m.icon),isExpanded:t.expandedSections.has(m.id)}))},p=Qo(u),g=en(f),w=mt({hasShell:!0,shellHeader:p,shellBody:g});o.appendChild(w)}else{const r=mt({hasShell:!1});o.appendChild(r)}return i}function hn(){return{startY:null,startX:null,scrollTop:null,scrollLeft:null,lastY:null,lastX:null,lastTime:null,velocityY:0,velocityX:0,momentumRaf:0}}function fn(o){o.startY=null,o.startX=null,o.scrollTop=null,o.scrollLeft=null,o.lastY=null,o.lastX=null,o.lastTime=null}function Et(o){o.momentumRaf&&(cancelAnimationFrame(o.momentumRaf),o.momentumRaf=0)}function pn(o,e,t){if(o.touches.length!==1)return;Et(e);const n=o.touches[0];e.startY=n.clientY,e.startX=n.clientX,e.lastY=n.clientY,e.lastX=n.clientX,e.lastTime=performance.now(),e.scrollTop=t.fauxScrollbar.scrollTop,e.scrollLeft=t.scrollArea?.scrollLeft??0,e.velocityY=0,e.velocityX=0}function gn(o,e,t){if(o.touches.length!==1||e.startY===null||e.startX===null||e.scrollTop===null||e.scrollLeft===null)return!1;const n=o.touches[0],i=n.clientY,r=n.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,f=l>0&&c<h||l<0&&c>0;let p=!1;if(t.scrollArea){const{scrollLeft:g,scrollWidth:w,clientWidth:m}=t.scrollArea,C=w-m;p=a>0&&g<C||a<0&&g>0}return f&&(t.fauxScrollbar.scrollTop=e.scrollTop+l),p&&t.scrollArea&&(t.scrollArea.scrollLeft=e.scrollLeft+a),f||p}function wn(o,e){(Math.abs(o.velocityY)>.1||Math.abs(o.velocityX)>.1)&&mn(o,e),fn(o)}function mn(o,e){const i=()=>{o.velocityY*=.95,o.velocityX*=.95;const r=o.velocityY*16,s=o.velocityX*16;Math.abs(o.velocityY)>.01&&(e.fauxScrollbar.scrollTop+=r),Math.abs(o.velocityX)>.01&&e.scrollArea&&(e.scrollArea.scrollLeft+=s),Math.abs(o.velocityY)>.01||Math.abs(o.velocityX)>.01?o.momentumRaf=requestAnimationFrame(i):o.momentumRaf=0};o.momentumRaf=requestAnimationFrame(i)}function bn(o,e,t,n){o.addEventListener("touchstart",i=>pn(i,e,t),{passive:!0,signal:n}),o.addEventListener("touchmove",i=>{gn(i,e,t)&&i.preventDefault()},{passive:!1,signal:n}),o.addEventListener("touchend",()=>wn(e,t),{passive:!0,signal:n})}class Rt{constructor(e){this.grid=e}plugins=[];pluginMap=new Map;cellRenderers=new Map;headerRenderers=new Map;cellEditors=new Map;attachAll(e){for(const t of e)this.attach(t)}attach(e){if(this.pluginMap.set(e.constructor,e),this.plugins.push(e),e.cellRenderers)for(const[t,n]of Object.entries(e.cellRenderers))this.cellRenderers.set(t,n);if(e.headerRenderers)for(const[t,n]of Object.entries(e.headerRenderers))this.headerRenderers.set(t,n);if(e.cellEditors)for(const[t,n]of Object.entries(e.cellEditors))this.cellEditors.set(t,n);e.attach(this.grid)}detachAll(){for(let e=this.plugins.length-1;e>=0;e--)this.plugins[e].detach();this.plugins=[],this.pluginMap.clear(),this.cellRenderers.clear(),this.headerRenderers.clear(),this.cellEditors.clear()}getPlugin(e){return this.pluginMap.get(e)}getPluginByName(e){return this.plugins.find(t=>t.name===e)}hasPlugin(e){return this.pluginMap.has(e)}getAll(){return this.plugins}getCellRenderer(e){return this.cellRenderers.get(e)}getHeaderRenderer(e){return this.headerRenderers.get(e)}getCellEditor(e){return this.cellEditors.get(e)}getAllStyles(){return this.plugins.filter(e=>e.styles).map(e=>e.styles).join(`
|
|
30
|
-
|
|
31
|
-
`);if(r.includes(".tbw-grid-root")&&r.includes(":host")){t=r;break}}catch{continue}t?(e.replaceSync(t),this.#n.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(n=>n.href||"(inline)"))}catch(t){console.warn("[tbw-grid] Failed to extract grid.css from document stylesheets:",t)}}getPlugin(e){return this.#t?.getPlugin(e)}getPluginByName(e){return this.#t?.getPluginByName(e)}requestRender(){this.#I(),this.#M(),J(this),G(this),this.refreshVirtualWindow(!0)}updateTemplate(){G(this)}requestAfterRender(){this.#t?.afterRender()}#Z(){this.#t=new Rt(this);const e=this.#o?.plugins,t=Array.isArray(e)?e:[];this.#t.attachAll(t)}#J(){const e=this.#t?.getAllStyles()??"";if(e){const t=document.createElement("style");t.setAttribute("data-plugin","all"),t.textContent=e,this.#n.appendChild(t)}}#Q(){this.#t&&this.#t.detachAll();for(const e of this.#e.toolPanels.keys()){const t=this.#e.lightDomToolPanelIds.has(e),n=this.#e.apiToolPanelIds.has(e);if(!t&&!n){const i=this.#e.panelCleanups.get(e);i&&(i(),this.#e.panelCleanups.delete(e)),this.#e.toolPanels.delete(e)}}for(const e of this.#e.headerContents.keys()){const t=this.#e.headerContentCleanups.get(e);t&&(t(),this.#e.headerContentCleanups.delete(e)),this.#e.headerContents.delete(e)}this.#Z(),this.#J(),this.#ee(),this.#T=this.#t?.getAll().some(e=>e.onScroll)??!1}#le(){this.#t?.detachAll()}#ee(){if(!this.#t)return;const e=this.#t.getToolPanels();for(const{panel:n}of e)this.#e.toolPanels.has(n.id)||this.#e.toolPanels.set(n.id,n);const t=this.#t.getHeaderContents();for(const{content:n}of t)this.#e.headerContents.has(n.id)||this.#e.headerContents.set(n.id,n)}#m(){const e=F.getAdapters();if(e.length===0&&!this.__frameworkAdapter)return;const t=this.__frameworkAdapter;return n=>{if(t?.createToolPanelRenderer){const i=t.createToolPanelRenderer(n);if(i)return i}for(const i of e)if(i.createToolPanelRenderer){const r=i.createToolPanelRenderer(n);if(r)return r}}}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.hasAttribute("version")||this.setAttribute("version",F.version),this._rows=Array.isArray(this.#s)?[...this.#s]:[],this.#c&&(this.#c.abort(),this.#L=!1),this.#c=new AbortController,this.#h&&(ht(this.#h),this.#h=void 0),Q(this,this.#e),ee(this,this.#e),te(this,this.#e,this.#m()),this.#a(),this.#Z(),this.#ee(),this.#r||(this.#j(),this.#J(),this.#r=!0),this.#z(),this.#h=Zo(()=>{this.#Re()},{timeout:100})}disconnectedCallback(){this.#h&&(ht(this.#h),this.#h=void 0),this.#le(),an(this.#e),this.#i.setInitialized(!1),this.#P?.(),this.#P=void 0,Et(this.#Y),this.#c&&(this.#c.abort(),this.#c=void 0),this.#C?.abort(),this.#C=void 0,this.#L=!1,this._resizeController&&this._resizeController.dispose(),this.#g&&(this.#g.disconnect(),this.#g=void 0),this.#w&&(this.#w.disconnect(),this.#w=void 0,this.#B=!1),this.#u&&(this.#u.disconnect(),this.#u=void 0),ae(this),this._rowEditSnapshots.clear(),this._changedRowIndices.clear(),this.#E.clear();for(const e of this._rowPool)e.remove();this._rowPool.length=0,this.__rowsBodyEl=null,this.#H=!1}attributeChangedCallback(e,t,n){if(t===n||!n||n==="null"||n==="undefined")return;const r={rows:"rows",columns:"columns","grid-config":"gridConfig","fit-mode":"fitMode","edit-on":"editOn"}[e];if(r)if(e==="rows"||e==="columns"||e==="grid-config")try{this[r]=JSON.parse(n)}catch{console.warn(`[tbw-grid] Invalid JSON for '${e}' attribute:`,n)}else this[r]=n}#z(){const t=this.#n.querySelector(".tbw-grid-content")??this.#n.querySelector(".tbw-grid-root");if(this._headerRowEl=t?.querySelector(".header-row"),this._virtualization.totalHeightEl=t?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=t?.querySelector(".rows-viewport"),this._bodyEl=t?.querySelector(".rows"),this.__rowsBodyEl=t?.querySelector(".rows-body"),this.#i.isInitialized){yt(this.#n,this.#e),rn(this.#n,this.#o?.shell,this.#e);const r=this.#o?.shell?.toolPanel?.defaultOpen;r&&this.#e.toolPanels.has(r)&&(this.openToolPanel(),this.#e.expandedSections.add(r))}if(this.setAttribute("data-upgraded",""),this.#H=!0,this._resizeController=Jo(this),this.#d(),this.#ae(t),this.#L)return;this.#L=!0;const n=this.disconnectSignal;this.addEventListener("keydown",r=>Mo(this,r),{signal:n}),document.addEventListener("keydown",r=>{r.key==="Escape"&&this._activeEditRows!==-1&&B(this,this._activeEditRows,!0)},{capture:!0,signal:n}),document.addEventListener("mousedown",r=>{if(this._activeEditRows===-1)return;const s=this.findRenderedRowElement(this._activeEditRows);!s||(r.composedPath&&r.composedPath()||[]).includes(s)||B(this,this._activeEditRows,!1)},{signal:n}),this.#n.addEventListener("mousedown",r=>this.#ye(r),{signal:n}),document.addEventListener("mousemove",r=>this.#Ce(r),{signal:n}),document.addEventListener("mouseup",r=>this.#xe(r),{signal:n});const i=this.#o.rowHeight;i&&i>0?this._virtualization.rowHeight=i:requestAnimationFrame(()=>this.#te()),queueMicrotask(()=>this.#de()),requestAnimationFrame(()=>requestAnimationFrame(()=>this.#R?.()))}#te(){const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const t=e.querySelectorAll(".cell");let n=0;t.forEach(s=>{const l=s.offsetHeight;l>n&&(n=l)});const i=e.getBoundingClientRect(),r=Math.max(i.height,n);r>0&&r!==this._virtualization.rowHeight&&(this._virtualization.rowHeight=r,this.refreshVirtualWindow(!0))}#ae(e){this.#C?.abort(),this.#C=new AbortController;const t=this.#C.signal,n=e?.querySelector(".faux-vscroll"),i=e?.querySelector(".rows");if(this._virtualization.container=n??this,this.#T=this.#t?.getAll().some(r=>r.onScroll)??!1,n&&i){n.addEventListener("scroll",()=>{if(!this._virtualization.enabled&&!this.#T)return;const l=n.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.#A=l,this.#p||(this.#p=requestAnimationFrame(()=>{this.#p=0,this.#A!==null&&(this.#ve(this.#A),this.#A=null)}))},{passive:!0,signal:t});const r=this.#n.querySelector(".tbw-grid-content"),s=this.#n.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}=n;(l.deltaY>0&&c<d-u||l.deltaY<0&&c>0)&&(l.preventDefault(),n.scrollTop+=l.deltaY)}},{passive:!1,signal:t}),bn(r,this.#Y,{fauxScrollbar:n,scrollArea:s},t))}this._bodyEl&&Xo(this,this._bodyEl,t),this.#g?.disconnect(),this._virtualization.viewportEl&&(this.#g=new ResizeObserver(()=>{this.#p||(this.#p=requestAnimationFrame(()=>{this.#p=0,this.refreshVirtualWindow(!0),N(this)}))}),this.#g.observe(this._virtualization.viewportEl)),this._virtualization.enabled&&requestAnimationFrame(()=>{this.refreshVirtualWindow(!0),this.#ce()})}#B=!1;#ce(){if(this.#B)return;const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;this.#B=!0,this.#w?.disconnect();const t=e.querySelectorAll(".cell");t.length>0&&(this.#w=new ResizeObserver(()=>{this.#te()}),t.forEach(n=>this.#w.observe(n)))}#V(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}#de(){this._bodyEl?.querySelectorAll(".data-grid-row")?.forEach((t,n)=>{const i=n===this._focusRow;t.setAttribute("aria-selected",String(i)),t.querySelectorAll(".cell").forEach((r,s)=>{r.setAttribute("aria-selected",String(i&&s===this._focusCol))})})}#x(e){this.#D[e]=!0,!this.#y&&(this.#y=!0,queueMicrotask(()=>this.#ue()))}#ue(){if(!this.#y||!this.#H){this.#y=!1;return}const e=this.#D;if(this.#y=!1,this.#D={rows:!1,columns:!1,gridConfig:!1,fitMode:!1,editMode:!1},e.gridConfig){this.#we();return}e.columns&&this.#fe(),e.rows&&this.#he(),e.fitMode&&this.#pe(),e.editMode&&this.#ge()}#he(){this._rows=Array.isArray(this.#s)?[...this.#s]:[],this.#I(),this._columns.length>0||Array.isArray(this.#o?.columns)&&this.#o.columns.length>0||Array.isArray(this.#l)&&this.#l.length>0?(this.#M(),this.refreshVirtualWindow(!0)):this.#d()}#fe(){ae(this),this.#a(),this.#d()}#pe(){this.#a(),this.#o.fitMode==="fixed"?(this.__didInitialAutoSize=!1,Qe(this)):(this._columns.forEach(t=>{!t.__userResized&&t.__autoSized&&delete t.width}),G(this))}#ge(){this.#a(),this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.refreshVirtualWindow(!0)}#we(){Q(this,this.#e),ee(this,this.#e);const e=!!this.#n.querySelector(".has-shell"),t=!!this.#n.querySelector(".tbw-tool-panel"),n=this.#n.querySelectorAll(".tbw-accordion-section").length;Je(this),this.#a(),this.#Q(),te(this,this.#e,this.#m());const i=bt(this.#o,this.#e),r=this.#e.toolPanels.size>0,s=this.#e.toolPanels.size!==n;if(e!==i||!e&&i||!t&&r||t&&s){this.#j(),this.#z();return}e&&this.#me(),this.#I(),this.#M(),J(this),G(this),this.refreshVirtualWindow(!0)}#me(){const e=this.#n.querySelector(".tbw-shell-header");if(!e)return;const t=this.#o.shell?.header?.title??this.#e.lightDomTitle;let n=e.querySelector(".tbw-shell-title");t?(n||(n=document.createElement("h2"),n.className="tbw-shell-title",n.setAttribute("part","shell-title"),e.insertBefore(n,e.firstChild)),n.textContent=t):n&&n.remove()}#M(){if(this.#t){const e=this.#q.length>0?this.#q:this._columns,t=e.filter(r=>!r.hidden),n=e.filter(r=>r.hidden),i=this.#t.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,...n];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]}}#I(){ae(this);const e=Array.isArray(this.#s)?[...this.#s]:[],t=this.#t?.processRows(e)??e;this._rows=t}#a(){const e=this.#v?{...this.#v}:{};let t=Array.isArray(e.columns)?[...e.columns]:[];const n=(this.__lightDomColumnsCache||[]).map(i=>({...i}));if(n.length){const i={};t.forEach(r=>i[r.field]=r),n.forEach(r=>{const s=i[r.field];if(!s)t.push(r),i[r.field]=r;else{r.header&&!s.header&&(s.header=r.header),r.type&&!s.type&&(s.type=r.type),s.sortable=s.sortable||r.sortable,r.resizable&&(s.resizable=!0),r.editable&&(s.editable=!0);const l=r.renderer||r.viewRenderer,a=s.renderer||s.viewRenderer;l&&!a&&(s.viewRenderer=l,r.renderer&&(s.renderer=l)),r.editor&&!s.editor&&(s.editor=r.editor)}})}if(this.#l&&this.#l.length&&(t=[...this.#l]),(!t||t.length===0)&&this._rows.length&&(t=je(this._rows).columns),t.length){t.forEach(s=>{s.sortable===void 0&&(s.sortable=!0),s.resizable===void 0&&(s.resizable=!0);const l=s;l.__originalWidth===void 0&&typeof s.width=="number"&&(l.__originalWidth=s.width)});const i=this.#o.columns;i?.some(s=>s.__compiledView||s.__compiledEditor)?e.columns=i:e.columns=t}else{const i=this.#o.columns;i?.some(r=>r.__compiledView||r.__compiledEditor)&&(e.columns=i)}this.#_&&(e.fitMode=this.#_),e.fitMode||(e.fitMode="stretch"),this.#S&&(e.editOn=this.#S),this.#e.lightDomTitle&&(e.shell||(e.shell={}),e.shell.header||(e.shell.header={}),e.shell.header.title||(e.shell.header.title=this.#e.lightDomTitle)),e.rowHeight&&e.rowHeight>0&&(this._virtualization.rowHeight=e.rowHeight),e.columnState&&!this.#f&&(this.#f=e.columnState),this.#o=e,e.fitMode==="fixed"&&this._columns.forEach(i=>{i.width==null&&(i.width=80)}),this.#be()}#be(){const e={...Ue,...this.#o.animation},t=e.mode??"reduced-motion";let n=1;t===!1||t==="off"?n=0:(t===!0||t==="on")&&(n=1),this.style.setProperty("--tbw-animation-duration",`${e.duration}ms`),this.style.setProperty("--tbw-animation-easing",e.easing??"ease-out"),this.style.setProperty("--tbw-animation-enabled",String(n)),this.dataset.animationMode=typeof t=="boolean"?t?"on":"off":t}#K(e,t,n=this.__rowRenderEpoch){this.#O||(this.#O=(i,r,s)=>this.#t?.renderRow(i,r,s)??!1),No(this,e,t,n,this.#O)}#G=-1;#oe=-1;#ne(e,t){if(e===this.#G&&t===this.#oe)return;const n=this.#G;this.#G=e,this.#oe=t,this.__rowsBodyEl&&(this.__rowsBodyEl.setAttribute("aria-rowcount",String(e)),this.__rowsBodyEl.setAttribute("aria-colcount",String(t))),e!==n&&this._bodyEl&&(e>0?this._bodyEl.setAttribute("role","rowgroup"):this._bodyEl.removeAttribute("role"))}#d(){if(!this.isConnected||!this._headerRowEl||!this._bodyEl)return;const e=this.#v?.columns||this.#l||[];if(e.length){const n=new Map(this._columns.filter(r=>r.hidden).map(r=>[r.field,!0])),i=e.map(r=>({...r,hidden:n.get(r.field)??r.hidden}));this._columns=i}if(Je(this),this.#a(),this.#Q(),this.#q=[...this._columns],this.#I(),this.#M(),this.#f){const n=this.#f;this.#f=void 0,this.#ie(n)}J(this),G(this),this.refreshVirtualWindow(!0),this.#o.fitMode==="fixed"&&!this.__didInitialAutoSize&&requestAnimationFrame(()=>Qe(this)),this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),queueMicrotask(()=>this.#t?.afterRender())}#ie(e){const t=this.#o.columns??[],n=this.#t?.getAll()??[];ao(this,e,t,n);for(const i of e.columns){const r=t.find(s=>s.field===i.field);r&&(r.hidden=!i.visible)}}#ve(e){if(this.refreshVirtualWindow(!1),this.#t?.onScrollRender(),this.#T){const t=this._virtualization.container,n=this.#re;n.scrollTop=e,n.scrollLeft=t?.scrollLeft??0,n.scrollHeight=t?.scrollHeight??0,n.scrollWidth=t?.scrollWidth??0,n.clientHeight=t?.clientHeight??0,n.clientWidth=t?.clientWidth??0,this.#t?.onScroll(n)}}findHeaderRow(){return this.#n.querySelector(".header-row")}findRenderedRowElement(e){return Array.from(this._bodyEl.querySelectorAll(".data-grid-row")).find(t=>{const n=t.querySelector(".cell[data-row]");return n&&Number(n.getAttribute("data-row"))===e})||null}_dispatchCellClick(e,t,n,i){const r=this._rows[t],s=this._columns[n];if(!r||!s)return!1;const l={row:r,rowIndex:t,colIndex:n,field:s.field,value:r[s.field],cellEl:i,originalEvent:e};return this.#t?.onCellClick(l)??!1}_dispatchRowClick(e,t,n,i){if(!n)return!1;const r={rowIndex:t,row:n,rowEl:i,originalEvent:e};return this.#t?.onRowClick(r)??!1}_dispatchHeaderClick(e,t,n){const i=this._columns[t];if(!i)return!1;const r={colIndex:t,field:i.field,column:i,headerEl:n,originalEvent:e};return this.#t?.onHeaderClick(r)??!1}_dispatchKeyDown(e){return this.#t?.onKeyDown(e)??!1}_getHorizontalScrollOffsets(e,t){return this.#t?.getHorizontalScrollOffsets(e,t)??{left:0,right:0}}queryPlugins(e){return this.#t?.queryPlugins(e)??[]}#W(e,t){let n=null;const i=e.composedPath?.();if(i&&i.length>0?n=i[0]:n=e.target,n&&!this.#n.contains(n)){const p=this.#n.elementFromPoint(e.clientX,e.clientY);p&&(n=p)}const r=n?.closest?.("[data-col]"),s=n?.closest?.(".data-grid-row"),l=n?.closest?.(".header-row");let a,c,d,u,h,f;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],f=this._columns[c],u=f?.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:f,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}}#ye(e){const t=this.#W(e,"mousedown");(this.#t?.onCellMouseDown(t)??!1)&&(this.#k=!0)}#Ce(e){if(!this.#k)return;const t=this.#W(e,"mousemove");this.#t?.onCellMouseMove(t)}#xe(e){if(!this.#k)return;const t=this.#W(e,"mouseup");this.#t?.onCellMouseUp(t),this.#k=!1}get changedRows(){return it(this)}get changedRowIndices(){return rt(this)}async resetChangedRows(e){Bo(this,e)}async beginBulkEdit(e){Vo(this,e,{findRenderedRowElement:t=>this.findRenderedRowElement?.(t)??null})}async commitActiveRowEdit(){Ko(this)}async cancelActiveRowEdit(){Go(this)}async ready(){return this.#b}async forceLayout(){this.#d(),await new Promise(e=>requestAnimationFrame(()=>requestAnimationFrame(e)))}async getConfig(){return Object.freeze({...this.#o||{}})}#$={emit:(e,t)=>this.#V(e,t),clearRowPool:()=>{this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++},setup:()=>this.#d(),requestStateChange:()=>this.requestStateChange()};setColumnVisible(e,t){return $e(this,e,t,this.#$)}toggleColumnVisibility(e){return uo(this,e,this.#$)}isColumnVisible(e){return ho(this,e)}showAllColumns(){fo(this,this.#$)}getAllColumns(){return po(this)}setColumnOrder(e){wo(this,e,{renderHeader:()=>J(this),updateTemplate:()=>G(this),refreshVirtualWindow:()=>this.refreshVirtualWindow(!0)})}getColumnOrder(){return go(this)}getColumnState(){const e=this.#t?.getAll()??[];return We(this,e)}set columnState(e){e&&(this.#f=e,this.#r&&this.#Ee(e))}get columnState(){return this.getColumnState()}#Ee(e){(this.#o.columns??[]).forEach(n=>{n.hidden=!1}),this.#ie(e),this.#d()}requestStateChange(){this.#F||(this.#F=co(this,()=>this.#t?.getAll()??[],e=>this.#V("column-state-change",e))),this.#F()}resetColumnState(){this.#f=void 0,(this.#o.columns??[]).forEach(n=>{n.hidden=!1}),this._sortState=null,this.__originalOrder=[],this.#a(),this.#d();const t=this.#t?.getAll()??[];for(const n of t)if(n.applyColumnState)for(const i of this._columns)n.applyColumnState(i.field,{field:i.field,order:0,visible:!0});this.requestStateChange()}get isToolPanelOpen(){return this.#i.isPanelOpen}get activeToolPanel(){return this.#i.activePanel}get expandedToolPanelSections(){return this.#i.expandedSections}openToolPanel(){this.#i.openToolPanel()}closeToolPanel(){this.#i.closeToolPanel()}toggleToolPanel(){this.#i.toggleToolPanel()}toggleToolPanelSection(e){this.#i.toggleToolPanelSection(e)}getToolPanels(){return this.#i.getToolPanels()}registerToolPanel(e){this.#e.apiToolPanelIds.add(e.id),this.#i.registerToolPanel(e)}unregisterToolPanel(e){this.#e.apiToolPanelIds.delete(e),this.#i.unregisterToolPanel(e)}getHeaderContents(){return this.#i.getHeaderContents()}registerHeaderContent(e){this.#i.registerHeaderContent(e)}unregisterHeaderContent(e){this.#i.unregisterHeaderContent(e)}getToolbarButtons(){return this.#i.getToolbarButtons()}registerToolbarButton(e){this.#i.registerToolbarButton(e)}unregisterToolbarButton(e){this.#i.unregisterToolbarButton(e)}setToolbarButtonDisabled(e,t){this.#i.setToolbarButtonDisabled(e,t)}refreshShellHeader(){Q(this,this.#e),ee(this,this.#e),te(this,this.#e,this.#m()),this.#j(),this.#z()}#E=new Map;registerStyles(e,t){this.unregisterStyles(e);const n=document.createElement("style");n.id=`tbw-custom-${e}`,n.textContent=t,this.#n.appendChild(n),this.#E.set(e,n)}unregisterStyles(e){const t=this.#E.get(e);t&&(t.remove(),this.#E.delete(e))}getRegisteredStyles(){return Array.from(this.#E.keys())}#Re(){this.#u&&this.#u.disconnect();let e=null,t=!1,n=!1;const i=()=>{if(e=null,t){const r=this.#e.lightDomTitle,s=this.#e.hasToolButtonsContainer;Q(this,this.#e),ee(this,this.#e),te(this,this.#e,this.#m());const l=this.#e.lightDomTitle,a=this.#e.hasToolButtonsContainer;if(l&&!r||a&&!s){this.#a();const c=this.#n.querySelector(".tbw-shell-header");if(c){const d=vt(this.#o.shell,this.#e,this.#o.icons?.toolPanel),u=document.createElement("div");u.innerHTML=d;const h=u.firstElementChild;h&&(c.replaceWith(h),this.#X())}}t=!1}n&&(this.__lightDomColumnsCache=void 0,this.#d(),n=!1)};this.#u=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();c==="tbw-grid-header"?t=!0:(c==="tbw-grid-column"||c==="tbw-grid-detail")&&(n=!0)}if(s.type==="attributes"&&s.target.nodeType===Node.ELEMENT_NODE){const a=s.target.tagName.toLowerCase();a==="tbw-grid-header"?t=!0:a==="tbw-grid-column"&&(n=!0)}}(t||n)&&!e&&(e=setTimeout(i,0))}),this.#u.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["title","field","header","width","hidden"]})}refreshColumns(){this.#N||(this.#N=requestAnimationFrame(()=>{this.#N=0,this.#_e()}))}#_e(){this.__lightDomColumnsCache=void 0,ae(this);const e=this.#e.lightDomTitle,t=this.#e.hasToolButtonsContainer;Q(this,this.#e),ee(this,this.#e),te(this,this.#e,this.#m());const n=this.#e.lightDomTitle,i=this.#e.hasToolButtonsContainer;if(n&&!e||i&&!t){this.#a();const s=this.#n.querySelector(".tbw-shell-header");if(s){const l=vt(this.#o.shell,this.#e,this.#o.icons?.toolPanel),a=document.createElement("div");a.innerHTML=l;const c=a.firstElementChild;c&&(s.replaceWith(c),this.#X())}}this.#d()}#U(e){const t=this._virtualization.rowHeight,n=this._virtualization.container??this,i=this._virtualization.viewportEl??n,r=n.clientHeight,s=i.clientHeight,a=this.shadowRoot?.querySelector(".tbw-scroll-area"),c=a?a.clientHeight:r,u=c-s,h=this.#t?.getExtraHeight()??0,f=Math.max(0,r-c);return e*t+u+h+f}refreshVirtualWindow(e=!1){if(!this._bodyEl)return;const t=this._rows.length;if(!this._virtualization.enabled){this.#K(0,t),this.#t?.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.#K(0,t,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${this.#U(t)}px`),this.#ne(t,this._visibleColumns.length),this.#t?.afterRender();return}const n=this._virtualization.container??this,i=this._virtualization.viewportEl??n,r=i.clientHeight,s=this._virtualization.rowHeight,l=n.scrollTop;let a=Math.floor(l/s),c=0;const d=10;for(;c<d;){const C=this.#t?.getExtraHeightBefore?.(a)??0,x=Math.floor((l-C)/s);if(x>=a||x<0)break;a=x,c++}a=a-a%2,a<0&&(a=0);const u=this.#t?.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 f=a+h;if(f>t&&(f=t),this._virtualization.start=a,this._virtualization.end=f,n.clientHeight===0&&r>0){requestAnimationFrame(()=>this.refreshVirtualWindow(e));return}const g=this.#U(t);this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${g}px`);const w=this.#t?.getExtraHeightBefore?.(a)??0,m=-(l-a*s-w);this._bodyEl.style.transform=`translateY(${m}px)`,this.#K(a,f,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),this.#ne(t,this._visibleColumns.length),e&&(this.#t?.afterRender(),queueMicrotask(()=>{const C=n.clientHeight,x=i.clientHeight;if(C===0&&x>0)return;const v=this.#U(t);this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${v}px`)}))}#j(){Q(this,this.#e),ee(this,this.#e),te(this,this.#e,this.#m()),this.#a();const e=this.#o?.shell;un(this.#n,e,this.#e,this.#o?.icons)&&(this.#X(),this.#i.setInitialized(!0))}#X(){on(this.#n,this.#o?.shell,this.#e,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e),onToolbarButtonClick:e=>this.#Se(e)}),this.#P?.(),this.#P=nn(this.#n,this.#o?.shell,e=>{this.style.setProperty("--tbw-tool-panel-width",`${e}px`)})}#Se(e){}}customElements.get(F.tagName)||customElements.define(F.tagName,F),globalThis.DataGridElement=F;const ce={CAN_MOVE_COLUMN:"canMoveColumn",GET_CONTEXT_MENU_ITEMS:"getContextMenuItems"};class T{version="1.0.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}attach(e){this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}requestRender(){this.grid?.requestRender?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get shadowRoot(){return this.grid?.shadowRoot??null}get disconnectSignal(){return this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...H,...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 P={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"},de={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"},vn={ROOT:`.${P.ROOT}`,HEADER:`.${P.HEADER}`,HEADER_ROW:`.${P.HEADER_ROW}`,HEADER_CELL:`.${P.HEADER_CELL}`,ROWS_VIEWPORT:`.${P.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${P.ROWS_CONTAINER}`,DATA_ROW:`.${P.DATA_ROW}`,DATA_CELL:`.${P.DATA_CELL}`,GROUP_ROW:`.${P.GROUP_ROW}`,ROW_BY_INDEX:o=>`.${P.DATA_ROW}[${de.ROW_INDEX}="${o}"]`,CELL_BY_FIELD:o=>`.${P.DATA_CELL}[${de.FIELD}="${o}"]`,CELL_AT:(o,e)=>`.${P.DATA_ROW}[${de.ROW_INDEX}="${o}"] .${P.DATA_CELL}[${de.COL_INDEX}="${e}"]`,SELECTED_ROWS:`.${P.DATA_ROW}.${P.SELECTED}`,EDITING_CELL:`.${P.DATA_CELL}.${P.EDITING}`},yn={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"},Cn={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"},xn={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 En(o,e,t,n){if(n.processCell)return n.processCell(o,e,t);if(o==null)return"";if(o instanceof Date)return o.toISOString();if(typeof o=="object")return JSON.stringify(o);const i=String(o),r=n.delimiter??" ",s=n.newline??`
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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.
|
|
30
|
+
→ Add the plugin to your gridConfig.plugins array:
|
|
31
|
+
${a}
|
|
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.
|
|
33
|
+
→ Add the plugin to your gridConfig.plugins array:
|
|
34
|
+
${a}
|
|
35
|
+
plugins: [new ${s.charAt(0).toUpperCase()+s.slice(1)}Plugin(), ...]`)}throw new Error(`[tbw-grid] Configuration error:
|
|
36
|
+
|
|
37
|
+
${r.join(`
|
|
38
|
+
|
|
39
|
+
`)}
|
|
40
|
+
|
|
41
|
+
This validation helps catch misconfigurations early. The properties listed above require their respective plugins to function.`)}}class wt{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(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(`
|
|
42
|
+
`)}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=Vo();#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=Io();#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 Lo({mergeConfig:()=>{this.#o.parseLightDomColumns(this),this.#o.merge(),this.#W(),Qo(this.#n,this.#i?.getPlugins()??[]),this.#O=[...this._columns]},processColumns:()=>this.#de(),processRows:()=>this.#ue(),renderHeader:()=>ae(this),updateTemplate:()=>ee(this),renderVirtualWindow:()=>this.refreshVirtualWindow(!0),afterRender:()=>{this.#i?.afterRender(),this.#n.fitMode==="fixed"&&!this.__didInitialAutoSize&&(this.__didInitialAutoSize=!0,Ke(this))},isConnected:()=>this.isConnected&&this.#f}),this.#l.setInitialReadyResolver(()=>this.#c?.()),this.#u=Bo(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 yo({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:()=>ae(this),updateTemplate:()=>ee(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(K.length>0){e.replaceSync(K),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(`
|
|
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
|
+
`;return o.quoteStrings||i.includes(r)||i.includes(s)||i.includes('"')?`"${i.replace(/"/g,'""')}"`:i}function ye(n){const{rows:e,columns:t,selectedIndices:o,config:i}=n,r=i.delimiter??" ",s=i.newline??`
|
|
45
|
+
`,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=>rn(h[f.field],f.field,h,i));a.push(p.join(r))}return a.join(s)}async function Ce(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 bt(n,e){const t=e.delimiter??" ",o=e.newline??`
|
|
46
|
+
`,i=n.replace(/\r\n/g,`
|
|
35
47
|
`).replace(/\r/g,`
|
|
36
|
-
`),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===
|
|
37
|
-
`,quoteStrings:!1}}lastCopied=null;detach(){this.lastCopied=null}onKeyDown(e){const t=(e.ctrlKey||e.metaKey)&&e.key==="c",
|
|
38
|
-
`,h=[],f=this.columns.slice(a,c+1);if(this.config.includeHeaders){const p=f.map(g=>g.header||g.field);h.push(p.join(d))}for(let p=s;p<=l;p++){const g=this.rows[p];if(!g)continue;const w=f.map(m=>{const 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}}#l(e){const t=e.closest("[data-field-cache]");if(!t)return null;const n=t.dataset.fieldCache;if(!n)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[n],c=this.columns.find(u=>u.field===n)?.header||n;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:n,value:l}}async copy(){const t=this.#b()?.getSelectedRows()??[],n=Se({rows:this.rows,columns:[...this.columns],selectedIndices:t,config:this.config});return await Ae(n),this.lastCopied={text:n,timestamp:Date.now()},n}async copyRows(e){const t=Se({rows:this.rows,columns:[...this.columns],selectedIndices:e,config:this.config});return await Ae(t),this.lastCopied={text:t,timestamp:Date.now()},t}async paste(){const e=await St();return e?_t(e,this.config):null}getLastCopied(){return this.lastCopied}}const At=100;function Te(o){if(o==null)return At;if(typeof o=="number")return o;const e=parseFloat(o);return isNaN(e)?At:e}function Tt(o){return o.map(e=>Te(e.width))}function kt(o){const e=[];let t=0;for(const n of o)e.push(t),t+=Te(n.width);return e}function Lt(o){return o.reduce((e,t)=>e+Te(t.width),0)}function _n(o,e,t,n,i){const r=t.length;if(r===0)return{startCol:0,endCol:0,visibleColumns:[]};let s=Sn(o,t,n);s=Math.max(0,s-i);const l=o+e;let a=s;for(let d=s;d<r;d++){if(t[d]>=l){a=d-1;break}a=d}a=Math.min(r-1,a+i);const c=[];for(let d=s;d<=a;d++)c.push(d);return{startCol:s,endCol:a,visibleColumns:c}}function Sn(o,e,t){let n=0,i=e.length-1;for(;n<i;){const r=Math.floor((n+i)/2);e[r]+t[r]<=o?n=r+1:i=r}return n}function An(o,e,t){return t?o>e:!1}class Tn extends T{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=Tt(t),this.columnOffsets=kt(t),this.totalWidth=Lt(t),this.endCol=t.length-1}detach(){this.columnWidths=[],this.columnOffsets=[],this.isVirtualized=!1,this.startCol=0,this.endCol=0,this.scrollLeft=0,this.totalWidth=0}processColumns(e){const t=An(e.length,this.config.threshold??30,this.config.autoEnable??!0);if(this.isVirtualized=t??!1,this.columnWidths=Tt(e),this.columnOffsets=kt(e),this.totalWidth=Lt(e),!t)return this.startCol=0,this.endCol=e.length-1,[...e];const n=this.grid.clientWidth||800,i=_n(this.scrollLeft,n,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,n=e.querySelector(".header-row"),i=e.querySelectorAll(".data-grid-row");n&&(n.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,n=this.grid;n.scrollLeft=t}getColumnOffset(e){return this.columnOffsets[e]??0}getTotalWidth(){return this.totalWidth}}const ke=".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 Le(o,e){return(typeof o=="function"?o(e):o).filter(n=>!(n.hidden===!0||typeof n.hidden=="function"&&n.hidden(e)))}function kn(o,e){return o.disabled===!0?!0:typeof o.disabled=="function"?o.disabled(e):!1}function Pe(o,e,t,n=H.submenuArrow){const i=document.createElement("div");i.className="tbw-context-menu",i.setAttribute("role","menu");for(const r of o){if(r.separator){const c=document.createElement("div");c.className="tbw-context-menu-separator",c.setAttribute("role","separator"),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=kn(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 n=="string"?c.innerHTML=n:n instanceof HTMLElement&&c.appendChild(n.cloneNode(!0)),s.appendChild(c),s.addEventListener("mouseenter",()=>{if(s.querySelector(".tbw-context-menu")||!r.subMenu)return;const u=Le(r.subMenu,e),h=Pe(u,e,t,n);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 Pt(o,e,t){o.style.position="fixed",o.style.left=`${e}px`,o.style.top=`${t}px`,o.style.visibility="hidden",o.style.zIndex="10000";const n=o.getBoundingClientRect(),i=window.innerWidth,r=window.innerHeight;let s=e,l=t;e+n.width>i&&(s=e-n.width),t+n.height>r&&(l=t-n.height),s=Math.max(0,s),l=Math.max(0,l),o.style.left=`${s}px`,o.style.top=`${l}px`,o.style.visibility="visible"}let oe=null,ne=null,V=null,Me=0;const Ie=[{id:"copy",name:"Copy",shortcut:"Ctrl+C",action:o=>{o.grid?.plugins?.clipboard?.copy?.()}},{separator:!0,id:"sep1",name:""},{id:"export-csv",name:"Export CSV",action:o=>{o.grid?.plugins?.export?.exportCsv?.()}}];class Ln extends T{name="contextMenu";version="1.0.0";get defaultConfig(){return{items:Ie}}isOpen=!1;position={x:0,y:0};params=null;menuElement=null;attach(e){super.attach(e),this.installGlobalHandlers(),Me++}detach(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null),this.isOpen=!1,this.params=null,this.uninstallGlobalHandlers()}installGlobalHandlers(){!V&&typeof document<"u"&&typeof ke=="string"&&ke&&(V=document.createElement("style"),V.id="tbw-context-menu-styles",V.textContent=ke,document.head.appendChild(V)),oe||(oe=()=>{document.querySelectorAll(".tbw-context-menu").forEach(t=>t.remove())},document.addEventListener("click",oe)),ne||(ne=e=>{e.key==="Escape"&&document.querySelectorAll(".tbw-context-menu").forEach(n=>n.remove())},document.addEventListener("keydown",ne))}uninstallGlobalHandlers(){Me--,!(Me>0)&&(oe&&(document.removeEventListener("click",oe),oe=null),ne&&(document.removeEventListener("keydown",ne),ne=null),V&&(V.remove(),V=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",n=>{const i=n;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],f=this.rows[d];a={row:f,rowIndex:d,column:h,columnIndex:u,field:h?.field??"",value:f?.[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=Le(this.config.items??Ie,a);c.length&&(this.menuElement&&this.menuElement.remove(),this.menuElement=Pe(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),Pt(this.menuElement,i.clientX,i.clientY),this.isOpen=!0,this.emit("context-menu-open",{params:a,items:c}))}))}showMenu(e,t,n){const i={row:n.row??null,rowIndex:n.rowIndex??-1,column:n.column??null,columnIndex:n.columnIndex??-1,field:n.field??"",value:n.value??null,isHeader:n.isHeader??!1,event:n.event??new MouseEvent("contextmenu")},r=Le(this.config.items??Ie,i);this.menuElement&&this.menuElement.remove(),this.menuElement=Pe(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),Pt(this.menuElement,e,t),this.isOpen=!0}hideMenu(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null,this.isOpen=!1)}isMenuOpen(){return this.isOpen}}function Mt(o,e=!0){if(o==null)return"";if(o instanceof Date)return o.toISOString();if(typeof o=="object")return JSON.stringify(o);const t=String(o);return e&&(t.includes(",")||t.includes('"')||t.includes(`
|
|
39
|
-
`)||t.includes("\r"))?`"${t.replace(/"/g,'""')}"`:t}function
|
|
40
|
-
`,s=[],l=
|
|
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 vt(){try{return await navigator.clipboard.readText()}catch{return""}}class sn extends S{name="clipboard";version="1.0.0";get defaultConfig(){return{includeHeaders:!1,delimiter:" ",newline:`
|
|
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=ye({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}Ce(a).then(()=>{this.lastCopied={text:a,timestamp:Date.now()},this.emit("copy",{text:a,rowCount:c,columnCount:d})})}#s(){vt().then(e=>{if(!e)return;const t=bt(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??`
|
|
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 wn(n,e,t,o={}){const i=o.delimiter??",",r=o.newline??`
|
|
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 At(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)),At(u)});s.push(c.join(i))}return l+s.join(r)}function Te(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 bn(n,e){const t=new Blob([n],{type:"text/csv;charset=utf-8;"});Te(t,e)}function Tt(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function vn(n,e,t){let o=`<?xml version="1.0" encoding="UTF-8"?>
|
|
41
53
|
<?mso-application progid="Excel.Sheet"?>
|
|
42
54
|
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
|
|
43
55
|
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
|
|
44
56
|
<Worksheet ss:Name="Sheet1">
|
|
45
|
-
<Table>`;if(t.includeHeaders!==!1){
|
|
46
|
-
<Row>`;for(const i of e){const r=i.header||i.field,s=t.processHeader?t.processHeader(r,i.field):r;
|
|
47
|
-
<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=
|
|
57
|
+
<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">${Tt(s)}</Data></Cell>`}o+="</Row>"}for(const i of n){o+=`
|
|
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=Tt(String(s)),o+=`<Cell><Data ss:Type="${l}">${a}</Data></Cell>`}o+="</Row>"}return o+=`
|
|
48
60
|
</Table>
|
|
49
61
|
</Worksheet>
|
|
50
|
-
</Workbook>`,n}function Hn(o,e){const t=e.endsWith(".xls")?e:`${e}.xls`,n=new Blob([o],{type:"application/vnd.ms-excel;charset=utf-8;"});He(n,t)}class Dn extends T{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 n=this.config,i={format:e,fileName:t?.fileName??n.fileName??"export",includeHeaders:t?.includeHeaders??n.includeHeaders,processCell:t?.processCell,processHeader:t?.processHeader,columns:t?.columns,rowIndices:t?.rowIndices};let r=[...this.columns];if(n.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(n.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=Pn(s,r,i,{bom:!0});l=l.endsWith(".csv")?l:`${l}.csv`,Mn(a,l);break}case"excel":{const a=In(s,r,i);l=l.endsWith(".xls")?l:`${l}.xls`,Hn(a,l);break}case"json":{const a=s.map(u=>{const h={};for(const f of r){let p=u[f.field];i.processCell&&(p=i.processCell(p,f.field,u)),h[f.field]=p}return h}),c=JSON.stringify(a,null,2);l=l.endsWith(".json")?l:`${l}.json`;const d=new Blob([c],{type:"application/json"});He(d,l);break}}this.lastExportInfo={format:e,timestamp:new Date},this.emit("export-complete",{format:e,fileName:l,rowCount:s.length,columnCount:r.length})}finally{this.isExportingFlag=!1}}getSelectionState(){try{return this.grid?.getPluginState?.("selection")??null}catch{return null}}exportCsv(e){this.performExport("csv",e)}exportExcel(e){this.performExport("excel",e)}exportJson(e){this.performExport("json",e)}isExporting(){return this.isExportingFlag}getLastExport(){return this.lastExportInfo}}function On(o){const{totalRows:e,viewportHeight:t,scrollTop:n,rowHeight:i,overscan:r}=o,s=Math.ceil(t/i);let l=Math.floor(n/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 Nn(o,e){return o<=e}function Fn(o,e,t=!1){const n=o[e.field];if(e.operator==="blank")return n==null||n==="";if(e.operator==="notBlank")return n!=null&&n!=="";if(n==null)return!1;const i=String(n),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(n)<Number(e.value);case"lessThanOrEqual":return Number(n)<=Number(e.value);case"greaterThan":return Number(n)>Number(e.value);case"greaterThanOrEqual":return Number(n)>=Number(e.value);case"between":return Number(n)>=Number(e.value)&&Number(n)<=Number(e.valueTo);case"in":return Array.isArray(e.value)&&e.value.includes(n);case"notIn":return Array.isArray(e.value)&&!e.value.includes(n);default:return!0}}function qn(o,e,t=!1){return e.length?o.filter(n=>e.every(i=>Fn(n,i,t))):o}function zn(o){return JSON.stringify(o.map(e=>({field:e.field,operator:e.operator,value:e.value,valueTo:e.valueTo})))}function Ht(o,e){const t=new Set;for(const n of o){const i=n[e];i!=null&&t.add(i)}return[...t].sort((n,i)=>typeof n=="number"&&typeof i=="number"?n-i:String(n).localeCompare(String(i)))}const Bn=':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)}.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%}.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}.tbw-filter-btn:hover,.tbw-filter-btn.active{opacity:1}.tbw-filter-btn.active{color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6))}',Vn=".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 K extends T{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 n=zn(t);if(this.cacheKey===n&&this.cachedResult)return this.cachedResult;const i=qn([...e],t,this.config.caseSensitive);return this.cachedResult=i,this.cacheKey=n,i}afterRender(){const e=this.shadowRoot;if(!e)return;e.querySelectorAll('[part~="header-cell"]').forEach(n=>{const i=n.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=n.querySelector(".tbw-filter-btn");if(a){a.classList.toggle("active",l),n.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"),n.classList.add("filtered")),a.addEventListener("click",c=>{c.stopPropagation(),this.toggleFilterPanel(s,r,a)}),n.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 Ht(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=Vn,document.head.appendChild(e),this.globalStylesInjected=!0}toggleFilterPanel(e,t,n){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,n),this.setupPanelCloseHandler(i,n),this.config.valuesHandler(e,t).then(s=>{this.openPanelField!==e||!this.panelElement||(i.innerHTML="",this.renderPanelContent(e,t,i,s))});return}const r=Ht(this.sourceRows,e);this.renderPanelContent(e,t,i,r),document.body.appendChild(i),this.positionPanel(i,n),this.setupPanelCloseHandler(i,n)}renderPanelContent(e,t,n,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(n,l),a=n.children.length>0),a||this.renderDefaultFilterPanel(n,l,i,r)}setupPanelCloseHandler(e,t){this.panelAbortController=new AbortController,setTimeout(()=>{document.addEventListener("click",n=>{!e.contains(n.target)&&n.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 n=t.getBoundingClientRect();e.style.position="fixed",e.style.top=`${n.bottom+4}px`,e.style.left=`${n.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=`${n.top-i.height-4}px`)})}renderDefaultFilterPanel(e,t,n,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()],R=b.every(_=>_),E=b.every(_=>!_);d.checked=R,d.indeterminate=!R&&!E};d.addEventListener("change",()=>{const b=d.checked;for(const R of w.keys())w.set(R,b);h(),x()}),e.appendChild(a);const f=document.createElement("div");f.className="tbw-filter-values";const p=document.createElement("div");p.className="tbw-filter-values-spacer",f.appendChild(p);const g=document.createElement("div");g.className="tbw-filter-values-content",f.appendChild(g);const w=new Map;n.forEach(b=>{const R=b==null?"__null__":String(b);w.set(R,!i.has(b))}),h();let m=[];const C=(b,R)=>{const E=b==null?"(Blank)":String(b),_=b==null?"__null__":String(b),L=document.createElement("label");L.className="tbw-filter-value-item",L.style.position="absolute",L.style.top=`${R*K.LIST_ITEM_HEIGHT}px`,L.style.left="0",L.style.right="0",L.style.height=`${K.LIST_ITEM_HEIGHT}px`,L.style.boxSizing="border-box";const z=document.createElement("input");z.type="checkbox",z.className="tbw-filter-checkbox",z.checked=w.get(_)??!0,z.dataset.value=_,z.addEventListener("change",()=>{w.set(_,z.checked),h()});const so=document.createElement("span");return so.textContent=E,L.appendChild(z),L.appendChild(so),L},x=()=>{const b=m.length,R=f.clientHeight,E=f.scrollTop;if(p.style.height=`${b*K.LIST_ITEM_HEIGHT}px`,Nn(b,K.LIST_BYPASS_THRESHOLD/3)){g.innerHTML="",g.style.transform="translateY(0px)",m.forEach((L,z)=>{g.appendChild(C(L,z))});return}const _=On({totalRows:b,viewportHeight:R,scrollTop:E,rowHeight:K.LIST_ITEM_HEIGHT,overscan:K.LIST_OVERSCAN});g.style.transform=`translateY(${_.offsetY}px)`,g.innerHTML="";for(let L=_.start;L<_.end;L++)g.appendChild(C(m[L],L-_.start))},v=b=>{const R=b.toLowerCase();if(m=n.filter(E=>{const _=E==null?"(Blank)":String(E);return!b||_.toLowerCase().includes(R)}),m.length===0){p.style.height="0px",g.innerHTML="";const E=document.createElement("div");E.className="tbw-filter-no-match",E.textContent="No matching values",g.appendChild(E);return}x()};f.addEventListener("scroll",()=>{m.length>0&&x()},{passive:!0}),v(l.value),e.appendChild(f);let S;l.addEventListener("input",()=>{clearTimeout(S),S=setTimeout(()=>{this.searchText.set(r,l.value),v(l.value)},this.config.debounceMs??150)});const k=document.createElement("div");k.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[R,E]of w)if(!E)if(R==="__null__")b.push(null);else{const _=n.find(L=>String(L)===R);b.push(_!==void 0?_:R)}t.applySetFilter(b)}),k.appendChild(q);const A=document.createElement("button");A.className="tbw-filter-clear-btn",A.textContent="Clear Filter",A.addEventListener("click",()=>{t.clearFilter()}),k.appendChild(A),e.appendChild(k)}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,n,i){this.filters.set(e,{field:e,type:"text",operator:t,value:n,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 n=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()};n&&typeof n.then=="function"?n.then(i):i(n);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 n={field:e,type:t.filter.type,operator:t.filter.operator,value:t.filter.value,valueTo:t.filter.valueTo};this.filters.set(e,n),this.cachedResult=null,this.cacheKey=null}styles=Bn}function Kn(o){if(!o.length)return[];const e=new Map,t=[],n=(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 o.forEach((s,l)=>{const a=s.group;if(!a){i.length===0&&(r=l),i.push(s);return}i.length&&(n(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&&n(r,i),t.length===1&&t[0].implicit&&t[0].columns.length===o.length?[]:t}function Gn(o,e,t){if(!e.length||!o)return;const n=new Map;for(const r of e)for(const s of r.columns)s?.field&&n.set(s.field,r.id);const i=Array.from(o.querySelectorAll(".cell[data-field]"));i.forEach(r=>{const s=r.getAttribute("data-field")||"",l=n.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 Wn(o,e){if(o.length===0)return null;const t=document.createElement("div");t.className="header-group-row",t.setAttribute("role","row");for(const n of o){const i=n.firstIndex!=null?n.firstIndex:e.findIndex(a=>n.columns.includes(a)),r=String(n.id).startsWith("__implicit__"),s=r?"":n.label||n.id,l=document.createElement("div");l.className="cell header-group-cell",r&&l.classList.add("implicit-group"),l.setAttribute("data-group",String(n.id)),l.style.gridColumn=`${i+1} / span ${n.columns.length}`,l.textContent=s,t.appendChild(l)}return t}function $n(o){return o.some(e=>e.group!=null)}const Un=".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 jn extends T{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 n=t?.columns;return Array.isArray(n)?$n(n):!1}processColumns(e){const t=this.grid?.gridConfig?.columnGroups;let n;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});n=e.map(s=>{const l=r.get(s.field);return l&&!s.group?{...s,group:l}:s})}else n=[...e];const i=Kn(n);return i.length===0?(this.isActive=!1,this.groups=[],n):(this.isActive=!0,this.groups=i,n)}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 n=Wn(this.groups,this.columns);if(n){n.classList.toggle("no-borders",!this.config.showGroupBorders);const r=e.querySelector(".header-row");r?e.insertBefore(n,r):e.appendChild(n)}const i=e.querySelector(".header-row");i&&(i.classList.toggle("no-group-borders",!this.config.showGroupBorders),Gn(i,this.groups,this.columns))}isGroupingActive(){return this.isActive}getGroups(){return this.groups}getGroupColumns(e){const t=this.groups.find(n=>n.id===e);return t?t.columns:[]}refresh(){this.requestRender()}styles=Un}const De={sum:(o,e)=>o.reduce((t,n)=>t+(Number(n[e])||0),0),avg:(o,e)=>{const t=o.reduce((n,i)=>n+(Number(i[e])||0),0);return o.length?t/o.length:0},count:o=>o.length,min:(o,e)=>Math.min(...o.map(t=>Number(t[e])||1/0)),max:(o,e)=>Math.max(...o.map(t=>Number(t[e])||-1/0)),first:(o,e)=>o[0]?.[e],last:(o,e)=>o[o.length-1]?.[e]},ue=new Map,O={register(o,e){ue.set(o,e)},unregister(o){ue.delete(o)},get(o){if(o!==void 0)return typeof o=="function"?o:ue.get(o)??De[o]},run(o,e,t,n){const i=this.get(o);return i?i(e,t,n):void 0},has(o){return ue.has(o)||o in De},list(){return[...Object.keys(De),...ue.keys()]}},Dt={sum:o=>o.reduce((e,t)=>e+t,0),avg:o=>o.length?o.reduce((e,t)=>e+t,0)/o.length:0,count:o=>o.length,min:o=>o.length?Math.min(...o):0,max:o=>o.length?Math.max(...o):0,first:o=>o[0]??0,last:o=>o[o.length-1]??0};function Xn(o){return Dt[o]??Dt.sum}O.register.bind(O),O.unregister.bind(O);const Ot=O.get.bind(O),Nt=O.run.bind(O);O.list.bind(O);function Yn({rows:o,config:e,expanded:t}){const n=e.groupOn;if(typeof n!="function")return[];const i={key:"__root__",value:null,depth:-1,rows:[],children:new Map};if(o.forEach(l=>{let a=n(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),f=c.key==="__root__"?h:c.key+"||"+h;let p=c.children.get(h);p||(p={key:f,value:d,depth:u,rows:[],children:new Map,parent:c},c.children.set(h,p)),c=p}),c.rows.push(l)}),i.children.size===1&&i.children.has("__ungrouped__")&&i.children.get("__ungrouped__").rows.length===o.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:o.indexOf(c)})))};return s(i),r}function Zn(o,e){const t=new Set(o);return t.has(e)?t.delete(e):t.add(e),t}function Jn(o){const e=new Set;for(const t of o)t.kind==="group"&&e.add(t.key);return e}function Qn(){return new Set}function ei(o){return o.kind!=="group"?0:o.rows.length}const ti='.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 oi extends T{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 n=this.shadowRoot?.host;if(n&&getComputedStyle(n).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 n=Yn({rows:e,config:t,expanded:this.expandedKeys});if(n.length===0)return this.isActive=!1,this.flattenedRows=[],[...e];this.isActive=!0,this.flattenedRows=n,this.keysToAnimate.clear();const i=new Set;return n.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,n.map(r=>r.kind==="group"?{__isGroupRow:!0,__groupKey:r.key,__groupValue:r.value,__groupDepth:r.depth,__groupRows:r.rows,__groupExpanded:r.expanded,__groupRowCount:ei(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,n){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 n=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(n),i.addEventListener("animationend",()=>i.classList.remove(n),{once:!0}))}this.keysToAnimate.clear()}renderFullWidthGroupRow(e,t,n){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(),n()}),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,n){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 f=document.createElement("button");f.type="button",f.className=`group-toggle${e.__groupExpanded?" expanded":""}`,f.setAttribute("aria-label",e.__groupExpanded?"Collapse group":"Expand group"),this.setIcon(f,this.resolveIcon(e.__groupExpanded?"collapse":"expand")),f.addEventListener("click",w=>{w.stopPropagation(),n()}),h.appendChild(f);const p=document.createElement("span"),g=r[d.field];if(g){const w=Nt(g,l,d.field,d);p.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);p.textContent=w}if(h.appendChild(p),i.showRowCount!==!1){const w=document.createElement("span");w.className="group-count",w.textContent=` (${l.length})`,h.appendChild(w)}}else{const f=r[d.field];if(f){const p=Nt(f,l,d.field,d);h.textContent=p!=null?String(p):""}else h.textContent=""}t.appendChild(h)})}expandAll(){this.expandedKeys=Jn(this.flattenedRows),this.requestRender()}collapseAll(){this.expandedKeys=Qn(),this.requestRender()}toggle(e){this.expandedKeys=Zn(this.expandedKeys,e);const t=this.flattenedRows.find(n=>n.kind==="group"&&n.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=ti}function Oe(o,e){const t=new Set(o);return t.has(e)?t.delete(e):t.add(e),t}function ni(o,e){const t=new Set(o);return t.add(e),t}function ii(o,e){const t=new Set(o);return t.delete(e),t}function ri(o,e){return o.has(e)}function si(o,e,t,n){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 / ${n+1}`;const s=t(o,e);return typeof s=="string"?r.innerHTML=s:s instanceof HTMLElement&&r.appendChild(s),i.appendChild(r),i}const li=".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 ai extends T{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 n=e;if(n.__frameworkAdapter?.parseDetailElement){const u=n.__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 f=ve(d,{value:u,row:u});return se(f)}),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 n=this.shadowRoot?.host;return n?getComputedStyle(n).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(),n=parseInt(t,10);if(!isNaN(n))return n}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 n=()=>{e.classList.remove("tbw-collapsing"),t()};e.addEventListener("animationend",n,{once:!0}),setTimeout(n,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 n={...t[0]},i=n.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"),u.addEventListener("click",f=>{f.stopPropagation();const p=this.rows.indexOf(a);this.expandedRows=Oe(this.expandedRows,a),this.emit("detail-expand",{rowIndex:p,row:a,expanded:this.expandedRows.has(a)}),this.requestRender()}),d.appendChild(u);const h=document.createElement("span");if(i){const f=i(s);f instanceof Node?h.appendChild(f):h.textContent=String(f??l??"")}else h.textContent=String(l??"");return d.appendChild(h),d};r.__masterDetailWrapped=!0,n.viewRenderer=r,t[0]=n}return t}onRowClick(e){if(!(!this.config.expandOnRowClick||!this.config.detailRenderer))return this.expandedRows=Oe(this.expandedRows,e.row),this.emit("detail-expand",{rowIndex:e.rowIndex,row:e.row,expanded:this.expandedRows.has(e.row)}),this.requestRender(),!1}onCellClick(){this.expandedRows.size>0&&queueMicrotask(()=>this.#n())}afterRender(){this.#n()}onScrollRender(){!this.config.detailRenderer||this.expandedRows.size===0||this.#n()}#n(){if(!this.config.detailRenderer)return;const e=this.shadowRoot?.querySelector(".rows");if(!e)return;const t=new Map,n=e.querySelectorAll(".data-grid-row"),i=this.columns.length;for(const s of n){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=si(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 n=this.detailElements.get(t);if(n)e+=n.offsetHeight;else{const i=this.config?.detailHeight;e+=typeof i=="number"?i:150}}return e}getExtraHeightBefore(e){let t=0;for(const n of this.expandedRows){const i=this.rows.indexOf(n);if(i>=0&&i<e){const r=this.detailElements.get(n);if(r)t+=r.offsetHeight;else{const s=this.config?.detailHeight;t+=typeof s=="number"?s:150}}}return t}adjustVirtualStart(e,t,n){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*n+s,u=this.detailElements.get(a)?.offsetHeight??(typeof this.config?.detailHeight=="number"?this.config.detailHeight:150),h=c+n+u;s+=u,!(l>=e)&&h>t&&l<r&&(r=l)}return r}expand(e){const t=this.rows[e];t&&(this.expandedRows=ni(this.expandedRows,t),this.requestRender())}collapse(e){const t=this.rows[e];t&&(this.expandedRows=ii(this.expandedRows,t),this.requestRender())}toggle(e){const t=this.rows[e];t&&(this.expandedRows=Oe(this.expandedRows,t),this.requestRender())}isExpanded(e){const t=this.rows[e];return t?ri(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 n=this.rows.indexOf(t);n>=0&&e.push(n)}return e}getDetailElement(e){const t=this.rows[e];return t?this.detailElements.get(t):void 0}refreshDetailRenderer(){const e=this.config.detailRenderer;this.config={...this.config,detailRenderer:void 0},this.parseLightDomDetail(),!this.config.detailRenderer&&e&&(this.config={...this.config,detailRenderer:e})}styles=li}function ci(o,e,t){return e.length?[...o].sort((n,i)=>{for(const r of e){const l=t.find(u=>u.field===r.field)?.sortComparator??di,a=n[r.field],c=i[r.field],d=l(a,c,n,i);if(d!==0)return r.direction==="asc"?d:-d}return 0}):[...o]}function di(o,e){return o==null&&e==null?0:o==null?1:e==null?-1:typeof o=="number"&&typeof e=="number"?o-e:o instanceof Date&&e instanceof Date?o.getTime()-e.getTime():typeof o=="boolean"&&typeof e=="boolean"?o===e?0:o?-1:1:String(o).localeCompare(String(e))}function ui(o,e,t,n){const i=o.find(r=>r.field===e);return t?i?i.direction==="asc"?o.map(r=>r.field===e?{...r,direction:"desc"}:r):o.filter(r=>r.field!==e):o.length<n?[...o,{field:e,direction:"asc"}]:o:i?.direction==="asc"?[{field:e,direction:"desc"}]:i?.direction==="desc"?[]:[{field:e,direction:"asc"}]}function Ft(o,e){const t=o.findIndex(n=>n.field===e);return t>=0?t+1:void 0}function qt(o,e){return o.find(t=>t.field===e)?.direction}const hi='.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 fi extends T{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]:ci([...e],this.sortModel,[...this.columns])}onHeaderClick(e){if(!this.columns.find(r=>r.field===e.field)?.sortable)return!1;const n=e.originalEvent.shiftKey,i=this.config.maxSortColumns??3;return this.sortModel=ui(this.sortModel,e.field,n,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=Ft(this.sortModel,r),l=qt(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");if(d.className="sort-indicator",this.setIcon(d,this.resolveIcon(l==="asc"?"sortAsc":"sortDesc")),i.appendChild(d),t&&this.sortModel.length>1&&s!==void 0){const u=document.createElement("span");u.className="sort-index",u.textContent=String(s),i.appendChild(u)}}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 Ft(this.sortModel,e)}getSortDirection(e){return qt(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 n=this.sortModel.findIndex(r=>r.field===e),i={field:e,direction:t.sort.direction};n!==-1?this.sortModel[n]=i:this.sortModel.splice(t.sort.priority,0,i)}styles=hi}function pi(o){return o.filter(e=>e.sticky==="left")}function gi(o){return o.filter(e=>e.sticky==="right")}function Ne(o){return o.some(e=>e.sticky==="left"||e.sticky==="right")}function zt(o,e){const t=o.shadowRoot;if(!t)return;const n=Array.from(t.querySelectorAll(".header-row .cell"));if(!n.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=n.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=n.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 Bt(o){const e=o.shadowRoot;if(!e)return;e.querySelectorAll(".sticky-left, .sticky-right").forEach(n=>{n.classList.remove("sticky-left","sticky-right"),n.style.position="",n.style.left="",n.style.right=""})}class wi extends T{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 n=t?.columns;return Array.isArray(n)?Ne(n):!1}processColumns(e){return this.isApplied=Ne([...e]),[...e]}afterRender(){if(!this.isApplied)return;const e=this.grid,t=[...this.columns];if(!Ne(t)){Bt(e),this.isApplied=!1;return}queueMicrotask(()=>{zt(e,t)})}onPluginQuery(e){switch(e.type){case ce.CAN_MOVE_COLUMN:{const t=e.context,n=t.sticky;if(n==="left"||n==="right")return!1;const i=t.meta?.sticky;return i==="left"||i==="right"?!1:void 0}default:return}}refreshStickyOffsets(){const e=[...this.columns];zt(this.grid,e)}getLeftPinnedColumns(){const e=[...this.columns];return pi(e)}getRightPinnedColumns(){const e=[...this.columns];return gi(e)}clearStickyPositions(){Bt(this.grid)}getHorizontalScrollOffsets(e,t){if(!this.isApplied)return;let n=0,i=0;if(e){const s=e.querySelectorAll(".sticky-left"),l=e.querySelectorAll(".sticky-right");s.forEach(a=>{n+=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")?n+=c.offsetWidth:c.classList.contains("sticky-right")&&(i+=c.offsetWidth)})}const r=t?.classList.contains("sticky-left")||t?.classList.contains("sticky-right");return{left:n,right:i,skipScroll:r}}}function mi(o){return typeof o=="object"&&o!==null&&"aggFunc"in o}function Fe(o,e){const t=document.createElement("div");t.className="tbw-pinned-rows",t.setAttribute("role","presentation"),t.setAttribute("aria-live","polite");const n=document.createElement("div");n.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",o.showRowCount!==!1){const s=document.createElement("span");s.className="tbw-status-panel tbw-status-panel-row-count",s.textContent=`Total: ${e.totalRows} rows`,n.appendChild(s)}if(o.showFilteredCount&&e.filteredRows!==e.totalRows){const s=document.createElement("span");s.className="tbw-status-panel tbw-status-panel-filtered-count",s.textContent=`Filtered: ${e.filteredRows}`,n.appendChild(s)}if(o.showSelectedCount&&e.selectedRows>0){const s=document.createElement("span");s.className="tbw-status-panel tbw-status-panel-selected-count",s.textContent=`Selected: ${e.selectedRows}`,r.appendChild(s)}if(o.customPanels)for(const s of o.customPanels){const l=bi(s,e);switch(s.position){case"left":n.appendChild(l);break;case"center":i.appendChild(l);break;case"right":r.appendChild(l);break}}return t.appendChild(n),t.appendChild(i),t.appendChild(r),t}function Vt(o){const e=document.createElement("div");return e.className=`tbw-aggregation-rows tbw-aggregation-rows-${o}`,e.setAttribute("role","presentation"),e}function Kt(o,e,t,n){o.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(mi(d)){const u=Ot(d.aggFunc);u&&(a=u(n,s.field,s)),c=d.formatter}else{const u=Ot(d);u&&(a=u(n,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(n,s.field,s):a=u}a!=null?l.textContent=c?c(a,s.field,s):String(a):l.textContent="",r.appendChild(l)}o.appendChild(r)}}function bi(o,e){const t=document.createElement("div");t.className="tbw-status-panel tbw-status-panel-custom",t.id=`status-panel-${o.id}`;const n=o.render(e);return typeof n=="string"?t.innerHTML=n:t.appendChild(n),t}function Gt(o,e,t,n,i){return{totalRows:o.length,filteredRows:i?.cachedResult?.length??o.length,selectedRows:n?.selected?.size??0,columns:e,rows:o,grid:t}}const vi=".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 yi extends T{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;const n=this.getSelectionState(),i=this.getFilterState(),r=Gt(this.rows,this.columns,this.grid,n,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=Vt("top");const h=e.querySelector(".header");h&&h.nextSibling?t.insertBefore(this.topAggregationContainer,h.nextSibling):t.appendChild(this.topAggregationContainer)}Kt(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=Fe(this.config,r),t.insertBefore(this.infoBarElement,t.firstChild);else{const h=Fe(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=Vt("bottom")),this.footerWrapper.appendChild(this.bottomAggregationContainer),Kt(this.bottomAggregationContainer,a,this.visibleColumns,this.rows)),d&&(this.infoBarElement=Fe(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 Gt(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=vi}const Ci=Xn;function xi(o){const e=[];return!o.rowGroupFields?.length&&!o.columnGroupFields?.length&&e.push("At least one row or column group field is required"),o.valueFields?.length||e.push("At least one value field is required"),e}function qe(o,e){return[...o,e].join("|")}function Ei(o,e){const t=e.rowGroupFields??[],n=e.columnGroupFields??[],i=e.valueFields??[],r=Ri(o,n),s=Wt(o,t,n,r,i,0,""),l=Si(s,r,i),a=Object.values(l).reduce((c,d)=>c+d,0);return{rows:s,columnKeys:r,totals:l,grandTotal:a}}function Ri(o,e){if(e.length===0)return["value"];const t=new Set;for(const n of o){const i=e.map(r=>String(n[r]??"")).join("|");t.add(i)}return[...t].sort()}function _i(o,e){const t=new Map;for(const n of o){const i=String(n[e]??""),r=t.get(i);r?r.push(n):t.set(i,[n])}return t}function Wt(o,e,t,n,i,r,s){const l=[];if(e.length===0){const h=$t(o,t,n,i),f=Ut(h);return l.push({rowKey:s||"all",rowLabel:s||"All",depth:r,values:h,total:f,isGroup:!1,rowCount:o.length}),l}const a=e[0],c=e.slice(1),d=c.length>0,u=_i(o,a);for(const[h,f]of u){const p=s?`${s}|${h}`:h,g=$t(f,t,n,i),w=Ut(g);let m;d&&(m=Wt(f,c,t,n,i,r+1,p)),l.push({rowKey:p,rowLabel:h||"(blank)",depth:r,values:g,total:w,isGroup:d,children:m,rowCount:f.length})}return l}function $t(o,e,t,n){const i={};for(const r of t)for(const s of n){const a=(e.length>0?o.filter(h=>e.map(f=>String(h[f]??"")).join("|")===r):o).map(h=>Number(h[s.field])||0),c=Ci(s.aggFunc),d=a.length>0?c(a):null,u=qe([r],s.field);i[u]=d}return i}function Ut(o){let e=0;for(const t of Object.values(o))e+=t??0;return e}function Si(o,e,t){const n={};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=qe([l],a.field);n[c]=(n[c]??0)+(s.values[c]??0)}else s.children&&i(s.children)}return i(o),n}function Ai(o,e,t=!0){const n=[];function i(r){n.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 o)i(r);return n}function ze(o){const e=[];function t(n){if(n.isGroup&&e.push(n.rowKey),n.children)for(const i of n.children)t(i)}for(const n of o)t(n);return e}const Ti=["sum","avg","count","min","max","first","last"];function ki(o,e,t,n){const i=new AbortController,r={config:e,callbacks:n,signal:i.signal},s=document.createElement("div");return s.className="tbw-pivot-panel",s.appendChild(he("Options",()=>Hi(t,r))),s.appendChild(he("Row Groups",()=>jt("rowGroups",r))),s.appendChild(he("Column Groups",()=>jt("columnGroups",r))),s.appendChild(he("Values",()=>Pi(r))),s.appendChild(he("Available Fields",()=>Ii(r))),o.appendChild(s),()=>{i.abort(),s.remove()}}function he(o,e){const t=document.createElement("div");t.className="tbw-pivot-section";const n=document.createElement("div");n.className="tbw-pivot-section-header",n.textContent=o;const i=document.createElement("div");return i.className="tbw-pivot-section-content",i.appendChild(e()),t.appendChild(n),t.appendChild(i),t}function jt(o,e){const{config:t,callbacks:n,signal:i}=e,r=document.createElement("div");r.className="tbw-pivot-drop-zone",r.setAttribute("data-zone",o);const s=o==="rowGroups"?t.rowGroupFields??[]:t.columnGroupFields??[];if(s.length===0){const l=document.createElement("div");l.className="tbw-pivot-placeholder",l.textContent="Drag fields here or click to add",r.appendChild(l)}else for(const l of s)r.appendChild(Li(l,o,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&&n.onAddFieldToZone(a,o)},{signal:i}),r}function Li(o,e,t){const{callbacks:n,signal:i}=t,r=document.createElement("div");r.className="tbw-pivot-field-chip",r.draggable=!0;const s=n.getAvailableFields().find(c=>c.field===o),l=document.createElement("span");l.className="tbw-pivot-chip-label",l.textContent=s?.header??o;const a=document.createElement("button");return a.className="tbw-pivot-chip-remove",a.innerHTML="×",a.title="Remove field",a.addEventListener("click",c=>{c.stopPropagation(),n.onRemoveFieldFromZone(o,e)},{signal:i}),r.appendChild(l),r.appendChild(a),r.addEventListener("dragstart",c=>{c.dataTransfer?.setData("text/plain",o),c.dataTransfer?.setData("source-zone",e),r.classList.add("dragging")},{signal:i}),r.addEventListener("dragend",()=>{r.classList.remove("dragging")},{signal:i}),r}function Pi(o){const{config:e,callbacks:t,signal:n}=o,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(Mi(s,o));return i.addEventListener("dragover",s=>{s.preventDefault(),i.classList.add("drag-over")},{signal:n}),i.addEventListener("dragleave",()=>{i.classList.remove("drag-over")},{signal:n}),i.addEventListener("drop",s=>{s.preventDefault(),i.classList.remove("drag-over");const l=s.dataTransfer?.getData("text/plain");l&&t.onAddValueField(l,"sum")},{signal:n}),i}function Mi(o,e){const{callbacks:t,signal:n}=e,i=document.createElement("div");i.className="tbw-pivot-field-chip tbw-pivot-value-chip";const r=t.getAvailableFields().find(d=>d.field===o.field),s=document.createElement("div");s.className="tbw-pivot-value-label-wrapper";const l=document.createElement("span");l.className="tbw-pivot-chip-label",l.textContent=r?.header??o.field;const a=document.createElement("select");a.className="tbw-pivot-agg-select",a.title="Aggregation function";for(const d of Ti){const u=document.createElement("option");u.value=d,u.textContent=d.toUpperCase(),u.selected=d===o.aggFunc,a.appendChild(u)}a.addEventListener("change",()=>{t.onUpdateValueAggFunc(o.field,a.value)},{signal:n});const c=document.createElement("button");return c.className="tbw-pivot-chip-remove",c.innerHTML="×",c.title="Remove value field",c.addEventListener("click",d=>{d.stopPropagation(),t.onRemoveValueField(o.field)},{signal:n}),s.appendChild(l),s.appendChild(a),i.appendChild(s),i.appendChild(c),i}function Ii(o){const{config:e,callbacks:t,signal:n}=o,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:n}),c.addEventListener("dragend",()=>{c.classList.remove("dragging")},{signal:n}),i.appendChild(c)}return i}function Hi(o,e){const{config:t,callbacks:n,signal:i}=e,r=document.createElement("div");return r.className="tbw-pivot-options",r.appendChild(Be("Enable Pivot View",o,s=>{n.onTogglePivot(s)},i)),r.appendChild(Be("Show Row Totals",t.showTotals??!0,s=>{n.onOptionChange("showTotals",s)},i)),r.appendChild(Be("Show Grand Total",t.showGrandTotal??!0,s=>{n.onOptionChange("showGrandTotal",s)},i)),r}function Be(o,e,t,n){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:n});const s=document.createElement("span");return s.textContent=o,i.appendChild(r),i.appendChild(s),i}function Di(o,e,t){return e.className="pivot-group-row",e.setAttribute("data-pivot-depth",String(o.__pivotDepth??0)),e.setAttribute("data-pivot-key",String(o.__pivotRowKey??"")),e.setAttribute("role","row"),e.innerHTML="",t.columns.forEach((n,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(o.__pivotIndent)||0;r.style.paddingLeft=`${s}px`;const l=String(o.__pivotRowKey),a=document.createElement("button");a.type="button",a.className="pivot-toggle",a.setAttribute("aria-label",o.__pivotExpanded?"Collapse group":"Expand group"),t.setIcon(a,t.resolveIcon(o.__pivotExpanded?"collapse":"expand")),a.addEventListener("click",u=>{u.stopPropagation(),t.onToggle(l)}),r.appendChild(a);const c=document.createElement("span");c.className="pivot-label",c.textContent=String(o.__pivotLabel??""),r.appendChild(c);const d=document.createElement("span");d.className="pivot-count",d.textContent=` (${Number(o.__pivotRowCount)||0})`,r.appendChild(d)}else{const s=o[n.field];r.textContent=s!=null?String(s):""}e.appendChild(r)}),!0}function Oi(o,e,t){return e.className="pivot-leaf-row",e.setAttribute("data-pivot-depth",String(o.__pivotDepth??0)),e.setAttribute("data-pivot-key",String(o.__pivotRowKey??"")),e.innerHTML="",t.forEach((n,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(o.__pivotIndent)||0;r.style.paddingLeft=`${s+20}px`;const l=document.createElement("span");l.className="pivot-label",l.textContent=String(o.__pivotLabel??""),r.appendChild(l)}else{const s=o[n.field];r.textContent=s!=null?String(s):""}e.appendChild(r)}),!0}function Ni(o,e,t){return e.className="pivot-grand-total-row",e.setAttribute("role","presentation"),e.innerHTML="",t.forEach((n,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=o[n.field];r.textContent=s!=null?String(s):""}e.appendChild(r)}),!0}const Fi='.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 ie extends T{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 n=this.shadowRoot?.host;if(n&&getComputedStyle(n).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:ie.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=xi(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=ze(this.pivotResult.rows);for(const l of s)this.expandedKeys.add(l)}if(this.pivotResult=Ei(e,this.config),this.expandedKeys.size===0&&this.defaultExpanded){const s=ze(this.pivotResult.rows);for(const l of s)this.expandedKeys.add(l)}const n=this.config.indentWidth??20,i=Ai(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*n,__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=[],n=(this.config.rowGroupFields??[]).map(i=>this.fieldHeaderMap.get(i)??i).join(" / ");t.push({field:"__pivotLabel",header:n||"Group",width:200});for(const i of this.pivotResult.columnKeys)for(const r of this.config.valueFields??[]){const s=qe([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 n=e;return n.__pivotRowKey&&n.__pivotHasChildren?Di(n,t,{columns:this.gridColumns,onToggle:i=>this.toggle(i),resolveIcon:i=>this.resolveIcon(i),setIcon:(i,r)=>this.setIcon(i,r)}):n.__pivotRowKey!==void 0&&this.isActive?Oi(n,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 n=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(n),i.addEventListener("animationend",()=>i.classList.remove(n),{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 n={__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals};Ni(n,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=ze(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(ie.PANEL_ID)}hidePanel(){this.grid.closeToolPanel()}togglePanel(){this.grid.toggleToolPanel(ie.PANEL_ID)}isPanelVisible(){return this.grid.activeToolPanel===ie.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(n=>!n.field.startsWith("__pivot")).map(n=>({field:n.field,header:n.header??n.field})),this.originalColumns}catch{return[]}}renderPanel(e){this.panelContainer=e,this.originalColumns.length===0&&this.captureOriginalColumns();const t={onTogglePivot:n=>{n?this.enablePivot():this.disablePivot(),this.refreshPanel()},onAddFieldToZone:(n,i)=>this.addFieldToZone(n,i),onRemoveFieldFromZone:(n,i)=>this.removeFieldFromZone(n,i),onAddValueField:(n,i)=>this.addValueField(n,i),onRemoveValueField:n=>this.removeValueField(n),onUpdateValueAggFunc:(n,i)=>this.updateValueAggFunc(n,i),onOptionChange:(n,i)=>{this.config[n]=i,this.isActive&&this.refresh()},getAvailableFields:()=>this.getAvailableFields()};return ki(e,this.config,this.isActive,t)}refreshPanel(){this.panelContainer&&(this.panelContainer.innerHTML="",this.renderPanel(this.panelContainer))}addFieldToZone(e,t){if(t==="rowGroups"){const n=this.config.rowGroupFields??[];n.includes(e)||(this.config.rowGroupFields=[...n,e])}else{const n=this.config.columnGroupFields??[];n.includes(e)||(this.config.columnGroupFields=[...n,e])}this.removeFromOtherZones(e,t),this.isActive&&this.refresh(),this.refreshPanel()}removeFieldFromZone(e,t){t==="rowGroups"?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(n=>n!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(n=>n!==e),this.isActive&&this.refresh(),this.refreshPanel()}removeFromOtherZones(e,t){t!=="rowGroups"&&(this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(n=>n!==e)),t!=="columnGroups"&&(this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(n=>n!==e)),t!=="values"&&(this.config.valueFields=(this.config.valueFields??[]).filter(n=>n.field!==e))}addValueField(e,t){const n=this.config.valueFields??[];n.some(i=>i.field===e)||(this.config.valueFields=[...n,{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 n=this.config.valueFields??[],i=n.findIndex(r=>r.field===e);i>=0&&(n[i]={...n[i],aggFunc:t},this.config.valueFields=[...n]),this.isActive&&this.refresh()}styles=Fi}function Xt(o){const e=o.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}function Yt(o,e,t){if(e===t||e<0||e>=o.length||t<0||t>o.length)return o;const n=[...o],[i]=n.splice(e,1);return n.splice(t,0,i),n}const qi='.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 zi extends T{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 n=this.shadowRoot?.host;return n?getComputedStyle(n).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(),n=parseInt(t,10);if(!isNaN(n))return n}return 200}isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;attach(e){super.attach(e),e.addEventListener("column-reorder-request",t=>{const n=t.detail;n?.field&&typeof n.toIndex=="number"&&this.moveColumn(n.field,n.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(n=>{const i=n,r=i.getAttribute("data-field");if(!r)return;const s=this.columns.find(d=>d.field===r),c=!this.grid.queryPlugins({type:ce.CAN_MOVE_COLUMN,context:s}).includes(!1);if(!s||!Xt(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,p=this.getColumnOrder().indexOf(r);this.dropIndex=d.clientX<h?p:p+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,f=this.dropIndex;if(!this.isDragging||u===null||h===null||f===null)return;const p=f>h?f-1:f,g=this.getColumnOrder(),w=Yt(g,h,p),m={field:u,fromIndex:h,toIndex:p,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,n=t._focusCol,i=t._visibleColumns;if(n<0||n>=i.length)return;const r=i[n];if(!r||!Xt(r))return;const s=this.grid;if(s.queryPlugins({type:ce.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:ce.CAN_MOVE_COLUMN,context:u}).includes(!1)))return this.moveColumn(r.field,d),t._focusCol=d,N(this.grid),e.preventDefault(),e.stopPropagation(),!0}getColumnOrder(){return this.grid.getColumnOrder()}moveColumn(e,t){const n=this.getColumnOrder(),i=n.indexOf(e);if(i===-1)return;const r=Yt(n,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 n=t.getAttribute("data-field");n&&e.set(n,t.getBoundingClientRect().left)}),e}animateFLIP(e){const t=this.shadowRoot;if(!t||e.size===0)return;const n=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&&n.set(l,c)}),n.size===0)return;const i=[];if(t.querySelectorAll(".cell[data-field]").forEach(s=>{const l=n.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 n=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=n.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,n=this.animationType;if(n==="flip"&&this.shadowRoot){const i=this.captureHeaderPositions();t.setColumnOrder(e),this.shadowRoot.host.offsetHeight,this.animateFLIP(i)}else n==="fade"?this.animateFade(()=>t.setColumnOrder(e)):t.setColumnOrder(e);t.requestStateChange?.()}styles=qi}function me(o){return{startRow:Math.min(o.startRow,o.endRow),startCol:Math.min(o.startCol,o.endCol),endRow:Math.max(o.startRow,o.endRow),endCol:Math.max(o.startCol,o.endCol)}}function Bi(o){const e=me(o);return{from:{row:e.startRow,col:e.startCol},to:{row:e.endRow,col:e.endCol}}}function Ve(o){return o.map(Bi)}function Vi(o,e,t){const n=me(t);return o>=n.startRow&&o<=n.endRow&&e>=n.startCol&&e<=n.endCol}function Zt(o,e,t){return t.some(n=>Vi(o,e,n))}function Ki(o){const e=[],t=me(o);for(let n=t.startRow;n<=t.endRow;n++)for(let i=t.startCol;i<=t.endCol;i++)e.push({row:n,col:i});return e}function Gi(o){const e=new Map;for(const t of o)for(const n of Ki(t))e.set(`${n.row},${n.col}`,n);return[...e.values()]}function Ke(o,e){return{startRow:o.row,startCol:o.col,endRow:e.row,endCol:e.col}}const Wi=':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 $i(o,e,t){if(o==="cell"&&e.selectedCell)return{mode:o,ranges:[{from:{row:e.selectedCell.row,col:e.selectedCell.col},to:{row:e.selectedCell.row,col:e.selectedCell.col}}]};if(o==="row"&&e.selected.size>0){const n=[...e.selected].map(i=>({from:{row:i,col:0},to:{row:i,col:t-1}}));return{mode:o,ranges:n}}return o==="range"&&e.ranges.length>0?{mode:o,ranges:Ve(e.ranges)}:{mode:o,ranges:[]}}class Ui extends T{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:n,originalEvent:i}=e,{mode:r}=this.config;if(r==="cell")return this.selectedCell={row:t,col:n},this.emit("selection-change",this.#r()),this.requestAfterRender(),!1;if(r==="row")return this.selected.clear(),this.selected.add(t),this.lastSelected=t,this.emit("selection-change",this.#r()),this.requestAfterRender(),!1;if(r==="range"){const s=i.shiftKey,l=i.ctrlKey||i.metaKey;if(s&&this.cellAnchor){const a=Ke(this.cellAnchor,{row:t,col:n});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:n,endRow:t,endCol:n};this.ranges.push(a),this.activeRange=a,this.cellAnchor={row:t,col:n}}else{const a={startRow:t,startCol:n,endRow:t,endCol:n};this.ranges=[a],this.activeRange=a,this.cellAnchor={row:t,col:n}}return this.emit("selection-change",this.#r()),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.#r()),this.requestAfterRender(),!0;if(t==="cell"&&i)return queueMicrotask(()=>{this.selectedCell={row:this.grid._focusRow,col:this.grid._focusCol},this.emit("selection-change",this.#r()),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.#r()),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.#r()),this.requestAfterRender(),!0}}return!1}onCellMouseDown(e){if(this.config.mode!=="range"||e.rowIndex===void 0||e.colIndex===void 0||e.rowIndex<0||e.originalEvent.shiftKey&&this.cellAnchor)return;this.isDragging=!0;const t=e.rowIndex,n=e.colIndex;this.cellAnchor={row:t,col:n},e.originalEvent.ctrlKey||e.originalEvent.metaKey||(this.ranges=[]);const r={startRow:t,startCol:n,endRow:t,endCol:n};return this.ranges.push(r),this.activeRange=r,this.emit("selection-change",this.#r()),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=Ke(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.#r()),this.requestAfterRender(),!0}onCellMouseUp(e){if(this.config.mode==="range"&&this.isDragging)return this.isDragging=!1,!0}#n(){const e=this.shadowRoot;if(!e)return;const{mode:t}=this.config;e.querySelectorAll(".cell").forEach(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"&&(X(e),i.forEach(r=>{const s=r.querySelector(".cell[data-row]"),l=Ce(s);l>=0&&this.selected.has(l)&&r.classList.add("selected","row-focus")})),t==="range"&&this.ranges.length>0){X(e);const r=this.activeRange?me(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&&Zt(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&&X(e)}afterRender(){const e=this.shadowRoot;if(!e)return;const t=e.children[0],{mode:n}=this.config;if(this.pendingKeyboardUpdate&&n==="range"){const{shiftKey:i}=this.pendingKeyboardUpdate;this.pendingKeyboardUpdate=null;const r=this.grid._focusRow,s=this.grid._focusCol;if(i&&this.cellAnchor){const l=Ke(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.#r())}this.grid.setAttribute("data-selection-mode",n),t&&t.classList.toggle("selecting",this.isDragging),this.#n()}onScrollRender(){this.#n()}getSelectedCell(){return this.selectedCell}getSelectedRows(){return[...this.selected]}getRanges(){return Ve(this.ranges)}getSelectedCells(){return Gi(this.ranges)}isCellSelected(e,t){return Zt(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:Ve(this.ranges)}),this.requestAfterRender()}#r(){return $i(this.config.mode,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges},this.columns.length)}styles=Wi}function be(o,e){return Math.floor(o/e)}function ji(o,e){return{start:o*e,end:(o+1)*e}}function Xi(o,e,t){const n=be(o,t),i=be(e-1,t),r=[];for(let s=n;s<=i;s++)r.push(s);return r}async function Jt(o,e,t,n){const i=ji(e,t);return o.getRows({startRow:i.start,endRow:i.end,sortModel:n.sortModel,filterModel:n.filterModel})}function Yi(o,e,t){const n=be(o,e),i=t.get(n);if(!i)return;const r=o%e;return i[r]}const Zi=100;class Ji extends T{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,n={startRow:e._virtualization.start,endRow:e._virtualization.end},i=Xi(n.startRow,n.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 n=0;n<this.totalRowCount;n++){const i=Yi(n,this.config.cacheBlockSize??100,this.loadedBlocks);t.push(i??{__loading:!0,__index:n})}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;Jt(e,0,t,{}).then(n=>{this.loadedBlocks.set(0,n.rows),this.totalRowCount=n.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,n=be(e,t);return this.loadedBlocks.has(n)}getLoadedBlockCount(){return this.loadedBlocks.size}}function Qt(o,e,t){return o.id!==void 0?String(o.id):t?`${t}-${e}`:String(e)}function eo(o,e){const t=new Set(o);return t.has(e)?t.delete(e):t.add(e),t}function Ge(o,e,t=null,n=0){const i=e.childrenField??"children",r=new Set;for(let s=0;s<o.length;s++){const l=o[s],a=Qt(l,s,t),c=l[i];if(Array.isArray(c)&&c.length>0){r.add(a);const d=Ge(c,e,a,n+1);for(const u of d)r.add(u)}}return r}function Qi(){return new Set}function to(o,e,t,n=null,i=0){const r=t.childrenField??"children";for(let s=0;s<o.length;s++){const l=o[s],a=Qt(l,s,n);if(a===e)return[a];const c=l[r];if(Array.isArray(c)&&c.length>0){const d=to(c,e,t,a,i+1);if(d)return[a,...d]}}return null}function er(o,e,t,n){const i=to(o,e,t);if(!i)return n;const r=new Set(n);for(let s=0;s<i.length-1;s++)r.add(i[s]);return r}function oo(o,e="children"){if(!Array.isArray(o)||o.length===0)return!1;for(const t of o)if(t&&Array.isArray(t[e])&&t[e].length>0)return!0;return!1}function tr(o){if(!Array.isArray(o)||o.length===0)return null;const e=["children","items","nodes","subRows","nested"];for(const t of o)if(!(!t||typeof t!="object")){for(const n of e)if(Array.isArray(t[n])&&t[n].length>0)return n}return null}const or=".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 nr extends T{name="tree";version="1.0.0";styles=or;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 n=this.shadowRoot?.host;if(n&&getComputedStyle(n).getPropertyValue("--tbw-animation-enabled").trim()==="0")return!1}return this.config.animation??"slide"}detect(e){if(!this.config.autoDetect)return!1;const t=this.config.childrenField??tr(e)??"children";return oo(e,t)}processRows(e){const t=this.config.childrenField??"children";if(!oo(e,t))return this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),[...e];let n=this.withStableKeys(e);this.sortState&&(n=this.sortTree(n,this.sortState.field,this.sortState.direction)),this.config.defaultExpanded&&!this.initialExpansionDone&&(this.expandedKeys=Ge(n,this.config),this.initialExpansionDone=!0),this.flattenedRows=this.flattenTree(n,this.expandedKeys),this.rowKeyMap.clear(),this.keysToAnimate.clear();const i=new Set;for(const r of this.flattenedRows)this.rowKeyMap.set(r.key,r),i.add(r.key),!this.previousVisibleKeys.has(r.key)&&r.depth>0&&this.keysToAnimate.add(r.key);return this.previousVisibleKeys=i,this.flattenedRows.map(r=>({...r.data,__treeKey:r.key,__treeDepth:r.depth,__treeHasChildren:r.hasChildren,__treeExpanded:r.isExpanded}))}withStableKeys(e,t=null){const n=this.config.childrenField??"children";return e.map((i,r)=>{const s=i.id!==void 0?String(i.id):i.__stableKey??(t?`${t}-${r}`:String(r)),l=i[n],a=Array.isArray(l)&&l.length>0;return{...i,__stableKey:s,...a?{[n]:this.withStableKeys(l,s)}:{}}})}flattenTree(e,t,n=0){const i=this.config.childrenField??"children",r=[];for(const s of e){const l=s.__stableKey??s.id??"?",a=s[i],c=Array.isArray(a)&&a.length>0,d=t.has(l);r.push({key:l,data:s,depth:n,hasChildren:c,isExpanded:d,parentKey:n>0&&l.substring(0,l.lastIndexOf("-"))||null}),c&&d&&r.push(...this.flattenTree(a,t,n+1))}return r}sortTree(e,t,n){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?n:a<c?-n:0}).map(s=>{const l=s[i];return Array.isArray(l)&&l.length>0?{...s,[i]:this.sortTree(l,t,n)}:s})}processColumns(e){if(this.flattenedRows.length===0)return[...e];const t=[...e];if(t.length===0)return t;const n={...t[0]},i=n.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:f=!0}=r(),p=document.createElement("span");if(p.className="tree-cell",p.style.setProperty("--tree-depth",String(u.__treeDepth??0)),p.style.setProperty("--tbw-tree-indent",`${h}px`),u.__treeHasChildren&&f){const w=document.createElement("span");w.className=`tree-toggle${u.__treeExpanded?" expanded":""}`,s(w,l(u.__treeExpanded?"collapse":"expand")),w.setAttribute("data-tree-key",u.__treeKey),p.appendChild(w)}else if(f){const w=document.createElement("span");w.className="tree-spacer",p.appendChild(w)}const g=document.createElement("span");if(i){const w=i(c);w instanceof Node?g.appendChild(w):g.textContent=String(w??d??"")}else g.textContent=String(d??"");return p.appendChild(g),p};return a.__treeWrapped=!0,n.viewRenderer=a,t[0]=n,t}onCellClick(e){const t=e.originalEvent?.target;if(!t?.classList.contains("tree-toggle"))return!1;const n=t.getAttribute("data-tree-key"),i=n?this.rowKeyMap.get(n):null;return i?(this.expandedKeys=eo(this.expandedKeys,n),this.emit("tree-expand",{key:n,row:i.data,expanded:this.expandedKeys.has(n),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 n=this.grid;return n._sortState!==void 0&&(n._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 n=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(n),i.addEventListener("animationend",()=>i.classList.remove(n),{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=eo(this.expandedKeys,e),this.requestRender()}expandAll(){this.expandedKeys=Ge(this.rows,this.config),this.requestRender()}collapseAll(){this.expandedKeys=Qi(),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=er(this.rows,e,this.config,this.expandedKeys),this.requestRender()}}function ir(o,e,t){const n=[...o.undoStack,e];for(;n.length>t;)n.shift();return{undoStack:n,redoStack:[]}}function no(o){if(o.undoStack.length===0)return{newState:o,action:null};const e=[...o.undoStack],t=e.pop();return t?{newState:{undoStack:e,redoStack:[...o.redoStack,t]},action:t}:{newState:o,action:null}}function io(o){if(o.redoStack.length===0)return{newState:o,action:null};const e=[...o.redoStack],t=e.pop();return t?{newState:{undoStack:[...o.undoStack,t],redoStack:e},action:t}:{newState:o,action:null}}function rr(o){return o.undoStack.length>0}function sr(o){return o.redoStack.length>0}function lr(){return{undoStack:[],redoStack:[]}}function ar(o,e,t,n){return{type:"cell-edit",rowIndex:o,field:e,oldValue:t,newValue:n,timestamp:Date.now()}}class cr extends T{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,n=(e.ctrlKey||e.metaKey)&&(e.key==="y"||e.key==="z"&&e.shiftKey);if(t){const i=no({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(n){const i=io({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,n,i){const r=ar(e,t,n,i),s=ir({undoStack:this.undoStack,redoStack:this.redoStack},r,this.config.maxHistorySize??100);this.undoStack=s.undoStack,this.redoStack=s.redoStack}undo(){const e=no({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=io({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 rr({undoStack:this.undoStack,redoStack:this.redoStack})}canRedo(){return sr({undoStack:this.undoStack,redoStack:this.redoStack})}clearHistory(){const e=lr();this.undoStack=e.undoStack,this.redoStack=e.redoStack}getUndoStack(){return[...this.undoStack]}getRedoStack(){return[...this.redoStack]}}const dr='.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 ro(o){const e=o.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}class re extends T{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:re.PANEL_ID,title:"Columns",icon:"☰",tooltip:"Column visibility",order:100,render:e=>this.renderPanelContent(e)}}show(){this.grid.openToolPanel(re.PANEL_ID)}hide(){this.grid.closeToolPanel()}toggle(){this.grid.toggleToolPanel(re.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===re.PANEL_ID}renderPanelContent(e){const t=this.grid,n=document.createElement("div");n.className="tbw-visibility-content";const i=document.createElement("div");i.className="tbw-visibility-list",n.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)}),n.appendChild(r),this.columnListElement=i,this.rebuildToggles(i),e.appendChild(n),()=>{this.columnListElement=null,n.remove()}}hasReorderPlugin(){const e=this.grid?.getPluginByName?.("reorder");return!!(e&&typeof e.moveColumn=="function")}rebuildToggles(e){const t=this.grid,n=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)),n&&ro(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),n&&ro(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,n,i){e.addEventListener("dragstart",r=>{this.isDragging=!0,this.draggedField=t,this.draggedIndex=n,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?n:n+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=dr}y.BaseGridPlugin=T,y.ClipboardPlugin=Rn,y.ColumnVirtualizationPlugin=Tn,y.ContextMenuPlugin=Ln,y.DEFAULT_ANIMATION_CONFIG=Ue,y.DEFAULT_GRID_ICONS=H,y.DGEvents=Cn,y.DataGridElement=F,y.ExportPlugin=Dn,y.FilteringPlugin=K,y.FitModeEnum=j,y.GridCSSVars=yn,y.GridClasses=P,y.GridDataAttrs=de,y.GridElement=F,y.GridSelectors=vn,y.GroupingColumnsPlugin=jn,y.GroupingRowsPlugin=oi,y.MasterDetailPlugin=ai,y.MultiSortPlugin=fi,y.PLUGIN_QUERIES=ce,y.PinnedColumnsPlugin=wi,y.PinnedRowsPlugin=yi,y.PivotPlugin=ie,y.PluginEvents=xn,y.PluginManager=Rt,y.ReorderPlugin=zi,y.SelectionPlugin=Ui,y.ServerSidePlugin=Ji,y.TreePlugin=nr,y.UndoRedoPlugin=cr,y.VisibilityPlugin=re,y.builtInSort=lt,y.defaultComparator=st,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})}));
|
|
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"})}));
|
|
51
63
|
//# sourceMappingURL=grid.all.umd.js.map
|