@react-stately/layout 3.13.10-nightly.4684 → 3.13.10-nightly.4691

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.
@@ -1,5 +1,5 @@
1
1
  import {getChildNodes as $img26$getChildNodes} from "@react-stately/collections";
2
- import {Rect as $img26$Rect, LayoutInfo as $img26$LayoutInfo, Size as $img26$Size, Point as $img26$Point, Layout as $img26$Layout} from "@react-stately/virtualizer";
2
+ import {Rect as $img26$Rect, Size as $img26$Size, LayoutInfo as $img26$LayoutInfo, Point as $img26$Point, Layout as $img26$Layout} from "@react-stately/virtualizer";
3
3
 
4
4
  /*
5
5
  * Copyright 2020 Adobe. All rights reserved.
@@ -16,8 +16,9 @@ import {Rect as $img26$Rect, LayoutInfo as $img26$LayoutInfo, Size as $img26$Siz
16
16
  const $61ef60fc9b1041f4$var$DEFAULT_HEIGHT = 48;
17
17
  class $61ef60fc9b1041f4$export$cacbb3924155d68e extends (0, $img26$Layout) {
18
18
  getLayoutInfo(key) {
19
+ var _this_layoutNodes_get;
19
20
  this.ensureLayoutInfo(key);
20
- return this.layoutInfos.get(key);
21
+ return ((_this_layoutNodes_get = this.layoutNodes.get(key)) === null || _this_layoutNodes_get === void 0 ? void 0 : _this_layoutNodes_get.layoutInfo) || null;
21
22
  }
22
23
  getVisibleLayoutInfos(rect) {
23
24
  // Adjust rect to keep number of visible rows consistent.
@@ -35,7 +36,6 @@ class $61ef60fc9b1041f4$export$cacbb3924155d68e extends (0, $img26$Layout) {
35
36
  let addNodes = (nodes)=>{
36
37
  for (let node of nodes)if (this.isVisible(node, rect)) {
37
38
  res.push(node.layoutInfo);
38
- if (node.header) res.push(node.header);
39
39
  if (node.children) addNodes(node.children);
40
40
  }
41
41
  };
@@ -56,7 +56,7 @@ class $61ef60fc9b1041f4$export$cacbb3924155d68e extends (0, $img26$Layout) {
56
56
  // If the layout info wasn't found, it might be outside the bounds of the area that we've
57
57
  // computed layout for so far. This can happen when accessing a random key, e.g pressing Home/End.
58
58
  // Compute the full layout and try again.
59
- if (!this.layoutInfos.has(key) && this.requestedRect.area < this.contentSize.area && this.lastCollection) {
59
+ if (!this.layoutNodes.has(key) && this.requestedRect.area < this.contentSize.area && this.lastCollection) {
60
60
  this.requestedRect = new (0, $img26$Rect)(0, 0, Infinity, Infinity);
61
61
  this.rootNodes = this.buildCollection();
62
62
  this.requestedRect = new (0, $img26$Rect)(0, 0, this.contentSize.width, this.contentSize.height);
@@ -65,7 +65,7 @@ class $61ef60fc9b1041f4$export$cacbb3924155d68e extends (0, $img26$Layout) {
65
65
  return false;
66
66
  }
67
67
  isVisible(node, rect) {
68
- return node.layoutInfo.rect.intersects(rect) || node.layoutInfo.isSticky || this.virtualizer.isPersistedKey(node.layoutInfo.key);
68
+ return node.layoutInfo.rect.intersects(rect) || node.layoutInfo.isSticky || node.layoutInfo.type === 'header' || this.virtualizer.isPersistedKey(node.layoutInfo.key);
69
69
  }
70
70
  shouldInvalidateEverything(invalidationContext) {
71
71
  // Invalidate cache if the size of the collection changed.
@@ -73,9 +73,7 @@ class $61ef60fc9b1041f4$export$cacbb3924155d68e extends (0, $img26$Layout) {
73
73
  return invalidationContext.sizeChanged;
74
74
  }
75
75
  validate(invalidationContext) {
76
- var _invalidationContext_layoutOptions;
77
76
  this.collection = this.virtualizer.collection;
78
- this.isLoading = ((_invalidationContext_layoutOptions = invalidationContext.layoutOptions) === null || _invalidationContext_layoutOptions === void 0 ? void 0 : _invalidationContext_layoutOptions.isLoading) || false;
79
77
  // Reset valid rect if we will have to invalidate everything.
80
78
  // Otherwise we can reuse cached layout infos outside the current visible rect.
81
79
  this.invalidateEverything = this.shouldInvalidateEverything(invalidationContext);
@@ -85,12 +83,7 @@ class $61ef60fc9b1041f4$export$cacbb3924155d68e extends (0, $img26$Layout) {
85
83
  if (this.lastCollection && this.collection !== this.lastCollection) {
86
84
  for (let key of this.lastCollection.getKeys())if (!this.collection.getItem(key)) {
87
85
  let layoutNode = this.layoutNodes.get(key);
88
- if (layoutNode) {
89
- var _layoutNode_header;
90
- this.layoutInfos.delete(layoutNode.layoutInfo.key);
91
- this.layoutInfos.delete((_layoutNode_header = layoutNode.header) === null || _layoutNode_header === void 0 ? void 0 : _layoutNode_header.key);
92
- this.layoutNodes.delete(key);
93
- }
86
+ if (layoutNode) this.layoutNodes.delete(key);
94
87
  }
95
88
  }
96
89
  this.lastWidth = this.virtualizer.visibleRect.width;
@@ -98,8 +91,7 @@ class $61ef60fc9b1041f4$export$cacbb3924155d68e extends (0, $img26$Layout) {
98
91
  this.invalidateEverything = false;
99
92
  this.validRect = this.requestedRect.copy();
100
93
  }
101
- buildCollection() {
102
- let y = this.padding;
94
+ buildCollection(y = 0) {
103
95
  let skipped = 0;
104
96
  let nodes = [];
105
97
  for (let node of this.collection){
@@ -119,40 +111,18 @@ class $61ef60fc9b1041f4$export$cacbb3924155d68e extends (0, $img26$Layout) {
119
111
  break;
120
112
  }
121
113
  }
122
- if (this.isLoading) {
123
- var _this_loaderHeight;
124
- let rect = new (0, $img26$Rect)(0, y, this.virtualizer.visibleRect.width, (_this_loaderHeight = this.loaderHeight) !== null && _this_loaderHeight !== void 0 ? _this_loaderHeight : this.virtualizer.visibleRect.height);
125
- let loader = new (0, $img26$LayoutInfo)('loader', 'loader', rect);
126
- this.layoutInfos.set('loader', loader);
127
- nodes.push({
128
- layoutInfo: loader
129
- });
130
- y = loader.rect.maxY;
131
- }
132
- if (nodes.length === 0 && this.enableEmptyState) {
133
- var _this_placeholderHeight;
134
- let rect = new (0, $img26$Rect)(0, y, this.virtualizer.visibleRect.width, (_this_placeholderHeight = this.placeholderHeight) !== null && _this_placeholderHeight !== void 0 ? _this_placeholderHeight : this.virtualizer.visibleRect.height);
135
- let placeholder = new (0, $img26$LayoutInfo)('placeholder', 'placeholder', rect);
136
- this.layoutInfos.set('placeholder', placeholder);
137
- nodes.push({
138
- layoutInfo: placeholder
139
- });
140
- y = placeholder.rect.maxY;
141
- }
142
- this.contentSize = new (0, $img26$Size)(this.virtualizer.visibleRect.width, y + this.padding);
114
+ this.contentSize = new (0, $img26$Size)(this.virtualizer.visibleRect.width, y);
143
115
  return nodes;
144
116
  }
145
117
  isValid(node, y) {
146
118
  let cached = this.layoutNodes.get(node.key);
147
- return !this.invalidateEverything && cached && cached.node === node && y === (cached.header || cached.layoutInfo).rect.y && cached.layoutInfo.rect.intersects(this.validRect) && cached.validRect.containsRect(cached.layoutInfo.rect.intersection(this.requestedRect));
119
+ return !this.invalidateEverything && cached && cached.node === node && y === cached.layoutInfo.rect.y && cached.layoutInfo.rect.intersects(this.validRect) && cached.validRect.containsRect(cached.layoutInfo.rect.intersection(this.requestedRect));
148
120
  }
149
121
  buildChild(node, x, y, parentKey) {
150
122
  if (this.isValid(node, y)) return this.layoutNodes.get(node.key);
151
123
  let layoutNode = this.buildNode(node, x, y);
152
124
  layoutNode.node = node;
153
125
  layoutNode.layoutInfo.parentKey = parentKey !== null && parentKey !== void 0 ? parentKey : null;
154
- this.layoutInfos.set(layoutNode.layoutInfo.key, layoutNode.layoutInfo);
155
- if (layoutNode.header) this.layoutInfos.set(layoutNode.header.key, layoutNode.header);
156
126
  this.layoutNodes.set(node.key, layoutNode);
157
127
  return layoutNode;
158
128
  }
@@ -168,14 +138,6 @@ class $61ef60fc9b1041f4$export$cacbb3924155d68e extends (0, $img26$Layout) {
168
138
  }
169
139
  buildSection(node, x, y) {
170
140
  let width = this.virtualizer.visibleRect.width;
171
- let header = null;
172
- if (node.rendered || this.forceSectionHeaders) {
173
- let headerNode = this.buildSectionHeader(node, x, y);
174
- header = headerNode.layoutInfo;
175
- header.key += ':header';
176
- header.parentKey = node.key;
177
- y += header.rect.height;
178
- }
179
141
  let rect = new (0, $img26$Rect)(0, y, width, 0);
180
142
  let layoutInfo = new (0, $img26$LayoutInfo)(node.type, node.key, rect);
181
143
  let startY = y;
@@ -203,7 +165,6 @@ class $61ef60fc9b1041f4$export$cacbb3924155d68e extends (0, $img26$Layout) {
203
165
  }
204
166
  rect.height = y - startY;
205
167
  return {
206
- header: header,
207
168
  layoutInfo: layoutInfo,
208
169
  children: children,
209
170
  validRect: layoutInfo.rect.intersection(this.requestedRect)
@@ -219,7 +180,7 @@ class $61ef60fc9b1041f4$export$cacbb3924155d68e extends (0, $img26$Layout) {
219
180
  // Mark as estimated if the size of the overall virtualizer changed,
220
181
  // or the content of the item changed.
221
182
  let previousLayoutNode = this.layoutNodes.get(node.key);
222
- let previousLayoutInfo = (previousLayoutNode === null || previousLayoutNode === void 0 ? void 0 : previousLayoutNode.header) || (previousLayoutNode === null || previousLayoutNode === void 0 ? void 0 : previousLayoutNode.layoutInfo);
183
+ let previousLayoutInfo = previousLayoutNode === null || previousLayoutNode === void 0 ? void 0 : previousLayoutNode.layoutInfo;
223
184
  if (previousLayoutInfo) {
224
185
  let curNode = this.collection.getItem(node.key);
225
186
  let lastNode = this.lastCollection ? this.lastCollection.getItem(node.key) : null;
@@ -259,11 +220,8 @@ class $61ef60fc9b1041f4$export$cacbb3924155d68e extends (0, $img26$Layout) {
259
220
  }
260
221
  }
261
222
  if (rectHeight == null) rectHeight = $61ef60fc9b1041f4$var$DEFAULT_HEIGHT;
262
- if (typeof this.indentationForItem === 'function') x += this.indentationForItem(this.collection, node.key) || 0;
263
223
  let rect = new (0, $img26$Rect)(x, y, width - x, rectHeight);
264
224
  let layoutInfo = new (0, $img26$LayoutInfo)(node.type, node.key, rect);
265
- // allow overflow so the focus ring/selection ring can extend outside to overlap with the adjacent items borders
266
- layoutInfo.allowOverflow = true;
267
225
  layoutInfo.estimatedSize = isEstimated;
268
226
  return {
269
227
  layoutInfo: layoutInfo,
@@ -271,15 +229,16 @@ class $61ef60fc9b1041f4$export$cacbb3924155d68e extends (0, $img26$Layout) {
271
229
  };
272
230
  }
273
231
  updateItemSize(key, size) {
274
- let layoutInfo = this.layoutInfos.get(key);
232
+ let layoutNode = this.layoutNodes.get(key);
275
233
  // If no layoutInfo, item has been deleted/removed.
276
- if (!layoutInfo) return false;
234
+ if (!layoutNode) return false;
235
+ let layoutInfo = layoutNode.layoutInfo;
277
236
  layoutInfo.estimatedSize = false;
278
237
  if (layoutInfo.rect.height !== size.height) {
279
238
  // Copy layout info rather than mutating so that later caches are invalidated.
280
239
  let newLayoutInfo = layoutInfo.copy();
281
240
  newLayoutInfo.rect.height = size.height;
282
- this.layoutInfos.set(key, newLayoutInfo);
241
+ layoutNode.layoutInfo = newLayoutInfo;
283
242
  // Items after this layoutInfo will need to be repositioned to account for the new height.
284
243
  // Adjust the validRect so that only items above remain valid.
285
244
  this.validRect.height = Math.min(this.validRect.height, layoutInfo.rect.y - this.validRect.y);
@@ -302,8 +261,7 @@ class $61ef60fc9b1041f4$export$cacbb3924155d68e extends (0, $img26$Layout) {
302
261
  // Invalidate by intersecting the validRect of this node with the overall validRect.
303
262
  n.validRect = n.validRect.intersection(this.validRect);
304
263
  // Replace layout info in LayoutNode
305
- if (n.header === oldLayoutInfo) n.header = newLayoutInfo;
306
- else if (n.layoutInfo === oldLayoutInfo) n.layoutInfo = newLayoutInfo;
264
+ if (n.layoutInfo === oldLayoutInfo) n.layoutInfo = newLayoutInfo;
307
265
  }
308
266
  }
309
267
  getContentSize() {
@@ -354,13 +312,6 @@ class $61ef60fc9b1041f4$export$cacbb3924155d68e extends (0, $img26$Layout) {
354
312
  this.estimatedRowHeight = options.estimatedRowHeight;
355
313
  this.headingHeight = options.headingHeight;
356
314
  this.estimatedHeadingHeight = options.estimatedHeadingHeight;
357
- this.forceSectionHeaders = options.forceSectionHeaders;
358
- this.padding = options.padding || 0;
359
- this.indentationForItem = options.indentationForItem;
360
- this.loaderHeight = options.loaderHeight;
361
- this.placeholderHeight = options.placeholderHeight;
362
- this.enableEmptyState = options.enableEmptyState || false;
363
- this.layoutInfos = new Map();
364
315
  this.layoutNodes = new Map();
365
316
  this.rootNodes = [];
366
317
  this.lastWidth = 0;
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAkCD,MAAM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C,CAAC,CAAE;QAC9C,KAAK;QACL,IAAI,CAAC,SAAS,GAAG,QAAQ,SAAS;QAClC,IAAI,CAAC,kBAAkB,GAAG,QAAQ,kBAAkB;QACpD,IAAI,CAAC,aAAa,GAAG,QAAQ,aAAa;QAC1C,IAAI,CAAC,sBAAsB,GAAG,QAAQ,sBAAsB;QAC5D,IAAI,CAAC,mBAAmB,GAAG,QAAQ,mBAAmB;QACtD,IAAI,CAAC,OAAO,GAAG,QAAQ,OAAO,IAAI;QAClC,IAAI,CAAC,kBAAkB,GAAG,QAAQ,kBAAkB;QACpD,IAAI,CAAC,YAAY,GAAG,QAAQ,YAAY;QACxC,IAAI,CAAC,iBAAiB,GAAG,QAAQ,iBAAiB;QAClD,IAAI,CAAC,gBAAgB,GAAG,QAAQ,gBAAgB,IAAI;QACpD,IAAI,CAAC,WAAW,GAAG,IAAI;QACvB,IAAI,CAAC,WAAW,GAAG,IAAI;QACvB,IAAI,CAAC,SAAS,GAAG,EAAE;QACnB,IAAI,CAAC,SAAS,GAAG;QACjB,IAAI,CAAC,cAAc,GAAG;QACtB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA,GAAA,WAAG;QACxB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAA,GAAA,WAAG;QAC5B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAA,GAAA,WAAG;IAC5B;AAgaF","sources":["packages/@react-stately/layout/src/ListLayout.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, DropTarget, DropTargetDelegate, Key, Node} from '@react-types/shared';\nimport {getChildNodes} from '@react-stately/collections';\nimport {InvalidationContext, Layout, LayoutInfo, Point, Rect, Size} from '@react-stately/virtualizer';\n\nexport type ListLayoutOptions<T> = {\n /** The height of a row in px. */\n rowHeight?: number,\n estimatedRowHeight?: number,\n headingHeight?: number,\n estimatedHeadingHeight?: number,\n padding?: number,\n indentationForItem?: (collection: Collection<Node<T>>, key: Key) => number,\n loaderHeight?: number,\n placeholderHeight?: number,\n forceSectionHeaders?: boolean,\n enableEmptyState?: boolean\n};\n\n// A wrapper around LayoutInfo that supports hierarchy\nexport interface LayoutNode {\n node?: Node<unknown>,\n layoutInfo: LayoutInfo,\n header?: LayoutInfo,\n children?: LayoutNode[],\n validRect: Rect,\n index?: number\n}\n\nexport interface ListLayoutProps {\n isLoading?: boolean\n}\n\nconst DEFAULT_HEIGHT = 48;\n\n/**\n * The ListLayout class is an implementation of a virtualizer {@link Layout}\n * it is used for creating lists and lists with indented sub-lists.\n *\n * To configure a ListLayout, you can use the properties to define the\n * layouts and/or use the method for defining indentation.\n * The {@link ListKeyboardDelegate} extends the existing virtualizer\n * delegate with an additional method to do this (it uses the same delegate object as\n * the virtualizer itself).\n */\nexport class ListLayout<T> extends Layout<Node<T>, ListLayoutProps> implements DropTargetDelegate {\n protected rowHeight: number;\n protected estimatedRowHeight: number;\n protected headingHeight: number;\n protected estimatedHeadingHeight: number;\n protected forceSectionHeaders: boolean;\n protected padding: number;\n protected indentationForItem?: (collection: Collection<Node<T>>, key: Key) => number;\n protected layoutInfos: Map<Key, LayoutInfo>;\n protected layoutNodes: Map<Key, LayoutNode>;\n protected contentSize: Size;\n protected collection: Collection<Node<T>>;\n protected isLoading: boolean;\n protected lastWidth: number;\n protected lastCollection: Collection<Node<T>>;\n protected rootNodes: LayoutNode[];\n protected invalidateEverything: boolean;\n protected loaderHeight: number;\n protected placeholderHeight: number;\n protected enableEmptyState: boolean;\n /** The rectangle containing currently valid layout infos. */\n protected validRect: Rect;\n /** The rectangle of requested layout infos so far. */\n protected requestedRect: Rect;\n\n /**\n * Creates a new ListLayout with options. See the list of properties below for a description\n * of the options that can be provided.\n */\n constructor(options: ListLayoutOptions<T> = {}) {\n super();\n this.rowHeight = options.rowHeight;\n this.estimatedRowHeight = options.estimatedRowHeight;\n this.headingHeight = options.headingHeight;\n this.estimatedHeadingHeight = options.estimatedHeadingHeight;\n this.forceSectionHeaders = options.forceSectionHeaders;\n this.padding = options.padding || 0;\n this.indentationForItem = options.indentationForItem;\n this.loaderHeight = options.loaderHeight;\n this.placeholderHeight = options.placeholderHeight;\n this.enableEmptyState = options.enableEmptyState || false;\n this.layoutInfos = new Map();\n this.layoutNodes = new Map();\n this.rootNodes = [];\n this.lastWidth = 0;\n this.lastCollection = null;\n this.validRect = new Rect();\n this.requestedRect = new Rect();\n this.contentSize = new Size();\n }\n\n getLayoutInfo(key: Key) {\n this.ensureLayoutInfo(key);\n return this.layoutInfos.get(key)!;\n }\n\n getVisibleLayoutInfos(rect: Rect) {\n // Adjust rect to keep number of visible rows consistent.\n // (only if height > 1 for getDropTargetFromPoint)\n if (rect.height > 1) {\n let rowHeight = (this.rowHeight ?? this.estimatedRowHeight);\n rect.y = Math.floor(rect.y / rowHeight) * rowHeight;\n rect.height = Math.ceil(rect.height / rowHeight) * rowHeight;\n }\n\n // If layout hasn't yet been done for the requested rect, union the\n // new rect with the existing valid rect, and recompute.\n this.layoutIfNeeded(rect);\n\n let res: LayoutInfo[] = [];\n\n let addNodes = (nodes: LayoutNode[]) => {\n for (let node of nodes) {\n if (this.isVisible(node, rect)) {\n res.push(node.layoutInfo);\n if (node.header) {\n res.push(node.header);\n }\n\n if (node.children) {\n addNodes(node.children);\n }\n }\n }\n };\n\n addNodes(this.rootNodes);\n return res;\n }\n\n protected layoutIfNeeded(rect: Rect) {\n if (!this.lastCollection) {\n return;\n }\n\n if (!this.requestedRect.containsRect(rect)) {\n this.requestedRect = this.requestedRect.union(rect);\n this.rootNodes = this.buildCollection();\n } else {\n // Ensure all of the persisted keys are available.\n for (let key of this.virtualizer.persistedKeys) {\n if (this.ensureLayoutInfo(key)) {\n break;\n }\n }\n }\n }\n\n private ensureLayoutInfo(key: Key) {\n // If the layout info wasn't found, it might be outside the bounds of the area that we've\n // computed layout for so far. This can happen when accessing a random key, e.g pressing Home/End.\n // Compute the full layout and try again.\n if (!this.layoutInfos.has(key) && this.requestedRect.area < this.contentSize.area && this.lastCollection) {\n this.requestedRect = new Rect(0, 0, Infinity, Infinity);\n this.rootNodes = this.buildCollection();\n this.requestedRect = new Rect(0, 0, this.contentSize.width, this.contentSize.height);\n return true;\n }\n\n return false;\n }\n\n private isVisible(node: LayoutNode, rect: Rect) {\n return node.layoutInfo.rect.intersects(rect) || node.layoutInfo.isSticky || this.virtualizer.isPersistedKey(node.layoutInfo.key);\n }\n\n protected shouldInvalidateEverything(invalidationContext: InvalidationContext<ListLayoutProps>) {\n // Invalidate cache if the size of the collection changed.\n // In this case, we need to recalculate the entire layout.\n return invalidationContext.sizeChanged;\n }\n\n validate(invalidationContext: InvalidationContext<ListLayoutProps>) {\n this.collection = this.virtualizer.collection;\n this.isLoading = invalidationContext.layoutOptions?.isLoading || false;\n\n // Reset valid rect if we will have to invalidate everything.\n // Otherwise we can reuse cached layout infos outside the current visible rect.\n this.invalidateEverything = this.shouldInvalidateEverything(invalidationContext);\n if (this.invalidateEverything) {\n this.requestedRect = this.virtualizer.visibleRect.copy();\n }\n\n this.rootNodes = this.buildCollection();\n\n // Remove deleted layout nodes\n if (this.lastCollection && this.collection !== this.lastCollection) {\n for (let key of this.lastCollection.getKeys()) {\n if (!this.collection.getItem(key)) {\n let layoutNode = this.layoutNodes.get(key);\n if (layoutNode) {\n this.layoutInfos.delete(layoutNode.layoutInfo.key);\n this.layoutInfos.delete(layoutNode.header?.key);\n this.layoutNodes.delete(key);\n }\n }\n }\n }\n\n this.lastWidth = this.virtualizer.visibleRect.width;\n this.lastCollection = this.collection;\n this.invalidateEverything = false;\n this.validRect = this.requestedRect.copy();\n }\n\n protected buildCollection(): LayoutNode[] {\n let y = this.padding;\n let skipped = 0;\n let nodes = [];\n for (let node of this.collection) {\n let rowHeight = (this.rowHeight ?? this.estimatedRowHeight);\n\n // Skip rows before the valid rectangle unless they are already cached.\n if (node.type === 'item' && y + rowHeight < this.requestedRect.y && !this.isValid(node, y)) {\n y += rowHeight;\n skipped++;\n continue;\n }\n\n let layoutNode = this.buildChild(node, 0, y, null);\n y = layoutNode.layoutInfo.rect.maxY;\n nodes.push(layoutNode);\n\n if (node.type === 'item' && y > this.requestedRect.maxY) {\n y += (this.collection.size - (nodes.length + skipped)) * rowHeight;\n break;\n }\n }\n\n if (this.isLoading) {\n let rect = new Rect(0, y, this.virtualizer.visibleRect.width,\n this.loaderHeight ?? this.virtualizer.visibleRect.height);\n let loader = new LayoutInfo('loader', 'loader', rect);\n this.layoutInfos.set('loader', loader);\n nodes.push({layoutInfo: loader});\n y = loader.rect.maxY;\n }\n\n if (nodes.length === 0 && this.enableEmptyState) {\n let rect = new Rect(0, y, this.virtualizer.visibleRect.width,\n this.placeholderHeight ?? this.virtualizer.visibleRect.height);\n let placeholder = new LayoutInfo('placeholder', 'placeholder', rect);\n this.layoutInfos.set('placeholder', placeholder);\n nodes.push({layoutInfo: placeholder});\n y = placeholder.rect.maxY;\n }\n\n this.contentSize = new Size(this.virtualizer.visibleRect.width, y + this.padding);\n return nodes;\n }\n\n protected isValid(node: Node<T>, y: number) {\n let cached = this.layoutNodes.get(node.key);\n return (\n !this.invalidateEverything &&\n cached &&\n cached.node === node &&\n y === (cached.header || cached.layoutInfo).rect.y &&\n cached.layoutInfo.rect.intersects(this.validRect) &&\n cached.validRect.containsRect(cached.layoutInfo.rect.intersection(this.requestedRect))\n );\n }\n\n protected buildChild(node: Node<T>, x: number, y: number, parentKey: Key | null): LayoutNode {\n if (this.isValid(node, y)) {\n return this.layoutNodes.get(node.key);\n }\n\n let layoutNode = this.buildNode(node, x, y);\n layoutNode.node = node;\n\n layoutNode.layoutInfo.parentKey = parentKey ?? null;\n this.layoutInfos.set(layoutNode.layoutInfo.key, layoutNode.layoutInfo);\n if (layoutNode.header) {\n this.layoutInfos.set(layoutNode.header.key, layoutNode.header);\n }\n\n this.layoutNodes.set(node.key, layoutNode);\n return layoutNode;\n }\n\n protected buildNode(node: Node<T>, x: number, y: number): LayoutNode {\n switch (node.type) {\n case 'section':\n return this.buildSection(node, x, y);\n case 'item':\n return this.buildItem(node, x, y);\n case 'header':\n return this.buildSectionHeader(node, x, y);\n }\n }\n\n private buildSection(node: Node<T>, x: number, y: number): LayoutNode {\n let width = this.virtualizer.visibleRect.width;\n let header = null;\n if (node.rendered || this.forceSectionHeaders) {\n let headerNode = this.buildSectionHeader(node, x, y);\n header = headerNode.layoutInfo;\n header.key += ':header';\n header.parentKey = node.key;\n y += header.rect.height;\n }\n\n let rect = new Rect(0, y, width, 0);\n let layoutInfo = new LayoutInfo(node.type, node.key, rect);\n\n let startY = y;\n let skipped = 0;\n let children = [];\n for (let child of getChildNodes(node, this.collection)) {\n let rowHeight = (this.rowHeight ?? this.estimatedRowHeight);\n\n // Skip rows before the valid rectangle unless they are already cached.\n if (y + rowHeight < this.requestedRect.y && !this.isValid(node, y)) {\n y += rowHeight;\n skipped++;\n continue;\n }\n\n let layoutNode = this.buildChild(child, x, y, layoutInfo.key);\n y = layoutNode.layoutInfo.rect.maxY;\n children.push(layoutNode);\n\n if (y > this.requestedRect.maxY) {\n // Estimate the remaining height for rows that we don't need to layout right now.\n y += ([...getChildNodes(node, this.collection)].length - (children.length + skipped)) * rowHeight;\n break;\n }\n }\n\n rect.height = y - startY;\n\n return {\n header,\n layoutInfo,\n children,\n validRect: layoutInfo.rect.intersection(this.requestedRect)\n };\n }\n\n private buildSectionHeader(node: Node<T>, x: number, y: number): LayoutNode {\n let width = this.virtualizer.visibleRect.width;\n let rectHeight = this.headingHeight;\n let isEstimated = false;\n\n // If no explicit height is available, use an estimated height.\n if (rectHeight == null) {\n // If a previous version of this layout info exists, reuse its height.\n // Mark as estimated if the size of the overall virtualizer changed,\n // or the content of the item changed.\n let previousLayoutNode = this.layoutNodes.get(node.key);\n let previousLayoutInfo = previousLayoutNode?.header || previousLayoutNode?.layoutInfo;\n if (previousLayoutInfo) {\n let curNode = this.collection.getItem(node.key);\n let lastNode = this.lastCollection ? this.lastCollection.getItem(node.key) : null;\n rectHeight = previousLayoutInfo.rect.height;\n isEstimated = width !== this.lastWidth || curNode !== lastNode || previousLayoutInfo.estimatedSize;\n } else {\n rectHeight = (node.rendered ? this.estimatedHeadingHeight : 0);\n isEstimated = true;\n }\n }\n\n if (rectHeight == null) {\n rectHeight = DEFAULT_HEIGHT;\n }\n\n let headerRect = new Rect(0, y, width, rectHeight);\n let header = new LayoutInfo('header', node.key, headerRect);\n header.estimatedSize = isEstimated;\n return {\n layoutInfo: header,\n children: [],\n validRect: header.rect.intersection(this.requestedRect)\n };\n }\n\n private buildItem(node: Node<T>, x: number, y: number): LayoutNode {\n let width = this.virtualizer.visibleRect.width;\n let rectHeight = this.rowHeight;\n let isEstimated = false;\n\n // If no explicit height is available, use an estimated height.\n if (rectHeight == null) {\n // If a previous version of this layout info exists, reuse its height.\n // Mark as estimated if the size of the overall virtualizer changed,\n // or the content of the item changed.\n let previousLayoutNode = this.layoutNodes.get(node.key);\n if (previousLayoutNode) {\n rectHeight = previousLayoutNode.layoutInfo.rect.height;\n isEstimated = width !== this.lastWidth || node !== previousLayoutNode.node || previousLayoutNode.layoutInfo.estimatedSize;\n } else {\n rectHeight = this.estimatedRowHeight;\n isEstimated = true;\n }\n }\n\n if (rectHeight == null) {\n rectHeight = DEFAULT_HEIGHT;\n }\n\n if (typeof this.indentationForItem === 'function') {\n x += this.indentationForItem(this.collection, node.key) || 0;\n }\n\n let rect = new Rect(x, y, width - x, rectHeight);\n let layoutInfo = new LayoutInfo(node.type, node.key, rect);\n // allow overflow so the focus ring/selection ring can extend outside to overlap with the adjacent items borders\n layoutInfo.allowOverflow = true;\n layoutInfo.estimatedSize = isEstimated;\n return {\n layoutInfo,\n validRect: layoutInfo.rect\n };\n }\n\n updateItemSize(key: Key, size: Size) {\n let layoutInfo = this.layoutInfos.get(key);\n // If no layoutInfo, item has been deleted/removed.\n if (!layoutInfo) {\n return false;\n }\n\n layoutInfo.estimatedSize = false;\n if (layoutInfo.rect.height !== size.height) {\n // Copy layout info rather than mutating so that later caches are invalidated.\n let newLayoutInfo = layoutInfo.copy();\n newLayoutInfo.rect.height = size.height;\n this.layoutInfos.set(key, newLayoutInfo);\n\n // Items after this layoutInfo will need to be repositioned to account for the new height.\n // Adjust the validRect so that only items above remain valid.\n this.validRect.height = Math.min(this.validRect.height, layoutInfo.rect.y - this.validRect.y);\n\n // The requestedRect also needs to be adjusted to account for the height difference.\n this.requestedRect.height += newLayoutInfo.rect.height - layoutInfo.rect.height;\n\n // Invalidate layout for this layout node and all parents\n this.updateLayoutNode(key, layoutInfo, newLayoutInfo);\n\n let node = this.collection.getItem(layoutInfo.parentKey);\n while (node) {\n this.updateLayoutNode(node.key, layoutInfo, newLayoutInfo);\n node = this.collection.getItem(node.parentKey);\n }\n\n return true;\n }\n\n return false;\n }\n\n private updateLayoutNode(key: Key, oldLayoutInfo: LayoutInfo, newLayoutInfo: LayoutInfo) {\n let n = this.layoutNodes.get(key);\n if (n) {\n // Invalidate by intersecting the validRect of this node with the overall validRect.\n n.validRect = n.validRect.intersection(this.validRect);\n\n // Replace layout info in LayoutNode\n if (n.header === oldLayoutInfo) {\n n.header = newLayoutInfo;\n } else if (n.layoutInfo === oldLayoutInfo) {\n n.layoutInfo = newLayoutInfo;\n }\n }\n }\n\n getContentSize() {\n return this.contentSize;\n }\n\n getDropTargetFromPoint(x: number, y: number, isValidDropTarget: (target: DropTarget) => boolean): DropTarget {\n x += this.virtualizer.visibleRect.x;\n y += this.virtualizer.visibleRect.y;\n\n let key = this.virtualizer.keyAtPoint(new Point(x, y));\n if (key == null || this.collection.size === 0) {\n return {type: 'root'};\n }\n\n let layoutInfo = this.getLayoutInfo(key);\n let rect = layoutInfo.rect;\n let target: DropTarget = {\n type: 'item',\n key: layoutInfo.key,\n dropPosition: 'on'\n };\n\n // If dropping on the item isn't accepted, try the target before or after depending on the y position.\n // Otherwise, if dropping on the item is accepted, still try the before/after positions if within 10px\n // of the top or bottom of the item.\n if (!isValidDropTarget(target)) {\n if (y <= rect.y + rect.height / 2 && isValidDropTarget({...target, dropPosition: 'before'})) {\n target.dropPosition = 'before';\n } else if (isValidDropTarget({...target, dropPosition: 'after'})) {\n target.dropPosition = 'after';\n }\n } else if (y <= rect.y + 10 && isValidDropTarget({...target, dropPosition: 'before'})) {\n target.dropPosition = 'before';\n } else if (y >= rect.maxY - 10 && isValidDropTarget({...target, dropPosition: 'after'})) {\n target.dropPosition = 'after';\n }\n\n return target;\n }\n}\n"],"names":[],"version":3,"file":"ListLayout.module.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AA0BD,MAAM,uCAAiB;AAUhB,MAAM,kDAA+B,CAAA,GAAA,aAAK;IAoC/C,cAAc,GAAQ,EAAE;YAEf;QADP,IAAI,CAAC,gBAAgB,CAAC;QACtB,OAAO,EAAA,wBAAA,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,kBAArB,4CAAA,sBAA2B,UAAU,KAAI;IAClD;IAEA,sBAAsB,IAAU,EAAE;QAChC,yDAAyD;QACzD,kDAAkD;QAClD,IAAI,KAAK,MAAM,GAAG,GAAG;gBACF;YAAjB,IAAI,YAAa,CAAA,kBAAA,IAAI,CAAC,SAAS,cAAd,6BAAA,kBAAkB,IAAI,CAAC,kBAAkB;YAC1D,KAAK,CAAC,GAAG,KAAK,KAAK,CAAC,KAAK,CAAC,GAAG,aAAa;YAC1C,KAAK,MAAM,GAAG,KAAK,IAAI,CAAC,KAAK,MAAM,GAAG,aAAa;QACrD;QAEA,mEAAmE;QACnE,wDAAwD;QACxD,IAAI,CAAC,cAAc,CAAC;QAEpB,IAAI,MAAoB,EAAE;QAE1B,IAAI,WAAW,CAAC;YACd,KAAK,I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AAsB,GAAG,QAAQ,sBAAsB;QAC5D,IAAI,CAAC,WAAW,GAAG,IAAI;QACvB,IAAI,CAAC,SAAS,GAAG,EAAE;QACnB,IAAI,CAAC,SAAS,GAAG;QACjB,IAAI,CAAC,cAAc,GAAG;QACtB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA,GAAA,WAAG;QACxB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAA,GAAA,WAAG;QAC5B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAA,GAAA,WAAG;IAC5B;AAiXF","sources":["packages/@react-stately/layout/src/ListLayout.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, DropTarget, DropTargetDelegate, Key, Node} from '@react-types/shared';\nimport {getChildNodes} from '@react-stately/collections';\nimport {InvalidationContext, Layout, LayoutInfo, Point, Rect, Size} from '@react-stately/virtualizer';\n\nexport interface ListLayoutOptions {\n /** The fixed height of a row in px. */\n rowHeight?: number,\n /** The estimated height of a row, when row heights are variable. */\n estimatedRowHeight?: number,\n /** The fixed height of a section header in px. */\n headingHeight?: number,\n /** The estimated height of a section header, when the height is variable. */\n estimatedHeadingHeight?: number\n}\n\n// A wrapper around LayoutInfo that supports hierarchy\nexport interface LayoutNode {\n node?: Node<unknown>,\n layoutInfo: LayoutInfo,\n children?: LayoutNode[],\n validRect: Rect,\n index?: number\n}\n\nconst DEFAULT_HEIGHT = 48;\n\n/**\n * The ListLayout class is an implementation of a virtualizer {@link Layout}.\n * To configure a ListLayout, you can use the properties to define the\n * layouts and/or use the method for defining indentation.\n * The {@link ListKeyboardDelegate} extends the existing virtualizer\n * delegate with an additional method to do this (it uses the same delegate object as\n * the virtualizer itself).\n */\nexport class ListLayout<T, O = any> extends Layout<Node<T>, O> implements DropTargetDelegate {\n protected rowHeight: number;\n protected estimatedRowHeight: number;\n protected headingHeight: number;\n protected estimatedHeadingHeight: number;\n protected layoutNodes: Map<Key, LayoutNode>;\n protected contentSize: Size;\n protected collection: Collection<Node<T>>;\n private lastCollection: Collection<Node<T>>;\n private lastWidth: number;\n protected rootNodes: LayoutNode[];\n private invalidateEverything: boolean;\n /** The rectangle containing currently valid layout infos. */\n protected validRect: Rect;\n /** The rectangle of requested layout infos so far. */\n protected requestedRect: Rect;\n\n /**\n * Creates a new ListLayout with options. See the list of properties below for a description\n * of the options that can be provided.\n */\n constructor(options: ListLayoutOptions = {}) {\n super();\n this.rowHeight = options.rowHeight;\n this.estimatedRowHeight = options.estimatedRowHeight;\n this.headingHeight = options.headingHeight;\n this.estimatedHeadingHeight = options.estimatedHeadingHeight;\n this.layoutNodes = new Map();\n this.rootNodes = [];\n this.lastWidth = 0;\n this.lastCollection = null;\n this.validRect = new Rect();\n this.requestedRect = new Rect();\n this.contentSize = new Size();\n }\n\n getLayoutInfo(key: Key) {\n this.ensureLayoutInfo(key);\n return this.layoutNodes.get(key)?.layoutInfo || null;\n }\n\n getVisibleLayoutInfos(rect: Rect) {\n // Adjust rect to keep number of visible rows consistent.\n // (only if height > 1 for getDropTargetFromPoint)\n if (rect.height > 1) {\n let rowHeight = (this.rowHeight ?? this.estimatedRowHeight);\n rect.y = Math.floor(rect.y / rowHeight) * rowHeight;\n rect.height = Math.ceil(rect.height / rowHeight) * rowHeight;\n }\n\n // If layout hasn't yet been done for the requested rect, union the\n // new rect with the existing valid rect, and recompute.\n this.layoutIfNeeded(rect);\n\n let res: LayoutInfo[] = [];\n\n let addNodes = (nodes: LayoutNode[]) => {\n for (let node of nodes) {\n if (this.isVisible(node, rect)) {\n res.push(node.layoutInfo);\n\n if (node.children) {\n addNodes(node.children);\n }\n }\n }\n };\n\n addNodes(this.rootNodes);\n return res;\n }\n\n protected layoutIfNeeded(rect: Rect) {\n if (!this.lastCollection) {\n return;\n }\n\n if (!this.requestedRect.containsRect(rect)) {\n this.requestedRect = this.requestedRect.union(rect);\n this.rootNodes = this.buildCollection();\n } else {\n // Ensure all of the persisted keys are available.\n for (let key of this.virtualizer.persistedKeys) {\n if (this.ensureLayoutInfo(key)) {\n break;\n }\n }\n }\n }\n\n private ensureLayoutInfo(key: Key) {\n // If the layout info wasn't found, it might be outside the bounds of the area that we've\n // computed layout for so far. This can happen when accessing a random key, e.g pressing Home/End.\n // Compute the full layout and try again.\n if (!this.layoutNodes.has(key) && this.requestedRect.area < this.contentSize.area && this.lastCollection) {\n this.requestedRect = new Rect(0, 0, Infinity, Infinity);\n this.rootNodes = this.buildCollection();\n this.requestedRect = new Rect(0, 0, this.contentSize.width, this.contentSize.height);\n return true;\n }\n\n return false;\n }\n\n protected isVisible(node: LayoutNode, rect: Rect) {\n return node.layoutInfo.rect.intersects(rect) || node.layoutInfo.isSticky || node.layoutInfo.type === 'header' || this.virtualizer.isPersistedKey(node.layoutInfo.key);\n }\n\n protected shouldInvalidateEverything(invalidationContext: InvalidationContext<O>) {\n // Invalidate cache if the size of the collection changed.\n // In this case, we need to recalculate the entire layout.\n return invalidationContext.sizeChanged;\n }\n\n validate(invalidationContext: InvalidationContext<O>) {\n this.collection = this.virtualizer.collection;\n\n // Reset valid rect if we will have to invalidate everything.\n // Otherwise we can reuse cached layout infos outside the current visible rect.\n this.invalidateEverything = this.shouldInvalidateEverything(invalidationContext);\n if (this.invalidateEverything) {\n this.requestedRect = this.virtualizer.visibleRect.copy();\n }\n\n this.rootNodes = this.buildCollection();\n\n // Remove deleted layout nodes\n if (this.lastCollection && this.collection !== this.lastCollection) {\n for (let key of this.lastCollection.getKeys()) {\n if (!this.collection.getItem(key)) {\n let layoutNode = this.layoutNodes.get(key);\n if (layoutNode) {\n this.layoutNodes.delete(key);\n }\n }\n }\n }\n\n this.lastWidth = this.virtualizer.visibleRect.width;\n this.lastCollection = this.collection;\n this.invalidateEverything = false;\n this.validRect = this.requestedRect.copy();\n }\n\n protected buildCollection(y = 0): LayoutNode[] {\n let skipped = 0;\n let nodes = [];\n for (let node of this.collection) {\n let rowHeight = this.rowHeight ?? this.estimatedRowHeight;\n\n // Skip rows before the valid rectangle unless they are already cached.\n if (node.type === 'item' && y + rowHeight < this.requestedRect.y && !this.isValid(node, y)) {\n y += rowHeight;\n skipped++;\n continue;\n }\n\n let layoutNode = this.buildChild(node, 0, y, null);\n y = layoutNode.layoutInfo.rect.maxY;\n nodes.push(layoutNode);\n\n if (node.type === 'item' && y > this.requestedRect.maxY) {\n y += (this.collection.size - (nodes.length + skipped)) * rowHeight;\n break;\n }\n }\n\n this.contentSize = new Size(this.virtualizer.visibleRect.width, y);\n return nodes;\n }\n\n protected isValid(node: Node<T>, y: number) {\n let cached = this.layoutNodes.get(node.key);\n return (\n !this.invalidateEverything &&\n cached &&\n cached.node === node &&\n y === cached.layoutInfo.rect.y &&\n cached.layoutInfo.rect.intersects(this.validRect) &&\n cached.validRect.containsRect(cached.layoutInfo.rect.intersection(this.requestedRect))\n );\n }\n\n protected buildChild(node: Node<T>, x: number, y: number, parentKey: Key | null): LayoutNode {\n if (this.isValid(node, y)) {\n return this.layoutNodes.get(node.key);\n }\n\n let layoutNode = this.buildNode(node, x, y);\n layoutNode.node = node;\n\n layoutNode.layoutInfo.parentKey = parentKey ?? null;\n this.layoutNodes.set(node.key, layoutNode);\n return layoutNode;\n }\n\n protected buildNode(node: Node<T>, x: number, y: number): LayoutNode {\n switch (node.type) {\n case 'section':\n return this.buildSection(node, x, y);\n case 'item':\n return this.buildItem(node, x, y);\n case 'header':\n return this.buildSectionHeader(node, x, y);\n }\n }\n\n protected buildSection(node: Node<T>, x: number, y: number): LayoutNode {\n let width = this.virtualizer.visibleRect.width;\n let rect = new Rect(0, y, width, 0);\n let layoutInfo = new LayoutInfo(node.type, node.key, rect);\n\n let startY = y;\n let skipped = 0;\n let children = [];\n for (let child of getChildNodes(node, this.collection)) {\n let rowHeight = (this.rowHeight ?? this.estimatedRowHeight);\n\n // Skip rows before the valid rectangle unless they are already cached.\n if (y + rowHeight < this.requestedRect.y && !this.isValid(node, y)) {\n y += rowHeight;\n skipped++;\n continue;\n }\n\n let layoutNode = this.buildChild(child, x, y, layoutInfo.key);\n y = layoutNode.layoutInfo.rect.maxY;\n children.push(layoutNode);\n\n if (y > this.requestedRect.maxY) {\n // Estimate the remaining height for rows that we don't need to layout right now.\n y += ([...getChildNodes(node, this.collection)].length - (children.length + skipped)) * rowHeight;\n break;\n }\n }\n\n rect.height = y - startY;\n\n return {\n layoutInfo,\n children,\n validRect: layoutInfo.rect.intersection(this.requestedRect)\n };\n }\n\n protected buildSectionHeader(node: Node<T>, x: number, y: number): LayoutNode {\n let width = this.virtualizer.visibleRect.width;\n let rectHeight = this.headingHeight;\n let isEstimated = false;\n\n // If no explicit height is available, use an estimated height.\n if (rectHeight == null) {\n // If a previous version of this layout info exists, reuse its height.\n // Mark as estimated if the size of the overall virtualizer changed,\n // or the content of the item changed.\n let previousLayoutNode = this.layoutNodes.get(node.key);\n let previousLayoutInfo = previousLayoutNode?.layoutInfo;\n if (previousLayoutInfo) {\n let curNode = this.collection.getItem(node.key);\n let lastNode = this.lastCollection ? this.lastCollection.getItem(node.key) : null;\n rectHeight = previousLayoutInfo.rect.height;\n isEstimated = width !== this.lastWidth || curNode !== lastNode || previousLayoutInfo.estimatedSize;\n } else {\n rectHeight = (node.rendered ? this.estimatedHeadingHeight : 0);\n isEstimated = true;\n }\n }\n\n if (rectHeight == null) {\n rectHeight = DEFAULT_HEIGHT;\n }\n\n let headerRect = new Rect(0, y, width, rectHeight);\n let header = new LayoutInfo('header', node.key, headerRect);\n header.estimatedSize = isEstimated;\n return {\n layoutInfo: header,\n children: [],\n validRect: header.rect.intersection(this.requestedRect)\n };\n }\n\n protected buildItem(node: Node<T>, x: number, y: number): LayoutNode {\n let width = this.virtualizer.visibleRect.width;\n let rectHeight = this.rowHeight;\n let isEstimated = false;\n\n // If no explicit height is available, use an estimated height.\n if (rectHeight == null) {\n // If a previous version of this layout info exists, reuse its height.\n // Mark as estimated if the size of the overall virtualizer changed,\n // or the content of the item changed.\n let previousLayoutNode = this.layoutNodes.get(node.key);\n if (previousLayoutNode) {\n rectHeight = previousLayoutNode.layoutInfo.rect.height;\n isEstimated = width !== this.lastWidth || node !== previousLayoutNode.node || previousLayoutNode.layoutInfo.estimatedSize;\n } else {\n rectHeight = this.estimatedRowHeight;\n isEstimated = true;\n }\n }\n\n if (rectHeight == null) {\n rectHeight = DEFAULT_HEIGHT;\n }\n\n let rect = new Rect(x, y, width - x, rectHeight);\n let layoutInfo = new LayoutInfo(node.type, node.key, rect);\n layoutInfo.estimatedSize = isEstimated;\n return {\n layoutInfo,\n validRect: layoutInfo.rect\n };\n }\n\n updateItemSize(key: Key, size: Size) {\n let layoutNode = this.layoutNodes.get(key);\n // If no layoutInfo, item has been deleted/removed.\n if (!layoutNode) {\n return false;\n }\n\n let layoutInfo = layoutNode.layoutInfo;\n layoutInfo.estimatedSize = false;\n if (layoutInfo.rect.height !== size.height) {\n // Copy layout info rather than mutating so that later caches are invalidated.\n let newLayoutInfo = layoutInfo.copy();\n newLayoutInfo.rect.height = size.height;\n layoutNode.layoutInfo = newLayoutInfo;\n\n // Items after this layoutInfo will need to be repositioned to account for the new height.\n // Adjust the validRect so that only items above remain valid.\n this.validRect.height = Math.min(this.validRect.height, layoutInfo.rect.y - this.validRect.y);\n\n // The requestedRect also needs to be adjusted to account for the height difference.\n this.requestedRect.height += newLayoutInfo.rect.height - layoutInfo.rect.height;\n\n // Invalidate layout for this layout node and all parents\n this.updateLayoutNode(key, layoutInfo, newLayoutInfo);\n\n let node = this.collection.getItem(layoutInfo.parentKey);\n while (node) {\n this.updateLayoutNode(node.key, layoutInfo, newLayoutInfo);\n node = this.collection.getItem(node.parentKey);\n }\n\n return true;\n }\n\n return false;\n }\n\n private updateLayoutNode(key: Key, oldLayoutInfo: LayoutInfo, newLayoutInfo: LayoutInfo) {\n let n = this.layoutNodes.get(key);\n if (n) {\n // Invalidate by intersecting the validRect of this node with the overall validRect.\n n.validRect = n.validRect.intersection(this.validRect);\n\n // Replace layout info in LayoutNode\n if (n.layoutInfo === oldLayoutInfo) {\n n.layoutInfo = newLayoutInfo;\n }\n }\n }\n\n getContentSize() {\n return this.contentSize;\n }\n\n getDropTargetFromPoint(x: number, y: number, isValidDropTarget: (target: DropTarget) => boolean): DropTarget {\n x += this.virtualizer.visibleRect.x;\n y += this.virtualizer.visibleRect.y;\n\n let key = this.virtualizer.keyAtPoint(new Point(x, y));\n if (key == null || this.collection.size === 0) {\n return {type: 'root'};\n }\n\n let layoutInfo = this.getLayoutInfo(key);\n let rect = layoutInfo.rect;\n let target: DropTarget = {\n type: 'item',\n key: layoutInfo.key,\n dropPosition: 'on'\n };\n\n // If dropping on the item isn't accepted, try the target before or after depending on the y position.\n // Otherwise, if dropping on the item is accepted, still try the before/after positions if within 10px\n // of the top or bottom of the item.\n if (!isValidDropTarget(target)) {\n if (y <= rect.y + rect.height / 2 && isValidDropTarget({...target, dropPosition: 'before'})) {\n target.dropPosition = 'before';\n } else if (isValidDropTarget({...target, dropPosition: 'after'})) {\n target.dropPosition = 'after';\n }\n } else if (y <= rect.y + 10 && isValidDropTarget({...target, dropPosition: 'before'})) {\n target.dropPosition = 'before';\n } else if (y >= rect.maxY - 10 && isValidDropTarget({...target, dropPosition: 'after'})) {\n target.dropPosition = 'after';\n }\n\n return target;\n }\n}\n"],"names":[],"version":3,"file":"ListLayout.module.js.map"}
@@ -45,15 +45,13 @@ class $67c493497dcda343$export$62444c3c724b1b20 extends (0, $fe69e47e38ed0ac4$ex
45
45
  super.validate(invalidationContext);
46
46
  }
