solid-alive 0.3.2 → 0.3.3

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 CHANGED
@@ -1 +1 @@
1
- import{createComponent as e}from"solid-js/web";import{createContext as t,useContext as n,createRoot as r,getOwner as i,onCleanup as l,runWithOwner as o,createEffect as s,untrack as d}from"solid-js";import{produce as v,createStore as a}from"solid-js/store";const u=Symbol("currentId"),c=Symbol("setActiveCb");var m=t({elements:{},setElements:()=>{},setActiveCb:()=>{},aliveIds:()=>{}});const f=t({[u]:void 0,[c]:()=>{}});var A=(t,n,r)=>e(f.Provider,{value:{[u]:r,[c]:n},get children(){return t()}});function y(e,t,s){return function(d){var a,u,c=n(m);return(null===(a=c.aliveIds())||void 0===a?void 0:a.includes(t))?(c.elements[t]?null===(u=c.elements[t].onActivated)||void 0===u||u.forEach((e=>e())):(c.setElements({[t]:{id:t,subsets:Array.isArray(s)?s:null}}),r((n=>{c.setElements(v((r=>{r[t].dispose=n,r[t].id=t,r[t].owner=i(),r[t].element=A((()=>e(d)),c.setActiveCb,t)})))}))),l((()=>{var e;null===(e=c.elements[t].onDeactivated)||void 0===e||e.forEach((e=>e()))})),c.elements[t].owner&&o(c.elements[t].owner,(()=>c.elements[t].element))):A((()=>e(d)))}}function h(t){const[n,r]=a(),i=e=>{var t,l,o;if(Array.isArray(e))for(var s of e)i(null===(t=n[s])||void 0===t?void 0:t.subsets),null===(o=null===(l=n[s])||void 0===l?void 0:l.dispose)||void 0===o||o.call(l),r({[s]:void 0})};return s((e=>{var n=Array.isArray(t.include)?t.include:[];if(e.length>n.length){var r=new Set(n);i(e.filter((e=>!r.has(e))))}return n}),Array.isArray(t.include)?t.include:[]),e(m.Provider,{value:{elements:n,setElements:r,setActiveCb:(e,t,n,i)=>{r(v((r=>{r[e][t]?r[e][t][i](n):"add"===i&&(r[e][t]=new Set([n]))})))},aliveIds:()=>t.include},get children(){return t.children}})}function p(e,t){d((()=>{var r,i=n(f),o=i[u];o&&(null===(r=i[c])||void 0===r||r.call(i,o,e,t,"add"),"onActivated"===e&&s((()=>{!function(e){"undefined"!=typeof Promise&&"function"==typeof Promise.prototype.then?Promise.resolve().then(e):setTimeout(e)}(t)})),l((()=>{var n;null===(n=i[c])||void 0===n||n.call(i,o,e,t,"delete"),t=null})))}))}function b(e){p("onActivated",e)}function w(e){p("onDeactivated",e)}export{h as AliveProvider,y as aliveTransfer,b as onActivated,w as onDeactivated};
1
+ import{createComponent as e}from"solid-js/web";import{createContext as n,useContext as t,createRoot as r,createEffect as i,onCleanup as o,untrack as l}from"solid-js";import{produce as s,createStore as a}from"solid-js/store";const d=Symbol("currentId"),v=Symbol("setActiveCb"),u=Symbol("parentId");var c=n({elements:{},setElements:()=>{},setActiveCb:()=>{},aliveIds:()=>{},info:{frozen:!1},transitionEnterName:()=>{}});const f=n({[d]:void 0,[v]:()=>{}});var m=(n,t,r,i)=>e(f.Provider,{value:{[d]:i,[v]:r,[u]:t},get children(){return n()}}),p=e=>{for(;"function"==typeof e;)e=e();return e},h=!1;function y(e,n,l){return function(a){var v,u,y,A,b=t(c),E=t(f)[d],I=b.transitionEnterName();if(!(null===(v=b.aliveIds())||void 0===v?void 0:v.includes(n)))return m((()=>e(a)));if(E&&(null===(u=b.elements[n])||void 0===u?void 0:u.parentId)&&b.elements[n].parentId!==E)return null;b.elements[n]?b.info.frozen?(null===(y=b.elements[n].subsets)||void 0===y?void 0:y.some((e=>b.elements[e])))||(b.info.frozen=!1):null===(A=b.elements[n].onActivated)||void 0===A||A.forEach((e=>e())):(b.setElements({[n]:{id:n,subsets:Array.isArray(l)?l:null}}),r((t=>{b.setElements(s((r=>{var i;r[n].dispose=t,r[n].parentId=null===(i=Object.values(b.elements).find((e=>{var t;return null===(t=e.subsets)||void 0===t?void 0:t.includes(n)})))||void 0===i?void 0:i.id,r[n].element=m((()=>e(a)),r[n].parentId,b.setActiveCb,n)})))})));var g=e=>{if(e instanceof HTMLElement&&!h){h=!0,e.classList.add(I);var n=()=>{e.removeEventListener("animationend",n),e.classList.remove(I),h=!1};e.addEventListener("animationend",n)}};return I&&!b.info.frozen&&i((()=>{if(!h){var e=n;do{b.elements[e].parentId||g(p(b.elements[e].element)),e=b.elements[e].parentId}while(e)}})),o((()=>{var e,t;b.info.frozen||null===(t=null===(e=b.elements[n])||void 0===e?void 0:e.onDeactivated)||void 0===t||t.forEach((e=>e()))})),b.elements[n].element}}function A(n){const[t,r]=a();return i((e=>{var i=Array.isArray(n.include)?n.include:[];if(e.length>i.length){var o=new Set(i);(e=>{var n,i;if(Array.isArray(e))for(var o of e)null===(i=null===(n=t[o])||void 0===n?void 0:n.dispose)||void 0===i||i.call(n),r({[o]:void 0})})(e.filter((e=>!o.has(e))))}return i}),Array.isArray(n.include)?n.include:[]),e(c.Provider,{value:{info:{frozen:!1},elements:t,setElements:r,setActiveCb:(e,n,t,i)=>{r(s((r=>{r[e][n]?r[e][n][i](t):"add"===i&&(r[e][n]=new Set([t]))})))},aliveIds:()=>n.include,transitionEnterName:()=>n.transitionEnterName},get children(){return n.children}})}const b=(()=>{let e=[],n=!1,t=()=>{},r=/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,i=()=>{n=!1;var t=e.slice(0);e.length=0;for(let e=0;e<t.length;e++)t[e]()};if("undefined"!=typeof Promise&&"function"==typeof Promise.prototype.then){const e=Promise.resolve();t=()=>{e.then(i),r&&setTimeout((()=>{}))}}else if("undefined"!=typeof MutationObserver){let e=1;const n=new MutationObserver(i),r=document.createTextNode(String(e));n.observe(r,{characterData:!0}),t=()=>{e=(e+1)%2,r.data=String(e)}}else t=()=>{setTimeout(i,0)};return r=>{e.push(r),n||(n=!0,t())}})();function E(e,n){l((()=>{var r,i=t(f),l=i[d];l&&(null===(r=i[v])||void 0===r||r.call(i,l,e,n,"add"),"onActivated"===e&&b(n),o((()=>{var t;null===(t=i[v])||void 0===t||t.call(i,l,e,n,"delete"),n=null})))}))}function I(e){E("onActivated",e)}function g(e){E("onDeactivated",e)}function S(){var e=t(c).info;return()=>e.frozen=!0}export{A as AliveProvider,y as aliveTransfer,b as nextTick,I as onActivated,g as onDeactivated,S as useAliveFrozen};
@@ -1,2 +1,8 @@
1
1
  import { ProveiderProps } from "./types";
