@toolbox-web/grid 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1265 -1247
- package/index.js.map +1 -1
- package/lib/core/grid.d.ts +2 -8
- package/lib/core/grid.d.ts.map +1 -1
- package/lib/core/internal/columns.d.ts +2 -69
- package/lib/core/internal/columns.d.ts.map +1 -1
- package/lib/core/internal/dom-builder.d.ts +7 -11
- package/lib/core/internal/dom-builder.d.ts.map +1 -1
- package/lib/core/internal/editing.d.ts.map +1 -1
- package/lib/core/internal/idle-scheduler.d.ts +0 -8
- package/lib/core/internal/idle-scheduler.d.ts.map +1 -1
- package/lib/core/internal/rows.d.ts +0 -5
- package/lib/core/internal/rows.d.ts.map +1 -1
- package/lib/core/internal/shell.d.ts +34 -18
- package/lib/core/internal/shell.d.ts.map +1 -1
- package/lib/core/internal/utils.d.ts +0 -7
- package/lib/core/internal/utils.d.ts.map +1 -1
- package/lib/core/types.d.ts +42 -15
- package/lib/core/types.d.ts.map +1 -1
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/reorder/index.js.map +1 -1
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/public.d.ts +6 -0
- package/public.d.ts.map +1 -1
- package/umd/grid.all.umd.js +20 -20
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +10 -10
- package/umd/grid.umd.js.map +1 -1
package/umd/grid.umd.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
(function(C,q){typeof exports=="object"&&typeof module<"u"?q(exports):typeof define=="function"&&define.amd?define(["exports"],q):(C=typeof globalThis<"u"?globalThis:C||self,q(C.TbwGrid={}))})(this,(function(C){"use strict";const q=':root{color-scheme:light dark}:host{--tbw-color-bg: transparent;--tbw-color-panel-bg: light-dark(#eeeeee, #222222);--tbw-color-fg: light-dark(#222222, #eeeeee);--tbw-color-fg-muted: light-dark(#555555, #aaaaaa);--tbw-color-accent: light-dark(#3b82f6, #3b82f6);--tbw-color-accent-fg: light-dark(#ffffff, #000000);--tbw-color-success: light-dark(hsl(122, 39%, 40%), hsl(122, 39%, 49%));--tbw-color-selection: light-dark(#fff7d6, #333333);--tbw-color-row-alt: var(--tbw-color-bg);--tbw-color-row-hover: light-dark(#f0f6ff, #1c1c1c);--tbw-color-header-bg: color-mix(in hsl, var(--tbw-color-panel-bg) 85%, var(--tbw-color-fg));--tbw-color-header-fg: color-mix(in hsl, var(--tbw-color-fg) 75%, var(--tbw-color-panel-bg));--tbw-color-border: light-dark(#d0d0d4, #454545);--tbw-color-border-strong: light-dark(#777777, #adacac);--tbw-color-border-cell: var(--tbw-color-border);--tbw-color-border-header: var(--tbw-color-border);--tbw-color-shadow: light-dark(rgba(0, 0, 0, .1), rgba(0, 0, 0, .3));--tbw-font-family: inherit;--tbw-font-size: inherit;--tbw-font-size-header: var(--tbw-font-size);--tbw-font-weight-header: bold;--tbw-cell-padding-header: 2px 8px;--tbw-cell-padding: 2px 8px;--tbw-cell-padding-input: 2px 6px;--tbw-row-height: 28px;--tbw-header-height: 30px;--tbw-cell-white-space: nowrap;--tbw-border-radius: 4px;--tbw-border-input: 1px solid var(--tbw-color-border-strong);--tbw-border-header: 1px solid var(--tbw-color-border-header);--tbw-row-divider: 1px solid var(--tbw-color-border-cell);--tbw-row-hover-outline: 0;--tbw-color-active-row-bg: var(--tbw-color-selection);--tbw-active-row-outline: 0;--tbw-focus-outline: 2px solid var(--tbw-color-accent);--tbw-focus-outline-offset: -2px;--tbw-focus-background: rgba(from var(--tbw-color-accent) r g b / 12%);--tbw-range-border-color: var(--tbw-color-accent);--tbw-range-selection-bg: rgba(from var(--tbw-range-border-color) r g b / 12%);--tbw-resize-handle-width: 6px;--tbw-resize-handle-color: transparent;--tbw-resize-handle-color-hover: var(--tbw-color-accent);--tbw-resize-handle-border-radius: 0;--tbw-scrollbar-thumb: var(--tbw-color-border-strong);--tbw-scrollbar-track: var(--tbw-color-bg);--tbw-transition-duration: .12s;--tbw-transition-ease: ease;--tbw-animation-duration: .2s;--tbw-animation-easing: ease-out;--tbw-animation-enabled: 1;--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-border: var(--tbw-border-input, 1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input: var(--tbw-cell-padding-input, 2px 6px);--tbw-font-size-editor: inherit;--tbw-sort-indicator-color: var(--tbw-color-fg-muted);--tbw-sort-indicator-active-color: var(--tbw-color-accent);--tbw-header-text-transform: none;--tbw-header-letter-spacing: normal;--tbw-color-header-separator: var(--tbw-color-border-cell);--tbw-checkbox-size: 16px;--tbw-density-scale: 1}:host{position:relative;display:block;width:100%;height:100%;min-height:0;contain:content;font-family:var(--tbw-font-family);font-size:var(--tbw-font-size);background:var(--tbw-color-bg);color:var(--tbw-color-fg);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);overflow:clip;outline:none}:host,:host *{box-sizing:border-box}:host .header{display:block;flex-shrink:0;z-index:var(--tbw-z-layer-header, 30);background:var(--tbw-color-header-bg);overflow:visible}:host .header-group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-color-header-bg);z-index:var(--tbw-z-layer-header, 30)}:host .header-group-cell{display:flex;align-items:center;justify-content:flex-start;padding:var(--tbw-cell-padding-header, 2px 8px);color:var(--tbw-color-header-group-fg, var(--tbw-color-header-fg));font-weight:var(--tbw-font-weight-header-group, var(--tbw-font-weight-header));justify-content:var(--tbw-align-header-group, var(--tbw-align-header, flex-start))}:host .header-row{display:grid;grid-template-columns:var(--tbw-column-template);color:var(--tbw-color-header-fg);font-size:var(--tbw-font-size-header);min-height:var(--tbw-header-height);border-bottom:var(--tbw-border-header);z-index:var(--tbw-z-layer-header, 30)}:host .header-row>.cell{display:flex;align-items:center;gap:4px;padding:var(--tbw-cell-padding-header, 2px 8px);background-color:var(--tbw-color-header-bg);font-weight:var(--tbw-font-weight-header);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}:host .header-row>.cell>span:first-child{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}:host .header-row>.cell>span[part~=sort-indicator]{flex-shrink:0;opacity:.6}:host .header-row>.cell:last-child{border-right:0}:host .header-group-cell:not(:last-child),:host .header-row>.cell.grouped.group-end:not(:last-child){border-right:2px solid var(--tbw-color-border)}:host .tbw-grid-root{display:flex;flex-direction:column;height:100%}:host .rows-body-wrapper{flex:1;min-height:0;display:flex;flex-direction:row;width:100%;min-width:fit-content}:host .rows-body{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow:visible}:host .rows-container{display:flex;flex-direction:row;flex:1;min-height:0;overflow:visible}:host .rows-viewport{flex:1;min-width:0;position:relative;display:block;overflow:clip}:host .faux-vscroll{position:sticky;inset-inline-end:0;flex-shrink:0;width:auto;overflow-y:auto;overflow-x:hidden;z-index:var(--tbw-z-layer-header, 30)}:host .faux-vscroll-spacer{width:1px}:host .rows-viewport .rows{position:absolute;top:0;left:0;min-width:100%;will-change:transform;z-index:var(--tbw-z-layer-rows, 1)}:host .data-grid-row{display:grid;grid-template-columns:var(--tbw-column-template);contain:layout style}:host .data-grid-row:has(.editing){background:var(--tbw-editing-bg)}:host .selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}:host .data-grid-row>.cell.selected:focus-visible,:host .data-grid-row>.cell:focus-visible:not(.cell-focus){outline:none}:host .data-grid-row>.cell{display:block;padding:var(--tbw-cell-padding, 2px 8px);border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height);line-height:calc(var(--tbw-row-height) - 5px);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0;white-space:var(--tbw-cell-white-space, nowrap);text-overflow:ellipsis}:host .data-grid-row>.cell>*{overflow:hidden;text-overflow:ellipsis;white-space:inherit;min-width:0}:host .data-grid-row>.cell:last-child{border-right:0}:host .data-grid-row>.cell[data-type=boolean]{text-align:center}:host .data-grid-row>.cell[data-type=boolean] input[type=checkbox]{margin:0;width:var(--tbw-checkbox-size);height:var(--tbw-checkbox-size);vertical-align:middle}:host .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex;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(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 Ye(t){const e=new Map;return t._sortState&&e.set(t._sortState.field,{direction:t._sortState.direction===1?"asc":"desc",priority:0}),e}function he(t,e){const o=t._columns,n=Ye(t);return{columns:o.map((i,l)=>{const r={field:i.field,order:l,visible:!0},s=i;s.__renderedWidth!==void 0?r.width=s.__renderedWidth:i.width!==void 0&&(r.width=typeof i.width=="string"?parseFloat(i.width):i.width);const a=n.get(i.field);a&&(r.sort=a);for(const c of e)if(c.getColumnState){const h=c.getColumnState(i.field);h&&Object.assign(r,h)}return r})}}function je(t,e,o,n){if(!e.columns||e.columns.length===0)return;const i=new Map(e.columns.map(s=>[s.field,s])),l=o.map(s=>{const a=i.get(s.field);if(!a)return s;const c={...s};return a.width!==void 0&&(c.width=a.width,c.__renderedWidth=a.width),a.visible!==void 0&&(c.hidden=!a.visible),c});l.sort((s,a)=>{const c=i.get(s.field)?.order??1/0,h=i.get(a.field)?.order??1/0;return c-h}),t._columns=l;const r=e.columns.filter(s=>s.sort!==void 0).sort((s,a)=>(s.sort?.priority??0)-(a.sort?.priority??0));if(r.length>0){const s=r[0];s.sort&&(t._sortState={field:s.field,direction:s.sort.direction==="asc"?1:-1})}else t._sortState=null;for(const s of n)if(s.applyColumnState)for(const a of e.columns)s.applyColumnState(a.field,a)}function Ke(t,e,o){let n=null;return()=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{n=null;const i=he(t,e());o(i)},100)}}function fe(t,e,o,n){const i=t.effectiveConfig?.columns??[],l=i.find(s=>s.field===e);return!l||!o&&l.lockVisible||!o&&i.filter(a=>!a.hidden&&a.field!==e).length===0||!!l.hidden===!o?!1:(l.hidden=!o,n.emit("column-visibility",{field:e,visible:o,visibleColumns:i.filter(s=>!s.hidden).map(s=>s.field)}),n.clearRowPool(),n.setup(),n.requestStateChange(),!0)}function Ze(t,e,o){const i=(t.effectiveConfig?.columns??[]).find(l=>l.field===e);return i?fe(t,e,!!i.hidden,o):!1}function Qe(t,e){const n=(t.effectiveConfig?.columns??[]).find(i=>i.field===e);return n?!n.hidden:!1}function Je(t,e){const o=t.effectiveConfig?.columns??[];o.some(n=>n.hidden)&&(o.forEach(n=>n.hidden=!1),e.emit("column-visibility",{visibleColumns:o.map(n=>n.field)}),e.clearRowPool(),e.setup(),e.requestStateChange())}function et(t){return(t.effectiveConfig?.columns??[]).map(o=>({field:o.field,header:o.header||o.field,visible:!o.hidden,lockVisible:o.lockVisible}))}function tt(t){return t._columns.map(e=>e.field)}function ot(t,e,o){if(!e.length)return;const n=new Map(t._columns.map(l=>[l.field,l])),i=[];for(const l of e){const r=n.get(l);r&&(i.push(r),n.delete(l))}for(const l of n.values())i.push(l);t._columns=i,o.renderHeader(),o.updateTemplate(),o.refreshVirtualWindow()}const W={STRETCH:"stretch",FIXED:"fixed"},pe={mode:"reduced-motion",duration:200,easing:"ease-out"},P={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰"};function nt(t){return t==null?"string":typeof t=="number"?"number":typeof t=="boolean"?"boolean":t instanceof Date||typeof t=="string"&&/\d{4}-\d{2}-\d{2}/.test(t)&&!isNaN(Date.parse(t))?"date":"string"}function be(t,e){if(e&&e.length){const l={};return e.forEach(r=>{r.type&&(l[r.field]=r.type)}),{columns:e,typeMap:l}}const o=t[0]||{},n=Object.keys(o).map(l=>{const r=o[l],s=nt(r);return{field:l,header:l.charAt(0).toUpperCase()+l.slice(1),type:s}}),i={};return n.forEach(l=>{i[l.field]=l.type||"string"}),{columns:n,typeMap:i}}const it=/{{\s*([^}]+)\s*}}/g,T="__DG_EMPTY__",lt=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,rt=/__(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/,st=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"]),we=/^on\w+$/i,at=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),ct=/^\s*(javascript|vbscript|data|blob):/i;function Z(t){if(!t||typeof t!="string")return"";if(t.indexOf("<")===-1)return t;const e=document.createElement("template");return e.innerHTML=t,dt(e.content),e.innerHTML}function dt(t){const e=[],o=t.querySelectorAll("*");for(const n of o){const i=n.tagName.toLowerCase();if(st.has(i)){e.push(n);continue}if((i==="svg"||n.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(n.attributes).some(s=>we.test(s.name)||s.name==="href"||s.name==="xlink:href")){e.push(n);continue}const l=[];for(const r of n.attributes){const s=r.name.toLowerCase();if(we.test(s)){l.push(r.name);continue}if(at.has(s)&&ct.test(r.value)){l.push(r.name);continue}if(s==="style"&&/expression\s*\(|javascript:|behavior\s*:/i.test(r.value)){l.push(r.name);continue}}l.forEach(r=>n.removeAttribute(r))}e.forEach(n=>n.remove())}function ge(t,e){if(!t||t.indexOf("{{")===-1)return t;const o=[],n=t.replace(it,(s,a)=>{const c=ut(a,e);return o.push({expr:a.trim(),result:c}),c}),i=ht(n),l=o.length&&o.every(s=>s.result===""||s.result===T);return/Reflect\.|\bProxy\b|ownKeys\(/.test(t)||l?"":i}function ut(t,e){if(t=(t||"").trim(),!t||/\b(Reflect|Proxy|ownKeys)\b/.test(t))return T;if(t==="value")return e.value==null?T:String(e.value);if(t.startsWith("row.")&&!/[()?]/.test(t)&&!t.includes(":")){const n=t.slice(4),i=e.row?e.row[n]:void 0;return i==null?T:String(i)}if(t.length>80||!lt.test(t)||rt.test(t))return T;const o=t.match(/\./g);if(o&&o.length>1)return T;try{const i=new Function("value","row",`return (${t});`)(e.value,e.row),l=i==null?"":String(i);return/Reflect|Proxy|ownKeys/.test(l)?T:l||T}catch{return T}}function ht(t){return t&&t.replace(new RegExp(T,"g"),"").replace(/Reflect\.[^<>{}\s]+/g,"").replace(/\bProxy\b/g,"").replace(/ownKeys\([^)]*\)/g,"")}function ft(t){if(/Reflect|Proxy|ownKeys/.test(t.textContent||"")){if(Array.from(t.childNodes).forEach(e=>{e.nodeType===Node.TEXT_NODE&&/Reflect|Proxy|ownKeys/.test(e.textContent||"")&&(e.textContent="")}),/Reflect|Proxy|ownKeys/.test(t.textContent||"")){if(/Reflect|Proxy|ownKeys/.test(t.textContent||""))for(;t.firstChild;)t.removeChild(t.firstChild);t.textContent=(t.textContent||"").replace(/Reflect|Proxy|ownKeys/g,"")}(t.textContent||"").trim().length===0&&(t.textContent="")}}function me(t){const e=/Reflect\.|\bProxy\b|ownKeys\(/.test(t),o=n=>e?"":ge(t,n);return o.__blocked=e,o}function pt(t){return Array.from(t.querySelectorAll("tbw-grid-column")).map(o=>{const n=o.getAttribute("field")||"";if(!n)return null;const i=o.getAttribute("type")||void 0,r=i&&new Set(["number","string","date","boolean","select","typeahead"]).has(i)?i:void 0,s=o.getAttribute("header")||void 0,a=o.hasAttribute("sortable"),c=o.hasAttribute("editable"),h={field:n,type:r,header:s,sortable:a,editable:c},d=o.getAttribute("width");if(d){const m=parseFloat(d);!isNaN(m)&&/^\d+(\.\d+)?$/.test(d.trim())?h.width=m:h.width=d}const u=o.getAttribute("minWidth")||o.getAttribute("min-width");if(u){const m=parseFloat(u);isNaN(m)||(h.minWidth=m)}o.hasAttribute("resizable")&&(h.resizable=!0),o.hasAttribute("sizable")&&(h.resizable=!0);const p=o.getAttribute("editor"),f=o.getAttribute("renderer");p&&(h.__editorName=p),f&&(h.__rendererName=f);const b=o.getAttribute("options");b&&(h.options=b.split(",").map(m=>{const[v,E]=m.includes(":")?m.split(":"):[m.trim(),m.trim()];return{value:v.trim(),label:E?.trim()||v.trim()}}));const g=o.querySelector("tbw-grid-column-view"),w=o.querySelector("tbw-grid-column-editor"),_=o.querySelector("tbw-grid-column-header");if(g&&(h.__viewTemplate=g),w&&(h.__editorTemplate=w),_&&(h.__headerTemplate=_),g){const v=(globalThis.DataGridElement?.getAdapters?.()??[]).find(E=>E.canHandle(g));v&&(h.viewRenderer=v.createRenderer(g))}if(w){const v=(globalThis.DataGridElement?.getAdapters?.()??[]).find(E=>E.canHandle(w));v&&(h.editor=v.createEditor(w))}return h}).filter(o=>!!o)}function bt(t,e){if((!t||!t.length)&&(!e||!e.length))return[];if(!t||!t.length)return e||[];if(!e||!e.length)return t;const o={};e.forEach(i=>o[i.field]=i);const n=t.map(i=>{const l=o[i.field];if(!l)return i;const r={...i};return l.header&&!r.header&&(r.header=l.header),l.type&&!r.type&&(r.type=l.type),r.sortable=i.sortable||l.sortable,(i.resizable===!0||l.resizable===!0)&&(r.resizable=!0),r.editable=i.editable||l.editable,l.width!=null&&r.width==null&&(r.width=l.width),l.minWidth!=null&&r.minWidth==null&&(r.minWidth=l.minWidth),l.__viewTemplate&&(r.__viewTemplate=l.__viewTemplate),l.__editorTemplate&&(r.__editorTemplate=l.__editorTemplate),l.__headerTemplate&&(r.__headerTemplate=l.__headerTemplate),l.viewRenderer&&!r.viewRenderer&&(r.viewRenderer=l.viewRenderer),l.editor&&!r.editor&&(r.editor=l.editor),delete o[i.field],r});return Object.keys(o).forEach(i=>n.push(o[i])),n}function ve(t,e){try{t.part?.add?.(e)}catch{}const o=t.getAttribute("part");o?o.split(/\s+/).includes(e)||t.setAttribute("part",o+" "+e):t.setAttribute("part",e)}function _e(t){t.__lightDomColumnsCache||(t.__originalColumnNodes=Array.from(t.querySelectorAll("tbw-grid-column")),t.__lightDomColumnsCache=t.__originalColumnNodes.length?pt(t):[]);const e=t.__lightDomColumnsCache,o=bt(t._columns,e);o.forEach(i=>{i.__viewTemplate&&!i.__compiledView&&(i.__compiledView=me(i.__viewTemplate.innerHTML)),i.__editorTemplate&&!i.__compiledEditor&&(i.__compiledEditor=me(i.__editorTemplate.innerHTML))});const{columns:n}=be(t._rows,o);t._columns=n}function Ce(t){const e=t.effectiveConfig?.fitMode||t.fitMode||W.STRETCH;if(e!==W.STRETCH&&e!==W.FIXED||t.__didInitialAutoSize||!t.isConnected)return;const o=t._headerRowEl?.children||[];if(!o.length)return;let n=!1;t._visibleColumns.forEach((i,l)=>{if(i.width)return;const r=o[l];let s=r?r.scrollWidth:0;for(const a of t._rowPool){const c=a.children[l];if(c){const h=c.scrollWidth;h>s&&(s=h)}}s>0&&(i.width=s+2,i.__autoSized=!0,n=!0)}),n&&I(t),t.__didInitialAutoSize=!0}function I(t){(t.effectiveConfig?.fitMode||t.fitMode||W.STRETCH)===W.STRETCH?t._gridTemplate=t._visibleColumns.map(o=>{if(o.width)return`${o.width}px`;const n=o.minWidth;return n!=null?`minmax(${n}px, 1fr)`:"1fr"}).join(" ").trim():t._gridTemplate=t._visibleColumns.map(o=>o.width?`${o.width}px`:"max-content").join(" "),t.style.setProperty("--tbw-column-template",t._gridTemplate)}function wt(t){switch(t.type){case"number":return e=>{const o=document.createElement("input");return o.type="number",o.value=e.value!=null?String(e.value):"",o.addEventListener("blur",()=>e.commit(o.value===""?null:Number(o.value))),o.addEventListener("keydown",n=>{n.key==="Enter"&&e.commit(o.value===""?null:Number(o.value)),n.key==="Escape"&&e.cancel()}),o};case"boolean":return e=>{const o=document.createElement("input");return o.type="checkbox",o.checked=!!e.value,o.addEventListener("change",()=>e.commit(o.checked)),o};case"date":return e=>{const o=document.createElement("input");return o.type="date",e.value instanceof Date&&(o.valueAsDate=e.value),o.addEventListener("change",()=>e.commit(o.valueAsDate)),o.addEventListener("keydown",n=>{n.key==="Escape"&&e.cancel()}),o};case"select":case"typeahead":return e=>{const o=document.createElement("select");e.column.multi&&(o.multiple=!0),(typeof e.column.options=="function"?e.column.options():e.column.options||[]).forEach(l=>{const r=document.createElement("option");r.value=String(l.value),r.textContent=l.label,(e.column.multi&&Array.isArray(e.value)&&e.value.includes(l.value)||!e.column.multi&&e.value===l.value)&&(r.selected=!0),o.appendChild(r)});const i=()=>{if(e.column.multi){const l=[];Array.from(o.selectedOptions).forEach(r=>{l.push(r.value)}),e.commit(l)}else e.commit(o.value)};return o.addEventListener("change",i),o.addEventListener("blur",i),o.addEventListener("keydown",l=>{l.key==="Escape"&&e.cancel()}),o};default:return e=>{const o=document.createElement("input");return o.type="text",o.value=e.value!=null?String(e.value):"",o.addEventListener("blur",()=>e.commit(o.value)),o.addEventListener("keydown",n=>{n.key==="Enter"&&e.commit(o.value),n.key==="Escape"&&e.cancel()}),o}}}function ie(t){return`<span role="checkbox" aria-checked="${t}" aria-label="${t}">${t?"🗹":"☐"}</span>`}function Ee(t){if(t==null||t==="")return"";if(t instanceof Date)return isNaN(t.getTime())?"":t.toLocaleDateString();if(typeof t=="number"||typeof t=="string"){const e=new Date(t);return isNaN(e.getTime())?"":e.toLocaleDateString()}return""}function ye(t){if(!t)return-1;const e=t.getAttribute("data-row");return e?parseInt(e,10):-1}function F(t){if(!t)return-1;const e=t.getAttribute("data-col");return e?parseInt(e,10):-1}function le(t){t&&t.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function gt(t,e){if(t._dispatchKeyDown?.(e))return;const o=t._rows.length-1,n=t._visibleColumns.length-1,i=t._activeEditRows!==void 0&&t._activeEditRows!==-1,r=t._visibleColumns[t._focusCol]?.type,s=e.composedPath?e.composedPath():[],a=s&&s.length?s[0]:e.target,c=h=>{if(!h)return!1;const d=h.tagName;return!!(d==="INPUT"||d==="SELECT"||d==="TEXTAREA"||h.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&&(r==="select"||r==="typeahead")&&(e.key==="ArrowDown"||e.key==="ArrowUp"))){switch(e.key){case"Tab":{e.preventDefault(),!e.shiftKey?t._focusCol<n?t._focusCol+=1:(typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow<o&&(t._focusRow+=1,t._focusCol=0)):t._focusCol>0?t._focusCol-=1:t._focusRow>0&&(typeof t.commitActiveRowEdit=="function"&&t._activeEditRows===t._focusRow&&t.commitActiveRowEdit(),t._focusRow-=1,t._focusCol=n),z(t);return}case"ArrowDown":i&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=Math.min(o,t._focusRow+1),e.preventDefault();break;case"ArrowUp":i&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=Math.max(0,t._focusRow-1),e.preventDefault();break;case"ArrowRight":t._focusCol=Math.min(n,t._focusCol+1),e.preventDefault();break;case"ArrowLeft":t._focusCol=Math.max(0,t._focusCol-1),e.preventDefault();break;case"Home":(e.ctrlKey||e.metaKey)&&(i&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=0),t._focusCol=0,e.preventDefault(),z(t,{forceScrollLeft:!0});return;case"End":(e.ctrlKey||e.metaKey)&&(i&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=o),t._focusCol=n,e.preventDefault(),z(t,{forceScrollRight:!0});return;case"PageDown":t._focusRow=Math.min(o,t._focusRow+20),e.preventDefault();break;case"PageUp":t._focusRow=Math.max(0,t._focusRow-20),e.preventDefault();break;case"Enter":if(typeof t.beginBulkEdit=="function"){t.beginBulkEdit(t._focusRow);return}else t.dispatchEvent(new CustomEvent("activate-cell",{detail:{row:t._focusRow,col:t._focusCol}}));return z(t);default:return}z(t)}}function z(t,e){if(t._virtualization?.enabled){const{rowHeight:r,container:s,viewportEl:a}=t._virtualization,c=s,h=a?.clientHeight??c?.clientHeight??0;if(c&&h>0){const d=t._focusRow*r;d<c.scrollTop?c.scrollTop=d:d+r>c.scrollTop+h&&(c.scrollTop=d-h+r)}}const o=t._activeEditRows!==void 0&&t._activeEditRows!==-1;o||t.refreshVirtualWindow(!1),le(t._bodyEl),Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(r=>{r.setAttribute("aria-selected","false")});const n=t._focusRow,i=t._virtualization.start??0,l=t._virtualization.end??t._rows.length;if(n>=i&&n<l){const r=t._bodyEl.querySelectorAll(".data-grid-row")[n-i],s=r?.children[t._focusCol];if(s){s.classList.add("cell-focus"),s.setAttribute("aria-selected","true");const a=t.shadowRoot?.querySelector(".tbw-scroll-area");if(a&&s&&!o)if(e?.forceScrollLeft)a.scrollLeft=0;else if(e?.forceScrollRight)a.scrollLeft=a.scrollWidth-a.clientWidth;else{const c=t._getHorizontalScrollOffsets?.(r??void 0,s)??{left:0,right:0};if(!c.skipScroll){const h=s.getBoundingClientRect(),d=a.getBoundingClientRect(),u=h.left-d.left+a.scrollLeft,p=u+h.width,f=a.scrollLeft+c.left,b=a.scrollLeft+a.clientWidth-c.right;u<f?a.scrollLeft=u-c.left:p>b&&(a.scrollLeft=p-a.clientWidth+c.right)}}if(t._activeEditRows!==void 0&&t._activeEditRows!==-1&&s.classList.contains("editing")){const c=s.querySelector(B);if(c&&document.activeElement!==c)try{c.focus({preventScroll:!0})}catch{}}else if(!s.contains(document.activeElement)){s.hasAttribute("tabindex")||s.setAttribute("tabindex","-1");try{s.focus({preventScroll:!0})}catch{}}}}}const Se=document.createElement("template");Se.innerHTML='<div class="cell" role="gridcell" part="cell"></div>';const Re=document.createElement("template");Re.innerHTML='<div class="data-grid-row" role="row" part="row"></div>';function mt(){return Se.content.firstElementChild.cloneNode(!0)}function vt(){return Re.content.firstElementChild.cloneNode(!0)}const _t="__cellDisplayCache",Ct="__cellCacheEpoch";function Q(t){t[_t]=void 0,t[Ct]=void 0,t.__hasSpecialColumns=void 0}function Et(t,e,o,n,i){const l=Math.max(0,o-e),r=t._bodyEl,s=t._visibleColumns,a=s.length;let c=t.__cachedHeaderRowCount;for(c===void 0&&(c=t.shadowRoot?.querySelector(".header-group-row")?2:1,t.__cachedHeaderRowCount=c);t._rowPool.length<l;){const d=vt();d.addEventListener("click",u=>Ae(t,u,d,!1)),d.addEventListener("dblclick",u=>Ae(t,u,d,!0)),t._rowPool.push(d)}if(t._rowPool.length>l){for(let d=l;d<t._rowPool.length;d++){const u=t._rowPool[d];u.parentNode===r&&u.remove()}t._rowPool.length=l}const h=i&&t.__hasRenderRowPlugins!==!1;for(let d=0;d<l;d++){const u=e+d,p=t._rows[u],f=t._rowPool[d];if(f.setAttribute("aria-rowindex",String(u+c+1)),h&&i(p,f,u)){f.__epoch=n,f.__rowDataRef=p,f.parentNode!==r&&r.appendChild(f);continue}const b=f.__epoch,g=f.__rowDataRef,w=f.children.length,m=b===n&&w===a,v=g!==p;let E=!1;if(m&&v){for(let A=0;A<a;A++)if(s[A].externalView&&!f.querySelector(`.cell[data-col="${A}"] [data-external-view]`)){E=!0;break}}if(!m||E){const A=J(f),M=t._activeEditRows===u;if(A&&!M)f.__isCustomRow&&(f.className="data-grid-row",f.setAttribute("role","row"),f.__isCustomRow=!1),ee(f),$(t,f,p,u),f.__epoch=n,f.__rowDataRef=p;else if(A&&M)re(t,f,p,u),f.__rowDataRef=p;else if(f.__isCustomRow&&(f.className="data-grid-row",f.setAttribute("role","row"),f.__isCustomRow=!1),$(t,f,p,u),f.__epoch=n,f.__rowDataRef=p,M){const D=f.children;for(let R=0;R<D.length;R++){const L=t._visibleColumns[R];L&&L.editable&&H(t,p,u,L,D[R],!0)}}}else if(v){const A=J(f),M=t._activeEditRows===u;if(A&&!M)ee(f),$(t,f,p,u),f.__epoch=n,f.__rowDataRef=p;else if(re(t,f,p,u),f.__rowDataRef=p,M&&!A){const D=f.children;for(let R=0;R<D.length;R++){const L=t._visibleColumns[R];L&&L.editable&&H(t,p,u,L,D[R],!0)}}}else{const A=J(f),M=t._activeEditRows===u;if(A&&!M)ee(f),$(t,f,p,u),f.__epoch=n,f.__rowDataRef=p;else if(re(t,f,p,u),M&&!A){const D=f.children;for(let R=0;R<D.length;R++){const L=t._visibleColumns[R];L&&L.editable&&H(t,p,u,L,D[R],!0)}}}const K=t._changedRowIndices.has(u),bo=f.classList.contains("changed");K!==bo&&f.classList.toggle("changed",K),f.parentNode!==r&&r.appendChild(f)}}function re(t,e,o,n){const i=e.children,l=t._visibleColumns,r=l.length,s=i.length,a=r<s?r:s,c=t._focusRow,h=t._focusCol;let d=t.__hasSpecialColumns;if(d===void 0){d=!1;for(let p=0;p<r;p++){const f=l[p];if(f.__viewTemplate||f.__compiledView||f.viewRenderer||f.externalView||f.format||f.type==="date"||f.type==="boolean"){d=!0;break}}t.__hasSpecialColumns=d}const u=String(n);if(!d){for(let p=0;p<a;p++){const f=i[p],b=o[l[p].field];f.textContent=b==null?"":String(b),f.getAttribute("data-row")!==u&&f.setAttribute("data-row",u);const g=c===n&&h===p,w=f.classList.contains("cell-focus");g!==w&&(f.classList.toggle("cell-focus",g),f.setAttribute("aria-selected",String(g)))}return}for(let p=0;p<a;p++)if(l[p].externalView&&!i[p].querySelector("[data-external-view]")){$(t,e,o,n);return}for(let p=0;p<a;p++){const f=l[p],b=i[p];b.getAttribute("data-row")!==u&&b.setAttribute("data-row",u);const g=c===n&&h===p,w=b.classList.contains("cell-focus");if(g!==w&&(b.classList.toggle("cell-focus",g),b.setAttribute("aria-selected",String(g))),b.classList.contains("editing"))continue;if(f.viewRenderer){const v=o[f.field],E=f.viewRenderer({row:o,value:v,field:f.field,column:f});typeof E=="string"?b.innerHTML=Z(E):E?(b.innerHTML="",b.appendChild(E)):b.textContent=v==null?"":String(v);continue}if(f.__viewTemplate||f.__compiledView||f.externalView)continue;const _=o[f.field];let m;if(f.format)try{const v=f.format(_,o);m=v==null?"":String(v)}catch{m=_==null?"":String(_)}else f.type==="date"?(m=Ee(_),b.textContent=m):f.type==="boolean"?b.innerHTML=ie(!!_):(m=_==null?"":String(_),b.textContent=m)}}function $(t,e,o,n){e.innerHTML="";const i=t._visibleColumns,l=i.length,r=t._focusRow,s=t._focusCol;t.effectiveConfig?.editOn||t.editOn;const a=t,c=document.createDocumentFragment();for(let h=0;h<l;h++){const d=i[h],u=mt();u.setAttribute("aria-colindex",String(h+1)),u.setAttribute("data-col",String(h)),u.setAttribute("data-row",String(n)),u.setAttribute("data-field",d.field),d.type,d.type&&u.setAttribute("data-type",d.type);let p=o[d.field];const f=d.format;if(f)try{p=f(p,o)}catch{}const b=d.__compiledView,g=d.__viewTemplate,w=d.viewRenderer,_=d.externalView;let m=!1;if(w){const v=w({row:o,value:p,field:d.field,column:d});typeof v=="string"?(u.innerHTML=Z(v),m=!0):v?u.appendChild(v):u.textContent=p==null?"":String(p)}else if(_){const v=_,E=document.createElement("div");E.setAttribute("data-external-view",""),E.setAttribute("data-field",d.field),u.appendChild(E);const K={row:o,value:p,field:d.field,column:d};if(v.mount)try{v.mount({placeholder:E,context:K,spec:v})}catch{}else queueMicrotask(()=>{try{a.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:E,spec:v,context:K}}))}catch{}});E.setAttribute("data-mounted","")}else if(b){const v=b({row:o,value:p,field:d.field,column:d}),E=b.__blocked;u.innerHTML=E?"":Z(v),m=!0,E&&(u.textContent="",u.setAttribute("data-blocked-template",""))}else if(g){const v=g.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(v)?(u.textContent="",u.setAttribute("data-blocked-template","")):(u.innerHTML=Z(ge(v,{row:o,value:p})),m=!0)}else d.type==="date"?u.textContent=Ee(p):d.type==="boolean"?u.innerHTML=ie(!!p):u.textContent=p==null?"":String(p);if(m){ft(u);const v=u.textContent||"";/Proxy|Reflect\.ownKeys/.test(v)&&(u.textContent=v.replace(/Proxy|Reflect\.ownKeys/g,"").trim(),/Proxy|Reflect\.ownKeys/.test(u.textContent||"")&&(u.textContent=""))}u.hasAttribute("data-blocked-template")&&(u.textContent||"").trim().length&&(u.textContent=""),d.editable?u.tabIndex=0:d.type==="boolean"&&(u.hasAttribute("tabindex")||(u.tabIndex=0)),r===n&&s===h?(u.classList.add("cell-focus"),u.setAttribute("aria-selected","true")):u.setAttribute("aria-selected","false"),c.appendChild(u)}e.appendChild(c)}function Ae(t,e,o,n){if(e.target?.closest(".resize-handle"))return;const i=o.querySelector(".cell[data-row]"),l=ye(i);if(l<0)return;const r=t._rows[l];if(!r||t._dispatchRowClick?.(e,l,r,o))return;const s=e.target?.closest(".cell[data-col]");if(s){const d=Number(s.getAttribute("data-col"));if(!isNaN(d)){if(t._dispatchCellClick?.(e,l,d,s))return;const u=t._focusRow!==l||t._focusCol!==d;if(t._focusRow=l,t._focusCol=d,s.classList.contains("editing")){u&&(le(t.shadowRoot??t._bodyEl),s.classList.add("cell-focus"));return}z(t)}}if(t._activeEditRows===l){s&&(le(t.shadowRoot??t._bodyEl),s.classList.add("cell-focus"),queueMicrotask(()=>{const d=Number(s.getAttribute("data-col")),u=t._visibleColumns[d];if(u&&u.editable&&s.classList.contains("editing")){const p=s.querySelector(B);try{p?.focus({preventScroll:!0})}catch{}}}));return}if(J(o)){if(!n)return;const d=o.children;for(let u=0;u<d.length;u++)d[u].classList.remove("editing");ee(o)}const c=t.effectiveConfig?.editOn??t.editOn??"dblClick";if(c===!1)return;const h=c==="dblclick"?"dblClick":c;if(h==="click"||h==="dblClick"&&n){if(typeof t.beginBulkEdit=="function"){t.beginBulkEdit(l);return}V(t,l,r)}else return;Array.from(o.children).forEach((d,u)=>{const p=t._visibleColumns[u];p&&p.editable&&H(t,r,l,p,d,!0)}),s&&queueMicrotask(()=>{const d=o.querySelector(`.cell[data-col="${t._focusCol}"]`);if(d?.classList.contains("editing")){const u=d.querySelector(B);try{u?.focus({preventScroll:!0})}catch{}}})}const B='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function se(t){return!(t==="__proto__"||t==="constructor"||t==="prototype")}function J(t){return(t.__editingCellCount??0)>0}function yt(t){const e=(t.__editingCellCount??0)+1;t.__editingCellCount=e,t.setAttribute("data-has-editing","")}function ee(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing")}function V(t,e,o){t._activeEditRows!==e&&(t._rowEditSnapshots.set(e,{...o}),t._activeEditRows=e)}function N(t,e,o){if(t._activeEditRows!==e)return;const n=t._rowEditSnapshots.get(e),i=t._rows[e],l=t.findRenderedRowElement?.(e);if(!o&&l&&i&&l.querySelectorAll(".cell.editing").forEach(s=>{const a=Number(s.getAttribute("data-col"));if(isNaN(a))return;const c=t._visibleColumns[a];if(!c)return;const h=s.querySelector("input,textarea,select");if(h){let d;h instanceof HTMLInputElement&&h.type==="checkbox"?d=h.checked:(d=h.value,c.type==="number"&&d!==""&&(d=Number(d))),i[c.field]!==d&&ae(t,e,c,d,i)}}),o&&n&&i)Object.keys(n).forEach(r=>i[r]=n[r]),t._changedRowIndices.delete(e),Q(t);else if(!o){const r=t._changedRowIndices.has(e);t.dispatchEvent(new CustomEvent("row-commit",{detail:{rowIndex:e,row:i,changed:r,changedRows:t.changedRows,changedRowIndices:t.changedRowIndices}}))}t._rowEditSnapshots.delete(e),t._activeEditRows=-1,l&&($(t,l,t._rows[e],e),t._changedRowIndices.has(e)?l.classList.add("changed"):l.classList.remove("changed")),queueMicrotask(()=>{try{const r=t._focusRow,s=t._focusCol,a=t.findRenderedRowElement?.(r);if(a){Array.from(t._bodyEl.querySelectorAll(".cell-focus")).forEach(h=>h.classList.remove("cell-focus"));const c=a.querySelector(`.cell[data-row="${r}"][data-col="${s}"]`);c&&(c.classList.add("cell-focus"),c.setAttribute("aria-selected","true"),c.hasAttribute("tabindex")||c.setAttribute("tabindex","-1"),c.focus({preventScroll:!0}))}}catch{}})}function ae(t,e,o,n,i){const l=o.field;if(!se(l)||i[l]===n)return;i[l]=n;const s=!t._changedRowIndices.has(e);t._changedRowIndices.add(e);const a=t.findRenderedRowElement?.(e);a&&a.classList.add("changed"),t.dispatchEvent(new CustomEvent("cell-commit",{detail:{row:i,field:l,value:n,rowIndex:e,changedRows:t.changedRows,changedRowIndices:t.changedRowIndices,firstTimeForRow:s}}))}function H(t,e,o,n,i,l=!1){if(!n.editable||(t._activeEditRows!==o&&V(t,o,e),i.classList.contains("editing")))return;const r=se(n.field)?e[n.field]:void 0;i.classList.add("editing");const s=i.parentElement;s&&yt(s);let a=!1;const c=b=>{a||t._activeEditRows===-1||ae(t,o,n,b,e)},h=()=>{a=!0,e[n.field]=se(n.field)?r:void 0;const b=i.querySelector("input,textarea,select");b&&(typeof HTMLInputElement<"u"&&b instanceof HTMLInputElement&&b.type==="checkbox"?b.checked=!!r:"value"in b&&(b.value=r??""))},d=document.createElement("div");d.style.display="contents",i.innerHTML="",i.appendChild(d),d.addEventListener("keydown",b=>{b.key==="Enter"&&(b.stopPropagation(),b.preventDefault(),a=!0,N(t,o,!1)),b.key==="Escape"&&(b.stopPropagation(),b.preventDefault(),h(),N(t,o,!0))});const u=n.__editorTemplate,p=n.editor||(u?"template":wt(n)),f=r;if(p==="template"&&u){const b=u.cloneNode(!0),g=n.__compiledEditor;g?b.innerHTML=g({row:e,value:r,field:n.field,column:n}):b.querySelectorAll("*").forEach(_=>{_.childNodes.length===1&&_.firstChild?.nodeType===Node.TEXT_NODE&&(_.textContent=_.textContent?.replace(/{{\s*value\s*}}/g,r==null?"":String(r)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(m,v)=>{const E=e[v];return E==null?"":String(E)})||"")});const w=b.querySelector("input,textarea,select");if(w){const _=typeof HTMLInputElement<"u";_&&w instanceof HTMLInputElement&&w.type==="checkbox"?w.checked=!!r:"value"in w&&(w.value=r??""),w.addEventListener("blur",()=>{const m=_&&w instanceof HTMLInputElement&&w.type==="checkbox"?w.checked:w.value;c(m)}),w.addEventListener("keydown",m=>{if(m.key==="Enter"){m.stopPropagation(),m.preventDefault(),a=!0;const v=_&&w instanceof HTMLInputElement&&w.type==="checkbox"?w.checked:w.value;c(v),N(t,o,!1)}m.key==="Escape"&&(m.stopPropagation(),m.preventDefault(),h(),N(t,o,!0))}),_&&w instanceof HTMLInputElement&&w.type==="checkbox"&&w.addEventListener("change",()=>{const m=w.checked;c(m)}),l||setTimeout(()=>w.focus({preventScroll:!0}),0)}d.appendChild(b)}else if(typeof p=="string"){const b=document.createElement(p);b.value=f,b.addEventListener("change",()=>c(b.value)),d.appendChild(b),l||queueMicrotask(()=>{d.querySelector(B)?.focus({preventScroll:!0})})}else if(typeof p=="function"){const b=p({row:e,value:f,field:n.field,column:n,commit:c,cancel:h});typeof b=="string"?d.innerHTML=b:d.appendChild(b),l||queueMicrotask(()=>{d.querySelector(B)?.focus({preventScroll:!0})})}else if(p&&typeof p=="object"){const b=document.createElement("div");b.setAttribute("data-external-editor",""),b.setAttribute("data-field",n.field),d.appendChild(b);const g={row:e,value:f,field:n.field,column:n,commit:c,cancel:h};if(p.mount)try{p.mount({placeholder:b,context:g,spec:p})}catch{}else t.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:b,spec:p,context:g}}))}}function St(t,e,o){t.dispatchEvent(new CustomEvent(e,{detail:o,bubbles:!0}))}function Te(t){return Array.from(t._changedRowIndices).map(e=>t._rows[e])}function xe(t){return Array.from(t._changedRowIndices)}function Rt(t,e){t._changedRowIndices.clear(),e||St(t,"changed-rows-reset",{rows:Te(t),indices:xe(t)}),t._rowPool.forEach(o=>o.classList.remove("changed"))}function At(t,e,o){if(t.effectiveConfig?.editOn===!1||!t._columns.some(r=>r.editable))return;const i=t._rows[e];V(t,e,i);const l=o.findRenderedRowElement(e);l&&(Array.from(l.children).forEach((r,s)=>{const a=t._visibleColumns[s];if(a?.editable){const c=r;c.classList.contains("editing")||H(t,i,e,a,c,!0)}}),setTimeout(()=>{let r=l.querySelector(`.cell[data-col="${t._focusCol}"]`);if(r?.classList.contains("editing")||(r=l.querySelector(".cell.editing")),r?.classList.contains("editing")){const s=r.querySelector(B);try{s?.focus({preventScroll:!0})}catch{}}},0))}function Tt(t){t._activeEditRows!==-1&&N(t,t._activeEditRows,!1)}function xt(t){t._activeEditRows!==-1&&N(t,t._activeEditRows,!0)}function te(t,e){const o=ye(e),n=F(e);if(o<0||n<0)return null;const i=t._rows[o],l=t._visibleColumns[n];return!i||!l?null:{rowIndex:o,colIndex:n,rowData:i,col:l}}function Lt(t,e){if(e.classList.contains("editing"))return;const o=te(t,e);o&&(t._focusRow=o.rowIndex,t._focusCol=o.colIndex,z(t))}function Pt(t,e,o){if(e.classList.contains("editing"))return;const n=te(t,e);n&&(o.stopPropagation(),t._focusRow=n.rowIndex,t._focusCol=n.colIndex,H(t,n.rowData,n.rowIndex,n.col,e))}function Ht(t,e,o){o.stopPropagation();const n=te(t,e);if(!n)return;if(typeof t.beginBulkEdit=="function"){t._focusRow=n.rowIndex,t._focusCol=n.colIndex,t.beginBulkEdit(n.rowIndex);return}V(t,n.rowIndex,n.rowData);const i=t.findRenderedRowElement?.(n.rowIndex);if(i){const l=i.children;for(let r=0;r<l.length;r++){const s=t._visibleColumns[r];s&&s.editable&&H(t,n.rowData,n.rowIndex,s,l[r],!0)}queueMicrotask(()=>{const r=i.querySelector(`.cell[data-col="${t._focusCol}"]`);if(r?.classList.contains("editing")){const s=r.querySelector(B);try{s?.focus({preventScroll:!0})}catch{}}})}}function Mt(t,e,o){const n=te(t,e);if(!n)return;const{rowIndex:i,colIndex:l,rowData:r,col:s}=n,a=e.classList.contains("editing");if((s.type==="select"||s.type==="typeahead")&&!a&&o.key==="Enter"){o.preventDefault(),t._activeEditRows!==i&&V(t,i,r),H(t,r,i,s,e),setTimeout(()=>{const c=e.querySelector("select");try{c?.showPicker?.()}catch{}c?.focus({preventScroll:!0})},0);return}if(s.type==="boolean"&&o.key===" "&&!a){o.preventDefault(),t._activeEditRows!==i&&V(t,i,r);const c=!r[s.field];ae(t,i,s,c,r),e.innerHTML=ie(!!c);return}if(o.key==="Enter"&&!a){o.preventDefault(),o.stopPropagation(),t._focusRow=i,t._focusCol=l,typeof t.beginBulkEdit=="function"?t.beginBulkEdit(i):H(t,r,i,s,e);return}if(o.key==="F2"&&!a){o.preventDefault(),H(t,r,i,s,e);return}}function Ot(t,e,o){const n=()=>t.effectiveConfig?.editOn||t.editOn;e.addEventListener("mousedown",i=>{const l=i.target.closest(".cell[data-col]");if(!l)return;const r=F(l);if(r<0)return;const s=t._visibleColumns[r];s&&s.editable&&Lt(t,l)},{signal:o}),e.addEventListener("click",i=>{if(n()!=="click")return;const r=i.target.closest(".cell[data-col]");if(!r)return;const s=F(r);if(s<0)return;const a=t._visibleColumns[s];a&&a.editable&&Pt(t,r,i)},{signal:o}),e.addEventListener("dblclick",i=>{const l=n();if((l==="dblclick"?"dblClick":l)==="click"||l===!1)return;const s=i.target.closest(".cell[data-col]");if(!s)return;const a=F(s);if(a<0)return;const c=t._visibleColumns[a];c&&c.editable&&Ht(t,s,i)},{signal:o}),e.addEventListener("keydown",i=>{const l=i.target.closest(".cell[data-col]");if(!l)return;const r=F(l);if(r<0)return;const s=t._visibleColumns[r];s&&s.editable&&Mt(t,l,i)},{signal:o})}function Le(t,e){return t==null&&e==null?0:t==null?-1:e==null||t>e?1:t<e?-1:0}function Pe(t,e,o){const i=o.find(s=>s.field===e.field)?.sortComparator??Le,{field:l,direction:r}=e;return[...t].sort((s,a)=>i(s[l],a[l],s,a)*r)}function He(t,e,o,n){t._rows=e,t.__rowRenderEpoch++,t._rowPool.forEach(i=>i.__epoch=-1),G(t),t.refreshVirtualWindow(!0),t.dispatchEvent(new CustomEvent("sort-change",{detail:{field:o.field,direction:n}})),t.requestStateChange?.()}function Me(t,e){!t._sortState||t._sortState.field!==e.field?(t._sortState||(t.__originalOrder=t._rows.slice()),Oe(t,e,1)):t._sortState.direction===1?Oe(t,e,-1):(t._sortState=null,t.__rowRenderEpoch++,t._rowPool.forEach(n=>n.__epoch=-1),t._rows=t.__originalOrder.slice(),G(t),t._headerRowEl?.querySelectorAll('[role="columnheader"].sortable')?.forEach(n=>{n.getAttribute("aria-sort")?(n.getAttribute("aria-sort")==="ascending"||n.getAttribute("aria-sort")==="descending")&&(t._sortState||n.setAttribute("aria-sort","none")):n.setAttribute("aria-sort","none")}),t.refreshVirtualWindow(!0),t.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:0}})),t.requestStateChange?.())}function Oe(t,e,o){t._sortState={field:e.field,direction:o};const n={field:e.field,direction:o},i=t._columns,r=(t.effectiveConfig?.sortHandler??Pe)(t._rows,n,i);r&&typeof r.then=="function"?r.then(s=>{He(t,s,e,o)}):He(t,r,e,o)}function kt(t,e){typeof e=="string"?t.textContent=e:e instanceof HTMLElement&&(t.innerHTML="",t.appendChild(e.cloneNode(!0)))}function G(t){t._headerRowEl=t.findHeaderRow();const e=t._headerRowEl;e.innerHTML="",t._visibleColumns.forEach((o,n)=>{const i=document.createElement("div");i.className="cell",ve(i,"header-cell"),i.setAttribute("role","columnheader"),i.setAttribute("aria-colindex",String(n+1)),i.setAttribute("data-field",o.field),i.setAttribute("data-col",String(n));const l=o.__headerTemplate;if(l)Array.from(l.childNodes).forEach(r=>i.appendChild(r.cloneNode(!0)));else{const r=o.header||o.field,s=document.createElement("span");s.textContent=r,i.appendChild(s)}if(o.sortable){i.classList.add("sortable"),i.tabIndex=0;const r=document.createElement("span");ve(r,"sort-indicator");const s=t._sortState?.field===o.field?t._sortState.direction:0,a={...P,...t.icons},c=s===1?a.sortAsc:s===-1?a.sortDesc:a.sortNone;kt(r,c),i.appendChild(r),i.setAttribute("aria-sort",s===0?"none":s===1?"ascending":"descending"),i.addEventListener("click",h=>{t._resizeController?.isResizing||t._dispatchHeaderClick?.(h,n,i)||Me(t,o)}),i.addEventListener("keydown",h=>{if(h.key==="Enter"||h.key===" "){if(h.preventDefault(),t._dispatchHeaderClick?.(h,n,i))return;Me(t,o)}})}if(o.resizable){i.style.position="relative";const r=document.createElement("div");r.className="resize-handle",r.setAttribute("aria-hidden","true"),r.addEventListener("mousedown",s=>{s.stopPropagation(),s.preventDefault(),t._resizeController.start(s,n,i)}),r.addEventListener("dblclick",s=>{s.stopPropagation(),s.preventDefault(),t._resizeController.resetColumn(n)}),i.appendChild(r)}e.appendChild(i)}),e.querySelectorAll(".cell.sortable").forEach(o=>{o.getAttribute("aria-sort")||o.setAttribute("aria-sort","none")}),e.children.length>0?(e.setAttribute("role","row"),e.setAttribute("aria-rowindex","1")):(e.removeAttribute("role"),e.removeAttribute("aria-rowindex"))}const ke=typeof requestIdleCallback=="function";function Dt(t,e){return ke?requestIdleCallback(t,e):window.setTimeout(()=>{const o=Date.now();t({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-o))})},1)}function De(t){ke?cancelIdleCallback(t):clearTimeout(t)}function zt(t){let e=null,o=null,n=null,i=null;const l=a=>{if(!e)return;const c=a.clientX-e.startX,h=Math.max(40,e.startWidth+c),d=t._visibleColumns[e.colIndex];d.width=h,d.__userResized=!0,d.__renderedWidth=h,o==null&&(o=requestAnimationFrame(()=>{o=null,t.updateTemplate?.()})),t.dispatchEvent(new CustomEvent("column-resize",{detail:{field:d.field,width:h}}))};let r=!1;const s=()=>{const a=e!==null;a&&(r=!0,requestAnimationFrame(()=>{r=!1})),window.removeEventListener("mousemove",l),window.removeEventListener("mouseup",s),n!==null&&(document.documentElement.style.cursor=n,n=null),i!==null&&(document.body.style.userSelect=i,i=null),e=null,a&&t.requestStateChange&&t.requestStateChange()};return{get isResizing(){return e!==null||r},start(a,c,h){a.preventDefault();const d=h.getBoundingClientRect();e={startX:a.clientX,colIndex:c,startWidth:d.width},window.addEventListener("mousemove",l),window.addEventListener("mouseup",s),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=t._visibleColumns[a];c&&(c.__userResized=!1,c.__renderedWidth=void 0,c.width=c.__originalWidth,t.updateTemplate?.(),t.requestStateChange?.(),t.dispatchEvent(new CustomEvent("column-resize-reset",{detail:{field:c.field,width:c.width}})))},dispose(){s()}}}function oe(t,e,o){const n=document.createElement(t);if(e)for(const i in e){const l=e[i];l!=null&&n.setAttribute(i,l)}return n}function S(t,e){const o=document.createElement("div");if(t&&(o.className=t),e)for(const n in e){const i=e[n];i!=null&&o.setAttribute(n,i)}return o}function ne(t,e,o){const n=document.createElement("button");if(t&&(n.className=t),e)for(const i in e){const l=e[i];l!=null&&n.setAttribute(i,l)}return n}function ze(t){const e=document.createElement("slot");return t&&(e.name=t),e}const Ne=document.createElement("template");Ne.innerHTML=`
|
|
1
|
+
(function(E,W){typeof exports=="object"&&typeof module<"u"?W(exports):typeof define=="function"&&define.amd?define(["exports"],W):(E=typeof globalThis<"u"?globalThis:E||self,W(E.TbwGrid={}))})(this,(function(E){"use strict";const W=':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 Ke(t){const e=new Map;return t._sortState&&e.set(t._sortState.field,{direction:t._sortState.direction===1?"asc":"desc",priority:0}),e}function he(t,e){const o=t._columns,n=Ke(t);return{columns:o.map((i,r)=>{const l={field:i.field,order:r,visible:!0},s=i;s.__renderedWidth!==void 0?l.width=s.__renderedWidth:i.width!==void 0&&(l.width=typeof i.width=="string"?parseFloat(i.width):i.width);const a=n.get(i.field);a&&(l.sort=a);for(const c of e)if(c.getColumnState){const f=c.getColumnState(i.field);f&&Object.assign(l,f)}return l})}}function Ze(t,e,o,n){if(!e.columns||e.columns.length===0)return;const i=new Map(e.columns.map(s=>[s.field,s])),r=o.map(s=>{const a=i.get(s.field);if(!a)return s;const c={...s};return a.width!==void 0&&(c.width=a.width,c.__renderedWidth=a.width),a.visible!==void 0&&(c.hidden=!a.visible),c});r.sort((s,a)=>{const c=i.get(s.field)?.order??1/0,f=i.get(a.field)?.order??1/0;return c-f}),t._columns=r;const l=e.columns.filter(s=>s.sort!==void 0).sort((s,a)=>(s.sort?.priority??0)-(a.sort?.priority??0));if(l.length>0){const s=l[0];s.sort&&(t._sortState={field:s.field,direction:s.sort.direction==="asc"?1:-1})}else t._sortState=null;for(const s of n)if(s.applyColumnState)for(const a of e.columns)s.applyColumnState(a.field,a)}function Qe(t,e,o){let n=null;return()=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{n=null;const i=he(t,e());o(i)},100)}}function fe(t,e,o,n){const i=t.effectiveConfig?.columns??[],r=i.find(s=>s.field===e);return!r||!o&&r.lockVisible||!o&&i.filter(a=>!a.hidden&&a.field!==e).length===0||!!r.hidden===!o?!1:(r.hidden=!o,n.emit("column-visibility",{field:e,visible:o,visibleColumns:i.filter(s=>!s.hidden).map(s=>s.field)}),n.clearRowPool(),n.setup(),n.requestStateChange(),!0)}function Je(t,e,o){const i=(t.effectiveConfig?.columns??[]).find(r=>r.field===e);return i?fe(t,e,!!i.hidden,o):!1}function et(t,e){const n=(t.effectiveConfig?.columns??[]).find(i=>i.field===e);return n?!n.hidden:!1}function tt(t,e){const o=t.effectiveConfig?.columns??[];o.some(n=>n.hidden)&&(o.forEach(n=>n.hidden=!1),e.emit("column-visibility",{visibleColumns:o.map(n=>n.field)}),e.clearRowPool(),e.setup(),e.requestStateChange())}function ot(t){return(t.effectiveConfig?.columns??[]).map(o=>({field:o.field,header:o.header||o.field,visible:!o.hidden,lockVisible:o.lockVisible}))}function nt(t){return t._columns.map(e=>e.field)}function it(t,e,o){if(!e.length)return;const n=new Map(t._columns.map(r=>[r.field,r])),i=[];for(const r of e){const l=n.get(r);l&&(i.push(l),n.delete(r))}for(const r of n.values())i.push(r);t._columns=i,o.renderHeader(),o.updateTemplate(),o.refreshVirtualWindow()}const V={STRETCH:"stretch",FIXED:"fixed"},pe={mode:"reduced-motion",duration:200,easing:"ease-out"},M={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰"};function rt(t){return t==null?"string":typeof t=="number"?"number":typeof t=="boolean"?"boolean":t instanceof Date||typeof t=="string"&&/\d{4}-\d{2}-\d{2}/.test(t)&&!isNaN(Date.parse(t))?"date":"string"}function we(t,e){if(e&&e.length){const r={};return e.forEach(l=>{l.type&&(r[l.field]=l.type)}),{columns:e,typeMap:r}}const o=t[0]||{},n=Object.keys(o).map(r=>{const l=o[r],s=rt(l);return{field:r,header:r.charAt(0).toUpperCase()+r.slice(1),type:s}}),i={};return n.forEach(r=>{i[r.field]=r.type||"string"}),{columns:n,typeMap:i}}const lt=/{{\s*([^}]+)\s*}}/g,L="__DG_EMPTY__",st=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,at=/__(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/,ct=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"]),be=/^on\w+$/i,dt=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),ut=/^\s*(javascript|vbscript|data|blob):/i;function J(t){if(!t||typeof t!="string")return"";if(t.indexOf("<")===-1)return t;const e=document.createElement("template");return e.innerHTML=t,ht(e.content),e.innerHTML}function ht(t){const e=[],o=t.querySelectorAll("*");for(const n of o){const i=n.tagName.toLowerCase();if(ct.has(i)){e.push(n);continue}if((i==="svg"||n.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(n.attributes).some(s=>be.test(s.name)||s.name==="href"||s.name==="xlink:href")){e.push(n);continue}const r=[];for(const l of n.attributes){const s=l.name.toLowerCase();if(be.test(s)){r.push(l.name);continue}if(dt.has(s)&&ut.test(l.value)){r.push(l.name);continue}if(s==="style"&&/expression\s*\(|javascript:|behavior\s*:/i.test(l.value)){r.push(l.name);continue}}r.forEach(l=>n.removeAttribute(l))}e.forEach(n=>n.remove())}function ge(t,e){if(!t||t.indexOf("{{")===-1)return t;const o=[],n=t.replace(lt,(s,a)=>{const c=ft(a,e);return o.push({expr:a.trim(),result:c}),c}),i=pt(n),r=o.length&&o.every(s=>s.result===""||s.result===L);return/Reflect\.|\bProxy\b|ownKeys\(/.test(t)||r?"":i}function ft(t,e){if(t=(t||"").trim(),!t||/\b(Reflect|Proxy|ownKeys)\b/.test(t))return L;if(t==="value")return e.value==null?L:String(e.value);if(t.startsWith("row.")&&!/[()?]/.test(t)&&!t.includes(":")){const n=t.slice(4),i=e.row?e.row[n]:void 0;return i==null?L:String(i)}if(t.length>80||!st.test(t)||at.test(t))return L;const o=t.match(/\./g);if(o&&o.length>1)return L;try{const i=new Function("value","row",`return (${t});`)(e.value,e.row),r=i==null?"":String(i);return/Reflect|Proxy|ownKeys/.test(r)?L:r||L}catch{return L}}function pt(t){return t&&t.replace(new RegExp(L,"g"),"").replace(/Reflect\.[^<>{}\s]+/g,"").replace(/\bProxy\b/g,"").replace(/ownKeys\([^)]*\)/g,"")}function wt(t){if(/Reflect|Proxy|ownKeys/.test(t.textContent||"")){if(Array.from(t.childNodes).forEach(e=>{e.nodeType===Node.TEXT_NODE&&/Reflect|Proxy|ownKeys/.test(e.textContent||"")&&(e.textContent="")}),/Reflect|Proxy|ownKeys/.test(t.textContent||"")){if(/Reflect|Proxy|ownKeys/.test(t.textContent||""))for(;t.firstChild;)t.removeChild(t.firstChild);t.textContent=(t.textContent||"").replace(/Reflect|Proxy|ownKeys/g,"")}(t.textContent||"").trim().length===0&&(t.textContent="")}}function me(t){const e=/Reflect\.|\bProxy\b|ownKeys\(/.test(t),o=n=>e?"":ge(t,n);return o.__blocked=e,o}function bt(t){return Array.from(t.querySelectorAll("tbw-grid-column")).map(o=>{const n=o.getAttribute("field")||"";if(!n)return null;const i=o.getAttribute("type")||void 0,l=i&&new Set(["number","string","date","boolean","select","typeahead"]).has(i)?i:void 0,s=o.getAttribute("header")||void 0,a=o.hasAttribute("sortable"),c=o.hasAttribute("editable"),f={field:n,type:l,header:s,sortable:a,editable:c},d=o.getAttribute("width");if(d){const C=parseFloat(d);!isNaN(C)&&/^\d+(\.\d+)?$/.test(d.trim())?f.width=C:f.width=d}const u=o.getAttribute("minWidth")||o.getAttribute("min-width");if(u){const C=parseFloat(u);isNaN(C)||(f.minWidth=C)}o.hasAttribute("resizable")&&(f.resizable=!0),o.hasAttribute("sizable")&&(f.resizable=!0);const w=o.getAttribute("editor"),h=o.getAttribute("renderer");w&&(f.__editorName=w),h&&(f.__rendererName=h);const p=o.getAttribute("options");p&&(f.options=p.split(",").map(C=>{const[P,A]=C.includes(":")?C.split(":"):[C.trim(),C.trim()];return{value:P.trim(),label:A?.trim()||P.trim()}}));const g=o.querySelector("tbw-grid-column-view"),b=o.querySelector("tbw-grid-column-editor"),_=o.querySelector("tbw-grid-column-header");g&&(f.__viewTemplate=g),b&&(f.__editorTemplate=b),_&&(f.__headerTemplate=_);const m=globalThis.DataGridElement?.getAdapters?.()??[],y=g??o,x=m.find(C=>C.canHandle(y));if(x){const C=x.createRenderer(y);C&&(f.viewRenderer=C)}const ie=b??o,T=m.find(C=>C.canHandle(ie));if(T){const C=T.createEditor(ie);C&&(f.editor=C)}return f}).filter(o=>!!o)}function gt(t,e){if((!t||!t.length)&&(!e||!e.length))return[];if(!t||!t.length)return e||[];if(!e||!e.length)return t;const o={};e.forEach(i=>{const r=o[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 l=i.renderer||i.viewRenderer,s=r.renderer||r.viewRenderer;l&&!s&&(r.viewRenderer=l,i.renderer&&(r.renderer=l)),i.editor&&!r.editor&&(r.editor=i.editor)}else o[i.field]={...i}});const n=t.map(i=>{const r=o[i.field];if(!r)return i;const l={...i};r.header&&!l.header&&(l.header=r.header),r.type&&!l.type&&(l.type=r.type),l.sortable=i.sortable||r.sortable,(i.resizable===!0||r.resizable===!0)&&(l.resizable=!0),l.editable=i.editable||r.editable,r.width!=null&&l.width==null&&(l.width=r.width),r.minWidth!=null&&l.minWidth==null&&(l.minWidth=r.minWidth),r.__viewTemplate&&(l.__viewTemplate=r.__viewTemplate),r.__editorTemplate&&(l.__editorTemplate=r.__editorTemplate),r.__headerTemplate&&(l.__headerTemplate=r.__headerTemplate);const s=r.renderer||r.viewRenderer,a=l.renderer||l.viewRenderer;return s&&!a&&(l.viewRenderer=s,r.renderer&&(l.renderer=s)),r.editor&&!l.editor&&(l.editor=r.editor),delete o[i.field],l});return Object.keys(o).forEach(i=>n.push(o[i])),n}function ve(t,e){try{t.part?.add?.(e)}catch{}const o=t.getAttribute("part");o?o.split(/\s+/).includes(e)||t.setAttribute("part",o+" "+e):t.setAttribute("part",e)}function _e(t){t.__lightDomColumnsCache||(t.__originalColumnNodes=Array.from(t.querySelectorAll("tbw-grid-column")),t.__lightDomColumnsCache=t.__originalColumnNodes.length?bt(t):[]);const e=t.__lightDomColumnsCache,o=gt(t._columns,e);o.forEach(i=>{i.__viewTemplate&&!i.__compiledView&&(i.__compiledView=me(i.__viewTemplate.innerHTML)),i.__editorTemplate&&!i.__compiledEditor&&(i.__compiledEditor=me(i.__editorTemplate.innerHTML))});const{columns:n}=we(t._rows,o);t._columns=n}function Ce(t){const e=t.effectiveConfig?.fitMode||t.fitMode||V.STRETCH;if(e!==V.STRETCH&&e!==V.FIXED||t.__didInitialAutoSize||!t.isConnected)return;const o=t._headerRowEl?.children||[];if(!o.length)return;let n=!1;t._visibleColumns.forEach((i,r)=>{if(i.width)return;const l=o[r];let s=l?l.scrollWidth:0;for(const a of t._rowPool){const c=a.children[r];if(c){const f=c.scrollWidth;f>s&&(s=f)}}s>0&&(i.width=s+2,i.__autoSized=!0,n=!0)}),n&&I(t),t.__didInitialAutoSize=!0}function I(t){(t.effectiveConfig?.fitMode||t.fitMode||V.STRETCH)===V.STRETCH?t._gridTemplate=t._visibleColumns.map(o=>{if(o.width)return`${o.width}px`;const n=o.minWidth;return n!=null?`minmax(${n}px, 1fr)`:"1fr"}).join(" ").trim():t._gridTemplate=t._visibleColumns.map(o=>o.width?`${o.width}px`:"max-content").join(" "),t.style.setProperty("--tbw-column-template",t._gridTemplate)}function mt(t){switch(t.type){case"number":return e=>{const o=document.createElement("input");return o.type="number",o.value=e.value!=null?String(e.value):"",o.addEventListener("blur",()=>e.commit(o.value===""?null:Number(o.value))),o.addEventListener("keydown",n=>{n.key==="Enter"&&e.commit(o.value===""?null:Number(o.value)),n.key==="Escape"&&e.cancel()}),o};case"boolean":return e=>{const o=document.createElement("input");return o.type="checkbox",o.checked=!!e.value,o.addEventListener("change",()=>e.commit(o.checked)),o};case"date":return e=>{const o=document.createElement("input");return o.type="date",e.value instanceof Date&&(o.valueAsDate=e.value),o.addEventListener("change",()=>e.commit(o.valueAsDate)),o.addEventListener("keydown",n=>{n.key==="Escape"&&e.cancel()}),o};case"select":case"typeahead":return e=>{const o=document.createElement("select");e.column.multi&&(o.multiple=!0),(typeof e.column.options=="function"?e.column.options():e.column.options||[]).forEach(r=>{const l=document.createElement("option");l.value=String(r.value),l.textContent=r.label,(e.column.multi&&Array.isArray(e.value)&&e.value.includes(r.value)||!e.column.multi&&e.value===r.value)&&(l.selected=!0),o.appendChild(l)});const i=()=>{if(e.column.multi){const r=[];Array.from(o.selectedOptions).forEach(l=>{r.push(l.value)}),e.commit(r)}else e.commit(o.value)};return o.addEventListener("change",i),o.addEventListener("blur",i),o.addEventListener("keydown",r=>{r.key==="Escape"&&e.cancel()}),o};default:return e=>{const o=document.createElement("input");return o.type="text",o.value=e.value!=null?String(e.value):"",o.addEventListener("blur",()=>e.commit(o.value)),o.addEventListener("keydown",n=>{n.key==="Enter"&&e.commit(o.value),n.key==="Escape"&&e.cancel()}),o}}}function re(t){return`<span role="checkbox" aria-checked="${t}" aria-label="${t}">${t?"🗹":"☐"}</span>`}function Ee(t){if(t==null||t==="")return"";if(t instanceof Date)return isNaN(t.getTime())?"":t.toLocaleDateString();if(typeof t=="number"||typeof t=="string"){const e=new Date(t);return isNaN(e.getTime())?"":e.toLocaleDateString()}return""}function ye(t){if(!t)return-1;const e=t.getAttribute("data-row");return e?parseInt(e,10):-1}function j(t){if(!t)return-1;const e=t.getAttribute("data-col");return e?parseInt(e,10):-1}function le(t){t&&t.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function vt(t,e){if(t._dispatchKeyDown?.(e))return;const o=t._rows.length-1,n=t._visibleColumns.length-1,i=t._activeEditRows!==void 0&&t._activeEditRows!==-1,l=t._visibleColumns[t._focusCol]?.type,s=e.composedPath?e.composedPath():[],a=s&&s.length?s[0]:e.target,c=f=>{if(!f)return!1;const d=f.tagName;return!!(d==="INPUT"||d==="SELECT"||d==="TEXTAREA"||f.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&&(l==="select"||l==="typeahead")&&(e.key==="ArrowDown"||e.key==="ArrowUp"))){switch(e.key){case"Tab":{e.preventDefault(),!e.shiftKey?t._focusCol<n?t._focusCol+=1:(typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow<o&&(t._focusRow+=1,t._focusCol=0)):t._focusCol>0?t._focusCol-=1:t._focusRow>0&&(typeof t.commitActiveRowEdit=="function"&&t._activeEditRows===t._focusRow&&t.commitActiveRowEdit(),t._focusRow-=1,t._focusCol=n),z(t);return}case"ArrowDown":i&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=Math.min(o,t._focusRow+1),e.preventDefault();break;case"ArrowUp":i&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=Math.max(0,t._focusRow-1),e.preventDefault();break;case"ArrowRight":t._focusCol=Math.min(n,t._focusCol+1),e.preventDefault();break;case"ArrowLeft":t._focusCol=Math.max(0,t._focusCol-1),e.preventDefault();break;case"Home":(e.ctrlKey||e.metaKey)&&(i&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=0),t._focusCol=0,e.preventDefault(),z(t,{forceScrollLeft:!0});return;case"End":(e.ctrlKey||e.metaKey)&&(i&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=o),t._focusCol=n,e.preventDefault(),z(t,{forceScrollRight:!0});return;case"PageDown":t._focusRow=Math.min(o,t._focusRow+20),e.preventDefault();break;case"PageUp":t._focusRow=Math.max(0,t._focusRow-20),e.preventDefault();break;case"Enter":if(typeof t.beginBulkEdit=="function"){t.beginBulkEdit(t._focusRow);return}else t.dispatchEvent(new CustomEvent("activate-cell",{detail:{row:t._focusRow,col:t._focusCol}}));return z(t);default:return}z(t)}}function z(t,e){if(t._virtualization?.enabled){const{rowHeight:l,container:s,viewportEl:a}=t._virtualization,c=s,f=a?.clientHeight??c?.clientHeight??0;if(c&&f>0){const d=t._focusRow*l;d<c.scrollTop?c.scrollTop=d:d+l>c.scrollTop+f&&(c.scrollTop=d-f+l)}}const o=t._activeEditRows!==void 0&&t._activeEditRows!==-1;o||t.refreshVirtualWindow(!1),le(t._bodyEl),Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(l=>{l.setAttribute("aria-selected","false")});const n=t._focusRow,i=t._virtualization.start??0,r=t._virtualization.end??t._rows.length;if(n>=i&&n<r){const l=t._bodyEl.querySelectorAll(".data-grid-row")[n-i],s=l?.children[t._focusCol];if(s){s.classList.add("cell-focus"),s.setAttribute("aria-selected","true");const a=t.shadowRoot?.querySelector(".tbw-scroll-area");if(a&&s&&!o)if(e?.forceScrollLeft)a.scrollLeft=0;else if(e?.forceScrollRight)a.scrollLeft=a.scrollWidth-a.clientWidth;else{const c=t._getHorizontalScrollOffsets?.(l??void 0,s)??{left:0,right:0};if(!c.skipScroll){const f=s.getBoundingClientRect(),d=a.getBoundingClientRect(),u=f.left-d.left+a.scrollLeft,w=u+f.width,h=a.scrollLeft+c.left,p=a.scrollLeft+a.clientWidth-c.right;u<h?a.scrollLeft=u-c.left:w>p&&(a.scrollLeft=w-a.clientWidth+c.right)}}if(t._activeEditRows!==void 0&&t._activeEditRows!==-1&&s.classList.contains("editing")){const c=s.querySelector(B);if(c&&document.activeElement!==c)try{c.focus({preventScroll:!0})}catch{}}else if(!s.contains(document.activeElement)){s.hasAttribute("tabindex")||s.setAttribute("tabindex","-1");try{s.focus({preventScroll:!0})}catch{}}}}}const Se=document.createElement("template");Se.innerHTML='<div class="cell" role="gridcell" part="cell"></div>';const Re=document.createElement("template");Re.innerHTML='<div class="data-grid-row" role="row" part="row"></div>';function _t(){return Se.content.firstElementChild.cloneNode(!0)}function Ct(){return Re.content.firstElementChild.cloneNode(!0)}const Et="__cellDisplayCache",yt="__cellCacheEpoch";function K(t){t[Et]=void 0,t[yt]=void 0,t.__hasSpecialColumns=void 0}function St(t,e,o,n,i){const r=Math.max(0,o-e),l=t._bodyEl,s=t._visibleColumns,a=s.length;let c=t.__cachedHeaderRowCount;for(c===void 0&&(c=t.shadowRoot?.querySelector(".header-group-row")?2:1,t.__cachedHeaderRowCount=c);t._rowPool.length<r;){const d=Ct();d.addEventListener("click",u=>Te(t,u,d,!1)),d.addEventListener("dblclick",u=>Te(t,u,d,!0)),t._rowPool.push(d)}if(t._rowPool.length>r){for(let d=r;d<t._rowPool.length;d++){const u=t._rowPool[d];u.parentNode===l&&u.remove()}t._rowPool.length=r}const f=i&&t.__hasRenderRowPlugins!==!1;for(let d=0;d<r;d++){const u=e+d,w=t._rows[u],h=t._rowPool[d];if(h.setAttribute("aria-rowindex",String(u+c+1)),f&&i(w,h,u)){h.__epoch=n,h.__rowDataRef=w,h.parentNode!==l&&l.appendChild(h);continue}const p=h.__epoch,g=h.__rowDataRef,b=h.children.length,v=p===n&&b===a,m=g!==w;let y=!1;if(v&&m){for(let T=0;T<a;T++)if(s[T].externalView&&!h.querySelector(`.cell[data-col="${T}"] [data-external-view]`)){y=!0;break}}if(!v||y){const T=ee(h),C=t._activeEditRows===u;if(T&&!C)h.__isCustomRow&&(h.className="data-grid-row",h.setAttribute("role","row"),h.__isCustomRow=!1),te(h),G(t,h,w,u),h.__epoch=n,h.__rowDataRef=w;else if(T&&C)se(t,h,w,u),h.__rowDataRef=w;else if(h.__isCustomRow&&(h.className="data-grid-row",h.setAttribute("role","row"),h.__isCustomRow=!1),G(t,h,w,u),h.__epoch=n,h.__rowDataRef=w,C){const P=h.children;for(let A=0;A<P.length;A++){const O=t._visibleColumns[A];O&&O.editable&&k(t,w,u,O,P[A],!0)}}}else if(m){const T=ee(h),C=t._activeEditRows===u;if(T&&!C)te(h),G(t,h,w,u),h.__epoch=n,h.__rowDataRef=w;else if(se(t,h,w,u),h.__rowDataRef=w,C&&!T){const P=h.children;for(let A=0;A<P.length;A++){const O=t._visibleColumns[A];O&&O.editable&&k(t,w,u,O,P[A],!0)}}}else{const T=ee(h),C=t._activeEditRows===u;if(T&&!C)te(h),G(t,h,w,u),h.__epoch=n,h.__rowDataRef=w;else if(se(t,h,w,u),C&&!T){const P=h.children;for(let A=0;A<P.length;A++){const O=t._visibleColumns[A];O&&O.editable&&k(t,w,u,O,P[A],!0)}}}const x=t._changedRowIndices.has(u),ie=h.classList.contains("changed");x!==ie&&h.classList.toggle("changed",x),h.parentNode!==l&&l.appendChild(h)}}function se(t,e,o,n){const i=e.children,r=t._visibleColumns,l=r.length,s=i.length,a=l<s?l:s,c=t._focusRow,f=t._focusCol;let d=t.__hasSpecialColumns;if(d===void 0){d=!1;for(let w=0;w<l;w++){const h=r[w];if(h.__viewTemplate||h.__compiledView||h.renderer||h.viewRenderer||h.externalView||h.format||h.type==="date"||h.type==="boolean"){d=!0;break}}t.__hasSpecialColumns=d}const u=String(n);if(!d){for(let w=0;w<a;w++){const h=i[w],p=o[r[w].field];h.textContent=p==null?"":String(p),h.getAttribute("data-row")!==u&&h.setAttribute("data-row",u);const g=c===n&&f===w,b=h.classList.contains("cell-focus");g!==b&&(h.classList.toggle("cell-focus",g),h.setAttribute("aria-selected",String(g)))}return}for(let w=0;w<a;w++)if(r[w].externalView&&!i[w].querySelector("[data-external-view]")){G(t,e,o,n);return}for(let w=0;w<a;w++){const h=r[w],p=i[w];p.getAttribute("data-row")!==u&&p.setAttribute("data-row",u);const g=c===n&&f===w,b=p.classList.contains("cell-focus");if(g!==b&&(p.classList.toggle("cell-focus",g),p.setAttribute("aria-selected",String(g))),p.classList.contains("editing"))continue;const _=h.renderer||h.viewRenderer;if(_){const y=o[h.field],x=_({row:o,value:y,field:h.field,column:h,cellEl:p});typeof x=="string"?p.innerHTML=J(x):x?x.parentElement!==p&&(p.innerHTML="",p.appendChild(x)):p.textContent=y==null?"":String(y);continue}if(h.__viewTemplate||h.__compiledView||h.externalView)continue;const v=o[h.field];let m;if(h.format)try{const y=h.format(v,o);m=y==null?"":String(y)}catch{m=v==null?"":String(v)}else h.type==="date"?(m=Ee(v),p.textContent=m):h.type==="boolean"?p.innerHTML=re(!!v):(m=v==null?"":String(v),p.textContent=m)}}function G(t,e,o,n){e.innerHTML="";const i=t._visibleColumns,r=i.length,l=t._focusRow,s=t._focusCol;t.effectiveConfig?.editOn||t.editOn;const a=t,c=document.createDocumentFragment();for(let f=0;f<r;f++){const d=i[f],u=_t();u.setAttribute("aria-colindex",String(f+1)),u.setAttribute("data-col",String(f)),u.setAttribute("data-row",String(n)),u.setAttribute("data-field",d.field),d.type,d.type&&u.setAttribute("data-type",d.type);let w=o[d.field];const h=d.format;if(h)try{w=h(w,o)}catch{}const p=d.__compiledView,g=d.__viewTemplate,b=d.renderer||d.viewRenderer,_=d.externalView;let v=!1;if(b){const m=b({row:o,value:w,field:d.field,column:d,cellEl:u});typeof m=="string"?(u.innerHTML=J(m),v=!0):m?m.parentElement!==u&&(u.textContent="",u.appendChild(m)):u.textContent=w==null?"":String(w)}else if(_){const m=_,y=document.createElement("div");y.setAttribute("data-external-view",""),y.setAttribute("data-field",d.field),u.appendChild(y);const x={row:o,value:w,field:d.field,column:d};if(m.mount)try{m.mount({placeholder:y,context:x,spec:m})}catch{}else queueMicrotask(()=>{try{a.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:y,spec:m,context:x}}))}catch{}});y.setAttribute("data-mounted","")}else if(p){const m=p({row:o,value:w,field:d.field,column:d}),y=p.__blocked;u.innerHTML=y?"":J(m),v=!0,y&&(u.textContent="",u.setAttribute("data-blocked-template",""))}else if(g){const m=g.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(m)?(u.textContent="",u.setAttribute("data-blocked-template","")):(u.innerHTML=J(ge(m,{row:o,value:w})),v=!0)}else d.type==="date"?u.textContent=Ee(w):d.type==="boolean"?u.innerHTML=re(!!w):u.textContent=w==null?"":String(w);if(v){wt(u);const m=u.textContent||"";/Proxy|Reflect\.ownKeys/.test(m)&&(u.textContent=m.replace(/Proxy|Reflect\.ownKeys/g,"").trim(),/Proxy|Reflect\.ownKeys/.test(u.textContent||"")&&(u.textContent=""))}u.hasAttribute("data-blocked-template")&&(u.textContent||"").trim().length&&(u.textContent=""),d.editable?u.tabIndex=0:d.type==="boolean"&&(u.hasAttribute("tabindex")||(u.tabIndex=0)),l===n&&s===f?(u.classList.add("cell-focus"),u.setAttribute("aria-selected","true")):u.setAttribute("aria-selected","false"),c.appendChild(u)}e.appendChild(c)}function Te(t,e,o,n){if(e.target?.closest(".resize-handle"))return;const i=o.querySelector(".cell[data-row]"),r=ye(i);if(r<0)return;const l=t._rows[r];if(!l||t._dispatchRowClick?.(e,r,l,o))return;const s=e.target?.closest(".cell[data-col]");if(s){const d=Number(s.getAttribute("data-col"));if(!isNaN(d)){if(t._dispatchCellClick?.(e,r,d,s))return;const u=t._focusRow!==r||t._focusCol!==d;if(t._focusRow=r,t._focusCol=d,s.classList.contains("editing")){u&&(le(t.shadowRoot??t._bodyEl),s.classList.add("cell-focus"));return}z(t)}}if(t._activeEditRows===r){s&&(le(t.shadowRoot??t._bodyEl),s.classList.add("cell-focus"),queueMicrotask(()=>{const d=Number(s.getAttribute("data-col")),u=t._visibleColumns[d];if(u&&u.editable&&s.classList.contains("editing")){const w=s.querySelector(B);try{w?.focus({preventScroll:!0})}catch{}}}));return}if(ee(o)){if(!n)return;const d=o.children;for(let u=0;u<d.length;u++)d[u].classList.remove("editing");te(o)}const c=t.effectiveConfig?.editOn??t.editOn??"dblClick";if(c===!1)return;const f=c==="dblclick"?"dblClick":c;if(f==="click"||f==="dblClick"&&n){if(typeof t.beginBulkEdit=="function"){t.beginBulkEdit(r);return}$(t,r,l)}else return;Array.from(o.children).forEach((d,u)=>{const w=t._visibleColumns[u];w&&w.editable&&k(t,l,r,w,d,!0)}),s&&queueMicrotask(()=>{const d=o.querySelector(`.cell[data-col="${t._focusCol}"]`);if(d?.classList.contains("editing")){const u=d.querySelector(B);try{u?.focus({preventScroll:!0})}catch{}}})}const B='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function ae(t){return!(t==="__proto__"||t==="constructor"||t==="prototype")}function ee(t){return(t.__editingCellCount??0)>0}function Rt(t){const e=(t.__editingCellCount??0)+1;t.__editingCellCount=e,t.setAttribute("data-has-editing","")}function te(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing")}function Tt(t,e,o,n,i){const r=t.querySelector("input,textarea,select");if(!r)return;const l=()=>{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",()=>{o(l())}),r instanceof HTMLInputElement&&r.type==="checkbox"?r.addEventListener("change",()=>o(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>o(l()))}function $(t,e,o){t._activeEditRows!==e&&(t._rowEditSnapshots.set(e,{...o}),t._activeEditRows=e)}function N(t,e,o){if(t._activeEditRows!==e)return;const n=t._rowEditSnapshots.get(e),i=t._rows[e],r=t.findRenderedRowElement?.(e);if(!o&&r&&i&&r.querySelectorAll(".cell.editing").forEach(s=>{const a=Number(s.getAttribute("data-col"));if(isNaN(a))return;const c=t._visibleColumns[a];if(!c)return;const f=s.querySelector("input,textarea,select");if(f){let d;f instanceof HTMLInputElement&&f.type==="checkbox"?d=f.checked:(d=f.value,c.type==="number"&&d!==""&&(d=Number(d))),i[c.field]!==d&&ce(t,e,c,d,i)}}),o&&n&&i)Object.keys(n).forEach(l=>i[l]=n[l]),t._changedRowIndices.delete(e),K(t);else if(!o){const l=t._changedRowIndices.has(e);t.dispatchEvent(new CustomEvent("row-commit",{detail:{rowIndex:e,row:i,changed:l,changedRows:t.changedRows,changedRowIndices:t.changedRowIndices}}))}t._rowEditSnapshots.delete(e),t._activeEditRows=-1,r&&(G(t,r,t._rows[e],e),t._changedRowIndices.has(e)?r.classList.add("changed"):r.classList.remove("changed")),queueMicrotask(()=>{try{const l=t._focusRow,s=t._focusCol,a=t.findRenderedRowElement?.(l);if(a){Array.from(t._bodyEl.querySelectorAll(".cell-focus")).forEach(f=>f.classList.remove("cell-focus"));const c=a.querySelector(`.cell[data-row="${l}"][data-col="${s}"]`);c&&(c.classList.add("cell-focus"),c.setAttribute("aria-selected","true"),c.hasAttribute("tabindex")||c.setAttribute("tabindex","-1"),c.focus({preventScroll:!0}))}}catch{}})}function ce(t,e,o,n,i){const r=o.field;if(!ae(r)||i[r]===n)return;i[r]=n;const s=!t._changedRowIndices.has(e);t._changedRowIndices.add(e);const a=t.findRenderedRowElement?.(e);a&&a.classList.add("changed"),t.dispatchEvent(new CustomEvent("cell-commit",{detail:{row:i,field:r,value:n,rowIndex:e,changedRows:t.changedRows,changedRowIndices:t.changedRowIndices,firstTimeForRow:s}}))}function k(t,e,o,n,i,r=!1){if(!n.editable||(t._activeEditRows!==o&&$(t,o,e),i.classList.contains("editing")))return;const l=ae(n.field)?e[n.field]:void 0;i.classList.add("editing");const s=i.parentElement;s&&Rt(s);let a=!1;const c=p=>{a||t._activeEditRows===-1||ce(t,o,n,p,e)},f=()=>{a=!0,e[n.field]=ae(n.field)?l:void 0;const p=i.querySelector("input,textarea,select");p&&(typeof HTMLInputElement<"u"&&p instanceof HTMLInputElement&&p.type==="checkbox"?p.checked=!!l:"value"in p&&(p.value=l??""))},d=document.createElement("div");d.style.display="contents",i.innerHTML="",i.appendChild(d),d.addEventListener("keydown",p=>{p.key==="Enter"&&(p.stopPropagation(),p.preventDefault(),a=!0,N(t,o,!1)),p.key==="Escape"&&(p.stopPropagation(),p.preventDefault(),f(),N(t,o,!0))});const u=n.__editorTemplate,w=n.editor||(u?"template":mt(n)),h=l;if(w==="template"&&u){const p=u.cloneNode(!0),g=n.__compiledEditor;g?p.innerHTML=g({row:e,value:l,field:n.field,column:n}):p.querySelectorAll("*").forEach(_=>{_.childNodes.length===1&&_.firstChild?.nodeType===Node.TEXT_NODE&&(_.textContent=_.textContent?.replace(/{{\s*value\s*}}/g,l==null?"":String(l)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(v,m)=>{const y=e[m];return y==null?"":String(y)})||"")});const b=p.querySelector("input,textarea,select");if(b){const _=typeof HTMLInputElement<"u";_&&b instanceof HTMLInputElement&&b.type==="checkbox"?b.checked=!!l:"value"in b&&(b.value=l??""),b.addEventListener("blur",()=>{const v=_&&b instanceof HTMLInputElement&&b.type==="checkbox"?b.checked:b.value;c(v)}),b.addEventListener("keydown",v=>{if(v.key==="Enter"){v.stopPropagation(),v.preventDefault(),a=!0;const m=_&&b instanceof HTMLInputElement&&b.type==="checkbox"?b.checked:b.value;c(m),N(t,o,!1)}v.key==="Escape"&&(v.stopPropagation(),v.preventDefault(),f(),N(t,o,!0))}),_&&b instanceof HTMLInputElement&&b.type==="checkbox"&&b.addEventListener("change",()=>{const v=b.checked;c(v)}),r||setTimeout(()=>b.focus({preventScroll:!0}),0)}d.appendChild(p)}else if(typeof w=="string"){const p=document.createElement(w);p.value=h,p.addEventListener("change",()=>c(p.value)),d.appendChild(p),r||queueMicrotask(()=>{d.querySelector(B)?.focus({preventScroll:!0})})}else if(typeof w=="function"){const p=w({row:e,value:h,field:n.field,column:n,commit:c,cancel:f});typeof p=="string"?(d.innerHTML=p,Tt(d,n,c)):d.appendChild(p),r||queueMicrotask(()=>{d.querySelector(B)?.focus({preventScroll:!0})})}else if(w&&typeof w=="object"){const p=document.createElement("div");p.setAttribute("data-external-editor",""),p.setAttribute("data-field",n.field),d.appendChild(p);const g={row:e,value:h,field:n.field,column:n,commit:c,cancel:f};if(w.mount)try{w.mount({placeholder:p,context:g,spec:w})}catch{}else t.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:p,spec:w,context:g}}))}}function At(t,e,o){t.dispatchEvent(new CustomEvent(e,{detail:o,bubbles:!0}))}function Ae(t){return Array.from(t._changedRowIndices).map(e=>t._rows[e])}function xe(t){return Array.from(t._changedRowIndices)}function xt(t,e){t._changedRowIndices.clear(),e||At(t,"changed-rows-reset",{rows:Ae(t),indices:xe(t)}),t._rowPool.forEach(o=>o.classList.remove("changed"))}function Lt(t,e,o){if(t.effectiveConfig?.editOn===!1||!t._columns.some(l=>l.editable))return;const i=t._rows[e];$(t,e,i);const r=o.findRenderedRowElement(e);r&&(Array.from(r.children).forEach((l,s)=>{const a=t._visibleColumns[s];if(a?.editable){const c=l;c.classList.contains("editing")||k(t,i,e,a,c,!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 s=l.querySelector(B);try{s?.focus({preventScroll:!0})}catch{}}},0))}function Pt(t){t._activeEditRows!==-1&&N(t,t._activeEditRows,!1)}function Ht(t){t._activeEditRows!==-1&&N(t,t._activeEditRows,!0)}function oe(t,e){const o=ye(e),n=j(e);if(o<0||n<0)return null;const i=t._rows[o],r=t._visibleColumns[n];return!i||!r?null:{rowIndex:o,colIndex:n,rowData:i,col:r}}function Ot(t,e){if(e.classList.contains("editing"))return;const o=oe(t,e);o&&(t._focusRow=o.rowIndex,t._focusCol=o.colIndex,z(t))}function Mt(t,e,o){if(e.classList.contains("editing"))return;const n=oe(t,e);n&&(o.stopPropagation(),t._focusRow=n.rowIndex,t._focusCol=n.colIndex,k(t,n.rowData,n.rowIndex,n.col,e))}function kt(t,e,o){o.stopPropagation();const n=oe(t,e);if(!n)return;if(typeof t.beginBulkEdit=="function"){t._focusRow=n.rowIndex,t._focusCol=n.colIndex,t.beginBulkEdit(n.rowIndex);return}$(t,n.rowIndex,n.rowData);const i=t.findRenderedRowElement?.(n.rowIndex);if(i){const r=i.children;for(let l=0;l<r.length;l++){const s=t._visibleColumns[l];s&&s.editable&&k(t,n.rowData,n.rowIndex,s,r[l],!0)}queueMicrotask(()=>{const l=i.querySelector(`.cell[data-col="${t._focusCol}"]`);if(l?.classList.contains("editing")){const s=l.querySelector(B);try{s?.focus({preventScroll:!0})}catch{}}})}}function Dt(t,e,o){const n=oe(t,e);if(!n)return;const{rowIndex:i,colIndex:r,rowData:l,col:s}=n,a=e.classList.contains("editing");if((s.type==="select"||s.type==="typeahead")&&!a&&o.key==="Enter"){o.preventDefault(),t._activeEditRows!==i&&$(t,i,l),k(t,l,i,s,e),setTimeout(()=>{const c=e.querySelector("select");try{c?.showPicker?.()}catch{}c?.focus({preventScroll:!0})},0);return}if(s.type==="boolean"&&o.key===" "&&!a){o.preventDefault(),t._activeEditRows!==i&&$(t,i,l);const c=!l[s.field];ce(t,i,s,c,l),e.innerHTML=re(!!c);return}if(o.key==="Enter"&&!a){o.preventDefault(),o.stopPropagation(),t._focusRow=i,t._focusCol=r,typeof t.beginBulkEdit=="function"?t.beginBulkEdit(i):k(t,l,i,s,e);return}if(o.key==="F2"&&!a){o.preventDefault(),k(t,l,i,s,e);return}}function zt(t,e,o){const n=()=>t.effectiveConfig?.editOn||t.editOn;e.addEventListener("mousedown",i=>{const r=i.target.closest(".cell[data-col]");if(!r)return;const l=j(r);if(l<0)return;const s=t._visibleColumns[l];s&&s.editable&&Ot(t,r)},{signal:o}),e.addEventListener("click",i=>{if(n()!=="click")return;const l=i.target.closest(".cell[data-col]");if(!l)return;const s=j(l);if(s<0)return;const a=t._visibleColumns[s];a&&a.editable&&Mt(t,l,i)},{signal:o}),e.addEventListener("dblclick",i=>{const r=n();if((r==="dblclick"?"dblClick":r)==="click"||r===!1)return;const s=i.target.closest(".cell[data-col]");if(!s)return;const a=j(s);if(a<0)return;const c=t._visibleColumns[a];c&&c.editable&&kt(t,s,i)},{signal:o}),e.addEventListener("keydown",i=>{const r=i.target.closest(".cell[data-col]");if(!r)return;const l=j(r);if(l<0)return;const s=t._visibleColumns[l];s&&s.editable&&Dt(t,r,i)},{signal:o})}function Le(t,e){return t==null&&e==null?0:t==null?-1:e==null||t>e?1:t<e?-1:0}function Pe(t,e,o){const i=o.find(s=>s.field===e.field)?.sortComparator??Le,{field:r,direction:l}=e;return[...t].sort((s,a)=>i(s[r],a[r],s,a)*l)}function He(t,e,o,n){t._rows=e,t.__rowRenderEpoch++,t._rowPool.forEach(i=>i.__epoch=-1),F(t),t.refreshVirtualWindow(!0),t.dispatchEvent(new CustomEvent("sort-change",{detail:{field:o.field,direction:n}})),t.requestStateChange?.()}function Oe(t,e){!t._sortState||t._sortState.field!==e.field?(t._sortState||(t.__originalOrder=t._rows.slice()),Me(t,e,1)):t._sortState.direction===1?Me(t,e,-1):(t._sortState=null,t.__rowRenderEpoch++,t._rowPool.forEach(n=>n.__epoch=-1),t._rows=t.__originalOrder.slice(),F(t),t._headerRowEl?.querySelectorAll('[role="columnheader"].sortable')?.forEach(n=>{n.getAttribute("aria-sort")?(n.getAttribute("aria-sort")==="ascending"||n.getAttribute("aria-sort")==="descending")&&(t._sortState||n.setAttribute("aria-sort","none")):n.setAttribute("aria-sort","none")}),t.refreshVirtualWindow(!0),t.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:0}})),t.requestStateChange?.())}function Me(t,e,o){t._sortState={field:e.field,direction:o};const n={field:e.field,direction:o},i=t._columns,l=(t.effectiveConfig?.sortHandler??Pe)(t._rows,n,i);l&&typeof l.then=="function"?l.then(s=>{He(t,s,e,o)}):He(t,l,e,o)}function Nt(t,e){typeof e=="string"?t.textContent=e:e instanceof HTMLElement&&(t.innerHTML="",t.appendChild(e.cloneNode(!0)))}function F(t){t._headerRowEl=t.findHeaderRow();const e=t._headerRowEl;e.innerHTML="",t._visibleColumns.forEach((o,n)=>{const i=document.createElement("div");i.className="cell",ve(i,"header-cell"),i.setAttribute("role","columnheader"),i.setAttribute("aria-colindex",String(n+1)),i.setAttribute("data-field",o.field),i.setAttribute("data-col",String(n));const r=o.__headerTemplate;if(r)Array.from(r.childNodes).forEach(l=>i.appendChild(l.cloneNode(!0)));else{const l=o.header||o.field,s=document.createElement("span");s.textContent=l,i.appendChild(s)}if(o.sortable){i.classList.add("sortable"),i.tabIndex=0;const l=document.createElement("span");ve(l,"sort-indicator");const s=t._sortState?.field===o.field?t._sortState.direction:0,a={...M,...t.icons},c=s===1?a.sortAsc:s===-1?a.sortDesc:a.sortNone;Nt(l,c),i.appendChild(l),i.setAttribute("aria-sort",s===0?"none":s===1?"ascending":"descending"),i.addEventListener("click",f=>{t._resizeController?.isResizing||t._dispatchHeaderClick?.(f,n,i)||Oe(t,o)}),i.addEventListener("keydown",f=>{if(f.key==="Enter"||f.key===" "){if(f.preventDefault(),t._dispatchHeaderClick?.(f,n,i))return;Oe(t,o)}})}if(o.resizable){i.style.position="relative";const l=document.createElement("div");l.className="resize-handle",l.setAttribute("aria-hidden","true"),l.addEventListener("mousedown",s=>{s.stopPropagation(),s.preventDefault(),t._resizeController.start(s,n,i)}),l.addEventListener("dblclick",s=>{s.stopPropagation(),s.preventDefault(),t._resizeController.resetColumn(n)}),i.appendChild(l)}e.appendChild(i)}),e.querySelectorAll(".cell.sortable").forEach(o=>{o.getAttribute("aria-sort")||o.setAttribute("aria-sort","none")}),e.children.length>0?(e.setAttribute("role","row"),e.setAttribute("aria-rowindex","1")):(e.removeAttribute("role"),e.removeAttribute("aria-rowindex"))}const ke=typeof requestIdleCallback=="function";function It(t,e){return ke?requestIdleCallback(t,e):window.setTimeout(()=>{const o=Date.now();t({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-o))})},1)}function De(t){ke?cancelIdleCallback(t):clearTimeout(t)}function Bt(t){let e=null,o=null,n=null,i=null;const r=a=>{if(!e)return;const c=a.clientX-e.startX,f=Math.max(40,e.startWidth+c),d=t._visibleColumns[e.colIndex];d.width=f,d.__userResized=!0,d.__renderedWidth=f,o==null&&(o=requestAnimationFrame(()=>{o=null,t.updateTemplate?.()})),t.dispatchEvent(new CustomEvent("column-resize",{detail:{field:d.field,width:f}}))};let l=!1;const s=()=>{const a=e!==null;a&&(l=!0,requestAnimationFrame(()=>{l=!1})),window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",s),n!==null&&(document.documentElement.style.cursor=n,n=null),i!==null&&(document.body.style.userSelect=i,i=null),e=null,a&&t.requestStateChange&&t.requestStateChange()};return{get isResizing(){return e!==null||l},start(a,c,f){a.preventDefault();const d=f.getBoundingClientRect();e={startX:a.clientX,colIndex:c,startWidth:d.width},window.addEventListener("mousemove",r),window.addEventListener("mouseup",s),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=t._visibleColumns[a];c&&(c.__userResized=!1,c.__renderedWidth=void 0,c.width=c.__originalWidth,t.updateTemplate?.(),t.requestStateChange?.(),t.dispatchEvent(new CustomEvent("column-resize-reset",{detail:{field:c.field,width:c.width}})))},dispose(){s()}}}function ne(t,e,o){const n=document.createElement(t);if(e)for(const i in e){const r=e[i];r!=null&&n.setAttribute(i,r)}return n}function R(t,e){const o=document.createElement("div");if(t&&(o.className=t),e)for(const n in e){const i=e[n];i!=null&&o.setAttribute(n,i)}return o}function ze(t,e,o){const n=document.createElement("button");if(t&&(n.className=t),e)for(const i in e){const r=e[i];r!=null&&n.setAttribute(i,r)}return n}function Ne(t){const e=document.createElement("slot");return t&&(e.name=t),e}const Ie=document.createElement("template");Ie.innerHTML=`
|
|
2
2
|
<div class="tbw-scroll-area">
|
|
3
3
|
<div class="rows-body-wrapper">
|
|
4
4
|
<div class="rows-body" role="grid">
|
|
5
|
-
<div class="header">
|
|
6
|
-
<div class="header-row" part="header-row"></div>
|
|
5
|
+
<div class="header" role="rowgroup">
|
|
6
|
+
<div class="header-row" role="row" part="header-row"></div>
|
|
7
7
|
</div>
|
|
8
|
-
<div class="rows-container">
|
|
9
|
-
<div class="rows-viewport">
|
|
8
|
+
<div class="rows-container" role="presentation">
|
|
9
|
+
<div class="rows-viewport" role="presentation">
|
|
10
10
|
<div class="rows"></div>
|
|
11
11
|
</div>
|
|
12
12
|
</div>
|
|
@@ -16,17 +16,17 @@
|
|
|
16
16
|
<div class="faux-vscroll">
|
|
17
17
|
<div class="faux-vscroll-spacer"></div>
|
|
18
18
|
</div>
|
|
19
|
-
`;function
|
|
19
|
+
`;function Be(){return Ie.content.cloneNode(!0)}function qe(t){const e=document.createDocumentFragment(),o=R(t.hasShell?"tbw-grid-root has-shell":"tbw-grid-root");if(t.hasShell&&t.shellHeader&&t.shellBody)o.appendChild(t.shellHeader),o.appendChild(t.shellBody);else{const n=R("tbw-grid-content");n.appendChild(Be()),o.appendChild(n)}return e.appendChild(o),e}function qt(t){const e=R("tbw-shell-header",{part:"shell-header",role:"presentation"});if(t.title){const r=R("tbw-shell-title");r.textContent=t.title,e.appendChild(r)}const o=R("tbw-shell-content",{part:"shell-content",role:"presentation"});o.appendChild(Ne("header-content")),e.appendChild(o);const n=R("tbw-shell-toolbar",{part:"shell-toolbar",role:"presentation"});for(const r of t.configButtons)(r.hasElement||r.hasRender)&&n.appendChild(R("tbw-toolbar-btn-slot",{"data-btn-slot":r.id}));for(const r of t.apiButtons)(r.hasElement||r.hasRender)&&n.appendChild(R("tbw-toolbar-btn-slot",{"data-btn-slot":r.id}));if(n.appendChild(Ne("toolbar")),(t.configButtons.some(r=>r.hasElement||r.hasRender)||t.apiButtons.some(r=>r.hasElement||r.hasRender))&&t.hasPanels&&n.appendChild(R("tbw-toolbar-separator")),t.hasPanels){const r=ze(t.isPanelOpen?"tbw-toolbar-btn active":"tbw-toolbar-btn",{"data-panel-toggle":"",title:"Settings","aria-label":"Toggle settings panel","aria-pressed":String(t.isPanelOpen),"aria-controls":"tbw-tool-panel"});r.innerHTML=t.toolPanelIcon,n.appendChild(r)}return e.appendChild(n),e}function Wt(t){const e=R("tbw-shell-body"),o=t.panels.length>0,n=t.panels.length===1,i=R("tbw-grid-content");i.appendChild(Be());let r=null;if(o){r=ne("aside",{class:t.isPanelOpen?"tbw-tool-panel open":"tbw-tool-panel",part:"tool-panel","data-position":t.position,role:"presentation",id:"tbw-tool-panel"});const l=t.position==="left"?"right":"left";r.appendChild(R("tbw-tool-panel-resize",{"data-resize-handle":"","data-handle-position":l,"aria-hidden":"true"}));const s=R("tbw-tool-panel-content",{role:"presentation"}),a=R("tbw-accordion");for(const c of t.panels){const f=`tbw-accordion-section${c.isExpanded?" expanded":""}${n?" single":""}`,d=R(f,{"data-section":c.id}),u=ze("tbw-accordion-header",{"aria-expanded":String(c.isExpanded),"aria-controls":`tbw-section-${c.id}`});if(n&&u.setAttribute("aria-disabled","true"),c.icon){const h=ne("span",{class:"tbw-accordion-icon"});h.innerHTML=c.icon,u.appendChild(h)}const w=ne("span",{class:"tbw-accordion-title"});if(w.textContent=c.title,u.appendChild(w),!n){const h=ne("span",{class:"tbw-accordion-chevron"});h.innerHTML=c.isExpanded?t.collapseIcon:t.expandIcon,u.appendChild(h)}d.appendChild(u),d.appendChild(R("tbw-accordion-content",{id:`tbw-section-${c.id}`,role:"presentation"})),a.appendChild(d)}s.appendChild(a),r.appendChild(s)}return t.position==="left"&&r?(e.appendChild(r),e.appendChild(i)):(e.appendChild(i),r&&e.appendChild(r)),e}function q(t){return t?typeof t=="string"?t:t.outerHTML:""}function Vt(){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 We(t,e){return!!(t?.header?.title||e.lightDomTitle||t?.header?.toolbarButtons?.length||e.toolPanels.size>0||e.headerContents.size>0||e.toolbarButtons.size>0||e.lightDomHeaderContent.length>0||e.hasToolButtonsContainer)}function Ve(t,e,o="☰"){const n=t?.header?.title??e.lightDomTitle??"",i=!!n,r=q(o),l=t?.header?.toolbarButtons??[],s=l.some(p=>p.element||p.render),a=[...e.toolbarButtons.values()].some(p=>p.element||p.render),c=e.toolPanels.size>0,d=(s||a)&&c,u=[...l].sort((p,g)=>(p.order??100)-(g.order??100)),w=[...e.toolbarButtons.values()].sort((p,g)=>(p.order??100)-(g.order??100));let h="";for(const p of u)(p.element||p.render)&&(h+=`<div class="tbw-toolbar-btn-slot" data-btn-slot="${p.id}"></div>`);for(const p of w)(p.element||p.render)&&(h+=`<div class="tbw-toolbar-btn-slot" data-btn-slot="${p.id}"></div>`);if(h+='<slot name="toolbar"></slot>',d&&(h+='<div class="tbw-toolbar-separator"></div>'),c){const p=e.isPanelOpen;h+=`<button class="${p?"tbw-toolbar-btn active":"tbw-toolbar-btn"}" data-panel-toggle title="Settings" aria-label="Toggle settings panel" aria-pressed="${p}" aria-controls="tbw-tool-panel">${r}</button>`}return`
|
|
20
20
|
<div class="tbw-shell-header" part="shell-header" role="presentation">
|
|
21
21
|
${i?`<div class="tbw-shell-title">${n}</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
|
+
${h}
|
|
27
27
|
</div>
|
|
28
28
|
</div>
|
|
29
|
-
`}function U(t,e){const o=t.querySelector("tbw-grid-header");if(!o)return;if(!e.lightDomTitle){const r=o.getAttribute("title");r&&(e.lightDomTitle=r)}const n=o.querySelectorAll("tbw-grid-header-content");n.length>0&&e.lightDomHeaderContent.length===0&&(e.lightDomHeaderContent=Array.from(n),e.lightDomHeaderContent.forEach(r=>{r.setAttribute("slot","header-content")}));const i=o.querySelectorAll("tbw-grid-tool-button"),l=o.querySelectorAll('button.tbw-toolbar-btn[slot="toolbar"]');i.length>0&&e.lightDomButtons.length===0?(e.lightDomButtons=Array.from(i).map(r=>{const s=document.createElement("button");s.className="tbw-toolbar-btn";const a=r.getAttribute("id")??"",c=r.getAttribute("label")??"",h=r.getAttribute("icon")??"",d=r.getAttribute("order")??"100";return s.setAttribute("data-btn",a),s.setAttribute("title",c),s.setAttribute("aria-label",c),s.setAttribute("data-order",d),s.textContent=h,s.setAttribute("slot","toolbar"),r.replaceWith(s),s}),e.lightDomButtons.sort((r,s)=>{const a=parseInt(r.getAttribute("data-order")??"100",10),c=parseInt(s.getAttribute("data-order")??"100",10);return a-c})):l.length>0&&e.lightDomButtons.length===0&&(e.lightDomButtons=Array.from(l),e.lightDomButtons.sort((r,s)=>{const a=parseInt(r.getAttribute("data-order")??"100",10),c=parseInt(s.getAttribute("data-order")??"100",10);return a-c})),e.lightDomButtons.forEach(r=>{r.parentElement===o&&t.appendChild(r)}),o.style.display="none"}function X(t,e,o){t.querySelectorAll(":scope > tbw-grid-tool-panel").forEach(i=>{const l=i,r=l.getAttribute("id"),s=l.getAttribute("title");if(!r||!s){console.warn(`[parseLightDomToolPanels] Tool panel missing required id or title attribute: id="${r??""}", title="${s??""}"`);return}const a=l.getAttribute("icon")??void 0,c=l.getAttribute("tooltip")??void 0,h=parseInt(l.getAttribute("order")??"100",10);let d;const u=o?.(l);if(u)d=u;else{const b=l.innerHTML.trim();d=g=>{const w=document.createElement("div");return w.innerHTML=b,g.appendChild(w),()=>w.remove()}}const p=e.toolPanels.get(r);if(p){if(u){p.render=d,p.order=h,p.icon=a,p.tooltip=c;const b=e.panelCleanups.get(r);b&&(b(),e.panelCleanups.delete(r))}return}const f={id:r,title:s,icon:a,tooltip:c,order:h,render:d};e.toolPanels.set(r,f),e.lightDomToolPanelIds.add(r),l.style.display="none"})}function qt(t,e,o,n){const i=t.querySelector(".tbw-shell-toolbar");i&&i.addEventListener("click",r=>{const s=r.target;if(s.closest("[data-panel-toggle]")){n.onPanelToggle();return}const c=s.closest("[data-btn]");if(c){const h=c.getAttribute("data-btn");h&&n.onToolbarButtonClick(h)}});const l=t.querySelector(".tbw-accordion");l&&l.addEventListener("click",r=>{const a=r.target.closest(".tbw-accordion-header");if(a){const h=a.closest("[data-section]")?.getAttribute("data-section");h&&n.onSectionToggle(h)}})}function Wt(t,e,o){const n=t.querySelector(".tbw-tool-panel"),i=t.querySelector("[data-resize-handle]"),l=t.querySelector(".tbw-shell-body");if(!n||!i||!l)return()=>{};const r=e?.toolPanel?.position??"right",s=200;let a=0,c=0,h=0,d=!1;const u=b=>{if(!d)return;b.preventDefault();const g=r==="left"?b.clientX-a:a-b.clientX,w=Math.min(h,Math.max(s,c+g));n.style.width=`${w}px`},p=()=>{if(!d)return;d=!1,i.classList.remove("resizing"),n.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const b=n.getBoundingClientRect().width;o(b),document.removeEventListener("mousemove",u),document.removeEventListener("mouseup",p)},f=b=>{b.preventDefault(),d=!0,a=b.clientX,c=n.getBoundingClientRect().width,h=l.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",u),document.addEventListener("mouseup",p)};return i.addEventListener("mousedown",f),()=>{i.removeEventListener("mousedown",f),document.removeEventListener("mousemove",u),document.removeEventListener("mouseup",p)}}function $t(t,e,o){const n=[...e?.header?.toolbarButtons??[],...o.toolbarButtons.values()];for(const i of n){const l=t.querySelector(`[data-btn-slot="${i.id}"]`);if(!l)continue;const r=o.toolbarButtonCleanups.get(i.id);if(r&&(r(),o.toolbarButtonCleanups.delete(i.id)),i.element)l.appendChild(i.element);else if(i.render){const s=i.render(l);s&&o.toolbarButtonCleanups.set(i.id,s)}}}function We(t,e){const o=t.querySelector(".tbw-shell-content");if(!o)return;const n=[...e.headerContents.values()].sort((l,r)=>(l.order??100)-(r.order??100)),i=o.querySelector('slot[name="header-content"]');for(const l of n){const r=e.headerContentCleanups.get(l.id);r&&(r(),e.headerContentCleanups.delete(l.id));let s=o.querySelector(`[data-header-content="${l.id}"]`);s||(s=document.createElement("div"),s.setAttribute("data-header-content",l.id),i?o.insertBefore(s,i):o.appendChild(s));const a=l.render(s);a&&e.headerContentCleanups.set(l.id,a)}}function Vt(t,e,o){if(!e.isPanelOpen)return;const n=O(o?.expand??P.expand),i=O(o?.collapse??P.collapse);for(const[l,r]of e.toolPanels){const s=e.expandedSections.has(l),a=t.querySelector(`[data-section="${l}"]`),c=a?.querySelector(".tbw-accordion-content");if(!a||!c)continue;a.classList.toggle("expanded",s);const h=a.querySelector(".tbw-accordion-header");h&&h.setAttribute("aria-expanded",String(s));const d=a.querySelector(".tbw-accordion-chevron");if(d&&(d.innerHTML=s?i:n),s){if(c.children.length===0){const u=r.render(c);u&&e.panelCleanups.set(l,u)}}else{const u=e.panelCleanups.get(l);u&&(u(),e.panelCleanups.delete(l)),c.innerHTML=""}}}function $e(t,e){const o=t.querySelector("[data-panel-toggle]");o&&(o.classList.toggle("active",e.isPanelOpen),o.setAttribute("aria-pressed",String(e.isPanelOpen)))}function Ve(t,e){const o=t.querySelector(".tbw-tool-panel");o&&(o.classList.toggle("open",e.isPanelOpen),e.isPanelOpen||(o.style.width=""))}function Gt(t,e){const o=[];for(const n of t?.header?.toolbarButtons??[])o.push({id:n.id,label:n.label,disabled:n.disabled??!1,source:"config"});for(const n of e.toolbarButtons.values())o.push({id:n.id,label:n.label,disabled:n.disabled??!1,source:"config"});for(let n=0;n<e.lightDomButtons.length;n++){const l=e.lightDomButtons[n].querySelector("button");o.push({id:`light-dom-${n}`,label:l?.getAttribute("title")??l?.getAttribute("aria-label")??"",disabled:l?.disabled??!1,source:"light-dom"})}for(const n of e.toolPanels.values())o.push({id:`panel-toggle-${n.id}`,label:n.tooltip??n.title,disabled:!1,source:"panel-toggle",panelId:n.id});return o}function Ft(t){for(const e of t.headerContentCleanups.values())e();t.headerContentCleanups.clear(),t.activePanelCleanup&&(t.activePanelCleanup(),t.activePanelCleanup=null);for(const e of t.toolbarButtonCleanups.values())e();t.toolbarButtonCleanups.clear(),t.activePanel&&t.toolPanels.get(t.activePanel)?.onClose?.(),t.toolPanels.clear(),t.headerContents.clear(),t.toolbarButtons.clear(),t.lightDomButtons=[],t.lightDomHeaderContent=[],t.activePanel=null}function Ut(t,e){let o=!1;const n={get isInitialized(){return o},setInitialized(i){o=i},get isPanelOpen(){return t.isPanelOpen},get activePanel(){return t.isPanelOpen&&t.expandedSections.size>0?[...t.expandedSections][0]:null},get expandedSections(){return[...t.expandedSections]},openToolPanel(){if(t.isPanelOpen)return;if(t.toolPanels.size===0){console.warn("[tbw-grid] No tool panels registered");return}if(t.isPanelOpen=!0,t.expandedSections.size===0&&t.toolPanels.size>0){const r=[...t.toolPanels.values()].sort((s,a)=>(s.order??100)-(a.order??100))[0];r&&t.expandedSections.add(r.id)}const i=e.getShadow();$e(i,t),Ve(i,t),Vt(i,t,e.getAccordionIcons()),e.emit("tool-panel-open",{sections:n.expandedSections})},closeToolPanel(){if(!t.isPanelOpen)return;for(const l of t.panelCleanups.values())l();t.panelCleanups.clear(),t.activePanelCleanup&&(t.activePanelCleanup(),t.activePanelCleanup=null);for(const l of t.toolPanels.values())l.onClose?.();t.isPanelOpen=!1;const i=e.getShadow();$e(i,t),Ve(i,t),e.emit("tool-panel-close",{})},toggleToolPanel(){t.isPanelOpen?n.closeToolPanel():n.openToolPanel()},toggleToolPanelSection(i){const l=t.toolPanels.get(i);if(!l){console.warn(`[tbw-grid] Tool panel section "${i}" not found`);return}if(t.toolPanels.size===1)return;const r=e.getShadow(),s=t.expandedSections.has(i);if(s){const a=t.panelCleanups.get(i);a&&(a(),t.panelCleanups.delete(i)),l.onClose?.(),t.expandedSections.delete(i),de(r,i,!1)}else{for(const[a,c]of t.toolPanels)if(a!==i&&t.expandedSections.has(a)){const h=t.panelCleanups.get(a);h&&(h(),t.panelCleanups.delete(a)),c.onClose?.(),t.expandedSections.delete(a),de(r,a,!1);const d=r.querySelector(`[data-section="${a}"] .tbw-accordion-content`);d&&(d.innerHTML="")}t.expandedSections.add(i),de(r,i,!0),Xt(r,t,i)}e.emit("tool-panel-section-toggle",{id:i,expanded:!s})},getToolPanels(){return[...t.toolPanels.values()]},registerToolPanel(i){if(t.toolPanels.has(i.id)){console.warn(`[tbw-grid] Tool panel "${i.id}" already registered`);return}t.toolPanels.set(i.id,i),o&&e.refreshShellHeader()},unregisterToolPanel(i){if(t.expandedSections.has(i)){const l=t.panelCleanups.get(i);l&&(l(),t.panelCleanups.delete(i)),t.expandedSections.delete(i)}t.toolPanels.delete(i),o&&e.refreshShellHeader()},getHeaderContents(){return[...t.headerContents.values()]},registerHeaderContent(i){if(t.headerContents.has(i.id)){console.warn(`[tbw-grid] Header content "${i.id}" already registered`);return}t.headerContents.set(i.id,i),o&&We(e.getShadow(),t)},unregisterHeaderContent(i){const l=t.headerContentCleanups.get(i);l&&(l(),t.headerContentCleanups.delete(i)),t.headerContents.get(i)?.onDestroy?.(),t.headerContents.delete(i),e.getShadow().querySelector(`[data-header-content="${i}"]`)?.remove()},getToolbarButtons(){return Gt(e.getShellConfig(),t)},registerToolbarButton(i){if(t.toolbarButtons.has(i.id)){console.warn(`[tbw-grid] Toolbar button "${i.id}" already registered`);return}t.toolbarButtons.set(i.id,i),o&&e.refreshShellHeader()},unregisterToolbarButton(i){const l=t.toolbarButtonCleanups.get(i);l&&(l(),t.toolbarButtonCleanups.delete(i)),t.toolbarButtons.delete(i),o&&e.refreshShellHeader()},setToolbarButtonDisabled(i,l){const r=t.toolbarButtons.get(i);r&&(r.disabled=l);const s=e.getShadow().querySelector(`[data-btn="${i}"]`);s&&(s.disabled=l)}};return n}function de(t,e,o){const n=t.querySelector(`[data-section="${e}"]`);n&&n.classList.toggle("expanded",o)}function Xt(t,e,o){const n=e.toolPanels.get(o);if(!n?.render)return;const i=t.querySelector(`[data-section="${o}"] .tbw-accordion-content`);if(!i)return;const l=n.render(i);l&&e.panelCleanups.set(o,l)}function Yt(t,e,o,n){const i=ce(e,o);if(t.replaceChildren(),i){const l=O(n?.toolPanel??P.toolPanel),r=O(n?.expand??P.expand),s=O(n?.collapse??P.collapse),c=[...e?.header?.toolbarButtons??[]].sort((w,_)=>(w.order??100)-(_.order??100)),h=[...o.toolbarButtons.values()].sort((w,_)=>(w.order??100)-(_.order??100)),d={title:e?.header?.title??o.lightDomTitle??void 0,hasLightDomButtons:o.lightDomButtons.length>0,hasPanels:o.toolPanels.size>0,isPanelOpen:o.isPanelOpen,toolPanelIcon:l,configButtons:c.map(w=>({id:w.id,label:w.label,icon:O(w.icon),disabled:w.disabled,hasElement:!!w.element,hasRender:!!w.render,action:w.action})),apiButtons:h.map(w=>({id:w.id,label:w.label,icon:O(w.icon),disabled:w.disabled,hasElement:!!w.element,hasRender:!!w.render,action:w.action}))},u=[...o.toolPanels.values()].sort((w,_)=>(w.order??100)-(_.order??100)),p={position:e?.toolPanel?.position??"right",isPanelOpen:o.isPanelOpen,expandIcon:r,collapseIcon:s,panels:u.map(w=>({id:w.id,title:w.title,icon:O(w.icon),isExpanded:o.expandedSections.has(w.id)}))},f=Nt(d),b=It(p),g=Be({hasShell:!0,shellHeader:f,shellBody:b});t.appendChild(g)}else{const l=Be({hasShell:!1});t.appendChild(l)}return i}function jt(){return{startY:null,startX:null,scrollTop:null,scrollLeft:null,lastY:null,lastX:null,lastTime:null,velocityY:0,velocityX:0,momentumRaf:0}}function Kt(t){t.startY=null,t.startX=null,t.scrollTop=null,t.scrollLeft=null,t.lastY=null,t.lastX=null,t.lastTime=null}function Ge(t){t.momentumRaf&&(cancelAnimationFrame(t.momentumRaf),t.momentumRaf=0)}function Zt(t,e,o){if(t.touches.length!==1)return;Ge(e);const n=t.touches[0];e.startY=n.clientY,e.startX=n.clientX,e.lastY=n.clientY,e.lastX=n.clientX,e.lastTime=performance.now(),e.scrollTop=o.fauxScrollbar.scrollTop,e.scrollLeft=o.scrollArea?.scrollLeft??0,e.velocityY=0,e.velocityX=0}function Qt(t,e,o){if(t.touches.length!==1||e.startY===null||e.startX===null||e.scrollTop===null||e.scrollLeft===null)return!1;const n=t.touches[0],i=n.clientY,l=n.clientX,r=performance.now(),s=e.startY-i,a=e.startX-l;if(e.lastTime!==null&&e.lastY!==null&&e.lastX!==null){const b=r-e.lastTime;b>0&&(e.velocityY=(e.lastY-i)/b,e.velocityX=(e.lastX-l)/b)}e.lastY=i,e.lastX=l,e.lastTime=r;const{scrollTop:c,scrollHeight:h,clientHeight:d}=o.fauxScrollbar,u=h-d,p=s>0&&c<u||s<0&&c>0;let f=!1;if(o.scrollArea){const{scrollLeft:b,scrollWidth:g,clientWidth:w}=o.scrollArea,_=g-w;f=a>0&&b<_||a<0&&b>0}return p&&(o.fauxScrollbar.scrollTop=e.scrollTop+s),f&&o.scrollArea&&(o.scrollArea.scrollLeft=e.scrollLeft+a),p||f}function Jt(t,e){(Math.abs(t.velocityY)>.1||Math.abs(t.velocityX)>.1)&&eo(t,e),Kt(t)}function eo(t,e){const i=()=>{t.velocityY*=.95,t.velocityX*=.95;const l=t.velocityY*16,r=t.velocityX*16;Math.abs(t.velocityY)>.01&&(e.fauxScrollbar.scrollTop+=l),Math.abs(t.velocityX)>.01&&e.scrollArea&&(e.scrollArea.scrollLeft+=r),Math.abs(t.velocityY)>.01||Math.abs(t.velocityX)>.01?t.momentumRaf=requestAnimationFrame(i):t.momentumRaf=0};t.momentumRaf=requestAnimationFrame(i)}function to(t,e,o,n){t.addEventListener("touchstart",i=>Zt(i,e,o),{passive:!0,signal:n}),t.addEventListener("touchmove",i=>{Qt(i,e,o)&&i.preventDefault()},{passive:!1,signal:n}),t.addEventListener("touchend",()=>Jt(e,o),{passive:!0,signal:n})}class Fe{constructor(e){this.grid=e}plugins=[];pluginMap=new Map;cellRenderers=new Map;headerRenderers=new Map;cellEditors=new Map;attachAll(e){for(const o of e)this.attach(o)}attach(e){if(this.pluginMap.set(e.constructor,e),this.plugins.push(e),e.cellRenderers)for(const[o,n]of Object.entries(e.cellRenderers))this.cellRenderers.set(o,n);if(e.headerRenderers)for(const[o,n]of Object.entries(e.headerRenderers))this.headerRenderers.set(o,n);if(e.cellEditors)for(const[o,n]of Object.entries(e.cellEditors))this.cellEditors.set(o,n);e.attach(this.grid)}detachAll(){for(let e=this.plugins.length-1;e>=0;e--)this.plugins[e].detach();this.plugins=[],this.pluginMap.clear(),this.cellRenderers.clear(),this.headerRenderers.clear(),this.cellEditors.clear()}getPlugin(e){return this.pluginMap.get(e)}getPluginByName(e){return this.plugins.find(o=>o.name===e)}hasPlugin(e){return this.pluginMap.has(e)}getAll(){return this.plugins}getCellRenderer(e){return this.cellRenderers.get(e)}getHeaderRenderer(e){return this.headerRenderers.get(e)}getCellEditor(e){return this.cellEditors.get(e)}getAllStyles(){return this.plugins.filter(e=>e.styles).map(e=>e.styles).join(`
|
|
30
|
-
`)}processRows(e){let o=[...e];for(const n of this.plugins)n.processRows&&(o=n.processRows(o));return o}processColumns(e){let o=[...e];for(const n of this.plugins)n.processColumns&&(o=n.processColumns(o));return o}beforeRender(){for(const e of this.plugins)e.beforeRender?.()}afterRender(){for(const e of this.plugins)e.afterRender?.()}onScrollRender(){for(const e of this.plugins)e.onScrollRender?.()}getExtraHeight(){let e=0;for(const o of this.plugins)typeof o.getExtraHeight=="function"&&(e+=o.getExtraHeight());return e}getExtraHeightBefore(e){let o=0;for(const n of this.plugins)typeof n.getExtraHeightBefore=="function"&&(o+=n.getExtraHeightBefore(e));return o}adjustVirtualStart(e,o,n){let i=e;for(const
|
|
31
|
-
`);if(l.includes(".tbw-grid-root")&&l.includes(":host")){o=l;break}}catch{continue}o?(e.replaceSync(o),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(o){console.warn("[tbw-grid] Failed to extract grid.css from document stylesheets:",o)}}getPlugin(e){return this.#e?.getPlugin(e)}getPluginByName(e){return this.#e?.getPluginByName(e)}requestRender(){this.#H(),this.#P(),G(this),I(this),this.refreshVirtualWindow(!0)}updateTemplate(){I(this)}requestAfterRender(){this.#e?.afterRender()}#j(){this.#e=new Fe(this);const e=this.#t?.plugins,o=Array.isArray(e)?e:[];this.#e.attachAll(o)}#K(){const e=this.#e?.getAllStyles()??"";if(e){const o=document.createElement("style");o.setAttribute("data-plugin","all"),o.textContent=e,this.#n.appendChild(o)}}#Z(){this.#e&&this.#e.detachAll(),this.#j(),this.#K(),this.#Q(),this.#A=this.#e?.getAll().some(e=>e.onScroll)??!1}#ne(){this.#e?.detachAll()}#Q(){if(!this.#e)return;const e=this.#e.getToolPanels();for(const{panel:n}of e)this.#o.toolPanels.has(n.id)||this.#o.toolPanels.set(n.id,n);const o=this.#e.getHeaderContents();for(const{content:n}of o)this.#o.headerContents.has(n.id)||this.#o.headerContents.set(n.id,n)}#_(){const e=k.getAdapters();if(e.length===0&&!this.__frameworkAdapter)return;const o=this.__frameworkAdapter;return n=>{if(o?.createToolPanelRenderer){const i=o.createToolPanelRenderer(n);if(i)return i}for(const i of e)if(i.createToolPanelRenderer){const l=i.createToolPanelRenderer(n);if(l)return l}}}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.hasAttribute("version")||this.setAttribute("version",k.version),this._rows=Array.isArray(this.#r)?[...this.#r]:[],this.#s&&(this.#s.abort(),this.#x=!1),this.#s=new AbortController,this.#h&&(De(this.#h),this.#h=void 0),U(this,this.#o),X(this,this.#o,this.#_()),this.#l(),this.#j(),this.#Q(),this.#M||(this.#G(),this.#K(),this.#M=!0),this.#I(),this.#h=Dt(()=>{this.#ve()},{timeout:100})}disconnectedCallback(){this.#h&&(De(this.#h),this.#h=void 0),this.#ne(),Ft(this.#o),this.#i.setInitialized(!1),this.#L?.(),this.#L=void 0,Ge(this.#Y),this.#s&&(this.#s.abort(),this.#s=void 0),this.#v?.abort(),this.#v=void 0,this.#x=!1,this._resizeController&&this._resizeController.dispose(),this.#b&&(this.#b.disconnect(),this.#b=void 0),this.#w&&(this.#w.disconnect(),this.#w=void 0,this.#B=!1),this.#u&&(this.#u.disconnect(),this.#u=void 0),Q(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.__scrollAreaEl=null,this.__footerEl=null,this.#O=!1}attributeChangedCallback(e,o,n){if(o===n||!n||n==="null"||n==="undefined")return;const l={rows:"rows",columns:"columns","grid-config":"gridConfig","fit-mode":"fitMode","edit-on":"editOn"}[e];if(l)if(e==="rows"||e==="columns"||e==="grid-config")try{this[l]=JSON.parse(n)}catch{console.warn(`[tbw-grid] Invalid JSON for '${e}' attribute:`,n)}else this[l]=n}#I(){const o=this.#n.querySelector(".tbw-grid-content")??this.#n.querySelector(".tbw-grid-root");if(this._headerRowEl=o?.querySelector(".header-row"),this._virtualization.totalHeightEl=o?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=o?.querySelector(".rows-viewport"),this._bodyEl=o?.querySelector(".rows"),this.__rowsBodyEl=o?.querySelector(".rows-body"),this.__scrollAreaEl=o?.querySelector(".tbw-scroll-area"),this.__footerEl=o?.querySelector(".tbw-footer"),this.#i.isInitialized){We(this.#n,this.#o),$t(this.#n,this.#t?.shell,this.#o);const l=this.#t?.shell?.toolPanel?.defaultOpen;l&&this.#o.toolPanels.has(l)&&(this.openToolPanel(),this.#o.expandedSections.add(l))}if(this.setAttribute("data-upgraded",""),this.#O=!0,this._resizeController=zt(this),this.#a(),this.#ie(o),this.#x)return;this.#x=!0;const n=this.disconnectSignal;this.addEventListener("keydown",l=>gt(this,l),{signal:n}),document.addEventListener("keydown",l=>{l.key==="Escape"&&this._activeEditRows!==-1&&N(this,this._activeEditRows,!0)},{capture:!0,signal:n}),document.addEventListener("mousedown",l=>{if(this._activeEditRows===-1)return;const r=this.findRenderedRowElement(this._activeEditRows);!r||(l.composedPath&&l.composedPath()||[]).includes(r)||N(this,this._activeEditRows,!1)},{signal:n}),this.#n.addEventListener("mousedown",l=>this.#be(l),{signal:n}),document.addEventListener("mousemove",l=>this.#we(l),{signal:n}),document.addEventListener("mouseup",l=>this.#ge(l),{signal:n});const i=this.#t.rowHeight;i&&i>0?this._virtualization.rowHeight=i:requestAnimationFrame(()=>this.#J()),queueMicrotask(()=>this.#re()),requestAnimationFrame(()=>requestAnimationFrame(()=>this.#X?.()))}#J(){const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const o=e.querySelectorAll(".cell");let n=0;o.forEach(r=>{const s=r.offsetHeight;s>n&&(n=s)});const i=e.getBoundingClientRect(),l=Math.max(i.height,n);l>0&&l!==this._virtualization.rowHeight&&(this._virtualization.rowHeight=l,this.refreshVirtualWindow(!0))}#ie(e){this.#v?.abort(),this.#v=new AbortController;const o=this.#v.signal,n=e?.querySelector(".faux-vscroll"),i=e?.querySelector(".rows");if(this._virtualization.container=n??this,this.#A=this.#e?.getAll().some(l=>l.onScroll)??!1,n&&i){n.addEventListener("scroll",()=>{if(!this._virtualization.enabled&&!this.#A)return;const s=n.scrollTop,a=this._virtualization.rowHeight;if(this._rows.length<=this._virtualization.bypassThreshold)i.style.transform=`translateY(${-s}px)`;else{const c=Math.floor(s/a),h=c-c%2,d=-(s-h*a);i.style.transform=`translateY(${d}px)`}this.#R=s,this.#p||(this.#p=requestAnimationFrame(()=>{this.#p=0,this.#R!==null&&(this.#pe(this.#R),this.#R=null)}))},{passive:!0,signal:o});const l=this.#n.querySelector(".tbw-grid-content"),r=this.#n.querySelector(".tbw-scroll-area");l&&(l.addEventListener("wheel",s=>{const a=s.shiftKey||Math.abs(s.deltaX)>Math.abs(s.deltaY);if(a&&r){const c=s.shiftKey?s.deltaY:s.deltaX,{scrollLeft:h,scrollWidth:d,clientWidth:u}=r;(c>0&&h<d-u||c<0&&h>0)&&(s.preventDefault(),r.scrollLeft+=c)}else if(!a){const{scrollTop:c,scrollHeight:h,clientHeight:d}=n;(s.deltaY>0&&c<h-d||s.deltaY<0&&c>0)&&(s.preventDefault(),n.scrollTop+=s.deltaY)}},{passive:!1,signal:o}),to(l,this.#Y,{fauxScrollbar:n,scrollArea:r},o))}this._bodyEl&&Ot(this,this._bodyEl,o),this.#b?.disconnect(),this._virtualization.viewportEl&&(this.#b=new ResizeObserver(()=>{this.#p||(this.#p=requestAnimationFrame(()=>{this.#p=0,this.refreshVirtualWindow(!0),z(this)}))}),this.#b.observe(this._virtualization.viewportEl)),this._virtualization.enabled&&requestAnimationFrame(()=>{this.refreshVirtualWindow(!0),this.#le()})}#B=!1;#le(){if(this.#B)return;const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;this.#B=!0,this.#w?.disconnect();const o=e.querySelectorAll(".cell");o.length>0&&(this.#w=new ResizeObserver(()=>{this.#J()}),o.forEach(n=>this.#w.observe(n)))}#d(e,o){this.dispatchEvent(new CustomEvent(e,{detail:o,bubbles:!0,composed:!0}))}_emitCellCommit(e){this.#d("cell-commit",e)}_emitRowCommit(e){this.#d("row-commit",e)}_emitSortChange(e){this.#d("sort-change",e)}_emitColumnResize(e){this.#d("column-resize",e)}_emitActivateCell(e){this.#d("activate-cell",e)}#re(){this._bodyEl?.querySelectorAll(".data-grid-row")?.forEach((o,n)=>{const i=n===this._focusRow;o.setAttribute("aria-selected",String(i)),o.querySelectorAll(".cell").forEach((l,r)=>{l.setAttribute("aria-selected",String(i&&r===this._focusCol))})})}#C(e){this.#k[e]=!0,!this.#m&&(this.#m=!0,queueMicrotask(()=>this.#se()))}#se(){if(!this.#m||!this.#O){this.#m=!1;return}const e=this.#k;if(this.#m=!1,this.#k={rows:!1,columns:!1,gridConfig:!1,fitMode:!1,editMode:!1},e.gridConfig){this.#he();return}e.columns&&this.#ce(),e.rows&&this.#ae(),e.fitMode&&this.#de(),e.editMode&&this.#ue()}#ae(){this._rows=Array.isArray(this.#r)?[...this.#r]:[],this.#H(),this._columns.length>0||Array.isArray(this.#t?.columns)&&this.#t.columns.length>0||Array.isArray(this.#c)&&this.#c.length>0?(this.#P(),this.refreshVirtualWindow(!0)):this.#a()}#ce(){Q(this),this.#l(),this.#a()}#de(){this.#l(),this.#t.fitMode==="fixed"?(this.__didInitialAutoSize=!1,Ce(this)):(this._columns.forEach(o=>{!o.__userResized&&o.__autoSized&&delete o.width}),I(this))}#ue(){this.#l(),this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.refreshVirtualWindow(!0)}#he(){const e=!!this.#n.querySelector(".has-shell");ce(this.#t,this.#o),_e(this),this.#l(),this.#Z();const o=ce(this.#t,this.#o);if(e!==o||!e&&o){this.#G(),this.#I();return}this.#H(),this.#P(),G(this),I(this),this.refreshVirtualWindow(!0)}#P(){if(this.#e){const e=this.#N.length>0?this.#N:this._columns,o=e.filter(l=>!l.hidden),n=e.filter(l=>l.hidden),i=this.#e.processColumns([...o]);if(i!==o){const l=new Map(i.map((s,a)=>[s.field,{col:s,order:a}]));if(!o.some(s=>l.has(s.field))&&i.length>0)this._columns=[...i,...n];else{const s=e.map(a=>{if(a.hidden)return a;const c=l.get(a.field);return c?c.col:a});this._columns=s}}else this._columns=[...e]}}#H(){Q(this);const e=Array.isArray(this.#r)?[...this.#r]:[],o=this.#e?.processRows(e)??e;this._rows=o}#l(){const e=this.#g?{...this.#g}:{};let o=Array.isArray(e.columns)?[...e.columns]:[];const n=(this.__lightDomColumnsCache||[]).map(i=>({...i}));if(n.length){const i={};o.forEach(l=>i[l.field]=l),n.forEach(l=>{const r=i[l.field];r?(l.header&&!r.header&&(r.header=l.header),l.type&&!r.type&&(r.type=l.type),r.sortable=r.sortable||l.sortable,l.resizable&&(r.resizable=!0),l.editable&&(r.editable=!0)):(o.push(l),i[l.field]=l)})}if(this.#c&&this.#c.length&&(o=[...this.#c]),(!o||o.length===0)&&this._rows.length&&(o=be(this._rows).columns),o.length){o.forEach(r=>{r.sortable===void 0&&(r.sortable=!0),r.resizable===void 0&&(r.resizable=!0);const s=r;s.__originalWidth===void 0&&typeof r.width=="number"&&(s.__originalWidth=r.width)});const i=this.#t.columns;i?.some(r=>r.__compiledView||r.__compiledEditor)?e.columns=i:e.columns=o}else{const i=this.#t.columns;i?.some(l=>l.__compiledView||l.__compiledEditor)&&(e.columns=i)}this.#y&&(e.fitMode=this.#y),e.fitMode||(e.fitMode="stretch"),this.#S&&(e.editOn=this.#S),this.#o.lightDomTitle&&(e.shell||(e.shell={}),e.shell.header||(e.shell.header={}),e.shell.header.title||(e.shell.header.title=this.#o.lightDomTitle)),e.rowHeight&&e.rowHeight>0&&(this._virtualization.rowHeight=e.rowHeight),e.columnState&&!this.#f&&(this.#f=e.columnState),this.#t=e,e.fitMode==="fixed"&&this._columns.forEach(i=>{i.width==null&&(i.width=80)}),this.#fe()}#fe(){const e={...pe,...this.#t.animation},o=e.mode??"reduced-motion";let n=1;o===!1||o==="off"?n=0:(o===!0||o==="on")&&(n=1),this.style.setProperty("--tbw-animation-duration",`${e.duration}ms`),this.style.setProperty("--tbw-animation-easing",e.easing??"ease-out"),this.style.setProperty("--tbw-animation-enabled",String(n)),this.dataset.animationMode=typeof o=="boolean"?o?"on":"off":o}#q(e,o,n=this.__rowRenderEpoch){this.#D||(this.#D=(i,l,r)=>this.#e?.renderRow(i,l,r)??!1),Et(this,e,o,n,this.#D)}#a(){if(!this.isConnected||!this._headerRowEl||!this._bodyEl)return;const e=this.#g?.columns||this.#c||[];if(e.length){const n=new Map(this._columns.filter(l=>l.hidden).map(l=>[l.field,!0])),i=e.map(l=>({...l,hidden:n.get(l.field)??l.hidden}));this._columns=i}if(_e(this),this.#l(),this.#Z(),this.#N=[...this._columns],this.#H(),this.#P(),this.#f){const n=this.#f;this.#f=void 0,this.#ee(n)}G(this),I(this),this.refreshVirtualWindow(!0),this.#t.fitMode==="fixed"&&!this.__didInitialAutoSize&&requestAnimationFrame(()=>Ce(this)),this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),queueMicrotask(()=>this.#e?.afterRender())}#ee(e){const o=this.#t.columns??[],n=this.#e?.getAll()??[];je(this,e,o,n);for(const i of e.columns){const l=o.find(r=>r.field===i.field);l&&(l.hidden=!i.visible)}}#pe(e){if(this.refreshVirtualWindow(!1),this.#e?.onScrollRender(),this.#A){const o=this._virtualization.container,n=this.#te;n.scrollTop=e,n.scrollLeft=o?.scrollLeft??0,n.scrollHeight=o?.scrollHeight??0,n.scrollWidth=o?.scrollWidth??0,n.clientHeight=o?.clientHeight??0,n.clientWidth=o?.clientWidth??0,this.#e?.onScroll(n)}}findHeaderRow(){return this.#n.querySelector(".header-row")}findRenderedRowElement(e){return Array.from(this._bodyEl.querySelectorAll(".data-grid-row")).find(o=>{const n=o.querySelector(".cell[data-row]");return n&&Number(n.getAttribute("data-row"))===e})||null}_dispatchCellClick(e,o,n,i){const l=this._rows[o],r=this._columns[n];if(!l||!r)return!1;const s={row:l,rowIndex:o,colIndex:n,field:r.field,value:l[r.field],cellEl:i,originalEvent:e};return this.#e?.onCellClick(s)??!1}_dispatchRowClick(e,o,n,i){if(!n)return!1;const l={rowIndex:o,row:n,rowEl:i,originalEvent:e};return this.#e?.onRowClick(l)??!1}_dispatchHeaderClick(e,o,n){const i=this._columns[o];if(!i)return!1;const l={colIndex:o,field:i.field,column:i,headerEl:n,originalEvent:e};return this.#e?.onHeaderClick(l)??!1}_dispatchKeyDown(e){return this.#e?.onKeyDown(e)??!1}_getHorizontalScrollOffsets(e,o){return this.#e?.getHorizontalScrollOffsets(e,o)??{left:0,right:0}}queryPlugins(e){return this.#e?.queryPlugins(e)??[]}#W(e,o){let n=null;const i=e.composedPath?.();if(i&&i.length>0?n=i[0]:n=e.target,n&&!this.#n.contains(n)){const f=this.#n.elementFromPoint(e.clientX,e.clientY);f&&(n=f)}const l=n?.closest?.("[data-col]"),r=n?.closest?.(".data-grid-row"),s=n?.closest?.(".header-row");let a,c,h,d,u,p;return l&&(a=parseInt(l.getAttribute("data-row")??"-1",10),c=parseInt(l.getAttribute("data-col")??"-1",10),a>=0&&c>=0&&(h=this._rows[a],p=this._columns[c],d=p?.field,u=h&&d?h[d]:void 0)),{type:o,row:h,rowIndex:a!==void 0&&a>=0?a:void 0,colIndex:c!==void 0&&c>=0?c:void 0,field:d,value:u,column:p,originalEvent:e,cellElement:l??void 0,rowElement:r??void 0,isHeader:!!s,cell:a!==void 0&&c!==void 0&&a>=0&&c>=0?{row:a,col:c}:void 0}}#be(e){const o=this.#W(e,"mousedown");(this.#e?.onCellMouseDown(o)??!1)&&(this.#T=!0)}#we(e){if(!this.#T)return;const o=this.#W(e,"mousemove");this.#e?.onCellMouseMove(o)}#ge(e){if(!this.#T)return;const o=this.#W(e,"mouseup");this.#e?.onCellMouseUp(o),this.#T=!1}get changedRows(){return Te(this)}get changedRowIndices(){return xe(this)}async resetChangedRows(e){Rt(this,e)}async beginBulkEdit(e){At(this,e,{findRenderedRowElement:o=>this.findRenderedRowElement?.(o)??null})}async commitActiveRowEdit(){Tt(this)}async cancelActiveRowEdit(){xt(this)}async ready(){return this.#U}async forceLayout(){this.#a(),await new Promise(e=>requestAnimationFrame(()=>requestAnimationFrame(e)))}async getConfig(){return Object.freeze({...this.#t||{}})}#$={emit:(e,o)=>this.#d(e,o),clearRowPool:()=>{this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++},setup:()=>this.#a(),requestStateChange:()=>this.requestStateChange()};setColumnVisible(e,o){return fe(this,e,o,this.#$)}toggleColumnVisibility(e){return Ze(this,e,this.#$)}isColumnVisible(e){return Qe(this,e)}showAllColumns(){Je(this,this.#$)}getAllColumns(){return et(this)}setColumnOrder(e){ot(this,e,{renderHeader:()=>G(this),updateTemplate:()=>I(this),refreshVirtualWindow:()=>this.refreshVirtualWindow(!0)})}getColumnOrder(){return tt(this)}getColumnState(){const e=this.#e?.getAll()??[];return he(this,e)}set columnState(e){e&&(this.#f=e,this.#M&&this.#me(e))}get columnState(){return this.getColumnState()}#me(e){(this.#t.columns??[]).forEach(n=>{n.hidden=!1}),this.#ee(e),this.#a()}requestStateChange(){this.#z||(this.#z=Ke(this,()=>this.#e?.getAll()??[],e=>this.#d("column-state-change",e))),this.#z()}resetColumnState(){this.#f=void 0,(this.#t.columns??[]).forEach(n=>{n.hidden=!1}),this._sortState=null,this.__originalOrder=[],this.#l(),this.#a();const o=this.#e?.getAll()??[];for(const n of o)if(n.applyColumnState)for(const i of this._columns)n.applyColumnState(i.field,{field:i.field,order:0,visible:!0});this.requestStateChange()}get isToolPanelOpen(){return this.#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.#i.registerToolPanel(e)}unregisterToolPanel(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,o){this.#i.setToolbarButtonDisabled(e,o)}refreshShellHeader(){U(this,this.#o),X(this,this.#o,this.#_()),this.#G(),this.#I()}#E=new Map;registerStyles(e,o){this.unregisterStyles(e);const n=document.createElement("style");n.id=`tbw-custom-${e}`,n.textContent=o,this.#n.appendChild(n),this.#E.set(e,n)}unregisterStyles(e){const o=this.#E.get(e);o&&(o.remove(),this.#E.delete(e))}getRegisteredStyles(){return Array.from(this.#E.keys())}#ve(){this.#u&&this.#u.disconnect();let e=null,o=!1,n=!1;const i=()=>{if(e=null,o){const l=this.#o.lightDomTitle;if(U(this,this.#o),X(this,this.#o,this.#_()),this.#o.lightDomTitle&&!l){this.#l();const s=this.#n.querySelector(".tbw-shell-header");if(s){const a=qe(this.#t.shell,this.#o,this.#t.icons?.toolPanel),c=document.createElement("div");c.innerHTML=a;const h=c.firstElementChild;h&&(s.replaceWith(h),this.#F())}}o=!1}n&&(this.__lightDomColumnsCache=void 0,this.#a(),n=!1)};this.#u=new MutationObserver(l=>{for(const r of l){for(const s of r.addedNodes){if(s.nodeType!==Node.ELEMENT_NODE)continue;const c=s.tagName.toLowerCase();c==="tbw-grid-header"?o=!0:(c==="tbw-grid-column"||c==="tbw-grid-detail")&&(n=!0)}if(r.type==="attributes"&&r.target.nodeType===Node.ELEMENT_NODE){const a=r.target.tagName.toLowerCase();a==="tbw-grid-header"?o=!0:a==="tbw-grid-column"&&(n=!0)}}(o||n)&&!e&&(e=setTimeout(i,0))}),this.#u.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["title","field","header","width","hidden"]})}refreshColumns(){this.__lightDomColumnsCache=void 0;const e=this.#o.lightDomTitle;if(U(this,this.#o),X(this,this.#o,this.#_()),this.#o.lightDomTitle&&!e){this.#l();const n=this.#n.querySelector(".tbw-shell-header");if(n){const i=qe(this.#t.shell,this.#o,this.#t.icons?.toolPanel),l=document.createElement("div");l.innerHTML=i;const r=l.firstElementChild;r&&(n.replaceWith(r),this.#F())}}this.#a()}#V(e){const o=this._virtualization.rowHeight,n=this._virtualization.container??this,i=this._virtualization.viewportEl??n,l=n.clientHeight,r=i.clientHeight,a=this.shadowRoot?.querySelector(".tbw-scroll-area"),c=a?a.clientHeight:l,d=c-r,u=this.#e?.getExtraHeight()??0,p=Math.max(0,l-c);return e*o+d+u+p}refreshVirtualWindow(e=!1){if(!this._bodyEl)return;const o=this._rows.length;if(!this._virtualization.enabled){this.#q(0,o),this.#e?.afterRender();return}if(this._rows.length<=this._virtualization.bypassThreshold){this._virtualization.start=0,this._virtualization.end=o,e&&(this._bodyEl.style.transform="translateY(0px)"),this.#q(0,o,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${this.#V(o)}px`),this.__rowsBodyEl?.setAttribute("aria-rowcount",String(o)),this.__rowsBodyEl?.setAttribute("aria-colcount",String(this._visibleColumns.length)),this.#e?.afterRender();return}const n=this._virtualization.container??this,i=this._virtualization.viewportEl??n,l=i.clientHeight,r=this._virtualization.rowHeight,s=n.scrollTop;let a=Math.floor(s/r),c=0;const h=10;for(;c<h;){const _=this.#e?.getExtraHeightBefore?.(a)??0,m=Math.floor((s-_)/r);if(m>=a||m<0)break;a=m,c++}a=a-a%2,a<0&&(a=0);const d=this.#e?.adjustVirtualStart(a,s,r);d!==void 0&&d<a&&(a=d,a=a-a%2,a<0&&(a=0));const u=Math.ceil(l/r)+3;let p=a+u;if(p>o&&(p=o),this._virtualization.start=a,this._virtualization.end=p,n.clientHeight===0&&l>0){requestAnimationFrame(()=>this.refreshVirtualWindow(e));return}const b=this.#V(o);this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${b}px`);const g=this.#e?.getExtraHeightBefore?.(a)??0,w=-(s-a*r-g);this._bodyEl.style.transform=`translateY(${w}px)`,this.#q(a,p,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),this.__rowsBodyEl?.setAttribute("aria-rowcount",String(o)),this.__rowsBodyEl?.setAttribute("aria-colcount",String(this._visibleColumns.length)),e&&(this.#e?.afterRender(),queueMicrotask(()=>{const _=n.clientHeight,m=i.clientHeight;if(_===0&&m>0)return;const v=this.#V(o);this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${v}px`)}))}#G(){U(this,this.#o),X(this,this.#o,this.#_()),this.#l();const e=this.#t?.shell;Yt(this.#n,e,this.#o,this.#t?.icons)&&(this.#F(),this.#i.setInitialized(!0))}#F(){qt(this.#n,this.#t?.shell,this.#o,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e),onToolbarButtonClick:e=>this.#_e(e)}),this.#L?.(),this.#L=Wt(this.#n,this.#t?.shell,e=>{this.style.setProperty("--tbw-tool-panel-width",`${e}px`)})}#_e(e){const n=(this.#t?.shell?.header?.toolbarButtons??[]).find(l=>l.id===e);if(n?.action){n.action();return}const i=this.#o.toolbarButtons.get(e);i?.action&&i.action()}}customElements.get(k.tagName)||customElements.define(k.tagName,k),globalThis.DataGridElement=k;const oo={CAN_MOVE_COLUMN:"canMoveColumn",GET_CONTEXT_MENU_ITEMS:"getContextMenuItems"};class no{version="1.0.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}attach(e){this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,o){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:o,bubbles:!0}))}requestRender(){this.grid?.requestRender?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get shadowRoot(){return this.grid?.shadowRoot??null}get disconnectSignal(){return this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...P,...e}}resolveIcon(e,o){return o!==void 0?o:this.gridIcons[e]}setIcon(e,o){typeof o=="string"?e.innerHTML=o:o instanceof HTMLElement&&(e.innerHTML="",e.appendChild(o.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}const y={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"},Y={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"},io={ROOT:`.${y.ROOT}`,HEADER:`.${y.HEADER}`,HEADER_ROW:`.${y.HEADER_ROW}`,HEADER_CELL:`.${y.HEADER_CELL}`,ROWS_VIEWPORT:`.${y.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${y.ROWS_CONTAINER}`,DATA_ROW:`.${y.DATA_ROW}`,DATA_CELL:`.${y.DATA_CELL}`,GROUP_ROW:`.${y.GROUP_ROW}`,ROW_BY_INDEX:t=>`.${y.DATA_ROW}[${Y.ROW_INDEX}="${t}"]`,CELL_BY_FIELD:t=>`.${y.DATA_CELL}[${Y.FIELD}="${t}"]`,CELL_AT:(t,e)=>`.${y.DATA_ROW}[${Y.ROW_INDEX}="${t}"] .${y.DATA_CELL}[${Y.COL_INDEX}="${e}"]`,SELECTED_ROWS:`.${y.DATA_ROW}.${y.SELECTED}`,EDITING_CELL:`.${y.DATA_CELL}.${y.EDITING}`},lo={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"},ro={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"},so={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"},ue={sum:(t,e)=>t.reduce((o,n)=>o+(Number(n[e])||0),0),avg:(t,e)=>{const o=t.reduce((n,i)=>n+(Number(i[e])||0),0);return t.length?o/t.length:0},count:t=>t.length,min:(t,e)=>Math.min(...t.map(o=>Number(o[e])||1/0)),max:(t,e)=>Math.max(...t.map(o=>Number(o[e])||-1/0)),first:(t,e)=>t[0]?.[e],last:(t,e)=>t[t.length-1]?.[e]},j=new Map,x={register(t,e){j.set(t,e)},unregister(t){j.delete(t)},get(t){if(t!==void 0)return typeof t=="function"?t:j.get(t)??ue[t]},run(t,e,o,n){const i=this.get(t);return i?i(e,o,n):void 0},has(t){return j.has(t)||t in ue},list(){return[...Object.keys(ue),...j.keys()]}},Ue={sum:t=>t.reduce((e,o)=>e+o,0),avg:t=>t.length?t.reduce((e,o)=>e+o,0)/t.length:0,count:t=>t.length,min:t=>t.length?Math.min(...t):0,max:t=>t.length?Math.max(...t):0,first:t=>t[0]??0,last:t=>t[t.length-1]??0};function Xe(t){return Ue[t]??Ue.sum}function ao(t,e){return Xe(t)(e)}const co=x.register.bind(x),uo=x.unregister.bind(x),ho=x.get.bind(x),fo=x.run.bind(x),po=x.list.bind(x);C.BaseGridPlugin=no,C.DEFAULT_ANIMATION_CONFIG=pe,C.DEFAULT_GRID_ICONS=P,C.DGEvents=ro,C.DataGridElement=k,C.FitModeEnum=W,C.GridCSSVars=lo,C.GridClasses=y,C.GridDataAttrs=Y,C.GridElement=k,C.GridSelectors=io,C.PLUGIN_QUERIES=oo,C.PluginEvents=so,C.PluginManager=Fe,C.aggregatorRegistry=x,C.builtInSort=Pe,C.defaultComparator=Le,C.getAggregator=ho,C.getValueAggregator=Xe,C.listAggregators=po,C.registerAggregator=co,C.runAggregator=fo,C.runValueAggregator=ao,C.unregisterAggregator=uo,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})}));
|
|
29
|
+
`}function U(t,e){const o=t.querySelector("tbw-grid-header");if(!o)return;if(!e.lightDomTitle){const i=o.getAttribute("title");i&&(e.lightDomTitle=i)}const n=o.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")})),o.style.display="none"}function X(t,e){const o=t.querySelector(":scope > tbw-grid-tool-buttons");o&&(e.hasToolButtonsContainer=!0,o.setAttribute("slot","toolbar"))}function Y(t,e,o){t.querySelectorAll(":scope > tbw-grid-tool-panel").forEach(i=>{const r=i,l=r.getAttribute("id"),s=r.getAttribute("title");if(!l||!s){console.warn(`[parseLightDomToolPanels] Tool panel missing required id or title attribute: id="${l??""}", title="${s??""}"`);return}const a=r.getAttribute("icon")??void 0,c=r.getAttribute("tooltip")??void 0,f=parseInt(r.getAttribute("order")??"100",10);let d;const u=o?.(r);if(u)d=u;else{const p=r.innerHTML.trim();d=g=>{const b=document.createElement("div");return b.innerHTML=p,g.appendChild(b),()=>b.remove()}}const w=e.toolPanels.get(l);if(w){if(u){w.render=d,w.order=f,w.icon=a,w.tooltip=c;const p=e.panelCleanups.get(l);p&&(p(),e.panelCleanups.delete(l))}return}const h={id:l,title:s,icon:a,tooltip:c,order:f,render:d};e.toolPanels.set(l,h),e.lightDomToolPanelIds.add(l),r.style.display="none"})}function Gt(t,e,o,n){const i=t.querySelector(".tbw-shell-toolbar");i&&i.addEventListener("click",l=>{const s=l.target;if(s.closest("[data-panel-toggle]")){n.onPanelToggle();return}const c=s.closest("[data-btn]");if(c){const f=c.getAttribute("data-btn");f&&n.onToolbarButtonClick(f)}});const r=t.querySelector(".tbw-accordion");r&&r.addEventListener("click",l=>{const a=l.target.closest(".tbw-accordion-header");if(a){const f=a.closest("[data-section]")?.getAttribute("data-section");f&&n.onSectionToggle(f)}})}function $t(t,e,o){const n=t.querySelector(".tbw-tool-panel"),i=t.querySelector("[data-resize-handle]"),r=t.querySelector(".tbw-shell-body");if(!n||!i||!r)return()=>{};const l=e?.toolPanel?.position??"right",s=200;let a=0,c=0,f=0,d=!1;const u=p=>{if(!d)return;p.preventDefault();const g=l==="left"?p.clientX-a:a-p.clientX,b=Math.min(f,Math.max(s,c+g));n.style.width=`${b}px`},w=()=>{if(!d)return;d=!1,i.classList.remove("resizing"),n.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const p=n.getBoundingClientRect().width;o(p),document.removeEventListener("mousemove",u),document.removeEventListener("mouseup",w)},h=p=>{p.preventDefault(),d=!0,a=p.clientX,c=n.getBoundingClientRect().width,f=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",u),document.addEventListener("mouseup",w)};return i.addEventListener("mousedown",h),()=>{i.removeEventListener("mousedown",h),document.removeEventListener("mousemove",u),document.removeEventListener("mouseup",w)}}function Ft(t,e,o){const n=[...e?.header?.toolbarButtons??[],...o.toolbarButtons.values()];for(const i of n){const r=t.querySelector(`[data-btn-slot="${i.id}"]`);if(!r)continue;const l=o.toolbarButtonCleanups.get(i.id);if(l&&(l(),o.toolbarButtonCleanups.delete(i.id)),i.element)r.appendChild(i.element);else if(i.render){const s=i.render(r);s&&o.toolbarButtonCleanups.set(i.id,s)}}}function Ge(t,e){const o=t.querySelector(".tbw-shell-content");if(!o)return;const n=[...e.headerContents.values()].sort((r,l)=>(r.order??100)-(l.order??100)),i=o.querySelector('slot[name="header-content"]');for(const r of n){const l=e.headerContentCleanups.get(r.id);l&&(l(),e.headerContentCleanups.delete(r.id));let s=o.querySelector(`[data-header-content="${r.id}"]`);s||(s=document.createElement("div"),s.setAttribute("data-header-content",r.id),i?o.insertBefore(s,i):o.appendChild(s));const a=r.render(s);a&&e.headerContentCleanups.set(r.id,a)}}function Ut(t,e,o){if(!e.isPanelOpen)return;const n=q(o?.expand??M.expand),i=q(o?.collapse??M.collapse);for(const[r,l]of e.toolPanels){const s=e.expandedSections.has(r),a=t.querySelector(`[data-section="${r}"]`),c=a?.querySelector(".tbw-accordion-content");if(!a||!c)continue;a.classList.toggle("expanded",s);const f=a.querySelector(".tbw-accordion-header");f&&f.setAttribute("aria-expanded",String(s));const d=a.querySelector(".tbw-accordion-chevron");if(d&&(d.innerHTML=s?i:n),s){if(c.children.length===0){const u=l.render(c);u&&e.panelCleanups.set(r,u)}}else{const u=e.panelCleanups.get(r);u&&(u(),e.panelCleanups.delete(r)),c.innerHTML=""}}}function $e(t,e){const o=t.querySelector("[data-panel-toggle]");o&&(o.classList.toggle("active",e.isPanelOpen),o.setAttribute("aria-pressed",String(e.isPanelOpen)))}function Fe(t,e){const o=t.querySelector(".tbw-tool-panel");o&&(o.classList.toggle("open",e.isPanelOpen),e.isPanelOpen||(o.style.width=""))}function Xt(t,e){const o=[];for(const n of t?.header?.toolbarButtons??[])o.push({id:n.id,label:n.label??"",source:"config"});for(const n of e.toolbarButtons.values())o.push({id:n.id,label:n.label??"",source:"config"});for(const n of e.toolPanels.values())o.push({id:`panel-toggle-${n.id}`,label:n.tooltip??n.title,source:"panel-toggle",panelId:n.id});return o}function Yt(t){for(const e of t.headerContentCleanups.values())e();t.headerContentCleanups.clear();for(const e of t.panelCleanups.values())e();t.panelCleanups.clear();for(const e of t.toolbarButtonCleanups.values())e();if(t.toolbarButtonCleanups.clear(),t.isPanelOpen)for(const e of t.expandedSections)t.toolPanels.get(e)?.onClose?.();t.isPanelOpen=!1,t.expandedSections.clear(),t.toolPanels.clear(),t.headerContents.clear(),t.toolbarButtons.clear(),t.lightDomHeaderContent=[]}function jt(t,e){let o=!1;const n={get isInitialized(){return o},setInitialized(i){o=i},get isPanelOpen(){return t.isPanelOpen},get activePanel(){return t.isPanelOpen&&t.expandedSections.size>0?[...t.expandedSections][0]:null},get expandedSections(){return[...t.expandedSections]},openToolPanel(){if(t.isPanelOpen)return;if(t.toolPanels.size===0){console.warn("[tbw-grid] No tool panels registered");return}if(t.isPanelOpen=!0,t.expandedSections.size===0&&t.toolPanels.size>0){const l=[...t.toolPanels.values()].sort((s,a)=>(s.order??100)-(a.order??100))[0];l&&t.expandedSections.add(l.id)}const i=e.getShadow();$e(i,t),Fe(i,t),Ut(i,t,e.getAccordionIcons()),e.emit("tool-panel-open",{sections:n.expandedSections})},closeToolPanel(){if(!t.isPanelOpen)return;for(const r of t.panelCleanups.values())r();t.panelCleanups.clear();for(const r of t.toolPanels.values())r.onClose?.();t.isPanelOpen=!1;const i=e.getShadow();$e(i,t),Fe(i,t),e.emit("tool-panel-close",{})},toggleToolPanel(){t.isPanelOpen?n.closeToolPanel():n.openToolPanel()},toggleToolPanelSection(i){const r=t.toolPanels.get(i);if(!r){console.warn(`[tbw-grid] Tool panel section "${i}" not found`);return}if(t.toolPanels.size===1)return;const l=e.getShadow(),s=t.expandedSections.has(i);if(s){const a=t.panelCleanups.get(i);a&&(a(),t.panelCleanups.delete(i)),r.onClose?.(),t.expandedSections.delete(i),de(l,i,!1)}else{for(const[a,c]of t.toolPanels)if(a!==i&&t.expandedSections.has(a)){const f=t.panelCleanups.get(a);f&&(f(),t.panelCleanups.delete(a)),c.onClose?.(),t.expandedSections.delete(a),de(l,a,!1);const d=l.querySelector(`[data-section="${a}"] .tbw-accordion-content`);d&&(d.innerHTML="")}t.expandedSections.add(i),de(l,i,!0),Kt(l,t,i)}e.emit("tool-panel-section-toggle",{id:i,expanded:!s})},getToolPanels(){return[...t.toolPanels.values()]},registerToolPanel(i){if(t.toolPanels.has(i.id)){console.warn(`[tbw-grid] Tool panel "${i.id}" already registered`);return}t.toolPanels.set(i.id,i),o&&e.refreshShellHeader()},unregisterToolPanel(i){if(t.expandedSections.has(i)){const r=t.panelCleanups.get(i);r&&(r(),t.panelCleanups.delete(i)),t.expandedSections.delete(i)}t.toolPanels.delete(i),o&&e.refreshShellHeader()},getHeaderContents(){return[...t.headerContents.values()]},registerHeaderContent(i){if(t.headerContents.has(i.id)){console.warn(`[tbw-grid] Header content "${i.id}" already registered`);return}t.headerContents.set(i.id,i),o&&Ge(e.getShadow(),t)},unregisterHeaderContent(i){const r=t.headerContentCleanups.get(i);r&&(r(),t.headerContentCleanups.delete(i)),t.headerContents.get(i)?.onDestroy?.(),t.headerContents.delete(i),e.getShadow().querySelector(`[data-header-content="${i}"]`)?.remove()},getToolbarButtons(){return Xt(e.getShellConfig(),t)},registerToolbarButton(i){if(t.toolbarButtons.has(i.id)){console.warn(`[tbw-grid] Toolbar button "${i.id}" already registered`);return}t.toolbarButtons.set(i.id,i),o&&e.refreshShellHeader()},unregisterToolbarButton(i){const r=t.toolbarButtonCleanups.get(i);r&&(r(),t.toolbarButtonCleanups.delete(i)),t.toolbarButtons.delete(i),o&&e.refreshShellHeader()},setToolbarButtonDisabled(i,r){}};return n}function de(t,e,o){const n=t.querySelector(`[data-section="${e}"]`);n&&n.classList.toggle("expanded",o)}function Kt(t,e,o){const n=e.toolPanels.get(o);if(!n?.render)return;const i=t.querySelector(`[data-section="${o}"] .tbw-accordion-content`);if(!i)return;const r=n.render(i);r&&e.panelCleanups.set(o,r)}function Zt(t,e,o,n){const i=We(e,o);if(t.replaceChildren(),i){const r=q(n?.toolPanel??M.toolPanel),l=q(n?.expand??M.expand),s=q(n?.collapse??M.collapse),c=[...e?.header?.toolbarButtons??[]].sort((b,_)=>(b.order??100)-(_.order??100)),f=[...o.toolbarButtons.values()].sort((b,_)=>(b.order??100)-(_.order??100)),d={title:e?.header?.title??o.lightDomTitle??void 0,hasPanels:o.toolPanels.size>0,isPanelOpen:o.isPanelOpen,toolPanelIcon:r,configButtons:c.map(b=>({id:b.id,hasElement:!!b.element,hasRender:!!b.render})),apiButtons:f.map(b=>({id:b.id,hasElement:!!b.element,hasRender:!!b.render}))},u=[...o.toolPanels.values()].sort((b,_)=>(b.order??100)-(_.order??100)),w={position:e?.toolPanel?.position??"right",isPanelOpen:o.isPanelOpen,expandIcon:l,collapseIcon:s,panels:u.map(b=>({id:b.id,title:b.title,icon:q(b.icon),isExpanded:o.expandedSections.has(b.id)}))},h=qt(d),p=Wt(w),g=qe({hasShell:!0,shellHeader:h,shellBody:p});t.appendChild(g)}else{const r=qe({hasShell:!1});t.appendChild(r)}return i}function Qt(){return{startY:null,startX:null,scrollTop:null,scrollLeft:null,lastY:null,lastX:null,lastTime:null,velocityY:0,velocityX:0,momentumRaf:0}}function Jt(t){t.startY=null,t.startX=null,t.scrollTop=null,t.scrollLeft=null,t.lastY=null,t.lastX=null,t.lastTime=null}function Ue(t){t.momentumRaf&&(cancelAnimationFrame(t.momentumRaf),t.momentumRaf=0)}function eo(t,e,o){if(t.touches.length!==1)return;Ue(e);const n=t.touches[0];e.startY=n.clientY,e.startX=n.clientX,e.lastY=n.clientY,e.lastX=n.clientX,e.lastTime=performance.now(),e.scrollTop=o.fauxScrollbar.scrollTop,e.scrollLeft=o.scrollArea?.scrollLeft??0,e.velocityY=0,e.velocityX=0}function to(t,e,o){if(t.touches.length!==1||e.startY===null||e.startX===null||e.scrollTop===null||e.scrollLeft===null)return!1;const n=t.touches[0],i=n.clientY,r=n.clientX,l=performance.now(),s=e.startY-i,a=e.startX-r;if(e.lastTime!==null&&e.lastY!==null&&e.lastX!==null){const p=l-e.lastTime;p>0&&(e.velocityY=(e.lastY-i)/p,e.velocityX=(e.lastX-r)/p)}e.lastY=i,e.lastX=r,e.lastTime=l;const{scrollTop:c,scrollHeight:f,clientHeight:d}=o.fauxScrollbar,u=f-d,w=s>0&&c<u||s<0&&c>0;let h=!1;if(o.scrollArea){const{scrollLeft:p,scrollWidth:g,clientWidth:b}=o.scrollArea,_=g-b;h=a>0&&p<_||a<0&&p>0}return w&&(o.fauxScrollbar.scrollTop=e.scrollTop+s),h&&o.scrollArea&&(o.scrollArea.scrollLeft=e.scrollLeft+a),w||h}function oo(t,e){(Math.abs(t.velocityY)>.1||Math.abs(t.velocityX)>.1)&&no(t,e),Jt(t)}function no(t,e){const i=()=>{t.velocityY*=.95,t.velocityX*=.95;const r=t.velocityY*16,l=t.velocityX*16;Math.abs(t.velocityY)>.01&&(e.fauxScrollbar.scrollTop+=r),Math.abs(t.velocityX)>.01&&e.scrollArea&&(e.scrollArea.scrollLeft+=l),Math.abs(t.velocityY)>.01||Math.abs(t.velocityX)>.01?t.momentumRaf=requestAnimationFrame(i):t.momentumRaf=0};t.momentumRaf=requestAnimationFrame(i)}function io(t,e,o,n){t.addEventListener("touchstart",i=>eo(i,e,o),{passive:!0,signal:n}),t.addEventListener("touchmove",i=>{to(i,e,o)&&i.preventDefault()},{passive:!1,signal:n}),t.addEventListener("touchend",()=>oo(e,o),{passive:!0,signal:n})}class Xe{constructor(e){this.grid=e}plugins=[];pluginMap=new Map;cellRenderers=new Map;headerRenderers=new Map;cellEditors=new Map;attachAll(e){for(const o of e)this.attach(o)}attach(e){if(this.pluginMap.set(e.constructor,e),this.plugins.push(e),e.cellRenderers)for(const[o,n]of Object.entries(e.cellRenderers))this.cellRenderers.set(o,n);if(e.headerRenderers)for(const[o,n]of Object.entries(e.headerRenderers))this.headerRenderers.set(o,n);if(e.cellEditors)for(const[o,n]of Object.entries(e.cellEditors))this.cellEditors.set(o,n);e.attach(this.grid)}detachAll(){for(let e=this.plugins.length-1;e>=0;e--)this.plugins[e].detach();this.plugins=[],this.pluginMap.clear(),this.cellRenderers.clear(),this.headerRenderers.clear(),this.cellEditors.clear()}getPlugin(e){return this.pluginMap.get(e)}getPluginByName(e){return this.plugins.find(o=>o.name===e)}hasPlugin(e){return this.pluginMap.has(e)}getAll(){return this.plugins}getCellRenderer(e){return this.cellRenderers.get(e)}getHeaderRenderer(e){return this.headerRenderers.get(e)}getCellEditor(e){return this.cellEditors.get(e)}getAllStyles(){return this.plugins.filter(e=>e.styles).map(e=>e.styles).join(`
|
|
30
|
+
`)}processRows(e){let o=[...e];for(const n of this.plugins)n.processRows&&(o=n.processRows(o));return o}processColumns(e){let o=[...e];for(const n of this.plugins)n.processColumns&&(o=n.processColumns(o));return o}beforeRender(){for(const e of this.plugins)e.beforeRender?.()}afterRender(){for(const e of this.plugins)e.afterRender?.()}onScrollRender(){for(const e of this.plugins)e.onScrollRender?.()}getExtraHeight(){let e=0;for(const o of this.plugins)typeof o.getExtraHeight=="function"&&(e+=o.getExtraHeight());return e}getExtraHeightBefore(e){let o=0;for(const n of this.plugins)typeof n.getExtraHeightBefore=="function"&&(o+=n.getExtraHeightBefore(e));return o}adjustVirtualStart(e,o,n){let i=e;for(const r of this.plugins)if(typeof r.adjustVirtualStart=="function"){const l=r.adjustVirtualStart(e,o,n);l<i&&(i=l)}return i}renderRow(e,o,n){for(const i of this.plugins)if(i.renderRow?.(e,o,n))return!0;return!1}queryPlugins(e){const o=[];for(const n of this.plugins){const i=n.onPluginQuery?.(e);i!==void 0&&o.push(i)}return o}onKeyDown(e){for(const o of this.plugins)if(o.onKeyDown?.(e))return!0;return!1}onCellClick(e){for(const o of this.plugins)if(o.onCellClick?.(e))return!0;return!1}onRowClick(e){for(const o of this.plugins)if(o.onRowClick?.(e))return!0;return!1}onHeaderClick(e){for(const o of this.plugins)if(o.onHeaderClick?.(e))return!0;return!1}onScroll(e){for(const o of this.plugins)o.onScroll?.(e)}onCellMouseDown(e){for(const o of this.plugins)if(o.onCellMouseDown?.(e))return!0;return!1}onCellMouseMove(e){for(const o of this.plugins)if(o.onCellMouseMove?.(e))return!0;return!1}onCellMouseUp(e){for(const o of this.plugins)if(o.onCellMouseUp?.(e))return!0;return!1}getHorizontalScrollOffsets(e,o){let n=0,i=0,r=!1;for(const l of this.plugins){const s=l.getHorizontalScrollOffsets?.(e,o);s&&(n+=s.left,i+=s.right,s.skipScroll&&(r=!0))}return{left:n,right:i,skipScroll:r}}getToolPanels(){const e=[];for(const o of this.plugins){const n=o.getToolPanel?.();n&&e.push({plugin:o,panel:n})}return e.sort((o,n)=>(o.panel.order??0)-(n.panel.order??0))}getHeaderContents(){const e=[];for(const o of this.plugins){const n=o.getHeaderContent?.();n&&e.push({plugin:o,content:n})}return e.sort((o,n)=>(o.content.order??0)-(n.content.order??0))}}class D extends HTMLElement{static tagName="tbw-grid";static version=typeof __GRID_VERSION__<"u"?__GRID_VERSION__:"dev";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"]}#n;#H=!1;#Y;#j;#l=[];#c;#g;#E;#y;#o={};#O=!1;#m=!1;#M={rows:!1,columns:!1,gridConfig:!1,fitMode:!1,editMode:!1};#f=0;#S=null;#R=!1;#k;#T=!1;#K=Qt();#s;#p;#w;#D=0;#d;#u;#re={scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0};#t;#A=!1;#v;#z;#h;#e=Vt();#i;#x;_rows=[];#N=[];get _columns(){return this.#o.columns??[]}set _columns(e){this.#o.columns=e}get _visibleColumns(){return this._columns.filter(e=>!e.hidden)}_headerRowEl;_bodyEl;_rowPool=[];_resizeController;_virtualization={enabled:!0,rowHeight:28,bypassThreshold:24,start:0,end:0,container:null,viewportEl:null,totalHeightEl:null};_focusRow=0;_focusCol=0;_sortState=null;_activeEditRows=-1;_rowEditSnapshots=new Map;_changedRowIndices=new Set;_gridTemplate="";__rowRenderEpoch=0;__didInitialAutoSize=!1;__lightDomColumnsCache;__originalColumnNodes;__originalOrder=[];__rowsBodyEl=null;get rows(){return this._rows}set rows(e){const o=this.#l;this.#l=e,o!==e&&this.#_("rows")}get sourceRows(){return this.#l}get columns(){return[...this._columns]}set columns(e){const o=this.#c;this.#c=e,o!==e&&this.#_("columns")}get gridConfig(){return this.#o}set gridConfig(e){const o=this.#g;this.#g=e,o!==e&&(this.__lightDomColumnsCache=void 0,this.#_("gridConfig"))}get fitMode(){return this.#o.fitMode??"stretch"}set fitMode(e){const o=this.#E;this.#E=e,o!==e&&this.#_("fitMode")}get editOn(){return this.#o.editOn}set editOn(e){const o=this.#y;this.#y=e,o!==e&&this.#_("editMode")}get effectiveConfig(){return this.#o}get disconnectSignal(){return this.#s||(this.#s=new AbortController),this.#s.signal}constructor(){super(),this.#n=this.attachShadow({mode:"open"}),this.#le(),this.#Y=new Promise(e=>this.#j=e),this.#i=jt(this.#e,{getShadow:()=>this.#n,getShellConfig:()=>this.#o?.shell,getAccordionIcons:()=>({expand:this.#o?.icons?.expand??M.expand,collapse:this.#o?.icons?.collapse??M.collapse}),emit:(e,o)=>this.#q(e,o),refreshShellHeader:()=>this.refreshShellHeader()})}async#le(){const e=new CSSStyleSheet;if(W.length>0){e.replaceSync(W),this.#n.adoptedStyleSheets=[e];return}await new Promise(o=>setTimeout(o,50));try{let o="";for(const n of Array.from(document.styleSheets))try{const r=Array.from(n.cssRules||[]).map(l=>l.cssText).join(`
|
|
31
|
+
`);if(r.includes(".tbw-grid-root")&&r.includes(":host")){o=r;break}}catch{continue}o?(e.replaceSync(o),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(o){console.warn("[tbw-grid] Failed to extract grid.css from document stylesheets:",o)}}getPlugin(e){return this.#t?.getPlugin(e)}getPluginByName(e){return this.#t?.getPluginByName(e)}requestRender(){this.#P(),this.#L(),F(this),I(this),this.refreshVirtualWindow(!0)}updateTemplate(){I(this)}requestAfterRender(){this.#t?.afterRender()}#Z(){this.#t=new Xe(this);const e=this.#o?.plugins,o=Array.isArray(e)?e:[];this.#t.attachAll(o)}#Q(){const e=this.#t?.getAllStyles()??"";if(e){const o=document.createElement("style");o.setAttribute("data-plugin","all"),o.textContent=e,this.#n.appendChild(o)}}#J(){this.#t&&this.#t.detachAll();for(const e of this.#e.toolPanels.keys()){const o=this.#e.lightDomToolPanelIds.has(e),n=this.#e.apiToolPanelIds.has(e);if(!o&&!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 o=this.#e.headerContentCleanups.get(e);o&&(o(),this.#e.headerContentCleanups.delete(e)),this.#e.headerContents.delete(e)}this.#Z(),this.#Q(),this.#ee(),this.#R=this.#t?.getAll().some(e=>e.onScroll)??!1}#se(){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 o=this.#t.getHeaderContents();for(const{content:n}of o)this.#e.headerContents.has(n.id)||this.#e.headerContents.set(n.id,n)}#b(){const e=D.getAdapters();if(e.length===0&&!this.__frameworkAdapter)return;const o=this.__frameworkAdapter;return n=>{if(o?.createToolPanelRenderer){const i=o.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",D.version),this._rows=Array.isArray(this.#l)?[...this.#l]:[],this.#s&&(this.#s.abort(),this.#A=!1),this.#s=new AbortController,this.#u&&(De(this.#u),this.#u=void 0),U(this,this.#e),X(this,this.#e),Y(this,this.#e,this.#b()),this.#r(),this.#Z(),this.#ee(),this.#H||(this.#U(),this.#Q(),this.#H=!0),this.#I(),this.#u=It(()=>{this.#Se()},{timeout:100})}disconnectedCallback(){this.#u&&(De(this.#u),this.#u=void 0),this.#se(),Yt(this.#e),this.#i.setInitialized(!1),this.#x?.(),this.#x=void 0,Ue(this.#K),this.#s&&(this.#s.abort(),this.#s=void 0),this.#v?.abort(),this.#v=void 0,this.#A=!1,this._resizeController&&this._resizeController.dispose(),this.#p&&(this.#p.disconnect(),this.#p=void 0),this.#w&&(this.#w.disconnect(),this.#w=void 0,this.#B=!1),this.#d&&(this.#d.disconnect(),this.#d=void 0),K(this),this._rowEditSnapshots.clear(),this._changedRowIndices.clear(),this.#C.clear();for(const e of this._rowPool)e.remove();this._rowPool.length=0,this.__rowsBodyEl=null,this.#O=!1}attributeChangedCallback(e,o,n){if(o===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}#I(){const o=this.#n.querySelector(".tbw-grid-content")??this.#n.querySelector(".tbw-grid-root");if(this._headerRowEl=o?.querySelector(".header-row"),this._virtualization.totalHeightEl=o?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=o?.querySelector(".rows-viewport"),this._bodyEl=o?.querySelector(".rows"),this.__rowsBodyEl=o?.querySelector(".rows-body"),this.#i.isInitialized){Ge(this.#n,this.#e),Ft(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.#O=!0,this._resizeController=Bt(this),this.#a(),this.#ae(o),this.#A)return;this.#A=!0;const n=this.disconnectSignal;this.addEventListener("keydown",r=>vt(this,r),{signal:n}),document.addEventListener("keydown",r=>{r.key==="Escape"&&this._activeEditRows!==-1&&N(this,this._activeEditRows,!0)},{capture:!0,signal:n}),document.addEventListener("mousedown",r=>{if(this._activeEditRows===-1)return;const l=this.findRenderedRowElement(this._activeEditRows);!l||(r.composedPath&&r.composedPath()||[]).includes(l)||N(this,this._activeEditRows,!1)},{signal:n}),this.#n.addEventListener("mousedown",r=>this.#_e(r),{signal:n}),document.addEventListener("mousemove",r=>this.#Ce(r),{signal:n}),document.addEventListener("mouseup",r=>this.#Ee(r),{signal:n});const i=this.#o.rowHeight;i&&i>0?this._virtualization.rowHeight=i:requestAnimationFrame(()=>this.#te()),queueMicrotask(()=>this.#de()),requestAnimationFrame(()=>requestAnimationFrame(()=>this.#j?.()))}#te(){const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const o=e.querySelectorAll(".cell");let n=0;o.forEach(l=>{const s=l.offsetHeight;s>n&&(n=s)});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.#v?.abort(),this.#v=new AbortController;const o=this.#v.signal,n=e?.querySelector(".faux-vscroll"),i=e?.querySelector(".rows");if(this._virtualization.container=n??this,this.#R=this.#t?.getAll().some(r=>r.onScroll)??!1,n&&i){n.addEventListener("scroll",()=>{if(!this._virtualization.enabled&&!this.#R)return;const s=n.scrollTop,a=this._virtualization.rowHeight;if(this._rows.length<=this._virtualization.bypassThreshold)i.style.transform=`translateY(${-s}px)`;else{const c=Math.floor(s/a),f=c-c%2,d=-(s-f*a);i.style.transform=`translateY(${d}px)`}this.#S=s,this.#f||(this.#f=requestAnimationFrame(()=>{this.#f=0,this.#S!==null&&(this.#ve(this.#S),this.#S=null)}))},{passive:!0,signal:o});const r=this.#n.querySelector(".tbw-grid-content"),l=this.#n.querySelector(".tbw-scroll-area");r&&(r.addEventListener("wheel",s=>{const a=s.shiftKey||Math.abs(s.deltaX)>Math.abs(s.deltaY);if(a&&l){const c=s.shiftKey?s.deltaY:s.deltaX,{scrollLeft:f,scrollWidth:d,clientWidth:u}=l;(c>0&&f<d-u||c<0&&f>0)&&(s.preventDefault(),l.scrollLeft+=c)}else if(!a){const{scrollTop:c,scrollHeight:f,clientHeight:d}=n;(s.deltaY>0&&c<f-d||s.deltaY<0&&c>0)&&(s.preventDefault(),n.scrollTop+=s.deltaY)}},{passive:!1,signal:o}),io(r,this.#K,{fauxScrollbar:n,scrollArea:l},o))}this._bodyEl&&zt(this,this._bodyEl,o),this.#p?.disconnect(),this._virtualization.viewportEl&&(this.#p=new ResizeObserver(()=>{this.#f||(this.#f=requestAnimationFrame(()=>{this.#f=0,this.refreshVirtualWindow(!0),z(this)}))}),this.#p.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 o=e.querySelectorAll(".cell");o.length>0&&(this.#w=new ResizeObserver(()=>{this.#te()}),o.forEach(n=>this.#w.observe(n)))}#q(e,o){this.dispatchEvent(new CustomEvent(e,{detail:o,bubbles:!0,composed:!0}))}#de(){this._bodyEl?.querySelectorAll(".data-grid-row")?.forEach((o,n)=>{const i=n===this._focusRow;o.setAttribute("aria-selected",String(i)),o.querySelectorAll(".cell").forEach((r,l)=>{r.setAttribute("aria-selected",String(i&&l===this._focusCol))})})}#_(e){this.#M[e]=!0,!this.#m&&(this.#m=!0,queueMicrotask(()=>this.#ue()))}#ue(){if(!this.#m||!this.#O){this.#m=!1;return}const e=this.#M;if(this.#m=!1,this.#M={rows:!1,columns:!1,gridConfig:!1,fitMode:!1,editMode:!1},e.gridConfig){this.#be();return}e.columns&&this.#fe(),e.rows&&this.#he(),e.fitMode&&this.#pe(),e.editMode&&this.#we()}#he(){this._rows=Array.isArray(this.#l)?[...this.#l]:[],this.#P(),this._columns.length>0||Array.isArray(this.#o?.columns)&&this.#o.columns.length>0||Array.isArray(this.#c)&&this.#c.length>0?(this.#L(),this.refreshVirtualWindow(!0)):this.#a()}#fe(){K(this),this.#r(),this.#a()}#pe(){this.#r(),this.#o.fitMode==="fixed"?(this.__didInitialAutoSize=!1,Ce(this)):(this._columns.forEach(o=>{!o.__userResized&&o.__autoSized&&delete o.width}),I(this))}#we(){this.#r(),this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++,this.refreshVirtualWindow(!0)}#be(){U(this,this.#e),X(this,this.#e);const e=!!this.#n.querySelector(".has-shell"),o=!!this.#n.querySelector(".tbw-tool-panel"),n=this.#n.querySelectorAll(".tbw-accordion-section").length;_e(this),this.#r(),this.#J(),Y(this,this.#e,this.#b());const i=We(this.#o,this.#e),r=this.#e.toolPanels.size>0,l=this.#e.toolPanels.size!==n;if(e!==i||!e&&i||!o&&r||o&&l){this.#U(),this.#I();return}e&&this.#ge(),this.#P(),this.#L(),F(this),I(this),this.refreshVirtualWindow(!0)}#ge(){const e=this.#n.querySelector(".tbw-shell-header");if(!e)return;const o=this.#o.shell?.header?.title??this.#e.lightDomTitle;let n=e.querySelector(".tbw-shell-title");o?(n||(n=document.createElement("h2"),n.className="tbw-shell-title",n.setAttribute("part","shell-title"),e.insertBefore(n,e.firstChild)),n.textContent=o):n&&n.remove()}#L(){if(this.#t){const e=this.#N.length>0?this.#N:this._columns,o=e.filter(r=>!r.hidden),n=e.filter(r=>r.hidden),i=this.#t.processColumns([...o]);if(i!==o){const r=new Map(i.map((s,a)=>[s.field,{col:s,order:a}]));if(!o.some(s=>r.has(s.field))&&i.length>0)this._columns=[...i,...n];else{const s=e.map(a=>{if(a.hidden)return a;const c=r.get(a.field);return c?c.col:a});this._columns=s}}else this._columns=[...e]}}#P(){K(this);const e=Array.isArray(this.#l)?[...this.#l]:[],o=this.#t?.processRows(e)??e;this._rows=o}#r(){const e=this.#g?{...this.#g}:{};let o=Array.isArray(e.columns)?[...e.columns]:[];const n=(this.__lightDomColumnsCache||[]).map(i=>({...i}));if(n.length){const i={};o.forEach(r=>i[r.field]=r),n.forEach(r=>{const l=i[r.field];if(!l)o.push(r),i[r.field]=r;else{r.header&&!l.header&&(l.header=r.header),r.type&&!l.type&&(l.type=r.type),l.sortable=l.sortable||r.sortable,r.resizable&&(l.resizable=!0),r.editable&&(l.editable=!0);const s=r.renderer||r.viewRenderer,a=l.renderer||l.viewRenderer;s&&!a&&(l.viewRenderer=s,r.renderer&&(l.renderer=s)),r.editor&&!l.editor&&(l.editor=r.editor)}})}if(this.#c&&this.#c.length&&(o=[...this.#c]),(!o||o.length===0)&&this._rows.length&&(o=we(this._rows).columns),o.length){o.forEach(l=>{l.sortable===void 0&&(l.sortable=!0),l.resizable===void 0&&(l.resizable=!0);const s=l;s.__originalWidth===void 0&&typeof l.width=="number"&&(s.__originalWidth=l.width)});const i=this.#o.columns;i?.some(l=>l.__compiledView||l.__compiledEditor)?e.columns=i:e.columns=o}else{const i=this.#o.columns;i?.some(r=>r.__compiledView||r.__compiledEditor)&&(e.columns=i)}this.#E&&(e.fitMode=this.#E),e.fitMode||(e.fitMode="stretch"),this.#y&&(e.editOn=this.#y),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.#h&&(this.#h=e.columnState),this.#o=e,e.fitMode==="fixed"&&this._columns.forEach(i=>{i.width==null&&(i.width=80)}),this.#me()}#me(){const e={...pe,...this.#o.animation},o=e.mode??"reduced-motion";let n=1;o===!1||o==="off"?n=0:(o===!0||o==="on")&&(n=1),this.style.setProperty("--tbw-animation-duration",`${e.duration}ms`),this.style.setProperty("--tbw-animation-easing",e.easing??"ease-out"),this.style.setProperty("--tbw-animation-enabled",String(n)),this.dataset.animationMode=typeof o=="boolean"?o?"on":"off":o}#W(e,o,n=this.__rowRenderEpoch){this.#k||(this.#k=(i,r,l)=>this.#t?.renderRow(i,r,l)??!1),St(this,e,o,n,this.#k)}#V=-1;#oe=-1;#ne(e,o){if(e===this.#V&&o===this.#oe)return;const n=this.#V;this.#V=e,this.#oe=o,this.__rowsBodyEl&&(this.__rowsBodyEl.setAttribute("aria-rowcount",String(e)),this.__rowsBodyEl.setAttribute("aria-colcount",String(o))),e!==n&&this._bodyEl&&(e>0?this._bodyEl.setAttribute("role","rowgroup"):this._bodyEl.removeAttribute("role"))}#a(){if(!this.isConnected||!this._headerRowEl||!this._bodyEl)return;const e=this.#g?.columns||this.#c||[];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(_e(this),this.#r(),this.#J(),this.#N=[...this._columns],this.#P(),this.#L(),this.#h){const n=this.#h;this.#h=void 0,this.#ie(n)}F(this),I(this),this.refreshVirtualWindow(!0),this.#o.fitMode==="fixed"&&!this.__didInitialAutoSize&&requestAnimationFrame(()=>Ce(this)),this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),queueMicrotask(()=>this.#t?.afterRender())}#ie(e){const o=this.#o.columns??[],n=this.#t?.getAll()??[];Ze(this,e,o,n);for(const i of e.columns){const r=o.find(l=>l.field===i.field);r&&(r.hidden=!i.visible)}}#ve(e){if(this.refreshVirtualWindow(!1),this.#t?.onScrollRender(),this.#R){const o=this._virtualization.container,n=this.#re;n.scrollTop=e,n.scrollLeft=o?.scrollLeft??0,n.scrollHeight=o?.scrollHeight??0,n.scrollWidth=o?.scrollWidth??0,n.clientHeight=o?.clientHeight??0,n.clientWidth=o?.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(o=>{const n=o.querySelector(".cell[data-row]");return n&&Number(n.getAttribute("data-row"))===e})||null}_dispatchCellClick(e,o,n,i){const r=this._rows[o],l=this._columns[n];if(!r||!l)return!1;const s={row:r,rowIndex:o,colIndex:n,field:l.field,value:r[l.field],cellEl:i,originalEvent:e};return this.#t?.onCellClick(s)??!1}_dispatchRowClick(e,o,n,i){if(!n)return!1;const r={rowIndex:o,row:n,rowEl:i,originalEvent:e};return this.#t?.onRowClick(r)??!1}_dispatchHeaderClick(e,o,n){const i=this._columns[o];if(!i)return!1;const r={colIndex:o,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,o){return this.#t?.getHorizontalScrollOffsets(e,o)??{left:0,right:0}}queryPlugins(e){return this.#t?.queryPlugins(e)??[]}#G(e,o){let n=null;const i=e.composedPath?.();if(i&&i.length>0?n=i[0]:n=e.target,n&&!this.#n.contains(n)){const h=this.#n.elementFromPoint(e.clientX,e.clientY);h&&(n=h)}const r=n?.closest?.("[data-col]"),l=n?.closest?.(".data-grid-row"),s=n?.closest?.(".header-row");let a,c,f,d,u,w;return r&&(a=parseInt(r.getAttribute("data-row")??"-1",10),c=parseInt(r.getAttribute("data-col")??"-1",10),a>=0&&c>=0&&(f=this._rows[a],w=this._columns[c],d=w?.field,u=f&&d?f[d]:void 0)),{type:o,row:f,rowIndex:a!==void 0&&a>=0?a:void 0,colIndex:c!==void 0&&c>=0?c:void 0,field:d,value:u,column:w,originalEvent:e,cellElement:r??void 0,rowElement:l??void 0,isHeader:!!s,cell:a!==void 0&&c!==void 0&&a>=0&&c>=0?{row:a,col:c}:void 0}}#_e(e){const o=this.#G(e,"mousedown");(this.#t?.onCellMouseDown(o)??!1)&&(this.#T=!0)}#Ce(e){if(!this.#T)return;const o=this.#G(e,"mousemove");this.#t?.onCellMouseMove(o)}#Ee(e){if(!this.#T)return;const o=this.#G(e,"mouseup");this.#t?.onCellMouseUp(o),this.#T=!1}get changedRows(){return Ae(this)}get changedRowIndices(){return xe(this)}async resetChangedRows(e){xt(this,e)}async beginBulkEdit(e){Lt(this,e,{findRenderedRowElement:o=>this.findRenderedRowElement?.(o)??null})}async commitActiveRowEdit(){Pt(this)}async cancelActiveRowEdit(){Ht(this)}async ready(){return this.#Y}async forceLayout(){this.#a(),await new Promise(e=>requestAnimationFrame(()=>requestAnimationFrame(e)))}async getConfig(){return Object.freeze({...this.#o||{}})}#$={emit:(e,o)=>this.#q(e,o),clearRowPool:()=>{this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++},setup:()=>this.#a(),requestStateChange:()=>this.requestStateChange()};setColumnVisible(e,o){return fe(this,e,o,this.#$)}toggleColumnVisibility(e){return Je(this,e,this.#$)}isColumnVisible(e){return et(this,e)}showAllColumns(){tt(this,this.#$)}getAllColumns(){return ot(this)}setColumnOrder(e){it(this,e,{renderHeader:()=>F(this),updateTemplate:()=>I(this),refreshVirtualWindow:()=>this.refreshVirtualWindow(!0)})}getColumnOrder(){return nt(this)}getColumnState(){const e=this.#t?.getAll()??[];return he(this,e)}set columnState(e){e&&(this.#h=e,this.#H&&this.#ye(e))}get columnState(){return this.getColumnState()}#ye(e){(this.#o.columns??[]).forEach(n=>{n.hidden=!1}),this.#ie(e),this.#a()}requestStateChange(){this.#z||(this.#z=Qe(this,()=>this.#t?.getAll()??[],e=>this.#q("column-state-change",e))),this.#z()}resetColumnState(){this.#h=void 0,(this.#o.columns??[]).forEach(n=>{n.hidden=!1}),this._sortState=null,this.__originalOrder=[],this.#r(),this.#a();const o=this.#t?.getAll()??[];for(const n of o)if(n.applyColumnState)for(const i of this._columns)n.applyColumnState(i.field,{field:i.field,order:0,visible:!0});this.requestStateChange()}get isToolPanelOpen(){return this.#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,o){this.#i.setToolbarButtonDisabled(e,o)}refreshShellHeader(){U(this,this.#e),X(this,this.#e),Y(this,this.#e,this.#b()),this.#U(),this.#I()}#C=new Map;registerStyles(e,o){this.unregisterStyles(e);const n=document.createElement("style");n.id=`tbw-custom-${e}`,n.textContent=o,this.#n.appendChild(n),this.#C.set(e,n)}unregisterStyles(e){const o=this.#C.get(e);o&&(o.remove(),this.#C.delete(e))}getRegisteredStyles(){return Array.from(this.#C.keys())}#Se(){this.#d&&this.#d.disconnect();let e=null,o=!1,n=!1;const i=()=>{if(e=null,o){const r=this.#e.lightDomTitle,l=this.#e.hasToolButtonsContainer;U(this,this.#e),X(this,this.#e),Y(this,this.#e,this.#b());const s=this.#e.lightDomTitle,a=this.#e.hasToolButtonsContainer;if(s&&!r||a&&!l){this.#r();const c=this.#n.querySelector(".tbw-shell-header");if(c){const f=Ve(this.#o.shell,this.#e,this.#o.icons?.toolPanel),d=document.createElement("div");d.innerHTML=f;const u=d.firstElementChild;u&&(c.replaceWith(u),this.#X())}}o=!1}n&&(this.__lightDomColumnsCache=void 0,this.#a(),n=!1)};this.#d=new MutationObserver(r=>{for(const l of r){for(const s of l.addedNodes){if(s.nodeType!==Node.ELEMENT_NODE)continue;const c=s.tagName.toLowerCase();c==="tbw-grid-header"?o=!0:(c==="tbw-grid-column"||c==="tbw-grid-detail")&&(n=!0)}if(l.type==="attributes"&&l.target.nodeType===Node.ELEMENT_NODE){const a=l.target.tagName.toLowerCase();a==="tbw-grid-header"?o=!0:a==="tbw-grid-column"&&(n=!0)}}(o||n)&&!e&&(e=setTimeout(i,0))}),this.#d.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["title","field","header","width","hidden"]})}refreshColumns(){this.#D||(this.#D=requestAnimationFrame(()=>{this.#D=0,this.#Re()}))}#Re(){this.__lightDomColumnsCache=void 0,K(this);const e=this.#e.lightDomTitle,o=this.#e.hasToolButtonsContainer;U(this,this.#e),X(this,this.#e),Y(this,this.#e,this.#b());const n=this.#e.lightDomTitle,i=this.#e.hasToolButtonsContainer;if(n&&!e||i&&!o){this.#r();const l=this.#n.querySelector(".tbw-shell-header");if(l){const s=Ve(this.#o.shell,this.#e,this.#o.icons?.toolPanel),a=document.createElement("div");a.innerHTML=s;const c=a.firstElementChild;c&&(l.replaceWith(c),this.#X())}}this.#a()}#F(e){const o=this._virtualization.rowHeight,n=this._virtualization.container??this,i=this._virtualization.viewportEl??n,r=n.clientHeight,l=i.clientHeight,a=this.shadowRoot?.querySelector(".tbw-scroll-area"),c=a?a.clientHeight:r,d=c-l,u=this.#t?.getExtraHeight()??0,w=Math.max(0,r-c);return e*o+d+u+w}refreshVirtualWindow(e=!1){if(!this._bodyEl)return;const o=this._rows.length;if(!this._virtualization.enabled){this.#W(0,o),this.#t?.afterRender();return}if(this._rows.length<=this._virtualization.bypassThreshold){this._virtualization.start=0,this._virtualization.end=o,e&&(this._bodyEl.style.transform="translateY(0px)"),this.#W(0,o,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${this.#F(o)}px`),this.#ne(o,this._visibleColumns.length),this.#t?.afterRender();return}const n=this._virtualization.container??this,i=this._virtualization.viewportEl??n,r=i.clientHeight,l=this._virtualization.rowHeight,s=n.scrollTop;let a=Math.floor(s/l),c=0;const f=10;for(;c<f;){const _=this.#t?.getExtraHeightBefore?.(a)??0,v=Math.floor((s-_)/l);if(v>=a||v<0)break;a=v,c++}a=a-a%2,a<0&&(a=0);const d=this.#t?.adjustVirtualStart(a,s,l);d!==void 0&&d<a&&(a=d,a=a-a%2,a<0&&(a=0));const u=Math.ceil(r/l)+3;let w=a+u;if(w>o&&(w=o),this._virtualization.start=a,this._virtualization.end=w,n.clientHeight===0&&r>0){requestAnimationFrame(()=>this.refreshVirtualWindow(e));return}const p=this.#F(o);this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${p}px`);const g=this.#t?.getExtraHeightBefore?.(a)??0,b=-(s-a*l-g);this._bodyEl.style.transform=`translateY(${b}px)`,this.#W(a,w,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),this.#ne(o,this._visibleColumns.length),e&&(this.#t?.afterRender(),queueMicrotask(()=>{const _=n.clientHeight,v=i.clientHeight;if(_===0&&v>0)return;const m=this.#F(o);this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${m}px`)}))}#U(){U(this,this.#e),X(this,this.#e),Y(this,this.#e,this.#b()),this.#r();const e=this.#o?.shell;Zt(this.#n,e,this.#e,this.#o?.icons)&&(this.#X(),this.#i.setInitialized(!0))}#X(){Gt(this.#n,this.#o?.shell,this.#e,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e),onToolbarButtonClick:e=>this.#Te(e)}),this.#x?.(),this.#x=$t(this.#n,this.#o?.shell,e=>{this.style.setProperty("--tbw-tool-panel-width",`${e}px`)})}#Te(e){}}customElements.get(D.tagName)||customElements.define(D.tagName,D),globalThis.DataGridElement=D;const ro={CAN_MOVE_COLUMN:"canMoveColumn",GET_CONTEXT_MENU_ITEMS:"getContextMenuItems"};class lo{version="1.0.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}attach(e){this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,o){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:o,bubbles:!0}))}requestRender(){this.grid?.requestRender?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get shadowRoot(){return this.grid?.shadowRoot??null}get disconnectSignal(){return this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...M,...e}}resolveIcon(e,o){return o!==void 0?o:this.gridIcons[e]}setIcon(e,o){typeof o=="string"?e.innerHTML=o:o instanceof HTMLElement&&(e.innerHTML="",e.appendChild(o.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}const S={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"},Z={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"},so={ROOT:`.${S.ROOT}`,HEADER:`.${S.HEADER}`,HEADER_ROW:`.${S.HEADER_ROW}`,HEADER_CELL:`.${S.HEADER_CELL}`,ROWS_VIEWPORT:`.${S.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${S.ROWS_CONTAINER}`,DATA_ROW:`.${S.DATA_ROW}`,DATA_CELL:`.${S.DATA_CELL}`,GROUP_ROW:`.${S.GROUP_ROW}`,ROW_BY_INDEX:t=>`.${S.DATA_ROW}[${Z.ROW_INDEX}="${t}"]`,CELL_BY_FIELD:t=>`.${S.DATA_CELL}[${Z.FIELD}="${t}"]`,CELL_AT:(t,e)=>`.${S.DATA_ROW}[${Z.ROW_INDEX}="${t}"] .${S.DATA_CELL}[${Z.COL_INDEX}="${e}"]`,SELECTED_ROWS:`.${S.DATA_ROW}.${S.SELECTED}`,EDITING_CELL:`.${S.DATA_CELL}.${S.EDITING}`},ao={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"},co={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"},uo={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"},ue={sum:(t,e)=>t.reduce((o,n)=>o+(Number(n[e])||0),0),avg:(t,e)=>{const o=t.reduce((n,i)=>n+(Number(i[e])||0),0);return t.length?o/t.length:0},count:t=>t.length,min:(t,e)=>Math.min(...t.map(o=>Number(o[e])||1/0)),max:(t,e)=>Math.max(...t.map(o=>Number(o[e])||-1/0)),first:(t,e)=>t[0]?.[e],last:(t,e)=>t[t.length-1]?.[e]},Q=new Map,H={register(t,e){Q.set(t,e)},unregister(t){Q.delete(t)},get(t){if(t!==void 0)return typeof t=="function"?t:Q.get(t)??ue[t]},run(t,e,o,n){const i=this.get(t);return i?i(e,o,n):void 0},has(t){return Q.has(t)||t in ue},list(){return[...Object.keys(ue),...Q.keys()]}},Ye={sum:t=>t.reduce((e,o)=>e+o,0),avg:t=>t.length?t.reduce((e,o)=>e+o,0)/t.length:0,count:t=>t.length,min:t=>t.length?Math.min(...t):0,max:t=>t.length?Math.max(...t):0,first:t=>t[0]??0,last:t=>t[t.length-1]??0};function je(t){return Ye[t]??Ye.sum}function ho(t,e){return je(t)(e)}const fo=H.register.bind(H),po=H.unregister.bind(H),wo=H.get.bind(H),bo=H.run.bind(H),go=H.list.bind(H);E.BaseGridPlugin=lo,E.DEFAULT_ANIMATION_CONFIG=pe,E.DEFAULT_GRID_ICONS=M,E.DGEvents=co,E.DataGridElement=D,E.FitModeEnum=V,E.GridCSSVars=ao,E.GridClasses=S,E.GridDataAttrs=Z,E.GridElement=D,E.GridSelectors=so,E.PLUGIN_QUERIES=ro,E.PluginEvents=uo,E.PluginManager=Xe,E.aggregatorRegistry=H,E.builtInSort=Pe,E.defaultComparator=Le,E.getAggregator=wo,E.getValueAggregator=je,E.listAggregators=go,E.registerAggregator=fo,E.runAggregator=bo,E.runValueAggregator=ho,E.unregisterAggregator=po,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})}));
|
|
32
32
|
//# sourceMappingURL=grid.umd.js.map
|