@solidtv/solid 1.6.4 → 1.6.6
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/config.d.ts +11 -0
- package/dist/src/core/config.js.map +1 -1
- package/dist/src/core/dom-renderer/domRenderer.d.ts +2 -0
- package/dist/src/core/dom-renderer/domRenderer.js +9 -0
- package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
- package/dist/src/core/dom-renderer/domRendererTypes.d.ts +4 -5
- package/dist/src/core/dom-renderer/domRendererUtils.d.ts +3 -8
- package/dist/src/core/dom-renderer/domRendererUtils.js +12 -22
- package/dist/src/core/dom-renderer/domRendererUtils.js.map +1 -1
- package/dist/src/core/focusManager.js +41 -1
- package/dist/src/core/focusManager.js.map +1 -1
- package/dist/src/primitives/createFocusStack.d.ts +1 -1
- package/dist/src/primitives/createFocusStack.jsx +6 -2
- package/dist/src/primitives/createFocusStack.jsx.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -4
- package/src/core/config.ts +11 -0
- package/src/core/dom-renderer/domRenderer.ts +11 -0
- package/src/core/dom-renderer/domRendererTypes.ts +4 -5
- package/src/core/dom-renderer/domRendererUtils.ts +13 -24
- package/src/core/focusManager.ts +49 -1
- package/src/primitives/createFocusStack.tsx +6 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidtv/solid",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.6",
|
|
4
4
|
"description": "SolidTV",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"sideEffects": false,
|
|
49
49
|
"scripts": {
|
|
50
50
|
"start": "pnpm run watch",
|
|
51
|
+
"bench": "node bench/run.mjs",
|
|
51
52
|
"test": "vitest",
|
|
52
53
|
"lint": "pnpm run lint:prettier && pnpm run lint:eslint",
|
|
53
54
|
"lint:fix": "pnpm run lint:fix:prettier && pnpm run lint:fix:eslint",
|
|
@@ -56,12 +57,13 @@
|
|
|
56
57
|
"lint:eslint": "eslint .",
|
|
57
58
|
"lint:fix:eslint": "eslint --fix .",
|
|
58
59
|
"build": "rm -rf dist && pnpm run tsc && cp jsx-runtime.d.ts dist/",
|
|
59
|
-
"tsc": "tsc",
|
|
60
|
+
"tsc": "tsc && tsc -p tests/tsconfig.contract.json",
|
|
60
61
|
"watch": "tsc -w",
|
|
61
62
|
"prepare": "husky",
|
|
62
63
|
"prepack": "pnpm run build",
|
|
63
64
|
"release": "release-it",
|
|
64
|
-
"test:browser": "vitest --config=vitest.browser.config.ts"
|
|
65
|
+
"test:browser": "vitest --config=vitest.browser.config.ts",
|
|
66
|
+
"test:webgl": "vitest run --config=vitest.webgl.config.ts"
|
|
65
67
|
},
|
|
66
68
|
"keywords": [
|
|
67
69
|
"lightning",
|
|
@@ -80,6 +82,7 @@
|
|
|
80
82
|
},
|
|
81
83
|
"devDependencies": {
|
|
82
84
|
"@eslint/js": "^9.39.4",
|
|
85
|
+
"@lightningtv/vite-hex-transform": "^1.1.0",
|
|
83
86
|
"@solid-devtools/debugger": "^0.28.1",
|
|
84
87
|
"@solidjs/testing-library": "^0.8.10",
|
|
85
88
|
"@typescript-eslint/eslint-plugin": "^8.59.2",
|
|
@@ -92,8 +95,10 @@
|
|
|
92
95
|
"husky": "^9.1.7",
|
|
93
96
|
"jsdom": "^26.1.0",
|
|
94
97
|
"lint-staged": "^17.0.4",
|
|
98
|
+
"playwright": "1.56.1",
|
|
95
99
|
"prettier": "^3.8.3",
|
|
96
100
|
"release-it": "^20.0.1",
|
|
101
|
+
"terser": "^5.51.2",
|
|
97
102
|
"typescript": "^6.0.3",
|
|
98
103
|
"typescript-eslint": "^8.59.2",
|
|
99
104
|
"vite": "^8.0.13",
|
|
@@ -109,7 +114,7 @@
|
|
|
109
114
|
},
|
|
110
115
|
"peerDependencies": {
|
|
111
116
|
"@solidjs/router": "^0.16.1",
|
|
112
|
-
"@solidtv/renderer": "^1.
|
|
117
|
+
"@solidtv/renderer": "^1.10.1",
|
|
113
118
|
"solid-js": "*"
|
|
114
119
|
},
|
|
115
120
|
"peerDependenciesMeta": {},
|
package/src/core/config.ts
CHANGED
|
@@ -73,6 +73,17 @@ export interface Config {
|
|
|
73
73
|
lockStyles?: boolean;
|
|
74
74
|
fontWeightAlias?: Record<string, number | string>;
|
|
75
75
|
throttleInput?: number;
|
|
76
|
+
/**
|
|
77
|
+
* For devices that never set `KeyboardEvent.repeat`: while a key is held
|
|
78
|
+
* they send a stream of `repeat=false` key-downs, and one key-up on release.
|
|
79
|
+
* With this set (in ms), a key-down of a key that has had no key-up since
|
|
80
|
+
* its previous key-down, arriving within this many ms of it, is marked as a
|
|
81
|
+
* repeat (`repeat` reads `true`) before anything handles it. It must cover
|
|
82
|
+
* the device's initial auto-repeat delay. A key-up that never arrives stops
|
|
83
|
+
* mattering once the window passes. Off by default: on a key that swallows
|
|
84
|
+
* key-up (webOS OK), a second tap inside the window would read as a repeat.
|
|
85
|
+
*/
|
|
86
|
+
inferKeyRepeat?: number;
|
|
76
87
|
/**
|
|
77
88
|
* Call `preventDefault()` on every key event the app consumed: a handler
|
|
78
89
|
* returned `true`, or the focus manager dropped the press itself (a
|
|
@@ -1358,6 +1358,8 @@ export class DOMNode extends EventEmitter implements IRendererNode {
|
|
|
1358
1358
|
|
|
1359
1359
|
preventCleanup = true;
|
|
1360
1360
|
|
|
1361
|
+
destroyed = false;
|
|
1362
|
+
|
|
1361
1363
|
constructor(
|
|
1362
1364
|
public stage: IRendererStage,
|
|
1363
1365
|
public props: IRendererNodeProps,
|
|
@@ -1380,6 +1382,7 @@ export class DOMNode extends EventEmitter implements IRendererNode {
|
|
|
1380
1382
|
}
|
|
1381
1383
|
|
|
1382
1384
|
destroy(): void {
|
|
1385
|
+
this.markDestroyed();
|
|
1383
1386
|
elMap.delete(this);
|
|
1384
1387
|
const parent = this.props.parent;
|
|
1385
1388
|
if (parent instanceof DOMNode) {
|
|
@@ -1388,6 +1391,14 @@ export class DOMNode extends EventEmitter implements IRendererNode {
|
|
|
1388
1391
|
this.div.parentNode?.removeChild(this.div);
|
|
1389
1392
|
}
|
|
1390
1393
|
|
|
1394
|
+
// Like CoreNode, destroying a node marks its whole subtree destroyed.
|
|
1395
|
+
private markDestroyed() {
|
|
1396
|
+
this.destroyed = true;
|
|
1397
|
+
for (const child of this.children) {
|
|
1398
|
+
child.markDestroyed();
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1391
1402
|
get parent() {
|
|
1392
1403
|
return this.props.parent;
|
|
1393
1404
|
}
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
/** Based on {@link lng.CoreRenderer} */
|
|
13
13
|
export interface IRendererCoreRenderer {
|
|
14
14
|
mode: 'canvas' | 'webgl' | undefined;
|
|
15
|
-
boundsMargin?: number;
|
|
15
|
+
boundsMargin?: number | [number, number, number, number];
|
|
16
16
|
}
|
|
17
17
|
/** Based on {@link lng.TrFontManager} */
|
|
18
18
|
export interface IRendererFontManager {
|
|
@@ -148,9 +148,8 @@ export interface DomRendererMainSettings {
|
|
|
148
148
|
* Preload margin around the viewport, in logical pixels (default: 200)
|
|
149
149
|
*
|
|
150
150
|
* @remarks
|
|
151
|
-
* A single number applied to all sides
|
|
152
|
-
*
|
|
153
|
-
* (the largest edge wins, with a warning) but should be replaced.
|
|
151
|
+
* A single number applied to all sides, or a per-side
|
|
152
|
+
* `[top, right, bottom, left]` tuple.
|
|
154
153
|
*/
|
|
155
|
-
boundsMargin?: number;
|
|
154
|
+
boundsMargin?: number | [number, number, number, number];
|
|
156
155
|
}
|
|
@@ -222,30 +222,19 @@ export function nodeHasTextureSource(node: DOMNode): boolean {
|
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
/**
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
* @remarks
|
|
228
|
-
* The `[top, right, bottom, left]` array form was dropped in renderer 1.8. An
|
|
229
|
-
* untyped app upgrading from 1.7 can still pass it, so mirror the WebGL
|
|
230
|
-
* renderer and take the widest edge rather than letting the margin arithmetic
|
|
231
|
-
* go wrong.
|
|
225
|
+
* Normalize a `boundsMargin` value (scalar or per-side tuple) into a
|
|
226
|
+
* `[top, right, bottom, left]` tuple.
|
|
232
227
|
*/
|
|
233
228
|
export function normalizeBoundsMargin(
|
|
234
229
|
margin: number | number[] | null | undefined,
|
|
235
|
-
): number {
|
|
236
|
-
if (margin == null) return 0;
|
|
237
|
-
if (Array.isArray(margin) === false)
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
for (let i = 0; i < arr.length; i++) {
|
|
241
|
-
if (arr[i]! > max) {
|
|
242
|
-
max = arr[i]!;
|
|
243
|
-
}
|
|
230
|
+
): [number, number, number, number] {
|
|
231
|
+
if (margin == null) return [0, 0, 0, 0];
|
|
232
|
+
if (Array.isArray(margin) === false) {
|
|
233
|
+
const m = (margin as number) || 0;
|
|
234
|
+
return [m, m, m, m];
|
|
244
235
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
);
|
|
248
|
-
return max;
|
|
236
|
+
const arr = margin as number[];
|
|
237
|
+
return [arr[0] || 0, arr[1] || 0, arr[2] || 0, arr[3] || 0];
|
|
249
238
|
}
|
|
250
239
|
|
|
251
240
|
export function computeRenderStateForNode(
|
|
@@ -273,10 +262,10 @@ export function computeRenderStateForNode(
|
|
|
273
262
|
const right = left + width;
|
|
274
263
|
const bottom = top + height;
|
|
275
264
|
|
|
276
|
-
const expandedLeft = rootLeft - margin;
|
|
277
|
-
const expandedTop = rootTop - margin;
|
|
278
|
-
const expandedRight = rootRight + margin;
|
|
279
|
-
const expandedBottom = rootBottom + margin;
|
|
265
|
+
const expandedLeft = rootLeft - margin[3];
|
|
266
|
+
const expandedTop = rootTop - margin[0];
|
|
267
|
+
const expandedRight = rootRight + margin[1];
|
|
268
|
+
const expandedBottom = rootBottom + margin[2];
|
|
280
269
|
|
|
281
270
|
const intersectsBounds =
|
|
282
271
|
right >= expandedLeft &&
|
package/src/core/focusManager.ts
CHANGED
|
@@ -496,6 +496,48 @@ const liftSuppression = (ids: KeyNameOrKeyCode[]): void => {
|
|
|
496
496
|
found.onRelease?.();
|
|
497
497
|
};
|
|
498
498
|
|
|
499
|
+
// Keys down with no key-up yet, for Config.inferKeyRepeat: when each last sent
|
|
500
|
+
// a key-down. Indexed under every identity like suppressedKeys, so a key-up
|
|
501
|
+
// naming the key differently (webOS Back) still ends the press.
|
|
502
|
+
type HeldKey = { ids: KeyNameOrKeyCode[]; time: number };
|
|
503
|
+
const heldKeys = new Map<KeyNameOrKeyCode, HeldKey>();
|
|
504
|
+
|
|
505
|
+
const findHeldKey = (ids: KeyNameOrKeyCode[]): HeldKey | undefined => {
|
|
506
|
+
for (const id of ids) {
|
|
507
|
+
const found = heldKeys.get(id);
|
|
508
|
+
if (found) return found;
|
|
509
|
+
}
|
|
510
|
+
return undefined;
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
// Marks a key-down as a repeat when it follows a key-down of the same key,
|
|
514
|
+
// with no key-up between, by less than `windowMs`. KeyboardEvent.repeat is a
|
|
515
|
+
// read-only getter; an own property shadows it, so handlers, useHold and the
|
|
516
|
+
// suppression check below all read the same value.
|
|
517
|
+
const inferRepeat = (
|
|
518
|
+
e: KeyboardEvent,
|
|
519
|
+
ids: KeyNameOrKeyCode[],
|
|
520
|
+
windowMs: number,
|
|
521
|
+
): void => {
|
|
522
|
+
const now = performance.now();
|
|
523
|
+
const held = findHeldKey(ids);
|
|
524
|
+
if (held === undefined) {
|
|
525
|
+
const entry: HeldKey = { ids, time: now };
|
|
526
|
+
for (const id of ids) heldKeys.set(id, entry);
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
if (!e.repeat && now - held.time < windowMs) {
|
|
530
|
+
Object.defineProperty(e, 'repeat', { value: true });
|
|
531
|
+
}
|
|
532
|
+
held.time = now;
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
const releaseHeldKey = (ids: KeyNameOrKeyCode[]): void => {
|
|
536
|
+
const held = findHeldKey(ids);
|
|
537
|
+
if (!held) return;
|
|
538
|
+
for (const id of held.ids) heldKeys.delete(id);
|
|
539
|
+
};
|
|
540
|
+
|
|
499
541
|
/**
|
|
500
542
|
* Drop auto-repeat key-downs for `keyOrEvent` until the key is released.
|
|
501
543
|
*
|
|
@@ -540,6 +582,9 @@ const handleKeyEvents = (
|
|
|
540
582
|
): boolean => {
|
|
541
583
|
if (keydown) {
|
|
542
584
|
const ids = keyIdentities(keydown);
|
|
585
|
+
if (Config.inferKeyRepeat) {
|
|
586
|
+
inferRepeat(keydown, ids, Config.inferKeyRepeat);
|
|
587
|
+
}
|
|
543
588
|
if (keydown.repeat) {
|
|
544
589
|
if (findSuppression(ids)) return true;
|
|
545
590
|
} else {
|
|
@@ -557,7 +602,9 @@ const handleKeyEvents = (
|
|
|
557
602
|
// The key is up: whatever was suppressing its repeats is done. Settle it
|
|
558
603
|
// before propagating, so a suppressor that is still in the focus path sees
|
|
559
604
|
// its own release callback rather than a second one via the key-up below.
|
|
560
|
-
|
|
605
|
+
const ids = keyIdentities(keyup);
|
|
606
|
+
releaseHeldKey(ids);
|
|
607
|
+
liftSuppression(ids);
|
|
561
608
|
|
|
562
609
|
return propagateKeyPress(
|
|
563
610
|
keyup,
|
|
@@ -658,5 +705,6 @@ export const useFocusManager = (
|
|
|
658
705
|
eventTarget.removeEventListener('keydown', keyPressHandler);
|
|
659
706
|
eventTarget.removeEventListener('keyup', keyUpHandler);
|
|
660
707
|
suppressedKeys.clear();
|
|
708
|
+
heldKeys.clear();
|
|
661
709
|
});
|
|
662
710
|
};
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
* Functions:
|
|
16
16
|
* - `storeFocus(element: ElementNode, prevElement?: ElementNode)`: Stores the provided element in the focus stack.
|
|
17
|
-
* - `restoreFocus()`: Restores focus to the last stored element and removes it from the stack. Returns `true` if successful, `false` otherwise.
|
|
17
|
+
* - `restoreFocus()`: Restores focus to the last stored element and removes it from the stack, skipping (and removing) destroyed elements. Returns `true` if successful, `false` otherwise.
|
|
18
18
|
* - `clearFocusStack()`: Empties the focus stack.
|
|
19
19
|
*/
|
|
20
20
|
import * as s from 'solid-js';
|
|
@@ -41,7 +41,11 @@ export function FocusStackProvider(props: { children: s.JSX.Element}) {
|
|
|
41
41
|
function restoreFocus(): boolean {
|
|
42
42
|
let wasFocused = false;
|
|
43
43
|
setFocusStack((stack) => {
|
|
44
|
-
|
|
44
|
+
let prevElement = stack.pop();
|
|
45
|
+
// Skip elements destroyed since they were stored
|
|
46
|
+
while (prevElement?.destroyed) {
|
|
47
|
+
prevElement = stack.pop();
|
|
48
|
+
}
|
|
45
49
|
if (prevElement && typeof prevElement.setFocus === 'function') {
|
|
46
50
|
prevElement.setFocus();
|
|
47
51
|
wasFocused = true;
|