@ninebone/table 0.0.228 → 0.0.230
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 +185 -196
- package/dist/nine-table.js.map +1 -1
- package/dist/nine-table.umd.js +6 -6
- 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(m,
|
|
1
|
+
(function(m,y){typeof exports=="object"&&typeof module<"u"?y(require("@ninebone/util")):typeof define=="function"&&define.amd?define(["@ninebone/util"],y):(m=typeof globalThis<"u"?globalThis:m||self,y(m.NineboneUtil))})(this,function(m){"use strict";var $e=Object.defineProperty;var We=m=>{throw TypeError(m)};var De=(m,y,S)=>y in m?$e(m,y,{enumerable:!0,configurable:!0,writable:!0,value:S}):m[y]=S;var a=(m,y)=>$e(m,"name",{value:y,configurable:!0});var E=(m,y,S)=>De(m,typeof y!="symbol"?y+"":y,S),Oe=(m,y,S)=>y.has(m)||We("Cannot "+S);var e=(m,y,S)=>(Oe(m,y,"read from private field"),S?S.call(m):y.get(m)),d=(m,y,S)=>y.has(m)?We("Cannot add the same private member more than once"):y instanceof WeakSet?y.add(m):y.set(m,S),g=(m,y,S,$)=>(Oe(m,y,"write to private field"),$?$.call(m,S):y.set(m,S),S);var ze=(m,y,S,$)=>({set _(Q){g(m,y,Q,S)},get _(){return e(m,y,$)}});var C,P,w,V,X,F,oe,Y,le,W,M,T,O,z,D,ae,ce,he,ee,H,Z,de,fe,ue,ie,R,be,se,ge,N,U,q,x,k,j,pe,B,ye,ne,me,we,G,K,ve;const qe=class qe extends m.trace.constructor{constructor(){super(),this.init("nine-table","green")}};a(qe,"Trace");let y=qe;const S=new y,ke=class ke extends HTMLElement{constructor(){super();d(this,C);d(this,P,!1);d(this,w);d(this,V);d(this,X);d(this,F);d(this,oe,a(()=>{if(!e(this,C))return;const t=e(this,C).querySelector(".ng-container-body");t&&(g(this,F,new ResizeObserver(()=>{this.refresh()})),e(this,F).observe(t))},"#observeResize"));E(this,"refresh",a(()=>{if(!e(this,C)||!e(this,w)||e(this,P))return;const t=e(this,w).container,r=t.querySelector("table");if(!r)return;const s=e(this,w).track,n=e(this,w).thumb,o=e(this,C).querySelector(".ng-container-bottom"),c=t.clientWidth,f=r.scrollWidth;if(c!==0&&f>c)o&&(o.style.display="flex");else{o&&(o.style.display="none");return}const l=s.clientWidth;if(l<=0)return;const h=Math.max(Math.min(l*(c/f),l),20);n.style.width=`${h}px`;const u=t.scrollLeft,b=f-c;let p=0;b>0&&(p=parseInt(u/b*(l-h),10)),p<0&&(p=0);const v=l-h;p>v&&(p=v),n.style.left=`${p}px`,S.log(p),e(this,w).left.disabled=p===0,e(this,w).right.disabled=p>=v-1},"refresh"));d(this,Y,a(t=>{if(!e(this,w))return!1;const r=e(this,w).container,s=r.querySelector("table");if(!s)return!1;const n=e(this,w).track.getBoundingClientRect(),o=e(this,w).thumb.clientWidth;let c=t;c<0&&(c=0);const f=n.width-o;c>f&&(c=f),c=parseInt(c,10),e(this,w).thumb.style.left=`${c}px`,e(this,w).left.disabled=c===0,e(this,w).right.disabled=c>=f-1;const l=r.clientWidth,h=s.scrollWidth;let u=f>0?-c*(h-l)/f:0;return-u>h-l&&(u=-(h-l)),-u+5>h-l&&(u=-(h-l)),l>=h&&(u=0),s.style.transform=`translateX(${u}px)`,c>0&&c<f-1},"#thumbMoveTo"));d(this,le,a(()=>{const t=a(s=>{clearInterval(e(this,V)),clearInterval(e(this,X));const n=parseInt(e(this,w).thumb.style.left||0,10);e(this,Y).call(this,n+s),g(this,V,setInterval(()=>{clearInterval(e(this,V)),g(this,X,setInterval(()=>{const o=parseInt(e(this,w).thumb.style.left||0,10);e(this,Y).call(this,o+s)||clearInterval(e(this,X))},50))},500))},"delayScroll"),r=a(()=>{clearInterval(e(this,V)),clearInterval(e(this,X))},"clearTimer");["mouseup","mouseleave","touchend"].forEach(s=>{e(this,w).left.addEventListener(s,r),e(this,w).right.addEventListener(s,r),e(this,w).track.addEventListener(s,r)}),e(this,w).left.addEventListener("mousedown",s=>{s.button===0&&t(-20)}),e(this,w).right.addEventListener("mousedown",s=>{s.button===0&&t(20)}),e(this,w).left.addEventListener("touchstart",()=>t(-20)),e(this,w).right.addEventListener("touchstart",()=>t(20)),e(this,w).track.addEventListener("mousedown",s=>{if(s.button!==0)return;s.preventDefault();const n=e(this,w).track.getBoundingClientRect(),o=e(this,w).thumb.clientWidth;e(this,Y).call(this,s.clientX-n.left-o/2)}),e(this,w).thumb.addEventListener("mousedown",s=>{if(s.button!==0)return;s.stopPropagation(),s.preventDefault(),g(this,P,!0),this.shiftX=s.clientX-e(this,w).thumb.getBoundingClientRect().left;const n=a(c=>{if(!e(this,P))return;const f=e(this,w).track.getBoundingClientRect();e(this,Y).call(this,c.clientX-f.left-this.shiftX)},"onMouseMove"),o=a(()=>{g(this,P,!1),r(),document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",o),this.refresh()},"onMouseUp");document.addEventListener("mousemove",n),document.addEventListener("mouseup",o)})},"#init"))}connectedCallback(){if(g(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
|
|
63
|
+
`;const t=a(()=>{const r=e(this,C).querySelector(".ng-container-body");if(!r){setTimeout(t,10);return}g(this,w,{container:r,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,F)&&e(this,F).disconnect()}};C=new WeakMap,P=new WeakMap,w=new WeakMap,V=new WeakMap,X=new WeakMap,F=new WeakMap,oe=new WeakMap,Y=new WeakMap,le=new WeakMap,a(ke,"NineTableHScrollBar");let $=ke;customElements.get("nine-table-hscrollbar")||customElements.define("nine-table-hscrollbar",$);const Le=class Le{constructor(i){d(this,W);d(this,M,[]);d(this,T,null);d(this,O,null);d(this,z,0);d(this,D,0);E(this,"getRowHeight",a(()=>e(this,T),"getRowHeight"));d(this,ae,a(()=>{e(this,ce).call(this)},"#init"));d(this,ce,a(()=>{if(!e(this,W)||!(e(this,W)instanceof HTMLElement))return;let i=null;g(this,O,new ResizeObserver(t=>{for(const r of t){const s=r.target;s.classList.contains("active")&&(clearTimeout(i),i=setTimeout(()=>{const n=r.contentRect.height;if(n<=0)return;const o=s.clientHeight||n;let c=0;const f=s.querySelector(".ng-container-body");if(!f)return;const l=f.querySelector("thead");l&&(c+=l.offsetHeight);const h=Math.max(o-c,100);if(e(this,z)!==h&&e(this,T)){g(this,z,h);const u=Math.ceil(e(this,z)/e(this,T));g(this,D,u+20),e(this,ee).call(this,f)}},100))}})),e(this,O).observe(e(this,W))},"#initResizeObserver"));E(this,"initialize",a(i=>{const t=e(this,W).querySelector(".ng-container-body"),r=i.querySelector("tbody"),s=Array.from(r.querySelectorAll("tr"));g(this,M,s.map(n=>n.cloneNode(!0))),g(this,T,null),e(this,he).call(this,t),e(this,ee).call(this,t)},"initialize"));d(this,he,a(i=>{if(e(this,T)!==null&&e(this,T)>0)return e(this,T);if(e(this,M).length===0)throw new Error("[RowManager] Template TRs are empty.");const t=i.querySelector("tbody.bindable")||i.querySelector("tbody");if(!t)return 24;t.querySelectorAll("tr:not(.nodata)").forEach(u=>u.remove());const r=t.querySelector("tr.nodata"),s=document.createDocumentFragment();e(this,M).forEach(u=>{s.appendChild(u.cloneNode(!0))}),r?r.before(s):t.appendChild(s);const n=i.closest("nine-table-sheet"),o=n?n.style.display:"",c=n?n.style.visibility:"",f=n?n.style.position:"";n&&(n.style.display==="none"||window.getComputedStyle(n).display==="none")&&(n.style.display="block",n.style.visibility="hidden",n.style.position="absolute");let l=0;if(t.querySelectorAll("tr:not(.nodata)").forEach((u,b)=>{l+=u.offsetHeight||u.getBoundingClientRect().height}),n&&(n.style.display=o,n.style.visibility=c,n.style.position=f),g(this,T,l),e(this,z)>0){const u=Math.ceil(e(this,z)/e(this,T));g(this,D,u+20)}else g(this,D,40);return console.log(`[RowManager] Template Height Cached: ${e(this,T)}px | RowCount: ${e(this,D)}`),e(this,T)},"#measureAndCacheHeight"));d(this,ee,a(i=>{if(e(this,M).length===0)return;const t=i.querySelector("tbody.bindable")||i.querySelector("tbody");if(!t)return;t.querySelectorAll("tr:not(.nodata)").forEach(o=>o.remove());const r=t.querySelector("tr.nodata"),s=document.createDocumentFragment(),n=e(this,D);for(let o=0;o<n;o++)e(this,M).forEach(c=>{s.appendChild(c.cloneNode(!0))});r?r.before(s):t.appendChild(s),console.log(`[RowManager] Rendered ${n} sets into DOM.`)},"#renderRows"));E(this,"destroy",a(()=>{e(this,O)&&(e(this,O).disconnect(),g(this,O,null))},"destroy"));g(this,W,i),e(this,ae).call(this)}get templateLength(){return e(this,M).length||1}};W=new WeakMap,M=new WeakMap,T=new WeakMap,O=new WeakMap,z=new WeakMap,D=new WeakMap,ae=new WeakMap,ce=new WeakMap,he=new WeakMap,ee=new WeakMap,a(Le,"RowManager");let Q=Le;const te=class te extends HTMLElement{constructor(){super();d(this,H,null);d(this,Z);E(this,"generate",a(t=>{if(!t)return;const r=a(l=>{const h=a(b=>{if(b.querySelector("colgroup"))return;const p=b.querySelector("tbody tr")||b.querySelector("tr"),v=p?p.querySelectorAll("th, td").length:1,A=document.createElement("colgroup"),L=Math.max(Math.floor(b.clientWidth/v),100);for(let I=0;I<v;I++){const J=document.createElement("col");J.setAttribute("width",L),A.appendChild(J)}b.prepend(A)},"ensureColgroup"),u=a(b=>{if(b.querySelector("thead"))return;const p=document.createElement("thead"),v=b.querySelector("colgroup");v?v.after(p):b.prepend(p)},"ensureThead");return h(l),u(l),l.classList.add("nine-table-element"),l},"initializeTable"),s=t.cloneNode(!0);g(this,H,r(s)),e(this,H).style.display="table";const n=this.querySelector(".ng-container-left"),o=this.querySelector(".ng-container-body"),c=this.querySelector(".ng-container-right"),f=a((l,h,u=!1)=>{const b=l.cloneNode(!0),p=Array.from(b.querySelectorAll("colgroup col")),v=[];return p.forEach((A,L)=>{const I=A.getAttribute("fixed");let J=!1;u?J=I!=="left"&&I!=="right":J=I===h,J||v.push(L)}),v.reverse().forEach(A=>{p[A]&&p[A].remove(),b.querySelectorAll("tr").forEach(L=>{const I=L.querySelectorAll("th, td");I[A]&&I[A].remove()})}),b},"filterTableByFixed");if(o){const l=f(e(this,H),null,!0);o.innerHTML="",o.appendChild(l),e(this,Z).initialize(e(this,H))}if(n){const l=f(e(this,H),"left",!1);let h=0;l.querySelectorAll("col").forEach(b=>{const p=parseInt(b.getAttribute("width"),10);isNaN(p)||(h+=p)}),n.innerHTML="",n.appendChild(l);const u=h>0?h:0;n.style.flex=`0 0 ${u}px`,n.style.width=`${u}px`}if(c){const l=f(e(this,H),"right",!1);let h=0;l.querySelectorAll("col").forEach(b=>{const p=parseInt(b.getAttribute("width"),10);isNaN(p)||(h+=p)}),c.innerHTML="",c.appendChild(l);const u=h>0?h:0;c.style.flex=`0 0 ${u}px`,c.style.width=`${u}px`}o&&o.addEventListener("scroll",()=>{var l;(l=this.querySelector("nine-table-hscrollbar"))==null||l.refresh()}),setTimeout(()=>{var l;(l=this.querySelector("nine-table-hscrollbar"))==null||l.refresh()},0)},"generate"));E(this,"getRowHeight",a(()=>e(this,Z).getRowHeight(),"getRowHeight"));E(this,"scrollToX",a(t=>{const r=this.querySelector(".ng-container-body");r&&(r.scrollLeft=t)},"scrollToX"));E(this,"scrollToY",a(t=>{const r=this.querySelector(".ng-container-body");r&&(r.scrollTop=t)},"scrollToY"));d(this,de,a(()=>{e(this,fe).call(this),new MutationObserver(t=>{const r=a(()=>{requestAnimationFrame(()=>{var u,b,p;const s=this.querySelector(".ng-container-left table"),n=this.querySelector(".ng-container-body table"),o=this.querySelector(".ng-container-right table");if(!n)return;const c=s?Array.from(s.querySelectorAll("tr")):[],f=Array.from(n.querySelectorAll("tr")),l=o?Array.from(o.querySelectorAll("tr")):[],h=Math.max(c.length,f.length,l.length);for(let v=0;v<h;v++){const A=[((u=c[v])==null?void 0:u.getBoundingClientRect().height)||0,((b=f[v])==null?void 0:b.getBoundingClientRect().height)||0,((p=l[v])==null?void 0:p.getBoundingClientRect().height)||0],L=Math.max(...A);L>0&&(c[v]&&(c[v].style.height=`${L}px`),f[v]&&(f[v].style.height=`${L}px`),l[v]&&(l[v].style.height=`${L}px`))}})},"syncRowHeights");for(const s of t)s.attributeName==="class"&&this.classList.contains("active")&&r()}).observe(this,{attributes:!0})},"#init"));d(this,fe,a(()=>{const t=te.SCROLLBAR_SIZE;this.innerHTML=`
|
|
64
64
|
<style>
|
|
65
65
|
nine-table-sheet {
|
|
66
66
|
display: none;
|
|
@@ -182,14 +182,14 @@
|
|
|
182
182
|
<nine-table-hscrollbar></nine-table-hscrollbar>
|
|
183
183
|
<div class='ng-scroll-edge'></div>
|
|
184
184
|
</div>
|
|
185
|
-
`},"#render"));
|
|
185
|
+
`},"#render"));g(this,Z,new Q(this))}connectedCallback(){e(this,de).call(this)}disconnectedCallback(){this.innerHTML="",S.log("NineTableSheet destroyed.")}};H=new WeakMap,Z=new WeakMap,de=new WeakMap,fe=new WeakMap,a(te,"NineTableSheet"),E(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();d(this,ue,a(()=>{var t;(t=this.querySelector(".nine-tab-bar"))==null||t.addEventListener("click",r=>{var o;const s=r.ctrlKey||r.metaKey||r.shiftKey,n=parseInt((o=r.target.closest(".nine-tab-item"))==null?void 0:o.dataset.index,10);e(this,ie).call(this,n,s)}),e(this,ie).call(this,0,!1)},"#init"));d(this,ie,a((t,r=!1)=>{const s=a(()=>{const h=Array.from(this.querySelectorAll("nine-table-sheet"));Array.from(this.querySelectorAll("nine-splitter")).forEach(p=>p.style.setProperty("display","none"));const b=h.filter(p=>p.classList.contains("active"));b.length<2||b.forEach(p=>{const v=parseInt(p.getAttribute("data-index"),10),A=this.querySelector(`nine-splitter[data-split-index="${v}"]`),L=h[v+1];A&&L&&L.classList.contains("active")&&A.style.setProperty("display","flex")})},"updateSplitters"),n=this.querySelector(".nine-tab-bar"),o=this.querySelector("nine-table-sheets-body"),c=n.querySelectorAll(".nine-tab-item"),f=o.querySelectorAll("nine-table-sheet");if(!c[t])return;if(!r)c.forEach((h,u)=>{h.classList.toggle("active",u===t)}),f.forEach((h,u)=>{const b=u===t;h.classList.toggle("active",b),h.style.flex=b?"1 1 100%":""});else{const h=c[t],u=n.querySelectorAll(".nine-tab-item.active");if(h.classList.contains("active")&&u.length<=1)return;h.classList.toggle("active");const b=o.querySelector(`nine-table-sheet[data-index="${t}"]`);b&&(b.classList.toggle("active"),b.classList.contains("active")||(b.style.flex=""))}const l=o.querySelectorAll("nine-table-sheet.active");l==null||l.forEach(h=>{h.style.flex=l.length>1?"1 1 0%":"1 1 100%"}),s()},"#switchSheet"))}connectedCallback(){e(this,ue).call(this)}};ue=new WeakMap,ie=new WeakMap,a(_e,"NineTableSheets");let xe=_e;customElements.get("nine-table-sheets")||customElements.define("nine-table-sheets",xe);const Ce=class Ce{constructor(i){d(this,R);d(this,be,a(()=>{e(this,ge).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"));d(this,se,a(()=>{var f,l;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,r=Math.max(...i.map(h=>h.getRowHeight())),s=(f=e(this,R).shadowRoot.querySelector("nine-table-header"))==null?void 0:f.getBoundingClientRect().height,n=(l=e(this,R).shadowRoot.querySelector("nine-table-sheets-footer"))==null?void 0:l.getBoundingClientRect().height,o=re.SCROLLBAR_SIZE,c=t*r+s+n+o;e(this,R).style.height=`${c}px`},"#applyAutoHeight"));d(this,ge,a(()=>{const t=Array.from(e(this,R).children).filter(f=>f.tagName==="TABLE"),r=e(this,R).getAttribute("auto-height")==="true",s=t.length,n=t.map((f,l)=>{const u=`<nine-table-sheet class="${l===0?"active":""}" data-index="${l}"></nine-table-sheet>`,b=l<s-1?`<nine-splitter class="h" data-split-index="${l}"></nine-splitter>`:"";return u+b}).join(""),o=t.map((f,l)=>`<div class="nine-tab-item ${l===0?"active":""}" data-index="${l}">Sheet ${l+1}</div>`).join("");e(this,R).shadowRoot.innerHTML=`
|
|
186
186
|
<style>
|
|
187
187
|
:host {
|
|
188
188
|
display: flex;
|
|
189
189
|
flex-direction: column;
|
|
190
190
|
position: relative;
|
|
191
191
|
overflow: hidden;
|
|
192
|
-
height: ${
|
|
192
|
+
height: ${r?"auto":"100%"};
|
|
193
193
|
background: #fff;
|
|
194
194
|
}
|
|
195
195
|
|
|
@@ -271,7 +271,7 @@
|
|
|
271
271
|
<nine-table-body>
|
|
272
272
|
<nine-table-summary></nine-table-summary>
|
|
273
273
|
<nine-table-sheets>
|
|
274
|
-
<nine-table-sheets-body>${
|
|
274
|
+
<nine-table-sheets-body>${n}</nine-table-sheets-body>
|
|
275
275
|
<nine-table-sheets-footer>
|
|
276
276
|
<div class="nine-tab-bar">${o}</div>
|
|
277
277
|
<div class="sheets-counter">Total : <span id="row-count">0</span></div>
|
|
@@ -280,5 +280,5 @@
|
|
|
280
280
|
<nine-table-analysis></nine-table-analysis>
|
|
281
281
|
</nine-table-body>
|
|
282
282
|
<nine-table-footer></nine-table-footer>
|
|
283
|
-
`;const c=e(this,
|
|
283
|
+
`;const c=e(this,R).shadowRoot.querySelectorAll("nine-table-sheet");c==null||c.forEach((f,l)=>{t[l]&&setTimeout(()=>{f.generate(t[l]),r&&e(this,se).call(this)})})},"#render"));g(this,R,i),e(this,be).call(this)}};R=new WeakMap,be=new WeakMap,se=new WeakMap,ge=new WeakMap,a(Ce,"LayoutManager");let Se=Ce;const Me=class Me{constructor(i){d(this,N);d(this,U,-1);E(this,"count",a(()=>e(this,N).rawRecords.length,"count"));g(this,N,i)}get at(){return e(this,U)}set at(i){var r,s;g(this,U,parseInt(i,10));const t=((s=(r=e(this,N).owner).querySelector)==null?void 0:s.call(r,".ng-container-body"))||e(this,N).owner.body;t&&!t.querySelector(`tbody.bindable tr[data-row="${e(this,U)}"]`)&&setTimeout(()=>{var n,o;(o=(n=e(this,N).owner).scrollTo_V1)==null||o.call(n,e(this,U))})}};N=new WeakMap,U=new WeakMap,a(Me,"ngRow");let Ee=Me;const _=class _{constructor(i,t){d(this,q);d(this,x);d(this,k,[]);d(this,j,[]);d(this,pe,0);d(this,B,[]);d(this,ye,a(()=>{g(this,B,[]);const i=e(this,q).template||[];Array.from(i).forEach(t=>{var r;e(this,B).push(((r=t.getBoundingClientRect)==null?void 0:r.call(t).height)||24)}),(e(this,x).rawRecords||[]).forEach(t=>{t.__ng||(t.__ng=e(this,ne).call(this)),t.__ng.height=e(this,B).slice()})},"#initialize"));E(this,"set",a(i=>{this.clear(),this.add(i,!1)},"set"));d(this,ne,a(()=>({rowState:_.ROW_STATE.EMPTY,deleted:!1,filtered:!1,height:e(this,B).slice(),o:{},c:{},_:[0,0,0,0,_.ROW_STATE.EMPTY,!1,!1,!0,!1,!0,!0,!1,e(this,B).slice(),-1,{},{}]}),"#getDefaultMeta"));E(this,"reset",a(()=>{g(this,k,[]),g(this,j,[])},"reset"));E(this,"clear",a(()=>{var i;e(this,x).rawRecords=[],g(this,k,[]),g(this,j,[]),(i=e(this,x).viewRecords)!=null&&i.reset&&e(this,x).viewRecords.reset()},"clear"));d(this,me,a(i=>{var s;Array.isArray(i)||(i=[i]);const t=typeof((s=e(this,q).fields)==null?void 0:s.get)=="function"?e(this,q).fields.get():Object.keys(i[0]||{}),r=[];return i.forEach(n=>{const o={v:[]};t.forEach(c=>{o.v.push(n[c]!==void 0&&n[c]!==null?n[c]:"")}),r.push(o)}),r},"#json2Array"));d(this,we,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=_.ROW_STATE.INSERT,t.__ng._[0]=t.__ng.rowid}),i),"#defaultInsert"));E(this,"add",a((i,t=!0)=>{var n;i===void 0&&(i={});const r=e(this,me).call(this,i);e(this,x).rawRecords=e(this,x).rawRecords.concat(e(this,we).call(this,r)),this.resetRecords();const s=this.count()-1;return t||r.forEach((o,c)=>{const f=e(this,x).rawRecords[s-c];f&&(f.__ng.rowState=_.ROW_STATE.EMPTY)}),(n=e(this,x).viewRecords)!=null&&n.reset&&e(this,x).viewRecords.reset(),s},"add"));E(this,"delete",a(i=>{var r;let t=[];Array.isArray(i)?t=i:typeof i>"u"?t=[e(this,x).owner.row.at]:t=[parseInt(i,10)],t.sort((s,n)=>n-s).forEach(s=>{if(e(this,k)[s]){const n=e(this,k)[s].__ng.rowid;e(this,k)[s].__ng.rowState===_.ROW_STATE.INSERT?e(this,x).rawRecords=e(this,x).rawRecords.filter(o=>o.__ng.rowid!==n):e(this,x).rawRecords.forEach(o=>{o.__ng.rowid===n&&(o.__ng.deleted=!0,o.__ng.rowState=_.ROW_STATE.DELETE)})}}),this.resetRecords(),(r=e(this,x).viewRecords)!=null&&r.reset&&e(this,x).viewRecords.reset()},"delete"));E(this,"setValue",a((i,t,r)=>{var f;i=parseInt(i,10);const n=(typeof((f=e(this,q).fields)==null?void 0:f.get)=="function"?e(this,q).fields.get():[]).indexOf(t);if(n<0)return;const o=this.getValidData()[i];if(!o)return;const c=o.v[n];c!==r&&o.__ng.rowState!==_.ROW_STATE.INSERT&&(o.__ng.o.hasOwnProperty(t)||(o.__ng.o[t]=c),o.__ng.rowState=_.ROW_STATE.UPDATE),o.v[n]=r,e(this,x).owner.refreshData&&e(this,x).owner.refreshData(i)},"setValue"));E(this,"resetRecords",a(()=>{g(this,j,e(this,x).rawRecords.filter(i=>!i.__ng.deleted)),g(this,k,e(this,x).rawRecords.filter(i=>!i.__ng.deleted&&!i.__ng.filtered)),e(this,x).rawRecords.forEach((i,t)=>{i.__ng.rowidx=t}),e(this,k).forEach((i,t)=>{i.__ng.i=t})},"resetRecords"));E(this,"getValidData",a(()=>(e(this,k).length===0&&e(this,x).rawRecords.length>0&&this.resetRecords(),e(this,k)),"getValidData"));d(this,G,a(i=>{var r;if(!i)return i;const t=typeof((r=e(this,q).fields)==null?void 0:r.get)=="function"?e(this,q).fields.get():[];return Array.isArray(i)?i.filter(s=>!s.__ng.deleted).map(s=>{const n={};return t.forEach((o,c)=>{n[o]=s.v?s.v[c]:s[o]}),n.__ng=s.__ng,n}):i},"#conv2"));E(this,"count",a(()=>this.getValidData().length,"count"));E(this,"get",a((i,t)=>{var n;const r=this.getValidData();if(!r||r.length<=0)return;if(i==null)return e(this,G).call(this,r);if(i<0||i>=r.length)return null;const s=typeof((n=e(this,q).fields)==null?void 0:n.get)=="function"?e(this,q).fields.get():[];if(t!=null){const o=s.indexOf(t);return o>=0?r[i].v[o]:null}return e(this,G).call(this,r[i])},"get"));g(this,q,i),g(this,x,t),e(this,ye).call(this)}get source(){return e(this,G).call(this,e(this,x).rawRecords)}set source(i){this.clear(),this.add(i,!1)}get nextId(){return++ze(this,pe)._}get length(){return e(this,k).length}getRowCount(){return this.length}};q=new WeakMap,x=new WeakMap,k=new WeakMap,j=new WeakMap,pe=new WeakMap,B=new WeakMap,ye=new WeakMap,ne=new WeakMap,me=new WeakMap,we=new WeakMap,G=new WeakMap,a(_,"ngData"),E(_,"ROW_STATE",{EMPTY:"EMPTY",NORMAL:"NORMAL",INSERT:"INSERT",UPDATE:"UPDATE",DELETE:"DELETE"});let Re=_;const He=class He{constructor(i){this.owner=i,this.row=new Ee(this),this.data=new Re(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 s,n;const r=parseInt(t,10);if(!(r>=this.data.count()))return(n=(s=this.data.getValidData()[r])==null?void 0:s.__ng)==null?void 0:n.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,r)=>this.data.get(t,r),this.setColumn=(t,r,s)=>{t=parseInt(t,10),this.data.setValue(t,r,s)},this.setDataSource([])}};a(He,"ngDataManager");let Te=He;const Ie=class Ie extends HTMLElement{constructor(){super();d(this,K);d(this,ve);this.attachShadow({mode:"open"}),g(this,K,new Te(this))}connectedCallback(){g(this,ve,new Se(this)),S.log("NineTable connected."),this.dispatchEvent(new CustomEvent("load",{bubbles:!0,detail:{target:this}}))}disconnectedCallback(){S.log("NineTable disconnected.")}get data(){return e(this,K).data}get row(){return e(this,K).row}get dataManager(){return e(this,K)}};K=new WeakMap,ve=new WeakMap,a(Ie,"NineTable");let Ae=Ie;customElements.get("nine-table")||customElements.define("nine-table",Ae)});
|
|
284
284
|
//# sourceMappingURL=nine-table.umd.js.map
|