You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
paopao-ce/web/dist/assets/v3-infinite-loading-e5c2e8b...

2 lines
2.5 KiB

import{d as L,r as v,S as C,w as $,j as H,I as M,o as x,c as h,z as N,v as O,a as i,U as u,V,M as g,O as y,y as E,W as D,X as R}from"./@vue-e0e89260.js";function T(t,o){const n=t.getBoundingClientRect();if(!o)return n.top>=0&&n.bottom<=window.innerHeight;const e=o.getBoundingClientRect();return n.top>=e.top&&n.bottom<=e.bottom}async function U(t){return await E(),t.value instanceof HTMLElement?t.value:t.value?document.querySelector(t.value):null}function w(t){let o=`0px 0px ${t.distance}px 0px`;t.top&&(o=`${t.distance}px 0px 0px 0px`);const n=new IntersectionObserver(e=>{e[0].isIntersecting&&(t.firstload&&t.emit(),t.firstload=!0)},{root:t.parentEl,rootMargin:o});return n.observe(t.infiniteLoading.value),n}const I=(t,o)=>{const n=t.__vccOpts||t;for(const[e,c]of o)n[e]=c;return n},j={},q=t=>(D("data-v-d3e37633"),t=t(),R(),t),z={class:"container"},W=q(()=>i("div",{class:"spinner"},null,-1)),A=[W];function F(t,o){return x(),h("div",z,A)}const G=I(j,[["render",F],["__scopeId","data-v-d3e37633"]]),J={class:"state-error"},K=L({__name:"InfiniteLoading",props:{top:{type:Boolean,default:!1},target:{},distance:{default:0},identifier:{},firstload:{type:Boolean,default:!0},slots:{}},emits:["infinite"],setup(t,{emit:o}){const n=t;let e=null,c=0;const d=v(null),s=v(""),{top:p,firstload:k,distance:S}=n,{identifier:_,target:B}=C(n),a={infiniteLoading:d,top:p,firstload:k,distance:S,parentEl:null,emit(){c=(a.parentEl||document.documentElement).scrollHeight,m.loading(),o("infinite",m)}},m={loading(){s.value="loading"},async loaded(){s.value="loaded";const r=a.parentEl||document.documentElement;await E(),p&&(r.scrollTop=r.scrollHeight-c),T(d.value,a.parentEl)&&a.emit()},complete(){s.value="complete",e==null||e.disconnect()},error(){s.value="error"}};return $(_,()=>{e==null||e.disconnect(),e=w(a)}),H(async()=>{a.parentEl=await U(B),e=w(a)}),M(()=>{e==null||e.disconnect()}),(r,f)=>(x(),h("div",{ref_key:"infiniteLoading",ref:d,style:{"min-height":"1px"}},[N(i("div",null,[u(r.$slots,"spinner",{},()=>[V(G)],!0)],512),[[O,s.value=="loading"]]),s.value=="complete"?u(r.$slots,"complete",{key:0},()=>{var l;return[i("span",null,g(((l=r.slots)==null?void 0:l.complete)||"No more results!"),1)]},!0):y("",!0),s.value=="error"?u(r.$slots,"error",{key:1,retry:a.emit},()=>{var l;return[i("span",J,[i("span",null,g(((l=r.slots)==null?void 0:l.error)||"Oops something went wrong!"),1),i("button",{class:"retry",onClick:f[0]||(f[0]=(...b)=>a.emit&&a.emit(...b))},"retry")])]},!0):y("",!0)],512))}}),X=I(K,[["__scopeId","data-v-a7077831"]]);export{X as W};