test-isc
Version:
An Ionic component similar to Ionic Select, that allows to search items, including async search, group, add, edit, delete items, and much more.
1 lines • 2.28 kB
JavaScript
import{r as t,d as s,w as i,i as h,h as n,e,H as o}from"./p-aa742337.js";import{g as a}from"./p-bdcea876.js";const r=class{constructor(i){t(this,i),this.thrPx=0,this.thrPc=0,this.didFire=!1,this.isBusy=!1,this.isLoading=!1,this.threshold="15%",this.disabled=!1,this.position="bottom",this.onScroll=()=>{const t=this.scrollEl;if(!t||!this.canStart())return 1;const s=this.el.offsetHeight;if(0===s)return 2;const i=t.scrollTop,h=t.offsetHeight,n=0!==this.thrPc?h*this.thrPc:this.thrPx;if(("bottom"===this.position?t.scrollHeight-s-i-n-h:i-s-n)<0){if(!this.didFire)return this.isLoading=!0,this.didFire=!0,this.ionInfinite.emit(),3}else this.didFire=!1;return 4},this.ionInfinite=s(this,"ionInfinite",7)}thresholdChanged(){const t=this.threshold;t.lastIndexOf("%")>-1?(this.thrPx=0,this.thrPc=parseFloat(t)/100):(this.thrPx=parseFloat(t),this.thrPc=0)}disabledChanged(){const t=this.disabled;t&&(this.isLoading=!1,this.isBusy=!1),this.enableScrollEvents(!t)}async connectedCallback(){const t=this.el.closest("ion-content");t?(this.scrollEl=await t.getScrollElement(),this.thresholdChanged(),this.disabledChanged(),"top"===this.position&&i(()=>{this.scrollEl&&(this.scrollEl.scrollTop=this.scrollEl.scrollHeight-this.scrollEl.clientHeight)})):console.error("<ion-infinite-scroll> must be used inside an <ion-content>")}disconnectedCallback(){this.enableScrollEvents(!1),this.scrollEl=void 0}async complete(){const t=this.scrollEl;if(this.isLoading&&t&&(this.isLoading=!1,"top"===this.position)){this.isBusy=!0;const s=t.scrollHeight-t.scrollTop;requestAnimationFrame(()=>{h(()=>{const h=t.scrollHeight-s;requestAnimationFrame(()=>{i(()=>{t.scrollTop=h,this.isBusy=!1})})})})}}canStart(){return!(this.disabled||this.isBusy||!this.scrollEl||this.isLoading)}enableScrollEvents(t){this.scrollEl&&(t?this.scrollEl.addEventListener("scroll",this.onScroll):this.scrollEl.removeEventListener("scroll",this.onScroll))}render(){const t=a(this);return n(o,{class:{[t]:!0,"infinite-scroll-loading":this.isLoading,"infinite-scroll-enabled":!this.disabled}})}get el(){return e(this)}static get watchers(){return{threshold:["thresholdChanged"],disabled:["disabledChanged"]}}};r.style="ion-infinite-scroll{display:none;width:100%}.infinite-scroll-enabled{display:block}";export{r as ion_infinite_scroll}