@react-stately/virtualizer 3.6.9-nightly.4555 → 3.6.9-nightly.4560

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 (66) hide show
  1. package/dist/Layout.main.js +75 -0
  2. package/dist/Layout.main.js.map +1 -0
  3. package/dist/Layout.mjs +70 -0
  4. package/dist/Layout.module.js +70 -0
  5. package/dist/Layout.module.js.map +1 -0
  6. package/dist/LayoutInfo.main.js +51 -0
  7. package/dist/LayoutInfo.main.js.map +1 -0
  8. package/dist/LayoutInfo.mjs +46 -0
  9. package/dist/LayoutInfo.module.js +46 -0
  10. package/dist/LayoutInfo.module.js.map +1 -0
  11. package/dist/OverscanManager.main.js +87 -0
  12. package/dist/OverscanManager.main.js.map +1 -0
  13. package/dist/OverscanManager.mjs +82 -0
  14. package/dist/OverscanManager.module.js +82 -0
  15. package/dist/OverscanManager.module.js.map +1 -0
  16. package/dist/Point.main.js +40 -0
  17. package/dist/Point.main.js.map +1 -0
  18. package/dist/Point.mjs +35 -0
  19. package/dist/Point.module.js +35 -0
  20. package/dist/Point.module.js.map +1 -0
  21. package/dist/Rect.main.js +130 -0
  22. package/dist/Rect.main.js.map +1 -0
  23. package/dist/Rect.mjs +125 -0
  24. package/dist/Rect.module.js +125 -0
  25. package/dist/Rect.module.js.map +1 -0
  26. package/dist/ReusableView.main.js +33 -0
  27. package/dist/ReusableView.main.js.map +1 -0
  28. package/dist/ReusableView.mjs +28 -0
  29. package/dist/ReusableView.module.js +28 -0
  30. package/dist/ReusableView.module.js.map +1 -0
  31. package/dist/Size.main.js +40 -0
  32. package/dist/Size.main.js.map +1 -0
  33. package/dist/Size.mjs +35 -0
  34. package/dist/Size.module.js +35 -0
  35. package/dist/Size.module.js.map +1 -0
  36. package/dist/Transaction.main.js +32 -0
  37. package/dist/Transaction.main.js.map +1 -0
  38. package/dist/Transaction.mjs +27 -0
  39. package/dist/Transaction.module.js +27 -0
  40. package/dist/Transaction.module.js.map +1 -0
  41. package/dist/Virtualizer.main.js +813 -0
  42. package/dist/Virtualizer.main.js.map +1 -0
  43. package/dist/Virtualizer.mjs +808 -0
  44. package/dist/Virtualizer.module.js +808 -0
  45. package/dist/Virtualizer.module.js.map +1 -0
  46. package/dist/import.mjs +7 -1399
  47. package/dist/main.js +14 -1406
  48. package/dist/main.js.map +1 -1
  49. package/dist/module.js +7 -1399
  50. package/dist/module.js.map +1 -1
  51. package/dist/tween.main.js +67 -0
  52. package/dist/tween.main.js.map +1 -0
  53. package/dist/tween.mjs +61 -0
  54. package/dist/tween.module.js +61 -0
  55. package/dist/tween.module.js.map +1 -0
  56. package/dist/useVirtualizerState.main.js +96 -0
  57. package/dist/useVirtualizerState.main.js.map +1 -0
  58. package/dist/useVirtualizerState.mjs +91 -0
  59. package/dist/useVirtualizerState.module.js +91 -0
  60. package/dist/useVirtualizerState.module.js.map +1 -0
  61. package/dist/utils.main.js +53 -0
  62. package/dist/utils.main.js.map +1 -0
  63. package/dist/utils.mjs +46 -0
  64. package/dist/utils.module.js +46 -0
  65. package/dist/utils.module.js.map +1 -0
  66. package/package.json +4 -4
