@react-stately/layout 4.6.0 → 4.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,233 +0,0 @@
1
- import {Size as $ipgKF$Size, Rect as $ipgKF$Rect, LayoutInfo as $ipgKF$LayoutInfo, Layout as $ipgKF$Layout} from "@react-stately/virtualizer";
2
-
3
- /*
4
- * Copyright 2024 Adobe. All rights reserved.
5
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License. You may obtain a copy
7
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software distributed under
10
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
- * OF ANY KIND, either express or implied. See the License for the specific language
12
- * governing permissions and limitations under the License.
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
- maxSpace: Infinity,
20
- maxColumns: Infinity,
21
- dropIndicatorThickness: 2,
22
- loaderHeight: 48
23
- };
24
- class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
25
- shouldInvalidateLayoutOptions(newOptions, oldOptions) {
26
- return newOptions.maxColumns !== oldOptions.maxColumns || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness || newOptions.preserveAspectRatio !== oldOptions.preserveAspectRatio || !(newOptions.minItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.minItemSize) || !(newOptions.maxItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.maxItemSize) || !(newOptions.minSpace || $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace) || newOptions.maxHorizontalSpace !== oldOptions.maxHorizontalSpace || newOptions.loaderHeight !== oldOptions.loaderHeight;
27
- }
28
- update(invalidationContext) {
29
- let { minItemSize: minItemSize = $a58592d295a170a4$var$DEFAULT_OPTIONS.minItemSize, maxItemSize: maxItemSize = $a58592d295a170a4$var$DEFAULT_OPTIONS.maxItemSize, preserveAspectRatio: preserveAspectRatio = $a58592d295a170a4$var$DEFAULT_OPTIONS.preserveAspectRatio, minSpace: minSpace = $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace, maxHorizontalSpace: maxHorizontalSpace = $a58592d295a170a4$var$DEFAULT_OPTIONS.maxSpace, maxColumns: maxColumns = $a58592d295a170a4$var$DEFAULT_OPTIONS.maxColumns, dropIndicatorThickness: dropIndicatorThickness = $a58592d295a170a4$var$DEFAULT_OPTIONS.dropIndicatorThickness, loaderHeight: loaderHeight = $a58592d295a170a4$var$DEFAULT_OPTIONS.loaderHeight } = invalidationContext.layoutOptions || {};
30
- this.dropIndicatorThickness = dropIndicatorThickness;
31
- let visibleWidth = this.virtualizer.visibleRect.width;
32
- // The max item width is always the entire viewport.
33
- // If the max item height is infinity, scale in proportion to the max width.
34
- let maxItemWidth = Math.min(maxItemSize.width, visibleWidth);
35
- let maxItemHeight = Number.isFinite(maxItemSize.height) ? maxItemSize.height : Math.floor(minItemSize.height / minItemSize.width * maxItemWidth);
36
- // Compute the number of rows and columns needed to display the content
37
- let columns = Math.floor(visibleWidth / (minItemSize.width + minSpace.width));
38
- let numColumns = Math.max(1, Math.min(maxColumns, columns));
39
- this.numColumns = numColumns;
40
- // Compute the available width (minus the space between items)
41
- let width = visibleWidth - minSpace.width * Math.max(0, numColumns);
42
- // Compute the item width based on the space available
43
- let itemWidth = Math.floor(width / numColumns);
44
- itemWidth = Math.max(minItemSize.width, Math.min(maxItemWidth, itemWidth));
45
- // Compute the item height, which is proportional to the item width
46
- let t = (itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width);
47
- let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);
48
- itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));
49
- // Compute the horizontal spacing, content height and horizontal margin
50
- let horizontalSpacing = Math.min(Math.max(maxHorizontalSpace, minSpace.width), Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1)));
51
- this.gap = new (0, $ipgKF$Size)(horizontalSpacing, minSpace.height);
52
- this.margin = Math.floor((visibleWidth - numColumns * itemWidth - horizontalSpacing * (numColumns + 1)) / 2);
53
- // If there is a skeleton loader within the last 2 items in the collection, increment the collection size
54
- // so that an additional row is added for the skeletons.
55
- let collection = this.virtualizer.collection;
56
- let collectionSize = collection.size;
57
- let lastKey = collection.getLastKey();
58
- for(let i = 0; i < 2 && lastKey != null; i++){
59
- let item = collection.getItem(lastKey);
60
- if ((item === null || item === void 0 ? void 0 : item.type) === 'skeleton') {
61
- collectionSize++;
62
- break;
63
- }
64
- lastKey = collection.getKeyBefore(lastKey);
65
- }
66
- let rows = Math.ceil(collectionSize / numColumns);
67
- let iterator = collection[Symbol.iterator]();
68
- let y = rows > 0 ? minSpace.height : 0;
69
- let newLayoutInfos = new Map();
70
- let skeleton = null;
71
- let skeletonCount = 0;
72
- for(let row = 0; row < rows; row++){
73
- let maxHeight = 0;
74
- let rowLayoutInfos = [];
75
- for(let col = 0; col < numColumns; col++){
76
- // Repeat skeleton until the end of the current row.
77
- let node = skeleton || iterator.next().value;
78
- if (!node) break;
79
- // We will add the loader after the skeletons so skip here
80
- if (node.type === 'loader') continue;
81
- if (node.type === 'skeleton') skeleton = node;
82
- let key = skeleton ? `${skeleton.key}-${skeletonCount++}` : node.key;
83
- let oldLayoutInfo = this.layoutInfos.get(key);
84
- let content = node;
85
- if (skeleton) content = oldLayoutInfo && oldLayoutInfo.content.key === key ? oldLayoutInfo.content : {
86
- ...skeleton,
87
- key: key
88
- };
89
- let x = horizontalSpacing + col * (itemWidth + horizontalSpacing) + this.margin;
90
- let height = itemHeight;
91
- let estimatedSize = !preserveAspectRatio;
92
- if (oldLayoutInfo && estimatedSize) {
93
- height = oldLayoutInfo.rect.height;
94
- estimatedSize = invalidationContext.layoutOptionsChanged || invalidationContext.sizeChanged || oldLayoutInfo.estimatedSize || oldLayoutInfo.content !== content;
95
- }
96
- let rect = new (0, $ipgKF$Rect)(x, y, itemWidth, height);
97
- let layoutInfo = new (0, $ipgKF$LayoutInfo)(node.type, key, rect);
98
- layoutInfo.estimatedSize = estimatedSize;
99
- layoutInfo.allowOverflow = true;
100
- layoutInfo.content = content;
101
- newLayoutInfos.set(key, layoutInfo);
102
- rowLayoutInfos.push(layoutInfo);
103
- maxHeight = Math.max(maxHeight, layoutInfo.rect.height);
104
- }
105
- for (let layoutInfo of rowLayoutInfos)layoutInfo.rect.height = maxHeight;
106
- y += maxHeight + minSpace.height;
107
- // Keep adding skeleton rows until we fill the viewport
108
- if (skeleton && row === rows - 1 && y < this.virtualizer.visibleRect.height) rows++;
109
- }
110
- // Always add the loader sentinel if present in the collection so we can make sure it is never virtualized out.
111
- let lastNode = collection.getItem(collection.getLastKey());
112
- if ((lastNode === null || lastNode === void 0 ? void 0 : lastNode.type) === 'loader') {
113
- if (skeletonCount > 0 || !lastNode.props.isLoading) loaderHeight = 0;
114
- const loaderWidth = visibleWidth - horizontalSpacing * 2;
115
- // Note that if the user provides isLoading to their sentinel during a case where they only want to render the emptyState, this will reserve
116
- // room for the loader alongside rendering the emptyState
117
- let rect = new (0, $ipgKF$Rect)(horizontalSpacing, y, loaderWidth, loaderHeight);
118
- let layoutInfo = new (0, $ipgKF$LayoutInfo)('loader', lastNode.key, rect);
119
- newLayoutInfos.set(lastNode.key, layoutInfo);
120
- y = layoutInfo.rect.maxY;
121
- }
122
- this.layoutInfos = newLayoutInfos;
123
- this.contentSize = new (0, $ipgKF$Size)(this.virtualizer.visibleRect.width, y);
124
- }
125
- getLayoutInfo(key) {
126
- return this.layoutInfos.get(key) || null;
127
- }
128
- getContentSize() {
129
- return this.contentSize;
130
- }
131
- getVisibleLayoutInfos(rect) {
132
- let layoutInfos = [];
133
- for (let layoutInfo of this.layoutInfos.values())if (layoutInfo.rect.intersects(rect) || this.virtualizer.isPersistedKey(layoutInfo.key) || layoutInfo.type === 'loader') layoutInfos.push(layoutInfo);
134
- return layoutInfos;
135
- }
136
- updateItemSize(key, size) {
137
- let layoutInfo = this.layoutInfos.get(key);
138
- if (!size || !layoutInfo) return false;
139
- if (size.height !== layoutInfo.rect.height) {
140
- let newLayoutInfo = layoutInfo.copy();
141
- newLayoutInfo.rect.height = size.height;
142
- newLayoutInfo.estimatedSize = false;
143
- this.layoutInfos.set(key, newLayoutInfo);
144
- return true;
145
- }
146
- return false;
147
- }
148
- getDropTargetFromPoint(x, y, isValidDropTarget) {
149
- if (this.layoutInfos.size === 0) return {
150
- type: 'root'
151
- };
152
- x += this.virtualizer.visibleRect.x;
153
- y += this.virtualizer.visibleRect.y;
154
- // Find the closest item within on either side of the point using the gap width.
155
- let key = null;
156
- if (this.numColumns === 1) {
157
- let searchRect = new (0, $ipgKF$Rect)(x, Math.max(0, y - this.gap.height), 1, Math.max(1, this.gap.height * 2));
158
- let candidates = this.getVisibleLayoutInfos(searchRect);
159
- let minDistance = Infinity;
160
- for (let candidate of candidates){
161
- // Ignore items outside the search rect, e.g. persisted keys.
162
- if (!candidate.rect.intersects(searchRect)) continue;
163
- let yDist = Math.abs(candidate.rect.y - y);
164
- let maxYDist = Math.abs(candidate.rect.maxY - y);
165
- let dist = Math.min(yDist, maxYDist);
166
- if (dist < minDistance) {
167
- minDistance = dist;
168
- key = candidate.key;
169
- }
170
- }
171
- } else {
172
- let searchRect = new (0, $ipgKF$Rect)(Math.max(0, x - this.gap.width), y, this.gap.width * 2, 1);
173
- let candidates = this.getVisibleLayoutInfos(searchRect);
174
- let minDistance = Infinity;
175
- for (let candidate of candidates){
176
- // Ignore items outside the search rect, e.g. persisted keys.
177
- if (!candidate.rect.intersects(searchRect)) continue;
178
- let xDist = Math.abs(candidate.rect.x - x);
179
- let maxXDist = Math.abs(candidate.rect.maxX - x);
180
- let dist = Math.min(xDist, maxXDist);
181
- if (dist < minDistance) {
182
- minDistance = dist;
183
- key = candidate.key;
184
- }
185
- }
186
- }
187
- let layoutInfo = key != null ? this.getLayoutInfo(key) : null;
188
- if (!layoutInfo) return {
189
- type: 'root'
190
- };
191
- let target = {
192
- type: 'item',
193
- key: layoutInfo.key,
194
- dropPosition: 'on'
195
- };
196
- let pos = this.numColumns === 1 ? y : x;
197
- let layoutInfoPos = this.numColumns === 1 ? layoutInfo.rect.y : layoutInfo.rect.x;
198
- let size = this.numColumns === 1 ? layoutInfo.rect.height : layoutInfo.rect.width;
199
- if (isValidDropTarget(target)) {
200
- // If dropping on the item is accepted, try the before/after positions
201
- // if within 5px of the start or end of the item.
202
- if (pos < layoutInfoPos + 5) target.dropPosition = 'before';
203
- else if (pos > layoutInfoPos + size - 5) target.dropPosition = 'after';
204
- } else {
205
- // If dropping on the item isn't accepted, try the target before or after depending on the position.
206
- let mid = layoutInfoPos + size / 2;
207
- if (pos <= mid && isValidDropTarget({
208
- ...target,
209
- dropPosition: 'before'
210
- })) target.dropPosition = 'before';
211
- else if (pos >= mid && isValidDropTarget({
212
- ...target,
213
- dropPosition: 'after'
214
- })) target.dropPosition = 'after';
215
- }
216
- return target;
217
- }
218
- getDropTargetLayoutInfo(target) {
219
- let layoutInfo = this.getLayoutInfo(target.key);
220
- let rect;
221
- if (this.numColumns === 1) // Flip from vertical to horizontal if only one column is visible.
222
- 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);
223
- 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);
224
- return new (0, $ipgKF$LayoutInfo)('dropIndicator', target.key + ':' + target.dropPosition, rect);
225
- }
226
- constructor(...args){
227
- super(...args), this.gap = $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace, this.dropIndicatorThickness = 2, this.numColumns = 0, this.contentSize = new (0, $ipgKF$Size)(), this.layoutInfos = new Map(), this.margin = 0;
228
- }
229
- }
230
-
231
-
232
- export {$a58592d295a170a4$export$7d2b12578154a735 as GridLayout};
233
- //# sourceMappingURL=GridLayout.module.js.map
@@ -1,233 +0,0 @@
1
- import {Size as $ipgKF$Size, Rect as $ipgKF$Rect, LayoutInfo as $ipgKF$LayoutInfo, Layout as $ipgKF$Layout} from "@react-stately/virtualizer";
2
-
3
- /*
4
- * Copyright 2024 Adobe. All rights reserved.
5
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License. You may obtain a copy
7
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software distributed under
10
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
- * OF ANY KIND, either express or implied. See the License for the specific language
12
- * governing permissions and limitations under the License.
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
- maxSpace: Infinity,
20
- maxColumns: Infinity,
21
- dropIndicatorThickness: 2,
22
- loaderHeight: 48
23
- };
24
- class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
25
- shouldInvalidateLayoutOptions(newOptions, oldOptions) {
26
- return newOptions.maxColumns !== oldOptions.maxColumns || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness || newOptions.preserveAspectRatio !== oldOptions.preserveAspectRatio || !(newOptions.minItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.minItemSize) || !(newOptions.maxItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || $a58592d295a170a4$var$DEFAULT_OPTIONS.maxItemSize) || !(newOptions.minSpace || $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace) || newOptions.maxHorizontalSpace !== oldOptions.maxHorizontalSpace || newOptions.loaderHeight !== oldOptions.loaderHeight;
27
- }
28
- update(invalidationContext) {
29
- let { minItemSize: minItemSize = $a58592d295a170a4$var$DEFAULT_OPTIONS.minItemSize, maxItemSize: maxItemSize = $a58592d295a170a4$var$DEFAULT_OPTIONS.maxItemSize, preserveAspectRatio: preserveAspectRatio = $a58592d295a170a4$var$DEFAULT_OPTIONS.preserveAspectRatio, minSpace: minSpace = $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace, maxHorizontalSpace: maxHorizontalSpace = $a58592d295a170a4$var$DEFAULT_OPTIONS.maxSpace, maxColumns: maxColumns = $a58592d295a170a4$var$DEFAULT_OPTIONS.maxColumns, dropIndicatorThickness: dropIndicatorThickness = $a58592d295a170a4$var$DEFAULT_OPTIONS.dropIndicatorThickness, loaderHeight: loaderHeight = $a58592d295a170a4$var$DEFAULT_OPTIONS.loaderHeight } = invalidationContext.layoutOptions || {};
30
- this.dropIndicatorThickness = dropIndicatorThickness;
31
- let visibleWidth = this.virtualizer.visibleRect.width;
32
- // The max item width is always the entire viewport.
33
- // If the max item height is infinity, scale in proportion to the max width.
34
- let maxItemWidth = Math.min(maxItemSize.width, visibleWidth);
35
- let maxItemHeight = Number.isFinite(maxItemSize.height) ? maxItemSize.height : Math.floor(minItemSize.height / minItemSize.width * maxItemWidth);
36
- // Compute the number of rows and columns needed to display the content
37
- let columns = Math.floor(visibleWidth / (minItemSize.width + minSpace.width));
38
- let numColumns = Math.max(1, Math.min(maxColumns, columns));
39
- this.numColumns = numColumns;
40
- // Compute the available width (minus the space between items)
41
- let width = visibleWidth - minSpace.width * Math.max(0, numColumns);
42
- // Compute the item width based on the space available
43
- let itemWidth = Math.floor(width / numColumns);
44
- itemWidth = Math.max(minItemSize.width, Math.min(maxItemWidth, itemWidth));
45
- // Compute the item height, which is proportional to the item width
46
- let t = (itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width);
47
- let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);
48
- itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));
49
- // Compute the horizontal spacing, content height and horizontal margin
50
- let horizontalSpacing = Math.min(Math.max(maxHorizontalSpace, minSpace.width), Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1)));
51
- this.gap = new (0, $ipgKF$Size)(horizontalSpacing, minSpace.height);
52
- this.margin = Math.floor((visibleWidth - numColumns * itemWidth - horizontalSpacing * (numColumns + 1)) / 2);
53
- // If there is a skeleton loader within the last 2 items in the collection, increment the collection size
54
- // so that an additional row is added for the skeletons.
55
- let collection = this.virtualizer.collection;
56
- let collectionSize = collection.size;
57
- let lastKey = collection.getLastKey();
58
- for(let i = 0; i < 2 && lastKey != null; i++){
59
- let item = collection.getItem(lastKey);
60
- if ((item === null || item === void 0 ? void 0 : item.type) === 'skeleton') {
61
- collectionSize++;
62
- break;
63
- }
64
- lastKey = collection.getKeyBefore(lastKey);
65
- }
66
- let rows = Math.ceil(collectionSize / numColumns);
67
- let iterator = collection[Symbol.iterator]();
68
- let y = rows > 0 ? minSpace.height : 0;
69
- let newLayoutInfos = new Map();
70
- let skeleton = null;
71
- let skeletonCount = 0;
72
- for(let row = 0; row < rows; row++){
73
- let maxHeight = 0;
74
- let rowLayoutInfos = [];
75
- for(let col = 0; col < numColumns; col++){
76
- // Repeat skeleton until the end of the current row.
77
- let node = skeleton || iterator.next().value;
78
- if (!node) break;
79
- // We will add the loader after the skeletons so skip here
80
- if (node.type === 'loader') continue;
81
- if (node.type === 'skeleton') skeleton = node;
82
- let key = skeleton ? `${skeleton.key}-${skeletonCount++}` : node.key;
83
- let oldLayoutInfo = this.layoutInfos.get(key);
84
- let content = node;
85
- if (skeleton) content = oldLayoutInfo && oldLayoutInfo.content.key === key ? oldLayoutInfo.content : {
86
- ...skeleton,
87
- key: key
88
- };
89
- let x = horizontalSpacing + col * (itemWidth + horizontalSpacing) + this.margin;
90
- let height = itemHeight;
91
- let estimatedSize = !preserveAspectRatio;
92
- if (oldLayoutInfo && estimatedSize) {
93
- height = oldLayoutInfo.rect.height;
94
- estimatedSize = invalidationContext.layoutOptionsChanged || invalidationContext.sizeChanged || oldLayoutInfo.estimatedSize || oldLayoutInfo.content !== content;
95
- }
96
- let rect = new (0, $ipgKF$Rect)(x, y, itemWidth, height);
97
- let layoutInfo = new (0, $ipgKF$LayoutInfo)(node.type, key, rect);
98
- layoutInfo.estimatedSize = estimatedSize;
99
- layoutInfo.allowOverflow = true;
100
- layoutInfo.content = content;
101
- newLayoutInfos.set(key, layoutInfo);
102
- rowLayoutInfos.push(layoutInfo);
103
- maxHeight = Math.max(maxHeight, layoutInfo.rect.height);
104
- }
105
- for (let layoutInfo of rowLayoutInfos)layoutInfo.rect.height = maxHeight;
106
- y += maxHeight + minSpace.height;
107
- // Keep adding skeleton rows until we fill the viewport
108
- if (skeleton && row === rows - 1 && y < this.virtualizer.visibleRect.height) rows++;
109
- }
110
- // Always add the loader sentinel if present in the collection so we can make sure it is never virtualized out.
111
- let lastNode = collection.getItem(collection.getLastKey());
112
- if ((lastNode === null || lastNode === void 0 ? void 0 : lastNode.type) === 'loader') {
113
- if (skeletonCount > 0 || !lastNode.props.isLoading) loaderHeight = 0;
114
- const loaderWidth = visibleWidth - horizontalSpacing * 2;
115
- // Note that if the user provides isLoading to their sentinel during a case where they only want to render the emptyState, this will reserve
116
- // room for the loader alongside rendering the emptyState
117
- let rect = new (0, $ipgKF$Rect)(horizontalSpacing, y, loaderWidth, loaderHeight);
118
- let layoutInfo = new (0, $ipgKF$LayoutInfo)('loader', lastNode.key, rect);
119
- newLayoutInfos.set(lastNode.key, layoutInfo);
120
- y = layoutInfo.rect.maxY;
121
- }
122
- this.layoutInfos = newLayoutInfos;
123
- this.contentSize = new (0, $ipgKF$Size)(this.virtualizer.visibleRect.width, y);
124
- }
125
- getLayoutInfo(key) {
126
- return this.layoutInfos.get(key) || null;
127
- }
128
- getContentSize() {
129
- return this.contentSize;
130
- }
131
- getVisibleLayoutInfos(rect) {
132
- let layoutInfos = [];
133
- for (let layoutInfo of this.layoutInfos.values())if (layoutInfo.rect.intersects(rect) || this.virtualizer.isPersistedKey(layoutInfo.key) || layoutInfo.type === 'loader') layoutInfos.push(layoutInfo);
134
- return layoutInfos;
135
- }
136
- updateItemSize(key, size) {
137
- let layoutInfo = this.layoutInfos.get(key);
138
- if (!size || !layoutInfo) return false;
139
- if (size.height !== layoutInfo.rect.height) {
140
- let newLayoutInfo = layoutInfo.copy();
141
- newLayoutInfo.rect.height = size.height;
142
- newLayoutInfo.estimatedSize = false;
143
- this.layoutInfos.set(key, newLayoutInfo);
144
- return true;
145
- }
146
- return false;
147
- }
148
- getDropTargetFromPoint(x, y, isValidDropTarget) {
149
- if (this.layoutInfos.size === 0) return {
150
- type: 'root'
151
- };
152
- x += this.virtualizer.visibleRect.x;
153
- y += this.virtualizer.visibleRect.y;
154
- // Find the closest item within on either side of the point using the gap width.
155
- let key = null;
156
- if (this.numColumns === 1) {
157
- let searchRect = new (0, $ipgKF$Rect)(x, Math.max(0, y - this.gap.height), 1, Math.max(1, this.gap.height * 2));
158
- let candidates = this.getVisibleLayoutInfos(searchRect);
159
- let minDistance = Infinity;
160
- for (let candidate of candidates){
161
- // Ignore items outside the search rect, e.g. persisted keys.
162
- if (!candidate.rect.intersects(searchRect)) continue;
163
- let yDist = Math.abs(candidate.rect.y - y);
164
- let maxYDist = Math.abs(candidate.rect.maxY - y);
165
- let dist = Math.min(yDist, maxYDist);
166
- if (dist < minDistance) {
167
- minDistance = dist;
168
- key = candidate.key;
169
- }
170
- }
171
- } else {
172
- let searchRect = new (0, $ipgKF$Rect)(Math.max(0, x - this.gap.width), y, this.gap.width * 2, 1);
173
- let candidates = this.getVisibleLayoutInfos(searchRect);
174
- let minDistance = Infinity;
175
- for (let candidate of candidates){
176
- // Ignore items outside the search rect, e.g. persisted keys.
177
- if (!candidate.rect.intersects(searchRect)) continue;
178
- let xDist = Math.abs(candidate.rect.x - x);
179
- let maxXDist = Math.abs(candidate.rect.maxX - x);
180
- let dist = Math.min(xDist, maxXDist);
181
- if (dist < minDistance) {
182
- minDistance = dist;
183
- key = candidate.key;
184
- }
185
- }
186
- }
187
- let layoutInfo = key != null ? this.getLayoutInfo(key) : null;
188
- if (!layoutInfo) return {
189
- type: 'root'
190
- };
191
- let target = {
192
- type: 'item',
193
- key: layoutInfo.key,
194
- dropPosition: 'on'
195
- };
196
- let pos = this.numColumns === 1 ? y : x;
197
- let layoutInfoPos = this.numColumns === 1 ? layoutInfo.rect.y : layoutInfo.rect.x;
198
- let size = this.numColumns === 1 ? layoutInfo.rect.height : layoutInfo.rect.width;
199
- if (isValidDropTarget(target)) {
200
- // If dropping on the item is accepted, try the before/after positions
201
- // if within 5px of the start or end of the item.
202
- if (pos < layoutInfoPos + 5) target.dropPosition = 'before';
203
- else if (pos > layoutInfoPos + size - 5) target.dropPosition = 'after';
204
- } else {
205
- // If dropping on the item isn't accepted, try the target before or after depending on the position.
206
- let mid = layoutInfoPos + size / 2;
207
- if (pos <= mid && isValidDropTarget({
208
- ...target,
209
- dropPosition: 'before'
210
- })) target.dropPosition = 'before';
211
- else if (pos >= mid && isValidDropTarget({
212
- ...target,
213
- dropPosition: 'after'
214
- })) target.dropPosition = 'after';
215
- }
216
- return target;
217
- }
218
- getDropTargetLayoutInfo(target) {
219
- let layoutInfo = this.getLayoutInfo(target.key);
220
- let rect;
221
- if (this.numColumns === 1) // Flip from vertical to horizontal if only one column is visible.
222
- 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);
223
- 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);
224
- return new (0, $ipgKF$LayoutInfo)('dropIndicator', target.key + ':' + target.dropPosition, rect);
225
- }
226
- constructor(...args){
227
- super(...args), this.gap = $a58592d295a170a4$var$DEFAULT_OPTIONS.minSpace, this.dropIndicatorThickness = 2, this.numColumns = 0, this.contentSize = new (0, $ipgKF$Size)(), this.layoutInfos = new Map(), this.margin = 0;
228
- }
229
- }
230
-
231
-
232
- export {$a58592d295a170a4$export$7d2b12578154a735 as GridLayout};
233
- //# sourceMappingURL=GridLayout.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC;AAmDD,MAAM,wCAAkB;IACtB,aAAa,IAAI,CAAA,GAAA,WAAG,EAAE,KAAK;IAC3B,aAAa,IAAI,CAAA,GAAA,WAAG,EAAE,UAAU;IAChC,qBAAqB;IACrB,UAAU,IAAI,CAAA,GAAA,WAAG,EAAE,IAAI;IACvB,UAAU;IACV,YAAY;IACZ,wBAAwB;IACxB,cAAc;AAChB;AAQO,MAAM,kDAAuE,CAAA,G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,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;;QA7SK,qBACK,MAAY,sCAAgB,QAAQ,OACpC,yBAAyB,QACzB,aAAqB,QACvB,cAAoB,IAAI,CAAA,GAAA,WAAG,UAC3B,cAAoC,IAAI,YACxC,SAAiB;;AAwS3B","sources":["packages/@react-stately/layout/src/GridLayout.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DropTarget, DropTargetDelegate, ItemDropTarget, Key, Node} from '@react-types/shared';\nimport {InvalidationContext, Layout, LayoutInfo, Rect, Size} from '@react-stately/virtualizer';\n\nexport interface GridLayoutOptions {\n /**\n * The minimum item size.\n * @default 200 x 200\n */\n minItemSize?: Size,\n /**\n * The maximum item size.\n * @default Infinity\n */\n maxItemSize?: Size,\n /**\n * Whether to preserve the aspect ratio of the `minItemSize`.\n * By default, grid rows may have variable heights. When `preserveAspectRatio`\n * is true, all rows will have equal heights.\n * @default false\n */\n preserveAspectRatio?: boolean,\n /**\n * The minimum space required between items.\n * @default 18 x 18\n */\n minSpace?: Size,\n /**\n * The maximum allowed horizontal space between items.\n * @default Infinity\n */\n maxHorizontalSpace?: number,\n /**\n * The maximum number of columns.\n * @default Infinity\n */\n maxColumns?: number,\n /**\n * The thickness of the drop indicator.\n * @default 2\n */\n dropIndicatorThickness?: number,\n /**\n * The fixed height of a loader element in px. This loader is specifically for\n * \"load more\" elements rendered when loading more rows at the root level or inside nested row/sections.\n * @default 48\n */\n loaderHeight?: number\n}\n\nconst DEFAULT_OPTIONS = {\n minItemSize: new Size(200, 200),\n maxItemSize: new Size(Infinity, Infinity),\n preserveAspectRatio: false,\n minSpace: new Size(18, 18),\n maxSpace: Infinity,\n maxColumns: Infinity,\n dropIndicatorThickness: 2,\n loaderHeight: 48\n};\n\n/**\n * GridLayout is a virtualizer Layout implementation\n * that arranges its items in a grid.\n * The items are sized between a minimum and maximum size\n * depending on the width of the container.\n */\nexport class GridLayout<T, O extends GridLayoutOptions = GridLayoutOptions> extends Layout<Node<T>, O> implements DropTargetDelegate {\n protected gap: Size = DEFAULT_OPTIONS.minSpace;\n protected dropIndicatorThickness = 2;\n protected numColumns: number = 0;\n private contentSize: Size = new Size();\n private layoutInfos: Map<Key, LayoutInfo> = new Map();\n private margin: number = 0;\n\n shouldInvalidateLayoutOptions(newOptions: O, oldOptions: O): boolean {\n return newOptions.maxColumns !== oldOptions.maxColumns\n || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness\n || newOptions.preserveAspectRatio !== oldOptions.preserveAspectRatio\n || (!(newOptions.minItemSize || DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || DEFAULT_OPTIONS.minItemSize))\n || (!(newOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize))\n || (!(newOptions.minSpace || DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || DEFAULT_OPTIONS.minSpace))\n || newOptions.maxHorizontalSpace !== oldOptions.maxHorizontalSpace\n || newOptions.loaderHeight !== oldOptions.loaderHeight;\n }\n\n update(invalidationContext: InvalidationContext<O>): void {\n let {\n minItemSize = DEFAULT_OPTIONS.minItemSize,\n maxItemSize = DEFAULT_OPTIONS.maxItemSize,\n preserveAspectRatio = DEFAULT_OPTIONS.preserveAspectRatio,\n minSpace = DEFAULT_OPTIONS.minSpace,\n maxHorizontalSpace = DEFAULT_OPTIONS.maxSpace,\n maxColumns = DEFAULT_OPTIONS.maxColumns,\n dropIndicatorThickness = DEFAULT_OPTIONS.dropIndicatorThickness,\n loaderHeight = DEFAULT_OPTIONS.loaderHeight\n } = invalidationContext.layoutOptions || {};\n this.dropIndicatorThickness = dropIndicatorThickness;\n\n let visibleWidth = this.virtualizer!.visibleRect.width;\n\n // The max item width is always the entire viewport.\n // If the max item height is infinity, scale in proportion to the max width.\n let maxItemWidth = Math.min(maxItemSize.width, visibleWidth);\n let maxItemHeight = Number.isFinite(maxItemSize.height)\n ? maxItemSize.height\n : Math.floor((minItemSize.height / minItemSize.width) * maxItemWidth);\n\n // Compute the number of rows and columns needed to display the content\n let columns = Math.floor(visibleWidth / (minItemSize.width + minSpace.width));\n let numColumns = Math.max(1, Math.min(maxColumns, columns));\n this.numColumns = numColumns;\n\n // Compute the available width (minus the space between items)\n let width = visibleWidth - (minSpace.width * Math.max(0, numColumns));\n\n // Compute the item width based on the space available\n let itemWidth = Math.floor(width / numColumns);\n itemWidth = Math.max(minItemSize.width, Math.min(maxItemWidth, itemWidth));\n\n // Compute the item height, which is proportional to the item width\n let t = ((itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width));\n let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);\n itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));\n\n // Compute the horizontal spacing, content height and horizontal margin\n let horizontalSpacing = Math.min(Math.max(maxHorizontalSpace, minSpace.width), Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1)));\n this.gap = new Size(horizontalSpacing, minSpace.height);\n this.margin = Math.floor((visibleWidth - numColumns * itemWidth - horizontalSpacing * (numColumns + 1)) / 2);\n\n // If there is a skeleton loader within the last 2 items in the collection, increment the collection size\n // so that an additional row is added for the skeletons.\n let collection = this.virtualizer!.collection;\n let collectionSize = collection.size;\n let lastKey = collection.getLastKey();\n for (let i = 0; i < 2 && lastKey != null; i++) {\n let item = collection.getItem(lastKey);\n if (item?.type === 'skeleton') {\n collectionSize++;\n break;\n }\n lastKey = collection.getKeyBefore(lastKey);\n }\n\n let rows = Math.ceil(collectionSize / numColumns);\n let iterator = collection[Symbol.iterator]();\n let y = rows > 0 ? minSpace.height : 0;\n let newLayoutInfos = new Map();\n let skeleton: Node<T> | null = null;\n let skeletonCount = 0;\n for (let row = 0; row < rows; row++) {\n let maxHeight = 0;\n let rowLayoutInfos: LayoutInfo[] = [];\n for (let col = 0; col < numColumns; col++) {\n // Repeat skeleton until the end of the current row.\n let node = skeleton || iterator.next().value;\n if (!node) {\n break;\n }\n\n // We will add the loader after the skeletons so skip here\n if (node.type === 'loader') {\n continue;\n }\n\n if (node.type === 'skeleton') {\n skeleton = node;\n }\n\n let key = skeleton ? `${skeleton.key}-${skeletonCount++}` : node.key;\n let oldLayoutInfo = this.layoutInfos.get(key);\n let content = node;\n if (skeleton) {\n content = oldLayoutInfo && oldLayoutInfo.content.key === key ? oldLayoutInfo.content : {...skeleton, key};\n }\n let x = horizontalSpacing + col * (itemWidth + horizontalSpacing) + this.margin;\n let height = itemHeight;\n let estimatedSize = !preserveAspectRatio;\n if (oldLayoutInfo && estimatedSize) {\n height = oldLayoutInfo.rect.height;\n estimatedSize = invalidationContext.layoutOptionsChanged || invalidationContext.sizeChanged || oldLayoutInfo.estimatedSize || (oldLayoutInfo.content !== content);\n }\n\n let rect = new Rect(x, y, itemWidth, height);\n let layoutInfo = new LayoutInfo(node.type, key, rect);\n layoutInfo.estimatedSize = estimatedSize;\n layoutInfo.allowOverflow = true;\n layoutInfo.content = content;\n newLayoutInfos.set(key, layoutInfo);\n rowLayoutInfos.push(layoutInfo);\n\n maxHeight = Math.max(maxHeight, layoutInfo.rect.height);\n }\n\n for (let layoutInfo of rowLayoutInfos) {\n layoutInfo.rect.height = maxHeight;\n }\n\n y += maxHeight + minSpace.height;\n\n // Keep adding skeleton rows until we fill the viewport\n if (skeleton && row === rows - 1 && y < this.virtualizer!.visibleRect.height) {\n rows++;\n }\n }\n\n // Always add the loader sentinel if present in the collection so we can make sure it is never virtualized out.\n let lastNode = collection.getItem(collection.getLastKey()!);\n if (lastNode?.type === 'loader') {\n if (skeletonCount > 0 || !lastNode.props.isLoading) {\n loaderHeight = 0;\n }\n const loaderWidth = visibleWidth - horizontalSpacing * 2;\n // Note that if the user provides isLoading to their sentinel during a case where they only want to render the emptyState, this will reserve\n // room for the loader alongside rendering the emptyState\n let rect = new Rect(horizontalSpacing, y, loaderWidth, loaderHeight);\n let layoutInfo = new LayoutInfo('loader', lastNode.key, rect);\n newLayoutInfos.set(lastNode.key, layoutInfo);\n y = layoutInfo.rect.maxY;\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"}