@react-stately/layout 4.3.1 → 4.5.0

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.
@@ -22,15 +22,16 @@ const $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS = {
22
22
  maxItemSize: new (0, $7Tzdl$reactstatelyvirtualizer.Size)(Infinity, Infinity),
23
23
  preserveAspectRatio: false,
24
24
  minSpace: new (0, $7Tzdl$reactstatelyvirtualizer.Size)(18, 18),
25
+ maxSpace: Infinity,
25
26
  maxColumns: Infinity,
26
27
  dropIndicatorThickness: 2
27
28
  };
28
29
  class $1f7773ceb2a3b9a6$export$7d2b12578154a735 extends (0, $7Tzdl$reactstatelyvirtualizer.Layout) {
29
30
  shouldInvalidateLayoutOptions(newOptions, oldOptions) {
30
- return newOptions.maxColumns !== oldOptions.maxColumns || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness || newOptions.preserveAspectRatio !== oldOptions.preserveAspectRatio || !(newOptions.minItemSize || $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.minItemSize) || !(newOptions.maxItemSize || $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.maxItemSize) || !(newOptions.minSpace || $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.minSpace);
31
+ return newOptions.maxColumns !== oldOptions.maxColumns || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness || newOptions.preserveAspectRatio !== oldOptions.preserveAspectRatio || !(newOptions.minItemSize || $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.minItemSize) || !(newOptions.maxItemSize || $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.maxItemSize) || !(newOptions.minSpace || $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.minSpace) || newOptions.maxHorizontalSpace !== oldOptions.maxHorizontalSpace;
31
32
  }
32
33
  update(invalidationContext) {
33
- let { minItemSize: minItemSize = $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.minItemSize, maxItemSize: maxItemSize = $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.maxItemSize, preserveAspectRatio: preserveAspectRatio = $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.preserveAspectRatio, minSpace: minSpace = $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.minSpace, maxColumns: maxColumns = $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.maxColumns, dropIndicatorThickness: dropIndicatorThickness = $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.dropIndicatorThickness } = invalidationContext.layoutOptions || {};
34
+ let { minItemSize: minItemSize = $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.minItemSize, maxItemSize: maxItemSize = $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.maxItemSize, preserveAspectRatio: preserveAspectRatio = $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.preserveAspectRatio, minSpace: minSpace = $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.minSpace, maxHorizontalSpace: maxHorizontalSpace = $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.maxSpace, maxColumns: maxColumns = $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.maxColumns, dropIndicatorThickness: dropIndicatorThickness = $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.dropIndicatorThickness } = invalidationContext.layoutOptions || {};
34
35
  this.dropIndicatorThickness = dropIndicatorThickness;
35
36
  let visibleWidth = this.virtualizer.visibleRect.width;
36
37
  // The max item width is always the entire viewport.
@@ -50,14 +51,24 @@ class $1f7773ceb2a3b9a6$export$7d2b12578154a735 extends (0, $7Tzdl$reactstatelyv
50
51
  let t = (itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width);
51
52
  let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);
52
53
  itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));
53
- // Compute the horizontal spacing and content height
54
- let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));
54
+ // Compute the horizontal spacing, content height and horizontal margin
55
+ let horizontalSpacing = Math.min(Math.max(maxHorizontalSpace, minSpace.width), Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1)));
55
56
  this.gap = new (0, $7Tzdl$reactstatelyvirtualizer.Size)(horizontalSpacing, minSpace.height);
57
+ this.margin = Math.floor((visibleWidth - numColumns * itemWidth - horizontalSpacing * (numColumns + 1)) / 2);
58
+ // If there is a skeleton loader within the last 2 items in the collection, increment the collection size
59
+ // so that an additional row is added for the skeletons.
56
60
  let collection = this.virtualizer.collection;
57
- // Make sure to set rows to 0 if we performing a first time load or are rendering the empty state so that Virtualizer
58
- // won't try to render its body
59
- let isEmptyOrLoading = (collection === null || collection === void 0 ? void 0 : collection.size) === 0 || collection.size === 1 && collection.getItem(collection.getFirstKey()).type === 'loader';
60
- let rows = isEmptyOrLoading ? 0 : Math.ceil(collection.size / numColumns);
61
+ let collectionSize = collection.size;
62
+ let lastKey = collection.getLastKey();
63
+ for(let i = 0; i < 2 && lastKey != null; i++){
64
+ let item = collection.getItem(lastKey);
65
+ if ((item === null || item === void 0 ? void 0 : item.type) === 'skeleton') {
66
+ collectionSize++;
67
+ break;
68
+ }
69
+ lastKey = collection.getKeyBefore(lastKey);
70
+ }
71
+ let rows = Math.ceil(collectionSize / numColumns);
61
72
  let iterator = collection[Symbol.iterator]();
62
73
  let y = rows > 0 ? minSpace.height : 0;
63
74
  let newLayoutInfos = new Map();
@@ -80,7 +91,7 @@ class $1f7773ceb2a3b9a6$export$7d2b12578154a735 extends (0, $7Tzdl$reactstatelyv
80
91
  ...skeleton,
81
92
  key: key
82
93
  };
83
- let x = horizontalSpacing + col * (itemWidth + horizontalSpacing);
94
+ let x = horizontalSpacing + col * (itemWidth + horizontalSpacing) + this.margin;
84
95
  let height = itemHeight;
85
96
  let estimatedSize = !preserveAspectRatio;
86
97
  if (oldLayoutInfo && estimatedSize) {
@@ -213,7 +224,7 @@ class $1f7773ceb2a3b9a6$export$7d2b12578154a735 extends (0, $7Tzdl$reactstatelyv
213
224
  return new (0, $7Tzdl$reactstatelyvirtualizer.LayoutInfo)('dropIndicator', target.key + ':' + target.dropPosition, rect);
214
225
  }
215
226
  constructor(...args){
216
- super(...args), this.gap = $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.minSpace, this.dropIndicatorThickness = 2, this.numColumns = 0, this.contentSize = new (0, $7Tzdl$reactstatelyvirtualizer.Size)(), this.layoutInfos = new Map();
227
+ super(...args), this.gap = $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.minSpace, this.dropIndicatorThickness = 2, this.numColumns = 0, this.contentSize = new (0, $7Tzdl$reactstatelyvirtualizer.Size)(), this.layoutInfos = new Map(), this.margin = 0;
217
228
  }
218
229
  }
