@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,147 @@
|
|
|
1
|
+
import { getOwner, runWithOwner, createMemo } from 'solid-js';
|
|
2
|
+
import {
|
|
3
|
+
type BaseRouterProps,
|
|
4
|
+
createRouter,
|
|
5
|
+
createBeforeLeave,
|
|
6
|
+
keepDepth,
|
|
7
|
+
notifyIfNotBlocked,
|
|
8
|
+
saveCurrentDepth,
|
|
9
|
+
type RouteDescription,
|
|
10
|
+
type RouteMatch,
|
|
11
|
+
} from '@solidjs/router';
|
|
12
|
+
import type { JSX } from 'solid-js';
|
|
13
|
+
|
|
14
|
+
export function hashParser(str: string) {
|
|
15
|
+
const to = str.replace(/^.*?#/, '');
|
|
16
|
+
// Hash-only hrefs like `#foo` from plain anchors will come in as `/#foo` whereas a link to
|
|
17
|
+
// `/foo` will be `/#/foo`. Check if the to starts with a `/` and if not append it as a hash
|
|
18
|
+
// to the current path so we can handle these in-page anchors correctly.
|
|
19
|
+
if (!to.startsWith('/')) {
|
|
20
|
+
const [, path = '/'] = window.location.hash.split('#', 2);
|
|
21
|
+
return `${path}#${to}`;
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type HashRouterProps = BaseRouterProps & {
|
|
27
|
+
actionBase?: string;
|
|
28
|
+
explicitLinks?: boolean;
|
|
29
|
+
preload?: boolean;
|
|
30
|
+
forceProxy?: boolean;
|
|
31
|
+
queryParams?: string[];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export function bindEvent(
|
|
35
|
+
target: EventTarget,
|
|
36
|
+
type: string,
|
|
37
|
+
handler: EventListener,
|
|
38
|
+
) {
|
|
39
|
+
target.addEventListener(type, handler);
|
|
40
|
+
return () => target.removeEventListener(type, handler);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function HashRouter(props: HashRouterProps): JSX.Element {
|
|
44
|
+
const getSource = () => window.location.hash.slice(1);
|
|
45
|
+
const beforeLeave = createBeforeLeave();
|
|
46
|
+
return createRouter({
|
|
47
|
+
get: getSource,
|
|
48
|
+
set({ value, replace, state }) {
|
|
49
|
+
if (replace) {
|
|
50
|
+
window.history.replaceState(keepDepth(state), '', '#' + value);
|
|
51
|
+
} else {
|
|
52
|
+
window.history.pushState(state, '', '#' + value);
|
|
53
|
+
}
|
|
54
|
+
saveCurrentDepth();
|
|
55
|
+
},
|
|
56
|
+
init: (notify) =>
|
|
57
|
+
bindEvent(
|
|
58
|
+
window,
|
|
59
|
+
'hashchange',
|
|
60
|
+
notifyIfNotBlocked(
|
|
61
|
+
notify,
|
|
62
|
+
(delta) =>
|
|
63
|
+
!beforeLeave.confirm(delta && delta < 0 ? delta : getSource()),
|
|
64
|
+
),
|
|
65
|
+
),
|
|
66
|
+
utils: {
|
|
67
|
+
go: (delta) => window.history.go(delta),
|
|
68
|
+
renderPath: (path) => `#${path}`,
|
|
69
|
+
parsePath: hashParser,
|
|
70
|
+
beforeLeave,
|
|
71
|
+
queryWrapper:
|
|
72
|
+
props.forceProxy || !SUPPORTS_PROXY
|
|
73
|
+
? (getQuery) => {
|
|
74
|
+
return createMemoWithoutProxy(getQuery, props.queryParams);
|
|
75
|
+
}
|
|
76
|
+
: undefined,
|
|
77
|
+
paramsWrapper:
|
|
78
|
+
props.forceProxy || !SUPPORTS_PROXY
|
|
79
|
+
? (buildParams, branches) => {
|
|
80
|
+
return createMemoWithoutProxy(
|
|
81
|
+
buildParams,
|
|
82
|
+
collectDynamicParams(branches()),
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
: undefined,
|
|
86
|
+
},
|
|
87
|
+
})(props);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const SUPPORTS_PROXY = typeof Proxy === 'function';
|
|
91
|
+
export function createMemoWithoutProxy<
|
|
92
|
+
T extends Record<string | symbol, unknown>,
|
|
93
|
+
>(fn: () => T, allKeys?: string[]): T {
|
|
94
|
+
const map = new Map();
|
|
95
|
+
const owner = getOwner()!;
|
|
96
|
+
const target = {} as T;
|
|
97
|
+
|
|
98
|
+
const handler = (property: keyof T) => {
|
|
99
|
+
if (!map.has(property)) {
|
|
100
|
+
runWithOwner(owner, () =>
|
|
101
|
+
map.set(
|
|
102
|
+
property,
|
|
103
|
+
createMemo(() => fn()[property]),
|
|
104
|
+
),
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
return map.get(property)!();
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const keys = allKeys ? allKeys : (Object.keys(fn()) as (keyof T)[]);
|
|
111
|
+
|
|
112
|
+
keys.forEach((key) => {
|
|
113
|
+
Object.defineProperty(target, key, {
|
|
114
|
+
get: () => handler(key),
|
|
115
|
+
enumerable: true,
|
|
116
|
+
configurable: true,
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
return target;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface Branch {
|
|
124
|
+
routes: RouteDescription[];
|
|
125
|
+
score: number;
|
|
126
|
+
matcher: (location: string) => RouteMatch[] | null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export const collectDynamicParams = (branches: Branch[]) => {
|
|
130
|
+
const dynamicParams: string[] = [];
|
|
131
|
+
|
|
132
|
+
branches.forEach((branch) => {
|
|
133
|
+
branch.routes.forEach((route) => {
|
|
134
|
+
if (route.pattern) {
|
|
135
|
+
const matches = route.pattern.match(/:(\w+)/g);
|
|
136
|
+
if (matches) {
|
|
137
|
+
matches.forEach((param) => {
|
|
138
|
+
const p = param.slice(1); // Remove the `:`
|
|
139
|
+
if (!dynamicParams.includes(p)) dynamicParams.push(p);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
return dynamicParams;
|
|
147
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { ElementNode, NodeProps, NodeStyles } from '../index.js';
|
|
2
|
+
import type { KeyHandler } from '../core/focusManager.js';
|
|
3
|
+
|
|
4
|
+
export type OnSelectedChanged = (
|
|
5
|
+
this: NavigableElement,
|
|
6
|
+
selectedIndex: number,
|
|
7
|
+
elm: NavigableElement,
|
|
8
|
+
active: ElementNode,
|
|
9
|
+
lastSelectedIndex?: number,
|
|
10
|
+
) => void;
|
|
11
|
+
|
|
12
|
+
export interface NavigableProps extends NodeProps {
|
|
13
|
+
/** function to be called when the selected of the component changes */
|
|
14
|
+
onSelectedChanged?: OnSelectedChanged;
|
|
15
|
+
|
|
16
|
+
/** Determines when to scroll(shift items along the axis):
|
|
17
|
+
* auto - scroll items immediately
|
|
18
|
+
* edge - scroll items when focus reaches the last item on screen
|
|
19
|
+
* always - focus remains at index 0, scroll until the final item is at index 0
|
|
20
|
+
* center - selected element will be centered to the screen
|
|
21
|
+
* none - disable scrolling behavior, focus shifts as expected
|
|
22
|
+
* in both `auto` and `edge` items will only scroll until the last item is on screen */
|
|
23
|
+
scroll?: 'always' | 'none' | 'edge' | 'auto' | 'center';
|
|
24
|
+
|
|
25
|
+
/** When auto scrolling, item index at which scrolling begins */
|
|
26
|
+
scrollIndex?: number;
|
|
27
|
+
|
|
28
|
+
/** The initial index */
|
|
29
|
+
selected?: number;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Adjust the x position of the row. Initial value is Y
|
|
33
|
+
*/
|
|
34
|
+
offset?: number;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Plinko - sets the selected item of the next row to match the previous row
|
|
38
|
+
*/
|
|
39
|
+
plinko?: boolean;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Wrap the row so active goes back to the beginning of the row
|
|
43
|
+
*/
|
|
44
|
+
wrap?: boolean;
|
|
45
|
+
|
|
46
|
+
/** function to be called when scrolled */
|
|
47
|
+
onScrolled?: (
|
|
48
|
+
elm: NavigableElement,
|
|
49
|
+
offset: number,
|
|
50
|
+
isInitial: boolean,
|
|
51
|
+
) => void;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Defines transitions for animatable properties when navigating up.
|
|
55
|
+
*/
|
|
56
|
+
transitionUp?: NodeStyles['transition'];
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Defines transitions for animatable properties when navigating down.
|
|
60
|
+
*/
|
|
61
|
+
transitionDown?: NodeStyles['transition'];
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Defines transitions for animatable properties when navigating left.
|
|
65
|
+
*/
|
|
66
|
+
transitionLeft?: NodeStyles['transition'];
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Defines transitions for animatable properties when navigating right.
|
|
70
|
+
*/
|
|
71
|
+
transitionRight?: NodeStyles['transition'];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// @ts-expect-error animationSettings is not identical - weird
|
|
75
|
+
export interface NavigableElement extends ElementNode, NavigableProps {
|
|
76
|
+
selected: number;
|
|
77
|
+
scrollToIndex: (this: NavigableElement, index: number) => void;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface NavigableStyleProperties {
|
|
81
|
+
/**
|
|
82
|
+
* the index of which we want scrolling to start
|
|
83
|
+
*/
|
|
84
|
+
scrollIndex?: number;
|
|
85
|
+
/**
|
|
86
|
+
* space between each keys
|
|
87
|
+
*/
|
|
88
|
+
itemSpacing?: NodeStyles['gap'];
|
|
89
|
+
/**
|
|
90
|
+
* animation transition
|
|
91
|
+
*/
|
|
92
|
+
itemTransition?: NodeStyles['transition'];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface ColumnProps extends NavigableProps, NavigableStyleProperties {
|
|
96
|
+
/** function to be called on down click */
|
|
97
|
+
onDown?: KeyHandler;
|
|
98
|
+
|
|
99
|
+
/** function to be called on up click */
|
|
100
|
+
onUp?: KeyHandler;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface RowProps extends NavigableProps, NavigableStyleProperties {
|
|
104
|
+
/** function to be called on down click */
|
|
105
|
+
onLeft?: KeyHandler;
|
|
106
|
+
|
|
107
|
+
/** function to be called on up click */
|
|
108
|
+
onRight?: KeyHandler;
|
|
109
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createEffect,
|
|
3
|
+
on,
|
|
4
|
+
createSignal,
|
|
5
|
+
onCleanup,
|
|
6
|
+
getOwner,
|
|
7
|
+
runWithOwner,
|
|
8
|
+
} from 'solid-js';
|
|
9
|
+
import { Config } from '../core/index.js';
|
|
10
|
+
import type { ElementNode } from '../core/index.js';
|
|
11
|
+
import {
|
|
12
|
+
useFocusManager as useFocusManagerCore,
|
|
13
|
+
type KeyMap,
|
|
14
|
+
type KeyHoldOptions,
|
|
15
|
+
} from '../core/focusManager.js';
|
|
16
|
+
import { activeElement, setActiveElement } from '../activeElement.js';
|
|
17
|
+
|
|
18
|
+
const [focusPath, setFocusPath] = createSignal<ElementNode[]>([]);
|
|
19
|
+
export { focusPath };
|
|
20
|
+
|
|
21
|
+
export const useFocusManager = (
|
|
22
|
+
userKeyMap?: Partial<KeyMap>,
|
|
23
|
+
keyHoldOptions?: KeyHoldOptions,
|
|
24
|
+
) => {
|
|
25
|
+
const owner = getOwner();
|
|
26
|
+
const ownerContext = runWithOwner.bind(this, owner);
|
|
27
|
+
Config.setActiveElement = (activeElm) =>
|
|
28
|
+
ownerContext(() => setActiveElement(activeElm));
|
|
29
|
+
|
|
30
|
+
const { cleanup, focusPath: focusPathCore } = useFocusManagerCore({
|
|
31
|
+
userKeyMap,
|
|
32
|
+
keyHoldOptions,
|
|
33
|
+
ownerContext,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
createEffect(
|
|
37
|
+
on(
|
|
38
|
+
activeElement,
|
|
39
|
+
() => {
|
|
40
|
+
setFocusPath([...focusPathCore()]);
|
|
41
|
+
},
|
|
42
|
+
{ defer: true },
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
onCleanup(cleanup);
|
|
47
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { createMemo } from 'solid-js';
|
|
2
|
+
|
|
3
|
+
export type UseHoldProps = {
|
|
4
|
+
onHold: () => void;
|
|
5
|
+
onEnter: () => void;
|
|
6
|
+
onRelease?: () => void;
|
|
7
|
+
holdThreshold?: number;
|
|
8
|
+
performOnEnterImmediately?: boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @example
|
|
13
|
+
* const [holdRight, releaseRight] = useHold({
|
|
14
|
+
* onHold: handleHoldRight,
|
|
15
|
+
* onEnter: handleOnRight,
|
|
16
|
+
* onRelease: handleReleaseHold,
|
|
17
|
+
* holdThreshold: 200,
|
|
18
|
+
* performOnEnterImmediately: true
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* <View
|
|
22
|
+
* onRight={holdRight}
|
|
23
|
+
* onRightRelease={releaseRight}
|
|
24
|
+
* />
|
|
25
|
+
*
|
|
26
|
+
* @param {UseHoldProps} props - The properties for configuring the hold behavior.
|
|
27
|
+
* @returns {[() => boolean, () => boolean]} A tuple containing `startHold` and `releaseHold` functions.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export function useHold(props: UseHoldProps) {
|
|
31
|
+
const holdThreshold = createMemo(() => props.holdThreshold ?? 500);
|
|
32
|
+
const performOnEnterImmediately = createMemo(
|
|
33
|
+
() => props.performOnEnterImmediately ?? false,
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
let holdTimeout = -1;
|
|
37
|
+
let wasHeld = false;
|
|
38
|
+
|
|
39
|
+
const startHold = () => {
|
|
40
|
+
if (holdTimeout === -1) {
|
|
41
|
+
if (performOnEnterImmediately()) {
|
|
42
|
+
props.onEnter();
|
|
43
|
+
}
|
|
44
|
+
holdTimeout = setTimeout(() => {
|
|
45
|
+
wasHeld = true;
|
|
46
|
+
props.onHold();
|
|
47
|
+
}, holdThreshold()) as unknown as number;
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const releaseHold = () => {
|
|
53
|
+
if (holdTimeout !== -1) {
|
|
54
|
+
clearTimeout(holdTimeout);
|
|
55
|
+
holdTimeout = -1;
|
|
56
|
+
if (!wasHeld) {
|
|
57
|
+
if (!performOnEnterImmediately()) props.onEnter();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
props.onRelease?.();
|
|
61
|
+
wasHeld = false;
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
return [startHold, releaseHold];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default useHold;
|