@ninebone/table 0.0.210 → 0.0.212
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 +237 -238
- 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(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 He=Object.defineProperty;var Ie=m=>{throw TypeError(m)};var Oe=(m,y,
|
|
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 He=Object.defineProperty;var Ie=m=>{throw TypeError(m)};var Oe=(m,y,R)=>y in m?He(m,y,{enumerable:!0,configurable:!0,writable:!0,value:R}):m[y]=R;var a=(m,y)=>He(m,"name",{value:y,configurable:!0});var S=(m,y,R)=>Oe(m,typeof y!="symbol"?y+"":y,R),$e=(m,y,R)=>y.has(m)||Ie("Cannot "+R);var e=(m,y,R)=>($e(m,y,"read from private field"),R?R.call(m):y.get(m)),u=(m,y,R)=>y.has(m)?Ie("Cannot add the same private member more than once"):y instanceof WeakSet?y.add(m):y.set(m,R),p=(m,y,R,O)=>($e(m,y,"write to private field"),O?O.call(m,R):y.set(m,R),R);var We=(m,y,R,O)=>({set _(J){p(m,y,J,R)},get _(){return e(m,y,O)}});var _,N,w,P,V,X,ne,F,re,Y,M,A,z,H,I,oe,le,$,U,ae,ce,he,ee,T,de,te,fe,B,K,q,x,k,j,ue,D,ge,ie,be,pe,G,Z,ye;const Ee=class Ee extends m.trace.constructor{constructor(){super(),this.init("nine-table","green")}};a(Ee,"Trace");let y=Ee;const R=new y,Te=class Te extends HTMLElement{constructor(){super();u(this,_);u(this,N,!1);u(this,w);u(this,P);u(this,V);u(this,X);u(this,ne,a(()=>{if(!e(this,_))return;const t=e(this,_).querySelector(".ng-container-body");t&&(p(this,X,new ResizeObserver(()=>{this.refresh()})),e(this,X).observe(t))},"#observeResize"));S(this,"refresh",a(()=>{if(!e(this,_)||!e(this,w)||e(this,N))return;const t=e(this,w).container,s=t.querySelector("table");if(!s)return;const n=e(this,w).track,r=e(this,w).thumb,o=e(this,_).querySelector(".ng-container-bottom"),c=t.clientWidth,h=s.scrollWidth;if(c!==0&&h>c)o&&(o.style.display="flex");else{o&&(o.style.display="none");return}const l=n.clientWidth;if(l<=0)return;const d=Math.max(Math.min(l*(c/h),l),20);r.style.width=`${d}px`;let f=0;const g=s.style.transform;if(g&&g.includes("translateX")){const E=g.match(/translateX\(([-\d.]+)px\)/);E&&E[1]&&(f=parseFloat(E[1]))}else f=parseInt(s.style.left||0,10);let b=parseInt(Math.abs(f)*l/h,10);b<0&&(b=0);const v=l-d;b>v&&(b=v),r.style.left=`${b}px`,e(this,w).left.disabled=b===0,e(this,w).right.disabled=b>=v-1},"refresh"));u(this,F,a(t=>{if(!e(this,w))return!1;const s=e(this,w).container,n=s.querySelector("table");if(!n)return!1;const r=e(this,w).track.getBoundingClientRect(),o=e(this,w).thumb.clientWidth;let c=t;c<0&&(c=0);const h=r.width-o;c>h&&(c=h),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>=h-1;const l=s.clientWidth,d=n.scrollWidth;let f=h>0?-c*(d-l)/h:0;return-f>d-l&&(f=-(d-l)),-f+5>d-l&&(f=-(d-l)),l>=d&&(f=0),n.style.transform=`translateX(${f}px)`,c>0&&c<h-1},"#thumbMoveTo"));u(this,re,a(()=>{const t=a(n=>{clearInterval(e(this,P)),clearInterval(e(this,V));const r=parseInt(e(this,w).thumb.style.left||0,10);e(this,F).call(this,r+n),p(this,P,setInterval(()=>{clearInterval(e(this,P)),p(this,V,setInterval(()=>{const o=parseInt(e(this,w).thumb.style.left||0,10);e(this,F).call(this,o+n)||clearInterval(e(this,V))},50))},500))},"delayScroll"),s=a(()=>{clearInterval(e(this,P)),clearInterval(e(this,V))},"clearTimer");["mouseup","mouseleave","touchend"].forEach(n=>{e(this,w).left.addEventListener(n,s),e(this,w).right.addEventListener(n,s),e(this,w).track.addEventListener(n,s)}),e(this,w).left.addEventListener("mousedown",n=>{n.button===0&&t(-20)}),e(this,w).right.addEventListener("mousedown",n=>{n.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",n=>{if(n.button!==0)return;n.preventDefault();const r=e(this,w).track.getBoundingClientRect(),o=e(this,w).thumb.clientWidth;e(this,F).call(this,n.clientX-r.left-o/2)}),e(this,w).thumb.addEventListener("mousedown",n=>{if(n.button!==0)return;n.stopPropagation(),n.preventDefault(),p(this,N,!0),this.shiftX=n.clientX-e(this,w).thumb.getBoundingClientRect().left;const r=a(c=>{if(!e(this,N))return;const h=e(this,w).track.getBoundingClientRect();e(this,F).call(this,c.clientX-h.left-this.shiftX)},"onMouseMove"),o=a(()=>{p(this,N,!1),s(),document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",o),this.refresh()},"onMouseUp");document.addEventListener("mousemove",r),document.addEventListener("mouseup",o)})},"#init"))}connectedCallback(){if(p(this,_,this.closest("nine-table-sheet")||this.getRootNode().host),!e(this,_))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,
|
|
63
|
+
`;const t=a(()=>{const s=e(this,_).querySelector(".ng-container-body");if(!s){setTimeout(t,10);return}p(this,w,{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,re).call(this),e(this,ne).call(this),this.refresh()},"initWhenReady");t()}disconnectedCallback(){e(this,X)&&e(this,X).disconnect()}};_=new WeakMap,N=new WeakMap,w=new WeakMap,P=new WeakMap,V=new WeakMap,X=new WeakMap,ne=new WeakMap,F=new WeakMap,re=new WeakMap,a(Te,"NineTableHScrollBar");let O=Te;customElements.get("nine-table-hscrollbar")||customElements.define("nine-table-hscrollbar",O);const Ae=class Ae{constructor(i){u(this,Y);u(this,M,[]);u(this,A,null);u(this,z,null);u(this,H,0);u(this,I,0);S(this,"getRowHeight",a(()=>e(this,A),"getRowHeight"));u(this,oe,a(()=>{e(this,le).call(this)},"#init"));u(this,le,a(()=>{!e(this,Y)||!(e(this,Y)instanceof HTMLElement)||(p(this,z,new ResizeObserver(i=>{for(const t of i){const s=t.target;if(!s.classList.contains("active"))continue;const n=t.contentRect.height||(t.borderBoxSize&&t.borderBoxSize[0]?t.borderBoxSize[0].blockSize:0);if(n>0){const r=s.clientHeight||s.getBoundingClientRect().height||n;let o=0;const c=s.querySelector(".ng-container-body")||s,h=c.querySelector("thead"),l=c.querySelector("tfoot");h&&(o+=h.offsetHeight||h.getBoundingClientRect().height),l&&(o+=l.offsetHeight||l.getBoundingClientRect().height);const d=Math.max(r-o,100);if(e(this,H)!==d&&(p(this,H,d),e(this,A)!==null)){const f=Math.ceil(e(this,H)/e(this,A));p(this,I,f+20),R.log(`[RowManager] Resized. Height: ${e(this,H)}px | Target Rows: ${e(this,I)}`),[".ng-container-body",".ng-container-left",".ng-container-right"].forEach(g=>{const b=s.querySelector(g);b&&b.querySelector("tbody")&&this.renderRows(b)})}}}})),e(this,z).observe(e(this,Y)))},"#initResizeObserver"));S(this,"initTemplate",a(i=>{const t=i.querySelector("tbody.bindable")||i.querySelector("tbody");if(!t)return;const s=Array.from(t.querySelectorAll("tr")).filter(n=>!n.classList.contains("nodata"));p(this,M,s.map(n=>n.cloneNode(!0))),p(this,A,null),console.log(`[RowManager] Template initialized with ${e(this,M).length} row(s).`)},"initTemplate"));S(this,"measureAndCacheHeight",a(i=>{if(e(this,A)!==null&&e(this,A)>0)return e(this,A);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(f=>f.remove());const s=t.querySelector("tr.nodata"),n=document.createDocumentFragment();e(this,M).forEach(f=>{n.appendChild(f.cloneNode(!0))}),s?s.before(n):t.appendChild(n);const r=i.closest("nine-table-sheet"),o=r?r.style.display:"",c=r?r.style.visibility:"",h=r?r.style.position:"";r&&(r.style.display==="none"||window.getComputedStyle(r).display==="none")&&(r.style.display="block",r.style.visibility="hidden",r.style.position="absolute");let l=0;if(t.querySelectorAll("tr:not(.nodata)").forEach((f,g)=>{const b=f.offsetHeight||f.getBoundingClientRect().height;b===0?l+=40:l+=b}),r&&(r.style.display=o,r.style.visibility=c,r.style.position=h),p(this,A,l),e(this,H)>0){const f=Math.ceil(e(this,H)/e(this,A));p(this,I,f+20)}else p(this,I,40);return console.log(`[RowManager] Template Height Cached: ${e(this,A)}px | RowCount: ${e(this,I)}`),e(this,A)},"measureAndCacheHeight"));S(this,"renderRows",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 s=t.querySelector("tr.nodata"),n=document.createDocumentFragment(),r=e(this,I);for(let o=0;o<r;o++)e(this,M).forEach(c=>{n.appendChild(c.cloneNode(!0))});s?s.before(n):t.appendChild(n),console.log(`[RowManager] Rendered ${r} sets into DOM.`)},"renderRows"));S(this,"destroy",a(()=>{e(this,z)&&(e(this,z).disconnect(),p(this,z,null))},"destroy"));p(this,Y,i),e(this,oe).call(this)}get templateLength(){return e(this,M).length||1}};Y=new WeakMap,M=new WeakMap,A=new WeakMap,z=new WeakMap,H=new WeakMap,I=new WeakMap,oe=new WeakMap,le=new WeakMap,a(Ae,"RowManager");let J=Ae;const Q=class Q extends HTMLElement{constructor(){super();u(this,$,null);u(this,U);S(this,"generate",a(t=>{if(!t)return;const s=a(l=>{const d=a(g=>{if(g.querySelector("colgroup"))return;const b=g.querySelector("tbody tr")||g.querySelector("tr"),v=b?b.querySelectorAll("th, td").length:1,E=document.createElement("colgroup"),L=Math.max(Math.floor((g.clientWidth||600)/v),100);for(let W=0;W<v;W++){const Me=document.createElement("col");Me.setAttribute("width",L),E.appendChild(Me)}g.prepend(E)},"ensureColgroup"),f=a(g=>{if(g.querySelector("thead"))return;const b=document.createElement("thead"),v=g.querySelector("colgroup");v?v.after(b):g.prepend(b)},"ensureThead");return d(l),f(l),l.classList.add("nine-table-element"),l},"initializeTable"),n=t.cloneNode(!0);p(this,$,s(n)),e(this,$).style.display="table",e(this,U).initTemplate(e(this,$));const r=this.querySelector(".ng-container-left"),o=this.querySelector(".ng-container-body"),c=this.querySelector(".ng-container-right"),h=a((l,d,f=!1)=>{const g=l.cloneNode(!0),b=Array.from(g.querySelectorAll("colgroup col")),v=[];return b.forEach((E,L)=>{const W=E.getAttribute("fixed");(f?W!=="left"&&W!=="right":W===d)||v.push(L)}),v.reverse().forEach(E=>{b[E]&&b[E].remove(),g.querySelectorAll("tr").forEach(L=>{const W=L.querySelectorAll("th, td");W[E]&&W[E].remove()})}),g},"filterTableByFixed");if(o){const l=h(e(this,$),null,!0);o.innerHTML="",o.appendChild(l),e(this,U).measureAndCacheHeight(o)}if(r){const l=h(e(this,$),"left",!1);let d=0;l.querySelectorAll("col").forEach(g=>{const b=parseInt(g.getAttribute("width"),10);isNaN(b)||(d+=b)}),r.innerHTML="",r.appendChild(l);const f=d>0?d:0;r.style.flex=`0 0 ${f}px`,r.style.width=`${f}px`}if(c){const l=h(e(this,$),"right",!1);let d=0;l.querySelectorAll("col").forEach(g=>{const b=parseInt(g.getAttribute("width"),10);isNaN(b)||(d+=b)}),c.innerHTML="",c.appendChild(l);const f=d>0?d:0;c.style.flex=`0 0 ${f}px`,c.style.width=`${f}px`}o&&o.addEventListener("scroll",()=>{var l;this.querySelector("nine-table-hscrollbar"),(l=this.querySelector("nine-table-hscrollbar"))==null||l.refresh()}),setTimeout(()=>{const l=this.querySelector("nine-table-hscrollbar");l&&typeof l.refresh=="function"&&l.refresh()},0)},"generate"));S(this,"getRowHeight",a(()=>e(this,U).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"));u(this,ae,a(()=>{e(this,ce).call(this),new MutationObserver(t=>{const s=a(()=>{requestAnimationFrame(()=>{var f,g,b;const n=this.querySelector(".ng-container-left table"),r=this.querySelector(".ng-container-body table"),o=this.querySelector(".ng-container-right table");if(!r)return;const c=n?Array.from(n.querySelectorAll("tr")):[],h=Array.from(r.querySelectorAll("tr")),l=o?Array.from(o.querySelectorAll("tr")):[],d=Math.max(c.length,h.length,l.length);for(let v=0;v<d;v++){const E=[((f=c[v])==null?void 0:f.getBoundingClientRect().height)||0,((g=h[v])==null?void 0:g.getBoundingClientRect().height)||0,((b=l[v])==null?void 0:b.getBoundingClientRect().height)||0],L=Math.max(...E);L>0&&(c[v]&&(c[v].style.height=`${L}px`),h[v]&&(h[v].style.height=`${L}px`),l[v]&&(l[v].style.height=`${L}px`))}})},"syncRowHeights");for(const n of t)n.attributeName==="class"&&this.classList.contains("active")&&s()}).observe(this,{attributes:!0})},"#init"));u(this,ce,a(()=>{const t=Q.SCROLLBAR_SIZE;this.innerHTML=`
|
|
64
64
|
<style>
|
|
65
65
|
nine-table-sheet {
|
|
66
66
|
display: none;
|
|
@@ -172,7 +172,7 @@
|
|
|
172
172
|
<nine-table-hscrollbar></nine-table-hscrollbar>
|
|
173
173
|
<div class='ng-scroll-edge'></div>
|
|
174
174
|
</div>
|
|
175
|
-
`},"#render"));p(this,U,new J(this))}connectedCallback(){e(this,ae).call(this)}disconnectedCallback(){this.innerHTML="",
|
|
175
|
+
`},"#render"));p(this,U,new J(this))}connectedCallback(){e(this,ae).call(this)}disconnectedCallback(){this.innerHTML="",R.log("NineTableSheet destroyed.")}};$=new WeakMap,U=new WeakMap,ae=new WeakMap,ce=new WeakMap,a(Q,"NineTableSheet"),S(Q,"SCROLLBAR_SIZE",16);let se=Q;customElements.get("nine-table-sheet")||customElements.define("nine-table-sheet",se);const qe=class qe extends HTMLElement{constructor(){super();u(this,he,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,ee).call(this,r,n)}),e(this,ee).call(this,0,!1)},"#init"));u(this,ee,a((t,s=!1)=>{const n=a(()=>{const d=Array.from(this.querySelectorAll("nine-table-sheet"));Array.from(this.querySelectorAll("nine-splitter")).forEach(b=>b.style.setProperty("display","none"));const g=d.filter(b=>b.classList.contains("active"));g.length<2||g.forEach(b=>{const v=parseInt(b.getAttribute("data-index"),10),E=this.querySelector(`nine-splitter[data-split-index="${v}"]`),L=d[v+1];E&&L&&L.classList.contains("active")&&E.style.setProperty("display","flex")})},"updateSplitters"),r=this.querySelector(".nine-tab-bar"),o=this.querySelector("nine-table-sheets-body"),c=r.querySelectorAll(".nine-tab-item"),h=o.querySelectorAll("nine-table-sheet");if(!c[t])return;if(!s)c.forEach((d,f)=>{d.classList.toggle("active",f===t)}),h.forEach((d,f)=>{const g=f===t;d.classList.toggle("active",g),d.style.flex=g?"1 1 100%":""});else{const d=c[t],f=r.querySelectorAll(".nine-tab-item.active");if(d.classList.contains("active")&&f.length<=1)return;d.classList.toggle("active");const g=o.querySelector(`nine-table-sheet[data-index="${t}"]`);g&&(g.classList.toggle("active"),g.classList.contains("active")||(g.style.flex=""))}const l=o.querySelectorAll("nine-table-sheet.active");l==null||l.forEach(d=>{d.style.flex=l.length>1?"1 1 0%":"1 1 100%"}),n()},"#switchSheet"))}connectedCallback(){e(this,he).call(this)}};he=new WeakMap,ee=new WeakMap,a(qe,"NineTableSheets");let me=qe;customElements.get("nine-table-sheets")||customElements.define("nine-table-sheets",me);const ke=class ke{constructor(i){u(this,T);u(this,de,a(()=>{e(this,fe).call(this),new ResizeObserver(i=>{for(let t of i)e(this,T).getAttribute("auto-height")==="true"&&e(this,te).call(this)}).observe(e(this,T))},"#init"));u(this,te,a(()=>{var h,l;const i=Array.from(e(this,T).shadowRoot.querySelectorAll("nine-table-sheet.active"));if(i.length===0)return;const t=parseInt(e(this,T).getAttribute("max-display-row"),10)||10,s=Math.max(...i.map(d=>d.getRowHeight())),n=(h=e(this,T).shadowRoot.querySelector("nine-table-header"))==null?void 0:h.getBoundingClientRect().height,r=(l=e(this,T).shadowRoot.querySelector("nine-table-sheets-footer"))==null?void 0:l.getBoundingClientRect().height,o=se.SCROLLBAR_SIZE,c=t*s+n+r+o;e(this,T).style.height=`${c}px`},"#applyAutoHeight"));u(this,fe,a(()=>{const t=Array.from(e(this,T).children).filter(h=>h.tagName==="TABLE"),s=e(this,T).getAttribute("auto-height")==="true",n=t.length,r=t.map((h,l)=>{const f=`<nine-table-sheet class="${l===0?"active":""}" data-index="${l}"></nine-table-sheet>`,g=l<n-1?`<nine-splitter class="h" data-split-index="${l}"></nine-splitter>`:"";return f+g}).join(""),o=t.map((h,l)=>`<div class="nine-tab-item ${l===0?"active":""}" data-index="${l}">Sheet ${l+1}</div>`).join("");e(this,T).shadowRoot.innerHTML=`
|
|
176
176
|
<style>
|
|
177
177
|
:host {
|
|
178
178
|
display: flex;
|
|
@@ -270,5 +270,5 @@
|
|
|
270
270
|
<nine-table-analysis></nine-table-analysis>
|
|
271
271
|
</nine-table-body>
|
|
272
272
|
<nine-table-footer></nine-table-footer>
|
|
273
|
-
`;const c=e(this,T).shadowRoot.querySelectorAll("nine-table-sheet");c==null||c.forEach((
|
|
273
|
+
`;const c=e(this,T).shadowRoot.querySelectorAll("nine-table-sheet");c==null||c.forEach((h,l)=>{t[l]&&setTimeout(()=>{h.generate(t[l]),s&&e(this,te).call(this)})})},"#render"));p(this,T,i),e(this,de).call(this)}};T=new WeakMap,de=new WeakMap,te=new WeakMap,fe=new WeakMap,a(ke,"LayoutManager");let we=ke;const Le=class Le{constructor(i){u(this,B);u(this,K,-1);S(this,"count",a(()=>e(this,B).rawRecords.length,"count"));p(this,B,i)}get at(){return e(this,K)}set at(i){var s,n;p(this,K,parseInt(i,10));const t=((n=(s=e(this,B).owner).querySelector)==null?void 0:n.call(s,".ng-container-body"))||e(this,B).owner.body;t&&!t.querySelector(`tbody.bindable tr[data-row="${e(this,K)}"]`)&&setTimeout(()=>{var r,o;(o=(r=e(this,B).owner).scrollTo_V1)==null||o.call(r,e(this,K))})}};B=new WeakMap,K=new WeakMap,a(Le,"ngRow");let ve=Le;const C=class C{constructor(i,t){u(this,q);u(this,x);u(this,k,[]);u(this,j,[]);u(this,ue,0);u(this,D,[]);u(this,ge,a(()=>{p(this,D,[]);const i=e(this,q).template||[];Array.from(i).forEach(t=>{var s;e(this,D).push(((s=t.getBoundingClientRect)==null?void 0:s.call(t).height)||24)}),(e(this,x).rawRecords||[]).forEach(t=>{t.__ng||(t.__ng=e(this,ie).call(this)),t.__ng.height=e(this,D).slice()})},"#initialize"));S(this,"set",a(i=>{this.clear(),this.add(i,!1)},"set"));u(this,ie,a(()=>({rowState:C.ROW_STATE.EMPTY,deleted:!1,filtered:!1,height:e(this,D).slice(),o:{},c:{},_:[0,0,0,0,C.ROW_STATE.EMPTY,!1,!1,!0,!1,!0,!0,!1,e(this,D).slice(),-1,{},{}]}),"#getDefaultMeta"));S(this,"reset",a(()=>{p(this,k,[]),p(this,j,[])},"reset"));S(this,"clear",a(()=>{var i;e(this,x).rawRecords=[],p(this,k,[]),p(this,j,[]),(i=e(this,x).viewRecords)!=null&&i.reset&&e(this,x).viewRecords.reset()},"clear"));u(this,be,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(c=>{o.v.push(r[c]!==void 0&&r[c]!==null?r[c]:"")}),s.push(o)}),s},"#json2Array"));u(this,pe,a(i=>(Array.isArray(i)||(i=[i]),i.forEach(t=>{t.__ng=e(this,ie).call(this),t.__ng.rowid=this.nextId,t.__ng.rowState=C.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,be).call(this,i);e(this,x).rawRecords=e(this,x).rawRecords.concat(e(this,pe).call(this,s)),this.resetRecords();const n=this.count()-1;return t||s.forEach((o,c)=>{const h=e(this,x).rawRecords[n-c];h&&(h.__ng.rowState=C.ROW_STATE.EMPTY)}),(r=e(this,x).viewRecords)!=null&&r.reset&&e(this,x).viewRecords.reset(),n},"add"));S(this,"delete",a(i=>{var s;let t=[];Array.isArray(i)?t=i:typeof i>"u"?t=[e(this,x).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===C.ROW_STATE.INSERT?e(this,x).rawRecords=e(this,x).rawRecords.filter(o=>o.__ng.rowid!==r):e(this,x).rawRecords.forEach(o=>{o.__ng.rowid===r&&(o.__ng.deleted=!0,o.__ng.rowState=C.ROW_STATE.DELETE)})}}),this.resetRecords(),(s=e(this,x).viewRecords)!=null&&s.reset&&e(this,x).viewRecords.reset()},"delete"));S(this,"setValue",a((i,t,s)=>{var h;i=parseInt(i,10);const r=(typeof((h=e(this,q).fields)==null?void 0:h.get)=="function"?e(this,q).fields.get():[]).indexOf(t);if(r<0)return;const o=this.getValidData()[i];if(!o)return;const c=o.v[r];c!==s&&o.__ng.rowState!==C.ROW_STATE.INSERT&&(o.__ng.o.hasOwnProperty(t)||(o.__ng.o[t]=c),o.__ng.rowState=C.ROW_STATE.UPDATE),o.v[r]=s,e(this,x).owner.refreshData&&e(this,x).owner.refreshData(i)},"setValue"));S(this,"resetRecords",a(()=>{p(this,j,e(this,x).rawRecords.filter(i=>!i.__ng.deleted)),p(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"));S(this,"getValidData",a(()=>(e(this,k).length===0&&e(this,x).rawRecords.length>0&&this.resetRecords(),e(this,k)),"getValidData"));u(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,c)=>{r[o]=n.v?n.v[c]: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"));p(this,q,i),p(this,x,t),e(this,ge).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++We(this,ue)._}get length(){return e(this,k).length}getRowCount(){return this.length}};q=new WeakMap,x=new WeakMap,k=new WeakMap,j=new WeakMap,ue=new WeakMap,D=new WeakMap,ge=new WeakMap,ie=new WeakMap,be=new WeakMap,pe=new WeakMap,G=new WeakMap,a(C,"ngData"),S(C,"ROW_STATE",{EMPTY:"EMPTY",NORMAL:"NORMAL",INSERT:"INSERT",UPDATE:"UPDATE",DELETE:"DELETE"});let xe=C;const Ce=class Ce{constructor(i){this.owner=i,this.row=new ve(this),this.data=new xe(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(Ce,"ngDataManager");let Se=Ce;const _e=class _e extends HTMLElement{constructor(){super();u(this,Z);u(this,ye);this.attachShadow({mode:"open"}),p(this,Z,new Se(this))}connectedCallback(){p(this,ye,new we(this)),R.log("NineTable connected."),this.dispatchEvent(new CustomEvent("load",{bubbles:!0,detail:{target:this}}))}disconnectedCallback(){R.log("NineTable disconnected.")}get data(){return e(this,Z).data}get row(){return e(this,Z).row}get dataManager(){return e(this,Z)}};Z=new WeakMap,ye=new WeakMap,a(_e,"NineTable");let Re=_e;customElements.get("nine-table")||customElements.define("nine-table",Re)});
|
|
274
274
|
//# sourceMappingURL=nine-table.umd.js.map
|