47
47
  buildCollection() {
48
- // Track whether we were previously loading. This is used to adjust the animations of async loading vs inserts.
49
- let loadingState = this.collection.body.props.loadingState;
50
- this.isLoading = loadingState === 'loading' || loadingState === 'loadingMore';
51
48
  this.stickyColumnIndices = [];
52
49
  for (let column of this.collection.columns)// The selection cell and any other sticky columns always need to be visible.
53
50
  // In addition, row headers need to be in the DOM for accessibility labeling.
54
- if (column.props.isDragButtonCell || column.props.isSelectionCell || this.collection.rowHeaderColumnKeys.has(column.key)) this.stickyColumnIndices.push(column.index);
55
- let header = this.buildColumnHeader();
56
- let body = this.buildBody(this.scrollContainer === 'body' ? 0 : header.layoutInfo.rect.height);
51
+ if (this.isStickyColumn(column) || this.collection.rowHeaderColumnKeys.has(column.key)) this.stickyColumnIndices.push(column.index);
52
+ let header = this.buildTableHeader();
53
+ this.layoutNodes.set(header.layoutInfo.key, header);
54
+ let body = this.buildBody(header.layoutInfo.rect.height);
57
55
  this.lastPersistedKeys = null;
58
56
  body.layoutInfo.rect.width = Math.max(header.layoutInfo.rect.width, body.layoutInfo.rect.width);
59
57
  this.contentSize = new (0, $9lycG$reactstatelyvirtualizer.Size)(body.layoutInfo.rect.width, body.layoutInfo.rect.maxY);
@@ -62,7 +60,7 @@ class $67c493497dcda343$export$62444c3c724b1b20 extends (0, $fe69e47e38ed0ac4$ex
62
60
  body
63
61
  ];
64
62
  }
