@ninebone/datagrid 0.0.13 → 0.0.14

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.
@@ -19,11 +19,11 @@
19
19
  <button class='scroll-left' disabled><div class='scroll-icon'></div></button>
20
20
  <div class='scroll-track'><div class='scroll-thumb'></div></div>
21
21
  <button class='scroll-right' disabled><div class='scroll-icon'></div></button>
22
- `;let e=()=>{let t=this.#e.querySelector(`.ng-sheet-body .ng-container-body`);t?(this.#n={container:t,track:this.querySelector(`.scroll-track`),thumb:this.querySelector(`.scroll-thumb`),left:this.querySelector(`.scroll-left`),right:this.querySelector(`.scroll-right`)},this.#c(),this.#o(),this.refresh()):setTimeout(e,10)};e()}disconnectedCallback(){this.#a&&this.#a.disconnect()}#o=()=>{if(!this.#e)return;let e=this.#e.querySelector(`.ng-sheet-body .ng-container-body`);e&&(this.#a=new ResizeObserver(()=>{this.refresh()}),this.#a.observe(e))};refresh=()=>{if(!this.#e||!this.#n||this.#t)return;let e=this.#n.container,t=e.querySelector(`table`);if(!t)return;let n=this.#n.track,r=this.#n.thumb,i=e.clientWidth,a=t.scrollWidth,o=i!==0&&a>i;if(this.#e.classList.toggle(`hscroll-visible`,o),!o)return;let s=n.clientWidth;if(s<=0)return;let c=Math.max(Math.min(i/a*s,s),20);r.style.width=`${c}px`;let l=e.scrollLeft,u=a-i,d=0;u>0&&(d=parseInt(l/u*(s-c),10)),d<0&&(d=0);let f=s-c;d>f&&(d=f),r.style.left=`${d}px`,this.#n.left.disabled=d===0,this.#n.right.disabled=d>=f-1};#s=e=>{if(!this.#n)return!1;let t=this.#n.container,n=t.querySelector(`table`);if(!n)return!1;let r=this.#n.track.getBoundingClientRect(),i=this.#n.thumb.clientWidth,a=e;a<0&&(a=0);let o=r.width-i;a>o&&(a=o),a=parseInt(a,10),this.#n.thumb.style.left=`${a}px`,this.#n.left.disabled=a===0,this.#n.right.disabled=a>=o-1;let s=t.clientWidth,c=n.scrollWidth-s;return o>0&&c>0&&(t.scrollLeft=a/o*c),a>0&&a<o-1};#c=()=>{let e=e=>{clearInterval(this.#r),clearInterval(this.#i);let t=parseInt(this.#n.thumb.style.left||0,10);this.#s(t+e),this.#r=setInterval(()=>{clearInterval(this.#r),this.#i=setInterval(()=>{let t=parseInt(this.#n.thumb.style.left||0,10);this.#s(t+e)||clearInterval(this.#i)},50)},500)},t=()=>{clearInterval(this.#r),clearInterval(this.#i)};[`mouseup`,`mouseleave`,`touchend`].forEach(e=>{this.#n.left.addEventListener(e,t),this.#n.right.addEventListener(e,t),this.#n.track.addEventListener(e,t)}),this.#n.left.addEventListener(`mousedown`,t=>{t.button===0&&e(-20)}),this.#n.right.addEventListener(`mousedown`,t=>{t.button===0&&e(20)}),this.#n.left.addEventListener(`touchstart`,()=>e(-20)),this.#n.right.addEventListener(`touchstart`,()=>e(20)),this.#n.track.addEventListener(`mousedown`,e=>{if(e.button!==0)return;e.preventDefault();let t=this.#n.track.getBoundingClientRect(),n=this.#n.thumb.clientWidth;this.#s(e.clientX-t.left-n/2)}),this.#n.thumb.addEventListener(`mousedown`,e=>{if(e.button!==0)return;e.stopPropagation(),e.preventDefault(),this.#t=!0,this.shiftX=e.clientX-this.#n.thumb.getBoundingClientRect().left;let n=e=>{if(!this.#t)return;let t=this.#n.track.getBoundingClientRect();this.#s(e.clientX-t.left-this.shiftX)},r=()=>{this.#t=!1,t(),document.removeEventListener(`mousemove`,n),document.removeEventListener(`mouseup`,r),this.refresh()};document.addEventListener(`mousemove`,n),document.addEventListener(`mouseup`,r)})}};customElements.get(`nine-table-hscrollbar`)||customElements.define(`nine-table-hscrollbar`,p);var m=class extends HTMLElement{#e;#t;#n=!1;#r;#i=0;#a=0;constructor(){super()}connectedCallback(){this.#e=this.getRootNode().host,this.#t=this.closest(`nine-table-sheet`),this.innerHTML=`
22
+ `;let e=()=>{let t=this.#e.querySelector(`.ng-sheet-body .ng-container-body`);t?(this.#n={container:t,track:this.querySelector(`.scroll-track`),thumb:this.querySelector(`.scroll-thumb`),left:this.querySelector(`.scroll-left`),right:this.querySelector(`.scroll-right`)},this.#c(),this.#o(),this.refresh()):setTimeout(e,10)};e()}disconnectedCallback(){this.#a&&this.#a.disconnect()}#o=()=>{if(!this.#e)return;let e=this.#e.querySelector(`.ng-sheet-body .ng-container-body`);e&&(this.#a=new ResizeObserver(()=>{this.refresh()}),this.#a.observe(e))};refresh=()=>{if(!this.#e||!this.#n||this.#t)return;let e=this.#n.container,t=e.querySelector(`table`);if(!t)return;let n=this.#n.track,r=this.#n.thumb,i=e.clientWidth,a=t.scrollWidth,o=i!==0&&a>i;if(this.#e.classList.toggle(`hscroll-visible`,o),!o)return;let s=n.clientWidth;if(s<=0)return;let c=Math.max(Math.min(i/a*s,s),20);r.style.width=`${c}px`;let l=e.scrollLeft,u=a-i,d=0;u>0&&(d=parseInt(l/u*(s-c),10)),d<0&&(d=0);let f=s-c;d>f&&(d=f),r.style.left=`${d}px`,this.#n.left.disabled=d===0,this.#n.right.disabled=d>=f-1};#s=e=>{if(!this.#n)return!1;let t=this.#n.container,n=t.querySelector(`table`);if(!n)return!1;let r=this.#n.track.getBoundingClientRect(),i=this.#n.thumb.clientWidth,a=e;a<0&&(a=0);let o=r.width-i;a>o&&(a=o),a=parseInt(a,10),this.#n.thumb.style.left=`${a}px`,this.#n.left.disabled=a===0,this.#n.right.disabled=a>=o-1;let s=t.clientWidth,c=n.scrollWidth-s;return o>0&&c>0&&(t.scrollLeft=a/o*c),a>0&&a<o-1};#c=()=>{let e=e=>{clearInterval(this.#r),clearInterval(this.#i);let t=parseInt(this.#n.thumb.style.left||0,10);this.#s(t+e),this.#r=setInterval(()=>{clearInterval(this.#r),this.#i=setInterval(()=>{let t=parseInt(this.#n.thumb.style.left||0,10);this.#s(t+e)||clearInterval(this.#i)},50)},500)},t=()=>{clearInterval(this.#r),clearInterval(this.#i)};[`mouseup`,`mouseleave`].forEach(e=>{this.#n.left.addEventListener(e,t),this.#n.right.addEventListener(e,t),this.#n.track.addEventListener(e,t)}),this.#n.left.addEventListener(`mousedown`,t=>{t.button===0&&e(-20)}),this.#n.right.addEventListener(`mousedown`,t=>{t.button===0&&e(20)}),this.#n.track.addEventListener(`mousedown`,e=>{if(e.button!==0)return;e.preventDefault();let t=this.#n.track.getBoundingClientRect(),n=this.#n.thumb.clientWidth;this.#s(e.clientX-t.left-n/2)}),this.#n.thumb.addEventListener(`mousedown`,e=>{if(e.button!==0)return;e.stopPropagation(),e.preventDefault(),this.#t=!0,this.shiftX=e.clientX-this.#n.thumb.getBoundingClientRect().left;let n=e=>{if(!this.#t)return;let t=this.#n.track.getBoundingClientRect();this.#s(e.clientX-t.left-this.shiftX)},r=()=>{this.#t=!1,t(),document.removeEventListener(`mousemove`,n),document.removeEventListener(`mouseup`,r),this.refresh()};document.addEventListener(`mousemove`,n),document.addEventListener(`mouseup`,r)})}};customElements.get(`nine-table-hscrollbar`)||customElements.define(`nine-table-hscrollbar`,p);var m=class extends HTMLElement{#e;#t;#n=!1;#r;#i=0;#a=0;constructor(){super()}connectedCallback(){this.#e=this.getRootNode().host,this.#t=this.closest(`nine-table-sheet`),this.innerHTML=`
23
23
  <button class='scroll-top' disabled><div class='scroll-icon'></div></button>
24
24
  <div class='scroll-track'><div class='scroll-thumb'></div></div>
25
25
  <button class='scroll-bottom' disabled><div class='scroll-icon'></div></button>
