@react-stately/layout 3.13.10-nightly.4691 → 3.13.10-nightly.4695
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/GridLayout.main.js +137 -0
- package/dist/GridLayout.main.js.map +1 -0
- package/dist/GridLayout.mjs +132 -0
- package/dist/GridLayout.module.js +132 -0
- package/dist/GridLayout.module.js.map +1 -0
- package/dist/ListLayout.main.js +9 -0
- package/dist/ListLayout.main.js.map +1 -1
- package/dist/ListLayout.mjs +9 -0
- package/dist/ListLayout.module.js +9 -0
- package/dist/ListLayout.module.js.map +1 -1
- package/dist/TableLayout.main.js +5 -3
- package/dist/TableLayout.main.js.map +1 -1
- package/dist/TableLayout.mjs +5 -3
- package/dist/TableLayout.module.js +5 -3
- package/dist/TableLayout.module.js.map +1 -1
- package/dist/import.mjs +3 -1
- package/dist/main.js +3 -0
- package/dist/main.js.map +1 -1
- package/dist/module.js +3 -1
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +54 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/GridLayout.ts +215 -0
- package/src/ListLayout.ts +20 -2
- package/src/TableLayout.ts +7 -4
- package/src/index.ts +2 -0
package/dist/main.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
var $1f7773ceb2a3b9a6$exports = require("./GridLayout.main.js");
|
|
1
2
|
var $fe69e47e38ed0ac4$exports = require("./ListLayout.main.js");
|
|
2
3
|
var $67c493497dcda343$exports = require("./TableLayout.main.js");
|
|
3
4
|
|
|
@@ -6,6 +7,7 @@ function $parcel$export(e, n, v, s) {
|
|
|
6
7
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
8
|
}
|
|
8
9
|
|
|
10
|
+
$parcel$export(module.exports, "GridLayout", () => $1f7773ceb2a3b9a6$exports.GridLayout);
|
|
9
11
|
$parcel$export(module.exports, "ListLayout", () => $fe69e47e38ed0ac4$exports.ListLayout);
|
|
10
12
|
$parcel$export(module.exports, "TableLayout", () => $67c493497dcda343$exports.TableLayout);
|
|
11
13
|
/*
|
|
@@ -22,4 +24,5 @@ $parcel$export(module.exports, "TableLayout", () => $67c493497dcda343$exports.Ta
|
|
|
22
24
|
|
|
23
25
|
|
|
24
26
|
|
|
27
|
+
|
|
25
28
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/layout/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 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 */\nexport type {GridLayoutOptions} from './GridLayout';\nexport type {ListLayoutOptions, LayoutNode} from './ListLayout';\nexport type {TableLayoutProps} from './TableLayout';\nexport {GridLayout} from './GridLayout';\nexport {ListLayout} from './ListLayout';\nexport {TableLayout} from './TableLayout';\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {GridLayout as $a58592d295a170a4$export$7d2b12578154a735} from "./GridLayout.module.js";
|
|
1
2
|
import {ListLayout as $61ef60fc9b1041f4$export$cacbb3924155d68e} from "./ListLayout.module.js";
|
|
2
3
|
import {TableLayout as $a152112e902709bf$export$62444c3c724b1b20} from "./TableLayout.module.js";
|
|
3
4
|
|
|
@@ -15,5 +16,6 @@ import {TableLayout as $a152112e902709bf$export$62444c3c724b1b20} from "./TableL
|
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
|
|
20
|
+
export {$a58592d295a170a4$export$7d2b12578154a735 as GridLayout, $61ef60fc9b1041f4$export$cacbb3924155d68e as ListLayout, $a152112e902709bf$export$62444c3c724b1b20 as TableLayout};
|
|
19
21
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/layout/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 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 */\nexport type {GridLayoutOptions} from './GridLayout';\nexport type {ListLayoutOptions, LayoutNode} from './ListLayout';\nexport type {TableLayoutProps} from './TableLayout';\nexport {GridLayout} from './GridLayout';\nexport {ListLayout} from './ListLayout';\nexport {TableLayout} from './TableLayout';\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,54 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { DropTarget, DropTargetDelegate, ItemDropTarget, Key, Node, Collection } from "@react-types/shared";
|
|
2
|
+
import { Layout, LayoutInfo, Rect, Size, InvalidationContext } from "@react-stately/virtualizer";
|
|
3
3
|
import { GridNode } from "@react-types/grid";
|
|
4
4
|
import { TableCollection } from "@react-types/table";
|
|
5
|
+
export interface GridLayoutOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The minimum item size.
|
|
8
|
+
* @default 200 x 200
|
|
9
|
+
*/
|
|
10
|
+
minItemSize?: Size;
|
|
11
|
+
/**
|
|
12
|
+
* The maximum item size.
|
|
13
|
+
* @default Infinity
|
|
14
|
+
*/
|
|
15
|
+
maxItemSize?: Size;
|
|
16
|
+
/**
|
|
17
|
+
* The minimum space required between items.
|
|
18
|
+
* @default 18 x 18
|
|
19
|
+
*/
|
|
20
|
+
minSpace?: Size;
|
|
21
|
+
/**
|
|
22
|
+
* The maximum number of columns.
|
|
23
|
+
* @default Infinity
|
|
24
|
+
*/
|
|
25
|
+
maxColumns?: number;
|
|
26
|
+
/**
|
|
27
|
+
* The thickness of the drop indicator.
|
|
28
|
+
* @default 2
|
|
29
|
+
*/
|
|
30
|
+
dropIndicatorThickness?: number;
|
|
31
|
+
}
|
|
32
|
+
export class GridLayout<T, O = any> extends Layout<Node<T>, O> implements DropTargetDelegate {
|
|
33
|
+
protected minItemSize: Size;
|
|
34
|
+
protected maxItemSize: Size;
|
|
35
|
+
protected minSpace: Size;
|
|
36
|
+
protected maxColumns: number;
|
|
37
|
+
protected dropIndicatorThickness: number;
|
|
38
|
+
protected itemSize: Size;
|
|
39
|
+
protected numColumns: number;
|
|
40
|
+
protected horizontalSpacing: number;
|
|
41
|
+
protected layoutInfos: LayoutInfo[];
|
|
42
|
+
constructor(options: GridLayoutOptions);
|
|
43
|
+
validate(): void;
|
|
44
|
+
getVisibleLayoutInfos(rect: Rect): LayoutInfo[];
|
|
45
|
+
protected getIndexAtPoint(x: number, y: number): number;
|
|
46
|
+
getLayoutInfo(key: Key): LayoutInfo | null;
|
|
47
|
+
protected getLayoutInfoForNode(node: Node<T>): LayoutInfo;
|
|
48
|
+
getContentSize(): Size;
|
|
49
|
+
getDropTargetFromPoint(x: number, y: number, isValidDropTarget: (target: DropTarget) => boolean): DropTarget;
|
|
50
|
+
getDropTargetLayoutInfo(target: ItemDropTarget): LayoutInfo;
|
|
51
|
+
}
|
|
5
52
|
export interface ListLayoutOptions {
|
|
6
53
|
/** The fixed height of a row in px. */
|
|
7
54
|
rowHeight?: number;
|
|
@@ -11,6 +58,8 @@ export interface ListLayoutOptions {
|
|
|
11
58
|
headingHeight?: number;
|
|
12
59
|
/** The estimated height of a section header, when the height is variable. */
|
|
13
60
|
estimatedHeadingHeight?: number;
|
|
61
|
+
/** The thickness of the drop indicator. */
|
|
62
|
+
dropIndicatorThickness?: number;
|
|
14
63
|
}
|
|
15
64
|
export interface LayoutNode {
|
|
16
65
|
node?: Node<unknown>;
|
|
@@ -32,6 +81,7 @@ export class ListLayout<T, O = any> extends Layout<Node<T>, O> implements DropTa
|
|
|
32
81
|
protected estimatedRowHeight: number;
|
|
33
82
|
protected headingHeight: number;
|
|
34
83
|
protected estimatedHeadingHeight: number;
|
|
84
|
+
protected dropIndicatorThickness: number;
|
|
35
85
|
protected layoutNodes: Map<Key, LayoutNode>;
|
|
36
86
|
protected contentSize: Size;
|
|
37
87
|
protected collection: Collection<Node<T>>;
|
|
@@ -61,6 +111,7 @@ export class ListLayout<T, O = any> extends Layout<Node<T>, O> implements DropTa
|
|
|
61
111
|
updateItemSize(key: Key, size: Size): boolean;
|
|
62
112
|
getContentSize(): Size;
|
|
63
113
|
getDropTargetFromPoint(x: number, y: number, isValidDropTarget: (target: DropTarget) => boolean): DropTarget;
|
|
114
|
+
getDropTargetLayoutInfo(target: ItemDropTarget): LayoutInfo;
|
|
64
115
|
}
|
|
65
116
|
export interface TableLayoutProps {
|
|
66
117
|
columnWidths?: Map<Key, number>;
|
|
@@ -81,6 +132,7 @@ export class TableLayout<T, O extends TableLayoutProps = TableLayoutProps> exten
|
|
|
81
132
|
protected buildCell(node: GridNode<T>, x: number, y: number): LayoutNode;
|
|
82
133
|
getVisibleLayoutInfos(rect: Rect): LayoutInfo[];
|
|
83
134
|
getDropTargetFromPoint(x: number, y: number, isValidDropTarget: (target: DropTarget) => boolean): DropTarget;
|
|
135
|
+
getDropTargetLayoutInfo(target: ItemDropTarget): LayoutInfo;
|
|
84
136
|
}
|
|
85
137
|
|
|
86
138
|
//# sourceMappingURL=types.d.ts.map
|
package/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AAE,CAAC,EAAE,MAAM,GAAG,UAAU;IAgBxE,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,UAAU;IAsCvE,SAAS,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,UAAU;IAexE,qBAAqB,CAAC,IAAI,EAAE,IAAI;IA4KhC,sBAAsB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,GAAG,UAAU;IAgD5G,uBAAuB,CAAC,MAAM,EAAE,cAAc,GAAG,UAAU;CAK5D","sources":["packages/@react-stately/layout/src/packages/@react-stately/layout/src/GridLayout.ts","packages/@react-stately/layout/src/packages/@react-stately/layout/src/ListLayout.ts","packages/@react-stately/layout/src/packages/@react-stately/layout/src/TableLayout.ts","packages/@react-stately/layout/src/packages/@react-stately/layout/src/index.ts","packages/@react-stately/layout/src/index.ts"],"sourcesContent":[null,null,null,null,"/*\n * Copyright 2020 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 */\nexport type {GridLayoutOptions} from './GridLayout';\nexport type {ListLayoutOptions, LayoutNode} from './ListLayout';\nexport type {TableLayoutProps} from './TableLayout';\nexport {GridLayout} from './GridLayout';\nexport {ListLayout} from './ListLayout';\nexport {TableLayout} from './TableLayout';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/layout",
|
|
3
|
-
"version": "3.13.10-nightly.
|
|
3
|
+
"version": "3.13.10-nightly.4695+2964e9aaf",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-stately/collections": "3.0.0-nightly.
|
|
26
|
-
"@react-stately/table": "3.11.9-nightly.
|
|
27
|
-
"@react-stately/virtualizer": "3.7.2-nightly.
|
|
28
|
-
"@react-types/grid": "3.2.7-nightly.
|
|
29
|
-
"@react-types/shared": "3.0.0-nightly.
|
|
30
|
-
"@react-types/table": "3.9.6-nightly.
|
|
25
|
+
"@react-stately/collections": "3.0.0-nightly.2983+2964e9aaf",
|
|
26
|
+
"@react-stately/table": "3.11.9-nightly.4695+2964e9aaf",
|
|
27
|
+
"@react-stately/virtualizer": "3.7.2-nightly.4695+2964e9aaf",
|
|
28
|
+
"@react-types/grid": "3.2.7-nightly.4695+2964e9aaf",
|
|
29
|
+
"@react-types/shared": "3.0.0-nightly.2983+2964e9aaf",
|
|
30
|
+
"@react-types/table": "3.9.6-nightly.4695+2964e9aaf",
|
|
31
31
|
"@swc/helpers": "^0.5.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "2964e9aafc281888cd65da5bd77512e7f999bd84"
|
|
40
40
|
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {DropTarget, DropTargetDelegate, ItemDropTarget, Key, Node} from '@react-types/shared';
|
|
14
|
+
import {Layout, LayoutInfo, Rect, Size} from '@react-stately/virtualizer';
|
|
15
|
+
|
|
16
|
+
export interface GridLayoutOptions {
|
|
17
|
+
/**
|
|
18
|
+
* The minimum item size.
|
|
19
|
+
* @default 200 x 200
|
|
20
|
+
*/
|
|
21
|
+
minItemSize?: Size,
|
|
22
|
+
/**
|
|
23
|
+
* The maximum item size.
|
|
24
|
+
* @default Infinity
|
|
25
|
+
*/
|
|
26
|
+
maxItemSize?: Size,
|
|
27
|
+
/**
|
|
28
|
+
* The minimum space required between items.
|
|
29
|
+
* @default 18 x 18
|
|
30
|
+
*/
|
|
31
|
+
minSpace?: Size,
|
|
32
|
+
/**
|
|
33
|
+
* The maximum number of columns.
|
|
34
|
+
* @default Infinity
|
|
35
|
+
*/
|
|
36
|
+
maxColumns?: number,
|
|
37
|
+
/**
|
|
38
|
+
* The thickness of the drop indicator.
|
|
39
|
+
* @default 2
|
|
40
|
+
*/
|
|
41
|
+
dropIndicatorThickness?: number
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class GridLayout<T, O = any> extends Layout<Node<T>, O> implements DropTargetDelegate {
|
|
45
|
+
protected minItemSize: Size;
|
|
46
|
+
protected maxItemSize: Size;
|
|
47
|
+
protected minSpace: Size;
|
|
48
|
+
protected maxColumns: number;
|
|
49
|
+
protected dropIndicatorThickness: number;
|
|
50
|
+
protected itemSize: Size;
|
|
51
|
+
protected numColumns: number;
|
|
52
|
+
protected horizontalSpacing: number;
|
|
53
|
+
protected layoutInfos: LayoutInfo[];
|
|
54
|
+
|
|
55
|
+
constructor(options: GridLayoutOptions) {
|
|
56
|
+
super();
|
|
57
|
+
this.minItemSize = options.minItemSize || new Size(200, 200);
|
|
58
|
+
this.maxItemSize = options.maxItemSize || new Size(Infinity, Infinity);
|
|
59
|
+
this.minSpace = options.minSpace || new Size(18, 18);
|
|
60
|
+
this.maxColumns = options.maxColumns || Infinity;
|
|
61
|
+
this.dropIndicatorThickness = options.dropIndicatorThickness || 2;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
validate(): void {
|
|
65
|
+
let visibleWidth = this.virtualizer.visibleRect.width;
|
|
66
|
+
|
|
67
|
+
// The max item width is always the entire viewport.
|
|
68
|
+
// If the max item height is infinity, scale in proportion to the max width.
|
|
69
|
+
let maxItemWidth = Math.min(this.maxItemSize.width, visibleWidth);
|
|
70
|
+
let maxItemHeight = Number.isFinite(this.maxItemSize.height)
|
|
71
|
+
? this.maxItemSize.height
|
|
72
|
+
: Math.floor((this.minItemSize.height / this.minItemSize.width) * maxItemWidth);
|
|
73
|
+
|
|
74
|
+
// Compute the number of rows and columns needed to display the content
|
|
75
|
+
let columns = Math.floor(visibleWidth / (this.minItemSize.width + this.minSpace.width));
|
|
76
|
+
this.numColumns = Math.max(1, Math.min(this.maxColumns, columns));
|
|
77
|
+
|
|
78
|
+
// Compute the available width (minus the space between items)
|
|
79
|
+
let width = visibleWidth - (this.minSpace.width * Math.max(0, this.numColumns));
|
|
80
|
+
|
|
81
|
+
// Compute the item width based on the space available
|
|
82
|
+
let itemWidth = Math.floor(width / this.numColumns);
|
|
83
|
+
itemWidth = Math.max(this.minItemSize.width, Math.min(maxItemWidth, itemWidth));
|
|
84
|
+
|
|
85
|
+
// Compute the item height, which is proportional to the item width
|
|
86
|
+
let t = ((itemWidth - this.minItemSize.width) / (maxItemWidth - this.minItemSize.width));
|
|
87
|
+
let itemHeight = this.minItemSize.height + Math.floor((maxItemHeight - this.minItemSize.height) * t);
|
|
88
|
+
itemHeight = Math.max(this.minItemSize.height, Math.min(maxItemHeight, itemHeight));
|
|
89
|
+
this.itemSize = new Size(itemWidth, itemHeight);
|
|
90
|
+
|
|
91
|
+
// Compute the horizontal spacing and content height
|
|
92
|
+
this.horizontalSpacing = Math.floor((visibleWidth - this.numColumns * this.itemSize.width) / (this.numColumns + 1));
|
|
93
|
+
|
|
94
|
+
this.layoutInfos = [];
|
|
95
|
+
for (let node of this.virtualizer.collection) {
|
|
96
|
+
this.layoutInfos.push(this.getLayoutInfoForNode(node));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
getVisibleLayoutInfos(rect: Rect): LayoutInfo[] {
|
|
101
|
+
let firstVisibleItem = this.getIndexAtPoint(rect.x, rect.y);
|
|
102
|
+
let lastVisibleItem = this.getIndexAtPoint(rect.maxX, rect.maxY);
|
|
103
|
+
let result = this.layoutInfos.slice(firstVisibleItem, lastVisibleItem + 1);
|
|
104
|
+
let persistedIndices = [...this.virtualizer.persistedKeys].map(key => this.virtualizer.collection.getItem(key).index).sort((a, b) => a - b);
|
|
105
|
+
let persistedBefore = [];
|
|
106
|
+
for (let index of persistedIndices) {
|
|
107
|
+
if (index < firstVisibleItem) {
|
|
108
|
+
persistedBefore.push(this.layoutInfos[index]);
|
|
109
|
+
} else if (index > lastVisibleItem) {
|
|
110
|
+
result.push(this.layoutInfos[index]);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
result.unshift(...persistedBefore);
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
protected getIndexAtPoint(x: number, y: number) {
|
|
118
|
+
let itemHeight = this.itemSize.height + this.minSpace.height;
|
|
119
|
+
let itemWidth = this.itemSize.width + this.horizontalSpacing;
|
|
120
|
+
return Math.max(0,
|
|
121
|
+
Math.min(
|
|
122
|
+
this.virtualizer.collection.size - 1,
|
|
123
|
+
Math.floor(y / itemHeight) * this.numColumns + Math.floor((x - this.horizontalSpacing) / itemWidth)
|
|
124
|
+
)
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
getLayoutInfo(key: Key): LayoutInfo | null {
|
|
129
|
+
let node = this.virtualizer.collection.getItem(key);
|
|
130
|
+
return node ? this.layoutInfos[node.index] : null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
protected getLayoutInfoForNode(node: Node<T>): LayoutInfo {
|
|
134
|
+
let idx = node.index;
|
|
135
|
+
let row = Math.floor(idx / this.numColumns);
|
|
136
|
+
let column = idx % this.numColumns;
|
|
137
|
+
let x = this.horizontalSpacing + column * (this.itemSize.width + this.horizontalSpacing);
|
|
138
|
+
let y = this.minSpace.height + row * (this.itemSize.height + this.minSpace.height);
|
|
139
|
+
let rect = new Rect(x, y, this.itemSize.width, this.itemSize.height);
|
|
140
|
+
return new LayoutInfo(node.type, node.key, rect);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
getContentSize(): Size {
|
|
144
|
+
let numRows = Math.ceil(this.virtualizer.collection.size / this.numColumns);
|
|
145
|
+
let contentHeight = this.minSpace.height + numRows * (this.itemSize.height + this.minSpace.height);
|
|
146
|
+
return new Size(this.virtualizer.visibleRect.width, contentHeight);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
getDropTargetFromPoint(x: number, y: number, isValidDropTarget: (target: DropTarget) => boolean): DropTarget {
|
|
150
|
+
if (this.layoutInfos.length === 0) {
|
|
151
|
+
return {type: 'root'};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
x += this.virtualizer.visibleRect.x;
|
|
155
|
+
y += this.virtualizer.visibleRect.y;
|
|
156
|
+
let index = this.getIndexAtPoint(x, y);
|
|
157
|
+
|
|
158
|
+
let layoutInfo = this.layoutInfos[index];
|
|
159
|
+
let target: DropTarget = {
|
|
160
|
+
type: 'item',
|
|
161
|
+
key: layoutInfo.key,
|
|
162
|
+
dropPosition: 'on'
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
let pos = this.numColumns === 1 ? y : x;
|
|
166
|
+
let layoutInfoPos = this.numColumns === 1 ? layoutInfo.rect.y : layoutInfo.rect.x;
|
|
167
|
+
let size = this.numColumns === 1 ? layoutInfo.rect.height : layoutInfo.rect.width;
|
|
168
|
+
if (isValidDropTarget(target)) {
|
|
169
|
+
// If dropping on the item is accepted, try the before/after positions
|
|
170
|
+
// if within 5px of the start or end of the item.
|
|
171
|
+
if (pos < layoutInfoPos + 5) {
|
|
172
|
+
target.dropPosition = 'before';
|
|
173
|
+
} else if (pos > layoutInfoPos + size - 5) {
|
|
174
|
+
target.dropPosition = 'after';
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
// If dropping on the item isn't accepted, try the target before or after depending on the position.
|
|
178
|
+
let mid = layoutInfoPos + size / 2;
|
|
179
|
+
if (pos <= mid && isValidDropTarget({...target, dropPosition: 'before'})) {
|
|
180
|
+
target.dropPosition = 'before';
|
|
181
|
+
} else if (pos >= mid && isValidDropTarget({...target, dropPosition: 'after'})) {
|
|
182
|
+
target.dropPosition = 'after';
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return target;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
getDropTargetLayoutInfo(target: ItemDropTarget): LayoutInfo {
|
|
190
|
+
let layoutInfo = this.getLayoutInfo(target.key);
|
|
191
|
+
let rect: Rect;
|
|
192
|
+
if (this.numColumns === 1) {
|
|
193
|
+
// Flip from vertical to horizontal if only one column is visible.
|
|
194
|
+
rect = new Rect(
|
|
195
|
+
layoutInfo.rect.x,
|
|
196
|
+
target.dropPosition === 'before'
|
|
197
|
+
? layoutInfo.rect.y - this.minSpace.height / 2 - this.dropIndicatorThickness / 2
|
|
198
|
+
: layoutInfo.rect.maxY + this.minSpace.height / 2 - this.dropIndicatorThickness / 2,
|
|
199
|
+
layoutInfo.rect.width,
|
|
200
|
+
this.dropIndicatorThickness
|
|
201
|
+
);
|
|
202
|
+
} else {
|
|
203
|
+
rect = new Rect(
|
|
204
|
+
target.dropPosition === 'before'
|
|
205
|
+
? layoutInfo.rect.x - this.horizontalSpacing / 2 - this.dropIndicatorThickness / 2
|
|
206
|
+
: layoutInfo.rect.maxX + this.horizontalSpacing / 2 - this.dropIndicatorThickness / 2,
|
|
207
|
+
layoutInfo.rect.y,
|
|
208
|
+
this.dropIndicatorThickness,
|
|
209
|
+
layoutInfo.rect.height
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return new LayoutInfo('dropIndicator', target.key + ':' + target.dropPosition, rect);
|
|
214
|
+
}
|
|
215
|
+
}
|
package/src/ListLayout.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {Collection, DropTarget, DropTargetDelegate, Key, Node} from '@react-types/shared';
|
|
13
|
+
import {Collection, DropTarget, DropTargetDelegate, ItemDropTarget, Key, Node} from '@react-types/shared';
|
|
14
14
|
import {getChildNodes} from '@react-stately/collections';
|
|
15
15
|
import {InvalidationContext, Layout, LayoutInfo, Point, Rect, Size} from '@react-stately/virtualizer';
|
|
16
16
|
|
|
@@ -22,7 +22,9 @@ export interface ListLayoutOptions {
|
|
|
22
22
|
/** The fixed height of a section header in px. */
|
|
23
23
|
headingHeight?: number,
|
|
24
24
|
/** The estimated height of a section header, when the height is variable. */
|
|
25
|
-
estimatedHeadingHeight?: number
|
|
25
|
+
estimatedHeadingHeight?: number,
|
|
26
|
+
/** The thickness of the drop indicator. */
|
|
27
|
+
dropIndicatorThickness?: number
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
// A wrapper around LayoutInfo that supports hierarchy
|
|
@@ -49,6 +51,7 @@ export class ListLayout<T, O = any> extends Layout<Node<T>, O> implements DropTa
|
|
|
49
51
|
protected estimatedRowHeight: number;
|
|
50
52
|
protected headingHeight: number;
|
|
51
53
|
protected estimatedHeadingHeight: number;
|
|
54
|
+
protected dropIndicatorThickness: number;
|
|
52
55
|
protected layoutNodes: Map<Key, LayoutNode>;
|
|
53
56
|
protected contentSize: Size;
|
|
54
57
|
protected collection: Collection<Node<T>>;
|
|
@@ -71,6 +74,7 @@ export class ListLayout<T, O = any> extends Layout<Node<T>, O> implements DropTa
|
|
|
71
74
|
this.estimatedRowHeight = options.estimatedRowHeight;
|
|
72
75
|
this.headingHeight = options.headingHeight;
|
|
73
76
|
this.estimatedHeadingHeight = options.estimatedHeadingHeight;
|
|
77
|
+
this.dropIndicatorThickness = options.dropIndicatorThickness || 2;
|
|
74
78
|
this.layoutNodes = new Map();
|
|
75
79
|
this.rootNodes = [];
|
|
76
80
|
this.lastWidth = 0;
|
|
@@ -447,4 +451,18 @@ export class ListLayout<T, O = any> extends Layout<Node<T>, O> implements DropTa
|
|
|
447
451
|
|
|
448
452
|
return target;
|
|
449
453
|
}
|
|
454
|
+
|
|
455
|
+
getDropTargetLayoutInfo(target: ItemDropTarget): LayoutInfo {
|
|
456
|
+
let layoutInfo = this.getLayoutInfo(target.key);
|
|
457
|
+
let rect: Rect;
|
|
458
|
+
if (target.dropPosition === 'before') {
|
|
459
|
+
rect = new Rect(layoutInfo.rect.x, layoutInfo.rect.y - this.dropIndicatorThickness / 2, layoutInfo.rect.width, this.dropIndicatorThickness);
|
|
460
|
+
} else if (target.dropPosition === 'after') {
|
|
461
|
+
rect = new Rect(layoutInfo.rect.x, layoutInfo.rect.maxY - this.dropIndicatorThickness / 2, layoutInfo.rect.width, this.dropIndicatorThickness);
|
|
462
|
+
} else {
|
|
463
|
+
rect = layoutInfo.rect;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
return new LayoutInfo('dropIndicator', target.key + ':' + target.dropPosition, rect);
|
|
467
|
+
}
|
|
450
468
|
}
|
package/src/TableLayout.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {DropTarget, Key} from '@react-types/shared';
|
|
13
|
+
import {DropTarget, ItemDropTarget, Key} from '@react-types/shared';
|
|
14
14
|
import {getChildNodes} from '@react-stately/collections';
|
|
15
15
|
import {GridNode} from '@react-types/grid';
|
|
16
16
|
import {InvalidationContext, LayoutInfo, Point, Rect, Size} from '@react-stately/virtualizer';
|
|
@@ -508,9 +508,6 @@ export class TableLayout<T, O extends TableLayoutProps = TableLayoutProps> exten
|
|
|
508
508
|
x += this.virtualizer.visibleRect.x;
|
|
509
509
|
y += this.virtualizer.visibleRect.y;
|
|
510
510
|
|
|
511
|
-
// Offset for height of header row
|
|
512
|
-
y -= this.virtualizer.layout.getVisibleLayoutInfos(new Rect(x, y, 1, 1)).find(info => info.type === 'headerrow')?.rect.height;
|
|
513
|
-
|
|
514
511
|
// Custom variation of this.virtualizer.keyAtPoint that ignores body
|
|
515
512
|
let key: Key;
|
|
516
513
|
let point = new Point(x, y);
|
|
@@ -554,4 +551,10 @@ export class TableLayout<T, O extends TableLayoutProps = TableLayoutProps> exten
|
|
|
554
551
|
|
|
555
552
|
return target;
|
|
556
553
|
}
|
|
554
|
+
|
|
555
|
+
getDropTargetLayoutInfo(target: ItemDropTarget): LayoutInfo {
|
|
556
|
+
let layoutInfo = super.getDropTargetLayoutInfo(target);
|
|
557
|
+
layoutInfo.parentKey = this.collection.body.key;
|
|
558
|
+
return layoutInfo;
|
|
559
|
+
}
|
|
557
560
|
}
|
package/src/index.ts
CHANGED
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
+
export type {GridLayoutOptions} from './GridLayout';
|
|
12
13
|
export type {ListLayoutOptions, LayoutNode} from './ListLayout';
|
|
13
14
|
export type {TableLayoutProps} from './TableLayout';
|
|
15
|
+
export {GridLayout} from './GridLayout';
|
|
14
16
|
export {ListLayout} from './ListLayout';
|
|
15
17
|
export {TableLayout} from './TableLayout';
|