@base-framework/organisms
Version:
This will add default organisms to the base framework.
3 lines (2 loc) • 3.41 kB
JavaScript
var M=100;function N(t,e){return typeof t=="function"?t(e)||0:typeof t=="number"?t:e?.clientHeight||M}function m(t,e="id"){if(!t||t.length===0)return null;let l=t[0]?.[e]??null,n=t[t.length-1]?.[e]??null;return l!==null&&n!==null?l>n?l:n:l??n}var F=(t,e="list")=>{let l=e??"list",n=t?.[l]??null;return n||console.warn(`[organisms] No list found on parent under cache name "${l}". Check that the List "cache" prop matches the container "listCache" prop.`),n},y=(t,e,l)=>{l.refresh=()=>S(t,e,l)},b=(t,e,l,n)=>{try{let o=t(e,l);o&&typeof o.catch=="function"&&o.catch(s=>{console.error("[organisms] Fetch callback failed:",s),n()})}catch(o){console.error("[organisms] Fetch callback failed:",o),n()}};function h(t){let e=t===globalThis?globalThis.pageYOffset:t.scrollTop,l=t===globalThis?globalThis.innerHeight:t.clientHeight,n=t===globalThis?globalThis.document.documentElement.scrollHeight:t.scrollHeight;return{scrollTop:e,clientHeight:l,scrollHeight:n}}function I(t,e){let l=N(e,t);return t.scrollTop+t.clientHeight>=t.scrollHeight-l}function R(t,e){let l=N(e,t);return t.scrollTop>=0&&t.scrollTop<=l}var w=(t,e,l)=>I(t,l)&&e.canLoadMore(),A=(t,e,l)=>R(t,l)&&e.canLoadMore(),g=(t,e,l,n=null)=>{t&&t.length>0?(l.append(t),e.update(t.length,n)):(e.hasMoreData=!1,l.updateHasItems())},C=(t,e,l,n=null,o=null,s=null)=>{let i=()=>{typeof s=="function"&&s()};if(t&&t.length>0){let a=0,f=0;if(o){let r=h(o);a=r.scrollHeight,f=r.scrollTop}if(l.prepend(t),e.update(t.length,n),t.length<e.limit&&(e.hasMoreData=!1,l.addTrailingDivider&&l.addTrailingDivider()),!o){i();return}let c=()=>o===globalThis?globalThis.pageYOffset:o.scrollTop,d=()=>{let p=h(o).scrollHeight-a,u=f+p;return o===globalThis?globalThis.scrollTo(0,u):o.scrollTop=u,u};(()=>{let r=d(),p=0,u=()=>{if(r=d(),Math.abs(c()-r)<=2||++p>=6){i();return}requestAnimationFrame(u)};requestAnimationFrame(u)})()}else e.hasMoreData=!1,l.updateHasItems(),l.addTrailingDivider&&l.addTrailingDivider(),i()},v=(t,e,l,n=null)=>{t&&t.length>0&&(l.prepend(t),n!==null&&e.updateNewest(n))},O=(t,e="all")=>(l,n)=>{let o=s=>{let i=[],a=null;s&&(i=s.rows||s.items||[],a=s.lastCursor||null),n(i,a)};t.xhr[e]("",o,l.currentOffset,l.limit,l.lastCursor)},P=(t,e="all")=>(l,n)=>{let o=s=>{let i=[],a=null;s&&(i=s.rows||s.items||[],a=m(i)),n(i,a)};t.xhr[e]("",o,0,l.limit,null,l.newestId)},U=(t,e,l)=>{t(e,(n,o)=>{g(n,e,l,o)})},S=(t,e,l)=>{e.reset(),t(e,(n,o)=>{l.reset(),g(n,e,l,o);let s=m(n);s!==null&&e.updateNewest(s)})},q=(t,e,l)=>{e.canLoadNewer()&&(e.loadingNewer||(e.loadingNewer=!0,b(t,e,(n,o)=>{v(n,e,l,o),e.loadingNewer=!1},()=>{e.loadingNewer=!1})))},Y=(t,e,l,n="down",o="list",s)=>{let i=n==="up"?A:w,a=n==="up",f=s===void 0&&a?d=>Math.round((d.clientHeight||M)*.5):s,c=0;return(d,H,r)=>{let p=h(t);if(!(!r&&a&&performance.now()<c)&&(r||i(p,e,f))){if(e.loading)return;e.loading=!0,b(l,e,(u,T)=>{let x=F(H,o);if(r&&r(),!x){e.loading=!1;return}let D=e.currentOffset===0;if(a?C(u,e,x,T,t,()=>{c=performance.now()+300,e.loading=!1}):(g(u,e,x,T),e.loading=!1),D){let L=m(u);L!==null&&e.updateNewest(L)}},()=>{e.loading=!1})}}},E=(t,e,l,n)=>(o,s,i)=>{let a=h(t);if(i||w(a,e,n)){if(e.loading)return;e.loading=!0,b(l,e,(f,c)=>{i&&i(),g(f,e,s,c),e.loading=!1},()=>{e.loading=!1})}};export{N as a,m as b,F as c,y as d,b as e,h as f,I as g,R as h,w as i,A as j,g as k,C as l,v as m,O as n,P as o,U as p,S as q,q as r,Y as s,E as t};
//# sourceMappingURL=chunk-P5RHTUF4.js.map