219
230
 
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAwCD,MAAM,wCAAkB;IACtB,aAAa,IAAI,CAAA,GAAA,mCAAG,EAAE,KAAK;IAC3B,aAAa,IAAI,CAAA,GAAA,mCAAG,EAAE,UAAU;IAChC,qBAAqB;IACrB,UAAU,IAAI,CAAA,GAAA,mCAAG,EAAE,IAAI;IACvB,YAAY;IACZ,wBAAwB;AAC1B;AAQO,MAAM,kDAAuE,CAAA,GAAA,qCAAK;IAOvF,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kRlD","sources":["packages/@react-stately/layout/src/GridLayout.ts"],"sourcesContent":["/*\n * Copyright 2024 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 {DropTarget, DropTargetDelegate, ItemDropTarget, Key, Node} from '@react-types/shared';\nimport {InvalidationContext, Layout, LayoutInfo, Rect, Size} from '@react-stately/virtualizer';\n\nexport interface GridLayoutOptions {\n /**\n * The minimum item size.\n * @default 200 x 200\n */\n minItemSize?: Size,\n /**\n * The maximum item size.\n * @default Infinity\n */\n maxItemSize?: Size,\n /**\n * Whether to preserve the aspect ratio of the `minItemSize`.\n * By default, grid rows may have variable heights. When `preserveAspectRatio`\n * is true, all rows will have equal heights.\n * @default false\n */\n preserveAspectRatio?: boolean,\n /**\n * The minimum space required between items.\n * @default 18 x 18\n */\n minSpace?: Size,\n /**\n * The maximum number of columns.\n * @default Infinity\n */\n maxColumns?: number,\n /**\n * The thickness of the drop indicator.\n * @default 2\n */\n dropIndicatorThickness?: number\n}\n\nconst DEFAULT_OPTIONS = {\n minItemSize: new Size(200, 200),\n maxItemSize: new Size(Infinity, Infinity),\n preserveAspectRatio: false,\n minSpace: new Size(18, 18),\n maxColumns: Infinity,\n dropIndicatorThickness: 2\n};\n\n/**\n * GridLayout is a virtualizer Layout implementation\n * that arranges its items in a grid.\n * The items are sized between a minimum and maximum size\n * depending on the width of the container.\n */\nexport class GridLayout<T, O extends GridLayoutOptions = GridLayoutOptions> extends Layout<Node<T>, O> implements DropTargetDelegate {\n protected gap: Size = DEFAULT_OPTIONS.minSpace;\n protected dropIndicatorThickness = 2;\n protected numColumns: number = 0;\n private contentSize: Size = new Size();\n private layoutInfos: Map<Key, LayoutInfo> = new Map();\n\n shouldInvalidateLayoutOptions(newOptions: O, oldOptions: O): boolean {\n return newOptions.maxColumns !== oldOptions.maxColumns\n || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness\n || newOptions.preserveAspectRatio !== oldOptions.preserveAspectRatio\n || (!(newOptions.minItemSize || DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || DEFAULT_OPTIONS.minItemSize))\n || (!(newOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize))\n || (!(newOptions.minSpace || DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || DEFAULT_OPTIONS.minSpace));\n }\n\n update(invalidationContext: InvalidationContext<O>): void {\n let {\n minItemSize = DEFAULT_OPTIONS.minItemSize,\n maxItemSize = DEFAULT_OPTIONS.maxItemSize,\n preserveAspectRatio = DEFAULT_OPTIONS.preserveAspectRatio,\n minSpace = DEFAULT_OPTIONS.minSpace,\n maxColumns = DEFAULT_OPTIONS.maxColumns,\n dropIndicatorThickness = DEFAULT_OPTIONS.dropIndicatorThickness\n } = invalidationContext.layoutOptions || {};\n this.dropIndicatorThickness = dropIndicatorThickness;\n\n let visibleWidth = this.virtualizer!.visibleRect.width;\n\n // The max item width is always the entire viewport.\n // If the max item height is infinity, scale in proportion to the max width.\n let maxItemWidth = Math.min(maxItemSize.width, visibleWidth);\n let maxItemHeight = Number.isFinite(maxItemSize.height)\n ? maxItemSize.height\n : Math.floor((minItemSize.height / minItemSize.width) * maxItemWidth);\n\n // Compute the number of rows and columns needed to display the content\n let columns = Math.floor(visibleWidth / (minItemSize.width + minSpace.width));\n let numColumns = Math.max(1, Math.min(maxColumns, columns));\n this.numColumns = numColumns;\n\n // Compute the available width (minus the space between items)\n let width = visibleWidth - (minSpace.width * Math.max(0, numColumns));\n\n // Compute the item width based on the space available\n let itemWidth = Math.floor(width / numColumns);\n itemWidth = Math.max(minItemSize.width, Math.min(maxItemWidth, itemWidth));\n\n // Compute the item height, which is proportional to the item width\n let t = ((itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width));\n let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);\n itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));\n\n // Compute the horizontal spacing and content height\n let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));\n this.gap = new Size(horizontalSpacing, minSpace.height);\n\n let collection = this.virtualizer!.collection;\n // Make sure to set rows to 0 if we performing a first time load or are rendering the empty state so that Virtualizer\n // won't try to render its body\n let isEmptyOrLoading = collection?.size === 0 || (collection.size === 1 && collection.getItem(collection.getFirstKey()!)!.type === 'loader');\n let rows = isEmptyOrLoading ? 0 : Math.ceil(collection.size / numColumns);\n let iterator = collection[Symbol.iterator]();\n let y = rows > 0 ? minSpace.height : 0;\n let newLayoutInfos = new Map();\n let skeleton: Node<T> | null = null;\n let skeletonCount = 0;\n for (let row = 0; row < rows; row++) {\n let maxHeight = 0;\n let rowLayoutInfos: LayoutInfo[] = [];\n for (let col = 0; col < numColumns; col++) {\n // Repeat skeleton until the end of the current row.\n let node = skeleton || iterator.next().value;\n if (!node) {\n break;\n }\n\n // We will add the loader after the skeletons so skip here\n if (node.type === 'loader') {\n continue;\n }\n\n if (node.type === 'skeleton') {\n skeleton = node;\n }\n\n let key = skeleton ? `${skeleton.key}-${skeletonCount++}` : node.key;\n let oldLayoutInfo = this.layoutInfos.get(key);\n let content = node;\n if (skeleton) {\n content = oldLayoutInfo && oldLayoutInfo.content.key === key ? oldLayoutInfo.content : {...skeleton, key};\n }\n let x = horizontalSpacing + col * (itemWidth + horizontalSpacing);\n let height = itemHeight;\n let estimatedSize = !preserveAspectRatio;\n if (oldLayoutInfo && estimatedSize) {\n height = oldLayoutInfo.rect.height;\n estimatedSize = invalidationContext.layoutOptionsChanged || invalidationContext.sizeChanged || oldLayoutInfo.estimatedSize || (oldLayoutInfo.content !== content);\n }\n\n let rect = new Rect(x, y, itemWidth, height);\n let layoutInfo = new LayoutInfo(node.type, key, rect);\n layoutInfo.estimatedSize = estimatedSize;\n layoutInfo.allowOverflow = true;\n layoutInfo.content = content;\n newLayoutInfos.set(key, layoutInfo);\n rowLayoutInfos.push(layoutInfo);\n\n maxHeight = Math.max(maxHeight, layoutInfo.rect.height);\n }\n\n for (let layoutInfo of rowLayoutInfos) {\n layoutInfo.rect.height = maxHeight;\n }\n\n y += maxHeight + minSpace.height;\n\n // Keep adding skeleton rows until we fill the viewport\n if (skeleton && row === rows - 1 && y < this.virtualizer!.visibleRect.height) {\n rows++;\n }\n }\n\n // Always add the loader sentinel if present in the collection so we can make sure it is never virtualized out.\n let lastNode = collection.getItem(collection.getLastKey()!);\n if (lastNode?.type === 'loader') {\n let rect = new Rect(horizontalSpacing, y, itemWidth, 0);\n let layoutInfo = new LayoutInfo('loader', lastNode.key, rect);\n newLayoutInfos.set(lastNode.key, layoutInfo);\n }\n\n this.layoutInfos = newLayoutInfos;\n this.contentSize = new Size(this.virtualizer!.visibleRect.width, y);\n }\n\n getLayoutInfo(key: Key): LayoutInfo | null {\n return this.layoutInfos.get(key) || null;\n }\n\n getContentSize(): Size {\n return this.contentSize;\n }\n\n getVisibleLayoutInfos(rect: Rect): LayoutInfo[] {\n let layoutInfos: LayoutInfo[] = [];\n for (let layoutInfo of this.layoutInfos.values()) {\n if (layoutInfo.rect.intersects(rect) || this.virtualizer!.isPersistedKey(layoutInfo.key) || layoutInfo.type === 'loader') {\n layoutInfos.push(layoutInfo);\n }\n }\n return layoutInfos;\n }\n\n updateItemSize(key: Key, size: Size): boolean {\n let layoutInfo = this.layoutInfos.get(key);\n if (!size || !layoutInfo) {\n return false;\n }\n\n if (size.height !== layoutInfo.rect.height) {\n let newLayoutInfo = layoutInfo.copy();\n newLayoutInfo.rect.height = size.height;\n newLayoutInfo.estimatedSize = false;\n this.layoutInfos.set(key, newLayoutInfo);\n return true;\n }\n\n return false;\n }\n\n getDropTargetFromPoint(x: number, y: number, isValidDropTarget: (target: DropTarget) => boolean): DropTarget {\n if (this.layoutInfos.size === 0) {\n return {type: 'root'};\n }\n\n x += this.virtualizer!.visibleRect.x;\n y += this.virtualizer!.visibleRect.y;\n\n // Find the closest item within on either side of the point using the gap width.\n let key: Key | null = null;\n if (this.numColumns === 1) {\n let searchRect = new Rect(x, Math.max(0, y - this.gap.height), 1, Math.max(1, this.gap.height * 2));\n let candidates = this.getVisibleLayoutInfos(searchRect);\n let minDistance = Infinity;\n for (let candidate of candidates) {\n // Ignore items outside the search rect, e.g. persisted keys.\n if (!candidate.rect.intersects(searchRect)) {\n continue;\n }\n\n let yDist = Math.abs(candidate.rect.y - y);\n let maxYDist = Math.abs(candidate.rect.maxY - y);\n let dist = Math.min(yDist, maxYDist);\n if (dist < minDistance) {\n minDistance = dist;\n key = candidate.key;\n }\n }\n } else {\n let searchRect = new Rect(Math.max(0, x - this.gap.width), y, this.gap.width * 2, 1);\n let candidates = this.getVisibleLayoutInfos(searchRect);\n let minDistance = Infinity;\n for (let candidate of candidates) {\n // Ignore items outside the search rect, e.g. persisted keys.\n if (!candidate.rect.intersects(searchRect)) {\n continue;\n }\n\n let xDist = Math.abs(candidate.rect.x - x);\n let maxXDist = Math.abs(candidate.rect.maxX - x);\n let dist = Math.min(xDist, maxXDist);\n if (dist < minDistance) {\n minDistance = dist;\n key = candidate.key;\n }\n }\n }\n\n let layoutInfo = key != null ? this.getLayoutInfo(key) : null;\n if (!layoutInfo) {\n return {type: 'root'};\n }\n\n let target: DropTarget = {\n type: 'item',\n key: layoutInfo.key,\n dropPosition: 'on'\n };\n\n let pos = this.numColumns === 1 ? y : x;\n let layoutInfoPos = this.numColumns === 1 ? layoutInfo.rect.y : layoutInfo.rect.x;\n let size = this.numColumns === 1 ? layoutInfo.rect.height : layoutInfo.rect.width;\n if (isValidDropTarget(target)) {\n // If dropping on the item is accepted, try the before/after positions\n // if within 5px of the start or end of the item.\n if (pos < layoutInfoPos + 5) {\n target.dropPosition = 'before';\n } else if (pos > layoutInfoPos + size - 5) {\n target.dropPosition = 'after';\n }\n } else {\n // If dropping on the item isn't accepted, try the target before or after depending on the position.\n let mid = layoutInfoPos + size / 2;\n if (pos <= mid && isValidDropTarget({...target, dropPosition: 'before'})) {\n target.dropPosition = 'before';\n } else if (pos >= mid && isValidDropTarget({...target, dropPosition: 'after'})) {\n target.dropPosition = 'after';\n }\n }\n\n return target;\n }\n\n getDropTargetLayoutInfo(target: ItemDropTarget): LayoutInfo {\n let layoutInfo = this.getLayoutInfo(target.key)!;\n let rect: Rect;\n if (this.numColumns === 1) {\n // Flip from vertical to horizontal if only one column is visible.\n rect = new Rect(\n layoutInfo.rect.x,\n target.dropPosition === 'before'\n ? layoutInfo.rect.y - this.gap.height / 2 - this.dropIndicatorThickness / 2\n : layoutInfo.rect.maxY + this.gap.height / 2 - this.dropIndicatorThickness / 2,\n layoutInfo.rect.width,\n this.dropIndicatorThickness\n );\n } else {\n rect = new Rect(\n target.dropPosition === 'before'\n ? layoutInfo.rect.x - this.gap.width / 2 - this.dropIndicatorThickness / 2\n : layoutInfo.rect.maxX + this.gap.width / 2 - this.dropIndicatorThickness / 2,\n layoutInfo.rect.y,\n this.dropIndicatorThickness,\n layoutInfo.rect.height\n );\n }\n\n return new LayoutInfo('dropIndicator', target.key + ':' + target.dropPosition, rect);\n }\n}\n"],"names":[],"version":3,"file":"GridLayout.main.js.map"}
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AA6CD,MAAM,wCAAkB;IACtB,aAAa,IAAI,CAAA,GAAA,mCAAG,EAAE,KAAK;IAC3B,aAAa,IAAI,CAAA,GAAA,mCAAG,EAAE,UAAU;IAChC,qBAAqB;IACrB,UAAU,IAAI,CAAA,GAAA,mCAAG,EAAE,IAAI;IACvB,UAAU;IACV,YAAY;IACZ,wBAAwB;AAC1B;AAQO,MAAM,kDAAuE,CAAA,GAAA,qCAAK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AI,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,IAAI,CAAC,sBAAsB,GAAG,GAC9E,WAAW,IAAI,CAAC,CAAC,EACjB,IAAI,CAAC,sBAAsB,EAC3B,WAAW,IAAI,CAAC,MAAM;QAI1B,OAAO,IAAI,CAAA,GAAA,yCAAS,EAAE,iBAAiB,OAAO,GAAG,GAAG,MAAM,OAAO,YAAY,EAAE;IACjF;;QApSK,qBACK,MAAY,sCAAgB,QAAQ,OACpC,yBAAyB,QACzB,aAAqB,QACvB,cAAoB,IAAI,CAAA,GAAA,mCAAG,UAC3B,cAAoC,IAAI,YACxC,SAAiB;;AA+R3B","sources":["packages/@react-stately/layout/src/GridLayout.ts"],"sourcesContent":["/*\n * Copyright 2024 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 {DropTarget, DropTargetDelegate, ItemDropTarget, Key, Node} from '@react-types/shared';\nimport {InvalidationContext, Layout, LayoutInfo, Rect, Size} from '@react-stately/virtualizer';\n\nexport interface GridLayoutOptions {\n /**\n * The minimum item size.\n * @default 200 x 200\n */\n minItemSize?: Size,\n /**\n * The maximum item size.\n * @default Infinity\n */\n maxItemSize?: Size,\n /**\n * Whether to preserve the aspect ratio of the `minItemSize`.\n * By default, grid rows may have variable heights. When `preserveAspectRatio`\n * is true, all rows will have equal heights.\n * @default false\n */\n preserveAspectRatio?: boolean,\n /**\n * The minimum space required between items.\n * @default 18 x 18\n */\n minSpace?: Size,\n /**\n * The maximum allowed horizontal space between items.\n * @default Infinity\n */\n maxHorizontalSpace?: number,\n /**\n * The maximum number of columns.\n * @default Infinity\n */\n maxColumns?: number,\n /**\n * The thickness of the drop indicator.\n * @default 2\n */\n dropIndicatorThickness?: number\n}\n\nconst DEFAULT_OPTIONS = {\n minItemSize: new Size(200, 200),\n maxItemSize: new Size(Infinity, Infinity),\n preserveAspectRatio: false,\n minSpace: new Size(18, 18),\n maxSpace: Infinity,\n maxColumns: Infinity,\n dropIndicatorThickness: 2\n};\n\n/**\n * GridLayout is a virtualizer Layout implementation\n * that arranges its items in a grid.\n * The items are sized between a minimum and maximum size\n * depending on the width of the container.\n */\nexport class GridLayout<T, O extends GridLayoutOptions = GridLayoutOptions> extends Layout<Node<T>, O> implements DropTargetDelegate {\n protected gap: Size = DEFAULT_OPTIONS.minSpace;\n protected dropIndicatorThickness = 2;\n protected numColumns: number = 0;\n private contentSize: Size = new Size();\n private layoutInfos: Map<Key, LayoutInfo> = new Map();\n private margin: number = 0;\n\n shouldInvalidateLayoutOptions(newOptions: O, oldOptions: O): boolean {\n return newOptions.maxColumns !== oldOptions.maxColumns\n || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness\n || newOptions.preserveAspectRatio !== oldOptions.preserveAspectRatio\n || (!(newOptions.minItemSize || DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || DEFAULT_OPTIONS.minItemSize))\n || (!(newOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize))\n || (!(newOptions.minSpace || DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || DEFAULT_OPTIONS.minSpace))\n || newOptions.maxHorizontalSpace !== oldOptions.maxHorizontalSpace;\n }\n\n update(invalidationContext: InvalidationContext<O>): void {\n let {\n minItemSize = DEFAULT_OPTIONS.minItemSize,\n maxItemSize = DEFAULT_OPTIONS.maxItemSize,\n preserveAspectRatio = DEFAULT_OPTIONS.preserveAspectRatio,\n minSpace = DEFAULT_OPTIONS.minSpace,\n maxHorizontalSpace = DEFAULT_OPTIONS.maxSpace,\n maxColumns = DEFAULT_OPTIONS.maxColumns,\n dropIndicatorThickness = DEFAULT_OPTIONS.dropIndicatorThickness\n } = invalidationContext.layoutOptions || {};\n this.dropIndicatorThickness = dropIndicatorThickness;\n\n let visibleWidth = this.virtualizer!.visibleRect.width;\n\n // The max item width is always the entire viewport.\n // If the max item height is infinity, scale in proportion to the max width.\n let maxItemWidth = Math.min(maxItemSize.width, visibleWidth);\n let maxItemHeight = Number.isFinite(maxItemSize.height)\n ? maxItemSize.height\n : Math.floor((minItemSize.height / minItemSize.width) * maxItemWidth);\n\n // Compute the number of rows and columns needed to display the content\n let columns = Math.floor(visibleWidth / (minItemSize.width + minSpace.width));\n let numColumns = Math.max(1, Math.min(maxColumns, columns));\n this.numColumns = numColumns;\n\n // Compute the available width (minus the space between items)\n let width = visibleWidth - (minSpace.width * Math.max(0, numColumns));\n\n // Compute the item width based on the space available\n let itemWidth = Math.floor(width / numColumns);\n itemWidth = Math.max(minItemSize.width, Math.min(maxItemWidth, itemWidth));\n\n // Compute the item height, which is proportional to the item width\n let t = ((itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width));\n let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);\n itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));\n\n // Compute the horizontal spacing, content height and horizontal margin\n let horizontalSpacing = Math.min(Math.max(maxHorizontalSpace, minSpace.width), Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1)));\n this.gap = new Size(horizontalSpacing, minSpace.height);\n this.margin = Math.floor((visibleWidth - numColumns * itemWidth - horizontalSpacing * (numColumns + 1)) / 2);\n\n // If there is a skeleton loader within the last 2 items in the collection, increment the collection size\n // so that an additional row is added for the skeletons.\n let collection = this.virtualizer!.collection;\n let collectionSize = collection.size;\n let lastKey = collection.getLastKey();\n for (let i = 0; i < 2 && lastKey != null; i++) {\n let item = collection.getItem(lastKey);\n if (item?.type === 'skeleton') {\n collectionSize++;\n break;\n }\n lastKey = collection.getKeyBefore(lastKey);\n }\n\n let rows = Math.ceil(collectionSize / numColumns);\n let iterator = collection[Symbol.iterator]();\n let y = rows > 0 ? minSpace.height : 0;\n let newLayoutInfos = new Map();\n let skeleton: Node<T> | null = null;\n let skeletonCount = 0;\n for (let row = 0; row < rows; row++) {\n let maxHeight = 0;\n let rowLayoutInfos: LayoutInfo[] = [];\n for (let col = 0; col < numColumns; col++) {\n // Repeat skeleton until the end of the current row.\n let node = skeleton || iterator.next().value;\n if (!node) {\n break;\n }\n\n // We will add the loader after the skeletons so skip here\n if (node.type === 'loader') {\n continue;\n }\n\n if (node.type === 'skeleton') {\n skeleton = node;\n }\n\n let key = skeleton ? `${skeleton.key}-${skeletonCount++}` : node.key;\n let oldLayoutInfo = this.layoutInfos.get(key);\n let content = node;\n if (skeleton) {\n content = oldLayoutInfo && oldLayoutInfo.content.key === key ? oldLayoutInfo.content : {...skeleton, key};\n }\n let x = horizontalSpacing + col * (itemWidth + horizontalSpacing) + this.margin;\n let height = itemHeight;\n let estimatedSize = !preserveAspectRatio;\n if (oldLayoutInfo && estimatedSize) {\n height = oldLayoutInfo.rect.height;\n estimatedSize = invalidationContext.layoutOptionsChanged || invalidationContext.sizeChanged || oldLayoutInfo.estimatedSize || (oldLayoutInfo.content !== content);\n }\n\n let rect = new Rect(x, y, itemWidth, height);\n let layoutInfo = new LayoutInfo(node.type, key, rect);\n layoutInfo.estimatedSize = estimatedSize;\n layoutInfo.allowOverflow = true;\n layoutInfo.content = content;\n newLayoutInfos.set(key, layoutInfo);\n rowLayoutInfos.push(layoutInfo);\n\n maxHeight = Math.max(maxHeight, layoutInfo.rect.height);\n }\n\n for (let layoutInfo of rowLayoutInfos) {\n layoutInfo.rect.height = maxHeight;\n }\n\n y += maxHeight + minSpace.height;\n\n // Keep adding skeleton rows until we fill the viewport\n if (skeleton && row === rows - 1 && y < this.virtualizer!.visibleRect.height) {\n rows++;\n }\n }\n\n // Always add the loader sentinel if present in the collection so we can make sure it is never virtualized out.\n let lastNode = collection.getItem(collection.getLastKey()!);\n if (lastNode?.type === 'loader') {\n let rect = new Rect(horizontalSpacing, y, itemWidth, 0);\n let layoutInfo = new LayoutInfo('loader', lastNode.key, rect);\n newLayoutInfos.set(lastNode.key, layoutInfo);\n }\n\n this.layoutInfos = newLayoutInfos;\n this.contentSize = new Size(this.virtualizer!.visibleRect.width, y);\n }\n\n getLayoutInfo(key: Key): LayoutInfo | null {\n return this.layoutInfos.get(key) || null;\n }\n\n getContentSize(): Size {\n return this.contentSize;\n }\n\n getVisibleLayoutInfos(rect: Rect): LayoutInfo[] {\n let layoutInfos: LayoutInfo[] = [];\n for (let layoutInfo of this.layoutInfos.values()) {\n if (layoutInfo.rect.intersects(rect) || this.virtualizer!.isPersistedKey(layoutInfo.key) || layoutInfo.type === 'loader') {\n layoutInfos.push(layoutInfo);\n }\n }\n return layoutInfos;\n }\n\n updateItemSize(key: Key, size: Size): boolean {\n let layoutInfo = this.layoutInfos.get(key);\n if (!size || !layoutInfo) {\n return false;\n }\n\n if (size.height !== layoutInfo.rect.height) {\n let newLayoutInfo = layoutInfo.copy();\n newLayoutInfo.rect.height = size.height;\n newLayoutInfo.estimatedSize = false;\n this.layoutInfos.set(key, newLayoutInfo);\n return true;\n }\n\n return false;\n }\n\n getDropTargetFromPoint(x: number, y: number, isValidDropTarget: (target: DropTarget) => boolean): DropTarget {\n if (this.layoutInfos.size === 0) {\n return {type: 'root'};\n }\n\n x += this.virtualizer!.visibleRect.x;\n y += this.virtualizer!.visibleRect.y;\n\n // Find the closest item within on either side of the point using the gap width.\n let key: Key | null = null;\n if (this.numColumns === 1) {\n let searchRect = new Rect(x, Math.max(0, y - this.gap.height), 1, Math.max(1, this.gap.height * 2));\n let candidates = this.getVisibleLayoutInfos(searchRect);\n let minDistance = Infinity;\n for (let candidate of candidates) {\n // Ignore items outside the search rect, e.g. persisted keys.\n if (!candidate.rect.intersects(searchRect)) {\n continue;\n }\n\n let yDist = Math.abs(candidate.rect.y - y);\n let maxYDist = Math.abs(candidate.rect.maxY - y);\n let dist = Math.min(yDist, maxYDist);\n if (dist < minDistance) {\n minDistance = dist;\n key = candidate.key;\n }\n }\n } else {\n let searchRect = new Rect(Math.max(0, x - this.gap.width), y, this.gap.width * 2, 1);\n let candidates = this.getVisibleLayoutInfos(searchRect);\n let minDistance = Infinity;\n for (let candidate of candidates) {\n // Ignore items outside the search rect, e.g. persisted keys.\n if (!candidate.rect.intersects(searchRect)) {\n continue;\n }\n\n let xDist = Math.abs(candidate.rect.x - x);\n let maxXDist = Math.abs(candidate.rect.maxX - x);\n let dist = Math.min(xDist, maxXDist);\n if (dist < minDistance) {\n minDistance = dist;\n key = candidate.key;\n }\n }\n }\n\n let layoutInfo = key != null ? this.getLayoutInfo(key) : null;\n if (!layoutInfo) {\n return {type: 'root'};\n }\n\n let target: DropTarget = {\n type: 'item',\n key: layoutInfo.key,\n dropPosition: 'on'\n };\n\n let pos = this.numColumns === 1 ? y : x;\n let layoutInfoPos = this.numColumns === 1 ? layoutInfo.rect.y : layoutInfo.rect.x;\n let size = this.numColumns === 1 ? layoutInfo.rect.height : layoutInfo.rect.width;\n if (isValidDropTarget(target)) {\n // If dropping on the item is accepted, try the before/after positions\n // if within 5px of the start or end of the item.\n if (pos < layoutInfoPos + 5) {\n target.dropPosition = 'before';\n } else if (pos > layoutInfoPos + size - 5) {\n target.dropPosition = 'after';\n }\n } else {\n // If dropping on the item isn't accepted, try the target before or after depending on the position.\n let mid = layoutInfoPos + size / 2;\n if (pos <= mid && isValidDropTarget({...target, dropPosition: 'before'})) {\n target.dropPosition = 'before';\n } else if (pos >= mid && isValidDropTarget({...target, dropPosition: 'after'})) {\n target.dropPosition = 'after';\n }\n }\n\n return target;\n }\n\n getDropTargetLayoutInfo(target: ItemDropTarget): LayoutInfo {\n let layoutInfo = this.getLayoutInfo(target.key)!;\n let rect: Rect;\n if (this.numColumns === 1) {\n // Flip from vertical to horizontal if only one column is visible.\n rect = new Rect(\n layoutInfo.rect.x,\n target.dropPosition === 'before'\n ? layoutInfo.rect.y - this.gap.height / 2 - this.dropIndicatorThickness / 2\n : layoutInfo.rect.maxY + this.gap.height / 2 - this.dropIndicatorThickness / 2,\n layoutInfo.rect.width,\n this.dropIndicatorThickness\n );\n } else {\n rect = new Rect(\n target.dropPosition === 'before'\n ? layoutInfo.rect.x - this.gap.width / 2 - this.dropIndicatorThickness / 2\n : layoutInfo.rect.maxX + this.gap.width / 2 - this.dropIndicatorThickness / 2,\n layoutInfo.rect.y,\n this.dropIndicatorThickness,\n layoutInfo.rect.height\n );\n }\n\n return new LayoutInfo('dropIndicator', target.key + ':' + target.dropPosition, rect);\n }\n}\n"],"names":[],"version":3,"file":"GridLayout.main.js.map"}
@@ -16,15 +16,16 @@ const $a58592d295a170a4$var$DEFAULT_OPTIONS = {
16
16
  maxItemSize: new (0, $ipgKF$Size)(Infinity, Infinity),
17
17
  preserveAspectRatio: false,
18
18
  minSpace: new (0, $ipgKF$Size)(18, 18),
19
+ maxSpace: Infinity,
19
20
  maxColumns: Infinity,
20
21
  dropIndicatorThickness: 2
21
22
  };
22
23
  class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
23
24
  shouldInvalidateLayoutOptions(newOptions, oldOptions) {
24
- return newOptions.maxColumns !== oldOptions.maxColumns || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness || newOptions.preserveAspectRatio !== oldOptions.preserveAspectRatio || !(newOptions.minItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.minItemSize) || !(newOptions.maxItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.maxItemSize) || !(newOptions.minSpace || $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace);
25
+ return newOptions.maxColumns !== oldOptions.maxColumns || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness || newOptions.preserveAspectRatio !== oldOptions.preserveAspectRatio || !(newOptions.minItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.minItemSize) || !(newOptions.maxItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.maxItemSize) || !(newOptions.minSpace || $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace) || newOptions.maxHorizontalSpace !== oldOptions.maxHorizontalSpace;
25
26
  }
26
27
  update(invalidationContext) {
27
- let { minItemSize: minItemSize = $a58592d295a170a4$var$DEFAULT_OPTIONS.minItemSize, maxItemSize: maxItemSize = $a58592d295a170a4$var$DEFAULT_OPTIONS.maxItemSize, preserveAspectRatio: preserveAspectRatio = $a58592d295a170a4$var$DEFAULT_OPTIONS.preserveAspectRatio, minSpace: minSpace = $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace, maxColumns: maxColumns = $a58592d295a170a4$var$DEFAULT_OPTIONS.maxColumns, dropIndicatorThickness: dropIndicatorThickness = $a58592d295a170a4$var$DEFAULT_OPTIONS.dropIndicatorThickness } = invalidationContext.layoutOptions || {};
28
+ let { minItemSize: minItemSize = $a58592d295a170a4$var$DEFAULT_OPTIONS.minItemSize, maxItemSize: maxItemSize = $a58592d295a170a4$var$DEFAULT_OPTIONS.maxItemSize, preserveAspectRatio: preserveAspectRatio = $a58592d295a170a4$var$DEFAULT_OPTIONS.preserveAspectRatio, minSpace: minSpace = $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace, maxHorizontalSpace: maxHorizontalSpace = $a58592d295a170a4$var$DEFAULT_OPTIONS.maxSpace, maxColumns: maxColumns = $a58592d295a170a4$var$DEFAULT_OPTIONS.maxColumns, dropIndicatorThickness: dropIndicatorThickness = $a58592d295a170a4$var$DEFAULT_OPTIONS.dropIndicatorThickness } = invalidationContext.layoutOptions || {};
28
29
  this.dropIndicatorThickness = dropIndicatorThickness;
29
30
  let visibleWidth = this.virtualizer.visibleRect.width;
30
31
  // The max item width is always the entire viewport.
@@ -44,14 +45,24 @@ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
44
45
  let t = (itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width);
45
46
  let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);
46
47
  itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));
47
- // Compute the horizontal spacing and content height
48
- let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));
48
+ // Compute the horizontal spacing, content height and horizontal margin
49
+ let horizontalSpacing = Math.min(Math.max(maxHorizontalSpace, minSpace.width), Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1)));
49
50
  this.gap = new (0, $ipgKF$Size)(horizontalSpacing, minSpace.height);