2
+ /**
3
+ * @description Alive
4
+ * @param children jsx.element
5
+ * @param {Arrya<string> | null} [include] 哪些路由要缓存, 默认不缓存, ['/','/about',...]
6
+ * @param {string} [transitionEnterName] 动画名称 transitionEnterName="appear"
7
+ */
2
8
  export default function AliveProvider(props: ProveiderProps): import("solid-js").JSX.Element;
@@ -1,2 +1,3 @@
1
1
  export declare function onActivated(cb: () => void): void;
2
2
  export declare function onDeactivated(cb: () => void): void;
3
+ export declare function useAliveFrozen(): () => boolean;
@@ -1,2 +1,8 @@
1
1
  import { JSX } from "solid-js";
2
- export default function aliveTransfer(Component: <T>(props: T) => JSX.Element, id: string, subsets?: Array<string>): <T>(props: T) => JSX.Element;
2
+ /**
3
+ * @description Alive 组件用的 转换函数; aliveTransfer(Comp, ‘/home’)
4
+ * @param { ()=> JSX.Element } Component () => JSX.Element
5
+ * @param { string } id string,自己的id 值,一定要唯一
6
+ * @param { Array<string> } [subsets] [string,...], 子组件的 id值 可不传
7
+ */
8
+ export default function aliveTransfer(Component: <T>(props: T) => JSX.Element, id: string, subsets?: Array<string> | null): <T>(props: T) => JSX.Element;
@@ -1,9 +1,11 @@
1
1
  import { Context } from "./types";
