@react-stately/layout 4.1.0 → 4.2.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.
@@ -17,80 +17,120 @@ $parcel$export(module.exports, "GridLayout", () => $1f7773ceb2a3b9a6$export$7d2b
17
17
  * OF ANY KIND, either express or implied. See the License for the specific language
18
18
  * governing permissions and limitations under the License.
19
19
  */
20
+ const $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS = {
21
+ minItemSize: new (0, $7Tzdl$reactstatelyvirtualizer.Size)(200, 200),
22
+ maxItemSize: new (0, $7Tzdl$reactstatelyvirtualizer.Size)(Infinity, Infinity),
23
+ preserveAspectRatio: false,
24
+ minSpace: new (0, $7Tzdl$reactstatelyvirtualizer.Size)(18, 18),
25
+ maxColumns: Infinity,
26
+ dropIndicatorThickness: 2
27
+ };
20
28
  class $1f7773ceb2a3b9a6$export$7d2b12578154a735 extends (0, $7Tzdl$reactstatelyvirtualizer.Layout) {
21
- update() {
29
+ shouldInvalidateLayoutOptions(newOptions, oldOptions) {
30
+ return newOptions.maxColumns !== oldOptions.maxColumns || newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness || newOptions.preserveAspectRatio !== oldOptions.preserveAspectRatio || !(newOptions.minItemSize || $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.minItemSize).equals(oldOptions.minItemSize || $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.minItemSize) || !(newOptions.maxItemSize || $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.maxItemSize).equals(oldOptions.maxItemSize || $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.maxItemSize) || !(newOptions.minSpace || $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.minSpace).equals(oldOptions.minSpace || $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.minSpace);
31
+ }
32
+ update(invalidationContext) {
33
+ let { minItemSize: minItemSize = $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.minItemSize, maxItemSize: maxItemSize = $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.maxItemSize, preserveAspectRatio: preserveAspectRatio = $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.preserveAspectRatio, minSpace: minSpace = $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.minSpace, maxColumns: maxColumns = $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.maxColumns, dropIndicatorThickness: dropIndicatorThickness = $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.dropIndicatorThickness } = invalidationContext.layoutOptions || {};
34
+ this.dropIndicatorThickness = dropIndicatorThickness;
22
35
  let visibleWidth = this.virtualizer.visibleRect.width;
23
36
  // The max item width is always the entire viewport.
24
37
  // If the max item height is infinity, scale in proportion to the max width.
25
- let maxItemWidth = Math.min(this.maxItemSize.width, visibleWidth);
26
- let maxItemHeight = Number.isFinite(this.maxItemSize.height) ? this.maxItemSize.height : Math.floor(this.minItemSize.height / this.minItemSize.width * maxItemWidth);
38
+ let maxItemWidth = Math.min(maxItemSize.width, visibleWidth);
39
+ let maxItemHeight = Number.isFinite(maxItemSize.height) ? maxItemSize.height : Math.floor(minItemSize.height / minItemSize.width * maxItemWidth);
27
40
  // Compute the number of rows and columns needed to display the content
28
- let columns = Math.floor(visibleWidth / (this.minItemSize.width + this.minSpace.width));
29
- this.numColumns = Math.max(1, Math.min(this.maxColumns, columns));
41
+ let columns = Math.floor(visibleWidth / (minItemSize.width + minSpace.width));
42
+ let numColumns = Math.max(1, Math.min(maxColumns, columns));
30
43
  // Compute the available width (minus the space between items)
31
- let width = visibleWidth - this.minSpace.width * Math.max(0, this.numColumns);
44
+ let width = visibleWidth - minSpace.width * Math.max(0, numColumns);
32
45
  // Compute the item width based on the space available
33
- let itemWidth = Math.floor(width / this.numColumns);
34
- itemWidth = Math.max(this.minItemSize.width, Math.min(maxItemWidth, itemWidth));
46
+ let itemWidth = Math.floor(width / numColumns);
47
+ itemWidth = Math.max(minItemSize.width, Math.min(maxItemWidth, itemWidth));
35
48
  // Compute the item height, which is proportional to the item width
36
- let t = (itemWidth - this.minItemSize.width) / Math.max(1, maxItemWidth - this.minItemSize.width);
37
- let itemHeight = this.minItemSize.height + Math.floor((maxItemHeight - this.minItemSize.height) * t);
38
- itemHeight = Math.max(this.minItemSize.height, Math.min(maxItemHeight, itemHeight));
39
- this.itemSize = new (0, $7Tzdl$reactstatelyvirtualizer.Size)(itemWidth, itemHeight);
49
+ let t = (itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width);
50
+ let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);
51
+ itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));
40
52
  // Compute the horizontal spacing and content height
41
- this.horizontalSpacing = Math.floor((visibleWidth - this.numColumns * this.itemSize.width) / (this.numColumns + 1));
42
- this.layoutInfos = [];
43
- for (let node of this.virtualizer.collection)this.layoutInfos.push(this.getLayoutInfoForNode(node));
44
- }
45
- getVisibleLayoutInfos(rect) {
46
- let firstVisibleItem = this.getIndexAtPoint(rect.x, rect.y);
47
- let lastVisibleItem = this.getIndexAtPoint(rect.maxX, rect.maxY);
48
- let result = this.layoutInfos.slice(firstVisibleItem, lastVisibleItem + 1);
49
- let persistedIndices = [];
50
- for (let key of this.virtualizer.persistedKeys){
51
- let item = this.virtualizer.collection.getItem(key);
52
- if ((item === null || item === void 0 ? void 0 : item.index) != null) persistedIndices.push(item.index);
53
+ let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));
54
+ this.gap = new (0, $7Tzdl$reactstatelyvirtualizer.Size)(horizontalSpacing, minSpace.height);
55
+ let rows = Math.ceil(this.virtualizer.collection.size / numColumns);
56
+ let iterator = this.virtualizer.collection[Symbol.iterator]();
57
+ let y = rows > 0 ? minSpace.height : 0;
58
+ let newLayoutInfos = new Map();
59
+ let skeleton = null;
60
+ let skeletonCount = 0;
61
+ for(let row = 0; row < rows; row++){
62
+ let maxHeight = 0;
63
+ let rowLayoutInfos = [];
64
+ for(let col = 0; col < numColumns; col++){
65
+ // Repeat skeleton until the end of the current row.
66
+ let node = skeleton || iterator.next().value;
67
+ if (!node) break;
68
+ if (node.type === 'skeleton') skeleton = node;
69
+ let key = skeleton ? `${skeleton.key}-${skeletonCount++}` : node.key;
70
+ let oldLayoutInfo = this.layoutInfos.get(key);
71
+ let content = node;
72
+ if (skeleton) content = oldLayoutInfo && oldLayoutInfo.content.key === key ? oldLayoutInfo.content : {
73
+ ...skeleton,
74
+ key: key
75
+ };
76
+ let x = horizontalSpacing + col * (itemWidth + horizontalSpacing);
77
+ let height = itemHeight;
78
+ let estimatedSize = !preserveAspectRatio;
79
+ if (oldLayoutInfo && estimatedSize) {
80
+ height = oldLayoutInfo.rect.height;
81
+ estimatedSize = invalidationContext.layoutOptionsChanged || invalidationContext.sizeChanged || oldLayoutInfo.estimatedSize || oldLayoutInfo.content !== content;
82
+ }
83
+ let rect = new (0, $7Tzdl$reactstatelyvirtualizer.Rect)(x, y, itemWidth, height);
84
+ let layoutInfo = new (0, $7Tzdl$reactstatelyvirtualizer.LayoutInfo)(node.type, key, rect);
85
+ layoutInfo.estimatedSize = estimatedSize;
86
+ layoutInfo.allowOverflow = true;
87
+ layoutInfo.content = content;
88
+ newLayoutInfos.set(key, layoutInfo);
89
+ rowLayoutInfos.push(layoutInfo);
90
+ maxHeight = Math.max(maxHeight, layoutInfo.rect.height);
91
+ }
92
+ for (let layoutInfo of rowLayoutInfos)layoutInfo.rect.height = maxHeight;
93
+ y += maxHeight + minSpace.height;
94
+ // Keep adding skeleton rows until we fill the viewport
95
+ if (skeleton && row === rows - 1 && y < this.virtualizer.visibleRect.height) rows++;
53
96
  }
