solid-alive 0.3.52 → 0.3.54

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/README.md CHANGED
@@ -242,6 +242,7 @@ export default function C() {
242
242
  4. isolated
243
243
 
244
244
  ```tsx
245
+ // @/layout/Container/index.tsx
245
246
  import Aside from "xxxx"
246
247
 
247
248
  const Aside1 = aliveTransfer(Aside, "aside", {
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{createComponent as e}from"solid-js/web";import{createStore as l,produce as t}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 v,runWithOwner as u}from"solid-js";const f=n(),h=n();function m(n){const[s,i]=l({}),c=(e,l,n,o)=>i(t(t=>t[e][l]?t[e][l][o](n):"add"===o&&(t[e][l]=new Set([n])))),r=(e,l,n)=>i(t(t=>{const o=t[e].scrollDtvs;"set"===n?(!o&&(t[e].scrollDtvs=new Map),t[e].scrollDtvs.set(l,{left:0,top:0})):(null==o?void 0:o.has(l))&&(o.delete(l),!o.size&&delete t[e].scrollDtvs)})),d=o(e=>{if(!Array.isArray(n.include))return new Set([]);if(null==e?void 0:e.size){for(const l of n.include)e.delete(l);e.size&&(l=e,i(t(e=>{(l=>{var t,n;for(const o of l)e[o]&&(e[o].dispose(),e[o].parentId&&(null===(n=null===(t=e[e[o].parentId])||void 0===t?void 0:t.childIds)||void 0===n||n.delete(o)),e[o].component=null,e[o].owner=null,delete e[o])})(l)})))}var l;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=(l,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 l(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(t(e=>{const l=e[s];l.childIds?l.childIds.add(n):l.childIds=new Set([n])})),D(n),I.setCaches({[n]:{id:n,parentId:s,init:null}}),i(o=>I.setCaches(t(t=>{t[n].dispose=o,t[n].owner=c(),t[n].component=e(h.Provider,{value:{id:n},get children(){return r(l,m)}})})))}const z=e=>{var l;const s=I.scrollName;if(!s||(null===(l=I.caches[n].childIds)||void 0===l?void 0:l.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(t(e=>{const{scrollLeft:l,scrollTop:t}=i;e[n].scrollContainer={left:l,top:t}}))};let A=null;return d(()=>{var e;const l=I.caches[n];l?C()&&(p&&!(null==o?void 0:o.isolated)&&(null===(e=l.childIds)||void 0===e?void 0:e.size)&&(p=!1),l.init||!l.hasEl&&!(()=>{var e,l;if(null===(l=null===(e=I.caches[n])||void 0===e?void 0:e.component)||void 0===l?void 0:l.call(e))return I.setCaches(t(e=>{e[n].init=!0,e[n].hasEl=!0,e[n].owner=c();for(const l of e[n].aOnceSet||[])l();delete e[n].aOnceSet})),!0})()||a(()=>{(()=>{var e,l,t,s;if(S&&!(null==o?void 0:o.disableAnimation)){let o=n;for(;o;){const l=null===(e=I.caches[o])||void 0===e?void 0:e.parentId;if(!l)break;o=l}(s=null===(t=null===(l=I.caches[o])||void 0===l?void 0:l.component)||void 0===t?void 0:t.call(l))instanceof HTMLElement&&(s.classList.add(S),A=()=>{A&&(s.removeEventListener("animationend",A),s.classList.remove(S))},s.addEventListener("animationend",A))}})(),z("set");const{scrollDtvs:e,aSet:t}=l;for(const l of e||[])l[0].scrollTo(l[1]);for(const e of t||[])e()})):console.warn(`[solid-alive]: include中 id = ${n} 的值不存在`)}),v(()=>{var e;if(!(null==o?void 0:o.isolated)&&(p||!I.caches[n]))return;null==A||A(),A=null;const l=I.caches[n];if(I.currentIds.has(n))if(l.parentId){I.currentIds.delete(n);const t=e=>{var l;for(const n of e){I.currentIds.delete(n);const e=null===(l=I.caches[n])||void 0===l?void 0:l.childIds;(null==e?void 0:e.size)&&t(e)}};(null===(e=l.childIds)||void 0===e?void 0:e.size)&&t(l.childIds)}else I.currentIds.clear();if(C()){z("save"),I.setCaches(t(e=>{for(const l of e[n].scrollDtvs||[]){const{scrollLeft:e,scrollTop:t}=l[0];l[1].left=e,l[1].top=t}e[n].init=!1}));for(const e of l.dSet||[])e()}}),C()&&u(I.caches[n].owner,()=>I.caches[n].component)}),S=(e,l)=>{if("function"!=typeof l)return;const{id:t}=s(h)||{},n=s(f);t&&n&&(n.setActive(t,e,l,"add"),v(()=>{n.setActive(t,e,l,"delete")}))},w=e=>{S("aSet",e)},C=e=>{S("dSet",e)},D=()=>{const{id:e}=s(h)||{},l=s(f);return{aliveId:e,aliveScrollDelete:t=>e&&(null==l?void 0:l.setDirective(e,t,"delete")),aliveSaveScrollDtv:(t,n)=>{e&&!1!==(null==n?void 0:n()(t))&&(null==l||l.setDirective(e,t,"set"))}}},z=e=>{const t=s(f),{id:n}=s(h)||{},[o,i]=l();return n&&(null==t||t.setActive(n,"aOnceSet",()=>{u(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};
1
+ import{createComponent as e}from"solid-js/web";import{createStore as l,produce as t}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 v,runWithOwner as u}from"solid-js";const f=n(),h=n();function m(n){const[s,i]=l({}),c=(e,l,n,o)=>i(t(t=>t[e][l]?t[e][l][o](n):"add"===o&&(t[e][l]=new Set([n])))),r=(e,l,n)=>i(t(t=>{const o=t[e].scrollDtvs;"set"===n?(!o&&(t[e].scrollDtvs=new Map),t[e].scrollDtvs.set(l,{left:0,top:0})):(null==o?void 0:o.has(l))&&(o.delete(l),!o.size&&delete t[e].scrollDtvs)})),d=o(e=>{if(!Array.isArray(n.include))return new Set([]);if(null==e?void 0:e.size){for(const l of n.include)e.delete(l);e.size&&(l=e,i(t(e=>{(l=>{var t,n;for(const o of l)e[o]&&(e[o].dispose(),e[o].parentId&&(null===(n=null===(t=e[e[o].parentId])||void 0===t?void 0:t.childIds)||void 0===n||n.delete(o)),e[o].component=null,e[o].owner=null,delete e[o])})(l)})))}var l;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=(l,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 l(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(t(e=>{const l=e[s];l.childIds?l.childIds.add(n):l.childIds=new Set([n])})),D(n),I.setCaches({[n]:{id:n,parentId:s,init:null}}),i(o=>I.setCaches(t(t=>{t[n].dispose=o,t[n].owner=c(),t[n].component=e(h.Provider,{value:{id:n},get children(){return r(l,m)}})})))}const z=e=>{var l;const s=I.scrollName;if(!s||(null===(l=I.caches[n].childIds)||void 0===l?void 0:l.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(t(e=>{const{scrollLeft:l,scrollTop:t}=i;e[n].scrollContainer={left:l,top:t}}))};let A=null;return d(()=>{var e;const l=I.caches[n];if(!l)return console.warn(`[solid-alive]: include中 id = ${n} 的值不存在`);C()&&(!p||(null==o?void 0:o.isolated)||(null===(e=l.childIds)||void 0===e?void 0:e.size)||(p=!1),l.init||!l.hasEl&&!(()=>{var e,l;if(null===(l=null===(e=I.caches[n])||void 0===e?void 0:e.component)||void 0===l?void 0:l.call(e))return I.setCaches(t(e=>{e[n].init=!0,e[n].hasEl=!0,e[n].owner=c();for(const l of e[n].aOnceSet||[])l();delete e[n].aOnceSet})),!0})()||a(()=>{(()=>{var e,l,t,s;if(S&&!(null==o?void 0:o.disableAnimation)){let o=n;for(;o;){const l=null===(e=I.caches[o])||void 0===e?void 0:e.parentId;if(!l)break;o=l}(s=null===(t=null===(l=I.caches[o])||void 0===l?void 0:l.component)||void 0===t?void 0:t.call(l))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:t=[]}=l;for(const l of e)l[0].scrollTo(l[1]);for(const e of t)e()}))}),v(()=>{var e;if(!(null==o?void 0:o.isolated)&&(p||!I.caches[n]))return;null==A||A();const l=I.caches[n];if(I.currentIds.has(n))if(l.parentId){I.currentIds.delete(n);const t=e=>{var l;for(const n of e){I.currentIds.delete(n);const e=null===(l=I.caches[n])||void 0===l?void 0:l.childIds;(null==e?void 0:e.size)&&t(e)}};(null===(e=l.childIds)||void 0===e?void 0:e.size)&&t(l.childIds)}else I.currentIds.clear();if(C()){z("save"),I.setCaches(t(e=>{for(const l of e[n].scrollDtvs||[]){const{scrollLeft:e,scrollTop:t}=l[0];l[1].left=e,l[1].top=t}e[n].init=!1}));for(const e of l.dSet||[])e()}}),C()&&u(I.caches[n].owner,()=>I.caches[n].component)}),S=(e,l)=>{if("function"!=typeof l)return;const{id:t}=s(h)||{},n=s(f);t&&n&&(n.setActive(t,e,l,"add"),v(()=>{n.setActive(t,e,l,"delete")}))},w=e=>{S("aSet",e)},C=e=>{S("dSet",e)},D=()=>{const{id:e}=s(h)||{},l=s(f);return{aliveId:e,aliveScrollDelete:t=>e&&(null==l?void 0:l.setDirective(e,t,"delete")),aliveSaveScrollDtv:(t,n)=>{var o;e&&(n&&!1===(null===(o=n())||void 0===o?void 0:o(t))||null==l||l.setDirective(e,t,"set"))}}},z=e=>{const t=s(f),{id:n}=s(h)||{},[o,i]=l();return n&&(null==t||t.setActive(n,"aOnceSet",()=>{u(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};
@@ -7,10 +7,10 @@ import { type Context } from "solid-js";
7
7
  * const { aliveScrollDelete, aliveSaveScrollDtv } = useAlive()
8
8
  *
9
9
  * export function Fn(){
10
- * const divRef
11
- * const del = () => { divRef && aliveScrollDelete(divRef) }
12
- *
13
- * return <div use:aliveSaveScrollDtv >123</div>
10
+ * const divRef
11
+ * const del = () => { divRef && aliveScrollDelete(divRef) }
12
+ *
13
+ * return <div use:aliveSaveScrollDtv >123</div>
14
14
  * }
15
15
  *
16
16
  * ```
@@ -18,6 +18,8 @@ export type AliveProviderProps = {
18
18
  export type Cache = Expand<{
19
19
  /** 唯一值 */
20
20
  id: string
21
+ /** 没有在 include 中的路由 */
22
+ noCache?:boolean
21
23
  /** 表明dom加载过了 */
22
24
  hasEl?: boolean
23
25
  /** 是否有加载过, */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-alive",
3
- "version": "0.3.52",
3
+ "version": "0.3.54",
4
4
  "author": "1iuxs",
5
5
  "description": "solid-alive",
6
6
  "type": "module",