@react-stately/layout 4.1.1 → 4.2.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 +131 -63
- package/dist/GridLayout.main.js.map +1 -1
- package/dist/GridLayout.mjs +131 -63
- package/dist/GridLayout.module.js +131 -63
- package/dist/GridLayout.module.js.map +1 -1
- package/dist/ListLayout.main.js +62 -21
- package/dist/ListLayout.main.js.map +1 -1
- package/dist/ListLayout.mjs +63 -22
- package/dist/ListLayout.module.js +63 -22
- package/dist/ListLayout.module.js.map +1 -1
- package/dist/TableLayout.main.js +35 -23
- package/dist/TableLayout.main.js.map +1 -1
- package/dist/TableLayout.mjs +36 -24
- package/dist/TableLayout.module.js +36 -24
- package/dist/TableLayout.module.js.map +1 -1
- package/dist/WaterfallLayout.main.js +212 -0
- package/dist/WaterfallLayout.main.js.map +1 -0
- package/dist/WaterfallLayout.mjs +207 -0
- package/dist/WaterfallLayout.module.js +207 -0
- package/dist/WaterfallLayout.module.js.map +1 -0
- package/dist/import.mjs +3 -1
- package/dist/main.js +3 -0
- package/dist/main.js.map +1 -1
- package/dist/module.js +3 -1
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +102 -29
- package/dist/types.d.ts.map +1 -1
- package/package.json +10 -9
- package/src/GridLayout.ts +194 -89
- package/src/ListLayout.ts +105 -36
- package/src/TableLayout.ts +44 -27
- package/src/WaterfallLayout.ts +302 -0
- package/src/index.ts +2 -0
|
@@ -11,80 +11,153 @@ import {Size as $ipgKF$Size, Rect as $ipgKF$Rect, LayoutInfo as $ipgKF$LayoutInf
|
|
|
11
11
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
|
+
const $a58592d295a170a4$var$DEFAULT_OPTIONS = {
|
|
15
|
+
minItemSize: new (0, $ipgKF$Size)(200, 200),
|
|
16
|
+
maxItemSize: new (0, $ipgKF$Size)(Infinity, Infinity),
|
|
17
|
+
preserveAspectRatio: false,
|
|
18
|
+
minSpace: new (0, $ipgKF$Size)(18, 18),
|
|
19
|
+
maxColumns: Infinity,
|
|
20
|
+
dropIndicatorThickness: 2
|
|
21
|
+
};
|
|
14
22
|
class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
|
|
15
|
-
|
|
23
|
+
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
|
+
}
|
|
26
|
+
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
|
+
this.dropIndicatorThickness = dropIndicatorThickness;
|
|
16
29
|
let visibleWidth = this.virtualizer.visibleRect.width;
|
|
17
30
|
// The max item width is always the entire viewport.
|
|
18
31
|
// If the max item height is infinity, scale in proportion to the max width.
|
|
19
|
-
let maxItemWidth = Math.min(
|
|
20
|
-
let maxItemHeight = Number.isFinite(
|
|
32
|
+
let maxItemWidth = Math.min(maxItemSize.width, visibleWidth);
|
|
33
|
+
let maxItemHeight = Number.isFinite(maxItemSize.height) ? maxItemSize.height : Math.floor(minItemSize.height / minItemSize.width * maxItemWidth);
|
|
21
34
|
// Compute the number of rows and columns needed to display the content
|
|
22
|
-
let columns = Math.floor(visibleWidth / (
|
|
23
|
-
|
|
35
|
+
let columns = Math.floor(visibleWidth / (minItemSize.width + minSpace.width));
|
|
36
|
+
let numColumns = Math.max(1, Math.min(maxColumns, columns));
|
|
37
|
+
this.numColumns = numColumns;
|
|
24
38
|
// Compute the available width (minus the space between items)
|
|
25
|
-
let width = visibleWidth -
|
|
39
|
+
let width = visibleWidth - minSpace.width * Math.max(0, numColumns);
|
|
26
40
|
// Compute the item width based on the space available
|
|
27
|
-
let itemWidth = Math.floor(width /
|
|
28
|
-
itemWidth = Math.max(
|
|
41
|
+
let itemWidth = Math.floor(width / numColumns);
|
|
42
|
+
itemWidth = Math.max(minItemSize.width, Math.min(maxItemWidth, itemWidth));
|
|
29
43
|
// Compute the item height, which is proportional to the item width
|
|
30
|
-
let t = (itemWidth -
|
|
31
|
-
let itemHeight =
|
|
32
|
-
itemHeight = Math.max(
|
|
33
|
-
this.itemSize = new (0, $ipgKF$Size)(itemWidth, itemHeight);
|
|
44
|
+
let t = (itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width);
|
|
45
|
+
let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);
|
|
46
|
+
itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));
|
|
34
47
|
// Compute the horizontal spacing and content height
|
|
35
|
-
|
|
36
|
-
this.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
let
|
|
41
|
-
let
|
|
42
|
-
let
|
|
43
|
-
let
|
|
44
|
-
|
|
45
|
-
let
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));
|
|
49
|
+
this.gap = new (0, $ipgKF$Size)(horizontalSpacing, minSpace.height);
|
|
50
|
+
let rows = Math.ceil(this.virtualizer.collection.size / numColumns);
|
|
51
|
+
let iterator = this.virtualizer.collection[Symbol.iterator]();
|
|
52
|
+
let y = rows > 0 ? minSpace.height : 0;
|
|
53
|
+
let newLayoutInfos = new Map();
|
|
54
|
+
let skeleton = null;
|
|
55
|
+
let skeletonCount = 0;
|
|
56
|
+
for(let row = 0; row < rows; row++){
|
|
57
|
+
let maxHeight = 0;
|
|
58
|
+
let rowLayoutInfos = [];
|
|
59
|
+
for(let col = 0; col < numColumns; col++){
|
|
60
|
+
// Repeat skeleton until the end of the current row.
|
|
61
|
+
let node = skeleton || iterator.next().value;
|
|
62
|
+
if (!node) break;
|
|
63
|
+
if (node.type === 'skeleton') skeleton = node;
|
|
64
|
+
let key = skeleton ? `${skeleton.key}-${skeletonCount++}` : node.key;
|
|
65
|
+
let oldLayoutInfo = this.layoutInfos.get(key);
|
|
66
|
+
let content = node;
|
|
67
|
+
if (skeleton) content = oldLayoutInfo && oldLayoutInfo.content.key === key ? oldLayoutInfo.content : {
|
|
68
|
+
...skeleton,
|
|
69
|
+
key: key
|
|
70
|
+
};
|
|
71
|
+
let x = horizontalSpacing + col * (itemWidth + horizontalSpacing);
|
|
72
|
+
let height = itemHeight;
|
|
73
|
+
let estimatedSize = !preserveAspectRatio;
|
|
74
|
+
if (oldLayoutInfo && estimatedSize) {
|
|
75
|
+
height = oldLayoutInfo.rect.height;
|
|
76
|
+
estimatedSize = invalidationContext.layoutOptionsChanged || invalidationContext.sizeChanged || oldLayoutInfo.estimatedSize || oldLayoutInfo.content !== content;
|
|
77
|
+
}
|
|
78
|
+
let rect = new (0, $ipgKF$Rect)(x, y, itemWidth, height);
|
|
79
|
+
let layoutInfo = new (0, $ipgKF$LayoutInfo)(node.type, key, rect);
|
|
80
|
+
layoutInfo.estimatedSize = estimatedSize;
|
|
81
|
+
layoutInfo.allowOverflow = true;
|
|
82
|
+
layoutInfo.content = content;
|
|
83
|
+
newLayoutInfos.set(key, layoutInfo);
|
|
84
|
+
rowLayoutInfos.push(layoutInfo);
|
|
85
|
+
maxHeight = Math.max(maxHeight, layoutInfo.rect.height);
|
|
86
|
+
}
|
|
87
|
+
for (let layoutInfo of rowLayoutInfos)layoutInfo.rect.height = maxHeight;
|
|
88
|
+
y += maxHeight + minSpace.height;
|
|
89
|
+
// Keep adding skeleton rows until we fill the viewport
|
|
90
|
+
if (skeleton && row === rows - 1 && y < this.virtualizer.visibleRect.height) rows++;
|
|
53
91
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
getIndexAtPoint(x, y) {
|
|
58
|
-
let itemHeight = this.itemSize.height + this.minSpace.height;
|
|
59
|
-
let itemWidth = this.itemSize.width + this.horizontalSpacing;
|
|
60
|
-
return Math.max(0, Math.min(this.virtualizer.collection.size - 1, Math.floor(y / itemHeight) * this.numColumns + Math.floor((x - this.horizontalSpacing) / itemWidth)));
|
|
92
|
+
this.layoutInfos = newLayoutInfos;
|
|
93
|
+
this.contentSize = new (0, $ipgKF$Size)(this.virtualizer.visibleRect.width, y);
|
|
61
94
|
}
|
|
62
95
|
getLayoutInfo(key) {
|
|
63
|
-
|
|
64
|
-
return node ? this.layoutInfos[node.index] : null;
|
|
65
|
-
}
|
|
66
|
-
getLayoutInfoForNode(node) {
|
|
67
|
-
let idx = node.index;
|
|
68
|
-
let row = Math.floor(idx / this.numColumns);
|
|
69
|
-
let column = idx % this.numColumns;
|
|
70
|
-
let x = this.horizontalSpacing + column * (this.itemSize.width + this.horizontalSpacing);
|
|
71
|
-
let y = this.minSpace.height + row * (this.itemSize.height + this.minSpace.height);
|
|
72
|
-
let rect = new (0, $ipgKF$Rect)(x, y, this.itemSize.width, this.itemSize.height);
|
|
73
|
-
return new (0, $ipgKF$LayoutInfo)(node.type, node.key, rect);
|
|
96
|
+
return this.layoutInfos.get(key);
|
|
74
97
|
}
|
|
75
98
|
getContentSize() {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
99
|
+
return this.contentSize;
|
|
100
|
+
}
|
|
101
|
+
getVisibleLayoutInfos(rect) {
|
|
102
|
+
let layoutInfos = [];
|
|
103
|
+
for (let layoutInfo of this.layoutInfos.values())if (layoutInfo.rect.intersects(rect) || this.virtualizer.isPersistedKey(layoutInfo.key)) layoutInfos.push(layoutInfo);
|
|
104
|
+
return layoutInfos;
|
|
105
|
+
}
|
|
106
|
+
updateItemSize(key, size) {
|
|
107
|
+
let layoutInfo = this.layoutInfos.get(key);
|
|
108
|
+
if (!size || !layoutInfo) return false;
|
|
109
|
+
if (size.height !== layoutInfo.rect.height) {
|
|
110
|
+
let newLayoutInfo = layoutInfo.copy();
|
|
111
|
+
newLayoutInfo.rect.height = size.height;
|
|
112
|
+
newLayoutInfo.estimatedSize = false;
|
|
113
|
+
this.layoutInfos.set(key, newLayoutInfo);
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
79
117
|
}
|
|
80
118
|
getDropTargetFromPoint(x, y, isValidDropTarget) {
|
|
81
|
-
if (this.layoutInfos.
|
|
119
|
+
if (this.layoutInfos.size === 0) return {
|
|
82
120
|
type: 'root'
|
|
83
121
|
};
|
|
84
122
|
x += this.virtualizer.visibleRect.x;
|
|
85
123
|
y += this.virtualizer.visibleRect.y;
|
|
86
|
-
|
|
87
|
-
let
|
|
124
|
+
// Find the closest item within on either side of the point using the gap width.
|
|
125
|
+
let key = null;
|
|
126
|
+
if (this.numColumns === 1) {
|
|
127
|
+
let searchRect = new (0, $ipgKF$Rect)(x, Math.max(0, y - this.gap.height), 1, this.gap.height * 2);
|
|
128
|
+
let candidates = this.getVisibleLayoutInfos(searchRect);
|
|
129
|
+
let minDistance = Infinity;
|
|
130
|
+
for (let candidate of candidates){
|
|
131
|
+
// Ignore items outside the search rect, e.g. persisted keys.
|
|
132
|
+
if (!candidate.rect.intersects(searchRect)) continue;
|
|
133
|
+
let yDist = Math.abs(candidate.rect.y - y);
|
|
134
|
+
let maxYDist = Math.abs(candidate.rect.maxY - y);
|
|
135
|
+
let dist = Math.min(yDist, maxYDist);
|
|
136
|
+
if (dist < minDistance) {
|
|
137
|
+
minDistance = dist;
|
|
138
|
+
key = candidate.key;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
let searchRect = new (0, $ipgKF$Rect)(Math.max(0, x - this.gap.width), y, this.gap.width * 2, 1);
|
|
143
|
+
let candidates = this.getVisibleLayoutInfos(searchRect);
|
|
144
|
+
let minDistance = Infinity;
|
|
145
|
+
for (let candidate of candidates){
|
|
146
|
+
// Ignore items outside the search rect, e.g. persisted keys.
|
|
147
|
+
if (!candidate.rect.intersects(searchRect)) continue;
|
|
148
|
+
let xDist = Math.abs(candidate.rect.x - x);
|
|
149
|
+
let maxXDist = Math.abs(candidate.rect.maxX - x);
|
|
150
|
+
let dist = Math.min(xDist, maxXDist);
|
|
151
|
+
if (dist < minDistance) {
|
|
152
|
+
minDistance = dist;
|
|
153
|
+
key = candidate.key;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
let layoutInfo = key != null ? this.getLayoutInfo(key) : null;
|
|
158
|
+
if (!layoutInfo) return {
|
|
159
|
+
type: 'root'
|
|
160
|
+
};
|
|
88
161
|
let target = {
|
|
89
162
|
type: 'item',
|
|
90
163
|
key: layoutInfo.key,
|
|
@@ -116,17 +189,12 @@ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
|
|
|
116
189
|
let layoutInfo = this.getLayoutInfo(target.key);
|
|
117
190
|
let rect;
|
|
118
191
|
if (this.numColumns === 1) // Flip from vertical to horizontal if only one column is visible.
|
|
119
|
-
rect = new (0, $ipgKF$Rect)(layoutInfo.rect.x, target.dropPosition === 'before' ? layoutInfo.rect.y - this.
|
|
120
|
-
else rect = new (0, $ipgKF$Rect)(target.dropPosition === 'before' ? layoutInfo.rect.x - this.
|
|
192
|
+
rect = new (0, $ipgKF$Rect)(layoutInfo.rect.x, target.dropPosition === 'before' ? layoutInfo.rect.y - this.gap.height / 2 - this.dropIndicatorThickness / 2 : layoutInfo.rect.maxY + this.gap.height / 2 - this.dropIndicatorThickness / 2, layoutInfo.rect.width, this.dropIndicatorThickness);
|
|
193
|
+
else rect = new (0, $ipgKF$Rect)(target.dropPosition === 'before' ? layoutInfo.rect.x - this.gap.width / 2 - this.dropIndicatorThickness / 2 : layoutInfo.rect.maxX + this.gap.width / 2 - this.dropIndicatorThickness / 2, layoutInfo.rect.y, this.dropIndicatorThickness, layoutInfo.rect.height);
|
|
121
194
|
return new (0, $ipgKF$LayoutInfo)('dropIndicator', target.key + ':' + target.dropPosition, rect);
|
|
122
195
|
}
|
|
123
|
-
constructor(
|
|
124
|
-
super(), this.
|
|
125
|
-
this.minItemSize = options.minItemSize || new (0, $ipgKF$Size)(200, 200);
|
|
126
|
-
this.maxItemSize = options.maxItemSize || new (0, $ipgKF$Size)(Infinity, Infinity);
|
|
127
|
-
this.minSpace = options.minSpace || new (0, $ipgKF$Size)(18, 18);
|
|
128
|
-
this.maxColumns = options.maxColumns || Infinity;
|
|
129
|
-
this.dropIndicatorThickness = options.dropIndicatorThickness || 2;
|
|
196
|
+
constructor(...args){
|
|
197
|
+
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();
|
|
130
198
|
}
|
|
131
199
|
}
|
|
132
200
|
|
|
@@ -1 +1 @@
|
|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AAC,MAAM;QAI1B,OAAO,IAAI,CAAA,GAAA,iBAAS,EAAE,iBAAiB,OAAO,GAAG,GAAG,MAAM,OAAO,YAAY,EAAE;IACjF;IAvKA,YAAY,OAA0B,CAAE;QACtC,KAAK,SANG,WAAiB,IAAI,CAAA,GAAA,WAAG,UACxB,aAAqB,QACrB,oBAA4B,QAC5B,cAA4B,EAAE;QAItC,IAAI,CAAC,WAAW,GAAG,QAAQ,WAAW,IAAI,IAAI,CAAA,GAAA,WAAG,EAAE,KAAK;QACxD,IAAI,CAAC,WAAW,GAAG,QAAQ,WAAW,IAAI,IAAI,CAAA,GAAA,WAAG,EAAE,UAAU;QAC7D,IAAI,CAAC,QAAQ,GAAG,QAAQ,QAAQ,IAAI,IAAI,CAAA,GAAA,WAAG,EAAE,IAAI;QACjD,IAAI,CAAC,UAAU,GAAG,QAAQ,UAAU,IAAI;QACxC,IAAI,CAAC,sBAAsB,GAAG,QAAQ,sBAAsB,IAAI;IAClE;AAiKF","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 {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 * 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\nexport class GridLayout<T, O = any> extends Layout<Node<T>, O> implements DropTargetDelegate {\n protected minItemSize: Size;\n protected maxItemSize: Size;\n protected minSpace: Size;\n protected maxColumns: number;\n protected dropIndicatorThickness: number;\n protected itemSize: Size = new Size();\n protected numColumns: number = 0;\n protected horizontalSpacing: number = 0;\n protected layoutInfos: LayoutInfo[] = [];\n\n constructor(options: GridLayoutOptions) {\n super();\n this.minItemSize = options.minItemSize || new Size(200, 200);\n this.maxItemSize = options.maxItemSize || new Size(Infinity, Infinity);\n this.minSpace = options.minSpace || new Size(18, 18);\n this.maxColumns = options.maxColumns || Infinity;\n this.dropIndicatorThickness = options.dropIndicatorThickness || 2;\n }\n\n update(): void {\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(this.maxItemSize.width, visibleWidth);\n let maxItemHeight = Number.isFinite(this.maxItemSize.height) \n ? this.maxItemSize.height\n : Math.floor((this.minItemSize.height / this.minItemSize.width) * maxItemWidth);\n\n // Compute the number of rows and columns needed to display the content\n let columns = Math.floor(visibleWidth / (this.minItemSize.width + this.minSpace.width));\n this.numColumns = Math.max(1, Math.min(this.maxColumns, columns));\n\n // Compute the available width (minus the space between items)\n let width = visibleWidth - (this.minSpace.width * Math.max(0, this.numColumns));\n\n // Compute the item width based on the space available\n let itemWidth = Math.floor(width / this.numColumns);\n itemWidth = Math.max(this.minItemSize.width, Math.min(maxItemWidth, itemWidth));\n\n // Compute the item height, which is proportional to the item width\n let t = ((itemWidth - this.minItemSize.width) / Math.max(1, maxItemWidth - this.minItemSize.width));\n let itemHeight = this.minItemSize.height + Math.floor((maxItemHeight - this.minItemSize.height) * t);\n itemHeight = Math.max(this.minItemSize.height, Math.min(maxItemHeight, itemHeight));\n this.itemSize = new Size(itemWidth, itemHeight);\n\n // Compute the horizontal spacing and content height\n this.horizontalSpacing = Math.floor((visibleWidth - this.numColumns * this.itemSize.width) / (this.numColumns + 1));\n\n this.layoutInfos = [];\n for (let node of this.virtualizer!.collection) {\n this.layoutInfos.push(this.getLayoutInfoForNode(node));\n }\n }\n\n getVisibleLayoutInfos(rect: Rect): LayoutInfo[] {\n let firstVisibleItem = this.getIndexAtPoint(rect.x, rect.y);\n let lastVisibleItem = this.getIndexAtPoint(rect.maxX, rect.maxY);\n let result = this.layoutInfos.slice(firstVisibleItem, lastVisibleItem + 1);\n let persistedIndices: number[] = [];\n for (let key of this.virtualizer!.persistedKeys) {\n let item = this.virtualizer!.collection.getItem(key);\n if (item?.index != null) {\n persistedIndices.push(item.index);\n }\n }\n persistedIndices.sort((a, b) => a - b);\n \n let persistedBefore: LayoutInfo[] = [];\n for (let index of persistedIndices) {\n if (index < firstVisibleItem) {\n persistedBefore.push(this.layoutInfos[index]);\n } else if (index > lastVisibleItem) {\n result.push(this.layoutInfos[index]);\n }\n }\n result.unshift(...persistedBefore);\n return result;\n }\n\n protected getIndexAtPoint(x: number, y: number) {\n let itemHeight = this.itemSize.height + this.minSpace.height;\n let itemWidth = this.itemSize.width + this.horizontalSpacing;\n return Math.max(0,\n Math.min(\n this.virtualizer!.collection.size - 1,\n Math.floor(y / itemHeight) * this.numColumns + Math.floor((x - this.horizontalSpacing) / itemWidth)\n )\n );\n }\n\n getLayoutInfo(key: Key): LayoutInfo | null {\n let node = this.virtualizer!.collection.getItem(key);\n return node ? this.layoutInfos[node.index] : null;\n }\n\n protected getLayoutInfoForNode(node: Node<T>): LayoutInfo {\n let idx = node.index;\n let row = Math.floor(idx / this.numColumns);\n let column = idx % this.numColumns;\n let x = this.horizontalSpacing + column * (this.itemSize.width + this.horizontalSpacing);\n let y = this.minSpace.height + row * (this.itemSize.height + this.minSpace.height);\n let rect = new Rect(x, y, this.itemSize.width, this.itemSize.height);\n return new LayoutInfo(node.type, node.key, rect);\n }\n\n getContentSize(): Size {\n let numRows = Math.ceil(this.virtualizer!.collection.size / this.numColumns);\n let contentHeight = this.minSpace.height + numRows * (this.itemSize.height + this.minSpace.height); \n return new Size(this.virtualizer!.visibleRect.width, contentHeight);\n }\n\n getDropTargetFromPoint(x: number, y: number, isValidDropTarget: (target: DropTarget) => boolean): DropTarget {\n if (this.layoutInfos.length === 0) {\n return {type: 'root'};\n }\n\n x += this.virtualizer!.visibleRect.x;\n y += this.virtualizer!.visibleRect.y;\n let index = this.getIndexAtPoint(x, y);\n\n let layoutInfo = this.layoutInfos[index];\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.minSpace.height / 2 - this.dropIndicatorThickness / 2\n : layoutInfo.rect.maxY + this.minSpace.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.horizontalSpacing / 2 - this.dropIndicatorThickness / 2 \n : layoutInfo.rect.maxX + this.horizontalSpacing / 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;QACxD,IAAI,eACF,cAAc,sCAAgB,WAAW,eACzC,cAAc,sCAAgB,WAAW,uBACzC,sBAAsB,sCAAgB,mBAAm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["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 {\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)) {\n layoutInfos.push(layoutInfo);\n }\n }\n return layoutInfos;\n }\n\n updateItemSize(key: Key, size: Size) {\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"}
|
package/dist/ListLayout.main.js
CHANGED
|
@@ -35,7 +35,7 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
|
|
|
35
35
|
// (only if height > 1 for getDropTargetFromPoint)
|
|
36
36
|
if (rect.height > 1) {
|
|
37
37
|
var _this_rowHeight, _ref;
|
|
38
|
-
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;
|
|
38
|
+
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;
|
|
39
39
|
rect.y = Math.floor(rect.y / rowHeight) * rowHeight;
|
|
40
40
|
rect.height = Math.ceil(rect.height / rowHeight) * rowHeight;
|
|
41
41
|
}
|
|
@@ -81,7 +81,13 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
|
|
|
81
81
|
shouldInvalidateEverything(invalidationContext) {
|
|
82
82
|
// Invalidate cache if the size of the collection changed.
|
|
83
83
|
// In this case, we need to recalculate the entire layout.
|
|
84
|
-
|
|
84
|
+
// Also invalidate if fixed sizes/gaps change.
|
|
85
|
+
let options = invalidationContext.layoutOptions;
|
|
86
|
+
var _options_rowHeight, _options_headingHeight, _options_loaderHeight, _options_gap, _options_padding;
|
|
87
|
+
return invalidationContext.sizeChanged || this.rowHeight !== ((_options_rowHeight = options === null || options === void 0 ? void 0 : options.rowHeight) !== null && _options_rowHeight !== void 0 ? _options_rowHeight : this.rowHeight) || this.headingHeight !== ((_options_headingHeight = options === null || options === void 0 ? void 0 : options.headingHeight) !== null && _options_headingHeight !== void 0 ? _options_headingHeight : this.headingHeight) || this.loaderHeight !== ((_options_loaderHeight = options === null || options === void 0 ? void 0 : options.loaderHeight) !== null && _options_loaderHeight !== void 0 ? _options_loaderHeight : this.loaderHeight) || this.gap !== ((_options_gap = options === null || options === void 0 ? void 0 : options.gap) !== null && _options_gap !== void 0 ? _options_gap : this.gap) || this.padding !== ((_options_padding = options === null || options === void 0 ? void 0 : options.padding) !== null && _options_padding !== void 0 ? _options_padding : this.padding);
|
|
88
|
+
}
|
|
89
|
+
shouldInvalidateLayoutOptions(newOptions, oldOptions) {
|
|
90
|
+
return newOptions.rowHeight !== oldOptions.rowHeight || newOptions.estimatedRowHeight !== oldOptions.estimatedRowHeight || newOptions.headingHeight !== oldOptions.headingHeight || newOptions.estimatedHeadingHeight !== oldOptions.estimatedHeadingHeight || newOptions.loaderHeight !== oldOptions.loaderHeight || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness || newOptions.gap !== oldOptions.gap || newOptions.padding !== oldOptions.padding;
|
|
85
91
|
}
|
|
86
92
|
update(invalidationContext) {
|
|
87
93
|
let collection = this.virtualizer.collection;
|
|
@@ -92,6 +98,23 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
|
|
|
92
98
|
this.requestedRect = this.virtualizer.visibleRect.copy();
|
|
93
99
|
this.layoutNodes.clear();
|
|
94
100
|
}
|
|
101
|
+
let options = invalidationContext.layoutOptions;
|
|
102
|
+
var _options_rowHeight;
|
|
103
|
+
this.rowHeight = (_options_rowHeight = options === null || options === void 0 ? void 0 : options.rowHeight) !== null && _options_rowHeight !== void 0 ? _options_rowHeight : this.rowHeight;
|
|
104
|
+
var _options_estimatedRowHeight;
|
|
105
|
+
this.estimatedRowHeight = (_options_estimatedRowHeight = options === null || options === void 0 ? void 0 : options.estimatedRowHeight) !== null && _options_estimatedRowHeight !== void 0 ? _options_estimatedRowHeight : this.estimatedRowHeight;
|
|
106
|
+
var _options_headingHeight;
|
|
107
|
+
this.headingHeight = (_options_headingHeight = options === null || options === void 0 ? void 0 : options.headingHeight) !== null && _options_headingHeight !== void 0 ? _options_headingHeight : this.headingHeight;
|
|
108
|
+
var _options_estimatedHeadingHeight;
|
|
109
|
+
this.estimatedHeadingHeight = (_options_estimatedHeadingHeight = options === null || options === void 0 ? void 0 : options.estimatedHeadingHeight) !== null && _options_estimatedHeadingHeight !== void 0 ? _options_estimatedHeadingHeight : this.estimatedHeadingHeight;
|
|
110
|
+
var _options_loaderHeight;
|
|
111
|
+
this.loaderHeight = (_options_loaderHeight = options === null || options === void 0 ? void 0 : options.loaderHeight) !== null && _options_loaderHeight !== void 0 ? _options_loaderHeight : this.loaderHeight;
|
|
112
|
+
var _options_dropIndicatorThickness;
|
|
113
|
+
this.dropIndicatorThickness = (_options_dropIndicatorThickness = options === null || options === void 0 ? void 0 : options.dropIndicatorThickness) !== null && _options_dropIndicatorThickness !== void 0 ? _options_dropIndicatorThickness : this.dropIndicatorThickness;
|
|
114
|
+
var _options_gap;
|
|
115
|
+
this.gap = (_options_gap = options === null || options === void 0 ? void 0 : options.gap) !== null && _options_gap !== void 0 ? _options_gap : this.gap;
|
|
116
|
+
var _options_padding;
|
|
117
|
+
this.padding = (_options_padding = options === null || options === void 0 ? void 0 : options.padding) !== null && _options_padding !== void 0 ? _options_padding : this.padding;
|
|
95
118
|
this.rootNodes = this.buildCollection();
|
|
96
119
|
// Remove deleted layout nodes
|
|
97
120
|
if (this.lastCollection && collection !== this.lastCollection) {
|
|
@@ -100,32 +123,33 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
|
|
|
100
123
|
if (layoutNode) this.layoutNodes.delete(key);
|
|
101
124
|
}
|
|
102
125
|
}
|
|
103
|
-
this.lastWidth = this.virtualizer.visibleRect.width;
|
|
104
126
|
this.lastCollection = collection;
|
|
105
127
|
this.invalidateEverything = false;
|
|
106
128
|
this.validRect = this.requestedRect.copy();
|
|
107
129
|
}
|
|
108
|
-
buildCollection(y =
|
|
130
|
+
buildCollection(y = this.padding) {
|
|
109
131
|
let collection = this.virtualizer.collection;
|
|
110
132
|
let skipped = 0;
|
|
111
133
|
let nodes = [];
|
|
112
134
|
for (let node of collection){
|
|
113
135
|
var _this_rowHeight, _ref;
|
|
114
|
-
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;
|
|
136
|
+
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;
|
|
115
137
|
// Skip rows before the valid rectangle unless they are already cached.
|
|
116
138
|
if (node.type === 'item' && y + rowHeight < this.requestedRect.y && !this.isValid(node, y)) {
|
|
117
139
|
y += rowHeight;
|
|
118
140
|
skipped++;
|
|
119
141
|
continue;
|
|
120
142
|
}
|
|
121
|
-
let layoutNode = this.buildChild(node,
|
|
122
|
-
y = layoutNode.layoutInfo.rect.maxY;
|
|
143
|
+
let layoutNode = this.buildChild(node, this.padding, y, null);
|
|
144
|
+
y = layoutNode.layoutInfo.rect.maxY + this.gap;
|
|
123
145
|
nodes.push(layoutNode);
|
|
124
146
|
if (node.type === 'item' && y > this.requestedRect.maxY) {
|
|
125
147
|
y += (collection.size - (nodes.length + skipped)) * rowHeight;
|
|
126
148
|
break;
|
|
127
149
|
}
|
|
128
150
|
}
|
|
151
|
+
y -= this.gap;
|
|
152
|
+
y += this.padding;
|
|
129
153
|
this.contentSize = new (0, $iId4j$reactstatelyvirtualizer.Size)(this.virtualizer.visibleRect.width, y);
|
|
130
154
|
return nodes;
|
|
131
155
|
}
|
|
@@ -155,9 +179,9 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
|
|
|
155
179
|
}
|
|
156
180
|
}
|
|
157
181
|
buildLoader(node, x, y) {
|
|
158
|
-
let rect = new (0, $iId4j$reactstatelyvirtualizer.Rect)(x, y,
|
|
182
|
+
let rect = new (0, $iId4j$reactstatelyvirtualizer.Rect)(x, y, this.padding, 0);
|
|
159
183
|
let layoutInfo = new (0, $iId4j$reactstatelyvirtualizer.LayoutInfo)('loader', node.key, rect);
|
|
160
|
-
rect.width = this.virtualizer.contentSize.width;
|
|
184
|
+
rect.width = this.virtualizer.contentSize.width - this.padding - x;
|
|
161
185
|
rect.height = this.loaderHeight || this.rowHeight || this.estimatedRowHeight || $fe69e47e38ed0ac4$var$DEFAULT_HEIGHT;
|
|
162
186
|
return {
|
|
163
187
|
layoutInfo: layoutInfo,
|
|
@@ -166,15 +190,15 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
|
|
|
166
190
|
}
|
|
167
191
|
buildSection(node, x, y) {
|
|
168
192
|
let collection = this.virtualizer.collection;
|
|
169
|
-
let width = this.virtualizer.visibleRect.width;
|
|
170
|
-
let rect = new (0, $iId4j$reactstatelyvirtualizer.Rect)(
|
|
193
|
+
let width = this.virtualizer.visibleRect.width - this.padding;
|
|
194
|
+
let rect = new (0, $iId4j$reactstatelyvirtualizer.Rect)(x, y, width - x, 0);
|
|
171
195
|
let layoutInfo = new (0, $iId4j$reactstatelyvirtualizer.LayoutInfo)(node.type, node.key, rect);
|
|
172
196
|
let startY = y;
|
|
173
197
|
let skipped = 0;
|
|
174
198
|
let children = [];
|
|
175
199
|
for (let child of (0, $iId4j$reactstatelycollections.getChildNodes)(node, collection)){
|
|
176
200
|
var _this_rowHeight, _ref;
|
|
177
|
-
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;
|
|
201
|
+
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;
|
|
178
202
|
// Skip rows before the valid rectangle unless they are already cached.
|
|
179
203
|
if (y + rowHeight < this.requestedRect.y && !this.isValid(node, y)) {
|
|
180
204
|
y += rowHeight;
|
|
@@ -182,7 +206,7 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
|
|
|
182
206
|
continue;
|
|
183
207
|
}
|
|
184
208
|
let layoutNode = this.buildChild(child, x, y, layoutInfo.key);
|
|
185
|
-
y = layoutNode.layoutInfo.rect.maxY;
|
|
209
|
+
y = layoutNode.layoutInfo.rect.maxY + this.gap;
|
|
186
210
|
children.push(layoutNode);
|
|
187
211
|
if (y > this.requestedRect.maxY) {
|
|
188
212
|
// Estimate the remaining height for rows that we don't need to layout right now.
|
|
@@ -192,6 +216,7 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
|
|
|
192
216
|
break;
|
|
193
217
|
}
|
|
194
218
|
}
|
|
219
|
+
y -= this.gap;
|
|
195
220
|
rect.height = y - startY;
|
|
196
221
|
return {
|
|
197
222
|
layoutInfo: layoutInfo,
|
|
@@ -201,7 +226,7 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
|
|
|
201
226
|
};
|
|
202
227
|
}
|
|
203
228
|
buildSectionHeader(node, x, y) {
|
|
204
|
-
let width = this.virtualizer.visibleRect.width;
|
|
229
|
+
let width = this.virtualizer.visibleRect.width - this.padding;
|
|
205
230
|
let rectHeight = this.headingHeight;
|
|
206
231
|
let isEstimated = false;
|
|
207
232
|
// If no explicit height is available, use an estimated height.
|
|
@@ -215,14 +240,14 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
|
|
|
215
240
|
let curNode = this.virtualizer.collection.getItem(node.key);
|
|
216
241
|
let lastNode = this.lastCollection ? this.lastCollection.getItem(node.key) : null;
|
|
217
242
|
rectHeight = previousLayoutInfo.rect.height;
|
|
218
|
-
isEstimated = width !==
|
|
243
|
+
isEstimated = width !== previousLayoutInfo.rect.width || curNode !== lastNode || previousLayoutInfo.estimatedSize;
|
|
219
244
|
} else {
|
|
220
245
|
rectHeight = node.rendered ? this.estimatedHeadingHeight : 0;
|
|
221
246
|
isEstimated = true;
|
|
222
247
|
}
|
|
223
248
|
}
|
|
224
249
|
if (rectHeight == null) rectHeight = $fe69e47e38ed0ac4$var$DEFAULT_HEIGHT;
|
|
225
|
-
let headerRect = new (0, $iId4j$reactstatelyvirtualizer.Rect)(
|
|
250
|
+
let headerRect = new (0, $iId4j$reactstatelyvirtualizer.Rect)(x, y, width - x, rectHeight);
|
|
226
251
|
let header = new (0, $iId4j$reactstatelyvirtualizer.LayoutInfo)('header', node.key, headerRect);
|
|
227
252
|
header.estimatedSize = isEstimated;
|
|
228
253
|
return {
|
|
@@ -233,7 +258,7 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
|
|
|
233
258
|
};
|
|
234
259
|
}
|
|
235
260
|
buildItem(node, x, y) {
|
|
236
|
-
let width = this.virtualizer.visibleRect.width;
|
|
261
|
+
let width = this.virtualizer.visibleRect.width - this.padding - x;
|
|
237
262
|
let rectHeight = this.rowHeight;
|
|
238
263
|
let isEstimated = false;
|
|
239
264
|
// If no explicit height is available, use an estimated height.
|
|
@@ -244,14 +269,14 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
|
|
|
244
269
|
let previousLayoutNode = this.layoutNodes.get(node.key);
|
|
245
270
|
if (previousLayoutNode) {
|
|
246
271
|
rectHeight = previousLayoutNode.layoutInfo.rect.height;
|
|
247
|
-
isEstimated = width !==
|
|
272
|
+
isEstimated = width !== previousLayoutNode.layoutInfo.rect.width || node !== previousLayoutNode.node || previousLayoutNode.layoutInfo.estimatedSize;
|
|
248
273
|
} else {
|
|
249
274
|
rectHeight = this.estimatedRowHeight;
|
|
250
275
|
isEstimated = true;
|
|
251
276
|
}
|
|
252
277
|
}
|
|
253
278
|
if (rectHeight == null) rectHeight = $fe69e47e38ed0ac4$var$DEFAULT_HEIGHT;
|
|
254
|
-
let rect = new (0, $iId4j$reactstatelyvirtualizer.Rect)(x, y, width
|
|
279
|
+
let rect = new (0, $iId4j$reactstatelyvirtualizer.Rect)(x, y, width, rectHeight);
|
|
255
280
|
let layoutInfo = new (0, $iId4j$reactstatelyvirtualizer.LayoutInfo)(node.type, node.key, rect);
|
|
256
281
|
layoutInfo.estimatedSize = isEstimated;
|
|
257
282
|
return {
|
|
@@ -304,7 +329,22 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
|
|
|
304
329
|
getDropTargetFromPoint(x, y, isValidDropTarget) {
|
|
305
330
|
x += this.virtualizer.visibleRect.x;
|
|
306
331
|
y += this.virtualizer.visibleRect.y;
|
|
307
|
-
|
|
332
|
+
// 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);
|
|
334
|
+
let candidates = this.getVisibleLayoutInfos(searchRect);
|
|
335
|
+
let key = null;
|
|
336
|
+
let minDistance = Infinity;
|
|
337
|
+
for (let candidate of candidates){
|
|
338
|
+
// Ignore items outside the search rect, e.g. persisted keys.
|
|
339
|
+
if (!candidate.rect.intersects(searchRect)) continue;
|
|
340
|
+
let yDist = Math.abs(candidate.rect.y - y);
|
|
341
|
+
let maxYDist = Math.abs(candidate.rect.maxY - y);
|
|
342
|
+
let dist = Math.min(yDist, maxYDist);
|
|
343
|
+
if (dist < minDistance) {
|
|
344
|
+
minDistance = dist;
|
|
345
|
+
key = candidate.key;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
308
348
|
if (key == null || this.virtualizer.collection.size === 0) return {
|
|
309
349
|
type: 'root'
|
|
310
350
|
};
|
|
@@ -362,9 +402,10 @@ class $fe69e47e38ed0ac4$export$cacbb3924155d68e extends (0, $iId4j$reactstatelyv
|
|
|
362
402
|
var _options_loaderHeight;
|
|
363
403
|
this.loaderHeight = (_options_loaderHeight = options.loaderHeight) !== null && _options_loaderHeight !== void 0 ? _options_loaderHeight : null;
|
|
364
404
|
this.dropIndicatorThickness = options.dropIndicatorThickness || 2;
|
|
405
|
+
this.gap = options.gap || 0;
|
|
406
|
+
this.padding = options.padding || 0;
|
|
365
407
|
this.layoutNodes = new Map();
|
|
366
408
|
this.rootNodes = [];
|
|
367
|
-
this.lastWidth = 0;
|
|
368
409
|
this.lastCollection = null;
|
|
369
410
|
this.invalidateEverything = false;
|
|
370
411
|
this.validRect = new (0, $iId4j$reactstatelyvirtualizer.Rect)();
|