54
- persistedIndices.sort((a, b)=>a - b);
55
- let persistedBefore = [];
56
- for (let index of persistedIndices){
57
- if (index < firstVisibleItem) persistedBefore.push(this.layoutInfos[index]);
58
- else if (index > lastVisibleItem) result.push(this.layoutInfos[index]);
59
- }
60
- result.unshift(...persistedBefore);
61
- return result;
62
- }
63
- getIndexAtPoint(x, y) {
64
- let itemHeight = this.itemSize.height + this.minSpace.height;
65
- let itemWidth = this.itemSize.width + this.horizontalSpacing;
66
- return Math.max(0, Math.min(this.virtualizer.collection.size - 1, Math.floor(y / itemHeight) * this.numColumns + Math.floor((x - this.horizontalSpacing) / itemWidth)));
97
+ this.layoutInfos = newLayoutInfos;
98
+ this.contentSize = new (0, $7Tzdl$reactstatelyvirtualizer.Size)(this.virtualizer.visibleRect.width, y);
67
99
  }
68
100
  getLayoutInfo(key) {
69
- let node = this.virtualizer.collection.getItem(key);
70
- return node ? this.layoutInfos[node.index] : null;
71
- }
72
- getLayoutInfoForNode(node) {
73
- let idx = node.index;
74
- let row = Math.floor(idx / this.numColumns);
75
- let column = idx % this.numColumns;
76
- let x = this.horizontalSpacing + column * (this.itemSize.width + this.horizontalSpacing);
77
- let y = this.minSpace.height + row * (this.itemSize.height + this.minSpace.height);
78
- let rect = new (0, $7Tzdl$reactstatelyvirtualizer.Rect)(x, y, this.itemSize.width, this.itemSize.height);
79
- return new (0, $7Tzdl$reactstatelyvirtualizer.LayoutInfo)(node.type, node.key, rect);
101
+ return this.layoutInfos.get(key);
80
102
  }
