@sync-in/server
Version:
The secure, open-source platform for file storage, sharing, collaboration, and sync
2 lines (1 loc) • 9.48 kB
JavaScript
import{Cb as _}from"./chunk-O3YLAEVE.js";import{Aa as v,Hb as L,Ib as A,J as w,Kb as S,Lb as b,Mb as C,Qa as E,Ra as O,T as P,Wa as W,Y as M,_ as R,ab as D,f as H,ja as u,p as y,vb as I,wb as B,xa as x,xb as z}from"./chunk-D55YR5X7.js";var V=["content"],N=["shim"],Q=["*"],X=(()=>{let r=class r{constructor(){this.isScrollBottom=new E,this.isScrollTop=new E,this.resizeOffset=130,this.galleryMode=!1,this.selectedChat=null,this.items=[],this.childHeight=35,this.bufferAmount=0,this.viewPortItems=[],this.element=u(v),this.renderer=u(W),this.ngZone=u(O),this.layout=u(_),this.subscriptions=[],this.scrollbarWidth=0,this._scrollChat=new H,this.scrollChat=this._scrollChat.asObservable().pipe(w(50)),this.startupLoop=!0,this.scrollTimer=null,this.lastScrollHeight=-1,this.lastTopPadding=-1,this.toggleLeftSidebar=this.layout.toggleLeftSideBar.pipe(M(1),R(t=>y(t).pipe(P({count:30,delay:10})))),this.tableScrollHovering=()=>{clearTimeout(this.scrollTimer),this.contentElementRef.nativeElement.classList.contains("table-disable-hover")||this.renderer.addClass(this.contentElementRef.nativeElement,"table-disable-hover"),this.scrollTimer=setTimeout(()=>{this.renderer.removeClass(this.contentElementRef.nativeElement,"table-disable-hover")},200),this.refresh()},this.refreshWithDimensions=()=>{this.resizeOffsetHeight(),this.refresh(!0)},this.refreshWithoutDimensions=()=>{this.refresh()},this.refreshChatWithoutDimensions=()=>{this.chatIsScrolledToTop()&&!this.selectedChat.allHistoryLoaded?this.element.nativeElement.scrollTo({left:0,top:this.element.nativeElement.scrollTop,behavior:"auto"}):(this.refreshWithoutDimensions(),this._scrollChat.next())},this.refreshChatWithDimensions=()=>{this.resizeOffsetHeight(),this.refresh(!0),this.selectedChat.isScrolledToBottom?this.scrollInto(-2):this._scrollChat.next()}}ngOnInit(){this.resizeOffsetHeight(!0),this.addParentEventHandlers(),this.selectedChat?(this.childHeight=1,this.subscriptions.push(this.scrollChat.subscribe(()=>this.checkScrollChat()))):this.galleryMode||this.subscriptions.push(this.toggleLeftSidebar.subscribe(()=>this.resizeTableHeader()))}ngOnDestroy(){this.eventScrollHandler&&(this.eventScrollHandler(),this.eventScrollHandler=void 0),this.subscriptions.forEach(t=>t.unsubscribe())}ngOnChanges(t){if(this.previousStart=void 0,this.previousEnd=void 0,this.galleryMode)this.startupLoop=!0;else{let e=t.items||void 0;(t.items!==void 0&&e.previousValue===void 0||e.previousValue!==void 0&&e.previousValue.length===0)&&(this.startupLoop=!0)}this.refresh(!0),this.checkChangesOnChat(t)}refresh(t=!1){this.ngZone.runOutsideAngular(()=>{(t||!this.dimensionsView)&&this.calculateDimensions(),requestAnimationFrame(()=>this.calculateItems())}),this.resizeTableHeader()}scrollInto(t){if(t===-1){this.element.nativeElement.scrollTo({left:0,top:0,behavior:"auto"});return}else if(t===-2){this.element.nativeElement.scrollTo({left:0,top:this.element.nativeElement.scrollHeight,behavior:"smooth"});return}else if(t===0){this.refresh();return}let e=(this.items||[]).indexOf(t);if(e<0||e>=(this.items||[]).length)return;let i=this.dimensionsView,l=Math.floor(e/i.itemsPerRow)*i.childHeight-i.childHeight*Math.min(e,this.bufferAmount);this.element.nativeElement.scrollTo({left:0,top:l,behavior:"smooth"}),this.refresh()}checkChangesOnChat(t){this.selectedChat&&(t.selectedChat?(this.renderer.setStyle(this.element.nativeElement,"visibility","hidden"),setTimeout(()=>{this.selectedChat.lastScrollPosition===null&&this.saveChatScrollPosition(this.element.nativeElement.scrollHeight),this.element.nativeElement.scrollTo({left:0,top:this.selectedChat.lastScrollPosition,behavior:"auto"}),this.checkScrollChat(),this.renderer.setStyle(this.element.nativeElement,"visibility","visible")},50)):this.chatIsScrolledToBottom()?this.restoreBottomScrollChat():this.chatIsScrolledToTop()&&this.restoreTopScrollChat())}checkScrollChat(){let t=this.chatIsScrolledToBottom(),e=this.chatIsScrolledToTop();e?this.saveChatScrollPosition(this.element.nativeElement.scrollHeight-this.element.nativeElement.scrollTop):t?this.saveChatScrollPosition(this.element.nativeElement.scrollHeight):this.saveChatScrollPosition(),this.ngZone.run(()=>{this.isScrollBottom.next(t),this.isScrollTop.next(e)})}saveChatScrollPosition(t=null){this.selectedChat.lastScrollPosition=t||this.element.nativeElement.scrollTop}chatIsScrolledToBottom(){return Math.ceil(this.element.nativeElement.clientHeight/10)*10===Math.ceil((this.element.nativeElement.scrollHeight-this.element.nativeElement.scrollTop)/10)*10}chatIsScrolledToTop(){return this.element.nativeElement.scrollTop<=300}restoreBottomScrollChat(){setTimeout(()=>{this.element.nativeElement.scrollTo({left:0,top:this.element.nativeElement.scrollHeight,behavior:"smooth"})},50)}restoreTopScrollChat(){setTimeout(()=>{this.element.nativeElement.scrollTop=this.element.nativeElement.scrollHeight-this.selectedChat.lastScrollPosition},50)}resizeOffsetHeight(t=!1){let e=window.innerHeight-this.resizeOffset;(t||this.element.nativeElement.offsetHeight!==e)&&this.renderer.setStyle(this.element.nativeElement,"height",`${e-1}px`)}resizeTableHeader(){!this.selectedChat&&!this.galleryMode&&this.element.nativeElement.previousElementSibling&&this.element.nativeElement.previousElementSibling.classList.contains("app-table")&&setTimeout(()=>this.renderer.setStyle(this.element.nativeElement.previousElementSibling,"width",`${this.element.nativeElement.clientWidth}px`),50)}addParentEventHandlers(){this.ngZone.runOutsideAngular(()=>{this.galleryMode?this.eventScrollHandler=this.renderer.listen(this.element.nativeElement,"scroll",this.refreshWithoutDimensions):this.selectedChat?this.eventScrollHandler=this.renderer.listen(this.element.nativeElement,"scroll",this.refreshChatWithoutDimensions):this.eventScrollHandler=this.renderer.listen(this.element.nativeElement,"scroll",this.tableScrollHovering),this.selectedChat?this.subscriptions.push(this.layout.resizeEvent.subscribe(()=>this.refreshChatWithDimensions())):this.subscriptions.push(this.layout.resizeEvent.subscribe(()=>this.refreshWithDimensions()))})}countItemsPerRow(){if(this.galleryMode){let t,e,i=this.contentElementRef.nativeElement.children;for(i[0]&&(i=i[0].children),e=0;e<i.length&&!(t!==void 0&&t!==i[e].offsetTop);e++)t=i[e].offsetTop;return e}else return 1}calculateDimensions(){let t=this.element.nativeElement,e=t.offsetWidth-t.clientWidth;this.scrollbarWidth!=e&&(this.resizeTableHeader(),this.scrollbarWidth=e);let l=(this.items||[]).length,h=t.clientWidth-this.scrollbarWidth,p=t.clientHeight,a;if(this.childWidth===void 0||this.childHeight===void 0){let T=this.contentElementRef.nativeElement;a=T.children[0]?T.children[0].getBoundingClientRect():{width:h,height:p}}let s=this.childWidth||a.width,c=this.childHeight||a.height,o=this.countItemsPerRow(),m=Math.max(1,Math.floor(h/s));this.galleryMode&&o===0?o=m:o=Math.max(1,o);let n=Math.max(1,Math.floor(p/c)),d=t.scrollTop,k=Math.max(0,d),f=c*Math.ceil(l/o);n===1&&Math.floor(k/f*l)+m>=l&&(o=m),f!==this.lastScrollHeight&&(this.renderer.setStyle(this.shimElementRef.nativeElement,"height",`${f}px`),this.lastScrollHeight=f),this.dimensionsView={itemCount:l,viewWidth:h,viewHeight:p,childWidth:s,childHeight:c,itemsPerRow:o,itemsPerCol:n,itemsPerRowByCalc:m,scrollHeight:f}}calculateItems(){let t=this.element.nativeElement,e=this.dimensionsView,i=this.items||[],l=this.galleryMode?this.bufferAmount*e.itemsPerRowByCalc:this.bufferAmount,h=t.scrollTop;h>e.scrollHeight&&(h=e.scrollHeight);let a=Math.max(0,h)/e.scrollHeight*e.itemCount/e.itemsPerRow,s=Math.min(e.itemCount,Math.ceil(a)*e.itemsPerRow+e.itemsPerRow*(e.itemsPerCol+1)),c=s,o=s%e.itemsPerRow;o&&(c=s+e.itemsPerRow-o);let m=Math.max(0,c-e.itemsPerCol*e.itemsPerRow-e.itemsPerRow),n=Math.min(m,Math.floor(a)*e.itemsPerRow),d=i==null||i.length===0?0:e.childHeight*Math.ceil(n/e.itemsPerRow)-e.childHeight*Math.min(n,this.bufferAmount);d!==this.lastTopPadding&&(this.renderer.setStyle(this.contentElementRef.nativeElement,"transform",`translateY(${d}px)`),this.renderer.setStyle(this.contentElementRef.nativeElement,"webkitTransform",`translateY(${d}px)`),this.lastTopPadding=d),n=isNaN(n)?-1:n,s=isNaN(s)?-1:s,n-=l,n=Math.max(0,n),s+=l,s=Math.min(i.length,s),n!==this.previousStart||s!==this.previousEnd?(this.ngZone.run(()=>{this.viewPortItems=i.slice(n,s>=0?s:0)}),this.previousStart=n,this.previousEnd=s,this.startupLoop===!0&&this.refresh()):this.startupLoop===!0&&(this.startupLoop=!1,this.refresh(!0))}};r.\u0275fac=function(e){return new(e||r)},r.\u0275cmp=D({type:r,selectors:[["app-virtual-scroll"]],viewQuery:function(e,i){if(e&1&&(S(V,7,v),S(N,7,v)),e&2){let l;b(l=C())&&(i.contentElementRef=l.first),b(l=C())&&(i.shimElementRef=l.first)}},inputs:{resizeOffset:"resizeOffset",galleryMode:"galleryMode",selectedChat:"selectedChat",items:"items",childHeight:"childHeight",childWidth:"childWidth",bufferAmount:"bufferAmount"},outputs:{isScrollBottom:"isScrollBottom",isScrollTop:"isScrollTop"},features:[x],ngContentSelectors:Q,decls:5,vars:0,consts:[["shim",""],["content",""],[1,"total-padding"],[1,"scrollable-content"]],template:function(e,i){e&1&&(L(),z(0,"div",2,0),I(2,"div",3,1),A(4),B())},styles:["[_nghost-%COMP%]{display:block;overflow-x:hidden;overflow-y:auto;position:relative;scrollbar-width:thin}.scrollable-content[_ngcontent-%COMP%]{top:0;left:0;width:100%;position:absolute;will-change:transform}.total-padding[_ngcontent-%COMP%]{width:1px;opacity:0}"],changeDetection:0});let g=r;return g})();export{X as a};