@react-stately/virtualizer 3.0.0-nightly-641446f65-240905
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/README.md +3 -0
- package/dist/Layout.main.js +43 -0
- package/dist/Layout.main.js.map +1 -0
- package/dist/Layout.mjs +38 -0
- package/dist/Layout.module.js +38 -0
- package/dist/Layout.module.js.map +1 -0
- package/dist/LayoutInfo.main.js +51 -0
- package/dist/LayoutInfo.main.js.map +1 -0
- package/dist/LayoutInfo.mjs +46 -0
- package/dist/LayoutInfo.module.js +46 -0
- package/dist/LayoutInfo.module.js.map +1 -0
- package/dist/OverscanManager.main.js +52 -0
- package/dist/OverscanManager.main.js.map +1 -0
- package/dist/OverscanManager.mjs +47 -0
- package/dist/OverscanManager.module.js +47 -0
- package/dist/OverscanManager.module.js.map +1 -0
- package/dist/Point.main.js +40 -0
- package/dist/Point.main.js.map +1 -0
- package/dist/Point.mjs +35 -0
- package/dist/Point.module.js +35 -0
- package/dist/Point.module.js.map +1 -0
- package/dist/Rect.main.js +130 -0
- package/dist/Rect.main.js.map +1 -0
- package/dist/Rect.mjs +125 -0
- package/dist/Rect.module.js +125 -0
- package/dist/Rect.module.js.map +1 -0
- package/dist/ReusableView.main.js +56 -0
- package/dist/ReusableView.main.js.map +1 -0
- package/dist/ReusableView.mjs +51 -0
- package/dist/ReusableView.module.js +51 -0
- package/dist/ReusableView.module.js.map +1 -0
- package/dist/Size.main.js +40 -0
- package/dist/Size.main.js.map +1 -0
- package/dist/Size.mjs +35 -0
- package/dist/Size.module.js +35 -0
- package/dist/Size.module.js.map +1 -0
- package/dist/Virtualizer.main.js +233 -0
- package/dist/Virtualizer.main.js.map +1 -0
- package/dist/Virtualizer.mjs +228 -0
- package/dist/Virtualizer.module.js +228 -0
- package/dist/Virtualizer.module.js.map +1 -0
- package/dist/import.mjs +29 -0
- package/dist/main.js +40 -0
- package/dist/main.js.map +1 -0
- package/dist/module.js +29 -0
- package/dist/module.js.map +1 -0
- package/dist/types.d.ts +347 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/useVirtualizerState.main.js +94 -0
- package/dist/useVirtualizerState.main.js.map +1 -0
- package/dist/useVirtualizerState.mjs +89 -0
- package/dist/useVirtualizerState.module.js +89 -0
- package/dist/useVirtualizerState.module.js.map +1 -0
- package/dist/utils.main.js +27 -0
- package/dist/utils.main.js.map +1 -0
- package/dist/utils.mjs +22 -0
- package/dist/utils.module.js +22 -0
- package/dist/utils.module.js.map +1 -0
- package/package.json +36 -0
- package/src/Layout.ts +93 -0
- package/src/LayoutInfo.ts +108 -0
- package/src/OverscanManager.ts +56 -0
- package/src/Point.ts +45 -0
- package/src/Rect.ts +191 -0
- package/src/ReusableView.ts +83 -0
- package/src/Size.ts +43 -0
- package/src/Virtualizer.ts +347 -0
- package/src/index.ts +23 -0
- package/src/types.ts +43 -0
- package/src/useVirtualizerState.ts +110 -0
- package/src/utils.ts +30 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import { Key, Collection, ItemDropTarget, LayoutDelegate } from "@react-types/shared";
|
|
2
|
+
export class Point {
|
|
3
|
+
/** The x-coordinate of the point. */
|
|
4
|
+
x: number;
|
|
5
|
+
/** The y-coordinate of the point. */
|
|
6
|
+
y: number;
|
|
7
|
+
constructor(x?: number, y?: number);
|
|
8
|
+
/**
|
|
9
|
+
* Returns a copy of this point.
|
|
10
|
+
*/
|
|
11
|
+
copy(): Point;
|
|
12
|
+
/**
|
|
13
|
+
* Checks if two points are equal.
|
|
14
|
+
*/
|
|
15
|
+
equals(point: Point): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Returns true if this point is the origin.
|
|
18
|
+
*/
|
|
19
|
+
isOrigin(): boolean;
|
|
20
|
+
}
|
|
21
|
+
export class Size {
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
constructor(width?: number, height?: number);
|
|
25
|
+
/**
|
|
26
|
+
* Returns a copy of this size.
|
|
27
|
+
*/
|
|
28
|
+
copy(): Size;
|
|
29
|
+
/**
|
|
30
|
+
* Returns whether this size is equal to another one.
|
|
31
|
+
*/
|
|
32
|
+
equals(other: Size): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* The total area of the Size.
|
|
35
|
+
*/
|
|
36
|
+
get area(): number;
|
|
37
|
+
}
|
|
38
|
+
export type RectCorner = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight';
|
|
39
|
+
/**
|
|
40
|
+
* Represents a rectangle.
|
|
41
|
+
*/
|
|
42
|
+
export class Rect {
|
|
43
|
+
/** The x-coordinate of the rectangle. */
|
|
44
|
+
x: number;
|
|
45
|
+
/** The y-coordinate of the rectangle. */
|
|
46
|
+
y: number;
|
|
47
|
+
/** The width of the rectangle. */
|
|
48
|
+
width: number;
|
|
49
|
+
/** The height of the rectangle. */
|
|
50
|
+
height: number;
|
|
51
|
+
constructor(x?: number, y?: number, width?: number, height?: number);
|
|
52
|
+
/**
|
|
53
|
+
* The maximum x-coordinate in the rectangle.
|
|
54
|
+
*/
|
|
55
|
+
get maxX(): number;
|
|
56
|
+
/**
|
|
57
|
+
* The maximum y-coordinate in the rectangle.
|
|
58
|
+
*/
|
|
59
|
+
get maxY(): number;
|
|
60
|
+
/**
|
|
61
|
+
* The area of the rectangle.
|
|
62
|
+
*/
|
|
63
|
+
get area(): number;
|
|
64
|
+
/**
|
|
65
|
+
* The top left corner of the rectangle.
|
|
66
|
+
*/
|
|
67
|
+
get topLeft(): Point;
|
|
68
|
+
/**
|
|
69
|
+
* The top right corner of the rectangle.
|
|
70
|
+
*/
|
|
71
|
+
get topRight(): Point;
|
|
72
|
+
/**
|
|
73
|
+
* The bottom left corner of the rectangle.
|
|
74
|
+
*/
|
|
75
|
+
get bottomLeft(): Point;
|
|
76
|
+
/**
|
|
77
|
+
* The bottom right corner of the rectangle.
|
|
78
|
+
*/
|
|
79
|
+
get bottomRight(): Point;
|
|
80
|
+
/**
|
|
81
|
+
* Returns whether this rectangle intersects another rectangle.
|
|
82
|
+
* @param rect - The rectangle to check.
|
|
83
|
+
*/
|
|
84
|
+
intersects(rect: Rect): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Returns whether this rectangle fully contains another rectangle.
|
|
87
|
+
* @param rect - The rectangle to check.
|
|
88
|
+
*/
|
|
89
|
+
containsRect(rect: Rect): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Returns whether the rectangle contains the given point.
|
|
92
|
+
* @param point - The point to check.
|
|
93
|
+
*/
|
|
94
|
+
containsPoint(point: Point): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Returns the first corner of this rectangle (from top to bottom, left to right)
|
|
97
|
+
* that is contained in the given rectangle, or null of the rectangles do not intersect.
|
|
98
|
+
* @param rect - The rectangle to check.
|
|
99
|
+
*/
|
|
100
|
+
getCornerInRect(rect: Rect): RectCorner | null;
|
|
101
|
+
equals(rect: Rect): boolean;
|
|
102
|
+
pointEquals(point: Point | Rect): boolean;
|
|
103
|
+
sizeEquals(size: Size | Rect): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Returns the union of this Rect and another.
|
|
106
|
+
*/
|
|
107
|
+
union(other: Rect): Rect;
|
|
108
|
+
/**
|
|
109
|
+
* Returns the intersection of this Rect with another.
|
|
110
|
+
* If the rectangles do not intersect, an all zero Rect is returned.
|
|
111
|
+
*/
|
|
112
|
+
intersection(other: Rect): Rect;
|
|
113
|
+
/**
|
|
114
|
+
* Returns a copy of this rectangle.
|
|
115
|
+
*/
|
|
116
|
+
copy(): Rect;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Instances of this lightweight class are created by {@link Layout} subclasses
|
|
120
|
+
* to represent each view in the {@link Virtualizer}. LayoutInfo objects describe
|
|
121
|
+
* various properties of a view, such as its position and size, and style information.
|
|
122
|
+
* The virtualizer uses this information when creating actual views to display.
|
|
123
|
+
*/
|
|
124
|
+
export class LayoutInfo {
|
|
125
|
+
/**
|
|
126
|
+
* A string representing the view type. Should be `'item'` for item views.
|
|
127
|
+
* Other types are used by supplementary views.
|
|
128
|
+
*/
|
|
129
|
+
type: string;
|
|
130
|
+
/**
|
|
131
|
+
* A unique key for this view. For item views, it should match the content key.
|
|
132
|
+
*/
|
|
133
|
+
key: Key;
|
|
134
|
+
/**
|
|
135
|
+
* The key for a parent layout info, if any.
|
|
136
|
+
*/
|
|
137
|
+
parentKey: Key | null;
|
|
138
|
+
/**
|
|
139
|
+
* The rectangle describing the size and position of this view.
|
|
140
|
+
*/
|
|
141
|
+
rect: Rect;
|
|
142
|
+
/**
|
|
143
|
+
* Whether the size is estimated. `false` by default.
|
|
144
|
+
*/
|
|
145
|
+
estimatedSize: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Whether the layout info sticks to the viewport when scrolling.
|
|
148
|
+
*/
|
|
149
|
+
isSticky: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* The view's opacity. 1 by default.
|
|
152
|
+
*/
|
|
153
|
+
opacity: number;
|
|
154
|
+
/**
|
|
155
|
+
* A CSS transform string to apply to the view. `null` by default.
|
|
156
|
+
*/
|
|
157
|
+
transform: string | null;
|
|
158
|
+
/**
|
|
159
|
+
* The z-index of the view. 0 by default.
|
|
160
|
+
*/
|
|
161
|
+
zIndex: number;
|
|
162
|
+
/**
|
|
163
|
+
* Whether the layout info allows its contents to overflow its container.
|
|
164
|
+
* @default false
|
|
165
|
+
*/
|
|
166
|
+
allowOverflow: boolean;
|
|
167
|
+
/**
|
|
168
|
+
* @param type A string representing the view type. Should be `'item'` for item views.
|
|
169
|
+
Other types are used by supplementary views.
|
|
170
|
+
* @param key The unique key for this view.
|
|
171
|
+
* @param rect The rectangle describing the size and position of this view.
|
|
172
|
+
*/
|
|
173
|
+
constructor(type: string, key: Key, rect: Rect);
|
|
174
|
+
/**
|
|
175
|
+
* Returns a copy of the LayoutInfo.
|
|
176
|
+
*/
|
|
177
|
+
copy(): LayoutInfo;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* [Virtualizer]{@link Virtualizer} creates instances of the [ReusableView]{@link ReusableView} class to
|
|
181
|
+
* represent views currently being displayed.
|
|
182
|
+
*/
|
|
183
|
+
export class ReusableView<T extends object, V> {
|
|
184
|
+
/** The Virtualizer this view is a part of. */
|
|
185
|
+
virtualizer: Virtualizer<T, V>;
|
|
186
|
+
/** The LayoutInfo this view is currently representing. */
|
|
187
|
+
layoutInfo: LayoutInfo | null;
|
|
188
|
+
/** The content currently being displayed by this view, set by the virtualizer. */
|
|
189
|
+
content: T;
|
|
190
|
+
rendered: V;
|
|
191
|
+
viewType: string;
|
|
192
|
+
key: Key;
|
|
193
|
+
parent: ReusableView<T, V> | null;
|
|
194
|
+
children: Set<ReusableView<T, V>>;
|
|
195
|
+
reusableViews: Map<string, ReusableView<T, V>[]>;
|
|
196
|
+
constructor(virtualizer: Virtualizer<T, V>);
|
|
197
|
+
/**
|
|
198
|
+
* Prepares the view for reuse. Called just before the view is removed from the DOM.
|
|
199
|
+
*/
|
|
200
|
+
prepareForReuse(): void;
|
|
201
|
+
getReusableView(reuseType: string): ReusableView<T, V>;
|
|
202
|
+
reuseChild(child: ReusableView<T, V>): void;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* The Virtualizer class renders a scrollable collection of data using customizable layouts.
|
|
206
|
+
* It supports very large collections by only rendering visible views to the DOM, reusing
|
|
207
|
+
* them as you scroll. Virtualizer can present any type of view, including non-item views
|
|
208
|
+
* such as section headers and footers.
|
|
209
|
+
*
|
|
210
|
+
* Virtualizer uses {@link Layout} objects to compute what views should be visible, and how
|
|
211
|
+
* to position and style them. This means that virtualizer can have its items arranged in
|
|
212
|
+
* a stack, a grid, a circle, or any other layout you can think of. The layout can be changed
|
|
213
|
+
* dynamically at runtime as well.
|
|
214
|
+
*
|
|
215
|
+
* Layouts produce information on what views should appear in the virtualizer, but do not create
|
|
216
|
+
* the views themselves directly. It is the responsibility of the {@link VirtualizerDelegate} object
|
|
217
|
+
* to render elements for each layout info. The virtualizer manages a set of {@link ReusableView} objects,
|
|
218
|
+
* which are reused as the user scrolls by swapping their content with cached elements returned by the delegate.
|
|
219
|
+
*/
|
|
220
|
+
declare class Virtualizer<T extends object, V> {
|
|
221
|
+
/**
|
|
222
|
+
* The virtualizer delegate. The delegate is used by the virtualizer
|
|
223
|
+
* to create and configure views.
|
|
224
|
+
*/
|
|
225
|
+
delegate: VirtualizerDelegate<T, V>;
|
|
226
|
+
/** The current content of the virtualizer. */
|
|
227
|
+
readonly collection: Collection<T>;
|
|
228
|
+
/** The layout object that determines the visible views. */
|
|
229
|
+
readonly layout: Layout<T>;
|
|
230
|
+
/** The size of the scrollable content. */
|
|
231
|
+
readonly contentSize: Size;
|
|
232
|
+
/** The currently visible rectangle. */
|
|
233
|
+
readonly visibleRect: Rect;
|
|
234
|
+
/** The set of persisted keys that are always present in the DOM, even if not currently in view. */
|
|
235
|
+
readonly persistedKeys: Set<Key>;
|
|
236
|
+
constructor(delegate: VirtualizerDelegate<T, V>);
|
|
237
|
+
/** Returns whether the given key, or an ancestor, is persisted. */
|
|
238
|
+
isPersistedKey(key: Key): boolean;
|
|
239
|
+
/**
|
|
240
|
+
* Returns the key for the item view currently at the given point.
|
|
241
|
+
*/
|
|
242
|
+
keyAtPoint(point: Point): Key | null;
|
|
243
|
+
getVisibleLayoutInfos(): Map<any, any>;
|
|
244
|
+
/** Performs layout and updates visible views as needed. */
|
|
245
|
+
render(opts: VirtualizerRenderOptions<T>): ReusableView<T, V>[];
|
|
246
|
+
getVisibleView(key: Key): ReusableView<T, V> | undefined;
|
|
247
|
+
invalidate(context: InvalidationContext): void;
|
|
248
|
+
updateItemSize(key: Key, size: Size): void;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* [Virtualizer]{@link Virtualizer} supports arbitrary layout objects, which compute what views are visible, and how
|
|
252
|
+
* to position and style them. However, layouts do not create the views themselves directly. Instead,
|
|
253
|
+
* layouts produce lightweight {@link LayoutInfo} objects which describe various properties of a view,
|
|
254
|
+
* such as its position and size. The {@link Virtualizer} is then responsible for creating the actual
|
|
255
|
+
* views as needed, based on this layout information.
|
|
256
|
+
*
|
|
257
|
+
* Every layout extends from the {@link Layout} abstract base class. Layouts must implement a minimum of the
|
|
258
|
+
* two methods listed below. All other methods can be optionally overridden to implement custom behavior.
|
|
259
|
+
*
|
|
260
|
+
* @see {@link getVisibleLayoutInfos}
|
|
261
|
+
* @see {@link getLayoutInfo}
|
|
262
|
+
*/
|
|
263
|
+
export abstract class Layout<T extends object, O = any> implements LayoutDelegate {
|
|
264
|
+
/** The Virtualizer the layout is currently attached to. */
|
|
265
|
+
virtualizer: Virtualizer<T, any>;
|
|
266
|
+
/**
|
|
267
|
+
* Returns whether the layout should invalidate in response to
|
|
268
|
+
* visible rectangle changes. By default, it only invalidates
|
|
269
|
+
* when the virtualizer's size changes. Return true always
|
|
270
|
+
* to make the layout invalidate while scrolling (e.g. sticky headers).
|
|
271
|
+
*/
|
|
272
|
+
shouldInvalidate(newRect: Rect, oldRect: Rect): boolean;
|
|
273
|
+
/**
|
|
274
|
+
* This method allows the layout to perform any pre-computation
|
|
275
|
+
* it needs to in order to prepare {@link LayoutInfo}s for retrieval.
|
|
276
|
+
* Called by the virtualizer before {@link getVisibleLayoutInfos}
|
|
277
|
+
* or {@link getLayoutInfo} are called.
|
|
278
|
+
*/
|
|
279
|
+
update(invalidationContext: InvalidationContext<O>): void;
|
|
280
|
+
/**
|
|
281
|
+
* Returns an array of {@link LayoutInfo} objects which are inside the given rectangle.
|
|
282
|
+
* Should be implemented by subclasses.
|
|
283
|
+
* @param rect The rectangle that should contain the returned LayoutInfo objects.
|
|
284
|
+
*/
|
|
285
|
+
abstract getVisibleLayoutInfos(rect: Rect): LayoutInfo[];
|
|
286
|
+
/**
|
|
287
|
+
* Returns a {@link LayoutInfo} for the given key.
|
|
288
|
+
* Should be implemented by subclasses.
|
|
289
|
+
* @param key The key of the LayoutInfo to retrieve.
|
|
290
|
+
*/
|
|
291
|
+
abstract getLayoutInfo(key: Key): LayoutInfo | null;
|
|
292
|
+
/**
|
|
293
|
+
* Returns size of the content. By default, it returns collectionView's size.
|
|
294
|
+
*/
|
|
295
|
+
abstract getContentSize(): Size;
|
|
296
|
+
/**
|
|
297
|
+
* Updates the size of the given item.
|
|
298
|
+
*/
|
|
299
|
+
updateItemSize?(key: Key, size: Size): boolean;
|
|
300
|
+
/**
|
|
301
|
+
* Returns a LayoutInfo for the given drop target.
|
|
302
|
+
*/
|
|
303
|
+
getDropTargetLayoutInfo?(target: ItemDropTarget): LayoutInfo;
|
|
304
|
+
getItemRect(key: Key): Rect;
|
|
305
|
+
getVisibleRect(): Rect;
|
|
306
|
+
}
|
|
307
|
+
export interface InvalidationContext<O = any> {
|
|
308
|
+
contentChanged?: boolean;
|
|
309
|
+
offsetChanged?: boolean;
|
|
310
|
+
sizeChanged?: boolean;
|
|
311
|
+
itemSizeChanged?: boolean;
|
|
312
|
+
layoutOptions?: O;
|
|
313
|
+
}
|
|
314
|
+
interface VirtualizerDelegate<T extends object, V> {
|
|
315
|
+
setVisibleRect(rect: Rect): void;
|
|
316
|
+
renderView(type: string, content: T): V;
|
|
317
|
+
invalidate(ctx: InvalidationContext): void;
|
|
318
|
+
}
|
|
319
|
+
interface VirtualizerRenderOptions<T extends object, O = any> {
|
|
320
|
+
layout: Layout<T>;
|
|
321
|
+
collection: Collection<T>;
|
|
322
|
+
persistedKeys?: Set<Key>;
|
|
323
|
+
visibleRect: Rect;
|
|
324
|
+
invalidationContext: InvalidationContext;
|
|
325
|
+
isScrolling: boolean;
|
|
326
|
+
layoutOptions?: O;
|
|
327
|
+
}
|
|
328
|
+
interface VirtualizerProps<T extends object, V, O> {
|
|
329
|
+
renderView(type: string, content: T): V;
|
|
330
|
+
layout: Layout<T>;
|
|
331
|
+
collection: Collection<T>;
|
|
332
|
+
onVisibleRectChange(rect: Rect): void;
|
|
333
|
+
persistedKeys?: Set<Key> | null;
|
|
334
|
+
layoutOptions?: O;
|
|
335
|
+
}
|
|
336
|
+
export interface VirtualizerState<T extends object, V> {
|
|
337
|
+
visibleViews: ReusableView<T, V>[];
|
|
338
|
+
setVisibleRect: (rect: Rect) => void;
|
|
339
|
+
contentSize: Size;
|
|
340
|
+
virtualizer: Virtualizer<T, V>;
|
|
341
|
+
isScrolling: boolean;
|
|
342
|
+
startScrolling: () => void;
|
|
343
|
+
endScrolling: () => void;
|
|
344
|
+
}
|
|
345
|
+
export function useVirtualizerState<T extends object, V, O = any>(opts: VirtualizerProps<T, V, O>): VirtualizerState<T, V>;
|
|
346
|
+
|
|
347
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";AAYA;IACE,qCAAqC;IACrC,CAAC,EAAE,MAAM,CAAC;IAEV,qCAAqC;IACrC,CAAC,EAAE,MAAM,CAAC;gBAEE,CAAC,SAAI,EAAE,CAAC,SAAI;IAKxB;;OAEG;IACH,IAAI,IAAI,KAAK;IAIb;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAI7B;;OAEG;IACH,QAAQ,IAAI,OAAO;CAGpB;AChCD;IACE,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;gBAEH,KAAK,SAAI,EAAE,MAAM,SAAI;IAKjC;;OAEG;IACH,IAAI,IAAI,IAAI;IAIZ;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,IAAI,GAAG,OAAO;IAK5B;;OAEG;IACH,IAAI,IAAI,WAEP;CACF;AC3BD,yBAAyB,SAAS,GAAG,UAAU,GAAG,YAAY,GAAG,aAAa,CAAC;AAE/E;;GAEG;AACH;IACE,yCAAyC;IACzC,CAAC,EAAE,MAAM,CAAC;IAEV,yCAAyC;IACzC,CAAC,EAAE,MAAM,CAAC;IAEV,kCAAkC;IAClC,KAAK,EAAE,MAAM,CAAC;IAEd,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAC;gBAEH,CAAC,SAAI,EAAE,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C;IAC/C,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC;IACxC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAClB,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;IAC1B,mBAAmB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IACtC,aAAa,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAChC,aAAa,CAAC,EAAE,CAAC,CAAA;CAClB;AAED,kCAAkC,CAAC,SAAS,MAAM,EAAE,CAAC;IACnD,YAAY,EAAE,aAAa,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IACnC,cAAc,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACrC,WAAW,EAAE,IAAI,CAAC;IAClB,WAAW,EAAE,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/B,WAAW,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,YAAY,EAAE,MAAM,IAAI,CAAA;CACzB;AAED,oCAAoC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,iBAAiB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,iBAAiB,CAAC,EAAE,CAAC,CAAC,CAoEzH","sources":["packages/@react-stately/virtualizer/src/packages/@react-stately/virtualizer/src/Point.ts","packages/@react-stately/virtualizer/src/packages/@react-stately/virtualizer/src/Size.ts","packages/@react-stately/virtualizer/src/packages/@react-stately/virtualizer/src/Rect.ts","packages/@react-stately/virtualizer/src/packages/@react-stately/virtualizer/src/LayoutInfo.ts","packages/@react-stately/virtualizer/src/packages/@react-stately/virtualizer/src/utils.ts","packages/@react-stately/virtualizer/src/packages/@react-stately/virtualizer/src/OverscanManager.ts","packages/@react-stately/virtualizer/src/packages/@react-stately/virtualizer/src/ReusableView.ts","packages/@react-stately/virtualizer/src/packages/@react-stately/virtualizer/src/Virtualizer.ts","packages/@react-stately/virtualizer/src/packages/@react-stately/virtualizer/src/Layout.ts","packages/@react-stately/virtualizer/src/packages/@react-stately/virtualizer/src/types.ts","packages/@react-stately/virtualizer/src/packages/@react-stately/virtualizer/src/useVirtualizerState.ts","packages/@react-stately/virtualizer/src/packages/@react-stately/virtualizer/src/index.ts","packages/@react-stately/virtualizer/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {InvalidationContext} from './types';\nexport type {VirtualizerState} from './useVirtualizerState';\nexport type {RectCorner} from './Rect';\n\nexport {Layout} from './Layout';\nexport {LayoutInfo} from './LayoutInfo';\nexport {Point} from './Point';\nexport {Rect} from './Rect';\nexport {Size} from './Size';\nexport {ReusableView} from './ReusableView';\nexport {useVirtualizerState} from './useVirtualizerState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
var $41b7691783731623$exports = require("./Rect.main.js");
|
|
2
|
+
var $e1bc15d49d21df0e$exports = require("./Virtualizer.main.js");
|
|
3
|
+
var $amfZP$react = require("react");
|
|
4
|
+
var $amfZP$reactariautils = require("@react-aria/utils");
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
function $parcel$export(e, n, v, s) {
|
|
8
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
$parcel$export(module.exports, "useVirtualizerState", () => $f02ef43b5e8eee9b$export$1505db82fe357e65);
|
|
12
|
+
/*
|
|
13
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
14
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
15
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
16
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
19
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
20
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
21
|
+
* governing permissions and limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function $f02ef43b5e8eee9b$export$1505db82fe357e65(opts) {
|
|
27
|
+
let [visibleRect, setVisibleRect] = (0, $amfZP$react.useState)(new (0, $41b7691783731623$exports.Rect)(0, 0, 0, 0));
|
|
28
|
+
let [isScrolling, setScrolling] = (0, $amfZP$react.useState)(false);
|
|
29
|
+
let [invalidationContext, setInvalidationContext] = (0, $amfZP$react.useState)({});
|
|
30
|
+
let visibleRectChanged = (0, $amfZP$react.useRef)(false);
|
|
31
|
+
let [virtualizer] = (0, $amfZP$react.useState)(()=>new (0, $e1bc15d49d21df0e$exports.Virtualizer)({
|
|
32
|
+
setVisibleRect (rect) {
|
|
33
|
+
setVisibleRect(rect);
|
|
34
|
+
visibleRectChanged.current = true;
|
|
35
|
+
},
|
|
36
|
+
// TODO: should changing these invalidate the entire cache?
|
|
37
|
+
renderView: opts.renderView,
|
|
38
|
+
invalidate: setInvalidationContext
|
|
39
|
+
}));
|
|
40
|
+
// onVisibleRectChange must be called from an effect, not during render.
|
|
41
|
+
(0, $amfZP$reactariautils.useLayoutEffect)(()=>{
|
|
42
|
+
if (visibleRectChanged.current) {
|
|
43
|
+
visibleRectChanged.current = false;
|
|
44
|
+
opts.onVisibleRectChange(visibleRect);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
let mergedInvalidationContext = (0, $amfZP$react.useMemo)(()=>{
|
|
48
|
+
if (opts.layoutOptions != null) return {
|
|
49
|
+
...invalidationContext,
|
|
50
|
+
layoutOptions: opts.layoutOptions
|
|
51
|
+
};
|
|
52
|
+
return invalidationContext;
|
|
53
|
+
}, [
|
|
54
|
+
invalidationContext,
|
|
55
|
+
opts.layoutOptions
|
|
56
|
+
]);
|
|
57
|
+
let visibleViews = virtualizer.render({
|
|
58
|
+
layout: opts.layout,
|
|
59
|
+
collection: opts.collection,
|
|
60
|
+
persistedKeys: opts.persistedKeys,
|
|
61
|
+
layoutOptions: opts.layoutOptions,
|
|
62
|
+
visibleRect: visibleRect,
|
|
63
|
+
invalidationContext: mergedInvalidationContext,
|
|
64
|
+
isScrolling: isScrolling
|
|
65
|
+
});
|
|
66
|
+
let contentSize = virtualizer.contentSize;
|
|
67
|
+
let startScrolling = (0, $amfZP$react.useCallback)(()=>{
|
|
68
|
+
setScrolling(true);
|
|
69
|
+
}, []);
|
|
70
|
+
let endScrolling = (0, $amfZP$react.useCallback)(()=>{
|
|
71
|
+
setScrolling(false);
|
|
72
|
+
}, []);
|
|
73
|
+
let state = (0, $amfZP$react.useMemo)(()=>({
|
|
74
|
+
virtualizer: virtualizer,
|
|
75
|
+
visibleViews: visibleViews,
|
|
76
|
+
setVisibleRect: setVisibleRect,
|
|
77
|
+
contentSize: contentSize,
|
|
78
|
+
isScrolling: isScrolling,
|
|
79
|
+
startScrolling: startScrolling,
|
|
80
|
+
endScrolling: endScrolling
|
|
81
|
+
}), [
|
|
82
|
+
virtualizer,
|
|
83
|
+
visibleViews,
|
|
84
|
+
setVisibleRect,
|
|
85
|
+
contentSize,
|
|
86
|
+
isScrolling,
|
|
87
|
+
startScrolling,
|
|
88
|
+
endScrolling
|
|
89
|
+
]);
|
|
90
|
+
return state;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
//# sourceMapp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C/B,aAAa;IACf,GAAG,EAAE;IACL,IAAI,eAAe,CAAA,GAAA,wBAAU,EAAE;QAC7B,aAAa;IACf,GAAG,EAAE;IAEL,IAAI,QAAQ,CAAA,GAAA,oBAAM,EAAE,IAAO,CAAA;yBACzB;0BACA;4BACA;yBACA;yBACA;4BACA;0BACA;QACF,CAAA,GAAI;QACF;QACA;QACA;QACA;QACA;QACA;QACA;KACD;IAED,OAAO;AACT","sources":["packages/@react-stately/virtualizer/src/useVirtualizerState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Key} from '@react-types/shared';\nimport {InvalidationContext} from './types';\nimport {Layout} from './Layout';\nimport {Rect} from './Rect';\nimport {ReusableView} from './ReusableView';\nimport {Size} from './Size';\nimport {useCallback, useMemo, useRef, useState} from 'react';\nimport {useLayoutEffect} from '@react-aria/utils';\nimport {Virtualizer} from './Virtualizer';\n\ninterface VirtualizerProps<T extends object, V, O> {\n renderView(type: string, content: T): V,\n layout: Layout<T>,\n collection: Collection<T>,\n onVisibleRectChange(rect: Rect): void,\n persistedKeys?: Set<Key> | null,\n layoutOptions?: O\n}\n\nexport interface VirtualizerState<T extends object, V> {\n visibleViews: ReusableView<T, V>[],\n setVisibleRect: (rect: Rect) => void,\n contentSize: Size,\n virtualizer: Virtualizer<T, V>,\n isScrolling: boolean,\n startScrolling: () => void,\n endScrolling: () => void\n}\n\nexport function useVirtualizerState<T extends object, V, O = any>(opts: VirtualizerProps<T, V, O>): VirtualizerState<T, V> {\n let [visibleRect, setVisibleRect] = useState(new Rect(0, 0, 0, 0));\n let [isScrolling, setScrolling] = useState(false);\n let [invalidationContext, setInvalidationContext] = useState<InvalidationContext>({});\n let visibleRectChanged = useRef(false);\n let [virtualizer] = useState(() => new Virtualizer<T, V>({\n setVisibleRect(rect) {\n setVisibleRect(rect);\n visibleRectChanged.current = true;\n },\n // TODO: should changing these invalidate the entire cache?\n renderView: opts.renderView,\n invalidate: setInvalidationContext\n }));\n\n // onVisibleRectChange must be called from an effect, not during render.\n useLayoutEffect(() => {\n if (visibleRectChanged.current) {\n visibleRectChanged.current = false;\n opts.onVisibleRectChange(visibleRect);\n }\n });\n\n let mergedInvalidationContext = useMemo(() => {\n if (opts.layoutOptions != null) {\n return {...invalidationContext, layoutOptions: opts.layoutOptions};\n }\n return invalidationContext;\n }, [invalidationContext, opts.layoutOptions]);\n\n let visibleViews = virtualizer.render({\n layout: opts.layout,\n collection: opts.collection,\n persistedKeys: opts.persistedKeys,\n layoutOptions: opts.layoutOptions,\n visibleRect,\n invalidationContext: mergedInvalidationContext,\n isScrolling\n });\n\n let contentSize = virtualizer.contentSize;\n\n let startScrolling = useCallback(() => {\n setScrolling(true);\n }, []);\n let endScrolling = useCallback(() => {\n setScrolling(false);\n }, []);\n\n let state = useMemo(() => ({\n virtualizer,\n visibleViews,\n setVisibleRect,\n contentSize,\n isScrolling,\n startScrolling,\n endScrolling\n }), [\n virtualizer,\n visibleViews,\n setVisibleRect,\n contentSize,\n isScrolling,\n startScrolling,\n endScrolling\n ]);\n\n return state;\n}\n"],"names":[],"version":3,"file":"useVirtualizerState.main.js.map"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {Rect as $60423f92c7f9ad87$export$c79fc6492f3af13d} from "./Rect.mjs";
|
|
2
|
+
import {Virtualizer as $38b9490c1cca8fc4$export$89be5a243e59c4b2} from "./Virtualizer.mjs";
|
|
3
|
+
import {useState as $3Fik3$useState, useRef as $3Fik3$useRef, useMemo as $3Fik3$useMemo, useCallback as $3Fik3$useCallback} from "react";
|
|
4
|
+
import {useLayoutEffect as $3Fik3$useLayoutEffect} from "@react-aria/utils";
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
8
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
10
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
13
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
14
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
15
|
+
* governing permissions and limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
function $fc0b13b484ac1194$export$1505db82fe357e65(opts) {
|
|
21
|
+
let [visibleRect, setVisibleRect] = (0, $3Fik3$useState)(new (0, $60423f92c7f9ad87$export$c79fc6492f3af13d)(0, 0, 0, 0));
|
|
22
|
+
let [isScrolling, setScrolling] = (0, $3Fik3$useState)(false);
|
|
23
|
+
let [invalidationContext, setInvalidationContext] = (0, $3Fik3$useState)({});
|
|
24
|
+
let visibleRectChanged = (0, $3Fik3$useRef)(false);
|
|
25
|
+
let [virtualizer] = (0, $3Fik3$useState)(()=>new (0, $38b9490c1cca8fc4$export$89be5a243e59c4b2)({
|
|
26
|
+
setVisibleRect (rect) {
|
|
27
|
+
setVisibleRect(rect);
|
|
28
|
+
visibleRectChanged.current = true;
|
|
29
|
+
},
|
|
30
|
+
// TODO: should changing these invalidate the entire cache?
|
|
31
|
+
renderView: opts.renderView,
|
|
32
|
+
invalidate: setInvalidationContext
|
|
33
|
+
}));
|
|
34
|
+
// onVisibleRectChange must be called from an effect, not during render.
|
|
35
|
+
(0, $3Fik3$useLayoutEffect)(()=>{
|
|
36
|
+
if (visibleRectChanged.current) {
|
|
37
|
+
visibleRectChanged.current = false;
|
|
38
|
+
opts.onVisibleRectChange(visibleRect);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
let mergedInvalidationContext = (0, $3Fik3$useMemo)(()=>{
|
|
42
|
+
if (opts.layoutOptions != null) return {
|
|
43
|
+
...invalidationContext,
|
|
44
|
+
layoutOptions: opts.layoutOptions
|
|
45
|
+
};
|
|
46
|
+
return invalidationContext;
|
|
47
|
+
}, [
|
|
48
|
+
invalidationContext,
|
|
49
|
+
opts.layoutOptions
|
|
50
|
+
]);
|
|
51
|
+
let visibleViews = virtualizer.render({
|
|
52
|
+
layout: opts.layout,
|
|
53
|
+
collection: opts.collection,
|
|
54
|
+
persistedKeys: opts.persistedKeys,
|
|
55
|
+
layoutOptions: opts.layoutOptions,
|
|
56
|
+
visibleRect: visibleRect,
|
|
57
|
+
invalidationContext: mergedInvalidationContext,
|
|
58
|
+
isScrolling: isScrolling
|
|
59
|
+
});
|
|
60
|
+
let contentSize = virtualizer.contentSize;
|
|
61
|
+
let startScrolling = (0, $3Fik3$useCallback)(()=>{
|
|
62
|
+
setScrolling(true);
|
|
63
|
+
}, []);
|
|
64
|
+
let endScrolling = (0, $3Fik3$useCallback)(()=>{
|
|
65
|
+
setScrolling(false);
|
|
66
|
+
}, []);
|
|
67
|
+
let state = (0, $3Fik3$useMemo)(()=>({
|
|
68
|
+
virtualizer: virtualizer,
|
|
69
|
+
visibleViews: visibleViews,
|
|
70
|
+
setVisibleRect: setVisibleRect,
|
|
71
|
+
contentSize: contentSize,
|
|
72
|
+
isScrolling: isScrolling,
|
|
73
|
+
startScrolling: startScrolling,
|
|
74
|
+
endScrolling: endScrolling
|
|
75
|
+
}), [
|
|
76
|
+
virtualizer,
|
|
77
|
+
visibleViews,
|
|
78
|
+
setVisibleRect,
|
|
79
|
+
contentSize,
|
|
80
|
+
isScrolling,
|
|
81
|
+
startScrolling,
|
|
82
|
+
endScrolling
|
|
83
|
+
]);
|
|
84
|
+
return state;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
export {$fc0b13b484ac1194$export$1505db82fe357e65 as useVirtualizerState};
|
|
89
|
+
//# sourceMappingURL=useVirtualizerState.module.js.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {Rect as $60423f92c7f9ad87$export$c79fc6492f3af13d} from "./Rect.module.js";
|
|
2
|
+
import {Virtualizer as $38b9490c1cca8fc4$export$89be5a243e59c4b2} from "./Virtualizer.module.js";
|
|
3
|
+
import {useState as $3Fik3$useState, useRef as $3Fik3$useRef, useMemo as $3Fik3$useMemo, useCallback as $3Fik3$useCallback} from "react";
|
|
4
|
+
import {useLayoutEffect as $3Fik3$useLayoutEffect} from "@react-aria/utils";
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
8
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
10
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
13
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
14
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
15
|
+
* governing permissions and limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
function $fc0b13b484ac1194$export$1505db82fe357e65(opts) {
|
|
21
|
+
let [visibleRect, setVisibleRect] = (0, $3Fik3$useState)(new (0, $60423f92c7f9ad87$export$c79fc6492f3af13d)(0, 0, 0, 0));
|
|
22
|
+
let [isScrolling, setScrolling] = (0, $3Fik3$useState)(false);
|
|
23
|
+
let [invalidationContext, setInvalidationContext] = (0, $3Fik3$useState)({});
|
|
24
|
+
let visibleRectChanged = (0, $3Fik3$useRef)(false);
|
|
25
|
+
let [virtualizer] = (0, $3Fik3$useState)(()=>new (0, $38b9490c1cca8fc4$export$89be5a243e59c4b2)({
|
|
26
|
+
setVisibleRect (rect) {
|
|
27
|
+
setVisibleRect(rect);
|
|
28
|
+
visibleRectChanged.current = true;
|
|
29
|
+
},
|
|
30
|
+
// TODO: should changing these invalidate the entire cache?
|
|
31
|
+
renderView: opts.renderView,
|
|
32
|
+
invalidate: setInvalidationContext
|
|
33
|
+
}));
|
|
34
|
+
// onVisibleRectChange must be called from an effect, not during render.
|
|
35
|
+
(0, $3Fik3$useLayoutEffect)(()=>{
|
|
36
|
+
if (visibleRectChanged.current) {
|
|
37
|
+
visibleRectChanged.current = false;
|
|
38
|
+
opts.onVisibleRectChange(visibleRect);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
let mergedInvalidationContext = (0, $3Fik3$useMemo)(()=>{
|
|
42
|
+
if (opts.layoutOptions != null) return {
|
|
43
|
+
...invalidationContext,
|
|
44
|
+
layoutOptions: opts.layoutOptions
|
|
45
|
+
};
|
|
46
|
+
return invalidationContext;
|
|
47
|
+
}, [
|
|
48
|
+
invalidationContext,
|
|
49
|
+
opts.layoutOptions
|
|
50
|
+
]);
|
|
51
|
+
let visibleViews = virtualizer.render({
|
|
52
|
+
layout: opts.layout,
|
|
53
|
+
collection: opts.collection,
|
|
54
|
+
persistedKeys: opts.persistedKeys,
|
|
55
|
+
layoutOptions: opts.layoutOptions,
|
|
56
|
+
visibleRect: visibleRect,
|
|
57
|
+
invalidationContext: mergedInvalidationContext,
|
|
58
|
+
isScrolling: isScrolling
|
|
59
|
+
});
|
|
60
|
+
let contentSize = virtualizer.contentSize;
|
|
61
|
+
let startScrolling = (0, $3Fik3$useCallback)(()=>{
|
|
62
|
+
setScrolling(true);
|
|
63
|
+
}, []);
|
|
64
|
+
let endScrolling = (0, $3Fik3$useCallback)(()=>{
|
|
65
|
+
setScrolling(false);
|
|
66
|
+
}, []);
|
|
67
|
+
let state = (0, $3Fik3$useMemo)(()=>({
|
|
68
|
+
virtualizer: virtualizer,
|
|
69
|
+
visibleViews: visibleViews,
|
|
70
|
+
setVisibleRect: setVisibleRect,
|
|
71
|
+
contentSize: contentSize,
|
|
72
|
+
isScrolling: isScrolling,
|
|
73
|
+
startScrolling: startScrolling,
|
|
74
|
+
endScrolling: endScrolling
|
|
75
|
+
}), [
|
|
76
|
+
virtualizer,
|
|
77
|
+
visibleViews,
|
|
78
|
+
setVisibleRect,
|
|
79
|
+
contentSize,
|
|
80
|
+
isScrolling,
|
|
81
|
+
startScrolling,
|
|
82
|
+
endScrolling
|
|
83
|
+
]);
|
|
84
|
+
return state;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
export {$fc0b13b484ac1194$export$1505db82fe357e65 as useVirtualizerState};
|
|
89
|
+
//# sourceMappingURL=useVirtualizerState.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AA+BM,SAAS,0CAAkD,IAA+B;IAC/F,IAAI,CAAC,aAAa,eAAe,GAAG,CAAA,GAAA,eAAO,EAAE,IAAI,CAAA,GAAA,yCAAG,EAAE,GAAG,GAAG,GAAG;IAC/D,IAAI,CAAC,aAAa,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE;IAC3C,IAAI,CAAC,qBAAqB,uBAAuB,GAAG,CAAA,GAAA,eAAO,EAAuB,CAAC;IACnF,IAAI,qBAAqB,CAAA,GAAA,aAAK,EAAE;IAChC,IAAI,CAAC,YAAY,GAAG,CAAA,GAAA,eAAO,EAAE,IAAM,IAAI,CAAA,GAAA,yCAAU,EAAQ;YACvD,gBAAe,IAAI;gBACjB,eAAe;gBACf,mBAAmB,OAAO,GAAG;YAC/B;YACA,2DAA2D;YAC3D,YAAY,KAAK,UAAU;YAC3B,YAAY;QACd;IAEA,wEAAwE;IACxE,CAAA,GAAA,sBAAc,EAAE;QACd,IAAI,mBAAmB,OAAO,EAAE;YAC9B,mBAAmB,OAAO,GAAG;YAC7B,KAAK,mBAAmB,CAAC;QAC3B;IACF;IAEA,IAAI,4BAA4B,CAAA,GAAA,cAAM,EAAE;QACtC,IAAI,KAAK,aAAa,IAAI,MACxB,OAAO;YAAC,GAAG,mBAAmB;YAAE,eAAe,KAAK,aAAa;QAAA;QAEnE,OAAO;IACT,GAAG;QAAC;QAAqB,KAAK,aAAa;KAAC;IAE5C,IAAI,eAAe,YAAY,MAAM,CAAC;QACpC,QAAQ,KAAK,MAAM;QACnB,YAAY,KAAK,UAAU;QAC3B,eAAe,KAAK,aAAa;QACjC,eAAe,KAAK,aAAa;qBACjC;QACA,qBAAqB;qBACrB;IACF;IAEA,IAAI,cAAc,YAAY,WAAW;IAEzC,IAAI,iBAAiB,CAAA,GAAA,kBAAU,EAAE;QAC/B,aAAa;IACf,GAAG,EAAE;IACL,IAAI,eAAe,CAAA,GAAA,kBAAU,EAAE;QAC7B,aAAa;IACf,GAAG,EAAE;IAEL,IAAI,QAAQ,CAAA,GAAA,cAAM,EAAE,IAAO,CAAA;yBACzB;0BACA;4BACA;yBACA;yBACA;4BACA;0BACA;QACF,CAAA,GAAI;QACF;QACA;QACA;QACA;QACA;QACA;QACA;KACD;IAED,OAAO;AACT","sources":["packages/@react-stately/virtualizer/src/useVirtualizerState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Key} from '@react-types/shared';\nimport {InvalidationContext} from './types';\nimport {Layout} from './Layout';\nimport {Rect} from './Rect';\nimport {ReusableView} from './ReusableView';\nimport {Size} from './Size';\nimport {useCallback, useMemo, useRef, useState} from 'react';\nimport {useLayoutEffect} from '@react-aria/utils';\nimport {Virtualizer} from './Virtualizer';\n\ninterface VirtualizerProps<T extends object, V, O> {\n renderView(type: string, content: T): V,\n layout: Layout<T>,\n collection: Collection<T>,\n onVisibleRectChange(rect: Rect): void,\n persistedKeys?: Set<Key> | null,\n layoutOptions?: O\n}\n\nexport interface VirtualizerState<T extends object, V> {\n visibleViews: ReusableView<T, V>[],\n setVisibleRect: (rect: Rect) => void,\n contentSize: Size,\n virtualizer: Virtualizer<T, V>,\n isScrolling: boolean,\n startScrolling: () => void,\n endScrolling: () => void\n}\n\nexport function useVirtualizerState<T extends object, V, O = any>(opts: VirtualizerProps<T, V, O>): VirtualizerState<T, V> {\n let [visibleRect, setVisibleRect] = useState(new Rect(0, 0, 0, 0));\n let [isScrolling, setScrolling] = useState(false);\n let [invalidationContext, setInvalidationContext] = useState<InvalidationContext>({});\n let visibleRectChanged = useRef(false);\n let [virtualizer] = useState(() => new Virtualizer<T, V>({\n setVisibleRect(rect) {\n setVisibleRect(rect);\n visibleRectChanged.current = true;\n },\n // TODO: should changing these invalidate the entire cache?\n renderView: opts.renderView,\n invalidate: setInvalidationContext\n }));\n\n // onVisibleRectChange must be called from an effect, not during render.\n useLayoutEffect(() => {\n if (visibleRectChanged.current) {\n visibleRectChanged.current = false;\n opts.onVisibleRectChange(visibleRect);\n }\n });\n\n let mergedInvalidationContext = useMemo(() => {\n if (opts.layoutOptions != null) {\n return {...invalidationContext, layoutOptions: opts.layoutOptions};\n }\n return invalidationContext;\n }, [invalidationContext, opts.layoutOptions]);\n\n let visibleViews = virtualizer.render({\n layout: opts.layout,\n collection: opts.collection,\n persistedKeys: opts.persistedKeys,\n layoutOptions: opts.layoutOptions,\n visibleRect,\n invalidationContext: mergedInvalidationContext,\n isScrolling\n });\n\n let contentSize = virtualizer.contentSize;\n\n let startScrolling = useCallback(() => {\n setScrolling(true);\n }, []);\n let endScrolling = useCallback(() => {\n setScrolling(false);\n }, []);\n\n let state = useMemo(() => ({\n virtualizer,\n visibleViews,\n setVisibleRect,\n contentSize,\n isScrolling,\n startScrolling,\n endScrolling\n }), [\n virtualizer,\n visibleViews,\n setVisibleRect,\n contentSize,\n isScrolling,\n startScrolling,\n endScrolling\n ]);\n\n return state;\n}\n"],"names":[],"version":3,"file":"useVirtualizerState.module.js.map"}
|