81
103
  getContentSize() {
82
- let numRows = Math.ceil(this.virtualizer.collection.size / this.numColumns);
83
- let contentHeight = this.minSpace.height + numRows * (this.itemSize.height + this.minSpace.height);
84
- return new (0, $7Tzdl$reactstatelyvirtualizer.Size)(this.virtualizer.visibleRect.width, contentHeight);
104
+ return this.contentSize;
105
+ }
106
+ getVisibleLayoutInfos(rect) {
107
+ let layoutInfos = [];
108
+ for (let layoutInfo of this.layoutInfos.values())if (layoutInfo.rect.intersects(rect) || this.virtualizer.isPersistedKey(layoutInfo.key)) layoutInfos.push(layoutInfo);
109
+ return layoutInfos;
110
+ }
111
+ updateItemSize(key, size) {
112
+ let layoutInfo = this.layoutInfos.get(key);
113
+ if (!size || !layoutInfo) return false;
114
+ if (size.height !== layoutInfo.rect.height) {
115
+ let newLayoutInfo = layoutInfo.copy();
116
+ newLayoutInfo.rect.height = size.height;
117
+ newLayoutInfo.estimatedSize = false;
118
+ this.layoutInfos.set(key, newLayoutInfo);
119
+ return true;
120
+ }
121
+ return false;
85
122
  }