package/dist/import.mjs CHANGED
@@ -1,340 +1,10 @@
1
- import {useState as $8D3nr$useState, useMemo as $8D3nr$useMemo, useEffect as $8D3nr$useEffect, useCallback as $8D3nr$useCallback} from "react";
2
- import {useLayoutEffect as $8D3nr$useLayoutEffect} from "@react-aria/utils";
3
-
4
- /*
5
- * Copyright 2020 Adobe. All rights reserved.
6
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License. You may obtain a copy
8
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software distributed under
11
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
- * OF ANY KIND, either express or implied. See the License for the specific language
13
- * governing permissions and limitations under the License.
14
- */ /*
15
- * Copyright 2020 Adobe. All rights reserved.
16
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
17
- * you may not use this file except in compliance with the License. You may obtain a copy
18
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
19
- *
20
- * Unless required by applicable law or agreed to in writing, software distributed under
21
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
22
- * OF ANY KIND, either express or implied. See the License for the specific language
23
- * governing permissions and limitations under the License.
24
- */ class $c74cda7d31af1253$export$c84671f46d6a1ca {
25
- /**
26
- * Returns whether the layout should invalidate in response to
27
- * visible rectangle changes. By default, it only invalidates
28
- * when the collection view's size changes. Return true always
29
- * to make the layout invalidate while scrolling (e.g. sticky headers).
30
- */ shouldInvalidate(newRect, oldRect) {
31
- // By default, invalidate when the size changes
32
- return newRect.width !== oldRect.width || newRect.height !== oldRect.height;
33
- }
34
- /**
35
- * This method allows the layout to perform any pre-computation
36
- * it needs to in order to prepare {@link LayoutInfo}s for retrieval.
37
- * Called by the collection view before {@link getVisibleLayoutInfos}
38
- * or {@link getLayoutInfo} are called.
39
- */ validate(invalidationContext) {}
40
- /**
41
- * Returns a {@link DragTarget} describing a view at the given point to be dragged.
42
- * Return `null` to cancel the drag. The default implementation returns the view at the given point.
43
- * @param point The point at which the drag occurred.
44
- */ // getDragTarget(point: Point): DragTarget | null {
45
- // let target = this.virtualizer.keyAtPoint(point);
46
- // if (!target) {
47
- // return null;
48
- // }
49
- // return {
50
- // type: 'item',
51
- // key: target
52
- // };
53
- // }
54
- /**
55
- * Returns a {@link DragTarget} object describing where a drop should occur. Return `null`
56
- * to reject the drop. The dropped items will be inserted before the resulting target.
57
- * @param point The point at which the drop occurred.
58
- */ // getDropTarget(point: Point): DropTarget | null {
59
- // return null;
60
- // }
61
- /**
62
- * Returns the starting attributes for an animated insertion.
63
- * The view is animated from this {@link LayoutInfo} to the one returned by {@link getLayoutInfo}.
64
- * The default implementation just returns its input.
65
- *
66
- * @param layoutInfo The proposed LayoutInfo for this view.
67
- */ getInitialLayoutInfo(layoutInfo) {
68
- return layoutInfo;
69
- }
70
- /**
71
- * Returns the ending attributes for an animated removal.
72
- * The view is animated from the {@link LayoutInfo} returned by {@link getLayoutInfo}
73
- * to the one returned by this method. The default implementation returns its input.
74
- *
75
- * @param layoutInfo The original LayoutInfo for this view.
76
- */ getFinalLayoutInfo(layoutInfo) {
77
- return layoutInfo;
78
- }
79
- }
80
-
81
-
82
- /*
83
- * Copyright 2020 Adobe. All rights reserved.
84
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
85
- * you may not use this file except in compliance with the License. You may obtain a copy
86
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
87
- *
88
- * Unless required by applicable law or agreed to in writing, software distributed under
89
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
90
- * OF ANY KIND, either express or implied. See the License for the specific language
91
- * governing permissions and limitations under the License.
92
- */ class $d7fd61009c21d0bb$export$7e0eeb9da702a085 {
93
- /**
94
- * Returns a copy of the LayoutInfo.
95
- */ copy() {
96
- let res = new $d7fd61009c21d0bb$export$7e0eeb9da702a085(this.type, this.key, this.rect.copy());
97
- res.estimatedSize = this.estimatedSize;
98
- res.opacity = this.opacity;
99
- res.transform = this.transform;
100
- res.parentKey = this.parentKey;
101
- res.isSticky = this.isSticky;
102
- res.zIndex = this.zIndex;
103
- res.allowOverflow = this.allowOverflow;
104
- return res;
105
- }
106
- /**
107
- * @param type A string representing the view type. Should be `'item'` for item views.
108
- Other types are used by supplementary views.
109
- * @param key The unique key for this view.
110
- * @param rect The rectangle describing the size and position of this view.
111
- */ constructor(type, key, rect){
112
- this.type = type;
113
- this.key = key;
114
- this.parentKey = null;
115
- this.rect = rect;
116
- this.estimatedSize = false;
117
- this.isSticky = false;
118
- this.opacity = 1;
119
- this.transform = null;
120
- this.zIndex = 0;
121
- this.allowOverflow = false;
122
- }
123
- }
124
-
125
-
126
- /*
127
- * Copyright 2020 Adobe. All rights reserved.
128
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
129
- * you may not use this file except in compliance with the License. You may obtain a copy
130
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
131
- *
132
- * Unless required by applicable law or agreed to in writing, software distributed under
133
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
134
- * OF ANY KIND, either express or implied. See the License for the specific language
135
- * governing permissions and limitations under the License.
136
- */ class $3041db3296945e6e$export$baf26146a414f24a {
137
- /**
138
- * Returns a copy of this point.
139
- */ copy() {
140
- return new $3041db3296945e6e$export$baf26146a414f24a(this.x, this.y);
141
- }
142
- /**
143
- * Checks if two points are equal.
144
- */ equals(point) {
145
- return this.x === point.x && this.y === point.y;
146
- }
147
- /**
148
- * Returns true if this point is the origin.
149
- */ isOrigin() {
150
- return this.x === 0 && this.y === 0;
151
- }
152
- constructor(x = 0, y = 0){
153
- this.x = x;
154
- this.y = y;
155
- }
156
- }
157
-
158
-
159
- /*
160
- * Copyright 2020 Adobe. All rights reserved.
161
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
162
- * you may not use this file except in compliance with the License. You may obtain a copy
163
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
164
- *
165
- * Unless required by applicable law or agreed to in writing, software distributed under
166
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
167
- * OF ANY KIND, either express or implied. See the License for the specific language
168
- * governing permissions and limitations under the License.
169
- */
170
- class $60423f92c7f9ad87$export$c79fc6492f3af13d {
171
- /**
172
- * The maximum x-coordinate in the rectangle.
173
- */ get maxX() {
174
- return this.x + this.width;
175
- }
176
- /**
177
- * The maximum y-coordinate in the rectangle.
178
- */ get maxY() {
179
- return this.y + this.height;
180
- }
181
- /**
182
- * The area of the rectangle.
183
- */ get area() {
184
- return this.width * this.height;
185
- }
186
- /**
187
- * The top left corner of the rectangle.
188
- */ get topLeft() {
189
- return new (0, $3041db3296945e6e$export$baf26146a414f24a)(this.x, this.y);
190
- }
191
- /**
192
- * The top right corner of the rectangle.
193
- */ get topRight() {
194
- return new (0, $3041db3296945e6e$export$baf26146a414f24a)(this.maxX, this.y);
195
- }
196
- /**
197
- * The bottom left corner of the rectangle.
198
- */ get bottomLeft() {
199
- return new (0, $3041db3296945e6e$export$baf26146a414f24a)(this.x, this.maxY);
200
- }
201
- /**
202
- * The bottom right corner of the rectangle.
203
- */ get bottomRight() {
204
- return new (0, $3041db3296945e6e$export$baf26146a414f24a)(this.maxX, this.maxY);
205
- }
206
- /**
207
- * Returns whether this rectangle intersects another rectangle.
208
- * @param rect - The rectangle to check.
209
- */ intersects(rect) {
210
- return this.x <= rect.x + rect.width && rect.x <= this.x + this.width && this.y <= rect.y + rect.height && rect.y <= this.y + this.height;
211
- }
212
- /**
213
- * Returns whether this rectangle fully contains another rectangle.
214
- * @param rect - The rectangle to check.
215
- */ containsRect(rect) {
216
- return this.x <= rect.x && this.y <= rect.y && this.maxX >= rect.maxX && this.maxY >= rect.maxY;
217
- }
218
- /**
219
- * Returns whether the rectangle contains the given point.
220
- * @param point - The point to check.
221
- */ containsPoint(point) {
222
- return this.x <= point.x && this.y <= point.y && this.maxX >= point.x && this.maxY >= point.y;
223
- }
224
- /**
225
- * Returns the first corner of this rectangle (from top to bottom, left to right)
226
- * that is contained in the given rectangle, or null of the rectangles do not intersect.
227
- * @param rect - The rectangle to check.
228
- */ getCornerInRect(rect) {
229
- for (let key of [
230
- "topLeft",
231
- "topRight",
232
- "bottomLeft",
233
- "bottomRight"
234
- ]){
235
- if (rect.containsPoint(this[key])) return key;
236
- }
237
- return null;
238
- }
239
- equals(rect) {
240
- return rect.x === this.x && rect.y === this.y && rect.width === this.width && rect.height === this.height;
241
- }
242
- pointEquals(point) {
243
- return this.x === point.x && this.y === point.y;
244
- }
245
- sizeEquals(size) {
246
- return this.width === size.width && this.height === size.height;
247
- }
248
- /**
249
- * Returns the union of this Rect and another.
250
- */ union(other) {
251
- let x = Math.min(this.x, other.x);
252
- let y = Math.min(this.y, other.y);
253
- let width = Math.max(this.maxX, other.maxX) - x;
254
- let height = Math.max(this.maxY, other.maxY) - y;
255
- return new $60423f92c7f9ad87$export$c79fc6492f3af13d(x, y, width, height);
256
- }
257
- /**
258
- * Returns the intersection of this Rect with another.
259
- * If the rectangles do not intersect, an all zero Rect is returned.
260
- */ intersection(other) {
261
- if (!this.intersects(other)) return new $60423f92c7f9ad87$export$c79fc6492f3af13d(0, 0, 0, 0);
262
- let x = Math.max(this.x, other.x);
263
- let y = Math.max(this.y, other.y);
264
- return new $60423f92c7f9ad87$export$c79fc6492f3af13d(x, y, Math.min(this.maxX, other.maxX) - x, Math.min(this.maxY, other.maxY) - y);
265
- }
266
- /**
267
- * Returns a copy of this rectangle.
268
- */ copy() {
269
- return new $60423f92c7f9ad87$export$c79fc6492f3af13d(this.x, this.y, this.width, this.height);
270
- }
271
- constructor(x = 0, y = 0, width = 0, height = 0){
272
- this.x = x;
273
- this.y = y;
274
- this.width = width;
275
- this.height = height;
276
- }
277
- }
278
-
279
-
280
- /*
281
- * Copyright 2020 Adobe. All rights reserved.
282
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
283
- * you may not use this file except in compliance with the License. You may obtain a copy
284
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
285
- *
286
- * Unless required by applicable law or agreed to in writing, software distributed under
287
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
288
- * OF ANY KIND, either express or implied. See the License for the specific language
289
- * governing permissions and limitations under the License.
290
- */ class $ee1bfa90a957fb8a$export$cb6da89c6af1a8ec {
291
- /**
292
- * Returns a copy of this size.
293
- */ copy() {
294
- return new $ee1bfa90a957fb8a$export$cb6da89c6af1a8ec(this.width, this.height);
295
- }
296
- /**
297
- * Returns whether this size is equal to another one.
298
- */ equals(other) {
299
- return this.width === other.width && this.height === other.height;
300
- }
301
- /**
302
- * The total area of the Size.
303
- */ get area() {
304
- return this.width * this.height;
305
- }
306
- constructor(width = 0, height = 0){
307
- this.width = width;
308
- this.height = height;
309
- }
310
- }
311
-
312
-
313
- /*
314
- * Copyright 2020 Adobe. All rights reserved.
315
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
316
- * you may not use this file except in compliance with the License. You may obtain a copy
317
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
318
- *
319
- * Unless required by applicable law or agreed to in writing, software distributed under
320
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
321
- * OF ANY KIND, either express or implied. See the License for the specific language
322
- * governing permissions and limitations under the License.
323
- */ let $ad1d98aa8f0c31b4$var$KEY = 0;
324
- class $ad1d98aa8f0c31b4$export$1a5223887c560441 {
325
- /**
326
- * Prepares the view for reuse. Called just before the view is removed from the DOM.
327
- */ prepareForReuse() {
328
- this.content = null;
329
- this.rendered = null;
330
- this.layoutInfo = null;
331
- }
332
- constructor(virtualizer){
333
- this.virtualizer = virtualizer;
334
- this.key = ++$ad1d98aa8f0c31b4$var$KEY;
335
- }
336
- }
337
-
1
+ import {Layout as $c74cda7d31af1253$export$c84671f46d6a1ca} from "./Layout.mjs";
2
+ import {LayoutInfo as $d7fd61009c21d0bb$export$7e0eeb9da702a085} from "./LayoutInfo.mjs";
3
+ import {Point as $3041db3296945e6e$export$baf26146a414f24a} from "./Point.mjs";
4
+ import {Rect as $60423f92c7f9ad87$export$c79fc6492f3af13d} from "./Rect.mjs";
5
+ import {Size as $ee1bfa90a957fb8a$export$cb6da89c6af1a8ec} from "./Size.mjs";
6
+ import {ReusableView as $ad1d98aa8f0c31b4$export$1a5223887c560441} from "./ReusableView.mjs";
7
+ import {useVirtualizerState as $fc0b13b484ac1194$export$1505db82fe357e65} from "./useVirtualizerState.mjs";
338
8
 
