solid-alive 0.3.56 → 0.3.57
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 +14 -11
- package/dist/index.js +1 -1
- package/dist/types/aliveTransfer.d.ts +3 -2
- package/dist/types/context.d.ts +3 -1
- package/dist/types/hooks.d.ts +7 -8
- package/dist/types/types.d.ts +12 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
- stopSaveScroll : 当面组件不用去管滚动条 , 默认 false
|
|
37
37
|
- transitionEnterName : 当面页面的单独动画, 要 css keyframes
|
|
38
38
|
|
|
39
|
-
- **onActivated** :
|
|
40
|
-
- **onDeactivated** :
|
|
41
|
-
- **useAliveContext** :
|
|
42
|
-
- **useAlive**
|
|
39
|
+
- **onActivated** : 激活缓存页面时会触发的函数
|
|
40
|
+
- **onDeactivated** : 离开缓存页面时会触发的函数
|
|
41
|
+
- **useAliveContext** : 父子缓存路由会有 Context 时, 可能会用到的hooks
|
|
42
|
+
- **useAlive**
|
|
43
43
|
- aliveScrollDelete : 删除 保存了的 dom
|
|
44
44
|
- aliveSaveScrollDtv: 指令 保存 dom 滚动条数据
|
|
45
45
|
<!-- - aliveFrozen: 在你重新生成 Route 时 , 要执行这个函数 1iuxs -->
|
|
@@ -160,12 +160,14 @@ export default routes
|
|
|
160
160
|
|
|
161
161
|
```tsx
|
|
162
162
|
// src/view/Home/index.tsx
|
|
163
|
-
import { createContext, useContext } from "solid-js"
|
|
164
|
-
import { onActivated, onDeactivated, useAlive } from "solid-alive"
|
|
165
163
|
|
|
166
|
-
|
|
164
|
+
import { createContext, useContext } from "solid-js"
|
|
165
|
+
import { onActivated, onDeactivated, useAlive, type Setter } from "solid-alive"
|
|
166
|
+
import type { RouteSectionProps } from "@solidjs/router"
|
|
167
|
+
export const DataContext = createContext<{ data: ()=> string, setData: Setter<string> }>()
|
|
167
168
|
|
|
168
|
-
export default function Home(props:
|
|
169
|
+
export default function Home(props: RouteSectionProps) {
|
|
170
|
+
const [data, setData] = createSignal("123")
|
|
169
171
|
//@ts-ignore
|
|
170
172
|
const { aliveSaveScrollDtv, aliveScrollDelete } = useAlive()
|
|
171
173
|
const divRef: HTMLDivElement | null = null
|
|
@@ -183,7 +185,7 @@ export default function Home(props: any) {
|
|
|
183
185
|
}
|
|
184
186
|
|
|
185
187
|
return (
|
|
186
|
-
<ThemeContext.Provider value={{
|
|
188
|
+
<ThemeContext.Provider value={{ data, setData }}>
|
|
187
189
|
<div>
|
|
188
190
|
home <button> 清除路由 </button>
|
|
189
191
|
{props.children}
|
|
@@ -233,7 +235,7 @@ export default function C() {
|
|
|
233
235
|
|
|
234
236
|
return (
|
|
235
237
|
<div>
|
|
236
|
-
ccccccccc <input type="text" /> {data?.value?.()}cccccc
|
|
238
|
+
ccccccccc <input type="text" /> {data?.value?.()}cccccc {data1?.value?.()}
|
|
237
239
|
</div>
|
|
238
240
|
)
|
|
239
241
|
}
|
|
@@ -242,6 +244,7 @@ export default function C() {
|
|
|
242
244
|
4. isolated
|
|
243
245
|
|
|
244
246
|
```tsx
|
|
247
|
+
import type { RouteSectionProps } from "@solidjs/router"
|
|
245
248
|
// @/layout/Container/index.tsx
|
|
246
249
|
import Aside from "xxxx"
|
|
247
250
|
|
|
@@ -251,7 +254,7 @@ const Aside1 = aliveTransfer(Aside, "aside", {
|
|
|
251
254
|
})
|
|
252
255
|
|
|
253
256
|
/** 最外的容器 */
|
|
254
|
-
export function Container(props:
|
|
257
|
+
export function Container(props: RouteSectionProps) {
|
|
255
258
|
return (
|
|
256
259
|
<div class="container">
|
|
257
260
|
{props.children}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createComponent as e}from"solid-js/web";import{createStore as t,produce as
|
|
1
|
+
import{createComponent as e}from"solid-js/web";import{createStore as t,produce as o}from"solid-js/store";import{createContext as n,createMemo as l,useContext as s,createComponent as i,createRoot as c,getOwner as r,createEffect as d,untrack as a,onCleanup as v,runWithOwner as u}from"solid-js";const h=n(),f=n();function m(n){const[s,i]=t({}),c=(e,t,n,l)=>i(o(o=>o[e][t]?o[e][t][l](n):"add"===l&&(o[e][t]=new Set([n])))),r=(e,t,n)=>i(o(o=>{const l=o[e].scrollDtvs;"set"===n?(!l&&(o[e].scrollDtvs=new Map),o[e].scrollDtvs.set(t,{left:0,top:0})):(null==l?void 0:l.has(t))&&(l.delete(t),!l.size&&delete o[e].scrollDtvs)})),d=e=>i(o(t=>{(e=>{var o,n,l,s;for(const i of e)t[i]&&(t[i].parentId&&(null===(n=null===(o=t[t[i].parentId])||void 0===o?void 0:o.childIds)||void 0===n||n.delete(i)),t[i].component=void 0,t[i].scrollDtvs=void 0,t[i].owner=null,t[i].hasEl=!1,t[i].init||(null===(s=(l=t[i]).dispose)||void 0===s||s.call(l),delete t[i]))})(e)})),a=l(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&&d(e)}const t=new Set(n.include);return t.size&&t.size!==n.include.length&&console.warn("[solid-alive]:include中有值重复"),t});return e(h.Provider,{get value(){return{caches:s,include:a,currentIds:new Set,setCaches:i,setActive:c,aniName:()=>n.transitionEnterName,scrollName:n.scrollContainerName,setDirective:r,removeCaches:d}},get children(){return n.children}})}let p=!1;const C=(t,n,l)=>((null==l?void 0:l.isolated)||(p=!0),function(m){const C=s(h);if(!C||!n&&console.error(`[solid-alive]:id='${n}' 不正确`))return i(t,m);const I=(null==l?void 0:l.transitionEnterName)||C.aniName(),S=s(f),w=()=>{var e;return!(null==S?void 0:S.id)||(null===(e=C.caches[n])||void 0===e?void 0:e.parentId)===S.id},D=e=>(null==l?void 0:l.isolated)||C.currentIds.add(e);if(C.caches[n])D(n);else{const s=(null==l?void 0:l.isolated)?null:[...C.currentIds].at(-1);s&&C.caches[s]&&C.setCaches(o(e=>{const t=e[s];t.childIds?t.childIds.add(n):t.childIds=new Set([n])})),D(n);const d=!C.include().has(n);C.setCaches({[n]:Object.assign({id:n,parentId:s,init:null},d&&{noCache:d})}),c(l=>C.setCaches(o(o=>{o[n].dispose=l,o[n].owner=r(),o[n].component=e(f.Provider,{get value(){return Object.assign({id:n},d&&{noCache:d})},get children(){return i(t,m)}})})))}const E=e=>{var t;const s=C.scrollName;if(!s||(null==l?void 0:l.stopSaveScroll)||(null==l?void 0:l.isolated)||(null===(t=C.caches[n].childIds)||void 0===t?void 0:t.size))return;const i=document.querySelector(s);if(!i)return console.warn(`[solid-alive]:未找到为scrollContainerName='${s}' 的HTML元素`);"set"===e?i.scrollTo(C.caches[n].scrollContainer||{left:0,top:0}):C.setCaches(o(e=>{const{scrollLeft:t,scrollTop:o}=i;e[n].scrollContainer={left:t,top:o}}))};let z=null;return d(()=>{var e;const t=C.caches[n];t&&w()&&(!p||(null==l?void 0:l.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=C.caches[n])||void 0===e?void 0:e.component)||void 0===t?void 0:t.call(e))return C.setCaches(o(e=>{e[n].hasEl=!0,e[n].owner=r();for(const t of e[n].aOnceSet||[])t();delete e[n].aOnceSet})),!0})()||a(()=>{C.setCaches(n,"init",!0),(()=>{var e,t,o,s;if(I&&!(null==l?void 0:l.disableAnimation)){let l=n;for(;l;){const t=null===(e=C.caches[l])||void 0===e?void 0:e.parentId;if(!t)break;l=t}(s=null===(o=null===(t=C.caches[l])||void 0===t?void 0:t.component)||void 0===o?void 0:o.call(t))instanceof HTMLElement&&(s.classList.add(I),z=()=>{z&&(s.removeEventListener("animationend",z),s.classList.remove(I),z=null)},s.addEventListener("animationend",z))}})(),E("set");const{scrollDtvs:e=[],aSet:o=[]}=t;for(const t of e)t[0].scrollTo(t[1]);for(const e of o)e()}))}),v(()=>{var e;const t=C.caches[n];if(((null==l?void 0:l.isolated)||!p&&t)&&w()){if(null==z||z(),C.currentIds.has(n))if(t.parentId){const e=t=>{var o;for(const n of t){C.currentIds.delete(n);const t=null===(o=C.caches[n])||void 0===o?void 0:o.childIds;(null==t?void 0:t.size)&&e(t)}};e([n])}else C.currentIds.clear();if(t.noCache)return C.setCaches(n,"init",!1),void C.removeCaches([n]);E("save"),C.setCaches(o(e=>{for(const t of e[n].scrollDtvs||[]){const{scrollLeft:e,scrollTop:o}=t[0];t[1].left=e,t[1].top=o}e[n].init=!1}));for(const e of t.dSet||[])e();t.hasEl||(null===(e=t.dispose)||void 0===e||e.call(t),C.setCaches(o(e=>delete e[n])))}}),w()&&u(C.caches[n].owner,()=>C.caches[n].component)}),I=(e,t)=>{if("function"!=typeof t)return;const{id:o,noCache:n}=s(f)||{},l=s(h);!n&&o&&l&&(l.setActive(o,e,t,"add"),v(()=>{l.setActive(o,e,t,"delete")}))},S=e=>{I("aSet",e)},w=e=>{I("dSet",e)},D=()=>{const{id:e,noCache:t}=s(f)||{},o=s(h);return{aliveId:e,aliveScrollDelete:n=>t||e&&o&&n&&o.setDirective(e,n,"delete"),aliveSaveScrollDtv:(n,l)=>{if(!e||t)return;const s=l&&l();"function"==typeof s&&!1===s(n)||o&&o.setDirective(e,n,"set")}}},E=e=>{const o=s(h),{id:n}=s(f)||{},[l,i]=t();return n&&(null==o||o.setActive(n,"aOnceSet",()=>{u(r(),()=>{i(s(e))})},"add")),l};export{m as AliveProvider,C as aliveTransfer,S as onActivated,w as onDeactivated,D as useAlive,E as useAliveContext};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type JSXElement } from "solid-js";
|
|
2
|
+
import type { RouteProps2 } from "./types";
|
|
2
3
|
/**
|
|
3
4
|
* @description 转换
|
|
4
5
|
* @param {()=> JSXElement} Component 组件
|
|
@@ -10,7 +11,7 @@ import { type JSXElement } from "solid-js";
|
|
|
10
11
|
* const Home1 = aliveTransfer(Home, 'home')
|
|
11
12
|
* ```
|
|
12
13
|
* */
|
|
13
|
-
declare const aliveTransfer: (Component: <T
|
|
14
|
+
declare const aliveTransfer: (Component: <T extends RouteProps2<any>>(props: T) => JSXElement, id: string, params?: {
|
|
14
15
|
/** 成一个独立缓存组件 */
|
|
15
16
|
isolated?: boolean;
|
|
16
17
|
/** 禁用动画 */
|
|
@@ -19,5 +20,5 @@ declare const aliveTransfer: (Component: <T>(props: T) => JSXElement, id: string
|
|
|
19
20
|
transitionEnterName?: string;
|
|
20
21
|
/** 当前组件不去管制 滚动条 */
|
|
21
22
|
stopSaveScroll?: boolean;
|
|
22
|
-
}) => <T extends
|
|
23
|
+
}) => <T extends RouteProps2<any>>(props: T) => import("solid-js").JSX.Element;
|
|
23
24
|
export default aliveTransfer;
|
package/dist/types/context.d.ts
CHANGED
|
@@ -5,10 +5,12 @@ declare const Context: import("solid-js").Context<{
|
|
|
5
5
|
setCaches: import("solid-js/store").SetStoreFunction<import("./types").Caches>;
|
|
6
6
|
setActive: (id: string, t: import("./types").Activate, cb: () => void, t1: import("./types").SetType) => void;
|
|
7
7
|
aniName: () => string | void;
|
|
8
|
-
scrollName
|
|
8
|
+
scrollName?: string | undefined;
|
|
9
9
|
setDirective: (id: string, dom: HTMLElement, t: import("./types").MapType) => void;
|
|
10
|
+
removeCaches: (ids: Set<string> | Array<string>, deep?: boolean) => void;
|
|
10
11
|
} | undefined>;
|
|
11
12
|
declare const ChildContext: import("solid-js").Context<{
|
|
12
13
|
id: string;
|
|
14
|
+
noCache?: boolean;
|
|
13
15
|
} | undefined>;
|
|
14
16
|
export { ChildContext, Context };
|
package/dist/types/hooks.d.ts
CHANGED
|
@@ -3,14 +3,13 @@ import { type Context } from "solid-js";
|
|
|
3
3
|
* @description alive hook
|
|
4
4
|
* @example
|
|
5
5
|
* ```jsx
|
|
6
|
-
* //@ts-ignore
|
|
7
|
-
* const { aliveScrollDelete, aliveSaveScrollDtv } = useAlive()
|
|
8
|
-
*
|
|
9
6
|
* export function Fn(){
|
|
10
|
-
*
|
|
11
|
-
*
|
|
7
|
+
* const divRef
|
|
8
|
+
* //@ts-ignore
|
|
9
|
+
* const { aliveScrollDelete, aliveSaveScrollDtv } = useAlive()
|
|
10
|
+
* const del = () => { divRef && aliveScrollDelete(divRef) }
|
|
12
11
|
*
|
|
13
|
-
*
|
|
12
|
+
* return <div use:aliveSaveScrollDtv={(cn)=>(divRef = cn)} >123</div>
|
|
14
13
|
* }
|
|
15
14
|
*
|
|
16
15
|
* ```
|
|
@@ -25,7 +24,7 @@ export declare const useAlive: () => {
|
|
|
25
24
|
* aliveScrollDelete(divRef)
|
|
26
25
|
* ```
|
|
27
26
|
* */
|
|
28
|
-
aliveScrollDelete: (dom: HTMLElement) => void | ""
|
|
27
|
+
aliveScrollDelete: (dom: HTMLElement) => true | void | "";
|
|
29
28
|
/**
|
|
30
29
|
* @description directive 指令: 保存 dom的滚动条
|
|
31
30
|
* @example
|
|
@@ -33,7 +32,7 @@ export declare const useAlive: () => {
|
|
|
33
32
|
* <div use:aliveSaveScrollDtv >123</div>
|
|
34
33
|
* ```
|
|
35
34
|
* */
|
|
36
|
-
aliveSaveScrollDtv: (el: HTMLElement, v?: () => (v: HTMLElement) => Boolean | void | any) => void;
|
|
35
|
+
aliveSaveScrollDtv: (el: HTMLElement, v?: () => ((v: HTMLElement) => Boolean | void | any) | boolean) => void;
|
|
37
36
|
};
|
|
38
37
|
/**
|
|
39
38
|
* @description alive context
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { JSXElement, Accessor, Owner } from "solid-js"
|
|
2
2
|
import type { SetStoreFunction } from "solid-js/store"
|
|
3
|
-
|
|
3
|
+
import type { RouteSectionProps } from "@solidjs/router"
|
|
4
|
+
|
|
4
5
|
export type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never
|
|
5
6
|
|
|
7
|
+
export type RouteProps2<T> = RouteSectionProps<T>
|
|
8
|
+
|
|
6
9
|
export type AliveProviderProps = {
|
|
7
10
|
/** 子组件 */
|
|
8
11
|
children: JSXElement
|
|
@@ -19,7 +22,7 @@ export type Cache = Expand<{
|
|
|
19
22
|
/** 唯一值 */
|
|
20
23
|
id: string
|
|
21
24
|
/** 没有在 include 中的路由 */
|
|
22
|
-
noCache?:boolean
|
|
25
|
+
noCache?: boolean
|
|
23
26
|
/** 表明dom加载过了 */
|
|
24
27
|
hasEl?: boolean
|
|
25
28
|
/** 是否有加载过, */
|
|
@@ -29,13 +32,13 @@ export type Cache = Expand<{
|
|
|
29
32
|
/** 父级 */
|
|
30
33
|
parentId?: string | null
|
|
31
34
|
/** JSX */
|
|
32
|
-
component?: JSXElement
|
|
35
|
+
component?: JSXElement
|
|
33
36
|
/** 上下文 */
|
|
34
37
|
owner: Owner | null
|
|
35
38
|
/** 销毁函数 */
|
|
36
|
-
dispose
|
|
39
|
+
dispose?: () => void
|
|
37
40
|
/** 只执行一次的 active */
|
|
38
|
-
aOnceSet?: Set<() => void>
|
|
41
|
+
aOnceSet?: Set<() => void>
|
|
39
42
|
/** 激活 */
|
|
40
43
|
aSet?: Set<() => void>
|
|
41
44
|
/** 离开 */
|
|
@@ -47,7 +50,7 @@ export type Cache = Expand<{
|
|
|
47
50
|
}>
|
|
48
51
|
|
|
49
52
|
/** 所有缓存数据 */
|
|
50
|
-
export type Caches =
|
|
53
|
+
export type Caches = Record<string, Cache>
|
|
51
54
|
|
|
52
55
|
/** 共享数据 */
|
|
53
56
|
export type ContextProps = Expand<{
|
|
@@ -64,9 +67,11 @@ export type ContextProps = Expand<{
|
|
|
64
67
|
/** 动画类名, 要 css keyframes 动画*/
|
|
65
68
|
aniName: () => string | void
|
|
66
69
|
/** 滚动容器 名称 */
|
|
67
|
-
scrollName
|
|
70
|
+
scrollName?: string
|
|
68
71
|
/** 指令函数 */
|
|
69
72
|
setDirective: (id: string, dom: HTMLElement, t: MapType) => void
|
|
73
|
+
/** 删除 cache, deep:深度删除 */
|
|
74
|
+
removeCaches: (ids: Set<string> | Array<string>, deep?: boolean) => void
|
|
70
75
|
}>
|
|
71
76
|
|
|
72
77
|
export type Activate = "aSet" | "dSet" | "aOnceSet"
|