@polygrid/core 1.0.0 → 1.0.1
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/package.json +1 -1
- package/polygrid.es.js +2 -2
- package/polygrid.umd.js +1 -1
package/package.json
CHANGED
package/polygrid.es.js
CHANGED
|
@@ -432,7 +432,7 @@ function E(o, t) {
|
|
|
432
432
|
o.columns$.pipe(h(t)).subscribe((e) => {
|
|
433
433
|
const r = o.gridDom;
|
|
434
434
|
y(r, o.store);
|
|
435
|
-
const s = o.store.getState(), i = e.filter((a) => a.visible ?? !0), n = s.viewportWidth, c = C(i, n), l = c.reduce((a, u) => a + u);
|
|
435
|
+
const s = o.store.getState(), i = e.filter((a) => a.visible ?? !0), n = s.viewportWidth, c = C(i, n), l = c.reduce((a, u) => a + u, 0);
|
|
436
436
|
o.store.update((a) => {
|
|
437
437
|
a.resolvedColumnWidths = c, a.totalColumnWidth = l;
|
|
438
438
|
}), f(r, s, c);
|
|
@@ -440,7 +440,7 @@ function E(o, t) {
|
|
|
440
440
|
}
|
|
441
441
|
function it(o, t) {
|
|
442
442
|
o.viewportWidth$.pipe(h(t)).subscribe((e) => {
|
|
443
|
-
const r = o.store.getState().columns.filter((n) => n.visible ?? !0), s = C(r, e), i = s.reduce((n, c) => n + c);
|
|
443
|
+
const r = o.store.getState().columns.filter((n) => n.visible ?? !0), s = C(r, e), i = s.reduce((n, c) => n + c, 0);
|
|
444
444
|
o.store.update((n) => {
|
|
445
445
|
n.resolvedColumnWidths = s, n.totalColumnWidth = i;
|
|
446
446
|
});
|
package/polygrid.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(b,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(b=typeof globalThis<"u"?globalThis:b||self,d(b.PolyGrid={}))})(this,(function(b){"use strict";const d={root:"pg-root",grid:"pg-grid",viewport:"pg-viewport",vScroll:"pg-v-scroll",vScrollSpacerTop:"pg-v-scroll-spacer-top",vScrollInner:"pg-v-scroll-inner",vScrollTrack:"pg-v-scroll-track",vScrollSpacerBottom:"pg-v-scroll-spacer-bottom",vScrollBottomCorner:"pg-v-scroll-bottom-corner",hScroll:"pg-h-scroll",hScrollInner:"pg-h-scroll-inner",hScrollTrack:"pg-h-scroll-track",headerViewport:"pg-header-viewport",header:"pg-header",headerCell:"pg-header-cell",bodyViewport:"pg-body-viewport",body:"pg-body",row:"pg-row",cell:"pg-cell",footerViewport:"pg-footer-viewport",footer:"pg-footer",footerCell:"pg-footer-cell"};function O(o,t){const e=document.createElement("div");e.classList.add(d.cell);const r=o[t.field];return e.textContent=r!=null?String(r):"",e}function V(o,t,e){const r=[],s=t.filter(i=>i.visible??!0);return o.forEach(i=>{const n=document.createElement("div");n.classList.add(d.row),n.style.height=e+"px",s.forEach(c=>{const l=O(i.data,c);n.appendChild(l)}),r.push(n)}),r}function _(o,t){const e=document.createElement("div");e.className=d.bodyViewport;const r=document.createElement("div");r.className=d.body,r.innerHTML="";const s=o.getState().rows,i=o.getState().columns,n=o.getState().rowHeight,c=V(s,i,n),l=document.createDocumentFragment();for(const a of c)l.appendChild(a);return r.appendChild(l),e.appendChild(r),t.body=r,e}function L(o,t){const e=t.getState().columns.filter(r=>r.visible??!0);o.innerHTML="",e.forEach((r,s)=>{const i=document.createElement("div");i.className=d.footerCell,i.textContent=r.header,o.appendChild(i)})}function I(o,t){const e=document.createElement("div");e.className=d.footerViewport;const r=document.createElement("div");return r.className=d.footer,L(r,o),e.appendChild(r),t.footer=r,e}function T(o,t){const e=t.getState().columns.filter(r=>r.visible??!0);o.innerHTML="",e.forEach((r,s)=>{const i=document.createElement("div");i.className=d.headerCell,i.textContent=r.header,o.appendChild(i)})}function A(o,t){const e=document.createElement("div");e.className=d.headerViewport;const r=document.createElement("div");return r.className=d.header,T(r,o),e.appendChild(r),t.header=r,e}function N(o){const t=document.createElement("div");t.className=d.hScroll;const e=document.createElement("div");e.className=d.hScrollInner;const r=document.createElement("div");return r.className=d.hScrollTrack,t.appendChild(e),e.appendChild(r),o.hScrollInner=e,o.hScrollTrack=r,t}function B(o,t){const e=document.createElement("div");e.className=d.viewport;const r=A(o,t),s=_(o,t),i=I(o,t),n=N(t);return e.appendChild(r),e.appendChild(s),e.appendChild(i),e.appendChild(n),t.headerViewport=r,t.bodyViewport=s,t.footerViewport=i,t.hScrollbar=n,e}function P(){const o=document.createElement("div");return o.className=d.vScrollBottomCorner,o}function x(){const o=document.createElement("div");return o.className=d.vScrollSpacerBottom,o}function z(){const o=document.createElement("div");return o.className=d.vScrollSpacerTop,o}function k(o){const t=document.createElement("div");t.className=d.vScroll;const e=document.createElement("div");e.className=d.vScrollInner;const r=document.createElement("div");r.className=d.vScrollTrack;const s=z(),i=x(),n=P();return t.appendChild(s),t.appendChild(e),t.appendChild(i),t.appendChild(n),e.appendChild(r),o.vScrollInner=e,o.vScrollSpacerTop=s,o.vScrollSpacerBottom=i,o.vScrollBottomCorner=n,o.vScrollTrack=r,t}function D(o,t){const e=document.createElement("div");e.className=d.grid;const r=B(o,t),s=k(t);return e.appendChild(r),e.appendChild(s),t.viewport=r,t.vScrollbar=s,e}function G(o,t,e){const r=document.createElement("div");r.className=d.root,r.id=o.getState().id;const s=D(o,e);r.appendChild(s),t.appendChild(r),e.root=r,e.grid=s}function j(){return{id:"",columns:[],rows:[],rowHeight:20,resolvedColumnWidths:[],columnWidthState:"NOT_SET",totalColumnWidth:0,totalRowHeight:0,viewportWidth:0,viewportHeight:0,rawViewportWidth:0,rawViewportHeight:0,showHScrollbar:!1,showVScrollbar:!1}}function H(o,t,e=[],r){return new Proxy(o,{get(s,i,n){const c=Reflect.get(s,i,n);if(c&&typeof c=="object"){const l=e.concat(String(i));return H(c,t,l,r)}return c},set(s,i,n,c){const l=String(i),a=e.concat(l),u=U(a),E=M(t,a),Et=Reflect.set(s,i,n,c);return r.push({path:u,from:E,to:n}),Et}})}function M(o,t){let e=o;for(const r of t){if(e==null)return;e=e[r]}return e}function U(o){return o.map(t=>/^\d+$/.test(t)?`[${t}]`:t).join(".").replace(/\.\[/g,"[")}function F(o,t,e){console.groupCollapsed("%cPolyGridStore mutations","color:#FF9800;font-weight:bold;");for(const r of o)console.log(`Path: ${r.path}`),console.log("From:",r.from),console.log("To:",r.to);console.groupEnd()}class p{constructor(t){this._subscribe=t}subscribe(t,e){const r=s=>{e&&console.log(`%cSubscription ${e?`(${e})`:""} reacted`,"color:#9C27B0;font-weight:bold;"),t(s)};return this._subscribe(r)}pipe(...t){let e=this;for(const r of t)e=r(e);return e}}function K(o,t){let e=t(o.getState());return new p(r=>{r(e);const s=i=>{const n=t(i);Object.is(e,n)||(e=n,r(n))};return o.getSubscribers().add(s),()=>o.getSubscribers().delete(s)})}function Y(o,t){return new p(e=>{let r=t.map(i=>i(o.getState()));e(r);const s=t.map((i,n)=>o.select(i).subscribe(c=>{if(!Object.is(r[n],c)){const l=[...r];l[n]=c,r=l,e(r)}}));return()=>s.forEach(i=>i())})}function q(o,t){return new p(e=>{const r=new Array(t.length),s=new Array(t.length).fill(!1),i=t.map((n,c)=>{if(typeof n=="function"){const a=n;return r[c]=a(o.getState()),s[c]=!0,o.select(a).subscribe(u=>{r[c]=u,e([...r])})}return n.subscribe(a=>{r[c]=a,s[c]=!0,s.every(Boolean)&&e([...r])})});return s.every(Boolean)&&e([...r]),()=>i.forEach(n=>n())})}function X(o,t,e){let r=e(o.getState());return new p(s=>{const i=(n,c)=>{if(!c.includes(t))return;const l=e(n);Object.is(r,l)||(r=l,s(l))};return o.getSubscribers().add(i),()=>o.getSubscribers().delete(i)})}class Z{constructor(){this.subscribers=new Set,this.state=j()}getState(){return this.state}getSubscribers(){return this.subscribers}update(t){const e=this.state,r={...this.state},s=[],i=H(r,e,[],s);t(i),s.length>0&&F(s);const n=s.map(c=>c.path);this.state=r,this.emit(n)}subscribe(t){return this.subscribers.add(t),()=>this.subscribers.delete(t)}select(t){return K(this,t)}selectKeyed(t,e){return X(this,t,e)}combineLatest(t){return Y(this,t)}combineLatestAny(t){return q(this,t)}emit(t){for(const e of this.subscribers)e(this.state,t)}}class J{constructor(){this.subscribers=new Set,this.pipe=p.prototype.pipe}subscribe(t){return this.subscribers.add(t),()=>this.subscribers.delete(t)}next(t){this.subscribers.forEach(e=>e(t))}complete(){this.subscribers.clear()}}function Q(){return o=>new p(t=>{let e;return o.subscribe(r=>{e&&e.length===r.length&&e.every((s,i)=>Object.is(s,r[i]))||(e=r,t(r))})})}function w(o=(t,e)=>t===e){return t=>new p(e=>{let r=!1,s;return t.subscribe(i=>{(!r||!o(s,i))&&(r=!0,s=i,e(i))})})}function S(o){return t=>new p(e=>t.subscribe(r=>{o(r)&&e(r)}))}function f(o){return t=>new p(e=>t.subscribe(r=>e(o(r))))}function h(o){return t=>new p(e=>{const r=t.subscribe(e),s=o.subscribe(()=>{r(),s()});return()=>{r(),s()}})}function tt(o,t){o.totalRowHeight$.pipe(h(t)).subscribe(e=>{o.store.update(r=>{r.totalRowHeight=e})},"SET-TOTALROWHEIGHT")}function et(o,t){const e=o.gridDom;o.totalRowHeight$.pipe(h(t)).subscribe(r=>{e.vScrollTrack.style.height=`${r}px`},"RESIZE-V-SCROLLBAR")}function ot(o,t){const e=o.gridDom;o.totalRowHeight$.pipe(h(t)).subscribe(r=>{e.body.style.height=`${r}px`},"RESIZE-BODY-HEIGHT")}function W(o){return o.map((t,e)=>({index:e,data:t}))}function rt(o,t){o.update(i=>i.id=t.id);const e=t.columns;e&&o.update(i=>{i.columns=e});const r=t.data;r&&o.update(i=>{i.rows=W(r)});const s=t.rowHeight;s&&o.update(i=>{i.rowHeight=s})}function v(o,t,e,r){t.addEventListener(e,r),o.cleanups.push(()=>{t.removeEventListener(e,r)})}function st(o){const t=o.gridDom;v(t,t.vScrollInner,"scroll",()=>{const e=t.vScrollInner.scrollTop;t.bodyViewport.scrollTop!==e&&(t.bodyViewport.scrollTop=e)}),v(t,t.hScrollInner,"scroll",()=>{const e=t.hScrollInner.scrollLeft;t.bodyViewport.scrollLeft!==e&&(t.bodyViewport.scrollLeft=e),t.headerViewport.scrollLeft!==e&&(t.headerViewport.scrollLeft=e),t.footerViewport.scrollLeft!==e&&(t.footerViewport.scrollLeft=e)}),v(t,t.bodyViewport,"wheel",e=>{e.deltaY!==0&&(t.vScrollInner.scrollTop+=e.deltaY),e.deltaX!==0&&(t.hScrollInner.scrollLeft+=e.deltaX),e.preventDefault()})}function C(o,t){const e=o.filter(n=>n.width!=null),r=o.filter(n=>n.width==null),s=e.reduce((n,c)=>n+c.width,0);switch(e.length===o.length?"ALL_SET":e.length===0?"NOT_SET":"SOME_SET"){case"ALL_SET":if(s>=t)return o.map(c=>c.width);{const l=(t-s)/o.length;return o.map(a=>a.width+l)}case"SOME_SET":if(s>=t)return o.map(c=>c.width??0);{const l=(t-s)/r.length;return o.map(a=>a.width??l)}case"NOT_SET":const n=t/o.length;return o.map(()=>n)}}function y(o,t){const e=o.header;e.replaceChildren(),T(e,t);const r=o.body;r.replaceChildren();const s=t.getState().rows,i=t.getState().columns,n=t.getState().rowHeight,c=V(s,i,n),l=document.createDocumentFragment();for(const E of c)l.appendChild(E);r.appendChild(l),o.body.querySelector(".pg-row:last-child")?.classList.toggle("last-row",!t.getState().showVScrollbar);const u=o.footer;u.replaceChildren(),L(u,t)}function R(o,t){o.columns$.pipe(h(t)).subscribe(e=>{const r=o.gridDom;y(r,o.store);const s=o.store.getState(),i=e.filter(a=>a.visible??!0),n=s.viewportWidth,c=C(i,n),l=c.reduce((a,u)=>a+u);o.store.update(a=>{a.resolvedColumnWidths=c,a.totalColumnWidth=l}),g(r,s,c)},"SET-COLUMNS")}function it(o,t){o.viewportWidth$.pipe(h(t)).subscribe(e=>{const r=o.store.getState().columns.filter(n=>n.visible??!0),s=C(r,e),i=s.reduce((n,c)=>n+c);o.store.update(n=>{n.resolvedColumnWidths=s,n.totalColumnWidth=i})},"RESOLVE-COLUMN-WIDTHS")}function m(o,t,e){const r=o.children;for(let s=0;s<t.length;s++){const i=r[s];if(!i)continue;const n=t[s]+"px";i.style.width=n,i.style.minWidth=n,i.style.maxWidth=n,s===t.length-1&&i.classList.toggle("last-cell",!e)}}function g(o,t,e){m(o.header,e,t.showVScrollbar),m(o.footer,e,t.showVScrollbar),o.body.querySelectorAll(".pg-row").forEach(n=>{m(n,e,t.showVScrollbar)});const s=e.reduce((n,c)=>n+c,0);o.body.style.width=`${s}px`,o.header.style.width=`${s}px`,o.footer.style.width=`${s}px`,o.hScrollTrack.style.width=`${s}px`;const i=t.viewportWidth;o.viewport.style.width=`${i}px`}function nt(o,t){o.resolvedColWidths$.pipe(h(t)).subscribe(e=>{const r=o.gridDom,s=o.store.getState();g(r,s,e)},"APPLY-COLUMN-WIDTHS")}function ct(o,t){const e=o.gridDom;o.showVScrollbar$.pipe(h(t)).subscribe(r=>{o.store.update(i=>{i.showVScrollbar=r}),e.vScrollbar.style.display=r?"flex":"none",e.body.querySelector(".pg-row:last-child")?.classList.toggle("last-row",!r)},"SHOW-V-SCROLLBAR"),o.showHScrollbar$.pipe(h(t)).subscribe(r=>{o.store.update(s=>{s.showHScrollbar=r}),e.hScrollbar.style.display=r?"block":"none",e.vScrollBottomCorner.style.display=r?"block":"none"},"SHOW-H-SCROLLBAR"),o.adjustedViewportWidth$.pipe(h(t),f(([r,s])=>s-(r?16:0)),w(),S(r=>r>=0)).subscribe(r=>{o.store.update(s=>{s.viewportWidth=r})}),o.adjustedViewportHeight$.pipe(h(t),f(([r,s])=>s-(r?16:0)),w(),S(r=>r>=0)).subscribe(r=>{o.store.update(s=>{s.viewportHeight=r})})}function lt(o,t){o.computeTotalRowHeight(o,t),o.resizeVScrollbar(o,t),o.resizeBody(o,t),o.adjustViewport(o,t),o.computeColumnWidths(o,t),o.applyColumnWidths(o,t),o.addScrollEventListeners(o)}function dt(o,t,e){return new ResizeObserver(r=>{for(const s of r){const i=s.contentRect.width,n=s.contentRect.height,c=t.headerViewport.getBoundingClientRect().height,l=t.footerViewport.getBoundingClientRect().height;e.update(a=>{a.viewportWidth=i,a.viewportHeight=n-c-l,a.rawViewportWidth=i,a.rawViewportHeight=n-c-l})}})}function $(o,t){const e=o.gridDom;o.grid,o.gridId$.pipe(h(t)).subscribe(r=>{e.root.id=r},"SET-GRID-ID")}class at{constructor(t){this.resizeVScrollbar=et,this.resizeBody=ot,this.computeTotalRowHeight=tt,this.addScrollEventListeners=st,this.computeColumnWidths=it,this.setCellWidth=m,this.applyColumnWidths=nt,this.adjustViewport=ct,this.initializeLayoutPipeline=lt,this.setUpResizeObserver=dt,this.setGridId=$,this.updateColumnWidths=g,this.store=t._store,this.destroy$=t._destroy$,this.gridDom=t._gridDom,this.grid=t,this.totalRowHeight$=this.store.combineLatest([e=>e.rows,e=>e.rowHeight]).pipe(f(([e,r])=>e.length*r),w()),this.viewportWidth$=this.store.select(e=>e.viewportWidth).pipe(w()),this.resolvedColWidths$=this.store.combineLatest([e=>e.resolvedColumnWidths,e=>e.viewportWidth,e=>e.rawViewportWidth]).pipe(S(([e,r,s])=>r!==s),f(([e])=>e),Q()),this.showVScrollbar$=this.store.combineLatest([e=>e.totalRowHeight,e=>e.rawViewportHeight]).pipe(f(([e,r])=>e>r),w()),this.showHScrollbar$=this.store.combineLatest([e=>e.totalColumnWidth,e=>e.rawViewportWidth]).pipe(f(([e,r])=>e>r),w()),this.adjustedViewportWidth$=this.store.combineLatestAny([this.showVScrollbar$,e=>e.rawViewportWidth]),this.adjustedViewportHeight$=this.store.combineLatestAny([this.showHScrollbar$,e=>e.rawViewportHeight])}initApiSubscriptions(){this.gridId$=this.store.selectKeyed("id",t=>t.id),$(this,this.destroy$)}}class ht{constructor(t){this.resolveColumnWidths=C,this.setColumns=R,this.store=t._store,this.destroy$=t._destroy$,this.gridDom=t._gridDom,this.grid=t}initApiSubscriptions(){this.columns$=this.store.selectKeyed("columns",t=>t.columns),R(this,this.destroy$)}}class pt{constructor(t){this.store=t._store}}function ut(o,t){o.rows$.pipe(h(t)).subscribe(e=>{const r=o.gridDom,s=o.store.getState(),i=s.resolvedColumnWidths;y(r,o.store),g(r,s,i)},"SET-DATA")}class bt{constructor(t){this.store=t._store,this.destroy$=t._destroy$,this.gridDom=t._gridDom,this.grid=t}initApiSubscriptions(){this.rows$=this.store.selectKeyed("rows",t=>t.rows),ut(this,this.destroy$)}}class wt{constructor(t){this.reRenderCells=y,this.store=t._store,this.destroy$=t._destroy$,this.gridDom=t._gridDom,this.grid=t}initApiSubscriptions(){}}class ft{constructor(t){this.grid=t,this.layout=new at(this.grid),this.column=new ht(this.grid),this.row=new pt(this.grid),this.data=new bt(this.grid),this.renderer=new wt(this.grid)}}class mt{constructor(){this.cleanups=[]}}function gt(o,t){o._store.update(e=>{e.columns=t})}function St(o,t){o._store.update(e=>{e.rows=W(t)})}function vt(o,t){o._store.update(e=>{e.id=t})}function Ct(o){return{setGridId:t=>vt(o,t),setData:t=>St(o,t),setColumns:t=>gt(o,t)}}class yt{constructor(t,e){this.store=new Z,this.gridDom=new mt,this.destroy$=new J,this.services=new ft(this),rt(this.store,e),G(this.store,t,this.gridDom),this.resizeObserver=this.services.layout.setUpResizeObserver(this.resizeObserver,this.gridDom,this.store),this.resizeObserver.observe(this.gridDom.grid),this.services.layout.initializeLayoutPipeline(this.services.layout,this.destroy$),this.api=Ct(this),this.services.layout.initApiSubscriptions(),this.services.data.initApiSubscriptions(),this.services.column.initApiSubscriptions(),this.services.renderer.initApiSubscriptions(),console.log("PolyGrid initialized")}destroy(){this.destroy$.next(),this.destroy$.complete();for(const t of this.gridDom.cleanups)t()}get _store(){return this.store}get _destroy$(){return this.destroy$}get _gridDom(){return this.gridDom}}b.PolyGrid=yt,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(b,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(b=typeof globalThis<"u"?globalThis:b||self,d(b.PolyGrid={}))})(this,(function(b){"use strict";const d={root:"pg-root",grid:"pg-grid",viewport:"pg-viewport",vScroll:"pg-v-scroll",vScrollSpacerTop:"pg-v-scroll-spacer-top",vScrollInner:"pg-v-scroll-inner",vScrollTrack:"pg-v-scroll-track",vScrollSpacerBottom:"pg-v-scroll-spacer-bottom",vScrollBottomCorner:"pg-v-scroll-bottom-corner",hScroll:"pg-h-scroll",hScrollInner:"pg-h-scroll-inner",hScrollTrack:"pg-h-scroll-track",headerViewport:"pg-header-viewport",header:"pg-header",headerCell:"pg-header-cell",bodyViewport:"pg-body-viewport",body:"pg-body",row:"pg-row",cell:"pg-cell",footerViewport:"pg-footer-viewport",footer:"pg-footer",footerCell:"pg-footer-cell"};function O(o,t){const e=document.createElement("div");e.classList.add(d.cell);const r=o[t.field];return e.textContent=r!=null?String(r):"",e}function V(o,t,e){const r=[],s=t.filter(i=>i.visible??!0);return o.forEach(i=>{const n=document.createElement("div");n.classList.add(d.row),n.style.height=e+"px",s.forEach(c=>{const l=O(i.data,c);n.appendChild(l)}),r.push(n)}),r}function _(o,t){const e=document.createElement("div");e.className=d.bodyViewport;const r=document.createElement("div");r.className=d.body,r.innerHTML="";const s=o.getState().rows,i=o.getState().columns,n=o.getState().rowHeight,c=V(s,i,n),l=document.createDocumentFragment();for(const a of c)l.appendChild(a);return r.appendChild(l),e.appendChild(r),t.body=r,e}function L(o,t){const e=t.getState().columns.filter(r=>r.visible??!0);o.innerHTML="",e.forEach((r,s)=>{const i=document.createElement("div");i.className=d.footerCell,i.textContent=r.header,o.appendChild(i)})}function I(o,t){const e=document.createElement("div");e.className=d.footerViewport;const r=document.createElement("div");return r.className=d.footer,L(r,o),e.appendChild(r),t.footer=r,e}function T(o,t){const e=t.getState().columns.filter(r=>r.visible??!0);o.innerHTML="",e.forEach((r,s)=>{const i=document.createElement("div");i.className=d.headerCell,i.textContent=r.header,o.appendChild(i)})}function A(o,t){const e=document.createElement("div");e.className=d.headerViewport;const r=document.createElement("div");return r.className=d.header,T(r,o),e.appendChild(r),t.header=r,e}function N(o){const t=document.createElement("div");t.className=d.hScroll;const e=document.createElement("div");e.className=d.hScrollInner;const r=document.createElement("div");return r.className=d.hScrollTrack,t.appendChild(e),e.appendChild(r),o.hScrollInner=e,o.hScrollTrack=r,t}function B(o,t){const e=document.createElement("div");e.className=d.viewport;const r=A(o,t),s=_(o,t),i=I(o,t),n=N(t);return e.appendChild(r),e.appendChild(s),e.appendChild(i),e.appendChild(n),t.headerViewport=r,t.bodyViewport=s,t.footerViewport=i,t.hScrollbar=n,e}function P(){const o=document.createElement("div");return o.className=d.vScrollBottomCorner,o}function x(){const o=document.createElement("div");return o.className=d.vScrollSpacerBottom,o}function z(){const o=document.createElement("div");return o.className=d.vScrollSpacerTop,o}function k(o){const t=document.createElement("div");t.className=d.vScroll;const e=document.createElement("div");e.className=d.vScrollInner;const r=document.createElement("div");r.className=d.vScrollTrack;const s=z(),i=x(),n=P();return t.appendChild(s),t.appendChild(e),t.appendChild(i),t.appendChild(n),e.appendChild(r),o.vScrollInner=e,o.vScrollSpacerTop=s,o.vScrollSpacerBottom=i,o.vScrollBottomCorner=n,o.vScrollTrack=r,t}function D(o,t){const e=document.createElement("div");e.className=d.grid;const r=B(o,t),s=k(t);return e.appendChild(r),e.appendChild(s),t.viewport=r,t.vScrollbar=s,e}function G(o,t,e){const r=document.createElement("div");r.className=d.root,r.id=o.getState().id;const s=D(o,e);r.appendChild(s),t.appendChild(r),e.root=r,e.grid=s}function j(){return{id:"",columns:[],rows:[],rowHeight:20,resolvedColumnWidths:[],columnWidthState:"NOT_SET",totalColumnWidth:0,totalRowHeight:0,viewportWidth:0,viewportHeight:0,rawViewportWidth:0,rawViewportHeight:0,showHScrollbar:!1,showVScrollbar:!1}}function H(o,t,e=[],r){return new Proxy(o,{get(s,i,n){const c=Reflect.get(s,i,n);if(c&&typeof c=="object"){const l=e.concat(String(i));return H(c,t,l,r)}return c},set(s,i,n,c){const l=String(i),a=e.concat(l),u=U(a),E=M(t,a),Et=Reflect.set(s,i,n,c);return r.push({path:u,from:E,to:n}),Et}})}function M(o,t){let e=o;for(const r of t){if(e==null)return;e=e[r]}return e}function U(o){return o.map(t=>/^\d+$/.test(t)?`[${t}]`:t).join(".").replace(/\.\[/g,"[")}function F(o,t,e){console.groupCollapsed("%cPolyGridStore mutations","color:#FF9800;font-weight:bold;");for(const r of o)console.log(`Path: ${r.path}`),console.log("From:",r.from),console.log("To:",r.to);console.groupEnd()}class p{constructor(t){this._subscribe=t}subscribe(t,e){const r=s=>{e&&console.log(`%cSubscription ${e?`(${e})`:""} reacted`,"color:#9C27B0;font-weight:bold;"),t(s)};return this._subscribe(r)}pipe(...t){let e=this;for(const r of t)e=r(e);return e}}function K(o,t){let e=t(o.getState());return new p(r=>{r(e);const s=i=>{const n=t(i);Object.is(e,n)||(e=n,r(n))};return o.getSubscribers().add(s),()=>o.getSubscribers().delete(s)})}function Y(o,t){return new p(e=>{let r=t.map(i=>i(o.getState()));e(r);const s=t.map((i,n)=>o.select(i).subscribe(c=>{if(!Object.is(r[n],c)){const l=[...r];l[n]=c,r=l,e(r)}}));return()=>s.forEach(i=>i())})}function q(o,t){return new p(e=>{const r=new Array(t.length),s=new Array(t.length).fill(!1),i=t.map((n,c)=>{if(typeof n=="function"){const a=n;return r[c]=a(o.getState()),s[c]=!0,o.select(a).subscribe(u=>{r[c]=u,e([...r])})}return n.subscribe(a=>{r[c]=a,s[c]=!0,s.every(Boolean)&&e([...r])})});return s.every(Boolean)&&e([...r]),()=>i.forEach(n=>n())})}function X(o,t,e){let r=e(o.getState());return new p(s=>{const i=(n,c)=>{if(!c.includes(t))return;const l=e(n);Object.is(r,l)||(r=l,s(l))};return o.getSubscribers().add(i),()=>o.getSubscribers().delete(i)})}class Z{constructor(){this.subscribers=new Set,this.state=j()}getState(){return this.state}getSubscribers(){return this.subscribers}update(t){const e=this.state,r={...this.state},s=[],i=H(r,e,[],s);t(i),s.length>0&&F(s);const n=s.map(c=>c.path);this.state=r,this.emit(n)}subscribe(t){return this.subscribers.add(t),()=>this.subscribers.delete(t)}select(t){return K(this,t)}selectKeyed(t,e){return X(this,t,e)}combineLatest(t){return Y(this,t)}combineLatestAny(t){return q(this,t)}emit(t){for(const e of this.subscribers)e(this.state,t)}}class J{constructor(){this.subscribers=new Set,this.pipe=p.prototype.pipe}subscribe(t){return this.subscribers.add(t),()=>this.subscribers.delete(t)}next(t){this.subscribers.forEach(e=>e(t))}complete(){this.subscribers.clear()}}function Q(){return o=>new p(t=>{let e;return o.subscribe(r=>{e&&e.length===r.length&&e.every((s,i)=>Object.is(s,r[i]))||(e=r,t(r))})})}function w(o=(t,e)=>t===e){return t=>new p(e=>{let r=!1,s;return t.subscribe(i=>{(!r||!o(s,i))&&(r=!0,s=i,e(i))})})}function S(o){return t=>new p(e=>t.subscribe(r=>{o(r)&&e(r)}))}function f(o){return t=>new p(e=>t.subscribe(r=>e(o(r))))}function h(o){return t=>new p(e=>{const r=t.subscribe(e),s=o.subscribe(()=>{r(),s()});return()=>{r(),s()}})}function tt(o,t){o.totalRowHeight$.pipe(h(t)).subscribe(e=>{o.store.update(r=>{r.totalRowHeight=e})},"SET-TOTALROWHEIGHT")}function et(o,t){const e=o.gridDom;o.totalRowHeight$.pipe(h(t)).subscribe(r=>{e.vScrollTrack.style.height=`${r}px`},"RESIZE-V-SCROLLBAR")}function ot(o,t){const e=o.gridDom;o.totalRowHeight$.pipe(h(t)).subscribe(r=>{e.body.style.height=`${r}px`},"RESIZE-BODY-HEIGHT")}function W(o){return o.map((t,e)=>({index:e,data:t}))}function rt(o,t){o.update(i=>i.id=t.id);const e=t.columns;e&&o.update(i=>{i.columns=e});const r=t.data;r&&o.update(i=>{i.rows=W(r)});const s=t.rowHeight;s&&o.update(i=>{i.rowHeight=s})}function v(o,t,e,r){t.addEventListener(e,r),o.cleanups.push(()=>{t.removeEventListener(e,r)})}function st(o){const t=o.gridDom;v(t,t.vScrollInner,"scroll",()=>{const e=t.vScrollInner.scrollTop;t.bodyViewport.scrollTop!==e&&(t.bodyViewport.scrollTop=e)}),v(t,t.hScrollInner,"scroll",()=>{const e=t.hScrollInner.scrollLeft;t.bodyViewport.scrollLeft!==e&&(t.bodyViewport.scrollLeft=e),t.headerViewport.scrollLeft!==e&&(t.headerViewport.scrollLeft=e),t.footerViewport.scrollLeft!==e&&(t.footerViewport.scrollLeft=e)}),v(t,t.bodyViewport,"wheel",e=>{e.deltaY!==0&&(t.vScrollInner.scrollTop+=e.deltaY),e.deltaX!==0&&(t.hScrollInner.scrollLeft+=e.deltaX),e.preventDefault()})}function C(o,t){const e=o.filter(n=>n.width!=null),r=o.filter(n=>n.width==null),s=e.reduce((n,c)=>n+c.width,0);switch(e.length===o.length?"ALL_SET":e.length===0?"NOT_SET":"SOME_SET"){case"ALL_SET":if(s>=t)return o.map(c=>c.width);{const l=(t-s)/o.length;return o.map(a=>a.width+l)}case"SOME_SET":if(s>=t)return o.map(c=>c.width??0);{const l=(t-s)/r.length;return o.map(a=>a.width??l)}case"NOT_SET":const n=t/o.length;return o.map(()=>n)}}function y(o,t){const e=o.header;e.replaceChildren(),T(e,t);const r=o.body;r.replaceChildren();const s=t.getState().rows,i=t.getState().columns,n=t.getState().rowHeight,c=V(s,i,n),l=document.createDocumentFragment();for(const E of c)l.appendChild(E);r.appendChild(l),o.body.querySelector(".pg-row:last-child")?.classList.toggle("last-row",!t.getState().showVScrollbar);const u=o.footer;u.replaceChildren(),L(u,t)}function R(o,t){o.columns$.pipe(h(t)).subscribe(e=>{const r=o.gridDom;y(r,o.store);const s=o.store.getState(),i=e.filter(a=>a.visible??!0),n=s.viewportWidth,c=C(i,n),l=c.reduce((a,u)=>a+u,0);o.store.update(a=>{a.resolvedColumnWidths=c,a.totalColumnWidth=l}),g(r,s,c)},"SET-COLUMNS")}function it(o,t){o.viewportWidth$.pipe(h(t)).subscribe(e=>{const r=o.store.getState().columns.filter(n=>n.visible??!0),s=C(r,e),i=s.reduce((n,c)=>n+c,0);o.store.update(n=>{n.resolvedColumnWidths=s,n.totalColumnWidth=i})},"RESOLVE-COLUMN-WIDTHS")}function m(o,t,e){const r=o.children;for(let s=0;s<t.length;s++){const i=r[s];if(!i)continue;const n=t[s]+"px";i.style.width=n,i.style.minWidth=n,i.style.maxWidth=n,s===t.length-1&&i.classList.toggle("last-cell",!e)}}function g(o,t,e){m(o.header,e,t.showVScrollbar),m(o.footer,e,t.showVScrollbar),o.body.querySelectorAll(".pg-row").forEach(n=>{m(n,e,t.showVScrollbar)});const s=e.reduce((n,c)=>n+c,0);o.body.style.width=`${s}px`,o.header.style.width=`${s}px`,o.footer.style.width=`${s}px`,o.hScrollTrack.style.width=`${s}px`;const i=t.viewportWidth;o.viewport.style.width=`${i}px`}function nt(o,t){o.resolvedColWidths$.pipe(h(t)).subscribe(e=>{const r=o.gridDom,s=o.store.getState();g(r,s,e)},"APPLY-COLUMN-WIDTHS")}function ct(o,t){const e=o.gridDom;o.showVScrollbar$.pipe(h(t)).subscribe(r=>{o.store.update(i=>{i.showVScrollbar=r}),e.vScrollbar.style.display=r?"flex":"none",e.body.querySelector(".pg-row:last-child")?.classList.toggle("last-row",!r)},"SHOW-V-SCROLLBAR"),o.showHScrollbar$.pipe(h(t)).subscribe(r=>{o.store.update(s=>{s.showHScrollbar=r}),e.hScrollbar.style.display=r?"block":"none",e.vScrollBottomCorner.style.display=r?"block":"none"},"SHOW-H-SCROLLBAR"),o.adjustedViewportWidth$.pipe(h(t),f(([r,s])=>s-(r?16:0)),w(),S(r=>r>=0)).subscribe(r=>{o.store.update(s=>{s.viewportWidth=r})}),o.adjustedViewportHeight$.pipe(h(t),f(([r,s])=>s-(r?16:0)),w(),S(r=>r>=0)).subscribe(r=>{o.store.update(s=>{s.viewportHeight=r})})}function lt(o,t){o.computeTotalRowHeight(o,t),o.resizeVScrollbar(o,t),o.resizeBody(o,t),o.adjustViewport(o,t),o.computeColumnWidths(o,t),o.applyColumnWidths(o,t),o.addScrollEventListeners(o)}function dt(o,t,e){return new ResizeObserver(r=>{for(const s of r){const i=s.contentRect.width,n=s.contentRect.height,c=t.headerViewport.getBoundingClientRect().height,l=t.footerViewport.getBoundingClientRect().height;e.update(a=>{a.viewportWidth=i,a.viewportHeight=n-c-l,a.rawViewportWidth=i,a.rawViewportHeight=n-c-l})}})}function $(o,t){const e=o.gridDom;o.grid,o.gridId$.pipe(h(t)).subscribe(r=>{e.root.id=r},"SET-GRID-ID")}class at{constructor(t){this.resizeVScrollbar=et,this.resizeBody=ot,this.computeTotalRowHeight=tt,this.addScrollEventListeners=st,this.computeColumnWidths=it,this.setCellWidth=m,this.applyColumnWidths=nt,this.adjustViewport=ct,this.initializeLayoutPipeline=lt,this.setUpResizeObserver=dt,this.setGridId=$,this.updateColumnWidths=g,this.store=t._store,this.destroy$=t._destroy$,this.gridDom=t._gridDom,this.grid=t,this.totalRowHeight$=this.store.combineLatest([e=>e.rows,e=>e.rowHeight]).pipe(f(([e,r])=>e.length*r),w()),this.viewportWidth$=this.store.select(e=>e.viewportWidth).pipe(w()),this.resolvedColWidths$=this.store.combineLatest([e=>e.resolvedColumnWidths,e=>e.viewportWidth,e=>e.rawViewportWidth]).pipe(S(([e,r,s])=>r!==s),f(([e])=>e),Q()),this.showVScrollbar$=this.store.combineLatest([e=>e.totalRowHeight,e=>e.rawViewportHeight]).pipe(f(([e,r])=>e>r),w()),this.showHScrollbar$=this.store.combineLatest([e=>e.totalColumnWidth,e=>e.rawViewportWidth]).pipe(f(([e,r])=>e>r),w()),this.adjustedViewportWidth$=this.store.combineLatestAny([this.showVScrollbar$,e=>e.rawViewportWidth]),this.adjustedViewportHeight$=this.store.combineLatestAny([this.showHScrollbar$,e=>e.rawViewportHeight])}initApiSubscriptions(){this.gridId$=this.store.selectKeyed("id",t=>t.id),$(this,this.destroy$)}}class ht{constructor(t){this.resolveColumnWidths=C,this.setColumns=R,this.store=t._store,this.destroy$=t._destroy$,this.gridDom=t._gridDom,this.grid=t}initApiSubscriptions(){this.columns$=this.store.selectKeyed("columns",t=>t.columns),R(this,this.destroy$)}}class pt{constructor(t){this.store=t._store}}function ut(o,t){o.rows$.pipe(h(t)).subscribe(e=>{const r=o.gridDom,s=o.store.getState(),i=s.resolvedColumnWidths;y(r,o.store),g(r,s,i)},"SET-DATA")}class bt{constructor(t){this.store=t._store,this.destroy$=t._destroy$,this.gridDom=t._gridDom,this.grid=t}initApiSubscriptions(){this.rows$=this.store.selectKeyed("rows",t=>t.rows),ut(this,this.destroy$)}}class wt{constructor(t){this.reRenderCells=y,this.store=t._store,this.destroy$=t._destroy$,this.gridDom=t._gridDom,this.grid=t}initApiSubscriptions(){}}class ft{constructor(t){this.grid=t,this.layout=new at(this.grid),this.column=new ht(this.grid),this.row=new pt(this.grid),this.data=new bt(this.grid),this.renderer=new wt(this.grid)}}class mt{constructor(){this.cleanups=[]}}function gt(o,t){o._store.update(e=>{e.columns=t})}function St(o,t){o._store.update(e=>{e.rows=W(t)})}function vt(o,t){o._store.update(e=>{e.id=t})}function Ct(o){return{setGridId:t=>vt(o,t),setData:t=>St(o,t),setColumns:t=>gt(o,t)}}class yt{constructor(t,e){this.store=new Z,this.gridDom=new mt,this.destroy$=new J,this.services=new ft(this),rt(this.store,e),G(this.store,t,this.gridDom),this.resizeObserver=this.services.layout.setUpResizeObserver(this.resizeObserver,this.gridDom,this.store),this.resizeObserver.observe(this.gridDom.grid),this.services.layout.initializeLayoutPipeline(this.services.layout,this.destroy$),this.api=Ct(this),this.services.layout.initApiSubscriptions(),this.services.data.initApiSubscriptions(),this.services.column.initApiSubscriptions(),this.services.renderer.initApiSubscriptions(),console.log("PolyGrid initialized")}destroy(){this.destroy$.next(),this.destroy$.complete();for(const t of this.gridDom.cleanups)t()}get _store(){return this.store}get _destroy$(){return this.destroy$}get _gridDom(){return this.gridDom}}b.PolyGrid=yt,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
|