@react-stately/layout 3.4.3-nightly.3040 → 3.4.3-nightly.3064

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/module.js CHANGED
@@ -1,901 +1,665 @@
1
- import { Layout, LayoutInfo, Rect, Size } from "@react-stately/virtualizer";
2
- const $f5ce3e4c61ac6cf0e14287baf8f147b$var$DEFAULT_HEIGHT = 48;
3
- /**
4
- * The ListLayout class is an implementation of a collection view {@link Layout}
5
- * it is used for creating lists and lists with indented sub-lists.
6
- *
7
- * To configure a ListLayout, you can use the properties to define the
8
- * layouts and/or use the method for defining indentation.
9
- * The {@link ListKeyboardDelegate} extends the existing collection view
10
- * delegate with an additional method to do this (it uses the same delegate object as
11
- * the collection view itself).
12
- */
1
+ import {Rect as $lwi4v$Rect, LayoutInfo as $lwi4v$LayoutInfo, Size as $lwi4v$Size, Layout as $lwi4v$Layout} from "@react-stately/virtualizer";
13
2
 
14
- export class ListLayout extends Layout {
15
- /**
16
- * Creates a new ListLayout with options. See the list of properties below for a description
17
- * of the options that can be provided.
18
- */
19
- constructor(options) {
20
- if (options === void 0) {
21
- options = {};
22
- }
23
-
24
- super();
25
- this.rowHeight = void 0;
26
- this.estimatedRowHeight = void 0;
27
- this.headingHeight = void 0;
28
- this.estimatedHeadingHeight = void 0;
29
- this.padding = void 0;
30
- this.indentationForItem = void 0;
31
- this.layoutInfos = void 0;
32
- this.layoutNodes = void 0;
33
- this.contentSize = void 0;
34
- this.collection = void 0;
35
- this.disabledKeys = new Set();
36
- this.isLoading = void 0;
37
- this.lastWidth = void 0;
38
- this.lastCollection = void 0;
39
- this.rootNodes = void 0;
40
- this.collator = void 0;
41
- this.invalidateEverything = void 0;
42
- this.loaderHeight = void 0;
43
- this.placeholderHeight = void 0;
44
- this.rowHeight = options.rowHeight;
45
- this.estimatedRowHeight = options.estimatedRowHeight;
46
- this.headingHeight = options.headingHeight;
47
- this.estimatedHeadingHeight = options.estimatedHeadingHeight;
48
- this.padding = options.padding || 0;
49
- this.indentationForItem = options.indentationForItem;
50
- this.collator = options.collator;
51
- this.loaderHeight = options.loaderHeight;
52
- this.placeholderHeight = options.placeholderHeight;
53
- this.layoutInfos = new Map();
54
- this.layoutNodes = new Map();
55
- this.rootNodes = [];
56
- this.lastWidth = 0;
57
- this.lastCollection = null;
58
- }
59
-
60
- getLayoutInfo(key) {
61
- return this.layoutInfos.get(key);
62
- }
63
-
64
- getVisibleLayoutInfos(rect) {
65
- let res = [];
66
-
67
- let addNodes = nodes => {
68
- for (let node of nodes) {
69
- if (this.isVisible(node, rect)) {
70
- res.push(node.layoutInfo);
3
+ function $parcel$export(e, n, v, s) {
4
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
5
+ }
6
+ var $5c162b33e5b4dfc0$exports = {};
71
7
 
72
- if (node.header) {
73
- res.push(node.header);
74
- }
8
+ $parcel$export($5c162b33e5b4dfc0$exports, "ListLayout", () => $5c162b33e5b4dfc0$export$cacbb3924155d68e);
75
9
 
76
- if (node.children) {
77
- addNodes(node.children);
78
- }
10
+ const $5c162b33e5b4dfc0$var$DEFAULT_HEIGHT = 48;
11
+ class $5c162b33e5b4dfc0$export$cacbb3924155d68e extends $lwi4v$Layout {
12
+ /**
13
+ * Creates a new ListLayout with options. See the list of properties below for a description
14
+ * of the options that can be provided.
15
+ */ constructor(options = {
16
+ }){
17
+ super();
18
+ this.disabledKeys = new Set();
19
+ this.rowHeight = options.rowHeight;
20
+ this.estimatedRowHeight = options.estimatedRowHeight;
21
+ this.headingHeight = options.headingHeight;
22
+ this.estimatedHeadingHeight = options.estimatedHeadingHeight;
23
+ this.padding = options.padding || 0;
24
+ this.indentationForItem = options.indentationForItem;
25
+ this.collator = options.collator;
26
+ this.loaderHeight = options.loaderHeight;
27
+ this.placeholderHeight = options.placeholderHeight;
28
+ this.layoutInfos = new Map();
29
+ this.layoutNodes = new Map();
30
+ this.rootNodes = [];
31
+ this.lastWidth = 0;
32
+ this.lastCollection = null;
33
+ }
34
+ getLayoutInfo(key) {
35
+ return this.layoutInfos.get(key);
36
+ }
37
+ getVisibleLayoutInfos(rect) {
38
+ let res = [];
39
+ let addNodes = (nodes)=>{
40
+ for (let node of nodes)if (this.isVisible(node, rect)) {
41
+ res.push(node.layoutInfo);
42
+ if (node.header) res.push(node.header);
43
+ if (node.children) addNodes(node.children);
44
+ }
45
+ };
46
+ addNodes(this.rootNodes);
47
+ return res;
48
+ }
49
+ isVisible(node, rect) {
50
+ return node.layoutInfo.rect.intersects(rect) || node.layoutInfo.isSticky;
51
+ }
52
+ validate(invalidationContext) {
53
+ // Invalidate cache if the size of the collection changed.
54
+ // In this case, we need to recalculate the entire layout.
55
+ this.invalidateEverything = invalidationContext.sizeChanged;
56
+ this.collection = this.virtualizer.collection;
57
+ this.rootNodes = this.buildCollection();
58
+ // Remove deleted layout nodes
59
+ if (this.lastCollection) {
60
+ for (let key of this.lastCollection.getKeys())if (!this.collection.getItem(key)) {
61
+ let layoutNode = this.layoutNodes.get(key);
62
+ if (layoutNode) {
63
+ this.layoutInfos.delete(layoutNode.layoutInfo.key);
64
+ this.layoutInfos.delete(layoutNode.header?.key);
65
+ this.layoutNodes.delete(key);
66
+ }
67
+ }
79
68
  }
80
- }
81
- };
82
-
83
- addNodes(this.rootNodes);
84
- return res;
85
- }
86
-
87
- isVisible(node, rect) {
88
- return node.layoutInfo.rect.intersects(rect) || node.layoutInfo.isSticky;
89
- }
90
-
91
- validate(invalidationContext) {
92
- // Invalidate cache if the size of the collection changed.
93
- // In this case, we need to recalculate the entire layout.
94
- this.invalidateEverything = invalidationContext.sizeChanged;
95
- this.collection = this.virtualizer.collection;
96
- this.rootNodes = this.buildCollection(); // Remove deleted layout nodes
97
-
98
- if (this.lastCollection) {
99
- for (let key of this.lastCollection.getKeys()) {
100
- if (!this.collection.getItem(key)) {
101
- let layoutNode = this.layoutNodes.get(key);
102
-
103
- if (layoutNode) {
104
- var _layoutNode$header;
105
-
106
- this.layoutInfos.delete(layoutNode.layoutInfo.key);
107
- this.layoutInfos.delete((_layoutNode$header = layoutNode.header) == null ? void 0 : _layoutNode$header.key);
108
- this.layoutNodes.delete(key);
109
- }
69
+ this.lastWidth = this.virtualizer.visibleRect.width;
70
+ this.lastCollection = this.collection;
71
+ }
72
+ buildCollection() {
73
+ let y = this.padding;
74
+ let nodes = [];
75
+ for (let node of this.collection){
76
+ let layoutNode = this.buildChild(node, 0, y);
77
+ y = layoutNode.layoutInfo.rect.maxY;
78
+ nodes.push(layoutNode);
79
+ }
80
+ if (this.isLoading) {
81
+ let rect = new $lwi4v$Rect(0, y, this.virtualizer.visibleRect.width, this.loaderHeight ?? this.virtualizer.visibleRect.height);
82
+ let loader = new $lwi4v$LayoutInfo('loader', 'loader', rect);
83
+ this.layoutInfos.set('loader', loader);
84
+ nodes.push({
85
+ layoutInfo: loader
86
+ });
87
+ y = loader.rect.maxY;
88
+ }
89
+ if (nodes.length === 0) {
90
+ let rect = new $lwi4v$Rect(0, y, this.virtualizer.visibleRect.width, this.placeholderHeight ?? this.virtualizer.visibleRect.height);
91
+ let placeholder = new $lwi4v$LayoutInfo('placeholder', 'placeholder', rect);
92
+ this.layoutInfos.set('placeholder', placeholder);
93
+ nodes.push({
94
+ layoutInfo: placeholder
95
+ });
96
+ y = placeholder.rect.maxY;
97
+ }
98
+ this.contentSize = new $lwi4v$Size(this.virtualizer.visibleRect.width, y + this.padding);
99
+ return nodes;
100
+ }
101
+ buildChild(node, x, y) {
102
+ let cached = this.layoutNodes.get(node.key);
103
+ if (!this.invalidateEverything && cached && cached.node === node && y === (cached.header || cached.layoutInfo).rect.y) return cached;
104
+ let layoutNode = this.buildNode(node, x, y);
105
+ layoutNode.node = node;
106
+ layoutNode.layoutInfo.parentKey = node.parentKey || null;
107
+ this.layoutInfos.set(layoutNode.layoutInfo.key, layoutNode.layoutInfo);
108
+ if (layoutNode.header) this.layoutInfos.set(layoutNode.header.key, layoutNode.header);
109
+ this.layoutNodes.set(node.key, layoutNode);
110
+ return layoutNode;
111
+ }
112
+ buildNode(node, x, y) {
113
+ switch(node.type){
114
+ case 'section':
115
+ return this.buildSection(node, x, y);
116
+ case 'item':
117
+ return this.buildItem(node, x, y);
110
118
  }
111
- }
112
- }
113
-
114
- this.lastWidth = this.virtualizer.visibleRect.width;
115
- this.lastCollection = this.collection;
116
- }
117
-
118
- buildCollection() {
119
- let y = this.padding;
120
- let nodes = [];
121
-
122
- for (let node of this.collection) {
123
- let layoutNode = this.buildChild(node, 0, y);
124
- y = layoutNode.layoutInfo.rect.maxY;
125
- nodes.push(layoutNode);
126
- }
127
-
128
- if (this.isLoading) {
129
- var _this$loaderHeight;
130
-
131
- let rect = new Rect(0, y, this.virtualizer.visibleRect.width, (_this$loaderHeight = this.loaderHeight) != null ? _this$loaderHeight : this.virtualizer.visibleRect.height);
132
- let loader = new LayoutInfo('loader', 'loader', rect);
133
- this.layoutInfos.set('loader', loader);
134
- nodes.push({
135
- layoutInfo: loader
136
- });
137
- y = loader.rect.maxY;
138
- }
139
-
140
- if (nodes.length === 0) {
141
- var _this$placeholderHeig;
142
-
143
- let rect = new Rect(0, y, this.virtualizer.visibleRect.width, (_this$placeholderHeig = this.placeholderHeight) != null ? _this$placeholderHeig : this.virtualizer.visibleRect.height);
144
- let placeholder = new LayoutInfo('placeholder', 'placeholder', rect);
145
- this.layoutInfos.set('placeholder', placeholder);
146
- nodes.push({
147
- layoutInfo: placeholder
148
- });
149
- y = placeholder.rect.maxY;
150
- }
151
-
152
- this.contentSize = new Size(this.virtualizer.visibleRect.width, y + this.padding);
153
- return nodes;
154
- }
155
-
156
- buildChild(node, x, y) {
157
- let cached = this.layoutNodes.get(node.key);
158
-
159
- if (!this.invalidateEverything && cached && cached.node === node && y === (cached.header || cached.layoutInfo).rect.y) {
160
- return cached;
161
- }
162
-
163
- let layoutNode = this.buildNode(node, x, y);
164
- layoutNode.node = node;
165
- layoutNode.layoutInfo.parentKey = node.parentKey || null;
166
- this.layoutInfos.set(layoutNode.layoutInfo.key, layoutNode.layoutInfo);
167
-
168
- if (layoutNode.header) {
169
- this.layoutInfos.set(layoutNode.header.key, layoutNode.header);
170
- }
171
-
172
- this.layoutNodes.set(node.key, layoutNode);
173
- return layoutNode;
174
- }
175
-
176
- buildNode(node, x, y) {
177
- switch (node.type) {
178
- case 'section':
179
- return this.buildSection(node, x, y);
180
-
181
- case 'item':
182
- return this.buildItem(node, x, y);
183
- }
184
- }
185
-
186
- buildSection(node, x, y) {
187
- let width = this.virtualizer.visibleRect.width;
188
- let rectHeight = this.headingHeight;
189
- let isEstimated = false; // If no explicit height is available, use an estimated height.
190
-
191
- if (rectHeight == null) {
192
- // If a previous version of this layout info exists, reuse its height.
193
- // Mark as estimated if the size of the overall collection view changed,
194
- // or the content of the item changed.
195
- let previousLayoutNode = this.layoutNodes.get(node.key);
196
-
197
- if (previousLayoutNode && previousLayoutNode.header) {
198
- let curNode = this.collection.getItem(node.key);
199
- let lastNode = this.lastCollection ? this.lastCollection.getItem(node.key) : null;
200
- rectHeight = previousLayoutNode.header.rect.height;
201
- isEstimated = width !== this.lastWidth || curNode !== lastNode || previousLayoutNode.header.estimatedSize;
202
- } else {
203
- rectHeight = node.rendered ? this.estimatedHeadingHeight : 0;
204
- isEstimated = true;
205
- }
206
- }
207
-
208
- if (rectHeight == null) {
209
- rectHeight = $f5ce3e4c61ac6cf0e14287baf8f147b$var$DEFAULT_HEIGHT;
210
- }
211
-
212
- let headerRect = new Rect(0, y, width, rectHeight);
213
- let header = new LayoutInfo('header', node.key + ':header', headerRect);
214
- header.estimatedSize = isEstimated;
215
- header.parentKey = node.key;
216
- y += header.rect.height;
217
- let rect = new Rect(0, y, width, 0);
218
- let layoutInfo = new LayoutInfo(node.type, node.key, rect);
219
- let startY = y;
220
- let children = [];
221
-
222
- for (let child of node.childNodes) {
223
- let layoutNode = this.buildChild(child, x, y);
224
- y = layoutNode.layoutInfo.rect.maxY;
225
- children.push(layoutNode);
226
- }
227
-
228
- rect.height = y - startY;
229
- return {
230
- header,
231
- layoutInfo,
232
- children
233
- };
234
- }
235
-
236
- buildItem(node, x, y) {
237
- let width = this.virtualizer.visibleRect.width;
238
- let rectHeight = this.rowHeight;
239
- let isEstimated = false; // If no explicit height is available, use an estimated height.
240
-
241
- if (rectHeight == null) {
242
- // If a previous version of this layout info exists, reuse its height.
243
- // Mark as estimated if the size of the overall collection view changed,
244
- // or the content of the item changed.
245
- let previousLayoutNode = this.layoutNodes.get(node.key);
246
-
247
- if (previousLayoutNode) {
248
- let curNode = this.collection.getItem(node.key);
249
- let lastNode = this.lastCollection ? this.lastCollection.getItem(node.key) : null;
250
- rectHeight = previousLayoutNode.layoutInfo.rect.height;
251
- isEstimated = width !== this.lastWidth || curNode !== lastNode || previousLayoutNode.layoutInfo.estimatedSize;
252
- } else {
253
- rectHeight = this.estimatedRowHeight;
254
- isEstimated = true;
255
- }
256
- }
257
-
258
- if (rectHeight == null) {
259
- rectHeight = $f5ce3e4c61ac6cf0e14287baf8f147b$var$DEFAULT_HEIGHT;
260
- }
261
-
262
- if (typeof this.indentationForItem === 'function') {
263
- x += this.indentationForItem(this.collection, node.key) || 0;
264
- }
265
-
266
- let rect = new Rect(x, y, width - x, rectHeight);
267
- let layoutInfo = new LayoutInfo(node.type, node.key, rect);
268
- layoutInfo.estimatedSize = isEstimated;
269
- return {
270
- layoutInfo
271
- };
272
- }
273
-
274
- updateItemSize(key, size) {
275
- let layoutInfo = this.layoutInfos.get(key); // If no layoutInfo, item has been deleted/removed.
276
-
277
- if (!layoutInfo) {
278
- return false;
279
- }
280
-
281
- layoutInfo.estimatedSize = false;
282
-
283
- if (layoutInfo.rect.height !== size.height) {
284
- // Copy layout info rather than mutating so that later caches are invalidated.
285
- let newLayoutInfo = layoutInfo.copy();
286
- newLayoutInfo.rect.height = size.height;
287
- this.layoutInfos.set(key, newLayoutInfo); // Invalidate layout for this layout node and all parents
288
-
289
- this.updateLayoutNode(key, layoutInfo, newLayoutInfo);
290
- let node = this.collection.getItem(layoutInfo.parentKey);
291
-
292
- while (node) {
293
- this.updateLayoutNode(node.key, layoutInfo, newLayoutInfo);
294
- node = this.collection.getItem(node.parentKey);
295
- }
296
-
297
- return true;
298
- }
299
-
300
- return false;
301
- }
302
-
303
- updateLayoutNode(key, oldLayoutInfo, newLayoutInfo) {
304
- let n = this.layoutNodes.get(key);
305
-
306
- if (n) {
307
- // Invalidate by clearing node.
308
- n.node = null; // Replace layout info in LayoutNode
309
-
310
- if (n.header === oldLayoutInfo) {
311
- n.header = newLayoutInfo;
312
- } else if (n.layoutInfo === oldLayoutInfo) {
313
- n.layoutInfo = newLayoutInfo;
314
- }
315
- }
316
- }
317
-
318
- getContentSize() {
319
- return this.contentSize;
320
- }
321
-
322
- getKeyAbove(key) {
323
- let collection = this.collection;
324
- key = collection.getKeyBefore(key);
325
-
326
- while (key != null) {
327
- let item = collection.getItem(key);
328
-
329
- if (item.type === 'item' && !this.disabledKeys.has(item.key)) {
330
- return key;
331
- }
332
-
333
- key = collection.getKeyBefore(key);
334
119
  }
335
- }
336
-
337
- getKeyBelow(key) {
338
- let collection = this.collection;
339
- key = collection.getKeyAfter(key);
340
-
341
- while (key != null) {
342
- let item = collection.getItem(key);
343
-
344
- if (item.type === 'item' && !this.disabledKeys.has(item.key)) {
345
- return key;
346
- }
347
-
348
- key = collection.getKeyAfter(key);
120
+ buildSection(node, x, y) {
121
+ let width = this.virtualizer.visibleRect.width;
122
+ let rectHeight = this.headingHeight;
123
+ let isEstimated = false;
124
+ // If no explicit height is available, use an estimated height.
125
+ if (rectHeight == null) {
126
+ // If a previous version of this layout info exists, reuse its height.
127
+ // Mark as estimated if the size of the overall collection view changed,
128
+ // or the content of the item changed.
129
+ let previousLayoutNode = this.layoutNodes.get(node.key);
130
+ if (previousLayoutNode && previousLayoutNode.header) {
131
+ let curNode = this.collection.getItem(node.key);
132
+ let lastNode = this.lastCollection ? this.lastCollection.getItem(node.key) : null;
133
+ rectHeight = previousLayoutNode.header.rect.height;
134
+ isEstimated = width !== this.lastWidth || curNode !== lastNode || previousLayoutNode.header.estimatedSize;
135
+ } else {
136
+ rectHeight = node.rendered ? this.estimatedHeadingHeight : 0;
137
+ isEstimated = true;
138
+ }
139
+ }
140
+ if (rectHeight == null) rectHeight = $5c162b33e5b4dfc0$var$DEFAULT_HEIGHT;
141
+ let headerRect = new $lwi4v$Rect(0, y, width, rectHeight);
142
+ let header = new $lwi4v$LayoutInfo('header', node.key + ':header', headerRect);
143
+ header.estimatedSize = isEstimated;
144
+ header.parentKey = node.key;
145
+ y += header.rect.height;
146
+ let rect = new $lwi4v$Rect(0, y, width, 0);
147
+ let layoutInfo = new $lwi4v$LayoutInfo(node.type, node.key, rect);
148
+ let startY = y;
149
+ let children = [];
150
+ for (let child of node.childNodes){
151
+ let layoutNode = this.buildChild(child, x, y);
152
+ y = layoutNode.layoutInfo.rect.maxY;
153
+ children.push(layoutNode);
154
+ }
155
+ rect.height = y - startY;
156
+ return {
157
+ header: header,
158
+ layoutInfo: layoutInfo,
159
+ children: children
160
+ };
161
+ }
162
+ buildItem(node, x, y) {
163
+ let width = this.virtualizer.visibleRect.width;
164
+ let rectHeight = this.rowHeight;
165
+ let isEstimated = false;
166
+ // If no explicit height is available, use an estimated height.
167
+ if (rectHeight == null) {
168
+ // If a previous version of this layout info exists, reuse its height.
169
+ // Mark as estimated if the size of the overall collection view changed,
170
+ // or the content of the item changed.
171
+ let previousLayoutNode = this.layoutNodes.get(node.key);
172
+ if (previousLayoutNode) {
173
+ let curNode = this.collection.getItem(node.key);
174
+ let lastNode = this.lastCollection ? this.lastCollection.getItem(node.key) : null;
175
+ rectHeight = previousLayoutNode.layoutInfo.rect.height;
176
+ isEstimated = width !== this.lastWidth || curNode !== lastNode || previousLayoutNode.layoutInfo.estimatedSize;
177
+ } else {
178
+ rectHeight = this.estimatedRowHeight;
179
+ isEstimated = true;
180
+ }
181
+ }
182
+ if (rectHeight == null) rectHeight = $5c162b33e5b4dfc0$var$DEFAULT_HEIGHT;
183
+ if (typeof this.indentationForItem === 'function') x += this.indentationForItem(this.collection, node.key) || 0;
184
+ let rect = new $lwi4v$Rect(x, y, width - x, rectHeight);
185
+ let layoutInfo = new $lwi4v$LayoutInfo(node.type, node.key, rect);
186
+ layoutInfo.estimatedSize = isEstimated;
187
+ return {
188
+ layoutInfo: layoutInfo
189
+ };
190
+ }
191
+ updateItemSize(key, size) {
192
+ let layoutInfo = this.layoutInfos.get(key);
193
+ // If no layoutInfo, item has been deleted/removed.
194
+ if (!layoutInfo) return false;
195
+ layoutInfo.estimatedSize = false;
196
+ if (layoutInfo.rect.height !== size.height) {
197
+ // Copy layout info rather than mutating so that later caches are invalidated.
198
+ let newLayoutInfo = layoutInfo.copy();
199
+ newLayoutInfo.rect.height = size.height;
200
+ this.layoutInfos.set(key, newLayoutInfo);
201
+ // Invalidate layout for this layout node and all parents
202
+ this.updateLayoutNode(key, layoutInfo, newLayoutInfo);
203
+ let node = this.collection.getItem(layoutInfo.parentKey);
204
+ while(node){
205
+ this.updateLayoutNode(node.key, layoutInfo, newLayoutInfo);
206
+ node = this.collection.getItem(node.parentKey);
207
+ }
208
+ return true;
209
+ }
210
+ return false;
211
+ }
212
+ updateLayoutNode(key, oldLayoutInfo, newLayoutInfo) {
213
+ let n = this.layoutNodes.get(key);
214
+ if (n) {
215
+ // Invalidate by clearing node.
216
+ n.node = null;
217
+ // Replace layout info in LayoutNode
218
+ if (n.header === oldLayoutInfo) n.header = newLayoutInfo;
219
+ else if (n.layoutInfo === oldLayoutInfo) n.layoutInfo = newLayoutInfo;
220
+ }
349
221
  }
350
- }
351
-
352
- getKeyPageAbove(key) {
353
- let layoutInfo = this.getLayoutInfo(key);
354
-
355
- if (layoutInfo) {
356
- let pageY = Math.max(0, layoutInfo.rect.y + layoutInfo.rect.height - this.virtualizer.visibleRect.height);
357
-
358
- while (layoutInfo && layoutInfo.rect.y > pageY) {
359
- let keyAbove = this.getKeyAbove(layoutInfo.key);
360
- layoutInfo = this.getLayoutInfo(keyAbove);
361
- }
362
-
363
- if (layoutInfo) {
364
- return layoutInfo.key;
365
- }
222
+ getContentSize() {
223
+ return this.contentSize;
366
224
  }
367
-
368
- return this.getFirstKey();
369
- }
370
-
371
- getKeyPageBelow(key) {
372
- let layoutInfo = this.getLayoutInfo(key != null ? key : this.getFirstKey());
373
-
374
- if (layoutInfo) {
375
- let pageY = Math.min(this.virtualizer.contentSize.height, layoutInfo.rect.y - layoutInfo.rect.height + this.virtualizer.visibleRect.height);
376
-
377
- while (layoutInfo && layoutInfo.rect.y < pageY) {
378
- let keyBelow = this.getKeyBelow(layoutInfo.key);
379
- layoutInfo = this.getLayoutInfo(keyBelow);
380
- }
381
-
382
- if (layoutInfo) {
383
- return layoutInfo.key;
384
- }
225
+ getKeyAbove(key) {
226
+ let collection = this.collection;
227
+ key = collection.getKeyBefore(key);
228
+ while(key != null){
229
+ let item = collection.getItem(key);
230
+ if (item.type === 'item' && !this.disabledKeys.has(item.key)) return key;
231
+ key = collection.getKeyBefore(key);
232
+ }
385
233
  }
386
-
387
- return this.getLastKey();
388
- }
389
-
390
- getFirstKey() {
391
- let collection = this.collection;
392
- let key = collection.getFirstKey();
393
-
394
- while (key != null) {
395
- let item = collection.getItem(key);
396
-
397
- if (item.type === 'item' && !this.disabledKeys.has(item.key)) {
398
- return key;
399
- }
400
-
401
- key = collection.getKeyAfter(key);
234
+ getKeyBelow(key) {
235
+ let collection = this.collection;
236
+ key = collection.getKeyAfter(key);
237
+ while(key != null){
238
+ let item = collection.getItem(key);
239
+ if (item.type === 'item' && !this.disabledKeys.has(item.key)) return key;
240
+ key = collection.getKeyAfter(key);
241
+ }
402
242
  }
403
- }
404
-
405
- getLastKey() {
406
- let collection = this.collection;
407
- let key = collection.getLastKey();
408
-
409
- while (key != null) {
410
- let item = collection.getItem(key);
411
-
412
- if (item.type === 'item' && !this.disabledKeys.has(item.key)) {
413
- return key;
414
- }
415
-
416
- key = collection.getKeyBefore(key);
243
+ getKeyPageAbove(key) {
244
+ let layoutInfo = this.getLayoutInfo(key);
245
+ if (layoutInfo) {
246
+ let pageY = Math.max(0, layoutInfo.rect.y + layoutInfo.rect.height - this.virtualizer.visibleRect.height);
247
+ while(layoutInfo && layoutInfo.rect.y > pageY){
248
+ let keyAbove = this.getKeyAbove(layoutInfo.key);
249
+ layoutInfo = this.getLayoutInfo(keyAbove);
250
+ }
251
+ if (layoutInfo) return layoutInfo.key;
252
+ }
253
+ return this.getFirstKey();
254
+ }
255
+ getKeyPageBelow(key) {
256
+ let layoutInfo = this.getLayoutInfo(key != null ? key : this.getFirstKey());
257
+ if (layoutInfo) {
258
+ let pageY = Math.min(this.virtualizer.contentSize.height, layoutInfo.rect.y - layoutInfo.rect.height + this.virtualizer.visibleRect.height);
259
+ while(layoutInfo && layoutInfo.rect.y < pageY){
260
+ let keyBelow = this.getKeyBelow(layoutInfo.key);
261
+ layoutInfo = this.getLayoutInfo(keyBelow);
262
+ }
263
+ if (layoutInfo) return layoutInfo.key;
264
+ }
265
+ return this.getLastKey();
266
+ }
267
+ getFirstKey() {
268
+ let collection = this.collection;
269
+ let key = collection.getFirstKey();
270
+ while(key != null){
271
+ let item = collection.getItem(key);
272
+ if (item.type === 'item' && !this.disabledKeys.has(item.key)) return key;
273
+ key = collection.getKeyAfter(key);
274
+ }
417
275
  }
418
- }
419
-
420
- getKeyForSearch(search, fromKey) {
421
- if (!this.collator) {
422
- return null;
276
+ getLastKey() {
277
+ let collection = this.collection;
278
+ let key = collection.getLastKey();
279
+ while(key != null){
280
+ let item = collection.getItem(key);
281
+ if (item.type === 'item' && !this.disabledKeys.has(item.key)) return key;
282
+ key = collection.getKeyBefore(key);
283
+ }
423
284
  }
424
-
425
- let collection = this.collection;
426
- let key = fromKey || this.getFirstKey();
427
-
428
- while (key != null) {
429
- let item = collection.getItem(key);
430
- let substring = item.textValue.slice(0, search.length);
431
-
432
- if (item.textValue && this.collator.compare(substring, search) === 0) {
433
- return key;
434
- }
435
-
436
- key = this.getKeyBelow(key);
285
+ getKeyForSearch(search, fromKey) {
286
+ if (!this.collator) return null;
287
+ let collection = this.collection;
288
+ let key = fromKey || this.getFirstKey();
289
+ while(key != null){
290
+ let item = collection.getItem(key);
291
+ let substring = item.textValue.slice(0, search.length);
292
+ if (item.textValue && this.collator.compare(substring, search) === 0) return key;
293
+ key = this.getKeyBelow(key);
294
+ }
295
+ return null;
296
+ }
297
+ // getDragTarget(point: Point): DragTarget {
298
+ // let visible = this.getVisibleLayoutInfos(new Rect(point.x, point.y, 1, 1));
299
+ // if (visible.length > 0) {
300
+ // visible = visible.sort((a, b) => b.zIndex - a.zIndex);
301
+ // return {
302
+ // type: 'item',
303
+ // key: visible[0].key
304
+ // };
305
+ // }
306
+ // return null;
307
+ // }
308
+ // getDropTarget(point: Point): DropTarget {
309
+ // let key = this.virtualizer.keyAtPoint(point);
310
+ // if (key) {
311
+ // return {
312
+ // type: 'item',
313
+ // key,
314
+ // dropPosition: DropPosition.ON
315
+ // };
316
+ // }
317
+ // return null;
318
+ // }
319
+ getInitialLayoutInfo(layoutInfo) {
320
+ layoutInfo.opacity = 0;
321
+ layoutInfo.transform = 'scale3d(0.8, 0.8, 0.8)';
322
+ return layoutInfo;
323
+ }
324
+ getFinalLayoutInfo(layoutInfo) {
325
+ layoutInfo.opacity = 0;
326
+ layoutInfo.transform = 'scale3d(0.8, 0.8, 0.8)';
327
+ return layoutInfo;
437
328
  }
438
-
439
- return null;
440
- } // getDragTarget(point: Point): DragTarget {
441
- // let visible = this.getVisibleLayoutInfos(new Rect(point.x, point.y, 1, 1));
442
- // if (visible.length > 0) {
443
- // visible = visible.sort((a, b) => b.zIndex - a.zIndex);
444
- // return {
445
- // type: 'item',
446
- // key: visible[0].key
447
- // };
448
- // }
449
- // return null;
450
- // }
451
- // getDropTarget(point: Point): DropTarget {
452
- // let key = this.virtualizer.keyAtPoint(point);
453
- // if (key) {
454
- // return {
455
- // type: 'item',
456
- // key,
457
- // dropPosition: DropPosition.ON
458
- // };
459
- // }
460
- // return null;
461
- // }
462
-
463
-
464
- getInitialLayoutInfo(layoutInfo) {
465
- layoutInfo.opacity = 0;
466
- layoutInfo.transform = 'scale3d(0.8, 0.8, 0.8)';
467
- return layoutInfo;
468
- }
469
-
470
- getFinalLayoutInfo(layoutInfo) {
471
- layoutInfo.opacity = 0;
472
- layoutInfo.transform = 'scale3d(0.8, 0.8, 0.8)';
473
- return layoutInfo;
474
- }
475
-
476
329
  }
477
- export class TableLayout extends ListLayout {
478
- constructor(options) {
479
- super(options);
480
- this.collection = void 0;
481
- this.lastCollection = void 0;
482
- this.columnWidths = void 0;
483
- this.stickyColumnIndices = void 0;
484
- this.getDefaultWidth = void 0;
485
- this.wasLoading = false;
486
- this.isLoading = false;
487
- this.getDefaultWidth = options.getDefaultWidth;
488
- }
489
-
490
- buildCollection() {
491
- // If columns changed, clear layout cache.
492
- if (!this.lastCollection || this.collection.columns.length !== this.lastCollection.columns.length || this.collection.columns.some((c, i) => c.key !== this.lastCollection.columns[i].key)) {
493
- // Invalidate everything in this layout pass. Will be reset in ListLayout on the next pass.
494
- this.invalidateEverything = true;
495
- } // Track whether we were previously loading. This is used to adjust the animations of async loading vs inserts.
496
-
497
-
498
- let loadingState = this.collection.body.props.loadingState;
499
- this.wasLoading = this.isLoading;
500
- this.isLoading = loadingState === 'loading' || loadingState === 'loadingMore';
501
- this.buildColumnWidths();
502
- let header = this.buildHeader();
503
- let body = this.buildBody(0);
504
- body.layoutInfo.rect.width = Math.max(header.layoutInfo.rect.width, body.layoutInfo.rect.width);
505
- this.contentSize = new Size(body.layoutInfo.rect.width, body.layoutInfo.rect.maxY);
506
- return [header, body];
507
- }
508
-
509
- buildColumnWidths() {
510
- this.columnWidths = new Map();
511
- this.stickyColumnIndices = []; // Pass 1: set widths for all explicitly defined columns.
512
-
513
- let remainingColumns = new Set();
514
- let remainingSpace = this.virtualizer.visibleRect.width;
515
-
516
- for (let column of this.collection.columns) {
517
- var _props$width;
518
-
519
- let props = column.props;
520
- let width = (_props$width = props.width) != null ? _props$width : this.getDefaultWidth(props);
521
-
522
- if (width != null) {
523
- let w = this.parseWidth(width);
524
- this.columnWidths.set(column.key, w);
525
- remainingSpace -= w;
526
- } else {
527
- remainingColumns.add(column);
528
- } // The selection cell and any other sticky columns always need to be visible.
529
- // In addition, row headers need to be in the DOM for accessibility labeling.
530
-
531
-
532
- if (column.props.isSelectionCell || this.collection.rowHeaderColumnKeys.has(column.key)) {
533
- this.stickyColumnIndices.push(column.index);
534
- }
535
- } // Pass 2: if there are remaining columns, then distribute the remaining space evenly.
536
-
537
330
 
538
- if (remainingColumns.size > 0) {
539
- let columnWidth = remainingSpace / (this.collection.columns.length - this.columnWidths.size);
540
331
 
541
- for (let column of remainingColumns) {
542
- let props = column.props;
543
- let minWidth = props.minWidth != null ? this.parseWidth(props.minWidth) : 75;
544
- let maxWidth = props.maxWidth != null ? this.parseWidth(props.maxWidth) : Infinity;
545
- let width = Math.max(minWidth, Math.min(maxWidth, columnWidth));
546
- this.columnWidths.set(column.key, width);
547
- remainingSpace -= width;
548
-
549
- if (width !== columnWidth) {
550
- columnWidth = remainingSpace / (this.collection.columns.length - this.columnWidths.size);
332
+ var $69cac3683b58c7d1$exports = {};
333
+
334
+ $parcel$export($69cac3683b58c7d1$exports, "TableLayout", () => $69cac3683b58c7d1$export$62444c3c724b1b20);
335
+
336
+
337
+ class $69cac3683b58c7d1$export$62444c3c724b1b20 extends $5c162b33e5b4dfc0$export$cacbb3924155d68e {
338
+ constructor(options){
339
+ super(options);
340
+ this.wasLoading = false;
341
+ this.isLoading = false;
342
+ this.getDefaultWidth = options.getDefaultWidth;
343
+ }
344
+ buildCollection() {
345
+ // If columns changed, clear layout cache.
346
+ if (!this.lastCollection || this.collection.columns.length !== this.lastCollection.columns.length || this.collection.columns.some((c, i)=>c.key !== this.lastCollection.columns[i].key
347
+ )) // Invalidate everything in this layout pass. Will be reset in ListLayout on the next pass.
348
+ this.invalidateEverything = true;
349
+ // Track whether we were previously loading. This is used to adjust the animations of async loading vs inserts.
350
+ let loadingState = this.collection.body.props.loadingState;
351
+ this.wasLoading = this.isLoading;
352
+ this.isLoading = loadingState === 'loading' || loadingState === 'loadingMore';
353
+ this.buildColumnWidths();
354
+ let header = this.buildHeader();
355
+ let body = this.buildBody(0);
356
+ body.layoutInfo.rect.width = Math.max(header.layoutInfo.rect.width, body.layoutInfo.rect.width);
357
+ this.contentSize = new $lwi4v$Size(body.layoutInfo.rect.width, body.layoutInfo.rect.maxY);
358
+ return [
359
+ header,
360
+ body
361
+ ];
362
+ }
363
+ buildColumnWidths() {
364
+ this.columnWidths = new Map();
365
+ this.stickyColumnIndices = [];
366
+ // Pass 1: set widths for all explicitly defined columns.
367
+ let remainingColumns = new Set();
368
+ let remainingSpace = this.virtualizer.visibleRect.width;
369
+ for (let column of this.collection.columns){
370
+ let props = column.props;
371
+ let width = props.width ?? this.getDefaultWidth(props);
372
+ if (width != null) {
373
+ let w = this.parseWidth(width);
374
+ this.columnWidths.set(column.key, w);
375
+ remainingSpace -= w;
376
+ } else remainingColumns.add(column);
377
+ // The selection cell and any other sticky columns always need to be visible.
378
+ // In addition, row headers need to be in the DOM for accessibility labeling.
379
+ if (column.props.isSelectionCell || this.collection.rowHeaderColumnKeys.has(column.key)) this.stickyColumnIndices.push(column.index);
380
+ }
381
+ // Pass 2: if there are remaining columns, then distribute the remaining space evenly.
382
+ if (remainingColumns.size > 0) {
383
+ let columnWidth = remainingSpace / (this.collection.columns.length - this.columnWidths.size);
384
+ for (let column of remainingColumns){
385
+ let props = column.props;
386
+ let minWidth = props.minWidth != null ? this.parseWidth(props.minWidth) : 75;
387
+ let maxWidth = props.maxWidth != null ? this.parseWidth(props.maxWidth) : Infinity;
388
+ let width = Math.max(minWidth, Math.min(maxWidth, columnWidth));
389
+ this.columnWidths.set(column.key, width);
390
+ remainingSpace -= width;
391
+ if (width !== columnWidth) columnWidth = remainingSpace / (this.collection.columns.length - this.columnWidths.size);
392
+ }
551
393
  }
552
- }
553
- }
554
- }
555
-
556
- parseWidth(width) {
557
- if (typeof width === 'string') {
558
- let match = width.match(/^(\d+)%$/);
559
-
560
- if (!match) {
561
- throw new Error('Only percentages are supported as column widths');
562
- }
563
-
564
- return this.virtualizer.visibleRect.width * (parseInt(match[1], 10) / 100);
565
- }
566
-
567
- return width;
568
- }
569
-
570
- buildHeader() {
571
- let rect = new Rect(0, 0, 0, 0);
572
- let layoutInfo = new LayoutInfo('header', 'header', rect);
573
- let y = 0;
574
- let width = 0;
575
- let children = [];
576
-
577
- for (let headerRow of this.collection.headerRows) {
578
- let layoutNode = this.buildChild(headerRow, 0, y);
579
- layoutNode.layoutInfo.parentKey = 'header';
580
- y = layoutNode.layoutInfo.rect.maxY;
581
- width = Math.max(width, layoutNode.layoutInfo.rect.width);
582
- children.push(layoutNode);
583
- }
584
-
585
- rect.width = width;
586
- rect.height = y;
587
- this.layoutInfos.set('header', layoutInfo);
588
- return {
589
- layoutInfo,
590
- children
591
- };
592
- }
593
-
594
- buildHeaderRow(headerRow, x, y) {
595
- let rect = new Rect(0, y, 0, 0);
596
- let row = new LayoutInfo('headerrow', headerRow.key, rect);
597
- let height = 0;
598
- let columns = [];
599
-
600
- for (let cell of headerRow.childNodes) {
601
- let layoutNode = this.buildChild(cell, x, y);
602
- layoutNode.layoutInfo.parentKey = row.key;
603
- x = layoutNode.layoutInfo.rect.maxX;
604
- height = Math.max(height, layoutNode.layoutInfo.rect.height);
605
- columns.push(layoutNode);
606
- }
607
-
608
- this.setChildHeights(columns, height);
609
- rect.height = height;
610
- rect.width = x;
611
- return {
612
- layoutInfo: row,
613
- children: columns
614
- };
615
- }
616
-
617
- setChildHeights(children, height) {
618
- for (let child of children) {
619
- if (child.layoutInfo.rect.height !== height) {
620
- // Need to copy the layout info before we mutate it.
621
- child.layoutInfo = child.layoutInfo.copy();
622
- this.layoutInfos.set(child.layoutInfo.key, child.layoutInfo);
623
- child.layoutInfo.rect.height = height;
624
- }
625
- }
626
- }
627
-
628
- getColumnWidth(node) {
629
- var _node$colspan;
630
-
631
- let colspan = (_node$colspan = node.colspan) != null ? _node$colspan : 1;
632
- let width = 0;
633
-
634
- for (let i = 0; i < colspan; i++) {
635
- let column = this.collection.columns[node.index + i];
636
- width += this.columnWidths.get(column.key);
637
- }
638
-
639
- return width;
640
- }
641
-
642
- getEstimatedHeight(node, width, height, estimatedHeight) {
643
- let isEstimated = false; // If no explicit height is available, use an estimated height.
644
-
645
- if (height == null) {
646
- // If a previous version of this layout info exists, reuse its height.
647
- // Mark as estimated if the size of the overall collection view changed,
648
- // or the content of the item changed.
649
- let previousLayoutNode = this.layoutNodes.get(node.key);
650
-
651
- if (previousLayoutNode) {
652
- let curNode = this.collection.getItem(node.key);
653
- let lastNode = this.lastCollection ? this.lastCollection.getItem(node.key) : null;
654
- height = previousLayoutNode.layoutInfo.rect.height;
655
- isEstimated = curNode !== lastNode || width !== previousLayoutNode.layoutInfo.rect.width || previousLayoutNode.layoutInfo.estimatedSize;
656
- } else {
657
- height = estimatedHeight;
658
- isEstimated = true;
659
- }
660
- }
661
-
662
- return {
663
- height,
664
- isEstimated
665
- };
666
- }
667
-
668
- buildColumn(node, x, y) {
669
- var _node$props;
670
-
671
- let width = this.getColumnWidth(node);
672
- let {
673
- height,
674
- isEstimated
675
- } = this.getEstimatedHeight(node, width, this.headingHeight, this.estimatedHeadingHeight);
676
- let rect = new Rect(x, y, width, height);
677
- let layoutInfo = new LayoutInfo(node.type, node.key, rect);
678
- layoutInfo.isSticky = (_node$props = node.props) == null ? void 0 : _node$props.isSelectionCell;
679
- layoutInfo.zIndex = layoutInfo.isSticky ? 2 : 1;
680
- layoutInfo.estimatedSize = isEstimated;
681
- return {
682
- layoutInfo
683
- };
684
- }
685
-
686
- buildBody(y) {
687
- let rect = new Rect(0, y, 0, 0);
688
- let layoutInfo = new LayoutInfo('rowgroup', 'body', rect);
689
- let startY = y;
690
- let width = 0;
691
- let children = [];
692
-
693
- for (let node of this.collection.body.childNodes) {
694
- let layoutNode = this.buildChild(node, 0, y);
695
- layoutNode.layoutInfo.parentKey = 'body';
696
- y = layoutNode.layoutInfo.rect.maxY;
697
- width = Math.max(width, layoutNode.layoutInfo.rect.width);
698
- children.push(layoutNode);
699
- }
700
-
701
- if (this.isLoading) {
702
- let rect = new Rect(0, y, width || this.virtualizer.visibleRect.width, children.length === 0 ? this.virtualizer.visibleRect.height : 60);
703
- let loader = new LayoutInfo('loader', 'loader', rect);
704
- loader.parentKey = 'body';
705
- loader.isSticky = children.length === 0;
706
- this.layoutInfos.set('loader', loader);
707
- children.push({
708
- layoutInfo: loader
709
- });
710
- y = loader.rect.maxY;
711
- width = Math.max(width, rect.width);
712
- } else if (children.length === 0) {
713
- let rect = new Rect(0, y, this.virtualizer.visibleRect.width, this.virtualizer.visibleRect.height);
714
- let empty = new LayoutInfo('empty', 'empty', rect);
715
- empty.parentKey = 'body';
716
- empty.isSticky = true;
717
- this.layoutInfos.set('empty', empty);
718
- children.push({
719
- layoutInfo: empty
720
- });
721
- y = empty.rect.maxY;
722
- width = Math.max(width, rect.width);
723
- }
724
-
725
- rect.width = width;
726
- rect.height = y - startY;
727
- this.layoutInfos.set('body', layoutInfo);
728
- return {
729
- layoutInfo,
730
- children
731
- };
732
- }
733
-
734
- buildNode(node, x, y) {
735
- switch (node.type) {
736
- case 'headerrow':
737
- return this.buildHeaderRow(node, x, y);
738
-
739
- case 'item':
740
- return this.buildRow(node, x, y);
741
-
742
- case 'column':
743
- case 'placeholder':
744
- return this.buildColumn(node, x, y);
745
-
746
- case 'cell':
747
- return this.buildCell(node, x, y);
748
-
749
- default:
750
- throw new Error('Unknown node type ' + node.type);
751
- }
752
- }
753
-
754
- buildRow(node, x, y) {
755
- let rect = new Rect(x, y, 0, 0);
756
- let layoutInfo = new LayoutInfo('row', node.key, rect);
757
- let children = [];
758
- let height = 0;
759
-
760
- for (let child of node.childNodes) {
761
- let layoutNode = this.buildChild(child, x, y);
762
- x = layoutNode.layoutInfo.rect.maxX;
763
- height = Math.max(height, layoutNode.layoutInfo.rect.height);
764
- children.push(layoutNode);
765
394
  }
766
-
767
- this.setChildHeights(children, height);
768
- rect.width = x;
769
- rect.height = height + 1; // +1 for bottom border
770
-
771
- return {
772
- layoutInfo,
773
- children
774
- };
775
- }
776
-
777
- buildCell(node, x, y) {
778
- var _node$props2;
779
-
780
- let width = this.getColumnWidth(node);
781
- let {
782
- height,
783
- isEstimated
784
- } = this.getEstimatedHeight(node, width, this.rowHeight, this.estimatedRowHeight);
785
- let rect = new Rect(x, y, width, height);
786
- let layoutInfo = new LayoutInfo(node.type, node.key, rect);
787
- layoutInfo.isSticky = (_node$props2 = node.props) == null ? void 0 : _node$props2.isSelectionCell;
788
- layoutInfo.zIndex = layoutInfo.isSticky ? 2 : 1;
789
- layoutInfo.estimatedSize = isEstimated;
790
- return {
791
- layoutInfo
792
- };
793
- }
794
-
795
- getVisibleLayoutInfos(rect) {
796
- let res = [];
797
-
798
- for (let node of this.rootNodes) {
799
- res.push(node.layoutInfo);
800
- this.addVisibleLayoutInfos(res, node, rect);
395
+ parseWidth(width) {
396
+ if (typeof width === 'string') {
397
+ let match = width.match(/^(\d+)%$/);
398
+ if (!match) throw new Error('Only percentages are supported as column widths');
399
+ return this.virtualizer.visibleRect.width * (parseInt(match[1], 10) / 100);
400
+ }
401
+ return width;
402
+ }
403
+ buildHeader() {
404
+ let rect = new $lwi4v$Rect(0, 0, 0, 0);
405
+ let layoutInfo = new $lwi4v$LayoutInfo('header', 'header', rect);
406
+ let y = 0;
407
+ let width = 0;
408
+ let children = [];
409
+ for (let headerRow of this.collection.headerRows){
410
+ let layoutNode = this.buildChild(headerRow, 0, y);
411
+ layoutNode.layoutInfo.parentKey = 'header';
412
+ y = layoutNode.layoutInfo.rect.maxY;
413
+ width = Math.max(width, layoutNode.layoutInfo.rect.width);
414
+ children.push(layoutNode);
415
+ }
416
+ rect.width = width;
417
+ rect.height = y;
418
+ this.layoutInfos.set('header', layoutInfo);
419
+ return {
420
+ layoutInfo: layoutInfo,
421
+ children: children
422
+ };
423
+ }
424
+ buildHeaderRow(headerRow, x, y) {
425
+ let rect = new $lwi4v$Rect(0, y, 0, 0);
426
+ let row = new $lwi4v$LayoutInfo('headerrow', headerRow.key, rect);
427
+ let height = 0;
428
+ let columns = [];
429
+ for (let cell of headerRow.childNodes){
430
+ let layoutNode = this.buildChild(cell, x, y);
431
+ layoutNode.layoutInfo.parentKey = row.key;
432
+ x = layoutNode.layoutInfo.rect.maxX;
433
+ height = Math.max(height, layoutNode.layoutInfo.rect.height);
434
+ columns.push(layoutNode);
435
+ }
436
+ this.setChildHeights(columns, height);
437
+ rect.height = height;
438
+ rect.width = x;
439
+ return {
440
+ layoutInfo: row,
441
+ children: columns
442
+ };
443
+ }
444
+ setChildHeights(children, height) {
445
+ for (let child of children)if (child.layoutInfo.rect.height !== height) {
446
+ // Need to copy the layout info before we mutate it.
447
+ child.layoutInfo = child.layoutInfo.copy();
448
+ this.layoutInfos.set(child.layoutInfo.key, child.layoutInfo);
449
+ child.layoutInfo.rect.height = height;
450
+ }
801
451
  }
802
-
803
- return res;
804
- }
805
-
806
- addVisibleLayoutInfos(res, node, rect) {
807
- if (!node.children || node.children.length === 0) {
808
- return;
452
+ getColumnWidth(node) {
453
+ let colspan = node.colspan ?? 1;
454
+ let width = 0;
455
+ for(let i = 0; i < colspan; i++){
456
+ let column = this.collection.columns[node.index + i];
457
+ width += this.columnWidths.get(column.key);
458
+ }
459
+ return width;
460
+ }
461
+ getEstimatedHeight(node, width, height, estimatedHeight) {
462
+ let isEstimated = false;
463
+ // If no explicit height is available, use an estimated height.
464
+ if (height == null) {
465
+ // If a previous version of this layout info exists, reuse its height.
466
+ // Mark as estimated if the size of the overall collection view changed,
467
+ // or the content of the item changed.
468
+ let previousLayoutNode = this.layoutNodes.get(node.key);
469
+ if (previousLayoutNode) {
470
+ let curNode = this.collection.getItem(node.key);
471
+ let lastNode = this.lastCollection ? this.lastCollection.getItem(node.key) : null;
472
+ height = previousLayoutNode.layoutInfo.rect.height;
473
+ isEstimated = curNode !== lastNode || width !== previousLayoutNode.layoutInfo.rect.width || previousLayoutNode.layoutInfo.estimatedSize;
474
+ } else {
475
+ height = estimatedHeight;
476
+ isEstimated = true;
477
+ }
478
+ }
479
+ return {
480
+ height: height,
481
+ isEstimated: isEstimated
482
+ };
483
+ }
484
+ buildColumn(node, x, y) {
485
+ let width = this.getColumnWidth(node);
486
+ let { height: height , isEstimated: isEstimated } = this.getEstimatedHeight(node, width, this.headingHeight, this.estimatedHeadingHeight);
487
+ let rect = new $lwi4v$Rect(x, y, width, height);
488
+ let layoutInfo = new $lwi4v$LayoutInfo(node.type, node.key, rect);
489
+ layoutInfo.isSticky = node.props?.isSelectionCell;
490
+ layoutInfo.zIndex = layoutInfo.isSticky ? 2 : 1;
491
+ layoutInfo.estimatedSize = isEstimated;
492
+ return {
493
+ layoutInfo: layoutInfo
494
+ };
495
+ }
496
+ buildBody(y) {
497
+ let rect = new $lwi4v$Rect(0, y, 0, 0);
498
+ let layoutInfo = new $lwi4v$LayoutInfo('rowgroup', 'body', rect);
499
+ let startY = y;
500
+ let width = 0;
501
+ let children = [];
502
+ for (let node of this.collection.body.childNodes){
503
+ let layoutNode = this.buildChild(node, 0, y);
504
+ layoutNode.layoutInfo.parentKey = 'body';
505
+ y = layoutNode.layoutInfo.rect.maxY;
506
+ width = Math.max(width, layoutNode.layoutInfo.rect.width);
507
+ children.push(layoutNode);
508
+ }
509
+ if (this.isLoading) {
510
+ let rect = new $lwi4v$Rect(0, y, width || this.virtualizer.visibleRect.width, children.length === 0 ? this.virtualizer.visibleRect.height : 60);
511
+ let loader = new $lwi4v$LayoutInfo('loader', 'loader', rect);
512
+ loader.parentKey = 'body';
513
+ loader.isSticky = children.length === 0;
514
+ this.layoutInfos.set('loader', loader);
515
+ children.push({
516
+ layoutInfo: loader
517
+ });
518
+ y = loader.rect.maxY;
519
+ width = Math.max(width, rect.width);
520
+ } else if (children.length === 0) {
521
+ let rect = new $lwi4v$Rect(0, y, this.virtualizer.visibleRect.width, this.virtualizer.visibleRect.height);
522
+ let empty = new $lwi4v$LayoutInfo('empty', 'empty', rect);
523
+ empty.parentKey = 'body';
524
+ empty.isSticky = true;
525
+ this.layoutInfos.set('empty', empty);
526
+ children.push({
527
+ layoutInfo: empty
528
+ });
529
+ y = empty.rect.maxY;
530
+ width = Math.max(width, rect.width);
531
+ }
532
+ rect.width = width;
533
+ rect.height = y - startY;
534
+ this.layoutInfos.set('body', layoutInfo);
535
+ return {
536
+ layoutInfo: layoutInfo,
537
+ children: children
538
+ };
539
+ }
540
+ buildNode(node, x, y) {
541
+ switch(node.type){
542
+ case 'headerrow':
543
+ return this.buildHeaderRow(node, x, y);
544
+ case 'item':
545
+ return this.buildRow(node, x, y);
546
+ case 'column':
547
+ case 'placeholder':
548
+ return this.buildColumn(node, x, y);
549
+ case 'cell':
550
+ return this.buildCell(node, x, y);
551
+ default:
552
+ throw new Error('Unknown node type ' + node.type);
553
+ }
809
554
  }
810
-
811
- switch (node.layoutInfo.type) {
812
- case 'header':
813
- {
814
- for (let child of node.children) {
815
- res.push(child.layoutInfo);
816
- this.addVisibleLayoutInfos(res, child, rect);
817
- }
818
-
819
- break;
555
+ buildRow(node, x, y) {
556
+ let rect = new $lwi4v$Rect(x, y, 0, 0);
557
+ let layoutInfo = new $lwi4v$LayoutInfo('row', node.key, rect);
558
+ let children = [];
559
+ let height = 0;
560
+ for (let child of node.childNodes){
561
+ let layoutNode = this.buildChild(child, x, y);
562
+ x = layoutNode.layoutInfo.rect.maxX;
563
+ height = Math.max(height, layoutNode.layoutInfo.rect.height);
564
+ children.push(layoutNode);
820
565
  }
821
-
822
- case 'rowgroup':
823
- {
824
- let firstVisibleRow = this.binarySearch(node.children, rect.topLeft, 'y');
825
- let lastVisibleRow = this.binarySearch(node.children, rect.bottomRight, 'y');
826
-
827
- for (let i = firstVisibleRow; i <= lastVisibleRow; i++) {
828
- res.push(node.children[i].layoutInfo);
829
- this.addVisibleLayoutInfos(res, node.children[i], rect);
830
- }
831
-
832
- break;
566
+ this.setChildHeights(children, height);
567
+ rect.width = x;
568
+ rect.height = height + 1; // +1 for bottom border
569
+ return {
570
+ layoutInfo: layoutInfo,
571
+ children: children
572
+ };
573
+ }
574
+ buildCell(node, x, y) {
575
+ let width = this.getColumnWidth(node);
576
+ let { height: height , isEstimated: isEstimated } = this.getEstimatedHeight(node, width, this.rowHeight, this.estimatedRowHeight);
577
+ let rect = new $lwi4v$Rect(x, y, width, height);
578
+ let layoutInfo = new $lwi4v$LayoutInfo(node.type, node.key, rect);
579
+ layoutInfo.isSticky = node.props?.isSelectionCell;
580
+ layoutInfo.zIndex = layoutInfo.isSticky ? 2 : 1;
581
+ layoutInfo.estimatedSize = isEstimated;
582
+ return {
583
+ layoutInfo: layoutInfo
584
+ };
585
+ }
586
+ getVisibleLayoutInfos(rect) {
587
+ let res = [];
588
+ for (let node of this.rootNodes){
589
+ res.push(node.layoutInfo);
590
+ this.addVisibleLayoutInfos(res, node, rect);
833
591
  }
834
-
835
- case 'headerrow':
836
- case 'row':
837
- {
838
- let firstVisibleCell = this.binarySearch(node.children, rect.topLeft, 'x');
839
- let lastVisibleCell = this.binarySearch(node.children, rect.topRight, 'x');
840
- let stickyIndex = 0;
841
-
842
- for (let i = firstVisibleCell; i <= lastVisibleCell; i++) {
843
- // Sticky columns and row headers are always in the DOM. Interleave these
844
- // with the visible range so that they are in the right order.
845
- if (stickyIndex < this.stickyColumnIndices.length) {
846
- let idx = this.stickyColumnIndices[stickyIndex];
847
-
848
- while (idx < i) {
849
- res.push(node.children[idx].layoutInfo);
850
- idx = this.stickyColumnIndices[stickyIndex++];
851
- }
852
- }
853
-
854
- res.push(node.children[i].layoutInfo);
855
- }
856
-
857
- while (stickyIndex < this.stickyColumnIndices.length) {
858
- let idx = this.stickyColumnIndices[stickyIndex++];
859
- res.push(node.children[idx].layoutInfo);
860
- }
861
-
862
- break;
592
+ return res;
593
+ }
594
+ addVisibleLayoutInfos(res, node, rect) {
595
+ if (!node.children || node.children.length === 0) return;
596
+ switch(node.layoutInfo.type){
597
+ case 'header':
598
+ for (let child of node.children){
599
+ res.push(child.layoutInfo);
600
+ this.addVisibleLayoutInfos(res, child, rect);
601
+ }
602
+ break;
603
+ case 'rowgroup':
604
+ {
605
+ let firstVisibleRow = this.binarySearch(node.children, rect.topLeft, 'y');
606
+ let lastVisibleRow = this.binarySearch(node.children, rect.bottomRight, 'y');
607
+ for(let i = firstVisibleRow; i <= lastVisibleRow; i++){
608
+ res.push(node.children[i].layoutInfo);
609
+ this.addVisibleLayoutInfos(res, node.children[i], rect);
610
+ }
611
+ break;
612
+ }
613
+ case 'headerrow':
614
+ case 'row':
615
+ {
616
+ let firstVisibleCell = this.binarySearch(node.children, rect.topLeft, 'x');
617
+ let lastVisibleCell = this.binarySearch(node.children, rect.topRight, 'x');
618
+ let stickyIndex = 0;
619
+ for(let i = firstVisibleCell; i <= lastVisibleCell; i++){
620
+ // Sticky columns and row headers are always in the DOM. Interleave these
621
+ // with the visible range so that they are in the right order.
622
+ if (stickyIndex < this.stickyColumnIndices.length) {
623
+ let idx = this.stickyColumnIndices[stickyIndex];
624
+ while(idx < i){
625
+ res.push(node.children[idx].layoutInfo);
626
+ idx = this.stickyColumnIndices[stickyIndex++];
627
+ }
628
+ }
629
+ res.push(node.children[i].layoutInfo);
630
+ }
631
+ while(stickyIndex < this.stickyColumnIndices.length){
632
+ let idx = this.stickyColumnIndices[stickyIndex++];
633
+ res.push(node.children[idx].layoutInfo);
634
+ }
635
+ break;
636
+ }
637
+ default:
638
+ throw new Error('Unknown node type ' + node.layoutInfo.type);
863
639
  }
864
-
865
- default:
866
- throw new Error('Unknown node type ' + node.layoutInfo.type);
867
640
  }
868
- }
869
-
870
- binarySearch(items, point, axis) {
871
- let low = 0;
872
- let high = items.length - 1;
873
-
874
- while (low <= high) {
875
- let mid = low + high >> 1;
876
- let item = items[mid];
877
-
878
- if (axis === 'x' && item.layoutInfo.rect.maxX < point.x || axis === 'y' && item.layoutInfo.rect.maxY < point.y) {
879
- low = mid + 1;
880
- } else if (axis === 'x' && item.layoutInfo.rect.x > point.x || axis === 'y' && item.layoutInfo.rect.y > point.y) {
881
- high = mid - 1;
882
- } else {
883
- return mid;
884
- }
641
+ binarySearch(items, point, axis) {
642
+ let low = 0;
643
+ let high = items.length - 1;
644
+ while(low <= high){
645
+ let mid = low + high >> 1;
646
+ let item = items[mid];
647
+ if (axis === 'x' && item.layoutInfo.rect.maxX < point.x || axis === 'y' && item.layoutInfo.rect.maxY < point.y) low = mid + 1;
648
+ else if (axis === 'x' && item.layoutInfo.rect.x > point.x || axis === 'y' && item.layoutInfo.rect.y > point.y) high = mid - 1;
649
+ else return mid;
650
+ }
651
+ return Math.max(0, Math.min(items.length - 1, low));
885
652
  }
653
+ getInitialLayoutInfo(layoutInfo) {
654
+ let res = super.getInitialLayoutInfo(layoutInfo);
655
+ // If this insert was the result of async loading, remove the zoom effect and just keep the fade in.
656
+ if (this.wasLoading) res.transform = null;
657
+ return res;
658
+ }
659
+ }
886
660
 
887
- return Math.max(0, Math.min(items.length - 1, low));
888
- }
889
-
890
- getInitialLayoutInfo(layoutInfo) {
891
- let res = super.getInitialLayoutInfo(layoutInfo); // If this insert was the result of async loading, remove the zoom effect and just keep the fade in.
892
661
 
893
- if (this.wasLoading) {
894
- res.transform = null;
895
- }
896
662
 
897
- return res;
898
- }
899
663
 
900
- }
664
+ export {$5c162b33e5b4dfc0$export$cacbb3924155d68e as ListLayout, $69cac3683b58c7d1$export$62444c3c724b1b20 as TableLayout};
901
665
  //# sourceMappingURL=module.js.map