@ninebone/table 0.0.199 β 0.0.200
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 +303 -299
- package/dist/nine-table.js.map +1 -1
- package/dist/nine-table.umd.js +17 -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(
|
|
1
|
+
(function(p,g){typeof exports=="object"&&typeof module<"u"?g(require("@ninebone/util")):typeof define=="function"&&define.amd?define(["@ninebone/util"],g):(p=typeof globalThis<"u"?globalThis:p||self,g(p.NineboneUtil))})(this,function(p){"use strict";var Me=Object.defineProperty;var He=p=>{throw TypeError(p)};var We=(p,g,R)=>g in p?Me(p,g,{enumerable:!0,configurable:!0,writable:!0,value:R}):p[g]=R;var a=(p,g)=>Me(p,"name",{value:g,configurable:!0});var x=(p,g,R)=>We(p,typeof g!="symbol"?g+"":g,R),Ie=(p,g,R)=>g.has(p)||He("Cannot "+R);var e=(p,g,R)=>(Ie(p,g,"read from private field"),R?R.call(p):g.get(p)),c=(p,g,R)=>g.has(p)?He("Cannot add the same private member more than once"):g instanceof WeakSet?g.add(p):g.set(p,R),b=(p,g,R,W)=>(Ie(p,g,"write to private field"),W?W.call(p,R):g.set(p,R),R);var $e=(p,g,R,W)=>({set _(G){b(p,g,G,R)},get _(){return e(p,g,W)}});var _,N,y,B,P,V,ne,X,re,Y,M,E,z,H,I,oe,le,L,F,ae,he,Q,S,ce,ee,de,O,U,T,m,k,Z,fe,D,ue,te,be,ge,j,K,pe;const Se=class Se extends p.trace.constructor{constructor(){super(),this.init("nine-table","green")}};a(Se,"Trace");let g=Se;const R=new g,Ee=class Ee extends HTMLElement{constructor(){super();c(this,_);c(this,N,!1);c(this,y);c(this,B);c(this,P);c(this,V);c(this,ne,a(()=>{if(!e(this,_))return;const t=e(this,_).querySelector(".ng-container-body");t&&(b(this,V,new ResizeObserver(()=>{this.refresh()})),e(this,V).observe(t))},"#observeResize"));x(this,"refresh",a(()=>{if(!e(this,_)||!e(this,y)||e(this,N))return;const t=e(this,y).container,s=t.querySelector("table");if(!s)return;const n=e(this,y).track,r=e(this,y).thumb,o=e(this,_).querySelector(".ng-container-bottom"),h=t.clientWidth,f=s.scrollWidth;if(h!==0&&f>h)o&&(o.style.display="flex");else{o&&(o.style.display="none");return}const l=n.clientWidth;if(l<=0)return;const u=Math.max(Math.min(l*(h/f),l),20);r.style.width=`${u}px`;let d=0;const v=s.style.transform;if(v&&v.includes("translateX")){const q=v.match(/translateX\(([-\d.]+)px\)/);q&&q[1]&&(d=parseFloat(q[1]))}else d=parseInt(s.style.left||0,10);let w=parseInt(Math.abs(d)*l/f,10);w<0&&(w=0);const C=l-u;w>C&&(w=C),r.style.left=`${w}px`,e(this,y).left.disabled=w===0,e(this,y).right.disabled=w>=C-1},"refresh"));c(this,X,a(t=>{if(!e(this,y))return!1;const s=e(this,y).container,n=s.querySelector("table");if(!n)return!1;const r=e(this,y).track.getBoundingClientRect(),o=e(this,y).thumb.clientWidth;let h=t;h<0&&(h=0);const f=r.width-o;h>f&&(h=f),h=parseInt(h,10),e(this,y).thumb.style.left=`${h}px`,e(this,y).left.disabled=h===0,e(this,y).right.disabled=h>=f-1;const l=s.clientWidth,u=n.scrollWidth;let d=f>0?-h*(u-l)/f:0;return-d>u-l&&(d=-(u-l)),-d+5>u-l&&(d=-(u-l)),l>=u&&(d=0),n.style.transform=`translateX(${d}px)`,h>0&&h<f-1},"#thumbMoveTo"));c(this,re,a(()=>{const t=a(n=>{clearInterval(e(this,B)),clearInterval(e(this,P));const r=parseInt(e(this,y).thumb.style.left||0,10);e(this,X).call(this,r+n),b(this,B,setInterval(()=>{clearInterval(e(this,B)),b(this,P,setInterval(()=>{const o=parseInt(e(this,y).thumb.style.left||0,10);e(this,X).call(this,o+n)||clearInterval(e(this,P))},50))},500))},"delayScroll"),s=a(()=>{clearInterval(e(this,B)),clearInterval(e(this,P))},"clearTimer");["mouseup","mouseleave","touchend"].forEach(n=>{e(this,y).left.addEventListener(n,s),e(this,y).right.addEventListener(n,s),e(this,y).track.addEventListener(n,s)}),e(this,y).left.addEventListener("mousedown",n=>{n.button===0&&t(-20)}),e(this,y).right.addEventListener("mousedown",n=>{n.button===0&&t(20)}),e(this,y).left.addEventListener("touchstart",()=>t(-20)),e(this,y).right.addEventListener("touchstart",()=>t(20)),e(this,y).track.addEventListener("mousedown",n=>{if(n.button!==0)return;n.preventDefault();const r=e(this,y).track.getBoundingClientRect(),o=e(this,y).thumb.clientWidth;e(this,X).call(this,n.clientX-r.left-o/2)}),e(this,y).thumb.addEventListener("mousedown",n=>{if(n.button!==0)return;n.stopPropagation(),n.preventDefault(),b(this,N,!0),this.shiftX=n.clientX-e(this,y).thumb.getBoundingClientRect().left;const r=a(h=>{if(!e(this,N))return;const f=e(this,y).track.getBoundingClientRect();e(this,X).call(this,h.clientX-f.left-this.shiftX)},"onMouseMove"),o=a(()=>{b(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(b(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,_).querySelector(".ng-container-body");if(!s){setTimeout(t,10);return}
|
|
63
|
+
`;const t=a(()=>{const s=e(this,_).querySelector(".ng-container-body");if(!s){setTimeout(t,10);return}b(this,y,{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,V)&&e(this,V).disconnect()}};_=new WeakMap,N=new WeakMap,y=new WeakMap,B=new WeakMap,P=new WeakMap,V=new WeakMap,ne=new WeakMap,X=new WeakMap,re=new WeakMap,a(Ee,"NineTableHScrollBar");let W=Ee;customElements.get("nine-table-hscrollbar")||customElements.define("nine-table-hscrollbar",W);const Te=class Te{constructor(i){c(this,Y);c(this,M,[]);c(this,E,null);c(this,z,null);c(this,H,0);c(this,I,0);x(this,"getRowHeight",a(()=>e(this,E),"getRowHeight"));c(this,oe,a(()=>{e(this,le).call(this)},"#init"));c(this,le,a(()=>{!e(this,Y)||!(e(this,Y)instanceof HTMLElement)||(b(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 h=s.querySelector(".ng-container-body")||s,f=h.querySelector("thead"),l=h.querySelector("tfoot");f&&(o+=f.offsetHeight||f.getBoundingClientRect().height),l&&(o+=l.offsetHeight||l.getBoundingClientRect().height);const u=Math.max(r-o,100);if(e(this,H)!==u&&(b(this,H,u),e(this,E)!==null)){const d=Math.ceil(e(this,H)/e(this,E));b(this,I,d+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(v=>{const w=s.querySelector(v);w&&w.querySelector("tbody")&&this.renderRows(w)})}}}})),e(this,z).observe(e(this,Y)))},"#initResizeObserver"));x(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"));b(this,M,s.map(n=>n.cloneNode(!0))),b(this,E,null),console.log(`[RowManager] Template initialized with ${e(this,M).length} row(s).`)},"initTemplate"));x(this,"measureAndCacheHeight",a(i=>{if(e(this,E)!==null&&e(this,E)>0)return e(this,E);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(d=>d.remove());const s=t.querySelector("tr.nodata"),n=document.createDocumentFragment();e(this,M).forEach(d=>{n.appendChild(d.cloneNode(!0))}),s?s.before(n):t.appendChild(n);const r=i.closest("nine-table-sheet"),o=r?r.style.display:"",h=r?r.style.visibility:"",f=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((d,v)=>{const w=d.offsetHeight||d.getBoundingClientRect().height;w===0?l+=40:l+=w}),r&&(r.style.display=o,r.style.visibility=h,r.style.position=f),b(this,E,l),e(this,H)>0){const d=Math.ceil(e(this,H)/e(this,E));b(this,I,d+20)}else b(this,I,40);return console.log(`[RowManager] Template Height Cached: ${e(this,E)}px | RowCount: ${e(this,I)}`),e(this,E)},"measureAndCacheHeight"));x(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(h=>{n.appendChild(h.cloneNode(!0))});s?s.before(n):t.appendChild(n),console.log(`[RowManager] Rendered ${r} sets into DOM.`)},"renderRows"));x(this,"destroy",a(()=>{e(this,z)&&(e(this,z).disconnect(),b(this,z,null))},"destroy"));b(this,Y,i),e(this,oe).call(this)}get templateLength(){return e(this,M).length||1}};Y=new WeakMap,M=new WeakMap,E=new WeakMap,z=new WeakMap,H=new WeakMap,I=new WeakMap,oe=new WeakMap,le=new WeakMap,a(Te,"RowManager");let G=Te;const J=class J extends HTMLElement{constructor(){super();c(this,L,null);c(this,F);x(this,"init",a(t=>{if(!t)return;const s=a(l=>{const u=a(v=>{if(v.querySelector("colgroup"))return;const w=v.querySelector("tbody tr")||v.querySelector("tr"),C=w?w.querySelectorAll("th, td").length:1,q=document.createElement("colgroup"),ie=Math.max(Math.floor((v.clientWidth||600)/C),100);for(let $=0;$<C;$++){const _e=document.createElement("col");_e.setAttribute("width",ie),q.appendChild(_e)}v.prepend(q)},"ensureColgroup"),d=a(v=>{if(v.querySelector("thead"))return;const w=document.createElement("thead"),C=v.querySelector("colgroup");C?C.after(w):v.prepend(w)},"ensureThead");return u(l),d(l),l.classList.add("nine-table-element"),l},"initializeTable"),n=t.cloneNode(!0);b(this,L,s(n)),e(this,L).style.display="table",e(this,F).initTemplate(e(this,L));const r=this.querySelector(".ng-container-left"),o=this.querySelector(".ng-container-body"),h=this.querySelector(".ng-container-right"),f=a((l,u,d=!1)=>{const v=l.cloneNode(!0),w=Array.from(v.querySelectorAll("colgroup col")),C=[];return w.forEach((q,ie)=>{const $=q.getAttribute("fixed");(d?$!=="left"&&$!=="right":$===u)||C.push(ie)}),C.reverse().forEach(q=>{w[q]&&w[q].remove(),v.querySelectorAll("tr").forEach(ie=>{const $=ie.querySelectorAll("th, td");$[q]&&$[q].remove()})}),v},"filterTableByFixed");if(o){const l=f(e(this,L),null,!0);o.innerHTML="",o.appendChild(l),e(this,F).measureAndCacheHeight(o)}if(r){const l=f(e(this,L),"left",!1);let u=0;l.querySelectorAll("col").forEach(v=>{const w=parseInt(v.getAttribute("width"),10);isNaN(w)||(u+=w)}),r.innerHTML="",r.appendChild(l);const d=u>0?u:0;r.style.flex=`0 0 ${d}px`,r.style.width=`${d}px`}if(h){const l=f(e(this,L),"right",!1);let u=0;l.querySelectorAll("col").forEach(v=>{const w=parseInt(v.getAttribute("width"),10);isNaN(w)||(u+=w)}),h.innerHTML="",h.appendChild(l);const d=u>0?u:0;h.style.flex=`0 0 ${d}px`,h.style.width=`${d}px`}if(o){const l=this.getRowCount();o.style.overflowY=l>10?"auto":"hidden",o.addEventListener("scroll",()=>{const u=this.querySelector("nine-table-hscrollbar");u&&typeof u.refresh=="function"&&u.refresh()})}setTimeout(()=>{const l=this.querySelector("nine-table-hscrollbar");l&&typeof l.refresh=="function"&&l.refresh()},0),R.log(`NineTableSheet 3-split initialized with rows: ${this.getRowCount()}`)},"init"));x(this,"getRowHeight",a(()=>e(this,F).getRowHeight(),"getRowHeight"));x(this,"getRowCount",a(()=>e(this,L)?e(this,L).querySelectorAll("tbody tr").length:0,"getRowCount"));x(this,"scrollToX",a(t=>{const s=this.querySelector(".ng-container-body");s&&(s.scrollLeft=t)},"scrollToX"));x(this,"scrollToY",a(t=>{const s=this.querySelector(".ng-container-body");s&&(s.scrollTop=t)},"scrollToY"));c(this,ae,a(()=>{const t=J.SCROLLBAR_SIZE;this.innerHTML=`
|
|
64
64
|
<style>
|
|
65
65
|
nine-table-sheet {
|
|
66
66
|
flex-direction: column;
|
|
@@ -160,6 +160,19 @@
|
|
|
160
160
|
font-weight: 600;
|
|
161
161
|
text-align: left;
|
|
162
162
|
}
|
|
163
|
+
|
|
164
|
+
nine-splitter {
|
|
165
|
+
display: none;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/*
|
|
169
|
+
π― [ν΅μ¬ CSS]
|
|
170
|
+
μμ (nine-splitter) λ°λ‘ λ€μμ μ€λ μνΈ(.active)κ° μΌμ Έ μκ³ ,
|
|
171
|
+
κ·Έ μ€νλ¦¬ν° λ°λ‘ μμ μλ μνΈ(.active)λ μΌμ Έ μμ λλ§ display: block
|
|
172
|
+
*/
|
|
173
|
+
nine-table-sheet.active + nine-splitter + nine-table-sheet.active {
|
|
174
|
+
display: flex;
|
|
175
|
+
}
|
|
163
176
|
</style>
|
|
164
177
|
|
|
165
178
|
<div class='ng-container-top'>
|
|
@@ -172,7 +185,7 @@
|
|
|
172
185
|
<nine-table-hscrollbar></nine-table-hscrollbar>
|
|
173
186
|
<div class='ng-scroll-edge'></div>
|
|
174
187
|
</div>
|
|
175
|
-
`},"#render"));
|
|
188
|
+
`},"#render"));b(this,F,new G(this))}connectedCallback(){e(this,ae).call(this)}disconnectedCallback(){this.innerHTML="",R.log("NineTableSheet destroyed.")}};L=new WeakMap,F=new WeakMap,ae=new WeakMap,a(J,"NineTableSheet"),x(J,"SCROLLBAR_SIZE",16);let se=J;customElements.get("nine-table-sheet")||customElements.define("nine-table-sheet",se);const ke=class ke extends HTMLElement{constructor(){super();c(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,Q).call(this,r,n)}),e(this,Q).call(this,0,!1)},"#init"));c(this,Q,a((t,s=!1)=>{var f;const n=this.querySelector(".nine-tab-bar"),r=this.querySelector("nine-table-sheets-body"),o=n.querySelectorAll(".nine-tab-item"),h=r.querySelectorAll("nine-table-sheet");if(o[t]){if(!s)o.forEach((l,u)=>{l.classList.toggle("active",u===t)}),h.forEach((l,u)=>{const d=u===t;l.classList.toggle("active",d),l.style.flex=d?"1 1 100%":""});else{const l=o[t],u=n.querySelectorAll(".nine-tab-item.active");if(l.classList.contains("active")&&u.length<=1)return;l.classList.toggle("active");const d=r.querySelector(`nine-table-sheet[data-index="${t}"]`);d&&(d.classList.toggle("active"),d.classList.contains("active")||(d.style.flex=""))}(f=r.querySelectorAll("nine-table-sheet.active"))==null||f.forEach(l=>{l.style.flex=activeSheets.length>1?"1 1 0%":"1 1 100%"})}},"#switchSheet"))}connectedCallback(){e(this,he).call(this)}};he=new WeakMap,Q=new WeakMap,a(ke,"NineTableSheets");let ye=ke;customElements.get("nine-table-sheets")||customElements.define("nine-table-sheets",ye);const qe=class qe{constructor(i){c(this,S);c(this,ce,a(()=>{e(this,de).call(this),new ResizeObserver(i=>{for(let t of i)e(this,S).getAttribute("auto-height")==="true"&&e(this,ee).call(this)}).observe(e(this,S))},"#init"));c(this,ee,a(()=>{var f,l;const i=Array.from(e(this,S).shadowRoot.querySelectorAll("nine-table-sheet.active"));if(i.length===0)return;const t=parseInt(e(this,S).getAttribute("max-display-row"),10)||10,s=Math.max(...i.map(u=>u.getRowHeight())),n=(f=e(this,S).shadowRoot.querySelector("nine-table-header"))==null?void 0:f.getBoundingClientRect().height,r=(l=e(this,S).shadowRoot.querySelector("nine-table-sheets-footer"))==null?void 0:l.getBoundingClientRect().height,o=se.SCROLLBAR_SIZE,h=t*s+n+r+o;e(this,S).style.height=`${h}px`},"#applyAutoHeight"));c(this,de,a(()=>{const t=Array.from(e(this,S).children).filter(f=>f.tagName==="TABLE"),s=e(this,S).getAttribute("auto-height")==="true",n=t.length,r=t.map((f,l)=>{const d=`<nine-table-sheet class="${l===0?"active":""}" data-index="${l}"></nine-table-sheet>`,v=l<n-1?`<nine-splitter class="h" data-split-index="${l}"></nine-splitter>`:"";return d+v}).join(""),o=t.map((f,l)=>`<div class="nine-tab-item ${l===0?"active":""}" data-index="${l}">Sheet ${l+1}</div>`).join("");e(this,S).shadowRoot.innerHTML=`
|
|
176
189
|
<style>
|
|
177
190
|
:host {
|
|
178
191
|
display: flex;
|
|
@@ -270,5 +283,5 @@
|
|
|
270
283
|
<nine-table-analysis></nine-table-analysis>
|
|
271
284
|
</nine-table-body>
|
|
272
285
|
<nine-table-footer></nine-table-footer>
|
|
273
|
-
`;const
|
|
286
|
+
`;const h=e(this,S).shadowRoot.querySelectorAll("nine-table-sheet");h==null||h.forEach((f,l)=>{t[l]&&setTimeout(()=>{f.init(t[l]),s&&e(this,ee).call(this)})})},"#render"));b(this,S,i),e(this,ce).call(this)}};S=new WeakMap,ce=new WeakMap,ee=new WeakMap,de=new WeakMap,a(qe,"LayoutManager");let we=qe;const Ae=class Ae{constructor(i){c(this,O);c(this,U,-1);x(this,"count",a(()=>e(this,O).rawRecords.length,"count"));b(this,O,i)}get at(){return e(this,U)}set at(i){var s,n;b(this,U,parseInt(i,10));const t=((n=(s=e(this,O).owner).querySelector)==null?void 0:n.call(s,".ng-container-body"))||e(this,O).owner.body;t&&!t.querySelector(`tbody.bindable tr[data-row="${e(this,U)}"]`)&&setTimeout(()=>{var r,o;(o=(r=e(this,O).owner).scrollTo_V1)==null||o.call(r,e(this,U))})}};O=new WeakMap,U=new WeakMap,a(Ae,"ngRow");let me=Ae;const A=class A{constructor(i,t){c(this,T);c(this,m);c(this,k,[]);c(this,Z,[]);c(this,fe,0);c(this,D,[]);c(this,ue,a(()=>{b(this,D,[]);const i=e(this,T).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,m).rawRecords||[]).forEach(t=>{t.__ng||(t.__ng=e(this,te).call(this)),t.__ng.height=e(this,D).slice()})},"#initialize"));x(this,"set",a(i=>{this.clear(),this.add(i,!1)},"set"));c(this,te,a(()=>({rowState:A.ROW_STATE.EMPTY,deleted:!1,filtered:!1,height:e(this,D).slice(),o:{},c:{},_:[0,0,0,0,A.ROW_STATE.EMPTY,!1,!1,!0,!1,!0,!0,!1,e(this,D).slice(),-1,{},{}]}),"#getDefaultMeta"));x(this,"reset",a(()=>{b(this,k,[]),b(this,Z,[])},"reset"));x(this,"clear",a(()=>{var i;e(this,m).rawRecords=[],b(this,k,[]),b(this,Z,[]),(i=e(this,m).viewRecords)!=null&&i.reset&&e(this,m).viewRecords.reset()},"clear"));c(this,be,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(h=>{o.v.push(r[h]!==void 0&&r[h]!==null?r[h]:"")}),s.push(o)}),s},"#json2Array"));c(this,ge,a(i=>(Array.isArray(i)||(i=[i]),i.forEach(t=>{t.__ng=e(this,te).call(this),t.__ng.rowid=this.nextId,t.__ng.rowState=A.ROW_STATE.INSERT,t.__ng._[0]=t.__ng.rowid}),i),"#defaultInsert"));x(this,"add",a((i,t=!0)=>{var r;i===void 0&&(i={});const s=e(this,be).call(this,i);e(this,m).rawRecords=e(this,m).rawRecords.concat(e(this,ge).call(this,s)),this.resetRecords();const n=this.count()-1;return t||s.forEach((o,h)=>{const f=e(this,m).rawRecords[n-h];f&&(f.__ng.rowState=A.ROW_STATE.EMPTY)}),(r=e(this,m).viewRecords)!=null&&r.reset&&e(this,m).viewRecords.reset(),n},"add"));x(this,"delete",a(i=>{var s;let t=[];Array.isArray(i)?t=i:typeof i>"u"?t=[e(this,m).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===A.ROW_STATE.INSERT?e(this,m).rawRecords=e(this,m).rawRecords.filter(o=>o.__ng.rowid!==r):e(this,m).rawRecords.forEach(o=>{o.__ng.rowid===r&&(o.__ng.deleted=!0,o.__ng.rowState=A.ROW_STATE.DELETE)})}}),this.resetRecords(),(s=e(this,m).viewRecords)!=null&&s.reset&&e(this,m).viewRecords.reset()},"delete"));x(this,"setValue",a((i,t,s)=>{var f;i=parseInt(i,10);const r=(typeof((f=e(this,T).fields)==null?void 0:f.get)=="function"?e(this,T).fields.get():[]).indexOf(t);if(r<0)return;const o=this.getValidData()[i];if(!o)return;const h=o.v[r];h!==s&&o.__ng.rowState!==A.ROW_STATE.INSERT&&(o.__ng.o.hasOwnProperty(t)||(o.__ng.o[t]=h),o.__ng.rowState=A.ROW_STATE.UPDATE),o.v[r]=s,e(this,m).owner.refreshData&&e(this,m).owner.refreshData(i)},"setValue"));x(this,"resetRecords",a(()=>{b(this,Z,e(this,m).rawRecords.filter(i=>!i.__ng.deleted)),b(this,k,e(this,m).rawRecords.filter(i=>!i.__ng.deleted&&!i.__ng.filtered)),e(this,m).rawRecords.forEach((i,t)=>{i.__ng.rowidx=t}),e(this,k).forEach((i,t)=>{i.__ng.i=t})},"resetRecords"));x(this,"getValidData",a(()=>(e(this,k).length===0&&e(this,m).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,h)=>{r[o]=n.v?n.v[h]:n[o]}),r.__ng=n.__ng,r}):i},"#conv2"));x(this,"count",a(()=>this.getValidData().length,"count"));x(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,m,t),e(this,ue).call(this)}get source(){return e(this,j).call(this,e(this,m).rawRecords)}set source(i){this.clear(),this.add(i,!1)}get nextId(){return++$e(this,fe)._}get length(){return e(this,k).length}getRowCount(){return this.length}};T=new WeakMap,m=new WeakMap,k=new WeakMap,Z=new WeakMap,fe=new WeakMap,D=new WeakMap,ue=new WeakMap,te=new WeakMap,be=new WeakMap,ge=new WeakMap,j=new WeakMap,a(A,"ngData"),x(A,"ROW_STATE",{EMPTY:"EMPTY",NORMAL:"NORMAL",INSERT:"INSERT",UPDATE:"UPDATE",DELETE:"DELETE"});let ve=A;const Ce=class Ce{constructor(i){this.owner=i,this.row=new me(this),this.data=new ve(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 xe=Ce;const Le=class Le extends HTMLElement{constructor(){super();c(this,K);c(this,pe);this.attachShadow({mode:"open"}),b(this,K,new xe(this))}connectedCallback(){b(this,pe,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,K).data}get row(){return e(this,K).row}get dataManager(){return e(this,K)}};K=new WeakMap,pe=new WeakMap,a(Le,"NineTable");let Re=Le;customElements.get("nine-table")||customElements.define("nine-table",Re)});
|
|
274
287
|
//# sourceMappingURL=nine-table.umd.js.map
|