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