@solidtv/solid 1.3.3 → 1.3.5
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/primitives/Column.jsx +1 -1
- package/dist/src/primitives/Column.jsx.map +1 -1
- package/dist/src/primitives/announcer/speech.js +28 -38
- package/dist/src/primitives/announcer/speech.js.map +1 -1
- package/dist/src/primitives/types.d.ts +5 -0
- package/dist/src/primitives/useHold.d.ts +20 -3
- package/dist/src/primitives/useHold.js +65 -16
- package/dist/src/primitives/useHold.js.map +1 -1
- package/dist/src/primitives/utils/withScrolling.d.ts +1 -0
- package/dist/src/primitives/utils/withScrolling.js +11 -2
- package/dist/src/primitives/utils/withScrolling.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/primitives/Column.tsx +6 -6
- package/src/primitives/announcer/speech.ts +57 -40
- package/src/primitives/types.ts +6 -0
- package/src/primitives/useHold.ts +68 -15
- package/src/primitives/utils/withScrolling.ts +13 -3
package/package.json
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { type Component } from 'solid-js';
|
|
2
|
-
import {
|
|
3
|
-
ElementNode,
|
|
4
|
-
combineStyles,
|
|
5
|
-
type NodeStyles,
|
|
6
|
-
} from '@solidtv/solid';
|
|
2
|
+
import { ElementNode, combineStyles, type NodeStyles } from '@solidtv/solid';
|
|
7
3
|
import {
|
|
8
4
|
navigableForwardFocus,
|
|
9
5
|
handleNavigation,
|
|
@@ -20,7 +16,11 @@ const ColumnStyles: NodeStyles = {
|
|
|
20
16
|
gap: 30,
|
|
21
17
|
};
|
|
22
18
|
|
|
23
|
-
function scrollToIndex(
|
|
19
|
+
function scrollToIndex(
|
|
20
|
+
this: ElementNode,
|
|
21
|
+
index: number,
|
|
22
|
+
options?: { noFocus?: boolean },
|
|
23
|
+
): void {
|
|
24
24
|
this.selected = index;
|
|
25
25
|
scrollColumn(index, this);
|
|
26
26
|
if (!options?.noFocus) {
|
|
@@ -17,7 +17,15 @@ type AriaLabel = { text: string; lang: string };
|
|
|
17
17
|
const ARIA_PARENT_ID = 'aria-parent';
|
|
18
18
|
let ariaLabelPhrases: AriaLabel[] = [];
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
// An Error carrying the structured speech-synthesis error code (e.g.
|
|
21
|
+
// "interrupted", "canceled", "network"). We reject with this instead of the
|
|
22
|
+
// raw SpeechSynthesisErrorEvent so callers can classify the failure without
|
|
23
|
+
// depending on the SpeechSynthesisErrorEvent global, which isn't defined on
|
|
24
|
+
// every TV browser.
|
|
25
|
+
interface SpeechError extends Error {
|
|
26
|
+
error?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
21
29
|
function flattenStrings(series: SpeechType[] = []): SpeechType[] {
|
|
22
30
|
const flattenedSeries = [];
|
|
23
31
|
|
|
@@ -153,13 +161,50 @@ function speak(
|
|
|
153
161
|
resolve();
|
|
154
162
|
};
|
|
155
163
|
utterance.onerror = (e) => {
|
|
156
|
-
|
|
164
|
+
const error: SpeechError = new Error(
|
|
165
|
+
`Speech synthesis error: ${e.error}`,
|
|
166
|
+
);
|
|
167
|
+
// Preserve the code so speakSeries can tell benign interruptions
|
|
168
|
+
// ("interrupted"/"canceled") apart from real failures ("network", etc.).
|
|
169
|
+
error.error = e.error;
|
|
170
|
+
reject(error);
|
|
157
171
|
};
|
|
158
172
|
utterances.push(utterance);
|
|
159
173
|
synth.speak(utterance);
|
|
160
174
|
});
|
|
161
175
|
}
|
|
162
176
|
|
|
177
|
+
/**
|
|
178
|
+
* @description Classify a caught speech error and apply back-off.
|
|
179
|
+
* Returns the retries remaining after handling. `interrupted`/`canceled` are
|
|
180
|
+
* benign — a newer announcement cancelled or replaced the in-flight one (see
|
|
181
|
+
* synth.cancel()), which happens constantly during directional navigation — so
|
|
182
|
+
* we stop retrying without surfacing them. `network` errors back off and retry.
|
|
183
|
+
* Anything else is genuinely unexpected and is rethrown.
|
|
184
|
+
*/
|
|
185
|
+
async function handleSpeechError(
|
|
186
|
+
e: unknown,
|
|
187
|
+
retriesLeft: number,
|
|
188
|
+
totalRetries: number,
|
|
189
|
+
): Promise<number> {
|
|
190
|
+
const code = (e as SpeechError | undefined)?.error;
|
|
191
|
+
|
|
192
|
+
if (code === 'network') {
|
|
193
|
+
retriesLeft--;
|
|
194
|
+
console.warn(
|
|
195
|
+
`Speech synthesis network error. Retries left: ${retriesLeft}`,
|
|
196
|
+
);
|
|
197
|
+
await delay(500 * (totalRetries - retriesLeft));
|
|
198
|
+
return retriesLeft;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (code === 'canceled' || code === 'interrupted') {
|
|
202
|
+
return 0; // benign — stop retrying, don't propagate
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
throw e;
|
|
206
|
+
}
|
|
207
|
+
|
|
163
208
|
function speakSeries(
|
|
164
209
|
series: SpeechType,
|
|
165
210
|
aria: boolean,
|
|
@@ -203,25 +248,11 @@ function speakSeries(
|
|
|
203
248
|
else await speak(phrase, utterances, lang, voice);
|
|
204
249
|
retriesLeft = 0; // Exit retry loop on success
|
|
205
250
|
} catch (e) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
);
|
|
212
|
-
await delay(500 * (totalRetries - retriesLeft));
|
|
213
|
-
} else if (
|
|
214
|
-
e.error === 'canceled' ||
|
|
215
|
-
e.error === 'interrupted'
|
|
216
|
-
) {
|
|
217
|
-
// Cancel or interrupt error (ignore)
|
|
218
|
-
retriesLeft = 0;
|
|
219
|
-
} else {
|
|
220
|
-
throw new Error(`SpeechSynthesisErrorEvent: ${e.error}`);
|
|
221
|
-
}
|
|
222
|
-
} else {
|
|
223
|
-
throw e;
|
|
224
|
-
}
|
|
251
|
+
retriesLeft = await handleSpeechError(
|
|
252
|
+
e,
|
|
253
|
+
retriesLeft,
|
|
254
|
+
totalRetries,
|
|
255
|
+
);
|
|
225
256
|
}
|
|
226
257
|
}
|
|
227
258
|
} else if (phrase instanceof SpeechSynthesisUtterance) {
|
|
@@ -241,25 +272,11 @@ function speakSeries(
|
|
|
241
272
|
retriesLeft = 0; // Exit retry loop on success
|
|
242
273
|
}
|
|
243
274
|
} catch (e) {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
);
|
|
250
|
-
await delay(500 * (totalRetries - retriesLeft));
|
|
251
|
-
} else if (
|
|
252
|
-
e.error === 'canceled' ||
|
|
253
|
-
e.error === 'interrupted'
|
|
254
|
-
) {
|
|
255
|
-
// Cancel or interrupt error (ignore)
|
|
256
|
-
retriesLeft = 0;
|
|
257
|
-
} else {
|
|
258
|
-
throw new Error(`SpeechSynthesisErrorEvent: ${e.error}`);
|
|
259
|
-
}
|
|
260
|
-
} else {
|
|
261
|
-
throw e;
|
|
262
|
-
}
|
|
275
|
+
retriesLeft = await handleSpeechError(
|
|
276
|
+
e,
|
|
277
|
+
retriesLeft,
|
|
278
|
+
totalRetries,
|
|
279
|
+
);
|
|
263
280
|
}
|
|
264
281
|
}
|
|
265
282
|
} else if (typeof phrase === 'function') {
|
package/src/primitives/types.ts
CHANGED
|
@@ -25,6 +25,12 @@ export interface NavigableProps extends NodeProps {
|
|
|
25
25
|
/** When auto scrolling, item index at which scrolling begins */
|
|
26
26
|
scrollIndex?: number;
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* When true and scroll is 'edge' or 'auto', the last item keeps the same
|
|
30
|
+
* position as the second-to-last instead of scrolling to remove trailing space.
|
|
31
|
+
*/
|
|
32
|
+
scrollStopLast?: boolean;
|
|
33
|
+
|
|
28
34
|
/** The initial index */
|
|
29
35
|
selected?: number;
|
|
30
36
|
|
|
@@ -9,13 +9,30 @@ export type UseHoldProps = {
|
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
+
* Distinguishes a tap from a press-and-hold for a single key, without depending
|
|
13
|
+
* on the key-up event. This matters on TV platforms (notably LG webOS) where the
|
|
14
|
+
* OK button does not reliably emit a key-up, so any tap logic gated on key-up
|
|
15
|
+
* (`onEnterRelease`) would never run and the card would never open.
|
|
16
|
+
*
|
|
17
|
+
* How a press resolves:
|
|
18
|
+
* - key-down starts the hold timer.
|
|
19
|
+
* - an auto-repeat key-down before the timer fires marks the key as still held;
|
|
20
|
+
* when the timer fires it resolves to a hold → `onHold`.
|
|
21
|
+
* - if key-up arrives before the timer, it's a tap → `onEnter` (fires
|
|
22
|
+
* immediately, no latency, on platforms that deliver key-up).
|
|
23
|
+
* - if neither key-up nor auto-repeat arrives, the timer resolves to a tap →
|
|
24
|
+
* `onEnter` after `holdThreshold` ms. This is the key-up-independent path that
|
|
25
|
+
* keeps taps working on webOS, at the cost of ~`holdThreshold` ms latency.
|
|
26
|
+
*
|
|
27
|
+
* `performOnEnterImmediately` keeps the legacy behavior of firing `onEnter` on
|
|
28
|
+
* key-down; a long-press then fires both `onEnter` and `onHold`.
|
|
29
|
+
*
|
|
12
30
|
* @example
|
|
13
31
|
* const [holdRight, releaseRight] = useHold({
|
|
14
32
|
* onHold: handleHoldRight,
|
|
15
33
|
* onEnter: handleOnRight,
|
|
16
34
|
* onRelease: handleReleaseHold,
|
|
17
35
|
* holdThreshold: 200,
|
|
18
|
-
* performOnEnterImmediately: true
|
|
19
36
|
* });
|
|
20
37
|
*
|
|
21
38
|
* <view
|
|
@@ -24,7 +41,7 @@ export type UseHoldProps = {
|
|
|
24
41
|
* />
|
|
25
42
|
*
|
|
26
43
|
* @param {UseHoldProps} props - The properties for configuring the hold behavior.
|
|
27
|
-
* @returns {[() => boolean, () => boolean]} A tuple containing `startHold` and `releaseHold` functions.
|
|
44
|
+
* @returns {[(e?: KeyboardEvent) => boolean, () => boolean]} A tuple containing `startHold` and `releaseHold` functions.
|
|
28
45
|
*/
|
|
29
46
|
|
|
30
47
|
export function useHold(props: UseHoldProps) {
|
|
@@ -34,32 +51,68 @@ export function useHold(props: UseHoldProps) {
|
|
|
34
51
|
);
|
|
35
52
|
|
|
36
53
|
let holdTimeout = -1;
|
|
37
|
-
let
|
|
54
|
+
let enterFired = false; // onEnter already fired for this press
|
|
55
|
+
let holdFired = false; // onHold already fired for this press
|
|
56
|
+
let repeated = false; // an auto-repeat key-down was seen (key still held)
|
|
57
|
+
|
|
58
|
+
const reset = () => {
|
|
59
|
+
if (holdTimeout !== -1) {
|
|
60
|
+
clearTimeout(holdTimeout);
|
|
61
|
+
holdTimeout = -1;
|
|
62
|
+
}
|
|
63
|
+
enterFired = false;
|
|
64
|
+
holdFired = false;
|
|
65
|
+
repeated = false;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const startHold = (e?: KeyboardEvent) => {
|
|
69
|
+
// Auto-repeat key-down: the key is still held. Record it so the timer
|
|
70
|
+
// resolves to a hold even if the key-up event never arrives (webOS).
|
|
71
|
+
if (e?.repeat) {
|
|
72
|
+
repeated = true;
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Fresh key-down begins a new press. Reset first so a previous press whose
|
|
77
|
+
// key-up was never delivered doesn't leave us wedged for this one.
|
|
78
|
+
reset();
|
|
38
79
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
80
|
+
if (performOnEnterImmediately()) {
|
|
81
|
+
enterFired = true;
|
|
82
|
+
props.onEnter();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
holdTimeout = setTimeout(() => {
|
|
86
|
+
holdTimeout = -1;
|
|
87
|
+
if (repeated) {
|
|
88
|
+
// Held past the threshold → hold gesture.
|
|
89
|
+
holdFired = true;
|
|
90
|
+
props.onHold();
|
|
91
|
+
} else if (!enterFired) {
|
|
92
|
+
// No key-up and no auto-repeat arrived: resolve as a tap so the
|
|
93
|
+
// primary action still fires on remotes that swallow key-up.
|
|
94
|
+
enterFired = true;
|
|
42
95
|
props.onEnter();
|
|
43
96
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
props.onHold();
|
|
47
|
-
}, holdThreshold()) as unknown as number;
|
|
48
|
-
}
|
|
97
|
+
}, holdThreshold()) as unknown as number;
|
|
98
|
+
|
|
49
99
|
return true;
|
|
50
100
|
};
|
|
51
101
|
|
|
52
102
|
const releaseHold = () => {
|
|
53
103
|
if (holdTimeout !== -1) {
|
|
104
|
+
// Released before the threshold → tap. Fires immediately where key-up is
|
|
105
|
+
// delivered, avoiding the timer latency.
|
|
54
106
|
clearTimeout(holdTimeout);
|
|
55
107
|
holdTimeout = -1;
|
|
56
|
-
if (!
|
|
57
|
-
|
|
58
|
-
|
|
108
|
+
if (!enterFired) {
|
|
109
|
+
enterFired = true;
|
|
110
|
+
props.onEnter();
|
|
59
111
|
}
|
|
112
|
+
} else if (holdFired) {
|
|
60
113
|
props.onRelease?.();
|
|
61
|
-
wasHeld = false;
|
|
62
114
|
}
|
|
115
|
+
reset();
|
|
63
116
|
return true;
|
|
64
117
|
};
|
|
65
118
|
|
|
@@ -28,11 +28,12 @@ export interface ScrollableElement extends ElementNode {
|
|
|
28
28
|
_targetPosition?: number;
|
|
29
29
|
_screenOffset?: number;
|
|
30
30
|
_initialPosition?: number;
|
|
31
|
+
scrollStopLast?: boolean;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
// From the renderer, not exported
|
|
34
35
|
const InViewPort = 8 as const;
|
|
35
|
-
const isNotShown = (node: ElementNode | ElementText) => {
|
|
36
|
+
const isNotShown = (node: ElementNode | ElementText): boolean => {
|
|
36
37
|
return (node.lng.renderState as number) !== InViewPort;
|
|
37
38
|
};
|
|
38
39
|
/*
|
|
@@ -185,7 +186,11 @@ export function withScrolling(isRow: boolean): Scroller {
|
|
|
185
186
|
nextPosition = Math.min(Math.max(centerPosition, maxOffset), offset);
|
|
186
187
|
} else if (!nextElement) {
|
|
187
188
|
// If at the last element, align to end
|
|
188
|
-
|
|
189
|
+
if (componentRef.scrollStopLast && isIncrementing) {
|
|
190
|
+
nextPosition = rootPosition - selectedSize - gap;
|
|
191
|
+
} else {
|
|
192
|
+
nextPosition = isIncrementing ? maxOffset : offset;
|
|
193
|
+
}
|
|
189
194
|
} else if (scroll === 'auto') {
|
|
190
195
|
if (componentRef.scrollIndex && componentRef.scrollIndex > 0) {
|
|
191
196
|
// Prevent scrolling if the selected item is within the last scrollIndex items
|
|
@@ -213,8 +218,13 @@ export function withScrolling(isRow: boolean): Scroller {
|
|
|
213
218
|
}
|
|
214
219
|
|
|
215
220
|
// Prevent container from moving beyond bounds
|
|
221
|
+
const isScrollStopLastCase =
|
|
222
|
+
componentRef.scrollStopLast && !nextElement && isIncrementing;
|
|
216
223
|
nextPosition =
|
|
217
|
-
isIncrementing &&
|
|
224
|
+
isIncrementing &&
|
|
225
|
+
scroll !== 'always' &&
|
|
226
|
+
scroll !== 'bounded' &&
|
|
227
|
+
!isScrollStopLastCase
|
|
218
228
|
? Math.max(nextPosition, maxOffset)
|
|
219
229
|
: Math.min(nextPosition, offset);
|
|
220
230
|
|