86
123
  getDropTargetFromPoint(x, y, isValidDropTarget) {
87
- if (this.layoutInfos.length === 0) return {
124
+ if (this.layoutInfos.size === 0) return {
88
125
  type: 'root'
89
126
  };
90
127
  x += this.virtualizer.visibleRect.x;
91
128
  y += this.virtualizer.visibleRect.y;
92
- let index = this.getIndexAtPoint(x, y);
93
- let layoutInfo = this.layoutInfos[index];
129
+ let key = this.virtualizer.keyAtPoint(new (0, $7Tzdl$reactstatelyvirtualizer.Point)(x, y));
130
+ let layoutInfo = key != null ? this.getLayoutInfo(key) : null;
131
+ if (!layoutInfo) return {
132
+ type: 'root'
133
+ };
94
134
  let target = {
95
135
  type: 'item',
96
136
  key: layoutInfo.key,
@@ -122,17 +162,12 @@ class $1f7773ceb2a3b9a6$export$7d2b12578154a735 extends (0, $7Tzdl$reactstatelyv
122
162
  let layoutInfo = this.getLayoutInfo(target.key);
123
163
  let rect;
124
164
  if (this.numColumns === 1) // Flip from vertical to horizontal if only one column is visible.
125
- rect = new (0, $7Tzdl$reactstatelyvirtualizer.Rect)(layoutInfo.rect.x, target.dropPosition === 'before' ? layoutInfo.rect.y - this.minSpace.height / 2 - this.dropIndicatorThickness / 2 : layoutInfo.rect.maxY + this.minSpace.height / 2 - this.dropIndicatorThickness / 2, layoutInfo.rect.width, this.dropIndicatorThickness);
126
- else rect = new (0, $7Tzdl$reactstatelyvirtualizer.Rect)(target.dropPosition === 'before' ? layoutInfo.rect.x - this.horizontalSpacing / 2 - this.dropIndicatorThickness / 2 : layoutInfo.rect.maxX + this.horizontalSpacing / 2 - this.dropIndicatorThickness / 2, layoutInfo.rect.y, this.dropIndicatorThickness, layoutInfo.rect.height);
165
+ rect = new (0, $7Tzdl$reactstatelyvirtualizer.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);
166
+ else rect = new (0, $7Tzdl$reactstatelyvirtualizer.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);
127
167
  return new (0, $7Tzdl$reactstatelyvirtualizer.LayoutInfo)('dropIndicator', target.key + ':' + target.dropPosition, rect);
128
168
  }
129
- constructor(options){
130
- super(), this.itemSize = new (0, $7Tzdl$reactstatelyvirtualizer.Size)(), this.numColumns = 0, this.horizontalSpacing = 0, this.layoutInfos = [];
131
- this.minItemSize = options.minItemSize || new (0, $7Tzdl$reactstatelyvirtualizer.Size)(200, 200);
132
- this.maxItemSize = options.maxItemSize || new (0, $7Tzdl$reactstatelyvirtualizer.Size)(Infinity, Infinity);
133
- this.minSpace = options.minSpace || new (0, $7Tzdl$reactstatelyvirtualizer.Size)(18, 18);
134
- this.maxColumns = options.maxColumns || Infinity;
135
- this.dropIndicatorThickness = options.dropIndicatorThickness || 2;
169
+ constructor(...args){
170
+ super(...args), this.gap = $1f7773ceb2a3b9a6$var$DEFAULT_OPTIONS.minSpace, this.dropIndicatorThickness = 2, this.numColumns = 0, this.contentSize = new (0, $7Tzdl$reactstatelyvirtualizer.Size)(), this.layoutInfos = new Map();
136
171
  }
137
172
  }
138
173
 
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAiCM,MAAM,kDAA+B,CAAA,GAAA,qCAAK;IAoB/C,SAAe;QACb,IAAI,eAAe,IAAI,CAAC,WAAW,CAAE,WAAW,CAAC,KAAK;QAEtD,oDAAoD;QACpD,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A,GAAA,mCAAG,UACxB,aAAqB,QACrB,oBAA4B,QAC5B,cAA4B,EAAE;QAItC,IAAI,CAAC,WAAW,GAAG,QAAQ,WAAW,IAAI,IAAI,CAAA,GAAA,mCAAG,EAAE,KAAK;QACxD,IAAI,CAAC,WAAW,GAAG,QAAQ,WAAW,IAAI,IAAI,CAAA,GAAA,mCAAG,EAAE,UAAU;QAC7D,IAAI,CAAC,QAAQ,GAAG,QAAQ,QAAQ,IAAI,IAAI,CAAA,GAAA,mCAAG,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.main.js.map"}
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAwCD,MAAM,wCAAkB;IACtB,aAAa,IAAI,CAAA,GAAA,mCAAG,EAAE,KAAK;IAC3B,aAAa,IAAI,CAAA,GAAA,mCAAG,EAAE,UAAU;IAChC,qBAAqB;IACrB,UAAU,IAAI,CAAA,GAAA,mCAAG,EAAE,IAAI;IACvB,YAAY;IACZ,wBAAwB;AAC1B;AAQO,MAAM,kDAAuE,CAAA,GAAA,qCAAK;IAOvF,8BAA8B,UAAa,EAAE,UAAa,EAAW;QACnE,OAAO,WAAW,UAAU,KAAK,WAAW,UAAU,IACjD,WAAW,sBAAsB,KAAK,WAAW,sBAAsB,IACvE,WAAW,mBAAmB,KAAK,WAAW,mBAAmB,IAChE,CAAC,AAAC,CAAA,WAAW,WAAW,IAAI,sCAAgB,WAAW,AAAD,EAAG,MAAM,CAAC,WAAW,WAAW,IAAI,sCAAgB,WAAW,KACrH,CAAC,AAAC,CAAA,WAAW,WAAW,IAAI,sCAAgB,WAAW,AAAD,EAAG,MAAM,CAAC,WAAW,WAAW,IAAI,sCAAgB,WAAW,KACrH,CAAC,AAAC,CAAA,WAAW,QAAQ,IAAI,sCAAgB,QAAQ,AAAD,EAAG,MAAM,CAAC,WAAW,QAAQ,IAAI,sCAAgB,QAAQ;IACjH;IAEA,OAAO,mBAA2C,EAAQ;QACxD,IAAI,eACF,cAAc,sCAAgB,WAAW,eACzC,cAAc,sCAAgB,WAAW,uBACzC,sBAAsB,sCAAgB,mBAAmB,YACzD,WAAW,sCAAgB,QAAQ,cACnC,aAAa,sCAAgB,UAAU,0BACvC,yBAAyB,sCAAgB,sBAAsB,EAChE,GAAG,oBAAoB,aAAa,IAAI,CAAC;QAC1C,IAAI,CAAC,sBAAsB,GAAG;Q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;IACT;IAEA,wBAAwB,MAAsB,EAAc;QAC1D,IAAI,aAAa,IAAI,CAAC,aAAa,CAAC,OAAO,GAAG;QAC9C,IAAI;QACJ,IAAI,IAAI,CAAC,UAAU,KAAK,GACtB,kEAAkE;QAClE,OAAO,IAAI,CAAA,GAAA,mCAAG,EACZ,WAAW,IAAI,CAAC,CAAC,EACjB,OAAO,YAAY,KAAK,WACpB,WAAW,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,IAAI,IAAI,CAAC,sBAAsB,GAAG,IACxE,WAAW,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,IAAI,IAAI,CAAC,sBAAsB,GAAG,GAC/E,WAAW,IAAI,CAAC,KAAK,EACrB,IAAI,CAAC,sBAAsB;aAG7B,OAAO,IAAI,CAAA,GAAA,mCAAG,EACZ,OAAO,YAAY,KAAK,WACpB,WAAW,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,IAAI,CAAC,sBAAsB,GAAG,IACvE,WAAW,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,IAAI,CAAC,sBAAsB,GAAG,GAC9E,WAAW,IAAI,CAAC,CAAC,EACjB,IAAI,CAAC,sBAAsB,EAC3B,WAAW,IAAI,CAAC,MAAM;QAI1B,OAAO,IAAI,CAAA,GAAA,yCAAS,EAAE,iBAAiB,OAAO,GAAG,GAAG,MAAM,OAAO,YAAY,EAAE;IACjF;;QA7NK,qBACK,MAAY,sCAAgB,QAAQ,OACpC,yBAAyB,QACzB,aAAqB,QACvB,cAAoB,IAAI,CAAA,GAAA,mCAAG,UAC3B,cAAoC,IAAI;;AAyNlD","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, Point, 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\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 let key = this.virtualizer!.keyAtPoint(new Point(x, y));\n let layoutInfo = key != null ? this.getLayoutInfo(key) : null;\n if (!layoutInfo) {\n return {type: 'root'};\n }\n\n let target: DropTarget = {\n type: 'item',\n key: layoutInfo.key,\n dropPosition: 'on'\n };\n\n let pos = this.numColumns === 1 ? y : x;\n let layoutInfoPos = this.numColumns === 1 ? layoutInfo.rect.y : layoutInfo.rect.x;\n let size = this.numColumns === 1 ? layoutInfo.rect.height : layoutInfo.rect.width;\n if (isValidDropTarget(target)) {\n // If dropping on the item is accepted, try the before/after positions\n // if within 5px of the start or end of the item.\n if (pos < layoutInfoPos + 5) {\n target.dropPosition = 'before';\n } else if (pos > layoutInfoPos + size - 5) {\n target.dropPosition = 'after';\n }\n } else {\n // If dropping on the item isn't accepted, try the target before or after depending on the position.\n let mid = layoutInfoPos + size / 2;\n if (pos <= mid && isValidDropTarget({...target, dropPosition: 'before'})) {\n target.dropPosition = 'before';\n } else if (pos >= mid && isValidDropTarget({...target, dropPosition: 'after'})) {\n target.dropPosition = 'after';\n }\n }\n\n return target;\n }\n\n getDropTargetLayoutInfo(target: ItemDropTarget): LayoutInfo {\n let layoutInfo = this.getLayoutInfo(target.key)!;\n let rect: Rect;\n if (this.numColumns === 1) {\n // Flip from vertical to horizontal if only one column is visible.\n rect = new Rect(\n layoutInfo.rect.x,\n target.dropPosition === 'before' \n ? layoutInfo.rect.y - this.gap.height / 2 - this.dropIndicatorThickness / 2\n : layoutInfo.rect.maxY + this.gap.height / 2 - this.dropIndicatorThickness / 2,\n layoutInfo.rect.width,\n this.dropIndicatorThickness\n );\n } else {\n rect = new Rect(\n target.dropPosition === 'before' \n ? layoutInfo.rect.x - this.gap.width / 2 - this.dropIndicatorThickness / 2 \n : layoutInfo.rect.maxX + this.gap.width / 2 - this.dropIndicatorThickness / 2,\n layoutInfo.rect.y,\n this.dropIndicatorThickness,\n layoutInfo.rect.height\n );\n }\n\n return new LayoutInfo('dropIndicator', target.key + ':' + target.dropPosition, rect);\n }\n}\n"],"names":[],"version":3,"file":"GridLayout.main.js.map"}
@@ -1,4 +1,4 @@
1
- import {Size as $ipgKF$Size, Rect as $ipgKF$Rect, LayoutInfo as $ipgKF$LayoutInfo, Layout as $ipgKF$Layout} from "@react-stately/virtualizer";
1
+ import {Size as $ipgKF$Size, Rect as $ipgKF$Rect, LayoutInfo as $ipgKF$LayoutInfo, Point as $ipgKF$Point, Layout as $ipgKF$Layout} from "@react-stately/virtualizer";
2
2
 
3
3
  /*
4
4
  * Copyright 2024 Adobe. All rights reserved.
@@ -11,80 +11,120 @@ 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
- update() {
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(this.maxItemSize.width, visibleWidth);
20
- let maxItemHeight = Number.isFinite(this.maxItemSize.height) ? this.maxItemSize.height : Math.floor(this.minItemSize.height / this.minItemSize.width * maxItemWidth);
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 / (this.minItemSize.width + this.minSpace.width));
23
- this.numColumns = Math.max(1, Math.min(this.maxColumns, columns));
35
+ let columns = Math.floor(visibleWidth / (minItemSize.width + minSpace.width));
36
+ let numColumns = Math.max(1, Math.min(maxColumns, columns));
24
37
  // Compute the available width (minus the space between items)
25
- let width = visibleWidth - this.minSpace.width * Math.max(0, this.numColumns);
38
+ let width = visibleWidth - minSpace.width * Math.max(0, numColumns);
26
39
  // Compute the item width based on the space available
27
- let itemWidth = Math.floor(width / this.numColumns);
28
- itemWidth = Math.max(this.minItemSize.width, Math.min(maxItemWidth, itemWidth));
40
+ let itemWidth = Math.floor(width / numColumns);
41
+ itemWidth = Math.max(minItemSize.width, Math.min(maxItemWidth, itemWidth));
29
42
  // Compute the item height, which is proportional to the item width
30
- let t = (itemWidth - this.minItemSize.width) / Math.max(1, maxItemWidth - this.minItemSize.width);
31
- let itemHeight = this.minItemSize.height + Math.floor((maxItemHeight - this.minItemSize.height) * t);
32
- itemHeight = Math.max(this.minItemSize.height, Math.min(maxItemHeight, itemHeight));
33
- this.itemSize = new (0, $ipgKF$Size)(itemWidth, itemHeight);
43
+ let t = (itemWidth - minItemSize.width) / Math.max(1, maxItemWidth - minItemSize.width);
44
+ let itemHeight = minItemSize.height + Math.floor((maxItemHeight - minItemSize.height) * t);
45
+ itemHeight = Math.max(minItemSize.height, Math.min(maxItemHeight, itemHeight));
34
46
  // Compute the horizontal spacing and content height
35
- this.horizontalSpacing = Math.floor((visibleWidth - this.numColumns * this.itemSize.width) / (this.numColumns + 1));
36
- this.layoutInfos = [];
37
- for (let node of this.virtualizer.collection)this.layoutInfos.push(this.getLayoutInfoForNode(node));
38
- }
39
- getVisibleLayoutInfos(rect) {
40
- let firstVisibleItem = this.getIndexAtPoint(rect.x, rect.y);
41
- let lastVisibleItem = this.getIndexAtPoint(rect.maxX, rect.maxY);
42
- let result = this.layoutInfos.slice(firstVisibleItem, lastVisibleItem + 1);
43
- let persistedIndices = [];
44
- for (let key of this.virtualizer.persistedKeys){
45
- let item = this.virtualizer.collection.getItem(key);
46
- if ((item === null || item === void 0 ? void 0 : item.index) != null) persistedIndices.push(item.index);
47
+ let horizontalSpacing = Math.floor((visibleWidth - numColumns * itemWidth) / (numColumns + 1));
48
+ this.gap = new (0, $ipgKF$Size)(horizontalSpacing, minSpace.height);
49
+ let rows = Math.ceil(this.virtualizer.collection.size / numColumns);
50
+ let iterator = this.virtualizer.collection[Symbol.iterator]();
51
+ let y = rows > 0 ? minSpace.height : 0;
52
+ let newLayoutInfos = new Map();
53
+ let skeleton = null;
54
+ let skeletonCount = 0;
55
+ for(let row = 0; row < rows; row++){
56
+ let maxHeight = 0;
57
+ let rowLayoutInfos = [];
58
+ for(let col = 0; col < numColumns; col++){
59
+ // Repeat skeleton until the end of the current row.
60
+ let node = skeleton || iterator.next().value;
61
+ if (!node) break;
62
+ if (node.type === 'skeleton') skeleton = node;
63
+ let key = skeleton ? `${skeleton.key}-${skeletonCount++}` : node.key;
64
+ let oldLayoutInfo = this.layoutInfos.get(key);
65
+ let content = node;
66
+ if (skeleton) content = oldLayoutInfo && oldLayoutInfo.content.key === key ? oldLayoutInfo.content : {
67
+ ...skeleton,
68
+ key: key
69
+ };
70
+ let x = horizontalSpacing + col * (itemWidth + horizontalSpacing);
71
+ let height = itemHeight;
72
+ let estimatedSize = !preserveAspectRatio;
73
+ if (oldLayoutInfo && estimatedSize) {
74
+ height = oldLayoutInfo.rect.height;
75
+ estimatedSize = invalidationContext.layoutOptionsChanged || invalidationContext.sizeChanged || oldLayoutInfo.estimatedSize || oldLayoutInfo.content !== content;
76
+ }
77
+ let rect = new (0, $ipgKF$Rect)(x, y, itemWidth, height);
78
+ let layoutInfo = new (0, $ipgKF$LayoutInfo)(node.type, key, rect);
79
+ layoutInfo.estimatedSize = estimatedSize;
80
+ layoutInfo.allowOverflow = true;
81
+ layoutInfo.content = content;
82
+ newLayoutInfos.set(key, layoutInfo);
83
+ rowLayoutInfos.push(layoutInfo);
84
+ maxHeight = Math.max(maxHeight, layoutInfo.rect.height);
85
+ }
86
+ for (let layoutInfo of rowLayoutInfos)layoutInfo.rect.height = maxHeight;
87
+ y += maxHeight + minSpace.height;
88
+ // Keep adding skeleton rows until we fill the viewport
89
+ if (skeleton && row === rows - 1 && y < this.virtualizer.visibleRect.height) rows++;
47
90
  }
48
- persistedIndices.sort((a, b)=>a - b);
49
- let persistedBefore = [];
50
- for (let index of persistedIndices){
51
- if (index < firstVisibleItem) persistedBefore.push(this.layoutInfos[index]);
52
- else if (index > lastVisibleItem) result.push(this.layoutInfos[index]);
53
- }
54
- result.unshift(...persistedBefore);
55
- return result;
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)));
91
+ this.layoutInfos = newLayoutInfos;
92
+ this.contentSize = new (0, $ipgKF$Size)(this.virtualizer.visibleRect.width, y);
61
93
  }
62
94
  getLayoutInfo(key) {
63
- let node = this.virtualizer.collection.getItem(key);
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);
95
+ return this.layoutInfos.get(key);
74
96
  }
75
97
  getContentSize() {
76
- let numRows = Math.ceil(this.virtualizer.collection.size / this.numColumns);
77
- let contentHeight = this.minSpace.height + numRows * (this.itemSize.height + this.minSpace.height);
78
- return new (0, $ipgKF$Size)(this.virtualizer.visibleRect.width, contentHeight);
98
+ return this.contentSize;
99
+ }
100
+ getVisibleLayoutInfos(rect) {
101
+ let layoutInfos = [];
102
+ for (let layoutInfo of this.layoutInfos.values())if (layoutInfo.rect.intersects(rect) || this.virtualizer.isPersistedKey(layoutInfo.key)) layoutInfos.push(layoutInfo);
103
+ return layoutInfos;
104
+ }
105
+ updateItemSize(key, size) {
106
+ let layoutInfo = this.layoutInfos.get(key);
107
+ if (!size || !layoutInfo) return false;
108
+ if (size.height !== layoutInfo.rect.height) {
109
+ let newLayoutInfo = layoutInfo.copy();
110
+ newLayoutInfo.rect.height = size.height;
111
+ newLayoutInfo.estimatedSize = false;
112
+ this.layoutInfos.set(key, newLayoutInfo);
113
+ return true;
114
+ }
115
+ return false;
79
116
  }
80
117
  getDropTargetFromPoint(x, y, isValidDropTarget) {
81
- if (this.layoutInfos.length === 0) return {
118
+ if (this.layoutInfos.size === 0) return {
82
119
  type: 'root'
83
120
  };
84
121
  x += this.virtualizer.visibleRect.x;
85
122
  y += this.virtualizer.visibleRect.y;
86
- let index = this.getIndexAtPoint(x, y);
87
- let layoutInfo = this.layoutInfos[index];
123
+ let key = this.virtualizer.keyAtPoint(new (0, $ipgKF$Point)(x, y));
124
+ let layoutInfo = key != null ? this.getLayoutInfo(key) : null;
125
+ if (!layoutInfo) return {
126
+ type: 'root'
127
+ };
88
128
  let target = {
89
129
  type: 'item',
90
130
  key: layoutInfo.key,
@@ -116,17 +156,12 @@ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
116
156
  let layoutInfo = this.getLayoutInfo(target.key);
117
157
  let rect;
118
158
  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.minSpace.height / 2 - this.dropIndicatorThickness / 2 : layoutInfo.rect.maxY + this.minSpace.height / 2 - this.dropIndicatorThickness / 2, layoutInfo.rect.width, this.dropIndicatorThickness);
120
- else rect = new (0, $ipgKF$Rect)(target.dropPosition === 'before' ? layoutInfo.rect.x - this.horizontalSpacing / 2 - this.dropIndicatorThickness / 2 : layoutInfo.rect.maxX + this.horizontalSpacing / 2 - this.dropIndicatorThickness / 2, layoutInfo.rect.y, this.dropIndicatorThickness, layoutInfo.rect.height);
159
+ 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);
160
+ 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
161
  return new (0, $ipgKF$LayoutInfo)('dropIndicator', target.key + ':' + target.dropPosition, rect);
122
162
  }
123
- constructor(options){
124
- super(), this.itemSize = new (0, $ipgKF$Size)(), this.numColumns = 0, this.horizontalSpacing = 0, this.layoutInfos = [];
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;
163
+ constructor(...args){
164
+ 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
165
  }
131
166
  }
132
167