65
- buildColumnHeader() {
63
+ buildTableHeader() {
66
64
  var _this_collection_head;
67
65
  let rect = new (0, $9lycG$reactstatelyvirtualizer.Rect)(0, 0, 0, 0);
68
66
  var _this_collection_head_key;
@@ -82,7 +80,6 @@ class $67c493497dcda343$export$62444c3c724b1b20 extends (0, $fe69e47e38ed0ac4$ex
82
80
  }
83
81
  rect.width = width;
84
82
  rect.height = y;
85
- this.layoutInfos.set(layoutInfo.key, layoutInfo);
86
83
  return {
87
84
  layoutInfo: layoutInfo,
88
85
  children: children,
@@ -116,7 +113,6 @@ class $67c493497dcda343$export$62444c3c724b1b20 extends (0, $fe69e47e38ed0ac4$ex
116
113
  for (let child of children)if (child.layoutInfo.rect.height !== height) {
117
114
  // Need to copy the layout info before we mutate it.
118
115
  child.layoutInfo = child.layoutInfo.copy();
119
- this.layoutInfos.set(child.layoutInfo.key, child.layoutInfo);
120
116
  child.layoutInfo.rect.height = height;
121
117
  }
122
118
  }
@@ -154,21 +150,28 @@ class $67c493497dcda343$export$62444c3c724b1b20 extends (0, $fe69e47e38ed0ac4$ex
154
150
  isEstimated: isEstimated
155
151
  };
156
152
  }
153
+ getEstimatedRowHeight() {
154
+ var _this_rowHeight;
155
+ return (_this_rowHeight = this.rowHeight) !== null && _this_rowHeight !== void 0 ? _this_rowHeight : this.estimatedRowHeight;
156
+ }
157
157
  buildColumn(node, x, y) {
158
- var _node_props, _node_props1;
159
158
  let width = this.getRenderedColumnWidth(node);
160
159
  let { height: height, isEstimated: isEstimated } = this.getEstimatedHeight(node, width, this.headingHeight, this.estimatedHeadingHeight);
161
160
  let rect = new (0, $9lycG$reactstatelyvirtualizer.Rect)(x, y, width, height);
162
161
  let layoutInfo = new (0, $9lycG$reactstatelyvirtualizer.LayoutInfo)(node.type, node.key, rect);
163
- layoutInfo.isSticky = !this.disableSticky && (((_node_props = node.props) === null || _node_props === void 0 ? void 0 : _node_props.isDragButtonCell) || ((_node_props1 = node.props) === null || _node_props1 === void 0 ? void 0 : _node_props1.isSelectionCell));
162
+ layoutInfo.isSticky = this.isStickyColumn(node);
164
163
  layoutInfo.zIndex = layoutInfo.isSticky ? 2 : 1;
165
164
  layoutInfo.estimatedSize = isEstimated;
166
- layoutInfo.allowOverflow = true;
167
165
  return {
168
166
  layoutInfo: layoutInfo,
169
167
  validRect: layoutInfo.rect
170
168
  };
171
169
  }
170
+ // For subclasses.
171
+ // eslint-disable-next-line
172
+ isStickyColumn(node) {
173
+ return false;
174
+ }
172
175
  buildBody(y) {
173
176
  let rect = new (0, $9lycG$reactstatelyvirtualizer.Rect)(0, y, 0, 0);
174
177
  let layoutInfo = new (0, $9lycG$reactstatelyvirtualizer.LayoutInfo)('rowgroup', this.collection.body.key, rect);
@@ -176,11 +179,10 @@ class $67c493497dcda343$export$62444c3c724b1b20 extends (0, $fe69e47e38ed0ac4$ex
176
179
  let skipped = 0;
177
180
  let width = 0;
178
181
  let children = [];
182
+ let rowHeight = this.getEstimatedRowHeight();
179
183
  for (let [i, node] of [
180
184
  ...(0, $9lycG$reactstatelycollections.getChildNodes)(this.collection.body, this.collection)
181
185
  ].entries()){
182
- var _this_rowHeight;
183
- let rowHeight = ((_this_rowHeight = this.rowHeight) !== null && _this_rowHeight !== void 0 ? _this_rowHeight : this.estimatedRowHeight) + 1;
184
186
  // Skip rows before the valid rectangle unless they are already cached.
185
187
  if (y + rowHeight < this.requestedRect.y && !this.isValid(node, y)) {
186
188
  y += rowHeight;
@@ -199,37 +201,9 @@ class $67c493497dcda343$export$62444c3c724b1b20 extends (0, $fe69e47e38ed0ac4$ex
199
201
  break;
200
202
  }
201
203
  }
202
- if (this.isLoading) {
203
- // Add some margin around the loader to ensure that scrollbars don't flicker in and out.
204
- let rect = new (0, $9lycG$reactstatelyvirtualizer.Rect)(40, Math.max(y, 40), (width || this.virtualizer.visibleRect.width) - 80, children.length === 0 ? this.virtualizer.visibleRect.height - 80 : 60);
205
- let loader = new (0, $9lycG$reactstatelyvirtualizer.LayoutInfo)('loader', 'loader', rect);
206
- loader.parentKey = layoutInfo.key;
207
- loader.isSticky = !this.disableSticky && children.length === 0;
208
- this.layoutInfos.set('loader', loader);
209
- children.push({
210
- layoutInfo: loader,
211
- validRect: loader.rect
212
- });
213
- y = loader.rect.maxY;
214
- width = Math.max(width, rect.width);
215
- } else if (children.length === 0) {
216
- if (this.enableEmptyState) {
217
- let rect = new (0, $9lycG$reactstatelyvirtualizer.Rect)(40, Math.max(y, 40), this.virtualizer.visibleRect.width - 80, this.virtualizer.visibleRect.height - 80);
218
- let empty = new (0, $9lycG$reactstatelyvirtualizer.LayoutInfo)('empty', 'empty', rect);
219
- empty.parentKey = layoutInfo.key;
220
- empty.isSticky = !this.disableSticky;
221
- this.layoutInfos.set('empty', empty);
222
- children.push({
223
- layoutInfo: empty,
224
- validRect: empty.rect
225
- });
226
- y = empty.rect.maxY;
227
- width = Math.max(width, rect.width);
228
- } else y = this.virtualizer.visibleRect.maxY;
229
- }
204
+ if (children.length === 0) y = this.virtualizer.visibleRect.maxY;
230
205
  rect.width = width;
231
206
  rect.height = y - startY;
232
- this.layoutInfos.set(layoutInfo.key, layoutInfo);
233
207
  return {
234
208
  layoutInfo: layoutInfo,
235
209
  children: children,
@@ -278,8 +252,8 @@ class $67c493497dcda343$export$62444c3c724b1b20 extends (0, $fe69e47e38ed0ac4$ex
278
252
  }
279
253
  this.setChildHeights(children, height);
280
254
  var _this_collection_head_key;
281
- rect.width = this.layoutInfos.get((_this_collection_head_key = (_this_collection_head = this.collection.head) === null || _this_collection_head === void 0 ? void 0 : _this_collection_head.key) !== null && _this_collection_head_key !== void 0 ? _this_collection_head_key : 'header').rect.width;
282
- rect.height = height + 1; // +1 for bottom border
255
+ rect.width = this.layoutNodes.get((_this_collection_head_key = (_this_collection_head = this.collection.head) === null || _this_collection_head === void 0 ? void 0 : _this_collection_head.key) !== null && _this_collection_head_key !== void 0 ? _this_collection_head_key : 'header').layoutInfo.rect.width;
256
+ rect.height = height;
283
257
  return {
284
258
  layoutInfo: layoutInfo,
285
259
  children: children,
@@ -287,12 +261,11 @@ class $67c493497dcda343$export$62444c3c724b1b20 extends (0, $fe69e47e38ed0ac4$ex
287
261
  };
288
262
  }
289
263
  buildCell(node, x, y) {
290
- var _node_props, _node_props1;
291
264
  let width = this.getRenderedColumnWidth(node);
292
265
  let { height: height, isEstimated: isEstimated } = this.getEstimatedHeight(node, width, this.rowHeight, this.estimatedRowHeight);
293
266
  let rect = new (0, $9lycG$reactstatelyvirtualizer.Rect)(x, y, width, height);
294
267
  let layoutInfo = new (0, $9lycG$reactstatelyvirtualizer.LayoutInfo)(node.type, node.key, rect);
295
- layoutInfo.isSticky = !this.disableSticky && (((_node_props = node.props) === null || _node_props === void 0 ? void 0 : _node_props.isDragButtonCell) || ((_node_props1 = node.props) === null || _node_props1 === void 0 ? void 0 : _node_props1.isSelectionCell));
268
+ layoutInfo.isSticky = this.isStickyColumn(node);
296
269
  layoutInfo.zIndex = layoutInfo.isSticky ? 2 : 1;
297
270
  layoutInfo.estimatedSize = isEstimated;
298
271
  return {
@@ -304,8 +277,7 @@ class $67c493497dcda343$export$62444c3c724b1b20 extends (0, $fe69e47e38ed0ac4$ex
304
277
  // Adjust rect to keep number of visible rows consistent.
305
278
  // (only if height > 1 for getDropTargetFromPoint)
306
279
  if (rect.height > 1) {
307
- var _this_rowHeight;
308
- let rowHeight = ((_this_rowHeight = this.rowHeight) !== null && _this_rowHeight !== void 0 ? _this_rowHeight : this.estimatedRowHeight) + 1; // +1 for border
280
+ let rowHeight = this.getEstimatedRowHeight();
309
281
  rect.y = Math.floor(rect.y / rowHeight) * rowHeight;
310
282
  rect.height = Math.ceil(rect.height / rowHeight) * rowHeight;
311
283
  }
@@ -407,9 +379,11 @@ class $67c493497dcda343$export$62444c3c724b1b20 extends (0, $fe69e47e38ed0ac4$ex
407
379
  this.persistedIndices.clear();
408
380
  // Build a map of parentKey => indices of children to persist.
409
381
  for (let key of this.virtualizer.persistedKeys){
410
- let layoutInfo = this.layoutInfos.get(key);
382
+ var _this_layoutNodes_get;
383
+ let layoutInfo = (_this_layoutNodes_get = this.layoutNodes.get(key)) === null || _this_layoutNodes_get === void 0 ? void 0 : _this_layoutNodes_get.layoutInfo;
411
384
  // Walk up ancestors so parents are also persisted if children are.
412
385
  while(layoutInfo && layoutInfo.parentKey){
386
+ var _this_layoutNodes_get1;
413
387
  let collectionNode = this.collection.getItem(layoutInfo.key);
414
388
  let indices = this.persistedIndices.get(layoutInfo.parentKey);
415
389
  if (!indices) {
@@ -421,24 +395,11 @@ class $67c493497dcda343$export$62444c3c724b1b20 extends (0, $fe69e47e38ed0ac4$ex
421
395
  }
422
396
  let index = this.layoutNodes.get(layoutInfo.key).index;
423
397
  if (!indices.includes(index)) indices.push(index);
424
- layoutInfo = this.layoutInfos.get(layoutInfo.parentKey);
398
+ layoutInfo = (_this_layoutNodes_get1 = this.layoutNodes.get(layoutInfo.parentKey)) === null || _this_layoutNodes_get1 === void 0 ? void 0 : _this_layoutNodes_get1.layoutInfo;
425
399
  }
426
400
  }
427
401
  for (let indices of this.persistedIndices.values())indices.sort((a, b)=>a - b);
428
402
  }
429
- // Checks if Chrome version is 105 or greater
430
- checkChrome105() {
431
- var _window_navigator_userAgentData;
432
- if (typeof window === 'undefined' || window.navigator == null) return false;
433
- let isChrome105;
434
- if (window.navigator['userAgentData']) isChrome105 = (_window_navigator_userAgentData = window.navigator['userAgentData']) === null || _window_navigator_userAgentData === void 0 ? void 0 : _window_navigator_userAgentData.brands.some((b)=>b.brand === 'Chromium' && Number(b.version) === 105);
435
- else {
436
- let regex = /Chrome\/(\d+)/;
437
- let matches = regex.exec(window.navigator.userAgent);
438
- isChrome105 = matches && matches.length >= 2 && Number(matches[1]) === 105;
439
- }
440
- return isChrome105;
441
- }
442
403
  getDropTargetFromPoint(x, y, isValidDropTarget) {
443
404
  var _this_virtualizer_layout_getVisibleLayoutInfos_find;
444
405
  x += this.virtualizer.visibleRect.x;
@@ -487,12 +448,9 @@ class $67c493497dcda343$export$62444c3c724b1b20 extends (0, $fe69e47e38ed0ac4$ex
487
448
  }
488
449
  constructor(options){
489
450
  super(options);
490
- this.isLoading = false;
491
451
  this.lastPersistedKeys = null;
492
452
  this.persistedIndices = new Map();
493
- this.scrollContainer = options.scrollContainer || 'table';
494
453
  this.stickyColumnIndices = [];
495
- this.disableSticky = this.checkChrome105();
496
454
  }
497
455
  }
498
456