@solidtv/solid 1.4.1-1 → 1.4.1-2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidtv/solid",
3
- "version": "1.4.1-1",
3
+ "version": "1.4.1-2",
4
4
  "description": "SolidTV",
5
5
  "type": "module",
6
6
  "exports": {
@@ -450,47 +450,27 @@ const keyHoldTimeouts: { [key: KeyNameOrKeyCode]: number | true } = {};
450
450
 
451
451
  const keyOf = (e: KeyboardEvent): KeyNameOrKeyCode => e.key || e.keyCode;
452
452
 
453
- // Keys this platform has actually been seen delivering a key-up for.
454
- //
455
- // Whether a hold can be detected by timer alone comes down to this. If a key
456
- // delivers key-up, reaching the hold threshold without one means the key is
457
- // genuinely still down, and no auto-repeat is needed to confirm the hold. If it
458
- // does not (webOS OK), a press that is already over is indistinguishable from
459
- // one still held, so only an auto-repeat can confirm it.
460
- //
461
- // This is per-key, not per-platform: webOS emits auto-repeat for OK but not for
462
- // Back, and swallows key-up for OK but not for Back.
463
- const keysSeenReleasing = new Set<KeyNameOrKeyCode>();
464
-
465
- /**
466
- * Record that `keyOrEvent` delivered a key-up. The focus manager calls this for
467
- * every key-up it sees; call it directly only when driving key events without
468
- * {@link useFocusManager}.
469
- */
470
- export const noteKeyUpDelivered = (
453
+ // `key` is not a stable identity for a physical key across key-down and key-up.
454
+ // webOS reports Back's key-down as { key: 'GoBack', keyCode: 461 } and its
455
+ // key-up as { key: 'Unidentified', keyCode: 461 } — same key, two names, with
456
+ // only the keyCode shared. So a key is identified by *every* name its event
457
+ // carries, and two events are the same key if any identity matches.
458
+ const UNIDENTIFIED = 'Unidentified';
459
+
460
+ const keyIdentities = (
471
461
  keyOrEvent: KeyboardEvent | KeyNameOrKeyCode,
472
- ): void => {
473
- keysSeenReleasing.add(
474
- typeof keyOrEvent === 'object' ? keyOf(keyOrEvent) : keyOrEvent,
475
- );
462
+ ): KeyNameOrKeyCode[] => {
463
+ if (typeof keyOrEvent !== 'object') return [keyOrEvent];
464
+ const ids: KeyNameOrKeyCode[] = [];
465
+ // 'Unidentified' names no particular key. Treating it as an identity would
466
+ // conflate every key that reports it.
467
+ if (keyOrEvent.key && keyOrEvent.key !== UNIDENTIFIED)
468
+ ids.push(keyOrEvent.key);
469
+ if (keyOrEvent.keyCode) ids.push(keyOrEvent.keyCode);
470
+ return ids;
476
471
  };
477
472
 
478
- /**
479
- * Whether this key has been observed delivering a key-up in this session.
480
- *
481
- * `false` for a key not yet pressed — absence of evidence, not evidence that the
482
- * key never releases. Callers that need a decision before any press has been
483
- * observed should be told the answer explicitly rather than inferring it.
484
- */
485
- export const keyDeliversKeyUp = (
486
- keyOrEvent: KeyboardEvent | KeyNameOrKeyCode,
487
- ): boolean =>
488
- keysSeenReleasing.has(
489
- typeof keyOrEvent === 'object' ? keyOf(keyOrEvent) : keyOrEvent,
490
- );
491
-
492
- // Keys whose auto-repeat key-downs are dropped before propagation, mapped to an
493
- // optional callback run when the key is finally released.
473
+ // Keys whose auto-repeat key-downs are dropped before propagation.
494
474
  //
495
475
  // A hold action typically moves focus (opening a context menu, say) while the
496
476
  // key is still physically down. Two things then go wrong, and neither can be
@@ -502,12 +482,29 @@ export const keyDeliversKeyUp = (
502
482
  // Both are propagation concerns, so the latch lives here. The release callback
503
483
  // is what lets a suppressor still learn about a key-up it can no longer receive
504
484
  // through the focus path.
505
- const suppressedKeys = new Map<KeyNameOrKeyCode, (() => void) | undefined>();
485
+ type Suppression = {
486
+ ids: KeyNameOrKeyCode[];
487
+ onRelease?: () => void;
488
+ };
506
489
 
507
- const liftSuppression = (key: KeyNameOrKeyCode): void => {
508
- const onRelease = suppressedKeys.get(key);
509
- suppressedKeys.delete(key);
510
- onRelease?.();
490
+ // Indexed under every identity of the suppressed key, so a key-up naming the
491
+ // key differently still finds it. Entries for one key share a Suppression.
492
+ const suppressedKeys = new Map<KeyNameOrKeyCode, Suppression>();
493
+
494
+ const findSuppression = (ids: KeyNameOrKeyCode[]): Suppression | undefined => {
495
+ for (const id of ids) {
496
+ const found = suppressedKeys.get(id);
497
+ if (found) return found;
498
+ }
499
+ return undefined;
500
+ };
501
+
502
+ const liftSuppression = (ids: KeyNameOrKeyCode[]): void => {
503
+ const found = findSuppression(ids);
504
+ if (!found) return;
505
+ // Drop every alias, not just the one that matched.
506
+ for (const id of found.ids) suppressedKeys.delete(id);
507
+ found.onRelease?.();
511
508
  };
512
509
 
513
510
  /**
@@ -519,6 +516,10 @@ const liftSuppression = (key: KeyNameOrKeyCode): void => {
519
516
  * when suppression lifts, whichever way it lifts, and is delivered regardless of
520
517
  * where focus has moved in the meantime.
521
518
  *
519
+ * Pass the `KeyboardEvent` where you have one: the key is then matched on both
520
+ * its name and its keyCode, which is what lets a key-up reporting a different
521
+ * `key` for the same physical key (webOS Back) still lift the suppression.
522
+ *
522
523
  * `useHold` calls this itself when a hold fires; call it directly only when
523
524
  * implementing hold behavior outside that primitive.
524
525
  */
@@ -526,10 +527,10 @@ export const suppressKeyUntilRelease = (
526
527
  keyOrEvent: KeyboardEvent | KeyNameOrKeyCode,
527
528
  onRelease?: () => void,
528
529
  ): void => {
529
- suppressedKeys.set(
530
- typeof keyOrEvent === 'object' ? keyOf(keyOrEvent) : keyOrEvent,
531
- onRelease,
532
- );
530
+ const ids = keyIdentities(keyOrEvent);
531
+ if (ids.length === 0) return;
532
+ const suppression: Suppression = { ids, onRelease };
533
+ for (const id of ids) suppressedKeys.set(id, suppression);
533
534
  };
534
535
 
535
536
  /**
@@ -539,9 +540,7 @@ export const suppressKeyUntilRelease = (
539
540
  export const releaseKeySuppression = (
540
541
  keyOrEvent: KeyboardEvent | KeyNameOrKeyCode,
541
542
  ): void => {
542
- liftSuppression(
543
- typeof keyOrEvent === 'object' ? keyOf(keyOrEvent) : keyOrEvent,
544
- );
543
+ liftSuppression(keyIdentities(keyOrEvent));
545
544
  };
546
545
 
547
546
  const handleKeyEvents = (
@@ -551,12 +550,13 @@ const handleKeyEvents = (
551
550
  ) => {
552
551
  if (keydown) {
553
552
  const key: KeyNameOrKeyCode = keyOf(keydown);
553
+ const ids = keyIdentities(keydown);
554
554
  if (keydown.repeat) {
555
- if (suppressedKeys.has(key)) return;
556
- } else if (suppressedKeys.has(key)) {
555
+ if (findSuppression(ids)) return;
556
+ } else {
557
557
  // A fresh press starts a new gesture, so the previous one is over even
558
558
  // though its key-up never arrived. Settle it before handling this press.
559
- liftSuppression(key);
559
+ liftSuppression(ids);
560
560
  }
561
561
  const mappedKeyHoldEvent =
562
562
  keyHoldMapEntries[keydown.key] || keyHoldMapEntries[keydown.keyCode];
@@ -575,11 +575,10 @@ const handleKeyEvents = (
575
575
  propagateKeyPress(keydown, mappedKeyEvent, false);
576
576
  } else if (keyup) {
577
577
  const key: KeyNameOrKeyCode = keyOf(keyup);
578
- keysSeenReleasing.add(key);
579
578
  // The key is up: whatever was suppressing its repeats is done. Settle it
580
579
  // before propagating, so a suppressor that is still in the focus path sees
581
580
  // its own release callback rather than a second one via the key-up below.
582
- if (suppressedKeys.has(key)) liftSuppression(key);
581
+ liftSuppression(keyIdentities(keyup));
583
582
  const mappedKeyEvent =
584
583
  keyMapEntries[keyup.key] || keyMapEntries[keyup.keyCode];
585
584
  if (keyHoldTimeouts[key] === true) {
@@ -4,8 +4,6 @@ export {
4
4
  setActiveElementCore,
5
5
  suppressKeyUntilRelease,
6
6
  releaseKeySuppression,
7
- keyDeliversKeyUp,
8
- noteKeyUpDelivered,
9
7
  type KeyMap,
10
8
  type KeyHoldOptions,
11
9
  } from '../core/focusManager.js';
@@ -1,9 +1,5 @@
1
1
  import { createMemo } from 'solid-js';
2
- import {
3
- suppressKeyUntilRelease,
4
- keyDeliversKeyUp,
5
- noteKeyUpDelivered,
6
- } from '../core/focusManager.js';
2
+ import { suppressKeyUntilRelease } from '../core/focusManager.js';
7
3
  import type { ElementNode } from '../core/elementNode.js';
8
4
 
9
5
  /**
@@ -33,21 +29,13 @@ export type UseHoldProps = {
33
29
  /**
34
30
  * Whether a hold must be confirmed by an auto-repeat key-down.
35
31
  *
36
- * - `'auto'` (default): use auto-repeat if the key needs it, otherwise resolve
37
- * by timer. A key that has been seen delivering key-up needs no auto-repeat —
38
- * reaching the threshold without a key-up means it is still down. A key that
39
- * swallows key-up does need one, since a finished press is otherwise
40
- * indistinguishable from one still held.
41
- * - `false`: always resolve by timer, matching the legacy `keyHoldOptions`
42
- * behavior. Deterministic from the very first press.
43
- * - `true`: require an auto-repeat, never resolving a repeat-less press as a
44
- * hold.
45
- *
46
- * `'auto'` infers from keys seen earlier in the session, so the first press of
47
- * a key resolves as a tap. Set this explicitly for a key you already know —
48
- * e.g. `false` for Back on webOS, which emits no auto-repeat.
32
+ * `true` (default): a press with neither key-up nor auto-repeat by the
33
+ * threshold resolves as a tap. `false`: it resolves as a hold, matching the
34
+ * legacy `keyHoldOptions` behavior. Set this to `false` on platforms whose
35
+ * remote input layer delivers no auto-repeat, where a hold gesture would
36
+ * otherwise be unreachable.
49
37
  */
50
- holdRequiresRepeat?: boolean | 'auto';
38
+ holdRequiresRepeat?: boolean;
51
39
  };
52
40
 
53
41
  /**
@@ -62,16 +50,11 @@ export type UseHoldProps = {
62
50
  * when the timer fires it resolves to a hold → `onHold`.
63
51
  * - if key-up arrives before the timer, it's a tap → `onEnter` (fires
64
52
  * immediately, no latency, on platforms that deliver key-up).
65
- * - if the timer fires with neither, the key is either still held or already
66
- * released with its key-up swallowed. `holdRequiresRepeat` decides which, and
67
- * by default (`'auto'`) infers it: a key known to deliver key-up must still be
68
- * down, so it resolves to a hold by timer alone; a key that swallows key-up
69
- * resolves to a tap, keeping the primary action working on webOS OK at the
70
- * cost of ~`holdThreshold` ms latency.
71
- *
72
- * Auto-repeat is therefore used where it exists and not required where it does
73
- * not — webOS emits it for OK but not for Back, so Back holds resolve by timer
74
- * while OK holds are confirmed by repeat.
53
+ * - if neither key-up nor auto-repeat arrives, the timer resolves to a tap →
54
+ * `onEnter` after `holdThreshold` ms. This is the key-up-independent path that
55
+ * keeps taps working on webOS, at the cost of ~`holdThreshold` ms latency.
56
+ * Set `holdRequiresRepeat: false` to resolve this ambiguous case as a hold
57
+ * instead, on platforms that deliver no auto-repeat at all.
75
58
  *
76
59
  * Once `onHold` fires the key is still physically down, so the focus manager
77
60
  * drops its remaining auto-repeats until it is released. Without that, a hold
@@ -113,18 +96,7 @@ export function useHold(props: UseHoldProps): [HoldHandler, HoldHandler] {
113
96
  const performOnEnterImmediately = createMemo(
114
97
  () => props.performOnEnterImmediately ?? false,
115
98
  );
116
- const holdRequiresRepeat = createMemo(
117
- () => props.holdRequiresRepeat ?? 'auto',
118
- );
119
-
120
- // At the threshold with no auto-repeat seen, is this press still held (a hold)
121
- // or already over with its key-up swallowed (a tap)? Only a key that delivers
122
- // key-up can answer that on its own.
123
- const requiresRepeat = (e: KeyboardEvent | undefined) => {
124
- const mode = holdRequiresRepeat();
125
- if (mode !== 'auto') return mode;
126
- return !(e !== undefined && keyDeliversKeyUp(e));
127
- };
99
+ const holdRequiresRepeat = createMemo(() => props.holdRequiresRepeat ?? true);
128
100
 
129
101
  let holdTimeout = -1;
130
102
  let enterFired = false; // onEnter already fired for this press
@@ -174,7 +146,7 @@ export function useHold(props: UseHoldProps): [HoldHandler, HoldHandler] {
174
146
 
175
147
  holdTimeout = setTimeout(() => {
176
148
  holdTimeout = -1;
177
- if (repeated || !requiresRepeat(e)) {
149
+ if (repeated || !holdRequiresRepeat()) {
178
150
  // Held past the threshold → hold gesture.
179
151
  holdFired = true;
180
152
  // The key is still down and will keep repeating. Drop those repeats so
@@ -194,11 +166,6 @@ export function useHold(props: UseHoldProps): [HoldHandler, HoldHandler] {
194
166
  };
195
167
 
196
168
  const releaseHold: HoldHandler = (e, target, handlerElm) => {
197
- // Reaching here at all is proof this key delivers key-up, which is what
198
- // `'auto'` reads. The focus manager records this too; doing it here as well
199
- // keeps `'auto'` working behind a custom focus manager.
200
- if (e) noteKeyUpDelivered(e);
201
-
202
169
  if (holdTimeout !== -1) {
203
170
  // Released before the threshold → tap. Fires immediately where key-up is
204
171
  // delivered, avoiding the timer latency.