@solidtv/solid 1.7.0-0 → 1.7.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/elementNode.d.ts +19 -1
- package/dist/src/core/elementNode.js +127 -26
- package/dist/src/core/elementNode.js.map +1 -1
- package/dist/src/core/focusManager.js +15 -4
- package/dist/src/core/focusManager.js.map +1 -1
- package/dist/src/core/lightningInit.js +65 -3
- package/dist/src/core/lightningInit.js.map +1 -1
- package/dist/src/core/nodeTypes.d.ts +1 -1
- package/dist/src/core/nodeTypes.js +2 -3
- package/dist/src/core/nodeTypes.js.map +1 -1
- package/dist/src/primitives/Lazy.jsx +7 -1
- package/dist/src/primitives/Lazy.jsx.map +1 -1
- package/dist/src/primitives/Virtual.d.ts +4 -0
- package/dist/src/primitives/Virtual.jsx +192 -106
- package/dist/src/primitives/Virtual.jsx.map +1 -1
- package/dist/src/primitives/VirtualGrid.jsx +87 -18
- package/dist/src/primitives/VirtualGrid.jsx.map +1 -1
- package/dist/src/primitives/utils/handleNavigation.js +12 -5
- package/dist/src/primitives/utils/handleNavigation.js.map +1 -1
- package/dist/src/primitives/utils/withScrolling.js +63 -57
- package/dist/src/primitives/utils/withScrolling.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -5
- package/src/core/elementNode.ts +143 -22
- package/src/core/focusManager.ts +12 -4
- package/src/core/lightningInit.ts +78 -4
- package/src/core/nodeTypes.ts +6 -3
- package/src/primitives/Lazy.tsx +8 -1
- package/src/primitives/Virtual.tsx +211 -117
- package/src/primitives/VirtualGrid.tsx +98 -21
- package/src/primitives/utils/handleNavigation.ts +12 -5
- package/src/primitives/utils/withScrolling.ts +63 -62
|
@@ -39,13 +39,20 @@ function findFirstFocusableChildIdx(
|
|
|
39
39
|
from = 0,
|
|
40
40
|
delta = 1,
|
|
41
41
|
): number {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
const children = el.children;
|
|
43
|
+
const length = children.length;
|
|
44
|
+
const wrap = el.wrap;
|
|
45
|
+
// Visits each child at most once, so with wrap and every child skipFocus
|
|
46
|
+
// the search ends (B1). With no children there is nothing to find: -1.
|
|
47
|
+
let i = from;
|
|
48
|
+
for (let n = 0; n < length; n++, i += delta) {
|
|
49
|
+
if (!(i >= 0 && i < length)) {
|
|
50
|
+
if (wrap) {
|
|
51
|
+
i = ((i % length) + length) % length;
|
|
46
52
|
} else break;
|
|
47
53
|
}
|
|
48
|
-
|
|
54
|
+
const child = children[i];
|
|
55
|
+
if (child !== undefined && !child.skipFocus) {
|
|
49
56
|
return i;
|
|
50
57
|
}
|
|
51
58
|
}
|
|
@@ -66,92 +66,97 @@ export function withScrolling(isRow: boolean): Scroller {
|
|
|
66
66
|
componentRef = selected as ScrollableElement;
|
|
67
67
|
selected = componentRef.selected || 0;
|
|
68
68
|
}
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
if (!componentRef) return;
|
|
70
|
+
// Each input is read once into a local: on renderer v2 every node prop
|
|
71
|
+
// read goes through an accessor.
|
|
72
|
+
const scrollProp = componentRef.scroll;
|
|
73
|
+
const children = componentRef.children;
|
|
74
|
+
const childCount = children.length;
|
|
75
|
+
if (scrollProp === 'none' || selected === lastSelected || !childCount)
|
|
75
76
|
return;
|
|
76
77
|
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
const position = componentRef[axis];
|
|
79
|
+
let initialPosition = componentRef._initialPosition;
|
|
80
|
+
if (initialPosition === undefined) {
|
|
81
|
+
initialPosition = position;
|
|
82
|
+
componentRef._initialPosition = position;
|
|
79
83
|
}
|
|
80
84
|
|
|
81
85
|
const lng = componentRef.lng as unknown as INode;
|
|
82
|
-
const
|
|
86
|
+
const root = lng.stage.root;
|
|
87
|
+
const screenSize = isRow ? root.w : root.h;
|
|
83
88
|
// Determine if movement is incremental or decremental
|
|
84
89
|
const isIncrementing =
|
|
85
90
|
lastSelected === undefined || lastSelected - 1 !== selected;
|
|
86
91
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
let offset = componentRef.offset;
|
|
93
|
+
let endOffset = componentRef.endOffset;
|
|
94
|
+
let screenOffset = componentRef._screenOffset;
|
|
95
|
+
if (screenOffset === undefined) {
|
|
96
|
+
const p = componentRef.parent!;
|
|
97
|
+
if (p.clipping) {
|
|
98
|
+
endOffset =
|
|
99
|
+
endOffset ??
|
|
92
100
|
screenSize - ((isRow ? p.absX : p.absY) || 0) - p[dimension];
|
|
101
|
+
componentRef.endOffset = endOffset;
|
|
93
102
|
}
|
|
94
103
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
(isRow ? lng.absX : lng.absY) - componentRef[axis];
|
|
104
|
+
screenOffset = offset ?? (isRow ? lng.absX : lng.absY) - position;
|
|
105
|
+
componentRef._screenOffset = screenOffset;
|
|
98
106
|
}
|
|
99
107
|
|
|
100
|
-
const screenOffset = componentRef._screenOffset;
|
|
101
108
|
const gap = componentRef.gap || 0;
|
|
109
|
+
const scrollIndex = componentRef.scrollIndex;
|
|
102
110
|
// when creating we set scroll to always so we setup the right location for selected and scrollIndex
|
|
103
111
|
const scroll =
|
|
104
|
-
|
|
112
|
+
scrollProp ||
|
|
105
113
|
(lastSelected === undefined
|
|
106
|
-
?
|
|
114
|
+
? scrollIndex
|
|
107
115
|
? 'center'
|
|
108
116
|
: 'always'
|
|
109
117
|
: 'auto');
|
|
110
118
|
|
|
111
119
|
// Allows manual position control
|
|
112
|
-
const targetPosition = componentRef._targetPosition ??
|
|
120
|
+
const targetPosition = componentRef._targetPosition ?? position;
|
|
113
121
|
const rootPosition = isIncrementing
|
|
114
|
-
? Math.min(targetPosition,
|
|
115
|
-
: Math.max(targetPosition,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
122
|
+
? Math.min(targetPosition, position)
|
|
123
|
+
: Math.max(targetPosition, position);
|
|
124
|
+
offset = offset ?? rootPosition;
|
|
125
|
+
componentRef.offset = offset;
|
|
126
|
+
const selectedEl = selectedElement || children[selected];
|
|
119
127
|
|
|
120
|
-
if (!
|
|
128
|
+
if (!selectedEl) {
|
|
121
129
|
return;
|
|
122
130
|
}
|
|
123
|
-
const selectedPosition =
|
|
124
|
-
const selectedSize =
|
|
131
|
+
const selectedPosition = selectedEl[axis] ?? 0;
|
|
132
|
+
const selectedSize = selectedEl[dimension] ?? 0;
|
|
133
|
+
// `$focus`, not `style.focus`: the focus state's styles live on the node
|
|
134
|
+
// under the state key, and the `style` getter allocates when unset.
|
|
125
135
|
const selectedScale =
|
|
126
|
-
|
|
127
|
-
(selectedElement.style?.focus as Styles)?.scale ??
|
|
128
|
-
1;
|
|
136
|
+
selectedEl.scale ?? (selectedEl.$focus as Styles | undefined)?.scale ?? 1;
|
|
129
137
|
const selectedSizeScaled = selectedSize * selectedScale;
|
|
130
138
|
const containerSize = componentRef[dimension] ?? 0;
|
|
131
139
|
const maxOffset = Math.min(
|
|
132
|
-
screenSize -
|
|
133
|
-
containerSize -
|
|
134
|
-
screenOffset -
|
|
135
|
-
(componentRef.endOffset ?? 2 * gap),
|
|
140
|
+
screenSize - containerSize - screenOffset - (endOffset ?? 2 * gap),
|
|
136
141
|
offset,
|
|
137
142
|
);
|
|
138
143
|
|
|
139
144
|
// Determine the next element based on whether incrementing or decrementing
|
|
140
145
|
const nextIndex = isIncrementing ? selected + 1 : selected - 1;
|
|
141
|
-
const nextElement =
|
|
146
|
+
const nextElement = children[nextIndex] || null;
|
|
147
|
+
const scrollStopLast = componentRef.scrollStopLast;
|
|
142
148
|
|
|
143
149
|
// Default nextPosition to align with the selected position and offset
|
|
144
150
|
let nextPosition = rootPosition;
|
|
145
151
|
|
|
146
152
|
// Update nextPosition based on scroll type and specific conditions
|
|
147
|
-
if (
|
|
153
|
+
if (selectedEl.centerScroll) {
|
|
148
154
|
nextPosition = -selectedPosition + (screenSize - selectedSizeScaled) / 2;
|
|
149
155
|
} else if (scroll === 'always') {
|
|
150
156
|
nextPosition = -selectedPosition + offset;
|
|
151
157
|
} else if (scroll === 'bounded') {
|
|
152
|
-
const totalItems = componentRef.children.length;
|
|
153
158
|
const upCount = componentRef.upCount || 6;
|
|
154
|
-
const nonScrollableZoneStart = Math.max(0,
|
|
159
|
+
const nonScrollableZoneStart = Math.max(0, childCount - upCount);
|
|
155
160
|
const isInNonScrollableZone = selected >= nonScrollableZoneStart;
|
|
156
161
|
const isFirstOfNonScrollableZone = selected === nonScrollableZoneStart;
|
|
157
162
|
const isEnteringZone =
|
|
@@ -163,11 +168,9 @@ export function withScrolling(isRow: boolean): Scroller {
|
|
|
163
168
|
nextPosition = -selectedPosition + offset;
|
|
164
169
|
} else if (isIncrementing) {
|
|
165
170
|
if (isEnteringZone) {
|
|
166
|
-
const firstOfZoneElement =
|
|
167
|
-
componentRef.children[nonScrollableZoneStart];
|
|
168
|
-
const firstOfZonePosition = firstOfZoneElement?.[axis] ?? 0;
|
|
171
|
+
const firstOfZoneElement = children[nonScrollableZoneStart];
|
|
169
172
|
nextPosition = firstOfZoneElement
|
|
170
|
-
? -
|
|
173
|
+
? -(firstOfZoneElement[axis] ?? 0) + offset
|
|
171
174
|
: rootPosition;
|
|
172
175
|
} else {
|
|
173
176
|
nextPosition = rootPosition;
|
|
@@ -186,23 +189,20 @@ export function withScrolling(isRow: boolean): Scroller {
|
|
|
186
189
|
nextPosition = Math.min(Math.max(centerPosition, maxOffset), offset);
|
|
187
190
|
} else if (!nextElement) {
|
|
188
191
|
// If at the last element, align to end
|
|
189
|
-
if (
|
|
192
|
+
if (scrollStopLast && isIncrementing) {
|
|
190
193
|
nextPosition = rootPosition - selectedSize - gap;
|
|
191
194
|
} else {
|
|
192
195
|
nextPosition = isIncrementing ? maxOffset : offset;
|
|
193
196
|
}
|
|
194
197
|
} else if (scroll === 'auto') {
|
|
195
|
-
if (
|
|
198
|
+
if (scrollIndex && scrollIndex > 0) {
|
|
196
199
|
// Prevent scrolling if the selected item is within the last scrollIndex items
|
|
197
|
-
const
|
|
198
|
-
const
|
|
200
|
+
const nearEndIndex = childCount - scrollIndex;
|
|
201
|
+
const currentSelected = componentRef.selected;
|
|
199
202
|
|
|
200
|
-
if (
|
|
201
|
-
isIncrementing &&
|
|
202
|
-
componentRef.selected >= componentRef.scrollIndex
|
|
203
|
-
) {
|
|
203
|
+
if (isIncrementing && currentSelected >= scrollIndex) {
|
|
204
204
|
nextPosition = rootPosition - selectedSize - gap;
|
|
205
|
-
} else if (!isIncrementing &&
|
|
205
|
+
} else if (!isIncrementing && currentSelected < nearEndIndex) {
|
|
206
206
|
nextPosition = rootPosition + selectedSize + gap;
|
|
207
207
|
}
|
|
208
208
|
} else if (isIncrementing) {
|
|
@@ -211,15 +211,15 @@ export function withScrolling(isRow: boolean): Scroller {
|
|
|
211
211
|
nextPosition = rootPosition + selectedSize + gap;
|
|
212
212
|
}
|
|
213
213
|
} // Handle Edge scrolling
|
|
214
|
-
else if (
|
|
215
|
-
nextPosition =
|
|
216
|
-
|
|
217
|
-
|
|
214
|
+
else if (isNotShown(nextElement)) {
|
|
215
|
+
nextPosition = isIncrementing
|
|
216
|
+
? rootPosition - selectedSize - gap
|
|
217
|
+
: -selectedPosition + offset;
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
// Prevent container from moving beyond bounds
|
|
221
221
|
const isScrollStopLastCase =
|
|
222
|
-
|
|
222
|
+
scrollStopLast && !nextElement && isIncrementing;
|
|
223
223
|
nextPosition =
|
|
224
224
|
isIncrementing &&
|
|
225
225
|
scroll !== 'always' &&
|
|
@@ -229,10 +229,11 @@ export function withScrolling(isRow: boolean): Scroller {
|
|
|
229
229
|
: Math.min(nextPosition, offset);
|
|
230
230
|
|
|
231
231
|
// Update position if it has changed
|
|
232
|
-
if (
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
232
|
+
if (position !== nextPosition) {
|
|
233
|
+
const onScrolled = componentRef.onScrolled;
|
|
234
|
+
if (onScrolled) {
|
|
235
|
+
const isInitial = nextPosition === initialPosition;
|
|
236
|
+
onScrolled.call(componentRef, componentRef, nextPosition, isInitial);
|
|
236
237
|
}
|
|
237
238
|
|
|
238
239
|
componentRef[axis] = nextPosition;
|