51
+ this.margin = Math.floor((visibleWidth - numColumns * itemWidth - horizontalSpacing * (numColumns + 1)) / 2);
52
+ // If there is a skeleton loader within the last 2 items in the collection, increment the collection size
53
+ // so that an additional row is added for the skeletons.
50
54
  let collection = this.virtualizer.collection;
51
- // Make sure to set rows to 0 if we performing a first time load or are rendering the empty state so that Virtualizer
52
- // won't try to render its body
53
- let isEmptyOrLoading = (collection === null || collection === void 0 ? void 0 : collection.size) === 0 || collection.size === 1 && collection.getItem(collection.getFirstKey()).type === 'loader';
54
- let rows = isEmptyOrLoading ? 0 : Math.ceil(collection.size / numColumns);
55
+ let collectionSize = collection.size;
56
+ let lastKey = collection.getLastKey();
57
+ for(let i = 0; i < 2 && lastKey != null; i++){
58
+ let item = collection.getItem(lastKey);
59
+ if ((item === null || item === void 0 ? void 0 : item.type) === 'skeleton') {
60
+ collectionSize++;
61
+ break;
62
+ }
63
+ lastKey = collection.getKeyBefore(lastKey);
64
+ }
65
+ let rows = Math.ceil(collectionSize / numColumns);
55
66
  let iterator = collection[Symbol.iterator]();
