@react-stately/layout 4.4.0 → 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.
- package/dist/GridLayout.main.js +8 -6
- package/dist/GridLayout.main.js.map +1 -1
- package/dist/GridLayout.mjs +8 -6
- package/dist/GridLayout.module.js +8 -6
- package/dist/GridLayout.module.js.map +1 -1
- package/dist/WaterfallLayout.main.js +8 -6
- package/dist/WaterfallLayout.main.js.map +1 -1
- package/dist/WaterfallLayout.mjs +8 -6
- package/dist/WaterfallLayout.module.js +8 -6
- package/dist/WaterfallLayout.module.js.map +1 -1
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/GridLayout.ts +15 -5
- package/src/WaterfallLayout.ts +14 -4
package/dist/GridLayout.main.js
CHANGED
|
@@ -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,9 +51,10 @@ 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
|
|
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);
|
|
56
58
|
// If there is a skeleton loader within the last 2 items in the collection, increment the collection size
|
|
57
59
|
// so that an additional row is added for the skeletons.
|
|
58
60
|
let collection = this.virtualizer.collection;
|
|
@@ -89,7 +91,7 @@ class $1f7773ceb2a3b9a6$export$7d2b12578154a735 extends (0, $7Tzdl$reactstatelyv
|
|
|
89
91
|
...skeleton,
|
|
90
92
|
key: key
|
|
91
93
|
};
|
|
92
|
-
let x = horizontalSpacing + col * (itemWidth + horizontalSpacing);
|
|
94
|
+
let x = horizontalSpacing + col * (itemWidth + horizontalSpacing) + this.margin;
|
|
93
95
|
let height = itemHeight;
|
|
94
96
|
let estimatedSize = !preserveAspectRatio;
|
|
95
97
|
if (oldLayoutInfo && estimatedSize) {
|
|
@@ -222,7 +224,7 @@ class $1f7773ceb2a3b9a6$export$7d2b12578154a735 extends (0, $7Tzdl$reactstatelyv
|
|
|
222
224
|
return new (0, $7Tzdl$reactstatelyvirtualizer.LayoutInfo)('dropIndicator', target.key + ':' + target.dropPosition, rect);
|
|
223
225
|
}
|
|
224
226
|
constructor(...args){
|
|
225
|
-
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;
|
|
226
228
|
}
|
|
227
229
|
}
|
|
228
230
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAwCD,MAAM,wCAAkB;IACtB,aAAa,IAAI,CAAA,GAAA,mCAA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,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;;QAhSK,qBACK,MAAY,sCAAgB,QAAQ,OACpC,yBAAyB,QACzB,aAAqB,QACvB,cAAoB,IAAI,CAAA,GAAA,mCAAG,UAC3B,cAAoC,IAAI;;AA4RlD","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 // 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);\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('drop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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,mCAAG,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,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"}
|
package/dist/GridLayout.mjs
CHANGED
|
@@ -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,9 +45,10 @@ 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
|
|
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);
|
|
50
52
|
// If there is a skeleton loader within the last 2 items in the collection, increment the collection size
|
|
51
53
|
// so that an additional row is added for the skeletons.
|
|
52
54
|
let collection = this.virtualizer.collection;
|
|
@@ -83,7 +85,7 @@ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
|
|
|
83
85
|
...skeleton,
|
|
84
86
|
key: key
|
|
85
87
|
};
|
|
86
|
-
let x = horizontalSpacing + col * (itemWidth + horizontalSpacing);
|
|
88
|
+
let x = horizontalSpacing + col * (itemWidth + horizontalSpacing) + this.margin;
|
|
87
89
|
let height = itemHeight;
|
|
88
90
|
let estimatedSize = !preserveAspectRatio;
|
|
89
91
|
if (oldLayoutInfo && estimatedSize) {
|
|
@@ -216,7 +218,7 @@ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
|
|
|
216
218
|
return new (0, $ipgKF$LayoutInfo)('dropIndicator', target.key + ':' + target.dropPosition, rect);
|
|
217
219
|
}
|
|
218
220
|
constructor(...args){
|
|
219
|
-
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;
|
|
220
222
|
}
|
|
221
223
|
}
|
|
222
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,9 +45,10 @@ 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
|
|
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);
|
|
50
52
|
// If there is a skeleton loader within the last 2 items in the collection, increment the collection size
|
|
51
53
|
// so that an additional row is added for the skeletons.
|
|
52
54
|
let collection = this.virtualizer.collection;
|
|
@@ -83,7 +85,7 @@ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
|
|
|
83
85
|
...skeleton,
|
|
84
86
|
key: key
|
|
85
87
|
};
|
|
86
|
-
let x = horizontalSpacing + col * (itemWidth + horizontalSpacing);
|
|
88
|
+
let x = horizontalSpacing + col * (itemWidth + horizontalSpacing) + this.margin;
|
|
87
89
|
let height = itemHeight;
|
|
88
90
|
let estimatedSize = !preserveAspectRatio;
|
|
89
91
|
if (oldLayoutInfo && estimatedSize) {
|
|
@@ -216,7 +218,7 @@ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
|
|
|
216
218
|
return new (0, $ipgKF$LayoutInfo)('dropIndicator', target.key + ':' + target.dropPosition, rect);
|
|
217
219
|
}
|
|
218
220
|
constructor(...args){
|
|
219
|
-
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;
|
|
220
222
|
}
|
|
221
223
|
}
|
|
222
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,IAAI,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,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;;QAhSK,qBACK,MAAY,sCAAgB,QAAQ,OACpC,yBAAyB,QACzB,aAAqB,QACvB,cAAoB,IAAI,CAAA,GAAA,WAAG,UAC3B,cAAoC,IAAI;;AA4RlD","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 // 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);\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;QAC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Aa,CAAC,OAAO,GAAG;QAC9C,IAAI;QACJ,IAAI,IAAI,CAAC,UAAU,KAAK,GACtB,kEAAkE;QAClE,OAAO,IAAI,CAAA,GAAA,WAAG,EACZ,WAAW,IAAI,CAAC,CAAC,EACjB,OAAO,YAAY,KAAK,WACpB,WAAW,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"}
|
|
@@ -31,16 +31,17 @@ const $f2cd6b90da09fa37$var$DEFAULT_OPTIONS = {
|
|
|
31
31
|
minItemSize: new (0, $5TwTj$reactstatelyvirtualizer.Size)(200, 200),
|
|
32
32
|
maxItemSize: new (0, $5TwTj$reactstatelyvirtualizer.Size)(Infinity, Infinity),
|
|
33
33
|
minSpace: new (0, $5TwTj$reactstatelyvirtualizer.Size)(18, 18),
|
|
34
|
+
maxSpace: Infinity,
|
|
34
35
|
maxColumns: Infinity,
|
|
35
36
|
dropIndicatorThickness: 2
|
|
36
37
|
};
|
|
37
38
|
class $f2cd6b90da09fa37$export$e9f7cda058ba8df8 extends (0, $5TwTj$reactstatelyvirtualizer.Layout) {
|
|
38
39
|
shouldInvalidateLayoutOptions(newOptions, oldOptions) {
|
|
39
|
-
return newOptions.maxColumns !== oldOptions.maxColumns || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness || !(newOptions.minItemSize || $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.minItemSize) || !(newOptions.maxItemSize || $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.maxItemSize) || !(newOptions.minSpace || $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.minSpace);
|
|
40
|
+
return newOptions.maxColumns !== oldOptions.maxColumns || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness || !(newOptions.minItemSize || $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.minItemSize) || !(newOptions.maxItemSize || $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.maxItemSize) || !(newOptions.minSpace || $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.minSpace) || newOptions.maxHorizontalSpace !== oldOptions.maxHorizontalSpace;
|
|
40
41
|
}
|
|
41
42
|
update(invalidationContext) {
|
|
42
43
|
var _collection_getItem;
|
|
43
|
-
let { minItemSize: minItemSize = $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.minItemSize, maxItemSize: maxItemSize = $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.maxItemSize, minSpace: minSpace = $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.minSpace, maxColumns: maxColumns = $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.maxColumns, dropIndicatorThickness: dropIndicatorThickness = $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.dropIndicatorThickness } = invalidationContext.layoutOptions || {};
|
|
44
|
+
let { minItemSize: minItemSize = $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.minItemSize, maxItemSize: maxItemSize = $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.maxItemSize, minSpace: minSpace = $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.minSpace, maxHorizontalSpace: maxHorizontalSpace = $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.maxSpace, maxColumns: maxColumns = $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.maxColumns, dropIndicatorThickness: dropIndicatorThickness = $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.dropIndicatorThickness } = invalidationContext.layoutOptions || {};
|
|
44
45
|
this.dropIndicatorThickness = dropIndicatorThickness;
|
|
45
46
|
let visibleWidth = this.virtualizer.visibleRect.width;
|
|
46
47
|
// The max item width is always the entire viewport.
|
|
@@ -59,8 +60,9 @@ class $f2cd6b90da09fa37$export$e9f7cda058ba8df8 extends (0, $5TwTj$reactstatelyv
|
|
|
59
60
|
let t = (itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width);
|
|
60
61
|
let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);
|
|
61
62
|
itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));
|
|
62
|
-
// Compute the horizontal spacing and
|
|
63
|
-
let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));
|
|
63
|
+
// Compute the horizontal spacing, content height and horizontal margin
|
|
64
|
+
let horizontalSpacing = Math.min(Math.max(maxHorizontalSpace, minSpace.width), Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1)));
|
|
65
|
+
this.margin = Math.floor((visibleWidth - numColumns * itemWidth - horizontalSpacing * (numColumns + 1)) / 2);
|
|
64
66
|
// Setup an array of column heights
|
|
65
67
|
let columnHeights = Array(numColumns).fill(minSpace.height);
|
|
66
68
|
let newLayoutInfos = new Map();
|
|
@@ -76,7 +78,7 @@ class $f2cd6b90da09fa37$export$e9f7cda058ba8df8 extends (0, $5TwTj$reactstatelyv
|
|
|
76
78
|
// Preserve the previous column index so items don't jump around during resizing unless the number of columns changed.
|
|
77
79
|
let prevColumn = numColumns === this.numColumns && oldLayoutInfo && oldLayoutInfo.rect.y < this.virtualizer.visibleRect.maxY ? oldLayoutInfo.column : undefined;
|
|
78
80
|
let column = prevColumn !== null && prevColumn !== void 0 ? prevColumn : columnHeights.reduce((minIndex, h, i)=>h < columnHeights[minIndex] ? i : minIndex, 0);
|
|
79
|
-
let x = horizontalSpacing + column * (itemWidth + horizontalSpacing);
|
|
81
|
+
let x = horizontalSpacing + column * (itemWidth + horizontalSpacing) + this.margin;
|
|
80
82
|
let y = columnHeights[column];
|
|
81
83
|
let rect = new (0, $5TwTj$reactstatelyvirtualizer.Rect)(x, y, itemWidth, height);
|
|
82
84
|
let layoutInfo = new $f2cd6b90da09fa37$var$WaterfallLayoutInfo(node.type, key, rect);
|
|
@@ -218,7 +220,7 @@ class $f2cd6b90da09fa37$export$e9f7cda058ba8df8 extends (0, $5TwTj$reactstatelyv
|
|
|
218
220
|
};
|
|
219
221
|
}
|
|
220
222
|
constructor(...args){
|
|
221
|
-
super(...args), this.contentSize = new (0, $5TwTj$reactstatelyvirtualizer.Size)(), this.layoutInfos = new Map(), this.numColumns = 0, this.dropIndicatorThickness = 2;
|
|
223
|
+
super(...args), this.contentSize = new (0, $5TwTj$reactstatelyvirtualizer.Size)(), this.layoutInfos = new Map(), this.numColumns = 0, this.dropIndicatorThickness = 2, this.margin = 0;
|
|
222
224
|
}
|
|
223
225
|
}
|
|
224
226
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAiCD,MAAM,kDAA4B,CAAA,GAAA,yCAAS;IAGzC,OAA4B;QAC1B,IAAI,MAAM,KAAK,CAAC;QAChB,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM;QACxB,OAAO;IACT;;QAPF,qBACE,SAAS;;AAOX;AAEA,MAAM,wCAAkB;IACtB,aAAa,IAAI,CAAA,GAAA,mCAAG,EAAE,KAAK;IAC3B,aAAa,IAAI,CAAA,GAAA,mCAAG,EAAE,UAAU;IAChC,UAAU,IAAI,CAAA,GAAA,mCAAG,EAAE,IAAI;IACvB,YAAY;IACZ,wBAAwB;AAC1B;AAEO,MAAM,kDAAqG,CAAA,GAAA,qCAAK;IAMrH,8BAA8B,UAAa,EAAE,UAAa,EAAW;QACnE,OAAO,WAAW,UAAU,KAAK,WAAW,UAAU,IACjD,WAAW,sBAAsB,KAAK,WAAW,sBAAsB,IACtE,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;YAkGP;QAjGjD,IAAI,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C,IAAI,iBAAiB,IAAI,CAAC,aAAa,CAAC;QACxC,IAAI,eAAe,IAAI,CAAC,aAAa,CAAC;QACtC,IAAI,CAAC,kBAAkB,CAAC,cACtB,OAAO,EAAE;QAGX,6DAA6D;QAC7D,4DAA4D;QAC5D,IAAI,OAAO,eAAe,IAAI,CAAC,KAAK,CAAC,aAAa,IAAI;QACtD,IAAI,OAAc,EAAE;QACpB,KAAK,IAAI,cAAc,IAAI,CAAC,WAAW,CAAC,MAAM,GAC5C,IAAI,KAAK,YAAY,CAAC,WAAW,IAAI,EAAE,IAAI,GAAG,WAAW,IAAI,CAAC,IAAI,GAAG,GACnE,KAAK,IAAI,CAAC,WAAW,GAAG;QAG5B,OAAO;IACT;IAEA,uBAAuB,CAAS,EAAE,CAAS,EAAc;QACvD,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,GAC5B,OAAO;YAAC,MAAM;QAAM;QAGtB,KAAK,IAAI,CAAC,WAAW,CAAE,WAAW,CAAC,CAAC;QACpC,KAAK,IAAI,CAAC,WAAW,CAAE,WAAW,CAAC,CAAC;QACpC,IAAI,MAAM,IAAI,CAAC,WAAW,CAAE,UAAU,CAAC,IAAI,CAAA,GAAA,oCAAI,EAAE,GAAG;QACpD,IAAI,OAAO,MACT,OAAO;YAAC,MAAM;QAAM;QAGtB,uDAAuD;QACvD,oFAAoF;QACpF,OAAO;YACL,MAAM;iBACN;YACA,cAAc;QAChB;IACF;;QA3PK,qBACG,cAAoB,IAAI,CAAA,GAAA,mCAAG,UAC3B,cAA6C,IAAI,YAC/C,aAAa,QACb,yBAAyB;;AAwPrC","sources":["packages/@react-stately/layout/src/WaterfallLayout.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, Key, LayoutDelegate, Node} from '@react-types/shared';\nimport {InvalidationContext, Layout, LayoutInfo, Point, Rect, Size} from '@react-stately/virtualizer';\n\nexport interface WaterfallLayoutOptions {\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 * 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\nclass WaterfallLayoutInfo extends LayoutInfo {\n column = 0;\n\n copy(): WaterfallLayoutInfo {\n let res = super.copy() as WaterfallLayoutInfo;\n res.column = this.column;\n return res;\n }\n}\n\nconst DEFAULT_OPTIONS = {\n minItemSize: new Size(200, 200),\n maxItemSize: new Size(Infinity, Infinity),\n minSpace: new Size(18, 18),\n maxColumns: Infinity,\n dropIndicatorThickness: 2\n};\n\nexport class WaterfallLayout<T extends object, O extends WaterfallLayoutOptions = WaterfallLayoutOptions> extends Layout<Node<T>, O> implements LayoutDelegate, DropTargetDelegate {\n private contentSize: Size = new Size();\n private layoutInfos: Map<Key, WaterfallLayoutInfo> = new Map();\n protected numColumns = 0;\n protected dropIndicatorThickness = 2;\n\n shouldInvalidateLayoutOptions(newOptions: O, oldOptions: O): boolean {\n return newOptions.maxColumns !== oldOptions.maxColumns\n || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness\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 minSpace = DEFAULT_OPTIONS.minSpace,\n maxColumns = DEFAULT_OPTIONS.maxColumns,\n dropIndicatorThickness = DEFAULT_OPTIONS.dropIndicatorThickness\n } = invalidationContext.layoutOptions || {};\n this.dropIndicatorThickness = dropIndicatorThickness;\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\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\n // Setup an array of column heights\n let columnHeights = Array(numColumns).fill(minSpace.height);\n let newLayoutInfos = new Map();\n let addNode = (key: Key, node: Node<T>) => {\n let oldLayoutInfo = this.layoutInfos.get(key);\n let height = itemHeight;\n let estimatedSize = true;\n if (oldLayoutInfo) {\n height = oldLayoutInfo.rect.height;\n estimatedSize = invalidationContext.sizeChanged || oldLayoutInfo.estimatedSize || oldLayoutInfo.content !== node;\n }\n\n // Figure out which column to place the item in, and compute its position.\n // Preserve the previous column index so items don't jump around during resizing unless the number of columns changed.\n let prevColumn = numColumns === this.numColumns && oldLayoutInfo && oldLayoutInfo.rect.y < this.virtualizer!.visibleRect.maxY ? oldLayoutInfo.column : undefined;\n let column = prevColumn ?? columnHeights.reduce((minIndex, h, i) => h < columnHeights[minIndex] ? i : minIndex, 0);\n let x = horizontalSpacing + column * (itemWidth + horizontalSpacing);\n let y = columnHeights[column];\n\n let rect = new Rect(x, y, itemWidth, height);\n let layoutInfo = new WaterfallLayoutInfo(node.type, key, rect);\n layoutInfo.estimatedSize = estimatedSize;\n layoutInfo.allowOverflow = true;\n layoutInfo.content = node;\n layoutInfo.column = column;\n newLayoutInfos.set(key, layoutInfo);\n\n columnHeights[column] += layoutInfo.rect.height + minSpace.height;\n };\n\n let collection = this.virtualizer!.collection;\n let skeletonCount = 0;\n for (let node of collection) {\n if (node.type === 'skeleton') {\n // Add skeleton cards until every column has at least one, and we fill the viewport.\n let startingHeights = [...columnHeights];\n while (\n !columnHeights.every((h, i) => h !== startingHeights[i]) ||\n Math.min(...columnHeights) < this.virtualizer!.visibleRect.height\n ) {\n let key = `${node.key}-${skeletonCount++}`;\n let content = this.layoutInfos.get(key)?.content || {...node};\n addNode(key, content);\n }\n break;\n } else if (node.type !== 'loader') {\n addNode(node.key, node);\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 // Add it under the first column for simplicity\n let lastNode = collection.getItem(collection.getLastKey()!);\n if (lastNode?.type === 'loader') {\n let rect = new Rect(horizontalSpacing, columnHeights[0], itemWidth, 0);\n let layoutInfo = new LayoutInfo('loader', lastNode.key, rect);\n newLayoutInfos.set(lastNode.key, layoutInfo);\n }\n\n // Reset all columns to the maximum for the next section. If loading, set to 0 so virtualizer doesn't render its body since there aren't items to render,\n // except if we are performing skeleton loading\n let isEmptyOrLoading = collection?.size === 0 && collection.getItem(collection.getFirstKey()!)?.type !== 'skeleton';\n let maxHeight = isEmptyOrLoading ? 0 : Math.max(...columnHeights);\n this.contentSize = new Size(this.virtualizer!.visibleRect.width, maxHeight);\n this.layoutInfos = newLayoutInfos;\n this.numColumns = numColumns;\n }\n\n getLayoutInfo(key: Key): LayoutInfo {\n return this.layoutInfos.get(key)!;\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 // Override keyboard navigation to work spatially.\n getKeyRightOf(key: Key): Key | null {\n let layoutInfo = this.getLayoutInfo(key);\n if (!layoutInfo) {\n return null;\n }\n\n let rect = new Rect(layoutInfo.rect.maxX, layoutInfo.rect.y, this.virtualizer!.visibleRect.maxX - layoutInfo.rect.maxX, layoutInfo.rect.height);\n let layoutInfos = this.getVisibleLayoutInfos(rect);\n let bestKey: Key | null = null;\n let bestDistance = Infinity;\n for (let candidate of layoutInfos) {\n if (candidate.key === key) {\n continue;\n }\n\n // Find the closest item in the x direction with the most overlap in the y direction.\n let deltaX = candidate.rect.x - rect.x;\n let overlapY = Math.min(candidate.rect.maxY, rect.maxY) - Math.max(candidate.rect.y, rect.y);\n let distance = deltaX - overlapY;\n if (distance < bestDistance) {\n bestDistance = distance;\n bestKey = candidate.key;\n }\n }\n\n return bestKey;\n }\n\n getKeyLeftOf(key: Key): Key | null {\n let layoutInfo = this.getLayoutInfo(key);\n if (!layoutInfo) {\n return null;\n }\n\n let rect = new Rect(0, layoutInfo.rect.y, layoutInfo.rect.x, layoutInfo.rect.height);\n let layoutInfos = this.getVisibleLayoutInfos(rect);\n let bestKey: Key | null = null;\n let bestDistance = Infinity;\n for (let candidate of layoutInfos) {\n if (candidate.key === key) {\n continue;\n }\n\n // Find the closest item in the x direction with the most overlap in the y direction.\n let deltaX = rect.maxX - candidate.rect.maxX;\n let overlapY = Math.min(candidate.rect.maxY, rect.maxY) - Math.max(candidate.rect.y, rect.y);\n let distance = deltaX - overlapY;\n if (distance < bestDistance) {\n bestDistance = distance;\n bestKey = candidate.key;\n }\n }\n\n return bestKey;\n }\n\n // This overrides the default behavior of shift selection to work spatially\n // rather than following the order of the items in the collection (which may appear unpredictable).\n getKeyRange(from: Key, to: Key): Key[] {\n let fromLayoutInfo = this.getLayoutInfo(from);\n let toLayoutInfo = this.getLayoutInfo(to);\n if (!fromLayoutInfo || !toLayoutInfo) {\n return [];\n }\n\n // Find items where half of the area intersects the rectangle\n // formed from the first item to the last item in the range.\n let rect = fromLayoutInfo.rect.union(toLayoutInfo.rect);\n let keys: Key[] = [];\n for (let layoutInfo of this.layoutInfos.values()) {\n if (rect.intersection(layoutInfo.rect).area > layoutInfo.rect.area / 2) {\n keys.push(layoutInfo.key);\n }\n }\n return keys;\n }\n\n getDropTargetFromPoint(x: number, y: number): 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 let key = this.virtualizer!.keyAtPoint(new Point(x, y));\n if (key == null) {\n return {type: 'root'};\n }\n\n // Only support \"on\" drop position in waterfall layout.\n // Reordering doesn't make sense because the items don't have a deterministic order.\n return {\n type: 'item',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f,UAAU,UAAU,GAAG;YACzB;QACF;QAEA,OAAO;IACT;IAEA,2EAA2E;IAC3E,mGAAmG;IACnG,YAAY,IAAS,EAAE,EAAO,EAAS;QACrC,IAAI,iBAAiB,IAAI,CAAC,aAAa,CAAC;QACxC,IAAI,eAAe,IAAI,CAAC,aAAa,CAAC;QACtC,IAAI,CAAC,kBAAkB,CAAC,cACtB,OAAO,EAAE;QAGX,6DAA6D;QAC7D,4DAA4D;QAC5D,IAAI,OAAO,eAAe,IAAI,CAAC,KAAK,CAAC,aAAa,IAAI;QACtD,IAAI,OAAc,EAAE;QACpB,KAAK,IAAI,cAAc,IAAI,CAAC,WAAW,CAAC,MAAM,GAC5C,IAAI,KAAK,YAAY,CAAC,WAAW,IAAI,EAAE,IAAI,GAAG,WAAW,IAAI,CAAC,IAAI,GAAG,GACnE,KAAK,IAAI,CAAC,WAAW,GAAG;QAG5B,OAAO;IACT;IAEA,uBAAuB,CAAS,EAAE,CAAS,EAAc;QACvD,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,GAC5B,OAAO;YAAC,MAAM;QAAM;QAGtB,KAAK,IAAI,CAAC,WAAW,CAAE,WAAW,CAAC,CAAC;QACpC,KAAK,IAAI,CAAC,WAAW,CAAE,WAAW,CAAC,CAAC;QACpC,IAAI,MAAM,IAAI,CAAC,WAAW,CAAE,UAAU,CAAC,IAAI,CAAA,GAAA,oCAAI,EAAE,GAAG;QACpD,IAAI,OAAO,MACT,OAAO;YAAC,MAAM;QAAM;QAGtB,uDAAuD;QACvD,oFAAoF;QACpF,OAAO;YACL,MAAM;iBACN;YACA,cAAc;QAChB;IACF;;QA/PK,qBACG,cAAoB,IAAI,CAAA,GAAA,mCAAG,UAC3B,cAA6C,IAAI,YAC/C,aAAa,QACb,yBAAyB,QAC3B,SAAiB;;AA2P3B","sources":["packages/@react-stately/layout/src/WaterfallLayout.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, Key, LayoutDelegate, Node} from '@react-types/shared';\nimport {InvalidationContext, Layout, LayoutInfo, Point, Rect, Size} from '@react-stately/virtualizer';\n\nexport interface WaterfallLayoutOptions {\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 * 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\nclass WaterfallLayoutInfo extends LayoutInfo {\n column = 0;\n\n copy(): WaterfallLayoutInfo {\n let res = super.copy() as WaterfallLayoutInfo;\n res.column = this.column;\n return res;\n }\n}\n\nconst DEFAULT_OPTIONS = {\n minItemSize: new Size(200, 200),\n maxItemSize: new Size(Infinity, Infinity),\n minSpace: new Size(18, 18),\n maxSpace: Infinity,\n maxColumns: Infinity,\n dropIndicatorThickness: 2\n};\n\nexport class WaterfallLayout<T extends object, O extends WaterfallLayoutOptions = WaterfallLayoutOptions> extends Layout<Node<T>, O> implements LayoutDelegate, DropTargetDelegate {\n private contentSize: Size = new Size();\n private layoutInfos: Map<Key, WaterfallLayoutInfo> = new Map();\n protected numColumns = 0;\n protected dropIndicatorThickness = 2;\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.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 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 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\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.margin = Math.floor((visibleWidth - numColumns * itemWidth - horizontalSpacing * (numColumns + 1)) / 2);\n\n // Setup an array of column heights\n let columnHeights = Array(numColumns).fill(minSpace.height);\n let newLayoutInfos = new Map();\n let addNode = (key: Key, node: Node<T>) => {\n let oldLayoutInfo = this.layoutInfos.get(key);\n let height = itemHeight;\n let estimatedSize = true;\n if (oldLayoutInfo) {\n height = oldLayoutInfo.rect.height;\n estimatedSize = invalidationContext.sizeChanged || oldLayoutInfo.estimatedSize || oldLayoutInfo.content !== node;\n }\n\n // Figure out which column to place the item in, and compute its position.\n // Preserve the previous column index so items don't jump around during resizing unless the number of columns changed.\n let prevColumn = numColumns === this.numColumns && oldLayoutInfo && oldLayoutInfo.rect.y < this.virtualizer!.visibleRect.maxY ? oldLayoutInfo.column : undefined;\n let column = prevColumn ?? columnHeights.reduce((minIndex, h, i) => h < columnHeights[minIndex] ? i : minIndex, 0);\n let x = horizontalSpacing + column * (itemWidth + horizontalSpacing) + this.margin;\n let y = columnHeights[column];\n\n let rect = new Rect(x, y, itemWidth, height);\n let layoutInfo = new WaterfallLayoutInfo(node.type, key, rect);\n layoutInfo.estimatedSize = estimatedSize;\n layoutInfo.allowOverflow = true;\n layoutInfo.content = node;\n layoutInfo.column = column;\n newLayoutInfos.set(key, layoutInfo);\n\n columnHeights[column] += layoutInfo.rect.height + minSpace.height;\n };\n\n let collection = this.virtualizer!.collection;\n let skeletonCount = 0;\n for (let node of collection) {\n if (node.type === 'skeleton') {\n // Add skeleton cards until every column has at least one, and we fill the viewport.\n let startingHeights = [...columnHeights];\n while (\n !columnHeights.every((h, i) => h !== startingHeights[i]) ||\n Math.min(...columnHeights) < this.virtualizer!.visibleRect.height\n ) {\n let key = `${node.key}-${skeletonCount++}`;\n let content = this.layoutInfos.get(key)?.content || {...node};\n addNode(key, content);\n }\n break;\n } else if (node.type !== 'loader') {\n addNode(node.key, node);\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 // Add it under the first column for simplicity\n let lastNode = collection.getItem(collection.getLastKey()!);\n if (lastNode?.type === 'loader') {\n let rect = new Rect(horizontalSpacing, columnHeights[0], itemWidth, 0);\n let layoutInfo = new LayoutInfo('loader', lastNode.key, rect);\n newLayoutInfos.set(lastNode.key, layoutInfo);\n }\n\n // Reset all columns to the maximum for the next section. If loading, set to 0 so virtualizer doesn't render its body since there aren't items to render,\n // except if we are performing skeleton loading\n let isEmptyOrLoading = collection?.size === 0 && collection.getItem(collection.getFirstKey()!)?.type !== 'skeleton';\n let maxHeight = isEmptyOrLoading ? 0 : Math.max(...columnHeights);\n this.contentSize = new Size(this.virtualizer!.visibleRect.width, maxHeight);\n this.layoutInfos = newLayoutInfos;\n this.numColumns = numColumns;\n }\n\n getLayoutInfo(key: Key): LayoutInfo {\n return this.layoutInfos.get(key)!;\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 // Override keyboard navigation to work spatially.\n getKeyRightOf(key: Key): Key | null {\n let layoutInfo = this.getLayoutInfo(key);\n if (!layoutInfo) {\n return null;\n }\n\n let rect = new Rect(layoutInfo.rect.maxX, layoutInfo.rect.y, this.virtualizer!.visibleRect.maxX - layoutInfo.rect.maxX, layoutInfo.rect.height);\n let layoutInfos = this.getVisibleLayoutInfos(rect);\n let bestKey: Key | null = null;\n let bestDistance = Infinity;\n for (let candidate of layoutInfos) {\n if (candidate.key === key) {\n continue;\n }\n\n // Find the closest item in the x direction with the most overlap in the y direction.\n let deltaX = candidate.rect.x - rect.x;\n let overlapY = Math.min(candidate.rect.maxY, rect.maxY) - Math.max(candidate.rect.y, rect.y);\n let distance = deltaX - overlapY;\n if (distance < bestDistance) {\n bestDistance = distance;\n bestKey = candidate.key;\n }\n }\n\n return bestKey;\n }\n\n getKeyLeftOf(key: Key): Key | null {\n let layoutInfo = this.getLayoutInfo(key);\n if (!layoutInfo) {\n return null;\n }\n\n let rect = new Rect(0, layoutInfo.rect.y, layoutInfo.rect.x, layoutInfo.rect.height);\n let layoutInfos = this.getVisibleLayoutInfos(rect);\n let bestKey: Key | null = null;\n let bestDistance = Infinity;\n for (let candidate of layoutInfos) {\n if (candidate.key === key) {\n continue;\n }\n\n // Find the closest item in the x direction with the most overlap in the y direction.\n let deltaX = rect.maxX - candidate.rect.maxX;\n let overlapY = Math.min(candidate.rect.maxY, rect.maxY) - Math.max(candidate.rect.y, rect.y);\n let distance = deltaX - overlapY;\n if (distance < bestDistance) {\n bestDistance = distance;\n bestKey = candidate.key;\n }\n }\n\n return bestKey;\n }\n\n // This overrides the default behavior of shift selection to work spatially\n // rather than following the order of the items in the collection (which may appear unpredictable).\n getKeyRange(from: Key, to: Key): Key[] {\n let fromLayoutInfo = this.getLayoutInfo(from);\n let toLayoutInfo = this.getLayoutInfo(to);\n if (!fromLayoutInfo || !toLayoutInfo) {\n return [];\n }\n\n // Find items where half of the area intersects the rectangle\n // formed from the first item to the last item in the range.\n let rect = fromLayoutInfo.rect.union(toLayoutInfo.rect);\n let keys: Key[] = [];\n for (let layoutInfo of this.layoutInfos.values()) {\n if (rect.intersection(layoutInfo.rect).area > layoutInfo.rect.area / 2) {\n keys.push(layoutInfo.key);\n }\n }\n return keys;\n }\n\n getDropTargetFromPoint(x: number, y: number): 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 let key = this.virtualizer!.keyAtPoint(new Point(x, y));\n if (key == null) {\n return {type: 'root'};\n }\n\n // Only support \"on\" drop position in waterfall layout.\n // Reordering doesn't make sense because the items don't have a deterministic order.\n return {\n type: 'item',\n key,\n dropPosition: 'on'\n };\n }\n}\n"],"names":[],"version":3,"file":"WaterfallLayout.main.js.map"}
|
package/dist/WaterfallLayout.mjs
CHANGED
|
@@ -25,16 +25,17 @@ const $f483179558aa907f$var$DEFAULT_OPTIONS = {
|
|
|
25
25
|
minItemSize: new (0, $lFzwI$Size)(200, 200),
|
|
26
26
|
maxItemSize: new (0, $lFzwI$Size)(Infinity, Infinity),
|
|
27
27
|
minSpace: new (0, $lFzwI$Size)(18, 18),
|
|
28
|
+
maxSpace: Infinity,
|
|
28
29
|
maxColumns: Infinity,
|
|
29
30
|
dropIndicatorThickness: 2
|
|
30
31
|
};
|
|
31
32
|
class $f483179558aa907f$export$e9f7cda058ba8df8 extends (0, $lFzwI$Layout) {
|
|
32
33
|
shouldInvalidateLayoutOptions(newOptions, oldOptions) {
|
|
33
|
-
return newOptions.maxColumns !== oldOptions.maxColumns || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness || !(newOptions.minItemSize || $f483179558aa907f$var$DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || $f483179558aa907f$var$DEFAULT_OPTIONS.minItemSize) || !(newOptions.maxItemSize || $f483179558aa907f$var$DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || $f483179558aa907f$var$DEFAULT_OPTIONS.maxItemSize) || !(newOptions.minSpace || $f483179558aa907f$var$DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || $f483179558aa907f$var$DEFAULT_OPTIONS.minSpace);
|
|
34
|
+
return newOptions.maxColumns !== oldOptions.maxColumns || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness || !(newOptions.minItemSize || $f483179558aa907f$var$DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || $f483179558aa907f$var$DEFAULT_OPTIONS.minItemSize) || !(newOptions.maxItemSize || $f483179558aa907f$var$DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || $f483179558aa907f$var$DEFAULT_OPTIONS.maxItemSize) || !(newOptions.minSpace || $f483179558aa907f$var$DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || $f483179558aa907f$var$DEFAULT_OPTIONS.minSpace) || newOptions.maxHorizontalSpace !== oldOptions.maxHorizontalSpace;
|
|
34
35
|
}
|
|
35
36
|
update(invalidationContext) {
|
|
36
37
|
var _collection_getItem;
|
|
37
|
-
let { minItemSize: minItemSize = $f483179558aa907f$var$DEFAULT_OPTIONS.minItemSize, maxItemSize: maxItemSize = $f483179558aa907f$var$DEFAULT_OPTIONS.maxItemSize, minSpace: minSpace = $f483179558aa907f$var$DEFAULT_OPTIONS.minSpace, maxColumns: maxColumns = $f483179558aa907f$var$DEFAULT_OPTIONS.maxColumns, dropIndicatorThickness: dropIndicatorThickness = $f483179558aa907f$var$DEFAULT_OPTIONS.dropIndicatorThickness } = invalidationContext.layoutOptions || {};
|
|
38
|
+
let { minItemSize: minItemSize = $f483179558aa907f$var$DEFAULT_OPTIONS.minItemSize, maxItemSize: maxItemSize = $f483179558aa907f$var$DEFAULT_OPTIONS.maxItemSize, minSpace: minSpace = $f483179558aa907f$var$DEFAULT_OPTIONS.minSpace, maxHorizontalSpace: maxHorizontalSpace = $f483179558aa907f$var$DEFAULT_OPTIONS.maxSpace, maxColumns: maxColumns = $f483179558aa907f$var$DEFAULT_OPTIONS.maxColumns, dropIndicatorThickness: dropIndicatorThickness = $f483179558aa907f$var$DEFAULT_OPTIONS.dropIndicatorThickness } = invalidationContext.layoutOptions || {};
|
|
38
39
|
this.dropIndicatorThickness = dropIndicatorThickness;
|
|
39
40
|
let visibleWidth = this.virtualizer.visibleRect.width;
|
|
40
41
|
// The max item width is always the entire viewport.
|
|
@@ -53,8 +54,9 @@ class $f483179558aa907f$export$e9f7cda058ba8df8 extends (0, $lFzwI$Layout) {
|
|
|
53
54
|
let t = (itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width);
|
|
54
55
|
let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);
|
|
55
56
|
itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));
|
|
56
|
-
// Compute the horizontal spacing and
|
|
57
|
-
let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));
|
|
57
|
+
// Compute the horizontal spacing, content height and horizontal margin
|
|
58
|
+
let horizontalSpacing = Math.min(Math.max(maxHorizontalSpace, minSpace.width), Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1)));
|
|
59
|
+
this.margin = Math.floor((visibleWidth - numColumns * itemWidth - horizontalSpacing * (numColumns + 1)) / 2);
|
|
58
60
|
// Setup an array of column heights
|
|
59
61
|
let columnHeights = Array(numColumns).fill(minSpace.height);
|
|
60
62
|
let newLayoutInfos = new Map();
|
|
@@ -70,7 +72,7 @@ class $f483179558aa907f$export$e9f7cda058ba8df8 extends (0, $lFzwI$Layout) {
|
|
|
70
72
|
// Preserve the previous column index so items don't jump around during resizing unless the number of columns changed.
|
|
71
73
|
let prevColumn = numColumns === this.numColumns && oldLayoutInfo && oldLayoutInfo.rect.y < this.virtualizer.visibleRect.maxY ? oldLayoutInfo.column : undefined;
|
|
72
74
|
let column = prevColumn !== null && prevColumn !== void 0 ? prevColumn : columnHeights.reduce((minIndex, h, i)=>h < columnHeights[minIndex] ? i : minIndex, 0);
|
|
73
|
-
let x = horizontalSpacing + column * (itemWidth + horizontalSpacing);
|
|
75
|
+
let x = horizontalSpacing + column * (itemWidth + horizontalSpacing) + this.margin;
|
|
74
76
|
let y = columnHeights[column];
|
|
75
77
|
let rect = new (0, $lFzwI$Rect)(x, y, itemWidth, height);
|
|
76
78
|
let layoutInfo = new $f483179558aa907f$var$WaterfallLayoutInfo(node.type, key, rect);
|
|
@@ -212,7 +214,7 @@ class $f483179558aa907f$export$e9f7cda058ba8df8 extends (0, $lFzwI$Layout) {
|
|
|
212
214
|
};
|
|
213
215
|
}
|
|
214
216
|
constructor(...args){
|
|
215
|
-
super(...args), this.contentSize = new (0, $lFzwI$Size)(), this.layoutInfos = new Map(), this.numColumns = 0, this.dropIndicatorThickness = 2;
|
|
217
|
+
super(...args), this.contentSize = new (0, $lFzwI$Size)(), this.layoutInfos = new Map(), this.numColumns = 0, this.dropIndicatorThickness = 2, this.margin = 0;
|
|
216
218
|
}
|
|
217
219
|
}
|
|
218
220
|
|
|
@@ -25,16 +25,17 @@ const $f483179558aa907f$var$DEFAULT_OPTIONS = {
|
|
|
25
25
|
minItemSize: new (0, $lFzwI$Size)(200, 200),
|
|
26
26
|
maxItemSize: new (0, $lFzwI$Size)(Infinity, Infinity),
|
|
27
27
|
minSpace: new (0, $lFzwI$Size)(18, 18),
|
|
28
|
+
maxSpace: Infinity,
|
|
28
29
|
maxColumns: Infinity,
|
|
29
30
|
dropIndicatorThickness: 2
|
|
30
31
|
};
|
|
31
32
|
class $f483179558aa907f$export$e9f7cda058ba8df8 extends (0, $lFzwI$Layout) {
|
|
32
33
|
shouldInvalidateLayoutOptions(newOptions, oldOptions) {
|
|
33
|
-
return newOptions.maxColumns !== oldOptions.maxColumns || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness || !(newOptions.minItemSize || $f483179558aa907f$var$DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || $f483179558aa907f$var$DEFAULT_OPTIONS.minItemSize) || !(newOptions.maxItemSize || $f483179558aa907f$var$DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || $f483179558aa907f$var$DEFAULT_OPTIONS.maxItemSize) || !(newOptions.minSpace || $f483179558aa907f$var$DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || $f483179558aa907f$var$DEFAULT_OPTIONS.minSpace);
|
|
34
|
+
return newOptions.maxColumns !== oldOptions.maxColumns || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness || !(newOptions.minItemSize || $f483179558aa907f$var$DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || $f483179558aa907f$var$DEFAULT_OPTIONS.minItemSize) || !(newOptions.maxItemSize || $f483179558aa907f$var$DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || $f483179558aa907f$var$DEFAULT_OPTIONS.maxItemSize) || !(newOptions.minSpace || $f483179558aa907f$var$DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || $f483179558aa907f$var$DEFAULT_OPTIONS.minSpace) || newOptions.maxHorizontalSpace !== oldOptions.maxHorizontalSpace;
|
|
34
35
|
}
|
|
35
36
|
update(invalidationContext) {
|
|
36
37
|
var _collection_getItem;
|
|
37
|
-
let { minItemSize: minItemSize = $f483179558aa907f$var$DEFAULT_OPTIONS.minItemSize, maxItemSize: maxItemSize = $f483179558aa907f$var$DEFAULT_OPTIONS.maxItemSize, minSpace: minSpace = $f483179558aa907f$var$DEFAULT_OPTIONS.minSpace, maxColumns: maxColumns = $f483179558aa907f$var$DEFAULT_OPTIONS.maxColumns, dropIndicatorThickness: dropIndicatorThickness = $f483179558aa907f$var$DEFAULT_OPTIONS.dropIndicatorThickness } = invalidationContext.layoutOptions || {};
|
|
38
|
+
let { minItemSize: minItemSize = $f483179558aa907f$var$DEFAULT_OPTIONS.minItemSize, maxItemSize: maxItemSize = $f483179558aa907f$var$DEFAULT_OPTIONS.maxItemSize, minSpace: minSpace = $f483179558aa907f$var$DEFAULT_OPTIONS.minSpace, maxHorizontalSpace: maxHorizontalSpace = $f483179558aa907f$var$DEFAULT_OPTIONS.maxSpace, maxColumns: maxColumns = $f483179558aa907f$var$DEFAULT_OPTIONS.maxColumns, dropIndicatorThickness: dropIndicatorThickness = $f483179558aa907f$var$DEFAULT_OPTIONS.dropIndicatorThickness } = invalidationContext.layoutOptions || {};
|
|
38
39
|
this.dropIndicatorThickness = dropIndicatorThickness;
|
|
39
40
|
let visibleWidth = this.virtualizer.visibleRect.width;
|
|
40
41
|
// The max item width is always the entire viewport.
|
|
@@ -53,8 +54,9 @@ class $f483179558aa907f$export$e9f7cda058ba8df8 extends (0, $lFzwI$Layout) {
|
|
|
53
54
|
let t = (itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width);
|
|
54
55
|
let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);
|
|
55
56
|
itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));
|
|
56
|
-
// Compute the horizontal spacing and
|
|
57
|
-
let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));
|
|
57
|
+
// Compute the horizontal spacing, content height and horizontal margin
|
|
58
|
+
let horizontalSpacing = Math.min(Math.max(maxHorizontalSpace, minSpace.width), Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1)));
|
|
59
|
+
this.margin = Math.floor((visibleWidth - numColumns * itemWidth - horizontalSpacing * (numColumns + 1)) / 2);
|
|
58
60
|
// Setup an array of column heights
|
|
59
61
|
let columnHeights = Array(numColumns).fill(minSpace.height);
|
|
60
62
|
let newLayoutInfos = new Map();
|
|
@@ -70,7 +72,7 @@ class $f483179558aa907f$export$e9f7cda058ba8df8 extends (0, $lFzwI$Layout) {
|
|
|
70
72
|
// Preserve the previous column index so items don't jump around during resizing unless the number of columns changed.
|
|
71
73
|
let prevColumn = numColumns === this.numColumns && oldLayoutInfo && oldLayoutInfo.rect.y < this.virtualizer.visibleRect.maxY ? oldLayoutInfo.column : undefined;
|
|
72
74
|
let column = prevColumn !== null && prevColumn !== void 0 ? prevColumn : columnHeights.reduce((minIndex, h, i)=>h < columnHeights[minIndex] ? i : minIndex, 0);
|
|
73
|
-
let x = horizontalSpacing + column * (itemWidth + horizontalSpacing);
|
|
75
|
+
let x = horizontalSpacing + column * (itemWidth + horizontalSpacing) + this.margin;
|
|
74
76
|
let y = columnHeights[column];
|
|
75
77
|
let rect = new (0, $lFzwI$Rect)(x, y, itemWidth, height);
|
|
76
78
|
let layoutInfo = new $f483179558aa907f$var$WaterfallLayoutInfo(node.type, key, rect);
|
|
@@ -212,7 +214,7 @@ class $f483179558aa907f$export$e9f7cda058ba8df8 extends (0, $lFzwI$Layout) {
|
|
|
212
214
|
};
|
|
213
215
|
}
|
|
214
216
|
constructor(...args){
|
|
215
|
-
super(...args), this.contentSize = new (0, $lFzwI$Size)(), this.layoutInfos = new Map(), this.numColumns = 0, this.dropIndicatorThickness = 2;
|
|
217
|
+
super(...args), this.contentSize = new (0, $lFzwI$Size)(), this.layoutInfos = new Map(), this.numColumns = 0, this.dropIndicatorThickness = 2, this.margin = 0;
|
|
216
218
|
}
|
|
217
219
|
}
|
|
218
220
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAiCD,MAAM,kDAA4B,CAAA,GAAA,iBAAS;IAGzC,OAA4B;QAC1B,IAAI,MAAM,KAAK,CAAC;QAChB,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM;QACxB,OAAO;IACT;;QAPF,qBACE,SAAS;;AAOX;AAEA,MAAM,wCAAkB;IACtB,aAAa,IAAI,CAAA,GAAA,WAAG,EAAE,KAAK;IAC3B,aAAa,IAAI,CAAA,GAAA,WAAG,EAAE,UAAU;IAChC,UAAU,IAAI,CAAA,GAAA,WAAG,EAAE,IAAI;IACvB,YAAY;IACZ,wBAAwB;AAC1B;AAEO,MAAM,kDAAqG,CAAA,GAAA,aAAK;IAMrH,8BA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AC,IAAI,CAAA,GAAA,YAAI,EAAE,GAAG;QACpD,IAAI,OAAO,MACT,OAAO;YAAC,MAAM;QAAM;QAGtB,uDAAuD;QACvD,oFAAoF;QACpF,OAAO;YACL,MAAM;iBACN;YACA,cAAc;QAChB;IACF;;QA3PK,qBACG,cAAoB,IAAI,CAAA,GAAA,WAAG,UAC3B,cAA6C,IAAI,YAC/C,aAAa,QACb,yBAAyB;;AAwPrC","sources":["packages/@react-stately/layout/src/WaterfallLayout.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, Key, LayoutDelegate, Node} from '@react-types/shared';\nimport {InvalidationContext, Layout, LayoutInfo, Point, Rect, Size} from '@react-stately/virtualizer';\n\nexport interface WaterfallLayoutOptions {\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 * 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\nclass WaterfallLayoutInfo extends LayoutInfo {\n column = 0;\n\n copy(): WaterfallLayoutInfo {\n let res = super.copy() as WaterfallLayoutInfo;\n res.column = this.column;\n return res;\n }\n}\n\nconst DEFAULT_OPTIONS = {\n minItemSize: new Size(200, 200),\n maxItemSize: new Size(Infinity, Infinity),\n minSpace: new Size(18, 18),\n maxColumns: Infinity,\n dropIndicatorThickness: 2\n};\n\nexport class WaterfallLayout<T extends object, O extends WaterfallLayoutOptions = WaterfallLayoutOptions> extends Layout<Node<T>, O> implements LayoutDelegate, DropTargetDelegate {\n private contentSize: Size = new Size();\n private layoutInfos: Map<Key, WaterfallLayoutInfo> = new Map();\n protected numColumns = 0;\n protected dropIndicatorThickness = 2;\n\n shouldInvalidateLayoutOptions(newOptions: O, oldOptions: O): boolean {\n return newOptions.maxColumns !== oldOptions.maxColumns\n || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness\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 minSpace = DEFAULT_OPTIONS.minSpace,\n maxColumns = DEFAULT_OPTIONS.maxColumns,\n dropIndicatorThickness = DEFAULT_OPTIONS.dropIndicatorThickness\n } = invalidationContext.layoutOptions || {};\n this.dropIndicatorThickness = dropIndicatorThickness;\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\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\n // Setup an array of column heights\n let columnHeights = Array(numColumns).fill(minSpace.height);\n let newLayoutInfos = new Map();\n let addNode = (key: Key, node: Node<T>) => {\n let oldLayoutInfo = this.layoutInfos.get(key);\n let height = itemHeight;\n let estimatedSize = true;\n if (oldLayoutInfo) {\n height = oldLayoutInfo.rect.height;\n estimatedSize = invalidationContext.sizeChanged || oldLayoutInfo.estimatedSize || oldLayoutInfo.content !== node;\n }\n\n // Figure out which column to place the item in, and compute its position.\n // Preserve the previous column index so items don't jump around during resizing unless the number of columns changed.\n let prevColumn = numColumns === this.numColumns && oldLayoutInfo && oldLayoutInfo.rect.y < this.virtualizer!.visibleRect.maxY ? oldLayoutInfo.column : undefined;\n let column = prevColumn ?? columnHeights.reduce((minIndex, h, i) => h < columnHeights[minIndex] ? i : minIndex, 0);\n let x = horizontalSpacing + column * (itemWidth + horizontalSpacing);\n let y = columnHeights[column];\n\n let rect = new Rect(x, y, itemWidth, height);\n let layoutInfo = new WaterfallLayoutInfo(node.type, key, rect);\n layoutInfo.estimatedSize = estimatedSize;\n layoutInfo.allowOverflow = true;\n layoutInfo.content = node;\n layoutInfo.column = column;\n newLayoutInfos.set(key, layoutInfo);\n\n columnHeights[column] += layoutInfo.rect.height + minSpace.height;\n };\n\n let collection = this.virtualizer!.collection;\n let skeletonCount = 0;\n for (let node of collection) {\n if (node.type === 'skeleton') {\n // Add skeleton cards until every column has at least one, and we fill the viewport.\n let startingHeights = [...columnHeights];\n while (\n !columnHeights.every((h, i) => h !== startingHeights[i]) ||\n Math.min(...columnHeights) < this.virtualizer!.visibleRect.height\n ) {\n let key = `${node.key}-${skeletonCount++}`;\n let content = this.layoutInfos.get(key)?.content || {...node};\n addNode(key, content);\n }\n break;\n } else if (node.type !== 'loader') {\n addNode(node.key, node);\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 // Add it under the first column for simplicity\n let lastNode = collection.getItem(collection.getLastKey()!);\n if (lastNode?.type === 'loader') {\n let rect = new Rect(horizontalSpacing, columnHeights[0], itemWidth, 0);\n let layoutInfo = new LayoutInfo('loader', lastNode.key, rect);\n newLayoutInfos.set(lastNode.key, layoutInfo);\n }\n\n // Reset all columns to the maximum for the next section. If loading, set to 0 so virtualizer doesn't render its body since there aren't items to render,\n // except if we are performing skeleton loading\n let isEmptyOrLoading = collection?.size === 0 && collection.getItem(collection.getFirstKey()!)?.type !== 'skeleton';\n let maxHeight = isEmptyOrLoading ? 0 : Math.max(...columnHeights);\n this.contentSize = new Size(this.virtualizer!.visibleRect.width, maxHeight);\n this.layoutInfos = newLayoutInfos;\n this.numColumns = numColumns;\n }\n\n getLayoutInfo(key: Key): LayoutInfo {\n return this.layoutInfos.get(key)!;\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 // Override keyboard navigation to work spatially.\n getKeyRightOf(key: Key): Key | null {\n let layoutInfo = this.getLayoutInfo(key);\n if (!layoutInfo) {\n return null;\n }\n\n let rect = new Rect(layoutInfo.rect.maxX, layoutInfo.rect.y, this.virtualizer!.visibleRect.maxX - layoutInfo.rect.maxX, layoutInfo.rect.height);\n let layoutInfos = this.getVisibleLayoutInfos(rect);\n let bestKey: Key | null = null;\n let bestDistance = Infinity;\n for (let candidate of layoutInfos) {\n if (candidate.key === key) {\n continue;\n }\n\n // Find the closest item in the x direction with the most overlap in the y direction.\n let deltaX = candidate.rect.x - rect.x;\n let overlapY = Math.min(candidate.rect.maxY, rect.maxY) - Math.max(candidate.rect.y, rect.y);\n let distance = deltaX - overlapY;\n if (distance < bestDistance) {\n bestDistance = distance;\n bestKey = candidate.key;\n }\n }\n\n return bestKey;\n }\n\n getKeyLeftOf(key: Key): Key | null {\n let layoutInfo = this.getLayoutInfo(key);\n if (!layoutInfo) {\n return null;\n }\n\n let rect = new Rect(0, layoutInfo.rect.y, layoutInfo.rect.x, layoutInfo.rect.height);\n let layoutInfos = this.getVisibleLayoutInfos(rect);\n let bestKey: Key | null = null;\n let bestDistance = Infinity;\n for (let candidate of layoutInfos) {\n if (candidate.key === key) {\n continue;\n }\n\n // Find the closest item in the x direction with the most overlap in the y direction.\n let deltaX = rect.maxX - candidate.rect.maxX;\n let overlapY = Math.min(candidate.rect.maxY, rect.maxY) - Math.max(candidate.rect.y, rect.y);\n let distance = deltaX - overlapY;\n if (distance < bestDistance) {\n bestDistance = distance;\n bestKey = candidate.key;\n }\n }\n\n return bestKey;\n }\n\n // This overrides the default behavior of shift selection to work spatially\n // rather than following the order of the items in the collection (which may appear unpredictable).\n getKeyRange(from: Key, to: Key): Key[] {\n let fromLayoutInfo = this.getLayoutInfo(from);\n let toLayoutInfo = this.getLayoutInfo(to);\n if (!fromLayoutInfo || !toLayoutInfo) {\n return [];\n }\n\n // Find items where half of the area intersects the rectangle\n // formed from the first item to the last item in the range.\n let rect = fromLayoutInfo.rect.union(toLayoutInfo.rect);\n let keys: Key[] = [];\n for (let layoutInfo of this.layoutInfos.values()) {\n if (rect.intersection(layoutInfo.rect).area > layoutInfo.rect.area / 2) {\n keys.push(layoutInfo.key);\n }\n }\n return keys;\n }\n\n getDropTargetFromPoint(x: number, y: number): 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 let key = this.virtualizer!.keyAtPoint(new Point(x, y));\n if (key == null) {\n return {type: 'root'};\n }\n\n // Only support \"on\" drop position in waterfall layout.\n // Reordering doesn't make sense because the items don't have a deterministic order.\n return {\n type: 'item',\n key,\n dropPosition: 'on'\n };\n }\n}\n"],"names":[],"version":3,"file":"WaterfallLayout.module.js.map"}
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAsCD,MAAM,kDAA4B,CAAA,GAAA,iBAAS;IAGzC,OAA4B;QAC1B,IAAI,MAAM,KAAK,CAAC;QAChB,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM;QACxB,OAAO;IACT;;QAPF,qBACE,SAAS;;AAOX;AAEA,MAAM,wCAAkB;IACtB,aAAa,IAAI,CAAA,GAAA,WAAG,EAAE,KAAK;IAC3B,aAAa,IAAI,CAAA,GAAA,WAAG,EAAE,UAAU;IAChC,UAAU,IAAI,CAAA,GAAA,WAAG,EAAE,IAAI;IACvB,UAAU;IACV,YAAY;IACZ,wBAAwB;AAC1B;AAEO,MAAM,kDAAqG,CAAA,GAAA,aAAK;IAOrH,8BAA8B,UAAa,EAAE,UAAa,EAAW;QACnE,OAAO,WAAW,UAAU,KAAK,WAAW,UAAU,IACjD,WAAW,sBAAsB,KAAK,WAAW,sBAAsB,IACtE,CAAC,AAAC,CAAA,WAAW,WAAW,IAAI,sCAAgB,WAAW,AAAD,EAAG,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AAK,IAAI,CAAC,WAAW,CAAE,WAAW,CAAC,CAAC;QACpC,IAAI,MAAM,IAAI,CAAC,WAAW,CAAE,UAAU,CAAC,IAAI,CAAA,GAAA,YAAI,EAAE,GAAG;QACpD,IAAI,OAAO,MACT,OAAO;YAAC,MAAM;QAAM;QAGtB,uDAAuD;QACvD,oFAAoF;QACpF,OAAO;YACL,MAAM;iBACN;YACA,cAAc;QAChB;IACF;;QA/PK,qBACG,cAAoB,IAAI,CAAA,GAAA,WAAG,UAC3B,cAA6C,IAAI,YAC/C,aAAa,QACb,yBAAyB,QAC3B,SAAiB;;AA2P3B","sources":["packages/@react-stately/layout/src/WaterfallLayout.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, Key, LayoutDelegate, Node} from '@react-types/shared';\nimport {InvalidationContext, Layout, LayoutInfo, Point, Rect, Size} from '@react-stately/virtualizer';\n\nexport interface WaterfallLayoutOptions {\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 * 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\nclass WaterfallLayoutInfo extends LayoutInfo {\n column = 0;\n\n copy(): WaterfallLayoutInfo {\n let res = super.copy() as WaterfallLayoutInfo;\n res.column = this.column;\n return res;\n }\n}\n\nconst DEFAULT_OPTIONS = {\n minItemSize: new Size(200, 200),\n maxItemSize: new Size(Infinity, Infinity),\n minSpace: new Size(18, 18),\n maxSpace: Infinity,\n maxColumns: Infinity,\n dropIndicatorThickness: 2\n};\n\nexport class WaterfallLayout<T extends object, O extends WaterfallLayoutOptions = WaterfallLayoutOptions> extends Layout<Node<T>, O> implements LayoutDelegate, DropTargetDelegate {\n private contentSize: Size = new Size();\n private layoutInfos: Map<Key, WaterfallLayoutInfo> = new Map();\n protected numColumns = 0;\n protected dropIndicatorThickness = 2;\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.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 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 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\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.margin = Math.floor((visibleWidth - numColumns * itemWidth - horizontalSpacing * (numColumns + 1)) / 2);\n\n // Setup an array of column heights\n let columnHeights = Array(numColumns).fill(minSpace.height);\n let newLayoutInfos = new Map();\n let addNode = (key: Key, node: Node<T>) => {\n let oldLayoutInfo = this.layoutInfos.get(key);\n let height = itemHeight;\n let estimatedSize = true;\n if (oldLayoutInfo) {\n height = oldLayoutInfo.rect.height;\n estimatedSize = invalidationContext.sizeChanged || oldLayoutInfo.estimatedSize || oldLayoutInfo.content !== node;\n }\n\n // Figure out which column to place the item in, and compute its position.\n // Preserve the previous column index so items don't jump around during resizing unless the number of columns changed.\n let prevColumn = numColumns === this.numColumns && oldLayoutInfo && oldLayoutInfo.rect.y < this.virtualizer!.visibleRect.maxY ? oldLayoutInfo.column : undefined;\n let column = prevColumn ?? columnHeights.reduce((minIndex, h, i) => h < columnHeights[minIndex] ? i : minIndex, 0);\n let x = horizontalSpacing + column * (itemWidth + horizontalSpacing) + this.margin;\n let y = columnHeights[column];\n\n let rect = new Rect(x, y, itemWidth, height);\n let layoutInfo = new WaterfallLayoutInfo(node.type, key, rect);\n layoutInfo.estimatedSize = estimatedSize;\n layoutInfo.allowOverflow = true;\n layoutInfo.content = node;\n layoutInfo.column = column;\n newLayoutInfos.set(key, layoutInfo);\n\n columnHeights[column] += layoutInfo.rect.height + minSpace.height;\n };\n\n let collection = this.virtualizer!.collection;\n let skeletonCount = 0;\n for (let node of collection) {\n if (node.type === 'skeleton') {\n // Add skeleton cards until every column has at least one, and we fill the viewport.\n let startingHeights = [...columnHeights];\n while (\n !columnHeights.every((h, i) => h !== startingHeights[i]) ||\n Math.min(...columnHeights) < this.virtualizer!.visibleRect.height\n ) {\n let key = `${node.key}-${skeletonCount++}`;\n let content = this.layoutInfos.get(key)?.content || {...node};\n addNode(key, content);\n }\n break;\n } else if (node.type !== 'loader') {\n addNode(node.key, node);\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 // Add it under the first column for simplicity\n let lastNode = collection.getItem(collection.getLastKey()!);\n if (lastNode?.type === 'loader') {\n let rect = new Rect(horizontalSpacing, columnHeights[0], itemWidth, 0);\n let layoutInfo = new LayoutInfo('loader', lastNode.key, rect);\n newLayoutInfos.set(lastNode.key, layoutInfo);\n }\n\n // Reset all columns to the maximum for the next section. If loading, set to 0 so virtualizer doesn't render its body since there aren't items to render,\n // except if we are performing skeleton loading\n let isEmptyOrLoading = collection?.size === 0 && collection.getItem(collection.getFirstKey()!)?.type !== 'skeleton';\n let maxHeight = isEmptyOrLoading ? 0 : Math.max(...columnHeights);\n this.contentSize = new Size(this.virtualizer!.visibleRect.width, maxHeight);\n this.layoutInfos = newLayoutInfos;\n this.numColumns = numColumns;\n }\n\n getLayoutInfo(key: Key): LayoutInfo {\n return this.layoutInfos.get(key)!;\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 // Override keyboard navigation to work spatially.\n getKeyRightOf(key: Key): Key | null {\n let layoutInfo = this.getLayoutInfo(key);\n if (!layoutInfo) {\n return null;\n }\n\n let rect = new Rect(layoutInfo.rect.maxX, layoutInfo.rect.y, this.virtualizer!.visibleRect.maxX - layoutInfo.rect.maxX, layoutInfo.rect.height);\n let layoutInfos = this.getVisibleLayoutInfos(rect);\n let bestKey: Key | null = null;\n let bestDistance = Infinity;\n for (let candidate of layoutInfos) {\n if (candidate.key === key) {\n continue;\n }\n\n // Find the closest item in the x direction with the most overlap in the y direction.\n let deltaX = candidate.rect.x - rect.x;\n let overlapY = Math.min(candidate.rect.maxY, rect.maxY) - Math.max(candidate.rect.y, rect.y);\n let distance = deltaX - overlapY;\n if (distance < bestDistance) {\n bestDistance = distance;\n bestKey = candidate.key;\n }\n }\n\n return bestKey;\n }\n\n getKeyLeftOf(key: Key): Key | null {\n let layoutInfo = this.getLayoutInfo(key);\n if (!layoutInfo) {\n return null;\n }\n\n let rect = new Rect(0, layoutInfo.rect.y, layoutInfo.rect.x, layoutInfo.rect.height);\n let layoutInfos = this.getVisibleLayoutInfos(rect);\n let bestKey: Key | null = null;\n let bestDistance = Infinity;\n for (let candidate of layoutInfos) {\n if (candidate.key === key) {\n continue;\n }\n\n // Find the closest item in the x direction with the most overlap in the y direction.\n let deltaX = rect.maxX - candidate.rect.maxX;\n let overlapY = Math.min(candidate.rect.maxY, rect.maxY) - Math.max(candidate.rect.y, rect.y);\n let distance = deltaX - overlapY;\n if (distance < bestDistance) {\n bestDistance = distance;\n bestKey = candidate.key;\n }\n }\n\n return bestKey;\n }\n\n // This overrides the default behavior of shift selection to work spatially\n // rather than following the order of the items in the collection (which may appear unpredictable).\n getKeyRange(from: Key, to: Key): Key[] {\n let fromLayoutInfo = this.getLayoutInfo(from);\n let toLayoutInfo = this.getLayoutInfo(to);\n if (!fromLayoutInfo || !toLayoutInfo) {\n return [];\n }\n\n // Find items where half of the area intersects the rectangle\n // formed from the first item to the last item in the range.\n let rect = fromLayoutInfo.rect.union(toLayoutInfo.rect);\n let keys: Key[] = [];\n for (let layoutInfo of this.layoutInfos.values()) {\n if (rect.intersection(layoutInfo.rect).area > layoutInfo.rect.area / 2) {\n keys.push(layoutInfo.key);\n }\n }\n return keys;\n }\n\n getDropTargetFromPoint(x: number, y: number): 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 let key = this.virtualizer!.keyAtPoint(new Point(x, y));\n if (key == null) {\n return {type: 'root'};\n }\n\n // Only support \"on\" drop position in waterfall layout.\n // Reordering doesn't make sense because the items don't have a deterministic order.\n return {\n type: 'item',\n key,\n dropPosition: 'on'\n };\n }\n}\n"],"names":[],"version":3,"file":"WaterfallLayout.module.js.map"}
|
package/dist/types.d.ts
CHANGED
|
@@ -25,6 +25,11 @@ export interface GridLayoutOptions {
|
|
|
25
25
|
* @default 18 x 18
|
|
26
26
|
*/
|
|
27
27
|
minSpace?: Size;
|
|
28
|
+
/**
|
|
29
|
+
* The maximum allowed horizontal space between items.
|
|
30
|
+
* @default Infinity
|
|
31
|
+
*/
|
|
32
|
+
maxHorizontalSpace?: number;
|
|
28
33
|
/**
|
|
29
34
|
* The maximum number of columns.
|
|
30
35
|
* @default Infinity
|
|
@@ -190,6 +195,11 @@ export interface WaterfallLayoutOptions {
|
|
|
190
195
|
* @default 18 x 18
|
|
191
196
|
*/
|
|
192
197
|
minSpace?: Size;
|
|
198
|
+
/**
|
|
199
|
+
* The maximum allowed horizontal space between items.
|
|
200
|
+
* @default Infinity
|
|
201
|
+
*/
|
|
202
|
+
maxHorizontalSpace?: number;
|
|
193
203
|
/**
|
|
194
204
|
* The maximum number of columns.
|
|
195
205
|
* @default Infinity
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;AAeA;IACE;;;OAGG;IACH,WAAW,CAAC,EAAE,IAAI,CAAC;IACnB;;;OAGG;IACH,WAAW,CAAC,EAAE,IAAI,CAAC;IACnB;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAA;CAChC;
|
|
1
|
+
{"mappings":";;;;AAeA;IACE;;;OAGG;IACH,WAAW,CAAC,EAAE,IAAI,CAAC;IACnB;;;OAGG;IACH,WAAW,CAAC,EAAE,IAAI,CAAC;IACnB;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAA;CAChC;AAYD;;;;;GAKG;AACH,wBAAwB,CAAC,EAAE,CAAC,SAAS,iBAAiB,GAAG,iBAAiB,CAAE,SAAQ,OAAO,KAAK,CAAC,CA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,EAAE,CAAC,CAAE,YAAW,cAAc,EAAE,kBAAkB;IAGhL,SAAS,CAAC,UAAU,SAAK;IACzB,SAAS,CAAC,sBAAsB,SAAK;IAGrC,6BAA6B,CAAC,UAAU,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,GAAG,OAAO;IASpE,MAAM,CAAC,mBAAmB,EAAE,oBAAoB,CAAC,CAAC,GAAG,IAAI;IA2GzD,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,UAAU;IAInC,cAAc,IAAI,IAAI;IAItB,qBAAqB,CAAC,IAAI,EAAE,IAAI,GAAG,UAAU,EAAE;IAU/C,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO;IAkB7C,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI;IA4BnC,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI;IA8BlC,WAAW,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,GAAG,GAAG,EAAE;IAmBtC,sBAAsB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,UAAU;CAoBzD","sources":["packages/@react-stately/layout/src/packages/@react-stately/layout/src/GridLayout.ts","packages/@react-stately/layout/src/packages/@react-stately/layout/src/ListLayout.ts","packages/@react-stately/layout/src/packages/@react-stately/layout/src/TableLayout.ts","packages/@react-stately/layout/src/packages/@react-stately/layout/src/WaterfallLayout.ts","packages/@react-stately/layout/src/packages/@react-stately/layout/src/index.ts","packages/@react-stately/layout/src/index.ts"],"sourcesContent":[null,null,null,null,null,"/*\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 */\nexport type {GridLayoutOptions} from './GridLayout';\nexport type {ListLayoutOptions, LayoutNode} from './ListLayout';\nexport type {TableLayoutProps} from './TableLayout';\nexport type {WaterfallLayoutOptions} from './WaterfallLayout';\nexport {GridLayout} from './GridLayout';\nexport {ListLayout} from './ListLayout';\nexport {TableLayout} from './TableLayout';\nexport {WaterfallLayout} from './WaterfallLayout';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/layout",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"url": "https://github.com/adobe/react-spectrum"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@react-stately/collections": "^3.12.
|
|
30
|
-
"@react-stately/table": "^3.
|
|
31
|
-
"@react-stately/virtualizer": "^4.4.
|
|
32
|
-
"@react-types/grid": "^3.3.
|
|
33
|
-
"@react-types/shared": "^3.
|
|
34
|
-
"@react-types/table": "^3.13.
|
|
29
|
+
"@react-stately/collections": "^3.12.7",
|
|
30
|
+
"@react-stately/table": "^3.15.0",
|
|
31
|
+
"@react-stately/virtualizer": "^4.4.3",
|
|
32
|
+
"@react-types/grid": "^3.3.5",
|
|
33
|
+
"@react-types/shared": "^3.32.0",
|
|
34
|
+
"@react-types/table": "^3.13.3",
|
|
35
35
|
"@swc/helpers": "^0.5.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "2c58ed3ddd9be9100af9b1d0cfd137fcdc95ba2d"
|
|
45
45
|
}
|
package/src/GridLayout.ts
CHANGED
|
@@ -36,6 +36,11 @@ export interface GridLayoutOptions {
|
|
|
36
36
|
* @default 18 x 18
|
|
37
37
|
*/
|
|
38
38
|
minSpace?: Size,
|
|
39
|
+
/**
|
|
40
|
+
* The maximum allowed horizontal space between items.
|
|
41
|
+
* @default Infinity
|
|
42
|
+
*/
|
|
43
|
+
maxHorizontalSpace?: number,
|
|
39
44
|
/**
|
|
40
45
|
* The maximum number of columns.
|
|
41
46
|
* @default Infinity
|
|
@@ -53,6 +58,7 @@ const DEFAULT_OPTIONS = {
|
|
|
53
58
|
maxItemSize: new Size(Infinity, Infinity),
|
|
54
59
|
preserveAspectRatio: false,
|
|
55
60
|
minSpace: new Size(18, 18),
|
|
61
|
+
maxSpace: Infinity,
|
|
56
62
|
maxColumns: Infinity,
|
|
57
63
|
dropIndicatorThickness: 2
|
|
58
64
|
};
|
|
@@ -69,6 +75,7 @@ export class GridLayout<T, O extends GridLayoutOptions = GridLayoutOptions> exte
|
|
|
69
75
|
protected numColumns: number = 0;
|
|
70
76
|
private contentSize: Size = new Size();
|
|
71
77
|
private layoutInfos: Map<Key, LayoutInfo> = new Map();
|
|
78
|
+
private margin: number = 0;
|
|
72
79
|
|
|
73
80
|
shouldInvalidateLayoutOptions(newOptions: O, oldOptions: O): boolean {
|
|
74
81
|
return newOptions.maxColumns !== oldOptions.maxColumns
|
|
@@ -76,7 +83,8 @@ export class GridLayout<T, O extends GridLayoutOptions = GridLayoutOptions> exte
|
|
|
76
83
|
|| newOptions.preserveAspectRatio !== oldOptions.preserveAspectRatio
|
|
77
84
|
|| (!(newOptions.minItemSize || DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || DEFAULT_OPTIONS.minItemSize))
|
|
78
85
|
|| (!(newOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize))
|
|
79
|
-
|| (!(newOptions.minSpace || DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || DEFAULT_OPTIONS.minSpace))
|
|
86
|
+
|| (!(newOptions.minSpace || DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || DEFAULT_OPTIONS.minSpace))
|
|
87
|
+
|| newOptions.maxHorizontalSpace !== oldOptions.maxHorizontalSpace;
|
|
80
88
|
}
|
|
81
89
|
|
|
82
90
|
update(invalidationContext: InvalidationContext<O>): void {
|
|
@@ -85,6 +93,7 @@ export class GridLayout<T, O extends GridLayoutOptions = GridLayoutOptions> exte
|
|
|
85
93
|
maxItemSize = DEFAULT_OPTIONS.maxItemSize,
|
|
86
94
|
preserveAspectRatio = DEFAULT_OPTIONS.preserveAspectRatio,
|
|
87
95
|
minSpace = DEFAULT_OPTIONS.minSpace,
|
|
96
|
+
maxHorizontalSpace = DEFAULT_OPTIONS.maxSpace,
|
|
88
97
|
maxColumns = DEFAULT_OPTIONS.maxColumns,
|
|
89
98
|
dropIndicatorThickness = DEFAULT_OPTIONS.dropIndicatorThickness
|
|
90
99
|
} = invalidationContext.layoutOptions || {};
|
|
@@ -116,9 +125,10 @@ export class GridLayout<T, O extends GridLayoutOptions = GridLayoutOptions> exte
|
|
|
116
125
|
let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);
|
|
117
126
|
itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));
|
|
118
127
|
|
|
119
|
-
// Compute the horizontal spacing and
|
|
120
|
-
let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));
|
|
128
|
+
// Compute the horizontal spacing, content height and horizontal margin
|
|
129
|
+
let horizontalSpacing = Math.min(Math.max(maxHorizontalSpace, minSpace.width), Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1)));
|
|
121
130
|
this.gap = new Size(horizontalSpacing, minSpace.height);
|
|
131
|
+
this.margin = Math.floor((visibleWidth - numColumns * itemWidth - horizontalSpacing * (numColumns + 1)) / 2);
|
|
122
132
|
|
|
123
133
|
// If there is a skeleton loader within the last 2 items in the collection, increment the collection size
|
|
124
134
|
// so that an additional row is added for the skeletons.
|
|
@@ -133,7 +143,7 @@ export class GridLayout<T, O extends GridLayoutOptions = GridLayoutOptions> exte
|
|
|
133
143
|
}
|
|
134
144
|
lastKey = collection.getKeyBefore(lastKey);
|
|
135
145
|
}
|
|
136
|
-
|
|
146
|
+
|
|
137
147
|
let rows = Math.ceil(collectionSize / numColumns);
|
|
138
148
|
let iterator = collection[Symbol.iterator]();
|
|
139
149
|
let y = rows > 0 ? minSpace.height : 0;
|
|
@@ -165,7 +175,7 @@ export class GridLayout<T, O extends GridLayoutOptions = GridLayoutOptions> exte
|
|
|
165
175
|
if (skeleton) {
|
|
166
176
|
content = oldLayoutInfo && oldLayoutInfo.content.key === key ? oldLayoutInfo.content : {...skeleton, key};
|
|
167
177
|
}
|
|
168
|
-
let x = horizontalSpacing + col * (itemWidth + horizontalSpacing);
|
|
178
|
+
let x = horizontalSpacing + col * (itemWidth + horizontalSpacing) + this.margin;
|
|
169
179
|
let height = itemHeight;
|
|
170
180
|
let estimatedSize = !preserveAspectRatio;
|
|
171
181
|
if (oldLayoutInfo && estimatedSize) {
|
package/src/WaterfallLayout.ts
CHANGED
|
@@ -29,6 +29,11 @@ export interface WaterfallLayoutOptions {
|
|
|
29
29
|
* @default 18 x 18
|
|
30
30
|
*/
|
|
31
31
|
minSpace?: Size,
|
|
32
|
+
/**
|
|
33
|
+
* The maximum allowed horizontal space between items.
|
|
34
|
+
* @default Infinity
|
|
35
|
+
*/
|
|
36
|
+
maxHorizontalSpace?: number,
|
|
32
37
|
/**
|
|
33
38
|
* The maximum number of columns.
|
|
34
39
|
* @default Infinity
|
|
@@ -55,6 +60,7 @@ const DEFAULT_OPTIONS = {
|
|
|
55
60
|
minItemSize: new Size(200, 200),
|
|
56
61
|
maxItemSize: new Size(Infinity, Infinity),
|
|
57
62
|
minSpace: new Size(18, 18),
|
|
63
|
+
maxSpace: Infinity,
|
|
58
64
|
maxColumns: Infinity,
|
|
59
65
|
dropIndicatorThickness: 2
|
|
60
66
|
};
|
|
@@ -64,13 +70,15 @@ export class WaterfallLayout<T extends object, O extends WaterfallLayoutOptions
|
|
|
64
70
|
private layoutInfos: Map<Key, WaterfallLayoutInfo> = new Map();
|
|
65
71
|
protected numColumns = 0;
|
|
66
72
|
protected dropIndicatorThickness = 2;
|
|
73
|
+
private margin: number = 0;
|
|
67
74
|
|
|
68
75
|
shouldInvalidateLayoutOptions(newOptions: O, oldOptions: O): boolean {
|
|
69
76
|
return newOptions.maxColumns !== oldOptions.maxColumns
|
|
70
77
|
|| newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness
|
|
71
78
|
|| (!(newOptions.minItemSize || DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || DEFAULT_OPTIONS.minItemSize))
|
|
72
79
|
|| (!(newOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize))
|
|
73
|
-
|| (!(newOptions.minSpace || DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || DEFAULT_OPTIONS.minSpace))
|
|
80
|
+
|| (!(newOptions.minSpace || DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || DEFAULT_OPTIONS.minSpace))
|
|
81
|
+
|| (newOptions.maxHorizontalSpace !== oldOptions.maxHorizontalSpace);
|
|
74
82
|
}
|
|
75
83
|
|
|
76
84
|
update(invalidationContext: InvalidationContext<O>): void {
|
|
@@ -78,6 +86,7 @@ export class WaterfallLayout<T extends object, O extends WaterfallLayoutOptions
|
|
|
78
86
|
minItemSize = DEFAULT_OPTIONS.minItemSize,
|
|
79
87
|
maxItemSize = DEFAULT_OPTIONS.maxItemSize,
|
|
80
88
|
minSpace = DEFAULT_OPTIONS.minSpace,
|
|
89
|
+
maxHorizontalSpace = DEFAULT_OPTIONS.maxSpace,
|
|
81
90
|
maxColumns = DEFAULT_OPTIONS.maxColumns,
|
|
82
91
|
dropIndicatorThickness = DEFAULT_OPTIONS.dropIndicatorThickness
|
|
83
92
|
} = invalidationContext.layoutOptions || {};
|
|
@@ -107,8 +116,9 @@ export class WaterfallLayout<T extends object, O extends WaterfallLayoutOptions
|
|
|
107
116
|
let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);
|
|
108
117
|
itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));
|
|
109
118
|
|
|
110
|
-
// Compute the horizontal spacing and
|
|
111
|
-
let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));
|
|
119
|
+
// Compute the horizontal spacing, content height and horizontal margin
|
|
120
|
+
let horizontalSpacing = Math.min(Math.max(maxHorizontalSpace, minSpace.width), Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1)));
|
|
121
|
+
this.margin = Math.floor((visibleWidth - numColumns * itemWidth - horizontalSpacing * (numColumns + 1)) / 2);
|
|
112
122
|
|
|
113
123
|
// Setup an array of column heights
|
|
114
124
|
let columnHeights = Array(numColumns).fill(minSpace.height);
|
|
@@ -126,7 +136,7 @@ export class WaterfallLayout<T extends object, O extends WaterfallLayoutOptions
|
|
|
126
136
|
// Preserve the previous column index so items don't jump around during resizing unless the number of columns changed.
|
|
127
137
|
let prevColumn = numColumns === this.numColumns && oldLayoutInfo && oldLayoutInfo.rect.y < this.virtualizer!.visibleRect.maxY ? oldLayoutInfo.column : undefined;
|
|
128
138
|
let column = prevColumn ?? columnHeights.reduce((minIndex, h, i) => h < columnHeights[minIndex] ? i : minIndex, 0);
|
|
129
|
-
let x = horizontalSpacing + column * (itemWidth + horizontalSpacing);
|
|
139
|
+
let x = horizontalSpacing + column * (itemWidth + horizontalSpacing) + this.margin;
|
|
130
140
|
let y = columnHeights[column];
|
|
131
141
|
|
|
132
142
|
let rect = new Rect(x, y, itemWidth, height);
|