(()=>{var G=0,R=class{constructor(t){this.grid=t,this.columns=[],this.column=null,this.columnIndex=0,this.leftIndex=0,this.rightIndex=0,this.indices=[],this.refresh=null,this.createCell=(e,o)=>{if(this.column=this.columns[this.columnIndex=o],e.row.id==="header")if(this.column.id==="header"){let i=t.createStub();return t.updateStub(i,this),i}else{let i=t.createColumnHeader();return t.updateColumnHeader(i,this),i}else if(this.column.id==="header"){let i=t.createRowHeader();return t.updateRowHeader(i,this,e),i}else{let i=t.createGridCell();return t.updateGridCell(i,this,e),i}},this.updateCell=(e,o,i)=>(this.column=this.columns[this.columnIndex=i],e.row.id==="header"?this.column.id==="header"?(t.updateStub(o,this),o):(t.updateColumnHeader(o,this),o):this.column.id==="header"?(t.updateRowHeader(o,this,e),o):(t.updateGridCell(o,this,e),o))}render(t,e){let{indices:o}=this,i=t.firstChild,r=0;for(;i&&r0?c.push(d.pop()):s.push(p);this.columns=t,this.leftIndex=i,this.rightIndex=r,this.indices=[...c,...d],c.length||d.length?this.update=(p,f)=>{let{childNodes:x}=p,a=s.length;for(;a>0;)x[s[--a]].remove();for(a=0;athis.rightIndex||o>this.leftIndex)&&(r=Math.max(this.rightIndex,o),l=i,d=this.leftIndex,c=Math.min(this.rightIndex,o)),this.leftIndex=o,this.rightIndex=i,r!==void 0){let s=this.indices,h=[],p=[],f=[],x=0,a=r;for(let u=0;u=d?a{let m=u.childNodes,g=h.length;for(;g>0;)u.removeChild(m[h[--g]]);for(g=0;g0&&(i=Math.max(i,Y(t,e)-G),r=Math.min(r,1+Y(t,e+o)+G)),{leftIndex:i,rightIndex:r}}};function Y(n,t){let e,o,i=0,r=n.length-1;for(;i>1;let{left:l,width:d}=n[e];if(o=t-l,o>=d)i=e+1;else if(o<0)r=e-1;else return e}return i}function M(n=[]){let t=0;for(let e,o=0;o{if(this.row=this.rows[this.rowIndex=o],this.row.id==="header"){let i=t.createHeaderRow(this);return t.updateHeaderRow(i,this),e.render(i,this),i}else{let i=t.createGridRow(this);return t.updateGridRow(i,this),e.render(i,this),i}},this.updateRow=(e,o,i)=>(this.row=this.rows[this.rowIndex=i],this.row.id==="header"?(t.updateHeaderRow(o,this),e.render(o,this),o):(t.updateGridRow(o,this),e.render(o,this),o))}render(t,e){let{indices:o}=this,i=t.firstChild.nextSibling,r=0;for(;i&&r0?c.push(d.pop()):s.push(p);this.rows=t,this.topIndex=i,this.bottomIndex=r,this.indices=[...c,...d],this.update=(p,f)=>{let{childNodes:x}=p,a=s.length;for(;a>0;)x[1+s[--a]].remove();for(a=0;athis.bottomIndex||o>this.topIndex)&&(r=Math.max(o,this.bottomIndex),l=i,d=this.topIndex,c=Math.min(o,this.bottomIndex)),this.topIndex=o,this.bottomIndex=i,r!==void 0){let s=this.indices,h=[],p=[],f=[],x=[],a=0,u=r;for(let w=0;w=d?u{let{childNodes:g}=w,b=h.length;for(;b>0;)g[1+h[--b]].remove();for(b=0;b0&&(i=Math.max(i,X(t,e)-V),r=Math.min(r,1+X(t,e+o)+V)),{topIndex:i,bottomIndex:r}}refresh(t,e){if(e.refresh){let{childNodes:o}=t;for(let i=0;i>1;let{top:l,height:d}=n[e];if(o=t-l,o>=d)i=e+1;else if(o<0)r=e-1;else return e}return i}function E(n=[]){let t=0;for(let e,o=0;o .item { padding: var(--padding); border: 2px solid transparent; margin: -2px; } .menu > .separator { padding-top: var(--padding); padding-bottom: var(--padding); } .menu > .separator > .line { border-top: 1px solid var(--border-color); } .menu > .item:hover { background-color: rgb(100, 149, 237, 0.33); border: 2px solid cornflowerblue; } #highlight { position: absolute; opacity: .66; left: 0; top: 0; border: 2px solid gold; z-index: 10 !important; pointer-events: none; transition: opacity 160ms ease-in-out, transform 160ms ease-out, width 160ms ease-out, height 160ms ease-out; background-color: rgba(255, 215, 0, 0.33); } /* ============================================================================================================== */ /* Drag 'n Drop */ /* ============================================================================================================== */ .header.cell * { user-select: none; } .cell.detached { opacity: 0.333; z-index: 100 !important; transition: left 160ms ease-in-out, opacity 160ms ease-in-out; } .row.detached { opacity: 0.333; z-index: 100 !important; transition: transform 160ms ease-in-out, opacity 160ms ease-in-out; } .drag-n-drop .header.cell { cursor: grab; } .drag-n-drop .header.cell * { pointer-events: none !important; } .drag-n-drop .row > * { cursor: no-drop; } .ghost { cursor: grab; position: fixed; z-index: 10000; box-shadow: 3px 6px 12px rgba(0, 0, 0, .1), -3px 6px 12px rgba(0, 0, 0, .5); background: var(--background-color); opacity: 0; transition: opacity 0.25s ease-in-out; pointer-events: none; overflow: hidden; } .ghost.cancel { opacity: 0.33; box-shadow: 0px 0px 0px 2px crimson, 3px 6px 12px rgba(0, 0, 0, .5), -3px 6px 12px rgba(0, 0, 0, .25); } .ghost.column { display: flex; flex-direction: column; align-items: stretch; } .ghost.column > :first-child { box-shadow: 1px 2px 3px var(--shadow-color); z-index: 10; } .ghost.row { display: flex; flex-direction: row; align-items: stretch; } .ghost.row > :first-child { box-shadow: 2px 1px 3px var(--shadow-color); z-index: 10; } .ghost > * { position: relative; } .ghost .cell.even { background-color: var(--even-rows-background); } .ghost .cell.odd { background-color: var(--odd-rows-background); } #drop-highlight { pointer-events: none; position: fixed; box-shadow: 0px 0px 0px 2px cornflowerblue; background-color: rgba(100, 149, 237, 0.25); transition: transform 0.125s ease-in-out; z-index: 1000; } ${/Windows/.test(navigator.userAgent)&&/Chrome/.test(navigator.userAgent)?` /* Let's get this party started */ ::-webkit-scrollbar { width: 8px; height: 8px; } /* Track */ ::-webkit-scrollbar-track { box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.25); margin-top: 32px; margin-left: 50px; } /* Handle */ ::-webkit-scrollbar-thumb { background: cornflowerblue; box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.25); } ::-webkit-scrollbar-thumb:window-inactive { background: rgba(100, 149, 237, 0.25); } `:""} `);var O=new CSSStyleSheet;O.replaceSync(` :host { display: block; overflow: visible; height: 100%; } :host(.busy) *, :host(.busy) *::after { cursor: progress !important; } * { box-sizing: border-box; } #root { position: relative; width: 100%; height: 100%; overflow: hidden; } #view-port { position: absolute; overflow: auto; width: 100%; height: 100%; --top-area-height: 0px; --right-area-width: 0px; --bottom-area-height: 0px; --left-area-width: 0px; --center-area-width: 100%; --center-area-height: 100%; } #sizer { position: fixed; visibility: hidden; width: 100%; height: 100%; z-index: -1000; } .area { visibility: hidden; position: absolute; overflow: auto; width: calc(var(--center-area-width) + var(--right-area-width)); height: var(--center-area-height); contain: layout; } .area.visible { visibility: visible; } .top-area { top: 0; height: var(--top-area-height); } .right-area { left: calc(100% - var(--right-area-width)); width: var(--right-area-width); } .bottom-area { bottom: 0; height: var(--bottom-area-height); margin-bottom: calc(-1 * var(--bottom-area-height)); } .left-area { left: 0; width: var(--left-area-width); } .top-area, .bottom-area { position: sticky; overflow-y: hidden; } .left-area, .right-area { position: sticky; overflow-x: hidden; } #top-left-area { z-index: 100; } #top-area { z-index: 50; margin-top: calc(-1 * var(--top-area-height)); margin-left: var(--left-area-width); min-width: calc(100% - var(--left-area-width)); } #top-right-area { z-index: 100; margin-top: calc(-1 * var(--top-area-height)); } #left-area { z-index: 50; } #center-area { z-index: 0; margin-top: var(--top-area-height); margin-left: var(--left-area-width); min-width: calc(100% - var(--left-area-width)); } #right-area { z-index: 50; margin-top: var(--top-area-height); } #bottom-left-area { z-index: 100; } #bottom-area { z-index: 50; margin-left: var(--left-area-width); min-width: calc(100% - var(--left-area-width)); } #bottom-right-area { z-index: 100; } :host([row-header="left"]) #center-area, :host([row-header="left"]) #right-area { margin-top: calc(-1 * var(--center-area-height)); } /* TODO: What follows has to be tidied up */ .area-shadow { display: none; } .area-shadow.top, .area-shadow.bottom { top: 100%; left: 0; width: 100%; height: 3px; } .area-shadow.left, .area-shadow.right { top: 0; left: 100%; width: 3px; height: 100%; } .row { position: absolute; width: 100%; white-space: nowrap; outline: none; contain: strict; } .row.header { contain: layout; } .cell { position: absolute; display: block; width: 100%; height: 100%; -webkit-user-select: none; user-select: none; } .handle { position: relative; z-index: 100; float: right; } .handle::after { position: absolute; z-index: 200; content: ""; background-color: transparent; } .width-handle { left: 1px; width: 1px; height: 100%; margin-left: 2px; } .width-handle:hover, .width-handle.active { left: 2px; width: 3px; margin-left: 0; } .width-handle::after { top: 0; bottom: 0; width: 9px; margin-left: -4px; cursor: ew-resize; } .height-handle { top: 0; left: 0; width: 100%; height: 1px; } .height-handle:hover, .height-handle.active { top: -1px; height: 3px; } .height-handle::after { right: 0; left: 0; height: 9px; margin-top: -4px; cursor: ns-resize; } `);"use strict";var U=Object.assign;typeof U!="function"&&(U=function(){var n=arguments,t=arguments[0];if(t==null)throw new TypeError("Cannot convert undefined or null to object");t=Object(t);for(var e=1;e=0&&(e=0)}function dt(n,t){t||(t={});var e=t.vargs||ct(n),o=Object.create(null),i=[],r=[],l=new WeakMap,d=function(a,u,w){return setTimeout(function(){if(w){u.splice(a,1),w.splice(a,1);return}u instanceof WeakMap?u.delete(a):delete u[a]},t.maxAge)},c=t.maxAge>0&&t.maxAge=0;u--)if(!(!h&&i[u].length!==a)){for(var w=a-1;w>=0&&s(i[u][w],arguments[w]);w--)if(w===0)return r[u]}return u=i.length-(u+1),!c||c(u,r,i),r[u]=n.apply(this,i[u]=arguments)}.bind(this),f.clear=function(){l=new WeakMap,o=Object.create(null),i=[],r=[]},f.keys=function(){return x?null:i.slice()},f.values=function(){return x?null:r.slice()},f.keyValues=function(){return x?{primitives:U({},o),objects:l}:null},f}var A=dt;function C(n,t){let e=document.createElement("template");e.innerHTML=n.replace(/\s+{let e=[],o=t.reduce((i,{field:r,search:l},d)=>{if(l){let c=new RegExp("^"+ut(l).replace(/\\\*/g,".*"),"i");e.push(c);let s=JSON.stringify(r);return i+` && this[${e.length-1}].test(row[${s}]) // [${d}] ${s} ${c}`}else return i},`row.id = id; return true`)+` `+n.sourceURL("filter");if(e.length>0)return new Function("row","id",o).bind(e)}),_=A((n,t)=>t.filter(n)),J=A((n,t)=>{let e=n.find(o=>o.sort);if(e){let o=e.sort==="asc"?1:-1,i=e.field;return[...t].sort(function(r,l){let d=r[i],c=l[i];return d===c?0:d{n(this.parentElement,o),o.classList.remove("busy"),this.classList.remove("active")}))}}function k(n){return function(e){e.preventDefault(),e.stopPropagation();let o=this.getRootNode().host;this.classList.add("active");let i=n.call(this,e,this.closest(".cell"),o);i.pending=0,document.body.addEventListener("pointermove",l),document.body.addEventListener("pointerup",l);let r=()=>{this.classList.contains("active")&&(this.classList.remove("active"),document.body.removeEventListener("pointermove",l),document.body.removeEventListener("pointerup",l),i.onEnd())};function l(d){d.preventDefault(),d.stopPropagation(),d.buttons!==1&&(requestAnimationFrame(function(){i.onEnd(d),r()}),i.pending++),i.pending===0&&(requestAnimationFrame(function(){i.onMove(d,r),i.pending--}),i.pending++)}}}function Z(n,t){let e=t.appendChild(n.createGridCell({column:{},columnIndex:0},{row:{},rowIndex:0}));e.style.cssText="width:auto;height:auto;";let o=e.querySelector(".cell-text");return o.innerHTML="",function(i,r){return n.renderCell(o,i,r),e}}function tt(n){return`//# sourceURL=moderno://sleekgrid/${this}/${n}`}function $(n){let t=n.closest(".area"),{columns:e,leftIndex:o,rightIndex:i}=t.columnCtrl,{columnIndex:r}=n,l=e[r];return{area:t,columns:e,leftIndex:o,rightIndex:i,column:l,columnIndex:r}}function I(n){let t=n.closest(".area"),{rows:e,topIndex:o,bottomIndex:i}=t.rowCtrl,{rowIndex:r}=n.parentElement,l=e[r];return{area:t,rows:e,topIndex:o,bottomIndex:i,row:l,rowIndex:r}}function z(n){let t=n.closest(".area"),e=t.getBoundingClientRect(),{top:o,bottom:i,left:r,right:l}=n.getBoundingClientRect();return t.visibleTop!==void 0?(o=Math.max(o,t.visibleTop),i=Math.min(i,t.visibleBottom)):(o=Math.max(o,e.top),i=Math.min(i,e.bottom)),t.visibleLeft!==void 0?(r=Math.max(r,t.visibleLeft),l=Math.min(l,t.visibleRight)):(r=Math.max(r,e.left),l=Math.min(l,e.right)),{top:o,bottom:i,left:r,right:l,height:i-o,width:l-r}}function N(n){n[0].id===void 0&&n.forEach((t,e)=>t.id=String(e)),typeof n[0].id!="string"&&n.forEach(t=>t.id=String(t.id))}var ft=0,v=class extends HTMLElement{#e;#t;constructor(){super();this.features={header:{width:0,height:0,top:!1,right:!1,bottom:!1,left:!1},sticky:{top:null,right:null,bottom:null,left:null},resize:{columns:!1,rows:!1},dnd:{columns:!1,rows:!1},autosize:"quick"},this.pendingUpdate={},this.properties={rows:[],columns:[]},this.#t=this.properties.rows,this.#e=this.properties.columns;let t=this.attachShadow({mode:"open"});t.adoptedStyleSheets=[O,q,new CSSStyleSheet],t.appendChild(this.createRoot()),this.root=t.getElementById("root"),this.viewPort=t.getElementById("view-port"),this.theme="light",this.cellSize=Z(this,t.getElementById("sizer"));let e,o=i=>{cancelAnimationFrame(e),e=requestAnimationFrame(()=>{Array.isArray(i)&&this.viewPort.refresh(this.getBoundingClientRect()),this.refresh()})};new ResizeObserver(o).observe(this.viewPort),this.viewPort.addEventListener("scroll",o,{capture:!0,passive:!0}),this.window={left:0,top:0,width:0,height:0},this.sourceURL=tt.bind(`grid-${ft++}`)}static get observedAttributes(){return["theme","column-header","column-resize","column-dnd","row-header","row-resize","row-dnd","sticky-top","sticky-right","sticky-bottom","sticky-left","autosize"]}set theme(t){let{style:e}=this.shadowRoot.getElementById("root");t==="dark"?(e.setProperty("--primary-color","dodgerblue"),e.setProperty("--text-color","white"),e.setProperty("--background-color","#444"),e.setProperty("--even-rows-background","#222"),e.setProperty("--odd-rows-background","#111"),e.setProperty("--border-color","#333"),e.setProperty("--shadow-color","rgba(0, 0, 0, 1)"),e.setProperty("--border-color-active","white")):(e.setProperty("--primary-color","dodgerblue"),e.setProperty("--text-color","black"),e.setProperty("--background-color","white"),e.setProperty("--even-rows-background","white"),e.setProperty("--odd-rows-background","#eee"),e.setProperty("--border-color","lightgrey"),e.setProperty("--shadow-color","rgba(0, 0, 0, 0.25)"),e.setProperty("--border-color-active","black"))}get columns(){return this.#e}set columns(t){Array.isArray(t)&&t.length&&(typeof t[0]=="string"&&(t=t.map((e,o)=>({id:String(o),label:e,field:o}))),N(t)),this.requestUpdate({columns:t??[]})}get rows(){return this.#t}set rows(t){Array.isArray(t)&&t.length&&N(t),this.requestUpdate({rows:t??[]})}connectedCallback(){this.setAttribute("grid-id",this.gridId),this.useHighlight(),this.update(this.pendingUpdate),this.pendingUpdate=null;let{width:t,height:e}=this.viewPort.getBoundingClientRect();this.window.left=this.viewPort.scrollLeft,this.window.top=this.viewPort.scrollTop,this.window.width=t,this.window.height=e}disconnectedCallback(){}attributeChangedCallback(t,e,o){switch(t){case"theme":return this.theme=o;case"column-header":{let{header:i}=this.features;if(i.top=i.bottom=!1,o){let r=/bottom/i.test(o)?"bottom":"top";i[r]=!0}this.requestUpdate({features:{...this.features,header:i}});return}case"row-header":{let{header:i}=this.features;if(i.left=i.right=!1,o){let r=/right/i.test(o)?"right":"left";i[r]=!0}this.requestUpdate({features:{...this.features,header:i}});return}case"sticky-top":case"sticky-right":case"sticky-bottom":case"sticky-left":{let{sticky:i}=this.features,r=t.split("-")[1];if(o){let l=i[r]={};for(let d of o.split(","))l[d]=!0}else i[r]=null;this.requestUpdate({features:{...this.features,sticky:i}});return}case"column-resize":{let{resize:i}=this.features;i.columns=!(o===null||o==="false"),this.requestUpdate({features:{...this.features,resize:i}});return}case"row-resize":{let{resize:i}=this.features;i.rows=!(o===null||o==="false"),this.requestUpdate({features:{...this.features,resize:i}});return}case"column-dnd":{let{dnd:i}=this.features;i.columns=!(o===null||o==="false"),this.requestUpdate({features:{...this.features,dnd:i}});return}case"row-dnd":{let{dnd:i}=this.features;i.rows=!(o===null||o==="false"),this.requestUpdate({features:{...this.features,dnd:i}});return}case"autosize":{let i=!(o===null||o==="false");this.requestUpdate({features:{...this.features,autosize:i}});return}}}requestUpdate(t=this.properties){this.pendingUpdate||(this.pendingUpdate=Object.create(null),this.shadowRoot&&setTimeout(()=>{this.update(this.pendingUpdate),this.pendingUpdate=null},0)),Object.assign(this.pendingUpdate,t)}update(t=this.properties){Object.assign(this.properties,t);let e=Object.assign(Object.create(this.properties),t);this.filter(e),this.sort(e),this.layout(e),this.render(e)}filter(t){let{columns:e,rows:o}=t;if(e||o){e=e??this.#e,o=o??this.#t;let i=K(this,e);i&&(o=_(i,o),o!==this.#t&&(i&&o.length===0&&(o=[e.reduce(function(r,l){return l.search&&(r[l.field]="NO MATCH"),r.id="",r},{})]),t.rows=o))}}sort(t){let{columns:e,rows:o}=t;(e||o)&&(o=J(e??this.#e,o??this.#t),o!==this.#t&&(t.rows=o))}layout(t){let{action:e,columns:o,rows:i,features:r}=t,l=this.viewPort.getBoundingClientRect();r&&((r.sticky||r.header)&&(o=o??this.#e,i=i??this.#t,this.viewPort.layout()),this.features=r);let{top:d,right:c,bottom:s,left:h,center:p,scrollTop:f,clientHeight:x,scrollLeft:a,clientWidth:u}=this.viewPort;if(o){e||this.autosizeColumns(o,i??this.#t,u);let w=this.sliceColumns(o);if(h){let g=w.left;h.width=M(g),h.columnCtrl.layout(g),h.columns=g,d&&(d.left.columns=g),s&&(s.left.columns=g),u-=h.width}if(c){let g=w.right;c.width=M(g),c.columnCtrl.layout(g),c.columns=g,d&&(d.right.columns=g),s&&(s.right.columns=g),u-=c.width}let m=w.center;p.width=Math.max(M(m),u-((h?.width??8)+(c?.width??8))),p.columnCtrl.layout(m,a,u),p.columns=m,d&&(d.columns=m),s&&(s.columns=m),this.#e=o,this.window.width=u}if(i){e||this.autosizeRows(i,x);let w=this.sliceRows(i);if(d){let g=w.top;d.height=E(g),d.rowCtrl.layout(g),d.rows=g,h&&(d.left.rows=g),c&&(d.right.rows=g),x-=d.height}if(s){let g=w.bottom;s.height=E(g),s.rowCtrl.layout(g),s.rows=g,h&&(s.left.rows=g),c&&(s.right.rows=g),x-=s.height}let m=w.center;p.height=Math.max(E(m),x-((d?.height??8)+(s?.height??8))),p.rowCtrl.layout(m,f,x),p.rows=m,h&&(h.rows=m),c&&(c.rows=m),this.#t=i,this.window.height=x}this.window.left=a,this.window.top=f,this.viewPort.refresh(l)}render({columns:t,rows:e}){let{top:o,right:i,bottom:r,left:l,center:d}=this.viewPort,{rowCtrl:c,columnCtrl:s}=d;c.update(d,s),o&&o.rowCtrl.update(o,s),r&&r.rowCtrl.update(r,s),l&&(c.update(l,l.columnCtrl),o&&o.rowCtrl.update(o.left,l.columnCtrl),r&&r.rowCtrl.update(r.left,l.columnCtrl)),i&&(c.update(i,i.columnCtrl),o&&o.rowCtrl.update(o.right,i.columnCtrl),r&&r.rowCtrl.update(r.right,i.columnCtrl))}scrollTo(t,e){this.viewPort.scrollTo(t,e)}refresh(){let{top:t,right:e,bottom:o,left:i,center:r,scrollTop:l,scrollLeft:d,clientHeight:c,clientWidth:s}=this.viewPort;this.window.left=d,this.window.top=l,t&&(c-=t.height),e&&(s-=e.width),o&&(c-=o.height),i&&(s-=i.width),this.window.width=s,this.window.height=c;let{rowCtrl:h,columnCtrl:p}=r;p.sync(d,s),h.sync(l,c),p.refresh&&(t&&t.rowCtrl.refresh(t,p),o&&o.rowCtrl.refresh(o,p)),i&&h.refresh(i,i.columnCtrl),h.refresh(r,p),e&&h.refresh(e,e.columnCtrl),this.pending=null}autosizeColumns(t,e=this.#t,o){let i=this.features.autosize;if(i==="quick")for(let r=0;r `);v.prototype.createArea=function(t){let e=mt();e.id=`${t}-area`,e.setAttribute("tabindex",String(gt(t)));let[o,i]=t.split("-");return o&&e.classList.add(`${o}-area`),i&&e.classList.add(`${i}-area`),e.addEventListener("keydown",function(r){let l=e.querySelector("#highlight");if(l)switch(r.code){case"KeyS":case"ArrowDown":return j(r,l,0,1);case"KeyW":case"ArrowUp":return j(r,l,0,-1);case"KeyA":case"ArrowLeft":return j(r,l,-1,0);case"KeyD":case"ArrowRight":return j(r,l,1,0)}}),e};function j(n,t,e,o){n.preventDefault(),n.stopPropagation(),t.move(e,o)}function gt(n){switch(n){case"top-left":return 1;case"top":return 2;case"top-right":return 3;case"left":return 4;case"center":return 5;case"right":return 6;case"bottom-left":return 7;case"bottom":return 8;case"bottom-right":return 9}}function H(n,t){let{style:e}=n.closest("#view-port"),o;Object.defineProperty(n,t,{get:()=>o,set:i=>e.setProperty(`--${n.id}-${t}`,`${o=i}px`)})}function S(n,t,e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(t,e))}function et(n,t,e){let{rows:o}=n.properties;o[o.findIndex(i=>i.id===t)].height=e}var ot=T((n,t)=>{let{area:e,rows:o,rowIndex:i,row:r}=I(n),l=Math.round(t.autoRowHeight(r)-r.height);if(l){r.height+=l,e.height+=l,t.resizeRowParts(r.id,r.height);for(let d,c=i+1;c{let u=a-h;return h=a,u},f=!1,x=()=>{f=!1};return{set done(a){x=()=>{a(),f=!1}},on(a,u){let w=p(a),m=a+d;if(!f){if(c=u.parentElement.rowIndex,w>0&&c>s){let g=W(u);m>g-8&&(r(s,c),s=c,o.parentElement.addEventListener("transitionend",x),f=!0)}w<0&&cy===u),[g]=a.splice(m,1),b=a.findIndex(({id:y})=>y===w);a.splice(b,0,g),n.requestUpdate({rows:a})}}}}function W(n){let{top:t,bottom:e}=n.getBoundingClientRect();return(t+e)/2}function bt(n,{rows:t},{top:e,bottom:o}){let i=n.shadowRoot.appendChild(document.createElement("div"));i.id="drop-highlight";let{left:r,right:l,bottom:d}=n.viewPort.getBoundingClientRect();i.style.cssText=` left:${r}px; top:${e}px; width:${l-r}px; height:${Math.min(o,d)-e-2}px; transform: translateY(0); `;let c;return{at(s,h){if(h||s!==c){let{top:p,bottom:f}=z(s);i.style.transform=`translateY(${p-e+1}px)`,i.style.height=`${f-p-2}px`,c=s}},dispose(){i.remove()}}}var rt=k(function({pageX:n,pageY:t},e,o){let i=I(e),{row:r}=i,l=z(e),d=wt(o,i,l),c=xt(o,i,e,n),s=bt(o,i,l);c.done=()=>{s.at(e,!0)},o.viewPort.classList.add("drag-n-drop","drag-row"),o.queryRowParts(r.id).forEach(a=>a.classList.add("detached"));let{left:h,right:p}=o.viewPort.getBoundingClientRect(),f=e.closest(".area"),x=f;return{onMove({pageX:a,pageY:u}){let w=Math.min(p,Math.max(h,a))-n,m=u-t;d.move(w,m);let g=o.shadowRoot.elementFromPoint(a,u);g.classList.contains("header")&&(x=g.closest(".area"),x===f?(s.at(e),c.on(u,g)):s.at(x))},onEnd(){if(d.dispose(),s.dispose(),c.dispose(),x!==f){let{sticky:a}=o.features,u=x.classList;u.contains("top-area")?a.top={...a.top,[r.id]:!0}:u.contains("bottom-area")&&(a.bottom={...a.bottom,[r.id]:!0}),o.requestUpdate({features:{...o.features,sticky:a}})}o.viewPort.classList.remove("drag-n-drop","drag-row"),o.queryRowParts(r.id).forEach(a=>a.classList.remove("detached"))}}});v.prototype.createGridRow=C(`
`);v.prototype.updateGridRow=function(t,{row:e,rowIndex:o}){t.row!==e&&(t.setAttribute("row-id",e.id),t.style.transform=`translateY(${e.top}px)`,t.style.height=`${e.height}px`,t.row=e),t.rowIndex!==o&&(t.classList.replace(t.classList[1],`r-${o}`),o%2?t.className=`row odd r-${o}`:t.className=`row even r-${o}`,t.rowIndex=o)};v.prototype.createGridCell=C(`
`);v.prototype.updateGridCell=function(t,{column:e,columnIndex:o},{row:i}){t.columnIndex!==o&&(t.classList.replace(t.classList[1],`c-${o}`),t.columnIndex=o),t.column!==e&&(t.setAttribute("column-id",e.id),t.style.left=`${e.left}px`,t.style.width=`${e.width}px`,t.column=e),this.renderCell(t.firstChild,e,i)};v.prototype.createRowHeader=C(`
`,function(n){let{firstChild:t,lastChild:e}=n;this.features.resize.columns&&(e.addEventListener("dblclick",ot),e.addEventListener("pointerdown",it)),this.features.dnd.rows&&t.addEventListener("pointerdown",rt)});v.prototype.updateRowHeader=function(t,{column:e,columnIndex:o},{row:i}){t.columnIndex!==o&&(t.classList.replace(t.classList[3],`c-${o}`),t.columnIndex=o),t.column!==e&&(t.setAttribute("column-id",e.id),t.classList.replace(t.classList[0],e.position),t.style.left=`${e.left}px`,t.style.width=`${e.width}px`,t.column=e),t.firstChild.innerText=i[e.field]};function vt(n,{column:t},{top:e,left:o,width:i}){let{clientHeight:r}=n.viewPort,l=n.root.appendChild(document.createElement("div"));l.className="ghost column",l.style.cssText=` left:${o+4}px; top:${e+2}px; width:${i-8}px; height:${r-4}px; `;for(let d of n.queryColumnCells(t.id)){let c=d.cloneNode(!0);c.style.left="0",c.style.transform=d.parentElement.transform,c.classList.add(d.parentElement.classList.contains("odd")?"odd":"even"),l.appendChild(c)}return l.firstElementChild.classList.remove("odd","even"),requestAnimationFrame(function(){l.style.opacity="1"}),{move(d,c){l.style.transform=`translate(${d}px, ${c}px)`},dispose(){l.style.opacity=null,setTimeout(function(){l.remove()},300)}}}function yt(n,{columns:t,columnIndex:e},o,i){function r(a,u){let w=t[a],m,g=w.left;for(let b=a;b{let u=a-h;return h=a,u},f=!1,x=()=>{f=!1};return{set done(a){x=()=>{a(),f=!1}},on(a,u){let w=p(a),m=a+d;if(!f){if(c=u.columnIndex,w>0&&c>s){let g=B(u);m>g-8&&(r(s,c),s=c,o.addEventListener("transitionend",x),f=!0)}w<0&&cy===u),[g]=a.splice(m,1),b=a.findIndex(({id:y})=>y===w);a.splice(b,0,g),n.requestUpdate({columns:a})}}}}function B(n){let{left:t,right:e}=n.getBoundingClientRect();return(t+e)/2}function Ct(n,{columns:t},{left:e,right:o}){let i=n.shadowRoot.appendChild(document.createElement("div"));i.id="drop-highlight";let{top:r,bottom:l,right:d}=n.viewPort.getBoundingClientRect();i.style.cssText=` top:${r}px; left:${e}px; height:${l-r}px; width:${Math.min(o,d)-e-2}px; transform: translateX(0); `;let c;return{at(s,h){if(h||s!==c){let{left:p,right:f}=z(s);i.style.transform=`translateX(${p-e+1}px)`,i.style.width=`${f-p-2}px`,c=s}},dispose(){i.remove()}}}var st=k(function({pageX:n,pageY:t},e,o){let i=$(e),{column:r}=i,l=z(e),d=vt(o,i,l),c=yt(o,i,e,n),s=Ct(o,i,l);c.done=()=>{s.at(e,!0)},o.viewPort.classList.add("drag-n-drop","drag-column"),o.queryColumnCells(r.id).forEach(a=>a.classList.add("detached"));let{top:h,bottom:p}=o.viewPort.getBoundingClientRect(),f=e.closest(".area"),x=f;return{onMove({pageX:a,pageY:u}){let w=a-n,m=Math.min(p,Math.max(h,u))-t;d.move(w,m);let g=o.shadowRoot.elementFromPoint(a,u);g.classList.contains("header")&&(x=g.closest(".area"),x===f?(s.at(e),c.on(a,g)):s.at(x))},onEnd(){if(d.dispose(),s.dispose(),c.dispose(),x!==f){let{sticky:a}=o.features,u=x.classList;u.contains("left-area")?a.left={...a.left,[r.id]:!0}:u.contains("right-area")&&(a.right={...a.right,[r.id]:!0}),o.requestUpdate({features:{...o.features,sticky:a}})}o.viewPort.classList.remove("drag-n-drop","drag-column"),o.queryColumnCells(r.id).forEach(a=>a.classList.remove("detached"))}}});function nt(n,t,e){let{columns:o}=n.properties;o[o.findIndex(i=>i.id===t)].width=e}var lt=T((n,t)=>{let{area:e,columns:o,columnIndex:i,column:r}=$(n),l=Math.round(t.autoColumnWidth(r)-r.width);if(l){r.width+=l,e.width+=l,t.resizeColumnCells(r.id,r.width);for(let d,c=i+1;c `);v.prototype.updateHeaderRow=function(t,{row:e,rowIndex:o}){if(t.row!==e){t.setAttribute("row-id",e.id),t.classList.replace(t.classList[0],e.position),t.style.transform=`translateY(${e.top}px)`,t.style.height=`${e.height}px`,t.row=e;let i=Math.min(8,Math.max(2,2+(e.height-32)*6/10));t.style.setProperty("--search-input-padding",`${i}px`)}t.rowIndex!==o&&(t.classList.replace(t.classList[3],`r-${o}`),t.rowIndex=o)};v.prototype.createStub=C(`
`);v.prototype.updateStub=function(t,{column:e,columnIndex:o}){t.column!==e&&(t.classList.replace(t.classList[0],e.position),t.setAttribute("column-id",e.id),t.style.left=`${e.left}px`,t.style.width=`${e.width}px`,t.column=e),t.columnIndex!==o&&(t.classList.replace(`c-${t.columnIndex}`,`c-${o}`),t.columnIndex=o)};v.prototype.createColumnHeader=C(`

`,function(n){let t=n.firstChild,e=n.lastChild.firstChild,o=e.nextSibling.nextSibling,i=o.nextSibling,r=this,l;e.addEventListener("focus",()=>{l=!0,r.scrollIntoView(e.closest(".cell"))}),e.addEventListener("blur",()=>l=!1),e.addEventListener("input",c=>{let s=n.getAttribute("column-id");r.properties.columns.find(h=>h.id===s).search=e.value,r.requestUpdate({action:"filter",columns:[...r.properties.columns]})}),i.addEventListener("click",c=>{let{left:s,top:h}=i.getBoundingClientRect(),p=document.createElement("dialog");p.className="ch menu",requestAnimationFrame(function(){p.setAttribute("open","")}),p.style.marginLeft=`${s-4}px`,p.style.top=`${h}px;`,p.innerHTML=`
Pin Column
Clear Search
Hide Column
`,p.addEventListener("click",function(){p.removeAttribute("open"),setTimeout(function(){p.remove()},300)}),r.root.append(p)},!0),o.addEventListener("click",c=>{let{extentOffset:s,anchorOffset:h,focusNode:p}=r.root.getSelection();(s===h||p.parentNode!==c.target)&&e.focus()},!1);let d=o.lastChild;d.addEventListener("pointerdown",c=>{c.preventDefault(),c.stopPropagation()}),d.addEventListener("click",c=>{c.preventDefault(),c.stopPropagation();let s=n.getAttribute("column-id");r.requestUpdate({action:"sort",columns:[...r.properties.columns.map(h=>h.id===s?{...h,sort:h.sort?h.sort==="asc"?"desc":void 0:"asc"}:{...h,sort:void 0})]})}),r.features.resize.columns&&(t.addEventListener("dblclick",lt),t.addEventListener("pointerdown",at)),r.features.dnd.columns&&o.addEventListener("pointerdown",st)});v.prototype.updateColumnHeader=function(t,{column:e,columnIndex:o}){t.columnIndex!==o&&(t.classList.replace(`c-${t.columnIndex}`,`c-${o}`),t.columnIndex=o),t.column!==e&&(t.setAttribute("column-id",e.id),t.style.left=`${e.left}px`,t.style.width=`${e.width}px`,t.column=e),t.childNodes[1].childNodes[2].firstChild.replaceWith(e.label);let r=t.childNodes[1].childNodes[0];r.value!==e.search&&(r.value=e.search||"",e.search?t.setAttribute("search",e.search):t.removeAttribute("search")),e.sort?t.setAttribute("sort",e.sort):t.removeAttribute("sort")};v.prototype.createRoot=C(`
`,function(n){let t=n.querySelector("#view-port"),e=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT);for(;e.nextNode();){let s=e.currentNode,h=null;Object.defineProperty(t,s.textContent,{get(){return h},set(p){p||(p=s),h||(h=s),h.replaceWith(p),p===s?h=null:h=p}})}let o=this,i=t.center=o.createArea("center");i.columnCtrl=new R(o),i.rowCtrl=new L(o),i.visibleRect={...t.getBoundingClientRect()},i.setAttribute("scroll-x",""),i.setAttribute("scroll-y",""),H(i,"width"),H(i,"height");let r=["top","bottom"],l=["left","right"],{header:d,sticky:c}=o.features;t.layout=function(){for(let s of r){let h=d[s],p=c[s];if(h||p){let f=this[s];f||(f=this[s]=o.createArea(s),f.rowCtrl=new L(o),f.columnCtrl=i.columnCtrl,f.setAttribute("scroll-x",""),H(f,"height"),S(f,i,"width")),f.header={[s]:h}}else this[s]&&(this[s].height=0,this[s]=null)}for(let s of l){let h=d[s],p=c[s];if(h||p){let f=this[s];f||(f=this[s]=o.createArea(s),f.rowCtrl=i.rowCtrl,f.columnCtrl=new R(o),f.setAttribute("scroll-y",""),H(f,"width"),S(f,i,"height")),f.header={[s]:h}}else this[s]&&(this[s].width=0,this[s]=null)}for(let s of r)for(let h of l){let p=`${s}-${h}`;if(this[s]&&this[h]){let f=this[p];f||(f=this[p]=this[s][h]=this[h][s]=o.createArea(p),f.columnCtrl=this[h].columnCtrl,f.rowCtrl=this[s].rowCtrl,S(f,this[h],"width"),S(f,this[s],"height"))}else this[p]=null,this[s]&&(this[s][h]=null),this[h]&&(this[h][s]=null)}},t.refresh=function(s){let{top:h,bottom:p,left:f,right:x,center:a}=this;a.visibleTop=s.top,a.visibleBottom=s.bottom,a.visibleLeft=s.left+f?.width,a.visibleRight=s.right-x?.width,h&&(a.visibleTop+=h.height,h.visibleLeft=a.visibleLeft,h.visibleRight=a.visibleRight),p&&(a.visibleBottom-=p.height,p.visibleLeft=a.visibleLeft,p.visibleRight=a.visibleRight),f&&(f.visibleTop=a.visibleTop,f.visibleBottom=a.visibleBottom),x&&(x.visibleTop=a.visibleTop,x.visibleBottom=a.visibleBottom)}});v.prototype.queryColumnCells=function(n){return this.viewPort.querySelectorAll(`[column-id="${n}"]`)};v.prototype.queryRowCells=function(n){return this.viewPort.querySelectorAll(`[row-id="${n}"] .cell`)};v.prototype.resizeColumnCells=function(t,e){let o=`${e}px`;for(let{style:i}of this.queryColumnCells(t))i.width=o};v.prototype.positionColumnCells=function(t,e){let o=`${e}px`,i=this.queryColumnCells(t);for(let{style:r}of i)r.left=o;return i};v.prototype.queryRowParts=function(n){return this.viewPort.querySelectorAll(`[row-id="${n}"]`)};v.prototype.resizeRowParts=function(t,e){let o=`${e}px`;for(let{style:i}of this.queryRowParts(t))i.height=o};v.prototype.positionRowParts=function(t,e){let o=`translateY(${e}px)`,i=this.queryRowParts(t);for(let{style:r}of i)r.transform=o;return i};var F=class extends HTMLDivElement{at(t,e){let{columnCtrl:{columns:o},rowCtrl:{rows:i}}=this.parentElement,{left:r,width:l}=o[t],{top:d,height:c}=i[e];this.className=`c-${t} r-${e}`,this.columnIndex=t,this.rowIndex=e,this.style.transform=`translate(${r}px,${d}px)`,this.style.width=`${l}px`,this.style.height=`${c}px`;let{window:s,viewPort:h}=this.getRootNode().host,p=this.parentElement,f=h.scrollLeft,x=h.scrollTop;if(p.hasAttribute("scroll-x"))if(r0&&(f+=a)}if(p.hasAttribute("scroll-y"))if(d0&&(x+=a)}(f!==h.scrollLeft||x!==h.scrollTop)&&h.scrollTo({left:f,top:x,behavior:"smooth"})}move(t,e){let{columnCtrl:{columns:o,leftIndex:i,rightIndex:r},rowCtrl:{rows:l,topIndex:d,bottomIndex:c}}=this.parentElement,{columnIndex:s,rowIndex:h}=this;this.at(Math.max(0,Math.min(s+t,o.length-1)),Math.max(0,Math.min(h+e,l.length-1)))}};v.prototype.useHighlight=C('
',function(t){t.columnIndex=0,t.rowIndex=0,t.at=F.prototype.at,t.move=F.prototype.move;let{root:e}=this,o=!1;e.addEventListener("pointerdown",i=>{let r=i.target.closest(".cell");if(r&&!r.classList.contains("header")){let{area:l}=I(r);i.stopPropagation(),l.firstChild!==t&&(t?.replaceWith(document.createComment("highlight")),l.firstChild.replaceWith(t),o=!0),t.at(r.columnIndex,r.parentElement.rowIndex)}else o&&(t?.replaceWith(document.createComment("highlight")),o=!1)},{capture:!0,passive:!0})});customElements.define("sleek-grid",v);})(); //# sourceMappingURL=sleek-grid.js.map