2
2
  export declare const CURRENTID: unique symbol;
3
3
  export declare const SETACTIVECB: unique symbol;
4
+ export declare const PARENTID: unique symbol;
4
5
  declare const _default: import("solid-js").Context<Context>;
5
6
  export default _default;
6
7
  export declare const ChildContext: import("solid-js").Context<{
7
8
  [CURRENTID]: string | undefined;
8
9
  [SETACTIVECB]?: Context["setActiveCb"];
10
+ [PARENTID]?: string;
9
11
  }>;
@@ -1,4 +1,5 @@
1
1
  import aliveTransfer from "./aliveTransfer";
2
2
  import AliveProvider from "./AliveProvider";
3
- import { onActivated, onDeactivated } from "./active";
4
- export { aliveTransfer, AliveProvider, onActivated, onDeactivated };
3
+ import { onActivated, onDeactivated, useAliveFrozen } from "./active";
4
+ import nextTick from "./nextTick";
5
+ export { aliveTransfer, AliveProvider, onActivated, onDeactivated, useAliveFrozen, nextTick };
@@ -1 +1,2 @@
1
- export declare function nextTick(cb: () => void): void;
1
+ declare const nextTick: (cb: () => void) => void;
2
+ export default nextTick;
@@ -1,4 +1,4 @@
1
- import { Owner, JSX } from "solid-js"
1
+ import { Owner, JSX, Accessor } from "solid-js"
2
2
  import { SetStoreFunction } from "solid-js/store"
3
3
 
4
4
  export type EmitType = keyof Emit
@@ -14,21 +14,34 @@ export interface Emit {
14
14
 
15
15
  export interface ProveiderProps {
16
16
  children: JSX.Element
17
- include?: Array<string>
17
+ include?: Array<string>
18
+ transitionEnterName?: string
19
+ }
20
+
21
+ export interface Info {
22
+ frozen: boolean
18
23
  }
19
24
 
20
25
  export interface Element {
21
26
  id: string
22
27
  element: JSX.Element
28
+ subsets?:Array<string> | null
23
29
  dispose?: () => void
24
30
  onActivated?: Set<() => void>
25
31
  onDeactivated?: Set<() => void>
26
- subsets?: Array<string>
32
+ parentId?: string
27
33
  owner?: Owner | null
28
34
  }
29
35
  export interface Context {
30
36
  elements: Record<string, Element>
31
37
  setElements: SetStoreFunction<{}>
32
- aliveIds: ()=> Array<string> | undefined
33
- setActiveCb: (id:string,t: Activate, cb: () => void, t1: 'add'| 'delete') => void
38
+ aliveIds: () => Array<string> | undefined
39
+ setActiveCb: (
40
+ id: string,
41
+ t: Activate,
42
+ cb: () => void,
43
+ t1: "add" | "delete"
44
+ ) => void
45
+ info: { frozen: boolean }
46
+ transitionEnterName: () => string | void
34
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-alive",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "author": "1iuxs",
5
5
  "description": "solid-alive",
6
6
  "type": "module",
@@ -12,9 +12,7 @@
12
12
  "test": "echo \"Error: no test specified\" && exit 1"
13
13
  },
14
14
  "keywords": [
15
- "keep-alive",
16
15
  "solid-js",
17
- "keepalive",
18
16
  "cache",
19
17
  "solid-alive",
20
18
  "solid-keep-alive",
@@ -32,7 +30,7 @@
32
30
  },
33
31
  "license": "ISC",
34
32
  "dependencies": {
35
- "solid-js": "^1.9.3"
33
+ "solid-js": "^1.9.4"
36
34
  },
37
35
  "devDependencies": {
38
36
  "@rollup/plugin-json": "^6.1.0",
@@ -40,13 +38,13 @@
40
38
  "@rollup/plugin-typescript": "^11.1.6",
41
39
  "@types/css-modules": "^1.0.5",
42
40
  "autoprefixer": "^10.4.20",
43
- "rollup": "^4.29.2",
41
+ "rollup": "^4.30.1",
44
42
  "rollup-plugin-cleanup": "^3.2.1",
45
43
  "rollup-plugin-postcss": "^4.0.2",
46
44
  "rollup-plugin-serve": "^1.1.1",
47
45
  "rollup-plugin-terser": "^7.0.2",
48
46
  "rollup-plugin-typescript2": "^0.36.0",
49
47
  "rollup-preset-solid": "^2.0.1",
50
- "typescript": "^5.7.2"
48
+ "typescript": "^5.7.3"
51
49
  }
52
50
  }