@solidtv/solid 1.4.1-2 → 1.5.1
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 +6 -1
- package/dist/src/core/dom-renderer/domRenderer.js +15 -5
- package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
- package/dist/src/core/dom-renderer/domRendererUtils.js +0 -2
- package/dist/src/core/dom-renderer/domRendererUtils.js.map +1 -1
- package/dist/src/core/elementNode.d.ts +50 -50
- package/dist/src/core/elementNode.js +3 -3
- package/dist/src/core/elementNode.js.map +1 -1
- package/dist/src/core/focusKeyTypes.d.ts +0 -10
- package/dist/src/core/focusManager.d.ts +2 -2
- package/dist/src/core/focusManager.js +13 -52
- package/dist/src/core/focusManager.js.map +1 -1
- package/dist/src/core/intrinsicTypes.d.ts +2 -2
- package/dist/src/primitives/KeepAlive.d.ts +1 -0
- package/dist/src/primitives/KeepAlive.jsx +9 -2
- package/dist/src/primitives/KeepAlive.jsx.map +1 -1
- package/dist/src/primitives/useFocusManager.d.ts +1 -1
- package/dist/src/primitives/useFocusManager.js +1 -1
- package/dist/src/primitives/useFocusManager.js.map +1 -1
- package/dist/src/primitives/useHold.d.ts +7 -3
- package/dist/src/primitives/useHold.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/core/dom-renderer/domRenderer.ts +14 -5
- package/src/core/dom-renderer/domRendererUtils.ts +0 -1
- package/src/core/elementNode.ts +51 -51
- package/src/core/focusKeyTypes.ts +0 -18
- package/src/core/focusManager.ts +19 -69
- package/src/core/intrinsicTypes.ts +1 -7
- package/src/primitives/KeepAlive.tsx +14 -3
- package/src/primitives/useFocusManager.ts +3 -1
- package/src/primitives/useHold.ts +7 -3
package/src/core/focusManager.ts
CHANGED
|
@@ -3,11 +3,7 @@ import { Config, isDev } from './config.js';
|
|
|
3
3
|
import { IRendererNode } from './dom-renderer/domRendererTypes.js';
|
|
4
4
|
export type * from './focusKeyTypes.js';
|
|
5
5
|
import { ElementNode } from './elementNode.js';
|
|
6
|
-
import type {
|
|
7
|
-
KeyNameOrKeyCode,
|
|
8
|
-
KeyHoldOptions,
|
|
9
|
-
KeyMap,
|
|
10
|
-
} from './focusKeyTypes.js';
|
|
6
|
+
import type { KeyNameOrKeyCode, KeyMap } from './focusKeyTypes.js';
|
|
11
7
|
import { isFunction } from './utils.js';
|
|
12
8
|
import {
|
|
13
9
|
activeElement,
|
|
@@ -30,9 +26,7 @@ const keyMapEntries: KeyMapEntries = {
|
|
|
30
26
|
Escape: 'Escape',
|
|
31
27
|
};
|
|
32
28
|
|
|
33
|
-
const
|
|
34
|
-
// Enter: 'EnterHold',
|
|
35
|
-
};
|
|
29
|
+
const keyOf = (e: KeyboardEvent): KeyNameOrKeyCode => e.key || e.keyCode;
|
|
36
30
|
|
|
37
31
|
const flattenKeyMap = (
|
|
38
32
|
keyMap: Partial<KeyMap>,
|
|
@@ -333,7 +327,6 @@ const runBubblePhase = (
|
|
|
333
327
|
fp: ElementNode[],
|
|
334
328
|
e: KeyboardEvent,
|
|
335
329
|
mappedEvent: string | undefined,
|
|
336
|
-
isHold: boolean,
|
|
337
330
|
isUp: boolean,
|
|
338
331
|
sameKey: boolean,
|
|
339
332
|
currentTime: number,
|
|
@@ -344,11 +337,9 @@ const runBubblePhase = (
|
|
|
344
337
|
? `on${mappedEvent}Release`
|
|
345
338
|
: `on${mappedEvent}`
|
|
346
339
|
: undefined;
|
|
347
|
-
const fallbackHandlerKey: '
|
|
340
|
+
const fallbackHandlerKey: 'onKeyPress' | undefined = isUp
|
|
348
341
|
? undefined
|
|
349
|
-
:
|
|
350
|
-
? 'onKeyHold'
|
|
351
|
-
: 'onKeyPress';
|
|
342
|
+
: 'onKeyPress';
|
|
352
343
|
|
|
353
344
|
let lastHandlerSeen: ElementNode | undefined;
|
|
354
345
|
|
|
@@ -387,11 +378,10 @@ const runBubblePhase = (
|
|
|
387
378
|
const propagateKeyPress = (
|
|
388
379
|
e: KeyboardEvent,
|
|
389
380
|
mappedEvent?: string,
|
|
390
|
-
isHold: boolean = false,
|
|
391
381
|
isUp: boolean = false,
|
|
392
382
|
): boolean => {
|
|
393
383
|
const currentTime = performance.now();
|
|
394
|
-
const key = e
|
|
384
|
+
const key = keyOf(e);
|
|
395
385
|
const sameKey = lastInputKey === key;
|
|
396
386
|
lastInputKey = key;
|
|
397
387
|
|
|
@@ -426,7 +416,6 @@ const propagateKeyPress = (
|
|
|
426
416
|
fp,
|
|
427
417
|
e,
|
|
428
418
|
mappedEvent,
|
|
429
|
-
isHold,
|
|
430
419
|
isUp,
|
|
431
420
|
sameKey,
|
|
432
421
|
currentTime,
|
|
@@ -434,7 +423,7 @@ const propagateKeyPress = (
|
|
|
434
423
|
if (handled) return true;
|
|
435
424
|
|
|
436
425
|
if (isDev && Config.keyDebug && !isUp) {
|
|
437
|
-
const detail = `key="${e.key}", mappedEvent=${mappedEvent},
|
|
426
|
+
const detail = `key="${e.key}", mappedEvent=${mappedEvent}, isUp=${isUp}`;
|
|
438
427
|
if (lastHandlerSeen) {
|
|
439
428
|
console.log(`Keypress bubbled, ${detail}`, lastHandlerSeen);
|
|
440
429
|
} else {
|
|
@@ -445,11 +434,6 @@ const propagateKeyPress = (
|
|
|
445
434
|
return false;
|
|
446
435
|
};
|
|
447
436
|
|
|
448
|
-
const DEFAULT_KEY_HOLD_THRESHOLD = 500; // ms
|
|
449
|
-
const keyHoldTimeouts: { [key: KeyNameOrKeyCode]: number | true } = {};
|
|
450
|
-
|
|
451
|
-
const keyOf = (e: KeyboardEvent): KeyNameOrKeyCode => e.key || e.keyCode;
|
|
452
|
-
|
|
453
437
|
// `key` is not a stable identity for a physical key across key-down and key-up.
|
|
454
438
|
// webOS reports Back's key-down as { key: 'GoBack', keyCode: 461 } and its
|
|
455
439
|
// key-up as { key: 'Unidentified', keyCode: 461 } — same key, two names, with
|
|
@@ -543,13 +527,8 @@ export const releaseKeySuppression = (
|
|
|
543
527
|
liftSuppression(keyIdentities(keyOrEvent));
|
|
544
528
|
};
|
|
545
529
|
|
|
546
|
-
const handleKeyEvents = (
|
|
547
|
-
delay: number,
|
|
548
|
-
keydown?: KeyboardEvent,
|
|
549
|
-
keyup?: KeyboardEvent,
|
|
550
|
-
) => {
|
|
530
|
+
const handleKeyEvents = (keydown?: KeyboardEvent, keyup?: KeyboardEvent) => {
|
|
551
531
|
if (keydown) {
|
|
552
|
-
const key: KeyNameOrKeyCode = keyOf(keydown);
|
|
553
532
|
const ids = keyIdentities(keydown);
|
|
554
533
|
if (keydown.repeat) {
|
|
555
534
|
if (findSuppression(ids)) return;
|
|
@@ -558,52 +537,29 @@ const handleKeyEvents = (
|
|
|
558
537
|
// though its key-up never arrived. Settle it before handling this press.
|
|
559
538
|
liftSuppression(ids);
|
|
560
539
|
}
|
|
561
|
-
const mappedKeyHoldEvent =
|
|
562
|
-
keyHoldMapEntries[keydown.key] || keyHoldMapEntries[keydown.keyCode];
|
|
563
|
-
const mappedKeyEvent =
|
|
564
|
-
keyMapEntries[keydown.key] || keyMapEntries[keydown.keyCode];
|
|
565
|
-
if (mappedKeyHoldEvent) {
|
|
566
|
-
if (!keyHoldTimeouts[key]) {
|
|
567
|
-
keyHoldTimeouts[key] = window.setTimeout(() => {
|
|
568
|
-
keyHoldTimeouts[key] = true;
|
|
569
|
-
propagateKeyPress(keydown, mappedKeyHoldEvent, true);
|
|
570
|
-
}, delay);
|
|
571
|
-
}
|
|
572
|
-
return;
|
|
573
|
-
}
|
|
574
540
|
|
|
575
|
-
propagateKeyPress(
|
|
541
|
+
propagateKeyPress(
|
|
542
|
+
keydown,
|
|
543
|
+
keyMapEntries[keydown.key] || keyMapEntries[keydown.keyCode],
|
|
544
|
+
);
|
|
576
545
|
} else if (keyup) {
|
|
577
|
-
const key: KeyNameOrKeyCode = keyOf(keyup);
|
|
578
546
|
// The key is up: whatever was suppressing its repeats is done. Settle it
|
|
579
547
|
// before propagating, so a suppressor that is still in the focus path sees
|
|
580
548
|
// its own release callback rather than a second one via the key-up below.
|
|
581
549
|
liftSuppression(keyIdentities(keyup));
|
|
582
|
-
const mappedKeyEvent =
|
|
583
|
-
keyMapEntries[keyup.key] || keyMapEntries[keyup.keyCode];
|
|
584
|
-
if (keyHoldTimeouts[key] === true) {
|
|
585
|
-
delete keyHoldTimeouts[key];
|
|
586
|
-
} else if (keyHoldTimeouts[key]) {
|
|
587
|
-
clearTimeout(keyHoldTimeouts[key]);
|
|
588
|
-
delete keyHoldTimeouts[key];
|
|
589
|
-
// trigger key down event when hold didn't finish
|
|
590
|
-
propagateKeyPress(keyup, mappedKeyEvent, false);
|
|
591
|
-
}
|
|
592
550
|
|
|
593
|
-
propagateKeyPress(
|
|
551
|
+
propagateKeyPress(
|
|
552
|
+
keyup,
|
|
553
|
+
keyMapEntries[keyup.key] || keyMapEntries[keyup.keyCode],
|
|
554
|
+
true,
|
|
555
|
+
);
|
|
594
556
|
}
|
|
595
557
|
};
|
|
596
558
|
|
|
597
|
-
export const useFocusManager = (
|
|
598
|
-
userKeyMap?: Partial<KeyMap>,
|
|
599
|
-
keyHoldOptions?: KeyHoldOptions,
|
|
600
|
-
) => {
|
|
559
|
+
export const useFocusManager = (userKeyMap?: Partial<KeyMap>) => {
|
|
601
560
|
if (userKeyMap) {
|
|
602
561
|
flattenKeyMap(userKeyMap, keyMapEntries);
|
|
603
562
|
}
|
|
604
|
-
if (keyHoldOptions?.userKeyHoldMap) {
|
|
605
|
-
flattenKeyMap(keyHoldOptions.userKeyHoldMap, keyHoldMapEntries);
|
|
606
|
-
}
|
|
607
563
|
|
|
608
564
|
// Capture the calling owner so signal updates and key-event reactions
|
|
609
565
|
// can run inside it — needed for programmatic .setFocus(), post-mutation
|
|
@@ -619,13 +575,10 @@ export const useFocusManager = (
|
|
|
619
575
|
Config.setActiveElement = (elm) =>
|
|
620
576
|
ownerContext(() => setActiveElementSignal(elm));
|
|
621
577
|
|
|
622
|
-
const delay = keyHoldOptions?.holdThreshold || DEFAULT_KEY_HOLD_THRESHOLD;
|
|
623
|
-
const runKeyEvent = handleKeyEvents.bind(null, delay);
|
|
624
|
-
|
|
625
578
|
const keyPressHandler = (event: KeyboardEvent) =>
|
|
626
|
-
ownerContext(() =>
|
|
579
|
+
ownerContext(() => handleKeyEvents(event, undefined));
|
|
627
580
|
const keyUpHandler = (event: KeyboardEvent) =>
|
|
628
|
-
ownerContext(() =>
|
|
581
|
+
ownerContext(() => handleKeyEvents(undefined, event));
|
|
629
582
|
|
|
630
583
|
document.addEventListener('keydown', keyPressHandler);
|
|
631
584
|
document.addEventListener('keyup', keyUpHandler);
|
|
@@ -633,9 +586,6 @@ export const useFocusManager = (
|
|
|
633
586
|
onCleanup(() => {
|
|
634
587
|
document.removeEventListener('keydown', keyPressHandler);
|
|
635
588
|
document.removeEventListener('keyup', keyUpHandler);
|
|
636
|
-
for (const timeout of Object.values(keyHoldTimeouts)) {
|
|
637
|
-
if (timeout && timeout !== true) clearTimeout(timeout);
|
|
638
|
-
}
|
|
639
589
|
suppressedKeys.clear();
|
|
640
590
|
});
|
|
641
591
|
};
|
|
@@ -10,12 +10,7 @@ import {
|
|
|
10
10
|
ShaderRoundedProps,
|
|
11
11
|
ShaderShadowProps,
|
|
12
12
|
} from './shaders.js';
|
|
13
|
-
import {
|
|
14
|
-
EventHandlers,
|
|
15
|
-
DefaultKeyMap,
|
|
16
|
-
KeyHoldMap,
|
|
17
|
-
FocusNode,
|
|
18
|
-
} from './focusKeyTypes.js';
|
|
13
|
+
import { EventHandlers, DefaultKeyMap, FocusNode } from './focusKeyTypes.js';
|
|
19
14
|
import type { JSXElement } from 'solid-js';
|
|
20
15
|
|
|
21
16
|
export type AnimationSettings = Partial<lngr.AnimationSettings>;
|
|
@@ -123,7 +118,6 @@ export interface NodeProps
|
|
|
123
118
|
extends
|
|
124
119
|
RendererNode,
|
|
125
120
|
EventHandlers<DefaultKeyMap>,
|
|
126
|
-
EventHandlers<KeyHoldMap>,
|
|
127
121
|
FocusNode,
|
|
128
122
|
Partial<
|
|
129
123
|
NewOmit<
|
|
@@ -14,6 +14,10 @@ export interface KeepAliveElement {
|
|
|
14
14
|
isAlive?: s.Accessor<boolean>;
|
|
15
15
|
setIsAlive?: (v: boolean) => void;
|
|
16
16
|
dispose?: () => void;
|
|
17
|
+
// Focused node captured on route exit so it can be refocused on re-entry.
|
|
18
|
+
// Stored here (rather than in a KeepAliveRoute closure) so it becomes
|
|
19
|
+
// garbage as soon as the entry is dropped from the map.
|
|
20
|
+
savedFocusedElement?: ElementNode;
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
const keepAliveElements = new Map<string, KeepAliveElement>();
|
|
@@ -199,8 +203,6 @@ export const KeepAliveRoute = <S extends string>(
|
|
|
199
203
|
return cached;
|
|
200
204
|
}
|
|
201
205
|
|
|
202
|
-
let savedFocusedElement: ElementNode | undefined;
|
|
203
|
-
|
|
204
206
|
const getExisting = (): KeepAliveElement => {
|
|
205
207
|
let existing = keepAliveRouteElements.get(key);
|
|
206
208
|
if (!existing) {
|
|
@@ -212,11 +214,20 @@ export const KeepAliveRoute = <S extends string>(
|
|
|
212
214
|
};
|
|
213
215
|
|
|
214
216
|
const onRemove = chainFunctions(props.onRemove, (elm: ElementNode) => {
|
|
215
|
-
|
|
217
|
+
const existing = keepAliveRouteElements.get(key);
|
|
218
|
+
if (existing) {
|
|
219
|
+
existing.savedFocusedElement = activeElement();
|
|
220
|
+
}
|
|
216
221
|
elm.alpha = 0;
|
|
217
222
|
});
|
|
218
223
|
|
|
219
224
|
const onRender = chainFunctions(props.onRender, (elm: ElementNode) => {
|
|
225
|
+
const existing = keepAliveRouteElements.get(key);
|
|
226
|
+
const savedFocusedElement = existing?.savedFocusedElement;
|
|
227
|
+
if (existing) {
|
|
228
|
+
existing.savedFocusedElement = undefined;
|
|
229
|
+
}
|
|
230
|
+
|
|
220
231
|
let isChild = false;
|
|
221
232
|
let current = savedFocusedElement;
|
|
222
233
|
while (current) {
|
|
@@ -4,7 +4,9 @@ export {
|
|
|
4
4
|
setActiveElementCore,
|
|
5
5
|
suppressKeyUntilRelease,
|
|
6
6
|
releaseKeySuppression,
|
|
7
|
+
printFocusHistory,
|
|
8
|
+
getFocusHistory,
|
|
9
|
+
type FocusHistoryEntry,
|
|
7
10
|
type KeyMap,
|
|
8
|
-
type KeyHoldOptions,
|
|
9
11
|
} from '../core/focusManager.js';
|
|
10
12
|
export { activeElement, setActiveElement } from '../core/activeElement.js';
|
|
@@ -31,9 +31,13 @@ export type UseHoldProps = {
|
|
|
31
31
|
*
|
|
32
32
|
* `true` (default): a press with neither key-up nor auto-repeat by the
|
|
33
33
|
* threshold resolves as a tap. `false`: it resolves as a hold, matching the
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
34
|
+
* behavior of the removed `keyHoldOptions`.
|
|
35
|
+
*
|
|
36
|
+
* Set this to `false` for a key that emits no auto-repeat but does emit
|
|
37
|
+
* key-up on real release: the timer alone can then resolve the hold. It does
|
|
38
|
+
* *not* rescue a key that emits key-up immediately at press time (LG's Back
|
|
39
|
+
* button does this) — that key-up cancels the timer before it fires, and no
|
|
40
|
+
* setting can distinguish such a tap from a hold.
|
|
37
41
|
*/
|
|
38
42
|
holdRequiresRepeat?: boolean;
|
|
39
43
|
};
|