@solidtv/solid 1.3.0-0 → 1.3.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/dist/src/core/activeElement.d.ts +20 -0
- package/dist/src/core/activeElement.js +21 -0
- package/dist/src/core/activeElement.js.map +1 -0
- package/dist/src/core/clickInspector.js +2 -1
- package/dist/src/core/clickInspector.js.map +1 -1
- package/dist/src/core/config.d.ts +9 -5
- package/dist/src/core/config.js +4 -7
- package/dist/src/core/config.js.map +1 -1
- package/dist/src/core/dom-renderer/domRenderer.d.ts +6 -2
- package/dist/src/core/dom-renderer/domRenderer.js +24 -4
- package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
- package/dist/src/core/elementNode.d.ts +3 -3
- package/dist/src/core/elementNode.js +14 -5
- package/dist/src/core/elementNode.js.map +1 -1
- package/dist/src/core/env.d.ts +5 -0
- package/dist/src/core/env.js +8 -0
- package/dist/src/core/env.js.map +1 -0
- package/dist/src/core/flex.js +52 -124
- package/dist/src/core/flex.js.map +1 -1
- package/dist/src/core/flexLayout.d.ts +2 -0
- package/dist/src/core/flexLayout.js +356 -0
- package/dist/src/core/flexLayout.js.map +1 -0
- package/dist/src/core/focusKeyTypes.d.ts +0 -14
- package/dist/src/core/focusManager.d.ts +10 -16
- package/dist/src/core/focusManager.js +28 -27
- package/dist/src/core/focusManager.js.map +1 -1
- package/dist/src/core/utils.d.ts +4 -2
- package/dist/src/core/utils.js.map +1 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/primitives/index.d.ts +1 -0
- package/dist/src/primitives/useFocusManager.d.ts +2 -1
- package/dist/src/primitives/useFocusManager.js +2 -1
- package/dist/src/primitives/useFocusManager.js.map +1 -1
- package/dist/src/render.js +1 -1
- package/dist/src/render.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/core/activeElement.ts +24 -0
- package/src/core/clickInspector.ts +2 -1
- package/src/core/config.ts +12 -11
- package/src/core/dom-renderer/domRenderer.ts +26 -4
- package/src/core/elementNode.ts +17 -12
- package/src/core/env.ts +11 -0
- package/src/core/flex.ts +56 -135
- package/src/core/flexLayout.ts +410 -0
- package/src/core/focusKeyTypes.ts +0 -14
- package/src/core/focusManager.ts +34 -42
- package/src/core/utils.ts +4 -2
- package/src/index.ts +2 -1
- package/src/primitives/index.ts +1 -0
- package/src/primitives/useFocusManager.ts +2 -2
- package/src/render.ts +1 -1
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import { type ElementNode } from './elementNode.js';
|
|
2
|
+
import { isTextNode, isElementText } from './utils.js';
|
|
3
|
+
|
|
4
|
+
function getArrayValue(
|
|
5
|
+
val: number | number[] | undefined,
|
|
6
|
+
index: number,
|
|
7
|
+
defaultValue: number = 0,
|
|
8
|
+
): number {
|
|
9
|
+
if (val === undefined) return defaultValue;
|
|
10
|
+
if (typeof val === 'number') return val;
|
|
11
|
+
|
|
12
|
+
const len = val.length;
|
|
13
|
+
let result;
|
|
14
|
+
if (len === 2) {
|
|
15
|
+
result = index % 2 === 0 ? val[0] : val[1];
|
|
16
|
+
} else if (len === 3) {
|
|
17
|
+
result = index === 0 ? val[0] : index === 2 ? val[2] : val[1];
|
|
18
|
+
} else {
|
|
19
|
+
result = val[index];
|
|
20
|
+
}
|
|
21
|
+
return result ?? defaultValue;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default function (node: ElementNode): boolean {
|
|
25
|
+
const direction = node.flexDirection || 'row';
|
|
26
|
+
const isRow = direction === 'row' || direction === 'row-reverse';
|
|
27
|
+
const isReverse =
|
|
28
|
+
direction === 'row-reverse' || direction === 'column-reverse';
|
|
29
|
+
const dimension = isRow ? 'width' : 'height';
|
|
30
|
+
const crossDimension = isRow ? 'height' : 'width';
|
|
31
|
+
|
|
32
|
+
// padding order: Top, Right, Bottom, Left
|
|
33
|
+
const nodePadding = node.padding;
|
|
34
|
+
const paddingTop = node.paddingTop ?? getArrayValue(nodePadding, 0);
|
|
35
|
+
const paddingRight = node.paddingRight ?? getArrayValue(nodePadding, 1);
|
|
36
|
+
const paddingBottom = node.paddingBottom ?? getArrayValue(nodePadding, 2);
|
|
37
|
+
const paddingLeft = node.paddingLeft ?? getArrayValue(nodePadding, 3);
|
|
38
|
+
|
|
39
|
+
const paddingStart = isRow ? paddingLeft : paddingTop;
|
|
40
|
+
const paddingEnd = isRow ? paddingRight : paddingBottom;
|
|
41
|
+
const paddingCrossStart = isRow ? paddingTop : paddingLeft;
|
|
42
|
+
const paddingCrossEnd = isRow ? paddingBottom : paddingRight;
|
|
43
|
+
const nodePaddingTotal = paddingStart + paddingEnd;
|
|
44
|
+
|
|
45
|
+
const minDimension = isRow ? 'minWidth' : 'minHeight';
|
|
46
|
+
const crossMinDimension = isRow ? 'minHeight' : 'minWidth';
|
|
47
|
+
|
|
48
|
+
const children = node.children;
|
|
49
|
+
const numChildren = children.length;
|
|
50
|
+
|
|
51
|
+
if (numChildren === 0) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Optimize arrays caching
|
|
56
|
+
const processableChildrenIndices: number[] = [];
|
|
57
|
+
let hasOrder = false;
|
|
58
|
+
let totalFlexGrow = 0;
|
|
59
|
+
let totalFlexShrink = 0;
|
|
60
|
+
|
|
61
|
+
for (let i = 0; i < numChildren; i++) {
|
|
62
|
+
const c = children[i]!;
|
|
63
|
+
|
|
64
|
+
if (isElementText(c) && c.text && !(c.width || c.height)) {
|
|
65
|
+
return false; // specific text layout constraint
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (isTextNode(c) || c.flexItem === false) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (c.flexOrder !== undefined) {
|
|
73
|
+
hasOrder = true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const flexGrow = c.flexGrow;
|
|
77
|
+
if (flexGrow !== undefined && flexGrow > 0) {
|
|
78
|
+
totalFlexGrow += flexGrow;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const flexShrink = c.flexShrink;
|
|
82
|
+
if (flexShrink !== undefined && flexShrink > 0) {
|
|
83
|
+
totalFlexShrink += flexShrink;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (c[minDimension] && (c[dimension] || 0) < c[minDimension]) {
|
|
87
|
+
c[dimension] = c[minDimension]!;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (
|
|
91
|
+
c[crossMinDimension] &&
|
|
92
|
+
(c[crossDimension] || 0) < c[crossMinDimension]
|
|
93
|
+
) {
|
|
94
|
+
c[crossDimension] = c[crossMinDimension]!;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
processableChildrenIndices.push(i);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (hasOrder) {
|
|
101
|
+
processableChildrenIndices.sort((aIdx, bIdx) => {
|
|
102
|
+
const a = children[aIdx] as ElementNode;
|
|
103
|
+
const b = children[bIdx] as ElementNode;
|
|
104
|
+
return (a.flexOrder || 0) - (b.flexOrder || 0);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Apply reverse layout ordering
|
|
109
|
+
if (isReverse || node.direction === 'rtl') {
|
|
110
|
+
processableChildrenIndices.reverse();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const numProcessedChildren = processableChildrenIndices.length;
|
|
114
|
+
if (numProcessedChildren === 0) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const prop = isRow ? 'x' : 'y';
|
|
119
|
+
const crossProp = isRow ? 'y' : 'x';
|
|
120
|
+
const containerSize = Math.max(
|
|
121
|
+
node[dimension] || 0,
|
|
122
|
+
node[minDimension] || 0,
|
|
123
|
+
0,
|
|
124
|
+
);
|
|
125
|
+
let containerCrossSize = Math.max(
|
|
126
|
+
node[crossDimension] || 0,
|
|
127
|
+
node[crossMinDimension] || 0,
|
|
128
|
+
0,
|
|
129
|
+
);
|
|
130
|
+
const isWrapReverse = node.flexWrap === 'wrap-reverse';
|
|
131
|
+
const gap = node.gap || 0;
|
|
132
|
+
const justify = node.justifyContent || 'flexStart';
|
|
133
|
+
const align = node.alignItems || (node.flexWrap ? 'flexStart' : undefined);
|
|
134
|
+
let containerUpdated = false;
|
|
135
|
+
|
|
136
|
+
// Resolve sizes matching old processed calculation
|
|
137
|
+
const childMainSizes = new Float32Array(numProcessedChildren);
|
|
138
|
+
const childMarginStarts = new Float32Array(numProcessedChildren);
|
|
139
|
+
const childMarginEnds = new Float32Array(numProcessedChildren);
|
|
140
|
+
const childTotalMainSizes = new Float32Array(numProcessedChildren);
|
|
141
|
+
const childCrossSizes = new Float32Array(numProcessedChildren);
|
|
142
|
+
const childMarginCrossStarts = new Float32Array(numProcessedChildren);
|
|
143
|
+
const childMarginCrossEnds = new Float32Array(numProcessedChildren);
|
|
144
|
+
|
|
145
|
+
let sumOfFlexBaseSizesWithMargins = 0;
|
|
146
|
+
|
|
147
|
+
for (let idx = 0; idx < numProcessedChildren; idx++) {
|
|
148
|
+
const c = children[processableChildrenIndices[idx]!] as ElementNode;
|
|
149
|
+
const marginArray = c.margin;
|
|
150
|
+
// index mappings for margins: Top: 0, Right: 1, Bottom: 2, Left: 3
|
|
151
|
+
// if row: main = left/right (3/1),
|
|
152
|
+
const flexBasis = c.flexBasis;
|
|
153
|
+
const isBasisAuto = flexBasis === undefined || flexBasis === 'auto';
|
|
154
|
+
const computedBasis = isBasisAuto
|
|
155
|
+
? c[dimension] || 0
|
|
156
|
+
: (flexBasis as number);
|
|
157
|
+
const baseMainSize = isBasisAuto
|
|
158
|
+
? computedBasis
|
|
159
|
+
: Math.max(computedBasis, c[minDimension] || 0);
|
|
160
|
+
|
|
161
|
+
const marginStart = isRow
|
|
162
|
+
? c.marginLeft || getArrayValue(marginArray, 3)
|
|
163
|
+
: c.marginTop || getArrayValue(marginArray, 0);
|
|
164
|
+
const marginEnd = isRow
|
|
165
|
+
? c.marginRight || getArrayValue(marginArray, 1)
|
|
166
|
+
: c.marginBottom || getArrayValue(marginArray, 2);
|
|
167
|
+
const marginCrossStart = isRow
|
|
168
|
+
? c.marginTop || getArrayValue(marginArray, 0)
|
|
169
|
+
: c.marginLeft || getArrayValue(marginArray, 3);
|
|
170
|
+
const marginCrossEnd = isRow
|
|
171
|
+
? c.marginBottom || getArrayValue(marginArray, 2)
|
|
172
|
+
: c.marginRight || getArrayValue(marginArray, 1);
|
|
173
|
+
|
|
174
|
+
childMainSizes[idx] = baseMainSize;
|
|
175
|
+
childMarginStarts[idx] = marginStart;
|
|
176
|
+
childMarginEnds[idx] = marginEnd;
|
|
177
|
+
childTotalMainSizes[idx] = baseMainSize + marginStart + marginEnd;
|
|
178
|
+
childCrossSizes[idx] = c[crossDimension] || 0;
|
|
179
|
+
childMarginCrossStarts[idx] = marginCrossStart;
|
|
180
|
+
childMarginCrossEnds[idx] = marginCrossEnd;
|
|
181
|
+
|
|
182
|
+
sumOfFlexBaseSizesWithMargins += childTotalMainSizes[idx]!;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if ((totalFlexGrow > 0 || totalFlexShrink > 0) && numProcessedChildren > 1) {
|
|
186
|
+
node.flexBoundary = node.flexBoundary || 'fixed';
|
|
187
|
+
|
|
188
|
+
const totalGapSpace =
|
|
189
|
+
numProcessedChildren > 0 ? gap * (numProcessedChildren - 1) : 0;
|
|
190
|
+
const availableSpace =
|
|
191
|
+
containerSize - sumOfFlexBaseSizesWithMargins - totalGapSpace;
|
|
192
|
+
|
|
193
|
+
if (availableSpace > 0 && totalFlexGrow > 0) {
|
|
194
|
+
for (let idx = 0; idx < numProcessedChildren; idx++) {
|
|
195
|
+
const c = children[processableChildrenIndices[idx]!] as ElementNode;
|
|
196
|
+
const flexGrowValue = c.flexGrow || 0;
|
|
197
|
+
if (flexGrowValue > 0) {
|
|
198
|
+
const shareOfSpace = (flexGrowValue / totalFlexGrow) * availableSpace;
|
|
199
|
+
const newMainSize = childMainSizes[idx]! + shareOfSpace;
|
|
200
|
+
c[dimension] = newMainSize;
|
|
201
|
+
childMainSizes[idx] = newMainSize;
|
|
202
|
+
childTotalMainSizes[idx] =
|
|
203
|
+
newMainSize + childMarginStarts[idx]! + childMarginEnds[idx]!;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
node._containsFlexGrow = node._containsFlexGrow ? null : true;
|
|
207
|
+
} else if (availableSpace < 0 && totalFlexShrink > 0) {
|
|
208
|
+
// Flex Shrink Phase
|
|
209
|
+
let totalScaledShrinkFactor = 0;
|
|
210
|
+
for (let idx = 0; idx < numProcessedChildren; idx++) {
|
|
211
|
+
const c = children[processableChildrenIndices[idx]!] as ElementNode;
|
|
212
|
+
const flexShrinkValue = c.flexShrink || 0;
|
|
213
|
+
totalScaledShrinkFactor += flexShrinkValue * childMainSizes[idx]!;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (totalScaledShrinkFactor > 0) {
|
|
217
|
+
for (let idx = 0; idx < numProcessedChildren; idx++) {
|
|
218
|
+
const c = children[processableChildrenIndices[idx]!] as ElementNode;
|
|
219
|
+
const flexShrinkValue = c.flexShrink || 0;
|
|
220
|
+
if (flexShrinkValue > 0) {
|
|
221
|
+
const shrinkRatio =
|
|
222
|
+
(flexShrinkValue * childMainSizes[idx]!) /
|
|
223
|
+
totalScaledShrinkFactor;
|
|
224
|
+
const sizeReduction = shrinkRatio * Math.abs(availableSpace);
|
|
225
|
+
let newMainSize = childMainSizes[idx]! - sizeReduction;
|
|
226
|
+
|
|
227
|
+
// Constrain by min width/height
|
|
228
|
+
const minBound = c[minDimension] || 0;
|
|
229
|
+
if (newMainSize < minBound) {
|
|
230
|
+
newMainSize = minBound;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
c[dimension] = newMainSize;
|
|
234
|
+
childMainSizes[idx] = newMainSize;
|
|
235
|
+
childTotalMainSizes[idx] =
|
|
236
|
+
newMainSize + childMarginStarts[idx]! + childMarginEnds[idx]!;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
node._containsFlexGrow = node._containsFlexGrow ? null : true;
|
|
241
|
+
} else if (node._containsFlexGrow) {
|
|
242
|
+
node._containsFlexGrow = null;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
let totalItemSize = 0;
|
|
247
|
+
if (
|
|
248
|
+
justify === 'center' ||
|
|
249
|
+
justify === 'spaceBetween' ||
|
|
250
|
+
justify === 'spaceEvenly' ||
|
|
251
|
+
justify === 'spaceAround'
|
|
252
|
+
) {
|
|
253
|
+
for (let idx = 0; idx < numProcessedChildren; idx++) {
|
|
254
|
+
totalItemSize += childTotalMainSizes[idx]!;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const doCrossAlign = containerCrossSize
|
|
259
|
+
? (c: ElementNode, idx: number, crossCurrentPos: number = 0) => {
|
|
260
|
+
const alignSelf = c.alignSelf || align;
|
|
261
|
+
if (!alignSelf) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
if (alignSelf === 'flexStart') {
|
|
265
|
+
c[crossProp] = crossCurrentPos + childMarginCrossStarts[idx]!;
|
|
266
|
+
} else if (alignSelf === 'center') {
|
|
267
|
+
c[crossProp] =
|
|
268
|
+
crossCurrentPos +
|
|
269
|
+
(containerCrossSize - childCrossSizes[idx]!) / 2 +
|
|
270
|
+
childMarginCrossStarts[idx]!;
|
|
271
|
+
} else if (alignSelf === 'flexEnd') {
|
|
272
|
+
c[crossProp] =
|
|
273
|
+
crossCurrentPos +
|
|
274
|
+
containerCrossSize -
|
|
275
|
+
childCrossSizes[idx]! -
|
|
276
|
+
childMarginCrossEnds[idx]!;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
: (_c: ElementNode, _idx: number, _crossCurrentPos: number = 0) => {
|
|
280
|
+
/* no-op */
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
if (isRow && node._calcHeight && !node.flexCrossBoundary) {
|
|
284
|
+
let maxHeight = 0;
|
|
285
|
+
for (let idx = 0; idx < numProcessedChildren; idx++) {
|
|
286
|
+
if (childCrossSizes[idx]! > maxHeight) maxHeight = childCrossSizes[idx]!;
|
|
287
|
+
}
|
|
288
|
+
const newHeight = maxHeight || node.height;
|
|
289
|
+
if (newHeight !== node.height) {
|
|
290
|
+
containerUpdated = true;
|
|
291
|
+
node.height = containerCrossSize = newHeight;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
let currentPos = paddingStart;
|
|
296
|
+
if (justify === 'flexStart') {
|
|
297
|
+
if (node.flexWrap === 'wrap') {
|
|
298
|
+
const childCrossSizeVar =
|
|
299
|
+
numProcessedChildren > 0 ? childCrossSizes[0]! : containerCrossSize;
|
|
300
|
+
let crossCurrentPos = isWrapReverse
|
|
301
|
+
? containerCrossSize - paddingCrossEnd - childCrossSizeVar
|
|
302
|
+
: paddingCrossStart;
|
|
303
|
+
const crossGap = isRow ? (node.columnGap ?? gap) : (node.rowGap ?? gap);
|
|
304
|
+
|
|
305
|
+
for (let idx = 0; idx < numProcessedChildren; idx++) {
|
|
306
|
+
const c = children[processableChildrenIndices[idx]!] as ElementNode;
|
|
307
|
+
if (
|
|
308
|
+
currentPos + childTotalMainSizes[idx]! > containerSize &&
|
|
309
|
+
currentPos > paddingStart
|
|
310
|
+
) {
|
|
311
|
+
currentPos = paddingStart;
|
|
312
|
+
crossCurrentPos += isWrapReverse
|
|
313
|
+
? -(childCrossSizeVar + crossGap)
|
|
314
|
+
: childCrossSizeVar + crossGap;
|
|
315
|
+
}
|
|
316
|
+
c[prop] = currentPos + childMarginStarts[idx]!;
|
|
317
|
+
currentPos += childTotalMainSizes[idx]! + gap;
|
|
318
|
+
doCrossAlign(c, idx, crossCurrentPos);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const finalCrossSize = isWrapReverse
|
|
322
|
+
? containerCrossSize - crossCurrentPos + paddingCrossStart
|
|
323
|
+
: crossCurrentPos + childCrossSizeVar + paddingCrossEnd;
|
|
324
|
+
|
|
325
|
+
if (node[crossDimension] !== finalCrossSize) {
|
|
326
|
+
node[`preFlex${crossDimension}`] = node[crossDimension];
|
|
327
|
+
node[crossDimension] = finalCrossSize;
|
|
328
|
+
containerUpdated = true;
|
|
329
|
+
}
|
|
330
|
+
} else {
|
|
331
|
+
for (let idx = 0; idx < numProcessedChildren; idx++) {
|
|
332
|
+
const c = children[processableChildrenIndices[idx]!] as ElementNode;
|
|
333
|
+
c[prop] = currentPos + childMarginStarts[idx]!;
|
|
334
|
+
currentPos += childTotalMainSizes[idx]! + gap;
|
|
335
|
+
doCrossAlign(c, idx, paddingCrossStart);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Update container size
|
|
340
|
+
if (node.flexBoundary !== 'fixed' && node.flexWrap !== 'wrap') {
|
|
341
|
+
let calculatedSize = currentPos - gap + paddingEnd;
|
|
342
|
+
const minSize = node[minDimension] || 0;
|
|
343
|
+
if (calculatedSize < minSize) {
|
|
344
|
+
calculatedSize = minSize;
|
|
345
|
+
}
|
|
346
|
+
if (calculatedSize !== (node[dimension] || 0)) {
|
|
347
|
+
node[`preFlex${dimension}`] = containerSize;
|
|
348
|
+
node[dimension] = calculatedSize;
|
|
349
|
+
return true;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
} else if (justify === 'flexEnd') {
|
|
353
|
+
currentPos = containerSize - paddingEnd;
|
|
354
|
+
for (let idx = numProcessedChildren - 1; idx >= 0; idx--) {
|
|
355
|
+
const c = children[processableChildrenIndices[idx]!] as ElementNode;
|
|
356
|
+
c[prop] = currentPos - childMainSizes[idx]! - childMarginEnds[idx]!;
|
|
357
|
+
currentPos -= childTotalMainSizes[idx]! + gap;
|
|
358
|
+
doCrossAlign(c, idx, paddingCrossStart);
|
|
359
|
+
}
|
|
360
|
+
} else if (justify === 'center') {
|
|
361
|
+
currentPos =
|
|
362
|
+
(containerSize - (totalItemSize + gap * (numProcessedChildren - 1))) / 2 +
|
|
363
|
+
paddingStart;
|
|
364
|
+
for (let idx = 0; idx < numProcessedChildren; idx++) {
|
|
365
|
+
const c = children[processableChildrenIndices[idx]!] as ElementNode;
|
|
366
|
+
c[prop] = currentPos + childMarginStarts[idx]!;
|
|
367
|
+
currentPos += childTotalMainSizes[idx]! + gap;
|
|
368
|
+
doCrossAlign(c, idx, paddingCrossStart);
|
|
369
|
+
}
|
|
370
|
+
} else if (justify === 'spaceBetween') {
|
|
371
|
+
const spaceBetween =
|
|
372
|
+
numProcessedChildren > 1
|
|
373
|
+
? (containerSize - totalItemSize - nodePaddingTotal) /
|
|
374
|
+
(numProcessedChildren - 1)
|
|
375
|
+
: 0;
|
|
376
|
+
currentPos = paddingStart;
|
|
377
|
+
for (let idx = 0; idx < numProcessedChildren; idx++) {
|
|
378
|
+
const c = children[processableChildrenIndices[idx]!] as ElementNode;
|
|
379
|
+
c[prop] = currentPos + childMarginStarts[idx]!;
|
|
380
|
+
currentPos += childTotalMainSizes[idx]! + spaceBetween;
|
|
381
|
+
doCrossAlign(c, idx, paddingCrossStart);
|
|
382
|
+
}
|
|
383
|
+
} else if (justify === 'spaceAround') {
|
|
384
|
+
const spaceAround =
|
|
385
|
+
numProcessedChildren > 0
|
|
386
|
+
? (containerSize - totalItemSize - nodePaddingTotal) /
|
|
387
|
+
numProcessedChildren
|
|
388
|
+
: 0;
|
|
389
|
+
currentPos = paddingStart + spaceAround / 2;
|
|
390
|
+
for (let idx = 0; idx < numProcessedChildren; idx++) {
|
|
391
|
+
const c = children[processableChildrenIndices[idx]!] as ElementNode;
|
|
392
|
+
c[prop] = currentPos + childMarginStarts[idx]!;
|
|
393
|
+
currentPos += childTotalMainSizes[idx]! + spaceAround;
|
|
394
|
+
doCrossAlign(c, idx, paddingCrossStart);
|
|
395
|
+
}
|
|
396
|
+
} else if (justify === 'spaceEvenly') {
|
|
397
|
+
const spaceEvenly =
|
|
398
|
+
(containerSize - totalItemSize - nodePaddingTotal) /
|
|
399
|
+
(numProcessedChildren + 1);
|
|
400
|
+
currentPos = spaceEvenly + paddingStart;
|
|
401
|
+
for (let idx = 0; idx < numProcessedChildren; idx++) {
|
|
402
|
+
const c = children[processableChildrenIndices[idx]!] as ElementNode;
|
|
403
|
+
c[prop] = currentPos + childMarginStarts[idx]!;
|
|
404
|
+
currentPos += childTotalMainSizes[idx]! + spaceEvenly;
|
|
405
|
+
doCrossAlign(c, idx, paddingCrossStart);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
return containerUpdated;
|
|
410
|
+
}
|
|
@@ -69,20 +69,6 @@ export type EventHandlers<Map> = {
|
|
|
69
69
|
|
|
70
70
|
export interface KeyHoldMap extends DefaultKeyHoldMap {}
|
|
71
71
|
|
|
72
|
-
/**
|
|
73
|
-
* Return type of key handlers (onEnter, onUp, onKeyPress, onCapture*, etc.).
|
|
74
|
-
*
|
|
75
|
-
* **1.3 contract:** a handler that runs is considered to have consumed the
|
|
76
|
-
* event by default — traversal up the focus path stops at that element. To
|
|
77
|
-
* let the event continue bubbling (for observation-only handlers like
|
|
78
|
-
* logging, analytics, instrumentation), explicitly `return false`.
|
|
79
|
-
*
|
|
80
|
-
* - `return false` → not consumed; bubble to the next ancestor.
|
|
81
|
-
* - any other return → consumed (default).
|
|
82
|
-
*
|
|
83
|
-
* This is a behavior flip from 1.2, where `return true` was required to
|
|
84
|
-
* consume. See `roadmap.md` for migration notes.
|
|
85
|
-
*/
|
|
86
72
|
export type KeyHandlerReturn = boolean | void;
|
|
87
73
|
|
|
88
74
|
export type KeyHandler = (
|
package/src/core/focusManager.ts
CHANGED
|
@@ -9,10 +9,10 @@ import type {
|
|
|
9
9
|
KeyMap,
|
|
10
10
|
} from './focusKeyTypes.js';
|
|
11
11
|
import { isFunction } from './utils.js';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
import {
|
|
13
|
+
activeElement,
|
|
14
|
+
setActiveElement as setActiveElementSignal,
|
|
15
|
+
} from './activeElement.js';
|
|
16
16
|
|
|
17
17
|
let _signalWrapper: (cb: () => void) => void = (cb) => cb();
|
|
18
18
|
|
|
@@ -204,14 +204,27 @@ export const printFocusHistory = (count: number): void => {
|
|
|
204
204
|
|
|
205
205
|
// ---------------------------------------------------------------------------
|
|
206
206
|
|
|
207
|
-
|
|
207
|
+
/**
|
|
208
|
+
* Built-in "apply focus" routine: diffs the focus path, fires
|
|
209
|
+
* `onFocus`/`onBlur`/`onFocusChanged`, records history, then publishes the
|
|
210
|
+
* active element through the `Config.setActiveElement` hook.
|
|
211
|
+
*
|
|
212
|
+
* This is what `ElementNode.setFocus()` ultimately invokes. It is intentionally
|
|
213
|
+
* *not* the public `setActiveElement` export — that name is the raw signal
|
|
214
|
+
* setter (see {@link ./activeElement.ts}). Keeping them separate is what stops
|
|
215
|
+
* a custom `Config.setActiveElement` (wired to a setter) from recursing back
|
|
216
|
+
* through the focus-path logic.
|
|
217
|
+
*/
|
|
218
|
+
export const setActiveElementCore = (elm: ElementNode) => {
|
|
208
219
|
const prev = activeElement();
|
|
209
220
|
if (elm === prev) return;
|
|
210
221
|
updateFocusPath(elm, prev);
|
|
211
222
|
recordFocusHistory(elm, prev);
|
|
212
223
|
// Reset key attribution so programmatic focus changes show '—' for key fields
|
|
213
224
|
_pendingHistoryKey = { keyPressed: undefined, mappedKey: undefined };
|
|
214
|
-
|
|
225
|
+
// Publish through the swappable hook rather than writing the signal directly,
|
|
226
|
+
// so the active-element signal stays decoupled from this focus manager.
|
|
227
|
+
Config.setActiveElement(elm);
|
|
215
228
|
};
|
|
216
229
|
|
|
217
230
|
export const [focusPath, setFocusPath] = createSignal<ElementNode[]>([]);
|
|
@@ -273,24 +286,6 @@ const updateFocusPath = (
|
|
|
273
286
|
let lastGlobalKeyPressTime = 0;
|
|
274
287
|
let lastInputKey: string | number | undefined;
|
|
275
288
|
|
|
276
|
-
/**
|
|
277
|
-
* Key-handler consume contract (1.3+):
|
|
278
|
-
*
|
|
279
|
-
* A focus-path handler that runs is considered to have consumed the event.
|
|
280
|
-
* Traversal stops at that element. To opt back into bubbling — for handlers
|
|
281
|
-
* that observe but don't act (logging, analytics, instrumentation) — the
|
|
282
|
-
* handler must explicitly `return false`.
|
|
283
|
-
*
|
|
284
|
-
* - `return false` → not consumed; event bubbles to the next ancestor.
|
|
285
|
-
* - any other return → consumed (default).
|
|
286
|
-
* (`undefined`, `true`, void, etc.)
|
|
287
|
-
*
|
|
288
|
-
* @internal exported for tests. Not part of the public API; signature may
|
|
289
|
-
* change in any minor.
|
|
290
|
-
*/
|
|
291
|
-
export const _isHandlerConsumed = (result: unknown): boolean =>
|
|
292
|
-
result !== false;
|
|
293
|
-
|
|
294
289
|
const isElementThrottled = (
|
|
295
290
|
elm: ElementNode,
|
|
296
291
|
sameKey: boolean,
|
|
@@ -321,18 +316,12 @@ const runCapturePhase = (
|
|
|
321
316
|
if (isElementThrottled(elm, sameKey, currentTime)) return true;
|
|
322
317
|
|
|
323
318
|
const captureHandler = elm[captureEvent] || elm[captureKey];
|
|
324
|
-
if (
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
mappedEvent,
|
|
331
|
-
);
|
|
332
|
-
if (_isHandlerConsumed(result)) {
|
|
333
|
-
elm._lastAnyKeyPressTime = currentTime;
|
|
334
|
-
return true;
|
|
335
|
-
}
|
|
319
|
+
if (
|
|
320
|
+
isFunction(captureHandler) &&
|
|
321
|
+
captureHandler.call(elm, e, elm, finalFocusElm, mappedEvent) === true
|
|
322
|
+
) {
|
|
323
|
+
elm._lastAnyKeyPressTime = currentTime;
|
|
324
|
+
return true;
|
|
336
325
|
}
|
|
337
326
|
}
|
|
338
327
|
return false;
|
|
@@ -374,18 +363,16 @@ const runBubblePhase = (
|
|
|
374
363
|
const eventHandler = elm[eventHandlerKey];
|
|
375
364
|
if (isFunction(eventHandler)) {
|
|
376
365
|
lastHandlerSeen = elm;
|
|
377
|
-
handled =
|
|
378
|
-
eventHandler.call(elm, e, elm, finalFocusElm),
|
|
379
|
-
);
|
|
366
|
+
handled = eventHandler.call(elm, e, elm, finalFocusElm) === true;
|
|
380
367
|
}
|
|
381
368
|
}
|
|
382
369
|
if (!handled && fallbackHandlerKey) {
|
|
383
370
|
const fallbackHandler = elm[fallbackHandlerKey];
|
|
384
371
|
if (isFunction(fallbackHandler)) {
|
|
385
372
|
lastHandlerSeen = elm;
|
|
386
|
-
handled =
|
|
387
|
-
fallbackHandler.call(elm, e, mappedEvent, elm, finalFocusElm)
|
|
388
|
-
|
|
373
|
+
handled =
|
|
374
|
+
fallbackHandler.call(elm, e, mappedEvent, elm, finalFocusElm) ===
|
|
375
|
+
true;
|
|
389
376
|
}
|
|
390
377
|
}
|
|
391
378
|
|
|
@@ -519,6 +506,11 @@ export const useFocusManager = (
|
|
|
519
506
|
runWithOwner(owner, cb);
|
|
520
507
|
};
|
|
521
508
|
_signalWrapper = ownerContext;
|
|
509
|
+
// Drive the active-element signal inside this owner so its effect subscribers
|
|
510
|
+
// have a parent for cleanup. Consumers replacing the focus manager can wire
|
|
511
|
+
// Config.setActiveElement themselves instead of calling useFocusManager.
|
|
512
|
+
Config.setActiveElement = (elm) =>
|
|
513
|
+
ownerContext(() => setActiveElementSignal(elm));
|
|
522
514
|
|
|
523
515
|
const delay = keyHoldOptions?.holdThreshold || DEFAULT_KEY_HOLD_THRESHOLD;
|
|
524
516
|
const runKeyEvent = handleKeyEvents.bind(null, delay);
|
package/src/core/utils.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type INode
|
|
1
|
+
import { type INode } from '@solidtv/renderer';
|
|
2
2
|
import { Config, isDev } from './config.js';
|
|
3
3
|
import type { Styles, ElementText } from './intrinsicTypes.js';
|
|
4
4
|
import { ElementNode } from './elementNode.js';
|
|
@@ -155,7 +155,9 @@ const node${i} = renderer.createNode(props${i});
|
|
|
155
155
|
return output;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
export interface Rect
|
|
158
|
+
export interface Rect {
|
|
159
|
+
x: number;
|
|
160
|
+
y: number;
|
|
159
161
|
width: number;
|
|
160
162
|
height: number;
|
|
161
163
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,8 @@ export type * from '@solidtv/solid/jsx-runtime';
|
|
|
2
2
|
export * from './core/index.js';
|
|
3
3
|
export type * from './core/index.js';
|
|
4
4
|
export type { KeyHandler, KeyMap } from './core/focusManager.js';
|
|
5
|
-
export { activeElement, setActiveElement } from './core/
|
|
5
|
+
export { activeElement, setActiveElement } from './core/activeElement.js';
|
|
6
|
+
export { setActiveElementCore } from './core/focusManager.js';
|
|
6
7
|
export * from './utils.js';
|
|
7
8
|
export * from './render.js';
|
|
8
9
|
export * from './types.js';
|
package/src/primitives/index.ts
CHANGED
package/src/render.ts
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
type Component,
|
|
19
19
|
} from 'solid-js';
|
|
20
20
|
import type { SolidNode } from './types.js';
|
|
21
|
-
import { activeElement } from './core/
|
|
21
|
+
import { activeElement } from './core/activeElement.js';
|
|
22
22
|
|
|
23
23
|
const solidRenderer = solidCreateRenderer<SolidNode>(nodeOpts);
|
|
24
24
|
|