@ninebone/table 0.0.284 → 0.0.285
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/nine-table.js +134 -146
- package/dist/nine-table.js.map +1 -1
- package/dist/nine-table.umd.js +4 -4
- package/dist/nine-table.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/nine-table.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(y,g){typeof exports=="object"&&typeof module<"u"?g(require("@ninebone/util")):typeof define=="function"&&define.amd?define(["@ninebone/util"],g):(y=typeof globalThis<"u"?globalThis:y||self,g(y.NineboneUtil))})(this,function(y){"use strict";var
|
|
1
|
+
(function(y,g){typeof exports=="object"&&typeof module<"u"?g(require("@ninebone/util")):typeof define=="function"&&define.amd?define(["@ninebone/util"],g):(y=typeof globalThis<"u"?globalThis:y||self,g(y.NineboneUtil))})(this,function(y){"use strict";var Pe=Object.defineProperty;var Ve=y=>{throw TypeError(y)};var Ue=(y,g,x)=>g in y?Pe(y,g,{enumerable:!0,configurable:!0,writable:!0,value:x}):y[g]=x;var a=(y,g)=>Pe(y,"name",{value:g,configurable:!0});var S=(y,g,x)=>Ue(y,typeof g!="symbol"?g+"":g,x),Xe=(y,g,x)=>g.has(y)||Ve("Cannot "+x);var e=(y,g,x)=>(Xe(y,g,"read from private field"),x?x.call(y):g.get(y)),c=(y,g,x)=>g.has(y)?Ve("Cannot add the same private member more than once"):g instanceof WeakSet?g.add(y):g.set(y,x),b=(y,g,x,I)=>(Xe(y,g,"write to private field"),I?I.call(y,x):g.set(y,x),x);var Ye=(y,g,x,I)=>({set _(G){b(y,g,G,x)},get _(){return e(y,g,I)}});var C,z,p,D,N,B,oe,P,le,ae,J,A,H,q,M,V,X,ce,he,Q,de,fe,ee,F,K,ue,ge,be,ye,pe,me,ie,R,we,se,xe,W,Y,T,w,k,Z,ve,$,Se,ne,Ee,Re,j,U,Ae;const He=class He extends y.trace.constructor{constructor(){super(),this.init("nine-table","green")}};a(He,"Trace");let g=He;const x=new g,Me=class Me extends HTMLElement{constructor(){super();c(this,C);c(this,z,!1);c(this,p);c(this,D);c(this,N);c(this,B);c(this,oe,a(()=>{if(!e(this,C))return;const t=e(this,C).querySelector(".ng-container-body");t&&(b(this,B,new ResizeObserver(()=>{this.refresh()})),e(this,B).observe(t))},"#observeResize"));S(this,"refresh",a(()=>{if(!e(this,C)||!e(this,p)||e(this,z))return;const t=e(this,p).container,s=t.querySelector("table");if(!s)return;const n=e(this,p).track,r=e(this,p).thumb,o=e(this,C).querySelector(".ng-container-bottom"),l=t.clientWidth,h=s.scrollWidth;if(l!==0&&h>l)o&&(o.style.display="flex");else{o&&(o.style.display="none");return}const d=n.clientWidth;if(d<=0)return;const u=Math.max(Math.min(d*(l/h),d),20);r.style.width=`${u}px`;const f=t.scrollLeft,m=h-l;let v=0;m>0&&(v=parseInt(f/m*(d-u),10)),v<0&&(v=0);const E=d-u;v>E&&(v=E),r.style.left=`${v}px`,x.log(v),e(this,p).left.disabled=v===0,e(this,p).right.disabled=v>=E-1},"refresh"));c(this,P,a(t=>{if(!e(this,p))return!1;const s=e(this,p).container,n=s.querySelector("table");if(!n)return!1;const r=e(this,p).track.getBoundingClientRect(),o=e(this,p).thumb.clientWidth;let l=t;l<0&&(l=0);const h=r.width-o;l>h&&(l=h),l=parseInt(l,10),e(this,p).thumb.style.left=`${l}px`,e(this,p).left.disabled=l===0,e(this,p).right.disabled=l>=h-1;const d=s.clientWidth,f=n.scrollWidth-d;return h>0&&f>0&&(s.scrollLeft=l/h*f),l>0&&l<h-1},"#thumbMoveTo"));c(this,le,a(()=>{const t=a(n=>{clearInterval(e(this,D)),clearInterval(e(this,N));const r=parseInt(e(this,p).thumb.style.left||0,10);e(this,P).call(this,r+n),b(this,D,setInterval(()=>{clearInterval(e(this,D)),b(this,N,setInterval(()=>{const o=parseInt(e(this,p).thumb.style.left||0,10);e(this,P).call(this,o+n)||clearInterval(e(this,N))},50))},500))},"delayScroll"),s=a(()=>{clearInterval(e(this,D)),clearInterval(e(this,N))},"clearTimer");["mouseup","mouseleave","touchend"].forEach(n=>{e(this,p).left.addEventListener(n,s),e(this,p).right.addEventListener(n,s),e(this,p).track.addEventListener(n,s)}),e(this,p).left.addEventListener("mousedown",n=>{n.button===0&&t(-20)}),e(this,p).right.addEventListener("mousedown",n=>{n.button===0&&t(20)}),e(this,p).left.addEventListener("touchstart",()=>t(-20)),e(this,p).right.addEventListener("touchstart",()=>t(20)),e(this,p).track.addEventListener("mousedown",n=>{if(n.button!==0)return;n.preventDefault();const r=e(this,p).track.getBoundingClientRect(),o=e(this,p).thumb.clientWidth;e(this,P).call(this,n.clientX-r.left-o/2)}),e(this,p).thumb.addEventListener("mousedown",n=>{if(n.button!==0)return;n.stopPropagation(),n.preventDefault(),b(this,z,!0),this.shiftX=n.clientX-e(this,p).thumb.getBoundingClientRect().left;const r=a(l=>{if(!e(this,z))return;const h=e(this,p).track.getBoundingClientRect();e(this,P).call(this,l.clientX-h.left-this.shiftX)},"onMouseMove"),o=a(()=>{b(this,z,!1),s(),document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",o),this.refresh()},"onMouseUp");document.addEventListener("mousemove",r),document.addEventListener("mouseup",o)})},"#init"))}connectedCallback(){if(b(this,C,this.closest("nine-table-sheet")||this.getRootNode().host),!e(this,C))return;this.innerHTML=`
|
|
2
2
|
<style>
|
|
3
3
|
nine-table-hscrollbar {
|
|
4
4
|
display: flex;
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
<button class='ng-scroll-left' disabled><div class='ng-scroll-icon'></div></button>
|
|
61
61
|
<div class='ng-scroll-track'><div class='ng-scroll-thumb'></div></div>
|
|
62
62
|
<button class='ng-scroll-right' disabled><div class='ng-scroll-icon'></div></button>
|
|
63
|
-
`;const t=a(()=>{const s=e(this,C).querySelector(".ng-container-body");if(!s){setTimeout(t,10);return}b(this,p,{container:s,track:this.querySelector(".ng-scroll-track"),thumb:this.querySelector(".ng-scroll-thumb"),left:this.querySelector(".ng-scroll-left"),right:this.querySelector(".ng-scroll-right")}),e(this,le).call(this),e(this,oe).call(this),this.refresh()},"initWhenReady");t()}disconnectedCallback(){e(this,B)&&e(this,B).disconnect()}};C=new WeakMap,z=new WeakMap,p=new WeakMap,D=new WeakMap,N=new WeakMap,B=new WeakMap,oe=new WeakMap,P=new WeakMap,le=new WeakMap,a(Me,"NineTableHScrollBar");let I=Me;customElements.get("nine-table-hscrollbar")||customElements.define("nine-table-hscrollbar",I);const _=class _{static compileAll(i){return Array.isArray(i)?i.map(t=>_.compile(t)):[]}static compile(i){var n,r,o;if(!i)return null;const t=i.cloneNode(!0);return e(n=_,ae).call(n,t),e(r=_,J).call(r,t,"thead"),e(o=_,J).call(o,t,"tbody"),Array.from(t.querySelectorAll("colgroup col")).forEach((l,
|
|
63
|
+
`;const t=a(()=>{const s=e(this,C).querySelector(".ng-container-body");if(!s){setTimeout(t,10);return}b(this,p,{container:s,track:this.querySelector(".ng-scroll-track"),thumb:this.querySelector(".ng-scroll-thumb"),left:this.querySelector(".ng-scroll-left"),right:this.querySelector(".ng-scroll-right")}),e(this,le).call(this),e(this,oe).call(this),this.refresh()},"initWhenReady");t()}disconnectedCallback(){e(this,B)&&e(this,B).disconnect()}};C=new WeakMap,z=new WeakMap,p=new WeakMap,D=new WeakMap,N=new WeakMap,B=new WeakMap,oe=new WeakMap,P=new WeakMap,le=new WeakMap,a(Me,"NineTableHScrollBar");let I=Me;customElements.get("nine-table-hscrollbar")||customElements.define("nine-table-hscrollbar",I);const _=class _{static compileAll(i){return Array.isArray(i)?i.map(t=>_.compile(t)):[]}static compile(i){var n,r,o;if(!i)return null;const t=i.cloneNode(!0);return e(n=_,ae).call(n,t),e(r=_,J).call(r,t,"thead"),e(o=_,J).call(o,t,"tbody"),Array.from(t.querySelectorAll("colgroup col")).forEach((l,h)=>{const d=l.getAttribute("fixed");d&&t.querySelectorAll(`[data-col="${h}"]`).forEach(u=>{u.setAttribute("fixed",d)})}),t}};ae=new WeakMap,J=new WeakMap,a(_,"TableCompiler"),c(_,ae,a(i=>{if(!i.querySelector("colgroup")){const t=i.querySelector("tbody tr")||i.querySelector("tr"),s=t?t.querySelectorAll("th, td").length:1,n=document.createElement("colgroup"),r=Math.max(Math.floor(i.clientWidth/s),100);for(let o=0;o<s;o++){const l=document.createElement("col");l.setAttribute("width",r),n.appendChild(l)}i.prepend(n)}if(!i.querySelector("thead")){const t=document.createElement("thead"),s=i.querySelector("colgroup");s?s.after(t):i.prepend(t)}i.classList.add("nine-table-element"),i.style.display="table"},"#ensureTableStructure")),c(_,J,a((i,t)=>{const s=Array.from(i.querySelectorAll(t+" tr")),n=Array.from(i.querySelectorAll(t+" th,"+t+" td")),r=s.length;if(r===0||n.length===0)return;let o=0;n.forEach(h=>{o+=h.colSpan||1});const l=Array.from(Array(r),()=>Array(o).fill(null));s.forEach(h=>{const d=h.sectionRowIndex;let u=0;Array.from(h.querySelectorAll("th,td")).forEach(f=>{for(let E=0;E<l[d].length;E++)if(l[d][E]===null){u=E;break}const m=f.rowSpan||1,v=f.colSpan||1;for(let E=0;E<m;E++)for(let O=0;O<v;O++)d+E<r&&u+O<o&&(l[d+E][u+O]=E===0&&O===0?"1":"0")})}),s.forEach(h=>{const d=h.sectionRowIndex;Array.from(h.querySelectorAll("th,td")).forEach(u=>{for(let f=0;f<l[d].length;f++)if(l[d][f]==="1"){u.dataset.col=f,l[d][f]="0";break}})})},"#resetColIndex"));let G=_;const We=class We{constructor(i){c(this,A);c(this,H,new Map);c(this,q,null);c(this,M,null);c(this,V,0);c(this,X,40);S(this,"initialize",a(()=>{b(this,q,null),e(this,H).clear(),[".ng-container-body",".ng-container-left",".ng-container-right"].forEach(t=>{const s=e(this,A).querySelector(t);if(!s)return;const n=s.querySelector("table");if(!n)return;const r=n.querySelector("tbody");if(!r)return;const l=Array.from(r.querySelectorAll("tr")).map(h=>h.cloneNode(!0));e(this,H).set(t,l)});const i=e(this,A).querySelector(".ng-container-body");i&&(e(this,he).call(this,i),e(this,ee).call(this))},"initialize"));c(this,ce,a((i,t)=>{const s=e(this,H).get(t);if(!s||s.length===0)return;const n=i.querySelector("tbody");if(!n)return;n.querySelectorAll("tr:not(.nodata)").forEach(l=>l.remove());const r=n.querySelector("tr.nodata"),o=document.createDocumentFragment();for(let l=0;l<e(this,X);l++)s.forEach(h=>{o.appendChild(h.cloneNode(!0))});r?r.before(o):n.appendChild(o)},"#renderRows"));c(this,he,a(i=>{if(e(this,q)!==null&&e(this,q)>0)return e(this,q);const t=e(this,H).get(".ng-container-body");if(!t||t.length===0)return 24;const s=i.querySelector("tbody");if(!s)return 24;s.querySelectorAll("tr:not(.nodata)").forEach(m=>m.remove());const n=s.querySelector("tr.nodata"),r=document.createDocumentFragment();t.forEach(m=>{r.appendChild(m.cloneNode(!0))}),n?n.before(r):s.appendChild(r);const o=e(this,A),l=o.style.display,h=o.style.visibility,d=o.style.position;(l==="none"||window.getComputedStyle(o).display==="none")&&(o.style.display="block",o.style.visibility="hidden",o.style.position="absolute");let u=0;const f=s.querySelectorAll("tr:not(.nodata)");return f.forEach(m=>{u+=m.offsetHeight||m.getBoundingClientRect().height}),f.forEach(m=>m.remove()),o.style.display=l,o.style.visibility=h,o.style.position=d,b(this,q,u>0?u:24),e(this,Q).call(this),x.log(`[RowManager] Height Cached: ${e(this,q)}px | RowCount: ${e(this,X)}`),e(this,q)},"#measureAndCacheHeight"));c(this,Q,a(()=>{if(e(this,V)>0&&e(this,q)>0){const i=Math.ceil(e(this,V)/e(this,q));b(this,X,i+20)}else b(this,X,40)},"#updateRowCount"));c(this,de,a(()=>{var h,d,u;const i=e(this,A).querySelector(".ng-container-left table"),t=e(this,A).querySelector(".ng-container-body table"),s=e(this,A).querySelector(".ng-container-right table");if(!t)return;const n=i?Array.from(i.querySelectorAll("tr")):[],r=Array.from(t.querySelectorAll("tr")),o=s?Array.from(s.querySelectorAll("tr")):[],l=Math.max(n.length,r.length,o.length);for(let f=0;f<l;f++){const m=[((h=n[f])==null?void 0:h.getBoundingClientRect().height)||0,((d=r[f])==null?void 0:d.getBoundingClientRect().height)||0,((u=o[f])==null?void 0:u.getBoundingClientRect().height)||0],v=Math.max(...m);v>0&&(n[f]&&(n[f].style.height=`${v}px`),r[f]&&(r[f].style.height=`${v}px`),o[f]&&(o[f].style.height=`${v}px`))}},"#syncRowHeights"));c(this,fe,a(()=>{!e(this,A)||!(e(this,A)instanceof HTMLElement)||(b(this,M,new ResizeObserver(i=>{for(const t of i){const s=t.target;if(!s.classList.contains("active"))continue;const n=t.contentRect.height;if(n>0){let r=0;const o=s.querySelector("thead");o&&(r+=o.offsetHeight||o.getBoundingClientRect().height);const l=Math.max(n-r,100);e(this,V)!==l&&(b(this,V,l),e(this,Q).call(this),e(this,q)!==null&&e(this,ee).call(this))}}})),e(this,M).observe(e(this,A)))},"#initResizeObserver"));c(this,ee,a(()=>{[".ng-container-body",".ng-container-left",".ng-container-right"].forEach(i=>{const t=e(this,A).querySelector(i);t&&t.querySelector("tbody")&&e(this,ce).call(this,t,i)}),e(this,de).call(this)},"#renderAllContainers"));S(this,"destroy",a(()=>{e(this,M)&&(e(this,M).disconnect(),b(this,M,null))},"destroy"));b(this,A,i),e(this,fe).call(this)}getRowHeight(){return e(this,q)}templateLength(i=".ng-container-body"){var t;return((t=e(this,H).get(i))==null?void 0:t.length)||1}};A=new WeakMap,H=new WeakMap,q=new WeakMap,M=new WeakMap,V=new WeakMap,X=new WeakMap,ce=new WeakMap,he=new WeakMap,Q=new WeakMap,de=new WeakMap,fe=new WeakMap,ee=new WeakMap,a(We,"RowManager");let qe=We;const te=class te extends HTMLElement{constructor(){super();c(this,F,null);c(this,K);c(this,ue,a(()=>{[{selector:".ng-container-body",type:null},{selector:".ng-container-left",type:"left"},{selector:".ng-container-right",type:"right"}].forEach(({selector:s,type:n})=>{const r=this.querySelector(s);if(!r)return;const o=e(this,be).call(this,e(this,F),n);r.innerHTML="",r.appendChild(o)})},"#renderSplitContainers"));c(this,ge,a(()=>{["left","right"].forEach(t=>{const s=this.querySelector(`.ng-container-${t}`),n=s==null?void 0:s.querySelector("table");if(!s||!n)return;let r=0;n.querySelectorAll("col").forEach(o=>{const l=parseInt(o.getAttribute("width"),10);isNaN(r)||(r+=l)}),s.style.flex=`0 0 ${r}px`,s.style.width=`${r}px`})},"#updateContainerWidths"));S(this,"generate",a(t=>{if(!t)return;b(this,F,G.compile(t)),e(this,F).style.display="table",e(this,ue).call(this),e(this,K).initialize(),e(this,ge).call(this);const s=this.querySelector(".ng-container-body");s&&s.addEventListener("scroll",()=>{var n;(n=this.querySelector("nine-table-hscrollbar"))==null||n.refresh()}),setTimeout(()=>{var n;(n=this.querySelector("nine-table-hscrollbar"))==null||n.refresh()},0)},"generate"));c(this,be,a((t,s)=>{const n=t.cloneNode(!0);return s==="left"?n.querySelectorAll("col, th, td").forEach(r=>{r.getAttribute("fixed")!=="left"&&r.remove()}):s==="right"?n.querySelectorAll("col, th, td").forEach(r=>{r.getAttribute("fixed")!=="right"&&r.remove()}):n.querySelectorAll("[fixed=left], [fixed=right]").forEach(r=>{r.remove()}),n},"#createSplitTable"));S(this,"getRowHeight",a(()=>e(this,K).getRowHeight(),"getRowHeight"));S(this,"scrollToX",a(t=>{const s=this.querySelector(".ng-container-body");s&&(s.scrollLeft=t)},"scrollToX"));S(this,"scrollToY",a(t=>{const s=this.querySelector(".ng-container-body");s&&(s.scrollTop=t)},"scrollToY"));c(this,ye,a(()=>{e(this,pe).call(this)},"#init"));c(this,pe,a(()=>{const t=te.SCROLLBAR_SIZE;this.innerHTML=`
|
|
64
64
|
<style>
|
|
65
65
|
nine-table-sheet {
|
|
66
66
|
display: none;
|
|
@@ -180,7 +180,7 @@
|
|
|
180
180
|
<nine-table-hscrollbar></nine-table-hscrollbar>
|
|
181
181
|
<div class='ng-scroll-edge'></div>
|
|
182
182
|
</div>
|
|
183
|
-
`},"#render"));b(this,
|
|
183
|
+
`},"#render"));b(this,K,new qe(this))}connectedCallback(){e(this,ye).call(this)}disconnectedCallback(){this.innerHTML="",x.log("NineTableSheet destroyed.")}};F=new WeakMap,K=new WeakMap,ue=new WeakMap,ge=new WeakMap,be=new WeakMap,ye=new WeakMap,pe=new WeakMap,a(te,"NineTableSheet"),S(te,"SCROLLBAR_SIZE",16);let re=te;customElements.get("nine-table-sheet")||customElements.define("nine-table-sheet",re);const $e=class $e extends HTMLElement{constructor(){super();c(this,me,a(()=>{var t;(t=this.querySelector(".nine-tab-bar"))==null||t.addEventListener("click",s=>{var o;const n=s.ctrlKey||s.metaKey||s.shiftKey,r=parseInt((o=s.target.closest(".nine-tab-item"))==null?void 0:o.dataset.index,10);e(this,ie).call(this,r,n)}),e(this,ie).call(this,0,!1)},"#init"));c(this,ie,a((t,s=!1)=>{const n=a(()=>{const u=Array.from(this.querySelectorAll("nine-table-sheet"));Array.from(this.querySelectorAll("nine-splitter")).forEach(v=>v.style.setProperty("display","none"));const m=u.filter(v=>v.classList.contains("active"));m.length<2||m.forEach(v=>{const E=parseInt(v.getAttribute("data-index"),10),O=this.querySelector(`nine-splitter[data-split-index="${E}"]`),Be=u[E+1];O&&Be&&Be.classList.contains("active")&&O.style.setProperty("display","flex")})},"updateSplitters"),r=this.querySelector(".nine-tab-bar"),o=this.querySelector("nine-table-sheets-body"),l=r.querySelectorAll(".nine-tab-item"),h=o.querySelectorAll("nine-table-sheet");if(!l[t])return;if(!s)l.forEach((u,f)=>{u.classList.toggle("active",f===t)}),h.forEach((u,f)=>{const m=f===t;u.classList.toggle("active",m),u.style.flex=m?"1 1 100%":""});else{const u=l[t],f=r.querySelectorAll(".nine-tab-item.active");if(u.classList.contains("active")&&f.length<=1)return;u.classList.toggle("active");const m=o.querySelector(`nine-table-sheet[data-index="${t}"]`);m&&(m.classList.toggle("active"),m.classList.contains("active")||(m.style.flex=""))}const d=o.querySelectorAll("nine-table-sheet.active");d==null||d.forEach(u=>{u.style.flex=d.length>1?"1 1 0%":"1 1 100%"}),n()},"#switchSheet"))}connectedCallback(){e(this,me).call(this)}};me=new WeakMap,ie=new WeakMap,a($e,"NineTableSheets");let Te=$e;customElements.get("nine-table-sheets")||customElements.define("nine-table-sheets",Te);const Oe=class Oe{constructor(i){c(this,R);c(this,we,a(()=>{e(this,xe).call(this),new ResizeObserver(i=>{for(let t of i)e(this,R).getAttribute("auto-height")==="true"&&e(this,se).call(this)}).observe(e(this,R))},"#init"));c(this,se,a(()=>{var h,d;const i=Array.from(e(this,R).shadowRoot.querySelectorAll("nine-table-sheet.active"));if(i.length===0)return;const t=parseInt(e(this,R).getAttribute("max-display-row"),10)||10,s=Math.max(...i.map(u=>u.getRowHeight())),n=(h=e(this,R).shadowRoot.querySelector("nine-table-header"))==null?void 0:h.getBoundingClientRect().height,r=(d=e(this,R).shadowRoot.querySelector("nine-table-sheets-footer"))==null?void 0:d.getBoundingClientRect().height,o=re.SCROLLBAR_SIZE,l=t*s+n+r+o;e(this,R).style.height=`${l}px`},"#applyAutoHeight"));c(this,xe,a(()=>{const t=Array.from(e(this,R).children).filter(h=>h.tagName==="TABLE"),s=e(this,R).getAttribute("auto-height")==="true",n=t.length,r=t.map((h,d)=>{const f=`<nine-table-sheet class="${d===0?"active":""}" data-index="${d}"></nine-table-sheet>`,m=d<n-1?`<nine-splitter class="h" data-split-index="${d}"></nine-splitter>`:"";return f+m}).join(""),o=t.map((h,d)=>`<div class="nine-tab-item ${d===0?"active":""}" data-index="${d}">Sheet ${d+1}</div>`).join("");e(this,R).shadowRoot.innerHTML=`
|
|
184
184
|
<style>
|
|
185
185
|
:host {
|
|
186
186
|
display: flex;
|
|
@@ -278,5 +278,5 @@
|
|
|
278
278
|
<nine-table-analysis></nine-table-analysis>
|
|
279
279
|
</nine-table-body>
|
|
280
280
|
<nine-table-footer></nine-table-footer>
|
|
281
|
-
`;const l=e(this,R).shadowRoot.querySelectorAll("nine-table-sheet");l==null||l.forEach((d
|
|
281
|
+
`;const l=e(this,R).shadowRoot.querySelectorAll("nine-table-sheet");l==null||l.forEach((h,d)=>{t[d]&&setTimeout(()=>{h.generate(t[d]),s&&e(this,se).call(this)})})},"#render"));b(this,R,i),e(this,we).call(this)}};R=new WeakMap,we=new WeakMap,se=new WeakMap,xe=new WeakMap,a(Oe,"LayoutManager");let ke=Oe;const ze=class ze{constructor(i){c(this,W);c(this,Y,-1);S(this,"count",a(()=>e(this,W).rawRecords.length,"count"));b(this,W,i)}get at(){return e(this,Y)}set at(i){var s,n;b(this,Y,parseInt(i,10));const t=((n=(s=e(this,W).owner).querySelector)==null?void 0:n.call(s,".ng-container-body"))||e(this,W).owner.body;t&&!t.querySelector(`tbody.bindable tr[data-row="${e(this,Y)}"]`)&&setTimeout(()=>{var r,o;(o=(r=e(this,W).owner).scrollTo_V1)==null||o.call(r,e(this,Y))})}};W=new WeakMap,Y=new WeakMap,a(ze,"ngRow");let Le=ze;const L=class L{constructor(i,t){c(this,T);c(this,w);c(this,k,[]);c(this,Z,[]);c(this,ve,0);c(this,$,[]);c(this,Se,a(()=>{b(this,$,[]);const i=e(this,T).template||[];Array.from(i).forEach(t=>{var s;e(this,$).push(((s=t.getBoundingClientRect)==null?void 0:s.call(t).height)||24)}),(e(this,w).rawRecords||[]).forEach(t=>{t.__ng||(t.__ng=e(this,ne).call(this)),t.__ng.height=e(this,$).slice()})},"#initialize"));S(this,"set",a(i=>{this.clear(),this.add(i,!1)},"set"));c(this,ne,a(()=>({rowState:L.ROW_STATE.EMPTY,deleted:!1,filtered:!1,height:e(this,$).slice(),o:{},c:{},_:[0,0,0,0,L.ROW_STATE.EMPTY,!1,!1,!0,!1,!0,!0,!1,e(this,$).slice(),-1,{},{}]}),"#getDefaultMeta"));S(this,"reset",a(()=>{b(this,k,[]),b(this,Z,[])},"reset"));S(this,"clear",a(()=>{var i;e(this,w).rawRecords=[],b(this,k,[]),b(this,Z,[]),(i=e(this,w).viewRecords)!=null&&i.reset&&e(this,w).viewRecords.reset()},"clear"));c(this,Ee,a(i=>{var n;Array.isArray(i)||(i=[i]);const t=typeof((n=e(this,T).fields)==null?void 0:n.get)=="function"?e(this,T).fields.get():Object.keys(i[0]||{}),s=[];return i.forEach(r=>{const o={v:[]};t.forEach(l=>{o.v.push(r[l]!==void 0&&r[l]!==null?r[l]:"")}),s.push(o)}),s},"#json2Array"));c(this,Re,a(i=>(Array.isArray(i)||(i=[i]),i.forEach(t=>{t.__ng=e(this,ne).call(this),t.__ng.rowid=this.nextId,t.__ng.rowState=L.ROW_STATE.INSERT,t.__ng._[0]=t.__ng.rowid}),i),"#defaultInsert"));S(this,"add",a((i,t=!0)=>{var r;i===void 0&&(i={});const s=e(this,Ee).call(this,i);e(this,w).rawRecords=e(this,w).rawRecords.concat(e(this,Re).call(this,s)),this.resetRecords();const n=this.count()-1;return t||s.forEach((o,l)=>{const h=e(this,w).rawRecords[n-l];h&&(h.__ng.rowState=L.ROW_STATE.EMPTY)}),(r=e(this,w).viewRecords)!=null&&r.reset&&e(this,w).viewRecords.reset(),n},"add"));S(this,"delete",a(i=>{var s;let t=[];Array.isArray(i)?t=i:typeof i>"u"?t=[e(this,w).owner.row.at]:t=[parseInt(i,10)],t.sort((n,r)=>r-n).forEach(n=>{if(e(this,k)[n]){const r=e(this,k)[n].__ng.rowid;e(this,k)[n].__ng.rowState===L.ROW_STATE.INSERT?e(this,w).rawRecords=e(this,w).rawRecords.filter(o=>o.__ng.rowid!==r):e(this,w).rawRecords.forEach(o=>{o.__ng.rowid===r&&(o.__ng.deleted=!0,o.__ng.rowState=L.ROW_STATE.DELETE)})}}),this.resetRecords(),(s=e(this,w).viewRecords)!=null&&s.reset&&e(this,w).viewRecords.reset()},"delete"));S(this,"setValue",a((i,t,s)=>{var h;i=parseInt(i,10);const r=(typeof((h=e(this,T).fields)==null?void 0:h.get)=="function"?e(this,T).fields.get():[]).indexOf(t);if(r<0)return;const o=this.getValidData()[i];if(!o)return;const l=o.v[r];l!==s&&o.__ng.rowState!==L.ROW_STATE.INSERT&&(o.__ng.o.hasOwnProperty(t)||(o.__ng.o[t]=l),o.__ng.rowState=L.ROW_STATE.UPDATE),o.v[r]=s,e(this,w).owner.refreshData&&e(this,w).owner.refreshData(i)},"setValue"));S(this,"resetRecords",a(()=>{b(this,Z,e(this,w).rawRecords.filter(i=>!i.__ng.deleted)),b(this,k,e(this,w).rawRecords.filter(i=>!i.__ng.deleted&&!i.__ng.filtered)),e(this,w).rawRecords.forEach((i,t)=>{i.__ng.rowidx=t}),e(this,k).forEach((i,t)=>{i.__ng.i=t})},"resetRecords"));S(this,"getValidData",a(()=>(e(this,k).length===0&&e(this,w).rawRecords.length>0&&this.resetRecords(),e(this,k)),"getValidData"));c(this,j,a(i=>{var s;if(!i)return i;const t=typeof((s=e(this,T).fields)==null?void 0:s.get)=="function"?e(this,T).fields.get():[];return Array.isArray(i)?i.filter(n=>!n.__ng.deleted).map(n=>{const r={};return t.forEach((o,l)=>{r[o]=n.v?n.v[l]:n[o]}),r.__ng=n.__ng,r}):i},"#conv2"));S(this,"count",a(()=>this.getValidData().length,"count"));S(this,"get",a((i,t)=>{var r;const s=this.getValidData();if(!s||s.length<=0)return;if(i==null)return e(this,j).call(this,s);if(i<0||i>=s.length)return null;const n=typeof((r=e(this,T).fields)==null?void 0:r.get)=="function"?e(this,T).fields.get():[];if(t!=null){const o=n.indexOf(t);return o>=0?s[i].v[o]:null}return e(this,j).call(this,s[i])},"get"));b(this,T,i),b(this,w,t),e(this,Se).call(this)}get source(){return e(this,j).call(this,e(this,w).rawRecords)}set source(i){this.clear(),this.add(i,!1)}get nextId(){return++Ye(this,ve)._}get length(){return e(this,k).length}getRowCount(){return this.length}};T=new WeakMap,w=new WeakMap,k=new WeakMap,Z=new WeakMap,ve=new WeakMap,$=new WeakMap,Se=new WeakMap,ne=new WeakMap,Ee=new WeakMap,Re=new WeakMap,j=new WeakMap,a(L,"ngData"),S(L,"ROW_STATE",{EMPTY:"EMPTY",NORMAL:"NORMAL",INSERT:"INSERT",UPDATE:"UPDATE",DELETE:"DELETE"});let Ce=L;const De=class De{constructor(i){this.owner=i,this.row=new Le(this),this.data=new Ce(i,this),this.rawRecords=[],this.viewRecords=[],this.delRecords=[],this.pageCnt=25,this.viewRecords.reset=()=>{var t;(t=this.owner.view)!=null&&t.redraw&&this.owner.view.redraw()},this.setDataSource=t=>{this.data&&this.data.reset(),this.rawRecords=[],this.viewRecords=[],this.delRecords=[],this.data.set(t||[])},this.getRowState=t=>{var n,r;const s=parseInt(t,10);if(!(s>=this.data.count()))return(r=(n=this.data.getValidData()[s])==null?void 0:n.__ng)==null?void 0:r.rowState},this.getRowPosition=()=>this.row.at,this.setRowPosition=t=>{this.row.at=t},this.scrollTo_V1=t=>(t<0&&(t=0),t>=this.rawRecords.length&&(t=this.rawRecords.length-1),this.viewRecords.rawIndex=t,this.viewRecords.reset&&this.viewRecords.reset(),!(t<=0||t>=this.rawRecords.length-1)),this.getColumn=(t,s)=>this.data.get(t,s),this.setColumn=(t,s,n)=>{t=parseInt(t,10),this.data.setValue(t,s,n)},this.setDataSource([])}};a(De,"ngDataManager");let _e=De;const Ne=class Ne extends HTMLElement{constructor(){super();c(this,U);c(this,Ae);this.attachShadow({mode:"open"}),b(this,U,new _e(this))}connectedCallback(){b(this,Ae,new ke(this)),x.log("NineTable connected."),this.dispatchEvent(new CustomEvent("load",{bubbles:!0,detail:{target:this}}))}disconnectedCallback(){x.log("NineTable disconnected.")}get data(){return e(this,U).data}get row(){return e(this,U).row}get dataManager(){return e(this,U)}};U=new WeakMap,Ae=new WeakMap,a(Ne,"NineTable");let Ie=Ne;customElements.get("nine-table")||customElements.define("nine-table",Ie)});
|
|
282
282
|
//# sourceMappingURL=nine-table.umd.js.map
|