@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.
@@ -0,0 +1,212 @@
1
+ var $5TwTj$reactstatelyvirtualizer = require("@react-stately/virtualizer");
2
+
3
+
4
+ function $parcel$export(e, n, v, s) {
5
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
+ }
7
+
8
+ $parcel$export(module.exports, "WaterfallLayout", () => $f2cd6b90da09fa37$export$e9f7cda058ba8df8);
9
+ /*
10
+ * Copyright 2024 Adobe. All rights reserved.
11
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License. You may obtain a copy
13
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software distributed under
16
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
+ * OF ANY KIND, either express or implied. See the License for the specific language
18
+ * governing permissions and limitations under the License.
19
+ */
20
+ class $f2cd6b90da09fa37$var$WaterfallLayoutInfo extends (0, $5TwTj$reactstatelyvirtualizer.LayoutInfo) {
21
+ copy() {
22
+ let res = super.copy();
23
+ res.column = this.column;
24
+ return res;
25
+ }
26
+ constructor(...args){
27
+ super(...args), this.column = 0;
28
+ }
29
+ }
30
+ const $f2cd6b90da09fa37$var$DEFAULT_OPTIONS = {
31
+ minItemSize: new (0, $5TwTj$reactstatelyvirtualizer.Size)(200, 200),
32
+ maxItemSize: new (0, $5TwTj$reactstatelyvirtualizer.Size)(Infinity, Infinity),
33
+ minSpace: new (0, $5TwTj$reactstatelyvirtualizer.Size)(18, 18),
34
+ maxColumns: Infinity,
35
+ dropIndicatorThickness: 2
36
+ };
37
+ class $f2cd6b90da09fa37$export$e9f7cda058ba8df8 extends (0, $5TwTj$reactstatelyvirtualizer.Layout) {
38
+ shouldInvalidateLayoutOptions(newOptions, oldOptions) {
39
+ return newOptions.maxColumns !== oldOptions.maxColumns || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness || !(newOptions.minItemSize || $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.minItemSize) || !(newOptions.maxItemSize || $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.maxItemSize) || !(newOptions.minSpace || $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.minSpace);
40
+ }
41
+ update(invalidationContext) {
42
+ let { minItemSize: minItemSize = $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.minItemSize, maxItemSize: maxItemSize = $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.maxItemSize, minSpace: minSpace = $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.minSpace, maxColumns: maxColumns = $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.maxColumns, dropIndicatorThickness: dropIndicatorThickness = $f2cd6b90da09fa37$var$DEFAULT_OPTIONS.dropIndicatorThickness } = invalidationContext.layoutOptions || {};
43
+ this.dropIndicatorThickness = dropIndicatorThickness;
44
+ let visibleWidth = this.virtualizer.visibleRect.width;
45
+ // The max item width is always the entire viewport.
46
+ // If the max item height is infinity, scale in proportion to the max width.
47
+ let maxItemWidth = Math.min(maxItemSize.width, visibleWidth);
48
+ let maxItemHeight = Number.isFinite(maxItemSize.height) ? maxItemSize.height : Math.floor(minItemSize.height / minItemSize.width * maxItemWidth);
49
+ // Compute the number of rows and columns needed to display the content
50
+ let columns = Math.floor(visibleWidth / (minItemSize.width + minSpace.width));
51
+ let numColumns = Math.max(1, Math.min(maxColumns, columns));
52
+ // Compute the available width (minus the space between items)
53
+ let width = visibleWidth - minSpace.width * Math.max(0, numColumns);
54
+ // Compute the item width based on the space available
55
+ let itemWidth = Math.floor(width / numColumns);
56
+ itemWidth = Math.max(minItemSize.width, Math.min(maxItemWidth, itemWidth));
57
+ // Compute the item height, which is proportional to the item width
58
+ let t = (itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width);
59
+ let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);
60
+ itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));
61
+ // Compute the horizontal spacing and content height
62
+ let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));
63
+ // Setup an array of column heights
64
+ let columnHeights = Array(numColumns).fill(minSpace.height);
65
+ let newLayoutInfos = new Map();
66
+ let addNode = (key, node)=>{
67
+ let oldLayoutInfo = this.layoutInfos.get(key);
68
+ let height = itemHeight;
69
+ let estimatedSize = true;
70
+ if (oldLayoutInfo) {
71
+ height = oldLayoutInfo.rect.height;
72
+ estimatedSize = invalidationContext.sizeChanged || oldLayoutInfo.estimatedSize || oldLayoutInfo.content !== node;
73
+ }
74
+ // Figure out which column to place the item in, and compute its position.
75
+ // Preserve the previous column index so items don't jump around during resizing unless the number of columns changed.
76
+ let prevColumn = numColumns === this.numColumns && oldLayoutInfo && oldLayoutInfo.rect.y < this.virtualizer.visibleRect.maxY ? oldLayoutInfo.column : undefined;
77
+ let column = prevColumn !== null && prevColumn !== void 0 ? prevColumn : columnHeights.reduce((minIndex, h, i)=>h < columnHeights[minIndex] ? i : minIndex, 0);
78
+ let x = horizontalSpacing + column * (itemWidth + horizontalSpacing);
79
+ let y = columnHeights[column];
80
+ let rect = new (0, $5TwTj$reactstatelyvirtualizer.Rect)(x, y, itemWidth, height);
81
+ let layoutInfo = new $f2cd6b90da09fa37$var$WaterfallLayoutInfo(node.type, key, rect);
82
+ layoutInfo.estimatedSize = estimatedSize;
83
+ layoutInfo.allowOverflow = true;
84
+ layoutInfo.content = node;
85
+ layoutInfo.column = column;
86
+ newLayoutInfos.set(key, layoutInfo);
87
+ columnHeights[column] += layoutInfo.rect.height + minSpace.height;
88
+ };
89
+ let skeletonCount = 0;
90
+ for (let node of this.virtualizer.collection)if (node.type === 'skeleton') {
91
+ // Add skeleton cards until every column has at least one, and we fill the viewport.
92
+ let startingHeights = [
93
+ ...columnHeights
94
+ ];
95
+ while(!columnHeights.every((h, i)=>h !== startingHeights[i]) || Math.min(...columnHeights) < this.virtualizer.visibleRect.height){
96
+ var _this_layoutInfos_get;
97
+ let key = `${node.key}-${skeletonCount++}`;
98
+ let content = ((_this_layoutInfos_get = this.layoutInfos.get(key)) === null || _this_layoutInfos_get === void 0 ? void 0 : _this_layoutInfos_get.content) || {
99
+ ...node
100
+ };
101
+ addNode(key, content);
102
+ }
103
+ break;
104
+ } else addNode(node.key, node);
105
+ // Reset all columns to the maximum for the next section
106
+ let maxHeight = Math.max(...columnHeights);
107
+ this.contentSize = new (0, $5TwTj$reactstatelyvirtualizer.Size)(this.virtualizer.visibleRect.width, maxHeight);
108
+ this.layoutInfos = newLayoutInfos;
109
+ this.numColumns = numColumns;
110
+ }
111
+ getLayoutInfo(key) {
112
+ return this.layoutInfos.get(key);
113
+ }
114
+ getContentSize() {
115
+ return this.contentSize;
116
+ }
117
+ getVisibleLayoutInfos(rect) {
118
+ let layoutInfos = [];
119
+ for (let layoutInfo of this.layoutInfos.values())if (layoutInfo.rect.intersects(rect) || this.virtualizer.isPersistedKey(layoutInfo.key)) layoutInfos.push(layoutInfo);
120
+ return layoutInfos;
121
+ }
122
+ updateItemSize(key, size) {
123
+ let layoutInfo = this.layoutInfos.get(key);
124
+ if (!size || !layoutInfo) return false;
125
+ if (size.height !== layoutInfo.rect.height) {
126
+ let newLayoutInfo = layoutInfo.copy();
127
+ newLayoutInfo.rect.height = size.height;
128
+ newLayoutInfo.estimatedSize = false;
129
+ this.layoutInfos.set(key, newLayoutInfo);
130
+ return true;
131
+ }
132
+ return false;
133
+ }
134
+ // Override keyboard navigation to work spatially.
135
+ getKeyRightOf(key) {
136
+ let layoutInfo = this.getLayoutInfo(key);
137
+ if (!layoutInfo) return null;
138
+ let rect = new (0, $5TwTj$reactstatelyvirtualizer.Rect)(layoutInfo.rect.maxX, layoutInfo.rect.y, this.virtualizer.visibleRect.maxX - layoutInfo.rect.maxX, layoutInfo.rect.height);
139
+ let layoutInfos = this.getVisibleLayoutInfos(rect);
140
+ let bestKey = null;
141
+ let bestDistance = Infinity;
142
+ for (let candidate of layoutInfos){
143
+ if (candidate.key === key) continue;
144
+ // Find the closest item in the x direction with the most overlap in the y direction.
145
+ let deltaX = candidate.rect.x - rect.x;
146
+ let overlapY = Math.min(candidate.rect.maxY, rect.maxY) - Math.max(candidate.rect.y, rect.y);
147
+ let distance = deltaX - overlapY;
148
+ if (distance < bestDistance) {
149
+ bestDistance = distance;
150
+ bestKey = candidate.key;
151
+ }
152
+ }
153
+ return bestKey;
154
+ }
155
+ getKeyLeftOf(key) {
156
+ let layoutInfo = this.getLayoutInfo(key);
157
+ if (!layoutInfo) return null;
158
+ let rect = new (0, $5TwTj$reactstatelyvirtualizer.Rect)(0, layoutInfo.rect.y, layoutInfo.rect.x, layoutInfo.rect.height);
159
+ let layoutInfos = this.getVisibleLayoutInfos(rect);
160
+ let bestKey = null;
161
+ let bestDistance = Infinity;
162
+ for (let candidate of layoutInfos){
163
+ if (candidate.key === key) continue;
164
+ // Find the closest item in the x direction with the most overlap in the y direction.
165
+ let deltaX = rect.maxX - candidate.rect.maxX;
166
+ let overlapY = Math.min(candidate.rect.maxY, rect.maxY) - Math.max(candidate.rect.y, rect.y);
167
+ let distance = deltaX - overlapY;
168
+ if (distance < bestDistance) {
169
+ bestDistance = distance;
170
+ bestKey = candidate.key;
171
+ }
172
+ }
173
+ return bestKey;
174
+ }
175
+ // This overrides the default behavior of shift selection to work spatially
176
+ // rather than following the order of the items in the collection (which may appear unpredictable).
177
+ getKeyRange(from, to) {
178
+ let fromLayoutInfo = this.getLayoutInfo(from);
179
+ let toLayoutInfo = this.getLayoutInfo(to);
180
+ if (!fromLayoutInfo || !toLayoutInfo) return [];
181
+ // Find items where half of the area intersects the rectangle
182
+ // formed from the first item to the last item in the range.
183
+ let rect = fromLayoutInfo.rect.union(toLayoutInfo.rect);
184
+ let keys = [];
185
+ for (let layoutInfo of this.layoutInfos.values())if (rect.intersection(layoutInfo.rect).area > layoutInfo.rect.area / 2) keys.push(layoutInfo.key);
186
+ return keys;
187
+ }
188
+ getDropTargetFromPoint(x, y) {
189
+ if (this.layoutInfos.size === 0) return {
190
+ type: 'root'
191
+ };
192
+ x += this.virtualizer.visibleRect.x;
193
+ y += this.virtualizer.visibleRect.y;
194
+ let key = this.virtualizer.keyAtPoint(new (0, $5TwTj$reactstatelyvirtualizer.Point)(x, y));
195
+ if (key == null) return {
196
+ type: 'root'
197
+ };
198
+ // Only support "on" drop position in waterfall layout.
199
+ // Reordering doesn't make sense because the items don't have a deterministic order.
200
+ return {
201
+ type: 'item',
202
+ key: key,
203
+ dropPosition: 'on'
204
+ };
205
+ }
206
+ constructor(...args){
207
+ super(...args), this.contentSize = new (0, $5TwTj$reactstatelyvirtualizer.Size)(), this.layoutInfos = new Map(), this.numColumns = 0, this.dropIndicatorThickness = 2;
208
+ }
209
+ }
210
+
211
+
212
+ //# sourceMappingURL=WaterfallLayout.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAiCD,MAAM,kDAA4B,CAAA,GAAA,yCAAS;IAGzC,OAA4B;QAC1B,IAAI,MAAM,KAAK,CAAC;QAChB,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM;QACxB,OAAO;IACT;;QAPF,qBACE,SAAS;;AAOX;AAEA,MAAM,wCAAkB;IACtB,aAAa,IAAI,CAAA,GAAA,mCAAG,EAAE,KAAK;IAC3B,aAAa,IAAI,CAAA,GAAA,mCAAG,EAAE,UAAU;IAChC,UAAU,IAAI,CAAA,GAAA,mCAAG,EAAE,IAAI;IACvB,YAAY;IACZ,wBAAwB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IAAI,CAAC,aAAa,CAAC;QACtC,IAAI,CAAC,kBAAkB,CAAC,cACtB,OAAO,EAAE;QAGX,6DAA6D;QAC7D,4DAA4D;QAC5D,IAAI,OAAO,eAAe,IAAI,CAAC,KAAK,CAAC,aAAa,IAAI;QACtD,IAAI,OAAc,EAAE;QACpB,KAAK,IAAI,cAAc,IAAI,CAAC,WAAW,CAAC,MAAM,GAC5C,IAAI,KAAK,YAAY,CAAC,WAAW,IAAI,EAAE,IAAI,GAAG,WAAW,IAAI,CAAC,IAAI,GAAG,GACnE,KAAK,IAAI,CAAC,WAAW,GAAG;QAG5B,OAAO;IACT;IAEA,uBAAuB,CAAS,EAAE,CAAS,EAAc;QACvD,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,GAC5B,OAAO;YAAC,MAAM;QAAM;QAGtB,KAAK,IAAI,CAAC,WAAW,CAAE,WAAW,CAAC,CAAC;QACpC,KAAK,IAAI,CAAC,WAAW,CAAE,WAAW,CAAC,CAAC;QACpC,IAAI,MAAM,IAAI,CAAC,WAAW,CAAE,UAAU,CAAC,IAAI,CAAA,GAAA,oCAAI,EAAE,GAAG;QACpD,IAAI,OAAO,MACT,OAAO;YAAC,MAAM;QAAM;QAGtB,uDAAuD;QACvD,oFAAoF;QACpF,OAAO;YACL,MAAM;iBACN;YACA,cAAc;QAChB;IACF;;QA/OK,qBACG,cAAoB,IAAI,CAAA,GAAA,mCAAG,UAC3B,cAA6C,IAAI,YAC/C,aAAa,QACb,yBAAyB;;AA4OrC","sources":["packages/@react-stately/layout/src/WaterfallLayout.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DropTarget, DropTargetDelegate, Key, LayoutDelegate, Node} from '@react-types/shared';\nimport {InvalidationContext, Layout, LayoutInfo, Point, Rect, Size} from '@react-stately/virtualizer';\n\nexport interface WaterfallLayoutOptions {\n /**\n * The minimum item size.\n * @default 200 x 200\n */\n minItemSize?: Size,\n /**\n * The maximum item size.\n * @default Infinity\n */\n maxItemSize?: Size,\n /**\n * The minimum space required between items.\n * @default 18 x 18\n */\n minSpace?: Size,\n /**\n * The maximum number of columns.\n * @default Infinity\n */\n maxColumns?: number,\n /**\n * The thickness of the drop indicator.\n * @default 2\n */\n dropIndicatorThickness?: number\n}\n\nclass WaterfallLayoutInfo extends LayoutInfo {\n column = 0;\n\n copy(): WaterfallLayoutInfo {\n let res = super.copy() as WaterfallLayoutInfo;\n res.column = this.column;\n return res;\n }\n}\n\nconst DEFAULT_OPTIONS = {\n minItemSize: new Size(200, 200),\n maxItemSize: new Size(Infinity, Infinity),\n minSpace: new Size(18, 18),\n maxColumns: Infinity,\n dropIndicatorThickness: 2\n};\n\nexport class WaterfallLayout<T extends object, O extends WaterfallLayoutOptions = WaterfallLayoutOptions> extends Layout<Node<T>, O> implements LayoutDelegate, DropTargetDelegate {\n private contentSize: Size = new Size();\n private layoutInfos: Map<Key, WaterfallLayoutInfo> = new Map();\n protected numColumns = 0;\n protected dropIndicatorThickness = 2;\n\n shouldInvalidateLayoutOptions(newOptions: O, oldOptions: O): boolean {\n return newOptions.maxColumns !== oldOptions.maxColumns\n || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness\n || (!(newOptions.minItemSize || DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || DEFAULT_OPTIONS.minItemSize))\n || (!(newOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || DEFAULT_OPTIONS.maxItemSize))\n || (!(newOptions.minSpace || DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || DEFAULT_OPTIONS.minSpace));\n }\n\n update(invalidationContext: InvalidationContext<O>): void {\n let {\n minItemSize = DEFAULT_OPTIONS.minItemSize,\n maxItemSize = DEFAULT_OPTIONS.maxItemSize,\n minSpace = DEFAULT_OPTIONS.minSpace,\n maxColumns = DEFAULT_OPTIONS.maxColumns,\n dropIndicatorThickness = DEFAULT_OPTIONS.dropIndicatorThickness\n } = invalidationContext.layoutOptions || {};\n this.dropIndicatorThickness = dropIndicatorThickness;\n let visibleWidth = this.virtualizer!.visibleRect.width;\n\n // The max item width is always the entire viewport.\n // If the max item height is infinity, scale in proportion to the max width.\n let maxItemWidth = Math.min(maxItemSize.width, visibleWidth);\n let maxItemHeight = Number.isFinite(maxItemSize.height)\n ? maxItemSize.height\n : Math.floor((minItemSize.height / minItemSize.width) * maxItemWidth);\n\n // Compute the number of rows and columns needed to display the content\n let columns = Math.floor(visibleWidth / (minItemSize.width + minSpace.width));\n let numColumns = Math.max(1, Math.min(maxColumns, columns));\n\n // Compute the available width (minus the space between items)\n let width = visibleWidth - (minSpace.width * Math.max(0, numColumns));\n\n // Compute the item width based on the space available\n let itemWidth = Math.floor(width / numColumns);\n itemWidth = Math.max(minItemSize.width, Math.min(maxItemWidth, itemWidth));\n\n // Compute the item height, which is proportional to the item width\n let t = ((itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width));\n let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);\n itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));\n\n // Compute the horizontal spacing and content height\n let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));\n\n // Setup an array of column heights\n let columnHeights = Array(numColumns).fill(minSpace.height);\n let newLayoutInfos = new Map();\n let addNode = (key: Key, node: Node<T>) => {\n let oldLayoutInfo = this.layoutInfos.get(key);\n let height = itemHeight;\n let estimatedSize = true;\n if (oldLayoutInfo) {\n height = oldLayoutInfo.rect.height;\n estimatedSize = invalidationContext.sizeChanged || oldLayoutInfo.estimatedSize || oldLayoutInfo.content !== node;\n }\n\n // Figure out which column to place the item in, and compute its position.\n // Preserve the previous column index so items don't jump around during resizing unless the number of columns changed.\n let prevColumn = numColumns === this.numColumns && oldLayoutInfo && oldLayoutInfo.rect.y < this.virtualizer!.visibleRect.maxY ? oldLayoutInfo.column : undefined;\n let column = prevColumn ?? columnHeights.reduce((minIndex, h, i) => h < columnHeights[minIndex] ? i : minIndex, 0);\n let x = horizontalSpacing + column * (itemWidth + horizontalSpacing);\n let y = columnHeights[column];\n\n let rect = new Rect(x, y, itemWidth, height);\n let layoutInfo = new WaterfallLayoutInfo(node.type, key, rect);\n layoutInfo.estimatedSize = estimatedSize;\n layoutInfo.allowOverflow = true;\n layoutInfo.content = node;\n layoutInfo.column = column;\n newLayoutInfos.set(key, layoutInfo);\n\n columnHeights[column] += layoutInfo.rect.height + minSpace.height;\n };\n\n let skeletonCount = 0;\n for (let node of this.virtualizer!.collection) {\n if (node.type === 'skeleton') {\n // Add skeleton cards until every column has at least one, and we fill the viewport.\n let startingHeights = [...columnHeights];\n while (\n !columnHeights.every((h, i) => h !== startingHeights[i]) ||\n Math.min(...columnHeights) < this.virtualizer!.visibleRect.height\n ) {\n let key = `${node.key}-${skeletonCount++}`;\n let content = this.layoutInfos.get(key)?.content || {...node};\n addNode(key, content);\n }\n break;\n } else {\n addNode(node.key, node);\n }\n }\n\n // Reset all columns to the maximum for the next section\n let maxHeight = Math.max(...columnHeights);\n this.contentSize = new Size(this.virtualizer!.visibleRect.width, maxHeight);\n this.layoutInfos = newLayoutInfos;\n this.numColumns = numColumns;\n }\n\n getLayoutInfo(key: Key): LayoutInfo {\n return this.layoutInfos.get(key)!;\n }\n\n getContentSize(): Size {\n return this.contentSize;\n }\n\n getVisibleLayoutInfos(rect: Rect): LayoutInfo[] {\n let layoutInfos: LayoutInfo[] = [];\n for (let layoutInfo of this.layoutInfos.values()) {\n if (layoutInfo.rect.intersects(rect) || this.virtualizer!.isPersistedKey(layoutInfo.key)) {\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 // Override keyboard navigation to work spatially.\n getKeyRightOf(key: Key): Key | null {\n let layoutInfo = this.getLayoutInfo(key);\n if (!layoutInfo) {\n return null;\n }\n\n let rect = new Rect(layoutInfo.rect.maxX, layoutInfo.rect.y, this.virtualizer!.visibleRect.maxX - layoutInfo.rect.maxX, layoutInfo.rect.height);\n let layoutInfos = this.getVisibleLayoutInfos(rect);\n let bestKey: Key | null = null;\n let bestDistance = Infinity;\n for (let candidate of layoutInfos) {\n if (candidate.key === key) {\n continue;\n }\n\n // Find the closest item in the x direction with the most overlap in the y direction.\n let deltaX = candidate.rect.x - rect.x;\n let overlapY = Math.min(candidate.rect.maxY, rect.maxY) - Math.max(candidate.rect.y, rect.y);\n let distance = deltaX - overlapY;\n if (distance < bestDistance) {\n bestDistance = distance;\n bestKey = candidate.key;\n }\n }\n\n return bestKey;\n }\n\n getKeyLeftOf(key: Key): Key | null {\n let layoutInfo = this.getLayoutInfo(key);\n if (!layoutInfo) {\n return null;\n }\n\n let rect = new Rect(0, layoutInfo.rect.y, layoutInfo.rect.x, layoutInfo.rect.height);\n let layoutInfos = this.getVisibleLayoutInfos(rect);\n let bestKey: Key | null = null;\n let bestDistance = Infinity;\n for (let candidate of layoutInfos) {\n if (candidate.key === key) {\n continue;\n }\n\n // Find the closest item in the x direction with the most overlap in the y direction.\n let deltaX = rect.maxX - candidate.rect.maxX;\n let overlapY = Math.min(candidate.rect.maxY, rect.maxY) - Math.max(candidate.rect.y, rect.y);\n let distance = deltaX - overlapY;\n if (distance < bestDistance) {\n bestDistance = distance;\n bestKey = candidate.key;\n }\n }\n\n return bestKey;\n }\n\n // This overrides the default behavior of shift selection to work spatially\n // rather than following the order of the items in the collection (which may appear unpredictable).\n getKeyRange(from: Key, to: Key): Key[] {\n let fromLayoutInfo = this.getLayoutInfo(from);\n let toLayoutInfo = this.getLayoutInfo(to);\n if (!fromLayoutInfo || !toLayoutInfo) {\n return [];\n }\n\n // Find items where half of the area intersects the rectangle\n // formed from the first item to the last item in the range.\n let rect = fromLayoutInfo.rect.union(toLayoutInfo.rect);\n let keys: Key[] = [];\n for (let layoutInfo of this.layoutInfos.values()) {\n if (rect.intersection(layoutInfo.rect).area > layoutInfo.rect.area / 2) {\n keys.push(layoutInfo.key);\n }\n }\n return keys;\n }\n\n getDropTargetFromPoint(x: number, y: number): DropTarget {\n if (this.layoutInfos.size === 0) {\n return {type: 'root'};\n }\n\n x += this.virtualizer!.visibleRect.x;\n y += this.virtualizer!.visibleRect.y;\n let key = this.virtualizer!.keyAtPoint(new Point(x, y));\n if (key == null) {\n return {type: 'root'};\n }\n\n // Only support \"on\" drop position in waterfall layout.\n // Reordering doesn't make sense because the items don't have a deterministic order.\n return {\n type: 'item',\n key,\n dropPosition: 'on'\n };\n }\n}\n"],"names":[],"version":3,"file":"WaterfallLayout.main.js.map"}
@@ -0,0 +1,207 @@
1
+ import {LayoutInfo as $lFzwI$LayoutInfo, Size as $lFzwI$Size, Rect as $lFzwI$Rect, Point as $lFzwI$Point, Layout as $lFzwI$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
+ class $f483179558aa907f$var$WaterfallLayoutInfo extends (0, $lFzwI$LayoutInfo) {
15
+ copy() {
16
+ let res = super.copy();
17
+ res.column = this.column;
18
+ return res;
19
+ }
20
+ constructor(...args){
21
+ super(...args), this.column = 0;
22
+ }
23
+ }
24
+ const $f483179558aa907f$var$DEFAULT_OPTIONS = {
25
+ minItemSize: new (0, $lFzwI$Size)(200, 200),
26
+ maxItemSize: new (0, $lFzwI$Size)(Infinity, Infinity),
27
+ minSpace: new (0, $lFzwI$Size)(18, 18),
28
+ maxColumns: Infinity,
29
+ dropIndicatorThickness: 2
30
+ };
31
+ class $f483179558aa907f$export$e9f7cda058ba8df8 extends (0, $lFzwI$Layout) {
32
+ shouldInvalidateLayoutOptions(newOptions, oldOptions) {
33
+ return newOptions.maxColumns !== oldOptions.maxColumns || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness || !(newOptions.minItemSize || $f483179558aa907f$var$DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || $f483179558aa907f$var$DEFAULT_OPTIONS.minItemSize) || !(newOptions.maxItemSize || $f483179558aa907f$var$DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || $f483179558aa907f$var$DEFAULT_OPTIONS.maxItemSize) || !(newOptions.minSpace || $f483179558aa907f$var$DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || $f483179558aa907f$var$DEFAULT_OPTIONS.minSpace);
34
+ }
35
+ update(invalidationContext) {
36
+ let { minItemSize: minItemSize = $f483179558aa907f$var$DEFAULT_OPTIONS.minItemSize, maxItemSize: maxItemSize = $f483179558aa907f$var$DEFAULT_OPTIONS.maxItemSize, minSpace: minSpace = $f483179558aa907f$var$DEFAULT_OPTIONS.minSpace, maxColumns: maxColumns = $f483179558aa907f$var$DEFAULT_OPTIONS.maxColumns, dropIndicatorThickness: dropIndicatorThickness = $f483179558aa907f$var$DEFAULT_OPTIONS.dropIndicatorThickness } = invalidationContext.layoutOptions || {};
37
+ this.dropIndicatorThickness = dropIndicatorThickness;
38
+ let visibleWidth = this.virtualizer.visibleRect.width;
39
+ // The max item width is always the entire viewport.
40
+ // If the max item height is infinity, scale in proportion to the max width.
41
+ let maxItemWidth = Math.min(maxItemSize.width, visibleWidth);
42
+ let maxItemHeight = Number.isFinite(maxItemSize.height) ? maxItemSize.height : Math.floor(minItemSize.height / minItemSize.width * maxItemWidth);
43
+ // Compute the number of rows and columns needed to display the content
44
+ let columns = Math.floor(visibleWidth / (minItemSize.width + minSpace.width));
45
+ let numColumns = Math.max(1, Math.min(maxColumns, columns));
46
+ // Compute the available width (minus the space between items)
47
+ let width = visibleWidth - minSpace.width * Math.max(0, numColumns);
48
+ // Compute the item width based on the space available
49
+ let itemWidth = Math.floor(width / numColumns);
50
+ itemWidth = Math.max(minItemSize.width, Math.min(maxItemWidth, itemWidth));
51
+ // Compute the item height, which is proportional to the item width
52
+ let t = (itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width);
53
+ let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);
54
+ itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));
55
+ // Compute the horizontal spacing and content height
56
+ let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));
57
+ // Setup an array of column heights
58
+ let columnHeights = Array(numColumns).fill(minSpace.height);
59
+ let newLayoutInfos = new Map();
60
+ let addNode = (key, node)=>{
61
+ let oldLayoutInfo = this.layoutInfos.get(key);
62
+ let height = itemHeight;
63
+ let estimatedSize = true;
64
+ if (oldLayoutInfo) {
65
+ height = oldLayoutInfo.rect.height;
66
+ estimatedSize = invalidationContext.sizeChanged || oldLayoutInfo.estimatedSize || oldLayoutInfo.content !== node;
67
+ }
68
+ // Figure out which column to place the item in, and compute its position.
69
+ // Preserve the previous column index so items don't jump around during resizing unless the number of columns changed.
70
+ let prevColumn = numColumns === this.numColumns && oldLayoutInfo && oldLayoutInfo.rect.y < this.virtualizer.visibleRect.maxY ? oldLayoutInfo.column : undefined;
71
+ let column = prevColumn !== null && prevColumn !== void 0 ? prevColumn : columnHeights.reduce((minIndex, h, i)=>h < columnHeights[minIndex] ? i : minIndex, 0);
72
+ let x = horizontalSpacing + column * (itemWidth + horizontalSpacing);
73
+ let y = columnHeights[column];
74
+ let rect = new (0, $lFzwI$Rect)(x, y, itemWidth, height);
75
+ let layoutInfo = new $f483179558aa907f$var$WaterfallLayoutInfo(node.type, key, rect);
76
+ layoutInfo.estimatedSize = estimatedSize;
77
+ layoutInfo.allowOverflow = true;
78
+ layoutInfo.content = node;
79
+ layoutInfo.column = column;
80
+ newLayoutInfos.set(key, layoutInfo);
81
+ columnHeights[column] += layoutInfo.rect.height + minSpace.height;
82
+ };
83
+ let skeletonCount = 0;
84
+ for (let node of this.virtualizer.collection)if (node.type === 'skeleton') {
85
+ // Add skeleton cards until every column has at least one, and we fill the viewport.
86
+ let startingHeights = [
87
+ ...columnHeights
88
+ ];
89
+ while(!columnHeights.every((h, i)=>h !== startingHeights[i]) || Math.min(...columnHeights) < this.virtualizer.visibleRect.height){
90
+ var _this_layoutInfos_get;
91
+ let key = `${node.key}-${skeletonCount++}`;
92
+ let content = ((_this_layoutInfos_get = this.layoutInfos.get(key)) === null || _this_layoutInfos_get === void 0 ? void 0 : _this_layoutInfos_get.content) || {
93
+ ...node
94
+ };
95
+ addNode(key, content);
96
+ }
97
+ break;
98
+ } else addNode(node.key, node);
99
+ // Reset all columns to the maximum for the next section
100
+ let maxHeight = Math.max(...columnHeights);
101
+ this.contentSize = new (0, $lFzwI$Size)(this.virtualizer.visibleRect.width, maxHeight);
102
+ this.layoutInfos = newLayoutInfos;
103
+ this.numColumns = numColumns;
104
+ }
105
+ getLayoutInfo(key) {
106
+ return this.layoutInfos.get(key);
107
+ }
108
+ getContentSize() {
109
+ return this.contentSize;
110
+ }
111
+ getVisibleLayoutInfos(rect) {
112
+ let layoutInfos = [];
113
+ for (let layoutInfo of this.layoutInfos.values())if (layoutInfo.rect.intersects(rect) || this.virtualizer.isPersistedKey(layoutInfo.key)) layoutInfos.push(layoutInfo);
114
+ return layoutInfos;
115
+ }
116
+ updateItemSize(key, size) {
117
+ let layoutInfo = this.layoutInfos.get(key);
118
+ if (!size || !layoutInfo) return false;
119
+ if (size.height !== layoutInfo.rect.height) {
120
+ let newLayoutInfo = layoutInfo.copy();
121
+ newLayoutInfo.rect.height = size.height;
122
+ newLayoutInfo.estimatedSize = false;
123
+ this.layoutInfos.set(key, newLayoutInfo);
124
+ return true;
125
+ }
126
+ return false;
127
+ }
128
+ // Override keyboard navigation to work spatially.
129
+ getKeyRightOf(key) {
130
+ let layoutInfo = this.getLayoutInfo(key);
131
+ if (!layoutInfo) return null;
132
+ let rect = new (0, $lFzwI$Rect)(layoutInfo.rect.maxX, layoutInfo.rect.y, this.virtualizer.visibleRect.maxX - layoutInfo.rect.maxX, layoutInfo.rect.height);
133
+ let layoutInfos = this.getVisibleLayoutInfos(rect);
134
+ let bestKey = null;
135
+ let bestDistance = Infinity;
136
+ for (let candidate of layoutInfos){
137
+ if (candidate.key === key) continue;
138
+ // Find the closest item in the x direction with the most overlap in the y direction.
139
+ let deltaX = candidate.rect.x - rect.x;
140
+ let overlapY = Math.min(candidate.rect.maxY, rect.maxY) - Math.max(candidate.rect.y, rect.y);
141
+ let distance = deltaX - overlapY;
142
+ if (distance < bestDistance) {
143
+ bestDistance = distance;
144
+ bestKey = candidate.key;
145
+ }
146
+ }
147
+ return bestKey;
148
+ }
149
+ getKeyLeftOf(key) {
150
+ let layoutInfo = this.getLayoutInfo(key);
151
+ if (!layoutInfo) return null;
152
+ let rect = new (0, $lFzwI$Rect)(0, layoutInfo.rect.y, layoutInfo.rect.x, layoutInfo.rect.height);
153
+ let layoutInfos = this.getVisibleLayoutInfos(rect);
154
+ let bestKey = null;
155
+ let bestDistance = Infinity;
156
+ for (let candidate of layoutInfos){
157
+ if (candidate.key === key) continue;
158
+ // Find the closest item in the x direction with the most overlap in the y direction.
159
+ let deltaX = rect.maxX - candidate.rect.maxX;
160
+ let overlapY = Math.min(candidate.rect.maxY, rect.maxY) - Math.max(candidate.rect.y, rect.y);
161
+ let distance = deltaX - overlapY;
162
+ if (distance < bestDistance) {
163
+ bestDistance = distance;
164
+ bestKey = candidate.key;
165
+ }
166
+ }
167
+ return bestKey;
168
+ }
169
+ // This overrides the default behavior of shift selection to work spatially
170
+ // rather than following the order of the items in the collection (which may appear unpredictable).
171
+ getKeyRange(from, to) {
172
+ let fromLayoutInfo = this.getLayoutInfo(from);
173
+ let toLayoutInfo = this.getLayoutInfo(to);
174
+ if (!fromLayoutInfo || !toLayoutInfo) return [];
175
+ // Find items where half of the area intersects the rectangle
176
+ // formed from the first item to the last item in the range.
177
+ let rect = fromLayoutInfo.rect.union(toLayoutInfo.rect);
178
+ let keys = [];
179
+ for (let layoutInfo of this.layoutInfos.values())if (rect.intersection(layoutInfo.rect).area > layoutInfo.rect.area / 2) keys.push(layoutInfo.key);
180
+ return keys;
181
+ }
182
+ getDropTargetFromPoint(x, y) {
183
+ if (this.layoutInfos.size === 0) return {
184
+ type: 'root'
185
+ };
186
+ x += this.virtualizer.visibleRect.x;
187
+ y += this.virtualizer.visibleRect.y;
188
+ let key = this.virtualizer.keyAtPoint(new (0, $lFzwI$Point)(x, y));
189
+ if (key == null) return {
190
+ type: 'root'
191
+ };
192
+ // Only support "on" drop position in waterfall layout.
193
+ // Reordering doesn't make sense because the items don't have a deterministic order.
194
+ return {
195
+ type: 'item',
196
+ key: key,
197
+ dropPosition: 'on'
198
+ };
199
+ }
200
+ constructor(...args){
201
+ super(...args), this.contentSize = new (0, $lFzwI$Size)(), this.layoutInfos = new Map(), this.numColumns = 0, this.dropIndicatorThickness = 2;
202
+ }
203
+ }
204
+
205
+
206
+ export {$f483179558aa907f$export$e9f7cda058ba8df8 as WaterfallLayout};
207
+ //# sourceMappingURL=WaterfallLayout.module.js.map