56
67
  let y = rows > 0 ? minSpace.height : 0;
57
68
  let newLayoutInfos = new Map();
@@ -74,7 +85,7 @@ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
74
85
  ...skeleton,
75
86
  key: key
76
87
  };
77
- let x = horizontalSpacing + col * (itemWidth + horizontalSpacing);
88
+ let x = horizontalSpacing + col * (itemWidth + horizontalSpacing) + this.margin;
78
89
  let height = itemHeight;
79
90
  let estimatedSize = !preserveAspectRatio;
80
91
  if (oldLayoutInfo && estimatedSize) {
@@ -207,7 +218,7 @@ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
207
218
  return new (0, $ipgKF$LayoutInfo)('dropIndicator', target.key + ':' + target.dropPosition, rect);
208
219
  }
209
220
  constructor(...args){
210
- super(...args), this.gap = $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace, this.dropIndicatorThickness = 2, this.numColumns = 0, this.contentSize = new (0, $ipgKF$Size)(), this.layoutInfos = new Map();
221
+ super(...args), this.gap = $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace, this.dropIndicatorThickness = 2, this.numColumns = 0, this.contentSize = new (0, $ipgKF$Size)(), this.layoutInfos = new Map(), this.margin = 0;
211
222
  }
212
223
  }
213
224
 
@@ -16,15 +16,16 @@ const $a58592d295a170a4$var$DEFAULT_OPTIONS = {
16
16
  maxItemSize: new (0, $ipgKF$Size)(Infinity, Infinity),
17
17
  preserveAspectRatio: false,
18
18
  minSpace: new (0, $ipgKF$Size)(18, 18),
19
+ maxSpace: Infinity,
19
20
  maxColumns: Infinity,
20
21
  dropIndicatorThickness: 2
21
22
  };
22
23
  class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
23
24
  shouldInvalidateLayoutOptions(newOptions, oldOptions) {
24
- return newOptions.maxColumns !== oldOptions.maxColumns || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness || newOptions.preserveAspectRatio !== oldOptions.preserveAspectRatio || !(newOptions.minItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.minItemSize) || !(newOptions.maxItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.maxItemSize) || !(newOptions.minSpace || $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace);
25
+ return newOptions.maxColumns !== oldOptions.maxColumns || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness || newOptions.preserveAspectRatio !== oldOptions.preserveAspectRatio || !(newOptions.minItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.minItemSize) || !(newOptions.maxItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.maxItemSize) || !(newOptions.minSpace || $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace) || newOptions.maxHorizontalSpace !== oldOptions.maxHorizontalSpace;
25
26
  }
