@solidtv/solid 1.0.0
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/LICENSE +202 -0
- package/NOTICE +7 -0
- package/README.md +95 -0
- package/dist/jsx-runtime.d.ts +14 -0
- package/dist/src/activeElement.d.ts +2 -0
- package/dist/src/activeElement.js +3 -0
- package/dist/src/activeElement.js.map +1 -0
- package/dist/src/core/config.d.ts +51 -0
- package/dist/src/core/config.js +37 -0
- package/dist/src/core/config.js.map +1 -0
- package/dist/src/core/dom-renderer/domRenderer.d.ts +138 -0
- package/dist/src/core/dom-renderer/domRenderer.js +1844 -0
- package/dist/src/core/dom-renderer/domRenderer.js.map +1 -0
- package/dist/src/core/dom-renderer/domRendererTypes.d.ts +110 -0
- package/dist/src/core/dom-renderer/domRendererTypes.js +2 -0
- package/dist/src/core/dom-renderer/domRendererTypes.js.map +1 -0
- package/dist/src/core/dom-renderer/domRendererUtils.d.ts +23 -0
- package/dist/src/core/dom-renderer/domRendererUtils.js +232 -0
- package/dist/src/core/dom-renderer/domRendererUtils.js.map +1 -0
- package/dist/src/core/elementNode.d.ts +508 -0
- package/dist/src/core/elementNode.js +928 -0
- package/dist/src/core/elementNode.js.map +1 -0
- package/dist/src/core/flex.d.ts +2 -0
- package/dist/src/core/flex.js +284 -0
- package/dist/src/core/flex.js.map +1 -0
- package/dist/src/core/flexLayout.d.ts +2 -0
- package/dist/src/core/flexLayout.js +360 -0
- package/dist/src/core/flexLayout.js.map +1 -0
- package/dist/src/core/focusKeyTypes.d.ts +42 -0
- package/dist/src/core/focusKeyTypes.js +2 -0
- package/dist/src/core/focusKeyTypes.js.map +1 -0
- package/dist/src/core/focusManager.d.ts +13 -0
- package/dist/src/core/focusManager.js +270 -0
- package/dist/src/core/focusManager.js.map +1 -0
- package/dist/src/core/index.d.ts +14 -0
- package/dist/src/core/index.js +11 -0
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/core/intrinsicTypes.d.ts +106 -0
- package/dist/src/core/intrinsicTypes.js +2 -0
- package/dist/src/core/intrinsicTypes.js.map +1 -0
- package/dist/src/core/lightningInit.d.ts +9 -0
- package/dist/src/core/lightningInit.js +34 -0
- package/dist/src/core/lightningInit.js.map +1 -0
- package/dist/src/core/nodeTypes.d.ts +6 -0
- package/dist/src/core/nodeTypes.js +6 -0
- package/dist/src/core/nodeTypes.js.map +1 -0
- package/dist/src/core/shaders.d.ts +52 -0
- package/dist/src/core/shaders.js +86 -0
- package/dist/src/core/shaders.js.map +1 -0
- package/dist/src/core/states.d.ts +12 -0
- package/dist/src/core/states.js +84 -0
- package/dist/src/core/states.js.map +1 -0
- package/dist/src/core/utils.d.ts +39 -0
- package/dist/src/core/utils.js +164 -0
- package/dist/src/core/utils.js.map +1 -0
- package/dist/src/devtools/index.d.ts +6 -0
- package/dist/src/devtools/index.js +65 -0
- package/dist/src/devtools/index.js.map +1 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.js +7 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/primitives/Column.d.ts +3 -0
- package/dist/src/primitives/Column.jsx +25 -0
- package/dist/src/primitives/Column.jsx.map +1 -0
- package/dist/src/primitives/FPSCounter.d.ts +4 -0
- package/dist/src/primitives/FPSCounter.jsx +188 -0
- package/dist/src/primitives/FPSCounter.jsx.map +1 -0
- package/dist/src/primitives/FadeInOut.d.ts +18 -0
- package/dist/src/primitives/FadeInOut.jsx +39 -0
- package/dist/src/primitives/FadeInOut.jsx.map +1 -0
- package/dist/src/primitives/Grid.d.ts +23 -0
- package/dist/src/primitives/Grid.jsx +100 -0
- package/dist/src/primitives/Grid.jsx.map +1 -0
- package/dist/src/primitives/Image.d.ts +8 -0
- package/dist/src/primitives/Image.jsx +42 -0
- package/dist/src/primitives/Image.jsx.map +1 -0
- package/dist/src/primitives/KeepAlive.d.ts +42 -0
- package/dist/src/primitives/KeepAlive.jsx +160 -0
- package/dist/src/primitives/KeepAlive.jsx.map +1 -0
- package/dist/src/primitives/Lazy.d.ts +15 -0
- package/dist/src/primitives/Lazy.jsx +95 -0
- package/dist/src/primitives/Lazy.jsx.map +1 -0
- package/dist/src/primitives/LazyImport.d.ts +8 -0
- package/dist/src/primitives/LazyImport.js +40 -0
- package/dist/src/primitives/LazyImport.js.map +1 -0
- package/dist/src/primitives/Marquee.d.ts +64 -0
- package/dist/src/primitives/Marquee.jsx +86 -0
- package/dist/src/primitives/Marquee.jsx.map +1 -0
- package/dist/src/primitives/Preserve.d.ts +4 -0
- package/dist/src/primitives/Preserve.jsx +11 -0
- package/dist/src/primitives/Preserve.jsx.map +1 -0
- package/dist/src/primitives/Row.d.ts +3 -0
- package/dist/src/primitives/Row.jsx +24 -0
- package/dist/src/primitives/Row.jsx.map +1 -0
- package/dist/src/primitives/Suspense.d.ts +22 -0
- package/dist/src/primitives/Suspense.jsx +33 -0
- package/dist/src/primitives/Suspense.jsx.map +1 -0
- package/dist/src/primitives/Virtual.d.ts +18 -0
- package/dist/src/primitives/Virtual.jsx +495 -0
- package/dist/src/primitives/Virtual.jsx.map +1 -0
- package/dist/src/primitives/VirtualGrid.d.ts +13 -0
- package/dist/src/primitives/VirtualGrid.jsx +160 -0
- package/dist/src/primitives/VirtualGrid.jsx.map +1 -0
- package/dist/src/primitives/Visible.d.ts +6 -0
- package/dist/src/primitives/Visible.jsx +37 -0
- package/dist/src/primitives/Visible.jsx.map +1 -0
- package/dist/src/primitives/announcer/announcer.d.ts +40 -0
- package/dist/src/primitives/announcer/announcer.js +125 -0
- package/dist/src/primitives/announcer/announcer.js.map +1 -0
- package/dist/src/primitives/announcer/index.d.ts +6 -0
- package/dist/src/primitives/announcer/index.js +15 -0
- package/dist/src/primitives/announcer/index.js.map +1 -0
- package/dist/src/primitives/announcer/speech.d.ts +10 -0
- package/dist/src/primitives/announcer/speech.js +281 -0
- package/dist/src/primitives/announcer/speech.js.map +1 -0
- package/dist/src/primitives/borderBox.d.ts +8 -0
- package/dist/src/primitives/borderBox.jsx +47 -0
- package/dist/src/primitives/borderBox.jsx.map +1 -0
- package/dist/src/primitives/createFocusStack.d.ts +31 -0
- package/dist/src/primitives/createFocusStack.jsx +62 -0
- package/dist/src/primitives/createFocusStack.jsx.map +1 -0
- package/dist/src/primitives/createInfiniteItems.d.ts +27 -0
- package/dist/src/primitives/createInfiniteItems.js +46 -0
- package/dist/src/primitives/createInfiniteItems.js.map +1 -0
- package/dist/src/primitives/createTag.d.ts +8 -0
- package/dist/src/primitives/createTag.jsx +20 -0
- package/dist/src/primitives/createTag.jsx.map +1 -0
- package/dist/src/primitives/index.d.ts +32 -0
- package/dist/src/primitives/index.js +31 -0
- package/dist/src/primitives/index.js.map +1 -0
- package/dist/src/primitives/portal.d.ts +5 -0
- package/dist/src/primitives/portal.jsx +21 -0
- package/dist/src/primitives/portal.jsx.map +1 -0
- package/dist/src/primitives/router.d.ts +20 -0
- package/dist/src/primitives/router.js +90 -0
- package/dist/src/primitives/router.js.map +1 -0
- package/dist/src/primitives/types.d.ts +79 -0
- package/dist/src/primitives/types.js +2 -0
- package/dist/src/primitives/types.js.map +1 -0
- package/dist/src/primitives/useFocusManager.d.ts +5 -0
- package/dist/src/primitives/useFocusManager.js +21 -0
- package/dist/src/primitives/useFocusManager.js.map +1 -0
- package/dist/src/primitives/useHold.d.ts +27 -0
- package/dist/src/primitives/useHold.js +54 -0
- package/dist/src/primitives/useHold.js.map +1 -0
- package/dist/src/primitives/useMouse.d.ts +18 -0
- package/dist/src/primitives/useMouse.js +240 -0
- package/dist/src/primitives/useMouse.js.map +1 -0
- package/dist/src/primitives/utils/chainFunctions.d.ts +30 -0
- package/dist/src/primitives/utils/chainFunctions.js +32 -0
- package/dist/src/primitives/utils/chainFunctions.js.map +1 -0
- package/dist/src/primitives/utils/createBlurredImage.d.ts +56 -0
- package/dist/src/primitives/utils/createBlurredImage.js +223 -0
- package/dist/src/primitives/utils/createBlurredImage.js.map +1 -0
- package/dist/src/primitives/utils/createSpriteMap.d.ts +9 -0
- package/dist/src/primitives/utils/createSpriteMap.js +18 -0
- package/dist/src/primitives/utils/createSpriteMap.js.map +1 -0
- package/dist/src/primitives/utils/handleNavigation.d.ts +103 -0
- package/dist/src/primitives/utils/handleNavigation.js +300 -0
- package/dist/src/primitives/utils/handleNavigation.js.map +1 -0
- package/dist/src/primitives/utils/withScrolling.d.ts +22 -0
- package/dist/src/primitives/utils/withScrolling.js +186 -0
- package/dist/src/primitives/utils/withScrolling.js.map +1 -0
- package/dist/src/render.d.ts +28 -0
- package/dist/src/render.js +107 -0
- package/dist/src/render.js.map +1 -0
- package/dist/src/solidOpts.d.ts +15 -0
- package/dist/src/solidOpts.js +93 -0
- package/dist/src/solidOpts.js.map +1 -0
- package/dist/src/types.d.ts +11 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils.d.ts +19 -0
- package/dist/src/utils.js +94 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/docs/AI_CODING_GUIDELINES.md +108 -0
- package/docs/README.md +35 -0
- package/jsx-runtime.d.ts +14 -0
- package/package.json +125 -0
- package/src/activeElement.ts +5 -0
- package/src/core/config.ts +101 -0
- package/src/core/dom-renderer/domRenderer.ts +2066 -0
- package/src/core/dom-renderer/domRendererTypes.ts +148 -0
- package/src/core/dom-renderer/domRendererUtils.ts +292 -0
- package/src/core/elementNode.ts +1623 -0
- package/src/core/flex.ts +331 -0
- package/src/core/flexLayout.ts +414 -0
- package/src/core/focusKeyTypes.ts +90 -0
- package/src/core/focusManager.ts +374 -0
- package/src/core/index.ts +15 -0
- package/src/core/intrinsicTypes.ts +216 -0
- package/src/core/lightningInit.ts +45 -0
- package/src/core/nodeTypes.ts +6 -0
- package/src/core/shaders.ts +187 -0
- package/src/core/states.ts +91 -0
- package/src/core/utils.ts +222 -0
- package/src/devtools/index.ts +77 -0
- package/src/index.ts +18 -0
- package/src/primitives/Column.tsx +59 -0
- package/src/primitives/FPSCounter.tsx +209 -0
- package/src/primitives/FadeInOut.tsx +58 -0
- package/src/primitives/Grid.tsx +151 -0
- package/src/primitives/Image.tsx +56 -0
- package/src/primitives/KeepAlive.tsx +268 -0
- package/src/primitives/Lazy.tsx +128 -0
- package/src/primitives/LazyImport.ts +53 -0
- package/src/primitives/Marquee.tsx +149 -0
- package/src/primitives/Preserve.tsx +18 -0
- package/src/primitives/Row.tsx +58 -0
- package/src/primitives/Suspense.tsx +39 -0
- package/src/primitives/Virtual.tsx +602 -0
- package/src/primitives/VirtualGrid.tsx +220 -0
- package/src/primitives/Visible.tsx +59 -0
- package/src/primitives/announcer/announcer.ts +198 -0
- package/src/primitives/announcer/index.ts +20 -0
- package/src/primitives/announcer/speech.ts +334 -0
- package/src/primitives/borderBox.tsx +69 -0
- package/src/primitives/createFocusStack.tsx +79 -0
- package/src/primitives/createInfiniteItems.ts +66 -0
- package/src/primitives/createTag.tsx +33 -0
- package/src/primitives/index.ts +37 -0
- package/src/primitives/portal.tsx +25 -0
- package/src/primitives/router.ts +147 -0
- package/src/primitives/types.ts +109 -0
- package/src/primitives/useFocusManager.ts +47 -0
- package/src/primitives/useHold.ts +69 -0
- package/src/primitives/useMouse.ts +417 -0
- package/src/primitives/utils/chainFunctions.ts +60 -0
- package/src/primitives/utils/createBlurredImage.ts +366 -0
- package/src/primitives/utils/createSpriteMap.ts +32 -0
- package/src/primitives/utils/handleNavigation.ts +373 -0
- package/src/primitives/utils/withScrolling.ts +238 -0
- package/src/render.ts +164 -0
- package/src/solidOpts.ts +107 -0
- package/src/types.ts +22 -0
- package/src/utils.ts +129 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { Route, RoutePreloadFuncArgs, RouteProps } from '@solidjs/router';
|
|
2
|
+
import * as s from 'solid-js';
|
|
3
|
+
import { ElementNode, activeElement } from '@solidtv/solid';
|
|
4
|
+
import { chainFunctions } from './utils/chainFunctions.js';
|
|
5
|
+
|
|
6
|
+
export interface KeepAliveElement {
|
|
7
|
+
id: string;
|
|
8
|
+
owner: s.Owner | null;
|
|
9
|
+
children: s.JSX.Element;
|
|
10
|
+
routeSignal?: s.Signal<unknown>;
|
|
11
|
+
isAlive?: s.Accessor<boolean>;
|
|
12
|
+
setIsAlive?: (v: boolean) => void;
|
|
13
|
+
dispose: () => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const keepAliveElements = new Map<string, KeepAliveElement>();
|
|
17
|
+
export const keepAliveRouteElements = new Map<string, KeepAliveElement>();
|
|
18
|
+
|
|
19
|
+
const _storeKeepAlive = (
|
|
20
|
+
map: Map<string, KeepAliveElement>,
|
|
21
|
+
element: KeepAliveElement,
|
|
22
|
+
): KeepAliveElement | undefined => {
|
|
23
|
+
const existing = map.get(element.id);
|
|
24
|
+
if (existing) {
|
|
25
|
+
Object.assign(existing, element);
|
|
26
|
+
return existing;
|
|
27
|
+
}
|
|
28
|
+
map.set(element.id, element);
|
|
29
|
+
return element;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const storeKeepAlive = (element: KeepAliveElement) =>
|
|
33
|
+
_storeKeepAlive(keepAliveElements, element);
|
|
34
|
+
export const storeKeepAliveRoute = (element: KeepAliveElement) =>
|
|
35
|
+
_storeKeepAlive(keepAliveRouteElements, element);
|
|
36
|
+
|
|
37
|
+
const _removeKeepAlive = (
|
|
38
|
+
map: Map<string, KeepAliveElement>,
|
|
39
|
+
id: string,
|
|
40
|
+
): void => {
|
|
41
|
+
const element = map.get(id);
|
|
42
|
+
if (element) {
|
|
43
|
+
(element.children as unknown as ElementNode)?.destroy();
|
|
44
|
+
element.dispose?.();
|
|
45
|
+
map.delete(id);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const removeKeepAlive = (id: string): void =>
|
|
50
|
+
_removeKeepAlive(keepAliveElements, id);
|
|
51
|
+
export const removeKeepAliveRoute = (id: string): void =>
|
|
52
|
+
_removeKeepAlive(keepAliveRouteElements, id);
|
|
53
|
+
|
|
54
|
+
const _clearKeepAlive = (map: Map<string, KeepAliveElement>): void => {
|
|
55
|
+
map.forEach((element) => {
|
|
56
|
+
(element.children as unknown as ElementNode)?.destroy();
|
|
57
|
+
element.dispose?.();
|
|
58
|
+
});
|
|
59
|
+
map.clear();
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const clearKeepAlive = (): void => _clearKeepAlive(keepAliveElements);
|
|
63
|
+
export const clearKeepAliveRoute = (): void =>
|
|
64
|
+
_clearKeepAlive(keepAliveRouteElements);
|
|
65
|
+
|
|
66
|
+
interface KeepAliveProps {
|
|
67
|
+
id: string;
|
|
68
|
+
shouldDispose?: (key: string) => boolean;
|
|
69
|
+
onRemove?: ElementNode['onRemove'];
|
|
70
|
+
onRender?: ElementNode['onRender'];
|
|
71
|
+
transition?: ElementNode['transition'];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function wrapChildren(
|
|
75
|
+
props: s.ParentProps<KeepAliveProps>,
|
|
76
|
+
setIsAlive?: (v: boolean) => void,
|
|
77
|
+
) {
|
|
78
|
+
const onRemove = chainFunctions(
|
|
79
|
+
props.onRemove ||
|
|
80
|
+
((elm: ElementNode) => {
|
|
81
|
+
elm.alpha = 0;
|
|
82
|
+
}),
|
|
83
|
+
() => setIsAlive?.(false),
|
|
84
|
+
);
|
|
85
|
+
const onRender = chainFunctions(
|
|
86
|
+
props.onRender ||
|
|
87
|
+
((elm: ElementNode) => {
|
|
88
|
+
elm.alpha = 1;
|
|
89
|
+
}),
|
|
90
|
+
() => setIsAlive?.(true),
|
|
91
|
+
);
|
|
92
|
+
const transition = props.transition || { alpha: true };
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<view
|
|
96
|
+
{...props}
|
|
97
|
+
preserve
|
|
98
|
+
onRemove={onRemove}
|
|
99
|
+
onRender={onRender}
|
|
100
|
+
forwardFocus={0}
|
|
101
|
+
transition={transition}
|
|
102
|
+
/>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const createKeepAliveComponent = (
|
|
107
|
+
map: Map<string, KeepAliveElement>,
|
|
108
|
+
storeFn: (element: KeepAliveElement) => KeepAliveElement | undefined,
|
|
109
|
+
) => {
|
|
110
|
+
return (props: s.ParentProps<KeepAliveProps>) => {
|
|
111
|
+
let existing = map.get(props.id);
|
|
112
|
+
|
|
113
|
+
if (
|
|
114
|
+
existing &&
|
|
115
|
+
(props.shouldDispose?.(props.id) ||
|
|
116
|
+
(existing.children as unknown as ElementNode)?.destroyed)
|
|
117
|
+
) {
|
|
118
|
+
(existing.children as unknown as ElementNode).destroy();
|
|
119
|
+
existing.dispose?.();
|
|
120
|
+
map.delete(props.id);
|
|
121
|
+
existing = undefined;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (!existing || !existing.dispose) {
|
|
125
|
+
return s.createRoot((dispose) => {
|
|
126
|
+
const [isAlive, setIsAlive] =
|
|
127
|
+
existing?.isAlive && existing?.setIsAlive
|
|
128
|
+
? [existing.isAlive, existing.setIsAlive]
|
|
129
|
+
: s.createSignal(true);
|
|
130
|
+
const children = wrapChildren(props, setIsAlive);
|
|
131
|
+
storeFn({
|
|
132
|
+
id: props.id,
|
|
133
|
+
owner: s.getOwner(),
|
|
134
|
+
children,
|
|
135
|
+
dispose,
|
|
136
|
+
isAlive,
|
|
137
|
+
setIsAlive,
|
|
138
|
+
});
|
|
139
|
+
return children;
|
|
140
|
+
});
|
|
141
|
+
} else if (existing && !existing.children) {
|
|
142
|
+
existing.children = s.runWithOwner(existing.owner, () =>
|
|
143
|
+
wrapChildren(props, existing!.setIsAlive),
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
return existing.children;
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export const KeepAlive = createKeepAliveComponent(
|
|
151
|
+
keepAliveElements,
|
|
152
|
+
storeKeepAlive,
|
|
153
|
+
);
|
|
154
|
+
const KeepAliveRouteInternal = createKeepAliveComponent(
|
|
155
|
+
keepAliveRouteElements,
|
|
156
|
+
storeKeepAliveRoute,
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
export const KeepAliveRoute = <S extends string>(
|
|
160
|
+
props: RouteProps<S> & {
|
|
161
|
+
id?: string;
|
|
162
|
+
path: string;
|
|
163
|
+
component: (
|
|
164
|
+
props: RouteProps<S> & { isAlive: s.Accessor<boolean> },
|
|
165
|
+
) => s.JSX.Element;
|
|
166
|
+
shouldDispose?: (key: string) => boolean;
|
|
167
|
+
onRemove?: ElementNode['onRemove'];
|
|
168
|
+
onRender?: ElementNode['onRender'];
|
|
169
|
+
transition?: ElementNode['transition'];
|
|
170
|
+
preload?: (
|
|
171
|
+
args: RoutePreloadFuncArgs & { isAlive: s.Accessor<boolean> },
|
|
172
|
+
) => void;
|
|
173
|
+
},
|
|
174
|
+
) => {
|
|
175
|
+
const key = props.id || props.path;
|
|
176
|
+
let savedFocusedElement: ElementNode | undefined;
|
|
177
|
+
|
|
178
|
+
const getExisting = () => {
|
|
179
|
+
let existing = keepAliveRouteElements.get(key);
|
|
180
|
+
if (!existing) {
|
|
181
|
+
const [isAlive, setIsAlive] = s.createSignal(true);
|
|
182
|
+
existing = {
|
|
183
|
+
id: key,
|
|
184
|
+
isAlive,
|
|
185
|
+
setIsAlive,
|
|
186
|
+
} as any;
|
|
187
|
+
keepAliveRouteElements.set(key, existing!);
|
|
188
|
+
}
|
|
189
|
+
return existing!;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const onRemove = chainFunctions(props.onRemove, (elm: ElementNode) => {
|
|
193
|
+
savedFocusedElement = activeElement() as ElementNode;
|
|
194
|
+
elm.alpha = 0;
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
const onRender = chainFunctions(props.onRender, (elm: ElementNode) => {
|
|
198
|
+
let isChild = false;
|
|
199
|
+
let current = savedFocusedElement;
|
|
200
|
+
while (current) {
|
|
201
|
+
if (current === elm) {
|
|
202
|
+
isChild = true;
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
current = current.parent as ElementNode | undefined;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (isChild && savedFocusedElement) {
|
|
209
|
+
savedFocusedElement.setFocus();
|
|
210
|
+
} else {
|
|
211
|
+
elm.setFocus();
|
|
212
|
+
}
|
|
213
|
+
elm.alpha = 1;
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
const preload = props.preload
|
|
217
|
+
? (preloadProps: RoutePreloadFuncArgs) => {
|
|
218
|
+
let existing = getExisting();
|
|
219
|
+
|
|
220
|
+
if (
|
|
221
|
+
existing.children &&
|
|
222
|
+
(props.shouldDispose?.(key) ||
|
|
223
|
+
(existing.children as unknown as ElementNode)?.destroyed)
|
|
224
|
+
) {
|
|
225
|
+
(existing.children as unknown as ElementNode).destroy();
|
|
226
|
+
existing.dispose?.();
|
|
227
|
+
keepAliveRouteElements.delete(key);
|
|
228
|
+
existing = getExisting();
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (!existing.dispose) {
|
|
232
|
+
return s.createRoot((dispose) => {
|
|
233
|
+
existing.owner = s.getOwner();
|
|
234
|
+
existing.dispose = dispose;
|
|
235
|
+
return props.preload!({ ...preloadProps, isAlive: existing.isAlive! });
|
|
236
|
+
});
|
|
237
|
+
} else if (existing.children) {
|
|
238
|
+
(existing.children as unknown as ElementNode)?.setFocus();
|
|
239
|
+
return props.preload!({ ...preloadProps, isAlive: existing.isAlive! });
|
|
240
|
+
} else {
|
|
241
|
+
return props.preload!({
|
|
242
|
+
...preloadProps,
|
|
243
|
+
isAlive: existing.isAlive!,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
: undefined;
|
|
248
|
+
|
|
249
|
+
return (
|
|
250
|
+
<Route
|
|
251
|
+
{...props}
|
|
252
|
+
preload={preload}
|
|
253
|
+
component={(childProps) => {
|
|
254
|
+
const existing = getExisting();
|
|
255
|
+
return (
|
|
256
|
+
<KeepAliveRouteInternal
|
|
257
|
+
id={key}
|
|
258
|
+
onRemove={onRemove}
|
|
259
|
+
onRender={onRender}
|
|
260
|
+
transition={props.transition}
|
|
261
|
+
>
|
|
262
|
+
{props.component({ ...childProps, isAlive: existing.isAlive! })}
|
|
263
|
+
</KeepAliveRouteInternal>
|
|
264
|
+
);
|
|
265
|
+
}}
|
|
266
|
+
/>
|
|
267
|
+
);
|
|
268
|
+
};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import * as lng from '@solidtv/solid';
|
|
2
|
+
import * as lngp from '@solidtv/solid/primitives';
|
|
3
|
+
import * as s from 'solid-js';
|
|
4
|
+
|
|
5
|
+
type LazyProps<T extends readonly any[]> = lng.NewOmit<lng.NodeProps, 'children'> & {
|
|
6
|
+
each: T | undefined | null | false;
|
|
7
|
+
upCount: number;
|
|
8
|
+
buffer?: number;
|
|
9
|
+
delay?: number;
|
|
10
|
+
sync?: boolean;
|
|
11
|
+
eagerLoad?: boolean;
|
|
12
|
+
noRefocus?: boolean;
|
|
13
|
+
children: (item: s.Accessor<T[number]>, index: number) => s.JSX.Element;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function createLazy<T>(
|
|
17
|
+
component: s.ValidComponent,
|
|
18
|
+
props: LazyProps<readonly T[]>,
|
|
19
|
+
keyHandler: (updateOffset: (event: KeyboardEvent, container: lng.ElementNode) => void) => Record<string, (event: KeyboardEvent, container: lng.ElementNode) => void>
|
|
20
|
+
) {
|
|
21
|
+
// Need at least one item so it can be focused
|
|
22
|
+
const [offset, setOffset] = s.createSignal<number>(props.sync ? props.upCount : 0);
|
|
23
|
+
let timeoutId: ReturnType<typeof setTimeout> | null = null;
|
|
24
|
+
let viewRef!: lngp.NavigableElement;
|
|
25
|
+
let itemLength: number = 0;
|
|
26
|
+
|
|
27
|
+
const buffer = s.createMemo(() => {
|
|
28
|
+
if (typeof props.buffer === 'number') {
|
|
29
|
+
return props.buffer;
|
|
30
|
+
}
|
|
31
|
+
const scroll = props.scroll || props.style?.scroll;
|
|
32
|
+
if (
|
|
33
|
+
!scroll ||
|
|
34
|
+
scroll === 'auto' ||
|
|
35
|
+
scroll === 'always' ||
|
|
36
|
+
scroll === 'bounded'
|
|
37
|
+
)
|
|
38
|
+
return props.upCount + 1;
|
|
39
|
+
if (scroll === 'center') return Math.ceil(props.upCount / 2) + 1;
|
|
40
|
+
return 2;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
s.createRenderEffect(() => setOffset(offset => Math.max(offset, (props.selected || 0) + buffer())));
|
|
44
|
+
|
|
45
|
+
if (!props.sync || props.eagerLoad) {
|
|
46
|
+
s.createEffect(() => {
|
|
47
|
+
if (props.each) {
|
|
48
|
+
const loadItems = () => {
|
|
49
|
+
let count = s.untrack(offset);
|
|
50
|
+
if (count < props.upCount) {
|
|
51
|
+
setOffset(count + 1);
|
|
52
|
+
timeoutId = setTimeout(loadItems, 16); // ~60fps
|
|
53
|
+
count++;
|
|
54
|
+
} else if (props.eagerLoad) {
|
|
55
|
+
const maxOffset = props.each ? props.each.length : 0;
|
|
56
|
+
if (count >= maxOffset) return;
|
|
57
|
+
setOffset((prev) => Math.min(prev + 1, maxOffset));
|
|
58
|
+
lng.scheduleTask(loadItems);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
loadItems();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const items: s.Accessor<T[]> = s.createMemo(() => {
|
|
67
|
+
if (Array.isArray(props.each)) {
|
|
68
|
+
if (itemLength != props.each.length) {
|
|
69
|
+
itemLength = props.each.length;
|
|
70
|
+
if (viewRef && !viewRef.noRefocus && lng.hasFocus(viewRef)) {
|
|
71
|
+
queueMicrotask(() => viewRef.setFocus());
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return props.each.slice(0, offset());
|
|
75
|
+
}
|
|
76
|
+
itemLength = 0;
|
|
77
|
+
return [];
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
function lazyScrollToIndex(this: lngp.NavigableElement, index: number) {
|
|
81
|
+
setOffset(Math.max(index, 0) + buffer())
|
|
82
|
+
queueMicrotask(() => viewRef.scrollToIndex(index));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const updateOffset = (_event: KeyboardEvent, container: lng.ElementNode) => {
|
|
86
|
+
const maxOffset = props.each ? props.each.length : 0;
|
|
87
|
+
const selected = container.selected || 0;
|
|
88
|
+
const numChildren = container.children.length;
|
|
89
|
+
if (offset() >= maxOffset || selected < numChildren - buffer()) return;
|
|
90
|
+
|
|
91
|
+
if (!props.delay) {
|
|
92
|
+
setOffset((prev) => Math.min(prev + 1, maxOffset));
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (timeoutId) {
|
|
97
|
+
clearTimeout(timeoutId);
|
|
98
|
+
//Moving faster than the delay so need to go sync
|
|
99
|
+
setOffset((prev) => Math.min(prev + 1, maxOffset));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
timeoutId = setTimeout(() => {
|
|
103
|
+
setOffset((prev) => Math.min(prev + 1, maxOffset));
|
|
104
|
+
timeoutId = null;
|
|
105
|
+
}, props.delay ?? 0);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const handler = keyHandler(updateOffset);
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<lng.Dynamic
|
|
112
|
+
{...props}
|
|
113
|
+
component={component}
|
|
114
|
+
{/* @once */ ...handler}
|
|
115
|
+
lazyScrollToIndex={lazyScrollToIndex}
|
|
116
|
+
ref={lngp.chainRefs(el => { viewRef = el as lngp.NavigableElement; }, props.ref)} >
|
|
117
|
+
<s.Index each={items()} children={props.children} />
|
|
118
|
+
</lng.Dynamic>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function LazyRow<T extends readonly any[]>(props: LazyProps<T>) {
|
|
123
|
+
return createLazy(lngp.Row, props, (updateOffset) => ({ onRight: updateOffset }));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function LazyColumn<T extends readonly any[]>(props: LazyProps<T>) {
|
|
127
|
+
return createLazy(lngp.Column, props, (updateOffset) => ({ onDown: updateOffset }));
|
|
128
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSignal,
|
|
3
|
+
createResource,
|
|
4
|
+
createMemo,
|
|
5
|
+
untrack,
|
|
6
|
+
Component,
|
|
7
|
+
JSX,
|
|
8
|
+
sharedConfig,
|
|
9
|
+
} from 'solid-js';
|
|
10
|
+
|
|
11
|
+
// lazy load a function component asynchronously
|
|
12
|
+
export function lazy<T extends Component<any>>(
|
|
13
|
+
fn: () => Promise<{ default: T }>,
|
|
14
|
+
): T & { preload: () => Promise<{ default: T }> } {
|
|
15
|
+
let comp: () => T | undefined;
|
|
16
|
+
let p: Promise<{ default: T }> | undefined;
|
|
17
|
+
const wrap: T & { preload?: () => void } = ((props: any) => {
|
|
18
|
+
const ctx = sharedConfig.context;
|
|
19
|
+
if (ctx) {
|
|
20
|
+
const [s, set] = createSignal<T>();
|
|
21
|
+
sharedConfig.count || (sharedConfig.count = 0);
|
|
22
|
+
sharedConfig.count++;
|
|
23
|
+
(p || (p = fn())).then((mod) => {
|
|
24
|
+
!sharedConfig.done && (sharedConfig.context = ctx);
|
|
25
|
+
sharedConfig.count!--;
|
|
26
|
+
set(() => mod.default);
|
|
27
|
+
sharedConfig.context = undefined;
|
|
28
|
+
});
|
|
29
|
+
comp = s;
|
|
30
|
+
} else if (!comp) {
|
|
31
|
+
const [s] = createResource<T>(() =>
|
|
32
|
+
(p || (p = fn())).then((mod) => mod.default),
|
|
33
|
+
);
|
|
34
|
+
comp = s;
|
|
35
|
+
}
|
|
36
|
+
let Comp: T | undefined;
|
|
37
|
+
return createMemo(() =>
|
|
38
|
+
(Comp = comp())
|
|
39
|
+
? untrack(() => {
|
|
40
|
+
if (!ctx || sharedConfig.done) return Comp!(props);
|
|
41
|
+
const c = sharedConfig.context;
|
|
42
|
+
sharedConfig.context = ctx;
|
|
43
|
+
const r = Comp!(props);
|
|
44
|
+
sharedConfig.context = c;
|
|
45
|
+
return r;
|
|
46
|
+
})
|
|
47
|
+
: null,
|
|
48
|
+
) as unknown as JSX.Element;
|
|
49
|
+
}) as T;
|
|
50
|
+
wrap.preload = () =>
|
|
51
|
+
p || ((p = fn()).then((mod) => (comp = () => mod.default)), p);
|
|
52
|
+
return wrap as T & { preload: () => Promise<{ default: T }> };
|
|
53
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import * as s from 'solid-js'
|
|
2
|
+
import * as lng from '@solidtv/solid'
|
|
3
|
+
import { chainFunctions } from './utils/chainFunctions.js'
|
|
4
|
+
|
|
5
|
+
export interface MarqueeAnimationProps {
|
|
6
|
+
/** delay in ms between animations, @default 1000 */
|
|
7
|
+
delay?: number
|
|
8
|
+
/** pixels per second, @default 200 */
|
|
9
|
+
speed?: number
|
|
10
|
+
/**
|
|
11
|
+
* distance between the end of the text and the start of the next animation
|
|
12
|
+
* @default `0.5 * clipWidth`
|
|
13
|
+
*/
|
|
14
|
+
scrollGap?: number
|
|
15
|
+
/** easing function, @default 'linear' */
|
|
16
|
+
easing?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface MarqueeControlProps {
|
|
20
|
+
/** whether to scroll the text or show it contained */
|
|
21
|
+
marquee: boolean
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface MarqueeTextProps
|
|
25
|
+
extends lng.TextProps, MarqueeControlProps, MarqueeAnimationProps {
|
|
26
|
+
/** width of the container */
|
|
27
|
+
clipWidth: number
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface MarqueeProps
|
|
31
|
+
extends lng.NewOmit<lng.NodeProps, 'children'>, MarqueeControlProps, MarqueeAnimationProps {
|
|
32
|
+
textProps?: lng.TextProps
|
|
33
|
+
children: lng.TextProps['children']
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const SAFETY_MARGIN = 10
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* MarqueeText is a component that scrolls text when it overflows the container.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* <view width={400} height={28} clipping>
|
|
44
|
+
* <MarqueeText
|
|
45
|
+
* clipWidth={400}
|
|
46
|
+
* marquee={inFocus()}
|
|
47
|
+
* speed={200}
|
|
48
|
+
* delay={1000}
|
|
49
|
+
* scrollGap={24}
|
|
50
|
+
* easing='ease-in-out'
|
|
51
|
+
* >
|
|
52
|
+
* This is a long text that will scroll when it overflows the container.
|
|
53
|
+
* </MarqueeText>
|
|
54
|
+
* </view>
|
|
55
|
+
*/
|
|
56
|
+
export function MarqueeText(props: MarqueeTextProps) {
|
|
57
|
+
|
|
58
|
+
const speed = s.createMemo(() => props.speed || 200)
|
|
59
|
+
const delay = s.createMemo(() => props.delay ?? 1000)
|
|
60
|
+
const scrollGap = s.createMemo(() => props.scrollGap ?? (props.clipWidth * 0.5))
|
|
61
|
+
|
|
62
|
+
const [textWidth, setTextWidth] = s.createSignal(0)
|
|
63
|
+
|
|
64
|
+
const isTextOverflowing = s.createMemo(() => textWidth() > props.clipWidth - SAFETY_MARGIN)
|
|
65
|
+
const shouldScroll = s.createMemo(() => props.marquee && isTextOverflowing())
|
|
66
|
+
|
|
67
|
+
const wasFocusedBefore = s.createMemo<boolean>(p => p || props.marquee, false)
|
|
68
|
+
|
|
69
|
+
s.createEffect(() => {
|
|
70
|
+
if (shouldScroll()) {
|
|
71
|
+
|
|
72
|
+
let options: lng.AnimationSettings = {
|
|
73
|
+
duration: (textWidth() + scrollGap()) / speed() * 1000,
|
|
74
|
+
delay: delay(),
|
|
75
|
+
loop: true,
|
|
76
|
+
easing: props.easing,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
text1.lng.x = 0
|
|
80
|
+
text2.lng.x = textWidth() + scrollGap()
|
|
81
|
+
|
|
82
|
+
let a1 = text1.lng.animate!({x: -textWidth() -scrollGap()}, options).start()
|
|
83
|
+
let a2 = text2.lng.animate!({x: 0}, options).start()
|
|
84
|
+
|
|
85
|
+
s.onCleanup(() => {
|
|
86
|
+
a1.stop()
|
|
87
|
+
a2.stop()
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
const events = {loaded(el: lng.ElementNode) {setTextWidth(el.width)}}
|
|
93
|
+
|
|
94
|
+
let text1!: lng.ElementNode
|
|
95
|
+
let text2!: lng.ElementNode
|
|
96
|
+
return (
|
|
97
|
+
<>
|
|
98
|
+
{wasFocusedBefore() && <>
|
|
99
|
+
<text {...props} ref={text1} hidden={!shouldScroll()} rtt maxLines={1} onEvent={events} />
|
|
100
|
+
<text {...props} ref={text2} hidden={!shouldScroll()} rtt maxLines={1} />
|
|
101
|
+
</>}
|
|
102
|
+
<text {...props} maxLines={1} hidden={shouldScroll()} contain='width' />
|
|
103
|
+
</>
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Marquee is a component that scrolls text when it overflows the container.
|
|
109
|
+
* It uses the {@link MarqueeText} component to do the actual scrolling.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```tsx
|
|
113
|
+
* <Marquee
|
|
114
|
+
* width={400}
|
|
115
|
+
* marquee={inFocus()}
|
|
116
|
+
* easing='ease-in-out'
|
|
117
|
+
* textProps={{
|
|
118
|
+
* fontSize: 28,
|
|
119
|
+
* }}
|
|
120
|
+
* >
|
|
121
|
+
* This is a long text that will scroll when it overflows the container.
|
|
122
|
+
* </Marquee>
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export function Marquee(props: MarqueeProps) {
|
|
126
|
+
const [clipWidth, setClipWidth] = s.createSignal(props.width || 0);
|
|
127
|
+
const clipHeight = s.createMemo(() => props.height || props.textProps?.lineHeight || ((props.textProps?.fontSize || 16) * 1.5));
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<view
|
|
131
|
+
{...props}
|
|
132
|
+
height={clipHeight()}
|
|
133
|
+
onLayout={/* @once */ chainFunctions(props.onLayout, (e: lng.ElementNode) => setClipWidth(e.width))}
|
|
134
|
+
clipping={props.marquee}
|
|
135
|
+
>
|
|
136
|
+
<MarqueeText
|
|
137
|
+
{...props.textProps}
|
|
138
|
+
marquee={props.marquee}
|
|
139
|
+
clipWidth={clipWidth()}
|
|
140
|
+
speed={props.speed}
|
|
141
|
+
delay={props.delay}
|
|
142
|
+
scrollGap={props.scrollGap}
|
|
143
|
+
easing={props.easing}
|
|
144
|
+
>
|
|
145
|
+
{props.children}
|
|
146
|
+
</MarqueeText>
|
|
147
|
+
</view>
|
|
148
|
+
)
|
|
149
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as s from 'solid-js'
|
|
2
|
+
import * as lng from '@solidtv/solid'
|
|
3
|
+
|
|
4
|
+
function Preserve(props: lng.NodeProps): s.JSX.Element {
|
|
5
|
+
|
|
6
|
+
let view = <view {...props} /> as any as lng.ElementNode
|
|
7
|
+
|
|
8
|
+
view.preserve = true;
|
|
9
|
+
|
|
10
|
+
view.onRender ??= () => {view.hidden = false}
|
|
11
|
+
view.onRemove ??= () => {view.hidden = true}
|
|
12
|
+
|
|
13
|
+
s.onCleanup(() => {view.destroy()})
|
|
14
|
+
|
|
15
|
+
return view as any as s.JSX.Element
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default Preserve;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type Component } from 'solid-js';
|
|
2
|
+
import {
|
|
3
|
+
combineStyles,
|
|
4
|
+
type NodeStyles,
|
|
5
|
+
type ElementNode,
|
|
6
|
+
} from '@solidtv/solid';
|
|
7
|
+
import { chainFunctions } from './utils/chainFunctions.js';
|
|
8
|
+
import {
|
|
9
|
+
handleNavigation,
|
|
10
|
+
navigableForwardFocus,
|
|
11
|
+
defaultTransitionBack,
|
|
12
|
+
defaultTransitionForward,
|
|
13
|
+
} from './utils/handleNavigation.js';
|
|
14
|
+
import type { RowProps } from './types.js';
|
|
15
|
+
import { scrollRow } from './utils/withScrolling.js';
|
|
16
|
+
|
|
17
|
+
const RowStyles: NodeStyles = {
|
|
18
|
+
display: 'flex',
|
|
19
|
+
gap: 30,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function scrollToIndex(this: ElementNode, index: number) {
|
|
23
|
+
this.selected = index;
|
|
24
|
+
scrollRow(index, this);
|
|
25
|
+
this.children[index]?.setFocus();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const onLeft = handleNavigation('left');
|
|
29
|
+
const onRight = handleNavigation('right');
|
|
30
|
+
|
|
31
|
+
export const Row: Component<RowProps> = (props) => {
|
|
32
|
+
return (
|
|
33
|
+
<view
|
|
34
|
+
transitionLeft={defaultTransitionBack}
|
|
35
|
+
transitionRight={defaultTransitionForward}
|
|
36
|
+
transition={/* @once */ {}}
|
|
37
|
+
{...props}
|
|
38
|
+
selected={props.selected || 0}
|
|
39
|
+
onLeft={/* @once */ chainFunctions(props.onLeft, onLeft)}
|
|
40
|
+
onRight={/* @once */ chainFunctions(props.onRight, onRight)}
|
|
41
|
+
forwardFocus={navigableForwardFocus}
|
|
42
|
+
scrollToIndex={scrollToIndex}
|
|
43
|
+
onLayout={
|
|
44
|
+
/* @once */
|
|
45
|
+
props.selected
|
|
46
|
+
? chainFunctions(props.onLayout, scrollRow)
|
|
47
|
+
: props.onLayout
|
|
48
|
+
}
|
|
49
|
+
onSelectedChanged={
|
|
50
|
+
/* @once */ chainFunctions(
|
|
51
|
+
props.onSelectedChanged,
|
|
52
|
+
props.scroll !== 'none' ? scrollRow : undefined,
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
style={/* @once */ combineStyles(props.style, RowStyles)}
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
};
|