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