@solidtv/solid 1.6.1 → 1.6.3
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/elementNode.js +13 -11
- package/dist/src/core/elementNode.js.map +1 -1
- package/dist/src/core/focusManager.d.ts +20 -1
- package/dist/src/core/focusManager.js +7 -5
- package/dist/src/core/focusManager.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/primitives/LazyImport.d.ts +8 -2
- package/dist/src/primitives/LazyImport.js +70 -24
- package/dist/src/primitives/LazyImport.js.map +1 -1
- package/dist/src/primitives/useFocusManager.d.ts +1 -1
- package/dist/src/primitives/useFocusManager.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/core/elementNode.ts +14 -12
- package/src/core/focusManager.ts +41 -9
- package/src/index.ts +6 -1
- package/src/primitives/LazyImport.ts +78 -28
- package/src/primitives/useFocusManager.ts +2 -0
package/package.json
CHANGED
package/src/core/elementNode.ts
CHANGED
|
@@ -1062,7 +1062,7 @@ export class ElementNode {
|
|
|
1062
1062
|
): IAnimationController {
|
|
1063
1063
|
if (!this.rendered) {
|
|
1064
1064
|
if (isDev) console.log('NOT RENDERED! CANNOT ANIMATE');
|
|
1065
|
-
return {} as IAnimationController;
|
|
1065
|
+
return { start: () => {} } as IAnimationController;
|
|
1066
1066
|
}
|
|
1067
1067
|
return (this.lng as IRendererNode).animate(
|
|
1068
1068
|
props,
|
|
@@ -1667,18 +1667,20 @@ export class ElementNode {
|
|
|
1667
1667
|
flexDirection === 'row' || flexDirection === 'row-reverse';
|
|
1668
1668
|
flexFitsWidth = isFlexRow && node.flexBoundary !== 'fixed';
|
|
1669
1669
|
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
if (
|
|
1670
|
+
// Every justify mode except flexStart positions children out of the
|
|
1671
|
+
// container's free space. Shrinking to fit leaves none, so fall back
|
|
1672
|
+
// to filling the parent unless the developer explicitly asked to
|
|
1673
|
+
// contain — in which case honor it and warn about the contradiction.
|
|
1674
|
+
if (
|
|
1675
|
+
flexFitsWidth &&
|
|
1676
|
+
node.justifyContent !== undefined &&
|
|
1677
|
+
node.justifyContent !== 'flexStart'
|
|
1678
|
+
) {
|
|
1679
|
+
if (node.flexBoundary === undefined) {
|
|
1680
|
+
flexFitsWidth = false;
|
|
1681
|
+
} else if (isDev) {
|
|
1680
1682
|
console.warn(
|
|
1681
|
-
`justifyContent '${node.justifyContent}'
|
|
1683
|
+
`justifyContent '${node.justifyContent}' has no free space to distribute on a flexBoundary 'contain' container without an explicit width: `,
|
|
1682
1684
|
this,
|
|
1683
1685
|
);
|
|
1684
1686
|
}
|
package/src/core/focusManager.ts
CHANGED
|
@@ -558,7 +558,37 @@ const handleKeyEvents = (keydown?: KeyboardEvent, keyup?: KeyboardEvent) => {
|
|
|
558
558
|
}
|
|
559
559
|
};
|
|
560
560
|
|
|
561
|
-
|
|
561
|
+
/**
|
|
562
|
+
* What the focus manager reads off a key event. A browser's `KeyboardEvent`
|
|
563
|
+
* has these; a host without a DOM raises objects that carry at least them,
|
|
564
|
+
* and key handlers receive whichever object the host raised.
|
|
565
|
+
*/
|
|
566
|
+
export interface KeyEventLike {
|
|
567
|
+
readonly key: string;
|
|
568
|
+
readonly keyCode: number;
|
|
569
|
+
readonly repeat: boolean;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Where {@link useFocusManager} listens for `keydown` and `keyup`: `document`
|
|
574
|
+
* in a browser, or anything with the same two methods on a host without one,
|
|
575
|
+
* such as a native key bridge.
|
|
576
|
+
*/
|
|
577
|
+
export interface KeyEventTarget {
|
|
578
|
+
addEventListener(
|
|
579
|
+
type: 'keydown' | 'keyup',
|
|
580
|
+
listener: (event: KeyEventLike) => void,
|
|
581
|
+
): void;
|
|
582
|
+
removeEventListener(
|
|
583
|
+
type: 'keydown' | 'keyup',
|
|
584
|
+
listener: (event: KeyEventLike) => void,
|
|
585
|
+
): void;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
export const useFocusManager = (
|
|
589
|
+
userKeyMap?: Partial<KeyMap>,
|
|
590
|
+
target: KeyEventTarget = document,
|
|
591
|
+
) => {
|
|
562
592
|
if (userKeyMap) {
|
|
563
593
|
flattenKeyMap(userKeyMap, keyMapEntries);
|
|
564
594
|
}
|
|
@@ -577,17 +607,19 @@ export const useFocusManager = (userKeyMap?: Partial<KeyMap>) => {
|
|
|
577
607
|
Config.setActiveElement = (elm) =>
|
|
578
608
|
ownerContext(() => setActiveElementSignal(elm));
|
|
579
609
|
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
const
|
|
583
|
-
ownerContext(() => handleKeyEvents(
|
|
610
|
+
// Handlers are typed as KeyboardEvent throughout; on a host that raises
|
|
611
|
+
// its own objects they see those, which carry the fields read here.
|
|
612
|
+
const keyPressHandler = (event: KeyEventLike) =>
|
|
613
|
+
ownerContext(() => handleKeyEvents(event as KeyboardEvent, undefined));
|
|
614
|
+
const keyUpHandler = (event: KeyEventLike) =>
|
|
615
|
+
ownerContext(() => handleKeyEvents(undefined, event as KeyboardEvent));
|
|
584
616
|
|
|
585
|
-
|
|
586
|
-
|
|
617
|
+
target.addEventListener('keydown', keyPressHandler);
|
|
618
|
+
target.addEventListener('keyup', keyUpHandler);
|
|
587
619
|
|
|
588
620
|
onCleanup(() => {
|
|
589
|
-
|
|
590
|
-
|
|
621
|
+
target.removeEventListener('keydown', keyPressHandler);
|
|
622
|
+
target.removeEventListener('keyup', keyUpHandler);
|
|
591
623
|
suppressedKeys.clear();
|
|
592
624
|
});
|
|
593
625
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
export type * from '@solidtv/solid/jsx-runtime';
|
|
2
2
|
export * from './core/index.js';
|
|
3
3
|
export type * from './core/index.js';
|
|
4
|
-
export type {
|
|
4
|
+
export type {
|
|
5
|
+
KeyEventLike,
|
|
6
|
+
KeyEventTarget,
|
|
7
|
+
KeyHandler,
|
|
8
|
+
KeyMap,
|
|
9
|
+
} from './core/focusManager.js';
|
|
5
10
|
export { activeElement, setActiveElement } from './core/activeElement.js';
|
|
6
11
|
export { setActiveElementCore } from './core/focusManager.js';
|
|
7
12
|
export * from './utils.js';
|
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
createResource,
|
|
4
4
|
createMemo,
|
|
5
5
|
untrack,
|
|
6
|
-
Component,
|
|
7
|
-
JSX,
|
|
6
|
+
type Component,
|
|
7
|
+
type JSX,
|
|
8
8
|
sharedConfig,
|
|
9
9
|
} from 'solid-js';
|
|
10
10
|
|
|
@@ -31,14 +31,31 @@ const NATIVE_ESM_CHUNK =
|
|
|
31
31
|
* @internal Exported for tests. The primitives barrel re-exports `lazy` by
|
|
32
32
|
* name, so this stays out of the package's public API.
|
|
33
33
|
*/
|
|
34
|
-
export const cacheBustableUrl = (error: unknown): string | undefined =>
|
|
35
|
-
NATIVE_ESM_CHUNK.exec(
|
|
34
|
+
export const cacheBustableUrl = (error: unknown): string | undefined => {
|
|
35
|
+
const match = NATIVE_ESM_CHUNK.exec(
|
|
36
36
|
error instanceof Error ? error.message : String(error),
|
|
37
|
-
)
|
|
37
|
+
);
|
|
38
|
+
return match ? match[1] : undefined;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Retry backoff delays in milliseconds (500ms, 2s, 5s). Max of 3 retries.
|
|
43
|
+
*
|
|
44
|
+
* @internal Exported for tests — see `cacheBustableUrl`.
|
|
45
|
+
*/
|
|
46
|
+
export const RETRY_DELAYS = [500, 2000, 5000];
|
|
38
47
|
|
|
39
48
|
/** @internal Exported for tests — see `cacheBustableUrl`. */
|
|
40
|
-
export const cacheBust = (url: string): string =>
|
|
41
|
-
|
|
49
|
+
export const cacheBust = (url: string, retry = 1): string => {
|
|
50
|
+
const cleanUrl = url
|
|
51
|
+
.replace(/([?&])chunkRetry=\d+(&|$)/, '$1')
|
|
52
|
+
.replace(/[?&]$/, '');
|
|
53
|
+
const separator = cleanUrl.indexOf('?') === -1 ? '?' : '&';
|
|
54
|
+
return cleanUrl + separator + 'chunkRetry=' + retry;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const wait = (ms: number): Promise<void> =>
|
|
58
|
+
new Promise((resolve) => setTimeout(resolve, ms));
|
|
42
59
|
|
|
43
60
|
/**
|
|
44
61
|
* A dynamic `import()`, built at runtime instead of written inline.
|
|
@@ -83,12 +100,12 @@ export function lazy<T extends Component<any>>(
|
|
|
83
100
|
let comp: () => T | undefined;
|
|
84
101
|
let p: Promise<{ default: T }> | undefined;
|
|
85
102
|
|
|
86
|
-
// Retry the import
|
|
87
|
-
//
|
|
88
|
-
//
|
|
89
|
-
// rejection is replayed for the rest of
|
|
90
|
-
// again, not even on a later navigation.
|
|
91
|
-
//
|
|
103
|
+
// Retry the import up to 3 times before giving up, with a backoff of 500ms, 2s,
|
|
104
|
+
// and 5s between retries. On a TV the chunk fetch is the fragile part — a brief
|
|
105
|
+
// dropout as the viewer presses OK on a rail rejects the import, and because
|
|
106
|
+
// `p` memoises the promise that single rejection is replayed for the rest of
|
|
107
|
+
// the session: the route never renders again, not even on a later navigation.
|
|
108
|
+
// Retries with backoff turn transient failures into a slightly delayed navigation.
|
|
92
109
|
//
|
|
93
110
|
// How it retries depends on which module system failed, because the two need
|
|
94
111
|
// opposite things.
|
|
@@ -101,26 +118,59 @@ export function lazy<T extends Component<any>>(
|
|
|
101
118
|
//
|
|
102
119
|
// Native ESM does the opposite. The module map memoises the *failure*, so a
|
|
103
120
|
// second `import()` of the same specifier resolves straight to the cached
|
|
104
|
-
// rejection without ever touching the network —
|
|
105
|
-
// where it is needed. It also names one module and only one, the one
|
|
106
|
-
// `import()`, so a cache-busted re-import of it is both safe and
|
|
107
|
-
//
|
|
121
|
+
// rejection without ever touching the network — re-running `fn` is a no-op
|
|
122
|
+
// exactly where it is needed. It also names one module and only one, the one
|
|
123
|
+
// handed to `import()`, so a cache-busted re-import of it is both safe and
|
|
124
|
+
// necessary: each retry gets a distinct URL (`chunkRetry=1`, `chunkRetry=2`,
|
|
125
|
+
// `chunkRetry=3`), creating a fresh module-map entry that really re-fetches.
|
|
108
126
|
//
|
|
109
127
|
// The cost there is a duplicate module record for this one chunk. Its own
|
|
110
128
|
// imports are unaffected — they resolve to their normal, already-cached URLs —
|
|
111
129
|
// so the duplication does not spread, and it only happens on a retry that
|
|
112
130
|
// would otherwise have left the route dead.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
131
|
+
//
|
|
132
|
+
// Written using explicit Promise chaining instead of `async`/`await` so older
|
|
133
|
+
// engines (such as Chrome 38/53 on webOS) and ES5 downleveling do not require
|
|
134
|
+
// regeneratorRuntime or complex state-machine transpilation helpers.
|
|
135
|
+
const load = (): Promise<{ default: T }> => {
|
|
136
|
+
let url: string | undefined;
|
|
137
|
+
|
|
138
|
+
const attemptLoad = (attempt: number): Promise<{ default: T }> => {
|
|
139
|
+
let p: Promise<{ default: T }>;
|
|
140
|
+
try {
|
|
141
|
+
if (attempt === 0) {
|
|
142
|
+
p = fn();
|
|
143
|
+
} else if (url !== undefined) {
|
|
144
|
+
// Null when this engine cannot compile a dynamic import, or a CSP
|
|
145
|
+
// forbids compiling one — see `getNativeImport`. Re-running the
|
|
146
|
+
// loader is then the best available retry, exactly as it is for
|
|
147
|
+
// every SystemJS failure.
|
|
148
|
+
const importer = getNativeImport();
|
|
149
|
+
p = (
|
|
150
|
+
importer !== null ? importer(cacheBust(url, attempt)) : fn()
|
|
151
|
+
) as Promise<{ default: T }>;
|
|
152
|
+
} else {
|
|
153
|
+
p = fn();
|
|
154
|
+
}
|
|
155
|
+
} catch (syncError: unknown) {
|
|
156
|
+
p = Promise.reject(syncError);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return p.catch((error: unknown) => {
|
|
160
|
+
const nextUrl = cacheBustableUrl(error);
|
|
161
|
+
url = nextUrl !== undefined ? nextUrl : url;
|
|
162
|
+
if (attempt < RETRY_DELAYS.length) {
|
|
163
|
+
const delay = RETRY_DELAYS[attempt];
|
|
164
|
+
if (delay !== undefined) {
|
|
165
|
+
return wait(delay).then(() => attemptLoad(attempt + 1));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return Promise.reject(error);
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
return attemptLoad(0);
|
|
173
|
+
};
|
|
124
174
|
|
|
125
175
|
const wrap: T & { preload?: () => void } = ((props: any) => {
|
|
126
176
|
const ctx = sharedConfig.context;
|