@toolbox-web/grid 1.18.0 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/all.js +64 -42
- package/all.js.map +1 -1
- package/index.js +2 -2
- package/lib/plugins/selection/SelectionPlugin.d.ts +18 -0
- package/lib/plugins/selection/SelectionPlugin.d.ts.map +1 -1
- package/lib/plugins/selection/index.js +110 -71
- package/lib/plugins/selection/index.js.map +1 -1
- package/package.json +1 -1
- package/umd/grid.all.umd.js +2 -2
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/plugins/selection.umd.js +2 -2
- package/umd/plugins/selection.umd.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toolbox-web/grid",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"description": "Zero-dependency, framework-agnostic data grid web component with virtualization, sorting, filtering, editing, and 20+ plugins. Works in vanilla JS, React, Vue, Angular, and any framework.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
package/umd/grid.all.umd.js
CHANGED
|
@@ -181,7 +181,7 @@ ${$(i.name)}Plugin and ${$(s.name)}Plugin are both loaded, but they are currentl
|
|
|
181
181
|
|
|
182
182
|
Note: Output will be limited to ${i.maxRows.toLocaleString()} rows.`:"";if(!confirm(`This grid has ${o.toLocaleString()} rows. Printing large datasets may cause performance issues or browser slowdowns.${c}
|
|
183
183
|
|
|
184
|
-
Click OK to continue, or Cancel to abort.`))return}i.maxRows>0&&o>i.maxRows&&(s=i.maxRows,l=!0),this.#t=!0;const a=performance.now();this.emit("print-start",{rowCount:s,limitApplied:l,originalRowCount:o});try{const c=this.#h;this.#u={bypassThreshold:c._virtualization?.bypassThreshold??24},this.#a(),l&&(this.#c=this.sourceRows,this.grid.rows=this.sourceRows.slice(0,s),await new Promise(d=>setTimeout(d,50))),(i.includeTitle||i.includeTimestamp)&&this.#w(i),await this.#y(),await new Promise(d=>requestAnimationFrame(d)),await new Promise(d=>requestAnimationFrame(d)),t.classList.add(`print-${i.orientation}`),await new Promise(d=>requestAnimationFrame(d)),await new Promise(d=>requestAnimationFrame(d)),i.isolate?await this.#g(i):await this.#d(),this.emit("print-complete",{success:!0,rowCount:s,duration:Math.round(performance.now()-a)})}catch(c){console.error("[PrintPlugin] Print failed:",c),this.emit("print-complete",{success:!1,rowCount:0,duration:Math.round(performance.now()-a)})}finally{this.#C(),this.#t=!1}}#w(e){const t=this.gridElement;if(t){if(this.#r=document.createElement("div"),this.#r.className="tbw-print-header",e.includeTitle){const i=e.title||this.grid.effectiveConfig?.shell?.header?.title||"Grid Data",n=document.createElement("div");n.className="tbw-print-header-title",n.textContent=i,this.#r.appendChild(n)}if(e.includeTimestamp){const i=document.createElement("div");i.className="tbw-print-header-timestamp",i.textContent=`Printed: ${new Date().toLocaleString()}`,this.#r.appendChild(i)}t.insertBefore(this.#r,t.firstChild),this.#l=document.createElement("div"),this.#l.className="tbw-print-footer",this.#l.textContent=`Page generated from ${window.location.hostname}`,t.appendChild(this.#l)}}async#y(){const e=this.#h;if(!e._virtualization)return;const t=this.rows.length;e._virtualization.bypassThreshold=t+100,e.refreshVirtualWindow(!0),await new Promise(i=>setTimeout(i,100))}async#d(){return new Promise(e=>{const t=()=>{window.removeEventListener("afterprint",t),e()};window.addEventListener("afterprint",t),window.print(),setTimeout(()=>{typeof window<"u"&&window.removeEventListener("afterprint",t),e()},1e3)})}async#g(e){const t=this.gridElement;t&&await Gi(t,{orientation:e.orientation})}#a(){const e=this.columns;if(e){this.#e=new Map;for(const t of e)t.printHidden&&t.field&&(this.#e.set(t.field,!t.hidden),this.grid.setColumnVisible(t.field,!1))}}#f(){if(this.#e){for(const[e,t]of this.#e)this.grid.setColumnVisible(e,t);this.#e=null}}#C(){const e=this.gridElement;if(!e)return;this.#f(),e.classList.remove("print-portrait","print-landscape"),this.#i!==null&&(e.style.transform="",e.style.transformOrigin="",e.style.width="",this.#i=null),this.#r&&(this.#r.remove(),this.#r=null),this.#l&&(this.#l.remove(),this.#l=null);const t=this.#h;this.#u&&t._virtualization&&(t._virtualization.bypassThreshold=this.#u.bypassThreshold,t.refreshVirtualWindow(!0),this.#u=null),this.#c!==null&&(this.grid.rows=this.#c,this.#c=null)}afterRender(){this.config?.button&&!this.#p&&(this.#R(),this.#p=!0)}#p=!1;#R(){this.#h.registerToolbarContent?.({id:"print-button",order:900,render:t=>{const i=document.createElement("button");i.className="tbw-toolbar-btn tbw-print-btn",i.title="Print grid",i.type="button";const n=this.resolveIcon("print")||"🖨️";this.setIcon(i,n),i.addEventListener("click",()=>{this.print()},{signal:this.disconnectSignal}),t.appendChild(i)}})}}function Ls(r){const e=r.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}function Bi(r,e,t){if(e===t||e<0||e>=r.length||t<0||t>r.length)return r;const i=[...r],[n]=i.splice(e,1);return i.splice(t,0,n),i}const Ps='@layer tbw-plugins{.header-row>.cell[draggable=true]{cursor:grab;position:relative}.header-row>.cell.dragging{opacity:.5;cursor:grabbing}.header-row>.cell.drop-before:before{content:"";position:absolute;left:0;top:0;bottom:0;width:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent));z-index:1}.header-row>.cell.drop-after:after{content:"";position:absolute;right:0;top:0;bottom:0;width:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent));z-index:1}.cell.flip-animating{transition:transform var(--tbw-animation-duration, .2s) ease-out;will-change:transform;z-index:1}@keyframes reorder-fade-in{0%{opacity:0}to{opacity:1}}.cell.fade-animating{animation:reorder-fade-in var(--tbw-animation-duration, .2s) ease-out backwards}}';class Hs extends M{name="reorder";styles=Ps;get defaultConfig(){return{animation:"flip"}}get animationType(){return this.isAnimationEnabled?this.config.animation!==void 0?this.config.animation:"flip":!1}get animationDuration(){return this.config.animationDuration!==void 0?this.config.animationDuration:super.animationDuration}isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;canMoveColumnWithPlugins(e){return!e||!Ls(e)?!1:!this.grid.query("canMoveColumn",e).includes(!1)}clearDragClasses(){this.gridElement?.querySelectorAll(".header-row > .cell").forEach(e=>{e.classList.remove("dragging","drop-target","drop-before","drop-after")})}attach(e){super.attach(e),e.addEventListener("column-reorder-request",t=>{const i=t.detail;i?.field&&typeof i.toIndex=="number"&&this.moveColumn(i.field,i.toIndex)},{signal:this.disconnectSignal})}detach(){this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null}afterRender(){const e=this.gridElement;if(!e)return;e.querySelectorAll(".header-row > .cell").forEach(i=>{const n=i,o=n.getAttribute("data-field");if(!o)return;const s=this.columns.find(l=>l.field===o);if(!this.canMoveColumnWithPlugins(s)){n.draggable=!1;return}n.draggable=!0,!n.getAttribute("data-dragstart-bound")&&(n.setAttribute("data-dragstart-bound","true"),n.addEventListener("dragstart",l=>{const c=this.getColumnOrder().indexOf(o);this.isDragging=!0,this.draggedField=o,this.draggedIndex=c,l.dataTransfer&&(l.dataTransfer.effectAllowed="move",l.dataTransfer.setData("text/plain",o)),n.classList.add("dragging")}),n.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.clearDragClasses()}),n.addEventListener("dragover",l=>{if(l.preventDefault(),!this.isDragging||this.draggedField===o)return;const a=n.getBoundingClientRect(),c=a.left+a.width/2,u=this.getColumnOrder().indexOf(o);this.dropIndex=l.clientX<c?u:u+1,n.classList.add("drop-target"),n.classList.toggle("drop-before",l.clientX<c),n.classList.toggle("drop-after",l.clientX>=c)}),n.addEventListener("dragleave",()=>{n.classList.remove("drop-target","drop-before","drop-after")}),n.addEventListener("drop",l=>{l.preventDefault();const a=this.draggedField,c=this.draggedIndex,d=this.dropIndex;if(!this.isDragging||a===null||c===null||d===null)return;const u=d>c?d-1:d,h=this.getColumnOrder(),g=Bi(h,c,u),f={field:a,fromIndex:c,toIndex:u,columnOrder:g};this.emitCancelable("column-move",f)||this.updateColumnOrder(g)}))})}onKeyDown(e){if(!e.altKey||e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;const t=this.grid,i=t._focusCol,n=t._visibleColumns;if(i<0||i>=n.length)return;const o=n[i];if(!this.canMoveColumnWithPlugins(o))return;const s=this.getColumnOrder(),l=s.indexOf(o.field);if(l===-1)return;const a=e.key==="ArrowLeft"?l-1:l+1;if(a<0||a>=s.length)return;const c=n.find(d=>d.field===s[a]);if(this.canMoveColumnWithPlugins(c))return this.moveColumn(o.field,a),t._focusCol=a,N(this.grid),e.preventDefault(),e.stopPropagation(),!0}getColumnOrder(){return this.grid.getColumnOrder()}moveColumn(e,t){const i=this.getColumnOrder(),n=i.indexOf(e);if(n===-1)return;const o=Bi(i,n,t);this.emitCancelable("column-move",{field:e,fromIndex:n,toIndex:t,columnOrder:o})||this.updateColumnOrder(o)}setColumnOrder(e){this.updateColumnOrder(e)}resetColumnOrder(){const e=this.columns.map(t=>t.field);this.updateColumnOrder(e)}captureHeaderPositions(){const e=new Map;return this.gridElement?.querySelectorAll(".header-row > .cell[data-field]").forEach(t=>{const i=t.getAttribute("data-field");i&&e.set(i,t.getBoundingClientRect().left)}),e}animateFLIP(e){const t=this.gridElement;if(!t||e.size===0)return;const i=new Map;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(s=>{const l=s.getAttribute("data-field");if(!l)return;const a=e.get(l);if(a===void 0)return;const c=a-s.getBoundingClientRect().left;Math.abs(c)>1&&i.set(l,c)}),i.size===0)return;const n=[];if(t.querySelectorAll(".cell[data-field]").forEach(s=>{const l=i.get(s.getAttribute("data-field")??"");if(l!==void 0){const a=s;a.style.transform=`translateX(${l}px)`,n.push(a)}}),n.length===0)return;this.gridElement.offsetHeight;const o=this.animationDuration;requestAnimationFrame(()=>{n.forEach(s=>{s.classList.add("flip-animating"),s.style.transform=""}),setTimeout(()=>{n.forEach(s=>{s.style.transform="",s.classList.remove("flip-animating")})},o+50)})}animateFade(e){const t=this.gridElement;if(!t){e();return}const i=this.captureHeaderPositions();e();const n=new Set;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(l=>{const a=l.getAttribute("data-field");if(!a)return;const c=i.get(a);if(c===void 0)return;const d=l.getBoundingClientRect().left;Math.abs(c-d)>1&&n.add(a)}),n.size===0)return;const o=[];if(t.querySelectorAll(".cell[data-field]").forEach(l=>{const a=l.getAttribute("data-field");if(a&&n.has(a)){const c=l;c.classList.add("fade-animating"),o.push(c)}}),o.length===0)return;const s=this.animationDuration;setTimeout(()=>{o.forEach(l=>l.classList.remove("fade-animating"))},s+50)}updateColumnOrder(e){const t=this.animationType;if(t==="flip"&&this.gridElement){const i=this.captureHeaderPositions();this.grid.setColumnOrder(e),requestAnimationFrame(()=>{this.gridElement.offsetHeight,this.animateFLIP(i)})}else t==="fade"?this.animateFade(()=>this.grid.setColumnOrder(e)):this.grid.setColumnOrder(e);this.grid.requestStateChange?.()}}const Is='tbw-grid[data-responsive-animate] .data-grid-row,tbw-grid[data-responsive-animate] .data-grid-row>.cell{transition:opacity var(--tbw-responsive-duration, .2s) ease-out,transform var(--tbw-responsive-duration, .2s) ease-out}tbw-grid[data-responsive][data-responsive-animate] .data-grid-row{animation:responsive-card-enter var(--tbw-responsive-duration, .2s) ease-out}@keyframes responsive-card-enter{0%{opacity:0;transform:translateY(-10px)}to{opacity:1;transform:translateY(0)}}tbw-grid[data-responsive] .header{display:none!important}tbw-grid[data-responsive] .footer-row{display:none}tbw-grid[data-responsive] .tbw-scroll-area{overflow-x:hidden;min-width:0!important}tbw-grid[data-responsive] .rows-body-wrapper{min-width:0!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row){display:block!important;grid-template-columns:none!important;padding:var(--tbw-cell-padding);padding-inline-start:var(--tbw-spacing-xl);border-bottom:1px solid var(--tbw-color-border);min-height:auto!important;height:auto!important;contain:none!important;content-visibility:visible!important;background:var(--tbw-color-bg);position:relative}tbw-grid[data-responsive] .data-grid-row:not(.group-row):nth-child(2n){background:var(--tbw-color-row-alt)}tbw-grid[data-responsive] .data-grid-row:not(.group-row):hover{background:var(--tbw-color-row-hover)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)[aria-selected=true]{background:var(--tbw-color-selection)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)[aria-selected=true]:before{content:"";position:absolute;inset-inline-start:0;top:0;bottom:0;width:4px;background:var(--tbw-color-accent)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell{display:flex!important;justify-content:space-between;align-items:center;padding:var(--tbw-spacing-xs) var(--tbw-spacing-md);width:100%!important;min-width:0!important;min-height:auto!important;height:auto!important;line-height:1.5!important;position:static!important;left:auto!important;right:auto!important;border:none!important;border-bottom:none!important;border-inline-end:none!important;background:transparent!important;white-space:normal!important;overflow:visible!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell:before{content:attr(data-header) ": ";font-weight:600;color:var(--tbw-color-header-fg);flex-shrink:0;margin-inline-end:var(--tbw-spacing-md);min-width:100px}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell:after{content:none}tbw-grid[data-responsive] .cell[data-utility]{display:none!important}tbw-grid[data-responsive] .cell[data-responsive-hidden]{display:none!important}tbw-grid[data-responsive] .cell[data-responsive-value-only]{justify-content:flex-start!important;font-weight:500}tbw-grid[data-responsive] .cell[data-responsive-value-only]:before{display:none!important}tbw-grid:not([data-responsive]) .cell[data-responsive-hidden]{display:none!important}tbw-grid[data-responsive] .tbw-footer,tbw-grid[data-responsive] .tbw-pinned-rows,tbw-grid[data-responsive] .tbw-aggregation-rows{display:none!important}tbw-grid[data-responsive] .tbw-pinned-rows,tbw-grid[data-responsive] .tbw-aggregation-rows,tbw-grid[data-responsive] .tbw-aggregation-row{min-width:0!important}tbw-grid[data-responsive] .data-grid-row.responsive-card{display:block!important;padding:var(--tbw-cell-padding);border-bottom:1px solid var(--tbw-color-border)}tbw-grid[data-responsive] .data-grid-row.responsive-card>*{width:100%}tbw-grid[data-responsive] .data-grid-row.responsive-card .cell:before{display:none}';class Ds extends M{name="responsive";version="1.0.0";styles=Is;static manifest={incompatibleWith:[{name:"groupingRows",reason:"Responsive card layout does not yet support row grouping. The variable row heights (cards vs group headers) cause scroll calculation issues."}],queries:[{type:"isCardMode",description:"Returns whether the grid is currently in responsive card mode"}]};#t;#e=!1;#u;#c=!1;#r=0;#l=new Set;#i=new Set;#h=null;#w=[];isResponsive(){return this.#e}setResponsive(e){e!==this.#e&&(this.#e=e,this.#C(),this.emit("responsive-change",{isResponsive:e,width:this.#r,breakpoint:this.config.breakpoint??0}))}setBreakpoint(e){this.config.breakpoint=e,this.#g(this.#r)}setCardRenderer(e){this.config.cardRenderer=e,this.#e&&this.requestRender()}getWidth(){return this.#r}getActiveBreakpoint(){return this.#h}attach(e){super.attach(e),this.#y(),this.#d(this.config.hiddenColumns),this.config.breakpoints?.length&&(this.#w=[...this.config.breakpoints].sort((t,i)=>i.maxWidth-t.maxWidth)),this.#t=new ResizeObserver(t=>{const i=t[0]?.contentRect.width??0;this.#r=i,clearTimeout(this.#u),this.#u=setTimeout(()=>{this.#g(i)},this.config.debounceMs??100)}),this.#t.observe(this.gridElement)}#y(){const e=this.grid;if(!e||typeof e.querySelector!="function")return;const t=e.querySelector("tbw-grid-responsive-card");if(!t)return;const i=e;if(i.__frameworkAdapter?.parseResponsiveCardElement){const u=i.__frameworkAdapter.parseResponsiveCardElement(t);u&&(this.config={...this.config,cardRenderer:u})}const n=t.getAttribute("breakpoint"),o=t.getAttribute("card-row-height"),s=t.getAttribute("hidden-columns"),l=t.getAttribute("hide-header"),a=t.getAttribute("debounce-ms"),c={};if(n!==null){const u=parseInt(n,10);isNaN(u)||(c.breakpoint=u)}if(o!==null&&(c.cardRowHeight=o==="auto"?"auto":parseInt(o,10)),s!==null&&(c.hiddenColumns=s.split(",").map(u=>u.trim()).filter(u=>u.length>0)),l!==null&&(c.hideHeader=l!=="false"),a!==null){const u=parseInt(a,10);isNaN(u)||(c.debounceMs=u)}const d=t.innerHTML.trim();d&&!this.config.cardRenderer&&!i.__frameworkAdapter?.parseResponsiveCardElement&&(c.cardRenderer=u=>{const h=Ee(d,{value:u,row:u}),g=X(h),f=document.createElement("div");return f.className="tbw-responsive-card-content",f.innerHTML=g,f}),Object.keys(c).length>0&&(this.config={...this.config,...c})}#d(e){if(this.#l.clear(),this.#i.clear(),!!e)for(const t of e)typeof t=="string"?this.#l.add(t):t.showValue?this.#i.add(t.field):this.#l.add(t.field)}detach(){this.#t?.disconnect(),this.#t=void 0,clearTimeout(this.#u),this.#u=void 0,this.gridElement&&this.gridElement.removeAttribute("data-responsive"),super.detach()}handleQuery(e){if(e.type==="isCardMode")return this.#e}afterRender(){if(this.#S(),!(this.#w.length>0?this.#h!==null:this.#e))return;const t=this.#l.size>0,i=this.#i.size>0;if(!t&&!i)return;const n=this.gridElement.querySelectorAll(".cell[data-field]");for(const o of n){const s=o.getAttribute("data-field");s&&(this.#l.has(s)?(o.setAttribute("data-responsive-hidden",""),o.removeAttribute("data-responsive-value-only")):this.#i.has(s)?(o.setAttribute("data-responsive-value-only",""),o.removeAttribute("data-responsive-hidden")):(o.removeAttribute("data-responsive-hidden"),o.removeAttribute("data-responsive-value-only")))}}#g(e){if(this.#w.length>0){this.#a(e);return}const t=this.config.breakpoint??0;t===0&&!this.#c&&(this.#c=!0,console.warn("[tbw-grid:ResponsivePlugin] No breakpoint configured. Responsive mode is disabled. Set a breakpoint based on your grid's column count."));const i=t>0&&e<t;i!==this.#e&&(this.#e=i,this.#C(),this.emit("responsive-change",{isResponsive:i,width:e,breakpoint:t}),this.requestRender())}#a(e){let t=null;for(const n of this.#w)e<=n.maxWidth&&(t=n);if(t!==this.#h){this.#h=t,t?.hiddenColumns?this.#d(t.hiddenColumns):this.#d(this.config.hiddenColumns);const n=t?.cardLayout===!0;n!==this.#e&&(this.#e=n,this.#C()),this.emit("responsive-change",{isResponsive:this.#e,width:e,breakpoint:t?.maxWidth??0}),this.requestRender()}}#f;#C(){this.gridElement.toggleAttribute("data-responsive",this.#e);const e=this.config.animate!==!1;this.gridElement.toggleAttribute("data-responsive-animate",e),this.config.animationDuration&&this.gridElement.style.setProperty("--tbw-responsive-duration",`${this.config.animationDuration}ms`);const t=this.grid;if(this.#e){t._virtualization&&(this.#f=t._virtualization.rowHeight);const i=this.gridElement.querySelector(".tbw-scroll-area");i&&(i.scrollLeft=0)}else{const i=this.gridElement.querySelectorAll(".data-grid-row");for(const n of i)n.style.height="",n.classList.remove("responsive-card");this.#f&&this.#f>0&&t._virtualization&&(t._virtualization.rowHeight=this.#f,this.#f=void 0),this.#p=void 0,this.#R=void 0,this.#_=void 0}}renderRow(e,t,i){if(!this.#e||!this.config.cardRenderer||e.__isGroupRow)return;t.replaceChildren();const n=this.config.cardRenderer(e,i);t.className="data-grid-row responsive-card";const o=this.config.cardRowHeight??"auto";return o!=="auto"?t.style.height=`${o}px`:t.style.height="auto",t.appendChild(n),!0}onKeyDown(e){if(!this.#e||this.config.cardRenderer&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(e.key))return!1;const t=this.rows.length-1,i=this.visibleColumns.length-1;switch(e.key){case"ArrowDown":if(this.grid._focusCol<i)return this.grid._focusCol+=1,e.preventDefault(),N(this.grid),!0;if(this.grid._focusRow<t)return this.grid._focusRow+=1,this.grid._focusCol=0,e.preventDefault(),N(this.grid),!0;break;case"ArrowUp":if(this.grid._focusCol>0)return this.grid._focusCol-=1,e.preventDefault(),N(this.grid),!0;if(this.grid._focusRow>0)return this.grid._focusRow-=1,this.grid._focusCol=i,e.preventDefault(),N(this.grid),!0;break;case"ArrowRight":if(this.grid._focusRow<t)return this.grid._focusRow+=1,e.preventDefault(),N(this.grid),!0;break;case"ArrowLeft":if(this.grid._focusRow>0)return this.grid._focusRow-=1,e.preventDefault(),N(this.grid),!0;break}return!1}#p;#R;#_;#x(){if(this.#p&&this.#p>0)return this.#p;const e=this.config.cardRowHeight;return typeof e=="number"&&e>0?e:80}#E(){return this.#R&&this.#R>0?this.#R:this.#f??28}#v(){for(const e of this.rows)if(e.__isGroupRow)return!0;return!1}#m(){let e=0,t=0;for(const i of this.rows)i.__isGroupRow?e++:t++;return{groupCount:e,cardCount:t}}getExtraHeight(){if(!this.#e||!this.config.cardRenderer||!this.#v())return 0;const e=this.#f??28,t=this.#E(),i=this.#x(),{groupCount:n,cardCount:o}=this.#m(),s=n*Math.max(0,t-e),l=o*Math.max(0,i-e);return s+l}getExtraHeightBefore(e){if(!this.#e||!this.config.cardRenderer||!this.#v())return 0;const t=this.#f??28,i=this.#E(),n=this.#x(),o=Math.max(0,i-t),s=Math.max(0,n-t);let l=0,a=0;const c=this.rows,d=Math.min(e,c.length);for(let u=0;u<d;u++)c[u].__isGroupRow?l++:a++;return l*o+a*s}getRowHeight(e,t){if(!(!this.#e||!this.config.cardRenderer))return e.__isGroupRow?this.#E():this.#x()}#A(){let e=0;for(const t of this.rows)t.__isGroupRow||e++;return e}#n=!1;#S(){if(!this.#e||!this.config.cardRenderer)return;let e=!1;const t=this.grid,i=this.#v(),n=this.#A();if(n!==this.#_&&(this.#_=n,e=!0),i){const s=this.gridElement.querySelector(".data-grid-row.group-row");if(s){const l=s.getBoundingClientRect().height;l>0&&l!==this.#R&&(this.#R=l,e=!0)}}const o=this.gridElement.querySelector(".data-grid-row.responsive-card");if(o){const s=o.getBoundingClientRect().height;s>0&&s!==this.#p&&(this.#p=s,e=!0,!i&&t._virtualization&&(t._virtualization.rowHeight=s))}e&&!this.#n&&(this.#n=!0,queueMicrotask(()=>{this.#n=!1,this.grid&&this.#e&&this.grid.refreshVirtualWindow?.(!0,!0)}))}}const Ms='@layer tbw-plugins{[data-field=__tbw_row_drag]{display:flex;align-items:center;justify-content:center}.dg-row-drag-handle{display:flex;align-items:center;justify-content:center;min-width:1em;min-height:1em;cursor:grab;-webkit-user-select:none;user-select:none;color:var(--tbw-row-reorder-handle-color, var(--tbw-color-fg-muted));transition:color var(--tbw-transition-duration, .12s) var(--tbw-transition-ease, ease);font-size:var(--tbw-font-size, 1em);letter-spacing:-2px}.dg-row-drag-handle:hover{color:var(--tbw-row-reorder-handle-hover, var(--tbw-color-fg))}.dg-row-drag-handle:active{cursor:grabbing}.data-grid-row.dragging{opacity:.6}.data-grid-row.drop-target{position:relative}.data-grid-row.drop-target.drop-before:before{content:"";position:absolute;top:0;left:0;right:0;height:2px;background-color:var(--tbw-row-reorder-indicator, var(--tbw-color-accent));z-index:10}.data-grid-row.drop-target.drop-after:after{content:"";position:absolute;bottom:0;left:0;right:0;height:2px;background-color:var(--tbw-row-reorder-indicator, var(--tbw-color-accent));z-index:10}.data-grid-row.keyboard-moving{background-color:var(--tbw-row-reorder-moving-bg, var(--tbw-focus-background));box-shadow:0 0 0 1px var(--tbw-row-reorder-moving-border, var(--tbw-color-accent)) inset}.data-grid-row.flip-animating{transition:transform var(--tbw-animation-duration, .2s) ease-out;will-change:transform;z-index:1}}',$i="__tbw_row_drag";class zs extends M{name="rowReorder";styles=Ms;get defaultConfig(){return{enableKeyboard:!0,showDragHandle:!0,dragHandlePosition:"left",dragHandleWidth:40,debounceMs:150,animation:"flip"}}get animationType(){return this.isAnimationEnabled?this.config.animation!==void 0?this.config.animation:"flip":!1}isDragging=!1;draggedRowIndex=null;dropRowIndex=null;pendingMove=null;debounceTimer=null;lastFocusCol=0;detach(){this.clearDebounceTimer(),this.isDragging=!1,this.draggedRowIndex=null,this.dropRowIndex=null,this.pendingMove=null}processColumns(e){if(!this.config.showDragHandle)return[...e];const t={field:$i,header:"",width:this.config.dragHandleWidth??40,resizable:!1,sortable:!1,filterable:!1,meta:{lockPosition:!0,suppressMovable:!0,utility:!0},viewRenderer:()=>{const i=document.createElement("div");return i.className="dg-row-drag-handle",i.setAttribute("aria-label","Drag to reorder"),i.setAttribute("role","button"),i.setAttribute("tabindex","-1"),i.draggable=!0,this.setIcon(i,this.resolveIcon("dragHandle")),i}};return this.config.dragHandlePosition==="right"?[...e,t]:[t,...e]}afterRender(){if(!this.config.showDragHandle)return;const e=this.gridElement;if(!e)return;e.querySelectorAll(".dg-row-drag-handle").forEach(n=>{const o=n;if(o.getAttribute("data-drag-bound"))return;o.setAttribute("data-drag-bound","true");const s=o.closest(".data-grid-row");s&&this.setupHandleDragListeners(o,s)}),e.querySelectorAll(".data-grid-row").forEach(n=>{const o=n;o.getAttribute("data-drop-bound")||(o.setAttribute("data-drop-bound","true"),this.setupRowDropListeners(o))})}onKeyDown(e){if(!this.config.enableKeyboard||!e.ctrlKey||e.key!=="ArrowUp"&&e.key!=="ArrowDown")return;const t=this.grid,i=t._focusRow,n=t._rows??this.sourceRows;if(i<0||i>=n.length)return;const o=e.key==="ArrowUp"?"up":"down",s=o==="up"?i-1:i+1;if(s<0||s>=n.length)return;const l=n[i];if(!(this.config.canMove&&!this.config.canMove(l,i,s,o)))return this.handleKeyboardMove(l,i,s,o,t._focusCol),e.preventDefault(),e.stopPropagation(),!0}onCellClick(){this.flushPendingMove()}moveRow(e,t){const i=[...this.sourceRows];if(e<0||e>=i.length||t<0||t>=i.length||e===t)return;const n=t<e?"up":"down",o=i[e];this.config.canMove&&!this.config.canMove(o,e,t,n)||this.executeMove(o,e,t,"keyboard")}canMoveRow(e,t){const i=this.sourceRows;if(e<0||e>=i.length||t<0||t>=i.length||e===t)return!1;if(!this.config.canMove)return!0;const n=t<e?"up":"down";return this.config.canMove(i[e],e,t,n)}setupHandleDragListeners(e,t){e.addEventListener("dragstart",i=>{const n=this.getRowIndex(t);n<0||(this.isDragging=!0,this.draggedRowIndex=n,i.dataTransfer&&(i.dataTransfer.effectAllowed="move",i.dataTransfer.setData("text/plain",String(n))),t.classList.add("dragging"))}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedRowIndex=null,this.dropRowIndex=null,this.clearDragClasses()})}setupRowDropListeners(e){e.addEventListener("dragover",t=>{if(t.preventDefault(),!this.isDragging||this.draggedRowIndex===null)return;const i=this.getRowIndex(e);if(i<0||i===this.draggedRowIndex)return;const n=e.getBoundingClientRect(),o=n.top+n.height/2,s=t.clientY<o;this.dropRowIndex=s?i:i+1,e.classList.add("drop-target"),e.classList.toggle("drop-before",s),e.classList.toggle("drop-after",!s)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",t=>{t.preventDefault();const i=this.draggedRowIndex;let n=this.dropRowIndex;if(!(!this.isDragging||i===null||n===null)&&(n>i&&n--,i!==n)){const s=this.sourceRows[i],l=n<i?"up":"down";(!this.config.canMove||this.config.canMove(s,i,n,l))&&this.executeMove(s,i,n,"drag")}})}handleKeyboardMove(e,t,i,n,o){this.pendingMove?this.pendingMove.currentIndex=i:this.pendingMove={originalIndex:t,currentIndex:i,row:e},this.lastFocusCol=o;const s=this.grid,l=[...s._rows??this.sourceRows],[a]=l.splice(t,1);l.splice(i,0,a),s._rows=l,s._focusRow=i,s._focusCol=o,s.refreshVirtualWindow(!0),N(s),this.clearDebounceTimer(),this.debounceTimer=setTimeout(()=>{this.flushPendingMove()},this.config.debounceMs??300)}flushPendingMove(){if(this.clearDebounceTimer(),!this.pendingMove)return;const{originalIndex:e,currentIndex:t,row:i}=this.pendingMove;if(this.pendingMove=null,e===t)return;const n={row:i,fromIndex:e,toIndex:t,rows:[...this.sourceRows],source:"keyboard"};if(this.emitCancelable("row-move",n)){const s=[...this.sourceRows],[l]=s.splice(t,1);s.splice(e,0,l);const a=this.grid;a._rows=s,a._focusRow=e,a._focusCol=this.lastFocusCol,a.refreshVirtualWindow(!0),N(a)}}executeMove(e,t,i,n){const o=[...this.sourceRows],[s]=o.splice(t,1);o.splice(i,0,s);const l={row:e,fromIndex:t,toIndex:i,rows:o,source:n};if(!this.emitCancelable("row-move",l))if(this.animationType==="flip"&&this.gridElement){const c=this.captureRowPositions();this.grid.rows=o,requestAnimationFrame(()=>{this.gridElement.offsetHeight,this.animateFLIP(c,t,i)})}else this.grid.rows=o}captureRowPositions(){const e=new Map;return this.gridElement?.querySelectorAll(".data-grid-row").forEach(t=>{const i=this.getRowIndex(t);i>=0&&e.set(i,t.getBoundingClientRect().top)}),e}animateFLIP(e,t,i){const n=this.gridElement;if(!n||e.size===0)return;const o=Math.min(t,i),s=Math.max(t,i),l=[];if(n.querySelectorAll(".data-grid-row").forEach(c=>{const d=c,u=this.getRowIndex(d);if(u<0||u<o||u>s)return;let h;u===i?h=t:t<i?h=u+1:h=u-1;const g=e.get(h);if(g===void 0)return;const f=d.getBoundingClientRect().top,p=g-f;Math.abs(p)>1&&l.push({el:d,deltaY:p})}),l.length===0)return;l.forEach(({el:c,deltaY:d})=>{c.style.transform=`translateY(${d}px)`}),n.offsetHeight;const a=this.animationDuration;requestAnimationFrame(()=>{l.forEach(({el:c})=>{c.classList.add("flip-animating"),c.style.transform=""}),setTimeout(()=>{l.forEach(({el:c})=>{c.style.transform="",c.classList.remove("flip-animating")})},a+50)})}getRowIndex(e){const t=e.querySelector(".cell[data-row]");return t?parseInt(t.getAttribute("data-row")??"-1",10):-1}clearDragClasses(){this.gridElement?.querySelectorAll(".data-grid-row").forEach(e=>{e.classList.remove("dragging","drop-target","drop-before","drop-after")})}clearDebounceTimer(){this.debounceTimer&&(clearTimeout(this.debounceTimer),this.debounceTimer=null)}}function ae(r){return{startRow:Math.min(r.startRow,r.endRow),startCol:Math.min(r.startCol,r.endCol),endRow:Math.max(r.startRow,r.endRow),endCol:Math.max(r.startCol,r.endCol)}}function Fs(r){const e=ae(r);return{from:{row:e.startRow,col:e.startCol},to:{row:e.endRow,col:e.endCol}}}function Ki(r){return r.map(Fs)}function Os(r,e,t){const i=ae(t);return r>=i.startRow&&r<=i.endRow&&e>=i.startCol&&e<=i.endCol}function Ns(r,e,t){return t.some(i=>Os(r,e,i))}function qs(r){const e=[],t=ae(r);for(let i=t.startRow;i<=t.endRow;i++)for(let n=t.startCol;n<=t.endCol;n++)e.push({row:i,col:n});return e}function Gs(r){const e=new Map;for(const t of r)for(const i of qs(t))e.set(`${i.row},${i.col}`,i);return[...e.values()]}function mt(r,e){return{startRow:r.row,startCol:r.col,endRow:e.row,endCol:e.col}}function Fe(r,e){const t=ae(r),i=ae(e);return t.startRow===i.startRow&&t.startCol===i.startCol&&t.endRow===i.endRow&&t.endCol===i.endCol}const Bs='@layer tbw-plugins{tbw-grid.selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}tbw-grid:has(.selection){-webkit-user-select:none;user-select:none}tbw-grid .data-grid-row.row-focus{background-color:var(--tbw-focus-background, rgba(from var(--tbw-color-accent) r g b / 12%));outline:none;position:relative}tbw-grid .data-grid-row.row-focus:after{content:"";position:absolute;inset:0;pointer-events:none;border-width:0;border-style:var(--tbw-selection-border-style, var(--tbw-border-style));border-color:var(--tbw-range-border-color, var(--tbw-color-accent));border-top-width:var(--tbw-selection-border-width, var(--tbw-border-width));border-bottom-width:var(--tbw-selection-border-width, var(--tbw-border-width));z-index:1}tbw-grid .data-grid-row.row-focus+.data-grid-row.row-focus:after{border-top-width:0}tbw-grid .data-grid-row.row-focus:has(+.data-grid-row.row-focus):after{border-bottom-width:0}tbw-grid[data-selection-mode=row] .cell-focus,tbw-grid[data-selection-mode=row] .row-focus,tbw-grid[data-selection-mode=range] .cell-focus{outline:none}tbw-grid .data-grid-row>.cell.selected{background-color:var(--tbw-range-selection-bg);position:relative}tbw-grid .data-grid-row>.cell.selected:after{content:"";position:absolute;inset:0;pointer-events:none;border:0 var(--tbw-selection-border-style, var(--tbw-border-style)) var(--tbw-range-border-color);z-index:1}tbw-grid .data-grid-row>.cell.selected.top:after{border-top-width:var(--tbw-selection-border-width, var(--tbw-border-width))}tbw-grid .data-grid-row>.cell.selected.bottom:after{border-bottom-width:var(--tbw-selection-border-width, var(--tbw-border-width))}tbw-grid .data-grid-row>.cell.selected.first:after{border-left-width:var(--tbw-selection-border-width, var(--tbw-border-width))}tbw-grid .data-grid-row>.cell.selected.last:after{border-right-width:var(--tbw-selection-border-width, var(--tbw-border-width))}tbw-grid .data-grid-row[data-selectable=false]{cursor:not-allowed;opacity:.6}tbw-grid .data-grid-row[data-selectable=false].row-focus{background-color:var(--tbw-color-row-alt)}tbw-grid .data-grid-row>.cell[data-selectable=false]{cursor:not-allowed;opacity:.6}tbw-grid .data-grid-row>.cell[data-selectable=false].selected{background-color:var(--tbw-selection-warning-bg, rgba(from var(--tbw-color-error) r g b / 50%))}tbw-grid .tbw-selection-summary{font-size:var(--tbw-font-size-sm, .8125rem);color:var(--tbw-color-fg-muted);white-space:nowrap}tbw-grid .data-grid-row>.cell[data-field=__tbw_checkbox],tbw-grid .header-row>.cell[data-field=__tbw_checkbox]{text-align:center;cursor:pointer;padding:0;display:flex;align-items:center;justify-content:center}tbw-grid .tbw-select-row-checkbox{pointer-events:none;margin:0;cursor:pointer}tbw-grid .tbw-checkbox-header{display:flex;justify-content:center;align-items:center;height:100%}tbw-grid .tbw-select-all-checkbox{margin:0;cursor:pointer}}',Wi="__tbw_checkbox";function $s(r,e,t){if(r==="cell"&&e.selectedCell)return{mode:r,ranges:[{from:{row:e.selectedCell.row,col:e.selectedCell.col},to:{row:e.selectedCell.row,col:e.selectedCell.col}}]};if(r==="row"&&e.selected.size>0){const i=[...e.selected].sort((l,a)=>l-a),n=[];let o=i[0],s=o;for(let l=1;l<i.length;l++)i[l]===s+1?s=i[l]:(n.push({from:{row:o,col:0},to:{row:s,col:t-1}}),o=i[l],s=o);return n.push({from:{row:o,col:0},to:{row:s,col:t-1}}),{mode:r,ranges:n}}return r==="range"&&e.ranges.length>0?{mode:r,ranges:Ki(e.ranges)}:{mode:r,ranges:[]}}class Ks extends M{static manifest={queries:[{type:"getSelection",description:"Get the current selection state"},{type:"selectRows",description:"Select specific rows by index (row mode only)"},{type:"getSelectedRowIndices",description:"Get sorted array of selected row indices"}],configRules:[{id:"selection/range-dblclick",severity:"warn",message:`"triggerOn: 'dblclick'" has no effect when mode is "range".
|
|
184
|
+
Click OK to continue, or Cancel to abort.`))return}i.maxRows>0&&o>i.maxRows&&(s=i.maxRows,l=!0),this.#t=!0;const a=performance.now();this.emit("print-start",{rowCount:s,limitApplied:l,originalRowCount:o});try{const c=this.#h;this.#u={bypassThreshold:c._virtualization?.bypassThreshold??24},this.#a(),l&&(this.#c=this.sourceRows,this.grid.rows=this.sourceRows.slice(0,s),await new Promise(d=>setTimeout(d,50))),(i.includeTitle||i.includeTimestamp)&&this.#w(i),await this.#y(),await new Promise(d=>requestAnimationFrame(d)),await new Promise(d=>requestAnimationFrame(d)),t.classList.add(`print-${i.orientation}`),await new Promise(d=>requestAnimationFrame(d)),await new Promise(d=>requestAnimationFrame(d)),i.isolate?await this.#g(i):await this.#d(),this.emit("print-complete",{success:!0,rowCount:s,duration:Math.round(performance.now()-a)})}catch(c){console.error("[PrintPlugin] Print failed:",c),this.emit("print-complete",{success:!1,rowCount:0,duration:Math.round(performance.now()-a)})}finally{this.#C(),this.#t=!1}}#w(e){const t=this.gridElement;if(t){if(this.#r=document.createElement("div"),this.#r.className="tbw-print-header",e.includeTitle){const i=e.title||this.grid.effectiveConfig?.shell?.header?.title||"Grid Data",n=document.createElement("div");n.className="tbw-print-header-title",n.textContent=i,this.#r.appendChild(n)}if(e.includeTimestamp){const i=document.createElement("div");i.className="tbw-print-header-timestamp",i.textContent=`Printed: ${new Date().toLocaleString()}`,this.#r.appendChild(i)}t.insertBefore(this.#r,t.firstChild),this.#l=document.createElement("div"),this.#l.className="tbw-print-footer",this.#l.textContent=`Page generated from ${window.location.hostname}`,t.appendChild(this.#l)}}async#y(){const e=this.#h;if(!e._virtualization)return;const t=this.rows.length;e._virtualization.bypassThreshold=t+100,e.refreshVirtualWindow(!0),await new Promise(i=>setTimeout(i,100))}async#d(){return new Promise(e=>{const t=()=>{window.removeEventListener("afterprint",t),e()};window.addEventListener("afterprint",t),window.print(),setTimeout(()=>{typeof window<"u"&&window.removeEventListener("afterprint",t),e()},1e3)})}async#g(e){const t=this.gridElement;t&&await Gi(t,{orientation:e.orientation})}#a(){const e=this.columns;if(e){this.#e=new Map;for(const t of e)t.printHidden&&t.field&&(this.#e.set(t.field,!t.hidden),this.grid.setColumnVisible(t.field,!1))}}#f(){if(this.#e){for(const[e,t]of this.#e)this.grid.setColumnVisible(e,t);this.#e=null}}#C(){const e=this.gridElement;if(!e)return;this.#f(),e.classList.remove("print-portrait","print-landscape"),this.#i!==null&&(e.style.transform="",e.style.transformOrigin="",e.style.width="",this.#i=null),this.#r&&(this.#r.remove(),this.#r=null),this.#l&&(this.#l.remove(),this.#l=null);const t=this.#h;this.#u&&t._virtualization&&(t._virtualization.bypassThreshold=this.#u.bypassThreshold,t.refreshVirtualWindow(!0),this.#u=null),this.#c!==null&&(this.grid.rows=this.#c,this.#c=null)}afterRender(){this.config?.button&&!this.#p&&(this.#R(),this.#p=!0)}#p=!1;#R(){this.#h.registerToolbarContent?.({id:"print-button",order:900,render:t=>{const i=document.createElement("button");i.className="tbw-toolbar-btn tbw-print-btn",i.title="Print grid",i.type="button";const n=this.resolveIcon("print")||"🖨️";this.setIcon(i,n),i.addEventListener("click",()=>{this.print()},{signal:this.disconnectSignal}),t.appendChild(i)}})}}function Ls(r){const e=r.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}function Bi(r,e,t){if(e===t||e<0||e>=r.length||t<0||t>r.length)return r;const i=[...r],[n]=i.splice(e,1);return i.splice(t,0,n),i}const Ps='@layer tbw-plugins{.header-row>.cell[draggable=true]{cursor:grab;position:relative}.header-row>.cell.dragging{opacity:.5;cursor:grabbing}.header-row>.cell.drop-before:before{content:"";position:absolute;left:0;top:0;bottom:0;width:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent));z-index:1}.header-row>.cell.drop-after:after{content:"";position:absolute;right:0;top:0;bottom:0;width:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent));z-index:1}.cell.flip-animating{transition:transform var(--tbw-animation-duration, .2s) ease-out;will-change:transform;z-index:1}@keyframes reorder-fade-in{0%{opacity:0}to{opacity:1}}.cell.fade-animating{animation:reorder-fade-in var(--tbw-animation-duration, .2s) ease-out backwards}}';class Hs extends M{name="reorder";styles=Ps;get defaultConfig(){return{animation:"flip"}}get animationType(){return this.isAnimationEnabled?this.config.animation!==void 0?this.config.animation:"flip":!1}get animationDuration(){return this.config.animationDuration!==void 0?this.config.animationDuration:super.animationDuration}isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;canMoveColumnWithPlugins(e){return!e||!Ls(e)?!1:!this.grid.query("canMoveColumn",e).includes(!1)}clearDragClasses(){this.gridElement?.querySelectorAll(".header-row > .cell").forEach(e=>{e.classList.remove("dragging","drop-target","drop-before","drop-after")})}attach(e){super.attach(e),e.addEventListener("column-reorder-request",t=>{const i=t.detail;i?.field&&typeof i.toIndex=="number"&&this.moveColumn(i.field,i.toIndex)},{signal:this.disconnectSignal})}detach(){this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null}afterRender(){const e=this.gridElement;if(!e)return;e.querySelectorAll(".header-row > .cell").forEach(i=>{const n=i,o=n.getAttribute("data-field");if(!o)return;const s=this.columns.find(l=>l.field===o);if(!this.canMoveColumnWithPlugins(s)){n.draggable=!1;return}n.draggable=!0,!n.getAttribute("data-dragstart-bound")&&(n.setAttribute("data-dragstart-bound","true"),n.addEventListener("dragstart",l=>{const c=this.getColumnOrder().indexOf(o);this.isDragging=!0,this.draggedField=o,this.draggedIndex=c,l.dataTransfer&&(l.dataTransfer.effectAllowed="move",l.dataTransfer.setData("text/plain",o)),n.classList.add("dragging")}),n.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.clearDragClasses()}),n.addEventListener("dragover",l=>{if(l.preventDefault(),!this.isDragging||this.draggedField===o)return;const a=n.getBoundingClientRect(),c=a.left+a.width/2,u=this.getColumnOrder().indexOf(o);this.dropIndex=l.clientX<c?u:u+1,n.classList.add("drop-target"),n.classList.toggle("drop-before",l.clientX<c),n.classList.toggle("drop-after",l.clientX>=c)}),n.addEventListener("dragleave",()=>{n.classList.remove("drop-target","drop-before","drop-after")}),n.addEventListener("drop",l=>{l.preventDefault();const a=this.draggedField,c=this.draggedIndex,d=this.dropIndex;if(!this.isDragging||a===null||c===null||d===null)return;const u=d>c?d-1:d,h=this.getColumnOrder(),g=Bi(h,c,u),f={field:a,fromIndex:c,toIndex:u,columnOrder:g};this.emitCancelable("column-move",f)||this.updateColumnOrder(g)}))})}onKeyDown(e){if(!e.altKey||e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;const t=this.grid,i=t._focusCol,n=t._visibleColumns;if(i<0||i>=n.length)return;const o=n[i];if(!this.canMoveColumnWithPlugins(o))return;const s=this.getColumnOrder(),l=s.indexOf(o.field);if(l===-1)return;const a=e.key==="ArrowLeft"?l-1:l+1;if(a<0||a>=s.length)return;const c=n.find(d=>d.field===s[a]);if(this.canMoveColumnWithPlugins(c))return this.moveColumn(o.field,a),t._focusCol=a,N(this.grid),e.preventDefault(),e.stopPropagation(),!0}getColumnOrder(){return this.grid.getColumnOrder()}moveColumn(e,t){const i=this.getColumnOrder(),n=i.indexOf(e);if(n===-1)return;const o=Bi(i,n,t);this.emitCancelable("column-move",{field:e,fromIndex:n,toIndex:t,columnOrder:o})||this.updateColumnOrder(o)}setColumnOrder(e){this.updateColumnOrder(e)}resetColumnOrder(){const e=this.columns.map(t=>t.field);this.updateColumnOrder(e)}captureHeaderPositions(){const e=new Map;return this.gridElement?.querySelectorAll(".header-row > .cell[data-field]").forEach(t=>{const i=t.getAttribute("data-field");i&&e.set(i,t.getBoundingClientRect().left)}),e}animateFLIP(e){const t=this.gridElement;if(!t||e.size===0)return;const i=new Map;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(s=>{const l=s.getAttribute("data-field");if(!l)return;const a=e.get(l);if(a===void 0)return;const c=a-s.getBoundingClientRect().left;Math.abs(c)>1&&i.set(l,c)}),i.size===0)return;const n=[];if(t.querySelectorAll(".cell[data-field]").forEach(s=>{const l=i.get(s.getAttribute("data-field")??"");if(l!==void 0){const a=s;a.style.transform=`translateX(${l}px)`,n.push(a)}}),n.length===0)return;this.gridElement.offsetHeight;const o=this.animationDuration;requestAnimationFrame(()=>{n.forEach(s=>{s.classList.add("flip-animating"),s.style.transform=""}),setTimeout(()=>{n.forEach(s=>{s.style.transform="",s.classList.remove("flip-animating")})},o+50)})}animateFade(e){const t=this.gridElement;if(!t){e();return}const i=this.captureHeaderPositions();e();const n=new Set;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(l=>{const a=l.getAttribute("data-field");if(!a)return;const c=i.get(a);if(c===void 0)return;const d=l.getBoundingClientRect().left;Math.abs(c-d)>1&&n.add(a)}),n.size===0)return;const o=[];if(t.querySelectorAll(".cell[data-field]").forEach(l=>{const a=l.getAttribute("data-field");if(a&&n.has(a)){const c=l;c.classList.add("fade-animating"),o.push(c)}}),o.length===0)return;const s=this.animationDuration;setTimeout(()=>{o.forEach(l=>l.classList.remove("fade-animating"))},s+50)}updateColumnOrder(e){const t=this.animationType;if(t==="flip"&&this.gridElement){const i=this.captureHeaderPositions();this.grid.setColumnOrder(e),requestAnimationFrame(()=>{this.gridElement.offsetHeight,this.animateFLIP(i)})}else t==="fade"?this.animateFade(()=>this.grid.setColumnOrder(e)):this.grid.setColumnOrder(e);this.grid.requestStateChange?.()}}const Is='tbw-grid[data-responsive-animate] .data-grid-row,tbw-grid[data-responsive-animate] .data-grid-row>.cell{transition:opacity var(--tbw-responsive-duration, .2s) ease-out,transform var(--tbw-responsive-duration, .2s) ease-out}tbw-grid[data-responsive][data-responsive-animate] .data-grid-row{animation:responsive-card-enter var(--tbw-responsive-duration, .2s) ease-out}@keyframes responsive-card-enter{0%{opacity:0;transform:translateY(-10px)}to{opacity:1;transform:translateY(0)}}tbw-grid[data-responsive] .header{display:none!important}tbw-grid[data-responsive] .footer-row{display:none}tbw-grid[data-responsive] .tbw-scroll-area{overflow-x:hidden;min-width:0!important}tbw-grid[data-responsive] .rows-body-wrapper{min-width:0!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row){display:block!important;grid-template-columns:none!important;padding:var(--tbw-cell-padding);padding-inline-start:var(--tbw-spacing-xl);border-bottom:1px solid var(--tbw-color-border);min-height:auto!important;height:auto!important;contain:none!important;content-visibility:visible!important;background:var(--tbw-color-bg);position:relative}tbw-grid[data-responsive] .data-grid-row:not(.group-row):nth-child(2n){background:var(--tbw-color-row-alt)}tbw-grid[data-responsive] .data-grid-row:not(.group-row):hover{background:var(--tbw-color-row-hover)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)[aria-selected=true]{background:var(--tbw-color-selection)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)[aria-selected=true]:before{content:"";position:absolute;inset-inline-start:0;top:0;bottom:0;width:4px;background:var(--tbw-color-accent)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell{display:flex!important;justify-content:space-between;align-items:center;padding:var(--tbw-spacing-xs) var(--tbw-spacing-md);width:100%!important;min-width:0!important;min-height:auto!important;height:auto!important;line-height:1.5!important;position:static!important;left:auto!important;right:auto!important;border:none!important;border-bottom:none!important;border-inline-end:none!important;background:transparent!important;white-space:normal!important;overflow:visible!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell:before{content:attr(data-header) ": ";font-weight:600;color:var(--tbw-color-header-fg);flex-shrink:0;margin-inline-end:var(--tbw-spacing-md);min-width:100px}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell:after{content:none}tbw-grid[data-responsive] .cell[data-utility]{display:none!important}tbw-grid[data-responsive] .cell[data-responsive-hidden]{display:none!important}tbw-grid[data-responsive] .cell[data-responsive-value-only]{justify-content:flex-start!important;font-weight:500}tbw-grid[data-responsive] .cell[data-responsive-value-only]:before{display:none!important}tbw-grid:not([data-responsive]) .cell[data-responsive-hidden]{display:none!important}tbw-grid[data-responsive] .tbw-footer,tbw-grid[data-responsive] .tbw-pinned-rows,tbw-grid[data-responsive] .tbw-aggregation-rows{display:none!important}tbw-grid[data-responsive] .tbw-pinned-rows,tbw-grid[data-responsive] .tbw-aggregation-rows,tbw-grid[data-responsive] .tbw-aggregation-row{min-width:0!important}tbw-grid[data-responsive] .data-grid-row.responsive-card{display:block!important;padding:var(--tbw-cell-padding);border-bottom:1px solid var(--tbw-color-border)}tbw-grid[data-responsive] .data-grid-row.responsive-card>*{width:100%}tbw-grid[data-responsive] .data-grid-row.responsive-card .cell:before{display:none}';class Ds extends M{name="responsive";version="1.0.0";styles=Is;static manifest={incompatibleWith:[{name:"groupingRows",reason:"Responsive card layout does not yet support row grouping. The variable row heights (cards vs group headers) cause scroll calculation issues."}],queries:[{type:"isCardMode",description:"Returns whether the grid is currently in responsive card mode"}]};#t;#e=!1;#u;#c=!1;#r=0;#l=new Set;#i=new Set;#h=null;#w=[];isResponsive(){return this.#e}setResponsive(e){e!==this.#e&&(this.#e=e,this.#C(),this.emit("responsive-change",{isResponsive:e,width:this.#r,breakpoint:this.config.breakpoint??0}))}setBreakpoint(e){this.config.breakpoint=e,this.#g(this.#r)}setCardRenderer(e){this.config.cardRenderer=e,this.#e&&this.requestRender()}getWidth(){return this.#r}getActiveBreakpoint(){return this.#h}attach(e){super.attach(e),this.#y(),this.#d(this.config.hiddenColumns),this.config.breakpoints?.length&&(this.#w=[...this.config.breakpoints].sort((t,i)=>i.maxWidth-t.maxWidth)),this.#t=new ResizeObserver(t=>{const i=t[0]?.contentRect.width??0;this.#r=i,clearTimeout(this.#u),this.#u=setTimeout(()=>{this.#g(i)},this.config.debounceMs??100)}),this.#t.observe(this.gridElement)}#y(){const e=this.grid;if(!e||typeof e.querySelector!="function")return;const t=e.querySelector("tbw-grid-responsive-card");if(!t)return;const i=e;if(i.__frameworkAdapter?.parseResponsiveCardElement){const u=i.__frameworkAdapter.parseResponsiveCardElement(t);u&&(this.config={...this.config,cardRenderer:u})}const n=t.getAttribute("breakpoint"),o=t.getAttribute("card-row-height"),s=t.getAttribute("hidden-columns"),l=t.getAttribute("hide-header"),a=t.getAttribute("debounce-ms"),c={};if(n!==null){const u=parseInt(n,10);isNaN(u)||(c.breakpoint=u)}if(o!==null&&(c.cardRowHeight=o==="auto"?"auto":parseInt(o,10)),s!==null&&(c.hiddenColumns=s.split(",").map(u=>u.trim()).filter(u=>u.length>0)),l!==null&&(c.hideHeader=l!=="false"),a!==null){const u=parseInt(a,10);isNaN(u)||(c.debounceMs=u)}const d=t.innerHTML.trim();d&&!this.config.cardRenderer&&!i.__frameworkAdapter?.parseResponsiveCardElement&&(c.cardRenderer=u=>{const h=Ee(d,{value:u,row:u}),g=X(h),f=document.createElement("div");return f.className="tbw-responsive-card-content",f.innerHTML=g,f}),Object.keys(c).length>0&&(this.config={...this.config,...c})}#d(e){if(this.#l.clear(),this.#i.clear(),!!e)for(const t of e)typeof t=="string"?this.#l.add(t):t.showValue?this.#i.add(t.field):this.#l.add(t.field)}detach(){this.#t?.disconnect(),this.#t=void 0,clearTimeout(this.#u),this.#u=void 0,this.gridElement&&this.gridElement.removeAttribute("data-responsive"),super.detach()}handleQuery(e){if(e.type==="isCardMode")return this.#e}afterRender(){if(this.#S(),!(this.#w.length>0?this.#h!==null:this.#e))return;const t=this.#l.size>0,i=this.#i.size>0;if(!t&&!i)return;const n=this.gridElement.querySelectorAll(".cell[data-field]");for(const o of n){const s=o.getAttribute("data-field");s&&(this.#l.has(s)?(o.setAttribute("data-responsive-hidden",""),o.removeAttribute("data-responsive-value-only")):this.#i.has(s)?(o.setAttribute("data-responsive-value-only",""),o.removeAttribute("data-responsive-hidden")):(o.removeAttribute("data-responsive-hidden"),o.removeAttribute("data-responsive-value-only")))}}#g(e){if(this.#w.length>0){this.#a(e);return}const t=this.config.breakpoint??0;t===0&&!this.#c&&(this.#c=!0,console.warn("[tbw-grid:ResponsivePlugin] No breakpoint configured. Responsive mode is disabled. Set a breakpoint based on your grid's column count."));const i=t>0&&e<t;i!==this.#e&&(this.#e=i,this.#C(),this.emit("responsive-change",{isResponsive:i,width:e,breakpoint:t}),this.requestRender())}#a(e){let t=null;for(const n of this.#w)e<=n.maxWidth&&(t=n);if(t!==this.#h){this.#h=t,t?.hiddenColumns?this.#d(t.hiddenColumns):this.#d(this.config.hiddenColumns);const n=t?.cardLayout===!0;n!==this.#e&&(this.#e=n,this.#C()),this.emit("responsive-change",{isResponsive:this.#e,width:e,breakpoint:t?.maxWidth??0}),this.requestRender()}}#f;#C(){this.gridElement.toggleAttribute("data-responsive",this.#e);const e=this.config.animate!==!1;this.gridElement.toggleAttribute("data-responsive-animate",e),this.config.animationDuration&&this.gridElement.style.setProperty("--tbw-responsive-duration",`${this.config.animationDuration}ms`);const t=this.grid;if(this.#e){t._virtualization&&(this.#f=t._virtualization.rowHeight);const i=this.gridElement.querySelector(".tbw-scroll-area");i&&(i.scrollLeft=0)}else{const i=this.gridElement.querySelectorAll(".data-grid-row");for(const n of i)n.style.height="",n.classList.remove("responsive-card");this.#f&&this.#f>0&&t._virtualization&&(t._virtualization.rowHeight=this.#f,this.#f=void 0),this.#p=void 0,this.#R=void 0,this.#_=void 0}}renderRow(e,t,i){if(!this.#e||!this.config.cardRenderer||e.__isGroupRow)return;t.replaceChildren();const n=this.config.cardRenderer(e,i);t.className="data-grid-row responsive-card";const o=this.config.cardRowHeight??"auto";return o!=="auto"?t.style.height=`${o}px`:t.style.height="auto",t.appendChild(n),!0}onKeyDown(e){if(!this.#e||this.config.cardRenderer&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(e.key))return!1;const t=this.rows.length-1,i=this.visibleColumns.length-1;switch(e.key){case"ArrowDown":if(this.grid._focusCol<i)return this.grid._focusCol+=1,e.preventDefault(),N(this.grid),!0;if(this.grid._focusRow<t)return this.grid._focusRow+=1,this.grid._focusCol=0,e.preventDefault(),N(this.grid),!0;break;case"ArrowUp":if(this.grid._focusCol>0)return this.grid._focusCol-=1,e.preventDefault(),N(this.grid),!0;if(this.grid._focusRow>0)return this.grid._focusRow-=1,this.grid._focusCol=i,e.preventDefault(),N(this.grid),!0;break;case"ArrowRight":if(this.grid._focusRow<t)return this.grid._focusRow+=1,e.preventDefault(),N(this.grid),!0;break;case"ArrowLeft":if(this.grid._focusRow>0)return this.grid._focusRow-=1,e.preventDefault(),N(this.grid),!0;break}return!1}#p;#R;#_;#x(){if(this.#p&&this.#p>0)return this.#p;const e=this.config.cardRowHeight;return typeof e=="number"&&e>0?e:80}#E(){return this.#R&&this.#R>0?this.#R:this.#f??28}#v(){for(const e of this.rows)if(e.__isGroupRow)return!0;return!1}#m(){let e=0,t=0;for(const i of this.rows)i.__isGroupRow?e++:t++;return{groupCount:e,cardCount:t}}getExtraHeight(){if(!this.#e||!this.config.cardRenderer||!this.#v())return 0;const e=this.#f??28,t=this.#E(),i=this.#x(),{groupCount:n,cardCount:o}=this.#m(),s=n*Math.max(0,t-e),l=o*Math.max(0,i-e);return s+l}getExtraHeightBefore(e){if(!this.#e||!this.config.cardRenderer||!this.#v())return 0;const t=this.#f??28,i=this.#E(),n=this.#x(),o=Math.max(0,i-t),s=Math.max(0,n-t);let l=0,a=0;const c=this.rows,d=Math.min(e,c.length);for(let u=0;u<d;u++)c[u].__isGroupRow?l++:a++;return l*o+a*s}getRowHeight(e,t){if(!(!this.#e||!this.config.cardRenderer))return e.__isGroupRow?this.#E():this.#x()}#A(){let e=0;for(const t of this.rows)t.__isGroupRow||e++;return e}#n=!1;#S(){if(!this.#e||!this.config.cardRenderer)return;let e=!1;const t=this.grid,i=this.#v(),n=this.#A();if(n!==this.#_&&(this.#_=n,e=!0),i){const s=this.gridElement.querySelector(".data-grid-row.group-row");if(s){const l=s.getBoundingClientRect().height;l>0&&l!==this.#R&&(this.#R=l,e=!0)}}const o=this.gridElement.querySelector(".data-grid-row.responsive-card");if(o){const s=o.getBoundingClientRect().height;s>0&&s!==this.#p&&(this.#p=s,e=!0,!i&&t._virtualization&&(t._virtualization.rowHeight=s))}e&&!this.#n&&(this.#n=!0,queueMicrotask(()=>{this.#n=!1,this.grid&&this.#e&&this.grid.refreshVirtualWindow?.(!0,!0)}))}}const Ms='@layer tbw-plugins{[data-field=__tbw_row_drag]{display:flex;align-items:center;justify-content:center}.dg-row-drag-handle{display:flex;align-items:center;justify-content:center;min-width:1em;min-height:1em;cursor:grab;-webkit-user-select:none;user-select:none;color:var(--tbw-row-reorder-handle-color, var(--tbw-color-fg-muted));transition:color var(--tbw-transition-duration, .12s) var(--tbw-transition-ease, ease);font-size:var(--tbw-font-size, 1em);letter-spacing:-2px}.dg-row-drag-handle:hover{color:var(--tbw-row-reorder-handle-hover, var(--tbw-color-fg))}.dg-row-drag-handle:active{cursor:grabbing}.data-grid-row.dragging{opacity:.6}.data-grid-row.drop-target{position:relative}.data-grid-row.drop-target.drop-before:before{content:"";position:absolute;top:0;left:0;right:0;height:2px;background-color:var(--tbw-row-reorder-indicator, var(--tbw-color-accent));z-index:10}.data-grid-row.drop-target.drop-after:after{content:"";position:absolute;bottom:0;left:0;right:0;height:2px;background-color:var(--tbw-row-reorder-indicator, var(--tbw-color-accent));z-index:10}.data-grid-row.keyboard-moving{background-color:var(--tbw-row-reorder-moving-bg, var(--tbw-focus-background));box-shadow:0 0 0 1px var(--tbw-row-reorder-moving-border, var(--tbw-color-accent)) inset}.data-grid-row.flip-animating{transition:transform var(--tbw-animation-duration, .2s) ease-out;will-change:transform;z-index:1}}',$i="__tbw_row_drag";class zs extends M{name="rowReorder";styles=Ms;get defaultConfig(){return{enableKeyboard:!0,showDragHandle:!0,dragHandlePosition:"left",dragHandleWidth:40,debounceMs:150,animation:"flip"}}get animationType(){return this.isAnimationEnabled?this.config.animation!==void 0?this.config.animation:"flip":!1}isDragging=!1;draggedRowIndex=null;dropRowIndex=null;pendingMove=null;debounceTimer=null;lastFocusCol=0;detach(){this.clearDebounceTimer(),this.isDragging=!1,this.draggedRowIndex=null,this.dropRowIndex=null,this.pendingMove=null}processColumns(e){if(!this.config.showDragHandle)return[...e];const t={field:$i,header:"",width:this.config.dragHandleWidth??40,resizable:!1,sortable:!1,filterable:!1,meta:{lockPosition:!0,suppressMovable:!0,utility:!0},viewRenderer:()=>{const i=document.createElement("div");return i.className="dg-row-drag-handle",i.setAttribute("aria-label","Drag to reorder"),i.setAttribute("role","button"),i.setAttribute("tabindex","-1"),i.draggable=!0,this.setIcon(i,this.resolveIcon("dragHandle")),i}};return this.config.dragHandlePosition==="right"?[...e,t]:[t,...e]}afterRender(){if(!this.config.showDragHandle)return;const e=this.gridElement;if(!e)return;e.querySelectorAll(".dg-row-drag-handle").forEach(n=>{const o=n;if(o.getAttribute("data-drag-bound"))return;o.setAttribute("data-drag-bound","true");const s=o.closest(".data-grid-row");s&&this.setupHandleDragListeners(o,s)}),e.querySelectorAll(".data-grid-row").forEach(n=>{const o=n;o.getAttribute("data-drop-bound")||(o.setAttribute("data-drop-bound","true"),this.setupRowDropListeners(o))})}onKeyDown(e){if(!this.config.enableKeyboard||!e.ctrlKey||e.key!=="ArrowUp"&&e.key!=="ArrowDown")return;const t=this.grid,i=t._focusRow,n=t._rows??this.sourceRows;if(i<0||i>=n.length)return;const o=e.key==="ArrowUp"?"up":"down",s=o==="up"?i-1:i+1;if(s<0||s>=n.length)return;const l=n[i];if(!(this.config.canMove&&!this.config.canMove(l,i,s,o)))return this.handleKeyboardMove(l,i,s,o,t._focusCol),e.preventDefault(),e.stopPropagation(),!0}onCellClick(){this.flushPendingMove()}moveRow(e,t){const i=[...this.sourceRows];if(e<0||e>=i.length||t<0||t>=i.length||e===t)return;const n=t<e?"up":"down",o=i[e];this.config.canMove&&!this.config.canMove(o,e,t,n)||this.executeMove(o,e,t,"keyboard")}canMoveRow(e,t){const i=this.sourceRows;if(e<0||e>=i.length||t<0||t>=i.length||e===t)return!1;if(!this.config.canMove)return!0;const n=t<e?"up":"down";return this.config.canMove(i[e],e,t,n)}setupHandleDragListeners(e,t){e.addEventListener("dragstart",i=>{const n=this.getRowIndex(t);n<0||(this.isDragging=!0,this.draggedRowIndex=n,i.dataTransfer&&(i.dataTransfer.effectAllowed="move",i.dataTransfer.setData("text/plain",String(n))),t.classList.add("dragging"))}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedRowIndex=null,this.dropRowIndex=null,this.clearDragClasses()})}setupRowDropListeners(e){e.addEventListener("dragover",t=>{if(t.preventDefault(),!this.isDragging||this.draggedRowIndex===null)return;const i=this.getRowIndex(e);if(i<0||i===this.draggedRowIndex)return;const n=e.getBoundingClientRect(),o=n.top+n.height/2,s=t.clientY<o;this.dropRowIndex=s?i:i+1,e.classList.add("drop-target"),e.classList.toggle("drop-before",s),e.classList.toggle("drop-after",!s)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",t=>{t.preventDefault();const i=this.draggedRowIndex;let n=this.dropRowIndex;if(!(!this.isDragging||i===null||n===null)&&(n>i&&n--,i!==n)){const s=this.sourceRows[i],l=n<i?"up":"down";(!this.config.canMove||this.config.canMove(s,i,n,l))&&this.executeMove(s,i,n,"drag")}})}handleKeyboardMove(e,t,i,n,o){this.pendingMove?this.pendingMove.currentIndex=i:this.pendingMove={originalIndex:t,currentIndex:i,row:e},this.lastFocusCol=o;const s=this.grid,l=[...s._rows??this.sourceRows],[a]=l.splice(t,1);l.splice(i,0,a),s._rows=l,s._focusRow=i,s._focusCol=o,s.refreshVirtualWindow(!0),N(s),this.clearDebounceTimer(),this.debounceTimer=setTimeout(()=>{this.flushPendingMove()},this.config.debounceMs??300)}flushPendingMove(){if(this.clearDebounceTimer(),!this.pendingMove)return;const{originalIndex:e,currentIndex:t,row:i}=this.pendingMove;if(this.pendingMove=null,e===t)return;const n={row:i,fromIndex:e,toIndex:t,rows:[...this.sourceRows],source:"keyboard"};if(this.emitCancelable("row-move",n)){const s=[...this.sourceRows],[l]=s.splice(t,1);s.splice(e,0,l);const a=this.grid;a._rows=s,a._focusRow=e,a._focusCol=this.lastFocusCol,a.refreshVirtualWindow(!0),N(a)}}executeMove(e,t,i,n){const o=[...this.sourceRows],[s]=o.splice(t,1);o.splice(i,0,s);const l={row:e,fromIndex:t,toIndex:i,rows:o,source:n};if(!this.emitCancelable("row-move",l))if(this.animationType==="flip"&&this.gridElement){const c=this.captureRowPositions();this.grid.rows=o,requestAnimationFrame(()=>{this.gridElement.offsetHeight,this.animateFLIP(c,t,i)})}else this.grid.rows=o}captureRowPositions(){const e=new Map;return this.gridElement?.querySelectorAll(".data-grid-row").forEach(t=>{const i=this.getRowIndex(t);i>=0&&e.set(i,t.getBoundingClientRect().top)}),e}animateFLIP(e,t,i){const n=this.gridElement;if(!n||e.size===0)return;const o=Math.min(t,i),s=Math.max(t,i),l=[];if(n.querySelectorAll(".data-grid-row").forEach(c=>{const d=c,u=this.getRowIndex(d);if(u<0||u<o||u>s)return;let h;u===i?h=t:t<i?h=u+1:h=u-1;const g=e.get(h);if(g===void 0)return;const f=d.getBoundingClientRect().top,p=g-f;Math.abs(p)>1&&l.push({el:d,deltaY:p})}),l.length===0)return;l.forEach(({el:c,deltaY:d})=>{c.style.transform=`translateY(${d}px)`}),n.offsetHeight;const a=this.animationDuration;requestAnimationFrame(()=>{l.forEach(({el:c})=>{c.classList.add("flip-animating"),c.style.transform=""}),setTimeout(()=>{l.forEach(({el:c})=>{c.style.transform="",c.classList.remove("flip-animating")})},a+50)})}getRowIndex(e){const t=e.querySelector(".cell[data-row]");return t?parseInt(t.getAttribute("data-row")??"-1",10):-1}clearDragClasses(){this.gridElement?.querySelectorAll(".data-grid-row").forEach(e=>{e.classList.remove("dragging","drop-target","drop-before","drop-after")})}clearDebounceTimer(){this.debounceTimer&&(clearTimeout(this.debounceTimer),this.debounceTimer=null)}}function ae(r){return{startRow:Math.min(r.startRow,r.endRow),startCol:Math.min(r.startCol,r.endCol),endRow:Math.max(r.startRow,r.endRow),endCol:Math.max(r.startCol,r.endCol)}}function Fs(r){const e=ae(r);return{from:{row:e.startRow,col:e.startCol},to:{row:e.endRow,col:e.endCol}}}function Ki(r){return r.map(Fs)}function Os(r,e,t){const i=ae(t);return r>=i.startRow&&r<=i.endRow&&e>=i.startCol&&e<=i.endCol}function Ns(r,e,t){return t.some(i=>Os(r,e,i))}function qs(r){const e=[],t=ae(r);for(let i=t.startRow;i<=t.endRow;i++)for(let n=t.startCol;n<=t.endCol;n++)e.push({row:i,col:n});return e}function Gs(r){const e=new Map;for(const t of r)for(const i of qs(t))e.set(`${i.row},${i.col}`,i);return[...e.values()]}function mt(r,e){return{startRow:r.row,startCol:r.col,endRow:e.row,endCol:e.col}}function Fe(r,e){const t=ae(r),i=ae(e);return t.startRow===i.startRow&&t.startCol===i.startCol&&t.endRow===i.endRow&&t.endCol===i.endCol}const Bs='@layer tbw-plugins{tbw-grid.selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}tbw-grid:has(.selection){-webkit-user-select:none;user-select:none}tbw-grid .data-grid-row.row-focus{background-color:var(--tbw-focus-background, rgba(from var(--tbw-color-accent) r g b / 12%));outline:none;position:relative}tbw-grid .data-grid-row.row-focus:after{content:"";position:absolute;inset:0;pointer-events:none;border-width:0;border-style:var(--tbw-selection-border-style, var(--tbw-border-style));border-color:var(--tbw-range-border-color, var(--tbw-color-accent));border-top-width:var(--tbw-selection-border-width, var(--tbw-border-width));border-bottom-width:var(--tbw-selection-border-width, var(--tbw-border-width));z-index:1}tbw-grid .data-grid-row.row-focus+.data-grid-row.row-focus:after{border-top-width:0}tbw-grid .data-grid-row.row-focus:has(+.data-grid-row.row-focus):after{border-bottom-width:0}tbw-grid[data-selection-mode=row] .cell-focus,tbw-grid[data-selection-mode=row] .row-focus,tbw-grid[data-selection-mode=range] .cell-focus{outline:none}tbw-grid .data-grid-row>.cell.selected{background-color:var(--tbw-range-selection-bg);position:relative}tbw-grid .data-grid-row>.cell.selected:after{content:"";position:absolute;inset:0;pointer-events:none;border:0 var(--tbw-selection-border-style, var(--tbw-border-style)) var(--tbw-range-border-color);z-index:1}tbw-grid .data-grid-row>.cell.selected.top:after{border-top-width:var(--tbw-selection-border-width, var(--tbw-border-width))}tbw-grid .data-grid-row>.cell.selected.bottom:after{border-bottom-width:var(--tbw-selection-border-width, var(--tbw-border-width))}tbw-grid .data-grid-row>.cell.selected.first:after{border-left-width:var(--tbw-selection-border-width, var(--tbw-border-width))}tbw-grid .data-grid-row>.cell.selected.last:after{border-right-width:var(--tbw-selection-border-width, var(--tbw-border-width))}tbw-grid .data-grid-row[data-selectable=false]{cursor:not-allowed;opacity:.6}tbw-grid .data-grid-row[data-selectable=false].row-focus{background-color:var(--tbw-color-row-alt)}tbw-grid .data-grid-row>.cell[data-selectable=false]{cursor:not-allowed;opacity:.6}tbw-grid .data-grid-row>.cell[data-selectable=false].selected{background-color:var(--tbw-selection-warning-bg, rgba(from var(--tbw-color-error) r g b / 50%))}tbw-grid .tbw-selection-summary{font-size:var(--tbw-font-size-sm, .8125rem);color:var(--tbw-color-fg-muted);white-space:nowrap}tbw-grid .data-grid-row>.cell[data-field=__tbw_checkbox],tbw-grid .header-row>.cell[data-field=__tbw_checkbox]{text-align:center;cursor:pointer;padding:0;display:flex;align-items:center;justify-content:center}tbw-grid .tbw-select-row-checkbox{pointer-events:none;margin:0;cursor:pointer}tbw-grid .tbw-checkbox-header{display:flex;justify-content:center;align-items:center;height:100%}tbw-grid .tbw-select-all-checkbox{margin:0;cursor:pointer}}',Wi="__tbw_checkbox";function $s(r,e,t){if(r==="cell"&&e.selectedCell)return{mode:r,ranges:[{from:{row:e.selectedCell.row,col:e.selectedCell.col},to:{row:e.selectedCell.row,col:e.selectedCell.col}}]};if(r==="row"&&e.selected.size>0){const i=[...e.selected].sort((l,a)=>l-a),n=[];let o=i[0],s=o;for(let l=1;l<i.length;l++)i[l]===s+1?s=i[l]:(n.push({from:{row:o,col:0},to:{row:s,col:t-1}}),o=i[l],s=o);return n.push({from:{row:o,col:0},to:{row:s,col:t-1}}),{mode:r,ranges:n}}return r==="range"&&e.ranges.length>0?{mode:r,ranges:Ki(e.ranges)}:{mode:r,ranges:[]}}class Ks extends M{static manifest={queries:[{type:"getSelection",description:"Get the current selection state"},{type:"selectRows",description:"Select specific rows by index (row mode only)"},{type:"getSelectedRowIndices",description:"Get sorted array of selected row indices"},{type:"getSelectedRows",description:"Get actual row objects for the current selection (works in all modes)"}],configRules:[{id:"selection/range-dblclick",severity:"warn",message:`"triggerOn: 'dblclick'" has no effect when mode is "range".
|
|
185
185
|
→ Range selection uses drag interaction (mousedown → mousemove), not click events.
|
|
186
|
-
→ The "triggerOn" option only affects "cell" and "row" selection modes.`,check:e=>e.mode==="range"&&e.triggerOn==="dblclick"}]};name="selection";styles=Bs;get defaultConfig(){return{mode:"cell",triggerOn:"click",enabled:!0}}selected=new Set;lastSelected=null;anchor=null;ranges=[];activeRange=null;cellAnchor=null;isDragging=!1;pendingKeyboardUpdate=null;selectedCell=null;lastSyncedFocusRow=-1;lastSyncedFocusCol=-1;explicitSelection=!1;isSelectionEnabled(){return this.config.enabled===!1?!1:this.grid.effectiveConfig?.selectable!==!1}checkSelectable(e,t){const{isSelectable:i}=this.config;if(!i)return!0;const n=this.rows[e];if(!n)return!1;const o=t!==void 0?this.columns[t]:void 0;return i(n,e,o,t)}isRowSelectable(e){return this.checkSelectable(e)}isCellSelectable(e,t){return this.checkSelectable(e,t)}attach(e){super.attach(e),this.on("filter-applied",()=>this.clearSelectionSilent()),this.on("grouping-state-change",()=>this.clearSelectionSilent()),this.on("tree-state-change",()=>this.clearSelectionSilent())}handleQuery(e){if(e.type==="getSelection")return this.getSelection();if(e.type==="getSelectedRowIndices")return this.getSelectedRowIndices();if(e.type==="selectRows")return this.selectRows(e.context),!0}detach(){this.selected.clear(),this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.isDragging=!1,this.selectedCell=null,this.pendingKeyboardUpdate=null,this.lastSyncedFocusRow=-1,this.lastSyncedFocusCol=-1}clearSelectionSilent(){this.selected.clear(),this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.selectedCell=null,this.lastSelected=null,this.anchor=null,this.lastSyncedFocusRow=-1,this.lastSyncedFocusCol=-1,this.requestAfterRender()}onCellClick(e){if(!this.isSelectionEnabled())return!1;const{rowIndex:t,colIndex:i,originalEvent:n}=e,{mode:o,triggerOn:s="click"}=this.config;if(n.type!==s)return!1;const l=this.columns[i],a=l&&le(l);if(o==="cell"){if(a||!this.isCellSelectable(t,i))return!1;const c=this.selectedCell;return c&&c.row===t&&c.col===i||(this.selectedCell={row:t,col:i},this.emit("selection-change",this.#r()),this.requestAfterRender()),!1}if(o==="row"){if(!this.isRowSelectable(t))return!1;const c=n.shiftKey,d=n.ctrlKey||n.metaKey,u=l?.meta?.checkboxColumn===!0;if(c&&this.anchor!==null){const h=Math.min(this.anchor,t),g=Math.max(this.anchor,t);d||this.selected.clear();for(let f=h;f<=g;f++)this.isRowSelectable(f)&&this.selected.add(f)}else if(d||u)this.selected.has(t)?this.selected.delete(t):this.selected.add(t),this.anchor=t;else{if(this.selected.size===1&&this.selected.has(t))return!1;this.selected.clear(),this.selected.add(t),this.anchor=t}return this.lastSelected=t,this.explicitSelection=!0,this.emit("selection-change",this.#r()),this.requestAfterRender(),!1}if(o==="range"){if(a||!this.isCellSelectable(t,i))return!1;const c=n.shiftKey,d=n.ctrlKey||n.metaKey;if(c&&this.cellAnchor){const u=mt(this.cellAnchor,{row:t,col:i}),h=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;if(h&&Fe(h,u))return!1;d?this.ranges.length>0?this.ranges[this.ranges.length-1]=u:this.ranges.push(u):this.ranges=[u],this.activeRange=u}else if(d){const u={startRow:t,startCol:i,endRow:t,endCol:i};this.ranges.push(u),this.activeRange=u,this.cellAnchor={row:t,col:i}}else{const u={startRow:t,startCol:i,endRow:t,endCol:i};if(this.ranges.length===1&&Fe(this.ranges[0],u))return!1;this.ranges=[u],this.activeRange=u,this.cellAnchor={row:t,col:i}}return this.emit("selection-change",this.#r()),this.requestAfterRender(),!1}return!1}onKeyDown(e){if(!this.isSelectionEnabled())return!1;const{mode:t}=this.config,n=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Tab","Home","End","PageUp","PageDown"].includes(e.key);if(e.key==="Escape")return this.grid.query("isEditing").some(Boolean)?!1:(t==="cell"?this.selectedCell=null:t==="row"?(this.selected.clear(),this.anchor=null):t==="range"&&(this.ranges=[],this.activeRange=null,this.cellAnchor=null),this.emit("selection-change",this.#r()),this.requestAfterRender(),!0);if(t==="cell"&&n)return queueMicrotask(()=>{const o=this.grid._focusRow,s=this.grid._focusCol;this.isCellSelectable(o,s)?this.selectedCell={row:o,col:s}:this.selectedCell=null,this.emit("selection-change",this.#r()),this.requestAfterRender()}),!1;if(t==="row"){if(e.key==="ArrowUp"||e.key==="ArrowDown"){const o=e.shiftKey;return o&&this.anchor===null&&(this.anchor=this.grid._focusRow),queueMicrotask(()=>{const s=this.grid._focusRow;if(o&&this.anchor!==null){this.selected.clear();const l=Math.min(this.anchor,s),a=Math.max(this.anchor,s);for(let c=l;c<=a;c++)this.isRowSelectable(c)&&this.selected.add(c)}else this.isRowSelectable(s)?(this.selected.clear(),this.selected.add(s),this.anchor=s):this.selected.clear();this.lastSelected=s,this.explicitSelection=!0,this.emit("selection-change",this.#r()),this.requestAfterRender()}),!1}if(e.key==="a"&&(e.ctrlKey||e.metaKey))return this.grid.query("isEditing").some(Boolean)?!1:(e.preventDefault(),e.stopPropagation(),this.selectAll(),!0)}if(t==="range"&&n){const o=e.key==="Tab",s=e.shiftKey&&!o;return s&&!this.cellAnchor&&(this.cellAnchor={row:this.grid._focusRow,col:this.grid._focusCol}),this.pendingKeyboardUpdate={shiftKey:s},queueMicrotask(()=>this.requestAfterRender()),!1}return t==="range"&&e.key==="a"&&(e.ctrlKey||e.metaKey)?this.grid.query("isEditing").some(Boolean)?!1:(e.preventDefault(),e.stopPropagation(),this.selectAll(),!0):!1}onCellMouseDown(e){if(!this.isSelectionEnabled()||this.config.mode!=="range"||e.rowIndex===void 0||e.colIndex===void 0||e.rowIndex<0)return;const t=this.columns[e.colIndex];if(t&&le(t)||!this.isCellSelectable(e.rowIndex,e.colIndex)||e.originalEvent.shiftKey&&this.cellAnchor)return;this.isDragging=!0;const i=e.rowIndex,n=e.colIndex,o=e.originalEvent.ctrlKey||e.originalEvent.metaKey,s={startRow:i,startCol:n,endRow:i,endCol:n};return!o&&this.ranges.length===1&&Fe(this.ranges[0],s)?(this.cellAnchor={row:i,col:n},!0):(this.cellAnchor={row:i,col:n},o||(this.ranges=[]),this.ranges.push(s),this.activeRange=s,this.emit("selection-change",this.#r()),this.requestAfterRender(),!0)}onCellMouseMove(e){if(!this.isSelectionEnabled()||this.config.mode!=="range"||!this.isDragging||!this.cellAnchor||e.rowIndex===void 0||e.colIndex===void 0||e.rowIndex<0)return;let t=e.colIndex;const i=this.columns[t];if(i&&le(i)){const s=this.columns.findIndex(l=>!le(l));s>=0&&(t=s)}const n=mt(this.cellAnchor,{row:e.rowIndex,col:t}),o=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;return o&&Fe(o,n)||(this.ranges.length>0?this.ranges[this.ranges.length-1]=n:this.ranges.push(n),this.activeRange=n,this.emit("selection-change",this.#r()),this.requestAfterRender()),!0}onCellMouseUp(e){if(this.isSelectionEnabled()&&this.config.mode==="range"&&this.isDragging)return this.isDragging=!1,!0}processColumns(e){if(this.config.checkbox&&this.config.mode==="row"){if(e.some(o=>o.field===Wi))return e;const t=this.#t(),i=e.findIndex(Me),n=i>=0?i+1:0;return[...e.slice(0,n),t,...e.slice(n)]}return e}#t(){return{field:Wi,header:"",width:32,resizable:!1,sortable:!1,meta:{lockPosition:!0,suppressMovable:!0,utility:!0,checkboxColumn:!0},headerRenderer:()=>{const e=document.createElement("div");e.className="tbw-checkbox-header";const t=document.createElement("input");return t.type="checkbox",t.className="tbw-select-all-checkbox",t.addEventListener("click",i=>{i.stopPropagation(),i.target.checked?this.selectAll():this.clearSelection()}),e.appendChild(t),e},renderer:e=>{const t=document.createElement("input");t.type="checkbox",t.className="tbw-select-row-checkbox";const i=e.cellEl;if(i){const n=parseInt(i.getAttribute("data-row")??"-1",10);n>=0&&(t.checked=this.selected.has(n))}return t}}}#e(e){e.querySelectorAll(".tbw-select-row-checkbox").forEach(n=>{const o=n.closest(".cell"),s=o?Re(o):-1;s>=0&&(n.checked=this.selected.has(s))});const i=e.querySelector(".tbw-select-all-checkbox");if(i){const n=this.rows.length;let o=0;if(this.config.isSelectable)for(let a=0;a<n;a++)this.isRowSelectable(a)&&o++;else o=n;const s=o>0&&this.selected.size>=o,l=this.selected.size>0;i.checked=s,i.indeterminate=l&&!s}}#u(e){const t=this.grid._focusRow,i=this.grid._focusCol;if(e==="row"){if(this.explicitSelection){this.explicitSelection=!1,this.lastSyncedFocusRow=t;return}t!==this.lastSyncedFocusRow&&(this.lastSyncedFocusRow=t,this.isRowSelectable(t)&&(!this.selected.has(t)||this.selected.size!==1)&&(this.selected.clear(),this.selected.add(t),this.lastSelected=t,this.anchor=t,this.emit("selection-change",this.#r())))}if(e==="cell"){if(this.explicitSelection){this.explicitSelection=!1,this.lastSyncedFocusRow=t,this.lastSyncedFocusCol=i;return}if((t!==this.lastSyncedFocusRow||i!==this.lastSyncedFocusCol)&&(this.lastSyncedFocusRow=t,this.lastSyncedFocusCol=i,this.isCellSelectable(t,i))){const n=this.selectedCell;(!n||n.row!==t||n.col!==i)&&(this.selectedCell={row:t,col:i},this.emit("selection-change",this.#r()))}}}#c(){const e=this.gridElement;if(!e)return;const{mode:t}=this.config,i=!!this.config.isSelectable;e.querySelectorAll(".cell").forEach(s=>{s.classList.remove("selected","top","bottom","first","last"),i&&s.removeAttribute("data-selectable")});const o=e.querySelectorAll(".data-grid-row");if(o.forEach(s=>{s.classList.remove("selected","row-focus"),i&&s.removeAttribute("data-selectable")}),t==="row"&&(he(e),o.forEach(s=>{const l=s.querySelector(".cell[data-row]"),a=Re(l);a>=0&&(i&&!this.isRowSelectable(a)&&s.setAttribute("data-selectable","false"),this.selected.has(a)&&s.classList.add("selected","row-focus"))}),this.config.checkbox&&this.#e(e)),(t==="cell"||t==="range")&&i&&e.querySelectorAll(".cell[data-row][data-col]").forEach(l=>{const a=parseInt(l.getAttribute("data-row")??"-1",10),c=parseInt(l.getAttribute("data-col")??"-1",10);a>=0&&c>=0&&(this.isCellSelectable(a,c)||l.setAttribute("data-selectable","false"))}),t==="range"&&this.ranges.length>0){he(e);const s=this.ranges.map(ae),l=(c,d)=>{for(const u of s)if(c>=u.startRow&&c<=u.endRow&&d>=u.startCol&&d<=u.endCol)return!0;return!1};e.querySelectorAll(".cell[data-row][data-col]").forEach(c=>{const d=parseInt(c.getAttribute("data-row")??"-1",10),u=parseInt(c.getAttribute("data-col")??"-1",10);if(d>=0&&u>=0){const h=this.columns[u];if(h&&le(h))return;l(d,u)&&(c.classList.add("selected"),l(d-1,u)||c.classList.add("top"),l(d+1,u)||c.classList.add("bottom"),l(d,u-1)||c.classList.add("first"),l(d,u+1)||c.classList.add("last"))}})}}afterRender(){if(!this.isSelectionEnabled())return;const e=this.gridElement;if(!e)return;const t=e.children[0],{mode:i}=this.config;if(this.pendingKeyboardUpdate&&i==="range"){const{shiftKey:n}=this.pendingKeyboardUpdate;this.pendingKeyboardUpdate=null;const o=this.grid._focusRow,s=this.grid._focusCol;if(n&&this.cellAnchor){const l=mt(this.cellAnchor,{row:o,col:s});this.ranges=[l],this.activeRange=l}else n||(this.ranges=[],this.activeRange=null,this.cellAnchor={row:o,col:s});this.emit("selection-change",this.#r())}this.#u(i),this.grid.setAttribute("data-selection-mode",i),t&&t.classList.toggle("selecting",this.isDragging),this.#c()}onScrollRender(){this.isSelectionEnabled()&&this.#c()}getSelection(){return{mode:this.config.mode,ranges:this.#r().ranges,anchor:this.cellAnchor}}getSelectedCells(){return Gs(this.ranges)}isCellSelected(e,t){return Ns(e,t,this.ranges)}selectAll(){const{mode:e}=this.config;if(e==="row"){this.selected.clear();for(let t=0;t<this.rows.length;t++)this.isRowSelectable(t)&&this.selected.add(t);this.explicitSelection=!0,this.emit("selection-change",this.#r()),this.requestAfterRender()}else if(e==="range"){const t=this.rows.length,i=this.columns.length;if(t>0&&i>0){const n={startRow:0,startCol:0,endRow:t-1,endCol:i-1};this.ranges=[n],this.activeRange=n,this.emit("selection-change",this.#r()),this.requestAfterRender()}}}selectRows(e){if(this.config.mode==="row"){this.selected.clear();for(const t of e)t>=0&&t<this.rows.length&&this.isRowSelectable(t)&&this.selected.add(t);this.anchor=e.length>0?e[e.length-1]:null,this.explicitSelection=!0,this.emit("selection-change",this.#r()),this.requestAfterRender()}}getSelectedRowIndices(){return[...this.selected].sort((e,t)=>e-t)}clearSelection(){this.selectedCell=null,this.selected.clear(),this.anchor=null,this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.emit("selection-change",{mode:this.config.mode,ranges:[]}),this.requestAfterRender()}setRanges(e){this.ranges=e.map(t=>({startRow:t.from.row,startCol:t.from.col,endRow:t.to.row,endCol:t.to.col})),this.activeRange=this.ranges.length>0?this.ranges[this.ranges.length-1]:null,this.emit("selection-change",{mode:this.config.mode,ranges:Ki(this.ranges)}),this.requestAfterRender()}#r(){return $s(this.config.mode,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges},this.columns.length)}}function Oe(r,e){return Math.floor(r/e)}function Ws(r,e){return{start:r*e,end:(r+1)*e}}function Vs(r,e,t){const i=Oe(r,t),n=Oe(e-1,t),o=[];for(let s=i;s<=n;s++)o.push(s);return o}async function Vi(r,e,t,i){const n=Ws(e,t);return r.getRows({startRow:n.start,endRow:n.end,sortModel:i.sortModel,filterModel:i.filterModel})}function Us(r,e,t){const i=Oe(r,e),n=t.get(i);if(!n)return;const o=r%e;return n[o]}const js=100;class Ys extends M{name="serverSide";get defaultConfig(){return{pageSize:100,cacheBlockSize:100,maxConcurrentRequests:2}}dataSource=null;totalRowCount=0;loadedBlocks=new Map;loadingBlocks=new Set;lastRequestId=0;scrollDebounceTimer;detach(){this.dataSource=null,this.totalRowCount=0,this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.lastRequestId=0,this.scrollDebounceTimer&&(clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=void 0)}loadRequiredBlocks(){if(!this.dataSource)return;const e=this.grid,t=this.config.cacheBlockSize??100,i={startRow:e._virtualization.start,endRow:e._virtualization.end},n=Vs(i.startRow,i.endRow,t);for(const o of n)if(!(this.loadedBlocks.has(o)||this.loadingBlocks.has(o))){if(this.loadingBlocks.size>=(this.config.maxConcurrentRequests??2))break;this.loadingBlocks.add(o),Vi(this.dataSource,o,t,{}).then(s=>{this.loadedBlocks.set(o,s.rows),this.totalRowCount=s.totalRowCount,this.loadingBlocks.delete(o),this.requestRender(),this.loadRequiredBlocks()}).catch(()=>{this.loadingBlocks.delete(o)})}}processRows(e){if(!this.dataSource)return[...e];const t=[];for(let i=0;i<this.totalRowCount;i++){const n=Us(i,this.config.cacheBlockSize??100,this.loadedBlocks);t.push(n??{__loading:!0,__index:i})}return t}onScroll(e){this.dataSource&&(this.loadRequiredBlocks(),this.scrollDebounceTimer&&clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=setTimeout(()=>{this.loadRequiredBlocks()},js))}setDataSource(e){this.dataSource=e,this.loadedBlocks.clear(),this.loadingBlocks.clear();const t=this.config.cacheBlockSize??100;Vi(e,0,t,{}).then(i=>{this.loadedBlocks.set(0,i.rows),this.totalRowCount=i.totalRowCount,this.requestRender()})}refresh(){this.dataSource&&(this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.requestRender())}purgeCache(){this.loadedBlocks.clear()}getTotalRowCount(){return this.totalRowCount}isRowLoaded(e){const t=this.config.cacheBlockSize??100,i=Oe(e,t);return this.loadedBlocks.has(i)}getLoadedBlockCount(){return this.loadedBlocks.size}}function Ui(r,e,t){return r.id!==void 0?String(r.id):t?`${t}-${e}`:String(e)}function bt(r,e){const t=new Set(r);return t.has(e)?t.delete(e):t.add(e),t}function vt(r,e,t=null,i=0){const n=e.childrenField??"children",o=new Set;for(let s=0;s<r.length;s++){const l=r[s],a=Ui(l,s,t),c=l[n];if(Array.isArray(c)&&c.length>0){o.add(a);const d=vt(c,e,a,i+1);for(const u of d)o.add(u)}}return o}function Xs(){return new Set}function ji(r,e,t,i=null,n=0){const o=t.childrenField??"children";for(let s=0;s<r.length;s++){const l=r[s],a=Ui(l,s,i);if(a===e)return[a];const c=l[o];if(Array.isArray(c)&&c.length>0){const d=ji(c,e,t,a,n+1);if(d)return[a,...d]}}return null}function Qs(r,e,t,i){const n=ji(r,e,t);if(!n)return i;const o=new Set(i);for(let s=0;s<n.length-1;s++)o.add(n[s]);return o}function Yi(r,e="children"){if(!Array.isArray(r)||r.length===0)return!1;for(const t of r){if(!t)continue;const i=t[e];if(Array.isArray(i)&&i.length>0)return!0}return!1}function Zs(r){if(!Array.isArray(r)||r.length===0)return null;const e=["children","items","nodes","subRows","nested"];for(const t of r)if(!(!t||typeof t!="object"))for(const i of e){const n=t[i];if(Array.isArray(n)&&n.length>0)return i}return null}const Js="@layer tbw-plugins{tbw-grid .cell[data-field=__tbw_expander]{border-inline-end:none!important;padding:0;display:flex;align-items:center;justify-content:flex-start}tbw-grid .header-row .cell[data-field=__tbw_expander]{display:none}tbw-grid .header-row .cell[data-field=__tbw_expander]+.cell{grid-column:1 / 3}tbw-grid .tree-cell-wrapper{display:inline-flex;align-items:center;padding-inline-start:calc(var(--tbw-tree-depth, 0) * var(--tbw-tree-indent-width, var(--tbw-tree-toggle-size, 1.25em)))}tbw-grid .tree-expander{display:flex;align-items:center;justify-content:flex-start;width:100%;height:100%;box-sizing:border-box}tbw-grid .tree-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-tree-toggle-size, 1.25em);height:var(--tbw-tree-toggle-size, 1.25em);flex-shrink:0}tbw-grid .tree-toggle:hover{color:var(--tbw-tree-accent, var(--tbw-color-accent))}tbw-grid .tree-spacer{width:var(--tbw-tree-toggle-size, 1.25em);display:inline-block;flex-shrink:0}tbw-grid .data-grid-row.tbw-tree-slide-in{animation:tbw-tree-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}tbw-grid .data-grid-row.tbw-tree-fade-in{animation:tbw-tree-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-tree-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}@keyframes tbw-tree-fade-in{0%{opacity:0}to{opacity:1}}}";class el extends M{static manifest={events:[{type:"tree-state-change",description:"Emitted when tree expansion state changes (toggle, expand all, collapse all)"}],queries:[{type:"canMoveRow",description:"Returns false for rows with children (parent nodes cannot be reordered)"}]};name="tree";styles=Js;get defaultConfig(){return{childrenField:"children",autoDetect:!0,defaultExpanded:!1,indentWidth:20,showExpandIcons:!0,animation:"slide"}}expandedKeys=new Set;initialExpansionDone=!1;flattenedRows=[];rowKeyMap=new Map;previousVisibleKeys=new Set;keysToAnimate=new Set;sortState=null;detach(){this.expandedKeys.clear(),this.initialExpansionDone=!1,this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.sortState=null}handleQuery(e){if(e.type==="canMoveRow"){const t=e.context,i=this.config.childrenField??"children",n=t?.[i];if(Array.isArray(n)&&n.length>0)return!1}}get animationStyle(){return this.isAnimationEnabled?this.config.animation??"slide":!1}detect(e){if(!this.config.autoDetect)return!1;const t=e,i=this.config.childrenField??Zs(t)??"children";return Yi(t,i)}processRows(e){const t=this.config.childrenField??"children",i=e;if(!Yi(i,t))return this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),[...e];let n=this.withStableKeys(i);this.sortState&&(n=this.sortTree(n,this.sortState.field,this.sortState.direction)),this.config.defaultExpanded&&!this.initialExpansionDone&&(this.expandedKeys=vt(n,this.config),this.initialExpansionDone=!0),this.flattenedRows=this.flattenTree(n,this.expandedKeys),this.rowKeyMap.clear(),this.keysToAnimate.clear();const o=new Set;for(const s of this.flattenedRows)this.rowKeyMap.set(s.key,s),o.add(s.key),!this.previousVisibleKeys.has(s.key)&&s.depth>0&&this.keysToAnimate.add(s.key);return this.previousVisibleKeys=o,this.flattenedRows.map(s=>({...s.data,__treeKey:s.key,__treeDepth:s.depth,__treeHasChildren:s.hasChildren,__treeExpanded:s.isExpanded}))}withStableKeys(e,t=null){const i=this.config.childrenField??"children";return e.map((n,o)=>{const s=n.__stableKey,l=n.id!==void 0?String(n.id):s??(t?`${t}-${o}`:String(o)),a=n[i],c=Array.isArray(a)&&a.length>0;return{...n,__stableKey:l,...c?{[i]:this.withStableKeys(a,l)}:{}}})}flattenTree(e,t,i=0){const n=this.config.childrenField??"children",o=[];for(const s of e){const a=s.__stableKey??String(s.id??"?"),c=s[n],d=Array.isArray(c)&&c.length>0,u=t.has(a);o.push({key:a,data:s,depth:i,hasChildren:d,isExpanded:u,parentKey:i>0&&a.substring(0,a.lastIndexOf("-"))||null}),d&&u&&o.push(...this.flattenTree(c,t,i+1))}return o}sortTree(e,t,i){const n=this.config.childrenField??"children";return[...e].sort((s,l)=>{const a=s[t],c=l[t];return a==null&&c==null?0:a==null?-1:c==null?1:a>c?i:a<c?-i:0}).map(s=>{const l=s[n];return Array.isArray(l)&&l.length>0?{...s,[n]:this.sortTree(l,t,i)}:s})}processColumns(e){if(this.flattenedRows.length===0)return[...e];const t=[...e];if(t.length===0)return t;const i=t[0],n=i.viewRenderer,o=()=>this.config,s=this.setIcon.bind(this),l=this.resolveIcon.bind(this),a=c=>{const{row:d,value:u}=c,{showExpandIcons:h=!0,indentWidth:g}=o(),f=d,p=f.__treeDepth??0,w=document.createElement("span");if(w.className="tree-cell-wrapper",w.style.setProperty("--tbw-tree-depth",String(p)),g!==void 0&&w.style.setProperty("--tbw-tree-indent-width",`${g}px`),h)if(f.__treeHasChildren){const m=document.createElement("span");m.className=`tree-toggle${f.__treeExpanded?" expanded":""}`,s(m,l(f.__treeExpanded?"collapse":"expand")),m.setAttribute("data-tree-key",String(f.__treeKey??"")),w.appendChild(m)}else{const m=document.createElement("span");m.className="tree-spacer",w.appendChild(m)}const y=document.createElement("span");if(y.className="tree-content",n){const m=n(c);m instanceof Node?y.appendChild(m):typeof m=="string"&&(y.innerHTML=m)}else y.textContent=u!=null?String(u):"";return w.appendChild(y),w};return t[0]={...i,viewRenderer:a},t}onCellClick(e){const t=e.originalEvent?.target;if(!t?.classList.contains("tree-toggle"))return!1;const i=t.getAttribute("data-tree-key");if(!i)return!1;const n=this.rowKeyMap.get(i);return n?(this.expandedKeys=bt(this.expandedKeys,i),this.emit("tree-expand",{key:i,row:n.data,expanded:this.expandedKeys.has(i),depth:n.depth}),this.requestRender(),!0):!1}onKeyDown(e){if(e.key!==" ")return;const t=this.grid._focusRow,i=this.flattenedRows[t];if(i?.hasChildren)return e.preventDefault(),this.expandedKeys=bt(this.expandedKeys,i.key),this.emit("tree-expand",{key:i.key,row:i.data,expanded:this.expandedKeys.has(i.key),depth:i.depth}),this.requestRenderWithFocus(),!0}onHeaderClick(e){if(this.flattenedRows.length===0||!e.column.sortable)return!1;const{field:t}=e.column;!this.sortState||this.sortState.field!==t?this.sortState={field:t,direction:1}:this.sortState.direction===1?this.sortState={field:t,direction:-1}:this.sortState=null;const i=this.grid;return i._sortState!==void 0&&(i._sortState=this.sortState?{...this.sortState}:null),this.emit("sort-change",{field:t,direction:this.sortState?.direction??0}),this.requestRender(),!0}afterRender(){const e=this.animationStyle;if(e===!1||this.keysToAnimate.size===0)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const i=e==="fade"?"tbw-tree-fade-in":"tbw-tree-slide-in";for(const n of t.querySelectorAll(".data-grid-row")){const o=n.querySelector(".cell[data-row]"),s=o?parseInt(o.getAttribute("data-row")??"-1",10):-1,l=this.flattenedRows[s]?.key;l&&this.keysToAnimate.has(l)&&(n.classList.add(i),n.addEventListener("animationend",()=>n.classList.remove(i),{once:!0}))}this.keysToAnimate.clear()}expand(e){this.expandedKeys.add(e),this.requestRender()}collapse(e){this.expandedKeys.delete(e),this.requestRender()}toggle(e){this.expandedKeys=bt(this.expandedKeys,e),this.emitPluginEvent("tree-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}expandAll(){this.expandedKeys=vt(this.rows,this.config),this.emitPluginEvent("tree-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}collapseAll(){this.expandedKeys=Xs(),this.emitPluginEvent("tree-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}getExpandedKeys(){return[...this.expandedKeys]}getFlattenedRows(){return[...this.flattenedRows]}getRowByKey(e){return this.rowKeyMap.get(e)?.data}expandToKey(e){this.expandedKeys=Qs(this.rows,e,this.config,this.expandedKeys),this.requestRender()}}function tl(r,e,t){const i=[...r.undoStack,e];for(;i.length>t;)i.shift();return{undoStack:i,redoStack:[]}}function Xi(r){if(r.undoStack.length===0)return{newState:r,action:null};const e=[...r.undoStack],t=e.pop();return t?{newState:{undoStack:e,redoStack:[...r.redoStack,t]},action:t}:{newState:r,action:null}}function Qi(r){if(r.redoStack.length===0)return{newState:r,action:null};const e=[...r.redoStack],t=e.pop();return t?{newState:{undoStack:[...r.undoStack,t],redoStack:e},action:t}:{newState:r,action:null}}function il(r){return r.undoStack.length>0}function nl(r){return r.redoStack.length>0}function rl(){return{undoStack:[],redoStack:[]}}function ol(r,e,t,i){return{type:"cell-edit",rowIndex:r,field:e,oldValue:t,newValue:i,timestamp:Date.now()}}class sl extends M{static dependencies=[{name:"editing",required:!0,reason:"UndoRedoPlugin tracks cell edit history"}];name="undoRedo";get defaultConfig(){return{maxHistorySize:100}}undoStack=[];redoStack=[];attach(e){super.attach(e),this.on("cell-edit-committed",t=>{this.recordEdit(t.rowIndex,t.field,t.oldValue,t.newValue)})}detach(){this.undoStack=[],this.redoStack=[]}onKeyDown(e){const t=(e.ctrlKey||e.metaKey)&&e.key==="z"&&!e.shiftKey,i=(e.ctrlKey||e.metaKey)&&(e.key==="y"||e.key==="z"&&e.shiftKey);if(t){const n=Xi({undoStack:this.undoStack,redoStack:this.redoStack});if(n.action){const o=this.rows;o[n.action.rowIndex]&&(o[n.action.rowIndex][n.action.field]=n.action.oldValue),this.undoStack=n.newState.undoStack,this.redoStack=n.newState.redoStack,this.emit("undo",{action:n.action,type:"undo"}),this.requestRender()}return!0}if(i){const n=Qi({undoStack:this.undoStack,redoStack:this.redoStack});if(n.action){const o=this.rows;o[n.action.rowIndex]&&(o[n.action.rowIndex][n.action.field]=n.action.newValue),this.undoStack=n.newState.undoStack,this.redoStack=n.newState.redoStack,this.emit("redo",{action:n.action,type:"redo"}),this.requestRender()}return!0}return!1}recordEdit(e,t,i,n){const o=ol(e,t,i,n),s=tl({undoStack:this.undoStack,redoStack:this.redoStack},o,this.config.maxHistorySize??100);this.undoStack=s.undoStack,this.redoStack=s.redoStack}undo(){const e=Xi({undoStack:this.undoStack,redoStack:this.redoStack});if(e.action){const t=this.rows;t[e.action.rowIndex]&&(t[e.action.rowIndex][e.action.field]=e.action.oldValue),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.requestRender()}return e.action}redo(){const e=Qi({undoStack:this.undoStack,redoStack:this.redoStack});if(e.action){const t=this.rows;t[e.action.rowIndex]&&(t[e.action.rowIndex][e.action.field]=e.action.newValue),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.requestRender()}return e.action}canUndo(){return il({undoStack:this.undoStack,redoStack:this.redoStack})}canRedo(){return nl({undoStack:this.undoStack,redoStack:this.redoStack})}clearHistory(){const e=rl();this.undoStack=e.undoStack,this.redoStack=e.redoStack}getUndoStack(){return[...this.undoStack]}getRedoStack(){return[...this.redoStack]}}const ll='@layer tbw-plugins{.tbw-visibility-content{display:flex;flex-direction:column;height:100%}.tbw-visibility-list{flex:1;overflow-y:auto;padding:var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem))}.tbw-visibility-row{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding:var(--tbw-menu-item-padding, .375rem .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem);border-radius:var(--tbw-border-radius, .25rem);position:relative}.tbw-visibility-row:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover))}.tbw-visibility-row input[type=checkbox]{cursor:pointer}.tbw-visibility-row.locked span{color:var(--tbw-color-fg-muted)}.tbw-visibility-handle{cursor:grab;color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-2xs, .625rem);letter-spacing:-2px;-webkit-user-select:none;user-select:none;flex-shrink:0}.tbw-visibility-row.reorderable:hover .tbw-visibility-handle{color:var(--tbw-color-fg)}.tbw-visibility-label{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));flex:1;cursor:pointer}.tbw-visibility-row.dragging{opacity:.5;cursor:grabbing}.tbw-visibility-row.drop-before:before{content:"";position:absolute;left:0;right:0;top:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-row.drop-after:after{content:"";position:absolute;left:0;right:0;bottom:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-show-all{margin:var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem));padding:var(--tbw-button-padding, .5rem .75rem);border:1px solid var(--tbw-visibility-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius, .25rem);background:var(--tbw-visibility-btn-bg, var(--tbw-color-header-bg));color:var(--tbw-color-fg);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem)}.tbw-visibility-show-all:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover))}.tbw-visibility-group-header{display:flex;align-items:center;padding:var(--tbw-menu-item-padding, .375rem .25rem);font-size:var(--tbw-font-size-sm, .8125rem);font-weight:600;color:var(--tbw-color-fg);border-bottom:1px solid var(--tbw-color-border);margin-top:var(--tbw-spacing-sm, .25rem);position:relative}.tbw-visibility-group-header:first-child{margin-top:0}.tbw-visibility-group-header .tbw-visibility-label{gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-visibility-group-header.reorderable{cursor:grab}.tbw-visibility-group-header.reorderable:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover))}.tbw-visibility-group-header .tbw-visibility-handle{cursor:grab;color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-2xs, .625rem);letter-spacing:-2px;-webkit-user-select:none;user-select:none;flex-shrink:0}.tbw-visibility-group-header.reorderable:hover .tbw-visibility-handle{color:var(--tbw-color-fg)}.tbw-visibility-group-header.dragging{opacity:.5;cursor:grabbing}.tbw-visibility-group-header.drop-before:before{content:"";position:absolute;left:0;right:0;top:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-group-header.drop-after:after{content:"";position:absolute;left:0;right:0;bottom:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-row--grouped{padding-left:calc(var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem)) + .75rem)}}';function Zi(r){const e=r.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}class ie extends M{static dependencies=[{name:"reorder",required:!1,reason:"Enables drag-to-reorder columns in visibility panel"}];static manifest={queries:[{type:"getContextMenuItems",description:'Contributes "Hide column" item to the header context menu'}]};name="visibility";static PANEL_ID="columns";styles=ll;get defaultConfig(){return{allowHideAll:!1}}columnListElement=null;isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;draggedGroupId=null;draggedGroupFields=[];clearDragClasses(e){e.querySelectorAll(".tbw-visibility-row, .tbw-visibility-group-header").forEach(t=>{t.classList.remove("dragging","drop-target","drop-before","drop-after")})}attach(e){super.attach(e),e.addEventListener("column-move",()=>{this.columnListElement&&requestAnimationFrame(()=>{this.columnListElement&&this.rebuildToggles(this.columnListElement)})},{signal:this.disconnectSignal})}detach(){this.columnListElement=null,this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null}handleQuery(e){if(e.type==="getContextMenuItems"){const t=e.context;if(!t.isHeader)return;const i=t.column;return!i?.field||i.meta?.lockVisibility?void 0:[{id:"visibility/hide-column",label:"Hide Column",icon:"👁",order:30,action:()=>this.hideColumn(i.field)}]}}getToolPanel(){return{id:ie.PANEL_ID,title:"Columns",icon:"☰",tooltip:"Column visibility",order:100,render:e=>this.renderPanelContent(e)}}show(){this.grid.openToolPanel(),this.grid.expandedToolPanelSections.includes(ie.PANEL_ID)||this.grid.toggleToolPanelSection(ie.PANEL_ID)}hide(){this.grid.closeToolPanel()}toggle(){this.grid.isToolPanelOpen||this.grid.openToolPanel(),this.grid.toggleToolPanelSection(ie.PANEL_ID)}isColumnVisible(e){return this.grid.isColumnVisible(e)}setColumnVisible(e,t){this.grid.setColumnVisible(e,t)}getVisibleColumns(){return this.grid.getAllColumns().filter(e=>e.visible).map(e=>e.field)}getHiddenColumns(){return this.grid.getAllColumns().filter(e=>!e.visible).map(e=>e.field)}showAll(){this.grid.showAllColumns()}toggleColumn(e){this.grid.toggleColumnVisibility(e)}showColumn(e){this.setColumnVisible(e,!0)}hideColumn(e){this.setColumnVisible(e,!1)}getAllColumns(){return this.grid.getAllColumns()}isPanelVisible(){return this.grid.isToolPanelOpen&&this.grid.expandedToolPanelSections.includes(ie.PANEL_ID)}renderPanelContent(e){const t=document.createElement("div");t.className="tbw-visibility-content";const i=document.createElement("div");i.className="tbw-visibility-list",t.appendChild(i);const n=document.createElement("button");return n.className="tbw-visibility-show-all",n.textContent="Show All",n.addEventListener("click",()=>{this.grid.showAllColumns(),this.rebuildToggles(i)}),t.appendChild(n),this.columnListElement=i,this.rebuildToggles(i),e.appendChild(t),()=>{this.columnListElement=null,t.remove()}}hasReorderPlugin(){const e=this.grid?.getPluginByName?.("reorder");return!!(e&&typeof e.moveColumn=="function")}rebuildToggles(e){const t=this.hasReorderPlugin();e.innerHTML="";const i=this.grid.getAllColumns().filter(a=>!a.utility),o=this.grid.query("getColumnGrouping")?.flat().filter(a=>a&&a.fields.length>0)??[];if(o.length===0){this.renderFlatColumnList(i,t,e);return}const s=new Map;for(const a of o)for(const c of a.fields)s.set(c,a);const l=new Set;for(const a of i){const c=s.get(a.field);if(c){if(!l.has(c.id)){l.add(c.id);const d=new Set(c.fields),u=i.filter(h=>d.has(h.field));u.length>0&&this.renderGroupSection(c,u,t,e)}}else{const d=i.indexOf(a);e.appendChild(this.createColumnRow(a,d,t,e))}}}renderGroupSection(e,t,i,n){const o=document.createElement("div");o.className="tbw-visibility-group-header",o.setAttribute("data-group-id",e.id),i&&(o.draggable=!0,o.classList.add("reorderable"),this.setupGroupDragListeners(o,e,n));const s=document.createElement("label");s.className="tbw-visibility-label";const l=document.createElement("input");l.type="checkbox";const a=t.filter(h=>h.visible).length,c=t.every(h=>h.lockVisible);a===t.length?(l.checked=!0,l.indeterminate=!1):a===0?(l.checked=!1,l.indeterminate=!1):(l.checked=!1,l.indeterminate=!0),l.disabled=c,l.addEventListener("change",()=>{const h=l.checked;for(const g of t)g.lockVisible||this.grid.setColumnVisible(g.field,h);setTimeout(()=>this.rebuildToggles(n),0)});const d=document.createElement("span");if(d.textContent=e.label,s.appendChild(l),s.appendChild(d),o.appendChild(s),i){const h=document.createElement("span");h.className="tbw-visibility-handle",this.setIcon(h,this.resolveIcon("dragHandle")),h.title="Drag to reorder group",o.insertBefore(h,s)}n.appendChild(o);const u=this.grid.getAllColumns().filter(h=>!h.utility);for(const h of t){const g=u.findIndex(p=>p.field===h.field),f=this.createColumnRow(h,g,i,n);f.classList.add("tbw-visibility-row--grouped"),n.appendChild(f)}}renderFlatColumnList(e,t,i){const n=this.grid.getAllColumns().filter(o=>!o.utility);for(const o of e){const s=n.findIndex(l=>l.field===o.field);i.appendChild(this.createColumnRow(o,s,t,i))}}createColumnRow(e,t,i,n){const o=e.header||e.field,s=document.createElement("div");s.className=e.lockVisible?"tbw-visibility-row locked":"tbw-visibility-row",s.setAttribute("data-field",e.field),s.setAttribute("data-index",String(t)),i&&Zi(e)&&(s.draggable=!0,s.classList.add("reorderable"),this.setupDragListeners(s,e.field,t,n));const l=document.createElement("label");l.className="tbw-visibility-label";const a=document.createElement("input");a.type="checkbox",a.checked=e.visible,a.disabled=e.lockVisible??!1,a.addEventListener("change",()=>{this.grid.toggleColumnVisibility(e.field),setTimeout(()=>this.rebuildToggles(n),0)});const c=document.createElement("span");if(c.textContent=o,l.appendChild(a),l.appendChild(c),i&&Zi(e)){const d=document.createElement("span");d.className="tbw-visibility-handle",this.setIcon(d,this.resolveIcon("dragHandle")),d.title="Drag to reorder",s.appendChild(d)}return s.appendChild(l),s}setupGroupDragListeners(e,t,i){e.addEventListener("dragstart",n=>{this.isDragging=!0,this.draggedGroupId=t.id,this.draggedGroupFields=[...t.fields],this.draggedField=null,this.draggedIndex=null,n.dataTransfer&&(n.dataTransfer.effectAllowed="move",n.dataTransfer.setData("text/plain",`group:${t.id}`)),e.classList.add("dragging"),i.querySelectorAll(".tbw-visibility-row--grouped").forEach(o=>{const s=o.getAttribute("data-field");s&&this.draggedGroupFields.includes(s)&&o.classList.add("dragging")})}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedGroupId=null,this.draggedGroupFields=[],this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.clearDragClasses(i)}),e.addEventListener("dragover",n=>{if(n.preventDefault(),!this.isDragging||this.draggedGroupId===t.id||!this.draggedGroupId)return;const o=e.getBoundingClientRect(),s=o.top+o.height/2,l=n.clientY<s;this.clearDragClasses(i),e.classList.add("drop-target"),e.classList.toggle("drop-before",l),e.classList.toggle("drop-after",!l)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",n=>{if(n.preventDefault(),!this.isDragging||!this.draggedGroupId||this.draggedGroupId===t.id)return;const o=e.getBoundingClientRect(),s=n.clientY<o.top+o.height/2;this.executeGroupDrop(this.draggedGroupFields,t.fields,s,i)})}executeGroupDrop(e,t,i,n){const s=this.grid.getAllColumns().map(h=>h.field),l=s.filter(h=>!e.includes(h)),a=i?t[0]:t[t.length-1],c=l.indexOf(a);if(c===-1)return;const d=i?c:c+1,u=s.filter(h=>e.includes(h));l.splice(d,0,...u),this.grid.setColumnOrder(l),requestAnimationFrame(()=>{this.columnListElement&&this.rebuildToggles(this.columnListElement)})}setupDragListeners(e,t,i,n){e.addEventListener("dragstart",o=>{this.isDragging=!0,this.draggedField=t,this.draggedIndex=i,this.draggedGroupId=null,this.draggedGroupFields=[],o.dataTransfer&&(o.dataTransfer.effectAllowed="move",o.dataTransfer.setData("text/plain",t)),e.classList.add("dragging")}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.clearDragClasses(n)}),e.addEventListener("dragover",o=>{if(o.preventDefault(),!this.isDragging)return;if(this.draggedGroupId){if(e.classList.contains("tbw-visibility-row--grouped"))return}else if(this.draggedField===t)return;const s=e.getBoundingClientRect(),l=s.top+s.height/2;this.dropIndex=o.clientY<l?i:i+1,this.clearDragClasses(n),this.draggedGroupId?(n.querySelector(`.tbw-visibility-group-header[data-group-id="${this.draggedGroupId}"]`)?.classList.add("dragging"),n.querySelectorAll(".tbw-visibility-row--grouped").forEach(a=>{const c=a.getAttribute("data-field");c&&this.draggedGroupFields.includes(c)&&a.classList.add("dragging")})):this.draggedField&&n.querySelector(`.tbw-visibility-row[data-field="${this.draggedField}"]`)?.classList.add("dragging"),e.classList.add("drop-target"),e.classList.toggle("drop-before",o.clientY<l),e.classList.toggle("drop-after",o.clientY>=l)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",o=>{if(o.preventDefault(),!this.isDragging)return;if(this.draggedGroupId&&this.draggedGroupFields.length>0){if(e.classList.contains("tbw-visibility-row--grouped"))return;const d=e.getBoundingClientRect(),u=o.clientY<d.top+d.height/2;this.executeGroupDrop(this.draggedGroupFields,[t],u,n);return}const s=this.draggedField,l=this.draggedIndex,a=this.dropIndex;if(s===null||l===null||a===null)return;const c=a>l?a-1:a;if(c!==l){const d=this.grid.getAllColumns(),h=d.filter(p=>!p.utility)[c]?.field,g=h?d.findIndex(p=>p.field===h):d.length,f={field:s,fromIndex:l,toIndex:g};this.emit("column-reorder-request",f)}})}}S.BLANK_FILTER_VALUE=ve,S.BaseGridPlugin=M,S.ClipboardPlugin=jr,S.ColumnVirtualizationPlugin=Zr,S.ContextMenuPlugin=lt,S.DEFAULT_ANIMATION_CONFIG=yt,S.DEFAULT_GRID_ICONS=W,S.DGEvents=$r,S.DataGridElement=U,S.EditingPlugin=ho,S.ExportPlugin=mo,S.FilteringPlugin=Y,S.FitModeEnum=ne,S.GridCSSVars=qr,S.GridClasses=q,S.GridDataAttrs=me,S.GridElement=U,S.GridSelectors=Nr,S.GroupingColumnsPlugin=Lo,S.GroupingRowsPlugin=No,S.MasterDetailPlugin=ut,S.MultiSortPlugin=Yo,S.PLUGIN_QUERIES=Or,S.PinnedColumnsPlugin=Jo,S.PinnedRowsPlugin=ss,S.PivotPlugin=te,S.PluginEvents=Kr,S.PluginManager=we,S.PrintPlugin=Ts,S.ROW_DRAG_HANDLE_FIELD=$i,S.RenderPhase=F,S.ReorderPlugin=Hs,S.ResponsivePlugin=Ds,S.RowReorderPlugin=zs,S.SelectionPlugin=Ks,S.ServerSidePlugin=Ys,S.TreePlugin=el,S.UndoRedoPlugin=sl,S.VisibilityPlugin=ie,S.builtInSort=Ft,S.createGrid=Gr,S.defaultComparator=zt,S.defaultEditorFor=gi,S.defaultPasteHandler=si,S.getUniqueValuesBatch=vi,S.printGridIsolated=Gi,S.queryGrid=Br,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})}));
|
|
186
|
+
→ The "triggerOn" option only affects "cell" and "row" selection modes.`,check:e=>e.mode==="range"&&e.triggerOn==="dblclick"}]};name="selection";styles=Bs;get defaultConfig(){return{mode:"cell",triggerOn:"click",enabled:!0}}selected=new Set;lastSelected=null;anchor=null;ranges=[];activeRange=null;cellAnchor=null;isDragging=!1;pendingKeyboardUpdate=null;selectedCell=null;lastSyncedFocusRow=-1;lastSyncedFocusCol=-1;explicitSelection=!1;isSelectionEnabled(){return this.config.enabled===!1?!1:this.grid.effectiveConfig?.selectable!==!1}checkSelectable(e,t){const{isSelectable:i}=this.config;if(!i)return!0;const n=this.rows[e];if(!n)return!1;const o=t!==void 0?this.columns[t]:void 0;return i(n,e,o,t)}isRowSelectable(e){return this.checkSelectable(e)}isCellSelectable(e,t){return this.checkSelectable(e,t)}attach(e){super.attach(e),this.on("filter-applied",()=>this.clearSelectionSilent()),this.on("grouping-state-change",()=>this.clearSelectionSilent()),this.on("tree-state-change",()=>this.clearSelectionSilent())}handleQuery(e){if(e.type==="getSelection")return this.getSelection();if(e.type==="getSelectedRowIndices")return this.getSelectedRowIndices();if(e.type==="getSelectedRows")return this.getSelectedRows();if(e.type==="selectRows")return this.selectRows(e.context),!0}detach(){this.selected.clear(),this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.isDragging=!1,this.selectedCell=null,this.pendingKeyboardUpdate=null,this.lastSyncedFocusRow=-1,this.lastSyncedFocusCol=-1}clearSelectionSilent(){this.selected.clear(),this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.selectedCell=null,this.lastSelected=null,this.anchor=null,this.lastSyncedFocusRow=-1,this.lastSyncedFocusCol=-1,this.requestAfterRender()}onCellClick(e){if(!this.isSelectionEnabled())return!1;const{rowIndex:t,colIndex:i,originalEvent:n}=e,{mode:o,triggerOn:s="click"}=this.config;if(n.type!==s)return!1;const l=this.columns[i],a=l&&le(l);if(o==="cell"){if(a||!this.isCellSelectable(t,i))return!1;const c=this.selectedCell;return c&&c.row===t&&c.col===i||(this.selectedCell={row:t,col:i},this.emit("selection-change",this.#r()),this.requestAfterRender()),!1}if(o==="row"){if(!this.isRowSelectable(t))return!1;const c=n.shiftKey,d=n.ctrlKey||n.metaKey,u=l?.meta?.checkboxColumn===!0;if(c&&this.anchor!==null){const h=Math.min(this.anchor,t),g=Math.max(this.anchor,t);d||this.selected.clear();for(let f=h;f<=g;f++)this.isRowSelectable(f)&&this.selected.add(f)}else if(d||u)this.selected.has(t)?this.selected.delete(t):this.selected.add(t),this.anchor=t;else{if(this.selected.size===1&&this.selected.has(t))return!1;this.selected.clear(),this.selected.add(t),this.anchor=t}return this.lastSelected=t,this.explicitSelection=!0,this.emit("selection-change",this.#r()),this.requestAfterRender(),!1}if(o==="range"){if(a||!this.isCellSelectable(t,i))return!1;const c=n.shiftKey,d=n.ctrlKey||n.metaKey;if(c&&this.cellAnchor){const u=mt(this.cellAnchor,{row:t,col:i}),h=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;if(h&&Fe(h,u))return!1;d?this.ranges.length>0?this.ranges[this.ranges.length-1]=u:this.ranges.push(u):this.ranges=[u],this.activeRange=u}else if(d){const u={startRow:t,startCol:i,endRow:t,endCol:i};this.ranges.push(u),this.activeRange=u,this.cellAnchor={row:t,col:i}}else{const u={startRow:t,startCol:i,endRow:t,endCol:i};if(this.ranges.length===1&&Fe(this.ranges[0],u))return!1;this.ranges=[u],this.activeRange=u,this.cellAnchor={row:t,col:i}}return this.emit("selection-change",this.#r()),this.requestAfterRender(),!1}return!1}onKeyDown(e){if(!this.isSelectionEnabled())return!1;const{mode:t}=this.config,n=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Tab","Home","End","PageUp","PageDown"].includes(e.key);if(e.key==="Escape")return this.grid.query("isEditing").some(Boolean)?!1:(t==="cell"?this.selectedCell=null:t==="row"?(this.selected.clear(),this.anchor=null):t==="range"&&(this.ranges=[],this.activeRange=null,this.cellAnchor=null),this.emit("selection-change",this.#r()),this.requestAfterRender(),!0);if(t==="cell"&&n)return queueMicrotask(()=>{const o=this.grid._focusRow,s=this.grid._focusCol;this.isCellSelectable(o,s)?this.selectedCell={row:o,col:s}:this.selectedCell=null,this.emit("selection-change",this.#r()),this.requestAfterRender()}),!1;if(t==="row"){if(e.key==="ArrowUp"||e.key==="ArrowDown"){const o=e.shiftKey;return o&&this.anchor===null&&(this.anchor=this.grid._focusRow),queueMicrotask(()=>{const s=this.grid._focusRow;if(o&&this.anchor!==null){this.selected.clear();const l=Math.min(this.anchor,s),a=Math.max(this.anchor,s);for(let c=l;c<=a;c++)this.isRowSelectable(c)&&this.selected.add(c)}else this.isRowSelectable(s)?(this.selected.clear(),this.selected.add(s),this.anchor=s):this.selected.clear();this.lastSelected=s,this.explicitSelection=!0,this.emit("selection-change",this.#r()),this.requestAfterRender()}),!1}if(e.key==="a"&&(e.ctrlKey||e.metaKey))return this.grid.query("isEditing").some(Boolean)?!1:(e.preventDefault(),e.stopPropagation(),this.selectAll(),!0)}if(t==="range"&&n){const o=e.key==="Tab",s=e.shiftKey&&!o;return s&&!this.cellAnchor&&(this.cellAnchor={row:this.grid._focusRow,col:this.grid._focusCol}),this.pendingKeyboardUpdate={shiftKey:s},queueMicrotask(()=>this.requestAfterRender()),!1}return t==="range"&&e.key==="a"&&(e.ctrlKey||e.metaKey)?this.grid.query("isEditing").some(Boolean)?!1:(e.preventDefault(),e.stopPropagation(),this.selectAll(),!0):!1}onCellMouseDown(e){if(!this.isSelectionEnabled()||this.config.mode!=="range"||e.rowIndex===void 0||e.colIndex===void 0||e.rowIndex<0)return;const t=this.columns[e.colIndex];if(t&&le(t)||!this.isCellSelectable(e.rowIndex,e.colIndex)||e.originalEvent.shiftKey&&this.cellAnchor)return;this.isDragging=!0;const i=e.rowIndex,n=e.colIndex,o=e.originalEvent.ctrlKey||e.originalEvent.metaKey,s={startRow:i,startCol:n,endRow:i,endCol:n};return!o&&this.ranges.length===1&&Fe(this.ranges[0],s)?(this.cellAnchor={row:i,col:n},!0):(this.cellAnchor={row:i,col:n},o||(this.ranges=[]),this.ranges.push(s),this.activeRange=s,this.emit("selection-change",this.#r()),this.requestAfterRender(),!0)}onCellMouseMove(e){if(!this.isSelectionEnabled()||this.config.mode!=="range"||!this.isDragging||!this.cellAnchor||e.rowIndex===void 0||e.colIndex===void 0||e.rowIndex<0)return;let t=e.colIndex;const i=this.columns[t];if(i&&le(i)){const s=this.columns.findIndex(l=>!le(l));s>=0&&(t=s)}const n=mt(this.cellAnchor,{row:e.rowIndex,col:t}),o=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;return o&&Fe(o,n)||(this.ranges.length>0?this.ranges[this.ranges.length-1]=n:this.ranges.push(n),this.activeRange=n,this.emit("selection-change",this.#r()),this.requestAfterRender()),!0}onCellMouseUp(e){if(this.isSelectionEnabled()&&this.config.mode==="range"&&this.isDragging)return this.isDragging=!1,!0}processColumns(e){if(this.config.checkbox&&this.config.mode==="row"){if(e.some(o=>o.field===Wi))return e;const t=this.#t(),i=e.findIndex(Me),n=i>=0?i+1:0;return[...e.slice(0,n),t,...e.slice(n)]}return e}#t(){return{field:Wi,header:"",width:32,resizable:!1,sortable:!1,meta:{lockPosition:!0,suppressMovable:!0,utility:!0,checkboxColumn:!0},headerRenderer:()=>{const e=document.createElement("div");e.className="tbw-checkbox-header";const t=document.createElement("input");return t.type="checkbox",t.className="tbw-select-all-checkbox",t.addEventListener("click",i=>{i.stopPropagation(),i.target.checked?this.selectAll():this.clearSelection()}),e.appendChild(t),e},renderer:e=>{const t=document.createElement("input");t.type="checkbox",t.className="tbw-select-row-checkbox";const i=e.cellEl;if(i){const n=parseInt(i.getAttribute("data-row")??"-1",10);n>=0&&(t.checked=this.selected.has(n))}return t}}}#e(e){e.querySelectorAll(".tbw-select-row-checkbox").forEach(n=>{const o=n.closest(".cell"),s=o?Re(o):-1;s>=0&&(n.checked=this.selected.has(s))});const i=e.querySelector(".tbw-select-all-checkbox");if(i){const n=this.rows.length;let o=0;if(this.config.isSelectable)for(let a=0;a<n;a++)this.isRowSelectable(a)&&o++;else o=n;const s=o>0&&this.selected.size>=o,l=this.selected.size>0;i.checked=s,i.indeterminate=l&&!s}}#u(e){const t=this.grid._focusRow,i=this.grid._focusCol;if(e==="row"){if(this.explicitSelection){this.explicitSelection=!1,this.lastSyncedFocusRow=t;return}t!==this.lastSyncedFocusRow&&(this.lastSyncedFocusRow=t,this.isRowSelectable(t)&&(!this.selected.has(t)||this.selected.size!==1)&&(this.selected.clear(),this.selected.add(t),this.lastSelected=t,this.anchor=t,this.emit("selection-change",this.#r())))}if(e==="cell"){if(this.explicitSelection){this.explicitSelection=!1,this.lastSyncedFocusRow=t,this.lastSyncedFocusCol=i;return}if((t!==this.lastSyncedFocusRow||i!==this.lastSyncedFocusCol)&&(this.lastSyncedFocusRow=t,this.lastSyncedFocusCol=i,this.isCellSelectable(t,i))){const n=this.selectedCell;(!n||n.row!==t||n.col!==i)&&(this.selectedCell={row:t,col:i},this.emit("selection-change",this.#r()))}}}#c(){const e=this.gridElement;if(!e)return;const{mode:t}=this.config,i=!!this.config.isSelectable;e.querySelectorAll(".cell").forEach(s=>{s.classList.remove("selected","top","bottom","first","last"),i&&s.removeAttribute("data-selectable")});const o=e.querySelectorAll(".data-grid-row");if(o.forEach(s=>{s.classList.remove("selected","row-focus"),i&&s.removeAttribute("data-selectable")}),t==="row"&&(he(e),o.forEach(s=>{const l=s.querySelector(".cell[data-row]"),a=Re(l);a>=0&&(i&&!this.isRowSelectable(a)&&s.setAttribute("data-selectable","false"),this.selected.has(a)&&s.classList.add("selected","row-focus"))}),this.config.checkbox&&this.#e(e)),(t==="cell"||t==="range")&&i&&e.querySelectorAll(".cell[data-row][data-col]").forEach(l=>{const a=parseInt(l.getAttribute("data-row")??"-1",10),c=parseInt(l.getAttribute("data-col")??"-1",10);a>=0&&c>=0&&(this.isCellSelectable(a,c)||l.setAttribute("data-selectable","false"))}),t==="range"&&this.ranges.length>0){he(e);const s=this.ranges.map(ae),l=(c,d)=>{for(const u of s)if(c>=u.startRow&&c<=u.endRow&&d>=u.startCol&&d<=u.endCol)return!0;return!1};e.querySelectorAll(".cell[data-row][data-col]").forEach(c=>{const d=parseInt(c.getAttribute("data-row")??"-1",10),u=parseInt(c.getAttribute("data-col")??"-1",10);if(d>=0&&u>=0){const h=this.columns[u];if(h&&le(h))return;l(d,u)&&(c.classList.add("selected"),l(d-1,u)||c.classList.add("top"),l(d+1,u)||c.classList.add("bottom"),l(d,u-1)||c.classList.add("first"),l(d,u+1)||c.classList.add("last"))}})}}afterRender(){if(!this.isSelectionEnabled())return;const e=this.gridElement;if(!e)return;const t=e.children[0],{mode:i}=this.config;if(this.pendingKeyboardUpdate&&i==="range"){const{shiftKey:n}=this.pendingKeyboardUpdate;this.pendingKeyboardUpdate=null;const o=this.grid._focusRow,s=this.grid._focusCol;if(n&&this.cellAnchor){const l=mt(this.cellAnchor,{row:o,col:s});this.ranges=[l],this.activeRange=l}else n||(this.ranges=[],this.activeRange=null,this.cellAnchor={row:o,col:s});this.emit("selection-change",this.#r())}this.#u(i),this.grid.setAttribute("data-selection-mode",i),t&&t.classList.toggle("selecting",this.isDragging),this.#c()}onScrollRender(){this.isSelectionEnabled()&&this.#c()}getSelection(){return{mode:this.config.mode,ranges:this.#r().ranges,anchor:this.cellAnchor}}getSelectedCells(){return Gs(this.ranges)}isCellSelected(e,t){return Ns(e,t,this.ranges)}selectAll(){const{mode:e}=this.config;if(e==="row"){this.selected.clear();for(let t=0;t<this.rows.length;t++)this.isRowSelectable(t)&&this.selected.add(t);this.explicitSelection=!0,this.emit("selection-change",this.#r()),this.requestAfterRender()}else if(e==="range"){const t=this.rows.length,i=this.columns.length;if(t>0&&i>0){const n={startRow:0,startCol:0,endRow:t-1,endCol:i-1};this.ranges=[n],this.activeRange=n,this.emit("selection-change",this.#r()),this.requestAfterRender()}}}selectRows(e){if(this.config.mode==="row"){this.selected.clear();for(const t of e)t>=0&&t<this.rows.length&&this.isRowSelectable(t)&&this.selected.add(t);this.anchor=e.length>0?e[e.length-1]:null,this.explicitSelection=!0,this.emit("selection-change",this.#r()),this.requestAfterRender()}}getSelectedRowIndices(){return[...this.selected].sort((e,t)=>e-t)}getSelectedRows(){const{mode:e}=this.config,t=this.rows;if(e==="row")return this.getSelectedRowIndices().filter(i=>i>=0&&i<t.length).map(i=>t[i]);if(e==="cell"&&this.selectedCell){const{row:i}=this.selectedCell;return i>=0&&i<t.length?[t[i]]:[]}if(e==="range"&&this.ranges.length>0){const i=new Set;for(const n of this.ranges){const o=Math.max(0,Math.min(n.startRow,n.endRow)),s=Math.min(t.length-1,Math.max(n.startRow,n.endRow));for(let l=o;l<=s;l++)i.add(l)}return[...i].sort((n,o)=>n-o).map(n=>t[n])}return[]}clearSelection(){this.selectedCell=null,this.selected.clear(),this.anchor=null,this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.emit("selection-change",{mode:this.config.mode,ranges:[]}),this.requestAfterRender()}setRanges(e){this.ranges=e.map(t=>({startRow:t.from.row,startCol:t.from.col,endRow:t.to.row,endCol:t.to.col})),this.activeRange=this.ranges.length>0?this.ranges[this.ranges.length-1]:null,this.emit("selection-change",{mode:this.config.mode,ranges:Ki(this.ranges)}),this.requestAfterRender()}#r(){return $s(this.config.mode,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges},this.columns.length)}}function Oe(r,e){return Math.floor(r/e)}function Ws(r,e){return{start:r*e,end:(r+1)*e}}function Vs(r,e,t){const i=Oe(r,t),n=Oe(e-1,t),o=[];for(let s=i;s<=n;s++)o.push(s);return o}async function Vi(r,e,t,i){const n=Ws(e,t);return r.getRows({startRow:n.start,endRow:n.end,sortModel:i.sortModel,filterModel:i.filterModel})}function Us(r,e,t){const i=Oe(r,e),n=t.get(i);if(!n)return;const o=r%e;return n[o]}const js=100;class Ys extends M{name="serverSide";get defaultConfig(){return{pageSize:100,cacheBlockSize:100,maxConcurrentRequests:2}}dataSource=null;totalRowCount=0;loadedBlocks=new Map;loadingBlocks=new Set;lastRequestId=0;scrollDebounceTimer;detach(){this.dataSource=null,this.totalRowCount=0,this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.lastRequestId=0,this.scrollDebounceTimer&&(clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=void 0)}loadRequiredBlocks(){if(!this.dataSource)return;const e=this.grid,t=this.config.cacheBlockSize??100,i={startRow:e._virtualization.start,endRow:e._virtualization.end},n=Vs(i.startRow,i.endRow,t);for(const o of n)if(!(this.loadedBlocks.has(o)||this.loadingBlocks.has(o))){if(this.loadingBlocks.size>=(this.config.maxConcurrentRequests??2))break;this.loadingBlocks.add(o),Vi(this.dataSource,o,t,{}).then(s=>{this.loadedBlocks.set(o,s.rows),this.totalRowCount=s.totalRowCount,this.loadingBlocks.delete(o),this.requestRender(),this.loadRequiredBlocks()}).catch(()=>{this.loadingBlocks.delete(o)})}}processRows(e){if(!this.dataSource)return[...e];const t=[];for(let i=0;i<this.totalRowCount;i++){const n=Us(i,this.config.cacheBlockSize??100,this.loadedBlocks);t.push(n??{__loading:!0,__index:i})}return t}onScroll(e){this.dataSource&&(this.loadRequiredBlocks(),this.scrollDebounceTimer&&clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=setTimeout(()=>{this.loadRequiredBlocks()},js))}setDataSource(e){this.dataSource=e,this.loadedBlocks.clear(),this.loadingBlocks.clear();const t=this.config.cacheBlockSize??100;Vi(e,0,t,{}).then(i=>{this.loadedBlocks.set(0,i.rows),this.totalRowCount=i.totalRowCount,this.requestRender()})}refresh(){this.dataSource&&(this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.requestRender())}purgeCache(){this.loadedBlocks.clear()}getTotalRowCount(){return this.totalRowCount}isRowLoaded(e){const t=this.config.cacheBlockSize??100,i=Oe(e,t);return this.loadedBlocks.has(i)}getLoadedBlockCount(){return this.loadedBlocks.size}}function Ui(r,e,t){return r.id!==void 0?String(r.id):t?`${t}-${e}`:String(e)}function bt(r,e){const t=new Set(r);return t.has(e)?t.delete(e):t.add(e),t}function vt(r,e,t=null,i=0){const n=e.childrenField??"children",o=new Set;for(let s=0;s<r.length;s++){const l=r[s],a=Ui(l,s,t),c=l[n];if(Array.isArray(c)&&c.length>0){o.add(a);const d=vt(c,e,a,i+1);for(const u of d)o.add(u)}}return o}function Xs(){return new Set}function ji(r,e,t,i=null,n=0){const o=t.childrenField??"children";for(let s=0;s<r.length;s++){const l=r[s],a=Ui(l,s,i);if(a===e)return[a];const c=l[o];if(Array.isArray(c)&&c.length>0){const d=ji(c,e,t,a,n+1);if(d)return[a,...d]}}return null}function Qs(r,e,t,i){const n=ji(r,e,t);if(!n)return i;const o=new Set(i);for(let s=0;s<n.length-1;s++)o.add(n[s]);return o}function Yi(r,e="children"){if(!Array.isArray(r)||r.length===0)return!1;for(const t of r){if(!t)continue;const i=t[e];if(Array.isArray(i)&&i.length>0)return!0}return!1}function Zs(r){if(!Array.isArray(r)||r.length===0)return null;const e=["children","items","nodes","subRows","nested"];for(const t of r)if(!(!t||typeof t!="object"))for(const i of e){const n=t[i];if(Array.isArray(n)&&n.length>0)return i}return null}const Js="@layer tbw-plugins{tbw-grid .cell[data-field=__tbw_expander]{border-inline-end:none!important;padding:0;display:flex;align-items:center;justify-content:flex-start}tbw-grid .header-row .cell[data-field=__tbw_expander]{display:none}tbw-grid .header-row .cell[data-field=__tbw_expander]+.cell{grid-column:1 / 3}tbw-grid .tree-cell-wrapper{display:inline-flex;align-items:center;padding-inline-start:calc(var(--tbw-tree-depth, 0) * var(--tbw-tree-indent-width, var(--tbw-tree-toggle-size, 1.25em)))}tbw-grid .tree-expander{display:flex;align-items:center;justify-content:flex-start;width:100%;height:100%;box-sizing:border-box}tbw-grid .tree-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-tree-toggle-size, 1.25em);height:var(--tbw-tree-toggle-size, 1.25em);flex-shrink:0}tbw-grid .tree-toggle:hover{color:var(--tbw-tree-accent, var(--tbw-color-accent))}tbw-grid .tree-spacer{width:var(--tbw-tree-toggle-size, 1.25em);display:inline-block;flex-shrink:0}tbw-grid .data-grid-row.tbw-tree-slide-in{animation:tbw-tree-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}tbw-grid .data-grid-row.tbw-tree-fade-in{animation:tbw-tree-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-tree-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}@keyframes tbw-tree-fade-in{0%{opacity:0}to{opacity:1}}}";class el extends M{static manifest={events:[{type:"tree-state-change",description:"Emitted when tree expansion state changes (toggle, expand all, collapse all)"}],queries:[{type:"canMoveRow",description:"Returns false for rows with children (parent nodes cannot be reordered)"}]};name="tree";styles=Js;get defaultConfig(){return{childrenField:"children",autoDetect:!0,defaultExpanded:!1,indentWidth:20,showExpandIcons:!0,animation:"slide"}}expandedKeys=new Set;initialExpansionDone=!1;flattenedRows=[];rowKeyMap=new Map;previousVisibleKeys=new Set;keysToAnimate=new Set;sortState=null;detach(){this.expandedKeys.clear(),this.initialExpansionDone=!1,this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.sortState=null}handleQuery(e){if(e.type==="canMoveRow"){const t=e.context,i=this.config.childrenField??"children",n=t?.[i];if(Array.isArray(n)&&n.length>0)return!1}}get animationStyle(){return this.isAnimationEnabled?this.config.animation??"slide":!1}detect(e){if(!this.config.autoDetect)return!1;const t=e,i=this.config.childrenField??Zs(t)??"children";return Yi(t,i)}processRows(e){const t=this.config.childrenField??"children",i=e;if(!Yi(i,t))return this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),[...e];let n=this.withStableKeys(i);this.sortState&&(n=this.sortTree(n,this.sortState.field,this.sortState.direction)),this.config.defaultExpanded&&!this.initialExpansionDone&&(this.expandedKeys=vt(n,this.config),this.initialExpansionDone=!0),this.flattenedRows=this.flattenTree(n,this.expandedKeys),this.rowKeyMap.clear(),this.keysToAnimate.clear();const o=new Set;for(const s of this.flattenedRows)this.rowKeyMap.set(s.key,s),o.add(s.key),!this.previousVisibleKeys.has(s.key)&&s.depth>0&&this.keysToAnimate.add(s.key);return this.previousVisibleKeys=o,this.flattenedRows.map(s=>({...s.data,__treeKey:s.key,__treeDepth:s.depth,__treeHasChildren:s.hasChildren,__treeExpanded:s.isExpanded}))}withStableKeys(e,t=null){const i=this.config.childrenField??"children";return e.map((n,o)=>{const s=n.__stableKey,l=n.id!==void 0?String(n.id):s??(t?`${t}-${o}`:String(o)),a=n[i],c=Array.isArray(a)&&a.length>0;return{...n,__stableKey:l,...c?{[i]:this.withStableKeys(a,l)}:{}}})}flattenTree(e,t,i=0){const n=this.config.childrenField??"children",o=[];for(const s of e){const a=s.__stableKey??String(s.id??"?"),c=s[n],d=Array.isArray(c)&&c.length>0,u=t.has(a);o.push({key:a,data:s,depth:i,hasChildren:d,isExpanded:u,parentKey:i>0&&a.substring(0,a.lastIndexOf("-"))||null}),d&&u&&o.push(...this.flattenTree(c,t,i+1))}return o}sortTree(e,t,i){const n=this.config.childrenField??"children";return[...e].sort((s,l)=>{const a=s[t],c=l[t];return a==null&&c==null?0:a==null?-1:c==null?1:a>c?i:a<c?-i:0}).map(s=>{const l=s[n];return Array.isArray(l)&&l.length>0?{...s,[n]:this.sortTree(l,t,i)}:s})}processColumns(e){if(this.flattenedRows.length===0)return[...e];const t=[...e];if(t.length===0)return t;const i=t[0],n=i.viewRenderer,o=()=>this.config,s=this.setIcon.bind(this),l=this.resolveIcon.bind(this),a=c=>{const{row:d,value:u}=c,{showExpandIcons:h=!0,indentWidth:g}=o(),f=d,p=f.__treeDepth??0,w=document.createElement("span");if(w.className="tree-cell-wrapper",w.style.setProperty("--tbw-tree-depth",String(p)),g!==void 0&&w.style.setProperty("--tbw-tree-indent-width",`${g}px`),h)if(f.__treeHasChildren){const m=document.createElement("span");m.className=`tree-toggle${f.__treeExpanded?" expanded":""}`,s(m,l(f.__treeExpanded?"collapse":"expand")),m.setAttribute("data-tree-key",String(f.__treeKey??"")),w.appendChild(m)}else{const m=document.createElement("span");m.className="tree-spacer",w.appendChild(m)}const y=document.createElement("span");if(y.className="tree-content",n){const m=n(c);m instanceof Node?y.appendChild(m):typeof m=="string"&&(y.innerHTML=m)}else y.textContent=u!=null?String(u):"";return w.appendChild(y),w};return t[0]={...i,viewRenderer:a},t}onCellClick(e){const t=e.originalEvent?.target;if(!t?.classList.contains("tree-toggle"))return!1;const i=t.getAttribute("data-tree-key");if(!i)return!1;const n=this.rowKeyMap.get(i);return n?(this.expandedKeys=bt(this.expandedKeys,i),this.emit("tree-expand",{key:i,row:n.data,expanded:this.expandedKeys.has(i),depth:n.depth}),this.requestRender(),!0):!1}onKeyDown(e){if(e.key!==" ")return;const t=this.grid._focusRow,i=this.flattenedRows[t];if(i?.hasChildren)return e.preventDefault(),this.expandedKeys=bt(this.expandedKeys,i.key),this.emit("tree-expand",{key:i.key,row:i.data,expanded:this.expandedKeys.has(i.key),depth:i.depth}),this.requestRenderWithFocus(),!0}onHeaderClick(e){if(this.flattenedRows.length===0||!e.column.sortable)return!1;const{field:t}=e.column;!this.sortState||this.sortState.field!==t?this.sortState={field:t,direction:1}:this.sortState.direction===1?this.sortState={field:t,direction:-1}:this.sortState=null;const i=this.grid;return i._sortState!==void 0&&(i._sortState=this.sortState?{...this.sortState}:null),this.emit("sort-change",{field:t,direction:this.sortState?.direction??0}),this.requestRender(),!0}afterRender(){const e=this.animationStyle;if(e===!1||this.keysToAnimate.size===0)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const i=e==="fade"?"tbw-tree-fade-in":"tbw-tree-slide-in";for(const n of t.querySelectorAll(".data-grid-row")){const o=n.querySelector(".cell[data-row]"),s=o?parseInt(o.getAttribute("data-row")??"-1",10):-1,l=this.flattenedRows[s]?.key;l&&this.keysToAnimate.has(l)&&(n.classList.add(i),n.addEventListener("animationend",()=>n.classList.remove(i),{once:!0}))}this.keysToAnimate.clear()}expand(e){this.expandedKeys.add(e),this.requestRender()}collapse(e){this.expandedKeys.delete(e),this.requestRender()}toggle(e){this.expandedKeys=bt(this.expandedKeys,e),this.emitPluginEvent("tree-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}expandAll(){this.expandedKeys=vt(this.rows,this.config),this.emitPluginEvent("tree-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}collapseAll(){this.expandedKeys=Xs(),this.emitPluginEvent("tree-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}getExpandedKeys(){return[...this.expandedKeys]}getFlattenedRows(){return[...this.flattenedRows]}getRowByKey(e){return this.rowKeyMap.get(e)?.data}expandToKey(e){this.expandedKeys=Qs(this.rows,e,this.config,this.expandedKeys),this.requestRender()}}function tl(r,e,t){const i=[...r.undoStack,e];for(;i.length>t;)i.shift();return{undoStack:i,redoStack:[]}}function Xi(r){if(r.undoStack.length===0)return{newState:r,action:null};const e=[...r.undoStack],t=e.pop();return t?{newState:{undoStack:e,redoStack:[...r.redoStack,t]},action:t}:{newState:r,action:null}}function Qi(r){if(r.redoStack.length===0)return{newState:r,action:null};const e=[...r.redoStack],t=e.pop();return t?{newState:{undoStack:[...r.undoStack,t],redoStack:e},action:t}:{newState:r,action:null}}function il(r){return r.undoStack.length>0}function nl(r){return r.redoStack.length>0}function rl(){return{undoStack:[],redoStack:[]}}function ol(r,e,t,i){return{type:"cell-edit",rowIndex:r,field:e,oldValue:t,newValue:i,timestamp:Date.now()}}class sl extends M{static dependencies=[{name:"editing",required:!0,reason:"UndoRedoPlugin tracks cell edit history"}];name="undoRedo";get defaultConfig(){return{maxHistorySize:100}}undoStack=[];redoStack=[];attach(e){super.attach(e),this.on("cell-edit-committed",t=>{this.recordEdit(t.rowIndex,t.field,t.oldValue,t.newValue)})}detach(){this.undoStack=[],this.redoStack=[]}onKeyDown(e){const t=(e.ctrlKey||e.metaKey)&&e.key==="z"&&!e.shiftKey,i=(e.ctrlKey||e.metaKey)&&(e.key==="y"||e.key==="z"&&e.shiftKey);if(t){const n=Xi({undoStack:this.undoStack,redoStack:this.redoStack});if(n.action){const o=this.rows;o[n.action.rowIndex]&&(o[n.action.rowIndex][n.action.field]=n.action.oldValue),this.undoStack=n.newState.undoStack,this.redoStack=n.newState.redoStack,this.emit("undo",{action:n.action,type:"undo"}),this.requestRender()}return!0}if(i){const n=Qi({undoStack:this.undoStack,redoStack:this.redoStack});if(n.action){const o=this.rows;o[n.action.rowIndex]&&(o[n.action.rowIndex][n.action.field]=n.action.newValue),this.undoStack=n.newState.undoStack,this.redoStack=n.newState.redoStack,this.emit("redo",{action:n.action,type:"redo"}),this.requestRender()}return!0}return!1}recordEdit(e,t,i,n){const o=ol(e,t,i,n),s=tl({undoStack:this.undoStack,redoStack:this.redoStack},o,this.config.maxHistorySize??100);this.undoStack=s.undoStack,this.redoStack=s.redoStack}undo(){const e=Xi({undoStack:this.undoStack,redoStack:this.redoStack});if(e.action){const t=this.rows;t[e.action.rowIndex]&&(t[e.action.rowIndex][e.action.field]=e.action.oldValue),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.requestRender()}return e.action}redo(){const e=Qi({undoStack:this.undoStack,redoStack:this.redoStack});if(e.action){const t=this.rows;t[e.action.rowIndex]&&(t[e.action.rowIndex][e.action.field]=e.action.newValue),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.requestRender()}return e.action}canUndo(){return il({undoStack:this.undoStack,redoStack:this.redoStack})}canRedo(){return nl({undoStack:this.undoStack,redoStack:this.redoStack})}clearHistory(){const e=rl();this.undoStack=e.undoStack,this.redoStack=e.redoStack}getUndoStack(){return[...this.undoStack]}getRedoStack(){return[...this.redoStack]}}const ll='@layer tbw-plugins{.tbw-visibility-content{display:flex;flex-direction:column;height:100%}.tbw-visibility-list{flex:1;overflow-y:auto;padding:var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem))}.tbw-visibility-row{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding:var(--tbw-menu-item-padding, .375rem .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem);border-radius:var(--tbw-border-radius, .25rem);position:relative}.tbw-visibility-row:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover))}.tbw-visibility-row input[type=checkbox]{cursor:pointer}.tbw-visibility-row.locked span{color:var(--tbw-color-fg-muted)}.tbw-visibility-handle{cursor:grab;color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-2xs, .625rem);letter-spacing:-2px;-webkit-user-select:none;user-select:none;flex-shrink:0}.tbw-visibility-row.reorderable:hover .tbw-visibility-handle{color:var(--tbw-color-fg)}.tbw-visibility-label{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));flex:1;cursor:pointer}.tbw-visibility-row.dragging{opacity:.5;cursor:grabbing}.tbw-visibility-row.drop-before:before{content:"";position:absolute;left:0;right:0;top:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-row.drop-after:after{content:"";position:absolute;left:0;right:0;bottom:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-show-all{margin:var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem));padding:var(--tbw-button-padding, .5rem .75rem);border:1px solid var(--tbw-visibility-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius, .25rem);background:var(--tbw-visibility-btn-bg, var(--tbw-color-header-bg));color:var(--tbw-color-fg);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem)}.tbw-visibility-show-all:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover))}.tbw-visibility-group-header{display:flex;align-items:center;padding:var(--tbw-menu-item-padding, .375rem .25rem);font-size:var(--tbw-font-size-sm, .8125rem);font-weight:600;color:var(--tbw-color-fg);border-bottom:1px solid var(--tbw-color-border);margin-top:var(--tbw-spacing-sm, .25rem);position:relative}.tbw-visibility-group-header:first-child{margin-top:0}.tbw-visibility-group-header .tbw-visibility-label{gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-visibility-group-header.reorderable{cursor:grab}.tbw-visibility-group-header.reorderable:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover))}.tbw-visibility-group-header .tbw-visibility-handle{cursor:grab;color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-2xs, .625rem);letter-spacing:-2px;-webkit-user-select:none;user-select:none;flex-shrink:0}.tbw-visibility-group-header.reorderable:hover .tbw-visibility-handle{color:var(--tbw-color-fg)}.tbw-visibility-group-header.dragging{opacity:.5;cursor:grabbing}.tbw-visibility-group-header.drop-before:before{content:"";position:absolute;left:0;right:0;top:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-group-header.drop-after:after{content:"";position:absolute;left:0;right:0;bottom:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-row--grouped{padding-left:calc(var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem)) + .75rem)}}';function Zi(r){const e=r.meta??{};return e.lockPosition!==!0&&e.suppressMovable!==!0}class ie extends M{static dependencies=[{name:"reorder",required:!1,reason:"Enables drag-to-reorder columns in visibility panel"}];static manifest={queries:[{type:"getContextMenuItems",description:'Contributes "Hide column" item to the header context menu'}]};name="visibility";static PANEL_ID="columns";styles=ll;get defaultConfig(){return{allowHideAll:!1}}columnListElement=null;isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;draggedGroupId=null;draggedGroupFields=[];clearDragClasses(e){e.querySelectorAll(".tbw-visibility-row, .tbw-visibility-group-header").forEach(t=>{t.classList.remove("dragging","drop-target","drop-before","drop-after")})}attach(e){super.attach(e),e.addEventListener("column-move",()=>{this.columnListElement&&requestAnimationFrame(()=>{this.columnListElement&&this.rebuildToggles(this.columnListElement)})},{signal:this.disconnectSignal})}detach(){this.columnListElement=null,this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null}handleQuery(e){if(e.type==="getContextMenuItems"){const t=e.context;if(!t.isHeader)return;const i=t.column;return!i?.field||i.meta?.lockVisibility?void 0:[{id:"visibility/hide-column",label:"Hide Column",icon:"👁",order:30,action:()=>this.hideColumn(i.field)}]}}getToolPanel(){return{id:ie.PANEL_ID,title:"Columns",icon:"☰",tooltip:"Column visibility",order:100,render:e=>this.renderPanelContent(e)}}show(){this.grid.openToolPanel(),this.grid.expandedToolPanelSections.includes(ie.PANEL_ID)||this.grid.toggleToolPanelSection(ie.PANEL_ID)}hide(){this.grid.closeToolPanel()}toggle(){this.grid.isToolPanelOpen||this.grid.openToolPanel(),this.grid.toggleToolPanelSection(ie.PANEL_ID)}isColumnVisible(e){return this.grid.isColumnVisible(e)}setColumnVisible(e,t){this.grid.setColumnVisible(e,t)}getVisibleColumns(){return this.grid.getAllColumns().filter(e=>e.visible).map(e=>e.field)}getHiddenColumns(){return this.grid.getAllColumns().filter(e=>!e.visible).map(e=>e.field)}showAll(){this.grid.showAllColumns()}toggleColumn(e){this.grid.toggleColumnVisibility(e)}showColumn(e){this.setColumnVisible(e,!0)}hideColumn(e){this.setColumnVisible(e,!1)}getAllColumns(){return this.grid.getAllColumns()}isPanelVisible(){return this.grid.isToolPanelOpen&&this.grid.expandedToolPanelSections.includes(ie.PANEL_ID)}renderPanelContent(e){const t=document.createElement("div");t.className="tbw-visibility-content";const i=document.createElement("div");i.className="tbw-visibility-list",t.appendChild(i);const n=document.createElement("button");return n.className="tbw-visibility-show-all",n.textContent="Show All",n.addEventListener("click",()=>{this.grid.showAllColumns(),this.rebuildToggles(i)}),t.appendChild(n),this.columnListElement=i,this.rebuildToggles(i),e.appendChild(t),()=>{this.columnListElement=null,t.remove()}}hasReorderPlugin(){const e=this.grid?.getPluginByName?.("reorder");return!!(e&&typeof e.moveColumn=="function")}rebuildToggles(e){const t=this.hasReorderPlugin();e.innerHTML="";const i=this.grid.getAllColumns().filter(a=>!a.utility),o=this.grid.query("getColumnGrouping")?.flat().filter(a=>a&&a.fields.length>0)??[];if(o.length===0){this.renderFlatColumnList(i,t,e);return}const s=new Map;for(const a of o)for(const c of a.fields)s.set(c,a);const l=new Set;for(const a of i){const c=s.get(a.field);if(c){if(!l.has(c.id)){l.add(c.id);const d=new Set(c.fields),u=i.filter(h=>d.has(h.field));u.length>0&&this.renderGroupSection(c,u,t,e)}}else{const d=i.indexOf(a);e.appendChild(this.createColumnRow(a,d,t,e))}}}renderGroupSection(e,t,i,n){const o=document.createElement("div");o.className="tbw-visibility-group-header",o.setAttribute("data-group-id",e.id),i&&(o.draggable=!0,o.classList.add("reorderable"),this.setupGroupDragListeners(o,e,n));const s=document.createElement("label");s.className="tbw-visibility-label";const l=document.createElement("input");l.type="checkbox";const a=t.filter(h=>h.visible).length,c=t.every(h=>h.lockVisible);a===t.length?(l.checked=!0,l.indeterminate=!1):a===0?(l.checked=!1,l.indeterminate=!1):(l.checked=!1,l.indeterminate=!0),l.disabled=c,l.addEventListener("change",()=>{const h=l.checked;for(const g of t)g.lockVisible||this.grid.setColumnVisible(g.field,h);setTimeout(()=>this.rebuildToggles(n),0)});const d=document.createElement("span");if(d.textContent=e.label,s.appendChild(l),s.appendChild(d),o.appendChild(s),i){const h=document.createElement("span");h.className="tbw-visibility-handle",this.setIcon(h,this.resolveIcon("dragHandle")),h.title="Drag to reorder group",o.insertBefore(h,s)}n.appendChild(o);const u=this.grid.getAllColumns().filter(h=>!h.utility);for(const h of t){const g=u.findIndex(p=>p.field===h.field),f=this.createColumnRow(h,g,i,n);f.classList.add("tbw-visibility-row--grouped"),n.appendChild(f)}}renderFlatColumnList(e,t,i){const n=this.grid.getAllColumns().filter(o=>!o.utility);for(const o of e){const s=n.findIndex(l=>l.field===o.field);i.appendChild(this.createColumnRow(o,s,t,i))}}createColumnRow(e,t,i,n){const o=e.header||e.field,s=document.createElement("div");s.className=e.lockVisible?"tbw-visibility-row locked":"tbw-visibility-row",s.setAttribute("data-field",e.field),s.setAttribute("data-index",String(t)),i&&Zi(e)&&(s.draggable=!0,s.classList.add("reorderable"),this.setupDragListeners(s,e.field,t,n));const l=document.createElement("label");l.className="tbw-visibility-label";const a=document.createElement("input");a.type="checkbox",a.checked=e.visible,a.disabled=e.lockVisible??!1,a.addEventListener("change",()=>{this.grid.toggleColumnVisibility(e.field),setTimeout(()=>this.rebuildToggles(n),0)});const c=document.createElement("span");if(c.textContent=o,l.appendChild(a),l.appendChild(c),i&&Zi(e)){const d=document.createElement("span");d.className="tbw-visibility-handle",this.setIcon(d,this.resolveIcon("dragHandle")),d.title="Drag to reorder",s.appendChild(d)}return s.appendChild(l),s}setupGroupDragListeners(e,t,i){e.addEventListener("dragstart",n=>{this.isDragging=!0,this.draggedGroupId=t.id,this.draggedGroupFields=[...t.fields],this.draggedField=null,this.draggedIndex=null,n.dataTransfer&&(n.dataTransfer.effectAllowed="move",n.dataTransfer.setData("text/plain",`group:${t.id}`)),e.classList.add("dragging"),i.querySelectorAll(".tbw-visibility-row--grouped").forEach(o=>{const s=o.getAttribute("data-field");s&&this.draggedGroupFields.includes(s)&&o.classList.add("dragging")})}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedGroupId=null,this.draggedGroupFields=[],this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.clearDragClasses(i)}),e.addEventListener("dragover",n=>{if(n.preventDefault(),!this.isDragging||this.draggedGroupId===t.id||!this.draggedGroupId)return;const o=e.getBoundingClientRect(),s=o.top+o.height/2,l=n.clientY<s;this.clearDragClasses(i),e.classList.add("drop-target"),e.classList.toggle("drop-before",l),e.classList.toggle("drop-after",!l)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",n=>{if(n.preventDefault(),!this.isDragging||!this.draggedGroupId||this.draggedGroupId===t.id)return;const o=e.getBoundingClientRect(),s=n.clientY<o.top+o.height/2;this.executeGroupDrop(this.draggedGroupFields,t.fields,s,i)})}executeGroupDrop(e,t,i,n){const s=this.grid.getAllColumns().map(h=>h.field),l=s.filter(h=>!e.includes(h)),a=i?t[0]:t[t.length-1],c=l.indexOf(a);if(c===-1)return;const d=i?c:c+1,u=s.filter(h=>e.includes(h));l.splice(d,0,...u),this.grid.setColumnOrder(l),requestAnimationFrame(()=>{this.columnListElement&&this.rebuildToggles(this.columnListElement)})}setupDragListeners(e,t,i,n){e.addEventListener("dragstart",o=>{this.isDragging=!0,this.draggedField=t,this.draggedIndex=i,this.draggedGroupId=null,this.draggedGroupFields=[],o.dataTransfer&&(o.dataTransfer.effectAllowed="move",o.dataTransfer.setData("text/plain",t)),e.classList.add("dragging")}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.clearDragClasses(n)}),e.addEventListener("dragover",o=>{if(o.preventDefault(),!this.isDragging)return;if(this.draggedGroupId){if(e.classList.contains("tbw-visibility-row--grouped"))return}else if(this.draggedField===t)return;const s=e.getBoundingClientRect(),l=s.top+s.height/2;this.dropIndex=o.clientY<l?i:i+1,this.clearDragClasses(n),this.draggedGroupId?(n.querySelector(`.tbw-visibility-group-header[data-group-id="${this.draggedGroupId}"]`)?.classList.add("dragging"),n.querySelectorAll(".tbw-visibility-row--grouped").forEach(a=>{const c=a.getAttribute("data-field");c&&this.draggedGroupFields.includes(c)&&a.classList.add("dragging")})):this.draggedField&&n.querySelector(`.tbw-visibility-row[data-field="${this.draggedField}"]`)?.classList.add("dragging"),e.classList.add("drop-target"),e.classList.toggle("drop-before",o.clientY<l),e.classList.toggle("drop-after",o.clientY>=l)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",o=>{if(o.preventDefault(),!this.isDragging)return;if(this.draggedGroupId&&this.draggedGroupFields.length>0){if(e.classList.contains("tbw-visibility-row--grouped"))return;const d=e.getBoundingClientRect(),u=o.clientY<d.top+d.height/2;this.executeGroupDrop(this.draggedGroupFields,[t],u,n);return}const s=this.draggedField,l=this.draggedIndex,a=this.dropIndex;if(s===null||l===null||a===null)return;const c=a>l?a-1:a;if(c!==l){const d=this.grid.getAllColumns(),h=d.filter(p=>!p.utility)[c]?.field,g=h?d.findIndex(p=>p.field===h):d.length,f={field:s,fromIndex:l,toIndex:g};this.emit("column-reorder-request",f)}})}}S.BLANK_FILTER_VALUE=ve,S.BaseGridPlugin=M,S.ClipboardPlugin=jr,S.ColumnVirtualizationPlugin=Zr,S.ContextMenuPlugin=lt,S.DEFAULT_ANIMATION_CONFIG=yt,S.DEFAULT_GRID_ICONS=W,S.DGEvents=$r,S.DataGridElement=U,S.EditingPlugin=ho,S.ExportPlugin=mo,S.FilteringPlugin=Y,S.FitModeEnum=ne,S.GridCSSVars=qr,S.GridClasses=q,S.GridDataAttrs=me,S.GridElement=U,S.GridSelectors=Nr,S.GroupingColumnsPlugin=Lo,S.GroupingRowsPlugin=No,S.MasterDetailPlugin=ut,S.MultiSortPlugin=Yo,S.PLUGIN_QUERIES=Or,S.PinnedColumnsPlugin=Jo,S.PinnedRowsPlugin=ss,S.PivotPlugin=te,S.PluginEvents=Kr,S.PluginManager=we,S.PrintPlugin=Ts,S.ROW_DRAG_HANDLE_FIELD=$i,S.RenderPhase=F,S.ReorderPlugin=Hs,S.ResponsivePlugin=Ds,S.RowReorderPlugin=zs,S.SelectionPlugin=Ks,S.ServerSidePlugin=Ys,S.TreePlugin=el,S.UndoRedoPlugin=sl,S.VisibilityPlugin=ie,S.builtInSort=Ft,S.createGrid=Gr,S.defaultComparator=zt,S.defaultEditorFor=gi,S.defaultPasteHandler=si,S.getUniqueValuesBatch=vi,S.printGridIsolated=Gi,S.queryGrid=Br,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})}));
|
|
187
187
|
//# sourceMappingURL=grid.all.umd.js.map
|