@lightningtv/solid 3.1.15 → 3.1.16
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/src/core/dom-renderer/domRenderer.js +67 -10
- package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
- package/dist/src/primitives/KeepAlive.d.ts +2 -2
- package/dist/src/primitives/KeepAlive.jsx +48 -30
- package/dist/src/primitives/KeepAlive.jsx.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/core/dom-renderer/domRenderer.ts +79 -11
- package/src/primitives/KeepAlive.tsx +120 -61
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Route, RoutePreloadFuncArgs, RouteProps } from
|
|
1
|
+
import { Route, RoutePreloadFuncArgs, RouteProps } from '@solidjs/router';
|
|
2
2
|
import * as s from 'solid-js';
|
|
3
|
-
import { ElementNode, activeElement } from
|
|
4
|
-
import { chainFunctions } from
|
|
3
|
+
import { ElementNode, activeElement } from '@lightningtv/solid';
|
|
4
|
+
import { chainFunctions } from './utils/chainFunctions.js';
|
|
5
5
|
|
|
6
6
|
export interface KeepAliveElement {
|
|
7
7
|
id: string;
|
|
@@ -16,37 +16,51 @@ export const keepAliveRouteElements = new Map<string, KeepAliveElement>();
|
|
|
16
16
|
|
|
17
17
|
const _storeKeepAlive = (
|
|
18
18
|
map: Map<string, KeepAliveElement>,
|
|
19
|
-
element: KeepAliveElement
|
|
19
|
+
element: KeepAliveElement,
|
|
20
20
|
): KeepAliveElement | undefined => {
|
|
21
21
|
if (map.has(element.id)) {
|
|
22
|
-
console.warn(
|
|
22
|
+
console.warn(
|
|
23
|
+
`[KeepAlive] Element with id "${element.id}" already in cache.`,
|
|
24
|
+
);
|
|
23
25
|
return element;
|
|
24
26
|
}
|
|
25
27
|
map.set(element.id, element);
|
|
26
28
|
return element;
|
|
27
29
|
};
|
|
28
30
|
|
|
29
|
-
export const storeKeepAlive = (element: KeepAliveElement) =>
|
|
30
|
-
|
|
31
|
+
export const storeKeepAlive = (element: KeepAliveElement) =>
|
|
32
|
+
_storeKeepAlive(keepAliveElements, element);
|
|
33
|
+
export const storeKeepAliveRoute = (element: KeepAliveElement) =>
|
|
34
|
+
_storeKeepAlive(keepAliveRouteElements, element);
|
|
31
35
|
|
|
32
|
-
const _removeKeepAlive = (
|
|
36
|
+
const _removeKeepAlive = (
|
|
37
|
+
map: Map<string, KeepAliveElement>,
|
|
38
|
+
id: string,
|
|
39
|
+
): void => {
|
|
33
40
|
const element = map.get(id);
|
|
34
41
|
if (element) {
|
|
42
|
+
(element.children as unknown as ElementNode).destroy();
|
|
35
43
|
element.dispose();
|
|
36
44
|
map.delete(id);
|
|
37
45
|
}
|
|
38
46
|
};
|
|
39
47
|
|
|
40
|
-
export const removeKeepAlive = (id: string): void =>
|
|
41
|
-
|
|
48
|
+
export const removeKeepAlive = (id: string): void =>
|
|
49
|
+
_removeKeepAlive(keepAliveElements, id);
|
|
50
|
+
export const removeKeepAliveRoute = (id: string): void =>
|
|
51
|
+
_removeKeepAlive(keepAliveRouteElements, id);
|
|
42
52
|
|
|
43
53
|
const _clearKeepAlive = (map: Map<string, KeepAliveElement>): void => {
|
|
44
|
-
map.forEach((element) =>
|
|
54
|
+
map.forEach((element) => {
|
|
55
|
+
(element.children as unknown as ElementNode).destroy();
|
|
56
|
+
element.dispose();
|
|
57
|
+
});
|
|
45
58
|
map.clear();
|
|
46
59
|
};
|
|
47
60
|
|
|
48
61
|
export const clearKeepAlive = (): void => _clearKeepAlive(keepAliveElements);
|
|
49
|
-
export const clearKeepAliveRoute = (): void =>
|
|
62
|
+
export const clearKeepAliveRoute = (): void =>
|
|
63
|
+
_clearKeepAlive(keepAliveRouteElements);
|
|
50
64
|
|
|
51
65
|
interface KeepAliveProps {
|
|
52
66
|
id: string;
|
|
@@ -57,8 +71,16 @@ interface KeepAliveProps {
|
|
|
57
71
|
}
|
|
58
72
|
|
|
59
73
|
function wrapChildren(props: s.ParentProps<KeepAliveProps>) {
|
|
60
|
-
const onRemove =
|
|
61
|
-
|
|
74
|
+
const onRemove =
|
|
75
|
+
props.onRemove ||
|
|
76
|
+
((elm: ElementNode) => {
|
|
77
|
+
elm.alpha = 0;
|
|
78
|
+
});
|
|
79
|
+
const onRender =
|
|
80
|
+
props.onRender ||
|
|
81
|
+
((elm: ElementNode) => {
|
|
82
|
+
elm.alpha = 1;
|
|
83
|
+
});
|
|
62
84
|
const transition = props.transition || { alpha: true };
|
|
63
85
|
|
|
64
86
|
return (
|
|
@@ -69,14 +91,23 @@ function wrapChildren(props: s.ParentProps<KeepAliveProps>) {
|
|
|
69
91
|
forwardFocus={0}
|
|
70
92
|
transition={transition}
|
|
71
93
|
{...props}
|
|
72
|
-
/>
|
|
94
|
+
/>
|
|
95
|
+
);
|
|
73
96
|
}
|
|
74
97
|
|
|
75
|
-
const createKeepAliveComponent = (
|
|
98
|
+
const createKeepAliveComponent = (
|
|
99
|
+
map: Map<string, KeepAliveElement>,
|
|
100
|
+
storeFn: (element: KeepAliveElement) => KeepAliveElement | undefined,
|
|
101
|
+
) => {
|
|
76
102
|
return (props: s.ParentProps<KeepAliveProps>) => {
|
|
77
|
-
let existing = map.get(props.id)
|
|
78
|
-
|
|
79
|
-
if (
|
|
103
|
+
let existing = map.get(props.id);
|
|
104
|
+
|
|
105
|
+
if (
|
|
106
|
+
existing &&
|
|
107
|
+
(props.shouldDispose?.(props.id) ||
|
|
108
|
+
(existing.children as unknown as ElementNode)?.destroyed)
|
|
109
|
+
) {
|
|
110
|
+
(existing.children as unknown as ElementNode).destroy();
|
|
80
111
|
existing.dispose();
|
|
81
112
|
map.delete(props.id);
|
|
82
113
|
existing = undefined;
|
|
@@ -94,24 +125,34 @@ const createKeepAliveComponent = (map: Map<string, KeepAliveElement>, storeFn: (
|
|
|
94
125
|
return children;
|
|
95
126
|
});
|
|
96
127
|
} else if (existing && !existing.children) {
|
|
97
|
-
existing.children = s.runWithOwner(existing.owner, () =>
|
|
128
|
+
existing.children = s.runWithOwner(existing.owner, () =>
|
|
129
|
+
wrapChildren(props),
|
|
130
|
+
);
|
|
98
131
|
}
|
|
99
132
|
return existing.children;
|
|
100
133
|
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export const KeepAlive = createKeepAliveComponent(keepAliveElements, storeKeepAlive);
|
|
104
|
-
const KeepAliveRouteInternal = createKeepAliveComponent(keepAliveRouteElements, storeKeepAliveRoute);
|
|
134
|
+
};
|
|
105
135
|
|
|
106
|
-
export const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
136
|
+
export const KeepAlive = createKeepAliveComponent(
|
|
137
|
+
keepAliveElements,
|
|
138
|
+
storeKeepAlive,
|
|
139
|
+
);
|
|
140
|
+
const KeepAliveRouteInternal = createKeepAliveComponent(
|
|
141
|
+
keepAliveRouteElements,
|
|
142
|
+
storeKeepAliveRoute,
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
export const KeepAliveRoute = <S extends string>(
|
|
146
|
+
props: RouteProps<S> & {
|
|
147
|
+
id?: string;
|
|
148
|
+
path: string;
|
|
149
|
+
component: s.Component<RouteProps<S>>;
|
|
150
|
+
shouldDispose?: (key: string) => boolean;
|
|
151
|
+
onRemove?: ElementNode['onRemove'];
|
|
152
|
+
onRender?: ElementNode['onRender'];
|
|
153
|
+
transition?: ElementNode['transition'];
|
|
154
|
+
},
|
|
155
|
+
) => {
|
|
115
156
|
const key = props.id || props.path;
|
|
116
157
|
let savedFocusedElement: ElementNode | undefined;
|
|
117
158
|
|
|
@@ -139,33 +180,51 @@ export const KeepAliveRoute = <S extends string>(props: RouteProps<S> & {
|
|
|
139
180
|
elm.alpha = 1;
|
|
140
181
|
});
|
|
141
182
|
|
|
142
|
-
const preload = props.preload
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
183
|
+
const preload = props.preload
|
|
184
|
+
? (preloadProps: RoutePreloadFuncArgs) => {
|
|
185
|
+
let existing = keepAliveRouteElements.get(key);
|
|
186
|
+
|
|
187
|
+
if (
|
|
188
|
+
existing &&
|
|
189
|
+
(props.shouldDispose?.(key) ||
|
|
190
|
+
(existing.children as unknown as ElementNode)?.destroyed)
|
|
191
|
+
) {
|
|
192
|
+
(existing.children as unknown as ElementNode).destroy();
|
|
193
|
+
existing.dispose();
|
|
194
|
+
keepAliveRouteElements.delete(key);
|
|
195
|
+
existing = undefined;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (!existing) {
|
|
199
|
+
return s.createRoot((dispose) => {
|
|
200
|
+
storeKeepAliveRoute({
|
|
201
|
+
id: key,
|
|
202
|
+
owner: s.getOwner(),
|
|
203
|
+
dispose,
|
|
204
|
+
children: null,
|
|
205
|
+
});
|
|
206
|
+
return props.preload!(preloadProps);
|
|
207
|
+
});
|
|
208
|
+
} else if (existing.children) {
|
|
209
|
+
(existing.children as unknown as ElementNode)?.setFocus();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
: undefined;
|
|
165
213
|
|
|
166
|
-
return (
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
214
|
+
return (
|
|
215
|
+
<Route
|
|
216
|
+
{...props}
|
|
217
|
+
preload={preload}
|
|
218
|
+
component={(childProps) => (
|
|
219
|
+
<KeepAliveRouteInternal
|
|
220
|
+
id={key}
|
|
221
|
+
onRemove={onRemove}
|
|
222
|
+
onRender={onRender}
|
|
223
|
+
transition={props.transition}
|
|
224
|
+
>
|
|
225
|
+
{props.component(childProps)}
|
|
226
|
+
</KeepAliveRouteInternal>
|
|
227
|
+
)}
|
|
228
|
+
/>
|
|
229
|
+
);
|
|
171
230
|
};
|