@react-stately/layout 4.2.2 → 4.3.1
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 +17 -4
- package/dist/GridLayout.main.js.map +1 -1
- package/dist/GridLayout.mjs +17 -4
- package/dist/GridLayout.module.js +17 -4
- package/dist/GridLayout.module.js.map +1 -1
- package/dist/ListLayout.main.js +24 -5
- package/dist/ListLayout.main.js.map +1 -1
- package/dist/ListLayout.mjs +24 -5
- package/dist/ListLayout.module.js +24 -5
- package/dist/ListLayout.module.js.map +1 -1
- package/dist/TableLayout.main.js +26 -4
- package/dist/TableLayout.main.js.map +1 -1
- package/dist/TableLayout.mjs +27 -5
- package/dist/TableLayout.module.js +27 -5
- package/dist/TableLayout.module.js.map +1 -1
- package/dist/WaterfallLayout.main.js +30 -18
- package/dist/WaterfallLayout.main.js.map +1 -1
- package/dist/WaterfallLayout.mjs +30 -18
- package/dist/WaterfallLayout.module.js +30 -18
- package/dist/WaterfallLayout.module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +13 -9
- package/src/GridLayout.ts +21 -4
- package/src/ListLayout.ts +30 -8
- package/src/TableLayout.ts +35 -5
- package/src/WaterfallLayout.ts +16 -5
package/dist/GridLayout.main.js
CHANGED
|
@@ -53,8 +53,12 @@ class $1f7773ceb2a3b9a6$export$7d2b12578154a735 extends (0, $7Tzdl$reactstatelyv
|
|
|
53
53
|
// Compute the horizontal spacing and content height
|
|
54
54
|
let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));
|
|
55
55
|
this.gap = new (0, $7Tzdl$reactstatelyvirtualizer.Size)(horizontalSpacing, minSpace.height);
|
|
56
|
-
let
|
|
57
|
-
|
|
56
|
+
let collection = this.virtualizer.collection;
|
|
57
|
+
// Make sure to set rows to 0 if we performing a first time load or are rendering the empty state so that Virtualizer
|
|
58
|
+
// won't try to render its body
|
|
59
|
+
let isEmptyOrLoading = (collection === null || collection === void 0 ? void 0 : collection.size) === 0 || collection.size === 1 && collection.getItem(collection.getFirstKey()).type === 'loader';
|
|
60
|
+
let rows = isEmptyOrLoading ? 0 : Math.ceil(collection.size / numColumns);
|
|
61
|
+
let iterator = collection[Symbol.iterator]();
|
|
58
62
|
let y = rows > 0 ? minSpace.height : 0;
|
|
59
63
|
let newLayoutInfos = new Map();
|
|
60
64
|
let skeleton = null;
|
|
@@ -66,6 +70,8 @@ class $1f7773ceb2a3b9a6$export$7d2b12578154a735 extends (0, $7Tzdl$reactstatelyv
|
|
|
66
70
|
// Repeat skeleton until the end of the current row.
|
|
67
71
|
let node = skeleton || iterator.next().value;
|
|
68
72
|
if (!node) break;
|
|
73
|
+
// We will add the loader after the skeletons so skip here
|
|
74
|
+
if (node.type === 'loader') continue;
|
|
69
75
|
if (node.type === 'skeleton') skeleton = node;
|
|
70
76
|
let key = skeleton ? `${skeleton.key}-${skeletonCount++}` : node.key;
|
|
71
77
|
let oldLayoutInfo = this.layoutInfos.get(key);
|
|
@@ -95,6 +101,13 @@ class $1f7773ceb2a3b9a6$export$7d2b12578154a735 extends (0, $7Tzdl$reactstatelyv
|
|
|
95
101
|
// Keep adding skeleton rows until we fill the viewport
|
|
96
102
|
if (skeleton && row === rows - 1 && y < this.virtualizer.visibleRect.height) rows++;
|
|
97
103
|
}
|
|
104
|
+
// Always add the loader sentinel if present in the collection so we can make sure it is never virtualized out.
|
|
105
|
+
let lastNode = collection.getItem(collection.getLastKey());
|
|
106
|
+
if ((lastNode === null || lastNode === void 0 ? void 0 : lastNode.type) === 'loader') {
|
|
107
|
+
let rect = new (0, $7Tzdl$reactstatelyvirtualizer.Rect)(horizontalSpacing, y, itemWidth, 0);
|
|
108
|
+
let layoutInfo = new (0, $7Tzdl$reactstatelyvirtualizer.LayoutInfo)('loader', lastNode.key, rect);
|
|
109
|
+
newLayoutInfos.set(lastNode.key, layoutInfo);
|
|
110
|
+
}
|
|
98
111
|
this.layoutInfos = newLayoutInfos;
|
|
99
112
|
this.contentSize = new (0, $7Tzdl$reactstatelyvirtualizer.Size)(this.virtualizer.visibleRect.width, y);
|
|
100
113
|
}
|
|
@@ -106,7 +119,7 @@ class $1f7773ceb2a3b9a6$export$7d2b12578154a735 extends (0, $7Tzdl$reactstatelyv
|
|
|
106
119
|
}
|
|
107
120
|
getVisibleLayoutInfos(rect) {
|
|
108
121
|
let layoutInfos = [];
|
|
109
|
-
for (let layoutInfo of this.layoutInfos.values())if (layoutInfo.rect.intersects(rect) || this.virtualizer.isPersistedKey(layoutInfo.key)) layoutInfos.push(layoutInfo);
|
|
122
|
+
for (let layoutInfo of this.layoutInfos.values())if (layoutInfo.rect.intersects(rect) || this.virtualizer.isPersistedKey(layoutInfo.key) || layoutInfo.type === 'loader') layoutInfos.push(layoutInfo);
|
|
110
123
|
return layoutInfos;
|
|
111
124
|
}
|
|
112
125
|
updateItemSize(key, size) {
|
|
@@ -130,7 +143,7 @@ class $1f7773ceb2a3b9a6$export$7d2b12578154a735 extends (0, $7Tzdl$reactstatelyv
|
|
|
130
143
|
// Find the closest item within on either side of the point using the gap width.
|
|
131
144
|
let key = null;
|
|
132
145
|
if (this.numColumns === 1) {
|
|
133
|
-
let searchRect = new (0, $7Tzdl$reactstatelyvirtualizer.Rect)(x, Math.max(0, y - this.gap.height), 1, this.gap.height * 2);
|
|
146
|
+
let searchRect = new (0, $7Tzdl$reactstatelyvirtualizer.Rect)(x, Math.max(0, y - this.gap.height), 1, Math.max(1, this.gap.height * 2));
|
|
134
147
|
let candidates = this.getVisibleLayoutInfos(searchRect);
|
|
135
148
|
let minDistance = Infinity;
|
|
136
149
|
for (let candidate of candidates){
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAwCD,MAAM,wCAAkB;IACtB,aAAa,IAAI,CAAA,GAAA,mCAAG,EAAE,KAAK;IAC3B,aAAa,IAAI,CAAA,GAAA,mCAAG,EAAE,UAAU;IAChC,qB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I,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;;QArQK,qBACK,MAAY,sCAAgB,QAAQ,OACpC,yBAAyB,QACzB,aAAqB,QACvB,cAAoB,IAAI,CAAA,GAAA,mCAAG,UAC3B,cAAoC,IAAI;;AAiQlD","sources":["packages/@react-stately/layout/src/GridLayout.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DropTarget, DropTargetDelegate, ItemDropTarget, Key, Node} from '@react-types/shared';\nimport {InvalidationContext, Layout, LayoutInfo, Rect, Size} from '@react-stately/virtualizer';\n\nexport interface GridLayoutOptions {\n /**\n * The minimum item size.\n * @default 200 x 200\n */\n minItemSize?: Size,\n /**\n * The maximum item size.\n * @default Infinity\n */\n maxItemSize?: Size,\n /**\n * Whether to preserve the aspect ratio of the `minItemSize`.\n * By default, grid rows may have variable heights. When `preserveAspectRatio`\n * is true, all rows will have equal heights.\n * @default false\n */\n preserveAspectRatio?: boolean,\n /**\n * The minimum space required between items.\n * @default 18 x 18\n */\n minSpace?: Size,\n /**\n * The maximum number of columns.\n * @default Infinity\n */\n maxColumns?: number,\n /**\n * The thickness of the drop indicator.\n * @default 2\n */\n dropIndicatorThickness?: number\n}\n\nconst DEFAULT_OPTIONS = {\n minItemSize: new Size(200, 200),\n maxItemSize: new Size(Infinity, Infinity),\n preserveAspectRatio: false,\n minSpace: new Size(18, 18),\n maxColumns: Infinity,\n dropIndicatorThickness: 2\n};\n\n/**\n * GridLayout is a virtualizer Layout implementation\n * that arranges its items in a grid.\n * The items are sized between a minimum and maximum size\n * depending on the width of the container.\n */\nexport class GridLayout<T, O extends GridLayoutOptions = GridLayoutOptions> extends Layout<Node<T>, O> implements DropTargetDelegate {\n protected gap: Size = DEFAULT_OPTIONS.minSpace;\n protected dropIndicatorThickness = 2;\n protected numColumns: number = 0;\n private contentSize: Size = new Size();\n private layoutInfos: Map<Key, LayoutInfo> = new Map();\n\n shouldInvalidateLayoutOptions(newOptions: O, oldOptions: O): boolean {\n return newOptions.maxColumns !== oldOptions.maxColumns\n || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness\n || newOptions.preserveAspectRatio !== oldOptions.preserveAspectRatio\n || (!(newOptions.minItemSize || DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || DEFAULT_OPTIONS.minItemSize))\n || (!(newOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize))\n || (!(newOptions.minSpace || DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || DEFAULT_OPTIONS.minSpace));\n }\n\n update(invalidationContext: InvalidationContext<O>): void {\n let {\n minItemSize = DEFAULT_OPTIONS.minItemSize,\n maxItemSize = DEFAULT_OPTIONS.maxItemSize,\n preserveAspectRatio = DEFAULT_OPTIONS.preserveAspectRatio,\n minSpace = DEFAULT_OPTIONS.minSpace,\n maxColumns = DEFAULT_OPTIONS.maxColumns,\n dropIndicatorThickness = DEFAULT_OPTIONS.dropIndicatorThickness\n } = invalidationContext.layoutOptions || {};\n this.dropIndicatorThickness = dropIndicatorThickness;\n\n let visibleWidth = this.virtualizer!.visibleRect.width;\n\n // The max item width is always the entire viewport.\n // If the max item height is infinity, scale in proportion to the max width.\n let maxItemWidth = Math.min(maxItemSize.width, visibleWidth);\n let maxItemHeight = Number.isFinite(maxItemSize.height)\n ? maxItemSize.height\n : Math.floor((minItemSize.height / minItemSize.width) * maxItemWidth);\n\n // Compute the number of rows and columns needed to display the content\n let columns = Math.floor(visibleWidth / (minItemSize.width + minSpace.width));\n let numColumns = Math.max(1, Math.min(maxColumns, columns));\n this.numColumns = numColumns;\n\n // Compute the available width (minus the space between items)\n let width = visibleWidth - (minSpace.width * Math.max(0, numColumns));\n\n // Compute the item width based on the space available\n let itemWidth = Math.floor(width / numColumns);\n itemWidth = Math.max(minItemSize.width, Math.min(maxItemWidth, itemWidth));\n\n // Compute the item height, which is proportional to the item width\n let t = ((itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width));\n let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);\n itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));\n\n // Compute the horizontal spacing and content height\n let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));\n this.gap = new Size(horizontalSpacing, minSpace.height);\n\n let rows = Math.ceil(this.virtualizer!.collection.size / numColumns);\n let iterator = this.virtualizer!.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 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 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)) {\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, 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,"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,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;;QAtRK,qBACK,MAAY,sCAAgB,QAAQ,OACpC,yBAAyB,QACzB,aAAqB,QACvB,cAAoB,IAAI,CAAA,GAAA,mCAAG,UAC3B,cAAoC,IAAI;;AAkRlD","sources":["packages/@react-stately/layout/src/GridLayout.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DropTarget, DropTargetDelegate, ItemDropTarget, Key, Node} from '@react-types/shared';\nimport {InvalidationContext, Layout, LayoutInfo, Rect, Size} from '@react-stately/virtualizer';\n\nexport interface GridLayoutOptions {\n /**\n * The minimum item size.\n * @default 200 x 200\n */\n minItemSize?: Size,\n /**\n * The maximum item size.\n * @default Infinity\n */\n maxItemSize?: Size,\n /**\n * Whether to preserve the aspect ratio of the `minItemSize`.\n * By default, grid rows may have variable heights. When `preserveAspectRatio`\n * is true, all rows will have equal heights.\n * @default false\n */\n preserveAspectRatio?: boolean,\n /**\n * The minimum space required between items.\n * @default 18 x 18\n */\n minSpace?: Size,\n /**\n * The maximum number of columns.\n * @default Infinity\n */\n maxColumns?: number,\n /**\n * The thickness of the drop indicator.\n * @default 2\n */\n dropIndicatorThickness?: number\n}\n\nconst DEFAULT_OPTIONS = {\n minItemSize: new Size(200, 200),\n maxItemSize: new Size(Infinity, Infinity),\n preserveAspectRatio: false,\n minSpace: new Size(18, 18),\n maxColumns: Infinity,\n dropIndicatorThickness: 2\n};\n\n/**\n * GridLayout is a virtualizer Layout implementation\n * that arranges its items in a grid.\n * The items are sized between a minimum and maximum size\n * depending on the width of the container.\n */\nexport class GridLayout<T, O extends GridLayoutOptions = GridLayoutOptions> extends Layout<Node<T>, O> implements DropTargetDelegate {\n protected gap: Size = DEFAULT_OPTIONS.minSpace;\n protected dropIndicatorThickness = 2;\n protected numColumns: number = 0;\n private contentSize: Size = new Size();\n private layoutInfos: Map<Key, LayoutInfo> = new Map();\n\n shouldInvalidateLayoutOptions(newOptions: O, oldOptions: O): boolean {\n return newOptions.maxColumns !== oldOptions.maxColumns\n || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness\n || newOptions.preserveAspectRatio !== oldOptions.preserveAspectRatio\n || (!(newOptions.minItemSize || DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || DEFAULT_OPTIONS.minItemSize))\n || (!(newOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize))\n || (!(newOptions.minSpace || DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || DEFAULT_OPTIONS.minSpace));\n }\n\n update(invalidationContext: InvalidationContext<O>): void {\n let {\n minItemSize = DEFAULT_OPTIONS.minItemSize,\n maxItemSize = DEFAULT_OPTIONS.maxItemSize,\n preserveAspectRatio = DEFAULT_OPTIONS.preserveAspectRatio,\n minSpace = DEFAULT_OPTIONS.minSpace,\n maxColumns = DEFAULT_OPTIONS.maxColumns,\n dropIndicatorThickness = DEFAULT_OPTIONS.dropIndicatorThickness\n } = invalidationContext.layoutOptions || {};\n this.dropIndicatorThickness = dropIndicatorThickness;\n\n let visibleWidth = this.virtualizer!.visibleRect.width;\n\n // The max item width is always the entire viewport.\n // If the max item height is infinity, scale in proportion to the max width.\n let maxItemWidth = Math.min(maxItemSize.width, visibleWidth);\n let maxItemHeight = Number.isFinite(maxItemSize.height)\n ? maxItemSize.height\n : Math.floor((minItemSize.height / minItemSize.width) * maxItemWidth);\n\n // Compute the number of rows and columns needed to display the content\n let columns = Math.floor(visibleWidth / (minItemSize.width + minSpace.width));\n let numColumns = Math.max(1, Math.min(maxColumns, columns));\n this.numColumns = numColumns;\n\n // Compute the available width (minus the space between items)\n let width = visibleWidth - (minSpace.width * Math.max(0, numColumns));\n\n // Compute the item width based on the space available\n let itemWidth = Math.floor(width / numColumns);\n itemWidth = Math.max(minItemSize.width, Math.min(maxItemWidth, itemWidth));\n\n // Compute the item height, which is proportional to the item width\n let t = ((itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width));\n let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);\n itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));\n\n // Compute the horizontal spacing and content height\n let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));\n this.gap = new Size(horizontalSpacing, minSpace.height);\n\n let collection = this.virtualizer!.collection;\n // Make sure to set rows to 0 if we performing a first time load or are rendering the empty state so that Virtualizer\n // won't try to render its body\n let isEmptyOrLoading = collection?.size === 0 || (collection.size === 1 && collection.getItem(collection.getFirstKey()!)!.type === 'loader');\n let rows = isEmptyOrLoading ? 0 : Math.ceil(collection.size / numColumns);\n let iterator = collection[Symbol.iterator]();\n let y = rows > 0 ? minSpace.height : 0;\n let newLayoutInfos = new Map();\n let skeleton: Node<T> | null = null;\n let skeletonCount = 0;\n for (let row = 0; row < rows; row++) {\n let maxHeight = 0;\n let rowLayoutInfos: LayoutInfo[] = [];\n for (let col = 0; col < numColumns; col++) {\n // Repeat skeleton until the end of the current row.\n let node = skeleton || iterator.next().value;\n if (!node) {\n break;\n }\n\n // We will add the loader after the skeletons so skip here\n if (node.type === 'loader') {\n continue;\n }\n\n if (node.type === 'skeleton') {\n skeleton = node;\n }\n\n let key = skeleton ? `${skeleton.key}-${skeletonCount++}` : node.key;\n let oldLayoutInfo = this.layoutInfos.get(key);\n let content = node;\n if (skeleton) {\n content = oldLayoutInfo && oldLayoutInfo.content.key === key ? oldLayoutInfo.content : {...skeleton, key};\n }\n let x = horizontalSpacing + col * (itemWidth + horizontalSpacing);\n let height = itemHeight;\n let estimatedSize = !preserveAspectRatio;\n if (oldLayoutInfo && estimatedSize) {\n height = oldLayoutInfo.rect.height;\n estimatedSize = invalidationContext.layoutOptionsChanged || invalidationContext.sizeChanged || oldLayoutInfo.estimatedSize || (oldLayoutInfo.content !== content);\n }\n\n let rect = new Rect(x, y, itemWidth, height);\n let layoutInfo = new LayoutInfo(node.type, key, rect);\n layoutInfo.estimatedSize = estimatedSize;\n layoutInfo.allowOverflow = true;\n layoutInfo.content = content;\n newLayoutInfos.set(key, layoutInfo);\n rowLayoutInfos.push(layoutInfo);\n\n maxHeight = Math.max(maxHeight, layoutInfo.rect.height);\n }\n\n for (let layoutInfo of rowLayoutInfos) {\n layoutInfo.rect.height = maxHeight;\n }\n\n y += maxHeight + minSpace.height;\n\n // Keep adding skeleton rows until we fill the viewport\n if (skeleton && row === rows - 1 && y < this.virtualizer!.visibleRect.height) {\n rows++;\n }\n }\n\n // Always add the loader sentinel if present in the collection so we can make sure it is never virtualized out.\n let lastNode = collection.getItem(collection.getLastKey()!);\n if (lastNode?.type === 'loader') {\n let rect = new Rect(horizontalSpacing, y, itemWidth, 0);\n let layoutInfo = new LayoutInfo('loader', lastNode.key, rect);\n newLayoutInfos.set(lastNode.key, layoutInfo);\n }\n\n this.layoutInfos = newLayoutInfos;\n this.contentSize = new Size(this.virtualizer!.visibleRect.width, y);\n }\n\n getLayoutInfo(key: Key): LayoutInfo | null {\n return this.layoutInfos.get(key) || null;\n }\n\n getContentSize(): Size {\n return this.contentSize;\n }\n\n getVisibleLayoutInfos(rect: Rect): LayoutInfo[] {\n let layoutInfos: LayoutInfo[] = [];\n for (let layoutInfo of this.layoutInfos.values()) {\n if (layoutInfo.rect.intersects(rect) || this.virtualizer!.isPersistedKey(layoutInfo.key) || layoutInfo.type === 'loader') {\n layoutInfos.push(layoutInfo);\n }\n }\n return layoutInfos;\n }\n\n updateItemSize(key: Key, size: Size): boolean {\n let layoutInfo = this.layoutInfos.get(key);\n if (!size || !layoutInfo) {\n return false;\n }\n\n if (size.height !== layoutInfo.rect.height) {\n let newLayoutInfo = layoutInfo.copy();\n newLayoutInfo.rect.height = size.height;\n newLayoutInfo.estimatedSize = false;\n this.layoutInfos.set(key, newLayoutInfo);\n return true;\n }\n\n return false;\n }\n\n getDropTargetFromPoint(x: number, y: number, isValidDropTarget: (target: DropTarget) => boolean): DropTarget {\n if (this.layoutInfos.size === 0) {\n return {type: 'root'};\n }\n\n x += this.virtualizer!.visibleRect.x;\n y += this.virtualizer!.visibleRect.y;\n\n // Find the closest item within on either side of the point using the gap width.\n let key: Key | null = null;\n if (this.numColumns === 1) {\n let searchRect = new Rect(x, Math.max(0, y - this.gap.height), 1, Math.max(1, this.gap.height * 2));\n let candidates = this.getVisibleLayoutInfos(searchRect);\n let minDistance = Infinity;\n for (let candidate of candidates) {\n // Ignore items outside the search rect, e.g. persisted keys.\n if (!candidate.rect.intersects(searchRect)) {\n continue;\n }\n\n let yDist = Math.abs(candidate.rect.y - y);\n let maxYDist = Math.abs(candidate.rect.maxY - y);\n let dist = Math.min(yDist, maxYDist);\n if (dist < minDistance) {\n minDistance = dist;\n key = candidate.key;\n }\n }\n } else {\n let searchRect = new Rect(Math.max(0, x - this.gap.width), y, this.gap.width * 2, 1);\n let candidates = this.getVisibleLayoutInfos(searchRect);\n let minDistance = Infinity;\n for (let candidate of candidates) {\n // Ignore items outside the search rect, e.g. persisted keys.\n if (!candidate.rect.intersects(searchRect)) {\n continue;\n }\n\n let xDist = Math.abs(candidate.rect.x - x);\n let maxXDist = Math.abs(candidate.rect.maxX - x);\n let dist = Math.min(xDist, maxXDist);\n if (dist < minDistance) {\n minDistance = dist;\n key = candidate.key;\n }\n }\n }\n\n let layoutInfo = key != null ? this.getLayoutInfo(key) : null;\n if (!layoutInfo) {\n return {type: 'root'};\n }\n\n let target: DropTarget = {\n type: 'item',\n key: layoutInfo.key,\n dropPosition: 'on'\n };\n\n let pos = this.numColumns === 1 ? y : x;\n let layoutInfoPos = this.numColumns === 1 ? layoutInfo.rect.y : layoutInfo.rect.x;\n let size = this.numColumns === 1 ? layoutInfo.rect.height : layoutInfo.rect.width;\n if (isValidDropTarget(target)) {\n // If dropping on the item is accepted, try the before/after positions\n // if within 5px of the start or end of the item.\n if (pos < layoutInfoPos + 5) {\n target.dropPosition = 'before';\n } else if (pos > layoutInfoPos + size - 5) {\n target.dropPosition = 'after';\n }\n } else {\n // If dropping on the item isn't accepted, try the target before or after depending on the position.\n let mid = layoutInfoPos + size / 2;\n if (pos <= mid && isValidDropTarget({...target, dropPosition: 'before'})) {\n target.dropPosition = 'before';\n } else if (pos >= mid && isValidDropTarget({...target, dropPosition: 'after'})) {\n target.dropPosition = 'after';\n }\n }\n\n return target;\n }\n\n getDropTargetLayoutInfo(target: ItemDropTarget): LayoutInfo {\n let layoutInfo = this.getLayoutInfo(target.key)!;\n let rect: Rect;\n if (this.numColumns === 1) {\n // Flip from vertical to horizontal if only one column is visible.\n rect = new Rect(\n layoutInfo.rect.x,\n target.dropPosition === 'before'\n ? layoutInfo.rect.y - this.gap.height / 2 - this.dropIndicatorThickness / 2\n : layoutInfo.rect.maxY + this.gap.height / 2 - this.dropIndicatorThickness / 2,\n layoutInfo.rect.width,\n this.dropIndicatorThickness\n );\n } else {\n rect = new Rect(\n target.dropPosition === 'before'\n ? layoutInfo.rect.x - this.gap.width / 2 - this.dropIndicatorThickness / 2\n : layoutInfo.rect.maxX + this.gap.width / 2 - this.dropIndicatorThickness / 2,\n layoutInfo.rect.y,\n this.dropIndicatorThickness,\n layoutInfo.rect.height\n );\n }\n\n return new LayoutInfo('dropIndicator', target.key + ':' + target.dropPosition, rect);\n }\n}\n"],"names":[],"version":3,"file":"GridLayout.main.js.map"}
|
package/dist/GridLayout.mjs
CHANGED
|
@@ -47,8 +47,12 @@ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
|
|
|
47
47
|
// Compute the horizontal spacing and content height
|
|
48
48
|
let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));
|
|
49
49
|
this.gap = new (0, $ipgKF$Size)(horizontalSpacing, minSpace.height);
|
|
50
|
-
let
|
|
51
|
-
|
|
50
|
+
let collection = this.virtualizer.collection;
|
|
51
|
+
// Make sure to set rows to 0 if we performing a first time load or are rendering the empty state so that Virtualizer
|
|
52
|
+
// won't try to render its body
|
|
53
|
+
let isEmptyOrLoading = (collection === null || collection === void 0 ? void 0 : collection.size) === 0 || collection.size === 1 && collection.getItem(collection.getFirstKey()).type === 'loader';
|
|
54
|
+
let rows = isEmptyOrLoading ? 0 : Math.ceil(collection.size / numColumns);
|
|
55
|
+
let iterator = collection[Symbol.iterator]();
|
|
52
56
|
let y = rows > 0 ? minSpace.height : 0;
|
|
53
57
|
let newLayoutInfos = new Map();
|
|
54
58
|
let skeleton = null;
|
|
@@ -60,6 +64,8 @@ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
|
|
|
60
64
|
// Repeat skeleton until the end of the current row.
|
|
61
65
|
let node = skeleton || iterator.next().value;
|
|
62
66
|
if (!node) break;
|
|
67
|
+
// We will add the loader after the skeletons so skip here
|
|
68
|
+
if (node.type === 'loader') continue;
|
|
63
69
|
if (node.type === 'skeleton') skeleton = node;
|
|
64
70
|
let key = skeleton ? `${skeleton.key}-${skeletonCount++}` : node.key;
|
|
65
71
|
let oldLayoutInfo = this.layoutInfos.get(key);
|
|
@@ -89,6 +95,13 @@ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
|
|
|
89
95
|
// Keep adding skeleton rows until we fill the viewport
|
|
90
96
|
if (skeleton && row === rows - 1 && y < this.virtualizer.visibleRect.height) rows++;
|
|
91
97
|
}
|
|
98
|
+
// Always add the loader sentinel if present in the collection so we can make sure it is never virtualized out.
|
|
99
|
+
let lastNode = collection.getItem(collection.getLastKey());
|
|
100
|
+
if ((lastNode === null || lastNode === void 0 ? void 0 : lastNode.type) === 'loader') {
|
|
101
|
+
let rect = new (0, $ipgKF$Rect)(horizontalSpacing, y, itemWidth, 0);
|
|
102
|
+
let layoutInfo = new (0, $ipgKF$LayoutInfo)('loader', lastNode.key, rect);
|
|
103
|
+
newLayoutInfos.set(lastNode.key, layoutInfo);
|
|
104
|
+
}
|
|
92
105
|
this.layoutInfos = newLayoutInfos;
|
|
93
106
|
this.contentSize = new (0, $ipgKF$Size)(this.virtualizer.visibleRect.width, y);
|
|
94
107
|
}
|
|
@@ -100,7 +113,7 @@ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
|
|
|
100
113
|
}
|
|
101
114
|
getVisibleLayoutInfos(rect) {
|
|
102
115
|
let layoutInfos = [];
|
|
103
|
-
for (let layoutInfo of this.layoutInfos.values())if (layoutInfo.rect.intersects(rect) || this.virtualizer.isPersistedKey(layoutInfo.key)) layoutInfos.push(layoutInfo);
|
|
116
|
+
for (let layoutInfo of this.layoutInfos.values())if (layoutInfo.rect.intersects(rect) || this.virtualizer.isPersistedKey(layoutInfo.key) || layoutInfo.type === 'loader') layoutInfos.push(layoutInfo);
|
|
104
117
|
return layoutInfos;
|
|
105
118
|
}
|
|
106
119
|
updateItemSize(key, size) {
|
|
@@ -124,7 +137,7 @@ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
|
|
|
124
137
|
// Find the closest item within on either side of the point using the gap width.
|
|
125
138
|
let key = null;
|
|
126
139
|
if (this.numColumns === 1) {
|
|
127
|
-
let searchRect = new (0, $ipgKF$Rect)(x, Math.max(0, y - this.gap.height), 1, this.gap.height * 2);
|
|
140
|
+
let searchRect = new (0, $ipgKF$Rect)(x, Math.max(0, y - this.gap.height), 1, Math.max(1, this.gap.height * 2));
|
|
128
141
|
let candidates = this.getVisibleLayoutInfos(searchRect);
|
|
129
142
|
let minDistance = Infinity;
|
|
130
143
|
for (let candidate of candidates){
|
|
@@ -47,8 +47,12 @@ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
|
|
|
47
47
|
// Compute the horizontal spacing and content height
|
|
48
48
|
let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));
|
|
49
49
|
this.gap = new (0, $ipgKF$Size)(horizontalSpacing, minSpace.height);
|
|
50
|
-
let
|
|
51
|
-
|
|
50
|
+
let collection = this.virtualizer.collection;
|
|
51
|
+
// Make sure to set rows to 0 if we performing a first time load or are rendering the empty state so that Virtualizer
|
|
52
|
+
// won't try to render its body
|
|
53
|
+
let isEmptyOrLoading = (collection === null || collection === void 0 ? void 0 : collection.size) === 0 || collection.size === 1 && collection.getItem(collection.getFirstKey()).type === 'loader';
|
|
54
|
+
let rows = isEmptyOrLoading ? 0 : Math.ceil(collection.size / numColumns);
|
|
55
|
+
let iterator = collection[Symbol.iterator]();
|
|
52
56
|
let y = rows > 0 ? minSpace.height : 0;
|
|
53
57
|
let newLayoutInfos = new Map();
|
|
54
58
|
let skeleton = null;
|
|
@@ -60,6 +64,8 @@ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
|
|
|
60
64
|
// Repeat skeleton until the end of the current row.
|
|
61
65
|
let node = skeleton || iterator.next().value;
|
|
62
66
|
if (!node) break;
|
|
67
|
+
// We will add the loader after the skeletons so skip here
|
|
68
|
+
if (node.type === 'loader') continue;
|
|
63
69
|
if (node.type === 'skeleton') skeleton = node;
|
|
64
70
|
let key = skeleton ? `${skeleton.key}-${skeletonCount++}` : node.key;
|
|
65
71
|
let oldLayoutInfo = this.layoutInfos.get(key);
|
|
@@ -89,6 +95,13 @@ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
|
|
|
89
95
|
// Keep adding skeleton rows until we fill the viewport
|
|
90
96
|
if (skeleton && row === rows - 1 && y < this.virtualizer.visibleRect.height) rows++;
|
|
91
97
|
}
|
|
98
|
+
// Always add the loader sentinel if present in the collection so we can make sure it is never virtualized out.
|
|
99
|
+
let lastNode = collection.getItem(collection.getLastKey());
|
|
100
|
+
if ((lastNode === null || lastNode === void 0 ? void 0 : lastNode.type) === 'loader') {
|
|
101
|
+
let rect = new (0, $ipgKF$Rect)(horizontalSpacing, y, itemWidth, 0);
|
|
102
|
+
let layoutInfo = new (0, $ipgKF$LayoutInfo)('loader', lastNode.key, rect);
|
|
103
|
+
newLayoutInfos.set(lastNode.key, layoutInfo);
|
|
104
|
+
}
|
|
92
105
|
this.layoutInfos = newLayoutInfos;
|
|
93
106
|
this.contentSize = new (0, $ipgKF$Size)(this.virtualizer.visibleRect.width, y);
|
|
94
107
|
}
|
|
@@ -100,7 +113,7 @@ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
|
|
|
100
113
|
}
|
|
101
114
|
getVisibleLayoutInfos(rect) {
|
|
102
115
|
let layoutInfos = [];
|
|
103
|
-
for (let layoutInfo of this.layoutInfos.values())if (layoutInfo.rect.intersects(rect) || this.virtualizer.isPersistedKey(layoutInfo.key)) layoutInfos.push(layoutInfo);
|
|
116
|
+
for (let layoutInfo of this.layoutInfos.values())if (layoutInfo.rect.intersects(rect) || this.virtualizer.isPersistedKey(layoutInfo.key) || layoutInfo.type === 'loader') layoutInfos.push(layoutInfo);
|
|
104
117
|
return layoutInfos;
|
|
105
118
|
}
|
|
106
119
|
updateItemSize(key, size) {
|
|
@@ -124,7 +137,7 @@ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
|
|
|
124
137
|
// Find the closest item within on either side of the point using the gap width.
|
|
125
138
|
let key = null;
|
|
126
139
|
if (this.numColumns === 1) {
|
|
127
|
-
let searchRect = new (0, $ipgKF$Rect)(x, Math.max(0, y - this.gap.height), 1, this.gap.height * 2);
|
|
140
|
+
let searchRect = new (0, $ipgKF$Rect)(x, Math.max(0, y - this.gap.height), 1, Math.max(1, this.gap.height * 2));
|
|
128
141
|
let candidates = this.getVisibleLayoutInfos(searchRect);
|
|
129
142
|
let minDistance = Infinity;
|
|
130
143
|
for (let candidate of candidates){
|
|
@@ -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,sBAAs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licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DropTarget, DropTargetDelegate, ItemDropTarget, Key, Node} from '@react-types/shared';\nimport {InvalidationContext, Layout, LayoutInfo, Rect, Size} from '@react-stately/virtualizer';\n\nexport interface GridLayoutOptions {\n /**\n * The minimum item size.\n * @default 200 x 200\n */\n minItemSize?: Size,\n /**\n * The maximum item size.\n * @default Infinity\n */\n maxItemSize?: Size,\n /**\n * Whether to preserve the aspect ratio of the `minItemSize`.\n * By default, grid rows may have variable heights. When `preserveAspectRatio`\n * is true, all rows will have equal heights.\n * @default false\n */\n preserveAspectRatio?: boolean,\n /**\n * The minimum space required between items.\n * @default 18 x 18\n */\n minSpace?: Size,\n /**\n * The maximum number of columns.\n * @default Infinity\n */\n maxColumns?: number,\n /**\n * The thickness of the drop indicator.\n * @default 2\n */\n dropIndicatorThickness?: number\n}\n\nconst DEFAULT_OPTIONS = {\n minItemSize: new Size(200, 200),\n maxItemSize: new Size(Infinity, Infinity),\n preserveAspectRatio: false,\n minSpace: new Size(18, 18),\n maxColumns: Infinity,\n dropIndicatorThickness: 2\n};\n\n/**\n * GridLayout is a virtualizer Layout implementation\n * that arranges its items in a grid.\n * The items are sized between a minimum and maximum size\n * depending on the width of the container.\n */\nexport class GridLayout<T, O extends GridLayoutOptions = GridLayoutOptions> extends Layout<Node<T>, O> implements DropTargetDelegate {\n protected gap: Size = DEFAULT_OPTIONS.minSpace;\n protected dropIndicatorThickness = 2;\n protected numColumns: number = 0;\n private contentSize: Size = new Size();\n private layoutInfos: Map<Key, LayoutInfo> = new Map();\n\n shouldInvalidateLayoutOptions(newOptions: O, oldOptions: O): boolean {\n return newOptions.maxColumns !== oldOptions.maxColumns\n || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness\n || newOptions.preserveAspectRatio !== oldOptions.preserveAspectRatio\n || (!(newOptions.minItemSize || DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || DEFAULT_OPTIONS.minItemSize))\n || (!(newOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize))\n || (!(newOptions.minSpace || DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || DEFAULT_OPTIONS.minSpace));\n }\n\n update(invalidationContext: InvalidationContext<O>): void {\n let {\n minItemSize = DEFAULT_OPTIONS.minItemSize,\n maxItemSize = DEFAULT_OPTIONS.maxItemSize,\n preserveAspectRatio = DEFAULT_OPTIONS.preserveAspectRatio,\n minSpace = DEFAULT_OPTIONS.minSpace,\n maxColumns = DEFAULT_OPTIONS.maxColumns,\n dropIndicatorThickness = DEFAULT_OPTIONS.dropIndicatorThickness\n } = invalidationContext.layoutOptions || {};\n this.dropIndicatorThickness = dropIndicatorThickness;\n\n let visibleWidth = this.virtualizer!.visibleRect.width;\n\n // The max item width is always the entire viewport.\n // If the max item height is infinity, scale in proportion to the max width.\n let maxItemWidth = Math.min(maxItemSize.width, visibleWidth);\n let maxItemHeight = Number.isFinite(maxItemSize.height)\n ? maxItemSize.height\n : Math.floor((minItemSize.height / minItemSize.width) * maxItemWidth);\n\n // Compute the number of rows and columns needed to display the content\n let columns = Math.floor(visibleWidth / (minItemSize.width + minSpace.width));\n let numColumns = Math.max(1, Math.min(maxColumns, columns));\n this.numColumns = numColumns;\n\n // Compute the available width (minus the space between items)\n let width = visibleWidth - (minSpace.width * Math.max(0, numColumns));\n\n // Compute the item width based on the space available\n let itemWidth = Math.floor(width / numColumns);\n itemWidth = Math.max(minItemSize.width, Math.min(maxItemWidth, itemWidth));\n\n // Compute the item height, which is proportional to the item width\n let t = ((itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width));\n let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);\n itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));\n\n // Compute the horizontal spacing and content height\n let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));\n this.gap = new Size(horizontalSpacing, minSpace.height);\n\n let rows = Math.ceil(this.virtualizer!.collection.size / numColumns);\n let iterator = this.virtualizer!.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 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 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)) {\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, 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;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;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AAM,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;;QAtRK,qBACK,MAAY,sCAAgB,QAAQ,OACpC,yBAAyB,QACzB,aAAqB,QACvB,cAAoB,IAAI,CAAA,GAAA,WAAG,UAC3B,cAAoC,IAAI;;AAkRlD","sources":["packages/@react-stately/layout/src/GridLayout.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DropTarget, DropTargetDelegate, ItemDropTarget, Key, Node} from '@react-types/shared';\nimport {InvalidationContext, Layout, LayoutInfo, Rect, Size} from '@react-stately/virtualizer';\n\nexport interface GridLayoutOptions {\n /**\n * The minimum item size.\n * @default 200 x 200\n */\n minItemSize?: Size,\n /**\n * The maximum item size.\n * @default Infinity\n */\n maxItemSize?: Size,\n /**\n * Whether to preserve the aspect ratio of the `minItemSize`.\n * By default, grid rows may have variable heights. When `preserveAspectRatio`\n * is true, all rows will have equal heights.\n * @default false\n */\n preserveAspectRatio?: boolean,\n /**\n * The minimum space required between items.\n * @default 18 x 18\n */\n minSpace?: Size,\n /**\n * The maximum number of columns.\n * @default Infinity\n */\n maxColumns?: number,\n /**\n * The thickness of the drop indicator.\n * @default 2\n */\n dropIndicatorThickness?: number\n}\n\nconst DEFAULT_OPTIONS = {\n minItemSize: new Size(200, 200),\n maxItemSize: new Size(Infinity, Infinity),\n preserveAspectRatio: false,\n minSpace: new Size(18, 18),\n maxColumns: Infinity,\n dropIndicatorThickness: 2\n};\n\n/**\n * GridLayout is a virtualizer Layout implementation\n * that arranges its items in a grid.\n * The items are sized between a minimum and maximum size\n * depending on the width of the container.\n */\nexport class GridLayout<T, O extends GridLayoutOptions = GridLayoutOptions> extends Layout<Node<T>, O> implements DropTargetDelegate {\n protected gap: Size = DEFAULT_OPTIONS.minSpace;\n protected dropIndicatorThickness = 2;\n protected numColumns: number = 0;\n private contentSize: Size = new Size();\n private layoutInfos: Map<Key, LayoutInfo> = new Map();\n\n shouldInvalidateLayoutOptions(newOptions: O, oldOptions: O): boolean {\n return newOptions.maxColumns !== oldOptions.maxColumns\n || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness\n || newOptions.preserveAspectRatio !== oldOptions.preserveAspectRatio\n || (!(newOptions.minItemSize || DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || DEFAULT_OPTIONS.minItemSize))\n || (!(newOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize))\n || (!(newOptions.minSpace || DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || DEFAULT_OPTIONS.minSpace));\n }\n\n update(invalidationContext: InvalidationContext<O>): void {\n let {\n minItemSize = DEFAULT_OPTIONS.minItemSize,\n maxItemSize = DEFAULT_OPTIONS.maxItemSize,\n preserveAspectRatio = DEFAULT_OPTIONS.preserveAspectRatio,\n minSpace = DEFAULT_OPTIONS.minSpace,\n maxColumns = DEFAULT_OPTIONS.maxColumns,\n dropIndicatorThickness = DEFAULT_OPTIONS.dropIndicatorThickness\n } = invalidationContext.layoutOptions || {};\n this.dropIndicatorThickness = dropIndicatorThickness;\n\n let visibleWidth = this.virtualizer!.visibleRect.width;\n\n // The max item width is always the entire viewport.\n // If the max item height is infinity, scale in proportion to the max width.\n let maxItemWidth = Math.min(maxItemSize.width, visibleWidth);\n let maxItemHeight = Number.isFinite(maxItemSize.height)\n ? maxItemSize.height\n : Math.floor((minItemSize.height / minItemSize.width) * maxItemWidth);\n\n // Compute the number of rows and columns needed to display the content\n let columns = Math.floor(visibleWidth / (minItemSize.width + minSpace.width));\n let numColumns = Math.max(1, Math.min(maxColumns, columns));\n this.numColumns = numColumns;\n\n // Compute the available width (minus the space between items)\n let width = visibleWidth - (minSpace.width * Math.max(0, numColumns));\n\n // Compute the item width based on the space available\n let itemWidth = Math.floor(width / numColumns);\n itemWidth = Math.max(minItemSize.width, Math.min(maxItemWidth, itemWidth));\n\n // Compute the item height, which is proportional to the item width\n let t = ((itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width));\n let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);\n itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));\n\n // Compute the horizontal spacing and content height\n let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));\n this.gap = new Size(horizontalSpacing, minSpace.height);\n\n let collection = this.virtualizer!.collection;\n // Make sure to set rows to 0 if we performing a first time load or are rendering the empty state so that Virtualizer\n // won't try to render its body\n let isEmptyOrLoading = collection?.size === 0 || (collection.size === 1 && collection.getItem(collection.getFirstKey()!)!.type === 'loader');\n let rows = isEmptyOrLoading ? 0 : Math.ceil(collection.size / numColumns);\n let iterator = collection[Symbol.iterator]();\n let y = rows > 0 ? minSpace.height : 0;\n let newLayoutInfos = new Map();\n let skeleton: Node<T> | null = null;\n let skeletonCount = 0;\n for (let row = 0; row < rows; row++) {\n let maxHeight = 0;\n let rowLayoutInfos: LayoutInfo[] = [];\n for (let col = 0; col < numColumns; col++) {\n // Repeat skeleton until the end of the current row.\n let node = skeleton || iterator.next().value;\n if (!node) {\n break;\n }\n\n // We will add the loader after the skeletons so skip here\n if (node.type === 'loader') {\n continue;\n }\n\n if (node.type === 'skeleton') {\n skeleton = node;\n }\n\n let key = skeleton ? `${skeleton.key}-${skeletonCount++}` : node.key;\n let oldLayoutInfo = this.layoutInfos.get(key);\n let content = node;\n if (skeleton) {\n content = oldLayoutInfo && oldLayoutInfo.content.key === key ? oldLayoutInfo.content : {...skeleton, key};\n }\n let x = horizontalSpacing + col * (itemWidth + horizontalSpacing);\n let height = itemHeight;\n let estimatedSize = !preserveAspectRatio;\n if (oldLayoutInfo && estimatedSize) {\n height = oldLayoutInfo.rect.height;\n estimatedSize = invalidationContext.layoutOptionsChanged || invalidationContext.sizeChanged || oldLayoutInfo.estimatedSize || (oldLayoutInfo.content !== content);\n }\n\n let rect = new Rect(x, y, itemWidth, height);\n let layoutInfo = new LayoutInfo(node.type, key, rect);\n layoutInfo.estimatedSize = estimatedSize;\n layoutInfo.allowOverflow = true;\n layoutInfo.content = content;\n newLayoutInfos.set(key, layoutInfo);\n rowLayoutInfos.push(layoutInfo);\n\n maxHeight = Math.max(maxHeight, layoutInfo.rect.height);\n }\n\n for (let layoutInfo of rowLayoutInfos) {\n layoutInfo.rect.height = maxHeight;\n }\n\n y += maxHeight + minSpace.height;\n\n // Keep adding skeleton rows until we fill the viewport\n if (skeleton && row === rows - 1 && y < this.virtualizer!.visibleRect.height) {\n rows++;\n }\n }\n\n // Always add the loader sentinel if present in the collection so we can make sure it is never virtualized out.\n let lastNode = collection.getItem(collection.getLastKey()!);\n if (lastNode?.type === 'loader') {\n let rect = new Rect(horizontalSpacing, y, itemWidth, 0);\n let layoutInfo = new LayoutInfo('loader', lastNode.key, rect);\n newLayoutInfos.set(lastNode.key, layoutInfo);\n }\n\n this.layoutInfos = newLayoutInfos;\n this.contentSize = new Size(this.virtualizer!.visibleRect.width, y);\n }\n\n getLayoutInfo(key: Key): LayoutInfo | null {\n return this.layoutInfos.get(key) || null;\n }\n\n getContentSize(): Size {\n return this.contentSize;\n }\n\n getVisibleLayoutInfos(rect: Rect): LayoutInfo[] {\n let layoutInfos: LayoutInfo[] = [];\n for (let layoutInfo of this.layoutInfos.values()) {\n if (layoutInfo.rect.intersects(rect) || this.virtualizer!.isPersistedKey(layoutInfo.key) || layoutInfo.type === 'loader') {\n layoutInfos.push(layoutInfo);\n }\n }\n return layoutInfos;\n }\n\n updateItemSize(key: Key, size: Size): boolean {\n let layoutInfo = this.layoutInfos.get(key);\n if (!size || !layoutInfo) {\n return false;\n }\n\n if (size.height !== layoutInfo.rect.height) {\n let newLayoutInfo = layoutInfo.copy();\n newLayoutInfo.rect.height = size.height;\n newLayoutInfo.estimatedSize = false;\n this.layoutInfos.set(key, newLayoutInfo);\n return true;\n }\n\n return false;\n }\n\n getDropTargetFromPoint(x: number, y: number, isValidDropTarget: (target: DropTarget) => boolean): DropTarget {\n if (this.layoutInfos.size === 0) {\n return {type: 'root'};\n }\n\n x += this.virtualizer!.visibleRect.x;\n y += this.virtualizer!.visibleRect.y;\n\n // Find the closest item within on either side of the point using the gap width.\n let key: Key | null = null;\n if (this.numColumns === 1) {\n let searchRect = new Rect(x, Math.max(0, y - this.gap.height), 1, Math.max(1, this.gap.height * 2));\n let candidates = this.getVisibleLayoutInfos(searchRect);\n let minDistance = Infinity;\n for (let candidate of candidates) {\n // Ignore items outside the search rect, e.g. persisted keys.\n if (!candidate.rect.intersects(searchRect)) {\n continue;\n }\n\n let yDist = Math.abs(candidate.rect.y - y);\n let maxYDist = Math.abs(candidate.rect.maxY - y);\n let dist = Math.min(yDist, maxYDist);\n if (dist < minDistance) {\n minDistance = dist;\n key = candidate.key;\n }\n }\n } else {\n let searchRect = new Rect(Math.max(0, x - this.gap.width), y, this.gap.width * 2, 1);\n let candidates = this.getVisibleLayoutInfos(searchRect);\n let minDistance = Infinity;\n for (let candidate of candidates) {\n // Ignore items outside the search rect, e.g. persisted keys.\n if (!candidate.rect.intersects(searchRect)) {\n continue;\n }\n\n let xDist = Math.abs(candidate.rect.x - x);\n let maxXDist = Math.abs(candidate.rect.maxX - x);\n let dist = Math.min(xDist, maxXDist);\n if (dist < minDistance) {\n minDistance = dist;\n key = candidate.key;\n }\n }\n }\n\n let layoutInfo = key != null ? this.getLayoutInfo(key) : null;\n if (!layoutInfo) {\n return {type: 'root'};\n }\n\n let target: DropTarget = {\n type: 'item',\n key: layoutInfo.key,\n dropPosition: 'on'\n };\n\n let pos = this.numColumns === 1 ? y : x;\n let layoutInfoPos = this.numColumns === 1 ? layoutInfo.rect.y : layoutInfo.rect.x;\n let size = this.numColumns === 1 ? layoutInfo.rect.height : layoutInfo.rect.width;\n if (isValidDropTarget(target)) {\n // If dropping on the item is accepted, try the before/after positions\n // if within 5px of the start or end of the item.\n if (pos < layoutInfoPos + 5) {\n target.dropPosition = 'before';\n } else if (pos > layoutInfoPos + size - 5) {\n target.dropPosition = 'after';\n }\n } else {\n // If dropping on the item isn't accepted, try the target before or after depending on the position.\n let mid = layoutInfoPos + size / 2;\n if (pos <= mid && isValidDropTarget({...target, dropPosition: 'before'})) {\n target.dropPosition = 'before';\n } else if (pos >= mid && isValidDropTarget({...target, dropPosition: 'after'})) {\n target.dropPosition = 'after';\n }\n }\n\n return target;\n }\n\n getDropTargetLayoutInfo(target: ItemDropTarget): LayoutInfo {\n let layoutInfo = this.getLayoutInfo(target.key)!;\n let rect: Rect;\n if (this.numColumns === 1) {\n // Flip from vertical to horizontal if only one column is visible.\n rect = new Rect(\n layoutInfo.rect.x,\n target.dropPosition === 'before'\n ? layoutInfo.rect.y - this.gap.height / 2 - this.dropIndicatorThickness / 2\n : layoutInfo.rect.maxY + this.gap.height / 2 - this.dropIndicatorThickness / 2,\n layoutInfo.rect.width,\n this.dropIndicatorThickness\n );\n } else {\n rect = new Rect(\n target.dropPosition === 'before'\n ? layoutInfo.rect.x - this.gap.width / 2 - this.dropIndicatorThickness / 2\n : layoutInfo.rect.maxX + this.gap.width / 2 - this.dropIndicatorThickness / 2,\n layoutInfo.rect.y,\n this.dropIndicatorThickness,\n layoutInfo.rect.height\n );\n }\n\n return new LayoutInfo('dropIndicator', target.key + ':' + target.dropPosition, rect);\n }\n}\n"],"names":[],"version":3,"file":"GridLayout.module.js.map"}
|
package/dist/ListLayout.main.js
CHANGED
|
@@ -76,7 +76,7 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
|
|
|
76
76
|
return false;
|
|
77
77
|
}
|
|
78
78
|
isVisible(node, rect) {
|
|
79
|
-
return node.layoutInfo.rect.intersects(rect) || node.layoutInfo.isSticky || node.layoutInfo.type === 'header' || this.virtualizer.isPersistedKey(node.layoutInfo.key);
|
|
79
|
+
return node.layoutInfo.rect.intersects(rect) || node.layoutInfo.isSticky || node.layoutInfo.type === 'header' || node.layoutInfo.type === 'loader' || this.virtualizer.isPersistedKey(node.layoutInfo.key);
|
|
80
80
|
}
|
|
81
81
|
shouldInvalidateEverything(invalidationContext) {
|
|
82
82
|
// Invalidate cache if the size of the collection changed.
|
|
@@ -131,6 +131,8 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
|
|
|
131
131
|
let collection = this.virtualizer.collection;
|
|
132
132
|
let skipped = 0;
|
|
133
133
|
let nodes = [];
|
|
134
|
+
let isEmptyOrLoading = (collection === null || collection === void 0 ? void 0 : collection.size) === 0 || collection.size === 1 && collection.getItem(collection.getFirstKey()).type === 'loader';
|
|
135
|
+
if (isEmptyOrLoading) y = 0;
|
|
134
136
|
for (let node of collection){
|
|
135
137
|
var _this_rowHeight, _ref;
|
|
136
138
|
let rowHeight = ((_ref = (_this_rowHeight = this.rowHeight) !== null && _this_rowHeight !== void 0 ? _this_rowHeight : this.estimatedRowHeight) !== null && _ref !== void 0 ? _ref : $fe69e47e38ed0ac4$var$DEFAULT_HEIGHT) + this.gap;
|
|
@@ -144,12 +146,23 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
|
|
|
144
146
|
y = layoutNode.layoutInfo.rect.maxY + this.gap;
|
|
145
147
|
nodes.push(layoutNode);
|
|
146
148
|
if (node.type === 'item' && y > this.requestedRect.maxY) {
|
|
147
|
-
|
|
149
|
+
var _nodes_at;
|
|
150
|
+
let itemsAfterRect = collection.size - (nodes.length + skipped);
|
|
151
|
+
let lastNode = collection.getItem(collection.getLastKey());
|
|
152
|
+
if ((lastNode === null || lastNode === void 0 ? void 0 : lastNode.type) === 'loader') itemsAfterRect--;
|
|
153
|
+
y += itemsAfterRect * rowHeight;
|
|
154
|
+
// Always add the loader sentinel if present. This assumes the loader is the last option/row
|
|
155
|
+
// will need to refactor when handling multi section loading
|
|
156
|
+
if ((lastNode === null || lastNode === void 0 ? void 0 : lastNode.type) === 'loader' && ((_nodes_at = nodes.at(-1)) === null || _nodes_at === void 0 ? void 0 : _nodes_at.layoutInfo.type) !== 'loader') {
|
|
157
|
+
let loader = this.buildChild(lastNode, this.padding, y, null);
|
|
158
|
+
nodes.push(loader);
|
|
159
|
+
y = loader.layoutInfo.rect.maxY;
|
|
160
|
+
}
|
|
148
161
|
break;
|
|
149
162
|
}
|
|
150
163
|
}
|
|
151
164
|
y -= this.gap;
|
|
152
|
-
y += this.padding;
|
|
165
|
+
y += isEmptyOrLoading ? 0 : this.padding;
|
|
153
166
|
this.contentSize = new (0, $iId4j$reactstatelyvirtualizer.Size)(this.virtualizer.visibleRect.width, y);
|
|
154
167
|
return nodes;
|
|
155
168
|
}
|
|
@@ -161,6 +174,7 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
|
|
|
161
174
|
if (this.isValid(node, y)) return this.layoutNodes.get(node.key);
|
|
162
175
|
let layoutNode = this.buildNode(node, x, y);
|
|
163
176
|
layoutNode.layoutInfo.parentKey = parentKey !== null && parentKey !== void 0 ? parentKey : null;
|
|
177
|
+
layoutNode.layoutInfo.allowOverflow = true;
|
|
164
178
|
this.layoutNodes.set(node.key, layoutNode);
|
|
165
179
|
return layoutNode;
|
|
166
180
|
}
|
|
@@ -174,6 +188,8 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
|
|
|
174
188
|
return this.buildSectionHeader(node, x, y);
|
|
175
189
|
case 'loader':
|
|
176
190
|
return this.buildLoader(node, x, y);
|
|
191
|
+
case 'separator':
|
|
192
|
+
return this.buildItem(node, x, y);
|
|
177
193
|
default:
|
|
178
194
|
throw new Error('Unsupported node type: ' + node.type);
|
|
179
195
|
}
|
|
@@ -182,7 +198,10 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
|
|
|
182
198
|
let rect = new (0, $iId4j$reactstatelyvirtualizer.Rect)(x, y, this.padding, 0);
|
|
183
199
|
let layoutInfo = new (0, $iId4j$reactstatelyvirtualizer.LayoutInfo)('loader', node.key, rect);
|
|
184
200
|
rect.width = this.virtualizer.contentSize.width - this.padding - x;
|
|
185
|
-
|
|
201
|
+
var _this_loaderHeight, _ref, _ref1;
|
|
202
|
+
// Note that if the user provides isLoading to their sentinel during a case where they only want to render the emptyState, this will reserve
|
|
203
|
+
// room for the loader alongside rendering the emptyState
|
|
204
|
+
rect.height = node.props.isLoading ? (_ref1 = (_ref = (_this_loaderHeight = this.loaderHeight) !== null && _this_loaderHeight !== void 0 ? _this_loaderHeight : this.rowHeight) !== null && _ref !== void 0 ? _ref : this.estimatedRowHeight) !== null && _ref1 !== void 0 ? _ref1 : $fe69e47e38ed0ac4$var$DEFAULT_HEIGHT : 0;
|
|
186
205
|
return {
|
|
187
206
|
layoutInfo: layoutInfo,
|
|
188
207
|
validRect: rect.intersection(this.requestedRect)
|
|
@@ -330,7 +349,7 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
|
|
|
330
349
|
x += this.virtualizer.visibleRect.x;
|
|
331
350
|
y += this.virtualizer.visibleRect.y;
|
|
332
351
|
// Find the closest item within on either side of the point using the gap width.
|
|
333
|
-
let searchRect = new (0, $iId4j$reactstatelyvirtualizer.Rect)(x, Math.max(0, y - this.gap), 1, this.gap * 2);
|
|
352
|
+
let searchRect = new (0, $iId4j$reactstatelyvirtualizer.Rect)(x, Math.max(0, y - this.gap), 1, Math.max(1, this.gap * 2));
|
|
334
353
|
let candidates = this.getVisibleLayoutInfos(searchRect);
|
|
335
354
|
let key = null;
|
|
336
355
|
let minDistance = Infinity;
|