@react-stately/layout 3.13.10-nightly.4685 → 3.13.10-nightly.4694

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,137 @@
1
+ var $7Tzdl$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, "GridLayout", () => $1f7773ceb2a3b9a6$export$7d2b12578154a735);
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 $1f7773ceb2a3b9a6$export$7d2b12578154a735 extends (0, $7Tzdl$reactstatelyvirtualizer.Layout) {
21
+ validate() {
22
+ let visibleWidth = this.virtualizer.visibleRect.width;
23
+ // The max item width is always the entire viewport.
24
+ // 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);
27
+ // 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));
30
+ // Compute the available width (minus the space between items)
31
+ let width = visibleWidth - this.minSpace.width * Math.max(0, this.numColumns);
32
+ // 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));
35
+ // Compute the item height, which is proportional to the item width
36
+ let t = (itemWidth - this.minItemSize.width) / (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);
40
+ // 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
+ ...this.virtualizer.persistedKeys
51
+ ].map((key)=>this.virtualizer.collection.getItem(key).index).sort((a, b)=>a - b);
52
+ let persistedBefore = [];
53
+ for (let index of persistedIndices){
54
+ if (index < firstVisibleItem) persistedBefore.push(this.layoutInfos[index]);
55
+ else if (index > lastVisibleItem) result.push(this.layoutInfos[index]);
56
+ }
57
+ result.unshift(...persistedBefore);
58
+ return result;
59
+ }
60
+ getIndexAtPoint(x, y) {
61
+ let itemHeight = this.itemSize.height + this.minSpace.height;
62
+ let itemWidth = this.itemSize.width + this.horizontalSpacing;
63
+ return Math.max(0, Math.min(this.virtualizer.collection.size - 1, Math.floor(y / itemHeight) * this.numColumns + Math.floor((x - this.horizontalSpacing) / itemWidth)));
64
+ }
65
+ getLayoutInfo(key) {
66
+ let node = this.virtualizer.collection.getItem(key);
67
+ return node ? this.layoutInfos[node.index] : null;
68
+ }
69
+ getLayoutInfoForNode(node) {
70
+ let idx = node.index;
71
+ let row = Math.floor(idx / this.numColumns);
72
+ let column = idx % this.numColumns;
73
+ let x = this.horizontalSpacing + column * (this.itemSize.width + this.horizontalSpacing);
74
+ let y = this.minSpace.height + row * (this.itemSize.height + this.minSpace.height);
75
+ let rect = new (0, $7Tzdl$reactstatelyvirtualizer.Rect)(x, y, this.itemSize.width, this.itemSize.height);
76
+ return new (0, $7Tzdl$reactstatelyvirtualizer.LayoutInfo)(node.type, node.key, rect);
77
+ }
78
+ getContentSize() {
79
+ let numRows = Math.ceil(this.virtualizer.collection.size / this.numColumns);
80
+ let contentHeight = this.minSpace.height + numRows * (this.itemSize.height + this.minSpace.height);
81
+ return new (0, $7Tzdl$reactstatelyvirtualizer.Size)(this.virtualizer.visibleRect.width, contentHeight);
82
+ }
83
+ getDropTargetFromPoint(x, y, isValidDropTarget) {
84
+ if (this.layoutInfos.length === 0) return {
85
+ type: 'root'
86
+ };
87
+ x += this.virtualizer.visibleRect.x;
88
+ y += this.virtualizer.visibleRect.y;
89
+ let index = this.getIndexAtPoint(x, y);
90
+ let layoutInfo = this.layoutInfos[index];
91
+ let target = {
92
+ type: 'item',
93
+ key: layoutInfo.key,
94
+ dropPosition: 'on'
95
+ };
96
+ let pos = this.numColumns === 1 ? y : x;
97
+ let layoutInfoPos = this.numColumns === 1 ? layoutInfo.rect.y : layoutInfo.rect.x;
98
+ let size = this.numColumns === 1 ? layoutInfo.rect.height : layoutInfo.rect.width;
99
+ if (isValidDropTarget(target)) {
100
+ // If dropping on the item is accepted, try the before/after positions
101
+ // if within 5px of the start or end of the item.
102
+ if (pos < layoutInfoPos + 5) target.dropPosition = 'before';
103
+ else if (pos > layoutInfoPos + size - 5) target.dropPosition = 'after';
104
+ } else {
105
+ // If dropping on the item isn't accepted, try the target before or after depending on the position.
106
+ let mid = layoutInfoPos + size / 2;
107
+ if (pos <= mid && isValidDropTarget({
108
+ ...target,
109
+ dropPosition: 'before'
110
+ })) target.dropPosition = 'before';
111
+ else if (pos >= mid && isValidDropTarget({
112
+ ...target,
113
+ dropPosition: 'after'
114
+ })) target.dropPosition = 'after';
115
+ }
116
+ return target;
117
+ }
118
+ getDropTargetLayoutInfo(target) {
119
+ let layoutInfo = this.getLayoutInfo(target.key);
120
+ let rect;
121
+ if (this.numColumns === 1) // Flip from vertical to horizontal if only one column is visible.
122
+ 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);
123
+ 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);
124
+ return new (0, $7Tzdl$reactstatelyvirtualizer.LayoutInfo)('dropIndicator', target.key + ':' + target.dropPosition, rect);
125
+ }
126
+ constructor(options){
127
+ super();
128
+ this.minItemSize = options.minItemSize || new (0, $7Tzdl$reactstatelyvirtualizer.Size)(200, 200);
129
+ this.maxItemSize = options.maxItemSize || new (0, $7Tzdl$reactstatelyvirtualizer.Size)(Infinity, Infinity);
130
+ this.minSpace = options.minSpace || new (0, $7Tzdl$reactstatelyvirtualizer.Size)(18, 18);
131
+ this.maxColumns = options.maxColumns || Infinity;
132
+ this.dropIndicatorThickness = options.dropIndicatorThickness || 2;
133
+ }
134
+ }
135
+
136
+
137
+ //# sourceMappingURL=GridLayout.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAiCM,MAAM,kDAA+B,CAAA,GAAA,qCAAK;IAoB/C,WAAiB;QACf,IAAI,eA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,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;AAyJF","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;\n protected numColumns: number;\n protected horizontalSpacing: number;\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 validate(): 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) / (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 = [...this.virtualizer.persistedKeys].map(key => this.virtualizer.collection.getItem(key).index).sort((a, b) => a - b);\n let persistedBefore = [];\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"}
@@ -0,0 +1,132 @@
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
+ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
15
+ validate() {
16
+ let visibleWidth = this.virtualizer.visibleRect.width;
17
+ // The max item width is always the entire viewport.
18
+ // 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);
21
+ // 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));
24
+ // Compute the available width (minus the space between items)
25
+ let width = visibleWidth - this.minSpace.width * Math.max(0, this.numColumns);
26
+ // 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));
29
+ // Compute the item height, which is proportional to the item width
30
+ let t = (itemWidth - this.minItemSize.width) / (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);
34
+ // 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
+ ...this.virtualizer.persistedKeys
45
+ ].map((key)=>this.virtualizer.collection.getItem(key).index).sort((a, b)=>a - b);
46
+ let persistedBefore = [];
47
+ for (let index of persistedIndices){
48
+ if (index < firstVisibleItem) persistedBefore.push(this.layoutInfos[index]);
49
+ else if (index > lastVisibleItem) result.push(this.layoutInfos[index]);
50
+ }
51
+ result.unshift(...persistedBefore);
52
+ return result;
53
+ }
54
+ getIndexAtPoint(x, y) {
55
+ let itemHeight = this.itemSize.height + this.minSpace.height;
56
+ let itemWidth = this.itemSize.width + this.horizontalSpacing;
57
+ return Math.max(0, Math.min(this.virtualizer.collection.size - 1, Math.floor(y / itemHeight) * this.numColumns + Math.floor((x - this.horizontalSpacing) / itemWidth)));
58
+ }
59
+ getLayoutInfo(key) {
60
+ let node = this.virtualizer.collection.getItem(key);
61
+ return node ? this.layoutInfos[node.index] : null;
62
+ }
63
+ getLayoutInfoForNode(node) {
64
+ let idx = node.index;
65
+ let row = Math.floor(idx / this.numColumns);
66
+ let column = idx % this.numColumns;
67
+ let x = this.horizontalSpacing + column * (this.itemSize.width + this.horizontalSpacing);
68
+ let y = this.minSpace.height + row * (this.itemSize.height + this.minSpace.height);
69
+ let rect = new (0, $ipgKF$Rect)(x, y, this.itemSize.width, this.itemSize.height);
70
+ return new (0, $ipgKF$LayoutInfo)(node.type, node.key, rect);
71
+ }
72
+ getContentSize() {
73
+ let numRows = Math.ceil(this.virtualizer.collection.size / this.numColumns);
74
+ let contentHeight = this.minSpace.height + numRows * (this.itemSize.height + this.minSpace.height);
75
+ return new (0, $ipgKF$Size)(this.virtualizer.visibleRect.width, contentHeight);
76
+ }
77
+ getDropTargetFromPoint(x, y, isValidDropTarget) {
78
+ if (this.layoutInfos.length === 0) return {
79
+ type: 'root'
80
+ };
81
+ x += this.virtualizer.visibleRect.x;
82
+ y += this.virtualizer.visibleRect.y;
83
+ let index = this.getIndexAtPoint(x, y);
84
+ let layoutInfo = this.layoutInfos[index];
85
+ let target = {
86
+ type: 'item',
87
+ key: layoutInfo.key,
88
+ dropPosition: 'on'
89
+ };
90
+ let pos = this.numColumns === 1 ? y : x;
91
+ let layoutInfoPos = this.numColumns === 1 ? layoutInfo.rect.y : layoutInfo.rect.x;
92
+ let size = this.numColumns === 1 ? layoutInfo.rect.height : layoutInfo.rect.width;
93
+ if (isValidDropTarget(target)) {
94
+ // If dropping on the item is accepted, try the before/after positions
95
+ // if within 5px of the start or end of the item.
96
+ if (pos < layoutInfoPos + 5) target.dropPosition = 'before';
97
+ else if (pos > layoutInfoPos + size - 5) target.dropPosition = 'after';
98
+ } else {
99
+ // If dropping on the item isn't accepted, try the target before or after depending on the position.
100
+ let mid = layoutInfoPos + size / 2;
101
+ if (pos <= mid && isValidDropTarget({
102
+ ...target,
103
+ dropPosition: 'before'
104
+ })) target.dropPosition = 'before';
105
+ else if (pos >= mid && isValidDropTarget({
106
+ ...target,
107
+ dropPosition: 'after'
108
+ })) target.dropPosition = 'after';
109
+ }
110
+ return target;
111
+ }
112
+ getDropTargetLayoutInfo(target) {
113
+ let layoutInfo = this.getLayoutInfo(target.key);
114
+ let rect;
115
+ if (this.numColumns === 1) // Flip from vertical to horizontal if only one column is visible.
116
+ 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);
117
+ 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);
118
+ return new (0, $ipgKF$LayoutInfo)('dropIndicator', target.key + ':' + target.dropPosition, rect);
119
+ }
120
+ constructor(options){
121
+ super();
122
+ this.minItemSize = options.minItemSize || new (0, $ipgKF$Size)(200, 200);
123
+ this.maxItemSize = options.maxItemSize || new (0, $ipgKF$Size)(Infinity, Infinity);
124
+ this.minSpace = options.minSpace || new (0, $ipgKF$Size)(18, 18);
125
+ this.maxColumns = options.maxColumns || Infinity;
126
+ this.dropIndicatorThickness = options.dropIndicatorThickness || 2;
127
+ }
128
+ }
129
+
130
+
131
+ export {$a58592d295a170a4$export$7d2b12578154a735 as GridLayout};
132
+ //# sourceMappingURL=GridLayout.module.js.map
@@ -0,0 +1,132 @@
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
+ class $a58592d295a170a4$export$7d2b12578154a735 extends (0, $ipgKF$Layout) {
15
+ validate() {
16
+ let visibleWidth = this.virtualizer.visibleRect.width;
17
+ // The max item width is always the entire viewport.
18
+ // 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);
21
+ // 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));
24
+ // Compute the available width (minus the space between items)
25
+ let width = visibleWidth - this.minSpace.width * Math.max(0, this.numColumns);
26
+ // 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));
29
+ // Compute the item height, which is proportional to the item width
30
+ let t = (itemWidth - this.minItemSize.width) / (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);
34
+ // 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
+ ...this.virtualizer.persistedKeys
45
+ ].map((key)=>this.virtualizer.collection.getItem(key).index).sort((a, b)=>a - b);
46
+ let persistedBefore = [];
47
+ for (let index of persistedIndices){
48
+ if (index < firstVisibleItem) persistedBefore.push(this.layoutInfos[index]);
49
+ else if (index > lastVisibleItem) result.push(this.layoutInfos[index]);
50
+ }
51
+ result.unshift(...persistedBefore);
52
+ return result;
53
+ }
54
+ getIndexAtPoint(x, y) {
55
+ let itemHeight = this.itemSize.height + this.minSpace.height;
56
+ let itemWidth = this.itemSize.width + this.horizontalSpacing;
57
+ return Math.max(0, Math.min(this.virtualizer.collection.size - 1, Math.floor(y / itemHeight) * this.numColumns + Math.floor((x - this.horizontalSpacing) / itemWidth)));
58
+ }
59
+ getLayoutInfo(key) {
60
+ let node = this.virtualizer.collection.getItem(key);
61
+ return node ? this.layoutInfos[node.index] : null;
62
+ }
63
+ getLayoutInfoForNode(node) {
64
+ let idx = node.index;
65
+ let row = Math.floor(idx / this.numColumns);
66
+ let column = idx % this.numColumns;
67
+ let x = this.horizontalSpacing + column * (this.itemSize.width + this.horizontalSpacing);
68
+ let y = this.minSpace.height + row * (this.itemSize.height + this.minSpace.height);
69
+ let rect = new (0, $ipgKF$Rect)(x, y, this.itemSize.width, this.itemSize.height);
70
+ return new (0, $ipgKF$LayoutInfo)(node.type, node.key, rect);
71
+ }
72
+ getContentSize() {
73
+ let numRows = Math.ceil(this.virtualizer.collection.size / this.numColumns);
74
+ let contentHeight = this.minSpace.height + numRows * (this.itemSize.height + this.minSpace.height);
75
+ return new (0, $ipgKF$Size)(this.virtualizer.visibleRect.width, contentHeight);
76
+ }
77
+ getDropTargetFromPoint(x, y, isValidDropTarget) {
78
+ if (this.layoutInfos.length === 0) return {
79
+ type: 'root'
80
+ };
81
+ x += this.virtualizer.visibleRect.x;
82
+ y += this.virtualizer.visibleRect.y;
83
+ let index = this.getIndexAtPoint(x, y);
84
+ let layoutInfo = this.layoutInfos[index];
85
+ let target = {
86
+ type: 'item',
87
+ key: layoutInfo.key,
88
+ dropPosition: 'on'
89
+ };
90
+ let pos = this.numColumns === 1 ? y : x;
91
+ let layoutInfoPos = this.numColumns === 1 ? layoutInfo.rect.y : layoutInfo.rect.x;
92
+ let size = this.numColumns === 1 ? layoutInfo.rect.height : layoutInfo.rect.width;
93
+ if (isValidDropTarget(target)) {
94
+ // If dropping on the item is accepted, try the before/after positions
95
+ // if within 5px of the start or end of the item.
96
+ if (pos < layoutInfoPos + 5) target.dropPosition = 'before';
97
+ else if (pos > layoutInfoPos + size - 5) target.dropPosition = 'after';
98
+ } else {
99
+ // If dropping on the item isn't accepted, try the target before or after depending on the position.
100
+ let mid = layoutInfoPos + size / 2;
101
+ if (pos <= mid && isValidDropTarget({
102
+ ...target,
103
+ dropPosition: 'before'
104
+ })) target.dropPosition = 'before';
105
+ else if (pos >= mid && isValidDropTarget({
106
+ ...target,
107
+ dropPosition: 'after'
108
+ })) target.dropPosition = 'after';
109
+ }
110
+ return target;
111
+ }
112
+ getDropTargetLayoutInfo(target) {
113
+ let layoutInfo = this.getLayoutInfo(target.key);
114
+ let rect;
115
+ if (this.numColumns === 1) // Flip from vertical to horizontal if only one column is visible.
116
+ 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);
117
+ 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);
118
+ return new (0, $ipgKF$LayoutInfo)('dropIndicator', target.key + ':' + target.dropPosition, rect);
119
+ }
120
+ constructor(options){
121
+ super();
122
+ this.minItemSize = options.minItemSize || new (0, $ipgKF$Size)(200, 200);
123
+ this.maxItemSize = options.maxItemSize || new (0, $ipgKF$Size)(Infinity, Infinity);
124
+ this.minSpace = options.minSpace || new (0, $ipgKF$Size)(18, 18);
125
+ this.maxColumns = options.maxColumns || Infinity;
126
+ this.dropIndicatorThickness = options.dropIndicatorThickness || 2;
127
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AM;QAI1B,OAAO,IAAI,CAAA,GAAA,iBAAS,EAAE,iBAAiB,OAAO,GAAG,GAAG,MAAM,OAAO,YAAY,EAAE;IACjF;IA/JA,YAAY,OAA0B,CAAE;QACtC,KAAK;QACL,IAAI,CAAC,WAAW,GAAG,QAAQ,WAAW,IAAI,IAAI,CAAA,GAAA,WAAG,EAAE,KAAK;QACxD,IAAI,CAAC,WAAW,GAAG,QAAQ,WAAW,IAAI,IAAI,CAAA,GAAA,WAAG,EAAE,UAAU;QAC7D,IAAI,CAAC,QAAQ,GAAG,QAAQ,QAAQ,IAAI,IAAI,CAAA,GAAA,WAAG,EAAE,IAAI;QACjD,IAAI,CAAC,UAAU,GAAG,QAAQ,UAAU,IAAI;QACxC,IAAI,CAAC,sBAAsB,GAAG,QAAQ,sBAAsB,IAAI;IAClE;AAyJF","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;\n protected numColumns: number;\n protected horizontalSpacing: number;\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 validate(): 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) / (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 = [...this.virtualizer.persistedKeys].map(key => this.virtualizer.collection.getItem(key).index).sort((a, b) => a - b);\n let persistedBefore = [];\n for (let index of persistedIndices) {\n if (index < firstVisibleItem) {\n persistedBefore.push(this.layoutInfos[index]);\n } else if (index > lastVisibleItem) {\n result.push(this.layoutInfos[index]);\n }\n }\n result.unshift(...persistedBefore);\n return result;\n }\n\n protected getIndexAtPoint(x: number, y: number) {\n let itemHeight = this.itemSize.height + this.minSpace.height;\n let itemWidth = this.itemSize.width + this.horizontalSpacing;\n return Math.max(0,\n Math.min(\n this.virtualizer.collection.size - 1,\n Math.floor(y / itemHeight) * this.numColumns + Math.floor((x - this.horizontalSpacing) / itemWidth)\n )\n );\n }\n\n getLayoutInfo(key: Key): LayoutInfo | null {\n let node = this.virtualizer.collection.getItem(key);\n return node ? this.layoutInfos[node.index] : null;\n }\n\n protected getLayoutInfoForNode(node: Node<T>): LayoutInfo {\n let idx = node.index;\n let row = Math.floor(idx / this.numColumns);\n let column = idx % this.numColumns;\n let x = this.horizontalSpacing + column * (this.itemSize.width + this.horizontalSpacing);\n let y = this.minSpace.height + row * (this.itemSize.height + this.minSpace.height);\n let rect = new Rect(x, y, this.itemSize.width, this.itemSize.height);\n return new LayoutInfo(node.type, node.key, rect);\n }\n\n getContentSize(): Size {\n let numRows = Math.ceil(this.virtualizer.collection.size / this.numColumns);\n let contentHeight = this.minSpace.height + numRows * (this.itemSize.height + this.minSpace.height); \n return new Size(this.virtualizer.visibleRect.width, contentHeight);\n }\n\n getDropTargetFromPoint(x: number, y: number, isValidDropTarget: (target: DropTarget) => boolean): DropTarget {\n if (this.layoutInfos.length === 0) {\n return {type: 'root'};\n }\n\n x += this.virtualizer.visibleRect.x;\n y += this.virtualizer.visibleRect.y;\n let index = this.getIndexAtPoint(x, y);\n\n let layoutInfo = this.layoutInfos[index];\n let target: DropTarget = {\n type: 'item',\n key: layoutInfo.key,\n dropPosition: 'on'\n };\n\n let pos = this.numColumns === 1 ? y : x;\n let layoutInfoPos = this.numColumns === 1 ? layoutInfo.rect.y : layoutInfo.rect.x;\n let size = this.numColumns === 1 ? layoutInfo.rect.height : layoutInfo.rect.width;\n if (isValidDropTarget(target)) {\n // If dropping on the item is accepted, try the before/after positions\n // if within 5px of the start or end of the item.\n if (pos < layoutInfoPos + 5) {\n target.dropPosition = 'before';\n } else if (pos > layoutInfoPos + size - 5) {\n target.dropPosition = 'after';\n }\n } else {\n // If dropping on the item isn't accepted, try the target before or after depending on the position.\n let mid = layoutInfoPos + size / 2;\n if (pos <= mid && isValidDropTarget({...target, dropPosition: 'before'})) {\n target.dropPosition = 'before';\n } else if (pos >= mid && isValidDropTarget({...target, dropPosition: 'after'})) {\n target.dropPosition = 'after';\n }\n }\n\n return target;\n }\n\n getDropTargetLayoutInfo(target: ItemDropTarget): LayoutInfo {\n let layoutInfo = this.getLayoutInfo(target.key);\n let rect: Rect;\n if (this.numColumns === 1) {\n // Flip from vertical to horizontal if only one column is visible.\n rect = new Rect(\n layoutInfo.rect.x,\n target.dropPosition === 'before' \n ? layoutInfo.rect.y - this.minSpace.height / 2 - this.dropIndicatorThickness / 2\n : layoutInfo.rect.maxY + this.minSpace.height / 2 - this.dropIndicatorThickness / 2,\n layoutInfo.rect.width,\n this.dropIndicatorThickness\n );\n } else {\n rect = new Rect(\n target.dropPosition === 'before' \n ? layoutInfo.rect.x - this.horizontalSpacing / 2 - this.dropIndicatorThickness / 2 \n : layoutInfo.rect.maxX + this.horizontalSpacing / 2 - this.dropIndicatorThickness / 2,\n layoutInfo.rect.y,\n this.dropIndicatorThickness,\n layoutInfo.rect.height\n );\n }\n\n return new LayoutInfo('dropIndicator', target.key + ':' + target.dropPosition, rect);\n }\n}\n"],"names":[],"version":3,"file":"GridLayout.module.js.map"}