solid-alive 0.3.54 → 0.3.56
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/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createComponent as e}from"solid-js/web";import{createStore as
|
|
1
|
+
import{createComponent as e}from"solid-js/web";import{createStore as t,produce as l}from"solid-js/store";import{createContext as n,createMemo as o,useContext as s,createRoot as i,getOwner as c,createComponent as r,createEffect as d,untrack as a,onCleanup as u,runWithOwner as v}from"solid-js";const f=n(),h=n();function m(n){const[s,i]=t({}),c=(e,t,n,o)=>i(l(l=>l[e][t]?l[e][t][o](n):"add"===o&&(l[e][t]=new Set([n])))),r=(e,t,n)=>i(l(l=>{const o=l[e].scrollDtvs;"set"===n?(!o&&(l[e].scrollDtvs=new Map),l[e].scrollDtvs.set(t,{left:0,top:0})):(null==o?void 0:o.has(t))&&(o.delete(t),!o.size&&delete l[e].scrollDtvs)})),d=o(e=>{if(!Array.isArray(n.include))return new Set([]);if(null==e?void 0:e.size){for(const t of n.include)e.delete(t);e.size&&(t=e,i(l(e=>{(t=>{var l,n;for(const o of t)e[o]&&(e[o].dispose(),e[o].parentId&&(null===(n=null===(l=e[e[o].parentId])||void 0===l?void 0:l.childIds)||void 0===n||n.delete(o)),e[o].component=null,e[o].owner=null,delete e[o])})(t)})))}var t;const o=new Set(n.include);return o.size&&o.size!==n.include.length&&console.warn("[solid-alive]:include中有值重复"),o});return e(f.Provider,{get value(){return{caches:s,include:d,currentIds:new Set,setCaches:i,setActive:c,aniName:()=>n.transitionEnterName,scrollName:n.scrollContainerName,setDirective:r}},get children(){return n.children}})}let p=!1;const I=(t,n,o)=>((null==o?void 0:o.isolated)||(p=!0),function(m){if(!n)return console.error(`[solid-alive]: id:'${n}' 不正确`),null;const I=s(f);if(!I||!I.include().has(n))return t(m);const S=(null==o?void 0:o.transitionEnterName)||I.aniName(),w=s(h),C=()=>{var e;return!(null==w?void 0:w.id)||(null===(e=I.caches[n])||void 0===e?void 0:e.parentId)===w.id},D=e=>(null==o?void 0:o.isolated)||I.currentIds.add(e);if(I.caches[n])D(n);else{const s=(null==o?void 0:o.isolated)?null:[...I.currentIds].at(-1);s&&I.caches[s]&&I.setCaches(l(e=>{const t=e[s];t.childIds?t.childIds.add(n):t.childIds=new Set([n])})),D(n),I.setCaches({[n]:{id:n,parentId:s,init:null}}),i(o=>I.setCaches(l(l=>{l[n].dispose=o,l[n].owner=c(),l[n].component=e(h.Provider,{value:{id:n},get children(){return r(t,m)}})})))}const z=e=>{var t;const s=I.scrollName;if(!s||(null===(t=I.caches[n].childIds)||void 0===t?void 0:t.size)||(null==o?void 0:o.stopSaveScroll))return;const i=document.querySelector(s);if(!i)return console.warn(`[solid-alive]:未找到为scrollContainerName=${s} 的HTML元素`);"set"===e?requestAnimationFrame(()=>i.scrollTo(I.caches[n].scrollContainer||{left:0,top:0})):I.setCaches(l(e=>{const{scrollLeft:t,scrollTop:l}=i;e[n].scrollContainer={left:t,top:l}}))};let A=null;return d(()=>{var e;const t=I.caches[n];if(!t)return console.warn(`[solid-alive]: include中 id = ${n} 的值不存在`);C()&&(!p||(null==o?void 0:o.isolated)||(null===(e=t.childIds)||void 0===e?void 0:e.size)||(p=!1),t.init||!t.hasEl&&!(()=>{var e,t;if(null===(t=null===(e=I.caches[n])||void 0===e?void 0:e.component)||void 0===t?void 0:t.call(e))return I.setCaches(l(e=>{e[n].init=!0,e[n].hasEl=!0,e[n].owner=c();for(const t of e[n].aOnceSet||[])t();delete e[n].aOnceSet})),!0})()||a(()=>{(()=>{var e,t,l,s;if(S&&!(null==o?void 0:o.disableAnimation)){let o=n;for(;o;){const t=null===(e=I.caches[o])||void 0===e?void 0:e.parentId;if(!t)break;o=t}(s=null===(l=null===(t=I.caches[o])||void 0===t?void 0:t.component)||void 0===l?void 0:l.call(t))instanceof HTMLElement&&(s.classList.add(S),A=()=>{A&&(s.removeEventListener("animationend",A),s.classList.remove(S),A=null)},s.addEventListener("animationend",A))}})(),z("set");const{scrollDtvs:e=[],aSet:l=[]}=t;for(const t of e)t[0].scrollTo(t[1]);for(const e of l)e()}))}),u(()=>{var e;if(!(null==o?void 0:o.isolated)&&(p||!I.caches[n]))return;null==A||A();const t=I.caches[n];if(I.currentIds.has(n))if(t.parentId){I.currentIds.delete(n);const l=e=>{var t;for(const n of e){I.currentIds.delete(n);const e=null===(t=I.caches[n])||void 0===t?void 0:t.childIds;(null==e?void 0:e.size)&&l(e)}};(null===(e=t.childIds)||void 0===e?void 0:e.size)&&l(t.childIds)}else I.currentIds.clear();if(C()){z("save"),I.setCaches(l(e=>{for(const t of e[n].scrollDtvs||[]){const{scrollLeft:e,scrollTop:l}=t[0];t[1].left=e,t[1].top=l}e[n].init=!1}));for(const e of t.dSet||[])e()}}),C()&&v(I.caches[n].owner,()=>I.caches[n].component)}),S=(e,t)=>{if("function"!=typeof t)return;const{id:l}=s(h)||{},n=s(f);l&&n&&(n.setActive(l,e,t,"add"),u(()=>{n.setActive(l,e,t,"delete")}))},w=e=>{S("aSet",e)},C=e=>{S("dSet",e)},D=()=>{const{id:e}=s(h)||{},t=s(f);return{aliveId:e,aliveScrollDelete:l=>e&&(null==t?void 0:t.setDirective(e,l,"delete")),aliveSaveScrollDtv:(l,n)=>{if(!e)return;const o=n&&n();"function"==typeof o&&!1===o(l)||null==t||t.setDirective(e,l,"set")}}},z=e=>{const l=s(f),{id:n}=s(h)||{},[o,i]=t();return n&&(null==l||l.setActive(n,"aOnceSet",()=>{v(c(),()=>{i(s(e))})},"add")),o};export{m as AliveProvider,I as aliveTransfer,w as onActivated,C as onDeactivated,D as useAlive,z as useAliveContext};
|