@ninebone/table 0.0.274 → 0.0.276
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 +338 -344
- package/dist/nine-table.js.map +1 -1
- package/dist/nine-table.umd.js +5 -5
- 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,b){typeof exports=="object"&&typeof module<"u"?b(require("@ninebone/util")):typeof define=="function"&&define.amd?define(["@ninebone/util"],b):(y=typeof globalThis<"u"?globalThis:y||self,b(y.NineboneUtil))})(this,function(y){"use strict";var
|
|
1
|
+
(function(y,b){typeof exports=="object"&&typeof module<"u"?b(require("@ninebone/util")):typeof define=="function"&&define.amd?define(["@ninebone/util"],b):(y=typeof globalThis<"u"?globalThis:y||self,b(y.NineboneUtil))})(this,function(y){"use strict";var Ne=Object.defineProperty;var Be=y=>{throw TypeError(y)};var Xe=(y,b,x)=>b in y?Ne(y,b,{enumerable:!0,configurable:!0,writable:!0,value:x}):y[b]=x;var a=(y,b)=>Ne(y,"name",{value:b,configurable:!0});var S=(y,b,x)=>Xe(y,typeof b!="symbol"?b+"":b,x),Pe=(y,b,x)=>b.has(y)||Be("Cannot "+x);var e=(y,b,x)=>(Pe(y,b,"read from private field"),x?x.call(y):b.get(y)),h=(y,b,x)=>b.has(y)?Be("Cannot add the same private member more than once"):b instanceof WeakSet?b.add(y):b.set(y,x),g=(y,b,x,M)=>(Pe(y,b,"write to private field"),M?M.call(y,x):b.set(y,x),x);var Ve=(y,b,x,M)=>({set _(J){g(y,b,J,x)},get _(){return e(y,b,M)}});var L,D,p,N,B,P,ae,V,ce,C,_,A,$,X,Y,he,Q,de,ee,fe,ue,te,H,K,Z,ie,ge,be,ye,ne,R,pe,re,me,W,F,q,w,T,j,we,O,xe,oe,ve,Se,G,U,Ee;const _e=class _e extends y.trace.constructor{constructor(){super(),this.init("nine-table","green")}};a(_e,"Trace");let b=_e;const x=new b,Ie=class Ie extends HTMLElement{constructor(){super();h(this,L);h(this,D,!1);h(this,p);h(this,N);h(this,B);h(this,P);h(this,ae,a(()=>{if(!e(this,L))return;const t=e(this,L).querySelector(".ng-container-body");t&&(g(this,P,new ResizeObserver(()=>{this.refresh()})),e(this,P).observe(t))},"#observeResize"));S(this,"refresh",a(()=>{if(!e(this,L)||!e(this,p)||e(this,D))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,L).querySelector(".ng-container-bottom"),l=t.clientWidth,d=s.scrollWidth;if(l!==0&&d>l)o&&(o.style.display="flex");else{o&&(o.style.display="none");return}const c=n.clientWidth;if(c<=0)return;const f=Math.max(Math.min(c*(l/d),c),20);r.style.width=`${f}px`;const u=t.scrollLeft,m=d-l;let E=0;m>0&&(E=parseInt(u/m*(c-f),10)),E<0&&(E=0);const v=c-f;E>v&&(E=v),r.style.left=`${E}px`,x.log(E),e(this,p).left.disabled=E===0,e(this,p).right.disabled=E>=v-1},"refresh"));h(this,V,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 d=r.width-o;l>d&&(l=d),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>=d-1;const c=s.clientWidth,f=n.scrollWidth;let u=d>0?-l*(f-c)/d:0;return-u>f-c&&(u=-(f-c)),-u+5>f-c&&(u=-(f-c)),c>=f&&(u=0),n.style.transform=`translateX(${u}px)`,l>0&&l<d-1},"#thumbMoveTo"));h(this,ce,a(()=>{const t=a(n=>{clearInterval(e(this,N)),clearInterval(e(this,B));const r=parseInt(e(this,p).thumb.style.left||0,10);e(this,V).call(this,r+n),g(this,N,setInterval(()=>{clearInterval(e(this,N)),g(this,B,setInterval(()=>{const o=parseInt(e(this,p).thumb.style.left||0,10);e(this,V).call(this,o+n)||clearInterval(e(this,B))},50))},500))},"delayScroll"),s=a(()=>{clearInterval(e(this,N)),clearInterval(e(this,B))},"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,V).call(this,n.clientX-r.left-o/2)}),e(this,p).thumb.addEventListener("mousedown",n=>{if(n.button!==0)return;n.stopPropagation(),n.preventDefault(),g(this,D,!0),this.shiftX=n.clientX-e(this,p).thumb.getBoundingClientRect().left;const r=a(l=>{if(!e(this,D))return;const d=e(this,p).track.getBoundingClientRect();e(this,V).call(this,l.clientX-d.left-this.shiftX)},"onMouseMove"),o=a(()=>{g(this,D,!1),s(),document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",o),this.refresh()},"onMouseUp");document.addEventListener("mousemove",r),document.addEventListener("mouseup",o)})},"#init"))}connectedCallback(){if(g(this,L,this.closest("nine-table-sheet")||this.getRootNode().host),!e(this,L))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,L).querySelector(".ng-container-body");if(!s){setTimeout(t,10);return}g(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,
|
|
63
|
+
`;const t=a(()=>{const s=e(this,L).querySelector(".ng-container-body");if(!s){setTimeout(t,10);return}g(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,ce).call(this),e(this,ae).call(this),this.refresh()},"initWhenReady");t()}disconnectedCallback(){e(this,P)&&e(this,P).disconnect()}};L=new WeakMap,D=new WeakMap,p=new WeakMap,N=new WeakMap,B=new WeakMap,P=new WeakMap,ae=new WeakMap,V=new WeakMap,ce=new WeakMap,a(Ie,"NineTableHScrollBar");let M=Ie;customElements.get("nine-table-hscrollbar")||customElements.define("nine-table-hscrollbar",M);const He=class He{constructor(i){h(this,C);h(this,_,[]);h(this,A,null);h(this,$,null);h(this,X,0);h(this,Y,40);S(this,"initialize",a(i=>{if(!i)return;const t=i.querySelector("tbody");if(!t)return;const s=Array.from(t.querySelectorAll("tr"));g(this,_,s.map(r=>r.cloneNode(!0))),g(this,A,null);const n=e(this,C).querySelector(".ng-container-body");n&&(e(this,he).call(this,n),e(this,ee).call(this))},"initialize"));h(this,he,a(i=>{if(e(this,A)!==null&&e(this,A)>0)return e(this,A);if(e(this,_).length===0)return 24;const t=i.querySelector("tbody");if(!t)return 24;t.querySelectorAll("tr:not(.nodata)").forEach(u=>u.remove());const s=t.querySelector("tr.nodata"),n=document.createDocumentFragment();e(this,_).forEach(u=>{n.appendChild(u.cloneNode(!0))}),s?s.before(n):t.appendChild(n);const r=e(this,C),o=r.style.display,l=r.style.visibility,d=r.style.position;(o==="none"||window.getComputedStyle(r).display==="none")&&(r.style.display="block",r.style.visibility="hidden",r.style.position="absolute");let c=0;const f=t.querySelectorAll("tr:not(.nodata)");return f.forEach(u=>{c+=u.offsetHeight||u.getBoundingClientRect().height}),f.forEach(u=>u.remove()),r.style.display=o,r.style.visibility=l,r.style.position=d,g(this,A,c>0?c:24),e(this,Q).call(this),x.log(`[RowManager] Height Cached: ${e(this,A)}px | RowCount: ${e(this,Y)}`),e(this,A)},"#measureAndCacheHeight"));h(this,Q,a(()=>{if(e(this,X)>0&&e(this,A)>0){const i=Math.ceil(e(this,X)/e(this,A));g(this,Y,i+20)}else g(this,Y,40)},"#updateRowCount"));h(this,de,a(()=>{!e(this,C)||!(e(this,C)instanceof HTMLElement)||(g(this,$,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,X)!==l&&(g(this,X,l),e(this,Q).call(this),e(this,A)!==null&&e(this,ee).call(this))}}})),e(this,$).observe(e(this,C)))},"#initResizeObserver"));h(this,ee,a(()=>{[".ng-container-body",".ng-container-left",".ng-container-right"].forEach(i=>{const t=e(this,C).querySelector(i);t&&t.querySelector("tbody")&&e(this,fe).call(this,t)})},"#renderAllContainers"));h(this,fe,a(i=>{if(e(this,_).length===0)return;const t=i.querySelector("tbody");if(!t)return;t.querySelectorAll("tr:not(.nodata)").forEach(r=>r.remove());const s=t.querySelector("tr.nodata"),n=(document.getDocumentFragment,document.createDocumentFragment());for(let r=0;r<e(this,Y);r++)e(this,_).forEach(o=>{n.appendChild(o.cloneNode(!0))});s?s.before(n):t.appendChild(n)},"#renderRows"));S(this,"destroy",a(()=>{e(this,$)&&(e(this,$).disconnect(),g(this,$,null))},"destroy"));g(this,C,i),e(this,de).call(this)}getRowHeight(){return e(this,A)}templateLength(){return e(this,_).length||1}};C=new WeakMap,_=new WeakMap,A=new WeakMap,$=new WeakMap,X=new WeakMap,Y=new WeakMap,he=new WeakMap,Q=new WeakMap,de=new WeakMap,ee=new WeakMap,fe=new WeakMap,a(He,"RowManager");let J=He;const I=class I{static compileAll(i){return Array.isArray(i)?i.map(t=>I.compile(t)):[]}static compile(i){var n,r,o;if(!i)return null;const t=i.cloneNode(!0);return e(n=I,ue).call(n,t),e(r=I,te).call(r,t,"thead"),e(o=I,te).call(o,t,"tbody"),Array.from(t.querySelectorAll("colgroup col")).forEach((l,d)=>{const c=l.getAttribute("fixed");c&&t.querySelectorAll(`[data-col="${d}"]`).forEach(f=>{f.setAttribute("fixed",c)})}),t}};ue=new WeakMap,te=new WeakMap,a(I,"TableCompiler"),h(I,ue,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")),h(I,te,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(d=>{o+=d.colSpan||1});const l=Array.from(Array(r),()=>Array(o).fill(null));s.forEach(d=>{const c=d.sectionRowIndex;let f=0;Array.from(d.querySelectorAll("th,td")).forEach(u=>{for(let v=0;v<l[c].length;v++)if(l[c][v]===null){f=v;break}const m=u.rowSpan||1,E=u.colSpan||1;for(let v=0;v<m;v++)for(let z=0;z<E;z++)c+v<r&&f+z<o&&(l[c+v][f+z]=v===0&&z===0?"1":"0")})}),s.forEach(d=>{const c=d.sectionRowIndex;Array.from(d.querySelectorAll("th,td")).forEach(f=>{for(let u=0;u<l[c].length;u++)if(l[c][u]==="1"){f.dataset.col=u,l[c][u]="0";break}})})},"#resetColIndex"));let Re=I;const se=class se extends HTMLElement{constructor(){super();h(this,H,null);h(this,K);S(this,"generate",a(t=>{if(!t)return;g(this,H,Re.compile(t)),e(this,H).style.display="table";const s=this.querySelector(".ng-container-left"),n=this.querySelector(".ng-container-body"),r=this.querySelector(".ng-container-right");if(n){const o=e(this,Z).call(this,e(this,H),null);n.innerHTML="",n.appendChild(o),e(this,K).initialize(e(this,H))}if(s){const o=e(this,Z).call(this,e(this,H),"left");let l=0;o.querySelectorAll("col").forEach(c=>{const f=parseInt(c.getAttribute("width"),10);isNaN(f)||(l+=f)}),s.innerHTML="",s.appendChild(o);const d=l>0?l:0;s.style.flex=`0 0 ${d}px`,s.style.width=`${d}px`}if(r){const o=e(this,Z).call(this,e(this,H),"right");let l=0;o.querySelectorAll("col").forEach(c=>{const f=parseInt(c.getAttribute("width"),10);isNaN(f)||(l+=f)}),r.innerHTML="",r.appendChild(o);const d=l>0?l:0;r.style.flex=`0 0 ${d}px`,r.style.width=`${d}px`}n&&n.addEventListener("scroll",()=>{var o;(o=this.querySelector("nine-table-hscrollbar"))==null||o.refresh()}),setTimeout(()=>{var o;e(this,ie).call(this),(o=this.querySelector("nine-table-hscrollbar"))==null||o.refresh()},0)},"generate"));h(this,Z,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"));h(this,ie,a(()=>{var c,f,u;const t=this.querySelector(".ng-container-left table"),s=this.querySelector(".ng-container-body table"),n=this.querySelector(".ng-container-right table");if(!s)return;const r=t?Array.from(t.querySelectorAll("tr")):[],o=Array.from(s.querySelectorAll("tr")),l=n?Array.from(n.querySelectorAll("tr")):[],d=Math.max(r.length,o.length,l.length);for(let m=0;m<d;m++){const E=[((c=r[m])==null?void 0:c.getBoundingClientRect().height)||0,((f=o[m])==null?void 0:f.getBoundingClientRect().height)||0,((u=l[m])==null?void 0:u.getBoundingClientRect().height)||0],v=Math.max(...E);v>0&&(r[m]&&(r[m].style.height=`${v}px`),o[m]&&(o[m].style.height=`${v}px`),l[m]&&(l[m].style.height=`${v}px`))}},"#syncRowHeights"));h(this,ge,a(()=>{e(this,be).call(this),new MutationObserver(t=>{for(const s of t)s.attributeName==="class"&&this.classList.contains("active")&&e(this,ie).call(this)}).observe(this,{attributes:!0})},"#init"));h(this,be,a(()=>{const t=se.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"));g(this,K,new J(this))}connectedCallback(){e(this,
|
|
183
|
+
`},"#render"));g(this,K,new J(this))}connectedCallback(){e(this,ge).call(this)}disconnectedCallback(){this.innerHTML="",x.log("NineTableSheet destroyed.")}};H=new WeakMap,K=new WeakMap,Z=new WeakMap,ie=new WeakMap,ge=new WeakMap,be=new WeakMap,a(se,"NineTableSheet"),S(se,"SCROLLBAR_SIZE",16);let le=se;customElements.get("nine-table-sheet")||customElements.define("nine-table-sheet",le);const Me=class Me extends HTMLElement{constructor(){super();h(this,ye,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,ne).call(this,r,n)}),e(this,ne).call(this,0,!1)},"#init"));h(this,ne,a((t,s=!1)=>{const n=a(()=>{const f=Array.from(this.querySelectorAll("nine-table-sheet"));Array.from(this.querySelectorAll("nine-splitter")).forEach(E=>E.style.setProperty("display","none"));const m=f.filter(E=>E.classList.contains("active"));m.length<2||m.forEach(E=>{const v=parseInt(E.getAttribute("data-index"),10),z=this.querySelector(`nine-splitter[data-split-index="${v}"]`),De=f[v+1];z&&De&&De.classList.contains("active")&&z.style.setProperty("display","flex")})},"updateSplitters"),r=this.querySelector(".nine-tab-bar"),o=this.querySelector("nine-table-sheets-body"),l=r.querySelectorAll(".nine-tab-item"),d=o.querySelectorAll("nine-table-sheet");if(!l[t])return;if(!s)l.forEach((f,u)=>{f.classList.toggle("active",u===t)}),d.forEach((f,u)=>{const m=u===t;f.classList.toggle("active",m),f.style.flex=m?"1 1 100%":""});else{const f=l[t],u=r.querySelectorAll(".nine-tab-item.active");if(f.classList.contains("active")&&u.length<=1)return;f.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 c=o.querySelectorAll("nine-table-sheet.active");c==null||c.forEach(f=>{f.style.flex=c.length>1?"1 1 0%":"1 1 100%"}),n()},"#switchSheet"))}connectedCallback(){e(this,ye).call(this)}};ye=new WeakMap,ne=new WeakMap,a(Me,"NineTableSheets");let Ae=Me;customElements.get("nine-table-sheets")||customElements.define("nine-table-sheets",Ae);const $e=class $e{constructor(i){h(this,R);h(this,pe,a(()=>{e(this,me).call(this),new ResizeObserver(i=>{for(let t of i)e(this,R).getAttribute("auto-height")==="true"&&e(this,re).call(this)}).observe(e(this,R))},"#init"));h(this,re,a(()=>{var d,c;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(f=>f.getRowHeight())),n=(d=e(this,R).shadowRoot.querySelector("nine-table-header"))==null?void 0:d.getBoundingClientRect().height,r=(c=e(this,R).shadowRoot.querySelector("nine-table-sheets-footer"))==null?void 0:c.getBoundingClientRect().height,o=le.SCROLLBAR_SIZE,l=t*s+n+r+o;e(this,R).style.height=`${l}px`},"#applyAutoHeight"));h(this,me,a(()=>{const t=Array.from(e(this,R).children).filter(d=>d.tagName==="TABLE"),s=e(this,R).getAttribute("auto-height")==="true",n=t.length,r=t.map((d,c)=>{const u=`<nine-table-sheet class="${c===0?"active":""}" data-index="${c}"></nine-table-sheet>`,m=c<n-1?`<nine-splitter class="h" data-split-index="${c}"></nine-splitter>`:"";return u+m}).join(""),o=t.map((d,c)=>`<div class="nine-tab-item ${c===0?"active":""}" data-index="${c}">Sheet ${c+1}</div>`).join("");e(this,R).shadowRoot.innerHTML=`
|
|
184
184
|
<style>
|
|
185
185
|
:host {
|
|
186
186
|
display: flex;
|
|
@@ -269,7 +269,7 @@
|
|
|
269
269
|
<nine-table-body>
|
|
270
270
|
<nine-table-summary></nine-table-summary>
|
|
271
271
|
<nine-table-sheets>
|
|
272
|
-
<nine-table-sheets-body>${
|
|
272
|
+
<nine-table-sheets-body>${r}</nine-table-sheets-body>
|
|
273
273
|
<nine-table-sheets-footer>
|
|
274
274
|
<div class="nine-tab-bar">${o}</div>
|
|
275
275
|
<div class="sheets-counter">Total : <span id="row-count">0</span></div>
|
|
@@ -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,
|
|
281
|
+
`;const l=e(this,R).shadowRoot.querySelectorAll("nine-table-sheet");l==null||l.forEach((d,c)=>{t[c]&&setTimeout(()=>{d.generate(t[c]),s&&e(this,re).call(this)})})},"#render"));g(this,R,i),e(this,pe).call(this)}};R=new WeakMap,pe=new WeakMap,re=new WeakMap,me=new WeakMap,a($e,"LayoutManager");let qe=$e;const We=class We{constructor(i){h(this,W);h(this,F,-1);S(this,"count",a(()=>e(this,W).rawRecords.length,"count"));g(this,W,i)}get at(){return e(this,F)}set at(i){var s,n;g(this,F,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,F)}"]`)&&setTimeout(()=>{var r,o;(o=(r=e(this,W).owner).scrollTo_V1)==null||o.call(r,e(this,F))})}};W=new WeakMap,F=new WeakMap,a(We,"ngRow");let Te=We;const k=class k{constructor(i,t){h(this,q);h(this,w);h(this,T,[]);h(this,j,[]);h(this,we,0);h(this,O,[]);h(this,xe,a(()=>{g(this,O,[]);const i=e(this,q).template||[];Array.from(i).forEach(t=>{var s;e(this,O).push(((s=t.getBoundingClientRect)==null?void 0:s.call(t).height)||24)}),(e(this,w).rawRecords||[]).forEach(t=>{t.__ng||(t.__ng=e(this,oe).call(this)),t.__ng.height=e(this,O).slice()})},"#initialize"));S(this,"set",a(i=>{this.clear(),this.add(i,!1)},"set"));h(this,oe,a(()=>({rowState:k.ROW_STATE.EMPTY,deleted:!1,filtered:!1,height:e(this,O).slice(),o:{},c:{},_:[0,0,0,0,k.ROW_STATE.EMPTY,!1,!1,!0,!1,!0,!0,!1,e(this,O).slice(),-1,{},{}]}),"#getDefaultMeta"));S(this,"reset",a(()=>{g(this,T,[]),g(this,j,[])},"reset"));S(this,"clear",a(()=>{var i;e(this,w).rawRecords=[],g(this,T,[]),g(this,j,[]),(i=e(this,w).viewRecords)!=null&&i.reset&&e(this,w).viewRecords.reset()},"clear"));h(this,ve,a(i=>{var n;Array.isArray(i)||(i=[i]);const t=typeof((n=e(this,q).fields)==null?void 0:n.get)=="function"?e(this,q).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"));h(this,Se,a(i=>(Array.isArray(i)||(i=[i]),i.forEach(t=>{t.__ng=e(this,oe).call(this),t.__ng.rowid=this.nextId,t.__ng.rowState=k.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,ve).call(this,i);e(this,w).rawRecords=e(this,w).rawRecords.concat(e(this,Se).call(this,s)),this.resetRecords();const n=this.count()-1;return t||s.forEach((o,l)=>{const d=e(this,w).rawRecords[n-l];d&&(d.__ng.rowState=k.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,T)[n]){const r=e(this,T)[n].__ng.rowid;e(this,T)[n].__ng.rowState===k.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=k.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 d;i=parseInt(i,10);const r=(typeof((d=e(this,q).fields)==null?void 0:d.get)=="function"?e(this,q).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!==k.ROW_STATE.INSERT&&(o.__ng.o.hasOwnProperty(t)||(o.__ng.o[t]=l),o.__ng.rowState=k.ROW_STATE.UPDATE),o.v[r]=s,e(this,w).owner.refreshData&&e(this,w).owner.refreshData(i)},"setValue"));S(this,"resetRecords",a(()=>{g(this,j,e(this,w).rawRecords.filter(i=>!i.__ng.deleted)),g(this,T,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,T).forEach((i,t)=>{i.__ng.i=t})},"resetRecords"));S(this,"getValidData",a(()=>(e(this,T).length===0&&e(this,w).rawRecords.length>0&&this.resetRecords(),e(this,T)),"getValidData"));h(this,G,a(i=>{var s;if(!i)return i;const t=typeof((s=e(this,q).fields)==null?void 0:s.get)=="function"?e(this,q).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,G).call(this,s);if(i<0||i>=s.length)return null;const n=typeof((r=e(this,q).fields)==null?void 0:r.get)=="function"?e(this,q).fields.get():[];if(t!=null){const o=n.indexOf(t);return o>=0?s[i].v[o]:null}return e(this,G).call(this,s[i])},"get"));g(this,q,i),g(this,w,t),e(this,xe).call(this)}get source(){return e(this,G).call(this,e(this,w).rawRecords)}set source(i){this.clear(),this.add(i,!1)}get nextId(){return++Ve(this,we)._}get length(){return e(this,T).length}getRowCount(){return this.length}};q=new WeakMap,w=new WeakMap,T=new WeakMap,j=new WeakMap,we=new WeakMap,O=new WeakMap,xe=new WeakMap,oe=new WeakMap,ve=new WeakMap,Se=new WeakMap,G=new WeakMap,a(k,"ngData"),S(k,"ROW_STATE",{EMPTY:"EMPTY",NORMAL:"NORMAL",INSERT:"INSERT",UPDATE:"UPDATE",DELETE:"DELETE"});let ke=k;const Oe=class Oe{constructor(i){this.owner=i,this.row=new Te(this),this.data=new ke(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(Oe,"ngDataManager");let Le=Oe;const ze=class ze extends HTMLElement{constructor(){super();h(this,U);h(this,Ee);this.attachShadow({mode:"open"}),g(this,U,new Le(this))}connectedCallback(){g(this,Ee,new qe(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,Ee=new WeakMap,a(ze,"NineTable");let Ce=ze;customElements.get("nine-table")||customElements.define("nine-table",Ce)});
|
|
282
282
|
//# sourceMappingURL=nine-table.umd.js.map
|