26
27
  update(invalidationContext) {
27
- let { minItemSize: minItemSize = $a58592d295a170a4$var$DEFAULT_OPTIONS.minItemSize, maxItemSize: maxItemSize = $a58592d295a170a4$var$DEFAULT_OPTIONS.maxItemSize, preserveAspectRatio: preserveAspectRatio = $a58592d295a170a4$var$DEFAULT_OPTIONS.preserveAspectRatio, minSpace: minSpace = $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace, maxColumns: maxColumns = $a58592d295a170a4$var$DEFAULT_OPTIONS.maxColumns, dropIndicatorThickness: dropIndicatorThickness = $a58592d295a170a4$var$DEFAULT_OPTIONS.dropIndicatorThickness } = invalidationContext.layoutOptions || {};
28
+ let { minItemSize: minItemSize = $a58592d295a170a4$var$DEFAULT_OPTIONS.minItemSize, maxItemSize: maxItemSize = $a58592d295a170a4$var$DEFAULT_OPTIONS.maxItemSize, preserveAspectRatio: preserveAspectRatio = $a58592d295a170a4$var$DEFAULT_OPTIONS.preserveAspectRatio, minSpace: minSpace = $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace, maxHorizontalSpace: maxHorizontalSpace = $a58592d295a170a4$var$DEFAULT_OPTIONS.maxSpace, maxColumns: maxColumns = $a58592d295a170a4$var$DEFAULT_OPTIONS.maxColumns, dropIndicatorThickness: dropIndicatorThickness = $a58592d295a170a4$var$DEFAULT_OPTIONS.dropIndicatorThickness } = invalidationContext.layoutOptions || {};
28
29
  this.dropIndicatorThickness = dropIndicatorThickness;
29
30
  let visibleWidth = this.virtualizer.visibleRect.width;
30
31
  // The max item width is always the entire viewport.
@@ -44,14 +45,24 @@ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
44
45
  let t = (itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width);
45
46
  let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);
46
47
  itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));
47
- // Compute the horizontal spacing and content height
48
- let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));
48
+ // Compute the horizontal spacing, content height and horizontal margin
49
+ let horizontalSpacing = Math.min(Math.max(maxHorizontalSpace, minSpace.width), Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1)));
49
50
  this.gap = new (0, $ipgKF$Size)(horizontalSpacing, minSpace.height);
51
+ this.margin = Math.floor((visibleWidth - numColumns * itemWidth - horizontalSpacing * (numColumns + 1)) / 2);
52
+ // If there is a skeleton loader within the last 2 items in the collection, increment the collection size
53
+ // so that an additional row is added for the skeletons.
50
54
  let collection = this.virtualizer.collection;
51
- // Make sure to set rows to 0 if we performing a first time load or are rendering the empty state so that Virtualizer
52
- // won't try to render its body
53
- let isEmptyOrLoading = (collection === null || collection === void 0 ? void 0 : collection.size) === 0 || collection.size === 1 && collection.getItem(collection.getFirstKey()).type === 'loader';
54
- let rows = isEmptyOrLoading ? 0 : Math.ceil(collection.size / numColumns);
55
+ let collectionSize = collection.size;
56
+ let lastKey = collection.getLastKey();
57
+ for(let i = 0; i < 2 && lastKey != null; i++){
58
+ let item = collection.getItem(lastKey);
59
+ if ((item === null || item === void 0 ? void 0 : item.type) === 'skeleton') {
60
+ collectionSize++;
61
+ break;
62
+ }
63
+ lastKey = collection.getKeyBefore(lastKey);
64
+ }
65
+ let rows = Math.ceil(collectionSize / numColumns);
55
66
  let iterator = collection[Symbol.iterator]();
56
67
  let y = rows > 0 ? minSpace.height : 0;
57
68
  let newLayoutInfos = new Map();
@@ -74,7 +85,7 @@ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
74
85
  ...skeleton,
75
86
  key: key
76
87
  };
77
- let x = horizontalSpacing + col * (itemWidth + horizontalSpacing);
88
+ let x = horizontalSpacing + col * (itemWidth + horizontalSpacing) + this.margin;
78
89
  let height = itemHeight;
79
90
  let estimatedSize = !preserveAspectRatio;
80
91
  if (oldLayoutInfo && estimatedSize) {
@@ -207,7 +218,7 @@ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
207
218
  return new (0, $ipgKF$LayoutInfo)('dropIndicator', target.key + ':' + target.dropPosition, rect);
208
219
  }
209
220
  constructor(...args){
210
- super(...args), this.gap = $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace, this.dropIndicatorThickness = 2, this.numColumns = 0, this.contentSize = new (0, $ipgKF$Size)(), this.layoutInfos = new Map();
221
+ super(...args), this.gap = $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace, this.dropIndicatorThickness = 2, this.numColumns = 0, this.contentSize = new (0, $ipgKF$Size)(), this.layoutInfos = new Map(), this.margin = 0;
211
222
  }
212
223
  }
213
224
 