339
9
  /*
340
10
  * Copyright 2020 Adobe. All rights reserved.
@@ -349,1070 +19,8 @@ class $ad1d98aa8f0c31b4$export$1a5223887c560441 {
349
19
  */
350
20
 
351
21
 
352
- /*
353
- * Copyright 2020 Adobe. All rights reserved.
354
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
355
- * you may not use this file except in compliance with the License. You may obtain a copy
356
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
357
- *
358
- * Unless required by applicable law or agreed to in writing, software distributed under
359
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
360
- * OF ANY KIND, either express or implied. See the License for the specific language
361
- * governing permissions and limitations under the License.
362
- */ /*
363
- * Copyright 2020 Adobe. All rights reserved.
364
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
365
- * you may not use this file except in compliance with the License. You may obtain a copy
366
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
367
- *
368
- * Unless required by applicable law or agreed to in writing, software distributed under
369
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
370
- * OF ANY KIND, either express or implied. See the License for the specific language
371
- * governing permissions and limitations under the License.
372
- */
373
- // use high res timer if available
374
- let $3eb131dcf37ad5f8$var$perf = typeof window !== "undefined" ? window.performance : null;
375
- // @ts-ignore
376
- let $3eb131dcf37ad5f8$var$perfNow = $3eb131dcf37ad5f8$var$perf && ($3eb131dcf37ad5f8$var$perf.now || $3eb131dcf37ad5f8$var$perf.webkitNow || $3eb131dcf37ad5f8$var$perf.msNow || $3eb131dcf37ad5f8$var$perf.mozNow);
377
- let $3eb131dcf37ad5f8$var$getTime = $3eb131dcf37ad5f8$var$perfNow ? $3eb131dcf37ad5f8$var$perfNow.bind($3eb131dcf37ad5f8$var$perf) : function() {
378
- return Date.now ? Date.now() : new Date().getTime();
379
- };
380
- let $3eb131dcf37ad5f8$var$fixTs;
381
- function $3eb131dcf37ad5f8$export$dc0b63720788090c(begin, end, duration, ease, fn) {
382
- let canceled = false;
383
- let raf_id;
384
- let promise = new Promise((resolve)=>{
385
- let start = $3eb131dcf37ad5f8$var$getTime();
386
- let diffX = end.x - begin.x;
387
- let diffY = end.y - begin.y;
388
- raf_id = requestAnimationFrame(function run(t) {
389
- // if we're using a high res timer, make sure timestamp is not the old epoch-based value.
390
- // http://updates.html5rocks.com/2012/05/requestAnimationFrame-API-now-with-sub-millisecond-precision
391
- if ($3eb131dcf37ad5f8$var$fixTs == null) $3eb131dcf37ad5f8$var$fixTs = t > 1e12 !== $3eb131dcf37ad5f8$var$getTime() > 1e12;
392
- if ($3eb131dcf37ad5f8$var$fixTs) t = $3eb131dcf37ad5f8$var$getTime();
393
- // check if we're done
394
- let delta = t - start;
395
- if (delta > duration) {
396
- fn(end);
397
- resolve();
398
- } else {
399
- // call frame callback after computing eased time and get the next frame
400
- let proceed = fn(new (0, $3041db3296945e6e$export$baf26146a414f24a)(begin.x + diffX * ease(delta / duration), begin.y + diffY * ease(delta / duration)));
401
- if (proceed !== false && !canceled) raf_id = requestAnimationFrame(run);
402
- }
403
- });
404
- });
405
- promise.cancel = function() {
406
- canceled = true;
407
- cancelAnimationFrame(raf_id);
408
- };
409
- return promise;
410
- }
411
- function $3eb131dcf37ad5f8$export$77860c106b4a6a2e(t) {
412
- return t;
413
- }
414
- function $3eb131dcf37ad5f8$export$57636bb43b1ccbb0(t) {
415
- return Math.sin(t * Math.PI / 2);
416
- }
417
-
418
-
419
- /*
420
- * Copyright 2020 Adobe. All rights reserved.
421
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
422
- * you may not use this file except in compliance with the License. You may obtain a copy
423
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
424
- *
425
- * Unless required by applicable law or agreed to in writing, software distributed under
426
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
427
- * OF ANY KIND, either express or implied. See the License for the specific language
428
- * governing permissions and limitations under the License.
429
- */ function $fc36f9a046a9ce79$export$37a26b283fd7740e(a, b) {
430
- let res = new Set();
431
- for (let key of a.keys())if (!b.has(key)) res.add(key);
432
- return res;
433
- }
434
- function $fc36f9a046a9ce79$export$acaf96a27438246b(a, b) {
435
- let toRemove = $fc36f9a046a9ce79$export$37a26b283fd7740e(a, b);
436
- let toAdd = $fc36f9a046a9ce79$export$37a26b283fd7740e(b, a);
437
- let toUpdate = new Set;
438
- for (let key of a.keys())if (b.has(key)) toUpdate.add(key);
439
- return {
440
- toRemove: toRemove,
441
- toAdd: toAdd,
442
- toUpdate: toUpdate
443
- };
444
- }
445
- function* $fc36f9a046a9ce79$export$cfc14088dfefce5f(...iterators) {
446
- for (let iterator of iterators)yield* iterator;
447
- }
448
- function $fc36f9a046a9ce79$export$6897c284b6f9f4dc(object) {
449
- let res = {};
450
- for(let key in object)res[object[key]] = key;
451
- return res;
452
- }
453
- function $fc36f9a046a9ce79$export$a8d0d0c8d1c5df64(a, b) {
454
- if (a === b) return true;
455
- if (a.size !== b.size) return false;
456
- for (let key of a){
457
- if (!b.has(key)) return false;
458
- }
459
- return true;
460
- }
461
-
462
-
463
- /*
464
- * Copyright 2020 Adobe. All rights reserved.
465
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
466
- * you may not use this file except in compliance with the License. You may obtain a copy
467
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
468
- *
469
- * Unless required by applicable law or agreed to in writing, software distributed under
470
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
471
- * OF ANY KIND, either express or implied. See the License for the specific language
472
- * governing permissions and limitations under the License.
473
- */
474
-
475
- class $364191b3decf3697$var$RollingAverage {
476
- addSample(sample) {
477
- this.count++;
478
- this.value += (sample - this.value) / this.count;
479
- }
480
- constructor(){
481
- this.count = 0;
482
- this.value = 0;
483
- }
484
- }
485
- class $364191b3decf3697$export$4455ee6afb38dcbb {
486
- setVisibleRect(rect) {
487
- let time = performance.now() - this.startTime;
488
- if (time < 500) {
489
- this.averageTime.addSample(time);
490
- if (rect.x !== this.visibleRect.x && time > 0) this.velocity.x = (rect.x - this.visibleRect.x) / time;
491
- if (rect.y !== this.visibleRect.y && time > 0) this.velocity.y = (rect.y - this.visibleRect.y) / time;
492
- }
493
- this.startTime = performance.now();
494
- this.visibleRect = rect;
495
- }
496
- collectMetrics() {
497
- let time = performance.now() - this.startTime;
498
- if (time < 500) this.averagePerf.addSample(time);
499
- if (this.visibleRect.height > 0) {
500
- let o = Math.abs(this.velocity.y * (this.averageTime.value + this.averagePerf.value));
501
- this.overscanY.addSample(o);
502
- }
503
- if (this.visibleRect.width > 0) {
504
- let o = Math.abs(this.velocity.x * (this.averageTime.value + this.averagePerf.value));
505
- this.overscanX.addSample(o);
506
- }
507
- }
508
- getOverscannedRect() {
509
- let overscanned = this.visibleRect.copy();
510
- let overscanY = Math.round(Math.min(this.visibleRect.height * 2, this.overscanY.value) / 100) * 100;
511
- if (this.velocity.y > 0) {
512
- overscanned.y -= overscanY * 0.2;
513
- overscanned.height += overscanY + overscanY * 0.2;
514
- } else {
515
- overscanned.y -= overscanY;
516
- overscanned.height += overscanY + overscanY * 0.2;
517
- }
518
- let overscanX = Math.round(Math.min(this.visibleRect.width * 2, this.overscanX.value) / 100) * 100;
519
- if (this.velocity.x > 0) {
520
- overscanned.x -= overscanX * 0.2;
521
- overscanned.width += overscanX + overscanX * 0.2;
522
- } else {
523
- overscanned.x -= overscanX;
524
- overscanned.width += overscanX + overscanX * 0.2;
525
- }
526
- return overscanned;
527
- }
528
- constructor(){
529
- this.startTime = 0;
530
- this.averagePerf = new $364191b3decf3697$var$RollingAverage();
531
- this.averageTime = new $364191b3decf3697$var$RollingAverage();
532
- this.velocity = new (0, $3041db3296945e6e$export$baf26146a414f24a)(5, 5);
533
- this.overscanX = new $364191b3decf3697$var$RollingAverage();
534
- this.overscanY = new $364191b3decf3697$var$RollingAverage();
535
- this.visibleRect = new (0, $60423f92c7f9ad87$export$c79fc6492f3af13d)();
536
- }
537
- }
538
-
539
-
540
-
541
-
542
-
543
-
544
- /*
545
- * Copyright 2020 Adobe. All rights reserved.
546
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
547
- * you may not use this file except in compliance with the License. You may obtain a copy
548
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
549
- *
550
- * Unless required by applicable law or agreed to in writing, software distributed under
551
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
552
- * OF ANY KIND, either express or implied. See the License for the specific language
553
- * governing permissions and limitations under the License.
554
- */ class $8e135e531d8dcb66$export$febc5573c75cefb0 {
555
- constructor(){
556
- this.level = 0;
557
- this.actions = [];
558
- this.animated = true;
559
- this.initialMap = new Map();
560
- this.finalMap = new Map();
561
- this.initialLayoutInfo = new Map();
562
- this.finalLayoutInfo = new Map();
563
- this.removed = new Map();
564
- this.toRemove = new Map();
565
- }
566
- }
567
-
568
-
569
- class $38b9490c1cca8fc4$export$89be5a243e59c4b2 {
570
- _setContentSize(size) {
571
- this._contentSize = size;
572
- this.delegate.setContentSize(size);
573
- }
574
- _setContentOffset(offset) {
575
- let rect = new (0, $60423f92c7f9ad87$export$c79fc6492f3af13d)(offset.x, offset.y, this._visibleRect.width, this._visibleRect.height);
576
- this.delegate.setVisibleRect(rect);
577
- }
578
- /**
579
- * Get the size of the scrollable content.
580
- */ get contentSize() {
581
- return this._contentSize;
582
- }
583
- /**
584
- * Get the collection view's currently visible rectangle.
585
- */ get visibleRect() {
586
- return this._visibleRect;
587
- }
588
- /**
589
- * Set the collection view's currently visible rectangle.
590
- */ set visibleRect(rect) {
591
- this._setVisibleRect(rect);
592
- }
593
- _setVisibleRect(rect, forceUpdate = false) {
594
- let current = this._visibleRect;
595
- // Ignore if the rects are equal
596
- if (rect.equals(current)) return;
597
- if (this.shouldOverscan) this._overscanManager.setVisibleRect(rect);
598
- let shouldInvalidate = this.layout && this.layout.shouldInvalidate(rect, this._visibleRect);
599
- this._resetAnimatedContentOffset();
600
- this._visibleRect = rect;
601
- if (shouldInvalidate) // We are already in a layout effect when this method is called, so relayoutNow is appropriate.
602
- this.relayoutNow({
603
- offsetChanged: !rect.pointEquals(current),
604
- sizeChanged: !rect.sizeEquals(current)
605
- });
606
- else this.updateSubviews(forceUpdate);
607
- }
608
- get collection() {
609
- return this._collection;
610
- }
611
- set collection(data) {
612
- this._setData(data);
613
- }
614
- _setData(data) {
615
- if (data === this._collection) return;
616
- if (this._collection) this._runTransaction(()=>{
617
- this._collection = data;
618
- }, this.transitionDuration > 0);
619
- else {
620
- this._collection = data;
621
- this.reloadData();
622
- }
623
- }
624
- /**
625
- * Reloads the data from the data source and relayouts the collection view.
626
- * Does not animate any changes. Equivalent to re-assigning the same data source
627
- * to the collection view.
628
- */ reloadData() {
629
- this.relayout({
630
- contentChanged: true
631
- });
632
- }
633
- /**
634
- * Returns the item with the given key.
635
- */ getItem(key) {
636
- return this._collection ? this._collection.getItem(key) : null;
637
- }
638
- /** The set of persisted keys are always present in the DOM, even if not currently in view. */ get persistedKeys() {
639
- return this._persistedKeys;
640
- }
641
- /** The set of persisted keys are always present in the DOM, even if not currently in view. */ set persistedKeys(persistedKeys) {
642
- if (!(0, $fc36f9a046a9ce79$export$a8d0d0c8d1c5df64)(persistedKeys, this._persistedKeys)) {
643
- this._persistedKeys = persistedKeys;
644
- this.updateSubviews();
645
- }
646
- }
647
- /** Returns whether the given key, or an ancestor, is persisted. */ isPersistedKey(key) {
648
- // Quick check if the key is directly in the set of persisted keys.
649
- if (this._persistedKeys.has(key)) return true;
650
- // If not, check if the key is an ancestor of any of the persisted keys.
651
- for (let k of this._persistedKeys)while(k != null){
652
- let layoutInfo = this.layout.getLayoutInfo(k);
653
- if (!layoutInfo) break;
654
- k = layoutInfo.parentKey;
655
- if (k === key) return true;
656
- }
657
- return false;
658
- }
659
- /**
660
- * Get the collection view's layout.
661
- */ get layout() {
662
- return this._layout;
663
- }
664
- /**
665
- * Set the collection view's layout.
666
- */ set layout(layout) {
667
- this.setLayout(layout);
668
- }
669
- /**
670
- * Sets the collection view's layout, optionally with an animated transition
671
- * from the current layout to the new layout.
672
- * @param layout The layout to switch to.
673
- * @param animated Whether to animate the layout change.
674
- */ setLayout(layout, animated = false) {
675
- if (layout === this._layout) return;
676
- let applyLayout = ()=>{
677
- if (this._layout) // @ts-ignore
678
- this._layout.virtualizer = null;
679
- layout.virtualizer = this;
680
- this._layout = layout;
681
- };
682
- if (animated) // Animated layout transitions are really simple, thanks to our transaction support.
683
- // We just set the layout inside a transaction action, which runs after the initial
684
- // layout infos for the animation are retrieved from the previous layout. Then, the
685
- // final layout infos are retrieved from the new layout, and animations occur.
686
- this._runTransaction(applyLayout);
687
- else {
688
- applyLayout();
689
- this.relayout();
690
- }
691
- }
692
- _getReuseType(layoutInfo, content) {
693
- if (layoutInfo.type === "item" && content) {
694
- let type = this.delegate.getType ? this.delegate.getType(content) : "item";
695
- let reuseType = type === "item" ? "item" : layoutInfo.type + "_" + type;
696
- return {
697
- type: type,
698
- reuseType: reuseType
699
- };
700
- }
701
- return {
702
- type: layoutInfo.type,
703
- reuseType: layoutInfo.type
704
- };
705
- }
706
- getReusableView(layoutInfo) {
707
- let content = this.getItem(layoutInfo.key);
708
- let { reuseType: reuseType } = this._getReuseType(layoutInfo, content);
709
- if (!this._reusableViews[reuseType]) this._reusableViews[reuseType] = [];
710
- let reusable = this._reusableViews[reuseType];
711
- let view = reusable.length > 0 ? reusable.pop() : new (0, $ad1d98aa8f0c31b4$export$1a5223887c560441)(this);
712
- view.viewType = reuseType;
713
- if (!this._animatedContentOffset.isOrigin()) {
714
- layoutInfo = layoutInfo.copy();
715
- layoutInfo.rect.x += this._animatedContentOffset.x;
716
- layoutInfo.rect.y += this._animatedContentOffset.y;
717
- }
718
- view.layoutInfo = layoutInfo;
719
- this._renderView(view);
720
- return view;
721
- }
722
- _renderView(reusableView) {
723
- let { type: type, key: key } = reusableView.layoutInfo;
724
- reusableView.content = this.getItem(key);
725
- reusableView.rendered = this._renderContent(type, reusableView.content);
726
- }
727
- _renderContent(type, content) {
728
- let cached = this._renderedContent.get(content);
729
- if (cached != null) return cached;
730
- let rendered = this.delegate.renderView(type, content);
731
- if (content) this._renderedContent.set(content, rendered);
732
- return rendered;
733
- }
734
- /**
735
- * Returns an array of all currently visible views, including both
736
- * item views and supplementary views.
737
- */ get visibleViews() {
738
- return Array.from(this._visibleViews.values());
739
- }
740
- /**
741
- * Gets the visible view for the given type and key. Returns null if
742
- * the view is not currently visible.
743
- *
744
- * @param key The key of the view to retrieve.
745
- */ getView(key) {
746
- return this._visibleViews.get(key) || null;
747
- }
748
- /**
749
- * Returns an array of visible views matching the given type.
750
- * @param type The view type to find.
751
- */ getViewsOfType(type) {
752
- return this.visibleViews.filter((v)=>v.layoutInfo && v.layoutInfo.type === type);
753
- }
754
- /**
755
- * Returns the key for the given view. Returns null
756
- * if the view is not currently visible.
757
- */ keyForView(view) {
758
- if (view && view.layoutInfo) return view.layoutInfo.key;
759
- return null;
760
- }
761
- /**
762
- * Returns the key for the item view currently at the given point.
763
- */ keyAtPoint(point) {
764
- let rect = new (0, $60423f92c7f9ad87$export$c79fc6492f3af13d)(point.x, point.y, 1, 1);
765
- let layoutInfos = this.layout.getVisibleLayoutInfos(rect);
766
- // Layout may return multiple layout infos in the case of
767
- // persisted keys, so find the first one that actually intersects.
768
- for (let layoutInfo of layoutInfos){
769
- if (layoutInfo.rect.intersects(rect)) return layoutInfo.key;
770
- }
771
- return null;
772
- }
773
- /**
774
- * Cleanup for when the Virtualizer will be unmounted.
775
- */ willUnmount() {
776
- cancelAnimationFrame(this._relayoutRaf);
777
- }
778
- /**
779
- * Triggers a layout invalidation, and updates the visible subviews.
780
- */ relayout(context = {}) {
781
- // Ignore relayouts while animating the scroll position
782
- if (this._scrollAnimation || typeof requestAnimationFrame === "undefined") return;
783
- // If we already scheduled a relayout, extend the invalidation
784
- // context so we coalesce multiple relayouts in the same frame.
785
- if (this._invalidationContext) {
786
- Object.assign(this._invalidationContext, context);
787
- return;
788
- }
789
- this._invalidationContext = context;
790
- }
791
- /**
792
- * Performs a relayout immediately. Prefer {@link relayout} over this method
793
- * where possible, since it coalesces multiple layout passes in the same tick.
794
- */ relayoutNow(context = this._invalidationContext || {}) {
795
- // Cancel the scheduled relayout, since we're doing it now.
796
- if (this._relayoutRaf) {
797
- cancelAnimationFrame(this._relayoutRaf);
798
- this._relayoutRaf = null;
799
- // Update the provided context with the current invalidationContext since we are cancelling
800
- // a scheduled relayoutNow call that has this._invalidationContext set as its default context arg (relayoutNow() in relayout)
801
- context = {
802
- ...this._invalidationContext,
803
- ...context
804
- };
805
- }
806
- // Reset the invalidation context
807
- this._invalidationContext = null;
808
- // Do nothing if we don't have a layout or content, or we are
809
- // in the middle of an animated scroll transition.
810
- if (!this.layout || !this._collection || this._scrollAnimation) return;
811
- let scrollAnchor = this._getScrollAnchor();
812
- // Trigger the beforeLayout hook, if provided
813
- if (typeof context.beforeLayout === "function") context.beforeLayout();
814
- // Validate the layout
815
- this.layout.validate(context);
816
- this._setContentSize(this.layout.getContentSize());
817
- // Trigger the afterLayout hook, if provided
818
- if (typeof context.afterLayout === "function") context.afterLayout();
819
- // Adjust scroll position based on scroll anchor, and constrain.
820
- // If the content changed, scroll to the top.
821
- let visibleRect = this.getVisibleRect();
822
- let restoredScrollAnchor = this._restoreScrollAnchor(scrollAnchor, context);
823
- let contentOffsetX = context.contentChanged ? 0 : restoredScrollAnchor.x;
824
- let contentOffsetY = context.contentChanged ? 0 : restoredScrollAnchor.y;
825
- contentOffsetX = Math.max(0, Math.min(this.contentSize.width - visibleRect.width, contentOffsetX));
826
- contentOffsetY = Math.max(0, Math.min(this.contentSize.height - visibleRect.height, contentOffsetY));
827
- let hasLayoutUpdates = false;
828
- if (contentOffsetX !== visibleRect.x || contentOffsetY !== visibleRect.y) {
829
- // If this is an animated relayout, we do not immediately scroll because it would be jittery.
830
- // Save the difference between the current and new content offsets, and apply it to the
831
- // individual content items instead. At the end of the animation, we'll reset and set the
832
- // scroll offset for real. This ensures jitter-free animation since we don't need to sync
833
- // the scroll animation and the content animation.
834
- if (context.animated || !this._animatedContentOffset.isOrigin()) {
835
- this._animatedContentOffset.x += visibleRect.x - contentOffsetX;
836
- this._animatedContentOffset.y += visibleRect.y - contentOffsetY;
837
- hasLayoutUpdates = this.updateSubviews(context.contentChanged);
838
- } else this._setContentOffset(new (0, $3041db3296945e6e$export$baf26146a414f24a)(contentOffsetX, contentOffsetY));
839
- } else hasLayoutUpdates = this.updateSubviews(context.contentChanged);
840
- // Apply layout infos, unless this is coming from an animated transaction
841
- if (!(context.transaction && context.animated)) this._applyLayoutInfos();
842
- // Wait for animations, and apply the afterAnimation hook, if provided
843
- if (context.animated && hasLayoutUpdates) {
844
- this._enableTransitions();
845
- let done = ()=>{
846
- this._disableTransitions();
847
- // Reset scroll position after animations (see above comment).
848
- if (!this._animatedContentOffset.isOrigin()) {
849
- // Get the content offset to scroll to, taking _animatedContentOffset into account.
850
- let { x: x, y: y } = this.getVisibleRect();
851
- this._resetAnimatedContentOffset();
852
- this._setContentOffset(new (0, $3041db3296945e6e$export$baf26146a414f24a)(x, y));
853
- }
854
- if (typeof context.afterAnimation === "function") context.afterAnimation();
855
- };
856
- // Sometimes the animation takes slightly longer than expected.
857
- setTimeout(done, this.transitionDuration + 100);
858
- return;
859
- } else if (typeof context.afterAnimation === "function") context.afterAnimation();
860
- }
861
- /**
862
- * Corrects DOM order of visible views to match item order of collection.
863
- */ _correctItemOrder() {
864
- // Defer until after scrolling and animated transactions are complete
865
- if (this._isScrolling || this._transaction) return;
866
- for (let key of this._visibleLayoutInfos.keys()){
867
- let view = this._visibleViews.get(key);
868
- this._children.delete(view);
869
- this._children.add(view);
870
- }
871
- }
872
- _enableTransitions() {
873
- this.delegate.beginAnimations();
874
- }
875
- _disableTransitions() {
876
- this.delegate.endAnimations();
877
- }
878
- _getScrollAnchor() {
879
- if (!this.anchorScrollPosition) return null;
880
- let visibleRect = this.getVisibleRect();
881
- // Ask the delegate to provide a scroll anchor, if possible
882
- if (this.delegate.getScrollAnchor) {
883
- let key = this.delegate.getScrollAnchor(visibleRect);
884
- if (key != null) {
885
- let layoutInfo = this.layout.getLayoutInfo(key);
886
- let corner = layoutInfo.rect.getCornerInRect(visibleRect);
887
- if (corner) {
888
- let key = layoutInfo.key;
889
- let offset = layoutInfo.rect[corner].y - visibleRect.y;
890
- return {
891
- key: key,
892
- layoutInfo: layoutInfo,
893
- corner: corner,
894
- offset: offset
895
- };
896
- }
897
- }
898
- }
899
- // No need to anchor the scroll position if it is at the top
900
- if (visibleRect.y === 0 && !this.anchorScrollPositionAtTop) return null;
901
- // Find a view with a visible corner that has the smallest distance to the top of the collection view
902
- let cornerAnchor = null;
903
- for (let [key, view] of this._visibleViews){
904
- let layoutInfo = view.layoutInfo;
905
- if (layoutInfo && layoutInfo.rect.area > 0) {
906
- let corner = layoutInfo.rect.getCornerInRect(visibleRect);
907
- if (corner) {
908
- let offset = layoutInfo.rect[corner].y - visibleRect.y;
909
- if (!cornerAnchor || offset < cornerAnchor.offset) cornerAnchor = {
910
- key: key,
911
- layoutInfo: layoutInfo,
912
- corner: corner,
913
- offset: offset
914
- };
915
- }
916
- }
917
- }
918
- return cornerAnchor;
919
- }
920
- _restoreScrollAnchor(scrollAnchor, context) {
921
- let contentOffset = this.getVisibleRect();
922
- if (scrollAnchor) {
923
- var _context_transaction;
924
- let finalAnchor = ((_context_transaction = context.transaction) === null || _context_transaction === void 0 ? void 0 : _context_transaction.animated) ? context.transaction.finalMap.get(scrollAnchor.key) : this.layout.getLayoutInfo(scrollAnchor.layoutInfo.key);
925
- if (finalAnchor) {
926
- let adjustment = finalAnchor.rect[scrollAnchor.corner].y - contentOffset.y - scrollAnchor.offset;
927
- contentOffset.y += adjustment;
928
- }
929
- }
930
- return contentOffset;
931
- }
932
- getVisibleRect() {
933
- let v = this.visibleRect;
934
- let x = v.x - this._animatedContentOffset.x;
935
- let y = v.y - this._animatedContentOffset.y;
936
- return new (0, $60423f92c7f9ad87$export$c79fc6492f3af13d)(x, y, v.width, v.height);
937
- }
938
- getVisibleLayoutInfos() {
939
- let isTestEnv = false;
940
- let isClientWidthMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes("clientWidth");
941
- let isClientHeightMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes("clientHeight");
942
- let rect;
943
- if (isTestEnv && !(isClientWidthMocked && isClientHeightMocked)) rect = this._getContentRect();
944
- else rect = this.shouldOverscan ? this._overscanManager.getOverscannedRect() : this.getVisibleRect();
945
- this._visibleLayoutInfos = this._getLayoutInfoMap(rect);
946
- return this._visibleLayoutInfos;
947
- }
948
- _getLayoutInfoMap(rect, copy = false) {
949
- let layoutInfos = this.layout.getVisibleLayoutInfos(rect);
950
- let map = new Map;
951
- for (let layoutInfo of layoutInfos){
952
- if (copy) layoutInfo = layoutInfo.copy();
953
- map.set(layoutInfo.key, layoutInfo);
954
- }
955
- return map;
956
- }
957
- updateSubviews(forceUpdate = false) {
958
- if (!this._collection) return;
959
- let visibleLayoutInfos = this.getVisibleLayoutInfos();
960
- let currentlyVisible = this._visibleViews;
961
- let toAdd, toRemove, toUpdate;
962
- // If this is a force update, remove and re-add all views.
963
- // Otherwise, find and update the diff.
964
- if (forceUpdate) {
965
- toAdd = visibleLayoutInfos;
966
- toRemove = currentlyVisible;
967
- toUpdate = new Set();
968
- } else {
969
- ({ toAdd: toAdd, toRemove: toRemove, toUpdate: toUpdate } = (0, $fc36f9a046a9ce79$export$acaf96a27438246b)(currentlyVisible, visibleLayoutInfos));
970
- for (let key of toUpdate){
971
- let view = currentlyVisible.get(key);
972
- if (!view || !view.layoutInfo) continue;
973
- let item = this.getItem(visibleLayoutInfos.get(key).key);
974
- if (view.content === item) toUpdate.delete(key);
975
- else {
976
- // If the view type changes, delete and recreate the view instead of updating
977
- let { reuseType: reuseType } = this._getReuseType(view.layoutInfo, item);
978
- if (view.viewType !== reuseType) {
979
- toUpdate.delete(key);
980
- toAdd.add(key);
981
- toRemove.add(key);
982
- }
983
- }
984
- }
985
- // We are done if the sets are equal
986
- if (toAdd.size === 0 && toRemove.size === 0 && toUpdate.size === 0) {
987
- if (this._transaction) this._applyLayoutInfos();
988
- return;
989
- }
990
- }
991
- // Track views that should be removed. They are not removed from
992
- // the DOM immediately, since we may reuse and need to re-insert
993
- // them back into the DOM anyway.
994
- let removed = new Set();
995
- for (let key of toRemove.keys()){
996
- let view = this._visibleViews.get(key);
997
- if (view) {
998
- removed.add(view);
999
- this._visibleViews.delete(key);
1000
- // If we are in the middle of a transaction, wait until the end
1001
- // of the animations to remove the views from the DOM. Also means
1002
- // we can't reuse those views immediately.
1003
- if (this._transaction) this._transaction.toRemove.set(key, view);
1004
- else this.reuseView(view);
1005
- }
1006
- }
1007
- for (let key of toAdd.keys()){
1008
- let layoutInfo = visibleLayoutInfos.get(key);
1009
- let view;
1010
- // If we're in a transaction, and a layout change happens
1011
- // during the animations such that a view that was going
1012
- // to be removed is now not, we don't create a new view
1013
- // since the old one is still in the DOM, marked as toRemove.
1014
- if (this._transaction) {
1015
- // if transaction, get initial layout attributes for the animation
1016
- if (this._transaction.initialLayoutInfo.has(key)) layoutInfo = this._transaction.initialLayoutInfo.get(key);
1017
- view = this._transaction.toRemove.get(key);
1018
- if (view) {
1019
- this._transaction.toRemove.delete(key);
1020
- this._applyLayoutInfo(view, layoutInfo);
1021
- }
1022
- }
1023
- if (!view) {
1024
- // Create or reuse a view for this row
1025
- view = this.getReusableView(layoutInfo);
1026
- // Add the view to the DOM if needed
1027
- if (!removed.has(view)) this._children.add(view);
1028
- }
1029
- this._visibleViews.set(key, view);
1030
- removed.delete(view);
1031
- }
1032
- for (let key of toUpdate){
1033
- let view = currentlyVisible.get(key);
1034
- this._renderedContent.delete(key);
1035
- this._renderView(view);
1036
- }
1037
- // Remove the remaining rows to delete from the DOM
1038
- if (!this._transaction) this.removeViews(removed);
1039
- this._correctItemOrder();
1040
- this._flushVisibleViews();
1041
- let hasLayoutUpdates = this._transaction && (toAdd.size > 0 || toRemove.size > 0 || this._hasLayoutUpdates());
1042
- if (hasLayoutUpdates) requestAnimationFrame(()=>{
1043
- // If we're in a transaction, apply animations to visible views
1044
- // and "to be removed" views, which animate off screen.
1045
- if (this._transaction) requestAnimationFrame(()=>this._applyLayoutInfos());
1046
- });
1047
- return hasLayoutUpdates;
1048
- }
1049
- afterRender() {
1050
- if (this._transactionQueue.length > 0) this._processTransactionQueue();
1051
- else if (this._invalidationContext) this.relayoutNow();
1052
- if (this.shouldOverscan) this._overscanManager.collectMetrics();
1053
- }
1054
- _flushVisibleViews() {
1055
- // CollectionVirtualizer deals with a flattened set of LayoutInfos, but they can represent hierarchy
1056
- // by referencing a parentKey. Just before rendering the visible views, we rebuild this hierarchy
1057
- // by creating a mapping of views by parent key and recursively calling the delegate's renderWrapper
1058
- // method to build the final tree.
1059
- let viewsByParentKey = new Map([
1060
- [
1061
- null,
1062
- []
1063
- ]
1064
- ]);
1065
- for (let view of this._children){
1066
- var _view_layoutInfo, _viewsByParentKey_get, _view_layoutInfo1, _view_layoutInfo2, _view_layoutInfo3;
1067
- if (((_view_layoutInfo = view.layoutInfo) === null || _view_layoutInfo === void 0 ? void 0 : _view_layoutInfo.parentKey) != null && !viewsByParentKey.has(view.layoutInfo.parentKey)) viewsByParentKey.set(view.layoutInfo.parentKey, []);
1068
- (_viewsByParentKey_get = viewsByParentKey.get((_view_layoutInfo1 = view.layoutInfo) === null || _view_layoutInfo1 === void 0 ? void 0 : _view_layoutInfo1.parentKey)) === null || _viewsByParentKey_get === void 0 ? void 0 : _viewsByParentKey_get.push(view);
1069
- if (!viewsByParentKey.has((_view_layoutInfo2 = view.layoutInfo) === null || _view_layoutInfo2 === void 0 ? void 0 : _view_layoutInfo2.key)) viewsByParentKey.set((_view_layoutInfo3 = view.layoutInfo) === null || _view_layoutInfo3 === void 0 ? void 0 : _view_layoutInfo3.key, []);
1070
- }
1071
- let buildTree = (parent, views)=>views.map((view)=>{
1072
- let children = viewsByParentKey.get(view.layoutInfo.key);
1073
- return this.delegate.renderWrapper(parent, view, children, (childViews)=>buildTree(view, childViews));
1074
- });
1075
- let children = buildTree(null, viewsByParentKey.get(null));
1076
- this.delegate.setVisibleViews(children);
1077
- }
1078
- _applyLayoutInfo(view, layoutInfo) {
1079
- if (view.layoutInfo === layoutInfo) return false;
1080
- view.layoutInfo = layoutInfo;
1081
- return true;
1082
- }
1083
- _applyLayoutInfos() {
1084
- let updated = false;
1085
- // Apply layout infos to visible views
1086
- for (let view of this._visibleViews.values()){
1087
- let cur = view.layoutInfo;
1088
- if ((cur === null || cur === void 0 ? void 0 : cur.key) != null) {
1089
- let layoutInfo = this.layout.getLayoutInfo(cur.key);
1090
- if (this._applyLayoutInfo(view, layoutInfo)) updated = true;
1091
- }
1092
- }
1093
- // Apply final layout infos for views that will be removed
1094
- if (this._transaction) {
1095
- for (let view of this._transaction.toRemove.values()){
1096
- let cur = view.layoutInfo;
1097
- if ((cur === null || cur === void 0 ? void 0 : cur.key) != null) {
1098
- let layoutInfo = this.layout.getLayoutInfo(cur.key);
1099
- if (this._applyLayoutInfo(view, layoutInfo)) updated = true;
1100
- }
1101
- }
1102
- for (let view of this._transaction.removed.values()){
1103
- let cur = view.layoutInfo;
1104
- let layoutInfo = this._transaction.finalLayoutInfo.get(cur.key) || cur;
1105
- layoutInfo = this.layout.getFinalLayoutInfo(layoutInfo.copy());
1106
- if (this._applyLayoutInfo(view, layoutInfo)) updated = true;
1107
- }
1108
- }
1109
- if (updated) this._flushVisibleViews();
1110
- }
1111
- _hasLayoutUpdates() {
1112
- if (!this._transaction) return false;
1113
- for (let view of this._visibleViews.values()){
1114
- let cur = view.layoutInfo;
1115
- if (!cur) return true;
1116
- let layoutInfo = this.layout.getLayoutInfo(cur.key);
1117
- if (// Uses equals rather than pointEquals so that width/height changes are taken into account
1118
- !cur.rect.equals(layoutInfo.rect) || cur.opacity !== layoutInfo.opacity || cur.transform !== layoutInfo.transform) return true;
1119
- }
1120
- return false;
1121
- }
1122
- reuseView(view) {
1123
- view.prepareForReuse();
1124
- this._reusableViews[view.viewType].push(view);
1125
- }
1126
- removeViews(toRemove) {
1127
- for (let view of toRemove)this._children.delete(view);
1128
- }
1129
- updateItemSize(key, size) {
1130
- // TODO: we should be able to invalidate a single index path
1131
- // @ts-ignore
1132
- if (!this.layout.updateItemSize) return;
1133
- // If the scroll position is currently animating, add the update
1134
- // to a queue to be processed after the animation is complete.
1135
- if (this._scrollAnimation) {
1136
- this._sizeUpdateQueue.set(key, size);
1137
- return;
1138
- }
1139
- // @ts-ignore
1140
- let changed = this.layout.updateItemSize(key, size);
1141
- if (changed) this.relayout();
1142
- }
1143
- startScrolling() {
1144
- this._isScrolling = true;
1145
- }
1146
- endScrolling() {
1147
- this._isScrolling = false;
1148
- this._correctItemOrder();
1149
- this._flushVisibleViews();
1150
- }
1151
- _resetAnimatedContentOffset() {
1152
- // Reset the animated content offset of subviews. See comment in relayoutNow for details.
1153
- if (!this._animatedContentOffset.isOrigin()) {
1154
- this._animatedContentOffset = new (0, $3041db3296945e6e$export$baf26146a414f24a)(0, 0);
1155
- this._applyLayoutInfos();
1156
- }
1157
- }
1158
- /**
1159
- * Scrolls the item with the given key into view, optionally with an animation.
1160
- * @param key The key of the item to scroll into view.
1161
- * @param duration The duration of the scroll animation.
1162
- */ scrollToItem(key, options) {
1163
- // key can be 0, so check if null or undefined
1164
- if (key == null) return;
1165
- let layoutInfo = this.layout.getLayoutInfo(key);
1166
- if (!layoutInfo) return;
1167
- let { duration: duration = 300, shouldScrollX: shouldScrollX = true, shouldScrollY: shouldScrollY = true, offsetX: offsetX = 0, offsetY: offsetY = 0 } = options;
1168
- let x = this.visibleRect.x;
1169
- let y = this.visibleRect.y;
1170
- let minX = layoutInfo.rect.x - offsetX;
1171
- let minY = layoutInfo.rect.y - offsetY;
1172
- let maxX = x + this.visibleRect.width;
1173
- let maxY = y + this.visibleRect.height;
1174
- if (shouldScrollX) {
1175
- if (minX <= x || maxX === 0) x = minX;
1176
- else if (layoutInfo.rect.maxX > maxX) x += layoutInfo.rect.maxX - maxX;
1177
- }
1178
- if (shouldScrollY) {
1179
- if (minY <= y || maxY === 0) y = minY;
1180
- else if (layoutInfo.rect.maxY > maxY) y += layoutInfo.rect.maxY - maxY;
1181
- }
1182
- return this.scrollTo(new (0, $3041db3296945e6e$export$baf26146a414f24a)(x, y), duration);
1183
- }
1184
- /**
1185
- * Performs an animated scroll to the given offset.
1186
- * @param offset - The offset to scroll to.
1187
- * @param duration The duration of the animation.
1188
- * @returns A promise that resolves when the animation is complete.
1189
- */ scrollTo(offset, duration = 300) {
1190
- // Cancel the current scroll animation
1191
- if (this._scrollAnimation) {
1192
- this._scrollAnimation.cancel();
1193
- this._scrollAnimation = null;
1194
- }
1195
- // Set the content offset synchronously if the duration is zero
1196
- if (duration <= 0 || this.visibleRect.pointEquals(offset)) {
1197
- this._setContentOffset(offset);
1198
- return Promise.resolve();
1199
- }
1200
- this.startScrolling();
1201
- this._scrollAnimation = (0, $3eb131dcf37ad5f8$export$dc0b63720788090c)(this.visibleRect, offset, duration, (0, $3eb131dcf37ad5f8$export$57636bb43b1ccbb0), (offset)=>{
1202
- this._setContentOffset(offset);
1203
- });
1204
- this._scrollAnimation.then(()=>{
1205
- this._scrollAnimation = null;
1206
- // Process view size updates that occurred during the animation.
1207
- // Only views that are still visible will be actually updated.
1208
- for (let [key, size] of this._sizeUpdateQueue)this.updateItemSize(key, size);
1209
- this._sizeUpdateQueue.clear();
1210
- this.relayout();
1211
- this._processTransactionQueue();
1212
- this.endScrolling();
1213
- });
1214
- return this._scrollAnimation;
1215
- }
1216
- _runTransaction(action, animated) {
1217
- this._startTransaction();
1218
- if (this._nextTransaction) this._nextTransaction.actions.push(action);
1219
- this._endTransaction(animated);
1220
- }
1221
- _startTransaction() {
1222
- if (!this._nextTransaction) this._nextTransaction = new (0, $8e135e531d8dcb66$export$febc5573c75cefb0);
1223
- this._nextTransaction.level++;
1224
- }
1225
- _endTransaction(animated) {
1226
- if (!this._nextTransaction) return false;
1227
- // Save whether the transaction should be animated.
1228
- if (animated != null) this._nextTransaction.animated = animated;
1229
- // If we haven't reached level 0, we are still in a
1230
- // nested transaction. Wait for the parent to end.
1231
- if (--this._nextTransaction.level > 0) return false;
1232
- // Do nothing for empty transactions
1233
- if (this._nextTransaction.actions.length === 0) {
1234
- this._nextTransaction = null;
1235
- return false;
1236
- }
1237
- // Default animations to true
1238
- if (this._nextTransaction.animated == null) this._nextTransaction.animated = true;
1239
- // Enqueue the transaction
1240
- this._transactionQueue.push(this._nextTransaction);
1241
- this._nextTransaction = null;
1242
- return true;
1243
- }
1244
- _processTransactionQueue() {
1245
- // If the current transaction is animating, wait until the end
1246
- // to process the next transaction.
1247
- if (this._transaction || this._scrollAnimation) return;
1248
- let next = this._transactionQueue.shift();
1249
- if (next) this._performTransaction(next);
1250
- }
1251
- _getContentRect() {
1252
- return new (0, $60423f92c7f9ad87$export$c79fc6492f3af13d)(0, 0, this.contentSize.width, this.contentSize.height);
1253
- }
1254
- _performTransaction(transaction) {
1255
- this._transaction = transaction;
1256
- this.relayoutNow({
1257
- transaction: transaction,
1258
- animated: transaction.animated,
1259
- beforeLayout: ()=>{
1260
- // Get the initial layout infos for all views before the updates
1261
- // so we can figure out which views to add and remove.
1262
- if (transaction.animated) transaction.initialMap = this._getLayoutInfoMap(this._getContentRect(), true);
1263
- // Apply the actions that occurred during this transaction
1264
- for (let action of transaction.actions)action();
1265
- },
1266
- afterLayout: ()=>{
1267
- // Get the final layout infos after the updates
1268
- if (transaction.animated) {
1269
- transaction.finalMap = this._getLayoutInfoMap(this._getContentRect());
1270
- this._setupTransactionAnimations(transaction);
1271
- } else this._transaction = null;
1272
- },
1273
- afterAnimation: ()=>{
1274
- // Remove and reuse views when animations are done
1275
- if (transaction.toRemove.size > 0 || transaction.removed.size > 0) for (let view of (0, $fc36f9a046a9ce79$export$cfc14088dfefce5f)(transaction.toRemove.values(), transaction.removed.values())){
1276
- this._children.delete(view);
1277
- this.reuseView(view);
1278
- }
1279
- this._transaction = null;
1280
- // Ensure DOM order is correct for accessibility after animations are complete
1281
- this._correctItemOrder();
1282
- this._flushVisibleViews();
1283
- this._processTransactionQueue();
1284
- }
1285
- });
1286
- }
1287
- _setupTransactionAnimations(transaction) {
1288
- let { initialMap: initialMap, finalMap: finalMap } = transaction;
1289
- // Store initial and final layout infos for animations
1290
- for (let [key, layoutInfo] of initialMap)if (finalMap.has(key)) // Store the initial layout info for use during animations.
1291
- transaction.initialLayoutInfo.set(key, layoutInfo);
1292
- else // This view was removed. Store the layout info for use
1293
- // in Layout#getFinalLayoutInfo during animations.
1294
- transaction.finalLayoutInfo.set(layoutInfo.key, layoutInfo);
1295
- // Get initial layout infos for views that were added
1296
- for (let [key, layoutInfo] of finalMap)if (!initialMap.has(key)) {
1297
- let initialLayoutInfo = this.layout.getInitialLayoutInfo(layoutInfo.copy());
1298
- transaction.initialLayoutInfo.set(key, initialLayoutInfo);
1299
- }
1300
- // Figure out which views were removed.
1301
- for (let [key, view] of this._visibleViews)// If an item has a width of 0, there is no need to remove it from the _visibleViews.
1302
- // Removing an item with width of 0 can cause a loop where the item gets added, removed,
1303
- // added, removed... etc in a loop.
1304
- if (!finalMap.has(key) && view.layoutInfo.rect.width > 0) {
1305
- transaction.removed.set(key, view);
1306
- this._visibleViews.delete(key);
1307
- // In case something weird happened, where we have a view but no
1308
- // initial layout info, use the one attached to the view.
1309
- if (view.layoutInfo) {
1310
- if (!transaction.finalLayoutInfo.has(view.layoutInfo.key)) transaction.finalLayoutInfo.set(view.layoutInfo.key, view.layoutInfo);
1311
- }
1312
- }
1313
- }
1314
- constructor(options = {}){
1315
- this._contentSize = new (0, $ee1bfa90a957fb8a$export$cb6da89c6af1a8ec);
1316
- this._visibleRect = new (0, $60423f92c7f9ad87$export$c79fc6492f3af13d);
1317
- this._reusableViews = {};
1318
- this._visibleLayoutInfos = new Map();
1319
- this._visibleViews = new Map();
1320
- this._renderedContent = new WeakMap();
1321
- this._children = new Set();
1322
- this._invalidationContext = null;
1323
- this._overscanManager = new (0, $364191b3decf3697$export$4455ee6afb38dcbb)();
1324
- this._persistedKeys = new Set();
1325
- this._scrollAnimation = null;
1326
- this._isScrolling = false;
1327
- this._sizeUpdateQueue = new Map();
1328
- this._animatedContentOffset = new (0, $3041db3296945e6e$export$baf26146a414f24a)(0, 0);
1329
- this._transaction = null;
1330
- this._nextTransaction = null;
1331
- this._transactionQueue = [];
1332
- var _options_transitionDuration;
1333
- // Set options from passed object if given
1334
- this.transitionDuration = (_options_transitionDuration = options.transitionDuration) !== null && _options_transitionDuration !== void 0 ? _options_transitionDuration : 500;
1335
- this.anchorScrollPosition = options.anchorScrollPosition || false;
1336
- this.anchorScrollPositionAtTop = options.anchorScrollPositionAtTop || false;
1337
- this.shouldOverscan = options.shouldOverscan !== false;
1338
- for (let key of [
1339
- "delegate",
1340
- "size",
1341
- "layout",
1342
- "collection"
1343
- ])if (options[key]) this[key] = options[key];
1344
- }
1345
- }
1346
22
 