26
- `;let e=()=>{let t=this.#t.querySelector(`.ng-sheet-body`);t?(this.#r={container:t,track:this.querySelector(`.scroll-track`),thumb:this.querySelector(`.scroll-thumb`),top:this.querySelector(`.scroll-top`),bottom:this.querySelector(`.scroll-bottom`)},this.#s(),this.refresh()):setTimeout(e,10)};e()}#o=()=>{let e=this.#t.view.getArray(),t=e?e.length:0,n=this.#t.elements?.scrollHolder,r=n&&parseFloat(n.style.height)||0;(!r||r<=0)&&(r=this.#t.sourceTable?.querySelector(`tbody tr[grouping='true']`)&&this.#t.rowManager?body.scrollHeight>body.clientHeight?body.scrollHeight:t*30:t*(this.#t.getRowHeight()||1));let i=15e6,a=r>i,o=1,s=r;return a&&(o=i/r,s=i),{rawContentHeight:r,contentHeight:s,scaleFactor:o,useScaling:a,totalCount:t}};refresh=()=>{if(this.#n||!this.#t||!this.#t.elements||!this.#r)return;let e=this.#r.container,t=this.#r.track,n=this.#r.thumb,{contentHeight:r}=this.#o(),i=(this.#t.querySelector(`thead`)?.offsetHeight||0)+(this.#t.querySelector(`tfoot`)?.offsetHeight||0)+(this.#t.querySelector(`tbody.head`)?.offsetHeight||0),a=this.#t.querySelector(`.ng-sheet-body`).offsetHeight||0,o=a-i,s=this.#t.view.getArray().length,c=this.#t.getRowHeight()*s,l=c>o;if(this.#t.classList.toggle(`vscroll-visible`,l),!l)return;let u=t.clientHeight;if(u<=0)return;let d=Math.max(Math.min(a/c*u,u),20);n.style.height=`${d}px`;let f=e.scrollTop,p=Math.max(r-this.#t.rowManager.getRowHeight(),1),m=0;p>0&&(m=f/p*(u-d));let h=u-d;m<0&&(m=0),m>h&&(m=h),n.style.top=`${m}px`,this.#r.top.disabled=f<=0,this.#r.bottom.disabled=f>=p-1};#s=()=>{this.#r.thumb.addEventListener(`mousedown`,e=>{if(e.button!==0)return;e.stopPropagation(),e.preventDefault(),this.#n=!0,this.#i=e.clientY,this.#a=parseFloat(this.#r.thumb.style.top)||0;let t=this.#r.track.getBoundingClientRect().height-this.#r.thumb.clientHeight,n=e=>{if(!this.#n||t<=0)return;let n=e.clientY-this.#i,r=this.#a+n;r<0&&(r=0),r>t&&(r=t),this.#r.thumb.style.top=`${r}px`;let i=r/t,a=this.#t.getRowHeight(),o=(this.#t.querySelector(`.ng-sheet-body`).offsetHeight||0)-(this.#t.elements.body.thead?.offsetHeight||0)-(this.#t.elements.body.tfoot?.offsetHeight||0)-(this.#t.elements.body.tbody.head.offsetHeight||0),s=Math.floor(o/a),{totalCount:c}=this.#o(),l=Math.floor(i*(c-s+1));this.#t.rowManager.scrollToDataRow(l);let{rawContentHeight:u,contentHeight:d}=this.#o(),f=this.#r.container.scrollTop,p=Math.max(d-this.#t.rowManager.getRowHeight(),0);this.#r.top.disabled=f<=0,this.#r.bottom.disabled=f>=p-1},r=()=>{this.#n=!1,document.removeEventListener(`mousemove`,n),document.removeEventListener(`mouseup`,r)};document.addEventListener(`mousemove`,n),document.addEventListener(`mouseup`,r)}),this.#r.track.addEventListener(`mousedown`,e=>{if(e.button!==0||e.target===this.#r.thumb)return;let t=this.#r.track.getBoundingClientRect(),n=this.#r.thumb.clientHeight,r=this.#r.track.clientHeight-n;if(r>0){let i=e.clientY-t.top-n/2,a=Math.max(0,Math.min(1,i/r)),{totalCount:o}=this.#o(),s=Math.max(0,Math.min(Math.floor(a*(o-1)),o-1));s>=0&&this.#t.rowManager&&typeof this.#t.rowManager.scrollToDataRow==`function`&&this.#t.rowManager.scrollToDataRow(s,`top`)}this.refresh()});let e=null,t=t=>{if(e)return;let n=()=>{let e=this.#t.querySelector(`tbody.body tr`);if(!e||e.dataset.row===void 0||t===`down`&&this.#t.isLastRow())return;let n=parseInt(e.dataset.row,10),r=t===`down`?n+1:Math.max(0,n-1);this.#t.rowManager.scrollToDataRow(r,null,()=>{this.refresh()})};n(),e=setInterval(n,200)},n=()=>{e&&=(clearInterval(e),null)};this.#r.top.addEventListener(`mousedown`,e=>{e.button===0&&t(`up`)}),this.#r.bottom.addEventListener(`mousedown`,e=>{e.button===0&&t(`down`)}),document.addEventListener(`mouseup`,n),this.#r.top.addEventListener(`mouseleave`,n),this.#r.bottom.addEventListener(`mouseleave`,n)}};customElements.get(`nine-table-vscrollbar`)||customElements.define(`nine-table-vscrollbar`,m);var h={ID:0,DEPTH:1,NAME:2,CHILDREN:3},g=class{#e;#t;#n=[];#r=new Map;#i=!1;constructor(e){this.#e=e,this.#t=this.#e.getRootNode().host}get columns(){return this.#n}get groupMap(){return this.#r}initialize=()=>{let e=[],t=this.#e.sourceTable;t&&t.querySelectorAll(`tbody tr[grouping="true"]`).forEach(t=>{let n=t.querySelector(`[cell-type="tree"]`);n&&n.dataset.bind&&e.push(n.dataset.bind)}),this.#n=e};apply(){if(this.#i)return;this.#i=!0;let e=[],t=this.#e.sourceTable;t&&t.querySelectorAll(`tbody tr[grouping="true"]`).forEach(t=>{let n=t.querySelector(`[cell-type="tree"]`);n&&n.dataset.bind&&e.push(n.dataset.bind)}),this.#n=e,this.#i=!1,this.#e.scrollToY(0),this.#e.view.refresh()}clear(){this.#n=[],this.#r.clear(),this.#i=!1,this.#e.scrollToY(0),this.#e.view.refresh()}setGroupMap(e){this.#r=e}getChildrenRowIds(e){return this.#r.get(e)||[]}getChildrenRecords(e){let t=this.getChildrenRowIds(e),n=this.#t.data;return t.map(e=>n.getArray(e)).filter(Boolean)}},_=class e{static apply(t,n=[],r=[]){if(!n||n.length===0)return{headers:[],renderItems:[],groupMap:new Map};let i=t.filter(e=>!e.__ng?.deleted),a=new Map,o=e.#t(i,n,r),s=[],c=[];return e.#e(o,0,n,s,c,a,``),{headers:s,renderItems:c,groupMap:a}}static#e(t,n,r,i,a,o,s){let c=0,l=n===r.length-1;for(let[u,d]of t.entries()){let t=s?`${s}_${c++}`:`g_${c++}`,f=e.#n(d);o.set(t,f);let p=[];p[h.ID]=t,p[h.DEPTH]=n,p[h.NAME]=u,p[h.CHILDREN]=f,p.__isGroupHeader=!0,p.__groupId=t,i.push(p),a.push({type:`group`,record:p,groupId:t}),!l&&d instanceof Map?e.#e(d,n+1,r,i,a,o,t):e.#r(d).forEach(e=>{e.__isGroupHeader=!1,e.__groupId=t,i.push(e),a.push({type:`data`,record:e,groupId:t})})}}static#t(t,n,r){let i=r.indexOf(n[0]),a=n.slice(1),o=new Map;if(t.forEach(e=>{let t=i>=0?e.v[i]:`(Unknown)`;o.has(t)||o.set(t,[]),o.get(t).push(e)}),a.length>0){let t=new Map;for(let[n,i]of o.entries())t.set(n,e.#t(i,a,r));return t}return o}static#n(t){let n=[];if(t instanceof Map)for(let r of t.values())n=n.concat(e.#n(r));else Array.isArray(t)&&(n=n.concat(t.map(e=>e.__ng?.rowid??e.m?._?.[0])));return n}static#r(t){let n=[];if(t instanceof Map)for(let r of t.values())n=n.concat(e.#r(r));else Array.isArray(t)&&(n=n.concat(t));return n}},v=class{#e=3;#t;#n;#r;#i=new Map;#a=[];#o=null;#s=null;#c=0;#l;#u=!1;#d=!1;constructor(e){this.#t=e.getRootNode().host,this.#n=e,this.#x()}getRowHeight(){return this.#a.reduce((e,t)=>e+t,0)}refresh=(e=!1)=>{if(!this.#n.classList.contains(`active`))return;let t=this.#n.querySelector(`.ng-sheet-body`);t&&((!this.#o||this.#o<=0)&&(this.#g(),this.#o&&this.#o>0&&this.#v()),this.#f(t.scrollTop,e),this.#n.querySelector(`nine-table-vscrollbar`)?.refresh())};#f=(e,t=!1)=>{if(this.#d){this.#p(e,t);return}let n=this.#o;if(!n||n<=0)return;let r=this.#n.view.getArray(),a=r.length;if(a===0){this.#n.elements.scrollHolder.style.height=`0px`;return}let o=this.#n.templateLength,s=(this.#n.elements.body.thead?.offsetHeight||0)+(this.#n.elements.body.tfoot?.offsetHeight||0)+this.#n.elements.body.tbody.head.offsetHeight,c=this.#n.querySelector(`.ng-sheet-body`).offsetHeight||0,l=Math.max(a*n-(c-s-n),0),u=15e6,d=l>u,f=1,p=l;d&&(f=u/l,p=u),this.#n.elements.scrollHolder.style.height=`${p}px`;let m=d?e/f:e,h=Math.max(0,a-1),g=Math.min(m,l),_=Math.max(0,Math.min(Math.floor(g/n),h)),v=g%n;this.#n.elements.left.tbody.body.style.top=this.#n.elements.body.tbody.body.style.top=this.#n.elements.right.tbody.body.style.top=`-${v}px`;let y=this.#r.firstTr,b=y&&y.dataset.row!==void 0?parseInt(y.dataset.row,10):-1;(t||b!==_)&&([this.#n.elements.left.tbody.body,this.#n.elements.body.tbody.body,this.#n.elements.right.tbody.body].forEach((e,t)=>{e&&e.querySelectorAll(`tbody.body tr`).forEach((e,t)=>{let n=_+Math.floor(t/o);if(n>=a){e.style.display=`none`,e.dataset.matrixRow=null,e.dataset.row=null,e.dataset.index=null;return}let s=r[n];if(!s){e.style.display=`none`;return}let c=s.m._[i.META.INDEX.ROWID];e.style.display=``,this.#h(e,s,c,n)})}),this.#n.selection.refresh())};#p=(e,t=!1)=>{let n=this.#n.view.getArray()||[],r=n.length;if(r===0){this.#n.elements.scrollHolder.style.height=`0px`;return}let i=this.#n.querySelector(`.ng-sheet-body .ng-sheet-body-content`),a=this.#n.templateLength||1,o=e=>{if(e.type===`group`){let t=e.record[h.DEPTH]||0;return this.#a[t]||this.#o/a}{let e=0,t=this.#n.templateLength||1,n=0;for(let e=0;e<t-1;e++)n+=this.#a[e]||0;return e=this.#o-n,e>0?e:this.#o}},s=0,c=Array(r);for(let e=0;e<r;e++){let t=o(n[e]);c[e]=t,s+=t}this.#n.elements.scrollHolder.style.height=`${s}px`;let l=this.#n.clientHeight,u=0,d=0;for(let t=0;t<r;t++){let n=c[t];if(u+n>e){d=t;break}u+=n,d=t}let f=e-u;i&&i.querySelectorAll(`tbody`).forEach(e=>{e.style.top=`-${Math.max(0,f)}px`});let p=this.#r.firstTr,m=p&&p.dataset.virtualIndex!==void 0?parseInt(p.dataset.virtualIndex,10):-1;if(!t&&m===d)return;let g=Math.ceil(l/(this.#o/a)),_=(this.#n.grouping.columns?.length||1)*15,v=d,y=Math.min(r,d+g+_),b=n.slice(v,y);[`.ng-container-body`,`.ng-container-left`,`.ng-container-right`].forEach(e=>{let t=this.#n.querySelector(`.ng-sheet-body ${e}`);if(!t)return;let r=Array.from(t.querySelectorAll(`tbody.body tr`));for(let e=0;e<r.length;e+=a){let t=Math.floor(e/a),i=b[t],o=r.slice(e,e+a);if(!i||t>=b.length){o.forEach(e=>{e.style.display=`none`,e.dataset.matrixRow=null,e.dataset.row=null,e.dataset.index=null});continue}let s=d+t;o.forEach((e,r)=>{let a=d+t;e.dataset.virtualIndex=a,e.dataset.row=i.type===`data`?s:``;let o=e.getAttribute(`grouping`)===`true`;if(i.type===`group`)o&&r===i.record[h.DEPTH]?(e.style.display=``,this.#m(e,n,i.record,a)):(e.style.display=`none`,e.dataset.matrixRow=null,e.dataset.row=null,e.dataset.index=null);else if(o)e.style.display=`none`,e.dataset.matrixRow=null,e.dataset.row=null,e.dataset.index=null;else{e.style.display=``;let t=i.record.m?.rowid??0;this.#h(e,i.record,t,a)}})}}),this.#n.selection.refresh()};#m=(e,t,n,r)=>{let i=this.#n.templateLength||1,a=parseInt(e.dataset.subrow,10)||0,o=r*i+a,s=n[h.CHILDREN],c=this.#t.data.getArray(),l=s?s.map(e=>c[e]).filter(Boolean):[];e.dataset.virtualIndex=r,e.dataset.row=``,e.dataset.matrixRow=o,e.data=l,e.dataset.groupId=n[h.ID],Array.from(e.cells).forEach(e=>{e.dataset.row=r;let t=Array.from(e.children).find(e=>e.tagName.toLowerCase().startsWith(`cell-`)||typeof e.refresh==`function`);t!==void 0&&typeof t.refresh==`function`&&t?.refresh()})};#h=(e,t,n,r)=>{let i=this.#n.templateLength||1,a=parseInt(e.dataset.subrow,10)||0,o=r*i+a;e.dataset.index=r,e.dataset.row=n,e.dataset.matrixRow=o,e.data=t,Array.from(e.cells).forEach(e=>{e.dataset.index=r,e.dataset.row=n,Array.from(e.children).find(e=>e.tagName.toLowerCase().startsWith(`cell-`)&&typeof e.refresh==`function`)?.refresh()})};initialize=()=>{this.#d=!!this.#n.sourceTable.querySelector(`tbody tr[grouping='true']`),this.#o=null,this.#i.clear(),this.#r={scrollTables:this.#n.querySelectorAll(`.ng-sheet-body table`),firstTr:this.#n.querySelector(`.ng-sheet-body .ng-container-body tbody.body tr`)},[`.ng-container-body`,`.ng-container-left`,`.ng-container-right`].forEach(e=>{let t=this.#n.querySelector(`.ng-sheet-body ${e}`);if(!t)return;let n=t.querySelector(`table`);if(!n)return;let r=n.querySelector(`tbody.body`);if(!r)return;let i=Array.from(r.querySelectorAll(`tr`)).map(e=>e.cloneNode(!0));this.#i.set(e,i)});let e=this.#n.querySelector(`.ng-sheet-body`);e&&(this.#c=e.clientHeight,this.#g(),this.#v(),this.#f(e.scrollTop,!0),e.addEventListener(`scroll`,t=>{if(this.#u)return;let n=this.#o||0;(this.#n.view.getArray()?.length||0)*n<=e.clientHeight||(this.#f(e.scrollTop),this.#n.querySelector(`nine-table-vscrollbar`).refresh())},{passive:!0}))};scrollToDataRow(e,t=`top`,n){let r=this.#n.querySelector(`.ng-sheet-body`),i=this.#n.view.getArray()?.length||0,a=Math.max(0,Math.min(e,i-1)),o=0;if(this.#d){let e=Math.max(r.scrollHeight-r.clientHeight,1);o=a/Math.max(i-1,1)*e}else{let e=this.#o,t=a*e,n=(this.#n.elements.body.thead?.offsetHeight||0)+(this.#n.elements.body.tfoot?.offsetHeight||0)+this.#n.elements.body.tbody.head.offsetHeight,s=r.offsetHeight||0,c=Math.max(i*e+n-s,0),l=15e6,u=c>l,d=1;u&&(d=l/c),o=t*d}this.#u=!0,r.scrollTop=o,this.#f(o),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.#u=!1,typeof n==`function`&&n()})})}destroy=()=>{this.#s&&=(this.#s.disconnect(),null)};#g=()=>{if(!this.#n.classList.contains(`active`)||!this.#n.sourceTable)return;let e=this.#n.sourceTable?.querySelectorAll(`tbody.body tr`),t=this.#n.querySelector(`.ng-sheet-body .ng-container-body tbody.body`);t.querySelectorAll(`tr`).forEach(e=>e.remove());let n=document.createDocumentFragment();e.forEach(e=>n.appendChild(e.cloneNode(!0))),t.appendChild(n);let r=t.querySelectorAll(`tr`);this.#a=[],r.forEach(e=>{this.#a.push(Math.max(e.offsetHeight,24))}),r.forEach(e=>e.remove()),this.#o=this.#a.reduce((e,t)=>e+t,0),this.#_()};#_=()=>{if(this.#c>0&&this.#o>0){let e=Math.ceil(this.#c/this.#o),t=this.#e;if(this.#d&&this.#n.grouping){let e=this.#n.grouping.columns?.length||1;t+=e*15}this.#l=e+t}};#v=()=>{[`.ng-container-body`,`.ng-container-left`,`.ng-container-right`].forEach(e=>{let t=this.#n.querySelector(`.ng-sheet-body ${e}`);t&&t.querySelector(`tbody`)&&this.#y(t)}),this.#b()};#y=e=>{let t=null;e.classList.contains(`ng-container-left`)?t=`left`:e.classList.contains(`ng-container-right`)&&(t=`right`);let n=Array.from(this.#n.sourceTable.querySelectorAll(`tbody.body tr`)).map(e=>{let n=e.cloneNode(!0);return t===`left`?n.querySelectorAll(`th,td`).forEach(e=>{e.getAttribute(`fixed`)!==`left`&&e.remove()}):t===`right`?n.querySelectorAll(`th,td`).forEach(e=>{e.getAttribute(`fixed`)!==`right`&&e.remove()}):n.querySelectorAll(`[fixed=left], [fixed=right]`).forEach(e=>{e.remove()}),n});if(n.length===0)return;let r=e.querySelector(`tbody.body`);if(!r)return;r.querySelectorAll(`tr`).forEach(e=>e.remove());let i=document.createDocumentFragment();for(let e=0;e<this.#l;e++)n.forEach(e=>i.appendChild(e.cloneNode(!0)));r.appendChild(i),e.classList.contains(`ng-container-body`)&&(this.#r.firstTr=r.querySelector(`tr`))};#b=()=>{let e=this.#n.querySelector(`.ng-sheet-body .ng-container-left table`),t=this.#n.querySelector(`.ng-sheet-body .ng-container-body table`),n=this.#n.querySelector(`.ng-sheet-body .ng-container-right table`);if(t){let r=e?Array.from(e.querySelectorAll(`tbody tr`)):[],i=Array.from(t.querySelectorAll(`tbody tr`)),a=n?Array.from(n.querySelectorAll(`tbody tr`)):[],o=Math.max(r.length,i.length,a.length);for(let e=0;e<o;e++){let t=[r[e]?.getBoundingClientRect().height||0,i[e]?.getBoundingClientRect().height||0,a[e]?.getBoundingClientRect().height||0],n=Math.max(...t);n>0&&(r[e]&&(r[e].style.height=`${n}px`),i[e]&&(i[e].style.height=`${n}px`),a[e]&&(a[e].style.height=`${n}px`))}}};#x=()=>{this.#n&&this.#n instanceof HTMLElement&&(this.#s=new ResizeObserver(e=>{for(let t of e){if(!t.target.classList.contains(`active`))continue;let e=t.contentRect.height;t.contentRect.width>0&&this.#n.isAutoFitCol&&this.#n.autoFit(!0),e>0&&this.#c!==e&&(this.#c=e,this.#_(),this.#o!==null&&(this.#v(),this.refresh()))}}),this.#s.observe(this.#n))}},y=class e{static compile(t){let n=t.cloneNode(!0);return e.resetColIndex(n,n.querySelectorAll(`thead tr`)),e.resetColIndex(n,n.querySelectorAll(`tbody.body tr[grouping="true"]`)),e.resetColIndex(n,n.querySelectorAll(`tbody.body tr:not([grouping="true"])`)),e.resetColIndex(n,n.querySelectorAll(`tfoot tr`)),e.#e(n),n}static recompile(t){return e.resetColIndex(t,t.querySelectorAll(`thead tr`)),e.resetColIndex(t,t.querySelectorAll(`tbody.body tr[grouping="true"]`)),e.resetColIndex(t,t.querySelectorAll(`tbody.body tr:not([grouping="true"])`)),e.resetColIndex(t,t.querySelectorAll(`tfoot tr`)),e.#e(t),t}static#e(e){e.querySelectorAll(`colgroup col`).forEach((t,n)=>{t.setAttribute(`data-col`,n);let r=t.getAttribute(`fixed`);e.querySelectorAll(`[data-col="${n}"]`).forEach(e=>{r?e.setAttribute(`fixed`,r):e.removeAttribute(`fixed`)})})}static resetColIndex(e,t){let n=e.querySelectorAll(`colgroup col`),r=Array.from({length:t.length},()=>Array(n.length).fill(null));t.forEach((e,i)=>{e.dataset.subrow=i;let a=0;e.querySelectorAll(`th, td`).forEach(e=>{for(;a<n.length&&r[i][a]!==null;)a++;e.dataset.col=a;let o=e.rowSpan||1,s=e.colSpan||1;for(let c=0;c<o;c++)for(let o=0;o<s;o++)i+c<t.length&&a+o<n.length&&(r[i+c][a+o]=e);a+=s})})}},b=class{#e;#t={startRow:-1,startCol:-1,endRow:-1,endCol:-1};constructor(e){this.#e=e,this.#r()}#n(e){if(!e)return{dataRow:-1,subRowIndex:-1,matrixRow:-1};let t=parseInt(e.dataset.index,10);if(isNaN(t))return{dataRow:-1,subRowIndex:-1,matrixRow:-1};let n=e.closest(`tbody`),r=Array.from(n.querySelectorAll(`tr`)).filter(e=>parseInt(e.dataset.index,10)===t),i=r.indexOf(e),a=r.length>0?r.length:1;return{dataRow:t,subRowIndex:i,matrixRow:t*a+(i>=0?i:e.sectionRowIndex%a)}}setFocus(e,t){this.#e.querySelectorAll(`tr.selected-start`).forEach(e=>{e.classList.remove(`selected-start`),e.querySelectorAll(`td.selected-start`).forEach(e=>{e.classList.remove(`selected-start`)})});let n=this.#e.querySelector(`.ng-sheet-body-content tr[data-matrix-row="${e}"] td[data-col="${t}"]`);n&&(n.classList.add(`selected-start`),n.closest(`tr`)?.classList.add(`selected-start`))}setRange(e,t,n,r){let i=Math.min(e,n),a=Math.max(e,n),o=Math.min(t,r),s=Math.max(t,r),c=this.#e.querySelectorAll(`.ng-container-left, .ng-container-body, .ng-container-right`),l=!0,u=0;for(;l&&u<5;)l=!1,u++,c.forEach(e=>{Array.from(e.querySelectorAll(`tbody tr`)).filter(e=>e.style.display!==`none`).forEach(e=>{let{matrixRow:t}=this.#n(e);t<0||e.querySelectorAll(`td, th`).forEach(e=>{let n=parseInt(e.dataset.col,10);if(isNaN(n))return;let r=parseInt(e.rowSpan||1,10),c=parseInt(e.colSpan||1,10),u=t+r-1,d=n+c-1;if(u>=i&&t<=a&&d>=o&&n<=s){let e=Math.min(i,t),r=Math.max(a,u),c=Math.min(o,n),f=Math.max(s,d);(e!==i||r!==a||c!==o||f!==s)&&(i=e,a=r,o=c,s=f,l=!0)}})})});this.#t={startRow:i,startCol:o,endRow:a,endCol:s},this.render()}get minRow(){return this.#t.startRow}get maxRow(){return this.#t.endRow}get minCol(){return this.#t.startCol}get maxCol(){return this.#t.endCol}refresh=()=>{this.render()};render=()=>{let{startRow:e,startCol:t,endRow:n,endCol:r}=this.#t,i=this.#e.querySelectorAll(`.ng-container-left, .ng-container-body, .ng-container-right`);i.forEach(e=>{e.querySelectorAll(`.selected, .selected-top, .selected-bottom, .selected-left, .selected-right, .selected-start`).forEach(e=>{e.classList.remove(`selected`,`selected-top`,`selected-bottom`,`selected-left`,`selected-right`,`selected-start`)}),e.querySelectorAll(`tr.selected-start`).forEach(e=>{e.classList.remove(`selected-start`)})}),e<0||t<0||i.forEach(i=>{Array.from(i.querySelectorAll(`tbody tr`)).filter(e=>e.style.display!==`none`).forEach(i=>{let{matrixRow:a}=this.#n(i);a<0||(a>=e&&a<=n&&i.classList.add(`selected`),i.querySelectorAll(`td, th`).forEach(i=>{let o=parseInt(i.dataset.col,10);if(isNaN(o))return;let s=parseInt(i.rowSpan||1,10),c=parseInt(i.colSpan||1,10),l=a+s-1,u=o+c-1;l>=e&&a<=n&&u>=t&&o<=r&&(i.classList.add(`selected`),a<=e&&i.classList.add(`selected-top`),l>=n&&i.classList.add(`selected-bottom`),o<=t&&i.classList.add(`selected-left`),u>=r&&i.classList.add(`selected-right`))}))})})};#r(){let e=this.#e.querySelector(`.ng-sheet-body`);e&&e.addEventListener(`mousedown`,e=>{if(e.button!==0)return;let t=e.target.closest(`td, th`);if(!t||t.dataset.row===void 0||t.dataset.col===void 0)return;this.#e.style.userSelect=`none`,this.#e.style.webkitUserSelect=`none`;let n=t.closest(`tr`),{matrixRow:r}=this.#n(n),i=parseInt(t.dataset.col,10);if(r<0){this.#e.style.userSelect=``,this.#e.style.webkitUserSelect=``;return}this.setFocus(r,i),this.setRange(r,i,r,i);let a=r,o=i,s=e=>{let t=document.elementFromPoint(e.clientX,e.clientY)?.closest(`td, th`);if(!t||!this.#e.contains(t)){let n=this.#e.querySelectorAll(`.ng-sheet-body-content tbody tr td, .ng-sheet-body-content tbody tr:not(.nodata) th`);for(let r of n){let n=r.getBoundingClientRect();if(e.clientX>=n.left&&e.clientX<=n.right&&e.clientY>=n.top&&e.clientY<=n.bottom){t=r;break}}}if(!t||t.dataset.row===void 0||t.dataset.col===void 0)return;let n=t.closest(`tr`),{matrixRow:s}=this.#n(n),c=parseInt(t.dataset.col,10);s<0||(a!==s||o!==c)&&(a=s,o=c,this.setRange(r,i,s,c))},c=()=>{this.#e.style.userSelect=``,this.#e.style.webkitUserSelect=``,document.removeEventListener(`mousemove`,s),document.removeEventListener(`mouseup`,c)};document.addEventListener(`mousemove`,s),document.addEventListener(`mouseup`,c)})}},x=class{#e;#t;#n=null;#r=null;constructor(e){this.#e=e,this.#t=e.getRootNode().host,this.#g()}get currentCell(){return this.#n}set currentCell(e){if(!e)return;this.#n=e,e.focus({preventScroll:!0}),this.#r=e.closest(`tr`);let t=parseInt(this.#r.dataset.matrixRow,10);this.#e.selection.setFocus(t,this.#n.dataset.col)}#i=(e,t)=>{if(t){switch(e.code){case`Tab`:e.shiftKey?this.#p(t)||t.scrollIntoView({inline:`nearest`,block:`nearest`}):this.#m(t)||t.scrollIntoView({inline:`nearest`,block:`nearest`});break;case`ArrowRight`:this.#m(t)||t.scrollIntoView({inline:`nearest`,block:`nearest`});break;case`ArrowLeft`:this.#p(t)||t.scrollIntoView({inline:`nearest`,block:`nearest`})}this.currentCell=t,this.#e.selection.setRange(this.#r.dataset.matrixRow,t.dataset.col,this.#r.dataset.matrixRow,t.dataset.col)}};#a=(e,t)=>{if(t){let n=!1;switch(e.code){case`Enter`:e.shiftKey,this.#f(t)&&(n=!0);break;case`ArrowDown`:this.#f(t)&&(n=!0);break;case`ArrowUp`:this.#d(t)&&(n=!0)}if(n){this.currentCell=t,this.#e.selection.setRange(this.#r.dataset.matrixRow,t.dataset.col,this.#r.dataset.matrixRow,t.dataset.col);return}}let n=parseInt(this.#r.dataset.index,10),r=-1;switch(e.code){case`Enter`:if(e.shiftKey){let e=this.#h();r=Math.max(n-e+0,0)}else r=Math.min(n,this.#e.view.count());break;case`ArrowDown`:r=Math.min(n,this.#e.view.count());break;case`ArrowUp`:let t=this.#h();r=Math.max(n-t+0,0)}if(r<0)return;let i=parseInt(this.#r.dataset.matrixRow,10),a=parseInt(this.#n.dataset.col,10),o=parseInt(this.#n.rowSpan,10)||1;switch(e.code){case`ArrowDown`:i+=o;break;case`ArrowUp`:i--}this.#e.rowManager.scrollToDataRow(r,null,()=>{let e=this.#c(i,a);e&&(this.currentCell=e,this.#e.selection.setRange(this.#r.dataset.matrixRow,e.dataset.col,this.#r.dataset.matrixRow,e.dataset.col))})};moveCell=e=>{if(e.target.tagName===`INPUT`&&([`text`].includes(e.target.type)&&[`ArrowLeft`,`ArrowRight`,`Home`,`End`].includes(e.code)||[`date`,`datetime-local`,`time`,`week`,`month`].includes(e.target.type))||!this.#n||!this.#r)return;let t;switch(e.code){case`Tab`:t=e.shiftKey?this.#s():this.#o();break;case`ArrowRight`:t=this.#o();break;case`ArrowLeft`:t=this.#s();break;case`Enter`:t=e.shiftKey?this.#l():this.#u();break;case`ArrowDown`:t=this.#u();break;case`ArrowUp`:t=this.#l()}e.preventDefault(),[`ArrowLeft`,`ArrowRight`,`Tab`].includes(e.code)?this.#i(e,t):[`Enter`,`ArrowUp`,`ArrowDown`].includes(e.code)&&this.#a(e,t)};#o=()=>{let e=parseInt(this.#n.dataset.col,10),t=parseInt(this.#n.colSpan,10)||1,n=parseInt(this.#r.dataset.index,10),r=parseInt(this.#r.dataset.matrixRow,10),i=e+t,a=this.#e.querySelector(`tbody tr[data-matrix-row="${r}"] td[data-col="${i}"]`);return a||=this.#e.querySelector(`tbody tr[data-index="${n}"] td[data-col="${i}"]`),a};#s=()=>{let e=parseInt(this.#n.dataset.col,10),t=parseInt(this.#r.dataset.index,10),n=parseInt(this.#r.dataset.matrixRow,10),r;for(let i=e-1;i>=0&&(r=this.#e.querySelector(`tbody tr[data-matrix-row="${n}"] td[data-col="${i}"]`),r||=this.#e.querySelector(`tbody tr[data-index="${t}"] td[data-col="${i}"]`),!r);i--);return r};#c=(e,t)=>{let n=this.#e.querySelector(`tbody tr[data-matrix-row="${e}"]`);if(!n)return;let r=parseInt(n.dataset.index,10),i=this.#e.querySelector(`tbody tr[data-matrix-row="${e}"] td[data-col="${t}"]`);return i||(this.#e.querySelectorAll(`tbody tr[data-matrix-row="${e}"] td`).forEach(e=>{let n=parseInt(e.dataset.col,10),r=parseInt(e.colSpan,10)||1;t>=n&&t<n+r&&(i=e)}),i||(i=this.#e.querySelector(`tbody tr[data-index="${r}"] td[data-col="${t}"]`),i||this.#e.querySelectorAll(`tbody tr[data-index="${r}"] td`).forEach(e=>{let n=parseInt(e.dataset.col,10),r=parseInt(e.colSpan,10)||1;t>=n&&t<n+r&&(i=e)}))),i};#l=()=>{let e=parseInt(this.#n.dataset.col,10),t=parseInt(this.#r.dataset.matrixRow,10);return this.#c(t-1,e)};#u=()=>{let e=parseInt(this.#n.dataset.col,10),t=parseInt(this.#r.dataset.matrixRow,10),n=parseInt(this.#n.rowSpan,10)||1;return this.#c(t+n,e)};#d=e=>{let t=this.#e.querySelector(`.ng-sheet-body`);if(!t||!e)return!0;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=t.querySelector(`thead`)?.offsetHeight||0;return n.top>=r.top+i};#f=e=>{let t=this.#e.querySelector(`.ng-sheet-body`);if(!t||!e)return!0;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();return n.bottom<=r.bottom};#p=e=>{let t=this.#e.querySelector(`.ng-container-body`);if(!t||!e)return!0;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();return n.left>=r.left};#m=e=>{let t=this.#e.querySelector(`.ng-container-body`);if(!t||!e)return!0;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();return n.right<=r.right};#h=()=>{let e=this.#e.querySelector(`.ng-sheet-body`),t=e.clientHeight-(e.querySelector(`thead`)?.offsetHeight||0),n=this.#e.rowManager.getRowHeight();return Math.max(1,Math.floor(t/n))};#g(){this.#e.addEventListener(`mousedown`,e=>{if(e.button!==0)return;let t=e.target.closest(`td, th`);t&&t.dataset.index!==void 0&&t.dataset.col!==void 0&&(this.currentCell=t)}),this.#e.addEventListener(`keydown`,e=>{[`Enter`,`Tab`,`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`].includes(e.code)&&this.moveCell(e)})}},S=2,C=class{#e;#t;#n;#r;#i=null;#a=null;#o=null;#s=null;#c=0;#l=0;#u=0;#d=0;#f=0;constructor(e){this.#e=e,this.#t=e.getRootNode().host,this.#n=this.#e.querySelector(`nine-table-col-resizer-panel`),this.#r=this.#n.querySelector(`.resizer-overlay`),this.bindEvents()}destroy(){this.#e.removeEventListener(`pointermove`,this.#h),this.#e.removeEventListener(`pointerdown`,this.#g),this.#e.removeEventListener(`dblclick`,this.#b)}refreshLayout(e=`body`){let t=Array.from(this.#e.querySelectorAll(`.ng-container-${e}`));if(t.length!==0){if(e===`left`||e===`right`||!this.#e.isAutoFitCol&&t[0].querySelector(`table`)?.getAttribute(`auto-fit-col`)!==`true`){let n=t[0].querySelector(`table colgroup`);if(!n)return;let r=0,i={};Array.from(n.querySelectorAll(`col`)).forEach(e=>{let t=e.getAttribute(`data-col`),n=parseInt(e.getAttribute(`width`),10);isNaN(n)||(i[t]=n,r+=n)}),t.forEach(t=>{let n=t.querySelectorAll(`table`);e===`body`?n.forEach(e=>{e.style.width=`${r}px`}):(t.style.flex=`0 0 ${r}px`,t.style.width=`${r}px`,t.style.minWidth=`${r}px`,t.style.maxWidth=`${r}px`,n.forEach(e=>{e.style.width=`${r}px`,e.style.minWidth=`${r}px`,e.style.maxWidth=`${r}px`,Object.entries(i).forEach(([t,n])=>{e.querySelectorAll(`th[data-col="${t}"], td[data-col="${t}"]`).forEach(e=>{e.style.width=`${n}px`,e.style.minWidth=`${n}px`,e.style.maxWidth=`${n}px`})})}))})}else t.forEach(e=>{e.querySelectorAll(`table`).forEach(e=>{})});this.#e.querySelector(`nine-table-hscrollbar`)?.refresh()}}setColumnWidth(e,t,n=null){let r=[];if(r=Array.from(this.#e.querySelectorAll(`table colgroup col[data-col="${e}"]`)),r.length===0)return;let i=r[0].closest(`.ng-container-left, .ng-container-body, .ng-container-right`),a=n||(i?.classList.contains(`ng-container-left`)?`left`:i?.classList.contains(`ng-container-right`)?`right`:`body`);r.forEach(e=>{e.setAttribute(`width`,t),e.style.width=`${t}px`});let o=this.#e.sourceTable?.querySelector(`colgroup col[data-col="${e}"]`);o&&(o.setAttribute(`width`,t),o.style.width=`${t}px`),this.refreshLayout(a),(a===`left`||a===`right`)&&this.refreshLayout(`body`),this.#e.rowManager?.refresh()}#p(e){if(this.#e.isAutoFitCol)return!0;let t=e?.closest(`table`);return!!(t&&t.getAttribute(`auto-fit-col`)===`true`)}bindEvents(){this.#e.addEventListener(`pointermove`,this.#h),this.#e.addDebounseEventListener(`dblclick`,this.#b,`pointerdown`,this.#g)}#m(e){let t=e.closest(`.ng-container-left, .ng-container-body, .ng-container-right`);return t?t.classList.contains(`ng-container-left`)?`left`:t.classList.contains(`ng-container-right`)?`right`:`body`:null}#h=e=>{let t=e.target.closest(`thead`);if(!t)return;let n=e.target.closest(`th, td`);if(t.querySelectorAll(`.resizable-edge`).forEach(e=>{e!==n&&e.classList.remove(`resizable-edge`)}),!n||n.dataset.col===void 0||n.getAttribute(`collapsed`)===`true`)return;let r=n.getBoundingClientRect(),i=e.clientX-r.left,a=i<=S,o=r.width-i<=S;if(a){let e=n.previousElementSibling;if(!e||e.getAttribute(`collapsed`)===`true`){n.classList.remove(`resizable-edge`);return}}a||o?n.classList.add(`resizable-edge`):n.classList.remove(`resizable-edge`)};#g=e=>{if(!e.actualTarget.closest(`thead`))return;let t=e.actualTarget.closest(`th, td`);if(!t||!t.classList.contains(`resizable-edge`))return;e.preventDefault();let n=t.getBoundingClientRect(),r=e.clientX-n.left,i=t;if(r<=S){let e=t.previousElementSibling;if(e&&e.dataset.col!==void 0&&e.getAttribute(`collapsed`)!==`true`)i=e;else if(!t.previousElementSibling)return}this.#s=i,this.#o=this.#m(i);let a=this.#e.querySelector(`.ng-container-${this.#o}`);if(!a)return;let o=parseInt(i.dataset.col,10),s=i.colSpan||1;if(this.#i=o+s-1,this.#p(i)){this.#a=this.#i+1;let e=a.querySelector(`col[data-col="${this.#a}"]`);e?this.#u=parseInt(e.getAttribute(`width`),10)||100:this.#a=null}else this.#a=null;let c=i.getBoundingClientRect(),l=this.#e.getBoundingClientRect();this.#d=c.width,this.#f=c.left-l.left;let u=a.querySelector(`col[data-col="${this.#i}"]`)?.getAttribute(`width`);this.#l=u&&!isNaN(parseInt(u,10))?parseInt(u,10):c.width/s,this.#c=e.clientX,this.#n&&(this.#n.classList.add(`active`),this.#_(e.clientX)),window.addEventListener(`pointermove`,this.#v),window.addEventListener(`pointerup`,this.#y,{once:!0})};#_(e){let t=e-this.#c,n=this.#p(this.#s);if(n&&this.#a!==null){let e=this.#u-16,n=-(this.#l-16);t=Math.max(n,Math.min(t,e))}let r=Math.max(16,this.#l+t),i=e-this.#s.getBoundingClientRect().left;if(n&&this.#a!==null){let e=this.#d+(this.#u-16);i=Math.min(i,e)}let a=Math.max(16,i);this.#n&&(this.#n.style.setProperty(`--col-resizer-tooltip-left`,`${this.#f}px`),this.#n.style.setProperty(`--col-resizer-tooltip-width`,`${a}px`));let o=this.#r?.querySelector(`.size-badge`);o&&(o.textContent=`${Math.round(r)}px`)}#v=e=>{this.#_(e.clientX)};#y=e=>{window.removeEventListener(`pointermove`,this.#v);let t=e.clientX-this.#c,n=this.#p(this.#s),r=0;if(n&&this.#a!==null){let e=Math.max(16,this.#l+t),n=this.#l+this.#u-e;n<16&&(n=16,e=this.#l+this.#u-16),this.setColumnWidth(this.#i,e,this.#o),this.setColumnWidth(this.#a,n,this.#o),r=e}else{let e=Math.max(16,this.#l+t);this.#i!==null&&this.#o&&(this.setColumnWidth(this.#i,e,this.#o),r=e)}if(this.#s){let e=this.#s;e.getAttribute(`collapsed`)!==`true`&&r>20&&(e.dataset.expandWidth=String(r))}this.#n&&(this.#r?.classList.add(`fade-out`),setTimeout(()=>{this.#n.classList.remove(`active`),this.#r?.classList.remove(`fade-out`)},150)),this.#i=null,this.#a=null,this.#o=null,this.#s=null};#b=e=>{let t=e.target.closest(`th, td`);if(!t||!t.classList.contains(`resizable-edge`))return;let n=t.getBoundingClientRect();e.clientX-n.left<=S&&(t=t.previousElementSibling);let r=parseInt(t.dataset.col,10),i=this.#e.querySelector(`tbody.body [data-col="${r}"]`);if(!i||!i.dataset.bind||i.classList.contains(`CELL-RADIO`))return;let a=0;Array.from(i.firstElementChild.children).forEach(e=>{switch(e.tagName){case`SPAN`:a+=8;break;case`DIV`:a+=8;break;case`BUTTON`:a+=32;break;case`SELECT`:a+=32;break;case`INPUT`:switch((e.type||`text`).toLowerCase()){case`checkbox`:case`radio`:a+=12;break;case`button`:case`submit`:case`reset`:case`image`:a+=16;break;case`color`:case`file`:case`range`:a+=24;break;case`hidden`:a+=0;break;default:a+=16}}});let o=this.#t.fields.get().indexOf(i.dataset.bind),s=window.getComputedStyle(i).font||`12px sans-serif`,c=t.innerText||``,l=(nine.measureTextSize(c,s).width||0)+16;this.#t.execute(()=>{this.#e.view.getArray().forEach((e,t)=>{let n=String(i.dataset.expr?this.#t.exprEngine.evaluate(i.dataset.expr,e,t):e.v[o]??``).trim(),r=nine.measureTextSize(n,s);r.width&&r.width>l&&(l=r.width)});let e=Math.max(32,Math.min(400,Math.ceil(l)+a));this.setColumnWidth(i.dataset.col,e,this.#m(t))})}},w=class extends HTMLElement{constructor(){super()}connectedCallback(){this.#e()}#e=()=>{this.innerHTML=`
26
+ `;let e=()=>{let t=this.#t.querySelector(`.ng-sheet-body`);t?(this.#r={container:t,track:this.querySelector(`.scroll-track`),thumb:this.querySelector(`.scroll-thumb`),top:this.querySelector(`.scroll-top`),bottom:this.querySelector(`.scroll-bottom`)},this.#s(),this.refresh()):setTimeout(e,10)};e()}#o=()=>{let e=this.#t.view.getArray(),t=e?e.length:0,n=this.#t.elements?.scrollHolder,r=n&&parseFloat(n.style.height)||0;(!r||r<=0)&&(r=this.#t.sourceTable?.querySelector(`tbody tr[grouping='true']`)&&this.#t.rowManager?body.scrollHeight>body.clientHeight?body.scrollHeight:t*30:t*(this.#t.getRowHeight()||1));let i=15e6,a=r>i,o=1,s=r;return a&&(o=i/r,s=i),{rawContentHeight:r,contentHeight:s,scaleFactor:o,useScaling:a,totalCount:t}};refresh=()=>{if(this.#n||!this.#t||!this.#t.elements||!this.#r)return;let e=this.#r.container,t=this.#r.track,n=this.#r.thumb,{contentHeight:r}=this.#o(),i=(this.#t.querySelector(`thead`)?.offsetHeight||0)+(this.#t.querySelector(`tfoot`)?.offsetHeight||0)+(this.#t.querySelector(`tbody.head`)?.offsetHeight||0),a=this.#t.querySelector(`.ng-sheet-body`).offsetHeight||0,o=a-i,s=this.#t.view.getArray().length,c=this.#t.getRowHeight()*s,l=c>o;if(this.#t.classList.toggle(`vscroll-visible`,l),!l)return;let u=t.clientHeight;if(u<=0)return;let d=Math.max(Math.min(a/c*u,u),20);n.style.height=`${d}px`;let f=e.scrollTop,p=Math.max(r-this.#t.rowManager.getRowHeight(),1),m=0;p>0&&(m=f/p*(u-d));let h=u-d;m<0&&(m=0),m>h&&(m=h),n.style.top=`${m}px`,this.#r.top.disabled=f<=0,this.#r.bottom.disabled=f>=p-1};#s=()=>{this.#r.thumb.addEventListener(`mousedown`,e=>{if(e.button!==0)return;e.stopPropagation(),e.preventDefault(),this.#n=!0,this.#i=e.clientY,this.#a=parseFloat(this.#r.thumb.style.top)||0;let t=this.#r.track.getBoundingClientRect().height-this.#r.thumb.clientHeight,n=e=>{if(!this.#n||t<=0)return;let n=e.clientY-this.#i,r=this.#a+n;r<0&&(r=0),r>t&&(r=t),this.#r.thumb.style.top=`${r}px`;let i=r/t,a=this.#t.getRowHeight(),o=(this.#t.querySelector(`.ng-sheet-body`).offsetHeight||0)-(this.#t.elements.body.thead?.offsetHeight||0)-(this.#t.elements.body.tfoot?.offsetHeight||0)-(this.#t.elements.body.tbody.head.offsetHeight||0),s=Math.floor(o/a),{totalCount:c}=this.#o(),l=Math.floor(i*(c-s+1));this.#t.rowManager.scrollToDataRow(l);let{rawContentHeight:u,contentHeight:d}=this.#o(),f=this.#r.container.scrollTop,p=Math.max(d-this.#t.rowManager.getRowHeight(),0);this.#r.top.disabled=f<=0,this.#r.bottom.disabled=f>=p-1},r=()=>{this.#n=!1,document.removeEventListener(`mousemove`,n),document.removeEventListener(`mouseup`,r)};document.addEventListener(`mousemove`,n),document.addEventListener(`mouseup`,r)}),this.#r.track.addEventListener(`mousedown`,e=>{if(e.button!==0||e.target===this.#r.thumb)return;let t=this.#r.track.getBoundingClientRect(),n=this.#r.thumb.clientHeight,r=this.#r.track.clientHeight-n;if(r>0){let i=e.clientY-t.top-n/2,a=Math.max(0,Math.min(1,i/r)),{totalCount:o}=this.#o(),s=Math.max(0,Math.min(Math.floor(a*(o-1)),o-1));s>=0&&this.#t.rowManager&&typeof this.#t.rowManager.scrollToDataRow==`function`&&this.#t.rowManager.scrollToDataRow(s,`top`)}this.refresh()});let e=null,t=t=>{if(e)return;let n=()=>{let e=this.#t.querySelector(`tbody.body tr`);if(!e||e.dataset.row===void 0||t===`down`&&this.#t.isLastRow())return;let n=parseInt(e.dataset.row,10),r=t===`down`?n+1:Math.max(0,n-1);this.#t.rowManager.scrollToDataRow(r,null,()=>{this.refresh()})};n(),e=setInterval(n,200)},n=()=>{e&&=(clearInterval(e),null)};this.#r.top.addEventListener(`mousedown`,e=>{e.button===0&&t(`up`)}),this.#r.bottom.addEventListener(`mousedown`,e=>{e.button===0&&t(`down`)}),document.addEventListener(`mouseup`,n),this.#r.top.addEventListener(`mouseleave`,n),this.#r.bottom.addEventListener(`mouseleave`,n)}};customElements.get(`nine-table-vscrollbar`)||customElements.define(`nine-table-vscrollbar`,m);var h={ID:0,DEPTH:1,NAME:2,CHILDREN:3},g=class{#e;#t;#n=[];#r=new Map;#i=!1;constructor(e){this.#e=e,this.#t=this.#e.getRootNode().host}get columns(){return this.#n}get groupMap(){return this.#r}initialize=()=>{let e=[],t=this.#e.sourceTable;t&&t.querySelectorAll(`tbody tr[grouping="true"]`).forEach(t=>{let n=t.querySelector(`[cell-type="tree"]`);n&&n.dataset.bind&&e.push(n.dataset.bind)}),this.#n=e};apply(){if(this.#i)return;this.#i=!0;let e=[],t=this.#e.sourceTable;t&&t.querySelectorAll(`tbody tr[grouping="true"]`).forEach(t=>{let n=t.querySelector(`[cell-type="tree"]`);n&&n.dataset.bind&&e.push(n.dataset.bind)}),this.#n=e,this.#i=!1,this.#e.scrollToY(0),this.#e.view.refresh()}clear(){this.#n=[],this.#r.clear(),this.#i=!1,this.#e.scrollToY(0),this.#e.view.refresh()}setGroupMap(e){this.#r=e}getChildrenRowIds(e){return this.#r.get(e)||[]}getChildrenRecords(e){let t=this.getChildrenRowIds(e),n=this.#t.data;return t.map(e=>n.getArray(e)).filter(Boolean)}},_=class e{static apply(t,n=[],r=[]){if(!n||n.length===0)return{headers:[],renderItems:[],groupMap:new Map};let i=t.filter(e=>!e.__ng?.deleted),a=new Map,o=e.#t(i,n,r),s=[],c=[];return e.#e(o,0,n,s,c,a,``),{headers:s,renderItems:c,groupMap:a}}static#e(t,n,r,i,a,o,s){let c=0,l=n===r.length-1;for(let[u,d]of t.entries()){let t=s?`${s}_${c++}`:`g_${c++}`,f=e.#n(d);o.set(t,f);let p=[];p[h.ID]=t,p[h.DEPTH]=n,p[h.NAME]=u,p[h.CHILDREN]=f,p.__isGroupHeader=!0,p.__groupId=t,i.push(p),a.push({type:`group`,record:p,groupId:t}),!l&&d instanceof Map?e.#e(d,n+1,r,i,a,o,t):e.#r(d).forEach(e=>{e.__isGroupHeader=!1,e.__groupId=t,i.push(e),a.push({type:`data`,record:e,groupId:t})})}}static#t(t,n,r){let i=r.indexOf(n[0]),a=n.slice(1),o=new Map;if(t.forEach(e=>{let t=i>=0?e.v[i]:`(Unknown)`;o.has(t)||o.set(t,[]),o.get(t).push(e)}),a.length>0){let t=new Map;for(let[n,i]of o.entries())t.set(n,e.#t(i,a,r));return t}return o}static#n(t){let n=[];if(t instanceof Map)for(let r of t.values())n=n.concat(e.#n(r));else Array.isArray(t)&&(n=n.concat(t.map(e=>e.__ng?.rowid??e.m?._?.[0])));return n}static#r(t){let n=[];if(t instanceof Map)for(let r of t.values())n=n.concat(e.#r(r));else Array.isArray(t)&&(n=n.concat(t));return n}},v=class{#e=3;#t;#n;#r;#i=new Map;#a=[];#o=null;#s=null;#c=0;#l;#u=!1;#d=!1;constructor(e){this.#t=e.getRootNode().host,this.#n=e,this.#x()}getRowHeight(){return this.#a.reduce((e,t)=>e+t,0)}refresh=(e=!1)=>{if(!this.#n.classList.contains(`active`))return;let t=this.#n.querySelector(`.ng-sheet-body`);t&&((!this.#o||this.#o<=0)&&(this.#g(),this.#o&&this.#o>0&&this.#v()),this.#f(t.scrollTop,e),this.#n.querySelector(`nine-table-vscrollbar`)?.refresh())};#f=(e,t=!1)=>{if(this.#d){this.#p(e,t);return}let n=this.#o;if(!n||n<=0)return;let r=this.#n.view.getArray(),a=r.length;if(a===0){this.#n.elements.scrollHolder.style.height=`0px`;return}let o=this.#n.templateLength,s=(this.#n.elements.body.thead?.offsetHeight||0)+(this.#n.elements.body.tfoot?.offsetHeight||0)+this.#n.elements.body.tbody.head.offsetHeight,c=this.#n.querySelector(`.ng-sheet-body`).offsetHeight||0,l=Math.max(a*n-(c-s-n),0),u=15e6,d=l>u,f=1,p=l;d&&(f=u/l,p=u),this.#n.elements.scrollHolder.style.height=`${p}px`;let m=d?e/f:e,h=Math.max(0,a-1),g=Math.min(m,l),_=Math.max(0,Math.min(Math.floor(g/n),h));this.#n.elements.left.tbody.body.style.transform=this.#n.elements.body.tbody.body.style.transform=this.#n.elements.right.tbody.body.style.transform=`translate3d(0px, -${g%n}px, 0px)`;let v=this.#r.firstTr,y=v&&v.dataset.row!==void 0?parseInt(v.dataset.row,10):-1;(t||y!==_)&&([this.#n.elements.left.tbody.body,this.#n.elements.body.tbody.body,this.#n.elements.right.tbody.body].forEach((e,t)=>{e&&e.querySelectorAll(`tbody.body tr`).forEach((e,t)=>{let n=_+Math.floor(t/o);if(n>=a){e.style.display=`none`,e.dataset.matrixRow=null,e.dataset.row=null,e.dataset.index=null;return}let s=r[n];if(!s){e.style.display=`none`;return}let c=s.m._[i.META.INDEX.ROWID];e.style.display=``,this.#h(e,s,c,n)})}),this.#n.selection.refresh())};#p=(e,t=!1)=>{let n=this.#n.view.getArray()||[],r=n.length;if(r===0){this.#n.elements.scrollHolder.style.height=`0px`;return}let i=this.#n.querySelector(`.ng-sheet-body .ng-sheet-body-content`),a=this.#n.templateLength||1,o=e=>{if(e.type===`group`){let t=e.record[h.DEPTH]||0;return this.#a[t]||this.#o/a}{let e=0,t=this.#n.templateLength||1,n=0;for(let e=0;e<t-1;e++)n+=this.#a[e]||0;return e=this.#o-n,e>0?e:this.#o}},s=0,c=Array(r);for(let e=0;e<r;e++){let t=o(n[e]);c[e]=t,s+=t}this.#n.elements.scrollHolder.style.height=`${s}px`;let l=this.#n.clientHeight,u=0,d=0;for(let t=0;t<r;t++){let n=c[t];if(u+n>e){d=t;break}u+=n,d=t}let f=e-u;i&&i.querySelectorAll(`tbody`).forEach(e=>{e.style.top=`-${Math.max(0,f)}px`});let p=this.#r.firstTr,m=p&&p.dataset.virtualIndex!==void 0?parseInt(p.dataset.virtualIndex,10):-1;if(!t&&m===d)return;let g=Math.ceil(l/(this.#o/a)),_=(this.#n.grouping.columns?.length||1)*15,v=d,y=Math.min(r,d+g+_),b=n.slice(v,y);[`.ng-container-body`,`.ng-container-left`,`.ng-container-right`].forEach(e=>{let t=this.#n.querySelector(`.ng-sheet-body ${e}`);if(!t)return;let r=Array.from(t.querySelectorAll(`tbody.body tr`));for(let e=0;e<r.length;e+=a){let t=Math.floor(e/a),i=b[t],o=r.slice(e,e+a);if(!i||t>=b.length){o.forEach(e=>{e.style.display=`none`,e.dataset.matrixRow=null,e.dataset.row=null,e.dataset.index=null});continue}let s=d+t;o.forEach((e,r)=>{let a=d+t;e.dataset.virtualIndex=a,e.dataset.row=i.type===`data`?s:``;let o=e.getAttribute(`grouping`)===`true`;if(i.type===`group`)o&&r===i.record[h.DEPTH]?(e.style.display=``,this.#m(e,n,i.record,a)):(e.style.display=`none`,e.dataset.matrixRow=null,e.dataset.row=null,e.dataset.index=null);else if(o)e.style.display=`none`,e.dataset.matrixRow=null,e.dataset.row=null,e.dataset.index=null;else{e.style.display=``;let t=i.record.m?.rowid??0;this.#h(e,i.record,t,a)}})}}),this.#n.selection.refresh()};#m=(e,t,n,r)=>{let i=this.#n.templateLength||1,a=parseInt(e.dataset.subrow,10)||0,o=r*i+a,s=n[h.CHILDREN],c=this.#t.data.getArray(),l=s?s.map(e=>c[e]).filter(Boolean):[];e.dataset.virtualIndex=r,e.dataset.row=``,e.dataset.matrixRow=o,e.data=l,e.dataset.groupId=n[h.ID],Array.from(e.cells).forEach(e=>{e.dataset.row=r;let t=Array.from(e.children).find(e=>e.tagName.toLowerCase().startsWith(`cell-`)||typeof e.refresh==`function`);t!==void 0&&typeof t.refresh==`function`&&t?.refresh()})};#h=(e,t,n,r)=>{let i=this.#n.templateLength||1,a=parseInt(e.dataset.subrow,10)||0,o=r*i+a;e.dataset.index=r,e.dataset.row=n,e.dataset.matrixRow=o,e.data=t,Array.from(e.cells).forEach(e=>{e.dataset.index=r,e.dataset.row=n,Array.from(e.children).find(e=>e.tagName.toLowerCase().startsWith(`cell-`)&&typeof e.refresh==`function`)?.refresh()})};initialize=()=>{this.#d=!!this.#n.sourceTable.querySelector(`tbody tr[grouping='true']`),this.#o=null,this.#i.clear(),this.#r={scrollTables:this.#n.querySelectorAll(`.ng-sheet-body table`),firstTr:this.#n.querySelector(`.ng-sheet-body .ng-container-body tbody.body tr`)},[`.ng-container-body`,`.ng-container-left`,`.ng-container-right`].forEach(e=>{let t=this.#n.querySelector(`.ng-sheet-body ${e}`);if(!t)return;let n=t.querySelector(`table`);if(!n)return;let r=n.querySelector(`tbody.body`);if(!r)return;let i=Array.from(r.querySelectorAll(`tr`)).map(e=>e.cloneNode(!0));this.#i.set(e,i)});let e=this.#n.querySelector(`.ng-sheet-body`);e&&(this.#c=e.clientHeight,this.#g(),this.#v(),this.#f(e.scrollTop,!0),e.addEventListener(`scroll`,t=>{if(this.#u)return;let n=this.#o||0;(this.#n.view.getArray()?.length||0)*n<=e.clientHeight||(this.#f(e.scrollTop),this.#n.querySelector(`nine-table-vscrollbar`).refresh())},{passive:!0}))};scrollToDataRow(e,t=`top`,n){let r=this.#n.querySelector(`.ng-sheet-body`),i=this.#n.view.getArray()?.length||0,a=Math.max(0,Math.min(e,i-1)),o=0;if(this.#d){let e=Math.max(r.scrollHeight-r.clientHeight,1);o=a/Math.max(i-1,1)*e}else{let e=this.#o,t=a*e,n=(this.#n.elements.body.thead?.offsetHeight||0)+(this.#n.elements.body.tfoot?.offsetHeight||0)+this.#n.elements.body.tbody.head.offsetHeight,s=r.offsetHeight||0,c=Math.max(i*e+n-s,0),l=15e6,u=c>l,d=1;u&&(d=l/c),o=t*d}this.#u=!0,r.scrollTop=o,this.#f(o),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.#u=!1,typeof n==`function`&&n()})})}destroy=()=>{this.#s&&=(this.#s.disconnect(),null)};#g=()=>{if(!this.#n.classList.contains(`active`)||!this.#n.sourceTable)return;let e=this.#n.sourceTable?.querySelectorAll(`tbody.body tr`),t=this.#n.querySelector(`.ng-sheet-body .ng-container-body tbody.body`);t.querySelectorAll(`tr`).forEach(e=>e.remove());let n=document.createDocumentFragment();e.forEach(e=>n.appendChild(e.cloneNode(!0))),t.appendChild(n);let r=t.querySelectorAll(`tr`);this.#a=[],r.forEach(e=>{this.#a.push(Math.max(e.offsetHeight,24))}),r.forEach(e=>e.remove()),this.#o=this.#a.reduce((e,t)=>e+t,0),this.#_()};#_=()=>{if(this.#c>0&&this.#o>0){let e=Math.ceil(this.#c/this.#o),t=this.#e;if(this.#d&&this.#n.grouping){let e=this.#n.grouping.columns?.length||1;t+=e*15}this.#l=e+t}};#v=()=>{[`.ng-container-body`,`.ng-container-left`,`.ng-container-right`].forEach(e=>{let t=this.#n.querySelector(`.ng-sheet-body ${e}`);t&&t.querySelector(`tbody`)&&this.#y(t)}),this.#b()};#y=e=>{let t=null;e.classList.contains(`ng-container-left`)?t=`left`:e.classList.contains(`ng-container-right`)&&(t=`right`);let n=Array.from(this.#n.sourceTable.querySelectorAll(`tbody.body tr`)).map(e=>{let n=e.cloneNode(!0);return t===`left`?n.querySelectorAll(`th,td`).forEach(e=>{e.getAttribute(`fixed`)!==`left`&&e.remove()}):t===`right`?n.querySelectorAll(`th,td`).forEach(e=>{e.getAttribute(`fixed`)!==`right`&&e.remove()}):n.querySelectorAll(`[fixed=left], [fixed=right]`).forEach(e=>{e.remove()}),n});if(n.length===0)return;let r=e.querySelector(`tbody.body`);if(!r)return;r.querySelectorAll(`tr`).forEach(e=>e.remove());let i=document.createDocumentFragment();for(let e=0;e<this.#l;e++)n.forEach(e=>i.appendChild(e.cloneNode(!0)));r.appendChild(i),e.classList.contains(`ng-container-body`)&&(this.#r.firstTr=r.querySelector(`tr`))};#b=()=>{let e=this.#n.querySelector(`.ng-sheet-body .ng-container-left table`),t=this.#n.querySelector(`.ng-sheet-body .ng-container-body table`),n=this.#n.querySelector(`.ng-sheet-body .ng-container-right table`);if(t){let r=e?Array.from(e.querySelectorAll(`tbody tr`)):[],i=Array.from(t.querySelectorAll(`tbody tr`)),a=n?Array.from(n.querySelectorAll(`tbody tr`)):[],o=Math.max(r.length,i.length,a.length);for(let e=0;e<o;e++){let t=[r[e]?.getBoundingClientRect().height||0,i[e]?.getBoundingClientRect().height||0,a[e]?.getBoundingClientRect().height||0],n=Math.max(...t);n>0&&(r[e]&&(r[e].style.height=`${n}px`),i[e]&&(i[e].style.height=`${n}px`),a[e]&&(a[e].style.height=`${n}px`))}}};#x=()=>{this.#n&&this.#n instanceof HTMLElement&&(this.#s=new ResizeObserver(e=>{for(let t of e){if(!t.target.classList.contains(`active`))continue;let e=t.contentRect.height;t.contentRect.width>0&&this.#n.isAutoFitCol&&this.#n.autoFit(!0),e>0&&this.#c!==e&&(this.#c=e,this.#_(),this.#o!==null&&(this.#v(),this.refresh()))}}),this.#s.observe(this.#n))}},y=class e{static compile(t){let n=t.cloneNode(!0);return e.resetColIndex(n,n.querySelectorAll(`thead tr`)),e.resetColIndex(n,n.querySelectorAll(`tbody.body tr[grouping="true"]`)),e.resetColIndex(n,n.querySelectorAll(`tbody.body tr:not([grouping="true"])`)),e.resetColIndex(n,n.querySelectorAll(`tfoot tr`)),e.#e(n),n}static recompile(t){return e.resetColIndex(t,t.querySelectorAll(`thead tr`)),e.resetColIndex(t,t.querySelectorAll(`tbody.body tr[grouping="true"]`)),e.resetColIndex(t,t.querySelectorAll(`tbody.body tr:not([grouping="true"])`)),e.resetColIndex(t,t.querySelectorAll(`tfoot tr`)),e.#e(t),t}static#e(e){e.querySelectorAll(`colgroup col`).forEach((t,n)=>{t.setAttribute(`data-col`,n);let r=t.getAttribute(`fixed`);e.querySelectorAll(`[data-col="${n}"]`).forEach(e=>{r?e.setAttribute(`fixed`,r):e.removeAttribute(`fixed`)})})}static resetColIndex(e,t){let n=e.querySelectorAll(`colgroup col`),r=Array.from({length:t.length},()=>Array(n.length).fill(null));t.forEach((e,i)=>{e.dataset.subrow=i;let a=0;e.querySelectorAll(`th, td`).forEach(e=>{for(;a<n.length&&r[i][a]!==null;)a++;e.dataset.col=a;let o=e.rowSpan||1,s=e.colSpan||1;for(let c=0;c<o;c++)for(let o=0;o<s;o++)i+c<t.length&&a+o<n.length&&(r[i+c][a+o]=e);a+=s})})}},b=class{#e;#t={startRow:-1,startCol:-1,endRow:-1,endCol:-1};constructor(e){this.#e=e,this.#r()}#n(e){if(!e)return{dataRow:-1,subRowIndex:-1,matrixRow:-1};let t=parseInt(e.dataset.index,10);if(isNaN(t))return{dataRow:-1,subRowIndex:-1,matrixRow:-1};let n=e.closest(`tbody`),r=Array.from(n.querySelectorAll(`tr`)).filter(e=>parseInt(e.dataset.index,10)===t),i=r.indexOf(e),a=r.length>0?r.length:1;return{dataRow:t,subRowIndex:i,matrixRow:t*a+(i>=0?i:e.sectionRowIndex%a)}}setFocus(e,t){this.#e.querySelectorAll(`tr.selected-start`).forEach(e=>{e.classList.remove(`selected-start`),e.querySelectorAll(`td.selected-start`).forEach(e=>{e.classList.remove(`selected-start`)})});let n=this.#e.querySelector(`.ng-sheet-body-content tr[data-matrix-row="${e}"] td[data-col="${t}"]`);n&&(n.classList.add(`selected-start`),n.closest(`tr`)?.classList.add(`selected-start`))}setRange(e,t,n,r){let i=Math.min(e,n),a=Math.max(e,n),o=Math.min(t,r),s=Math.max(t,r),c=this.#e.querySelectorAll(`.ng-container-left, .ng-container-body, .ng-container-right`),l=!0,u=0;for(;l&&u<5;)l=!1,u++,c.forEach(e=>{Array.from(e.querySelectorAll(`tbody tr`)).filter(e=>e.style.display!==`none`).forEach(e=>{let{matrixRow:t}=this.#n(e);t<0||e.querySelectorAll(`td, th`).forEach(e=>{let n=parseInt(e.dataset.col,10);if(isNaN(n))return;let r=parseInt(e.rowSpan||1,10),c=parseInt(e.colSpan||1,10),u=t+r-1,d=n+c-1;if(u>=i&&t<=a&&d>=o&&n<=s){let e=Math.min(i,t),r=Math.max(a,u),c=Math.min(o,n),f=Math.max(s,d);(e!==i||r!==a||c!==o||f!==s)&&(i=e,a=r,o=c,s=f,l=!0)}})})});this.#t={startRow:i,startCol:o,endRow:a,endCol:s},this.render()}get minRow(){return this.#t.startRow}get maxRow(){return this.#t.endRow}get minCol(){return this.#t.startCol}get maxCol(){return this.#t.endCol}refresh=()=>{this.render()};render=()=>{let{startRow:e,startCol:t,endRow:n,endCol:r}=this.#t,i=this.#e.querySelectorAll(`.ng-container-left, .ng-container-body, .ng-container-right`);i.forEach(e=>{e.querySelectorAll(`.selected, .selected-top, .selected-bottom, .selected-left, .selected-right, .selected-start`).forEach(e=>{e.classList.remove(`selected`,`selected-top`,`selected-bottom`,`selected-left`,`selected-right`,`selected-start`)}),e.querySelectorAll(`tr.selected-start`).forEach(e=>{e.classList.remove(`selected-start`)})}),e<0||t<0||i.forEach(i=>{Array.from(i.querySelectorAll(`tbody tr`)).filter(e=>e.style.display!==`none`).forEach(i=>{let{matrixRow:a}=this.#n(i);a<0||(a>=e&&a<=n&&i.classList.add(`selected`),i.querySelectorAll(`td, th`).forEach(i=>{let o=parseInt(i.dataset.col,10);if(isNaN(o))return;let s=parseInt(i.rowSpan||1,10),c=parseInt(i.colSpan||1,10),l=a+s-1,u=o+c-1;l>=e&&a<=n&&u>=t&&o<=r&&(i.classList.add(`selected`),a<=e&&i.classList.add(`selected-top`),l>=n&&i.classList.add(`selected-bottom`),o<=t&&i.classList.add(`selected-left`),u>=r&&i.classList.add(`selected-right`))}))})})};#r(){let e=this.#e.querySelector(`.ng-sheet-body`);e&&e.addEventListener(`mousedown`,e=>{if(e.button!==0)return;let t=e.target.closest(`td, th`);if(!t||t.dataset.row===void 0||t.dataset.col===void 0)return;this.#e.style.userSelect=`none`,this.#e.style.webkitUserSelect=`none`;let n=t.closest(`tr`),{matrixRow:r}=this.#n(n),i=parseInt(t.dataset.col,10);if(r<0){this.#e.style.userSelect=``,this.#e.style.webkitUserSelect=``;return}this.setFocus(r,i),this.setRange(r,i,r,i);let a=r,o=i,s=e=>{let t=document.elementFromPoint(e.clientX,e.clientY)?.closest(`td, th`);if(!t||!this.#e.contains(t)){let n=this.#e.querySelectorAll(`.ng-sheet-body-content tbody tr td, .ng-sheet-body-content tbody tr:not(.nodata) th`);for(let r of n){let n=r.getBoundingClientRect();if(e.clientX>=n.left&&e.clientX<=n.right&&e.clientY>=n.top&&e.clientY<=n.bottom){t=r;break}}}if(!t||t.dataset.row===void 0||t.dataset.col===void 0)return;let n=t.closest(`tr`),{matrixRow:s}=this.#n(n),c=parseInt(t.dataset.col,10);s<0||(a!==s||o!==c)&&(a=s,o=c,this.setRange(r,i,s,c))},c=()=>{this.#e.style.userSelect=``,this.#e.style.webkitUserSelect=``,document.removeEventListener(`mousemove`,s),document.removeEventListener(`mouseup`,c)};document.addEventListener(`mousemove`,s),document.addEventListener(`mouseup`,c)})}},x=class{#e;#t;#n=null;#r=null;constructor(e){this.#e=e,this.#t=e.getRootNode().host,this.#g()}get currentCell(){return this.#n}set currentCell(e){if(!e)return;this.#n=e,e.focus({preventScroll:!0}),this.#r=e.closest(`tr`);let t=parseInt(this.#r.dataset.matrixRow,10);this.#e.selection.setFocus(t,this.#n.dataset.col)}#i=(e,t)=>{if(t){switch(e.code){case`Tab`:e.shiftKey?this.#p(t)||t.scrollIntoView({inline:`nearest`,block:`nearest`}):this.#m(t)||t.scrollIntoView({inline:`nearest`,block:`nearest`});break;case`ArrowRight`:this.#m(t)||t.scrollIntoView({inline:`nearest`,block:`nearest`});break;case`ArrowLeft`:this.#p(t)||t.scrollIntoView({inline:`nearest`,block:`nearest`})}this.currentCell=t,this.#e.selection.setRange(this.#r.dataset.matrixRow,t.dataset.col,this.#r.dataset.matrixRow,t.dataset.col)}};#a=(e,t)=>{if(t){let n=!1;switch(e.code){case`Enter`:e.shiftKey,this.#f(t)&&(n=!0);break;case`ArrowDown`:this.#f(t)&&(n=!0);break;case`ArrowUp`:this.#d(t)&&(n=!0)}if(n){this.currentCell=t,this.#e.selection.setRange(this.#r.dataset.matrixRow,t.dataset.col,this.#r.dataset.matrixRow,t.dataset.col);return}}let n=parseInt(this.#r.dataset.index,10),r=-1;switch(e.code){case`Enter`:if(e.shiftKey){let e=this.#h();r=Math.max(n-e+0,0)}else r=Math.min(n,this.#e.view.count());break;case`ArrowDown`:r=Math.min(n,this.#e.view.count());break;case`ArrowUp`:let t=this.#h();r=Math.max(n-t+0,0)}if(r<0)return;let i=parseInt(this.#r.dataset.matrixRow,10),a=parseInt(this.#n.dataset.col,10),o=parseInt(this.#n.rowSpan,10)||1;switch(e.code){case`ArrowDown`:i+=o;break;case`ArrowUp`:i--}this.#e.rowManager.scrollToDataRow(r,null,()=>{let e=this.#c(i,a);e&&(this.currentCell=e,this.#e.selection.setRange(this.#r.dataset.matrixRow,e.dataset.col,this.#r.dataset.matrixRow,e.dataset.col))})};moveCell=e=>{if(e.target.tagName===`INPUT`&&([`text`].includes(e.target.type)&&[`ArrowLeft`,`ArrowRight`,`Home`,`End`].includes(e.code)||[`date`,`datetime-local`,`time`,`week`,`month`].includes(e.target.type))||!this.#n||!this.#r)return;let t;switch(e.code){case`Tab`:t=e.shiftKey?this.#s():this.#o();break;case`ArrowRight`:t=this.#o();break;case`ArrowLeft`:t=this.#s();break;case`Enter`:t=e.shiftKey?this.#l():this.#u();break;case`ArrowDown`:t=this.#u();break;case`ArrowUp`:t=this.#l()}e.preventDefault(),[`ArrowLeft`,`ArrowRight`,`Tab`].includes(e.code)?this.#i(e,t):[`Enter`,`ArrowUp`,`ArrowDown`].includes(e.code)&&this.#a(e,t)};#o=()=>{let e=parseInt(this.#n.dataset.col,10),t=parseInt(this.#n.colSpan,10)||1,n=parseInt(this.#r.dataset.index,10),r=parseInt(this.#r.dataset.matrixRow,10),i=e+t,a=this.#e.querySelector(`tbody tr[data-matrix-row="${r}"] td[data-col="${i}"]`);return a||=this.#e.querySelector(`tbody tr[data-index="${n}"] td[data-col="${i}"]`),a};#s=()=>{let e=parseInt(this.#n.dataset.col,10),t=parseInt(this.#r.dataset.index,10),n=parseInt(this.#r.dataset.matrixRow,10),r;for(let i=e-1;i>=0&&(r=this.#e.querySelector(`tbody tr[data-matrix-row="${n}"] td[data-col="${i}"]`),r||=this.#e.querySelector(`tbody tr[data-index="${t}"] td[data-col="${i}"]`),!r);i--);return r};#c=(e,t)=>{let n=this.#e.querySelector(`tbody tr[data-matrix-row="${e}"]`);if(!n)return;let r=parseInt(n.dataset.index,10),i=this.#e.querySelector(`tbody tr[data-matrix-row="${e}"] td[data-col="${t}"]`);return i||(this.#e.querySelectorAll(`tbody tr[data-matrix-row="${e}"] td`).forEach(e=>{let n=parseInt(e.dataset.col,10),r=parseInt(e.colSpan,10)||1;t>=n&&t<n+r&&(i=e)}),i||(i=this.#e.querySelector(`tbody tr[data-index="${r}"] td[data-col="${t}"]`),i||this.#e.querySelectorAll(`tbody tr[data-index="${r}"] td`).forEach(e=>{let n=parseInt(e.dataset.col,10),r=parseInt(e.colSpan,10)||1;t>=n&&t<n+r&&(i=e)}))),i};#l=()=>{let e=parseInt(this.#n.dataset.col,10),t=parseInt(this.#r.dataset.matrixRow,10);return this.#c(t-1,e)};#u=()=>{let e=parseInt(this.#n.dataset.col,10),t=parseInt(this.#r.dataset.matrixRow,10),n=parseInt(this.#n.rowSpan,10)||1;return this.#c(t+n,e)};#d=e=>{let t=this.#e.querySelector(`.ng-sheet-body`);if(!t||!e)return!0;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=t.querySelector(`thead`)?.offsetHeight||0;return n.top>=r.top+i};#f=e=>{let t=this.#e.querySelector(`.ng-sheet-body`);if(!t||!e)return!0;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();return n.bottom<=r.bottom};#p=e=>{let t=this.#e.querySelector(`.ng-container-body`);if(!t||!e)return!0;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();return n.left>=r.left};#m=e=>{let t=this.#e.querySelector(`.ng-container-body`);if(!t||!e)return!0;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();return n.right<=r.right};#h=()=>{let e=this.#e.querySelector(`.ng-sheet-body`),t=e.clientHeight-(e.querySelector(`thead`)?.offsetHeight||0),n=this.#e.rowManager.getRowHeight();return Math.max(1,Math.floor(t/n))};#g(){this.#e.addEventListener(`mousedown`,e=>{if(e.button!==0)return;let t=e.target.closest(`td, th`);t&&t.dataset.index!==void 0&&t.dataset.col!==void 0&&(this.currentCell=t)}),this.#e.addEventListener(`keydown`,e=>{[`Enter`,`Tab`,`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`].includes(e.code)&&this.moveCell(e)})}},S=2,C=class{#e;#t;#n;#r;#i=null;#a=null;#o=null;#s=null;#c=0;#l=0;#u=0;#d=0;#f=0;constructor(e){this.#e=e,this.#t=e.getRootNode().host,this.#n=this.#e.querySelector(`nine-table-col-resizer-panel`),this.#r=this.#n.querySelector(`.resizer-overlay`),this.bindEvents()}destroy(){this.#e.removeEventListener(`pointermove`,this.#h),this.#e.removeEventListener(`pointerdown`,this.#g),this.#e.removeEventListener(`dblclick`,this.#b)}refreshLayout(e=`body`){let t=Array.from(this.#e.querySelectorAll(`.ng-container-${e}`));if(t.length!==0){if(e===`left`||e===`right`||!this.#e.isAutoFitCol&&t[0].querySelector(`table`)?.getAttribute(`auto-fit-col`)!==`true`){let n=t[0].querySelector(`table colgroup`);if(!n)return;let r=0,i={};Array.from(n.querySelectorAll(`col`)).forEach(e=>{let t=e.getAttribute(`data-col`),n=parseInt(e.getAttribute(`width`),10);isNaN(n)||(i[t]=n,r+=n)}),t.forEach(t=>{let n=t.querySelectorAll(`table`);e===`body`?n.forEach(e=>{e.style.width=`${r}px`}):(t.style.flex=`0 0 ${r}px`,t.style.width=`${r}px`,t.style.minWidth=`${r}px`,t.style.maxWidth=`${r}px`,n.forEach(e=>{e.style.width=`${r}px`,e.style.minWidth=`${r}px`,e.style.maxWidth=`${r}px`,Object.entries(i).forEach(([t,n])=>{e.querySelectorAll(`th[data-col="${t}"], td[data-col="${t}"]`).forEach(e=>{e.style.width=`${n}px`,e.style.minWidth=`${n}px`,e.style.maxWidth=`${n}px`})})}))})}else t.forEach(e=>{e.querySelectorAll(`table`).forEach(e=>{})});this.#e.querySelector(`nine-table-hscrollbar`)?.refresh()}}setColumnWidth(e,t,n=null){let r=[];if(r=Array.from(this.#e.querySelectorAll(`table colgroup col[data-col="${e}"]`)),r.length===0)return;let i=r[0].closest(`.ng-container-left, .ng-container-body, .ng-container-right`),a=n||(i?.classList.contains(`ng-container-left`)?`left`:i?.classList.contains(`ng-container-right`)?`right`:`body`);r.forEach(e=>{e.setAttribute(`width`,t),e.style.width=`${t}px`});let o=this.#e.sourceTable?.querySelector(`colgroup col[data-col="${e}"]`);o&&(o.setAttribute(`width`,t),o.style.width=`${t}px`),this.refreshLayout(a),(a===`left`||a===`right`)&&this.refreshLayout(`body`),this.#e.rowManager?.refresh()}#p(e){if(this.#e.isAutoFitCol)return!0;let t=e?.closest(`table`);return!!(t&&t.getAttribute(`auto-fit-col`)===`true`)}bindEvents(){this.#e.addEventListener(`pointermove`,this.#h),this.#e.addDebounseEventListener(`dblclick`,this.#b,`pointerdown`,this.#g)}#m(e){let t=e.closest(`.ng-container-left, .ng-container-body, .ng-container-right`);return t?t.classList.contains(`ng-container-left`)?`left`:t.classList.contains(`ng-container-right`)?`right`:`body`:null}#h=e=>{let t=e.target.closest(`thead`);if(!t)return;let n=e.target.closest(`th, td`);if(t.querySelectorAll(`.resizable-edge`).forEach(e=>{e!==n&&e.classList.remove(`resizable-edge`)}),!n||n.dataset.col===void 0||n.getAttribute(`collapsed`)===`true`)return;let r=n.getBoundingClientRect(),i=e.clientX-r.left,a=i<=S,o=r.width-i<=S;if(a){let e=n.previousElementSibling;if(!e||e.getAttribute(`collapsed`)===`true`){n.classList.remove(`resizable-edge`);return}}a||o?n.classList.add(`resizable-edge`):n.classList.remove(`resizable-edge`)};#g=e=>{if(!e.actualTarget.closest(`thead`))return;let t=e.actualTarget.closest(`th, td`);if(!t||!t.classList.contains(`resizable-edge`))return;e.preventDefault();let n=t.getBoundingClientRect(),r=e.clientX-n.left,i=t;if(r<=S){let e=t.previousElementSibling;if(e&&e.dataset.col!==void 0&&e.getAttribute(`collapsed`)!==`true`)i=e;else if(!t.previousElementSibling)return}this.#s=i,this.#o=this.#m(i);let a=this.#e.querySelector(`.ng-container-${this.#o}`);if(!a)return;let o=parseInt(i.dataset.col,10),s=i.colSpan||1;if(this.#i=o+s-1,this.#p(i)){this.#a=this.#i+1;let e=a.querySelector(`col[data-col="${this.#a}"]`);e?this.#u=parseInt(e.getAttribute(`width`),10)||100:this.#a=null}else this.#a=null;let c=i.getBoundingClientRect(),l=this.#e.getBoundingClientRect();this.#d=c.width,this.#f=c.left-l.left;let u=a.querySelector(`col[data-col="${this.#i}"]`)?.getAttribute(`width`);this.#l=u&&!isNaN(parseInt(u,10))?parseInt(u,10):c.width/s,this.#c=e.clientX,this.#n&&(this.#n.classList.add(`active`),this.#_(e.clientX)),window.addEventListener(`pointermove`,this.#v),window.addEventListener(`pointerup`,this.#y,{once:!0})};#_(e){let t=e-this.#c,n=this.#p(this.#s);if(n&&this.#a!==null){let e=this.#u-16,n=-(this.#l-16);t=Math.max(n,Math.min(t,e))}let r=Math.max(16,this.#l+t),i=e-this.#s.getBoundingClientRect().left;if(n&&this.#a!==null){let e=this.#d+(this.#u-16);i=Math.min(i,e)}let a=Math.max(16,i);this.#n&&(this.#n.style.setProperty(`--col-resizer-tooltip-left`,`${this.#f}px`),this.#n.style.setProperty(`--col-resizer-tooltip-width`,`${a}px`));let o=this.#r?.querySelector(`.size-badge`);o&&(o.textContent=`${Math.round(r)}px`)}#v=e=>{this.#_(e.clientX)};#y=e=>{window.removeEventListener(`pointermove`,this.#v);let t=e.clientX-this.#c,n=this.#p(this.#s),r=0;if(n&&this.#a!==null){let e=Math.max(16,this.#l+t),n=this.#l+this.#u-e;n<16&&(n=16,e=this.#l+this.#u-16),this.setColumnWidth(this.#i,e,this.#o),this.setColumnWidth(this.#a,n,this.#o),r=e}else{let e=Math.max(16,this.#l+t);this.#i!==null&&this.#o&&(this.setColumnWidth(this.#i,e,this.#o),r=e)}if(this.#s){let e=this.#s;e.getAttribute(`collapsed`)!==`true`&&r>20&&(e.dataset.expandWidth=String(r))}this.#n&&(this.#r?.classList.add(`fade-out`),setTimeout(()=>{this.#n.classList.remove(`active`),this.#r?.classList.remove(`fade-out`)},150)),this.#i=null,this.#a=null,this.#o=null,this.#s=null};#b=e=>{let t=e.target.closest(`th, td`);if(!t||!t.classList.contains(`resizable-edge`))return;let n=t.getBoundingClientRect();e.clientX-n.left<=S&&(t=t.previousElementSibling);let r=parseInt(t.dataset.col,10),i=this.#e.querySelector(`tbody.body [data-col="${r}"]`);if(!i||!i.dataset.bind||i.classList.contains(`CELL-RADIO`))return;let a=0;Array.from(i.firstElementChild.children).forEach(e=>{switch(e.tagName){case`SPAN`:a+=8;break;case`DIV`:a+=8;break;case`BUTTON`:a+=32;break;case`SELECT`:a+=32;break;case`INPUT`:switch((e.type||`text`).toLowerCase()){case`checkbox`:case`radio`:a+=12;break;case`button`:case`submit`:case`reset`:case`image`:a+=16;break;case`color`:case`file`:case`range`:a+=24;break;case`hidden`:a+=0;break;default:a+=16}}});let o=this.#t.fields.get().indexOf(i.dataset.bind),s=window.getComputedStyle(i).font||`12px sans-serif`,c=t.innerText||``,l=(nine.measureTextSize(c,s).width||0)+16;this.#t.execute(()=>{this.#e.view.getArray().forEach((e,t)=>{let n=String(i.dataset.expr?this.#t.exprEngine.evaluate(i.dataset.expr,e,t):e.v[o]??``).trim(),r=nine.measureTextSize(n,s);r.width&&r.width>l&&(l=r.width)});let e=Math.max(32,Math.min(400,Math.ceil(l)+a));this.setColumnWidth(i.dataset.col,e,this.#m(t))})}},w=class extends HTMLElement{constructor(){super()}connectedCallback(){this.#e()}#e=()=>{this.innerHTML=`
27
27
  <div class="resizer-overlay">
28
28
  <span class="size-badge">0px</span>
29
29
  </div>
@@ -75,7 +75,7 @@
75
75
 
76
76
  <div class="ng-col-mover-grip"></div>
77
77
  <div class="ng-col-mover-indi"></div>
78
- `,this.#p={mainBody:this.querySelector(`.ng-sheet-body .ng-container-body`),hscrollbar:this.querySelector(`nine-table-hscrollbar`),vscrollbar:this.querySelector(`nine-table-vscrollbar`),content:this.querySelector(`.ng-sheet-body .ng-sheet-body-content`),scrollHolder:this.querySelector(`.ng-sheet-body .ng-virtual-height-holder`)}};#S=()=>{let e=this.querySelector(`.ng-container-left table`),t=this.querySelector(`.ng-container-body table`),n=this.querySelector(`.ng-container-right table`),r=Array.from(e.querySelectorAll(`thead tr:not(.col-indicator-rowgroup)`)),i=Array.from(t.querySelectorAll(`thead tr:not(.col-indicator-rowgroup)`)),a=Array.from(n.querySelectorAll(`thead tr:not(.col-indicator-rowgroup)`));this.#C(r,i,a);let o=Array.from(e.querySelectorAll(`tfoot tr`)),s=Array.from(t.querySelectorAll(`tfoot tr`)),c=Array.from(n.querySelectorAll(`tfoot tr`));this.#C(o,s,c)};#C=(e,t,n)=>{setTimeout(()=>{let r=Math.max(e.length,t.length,n.length);for(let i=0;i<r;i++){let r=[e[i]?.getBoundingClientRect().height||0,t[i]?.getBoundingClientRect().height||0,n[i]?.getBoundingClientRect().height||0],a=Math.max(...r);a>0&&(e[i]&&(e[i].style.height=`${a}px`),t[i]&&(t[i].style.height=`${a}px`),n[i]&&(n[i].style.height=`${a}px`))}})};#w=()=>{let e=this.querySelector(`.ng-sheet-body`);if(!e)return;let t=null;e.addEventListener(`mouseover`,n=>{let r=n.target.closest(`tr`);if(!r||!r.dataset.row&&r.dataset.row!==`0`)return;let i=r.dataset.row;t!==i&&(t=i,e.querySelectorAll(`tr[data-row="${i}"]`).forEach(e=>{e.classList.add(`hover`)}))}),e.addEventListener(`mouseout`,n=>{let r=n.target.closest(`tr`);if(!r)return;let i=n.relatedTarget;r.contains(i)||(e.querySelectorAll(`tr.hover`).forEach(e=>{e.classList.remove(`hover`)}),t=null)})};disconnectedCallback(){this.#a?.destroy(),this.#o?.destroy(),this.innerHTML=``}};customElements.get(`nine-table-sheet`)||customElements.define(`nine-table-sheet`,N);var P=class{#e;constructor(e){this.#e=e,this.#t()}#t=()=>{this.#r(),new ResizeObserver(e=>{for(let t of e)this.#e.getAttribute(`auto-height`)===`true`&&this.#n()}).observe(this.#e)};set loading(e){e?this.#e.classList.add(`loading`):this.#e.classList.remove(`loading`)}#n=()=>{let e=Array.from(this.#e.shadowRoot.querySelectorAll(`nine-table-sheet.active`));if(e.length===0)return;let t=parseInt(this.#e.getAttribute(`max-display-row`),10)||10,n=Math.max(...e.map(e=>e.getRowHeight())),r=this.#e.shadowRoot.querySelector(`nine-table-toolbar`),i=this.#e.shadowRoot.querySelector(`nine-table-sheets-footer`),a=r?r.getBoundingClientRect().height:0,o=i?i.getBoundingClientRect().height:0,s=N.SCROLLBAR_SIZE,c=t*n+a+o+s;this.#e.style.height=`${c}px`};#r=()=>{let e=Array.from(this.#e.children).filter(e=>e.tagName.toUpperCase()===`TABLE`),t=this.#e.getAttribute(`auto-height`)===`true`,n=e.length,r=e.map((e,t)=>{let r=t===0?`active`:``,i=e.id||`sheet${t+1}`;return`<nine-table-sheet class="${r}" data-index="${t}" data-sheet-id="${i}" id="${i}"></nine-table-sheet>`+(t<n-1?`<nine-splitter class="h" data-split-index="${t}"></nine-splitter>`:``)}).join(``),i=[`@import "https://cdn.jsdelivr.net/npm/@ninebone/datagrid@0.0.13/dist/css/nine-table.css";`];nine[`nine-table`]&&nine[`nine-table`].cssFile&&i.push(`@import "${nine[`nine-table`].cssFile}";`),this.#e.shadowRoot.innerHTML=`
78
+ `,this.#p={mainBody:this.querySelector(`.ng-sheet-body .ng-container-body`),hscrollbar:this.querySelector(`nine-table-hscrollbar`),vscrollbar:this.querySelector(`nine-table-vscrollbar`),content:this.querySelector(`.ng-sheet-body .ng-sheet-body-content`),scrollHolder:this.querySelector(`.ng-sheet-body .ng-virtual-height-holder`)}};#S=()=>{let e=this.querySelector(`.ng-container-left table`),t=this.querySelector(`.ng-container-body table`),n=this.querySelector(`.ng-container-right table`),r=Array.from(e.querySelectorAll(`thead tr:not(.col-indicator-rowgroup)`)),i=Array.from(t.querySelectorAll(`thead tr:not(.col-indicator-rowgroup)`)),a=Array.from(n.querySelectorAll(`thead tr:not(.col-indicator-rowgroup)`));this.#C(r,i,a);let o=Array.from(e.querySelectorAll(`tfoot tr`)),s=Array.from(t.querySelectorAll(`tfoot tr`)),c=Array.from(n.querySelectorAll(`tfoot tr`));this.#C(o,s,c)};#C=(e,t,n)=>{setTimeout(()=>{let r=Math.max(e.length,t.length,n.length);for(let i=0;i<r;i++){let r=[e[i]?.getBoundingClientRect().height||0,t[i]?.getBoundingClientRect().height||0,n[i]?.getBoundingClientRect().height||0],a=Math.max(...r);a>0&&(e[i]&&(e[i].style.height=`${a}px`),t[i]&&(t[i].style.height=`${a}px`),n[i]&&(n[i].style.height=`${a}px`))}})};#w=()=>{let e=this.querySelector(`.ng-sheet-body`);if(!e)return;let t=null;e.addEventListener(`mouseover`,n=>{let r=n.target.closest(`tr`);if(!r||!r.dataset.row&&r.dataset.row!==`0`)return;let i=r.dataset.row;t!==i&&(t=i,e.querySelectorAll(`tr[data-row="${i}"]`).forEach(e=>{e.classList.add(`hover`)}))}),e.addEventListener(`mouseout`,n=>{let r=n.target.closest(`tr`);if(!r)return;let i=n.relatedTarget;r.contains(i)||(e.querySelectorAll(`tr.hover`).forEach(e=>{e.classList.remove(`hover`)}),t=null)})};disconnectedCallback(){this.#a?.destroy(),this.#o?.destroy(),this.innerHTML=``}};customElements.get(`nine-table-sheet`)||customElements.define(`nine-table-sheet`,N);var P=class{#e;constructor(e){this.#e=e,this.#t()}#t=()=>{this.#r(),new ResizeObserver(e=>{for(let t of e)this.#e.getAttribute(`auto-height`)===`true`&&this.#n()}).observe(this.#e)};set loading(e){e?this.#e.classList.add(`loading`):this.#e.classList.remove(`loading`)}#n=()=>{let e=Array.from(this.#e.shadowRoot.querySelectorAll(`nine-table-sheet.active`));if(e.length===0)return;let t=parseInt(this.#e.getAttribute(`max-display-row`),10)||10,n=Math.max(...e.map(e=>e.getRowHeight())),r=this.#e.shadowRoot.querySelector(`nine-table-toolbar`),i=this.#e.shadowRoot.querySelector(`nine-table-sheets-footer`),a=r?r.getBoundingClientRect().height:0,o=i?i.getBoundingClientRect().height:0,s=N.SCROLLBAR_SIZE,c=t*n+a+o+s;this.#e.style.height=`${c}px`};#r=()=>{let e=Array.from(this.#e.children).filter(e=>e.tagName.toUpperCase()===`TABLE`),t=this.#e.getAttribute(`auto-height`)===`true`,n=e.length,r=e.map((e,t)=>{let r=t===0?`active`:``,i=e.id||`sheet${t+1}`;return`<nine-table-sheet class="${r}" data-index="${t}" data-sheet-id="${i}" id="${i}"></nine-table-sheet>`+(t<n-1?`<nine-splitter class="h" data-split-index="${t}"></nine-splitter>`:``)}).join(``),i=[`@import "https://cdn.jsdelivr.net/npm/@ninebone/datagrid@0.0.14/dist/css/nine-table.css";`];nine[`nine-table`]&&nine[`nine-table`].cssFile&&i.push(`@import "${nine[`nine-table`].cssFile}";`),this.#e.shadowRoot.innerHTML=`
79
79
  <style>
80
80
  ${i.join(`
81
81
  `)}
@@ -102,7 +102,7 @@
102
102
 
103
103
  if (!data && !host) return "";
104
104
  return ${i};
105
- `),this.#n.set(i,e)),e(t,n,this.#e)}return i}catch{return e}}},I=class extends HTMLElement{#e;#t;#n;#r=0;#i=``;constructor(){super(),[`NINE-TABLE`].includes(this.tagName)&&r.log(`Welcome nine-table`,`0.0.13`),this.#e=this.attachShadow({mode:`open`}),this.#t=new s(this)}connectedCallback(){setTimeout(()=>{this.#r=this.querySelectorAll(`table`)?.length,this.fields=new c(this),this.exprEngine=new F(this),this.#o(),this.#n=new P(this),this.#a()})}disconnectedCallback(){}#a=()=>{let e=0,t=setInterval(()=>{e++;let n=this.shadow.querySelectorAll(`nine-table-sheet`);if(e>=50&&clearInterval(t),n.length>=this.#r){let e=0;n.forEach(t=>{t.loaded&&e++}),e>=this.#r&&(clearInterval(t),this.loaded=!0,this.dispatchEvent(new CustomEvent(i.EVENT.LOAD,{bubbles:!0,detail:{target:this}})))}},100)};get shadow(){return this.#e}get dataManager(){return this.#t}get data(){return this.#t.data}get row(){return this.#t.row}get customStyle(){return this.#i}scrollTo=(e,t)=>{this.#e.querySelectorAll(`nine-table-sheet.active`).forEach(n=>{n.scrollTo(e,t)})};currentRow=()=>{let e=this.currentRows();return e.length===0?-1:e[0]};currentRows=()=>{let e=[];return this.#e.querySelectorAll(`nine-table-sheet.active`).forEach(t=>{let n=t.view.getArray(t.selection.minRow).m._[i.META.INDEX.ROWID];e.push(n)}),e};addRow=(e,t=!0)=>this.data.add(e,t);insertRow=(e,t,n=!0)=>{let r=this.#e.querySelector(`nine-table-sheet.active`);if(!r)return;let a=r.view.get(e).m._[i.META.INDEX.ROWID],o=this.data.insert(a,t,n);return r.view.getArray().findIndex(e=>!e||!e.m||!e.m._?!1:e.m._[i.META.INDEX.ROWID]===o)};removeRow=e=>{let t=this.#e.querySelector(`nine-table-sheet.active`);if(!t)return;let n=t.view.get(e).m._[i.META.INDEX.ROWID];this.data.remove(n)};currentIndex=()=>{let e=this.currentIndexs();return e.length===0?-1:e[0]};currentIndexs=()=>{let e=[];return this.#e.querySelectorAll(`nine-table-sheet.active`).forEach(t=>{e.push(t.selection.minRow)}),e};addProvider(e){if(!e||typeof e!=`object`)return;let{style:t,...n}=e;if(t&&typeof t==`string`){this.#i=t;let e=this.#e.getElementById(`nine-table-scoped-custom-style`);e&&(e.textContent=t)}Object.keys(n).length>0&&setTimeout(()=>{Object.entries(n).forEach(([e,t])=>{typeof t==`function`&&(this[e]=t)}),this.rerenderer()})}setData(e){this.#t.data.set(e),this.refresh()}refresh(){this.activeSheet?.invalidate()}set loading(e){this.#n&&(this.#n.loading=e)}rerenderer(){this.activeSheet?.querySelectorAll(`tbody.body th,tbody.body td`).forEach(e=>{Array.from(e.children).find(e=>e.tagName.toLowerCase().startsWith(`cell-`)&&typeof e.rerenderer==`function`)?.rerenderer()})}sheet=e=>{if(e===null||e<0)return this.activeSheet;let t=Array.from(this.shadow.querySelectorAll(`nine-table-sheet`));return typeof e==`number`?t[e]||null:typeof e==`string`?this.shadow.querySelector(`nine-table-sheet#${e}, nine-table-sheet[data-sheet-id="${e}"]`)||null:t[0]||null};get sheets(){return Array.from(this.shadow.querySelectorAll(`nine-table-sheet`))}get activeSheet(){return this.shadow.querySelector(`nine-table-sheet.active`)||null}#o(){let e=new Set;this.querySelectorAll(`[data-source]`).forEach(t=>{let n=t.getAttribute(`data-source`);if(!n)return;let r=n.matchAll(/(?:host\.)?([a-zA-Z0-9_$]+)\s*\(/g);for(let t of r){let n=t[1];n&&n!==`host`&&e.add(n)}}),e.forEach(e=>{let t=null;Object.defineProperty(this,e,{set:e=>{t=e,this.rerenderer()},get:()=>t,configurable:!0,enumerable:!0})})}execute=e=>{setTimeout(()=>{this.loading=!0,setTimeout(()=>{try{e.call(this)}finally{this.loading=!1}})})}};customElements.get(`nine-table`)||customElements.define(`nine-table`,I),customElements.get(`nine-table-simple`)||customElements.define(`nine-table-simple`,class extends I{connectedCallback(){this.setAttribute(`theme`,`simple`),super.connectedCallback()}});var L=class extends HTMLElement{constructor(){super()}applyBaseStyle(){}connectedCallback(){}},R=new Map,z=class extends L{#e;#t;#n;#r;#i;constructor(){super()}get host(){return this.#e}get sheet(){return this.#t}get cell(){return this.#r}get tr(){return this.#n}get attr(){return this.#i}connectedCallback(){super.connectedCallback(),this.#e=this.getRootNode().host,this.#r=this.closest(`th,td`),this.#n=this.#r.closest(`tr`),this.#t=this.#n.closest(`nine-table-sheet`),this.#r.classList.add(this.tagName),this.#i={};for(let e=0;e<this.#r.attributes.length;e++){let t=this.#r.attributes[e].name;[`text-align`,`class`,`cell-type`,`data-bind`,`data-expr`,`data-col`,`tabindex`].includes(t)||(this.#i[t]=this.#r.attributes[e].value)}if(!this.#r)return;let e=this.shadowRoot||this;e.querySelectorAll(`button, ng-expand-button`).forEach(e=>{e.addEventListener(`click`,()=>{let e=this.getAttribute(`onbuttonclick`)||this.getAttribute(`onButtonClick`)||this.#r?.getAttribute(`onbuttonclick`)||this.#r?.getAttribute(`onButtonClick`),t=this.data,n=parseInt(this.#r.dataset.row,10);if(e&&this.#e){e=e.replace(`()`,``);let r=e.match(/^(\w+)\s*\(/)?.[1]||e;typeof this.#e[r]==`function`?this.#e[r].call(this.#e,t,n,this.#r):typeof this.#e.exprFunction==`function`&&this.#e.exprFunction(e).call(this,t,n)}})});let t=e.querySelector(`.renderer`);t&&this.getAttribute(`link`)===`true`&&(t.classList.add(`link`),t.addEventListener(`click`,()=>{let e=this.getAttribute(`onlinkclick`)||this.getAttribute(`onLinkClick`),t=this.data,n=parseInt(this.#r.dataset.row,10);if(e&&this.#e){e=e.replace(`()`,``);let r=e.match(/^(\w+)\s*\(/)?.[1]||e;typeof this.#e[r]==`function`?this.#e[r].call(this.#e,t,n,this.#r):typeof this.#e.exprFunction==`function`&&this.#e.exprFunction(e).call(this,t,n)}this.#e?.dispatchEvent(new CustomEvent(ninegrid.EVENT.LINK_CLICK,{detail:{target:this.#r,data:t,currow:n},bubbles:!0,composed:!0}))}))}get data(){let e=this.#n?.data;if(!e)return null;if(!e.v)return e;let t=this.#e;return new Proxy(e,{get(e,n){if(n===`__ng`)return e.__ng;if(n===`v`)return e.v;let r=t?.fields?.indexOf?.(n)??-1;return r>=0?e.v[r]:e[n]}})}get value(){if(!this.#r||!this.#n?.data)return``;let e=this.#r.dataset?.bind;if(!e)return``;let t=this.#n.data;if(t.v&&Array.isArray(t.v)){let n=this.#e.fields.get().indexOf(e)??-1;return n>=0?t.v[n]??``:``}return t[e]??``}set value(e){if(!this.#r||!this.#e?.data)return;let t=parseInt(this.#n.dataset.row,10),n=this.#r.dataset.bind;!isNaN(t)&&n&&this.#e.data.setValue(t,n,e)}get row(){return parseInt(this.#r?.dataset?.row,10)}get index(){return parseInt(this.#r?.dataset?.index,10)}isValid(){return!this.#r.classList.contains(`invalid`)}isInvalid(){return!this.isValid()}getDisplayText=(e=``)=>{if(!this.#r||!this.#r.closest(`tbody`)||!this.#n.data)return e;let t=this.#r.dataset.expr,n=this.#r.dataset.bind,r=parseInt(this.#r.dataset.row,10);if(t)try{return this.#n.getAttribute(`grouping`)===`true`?this.getGroupExprValue(t,this.#n.data,r,this.#r):this.#e.exprEngine.evaluate(t,this.#n.data,r)}catch{return e}return n?this.value??e:e};refresh(){if(!this.#r||!this.#n)return;let e=this.value;return this.#r.classList.remove(`invalid`),[`color`,`background`,`background-color`,`visible`,`enable`,`validator`].forEach(e=>{let t=this.#i[e];if(t){let n=this.#e.exprEngine.evaluate(t,this.#n.data,parseInt(this.#r.dataset.row,10));e===`validator`?n||this.#r.classList.add(`invalid`):e===`visible`?this.style.display=n?``:`none`:e===`enable`?(this.querySelectorAll(`input, button, textarea, select`).forEach(e=>{e.disabled=!n}),n?this.#r.removeAttribute(`disabled`):this.#r.setAttribute(`disabled`,`true`)):this.#r.style[e]=n}}),e}getExprValue(e,t,n){return!this.#e||!this.#e.exprEngine||e==null||e===``?e:this.#e.exprEngine.evaluate(e,t,n)}getGroupExprValue=(e,t,n,r)=>{if(!e)return``;try{n=parseInt(n,10);let i=e.replace(`()`,``).trim();if(this.#e&&typeof this.#e[i]==`function`)return this.#e[i].call(this,t,n,r);let a=i.match(/^(\w+)\s*\(\s*([\w\-]*)\s*\)/);if(a){let e=t[GROUP_IDX.CHILDREN],n=this.#e?.data?.getArray?this.#e.data.getArray():[],r=e?e.map(e=>n[e]).filter(Boolean):[],[,i,o]=a,s=this.#e;switch(i.toLowerCase()){case`count`:return r.length;case`sum`:{let e=s?.fields?.indexOf?.(o)??-1;return r.reduce((t,n)=>{let r=e>=0?n.v?.[e]:n[o];return t+(Number(r)||0)},0)}case`avg`:{if(r.length===0)return 0;let e=s?.fields?.indexOf?.(o)??-1;return r.reduce((t,n)=>{let r=e>=0?n.v?.[e]:n[o];return t+(Number(r)||0)},0)/r.length}}}if(this.#e&&typeof this.#e.exprFunction==`function`)return this.#e.exprFunction(e).call(this,t,n,this.#e.data);if(e.includes(`data.`)||e.includes(`childRecords`)||e.includes(`groupRecord`)){let i=R.get(`grp_`+e);return i||(i=Function(`groupRecord`,`row`,`cell`,`host`,`
105
+ `),this.#n.set(i,e)),e(t,n,this.#e)}return i}catch{return e}}},I=class extends HTMLElement{#e;#t;#n;#r=0;#i=``;constructor(){super(),[`NINE-TABLE`].includes(this.tagName)&&r.log(`Welcome nine-table`,`0.0.14`),this.#e=this.attachShadow({mode:`open`}),this.#t=new s(this)}connectedCallback(){setTimeout(()=>{this.#r=this.querySelectorAll(`table`)?.length,this.fields=new c(this),this.exprEngine=new F(this),this.#o(),this.#n=new P(this),this.#a()})}disconnectedCallback(){}#a=()=>{let e=0,t=setInterval(()=>{e++;let n=this.shadow.querySelectorAll(`nine-table-sheet`);if(e>=50&&clearInterval(t),n.length>=this.#r){let e=0;n.forEach(t=>{t.loaded&&e++}),e>=this.#r&&(clearInterval(t),this.loaded=!0,this.dispatchEvent(new CustomEvent(i.EVENT.LOAD,{bubbles:!0,detail:{target:this}})))}},100)};get shadow(){return this.#e}get dataManager(){return this.#t}get data(){return this.#t.data}get row(){return this.#t.row}get customStyle(){return this.#i}scrollTo=(e,t)=>{this.#e.querySelectorAll(`nine-table-sheet.active`).forEach(n=>{n.scrollTo(e,t)})};currentRow=()=>{let e=this.currentRows();return e.length===0?-1:e[0]};currentRows=()=>{let e=[];return this.#e.querySelectorAll(`nine-table-sheet.active`).forEach(t=>{let n=t.view.getArray(t.selection.minRow).m._[i.META.INDEX.ROWID];e.push(n)}),e};addRow=(e,t=!0)=>this.data.add(e,t);insertRow=(e,t,n=!0)=>{let r=this.#e.querySelector(`nine-table-sheet.active`);if(!r)return;let a=r.view.get(e).m._[i.META.INDEX.ROWID],o=this.data.insert(a,t,n);return r.view.getArray().findIndex(e=>!e||!e.m||!e.m._?!1:e.m._[i.META.INDEX.ROWID]===o)};removeRow=e=>{let t=this.#e.querySelector(`nine-table-sheet.active`);if(!t)return;let n=t.view.get(e).m._[i.META.INDEX.ROWID];this.data.remove(n)};currentIndex=()=>{let e=this.currentIndexs();return e.length===0?-1:e[0]};currentIndexs=()=>{let e=[];return this.#e.querySelectorAll(`nine-table-sheet.active`).forEach(t=>{e.push(t.selection.minRow)}),e};addProvider(e){if(!e||typeof e!=`object`)return;let{style:t,...n}=e;if(t&&typeof t==`string`){this.#i=t;let e=this.#e.getElementById(`nine-table-scoped-custom-style`);e&&(e.textContent=t)}Object.keys(n).length>0&&setTimeout(()=>{Object.entries(n).forEach(([e,t])=>{typeof t==`function`&&(this[e]=t)}),this.rerenderer()})}setData(e){this.#t.data.set(e),this.refresh()}refresh(){this.activeSheet?.invalidate()}set loading(e){this.#n&&(this.#n.loading=e)}rerenderer(){this.activeSheet?.querySelectorAll(`tbody.body th,tbody.body td`).forEach(e=>{Array.from(e.children).find(e=>e.tagName.toLowerCase().startsWith(`cell-`)&&typeof e.rerenderer==`function`)?.rerenderer()})}sheet=e=>{if(e===null||e<0)return this.activeSheet;let t=Array.from(this.shadow.querySelectorAll(`nine-table-sheet`));return typeof e==`number`?t[e]||null:typeof e==`string`?this.shadow.querySelector(`nine-table-sheet#${e}, nine-table-sheet[data-sheet-id="${e}"]`)||null:t[0]||null};get sheets(){return Array.from(this.shadow.querySelectorAll(`nine-table-sheet`))}get activeSheet(){return this.shadow.querySelector(`nine-table-sheet.active`)||null}#o(){let e=new Set;this.querySelectorAll(`[data-source]`).forEach(t=>{let n=t.getAttribute(`data-source`);if(!n)return;let r=n.matchAll(/(?:host\.)?([a-zA-Z0-9_$]+)\s*\(/g);for(let t of r){let n=t[1];n&&n!==`host`&&e.add(n)}}),e.forEach(e=>{let t=null;Object.defineProperty(this,e,{set:e=>{t=e,this.rerenderer()},get:()=>t,configurable:!0,enumerable:!0})})}execute=e=>{setTimeout(()=>{this.loading=!0,setTimeout(()=>{try{e.call(this)}finally{this.loading=!1}})})}};customElements.get(`nine-table`)||customElements.define(`nine-table`,I),customElements.get(`nine-table-simple`)||customElements.define(`nine-table-simple`,class extends I{connectedCallback(){this.setAttribute(`theme`,`simple`),super.connectedCallback()}});var L=class extends HTMLElement{constructor(){super()}applyBaseStyle(){}connectedCallback(){}},R=new Map,z=class extends L{#e;#t;#n;#r;#i;constructor(){super()}get host(){return this.#e}get sheet(){return this.#t}get cell(){return this.#r}get tr(){return this.#n}get attr(){return this.#i}connectedCallback(){super.connectedCallback(),this.#e=this.getRootNode().host,this.#r=this.closest(`th,td`),this.#n=this.#r.closest(`tr`),this.#t=this.#n.closest(`nine-table-sheet`),this.#r.classList.add(this.tagName),this.#i={};for(let e=0;e<this.#r.attributes.length;e++){let t=this.#r.attributes[e].name;[`text-align`,`class`,`cell-type`,`data-bind`,`data-expr`,`data-col`,`tabindex`].includes(t)||(this.#i[t]=this.#r.attributes[e].value)}if(!this.#r)return;let e=this.shadowRoot||this;e.querySelectorAll(`button, ng-expand-button`).forEach(e=>{e.addEventListener(`click`,()=>{let e=this.getAttribute(`onbuttonclick`)||this.getAttribute(`onButtonClick`)||this.#r?.getAttribute(`onbuttonclick`)||this.#r?.getAttribute(`onButtonClick`),t=this.data,n=parseInt(this.#r.dataset.row,10);if(e&&this.#e){e=e.replace(`()`,``);let r=e.match(/^(\w+)\s*\(/)?.[1]||e;typeof this.#e[r]==`function`?this.#e[r].call(this.#e,t,n,this.#r):typeof this.#e.exprFunction==`function`&&this.#e.exprFunction(e).call(this,t,n)}})});let t=e.querySelector(`.renderer`);t&&this.getAttribute(`link`)===`true`&&(t.classList.add(`link`),t.addEventListener(`click`,()=>{let e=this.getAttribute(`onlinkclick`)||this.getAttribute(`onLinkClick`),t=this.data,n=parseInt(this.#r.dataset.row,10);if(e&&this.#e){e=e.replace(`()`,``);let r=e.match(/^(\w+)\s*\(/)?.[1]||e;typeof this.#e[r]==`function`?this.#e[r].call(this.#e,t,n,this.#r):typeof this.#e.exprFunction==`function`&&this.#e.exprFunction(e).call(this,t,n)}this.#e?.dispatchEvent(new CustomEvent(ninegrid.EVENT.LINK_CLICK,{detail:{target:this.#r,data:t,currow:n},bubbles:!0,composed:!0}))}))}get data(){let e=this.#n?.data;if(!e)return null;if(!e.v)return e;let t=this.#e;return new Proxy(e,{get(e,n){if(n===`__ng`)return e.__ng;if(n===`v`)return e.v;let r=t?.fields?.indexOf?.(n)??-1;return r>=0?e.v[r]:e[n]}})}get value(){if(!this.#r||!this.#n?.data)return``;let e=this.#r.dataset?.bind;if(!e)return``;let t=this.#n.data;if(t.v&&Array.isArray(t.v)){let n=this.#e.fields.get().indexOf(e)??-1;return n>=0?t.v[n]??``:``}return t[e]??``}set value(e){if(!this.#r||!this.#e?.data)return;let t=parseInt(this.#n.dataset.row,10),n=this.#r.dataset.bind;!isNaN(t)&&n&&this.#e.data.setValue(t,n,e)}get row(){return parseInt(this.#r?.dataset?.row,10)}get index(){return parseInt(this.#r?.dataset?.index,10)}isValid(){return!this.#r.classList.contains(`invalid`)}isInvalid(){return!this.isValid()}getDisplayText=(e=``)=>{if(!this.#r||!this.#r.closest(`tbody`)||!this.#n.data)return e;let t=this.#r.dataset.expr,n=this.#r.dataset.bind,r=parseInt(this.#r.dataset.row,10);if(t)try{return this.#n.getAttribute(`grouping`)===`true`?this.getGroupExprValue(t,this.#n.data,r,this.#r):this.#e.exprEngine.evaluate(t,this.#n.data,r)}catch{return e}return n?this.value??e:e};refresh(){if(!this.#r||!this.#n)return;let e=this.value;return this.#r.classList.remove(`invalid`),[`color`,`background`,`background-color`,`visible`,`enable`,`validator`].forEach(e=>{let t=this.#i[e];if(t){let n=this.#e.exprEngine.evaluate(t,this.#n.data,parseInt(this.#r.dataset.row,10));e===`validator`?n||this.#r.classList.add(`invalid`):e===`visible`?this.style.display=n?``:`none`:e===`enable`?(this.querySelectorAll(`input, button, textarea, select`).forEach(e=>{e.disabled=!n}),n?this.#r.removeAttribute(`disabled`):this.#r.setAttribute(`disabled`,`true`)):this.#r.style[e]=n}}),e}getExprValue(e,t,n){return!this.#e||!this.#e.exprEngine||e==null||e===``?e:this.#e.exprEngine.evaluate(e,t,n)}getGroupExprValue=(e,t,n,r)=>{if(!e)return``;try{n=parseInt(n,10);let i=e.replace(`()`,``).trim();if(this.#e&&typeof this.#e[i]==`function`)return this.#e[i].call(this,t,n,r);let a=i.match(/^(\w+)\s*\(\s*([\w\-]*)\s*\)/);if(a){let e=t[GROUP_IDX.CHILDREN],n=this.#e?.data?.getArray?this.#e.data.getArray():[],r=e?e.map(e=>n[e]).filter(Boolean):[],[,i,o]=a,s=this.#e;switch(i.toLowerCase()){case`count`:return r.length;case`sum`:{let e=s?.fields?.indexOf?.(o)??-1;return r.reduce((t,n)=>{let r=e>=0?n.v?.[e]:n[o];return t+(Number(r)||0)},0)}case`avg`:{if(r.length===0)return 0;let e=s?.fields?.indexOf?.(o)??-1;return r.reduce((t,n)=>{let r=e>=0?n.v?.[e]:n[o];return t+(Number(r)||0)},0)/r.length}}}if(this.#e&&typeof this.#e.exprFunction==`function`)return this.#e.exprFunction(e).call(this,t,n,this.#e.data);if(e.includes(`data.`)||e.includes(`childRecords`)||e.includes(`groupRecord`)){let i=R.get(`grp_`+e);return i||(i=Function(`groupRecord`,`row`,`cell`,`host`,`
106
106
  const indices = groupRecord[3]; // GROUP_IDX.CHILDREN = 3
107
107
  const allRecords = host?.data?.getArray ? host.data.getArray() : [];
108
108