@solidtv/solid 1.7.0-0 → 1.7.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.
Files changed (55) hide show
  1. package/README.md +4 -30
  2. package/dist/src/core/dom-renderer/domRenderer.d.ts +6 -2
  3. package/dist/src/core/dom-renderer/domRenderer.js +16 -1
  4. package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
  5. package/dist/src/core/dom-renderer/domRendererUtils.js.map +1 -1
  6. package/dist/src/core/elementNode.d.ts +20 -2
  7. package/dist/src/core/elementNode.js +128 -26
  8. package/dist/src/core/elementNode.js.map +1 -1
  9. package/dist/src/core/env.js.map +1 -1
  10. package/dist/src/core/flex.js.map +1 -1
  11. package/dist/src/core/flexLayout.js.map +1 -1
  12. package/dist/src/core/focusManager.js +15 -4
  13. package/dist/src/core/focusManager.js.map +1 -1
  14. package/dist/src/core/lightningInit.d.ts +2 -2
  15. package/dist/src/core/lightningInit.js +65 -3
  16. package/dist/src/core/lightningInit.js.map +1 -1
  17. package/dist/src/core/nodeTypes.d.ts +4 -4
  18. package/dist/src/core/nodeTypes.js +2 -3
  19. package/dist/src/core/nodeTypes.js.map +1 -1
  20. package/dist/src/core/shaders.js.map +1 -1
  21. package/dist/src/core/states.js.map +1 -1
  22. package/dist/src/core/utils.js.map +1 -1
  23. package/dist/src/devtools/hexColorTransform.js.map +1 -1
  24. package/dist/src/devtools/jsx-locator.d.ts +1 -1
  25. package/dist/src/primitives/KeepAlive.d.ts +3 -3
  26. package/dist/src/primitives/Lazy.jsx +7 -1
  27. package/dist/src/primitives/Lazy.jsx.map +1 -1
  28. package/dist/src/primitives/Virtual.d.ts +4 -0
  29. package/dist/src/primitives/Virtual.jsx +192 -106
  30. package/dist/src/primitives/Virtual.jsx.map +1 -1
  31. package/dist/src/primitives/VirtualGrid.jsx +87 -18
  32. package/dist/src/primitives/VirtualGrid.jsx.map +1 -1
  33. package/dist/src/primitives/announcer/announcer.js.map +1 -1
  34. package/dist/src/primitives/announcer/speech.js.map +1 -1
  35. package/dist/src/primitives/useMouse.js.map +1 -1
  36. package/dist/src/primitives/utils/handleNavigation.js +12 -5
  37. package/dist/src/primitives/utils/handleNavigation.js.map +1 -1
  38. package/dist/src/primitives/utils/withScrolling.js +63 -57
  39. package/dist/src/primitives/utils/withScrolling.js.map +1 -1
  40. package/dist/src/render.d.ts +3 -2
  41. package/dist/src/render.js.map +1 -1
  42. package/dist/src/utils.js.map +1 -1
  43. package/dist/tsconfig.tsbuildinfo +1 -1
  44. package/docs/README.md +2 -0
  45. package/package.json +20 -19
  46. package/src/core/dom-renderer/domRenderer.ts +16 -1
  47. package/src/core/elementNode.ts +144 -22
  48. package/src/core/focusManager.ts +12 -4
  49. package/src/core/lightningInit.ts +78 -4
  50. package/src/core/nodeTypes.ts +6 -3
  51. package/src/primitives/Lazy.tsx +8 -1
  52. package/src/primitives/Virtual.tsx +211 -117
  53. package/src/primitives/VirtualGrid.tsx +98 -21
  54. package/src/primitives/utils/handleNavigation.ts +12 -5
  55. 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
- for (let i = from; ; i += delta) {
43
- if (!idxInArray(i, el.children)) {
44
- if (el.wrap) {
45
- i = (i + el.children.length) % el.children.length;
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
- if (!el.children[i]?.skipFocus) {
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
- !componentRef ||
71
- componentRef.scroll === 'none' ||
72
- selected === lastSelected ||
73
- !componentRef.children.length
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
- if (componentRef._initialPosition === undefined) {
78
- componentRef._initialPosition = componentRef[axis];
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 screenSize = isRow ? lng.stage.root.w : lng.stage.root.h;
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
- if (componentRef._screenOffset === undefined) {
88
- if (componentRef.parent!.clipping) {
89
- const p = componentRef.parent!;
90
- componentRef.endOffset =
91
- componentRef.endOffset ??
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
- componentRef._screenOffset =
96
- componentRef.offset ??
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
- componentRef.scroll ||
112
+ scrollProp ||
105
113
  (lastSelected === undefined
106
- ? componentRef.scrollIndex
114
+ ? scrollIndex
107
115
  ? 'center'
108
116
  : 'always'
109
117
  : 'auto');
110
118
 
111
119
  // Allows manual position control
112
- const targetPosition = componentRef._targetPosition ?? componentRef[axis];
120
+ const targetPosition = componentRef._targetPosition ?? position;
113
121
  const rootPosition = isIncrementing
114
- ? Math.min(targetPosition, componentRef[axis])
115
- : Math.max(targetPosition, componentRef[axis]);
116
- componentRef.offset = componentRef.offset ?? rootPosition;
117
- const offset = componentRef.offset;
118
- selectedElement = selectedElement || componentRef.children[selected];
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 (!selectedElement) {
128
+ if (!selectedEl) {
121
129
  return;
122
130
  }
123
- const selectedPosition = selectedElement[axis] ?? 0;
124
- const selectedSize = selectedElement[dimension] ?? 0;
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
- selectedElement.scale ??
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 = componentRef.children[nextIndex] || null;
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 (selectedElement.centerScroll) {
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, totalItems - upCount);
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
- ? -firstOfZonePosition + offset
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 (componentRef.scrollStopLast && isIncrementing) {
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 (componentRef.scrollIndex && componentRef.scrollIndex > 0) {
198
+ if (scrollIndex && scrollIndex > 0) {
196
199
  // Prevent scrolling if the selected item is within the last scrollIndex items
197
- const totalItems = componentRef.children.length;
198
- const nearEndIndex = totalItems - componentRef.scrollIndex;
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 && componentRef.selected < nearEndIndex) {
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 (isIncrementing && isNotShown(nextElement)) {
215
- nextPosition = rootPosition - selectedSize - gap;
216
- } else if (isNotShown(nextElement)) {
217
- nextPosition = -selectedPosition + offset;
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
- componentRef.scrollStopLast && !nextElement && isIncrementing;
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 (componentRef[axis] !== nextPosition) {
233
- if (componentRef.onScrolled) {
234
- const isInitial = nextPosition === componentRef._initialPosition;
235
- componentRef.onScrolled(componentRef, nextPosition, isInitial);
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;