1347
23
 
1348
- function $fc0b13b484ac1194$export$1505db82fe357e65(opts) {
1349
- let [visibleViews, setVisibleViews] = (0, $8D3nr$useState)([]);
1350
- let [contentSize, setContentSize] = (0, $8D3nr$useState)(new (0, $ee1bfa90a957fb8a$export$cb6da89c6af1a8ec)());
1351
- let [isAnimating, setAnimating] = (0, $8D3nr$useState)(false);
1352
- let [isScrolling, setScrolling] = (0, $8D3nr$useState)(false);
1353
- let virtualizer = (0, $8D3nr$useMemo)(()=>new (0, $38b9490c1cca8fc4$export$89be5a243e59c4b2)(), []);
1354
- virtualizer.delegate = {
1355
- setVisibleViews: setVisibleViews,
1356
- setVisibleRect (rect) {
1357
- virtualizer.visibleRect = rect;
1358
- opts.onVisibleRectChange(rect);
1359
- },
1360
- setContentSize: setContentSize,
1361
- renderView: opts.renderView,
1362
- renderWrapper: opts.renderWrapper,
1363
- beginAnimations: ()=>setAnimating(true),
1364
- endAnimations: ()=>setAnimating(false),
1365
- getScrollAnchor: opts.getScrollAnchor
1366
- };
1367
- virtualizer.layout = opts.layout;
1368
- virtualizer.collection = opts.collection;
1369
- virtualizer.transitionDuration = opts.transitionDuration;
1370
- (0, $8D3nr$useLayoutEffect)(()=>{
1371
- virtualizer.afterRender();
1372
- });
1373
- // eslint-disable-next-line arrow-body-style
1374
- (0, $8D3nr$useEffect)(()=>{
1375
- return ()=>virtualizer.willUnmount();
1376
- // eslint-disable-next-line react-hooks/exhaustive-deps
1377
- }, []);
1378
- let setVisibleRect = (0, $8D3nr$useCallback)((rect)=>{
1379
- virtualizer.visibleRect = rect;
1380
- }, [
1381
- virtualizer
1382
- ]);
1383
- let startScrolling = (0, $8D3nr$useCallback)(()=>{
1384
- virtualizer.startScrolling();
1385
- setScrolling(true);
1386
- }, [
1387
- virtualizer
1388
- ]);
1389
- let endScrolling = (0, $8D3nr$useCallback)(()=>{
1390
- virtualizer.endScrolling();
1391
- setScrolling(false);
1392
- }, [
1393
- virtualizer
1394
- ]);
1395
- let state = (0, $8D3nr$useMemo)(()=>({
1396
- virtualizer: virtualizer,
1397
- visibleViews: visibleViews,
1398
- setVisibleRect: setVisibleRect,
1399
- contentSize: contentSize,
1400
- isAnimating: isAnimating,
1401
- isScrolling: isScrolling,
1402
- startScrolling: startScrolling,
1403
- endScrolling: endScrolling
1404
- }), [
1405
- virtualizer,
1406
- visibleViews,
1407
- setVisibleRect,
1408
- contentSize,
1409
- isAnimating,
1410
- isScrolling,
1411
- startScrolling,
1412
- endScrolling
1413
- ]);
1414
- return state;
1415
- }
1416
24
 
1417
25
 
1418
26