@solidtv/solid 1.1.3 → 1.2.0
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 +7 -1
- package/dist/src/core/config.js +7 -1
- package/dist/src/core/config.js.map +1 -1
- package/dist/src/core/dom-renderer/domRenderer.js +1 -0
- package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
- package/dist/src/core/dom-renderer/domRendererUtils.js +2 -2
- package/dist/src/core/dom-renderer/domRendererUtils.js.map +1 -1
- package/dist/src/core/elementNode.d.ts +10 -4
- package/dist/src/core/elementNode.js +59 -44
- package/dist/src/core/elementNode.js.map +1 -1
- package/dist/src/core/focusManager.d.ts +3 -9
- package/dist/src/core/focusManager.js +106 -98
- package/dist/src/core/focusManager.js.map +1 -1
- package/dist/src/core/lightningInit.js +3 -3
- package/dist/src/core/lightningInit.js.map +1 -1
- package/dist/src/core/shaders.js +10 -10
- package/dist/src/core/shaders.js.map +1 -1
- package/dist/src/core/utils.d.ts +0 -1
- package/dist/src/core/utils.js +0 -1
- package/dist/src/core/utils.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/primitives/useFocusManager.d.ts +1 -5
- package/dist/src/primitives/useFocusManager.js +1 -20
- package/dist/src/primitives/useFocusManager.js.map +1 -1
- package/dist/src/primitives/useMouse.js +4 -4
- package/dist/src/primitives/useMouse.js.map +1 -1
- package/dist/src/render.js +1 -3
- package/dist/src/render.js.map +1 -1
- package/dist/src/solidOpts.d.ts +1 -1
- package/dist/src/solidOpts.js +4 -23
- package/dist/src/solidOpts.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/core/config.ts +9 -2
- package/src/core/dom-renderer/domRenderer.ts +1 -0
- package/src/core/dom-renderer/domRendererUtils.ts +2 -2
- package/src/core/elementNode.ts +65 -40
- package/src/core/focusManager.ts +155 -137
- package/src/core/lightningInit.ts +3 -3
- package/src/core/shaders.ts +10 -10
- package/src/core/utils.ts +0 -3
- package/src/index.ts +1 -1
- package/src/primitives/useFocusManager.ts +5 -44
- package/src/primitives/useMouse.ts +4 -4
- package/src/render.ts +1 -3
- package/src/solidOpts.ts +4 -25
- package/dist/src/activeElement.d.ts +0 -2
- package/dist/src/activeElement.js +0 -3
- package/dist/src/activeElement.js.map +0 -1
- package/src/activeElement.ts +0 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidtv/solid",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "SolidTV",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
},
|
|
110
110
|
"peerDependencies": {
|
|
111
111
|
"@solidjs/router": "^0.16.1",
|
|
112
|
-
"@solidtv/renderer": "^1.
|
|
112
|
+
"@solidtv/renderer": "^1.2.3",
|
|
113
113
|
"solid-js": "*"
|
|
114
114
|
},
|
|
115
115
|
"peerDependenciesMeta": {},
|
package/src/core/config.ts
CHANGED
|
@@ -33,6 +33,15 @@ export const SHADERS_ENABLED =
|
|
|
33
33
|
typeof SOLIDTV_DISABLE_SHADERS === 'undefined' ||
|
|
34
34
|
SOLIDTV_DISABLE_SHADERS !== true;
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* True when the DOM renderer is both built in (`DOM_RENDERING`) and turned on
|
|
38
|
+
* at runtime (`Config.domRendererEnabled`). `Config.domRendererEnabled` is
|
|
39
|
+
* mutable up until the renderer starts, so this is a function rather than a
|
|
40
|
+
* constant.
|
|
41
|
+
*/
|
|
42
|
+
export const isDomRendererActive = () =>
|
|
43
|
+
DOM_RENDERING && Config.domRendererEnabled;
|
|
44
|
+
|
|
36
45
|
/**
|
|
37
46
|
RUNTIME LIGHTNING CONFIGURATION \
|
|
38
47
|
This configuration can be set at runtime, but it is recommended to set it
|
|
@@ -48,7 +57,6 @@ export interface Config {
|
|
|
48
57
|
animationsEnabled: boolean;
|
|
49
58
|
fontSettings: Partial<TextProps>;
|
|
50
59
|
rendererOptions?: Partial<RendererMainSettings> | DomRendererMainSettings;
|
|
51
|
-
setActiveElement: (elm: ElementNode) => void;
|
|
52
60
|
focusStateKey: DollarString;
|
|
53
61
|
lockStyles?: boolean;
|
|
54
62
|
fontWeightAlias?: Record<string, number | string>;
|
|
@@ -83,7 +91,6 @@ export const Config: Config = {
|
|
|
83
91
|
bold: 700,
|
|
84
92
|
black: 900,
|
|
85
93
|
},
|
|
86
|
-
setActiveElement: () => {},
|
|
87
94
|
focusStateKey: '$focus',
|
|
88
95
|
lockStyles: true,
|
|
89
96
|
rendererOptions: {},
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as lng from '@solidtv/renderer';
|
|
3
3
|
import { Config } from '../config.js';
|
|
4
4
|
import { DOMNode } from './domRenderer.js';
|
|
5
|
-
import {
|
|
5
|
+
import { isFunction } from '../utils.js';
|
|
6
6
|
|
|
7
7
|
// #region Color & Gradient Utils
|
|
8
8
|
|
|
@@ -160,7 +160,7 @@ export function applyEasing(
|
|
|
160
160
|
easing: string | lng.TimingFunction,
|
|
161
161
|
progress: number,
|
|
162
162
|
): number {
|
|
163
|
-
if (
|
|
163
|
+
if (isFunction(easing)) {
|
|
164
164
|
return easing(progress);
|
|
165
165
|
}
|
|
166
166
|
|
package/src/core/elementNode.ts
CHANGED
|
@@ -25,7 +25,6 @@ const calculateFlex = import.meta.env?.VITE_USE_NEW_FLEX
|
|
|
25
25
|
import {
|
|
26
26
|
log,
|
|
27
27
|
isArray,
|
|
28
|
-
isFunc,
|
|
29
28
|
keyExists,
|
|
30
29
|
isINode,
|
|
31
30
|
isElementNode,
|
|
@@ -34,7 +33,12 @@ import {
|
|
|
34
33
|
isFunction,
|
|
35
34
|
spliceItem,
|
|
36
35
|
} from './utils.js';
|
|
37
|
-
import {
|
|
36
|
+
import {
|
|
37
|
+
Config,
|
|
38
|
+
isDev,
|
|
39
|
+
SHADERS_ENABLED,
|
|
40
|
+
isDomRendererActive,
|
|
41
|
+
} from './config.js';
|
|
38
42
|
import type {
|
|
39
43
|
RendererMain,
|
|
40
44
|
INode,
|
|
@@ -78,9 +82,20 @@ let postMutationQueued = false;
|
|
|
78
82
|
let nextActiveElement: ElementNode | null = null;
|
|
79
83
|
let deferredFocusElement: ElementNode | null = null;
|
|
80
84
|
const layoutQueue = new Set<ElementNode>();
|
|
81
|
-
|
|
85
|
+
const elementDeleteQueue: ElementNode[] = [];
|
|
82
86
|
|
|
83
|
-
export function
|
|
87
|
+
export function enqueueDelete(node: ElementNode, n: number): void {
|
|
88
|
+
if (node._queueDelete === undefined) {
|
|
89
|
+
node._queueDelete = n;
|
|
90
|
+
if (elementDeleteQueue.push(node) === 1) {
|
|
91
|
+
schedulePostMutation();
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
node._queueDelete += n;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function schedulePostMutation() {
|
|
84
99
|
if (postMutationQueued) return;
|
|
85
100
|
postMutationQueued = true;
|
|
86
101
|
if ('reprocessUpdates' in renderer.stage && renderer.stage.reprocessUpdates) {
|
|
@@ -95,7 +110,7 @@ function runPostMutation() {
|
|
|
95
110
|
// Phase 1: delete-flush
|
|
96
111
|
if (elementDeleteQueue.length > 0) {
|
|
97
112
|
for (const el of elementDeleteQueue) {
|
|
98
|
-
if (
|
|
113
|
+
if ((el._queueDelete ?? 0) < 0) {
|
|
99
114
|
el.destroy();
|
|
100
115
|
}
|
|
101
116
|
el._queueDelete = undefined;
|
|
@@ -153,6 +168,15 @@ function buildFontTemplate() {
|
|
|
153
168
|
_fontTemplate = tpl;
|
|
154
169
|
}
|
|
155
170
|
|
|
171
|
+
const EFFECT_SHADER_KEYS = [
|
|
172
|
+
'border',
|
|
173
|
+
'borderTop',
|
|
174
|
+
'borderRight',
|
|
175
|
+
'borderBottom',
|
|
176
|
+
'borderLeft',
|
|
177
|
+
'shadow',
|
|
178
|
+
] as const satisfies ReadonlyArray<keyof StyleEffects>;
|
|
179
|
+
|
|
156
180
|
const parseAndAssignShaderProps = (
|
|
157
181
|
prefix: string,
|
|
158
182
|
obj: Record<string, unknown>,
|
|
@@ -200,7 +224,7 @@ function getPropertyAlias(name: string) {
|
|
|
200
224
|
return name;
|
|
201
225
|
}
|
|
202
226
|
|
|
203
|
-
|
|
227
|
+
const LightningRendererNumberProps = [
|
|
204
228
|
'alpha',
|
|
205
229
|
'color',
|
|
206
230
|
'colorTop',
|
|
@@ -299,7 +323,6 @@ export interface ElementNode extends RendererNode, FocusNode {
|
|
|
299
323
|
// Properties
|
|
300
324
|
/** @internal for managing series of insertions and deletions */
|
|
301
325
|
_queueDelete?: number;
|
|
302
|
-
preserve?: boolean;
|
|
303
326
|
_animationQueue?:
|
|
304
327
|
| Array<{
|
|
305
328
|
props: Partial<INodeAnimateProps<CoreShaderNode>>;
|
|
@@ -806,6 +829,25 @@ export class ElementNode {
|
|
|
806
829
|
return this.lng.shader;
|
|
807
830
|
}
|
|
808
831
|
|
|
832
|
+
/**
|
|
833
|
+
* Commit a built shader-props target back to `this.lng.shader`. When the
|
|
834
|
+
* node is already rendered we either convert the props into a real shader
|
|
835
|
+
* (first time) or self-assign so the DOM renderer's setter reapplies style;
|
|
836
|
+
* pre-render we just attach the bag for the upcoming `render()`.
|
|
837
|
+
*/
|
|
838
|
+
_writeShaderTarget(target: unknown) {
|
|
839
|
+
if (this.rendered) {
|
|
840
|
+
if (!this.lng.shader) {
|
|
841
|
+
this.lng.shader = Config.convertToShader(this, target as StyleEffects);
|
|
842
|
+
} else if (isDomRendererActive()) {
|
|
843
|
+
// eslint-disable-next-line no-self-assign -- lng.shader is a setter, force style update
|
|
844
|
+
this.lng.shader = this.lng.shader;
|
|
845
|
+
}
|
|
846
|
+
} else {
|
|
847
|
+
this.lng.shader = target;
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
|
|
809
851
|
set effects(v: StyleEffects) {
|
|
810
852
|
if (!SHADERS_ENABLED) return;
|
|
811
853
|
let target = this.lng.shader || {};
|
|
@@ -814,27 +856,11 @@ export class ElementNode {
|
|
|
814
856
|
}
|
|
815
857
|
if (v.rounded) target.radius = v.rounded.radius;
|
|
816
858
|
if (v.borderRadius) target.radius = v.borderRadius;
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
parseAndAssignShaderProps('borderTop', v.borderTop, target);
|
|
820
|
-
if (v.borderRight)
|
|
821
|
-
parseAndAssignShaderProps('borderRight', v.borderRight, target);
|
|
822
|
-
if (v.borderBottom)
|
|
823
|
-
parseAndAssignShaderProps('borderBottom', v.borderBottom, target);
|
|
824
|
-
if (v.borderLeft)
|
|
825
|
-
parseAndAssignShaderProps('borderLeft', v.borderLeft, target);
|
|
826
|
-
if (v.shadow) parseAndAssignShaderProps('shadow', v.shadow, target);
|
|
827
|
-
|
|
828
|
-
if (this.rendered) {
|
|
829
|
-
if (!this.lng.shader) {
|
|
830
|
-
this.lng.shader = Config.convertToShader(this, target);
|
|
831
|
-
} else if (DOM_RENDERING && Config.domRendererEnabled) {
|
|
832
|
-
// eslint-disable-next-line no-self-assign -- lng.shader is a setter, force style update
|
|
833
|
-
this.lng.shader = this.lng.shader;
|
|
834
|
-
}
|
|
835
|
-
} else {
|
|
836
|
-
this.lng.shader = target;
|
|
859
|
+
for (const k of EFFECT_SHADER_KEYS) {
|
|
860
|
+
if (v[k]) parseAndAssignShaderProps(k, v[k], target);
|
|
837
861
|
}
|
|
862
|
+
|
|
863
|
+
this._writeShaderTarget(target);
|
|
838
864
|
}
|
|
839
865
|
|
|
840
866
|
set id(id: string) {
|
|
@@ -1094,7 +1120,7 @@ export class ElementNode {
|
|
|
1094
1120
|
if (this.rendered) {
|
|
1095
1121
|
// can be 0
|
|
1096
1122
|
if (this.forwardFocus !== undefined) {
|
|
1097
|
-
if (
|
|
1123
|
+
if (isFunction(this.forwardFocus)) {
|
|
1098
1124
|
if (this.forwardFocus.call(this, this) !== false) {
|
|
1099
1125
|
return;
|
|
1100
1126
|
}
|
|
@@ -1274,6 +1300,14 @@ export class ElementNode {
|
|
|
1274
1300
|
return this.alpha === 0;
|
|
1275
1301
|
}
|
|
1276
1302
|
|
|
1303
|
+
get preserve(): boolean {
|
|
1304
|
+
return this._queueDelete === 0;
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
set preserve(v: boolean) {
|
|
1308
|
+
this._queueDelete = v ? 0 : undefined;
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1277
1311
|
/**
|
|
1278
1312
|
* Sets the autofocus state of the element.
|
|
1279
1313
|
* When set to a truthy value, the element will automatically gain focus.
|
|
@@ -1352,7 +1386,7 @@ export class ElementNode {
|
|
|
1352
1386
|
const flexChanged = this.display === 'flex' && calculateFlex(this);
|
|
1353
1387
|
layoutQueue.delete(this);
|
|
1354
1388
|
const onLayoutChanged =
|
|
1355
|
-
|
|
1389
|
+
isFunction(this.onLayout) && this.onLayout.call(this, this);
|
|
1356
1390
|
|
|
1357
1391
|
if ((flexChanged || onLayoutChanged) && this.parent) {
|
|
1358
1392
|
addToLayoutQueue(this.parent);
|
|
@@ -1364,7 +1398,7 @@ export class ElementNode {
|
|
|
1364
1398
|
if (c.display === 'flex' && isElementNode(c)) {
|
|
1365
1399
|
// calculating directly to prevent infinite loops recalculating parents
|
|
1366
1400
|
calculateFlex(c);
|
|
1367
|
-
|
|
1401
|
+
isFunction(c.onLayout) && c.onLayout.call(c, c);
|
|
1368
1402
|
addToLayoutQueue(this);
|
|
1369
1403
|
}
|
|
1370
1404
|
});
|
|
@@ -1774,16 +1808,7 @@ export function shaderAccessor<T extends Record<string, any> | number>(
|
|
|
1774
1808
|
parseAndAssignShaderProps(key, value, target);
|
|
1775
1809
|
}
|
|
1776
1810
|
|
|
1777
|
-
|
|
1778
|
-
if (!this.lng.shader) {
|
|
1779
|
-
this.lng.shader = Config.convertToShader(this, target);
|
|
1780
|
-
} else if (DOM_RENDERING && Config.domRendererEnabled) {
|
|
1781
|
-
// eslint-disable-next-line no-self-assign -- lng.shader is a setter, force style update
|
|
1782
|
-
this.lng.shader = this.lng.shader;
|
|
1783
|
-
}
|
|
1784
|
-
} else {
|
|
1785
|
-
this.lng.shader = target;
|
|
1786
|
-
}
|
|
1811
|
+
this._writeShaderTarget(target);
|
|
1787
1812
|
|
|
1788
1813
|
if (animationSettings) {
|
|
1789
1814
|
this.animate({ shaderProps: target }, animationSettings).start();
|
package/src/core/focusManager.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createSignal, getOwner, onCleanup, runWithOwner } from 'solid-js';
|
|
1
2
|
import { Config, isDev } from './config.js';
|
|
2
3
|
import { IRendererNode } from './dom-renderer/domRendererTypes.js';
|
|
3
4
|
export type * from './focusKeyTypes.js';
|
|
@@ -9,6 +10,12 @@ import type {
|
|
|
9
10
|
} from './focusKeyTypes.js';
|
|
10
11
|
import { isFunction } from './utils.js';
|
|
11
12
|
|
|
13
|
+
export const [activeElement, setActiveElementSignal] = createSignal<
|
|
14
|
+
ElementNode | undefined
|
|
15
|
+
>(undefined);
|
|
16
|
+
|
|
17
|
+
let _signalWrapper: (cb: () => void) => void = (cb) => cb();
|
|
18
|
+
|
|
12
19
|
type KeyMapEntries = Record<KeyNameOrKeyCode, string>;
|
|
13
20
|
|
|
14
21
|
const keyMapEntries: KeyMapEntries = {
|
|
@@ -197,20 +204,18 @@ export const printFocusHistory = (count: number): void => {
|
|
|
197
204
|
|
|
198
205
|
// ---------------------------------------------------------------------------
|
|
199
206
|
|
|
200
|
-
let activeElement: ElementNode | undefined;
|
|
201
207
|
export const setActiveElement = (elm: ElementNode) => {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
updateFocusPath(elm,
|
|
205
|
-
activeElement = elm;
|
|
208
|
+
const prev = activeElement();
|
|
209
|
+
if (elm === prev) return;
|
|
210
|
+
updateFocusPath(elm, prev);
|
|
206
211
|
recordFocusHistory(elm, prev);
|
|
207
212
|
// Reset key attribution so programmatic focus changes show '—' for key fields
|
|
208
213
|
_pendingHistoryKey = { keyPressed: undefined, mappedKey: undefined };
|
|
209
|
-
|
|
210
|
-
Config.setActiveElement(elm);
|
|
214
|
+
_signalWrapper(() => setActiveElementSignal(elm));
|
|
211
215
|
};
|
|
212
216
|
|
|
213
|
-
|
|
217
|
+
export const [focusPath, setFocusPath] = createSignal<ElementNode[]>([]);
|
|
218
|
+
|
|
214
219
|
const updateFocusPath = (
|
|
215
220
|
currentFocusedElm: ElementNode,
|
|
216
221
|
prevFocusedElm: ElementNode | undefined,
|
|
@@ -243,7 +248,8 @@ const updateFocusPath = (
|
|
|
243
248
|
current = current.parent;
|
|
244
249
|
}
|
|
245
250
|
|
|
246
|
-
focusPath
|
|
251
|
+
const prevFp = focusPath();
|
|
252
|
+
prevFp.forEach((elm) => {
|
|
247
253
|
if (!fpSet.has(elm)) {
|
|
248
254
|
elm.states.remove(Config.focusStateKey);
|
|
249
255
|
elm.onBlur?.call(elm, currentFocusedElm, prevFocusedElm!, elm);
|
|
@@ -258,69 +264,43 @@ const updateFocusPath = (
|
|
|
258
264
|
});
|
|
259
265
|
|
|
260
266
|
if (Config.focusDebug) {
|
|
261
|
-
addFocusDebug(
|
|
267
|
+
addFocusDebug(prevFp, fp);
|
|
262
268
|
}
|
|
263
269
|
|
|
264
|
-
|
|
265
|
-
return fp;
|
|
270
|
+
_signalWrapper(() => setFocusPath(fp));
|
|
266
271
|
};
|
|
267
272
|
|
|
268
273
|
let lastGlobalKeyPressTime = 0;
|
|
269
274
|
let lastInputKey: string | number | undefined;
|
|
270
275
|
|
|
271
|
-
const
|
|
276
|
+
const isElementThrottled = (
|
|
277
|
+
elm: ElementNode,
|
|
278
|
+
sameKey: boolean,
|
|
279
|
+
currentTime: number,
|
|
280
|
+
): boolean =>
|
|
281
|
+
elm.throttleInput !== undefined &&
|
|
282
|
+
sameKey &&
|
|
283
|
+
elm._lastAnyKeyPressTime !== undefined &&
|
|
284
|
+
currentTime - elm._lastAnyKeyPressTime < elm.throttleInput;
|
|
285
|
+
|
|
286
|
+
// Walk focus path root→leaf. Returns true if a capture handler claimed the
|
|
287
|
+
// event (or an element on the path is currently rate-limited).
|
|
288
|
+
const runCapturePhase = (
|
|
289
|
+
fp: ElementNode[],
|
|
272
290
|
e: KeyboardEvent,
|
|
273
|
-
mappedEvent
|
|
274
|
-
|
|
275
|
-
|
|
291
|
+
mappedEvent: string | undefined,
|
|
292
|
+
isUp: boolean,
|
|
293
|
+
sameKey: boolean,
|
|
294
|
+
currentTime: number,
|
|
276
295
|
): boolean => {
|
|
277
|
-
const
|
|
278
|
-
const key = e.key || e.keyCode;
|
|
279
|
-
const sameKey = lastInputKey === key;
|
|
280
|
-
lastInputKey = key;
|
|
281
|
-
|
|
282
|
-
if (!isUp && Config.throttleInput) {
|
|
283
|
-
if (
|
|
284
|
-
sameKey &&
|
|
285
|
-
currentTime - lastGlobalKeyPressTime < Config.throttleInput
|
|
286
|
-
) {
|
|
287
|
-
if (isDev && Config.keyDebug) {
|
|
288
|
-
console.log(
|
|
289
|
-
`Keypress throttled by global Config.throttleInput: ${Config.throttleInput}ms`,
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
return false;
|
|
293
|
-
}
|
|
294
|
-
lastGlobalKeyPressTime = currentTime;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// Record the key for focus-history attribution (keyup presses don't trigger focus changes)
|
|
298
|
-
if (!isUp) {
|
|
299
|
-
_pendingHistoryKey = { keyPressed: key, mappedKey: mappedEvent };
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const numItems = focusPath.length;
|
|
303
|
-
if (numItems === 0) return false;
|
|
304
|
-
|
|
305
|
-
let handlerAvailable: ElementNode | undefined;
|
|
306
|
-
const finalFocusElm = focusPath[0]!;
|
|
296
|
+
const finalFocusElm = fp[0]!;
|
|
307
297
|
const keyBase = mappedEvent || e.key;
|
|
308
298
|
const captureEvent = `onCapture${keyBase}${isUp ? 'Release' : ''}`;
|
|
309
299
|
const captureKey = isUp ? 'onCaptureKeyRelease' : 'onCaptureKey';
|
|
310
300
|
|
|
311
|
-
for (let i =
|
|
312
|
-
const elm =
|
|
313
|
-
|
|
314
|
-
// Check throttle for capture phase
|
|
315
|
-
if (elm.throttleInput) {
|
|
316
|
-
if (
|
|
317
|
-
sameKey &&
|
|
318
|
-
elm._lastAnyKeyPressTime !== undefined &&
|
|
319
|
-
currentTime - elm._lastAnyKeyPressTime < elm.throttleInput
|
|
320
|
-
) {
|
|
321
|
-
return true;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
301
|
+
for (let i = fp.length - 1; i >= 0; i--) {
|
|
302
|
+
const elm = fp[i]!;
|
|
303
|
+
if (isElementThrottled(elm, sameKey, currentTime)) return true;
|
|
324
304
|
|
|
325
305
|
const captureHandler = elm[captureEvent] || elm[captureKey];
|
|
326
306
|
if (
|
|
@@ -331,73 +311,121 @@ const propagateKeyPress = (
|
|
|
331
311
|
return true;
|
|
332
312
|
}
|
|
333
313
|
}
|
|
314
|
+
return false;
|
|
315
|
+
};
|
|
334
316
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
317
|
+
// Walk focus path leaf→root. Returns whether the event was handled and the
|
|
318
|
+
// last element that had *any* matching handler (for the no-handler debug log).
|
|
319
|
+
const runBubblePhase = (
|
|
320
|
+
fp: ElementNode[],
|
|
321
|
+
e: KeyboardEvent,
|
|
322
|
+
mappedEvent: string | undefined,
|
|
323
|
+
isHold: boolean,
|
|
324
|
+
isUp: boolean,
|
|
325
|
+
sameKey: boolean,
|
|
326
|
+
currentTime: number,
|
|
327
|
+
): { handled: boolean; lastHandlerSeen: ElementNode | undefined } => {
|
|
328
|
+
const finalFocusElm = fp[0]!;
|
|
329
|
+
const eventHandlerKey = mappedEvent
|
|
330
|
+
? isUp
|
|
331
|
+
? `on${mappedEvent}Release`
|
|
332
|
+
: `on${mappedEvent}`
|
|
333
|
+
: undefined;
|
|
334
|
+
const fallbackHandlerKey: 'onKeyHold' | 'onKeyPress' | undefined = isUp
|
|
335
|
+
? undefined
|
|
336
|
+
: isHold
|
|
337
|
+
? 'onKeyHold'
|
|
338
|
+
: 'onKeyPress';
|
|
339
|
+
|
|
340
|
+
let lastHandlerSeen: ElementNode | undefined;
|
|
341
|
+
|
|
342
|
+
for (let i = 0; i < fp.length; i++) {
|
|
343
|
+
const elm = fp[i]!;
|
|
344
|
+
if (isElementThrottled(elm, sameKey, currentTime)) {
|
|
345
|
+
return { handled: true, lastHandlerSeen };
|
|
358
346
|
}
|
|
359
347
|
|
|
360
348
|
let handled = false;
|
|
361
|
-
|
|
362
349
|
if (eventHandlerKey) {
|
|
363
350
|
const eventHandler = elm[eventHandlerKey];
|
|
364
351
|
if (isFunction(eventHandler)) {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
handled = true;
|
|
368
|
-
}
|
|
352
|
+
lastHandlerSeen = elm;
|
|
353
|
+
handled = eventHandler.call(elm, e, elm, finalFocusElm) === true;
|
|
369
354
|
}
|
|
370
355
|
}
|
|
371
|
-
|
|
372
|
-
// Check for the fallback handler if its key is defined and not already handled by specific key handler
|
|
373
356
|
if (!handled && fallbackHandlerKey) {
|
|
374
357
|
const fallbackHandler = elm[fallbackHandlerKey];
|
|
375
358
|
if (isFunction(fallbackHandler)) {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
fallbackHandler.call(elm, e, mappedEvent, elm, finalFocusElm) ===
|
|
379
|
-
|
|
380
|
-
handled = true;
|
|
381
|
-
}
|
|
359
|
+
lastHandlerSeen = elm;
|
|
360
|
+
handled =
|
|
361
|
+
fallbackHandler.call(elm, e, mappedEvent, elm, finalFocusElm) ===
|
|
362
|
+
true;
|
|
382
363
|
}
|
|
383
364
|
}
|
|
384
365
|
|
|
385
366
|
if (handled) {
|
|
386
367
|
elm._lastAnyKeyPressTime = currentTime;
|
|
387
|
-
return true;
|
|
368
|
+
return { handled: true, lastHandlerSeen };
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return { handled: false, lastHandlerSeen };
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
const propagateKeyPress = (
|
|
375
|
+
e: KeyboardEvent,
|
|
376
|
+
mappedEvent?: string,
|
|
377
|
+
isHold: boolean = false,
|
|
378
|
+
isUp: boolean = false,
|
|
379
|
+
): boolean => {
|
|
380
|
+
const currentTime = performance.now();
|
|
381
|
+
const key = e.key || e.keyCode;
|
|
382
|
+
const sameKey = lastInputKey === key;
|
|
383
|
+
lastInputKey = key;
|
|
384
|
+
|
|
385
|
+
if (!isUp && Config.throttleInput) {
|
|
386
|
+
if (
|
|
387
|
+
sameKey &&
|
|
388
|
+
currentTime - lastGlobalKeyPressTime < Config.throttleInput
|
|
389
|
+
) {
|
|
390
|
+
if (isDev && Config.keyDebug) {
|
|
391
|
+
console.log(
|
|
392
|
+
`Keypress throttled by global Config.throttleInput: ${Config.throttleInput}ms`,
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
return false;
|
|
388
396
|
}
|
|
397
|
+
lastGlobalKeyPressTime = currentTime;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// Keyup events don't trigger focus changes, so don't record their key.
|
|
401
|
+
if (!isUp) {
|
|
402
|
+
_pendingHistoryKey = { keyPressed: key, mappedKey: mappedEvent };
|
|
389
403
|
}
|
|
390
404
|
|
|
405
|
+
const fp = focusPath();
|
|
406
|
+
if (fp.length === 0) return false;
|
|
407
|
+
|
|
408
|
+
if (runCapturePhase(fp, e, mappedEvent, isUp, sameKey, currentTime)) {
|
|
409
|
+
return true;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const { handled, lastHandlerSeen } = runBubblePhase(
|
|
413
|
+
fp,
|
|
414
|
+
e,
|
|
415
|
+
mappedEvent,
|
|
416
|
+
isHold,
|
|
417
|
+
isUp,
|
|
418
|
+
sameKey,
|
|
419
|
+
currentTime,
|
|
420
|
+
);
|
|
421
|
+
if (handled) return true;
|
|
422
|
+
|
|
391
423
|
if (isDev && Config.keyDebug && !isUp) {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
handlerAvailable,
|
|
396
|
-
);
|
|
424
|
+
const detail = `key="${e.key}", mappedEvent=${mappedEvent}, isHold=${isHold}, isUp=${isUp}`;
|
|
425
|
+
if (lastHandlerSeen) {
|
|
426
|
+
console.log(`Keypress bubbled, ${detail}`, lastHandlerSeen);
|
|
397
427
|
} else {
|
|
398
|
-
console.log(
|
|
399
|
-
`No event handler available for keypress: key="${e.key}", mappedEvent=${mappedEvent}, isHold=${isHold}, isUp=${isUp}`,
|
|
400
|
-
);
|
|
428
|
+
console.log(`No event handler available for keypress: ${detail}`);
|
|
401
429
|
}
|
|
402
430
|
}
|
|
403
431
|
|
|
@@ -446,52 +474,42 @@ const handleKeyEvents = (
|
|
|
446
474
|
}
|
|
447
475
|
};
|
|
448
476
|
|
|
449
|
-
|
|
450
|
-
userKeyMap?: Partial<KeyMap
|
|
451
|
-
keyHoldOptions?: KeyHoldOptions
|
|
452
|
-
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
export const useFocusManager = ({
|
|
456
|
-
userKeyMap,
|
|
457
|
-
keyHoldOptions,
|
|
458
|
-
ownerContext = (cb) => {
|
|
459
|
-
cb();
|
|
460
|
-
},
|
|
461
|
-
}: FocusManagerOptions = {}) => {
|
|
477
|
+
export const useFocusManager = (
|
|
478
|
+
userKeyMap?: Partial<KeyMap>,
|
|
479
|
+
keyHoldOptions?: KeyHoldOptions,
|
|
480
|
+
) => {
|
|
462
481
|
if (userKeyMap) {
|
|
463
482
|
flattenKeyMap(userKeyMap, keyMapEntries);
|
|
464
483
|
}
|
|
465
|
-
|
|
466
484
|
if (keyHoldOptions?.userKeyHoldMap) {
|
|
467
485
|
flattenKeyMap(keyHoldOptions.userKeyHoldMap, keyHoldMapEntries);
|
|
468
486
|
}
|
|
469
487
|
|
|
488
|
+
// Capture the calling owner so signal updates and key-event reactions
|
|
489
|
+
// can run inside it — needed for programmatic .setFocus(), post-mutation
|
|
490
|
+
// focus, and any effect subscribers that rely on onCleanup.
|
|
491
|
+
const owner = getOwner();
|
|
492
|
+
const ownerContext = (cb: () => void) => {
|
|
493
|
+
runWithOwner(owner, cb);
|
|
494
|
+
};
|
|
495
|
+
_signalWrapper = ownerContext;
|
|
496
|
+
|
|
470
497
|
const delay = keyHoldOptions?.holdThreshold || DEFAULT_KEY_HOLD_THRESHOLD;
|
|
471
498
|
const runKeyEvent = handleKeyEvents.bind(null, delay);
|
|
472
499
|
|
|
473
|
-
// Owner context is for frameworks that need effects
|
|
474
500
|
const keyPressHandler = (event: KeyboardEvent) =>
|
|
475
|
-
ownerContext(() =>
|
|
476
|
-
runKeyEvent(event, undefined);
|
|
477
|
-
});
|
|
478
|
-
|
|
501
|
+
ownerContext(() => runKeyEvent(event, undefined));
|
|
479
502
|
const keyUpHandler = (event: KeyboardEvent) =>
|
|
480
|
-
ownerContext(() =>
|
|
481
|
-
runKeyEvent(undefined, event);
|
|
482
|
-
});
|
|
503
|
+
ownerContext(() => runKeyEvent(undefined, event));
|
|
483
504
|
|
|
484
|
-
document.addEventListener('keyup', keyUpHandler);
|
|
485
505
|
document.addEventListener('keydown', keyPressHandler);
|
|
506
|
+
document.addEventListener('keyup', keyUpHandler);
|
|
486
507
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
},
|
|
495
|
-
focusPath: () => focusPath,
|
|
496
|
-
};
|
|
508
|
+
onCleanup(() => {
|
|
509
|
+
document.removeEventListener('keydown', keyPressHandler);
|
|
510
|
+
document.removeEventListener('keyup', keyUpHandler);
|
|
511
|
+
for (const timeout of Object.values(keyHoldTimeouts)) {
|
|
512
|
+
if (timeout && timeout !== true) clearTimeout(timeout);
|
|
513
|
+
}
|
|
514
|
+
});
|
|
497
515
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as lng from '@solidtv/renderer';
|
|
2
|
-
import {
|
|
2
|
+
import { isDomRendererActive } from './config.js';
|
|
3
3
|
import { DOMRendererMain, loadFontToDom } from './dom-renderer/domRenderer.js';
|
|
4
4
|
import { DomRendererMainSettings } from './dom-renderer/domRendererTypes.js';
|
|
5
5
|
import { FontLoadOptions } from './intrinsicTypes.js';
|
|
@@ -14,7 +14,7 @@ export function startLightningRenderer(
|
|
|
14
14
|
options: lng.RendererMainSettings | DomRendererMainSettings,
|
|
15
15
|
rootId: string | HTMLElement = 'app',
|
|
16
16
|
) {
|
|
17
|
-
const enableDomRenderer =
|
|
17
|
+
const enableDomRenderer = isDomRendererActive();
|
|
18
18
|
|
|
19
19
|
renderer = enableDomRenderer
|
|
20
20
|
? new DOMRendererMain(options, rootId)
|
|
@@ -23,7 +23,7 @@ export function startLightningRenderer(
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export async function loadFonts(fonts: FontLoadOptions[]) {
|
|
26
|
-
const enableDomRenderer =
|
|
26
|
+
const enableDomRenderer = isDomRendererActive();
|
|
27
27
|
await Promise.all(
|
|
28
28
|
fonts.map((font) => {
|
|
29
29
|
// WebGL — SDF
|