@@ -1 +1 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC;AAwCD,MAAM,wCAAkB;IACtB,aAAa,IAAI,CAAA,GAAA,WAAG,EAAE,KAAK;IAC3B,aAAa,IAAI,CAAA,GAAA,WAAG,EAAE,UAAU;IAChC,qBAAqB;IACrB,UAAU,IAAI,CAAA,GAAA,WAAG,EAAE,IAAI;IACvB,YAAY;IACZ,wBAAwB;AAC1B;AAQO,MAAM,kDAAuE,CAAA,GAAA,aAAK;IAOvF,8BAA8B,UAAa,EAAE,UAAa,EAAW;QACnE,OAAO,WAAW,UAAU,KAAK,WAAW,UAAU,IACjD,WAAW,sBAAsB,KAAK,WAAW,sBAAsB,IACvE,WAAW,mBAAmB,KAAK,WAAW,mBAAmB,IAChE,CAAC,AAAC,CAAA,WAAW,WAAW,IAAI,sCAAgB,WAAW,AAAD,EAAG,MAAM,CAAC,WAAW,WAAW,IAAI,sCAAgB,WAAW,KACrH,CAAC,AAAC,CAAA,WAAW,WAAW,IAAI,sCAAgB,WAAW,AAAD,EAAG,MAAM,CAAC,WAAW,WAAW,IAAI,sCAAgB,WAAW,KACrH,CAAC,AAAC,CAAA,WAAW,QAAQ,IAAI,sCAAgB,QAAQ,AAAD,EAAG,MAAM,CAAC,WAAW,QAAQ,IAAI,sCAAgB,QAAQ;IACjH;IAEA,OAAO,mBAA2C,EAAQ;QACxD,IAAI,eACF,cAAc,sCAAgB,WAAW,eACzC,cAAc,sCAAgB,WAAW,uBACzC,sBAAsB,sCAAgB,mBAAmB,YACzD,WAAW,sCAAgB,QAAQ,cACnC,aAAa,sCAAgB,UAAU,0BACvC,yBAAyB,sCAAgB,sBAAsB,EAChE,GAAG,oBAAoB,aAAa,IAA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AG,CAAC,KAAK,GAAG,IAAI,IAAI,CAAC,sBAAsB,GAAG,IACvE,WAAW,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,IAAI,CAAC,sBAAsB,GAAG,GAC9E,WAAW,IAAI,CAAC,CAAC,EACjB,IAAI,CAAC,sBAAsB,EAC3B,WAAW,IAAI,CAAC,MAAM;QAI1B,OAAO,IAAI,CAAA,GAAA,iBAAS,EAAE,iBAAiB,OAAO,GAAG,GAAG,MAAM,OAAO,YAAY,EAAE;IACjF;;QAtRK,qBACK,MAAY,sCAAgB,QAAQ,OACpC,yBAAyB,QACzB,aAAqB,QACvB,cAAoB,IAAI,CAAA,GAAA,WAAG,UAC3B,cAAoC,IAAI;;AAkRlD","sources":["packages/@react-stately/layout/src/GridLayout.ts"],"sourcesContent":["/*\n * Copyright 2024 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 {DropTarget, DropTargetDelegate, ItemDropTarget, Key, Node} from '@react-types/shared';\nimport {InvalidationContext, Layout, LayoutInfo, Rect, Size} from '@react-stately/virtualizer';\n\nexport interface GridLayoutOptions {\n /**\n * The minimum item size.\n * @default 200 x 200\n */\n minItemSize?: Size,\n /**\n * The maximum item size.\n * @default Infinity\n */\n maxItemSize?: Size,\n /**\n * Whether to preserve the aspect ratio of the `minItemSize`.\n * By default, grid rows may have variable heights. When `preserveAspectRatio`\n * is true, all rows will have equal heights.\n * @default false\n */\n preserveAspectRatio?: boolean,\n /**\n * The minimum space required between items.\n * @default 18 x 18\n */\n minSpace?: Size,\n /**\n * The maximum number of columns.\n * @default Infinity\n */\n maxColumns?: number,\n /**\n * The thickness of the drop indicator.\n * @default 2\n */\n dropIndicatorThickness?: number\n}\n\nconst DEFAULT_OPTIONS = {\n minItemSize: new Size(200, 200),\n maxItemSize: new Size(Infinity, Infinity),\n preserveAspectRatio: false,\n minSpace: new Size(18, 18),\n maxColumns: Infinity,\n dropIndicatorThickness: 2\n};\n\n/**\n * GridLayout is a virtualizer Layout implementation\n * that arranges its items in a grid.\n * The items are sized between a minimum and maximum size\n * depending on the width of the container.\n */\nexport class GridLayout<T, O extends GridLayoutOptions = GridLayoutOptions> extends Layout<Node<T>, O> implements DropTargetDelegate {\n protected gap: Size = DEFAULT_OPTIONS.minSpace;\n protected dropIndicatorThickness = 2;\n protected numColumns: number = 0;\n private contentSize: Size = new Size();\n private layoutInfos: Map<Key, LayoutInfo> = new Map();\n\n shouldInvalidateLayoutOptions(newOptions: O, oldOptions: O): boolean {\n return newOptions.maxColumns !== oldOptions.maxColumns\n || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness\n || newOptions.preserveAspectRatio !== oldOptions.preserveAspectRatio\n || (!(newOptions.minItemSize || DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || DEFAULT_OPTIONS.minItemSize))\n || (!(newOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize))\n || (!(newOptions.minSpace || DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || DEFAULT_OPTIONS.minSpace));\n }\n\n update(invalidationContext: InvalidationContext<O>): void {\n let {\n minItemSize = DEFAULT_OPTIONS.minItemSize,\n maxItemSize = DEFAULT_OPTIONS.maxItemSize,\n preserveAspectRatio = DEFAULT_OPTIONS.preserveAspectRatio,\n minSpace = DEFAULT_OPTIONS.minSpace,\n maxColumns = DEFAULT_OPTIONS.maxColumns,\n dropIndicatorThickness = DEFAULT_OPTIONS.dropIndicatorThickness\n } = invalidationContext.layoutOptions || {};\n this.dropIndicatorThickness = dropIndicatorThickness;\n\n let visibleWidth = this.virtualizer!.visibleRect.width;\n\n // The max item width is always the entire viewport.\n // If the max item height is infinity, scale in proportion to the max width.\n let maxItemWidth = Math.min(maxItemSize.width, visibleWidth);\n let maxItemHeight = Number.isFinite(maxItemSize.height)\n ? maxItemSize.height\n : Math.floor((minItemSize.height / minItemSize.width) * maxItemWidth);\n\n // Compute the number of rows and columns needed to display the content\n let columns = Math.floor(visibleWidth / (minItemSize.width + minSpace.width));\n let numColumns = Math.max(1, Math.min(maxColumns, columns));\n this.numColumns = numColumns;\n\n // Compute the available width (minus the space between items)\n let width = visibleWidth - (minSpace.width * Math.max(0, numColumns));\n\n // Compute the item width based on the space available\n let itemWidth = Math.floor(width / numColumns);\n itemWidth = Math.max(minItemSize.width, Math.min(maxItemWidth, itemWidth));\n\n // Compute the item height, which is proportional to the item width\n let t = ((itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width));\n let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);\n itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));\n\n // Compute the horizontal spacing and content height\n let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));\n this.gap = new Size(horizontalSpacing, minSpace.height);\n\n let collection = this.virtualizer!.collection;\n // Make sure to set rows to 0 if we performing a first time load or are rendering the empty state so that Virtualizer\n // won't try to render its body\n let isEmptyOrLoading = collection?.size === 0 || (collection.size === 1 && collection.getItem(collection.getFirstKey()!)!.type === 'loader');\n let rows = isEmptyOrLoading ? 0 : Math.ceil(collection.size / numColumns);\n let iterator = collection[Symbol.iterator]();\n let y = rows > 0 ? minSpace.height : 0;\n let newLayoutInfos = new Map();\n let skeleton: Node<T> | null = null;\n let skeletonCount = 0;\n for (let row = 0; row < rows; row++) {\n let maxHeight = 0;\n let rowLayoutInfos: LayoutInfo[] = [];\n for (let col = 0; col < numColumns; col++) {\n // Repeat skeleton until the end of the current row.\n let node = skeleton || iterator.next().value;\n if (!node) {\n break;\n }\n\n // We will add the loader after the skeletons so skip here\n if (node.type === 'loader') {\n continue;\n }\n\n if (node.type === 'skeleton') {\n skeleton = node;\n }\n\n let key = skeleton ? `${skeleton.key}-${skeletonCount++}` : node.key;\n let oldLayoutInfo = this.layoutInfos.get(key);\n let content = node;\n if (skeleton) {\n content = oldLayoutInfo && oldLayoutInfo.content.key === key ? oldLayoutInfo.content : {...skeleton, key};\n }\n let x = horizontalSpacing + col * (itemWidth + horizontalSpacing);\n let height = itemHeight;\n let estimatedSize = !preserveAspectRatio;\n if (oldLayoutInfo && estimatedSize) {\n height = oldLayoutInfo.rect.height;\n estimatedSize = invalidationContext.layoutOptionsChanged || invalidationContext.sizeChanged || oldLayoutInfo.estimatedSize || (oldLayoutInfo.content !== content);\n }\n\n let rect = new Rect(x, y, itemWidth, height);\n let layoutInfo = new LayoutInfo(node.type, key, rect);\n layoutInfo.estimatedSize = estimatedSize;\n layoutInfo.allowOverflow = true;\n layoutInfo.content = content;\n newLayoutInfos.set(key, layoutInfo);\n rowLayoutInfos.push(layoutInfo);\n\n maxHeight = Math.max(maxHeight, layoutInfo.rect.height);\n }\n\n for (let layoutInfo of rowLayoutInfos) {\n layoutInfo.rect.height = maxHeight;\n }\n\n y += maxHeight + minSpace.height;\n\n // Keep adding skeleton rows until we fill the viewport\n if (skeleton && row === rows - 1 && y < this.virtualizer!.visibleRect.height) {\n rows++;\n }\n }\n\n // Always add the loader sentinel if present in the collection so we can make sure it is never virtualized out.\n let lastNode = collection.getItem(collection.getLastKey()!);\n if (lastNode?.type === 'loader') {\n let rect = new Rect(horizontalSpacing, y, itemWidth, 0);\n let layoutInfo = new LayoutInfo('loader', lastNode.key, rect);\n newLayoutInfos.set(lastNode.key, layoutInfo);\n }\n\n this.layoutInfos = newLayoutInfos;\n this.contentSize = new Size(this.virtualizer!.visibleRect.width, y);\n }\n\n getLayoutInfo(key: Key): LayoutInfo | null {\n return this.layoutInfos.get(key) || null;\n }\n\n getContentSize(): Size {\n return this.contentSize;\n }\n\n getVisibleLayoutInfos(rect: Rect): LayoutInfo[] {\n let layoutInfos: LayoutInfo[] = [];\n for (let layoutInfo of this.layoutInfos.values()) {\n if (layoutInfo.rect.intersects(rect) || this.virtualizer!.isPersistedKey(layoutInfo.key) || layoutInfo.type === 'loader') {\n layoutInfos.push(layoutInfo);\n }\n }\n return layoutInfos;\n }\n\n updateItemSize(key: Key, size: Size): boolean {\n let layoutInfo = this.layoutInfos.get(key);\n if (!size || !layoutInfo) {\n return false;\n }\n\n if (size.height !== layoutInfo.rect.height) {\n let newLayoutInfo = layoutInfo.copy();\n newLayoutInfo.rect.height = size.height;\n newLayoutInfo.estimatedSize = false;\n this.layoutInfos.set(key, newLayoutInfo);\n return true;\n }\n\n return false;\n }\n\n getDropTargetFromPoint(x: number, y: number, isValidDropTarget: (target: DropTarget) => boolean): DropTarget {\n if (this.layoutInfos.size === 0) {\n return {type: 'root'};\n }\n\n x += this.virtualizer!.visibleRect.x;\n y += this.virtualizer!.visibleRect.y;\n\n // Find the closest item within on either side of the point using the gap width.\n let key: Key | null = null;\n if (this.numColumns === 1) {\n let searchRect = new Rect(x, Math.max(0, y - this.gap.height), 1, Math.max(1, this.gap.height * 2));\n let candidates = this.getVisibleLayoutInfos(searchRect);\n let minDistance = Infinity;\n for (let candidate of candidates) {\n // Ignore items outside the search rect, e.g. persisted keys.\n if (!candidate.rect.intersects(searchRect)) {\n continue;\n }\n\n let yDist = Math.abs(candidate.rect.y - y);\n let maxYDist = Math.abs(candidate.rect.maxY - y);\n let dist = Math.min(yDist, maxYDist);\n if (dist < minDistance) {\n minDistance = dist;\n key = candidate.key;\n }\n }\n } else {\n let searchRect = new Rect(Math.max(0, x - this.gap.width), y, this.gap.width * 2, 1);\n let candidates = this.getVisibleLayoutInfos(searchRect);\n let minDistance = Infinity;\n for (let candidate of candidates) {\n // Ignore items outside the search rect, e.g. persisted keys.\n if (!candidate.rect.intersects(searchRect)) {\n continue;\n }\n\n let xDist = Math.abs(candidate.rect.x - x);\n let maxXDist = Math.abs(candidate.rect.maxX - x);\n let dist = Math.min(xDist, maxXDist);\n if (dist < minDistance) {\n minDistance = dist;\n key = candidate.key;\n }\n }\n }\n\n let layoutInfo = key != null ? this.getLayoutInfo(key) : null;\n if (!layoutInfo) {\n return {type: 'root'};\n }\n\n let target: DropTarget = {\n type: 'item',\n key: layoutInfo.key,\n dropPosition: 'on'\n };\n\n let pos = this.numColumns === 1 ? y : x;\n let layoutInfoPos = this.numColumns === 1 ? layoutInfo.rect.y : layoutInfo.rect.x;\n let size = this.numColumns === 1 ? layoutInfo.rect.height : layoutInfo.rect.width;\n if (isValidDropTarget(target)) {\n // If dropping on the item is accepted, try the before/after positions\n // if within 5px of the start or end of the item.\n if (pos < layoutInfoPos + 5) {\n target.dropPosition = 'before';\n } else if (pos > layoutInfoPos + size - 5) {\n target.dropPosition = 'after';\n }\n } else {\n // If dropping on the item isn't accepted, try the target before or after depending on the position.\n let mid = layoutInfoPos + size / 2;\n if (pos <= mid && isValidDropTarget({...target, dropPosition: 'before'})) {\n target.dropPosition = 'before';\n } else if (pos >= mid && isValidDropTarget({...target, dropPosition: 'after'})) {\n target.dropPosition = 'after';\n }\n }\n\n return target;\n }\n\n getDropTargetLayoutInfo(target: ItemDropTarget): LayoutInfo {\n let layoutInfo = this.getLayoutInfo(target.key)!;\n let rect: Rect;\n if (this.numColumns === 1) {\n // Flip from vertical to horizontal if only one column is visible.\n rect = new Rect(\n layoutInfo.rect.x,\n target.dropPosition === 'before'\n ? layoutInfo.rect.y - this.gap.height / 2 - this.dropIndicatorThickness / 2\n : layoutInfo.rect.maxY + this.gap.height / 2 - this.dropIndicatorThickness / 2,\n layoutInfo.rect.width,\n this.dropIndicatorThickness\n );\n } else {\n rect = new Rect(\n target.dropPosition === 'before'\n ? layoutInfo.rect.x - this.gap.width / 2 - this.dropIndicatorThickness / 2\n : layoutInfo.rect.maxX + this.gap.width / 2 - this.dropIndicatorThickness / 2,\n layoutInfo.rect.y,\n this.dropIndicatorThickness,\n layoutInfo.rect.height\n );\n }\n\n return new LayoutInfo('dropIndicator', target.key + ':' + target.dropPosition, rect);\n }\n}\n"],"names":[],"version":3,"file":"GridLayout.module.js.map"}
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC;AA6CD,MAAM,wCAAkB;IACtB,aAAa,IAAI,CAAA,GAAA,WAAG,EAAE,KAAK;IAC3B,aAAa,IAAI,CAAA,GAAA,WAAG,EAAE,UAAU;IAChC,qBAAqB;IACrB,UAAU,IAAI,CAAA,GAAA,WAAG,EAAE,IAAI;IACvB,UAAU;IACV,YAAY;IACZ,wBAAwB;AAC1B;AAQO,MAAM,kDAAuE,CAAA,GAAA,aAAK;IAQvF,8BAA8B,UAAa,EAAE,UAAa,EAAW;QACnE,OAAO,WAAW,UAAU,KAAK,WAAW,UAAU,IACjD,WAAW,sBAAsB,KAAK,WAAW,sBAAsB,IACvE,WAAW,mBAAmB,KAAK,WAAW,mBAAmB,IAChE,CAAC,AAAC,CAAA,WAAW,WAAW,IAAI,sCAAgB,WAAW,AAAD,EAAG,MAAM,CAAC,WAAW,WAAW,IAAI,sCAAgB,WAAW,KACrH,CAAC,AAAC,CAAA,WAAW,WAAW,IAAI,sCAAgB,WAAW,AAAD,EAAG,MAAM,CAAC,WAAW,WAAW,IAAI,sCAAgB,WAAW,KACrH,CAAC,AAAC,CAAA,WAAW,QAAQ,IAAI,sCAAgB,QAAQ,AAAD,EAAG,MAAM,CAAC,WAAW,QAAQ,IAAI,sCAAgB,QAAQ,KAC1G,WAAW,kBAAkB,KAAK,WAAW,kBAAkB;IACtE;IAEA,OAAO,mBAA2C,EAAQ;QACxD,IAAI,eACF,cAAc,sCAAgB,WAAW,eACzC,cAAc,sCAAgB,WAAW,uBACzC,sBAAsB,sCAAgB,mBAAmB,YACzD,WAAW,sCAAgB,QAAQ,sBACnC,qBAAqB,sCAAgB,QAAQ,cAC7C,aAAa,sCAAgB,UAAU,0B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AAW,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,IAAI,IAAI,CAAC,sBAAsB,GAAG,IACxE,WAAW,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,IAAI,IAAI,CAAC,sBAAsB,GAAG,GAC/E,WAAW,IAAI,CAAC,KAAK,EACrB,IAAI,CAAC,sBAAsB;aAG7B,OAAO,IAAI,CAAA,GAAA,WAAG,EACZ,OAAO,YAAY,KAAK,WACpB,WAAW,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,IAAI,CAAC,sBAAsB,GAAG,IACvE,WAAW,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,IAAI,CAAC,sBAAsB,GAAG,GAC9E,WAAW,IAAI,CAAC,CAAC,EACjB,IAAI,CAAC,sBAAsB,EAC3B,WAAW,IAAI,CAAC,MAAM;QAI1B,OAAO,IAAI,CAAA,GAAA,iBAAS,EAAE,iBAAiB,OAAO,GAAG,GAAG,MAAM,OAAO,YAAY,EAAE;IACjF;;QApSK,qBACK,MAAY,sCAAgB,QAAQ,OACpC,yBAAyB,QACzB,aAAqB,QACvB,cAAoB,IAAI,CAAA,GAAA,WAAG,UAC3B,cAAoC,IAAI,YACxC,SAAiB;;AA+R3B","sources":["packages/@react-stately/layout/src/GridLayout.ts"],"sourcesContent":["/*\n * Copyright 2024 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 {DropTarget, DropTargetDelegate, ItemDropTarget, Key, Node} from '@react-types/shared';\nimport {InvalidationContext, Layout, LayoutInfo, Rect, Size} from '@react-stately/virtualizer';\n\nexport interface GridLayoutOptions {\n /**\n * The minimum item size.\n * @default 200 x 200\n */\n minItemSize?: Size,\n /**\n * The maximum item size.\n * @default Infinity\n */\n maxItemSize?: Size,\n /**\n * Whether to preserve the aspect ratio of the `minItemSize`.\n * By default, grid rows may have variable heights. When `preserveAspectRatio`\n * is true, all rows will have equal heights.\n * @default false\n */\n preserveAspectRatio?: boolean,\n /**\n * The minimum space required between items.\n * @default 18 x 18\n */\n minSpace?: Size,\n /**\n * The maximum allowed horizontal space between items.\n * @default Infinity\n */\n maxHorizontalSpace?: number,\n /**\n * The maximum number of columns.\n * @default Infinity\n */\n maxColumns?: number,\n /**\n * The thickness of the drop indicator.\n * @default 2\n */\n dropIndicatorThickness?: number\n}\n\nconst DEFAULT_OPTIONS = {\n minItemSize: new Size(200, 200),\n maxItemSize: new Size(Infinity, Infinity),\n preserveAspectRatio: false,\n minSpace: new Size(18, 18),\n maxSpace: Infinity,\n maxColumns: Infinity,\n dropIndicatorThickness: 2\n};\n\n/**\n * GridLayout is a virtualizer Layout implementation\n * that arranges its items in a grid.\n * The items are sized between a minimum and maximum size\n * depending on the width of the container.\n */\nexport class GridLayout<T, O extends GridLayoutOptions = GridLayoutOptions> extends Layout<Node<T>, O> implements DropTargetDelegate {\n protected gap: Size = DEFAULT_OPTIONS.minSpace;\n protected dropIndicatorThickness = 2;\n protected numColumns: number = 0;\n private contentSize: Size = new Size();\n private layoutInfos: Map<Key, LayoutInfo> = new Map();\n private margin: number = 0;\n\n shouldInvalidateLayoutOptions(newOptions: O, oldOptions: O): boolean {\n return newOptions.maxColumns !== oldOptions.maxColumns\n || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness\n || newOptions.preserveAspectRatio !== oldOptions.preserveAspectRatio\n || (!(newOptions.minItemSize || DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || DEFAULT_OPTIONS.minItemSize))\n || (!(newOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize))\n || (!(newOptions.minSpace || DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || DEFAULT_OPTIONS.minSpace))\n || newOptions.maxHorizontalSpace !== oldOptions.maxHorizontalSpace;\n }\n\n update(invalidationContext: InvalidationContext<O>): void {\n let {\n minItemSize = DEFAULT_OPTIONS.minItemSize,\n maxItemSize = DEFAULT_OPTIONS.maxItemSize,\n preserveAspectRatio = DEFAULT_OPTIONS.preserveAspectRatio,\n minSpace = DEFAULT_OPTIONS.minSpace,\n maxHorizontalSpace = DEFAULT_OPTIONS.maxSpace,\n maxColumns = DEFAULT_OPTIONS.maxColumns,\n dropIndicatorThickness = DEFAULT_OPTIONS.dropIndicatorThickness\n } = invalidationContext.layoutOptions || {};\n this.dropIndicatorThickness = dropIndicatorThickness;\n\n let visibleWidth = this.virtualizer!.visibleRect.width;\n\n // The max item width is always the entire viewport.\n // If the max item height is infinity, scale in proportion to the max width.\n let maxItemWidth = Math.min(maxItemSize.width, visibleWidth);\n let maxItemHeight = Number.isFinite(maxItemSize.height)\n ? maxItemSize.height\n : Math.floor((minItemSize.height / minItemSize.width) * maxItemWidth);\n\n // Compute the number of rows and columns needed to display the content\n let columns = Math.floor(visibleWidth / (minItemSize.width + minSpace.width));\n let numColumns = Math.max(1, Math.min(maxColumns, columns));\n this.numColumns = numColumns;\n\n // Compute the available width (minus the space between items)\n let width = visibleWidth - (minSpace.width * Math.max(0, numColumns));\n\n // Compute the item width based on the space available\n let itemWidth = Math.floor(width / numColumns);\n itemWidth = Math.max(minItemSize.width, Math.min(maxItemWidth, itemWidth));\n\n // Compute the item height, which is proportional to the item width\n let t = ((itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width));\n let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);\n itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));\n\n // Compute the horizontal spacing, content height and horizontal margin\n let horizontalSpacing = Math.min(Math.max(maxHorizontalSpace, minSpace.width), Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1)));\n this.gap = new Size(horizontalSpacing, minSpace.height);\n this.margin = Math.floor((visibleWidth - numColumns * itemWidth - horizontalSpacing * (numColumns + 1)) / 2);\n\n // If there is a skeleton loader within the last 2 items in the collection, increment the collection size\n // so that an additional row is added for the skeletons.\n let collection = this.virtualizer!.collection;\n let collectionSize = collection.size;\n let lastKey = collection.getLastKey();\n for (let i = 0; i < 2 && lastKey != null; i++) {\n let item = collection.getItem(lastKey);\n if (item?.type === 'skeleton') {\n collectionSize++;\n break;\n }\n lastKey = collection.getKeyBefore(lastKey);\n }\n\n let rows = Math.ceil(collectionSize / numColumns);\n let iterator = collection[Symbol.iterator]();\n let y = rows > 0 ? minSpace.height : 0;\n let newLayoutInfos = new Map();\n let skeleton: Node<T> | null = null;\n let skeletonCount = 0;\n for (let row = 0; row < rows; row++) {\n let maxHeight = 0;\n let rowLayoutInfos: LayoutInfo[] = [];\n for (let col = 0; col < numColumns; col++) {\n // Repeat skeleton until the end of the current row.\n let node = skeleton || iterator.next().value;\n if (!node) {\n break;\n }\n\n // We will add the loader after the skeletons so skip here\n if (node.type === 'loader') {\n continue;\n }\n\n if (node.type === 'skeleton') {\n skeleton = node;\n }\n\n let key = skeleton ? `${skeleton.key}-${skeletonCount++}` : node.key;\n let oldLayoutInfo = this.layoutInfos.get(key);\n let content = node;\n if (skeleton) {\n content = oldLayoutInfo && oldLayoutInfo.content.key === key ? oldLayoutInfo.content : {...skeleton, key};\n }\n let x = horizontalSpacing + col * (itemWidth + horizontalSpacing) + this.margin;\n let height = itemHeight;\n let estimatedSize = !preserveAspectRatio;\n if (oldLayoutInfo && estimatedSize) {\n height = oldLayoutInfo.rect.height;\n estimatedSize = invalidationContext.layoutOptionsChanged || invalidationContext.sizeChanged || oldLayoutInfo.estimatedSize || (oldLayoutInfo.content !== content);\n }\n\n let rect = new Rect(x, y, itemWidth, height);\n let layoutInfo = new LayoutInfo(node.type, key, rect);\n layoutInfo.estimatedSize = estimatedSize;\n layoutInfo.allowOverflow = true;\n layoutInfo.content = content;\n newLayoutInfos.set(key, layoutInfo);\n rowLayoutInfos.push(layoutInfo);\n\n maxHeight = Math.max(maxHeight, layoutInfo.rect.height);\n }\n\n for (let layoutInfo of rowLayoutInfos) {\n layoutInfo.rect.height = maxHeight;\n }\n\n y += maxHeight + minSpace.height;\n\n // Keep adding skeleton rows until we fill the viewport\n if (skeleton && row === rows - 1 && y < this.virtualizer!.visibleRect.height) {\n rows++;\n }\n }\n\n // Always add the loader sentinel if present in the collection so we can make sure it is never virtualized out.\n let lastNode = collection.getItem(collection.getLastKey()!);\n if (lastNode?.type === 'loader') {\n let rect = new Rect(horizontalSpacing, y, itemWidth, 0);\n let layoutInfo = new LayoutInfo('loader', lastNode.key, rect);\n newLayoutInfos.set(lastNode.key, layoutInfo);\n }\n\n this.layoutInfos = newLayoutInfos;\n this.contentSize = new Size(this.virtualizer!.visibleRect.width, y);\n }\n\n getLayoutInfo(key: Key): LayoutInfo | null {\n return this.layoutInfos.get(key) || null;\n }\n\n getContentSize(): Size {\n return this.contentSize;\n }\n\n getVisibleLayoutInfos(rect: Rect): LayoutInfo[] {\n let layoutInfos: LayoutInfo[] = [];\n for (let layoutInfo of this.layoutInfos.values()) {\n if (layoutInfo.rect.intersects(rect) || this.virtualizer!.isPersistedKey(layoutInfo.key) || layoutInfo.type === 'loader') {\n layoutInfos.push(layoutInfo);\n }\n }\n return layoutInfos;\n }\n\n updateItemSize(key: Key, size: Size): boolean {\n let layoutInfo = this.layoutInfos.get(key);\n if (!size || !layoutInfo) {\n return false;\n }\n\n if (size.height !== layoutInfo.rect.height) {\n let newLayoutInfo = layoutInfo.copy();\n newLayoutInfo.rect.height = size.height;\n newLayoutInfo.estimatedSize = false;\n this.layoutInfos.set(key, newLayoutInfo);\n return true;\n }\n\n return false;\n }\n\n getDropTargetFromPoint(x: number, y: number, isValidDropTarget: (target: DropTarget) => boolean): DropTarget {\n if (this.layoutInfos.size === 0) {\n return {type: 'root'};\n }\n\n x += this.virtualizer!.visibleRect.x;\n y += this.virtualizer!.visibleRect.y;\n\n // Find the closest item within on either side of the point using the gap width.\n let key: Key | null = null;\n if (this.numColumns === 1) {\n let searchRect = new Rect(x, Math.max(0, y - this.gap.height), 1, Math.max(1, this.gap.height * 2));\n let candidates = this.getVisibleLayoutInfos(searchRect);\n let minDistance = Infinity;\n for (let candidate of candidates) {\n // Ignore items outside the search rect, e.g. persisted keys.\n if (!candidate.rect.intersects(searchRect)) {\n continue;\n }\n\n let yDist = Math.abs(candidate.rect.y - y);\n let maxYDist = Math.abs(candidate.rect.maxY - y);\n let dist = Math.min(yDist, maxYDist);\n if (dist < minDistance) {\n minDistance = dist;\n key = candidate.key;\n }\n }\n } else {\n let searchRect = new Rect(Math.max(0, x - this.gap.width), y, this.gap.width * 2, 1);\n let candidates = this.getVisibleLayoutInfos(searchRect);\n let minDistance = Infinity;\n for (let candidate of candidates) {\n // Ignore items outside the search rect, e.g. persisted keys.\n if (!candidate.rect.intersects(searchRect)) {\n continue;\n }\n\n let xDist = Math.abs(candidate.rect.x - x);\n let maxXDist = Math.abs(candidate.rect.maxX - x);\n let dist = Math.min(xDist, maxXDist);\n if (dist < minDistance) {\n minDistance = dist;\n key = candidate.key;\n }\n }\n }\n\n let layoutInfo = key != null ? this.getLayoutInfo(key) : null;\n if (!layoutInfo) {\n return {type: 'root'};\n }\n\n let target: DropTarget = {\n type: 'item',\n key: layoutInfo.key,\n dropPosition: 'on'\n };\n\n let pos = this.numColumns === 1 ? y : x;\n let layoutInfoPos = this.numColumns === 1 ? layoutInfo.rect.y : layoutInfo.rect.x;\n let size = this.numColumns === 1 ? layoutInfo.rect.height : layoutInfo.rect.width;\n if (isValidDropTarget(target)) {\n // If dropping on the item is accepted, try the before/after positions\n // if within 5px of the start or end of the item.\n if (pos < layoutInfoPos + 5) {\n target.dropPosition = 'before';\n } else if (pos > layoutInfoPos + size - 5) {\n target.dropPosition = 'after';\n }\n } else {\n // If dropping on the item isn't accepted, try the target before or after depending on the position.\n let mid = layoutInfoPos + size / 2;\n if (pos <= mid && isValidDropTarget({...target, dropPosition: 'before'})) {\n target.dropPosition = 'before';\n } else if (pos >= mid && isValidDropTarget({...target, dropPosition: 'after'})) {\n target.dropPosition = 'after';\n }\n }\n\n return target;\n }\n\n getDropTargetLayoutInfo(target: ItemDropTarget): LayoutInfo {\n let layoutInfo = this.getLayoutInfo(target.key)!;\n let rect: Rect;\n if (this.numColumns === 1) {\n // Flip from vertical to horizontal if only one column is visible.\n rect = new Rect(\n layoutInfo.rect.x,\n target.dropPosition === 'before'\n ? layoutInfo.rect.y - this.gap.height / 2 - this.dropIndicatorThickness / 2\n : layoutInfo.rect.maxY + this.gap.height / 2 - this.dropIndicatorThickness / 2,\n layoutInfo.rect.width,\n this.dropIndicatorThickness\n );\n } else {\n rect = new Rect(\n target.dropPosition === 'before'\n ? layoutInfo.rect.x - this.gap.width / 2 - this.dropIndicatorThickness / 2\n : layoutInfo.rect.maxX + this.gap.width / 2 - this.dropIndicatorThickness / 2,\n layoutInfo.rect.y,\n this.dropIndicatorThickness,\n layoutInfo.rect.height\n );\n }\n\n return new LayoutInfo('dropIndicator', target.key + ':' + target.dropPosition, rect);\n }\n}\n"],"names":[],"version":3,"file":"GridLayout.module.js.map"}
@@ -129,35 +129,44 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
129
129
  }
130
130
  buildCollection(y = this.padding) {
131
131
  let collection = this.virtualizer.collection;
132
- let skipped = 0;
132
+ let collectionNodes = [
133
+ ...collection
134
+ ];
135
+ let loaderNodes = collectionNodes.filter((node)=>node.type === 'loader');
133
136
  let nodes = [];
134
- let isEmptyOrLoading = (collection === null || collection === void 0 ? void 0 : collection.size) === 0 || collection.size === 1 && collection.getItem(collection.getFirstKey()).type === 'loader';
137
+ let isEmptyOrLoading = (collection === null || collection === void 0 ? void 0 : collection.size) === 0;
135
138
  if (isEmptyOrLoading) y = 0;
136
- for (let node of collection){
139
+ for (let node of collectionNodes){
137
140
  var _this_rowHeight, _ref;
138
141
  let rowHeight = ((_ref = (_this_rowHeight = this.rowHeight) !== null && _this_rowHeight !== void 0 ? _this_rowHeight : this.estimatedRowHeight) !== null && _ref !== void 0 ? _ref : $fe69e47e38ed0ac4$var$DEFAULT_HEIGHT) + this.gap;
139
142
  // Skip rows before the valid rectangle unless they are already cached.
140
143
  if (node.type === 'item' && y + rowHeight < this.requestedRect.y && !this.isValid(node, y)) {
141
144
  y += rowHeight;
142
- skipped++;
143
145
  continue;
144
146
  }
145
147
  let layoutNode = this.buildChild(node, this.padding, y, null);
146
148
  y = layoutNode.layoutInfo.rect.maxY + this.gap;
147
149
  nodes.push(layoutNode);
148
- if (node.type === 'item' && y > this.requestedRect.maxY) {
149
- var _nodes_at;
150
- let itemsAfterRect = collection.size - (nodes.length + skipped);
151
- let lastNode = collection.getItem(collection.getLastKey());
152
- if ((lastNode === null || lastNode === void 0 ? void 0 : lastNode.type) === 'loader') itemsAfterRect--;
153
- y += itemsAfterRect * rowHeight;
154
- // Always add the loader sentinel if present. This assumes the loader is the last option/row
155
- // will need to refactor when handling multi section loading
156
- if ((lastNode === null || lastNode === void 0 ? void 0 : lastNode.type) === 'loader' && ((_nodes_at = nodes.at(-1)) === null || _nodes_at === void 0 ? void 0 : _nodes_at.layoutInfo.type) !== 'loader') {
157
- let loader = this.buildChild(lastNode, this.padding, y, null);
150
+ if (node.type === 'loader') {
151
+ let index = loaderNodes.indexOf(node);
152
+ loaderNodes.splice(index, 1);
153
+ }
154
+ // Build each loader that exists in the collection that is outside the visible rect so that they are persisted
155
+ // at the proper estimated location. If the node.type is "section" then we don't do this shortcut since we have to
156
+ // build the sections to see how tall they are.
157
+ if ((node.type === 'item' || node.type === 'loader') && y > this.requestedRect.maxY) {
158
+ let lastProcessedIndex = collectionNodes.indexOf(node);
159
+ for (let loaderNode of loaderNodes){
160
+ let loaderNodeIndex = collectionNodes.indexOf(loaderNode);
161
+ // Subtract by an additional 1 since we've already added the current item's height to y
162
+ y += (loaderNodeIndex - lastProcessedIndex - 1) * rowHeight;
163
+ let loader = this.buildChild(loaderNode, this.padding, y, null);
158
164
  nodes.push(loader);
159
165
  y = loader.layoutInfo.rect.maxY;
166
+ lastProcessedIndex = loaderNodeIndex;
160
167
  }
168
+ // Account for the rest of the items after the last loader spinner, subtract by 1 since we've processed the current node's height already
169
+ y += (collectionNodes.length - lastProcessedIndex - 1) * rowHeight;
161
170
  break;
162
171
  }
163
172
  }
@@ -400,9 +409,23 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
400
409
  getDropTargetLayoutInfo(target) {
401
410
  let layoutInfo = this.getLayoutInfo(target.key);
402
411
  let rect;
403
- if (target.dropPosition === 'before') rect = new (0, $iId4j$reactstatelyvirtualizer.Rect)(layoutInfo.rect.x, layoutInfo.rect.y - this.dropIndicatorThickness / 2, layoutInfo.rect.width, this.dropIndicatorThickness);
404
- else if (target.dropPosition === 'after') rect = new (0, $iId4j$reactstatelyvirtualizer.Rect)(layoutInfo.rect.x, layoutInfo.rect.maxY - this.dropIndicatorThickness / 2, layoutInfo.rect.width, this.dropIndicatorThickness);
405
- else rect = layoutInfo.rect;
412
+ if (target.dropPosition === 'before') rect = new (0, $iId4j$reactstatelyvirtualizer.Rect)(layoutInfo.rect.x, Math.max(0, layoutInfo.rect.y - this.dropIndicatorThickness / 2), layoutInfo.rect.width, this.dropIndicatorThickness);
413
+ else if (target.dropPosition === 'after') {
414
+ // Render after last visible descendant of the drop target.
415
+ let targetNode = this.collection.getItem(target.key);
416
+ if (targetNode) {
417
+ var _targetNode_level;
418
+ let targetLevel = (_targetNode_level = targetNode.level) !== null && _targetNode_level !== void 0 ? _targetNode_level : 0;
419
+ let currentKey = this.collection.getKeyAfter(target.key);
420
+ while(currentKey != null){
421
+ let node = this.collection.getItem(currentKey);
422
+ if (!node || node.level <= targetLevel) break;
423
+ layoutInfo = this.getLayoutInfo(currentKey) || layoutInfo;
424
+ currentKey = this.collection.getKeyAfter(currentKey);
425
+ }
426
+ }
427
+ rect = new (0, $iId4j$reactstatelyvirtualizer.Rect)(layoutInfo.rect.x, layoutInfo.rect.maxY - this.dropIndicatorThickness / 2, layoutInfo.rect.width, this.dropIndicatorThickness);
428
+ } else rect = layoutInfo.rect;
406
429
  return new (0, $iId4j$reactstatelyvirtualizer.LayoutInfo)('dropIndicator', target.key + ':' + target.dropPosition, rect);
407
430
  }
408
431
  /**