@react-stately/grid 3.11.8 → 3.12.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.
- package/dist/import.mjs +3 -3
- package/dist/main.js +4 -4
- package/dist/main.js.map +1 -1
- package/dist/module.js +3 -3
- package/dist/module.js.map +1 -1
- package/dist/types/src/index.d.ts +4 -0
- package/package.json +17 -16
- package/src/index.ts +4 -3
- package/dist/GridCollection.main.js +0 -148
- package/dist/GridCollection.main.js.map +0 -1
- package/dist/GridCollection.mjs +0 -143
- package/dist/GridCollection.module.js +0 -143
- package/dist/GridCollection.module.js.map +0 -1
- package/dist/types.d.ts +0 -46
- package/dist/types.d.ts.map +0 -1
- package/dist/useGridState.main.js +0 -91
- package/dist/useGridState.main.js.map +0 -1
- package/dist/useGridState.mjs +0 -86
- package/dist/useGridState.module.js +0 -86
- package/dist/useGridState.module.js.map +0 -1
- package/src/GridCollection.ts +0 -180
- package/src/useGridState.ts +0 -122
package/dist/import.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {useGridState as $
|
|
2
|
-
import {GridCollection as $
|
|
1
|
+
import {useGridState as $f30cc900230da60a$re_export$useGridState} from "react-stately/private/grid/useGridState";
|
|
2
|
+
import {GridCollection as $f30cc900230da60a$re_export$GridCollection} from "react-stately/private/grid/GridCollection";
|
|
3
3
|
|
|
4
4
|
/*
|
|
5
5
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -15,5 +15,5 @@ import {GridCollection as $16805b1b18093c5f$export$de3fdf6493c353d} from "./Grid
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
export {$
|
|
18
|
+
export {$f30cc900230da60a$re_export$useGridState as useGridState, $f30cc900230da60a$re_export$GridCollection as GridCollection};
|
|
19
19
|
//# sourceMappingURL=module.js.map
|
package/dist/main.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
var $
|
|
2
|
-
var $
|
|
1
|
+
var $5ByT5$reactstatelyprivategriduseGridState = require("react-stately/private/grid/useGridState");
|
|
2
|
+
var $5ByT5$reactstatelyprivategridGridCollection = require("react-stately/private/grid/GridCollection");
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
function $parcel$export(e, n, v, s) {
|
|
6
6
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
$parcel$export(module.exports, "useGridState", ()
|
|
10
|
-
$parcel$export(module.exports, "GridCollection", ()
|
|
9
|
+
$parcel$export(module.exports, "useGridState", function () { return $5ByT5$reactstatelyprivategriduseGridState.useGridState; });
|
|
10
|
+
$parcel$export(module.exports, "GridCollection", function () { return $5ByT5$reactstatelyprivategridGridCollection.GridCollection; });
|
|
11
11
|
/*
|
|
12
12
|
* Copyright 2020 Adobe. All rights reserved.
|
|
13
13
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/grid/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 */\n\nexport {useGridState} from '
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/grid/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 */\n\nexport {useGridState} from 'react-stately/private/grid/useGridState';\n\nexport {GridCollection} from 'react-stately/private/grid/GridCollection';\nexport type {GridStateOptions, GridState} from 'react-stately/private/grid/useGridState';\nexport type {IGridCollection, GridNode, GridRow} from 'react-stately/private/grid/GridCollection';\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {useGridState as $
|
|
2
|
-
import {GridCollection as $
|
|
1
|
+
import {useGridState as $f30cc900230da60a$re_export$useGridState} from "react-stately/private/grid/useGridState";
|
|
2
|
+
import {GridCollection as $f30cc900230da60a$re_export$GridCollection} from "react-stately/private/grid/GridCollection";
|
|
3
3
|
|
|
4
4
|
/*
|
|
5
5
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -15,5 +15,5 @@ import {GridCollection as $16805b1b18093c5f$export$de3fdf6493c353d} from "./Grid
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
export {$
|
|
18
|
+
export {$f30cc900230da60a$re_export$useGridState as useGridState, $f30cc900230da60a$re_export$GridCollection as GridCollection};
|
|
19
19
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/grid/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 */\n\nexport {useGridState} from '
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/grid/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 */\n\nexport {useGridState} from 'react-stately/private/grid/useGridState';\n\nexport {GridCollection} from 'react-stately/private/grid/GridCollection';\nexport type {GridStateOptions, GridState} from 'react-stately/private/grid/useGridState';\nexport type {IGridCollection, GridNode, GridRow} from 'react-stately/private/grid/GridCollection';\n"],"names":[],"version":3,"file":"module.js.map"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { useGridState } from 'react-stately/private/grid/useGridState';
|
|
2
|
+
export { GridCollection } from 'react-stately/private/grid/GridCollection';
|
|
3
|
+
export type { GridStateOptions, GridState } from 'react-stately/private/grid/useGridState';
|
|
4
|
+
export type { IGridCollection, GridNode, GridRow } from 'react-stately/private/grid/GridCollection';
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/grid",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.12.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
7
7
|
"module": "dist/module.js",
|
|
8
8
|
"exports": {
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
"./dist/types.d.ts",
|
|
12
|
-
"./
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
9
|
+
".": {
|
|
10
|
+
"source": "./src/index.ts",
|
|
11
|
+
"types": "./dist/types/src/index.d.ts",
|
|
12
|
+
"import": "./dist/import.mjs",
|
|
13
|
+
"require": "./dist/main.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
16
|
},
|
|
17
|
-
"types": "dist/types.d.ts",
|
|
17
|
+
"types": "dist/types/src/index.d.ts",
|
|
18
18
|
"source": "src/index.ts",
|
|
19
19
|
"files": [
|
|
20
20
|
"dist",
|
|
@@ -26,17 +26,18 @@
|
|
|
26
26
|
"url": "https://github.com/adobe/react-spectrum"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@
|
|
30
|
-
"
|
|
31
|
-
"@react-types/grid": "^3.3.7",
|
|
32
|
-
"@react-types/shared": "^3.33.0",
|
|
33
|
-
"@swc/helpers": "^0.5.0"
|
|
29
|
+
"@swc/helpers": "^0.5.0",
|
|
30
|
+
"react-stately": "3.46.0"
|
|
34
31
|
},
|
|
35
32
|
"peerDependencies": {
|
|
36
|
-
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
|
|
33
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
|
|
34
|
+
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
|
|
37
35
|
},
|
|
38
36
|
"publishConfig": {
|
|
39
37
|
"access": "public"
|
|
40
38
|
},
|
|
41
|
-
"
|
|
39
|
+
"targets": {
|
|
40
|
+
"types": false
|
|
41
|
+
},
|
|
42
|
+
"gitHead": "a6999bdf494a2e9c0381a5881908328bdd22ddae"
|
|
42
43
|
}
|
package/src/index.ts
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
export {useGridState} from '
|
|
14
|
-
export {GridCollection} from './GridCollection';
|
|
13
|
+
export {useGridState} from 'react-stately/private/grid/useGridState';
|
|
15
14
|
|
|
16
|
-
export
|
|
15
|
+
export {GridCollection} from 'react-stately/private/grid/GridCollection';
|
|
16
|
+
export type {GridStateOptions, GridState} from 'react-stately/private/grid/useGridState';
|
|
17
|
+
export type {IGridCollection, GridNode, GridRow} from 'react-stately/private/grid/GridCollection';
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
function $parcel$export(e, n, v, s) {
|
|
3
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
$parcel$export(module.exports, "GridCollection", () => $8bb6a9101b052a66$export$de3fdf6493c353d);
|
|
7
|
-
/*
|
|
8
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
9
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
10
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
11
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
*
|
|
13
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
14
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
15
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
16
|
-
* governing permissions and limitations under the License.
|
|
17
|
-
*/ class $8bb6a9101b052a66$export$de3fdf6493c353d {
|
|
18
|
-
*[Symbol.iterator]() {
|
|
19
|
-
yield* [
|
|
20
|
-
...this.rows
|
|
21
|
-
];
|
|
22
|
-
}
|
|
23
|
-
get size() {
|
|
24
|
-
return [
|
|
25
|
-
...this.rows
|
|
26
|
-
].length;
|
|
27
|
-
}
|
|
28
|
-
getKeys() {
|
|
29
|
-
return this.keyMap.keys();
|
|
30
|
-
}
|
|
31
|
-
getKeyBefore(key) {
|
|
32
|
-
let node = this.keyMap.get(key);
|
|
33
|
-
var _node_prevKey;
|
|
34
|
-
return node ? (_node_prevKey = node.prevKey) !== null && _node_prevKey !== void 0 ? _node_prevKey : null : null;
|
|
35
|
-
}
|
|
36
|
-
getKeyAfter(key) {
|
|
37
|
-
let node = this.keyMap.get(key);
|
|
38
|
-
var _node_nextKey;
|
|
39
|
-
return node ? (_node_nextKey = node.nextKey) !== null && _node_nextKey !== void 0 ? _node_nextKey : null : null;
|
|
40
|
-
}
|
|
41
|
-
getFirstKey() {
|
|
42
|
-
var _;
|
|
43
|
-
return (_ = [
|
|
44
|
-
...this.rows
|
|
45
|
-
][0]) === null || _ === void 0 ? void 0 : _.key;
|
|
46
|
-
}
|
|
47
|
-
getLastKey() {
|
|
48
|
-
var _rows_;
|
|
49
|
-
let rows = [
|
|
50
|
-
...this.rows
|
|
51
|
-
];
|
|
52
|
-
return (_rows_ = rows[rows.length - 1]) === null || _rows_ === void 0 ? void 0 : _rows_.key;
|
|
53
|
-
}
|
|
54
|
-
getItem(key) {
|
|
55
|
-
var _this_keyMap_get;
|
|
56
|
-
return (_this_keyMap_get = this.keyMap.get(key)) !== null && _this_keyMap_get !== void 0 ? _this_keyMap_get : null;
|
|
57
|
-
}
|
|
58
|
-
at(idx) {
|
|
59
|
-
const keys = [
|
|
60
|
-
...this.getKeys()
|
|
61
|
-
];
|
|
62
|
-
return this.getItem(keys[idx]);
|
|
63
|
-
}
|
|
64
|
-
getChildren(key) {
|
|
65
|
-
let node = this.keyMap.get(key);
|
|
66
|
-
return (node === null || node === void 0 ? void 0 : node.childNodes) || [];
|
|
67
|
-
}
|
|
68
|
-
constructor(opts){
|
|
69
|
-
this.keyMap = new Map();
|
|
70
|
-
this.keyMap = new Map();
|
|
71
|
-
this.columnCount = opts === null || opts === void 0 ? void 0 : opts.columnCount;
|
|
72
|
-
this.rows = [];
|
|
73
|
-
let visit = (node)=>{
|
|
74
|
-
// If the node is the same object as the previous node for the same key,
|
|
75
|
-
// we can skip this node and its children. We always visit columns though,
|
|
76
|
-
// because we depend on order to build the columns array.
|
|
77
|
-
let prevNode = this.keyMap.get(node.key);
|
|
78
|
-
if (opts.visitNode) node = opts.visitNode(node);
|
|
79
|
-
this.keyMap.set(node.key, node);
|
|
80
|
-
let childKeys = new Set();
|
|
81
|
-
let last = null;
|
|
82
|
-
let rowHasCellWithColSpan = false;
|
|
83
|
-
if (node.type === 'item') {
|
|
84
|
-
var _child_props;
|
|
85
|
-
for (let child of node.childNodes)if (((_child_props = child.props) === null || _child_props === void 0 ? void 0 : _child_props.colSpan) !== undefined) {
|
|
86
|
-
rowHasCellWithColSpan = true;
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
for (let child of node.childNodes){
|
|
91
|
-
if (child.type === 'cell' && rowHasCellWithColSpan) {
|
|
92
|
-
var _child_props1, _child_props2;
|
|
93
|
-
child.colspan = (_child_props1 = child.props) === null || _child_props1 === void 0 ? void 0 : _child_props1.colSpan;
|
|
94
|
-
child.colSpan = (_child_props2 = child.props) === null || _child_props2 === void 0 ? void 0 : _child_props2.colSpan;
|
|
95
|
-
var _last_colIndex, _last_colSpan;
|
|
96
|
-
child.colIndex = !last ? child.index : ((_last_colIndex = last.colIndex) !== null && _last_colIndex !== void 0 ? _last_colIndex : last.index) + ((_last_colSpan = last.colSpan) !== null && _last_colSpan !== void 0 ? _last_colSpan : 1);
|
|
97
|
-
}
|
|
98
|
-
if (child.type === 'cell' && child.parentKey == null) // if child is a cell parent key isn't already established by the collection, match child node to parent row
|
|
99
|
-
child.parentKey = node.key;
|
|
100
|
-
childKeys.add(child.key);
|
|
101
|
-
if (last) {
|
|
102
|
-
last.nextKey = child.key;
|
|
103
|
-
child.prevKey = last.key;
|
|
104
|
-
} else child.prevKey = null;
|
|
105
|
-
visit(child);
|
|
106
|
-
last = child;
|
|
107
|
-
}
|
|
108
|
-
if (last) last.nextKey = null;
|
|
109
|
-
// Remove deleted nodes and their children from the key map
|
|
110
|
-
if (prevNode) {
|
|
111
|
-
for (let child of prevNode.childNodes)if (!childKeys.has(child.key)) remove(child);
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
let remove = (node)=>{
|
|
115
|
-
this.keyMap.delete(node.key);
|
|
116
|
-
for (let child of node.childNodes)if (this.keyMap.get(child.key) === child) remove(child);
|
|
117
|
-
};
|
|
118
|
-
let last = null;
|
|
119
|
-
for (let [i, node] of opts.items.entries()){
|
|
120
|
-
var _node_level, _node_key, _node_type, _node_value, _node_textValue, _node_index;
|
|
121
|
-
let rowNode = {
|
|
122
|
-
...node,
|
|
123
|
-
level: (_node_level = node.level) !== null && _node_level !== void 0 ? _node_level : 0,
|
|
124
|
-
key: (_node_key = node.key) !== null && _node_key !== void 0 ? _node_key : 'row-' + i,
|
|
125
|
-
type: (_node_type = node.type) !== null && _node_type !== void 0 ? _node_type : 'row',
|
|
126
|
-
value: (_node_value = node.value) !== null && _node_value !== void 0 ? _node_value : null,
|
|
127
|
-
hasChildNodes: true,
|
|
128
|
-
childNodes: [
|
|
129
|
-
...node.childNodes
|
|
130
|
-
],
|
|
131
|
-
rendered: node.rendered,
|
|
132
|
-
textValue: (_node_textValue = node.textValue) !== null && _node_textValue !== void 0 ? _node_textValue : '',
|
|
133
|
-
index: (_node_index = node.index) !== null && _node_index !== void 0 ? _node_index : i
|
|
134
|
-
};
|
|
135
|
-
if (last) {
|
|
136
|
-
last.nextKey = rowNode.key;
|
|
137
|
-
rowNode.prevKey = last.key;
|
|
138
|
-
} else rowNode.prevKey = null;
|
|
139
|
-
this.rows.push(rowNode);
|
|
140
|
-
visit(rowNode);
|
|
141
|
-
last = rowNode;
|
|
142
|
-
}
|
|
143
|
-
if (last) last.nextKey = null;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
//# sourceMappingURL=GridCollection.main.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GAWM,MAAM;IAkHX,CAAC,CAAC,OAAO,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Q,GAAG;gBAC1B,QAAQ,OAAO,GAAG,KAAK,GAAG;YAC5B,OACE,QAAQ,OAAO,GAAG;YAGpB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YACf,MAAM;YAEN,OAAO;QACT;QAEA,IAAI,MACF,KAAK,OAAO,GAAG;IAEnB;AA8CF","sources":["packages/@react-stately/grid/src/GridCollection.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 */\n\nimport {GridNode, GridRow, GridCollection as IGridCollection} from '@react-types/grid';\nimport {Key} from '@react-types/shared';\n\ninterface GridCollectionOptions<T> {\n columnCount: number,\n items: GridRow<T>[],\n visitNode?: (cell: GridNode<T>) => GridNode<T>\n}\n\nexport class GridCollection<T> implements IGridCollection<T> {\n keyMap: Map<Key, GridNode<T>> = new Map();\n columnCount: number;\n rows: GridNode<T>[];\n\n constructor(opts: GridCollectionOptions<T>) {\n this.keyMap = new Map();\n this.columnCount = opts?.columnCount;\n this.rows = [];\n\n let visit = (node: GridNode<T>) => {\n // If the node is the same object as the previous node for the same key,\n // we can skip this node and its children. We always visit columns though,\n // because we depend on order to build the columns array.\n let prevNode = this.keyMap.get(node.key);\n if (opts.visitNode) {\n node = opts.visitNode(node);\n }\n\n this.keyMap.set(node.key, node);\n\n let childKeys = new Set();\n let last: GridNode<T> | null = null;\n let rowHasCellWithColSpan = false;\n\n if (node.type === 'item') {\n for (let child of node.childNodes) {\n if (child.props?.colSpan !== undefined) {\n rowHasCellWithColSpan = true;\n break;\n }\n }\n }\n\n for (let child of node.childNodes as Iterable<GridNode<T>>) {\n if (child.type === 'cell' && rowHasCellWithColSpan) {\n child.colspan = child.props?.colSpan;\n child.colSpan = child.props?.colSpan;\n child.colIndex = !last ? child.index : (last.colIndex ?? last.index) + (last.colSpan ?? 1);\n }\n\n if (child.type === 'cell' && child.parentKey == null) {\n // if child is a cell parent key isn't already established by the collection, match child node to parent row\n child.parentKey = node.key;\n }\n childKeys.add(child.key);\n\n if (last) {\n last.nextKey = child.key;\n child.prevKey = last.key;\n } else {\n child.prevKey = null;\n }\n\n visit(child);\n last = child;\n }\n\n if (last) {\n last.nextKey = null;\n }\n\n // Remove deleted nodes and their children from the key map\n if (prevNode) {\n for (let child of prevNode.childNodes) {\n if (!childKeys.has(child.key)) {\n remove(child);\n }\n }\n }\n };\n\n let remove = (node: GridNode<T>) => {\n this.keyMap.delete(node.key);\n for (let child of node.childNodes) {\n if (this.keyMap.get(child.key) === child) {\n remove(child);\n }\n }\n };\n\n let last: GridNode<T> | null = null;\n for (let [i, node] of opts.items.entries()) {\n let rowNode: GridNode<T> = {\n ...node,\n level: node.level ?? 0,\n key: node.key ?? 'row-' + i,\n type: node.type ?? 'row',\n value: node.value ?? null,\n hasChildNodes: true,\n childNodes: [...node.childNodes],\n rendered: node.rendered,\n textValue: node.textValue ?? '',\n index: node.index ?? i\n };\n\n if (last) {\n last.nextKey = rowNode.key;\n rowNode.prevKey = last.key;\n } else {\n rowNode.prevKey = null;\n }\n\n this.rows.push(rowNode);\n visit(rowNode);\n\n last = rowNode;\n }\n\n if (last) {\n last.nextKey = null;\n }\n }\n\n *[Symbol.iterator](): IterableIterator<GridNode<T>> {\n yield* [...this.rows];\n }\n\n get size(): number {\n return [...this.rows].length;\n }\n\n getKeys(): IterableIterator<Key> {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key): Key | null {\n let node = this.keyMap.get(key);\n return node ? node.prevKey ?? null : null;\n }\n\n getKeyAfter(key: Key): Key | null {\n let node = this.keyMap.get(key);\n return node ? node.nextKey ?? null : null;\n }\n\n getFirstKey(): Key | null {\n return [...this.rows][0]?.key;\n }\n\n getLastKey(): Key | null {\n let rows = [...this.rows];\n return rows[rows.length - 1]?.key;\n }\n\n getItem(key: Key): GridNode<T> | null {\n return this.keyMap.get(key) ?? null;\n }\n\n at(idx: number): GridNode<T> | null {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n\n getChildren(key: Key): Iterable<GridNode<T>> {\n let node = this.keyMap.get(key);\n return node?.childNodes || [];\n }\n}\n"],"names":[],"version":3,"file":"GridCollection.main.js.map"}
|
package/dist/GridCollection.mjs
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 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
|
-
*/ class $16805b1b18093c5f$export$de3fdf6493c353d {
|
|
12
|
-
*[Symbol.iterator]() {
|
|
13
|
-
yield* [
|
|
14
|
-
...this.rows
|
|
15
|
-
];
|
|
16
|
-
}
|
|
17
|
-
get size() {
|
|
18
|
-
return [
|
|
19
|
-
...this.rows
|
|
20
|
-
].length;
|
|
21
|
-
}
|
|
22
|
-
getKeys() {
|
|
23
|
-
return this.keyMap.keys();
|
|
24
|
-
}
|
|
25
|
-
getKeyBefore(key) {
|
|
26
|
-
let node = this.keyMap.get(key);
|
|
27
|
-
var _node_prevKey;
|
|
28
|
-
return node ? (_node_prevKey = node.prevKey) !== null && _node_prevKey !== void 0 ? _node_prevKey : null : null;
|
|
29
|
-
}
|
|
30
|
-
getKeyAfter(key) {
|
|
31
|
-
let node = this.keyMap.get(key);
|
|
32
|
-
var _node_nextKey;
|
|
33
|
-
return node ? (_node_nextKey = node.nextKey) !== null && _node_nextKey !== void 0 ? _node_nextKey : null : null;
|
|
34
|
-
}
|
|
35
|
-
getFirstKey() {
|
|
36
|
-
var _;
|
|
37
|
-
return (_ = [
|
|
38
|
-
...this.rows
|
|
39
|
-
][0]) === null || _ === void 0 ? void 0 : _.key;
|
|
40
|
-
}
|
|
41
|
-
getLastKey() {
|
|
42
|
-
var _rows_;
|
|
43
|
-
let rows = [
|
|
44
|
-
...this.rows
|
|
45
|
-
];
|
|
46
|
-
return (_rows_ = rows[rows.length - 1]) === null || _rows_ === void 0 ? void 0 : _rows_.key;
|
|
47
|
-
}
|
|
48
|
-
getItem(key) {
|
|
49
|
-
var _this_keyMap_get;
|
|
50
|
-
return (_this_keyMap_get = this.keyMap.get(key)) !== null && _this_keyMap_get !== void 0 ? _this_keyMap_get : null;
|
|
51
|
-
}
|
|
52
|
-
at(idx) {
|
|
53
|
-
const keys = [
|
|
54
|
-
...this.getKeys()
|
|
55
|
-
];
|
|
56
|
-
return this.getItem(keys[idx]);
|
|
57
|
-
}
|
|
58
|
-
getChildren(key) {
|
|
59
|
-
let node = this.keyMap.get(key);
|
|
60
|
-
return (node === null || node === void 0 ? void 0 : node.childNodes) || [];
|
|
61
|
-
}
|
|
62
|
-
constructor(opts){
|
|
63
|
-
this.keyMap = new Map();
|
|
64
|
-
this.keyMap = new Map();
|
|
65
|
-
this.columnCount = opts === null || opts === void 0 ? void 0 : opts.columnCount;
|
|
66
|
-
this.rows = [];
|
|
67
|
-
let visit = (node)=>{
|
|
68
|
-
// If the node is the same object as the previous node for the same key,
|
|
69
|
-
// we can skip this node and its children. We always visit columns though,
|
|
70
|
-
// because we depend on order to build the columns array.
|
|
71
|
-
let prevNode = this.keyMap.get(node.key);
|
|
72
|
-
if (opts.visitNode) node = opts.visitNode(node);
|
|
73
|
-
this.keyMap.set(node.key, node);
|
|
74
|
-
let childKeys = new Set();
|
|
75
|
-
let last = null;
|
|
76
|
-
let rowHasCellWithColSpan = false;
|
|
77
|
-
if (node.type === 'item') {
|
|
78
|
-
var _child_props;
|
|
79
|
-
for (let child of node.childNodes)if (((_child_props = child.props) === null || _child_props === void 0 ? void 0 : _child_props.colSpan) !== undefined) {
|
|
80
|
-
rowHasCellWithColSpan = true;
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
for (let child of node.childNodes){
|
|
85
|
-
if (child.type === 'cell' && rowHasCellWithColSpan) {
|
|
86
|
-
var _child_props1, _child_props2;
|
|
87
|
-
child.colspan = (_child_props1 = child.props) === null || _child_props1 === void 0 ? void 0 : _child_props1.colSpan;
|
|
88
|
-
child.colSpan = (_child_props2 = child.props) === null || _child_props2 === void 0 ? void 0 : _child_props2.colSpan;
|
|
89
|
-
var _last_colIndex, _last_colSpan;
|
|
90
|
-
child.colIndex = !last ? child.index : ((_last_colIndex = last.colIndex) !== null && _last_colIndex !== void 0 ? _last_colIndex : last.index) + ((_last_colSpan = last.colSpan) !== null && _last_colSpan !== void 0 ? _last_colSpan : 1);
|
|
91
|
-
}
|
|
92
|
-
if (child.type === 'cell' && child.parentKey == null) // if child is a cell parent key isn't already established by the collection, match child node to parent row
|
|
93
|
-
child.parentKey = node.key;
|
|
94
|
-
childKeys.add(child.key);
|
|
95
|
-
if (last) {
|
|
96
|
-
last.nextKey = child.key;
|
|
97
|
-
child.prevKey = last.key;
|
|
98
|
-
} else child.prevKey = null;
|
|
99
|
-
visit(child);
|
|
100
|
-
last = child;
|
|
101
|
-
}
|
|
102
|
-
if (last) last.nextKey = null;
|
|
103
|
-
// Remove deleted nodes and their children from the key map
|
|
104
|
-
if (prevNode) {
|
|
105
|
-
for (let child of prevNode.childNodes)if (!childKeys.has(child.key)) remove(child);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
let remove = (node)=>{
|
|
109
|
-
this.keyMap.delete(node.key);
|
|
110
|
-
for (let child of node.childNodes)if (this.keyMap.get(child.key) === child) remove(child);
|
|
111
|
-
};
|
|
112
|
-
let last = null;
|
|
113
|
-
for (let [i, node] of opts.items.entries()){
|
|
114
|
-
var _node_level, _node_key, _node_type, _node_value, _node_textValue, _node_index;
|
|
115
|
-
let rowNode = {
|
|
116
|
-
...node,
|
|
117
|
-
level: (_node_level = node.level) !== null && _node_level !== void 0 ? _node_level : 0,
|
|
118
|
-
key: (_node_key = node.key) !== null && _node_key !== void 0 ? _node_key : 'row-' + i,
|
|
119
|
-
type: (_node_type = node.type) !== null && _node_type !== void 0 ? _node_type : 'row',
|
|
120
|
-
value: (_node_value = node.value) !== null && _node_value !== void 0 ? _node_value : null,
|
|
121
|
-
hasChildNodes: true,
|
|
122
|
-
childNodes: [
|
|
123
|
-
...node.childNodes
|
|
124
|
-
],
|
|
125
|
-
rendered: node.rendered,
|
|
126
|
-
textValue: (_node_textValue = node.textValue) !== null && _node_textValue !== void 0 ? _node_textValue : '',
|
|
127
|
-
index: (_node_index = node.index) !== null && _node_index !== void 0 ? _node_index : i
|
|
128
|
-
};
|
|
129
|
-
if (last) {
|
|
130
|
-
last.nextKey = rowNode.key;
|
|
131
|
-
rowNode.prevKey = last.key;
|
|
132
|
-
} else rowNode.prevKey = null;
|
|
133
|
-
this.rows.push(rowNode);
|
|
134
|
-
visit(rowNode);
|
|
135
|
-
last = rowNode;
|
|
136
|
-
}
|
|
137
|
-
if (last) last.nextKey = null;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
export {$16805b1b18093c5f$export$de3fdf6493c353d as GridCollection};
|
|
143
|
-
//# sourceMappingURL=GridCollection.module.js.map
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 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
|
-
*/ class $16805b1b18093c5f$export$de3fdf6493c353d {
|
|
12
|
-
*[Symbol.iterator]() {
|
|
13
|
-
yield* [
|
|
14
|
-
...this.rows
|
|
15
|
-
];
|
|
16
|
-
}
|
|
17
|
-
get size() {
|
|
18
|
-
return [
|
|
19
|
-
...this.rows
|
|
20
|
-
].length;
|
|
21
|
-
}
|
|
22
|
-
getKeys() {
|
|
23
|
-
return this.keyMap.keys();
|
|
24
|
-
}
|
|
25
|
-
getKeyBefore(key) {
|
|
26
|
-
let node = this.keyMap.get(key);
|
|
27
|
-
var _node_prevKey;
|
|
28
|
-
return node ? (_node_prevKey = node.prevKey) !== null && _node_prevKey !== void 0 ? _node_prevKey : null : null;
|
|
29
|
-
}
|
|
30
|
-
getKeyAfter(key) {
|
|
31
|
-
let node = this.keyMap.get(key);
|
|
32
|
-
var _node_nextKey;
|
|
33
|
-
return node ? (_node_nextKey = node.nextKey) !== null && _node_nextKey !== void 0 ? _node_nextKey : null : null;
|
|
34
|
-
}
|
|
35
|
-
getFirstKey() {
|
|
36
|
-
var _;
|
|
37
|
-
return (_ = [
|
|
38
|
-
...this.rows
|
|
39
|
-
][0]) === null || _ === void 0 ? void 0 : _.key;
|
|
40
|
-
}
|
|
41
|
-
getLastKey() {
|
|
42
|
-
var _rows_;
|
|
43
|
-
let rows = [
|
|
44
|
-
...this.rows
|
|
45
|
-
];
|
|
46
|
-
return (_rows_ = rows[rows.length - 1]) === null || _rows_ === void 0 ? void 0 : _rows_.key;
|
|
47
|
-
}
|
|
48
|
-
getItem(key) {
|
|
49
|
-
var _this_keyMap_get;
|
|
50
|
-
return (_this_keyMap_get = this.keyMap.get(key)) !== null && _this_keyMap_get !== void 0 ? _this_keyMap_get : null;
|
|
51
|
-
}
|
|
52
|
-
at(idx) {
|
|
53
|
-
const keys = [
|
|
54
|
-
...this.getKeys()
|
|
55
|
-
];
|
|
56
|
-
return this.getItem(keys[idx]);
|
|
57
|
-
}
|
|
58
|
-
getChildren(key) {
|
|
59
|
-
let node = this.keyMap.get(key);
|
|
60
|
-
return (node === null || node === void 0 ? void 0 : node.childNodes) || [];
|
|
61
|
-
}
|
|
62
|
-
constructor(opts){
|
|
63
|
-
this.keyMap = new Map();
|
|
64
|
-
this.keyMap = new Map();
|
|
65
|
-
this.columnCount = opts === null || opts === void 0 ? void 0 : opts.columnCount;
|
|
66
|
-
this.rows = [];
|
|
67
|
-
let visit = (node)=>{
|
|
68
|
-
// If the node is the same object as the previous node for the same key,
|
|
69
|
-
// we can skip this node and its children. We always visit columns though,
|
|
70
|
-
// because we depend on order to build the columns array.
|
|
71
|
-
let prevNode = this.keyMap.get(node.key);
|
|
72
|
-
if (opts.visitNode) node = opts.visitNode(node);
|
|
73
|
-
this.keyMap.set(node.key, node);
|
|
74
|
-
let childKeys = new Set();
|
|
75
|
-
let last = null;
|
|
76
|
-
let rowHasCellWithColSpan = false;
|
|
77
|
-
if (node.type === 'item') {
|
|
78
|
-
var _child_props;
|
|
79
|
-
for (let child of node.childNodes)if (((_child_props = child.props) === null || _child_props === void 0 ? void 0 : _child_props.colSpan) !== undefined) {
|
|
80
|
-
rowHasCellWithColSpan = true;
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
for (let child of node.childNodes){
|
|
85
|
-
if (child.type === 'cell' && rowHasCellWithColSpan) {
|
|
86
|
-
var _child_props1, _child_props2;
|
|
87
|
-
child.colspan = (_child_props1 = child.props) === null || _child_props1 === void 0 ? void 0 : _child_props1.colSpan;
|
|
88
|
-
child.colSpan = (_child_props2 = child.props) === null || _child_props2 === void 0 ? void 0 : _child_props2.colSpan;
|
|
89
|
-
var _last_colIndex, _last_colSpan;
|
|
90
|
-
child.colIndex = !last ? child.index : ((_last_colIndex = last.colIndex) !== null && _last_colIndex !== void 0 ? _last_colIndex : last.index) + ((_last_colSpan = last.colSpan) !== null && _last_colSpan !== void 0 ? _last_colSpan : 1);
|
|
91
|
-
}
|
|
92
|
-
if (child.type === 'cell' && child.parentKey == null) // if child is a cell parent key isn't already established by the collection, match child node to parent row
|
|
93
|
-
child.parentKey = node.key;
|
|
94
|
-
childKeys.add(child.key);
|
|
95
|
-
if (last) {
|
|
96
|
-
last.nextKey = child.key;
|
|
97
|
-
child.prevKey = last.key;
|
|
98
|
-
} else child.prevKey = null;
|
|
99
|
-
visit(child);
|
|
100
|
-
last = child;
|
|
101
|
-
}
|
|
102
|
-
if (last) last.nextKey = null;
|
|
103
|
-
// Remove deleted nodes and their children from the key map
|
|
104
|
-
if (prevNode) {
|
|
105
|
-
for (let child of prevNode.childNodes)if (!childKeys.has(child.key)) remove(child);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
let remove = (node)=>{
|
|
109
|
-
this.keyMap.delete(node.key);
|
|
110
|
-
for (let child of node.childNodes)if (this.keyMap.get(child.key) === child) remove(child);
|
|
111
|
-
};
|
|
112
|
-
let last = null;
|
|
113
|
-
for (let [i, node] of opts.items.entries()){
|
|
114
|
-
var _node_level, _node_key, _node_type, _node_value, _node_textValue, _node_index;
|
|
115
|
-
let rowNode = {
|
|
116
|
-
...node,
|
|
117
|
-
level: (_node_level = node.level) !== null && _node_level !== void 0 ? _node_level : 0,
|
|
118
|
-
key: (_node_key = node.key) !== null && _node_key !== void 0 ? _node_key : 'row-' + i,
|
|
119
|
-
type: (_node_type = node.type) !== null && _node_type !== void 0 ? _node_type : 'row',
|
|
120
|
-
value: (_node_value = node.value) !== null && _node_value !== void 0 ? _node_value : null,
|
|
121
|
-
hasChildNodes: true,
|
|
122
|
-
childNodes: [
|
|
123
|
-
...node.childNodes
|
|
124
|
-
],
|
|
125
|
-
rendered: node.rendered,
|
|
126
|
-
textValue: (_node_textValue = node.textValue) !== null && _node_textValue !== void 0 ? _node_textValue : '',
|
|
127
|
-
index: (_node_index = node.index) !== null && _node_index !== void 0 ? _node_index : i
|
|
128
|
-
};
|
|
129
|
-
if (last) {
|
|
130
|
-
last.nextKey = rowNode.key;
|
|
131
|
-
rowNode.prevKey = last.key;
|
|
132
|
-
} else rowNode.prevKey = null;
|
|
133
|
-
this.rows.push(rowNode);
|
|
134
|
-
visit(rowNode);
|
|
135
|
-
last = rowNode;
|
|
136
|
-
}
|
|
137
|
-
if (last) last.nextKey = null;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
export {$16805b1b18093c5f$export$de3fdf6493c353d as GridCollection};
|
|
143
|
-
//# sourceMappingURL=GridCollection.module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAAA;;;;;;;;;;CAUC,GAWM,MAAM;IAkHX,CAAC,CAAC,OAAO,QAAQ,CAAC,GAAkC;QAClD,OAAO;eAAI,IAAI,CAAC,IAAI;SAAC;IACvB;IAEA,IAAI,OAAe;QACjB,OAAO;eAAI,IAAI,CAAC,IAAI;SAAC,CAAC,MAAM;IAC9B;IAEA,UAAiC;QAC/B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB;IAEA,aAAa,GAAQ,EAAc;QACjC,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;YACb;QAAd,OAAO,OAAO,CAAA,gBAAA,KAAK,OAAO,cAAZ,2BAAA,gBAAgB,OAAO;IACvC;IAEA,YAAY,GAAQ,EAAc;QAChC,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;YACb;QAAd,OAAO,OAAO,CAAA,gBAAA,KAAK,OAAO,cAAZ,2BAAA,gBAAgB,OAAO;IACvC;IAEA,cAA0B;YACjB;QAAP,QAAO,IAAA;eAAI,IAAI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b;QAEA,IAAI,OAA2B;QAC/B,KAAK,IAAI,CAAC,GAAG,KAAK,IAAI,KAAK,KAAK,CAAC,OAAO,GAAI;gBAGjC,aACF,WACC,YACC,aAII,iBACJ;YAVT,IAAI,UAAuB;gBACzB,GAAG,IAAI;gBACP,OAAO,CAAA,cAAA,KAAK,KAAK,cAAV,yBAAA,cAAc;gBACrB,KAAK,CAAA,YAAA,KAAK,GAAG,cAAR,uBAAA,YAAY,SAAS;gBAC1B,MAAM,CAAA,aAAA,KAAK,IAAI,cAAT,wBAAA,aAAa;gBACnB,OAAO,CAAA,cAAA,KAAK,KAAK,cAAV,yBAAA,cAAc;gBACrB,eAAe;gBACf,YAAY;uBAAI,KAAK,UAAU;iBAAC;gBAChC,UAAU,KAAK,QAAQ;gBACvB,WAAW,CAAA,kBAAA,KAAK,SAAS,cAAd,6BAAA,kBAAkB;gBAC7B,OAAO,CAAA,cAAA,KAAK,KAAK,cAAV,yBAAA,cAAc;YACvB;YAEA,IAAI,MAAM;gBACR,KAAK,OAAO,GAAG,QAAQ,GAAG;gBAC1B,QAAQ,OAAO,GAAG,KAAK,GAAG;YAC5B,OACE,QAAQ,OAAO,GAAG;YAGpB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YACf,MAAM;YAEN,OAAO;QACT;QAEA,IAAI,MACF,KAAK,OAAO,GAAG;IAEnB;AA8CF","sources":["packages/@react-stately/grid/src/GridCollection.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 */\n\nimport {GridNode, GridRow, GridCollection as IGridCollection} from '@react-types/grid';\nimport {Key} from '@react-types/shared';\n\ninterface GridCollectionOptions<T> {\n columnCount: number,\n items: GridRow<T>[],\n visitNode?: (cell: GridNode<T>) => GridNode<T>\n}\n\nexport class GridCollection<T> implements IGridCollection<T> {\n keyMap: Map<Key, GridNode<T>> = new Map();\n columnCount: number;\n rows: GridNode<T>[];\n\n constructor(opts: GridCollectionOptions<T>) {\n this.keyMap = new Map();\n this.columnCount = opts?.columnCount;\n this.rows = [];\n\n let visit = (node: GridNode<T>) => {\n // If the node is the same object as the previous node for the same key,\n // we can skip this node and its children. We always visit columns though,\n // because we depend on order to build the columns array.\n let prevNode = this.keyMap.get(node.key);\n if (opts.visitNode) {\n node = opts.visitNode(node);\n }\n\n this.keyMap.set(node.key, node);\n\n let childKeys = new Set();\n let last: GridNode<T> | null = null;\n let rowHasCellWithColSpan = false;\n\n if (node.type === 'item') {\n for (let child of node.childNodes) {\n if (child.props?.colSpan !== undefined) {\n rowHasCellWithColSpan = true;\n break;\n }\n }\n }\n\n for (let child of node.childNodes as Iterable<GridNode<T>>) {\n if (child.type === 'cell' && rowHasCellWithColSpan) {\n child.colspan = child.props?.colSpan;\n child.colSpan = child.props?.colSpan;\n child.colIndex = !last ? child.index : (last.colIndex ?? last.index) + (last.colSpan ?? 1);\n }\n\n if (child.type === 'cell' && child.parentKey == null) {\n // if child is a cell parent key isn't already established by the collection, match child node to parent row\n child.parentKey = node.key;\n }\n childKeys.add(child.key);\n\n if (last) {\n last.nextKey = child.key;\n child.prevKey = last.key;\n } else {\n child.prevKey = null;\n }\n\n visit(child);\n last = child;\n }\n\n if (last) {\n last.nextKey = null;\n }\n\n // Remove deleted nodes and their children from the key map\n if (prevNode) {\n for (let child of prevNode.childNodes) {\n if (!childKeys.has(child.key)) {\n remove(child);\n }\n }\n }\n };\n\n let remove = (node: GridNode<T>) => {\n this.keyMap.delete(node.key);\n for (let child of node.childNodes) {\n if (this.keyMap.get(child.key) === child) {\n remove(child);\n }\n }\n };\n\n let last: GridNode<T> | null = null;\n for (let [i, node] of opts.items.entries()) {\n let rowNode: GridNode<T> = {\n ...node,\n level: node.level ?? 0,\n key: node.key ?? 'row-' + i,\n type: node.type ?? 'row',\n value: node.value ?? null,\n hasChildNodes: true,\n childNodes: [...node.childNodes],\n rendered: node.rendered,\n textValue: node.textValue ?? '',\n index: node.index ?? i\n };\n\n if (last) {\n last.nextKey = rowNode.key;\n rowNode.prevKey = last.key;\n } else {\n rowNode.prevKey = null;\n }\n\n this.rows.push(rowNode);\n visit(rowNode);\n\n last = rowNode;\n }\n\n if (last) {\n last.nextKey = null;\n }\n }\n\n *[Symbol.iterator](): IterableIterator<GridNode<T>> {\n yield* [...this.rows];\n }\n\n get size(): number {\n return [...this.rows].length;\n }\n\n getKeys(): IterableIterator<Key> {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key): Key | null {\n let node = this.keyMap.get(key);\n return node ? node.prevKey ?? null : null;\n }\n\n getKeyAfter(key: Key): Key | null {\n let node = this.keyMap.get(key);\n return node ? node.nextKey ?? null : null;\n }\n\n getFirstKey(): Key | null {\n return [...this.rows][0]?.key;\n }\n\n getLastKey(): Key | null {\n let rows = [...this.rows];\n return rows[rows.length - 1]?.key;\n }\n\n getItem(key: Key): GridNode<T> | null {\n return this.keyMap.get(key) ?? null;\n }\n\n at(idx: number): GridNode<T> | null {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n\n getChildren(key: Key): Iterable<GridNode<T>> {\n let node = this.keyMap.get(key);\n return node?.childNodes || [];\n }\n}\n"],"names":[],"version":3,"file":"GridCollection.module.js.map"}
|
package/dist/types.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { GridCollection as _GridCollection1, GridNode, GridRow } from "@react-types/grid";
|
|
2
|
-
import { Key } from "@react-types/shared";
|
|
3
|
-
import { MultipleSelectionState, MultipleSelectionStateProps, SelectionManager } from "@react-stately/selection";
|
|
4
|
-
export interface GridState<T, C extends _GridCollection1<T>> {
|
|
5
|
-
collection: C;
|
|
6
|
-
/** A set of keys for rows that are disabled. */
|
|
7
|
-
disabledKeys: Set<Key>;
|
|
8
|
-
/** A selection manager to read and update row selection state. */
|
|
9
|
-
selectionManager: SelectionManager;
|
|
10
|
-
/** Whether keyboard navigation is disabled, such as when the arrow keys should be handled by a component within a cell. */
|
|
11
|
-
isKeyboardNavigationDisabled: boolean;
|
|
12
|
-
}
|
|
13
|
-
export interface GridStateOptions<T, C extends _GridCollection1<T>> extends MultipleSelectionStateProps {
|
|
14
|
-
collection: C;
|
|
15
|
-
disabledKeys?: Iterable<Key>;
|
|
16
|
-
focusMode?: 'row' | 'cell';
|
|
17
|
-
/** @private - do not use unless you know what you're doing. */
|
|
18
|
-
UNSAFE_selectionState?: MultipleSelectionState;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Provides state management for a grid component. Handles row selection and focusing a grid cell's focusable child if applicable.
|
|
22
|
-
*/
|
|
23
|
-
export function useGridState<T extends object, C extends _GridCollection1<T>>(props: GridStateOptions<T, C>): GridState<T, C>;
|
|
24
|
-
interface GridCollectionOptions<T> {
|
|
25
|
-
columnCount: number;
|
|
26
|
-
items: GridRow<T>[];
|
|
27
|
-
visitNode?: (cell: GridNode<T>) => GridNode<T>;
|
|
28
|
-
}
|
|
29
|
-
export class GridCollection<T> implements _GridCollection1<T> {
|
|
30
|
-
keyMap: Map<Key, GridNode<T>>;
|
|
31
|
-
columnCount: number;
|
|
32
|
-
rows: GridNode<T>[];
|
|
33
|
-
constructor(opts: GridCollectionOptions<T>);
|
|
34
|
-
[Symbol.iterator](): IterableIterator<GridNode<T>>;
|
|
35
|
-
get size(): number;
|
|
36
|
-
getKeys(): IterableIterator<Key>;
|
|
37
|
-
getKeyBefore(key: Key): Key | null;
|
|
38
|
-
getKeyAfter(key: Key): Key | null;
|
|
39
|
-
getFirstKey(): Key | null;
|
|
40
|
-
getLastKey(): Key | null;
|
|
41
|
-
getItem(key: Key): GridNode<T> | null;
|
|
42
|
-
at(idx: number): GridN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,MAAM,CAAC;IACpB,IAAI,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC;gBAER,IAAI,EAAE,sBAAsB,CAAC,CAAC;IA6GzC,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC;IAInD,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,OAAO,IAAI,gBAAgB,CAAC,GAAG,CAAC;IAIhC,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI;IAKlC,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI;IAKjC,WAAW,IAAI,GAAG,GAAG,IAAI;IAIzB,UAAU,IAAI,GAAG,GAAG,IAAI;IAKxB,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,SAAS,CAAC,CAAC,GAAG,IAAI;IAIrC,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,GAAG,IAAI;IAKnC,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;CAI7C","sources":["packages/@react-stately/grid/src/packages/@react-stately/grid/src/useGridState.ts","packages/@react-stately/grid/src/packages/@react-stately/grid/src/GridCollection.ts","packages/@react-stately/grid/src/packages/@react-stately/grid/src/index.ts","packages/@react-stately/grid/src/index.ts"],"sourcesContent":[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 */\n\nexport {useGridState} from './useGridState';\nexport {GridCollection} from './GridCollection';\n\nexport type {GridStateOptions, GridState} from './useGridState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
var $5Cus8$reactstatelycollections = require("@react-stately/collections");
|
|
2
|
-
var $5Cus8$reactstatelyselection = require("@react-stately/selection");
|
|
3
|
-
var $5Cus8$react = require("react");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function $parcel$export(e, n, v, s) {
|
|
7
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
$parcel$export(module.exports, "useGridState", () => $38009b28e45912ea$export$4007ac09ff9c68ed);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function $38009b28e45912ea$export$4007ac09ff9c68ed(props) {
|
|
15
|
-
let { collection: collection, focusMode: focusMode } = props;
|
|
16
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
17
|
-
let selectionState = props.UNSAFE_selectionState || (0, $5Cus8$reactstatelyselection.useMultipleSelectionState)(props);
|
|
18
|
-
let disabledKeys = (0, $5Cus8$react.useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
|
|
19
|
-
props.disabledKeys
|
|
20
|
-
]);
|
|
21
|
-
let setFocusedKey = selectionState.setFocusedKey;
|
|
22
|
-
selectionState.setFocusedKey = (key, child)=>{
|
|
23
|
-
// If focusMode is cell and an item is focused, focus a child cell instead.
|
|
24
|
-
if (focusMode === 'cell' && key != null) {
|
|
25
|
-
let item = collection.getItem(key);
|
|
26
|
-
if ((item === null || item === void 0 ? void 0 : item.type) === 'item') {
|
|
27
|
-
var _getLastItem, _getFirstItem;
|
|
28
|
-
let children = (0, $5Cus8$reactstatelycollections.getChildNodes)(item, collection);
|
|
29
|
-
var _getLastItem_key, _getFirstItem_key;
|
|
30
|
-
if (child === 'last') key = (_getLastItem_key = (_getLastItem = (0, $5Cus8$reactstatelycollections.getLastItem)(children)) === null || _getLastItem === void 0 ? void 0 : _getLastItem.key) !== null && _getLastItem_key !== void 0 ? _getLastItem_key : null;
|
|
31
|
-
else key = (_getFirstItem_key = (_getFirstItem = (0, $5Cus8$reactstatelycollections.getFirstItem)(children)) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key) !== null && _getFirstItem_key !== void 0 ? _getFirstItem_key : null;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
setFocusedKey(key, child);
|
|
35
|
-
};
|
|
36
|
-
let selectionManager = (0, $5Cus8$react.useMemo)(()=>new (0, $5Cus8$reactstatelyselection.SelectionManager)(collection, selectionState), [
|
|
37
|
-
collection,
|
|
38
|
-
selectionState
|
|
39
|
-
]);
|
|
40
|
-
// Reset focused key if that item is deleted from the collection.
|
|
41
|
-
const cachedCollection = (0, $5Cus8$react.useRef)(null);
|
|
42
|
-
(0, $5Cus8$react.useEffect)(()=>{
|
|
43
|
-
if (selectionState.focusedKey != null && cachedCollection.current && !collection.getItem(selectionState.focusedKey)) {
|
|
44
|
-
const node = cachedCollection.current.getItem(selectionState.focusedKey);
|
|
45
|
-
const parentNode = (node === null || node === void 0 ? void 0 : node.parentKey) != null && (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column') ? cachedCollection.current.getItem(node.parentKey) : node;
|
|
46
|
-
if (!parentNode) {
|
|
47
|
-
selectionState.setFocusedKey(null);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const cachedRows = cachedCollection.current.rows;
|
|
51
|
-
const rows = collection.rows;
|
|
52
|
-
const diff = cachedRows.length - rows.length;
|
|
53
|
-
let index = Math.min(diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index, rows.length - 1);
|
|
54
|
-
let newRow = null;
|
|
55
|
-
while(index >= 0){
|
|
56
|
-
if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') {
|
|
57
|
-
newRow = rows[index];
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
// Find next, not disabled row.
|
|
61
|
-
if (index < rows.length - 1) index++;
|
|
62
|
-
else {
|
|
63
|
-
if (index > parentNode.index) index = parentNode.index;
|
|
64
|
-
index--;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (newRow) {
|
|
68
|
-
const childNodes = newRow.hasChildNodes ? [
|
|
69
|
-
...(0, $5Cus8$reactstatelycollections.getChildNodes)(newRow, collection)
|
|
70
|
-
] : [];
|
|
71
|
-
const keyToFocus = newRow.hasChildNodes && parentNode !== node && node && node.index < childNodes.length ? childNodes[node.index].key : newRow.key;
|
|
72
|
-
selectionState.setFocusedKey(keyToFocus);
|
|
73
|
-
} else selectionState.setFocusedKey(null);
|
|
74
|
-
}
|
|
75
|
-
cachedCollection.current = collection;
|
|
76
|
-
}, [
|
|
77
|
-
collection,
|
|
78
|
-
selectionManager,
|
|
79
|
-
selectionState,
|
|
80
|
-
selectionState.focusedKey
|
|
81
|
-
]);
|
|
82
|
-
return {
|
|
83
|
-
collection: collection,
|
|
84
|
-
disabledKeys: disabledKeys,
|
|
85
|
-
isKeyboardNavigationDisabled: false,
|
|
86
|
-
selectionManager: selectionManager
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
//# sourceMappingURL=useGridState.main.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;AA2BO,SAAS,0CAA4D,KAA6B;IACvG,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG;IAC9B,sDAAsD;IACtD,IAAI,iBAAiB,MAAM,qBAAqB,IAAI,CAAA,GAAA,sDAAwB,EAAE;IAC9E,IAAI,eAAe,CAAA,GAAA,oBAAM,EAAE,IACvB,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,IAAI,OACvD;QAAC,MAAM,YAAY;KAAC;IAExB,IAAI,gBAAgB,eAAe,aAAa;IAChD,eAAe,aAAa,GAAG,CAAC,KAAK;QACnC,2EAA2E;QAC3E,IAAI,cAAc,UAAU,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AQ,KAAK,GAAG,CAEhB,OAAO,IACP,KAAK,GAAG,CAAC,WAAW,KAAK,GAAG,OAAO,GAAG,KACtC,WAAW,KAAK,EAElB,KAAK,MAAM,GAAG;YAChB,IAAI,SAA6B;YACjC,MAAO,SAAS,EAAG;gBACjB,IAAI,CAAC,iBAAiB,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,KAAK,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,aAAa;oBACrF,SAAS,IAAI,CAAC,MAAM;oBACpB;gBACF;gBACA,+BAA+B;gBAC/B,IAAI,QAAQ,KAAK,MAAM,GAAG,GACxB;qBAEK;oBACL,IAAI,QAAQ,WAAW,KAAK,EAC1B,QAAQ,WAAW,KAAK;oBAE1B;gBACF;YACF;YACA,IAAI,QAAQ;gBACV,MAAM,aAAa,OAAO,aAAa,GAAG;uBAAI,CAAA,GAAA,4CAAY,EAAE,QAAQ;iBAAY,GAAG,EAAE;gBACrF,MAAM,aACJ,OAAO,aAAa,IACpB,eAAe,QACf,QACA,KAAK,KAAK,GAAG,WAAW,MAAM,GAC9B,UAAU,CAAC,KAAK,KAAK,CAAC,CAAC,GAAG,GAC1B,OAAO,GAAG;gBACZ,eAAe,aAAa,CAAC;YAC/B,OACE,eAAe,aAAa,CAAC;QAEjC;QACA,iBAAiB,OAAO,GAAG;IAC7B,GAAG;QAAC;QAAY;QAAkB;QAAgB,eAAe,UAAU;KAAC;IAE5E,OAAO;oBACL;sBACA;QACA,8BAA8B;0BAC9B;IACF;AACF","sources":["packages/@react-stately/grid/src/useGridState.ts"],"sourcesContent":["import {getChildNodes, getFirstItem, getLastItem} from '@react-stately/collections';\nimport {GridCollection, GridNode} from '@react-types/grid';\nimport {Key} from '@react-types/shared';\nimport {MultipleSelectionState, MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {useEffect, useMemo, useRef} from 'react';\n\nexport interface GridState<T, C extends GridCollection<T>> {\n collection: C,\n /** A set of keys for rows that are disabled. */\n disabledKeys: Set<Key>,\n /** A selection manager to read and update row selection state. */\n selectionManager: SelectionManager,\n /** Whether keyboard navigation is disabled, such as when the arrow keys should be handled by a component within a cell. */\n isKeyboardNavigationDisabled: boolean\n}\n\nexport interface GridStateOptions<T, C extends GridCollection<T>> extends MultipleSelectionStateProps {\n collection: C,\n disabledKeys?: Iterable<Key>,\n focusMode?: 'row' | 'cell',\n /** @private - do not use unless you know what you're doing. */\n UNSAFE_selectionState?: MultipleSelectionState\n}\n\n/**\n * Provides state management for a grid component. Handles row selection and focusing a grid cell's focusable child if applicable.\n */\nexport function useGridState<T extends object, C extends GridCollection<T>>(props: GridStateOptions<T, C>): GridState<T, C> {\n let {collection, focusMode} = props;\n // eslint-disable-next-line react-hooks/rules-of-hooks\n let selectionState = props.UNSAFE_selectionState || useMultipleSelectionState(props);\n let disabledKeys = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n let setFocusedKey = selectionState.setFocusedKey;\n selectionState.setFocusedKey = (key, child) => {\n // If focusMode is cell and an item is focused, focus a child cell instead.\n if (focusMode === 'cell' && key != null) {\n let item = collection.getItem(key);\n if (item?.type === 'item') {\n let children = getChildNodes(item, collection);\n if (child === 'last') {\n key = getLastItem(children)?.key ?? null;\n } else {\n key = getFirstItem(children)?.key ?? null;\n }\n }\n }\n\n setFocusedKey(key, child);\n };\n\n let selectionManager = useMemo(() =>\n new SelectionManager(collection, selectionState)\n , [collection, selectionState]\n );\n\n // Reset focused key if that item is deleted from the collection.\n const cachedCollection = useRef<C | null>(null);\n useEffect(() => {\n if (selectionState.focusedKey != null && cachedCollection.current && !collection.getItem(selectionState.focusedKey)) {\n const node = cachedCollection.current.getItem(selectionState.focusedKey);\n const parentNode =\n node?.parentKey != null && (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column') ?\n cachedCollection.current.getItem(node.parentKey) :\n node;\n if (!parentNode) {\n selectionState.setFocusedKey(null);\n return;\n }\n const cachedRows = cachedCollection.current.rows;\n const rows = collection.rows;\n const diff = cachedRows.length - rows.length;\n let index = Math.min(\n (\n diff > 1 ?\n Math.max(parentNode.index - diff + 1, 0) :\n parentNode.index\n ),\n rows.length - 1);\n let newRow: GridNode<T> | null = null;\n while (index >= 0) {\n if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') {\n newRow = rows[index];\n break;\n }\n // Find next, not disabled row.\n if (index < rows.length - 1) {\n index++;\n // Otherwise, find previous, not disabled row.\n } else {\n if (index > parentNode.index) {\n index = parentNode.index;\n }\n index--;\n }\n }\n if (newRow) {\n const childNodes = newRow.hasChildNodes ? [...getChildNodes(newRow, collection)] : [];\n const keyToFocus =\n newRow.hasChildNodes &&\n parentNode !== node &&\n node &&\n node.index < childNodes.length ?\n childNodes[node.index].key :\n newRow.key;\n selectionState.setFocusedKey(keyToFocus);\n } else {\n selectionState.setFocusedKey(null);\n }\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager, selectionState, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n isKeyboardNavigationDisabled: false,\n selectionManager\n };\n}\n"],"names":[],"version":3,"file":"useGridState.main.js.map"}
|
package/dist/useGridState.mjs
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import {getChildNodes as $7nPCv$getChildNodes, getLastItem as $7nPCv$getLastItem, getFirstItem as $7nPCv$getFirstItem} from "@react-stately/collections";
|
|
2
|
-
import {useMultipleSelectionState as $7nPCv$useMultipleSelectionState, SelectionManager as $7nPCv$SelectionManager} from "@react-stately/selection";
|
|
3
|
-
import {useMemo as $7nPCv$useMemo, useRef as $7nPCv$useRef, useEffect as $7nPCv$useEffect} from "react";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function $62967d126f3aa823$export$4007ac09ff9c68ed(props) {
|
|
9
|
-
let { collection: collection, focusMode: focusMode } = props;
|
|
10
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
11
|
-
let selectionState = props.UNSAFE_selectionState || (0, $7nPCv$useMultipleSelectionState)(props);
|
|
12
|
-
let disabledKeys = (0, $7nPCv$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
|
|
13
|
-
props.disabledKeys
|
|
14
|
-
]);
|
|
15
|
-
let setFocusedKey = selectionState.setFocusedKey;
|
|
16
|
-
selectionState.setFocusedKey = (key, child)=>{
|
|
17
|
-
// If focusMode is cell and an item is focused, focus a child cell instead.
|
|
18
|
-
if (focusMode === 'cell' && key != null) {
|
|
19
|
-
let item = collection.getItem(key);
|
|
20
|
-
if ((item === null || item === void 0 ? void 0 : item.type) === 'item') {
|
|
21
|
-
var _getLastItem, _getFirstItem;
|
|
22
|
-
let children = (0, $7nPCv$getChildNodes)(item, collection);
|
|
23
|
-
var _getLastItem_key, _getFirstItem_key;
|
|
24
|
-
if (child === 'last') key = (_getLastItem_key = (_getLastItem = (0, $7nPCv$getLastItem)(children)) === null || _getLastItem === void 0 ? void 0 : _getLastItem.key) !== null && _getLastItem_key !== void 0 ? _getLastItem_key : null;
|
|
25
|
-
else key = (_getFirstItem_key = (_getFirstItem = (0, $7nPCv$getFirstItem)(children)) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key) !== null && _getFirstItem_key !== void 0 ? _getFirstItem_key : null;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
setFocusedKey(key, child);
|
|
29
|
-
};
|
|
30
|
-
let selectionManager = (0, $7nPCv$useMemo)(()=>new (0, $7nPCv$SelectionManager)(collection, selectionState), [
|
|
31
|
-
collection,
|
|
32
|
-
selectionState
|
|
33
|
-
]);
|
|
34
|
-
// Reset focused key if that item is deleted from the collection.
|
|
35
|
-
const cachedCollection = (0, $7nPCv$useRef)(null);
|
|
36
|
-
(0, $7nPCv$useEffect)(()=>{
|
|
37
|
-
if (selectionState.focusedKey != null && cachedCollection.current && !collection.getItem(selectionState.focusedKey)) {
|
|
38
|
-
const node = cachedCollection.current.getItem(selectionState.focusedKey);
|
|
39
|
-
const parentNode = (node === null || node === void 0 ? void 0 : node.parentKey) != null && (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column') ? cachedCollection.current.getItem(node.parentKey) : node;
|
|
40
|
-
if (!parentNode) {
|
|
41
|
-
selectionState.setFocusedKey(null);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const cachedRows = cachedCollection.current.rows;
|
|
45
|
-
const rows = collection.rows;
|
|
46
|
-
const diff = cachedRows.length - rows.length;
|
|
47
|
-
let index = Math.min(diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index, rows.length - 1);
|
|
48
|
-
let newRow = null;
|
|
49
|
-
while(index >= 0){
|
|
50
|
-
if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') {
|
|
51
|
-
newRow = rows[index];
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
// Find next, not disabled row.
|
|
55
|
-
if (index < rows.length - 1) index++;
|
|
56
|
-
else {
|
|
57
|
-
if (index > parentNode.index) index = parentNode.index;
|
|
58
|
-
index--;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (newRow) {
|
|
62
|
-
const childNodes = newRow.hasChildNodes ? [
|
|
63
|
-
...(0, $7nPCv$getChildNodes)(newRow, collection)
|
|
64
|
-
] : [];
|
|
65
|
-
const keyToFocus = newRow.hasChildNodes && parentNode !== node && node && node.index < childNodes.length ? childNodes[node.index].key : newRow.key;
|
|
66
|
-
selectionState.setFocusedKey(keyToFocus);
|
|
67
|
-
} else selectionState.setFocusedKey(null);
|
|
68
|
-
}
|
|
69
|
-
cachedCollection.current = collection;
|
|
70
|
-
}, [
|
|
71
|
-
collection,
|
|
72
|
-
selectionManager,
|
|
73
|
-
selectionState,
|
|
74
|
-
selectionState.focusedKey
|
|
75
|
-
]);
|
|
76
|
-
return {
|
|
77
|
-
collection: collection,
|
|
78
|
-
disabledKeys: disabledKeys,
|
|
79
|
-
isKeyboardNavigationDisabled: false,
|
|
80
|
-
selectionManager: selectionManager
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
export {$62967d126f3aa823$export$4007ac09ff9c68ed as useGridState};
|
|
86
|
-
//# sourceMappingURL=useGridState.module.js.map
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import {getChildNodes as $7nPCv$getChildNodes, getLastItem as $7nPCv$getLastItem, getFirstItem as $7nPCv$getFirstItem} from "@react-stately/collections";
|
|
2
|
-
import {useMultipleSelectionState as $7nPCv$useMultipleSelectionState, SelectionManager as $7nPCv$SelectionManager} from "@react-stately/selection";
|
|
3
|
-
import {useMemo as $7nPCv$useMemo, useRef as $7nPCv$useRef, useEffect as $7nPCv$useEffect} from "react";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function $62967d126f3aa823$export$4007ac09ff9c68ed(props) {
|
|
9
|
-
let { collection: collection, focusMode: focusMode } = props;
|
|
10
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
11
|
-
let selectionState = props.UNSAFE_selectionState || (0, $7nPCv$useMultipleSelectionState)(props);
|
|
12
|
-
let disabledKeys = (0, $7nPCv$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
|
|
13
|
-
props.disabledKeys
|
|
14
|
-
]);
|
|
15
|
-
let setFocusedKey = selectionState.setFocusedKey;
|
|
16
|
-
selectionState.setFocusedKey = (key, child)=>{
|
|
17
|
-
// If focusMode is cell and an item is focused, focus a child cell instead.
|
|
18
|
-
if (focusMode === 'cell' && key != null) {
|
|
19
|
-
let item = collection.getItem(key);
|
|
20
|
-
if ((item === null || item === void 0 ? void 0 : item.type) === 'item') {
|
|
21
|
-
var _getLastItem, _getFirstItem;
|
|
22
|
-
let children = (0, $7nPCv$getChildNodes)(item, collection);
|
|
23
|
-
var _getLastItem_key, _getFirstItem_key;
|
|
24
|
-
if (child === 'last') key = (_getLastItem_key = (_getLastItem = (0, $7nPCv$getLastItem)(children)) === null || _getLastItem === void 0 ? void 0 : _getLastItem.key) !== null && _getLastItem_key !== void 0 ? _getLastItem_key : null;
|
|
25
|
-
else key = (_getFirstItem_key = (_getFirstItem = (0, $7nPCv$getFirstItem)(children)) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key) !== null && _getFirstItem_key !== void 0 ? _getFirstItem_key : null;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
setFocusedKey(key, child);
|
|
29
|
-
};
|
|
30
|
-
let selectionManager = (0, $7nPCv$useMemo)(()=>new (0, $7nPCv$SelectionManager)(collection, selectionState), [
|
|
31
|
-
collection,
|
|
32
|
-
selectionState
|
|
33
|
-
]);
|
|
34
|
-
// Reset focused key if that item is deleted from the collection.
|
|
35
|
-
const cachedCollection = (0, $7nPCv$useRef)(null);
|
|
36
|
-
(0, $7nPCv$useEffect)(()=>{
|
|
37
|
-
if (selectionState.focusedKey != null && cachedCollection.current && !collection.getItem(selectionState.focusedKey)) {
|
|
38
|
-
const node = cachedCollection.current.getItem(selectionState.focusedKey);
|
|
39
|
-
const parentNode = (node === null || node === void 0 ? void 0 : node.parentKey) != null && (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column') ? cachedCollection.current.getItem(node.parentKey) : node;
|
|
40
|
-
if (!parentNode) {
|
|
41
|
-
selectionState.setFocusedKey(null);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const cachedRows = cachedCollection.current.rows;
|
|
45
|
-
const rows = collection.rows;
|
|
46
|
-
const diff = cachedRows.length - rows.length;
|
|
47
|
-
let index = Math.min(diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index, rows.length - 1);
|
|
48
|
-
let newRow = null;
|
|
49
|
-
while(index >= 0){
|
|
50
|
-
if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') {
|
|
51
|
-
newRow = rows[index];
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
// Find next, not disabled row.
|
|
55
|
-
if (index < rows.length - 1) index++;
|
|
56
|
-
else {
|
|
57
|
-
if (index > parentNode.index) index = parentNode.index;
|
|
58
|
-
index--;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (newRow) {
|
|
62
|
-
const childNodes = newRow.hasChildNodes ? [
|
|
63
|
-
...(0, $7nPCv$getChildNodes)(newRow, collection)
|
|
64
|
-
] : [];
|
|
65
|
-
const keyToFocus = newRow.hasChildNodes && parentNode !== node && node && node.index < childNodes.length ? childNodes[node.index].key : newRow.key;
|
|
66
|
-
selectionState.setFocusedKey(keyToFocus);
|
|
67
|
-
} else selectionState.setFocusedKey(null);
|
|
68
|
-
}
|
|
69
|
-
cachedCollection.current = collection;
|
|
70
|
-
}, [
|
|
71
|
-
collection,
|
|
72
|
-
selectionManager,
|
|
73
|
-
selectionState,
|
|
74
|
-
selectionState.focusedKey
|
|
75
|
-
]);
|
|
76
|
-
return {
|
|
77
|
-
collection: collection,
|
|
78
|
-
disabledKeys: disabledKeys,
|
|
79
|
-
isKeyboardNavigationDisabled: false,
|
|
80
|
-
selectionManager: selectionManager
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
export {$62967d126f3aa823$export$4007ac09ff9c68ed as useGridState};
|
|
86
|
-
//# sourceMappingURL=useGridState.module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;;AA2BO,SAAS,0CAA4D,KAA6B;IACvG,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG;IAC9B,sDAAsD;IACtD,IAAI,iBAAiB,MAAM,qBAAqB,IAAI,CAAA,GAAA,gCAAwB,EAAE;IAC9E,IAAI,eAAe,CAAA,GAAA,cAAM,EAAE,IACvB,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,IAAI,OACvD;QAAC,MAAM,YAAY;KAAC;IAExB,IAAI,gBAAgB,eAAe,aAAa;IAChD,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I;YAC5B,MAAM,OAAO,WAAW,MAAM,GAAG,KAAK,MAAM;YAC5C,IAAI,QAAQ,KAAK,GAAG,CAEhB,OAAO,IACP,KAAK,GAAG,CAAC,WAAW,KAAK,GAAG,OAAO,GAAG,KACtC,WAAW,KAAK,EAElB,KAAK,MAAM,GAAG;YAChB,IAAI,SAA6B;YACjC,MAAO,SAAS,EAAG;gBACjB,IAAI,CAAC,iBAAiB,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,KAAK,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,aAAa;oBACrF,SAAS,IAAI,CAAC,MAAM;oBACpB;gBACF;gBACA,+BAA+B;gBAC/B,IAAI,QAAQ,KAAK,MAAM,GAAG,GACxB;qBAEK;oBACL,IAAI,QAAQ,WAAW,KAAK,EAC1B,QAAQ,WAAW,KAAK;oBAE1B;gBACF;YACF;YACA,IAAI,QAAQ;gBACV,MAAM,aAAa,OAAO,aAAa,GAAG;uBAAI,CAAA,GAAA,oBAAY,EAAE,QAAQ;iBAAY,GAAG,EAAE;gBACrF,MAAM,aACJ,OAAO,aAAa,IACpB,eAAe,QACf,QACA,KAAK,KAAK,GAAG,WAAW,MAAM,GAC9B,UAAU,CAAC,KAAK,KAAK,CAAC,CAAC,GAAG,GAC1B,OAAO,GAAG;gBACZ,eAAe,aAAa,CAAC;YAC/B,OACE,eAAe,aAAa,CAAC;QAEjC;QACA,iBAAiB,OAAO,GAAG;IAC7B,GAAG;QAAC;QAAY;QAAkB;QAAgB,eAAe,UAAU;KAAC;IAE5E,OAAO;oBACL;sBACA;QACA,8BAA8B;0BAC9B;IACF;AACF","sources":["packages/@react-stately/grid/src/useGridState.ts"],"sourcesContent":["import {getChildNodes, getFirstItem, getLastItem} from '@react-stately/collections';\nimport {GridCollection, GridNode} from '@react-types/grid';\nimport {Key} from '@react-types/shared';\nimport {MultipleSelectionState, MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {useEffect, useMemo, useRef} from 'react';\n\nexport interface GridState<T, C extends GridCollection<T>> {\n collection: C,\n /** A set of keys for rows that are disabled. */\n disabledKeys: Set<Key>,\n /** A selection manager to read and update row selection state. */\n selectionManager: SelectionManager,\n /** Whether keyboard navigation is disabled, such as when the arrow keys should be handled by a component within a cell. */\n isKeyboardNavigationDisabled: boolean\n}\n\nexport interface GridStateOptions<T, C extends GridCollection<T>> extends MultipleSelectionStateProps {\n collection: C,\n disabledKeys?: Iterable<Key>,\n focusMode?: 'row' | 'cell',\n /** @private - do not use unless you know what you're doing. */\n UNSAFE_selectionState?: MultipleSelectionState\n}\n\n/**\n * Provides state management for a grid component. Handles row selection and focusing a grid cell's focusable child if applicable.\n */\nexport function useGridState<T extends object, C extends GridCollection<T>>(props: GridStateOptions<T, C>): GridState<T, C> {\n let {collection, focusMode} = props;\n // eslint-disable-next-line react-hooks/rules-of-hooks\n let selectionState = props.UNSAFE_selectionState || useMultipleSelectionState(props);\n let disabledKeys = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n let setFocusedKey = selectionState.setFocusedKey;\n selectionState.setFocusedKey = (key, child) => {\n // If focusMode is cell and an item is focused, focus a child cell instead.\n if (focusMode === 'cell' && key != null) {\n let item = collection.getItem(key);\n if (item?.type === 'item') {\n let children = getChildNodes(item, collection);\n if (child === 'last') {\n key = getLastItem(children)?.key ?? null;\n } else {\n key = getFirstItem(children)?.key ?? null;\n }\n }\n }\n\n setFocusedKey(key, child);\n };\n\n let selectionManager = useMemo(() =>\n new SelectionManager(collection, selectionState)\n , [collection, selectionState]\n );\n\n // Reset focused key if that item is deleted from the collection.\n const cachedCollection = useRef<C | null>(null);\n useEffect(() => {\n if (selectionState.focusedKey != null && cachedCollection.current && !collection.getItem(selectionState.focusedKey)) {\n const node = cachedCollection.current.getItem(selectionState.focusedKey);\n const parentNode =\n node?.parentKey != null && (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column') ?\n cachedCollection.current.getItem(node.parentKey) :\n node;\n if (!parentNode) {\n selectionState.setFocusedKey(null);\n return;\n }\n const cachedRows = cachedCollection.current.rows;\n const rows = collection.rows;\n const diff = cachedRows.length - rows.length;\n let index = Math.min(\n (\n diff > 1 ?\n Math.max(parentNode.index - diff + 1, 0) :\n parentNode.index\n ),\n rows.length - 1);\n let newRow: GridNode<T> | null = null;\n while (index >= 0) {\n if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') {\n newRow = rows[index];\n break;\n }\n // Find next, not disabled row.\n if (index < rows.length - 1) {\n index++;\n // Otherwise, find previous, not disabled row.\n } else {\n if (index > parentNode.index) {\n index = parentNode.index;\n }\n index--;\n }\n }\n if (newRow) {\n const childNodes = newRow.hasChildNodes ? [...getChildNodes(newRow, collection)] : [];\n const keyToFocus =\n newRow.hasChildNodes &&\n parentNode !== node &&\n node &&\n node.index < childNodes.length ?\n childNodes[node.index].key :\n newRow.key;\n selectionState.setFocusedKey(keyToFocus);\n } else {\n selectionState.setFocusedKey(null);\n }\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager, selectionState, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n isKeyboardNavigationDisabled: false,\n selectionManager\n };\n}\n"],"names":[],"version":3,"file":"useGridState.module.js.map"}
|
package/src/GridCollection.ts
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 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 {GridNode, GridRow, GridCollection as IGridCollection} from '@react-types/grid';
|
|
14
|
-
import {Key} from '@react-types/shared';
|
|
15
|
-
|
|
16
|
-
interface GridCollectionOptions<T> {
|
|
17
|
-
columnCount: number,
|
|
18
|
-
items: GridRow<T>[],
|
|
19
|
-
visitNode?: (cell: GridNode<T>) => GridNode<T>
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class GridCollection<T> implements IGridCollection<T> {
|
|
23
|
-
keyMap: Map<Key, GridNode<T>> = new Map();
|
|
24
|
-
columnCount: number;
|
|
25
|
-
rows: GridNode<T>[];
|
|
26
|
-
|
|
27
|
-
constructor(opts: GridCollectionOptions<T>) {
|
|
28
|
-
this.keyMap = new Map();
|
|
29
|
-
this.columnCount = opts?.columnCount;
|
|
30
|
-
this.rows = [];
|
|
31
|
-
|
|
32
|
-
let visit = (node: GridNode<T>) => {
|
|
33
|
-
// If the node is the same object as the previous node for the same key,
|
|
34
|
-
// we can skip this node and its children. We always visit columns though,
|
|
35
|
-
// because we depend on order to build the columns array.
|
|
36
|
-
let prevNode = this.keyMap.get(node.key);
|
|
37
|
-
if (opts.visitNode) {
|
|
38
|
-
node = opts.visitNode(node);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
this.keyMap.set(node.key, node);
|
|
42
|
-
|
|
43
|
-
let childKeys = new Set();
|
|
44
|
-
let last: GridNode<T> | null = null;
|
|
45
|
-
let rowHasCellWithColSpan = false;
|
|
46
|
-
|
|
47
|
-
if (node.type === 'item') {
|
|
48
|
-
for (let child of node.childNodes) {
|
|
49
|
-
if (child.props?.colSpan !== undefined) {
|
|
50
|
-
rowHasCellWithColSpan = true;
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
for (let child of node.childNodes as Iterable<GridNode<T>>) {
|
|
57
|
-
if (child.type === 'cell' && rowHasCellWithColSpan) {
|
|
58
|
-
child.colspan = child.props?.colSpan;
|
|
59
|
-
child.colSpan = child.props?.colSpan;
|
|
60
|
-
child.colIndex = !last ? child.index : (last.colIndex ?? last.index) + (last.colSpan ?? 1);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (child.type === 'cell' && child.parentKey == null) {
|
|
64
|
-
// if child is a cell parent key isn't already established by the collection, match child node to parent row
|
|
65
|
-
child.parentKey = node.key;
|
|
66
|
-
}
|
|
67
|
-
childKeys.add(child.key);
|
|
68
|
-
|
|
69
|
-
if (last) {
|
|
70
|
-
last.nextKey = child.key;
|
|
71
|
-
child.prevKey = last.key;
|
|
72
|
-
} else {
|
|
73
|
-
child.prevKey = null;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
visit(child);
|
|
77
|
-
last = child;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (last) {
|
|
81
|
-
last.nextKey = null;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Remove deleted nodes and their children from the key map
|
|
85
|
-
if (prevNode) {
|
|
86
|
-
for (let child of prevNode.childNodes) {
|
|
87
|
-
if (!childKeys.has(child.key)) {
|
|
88
|
-
remove(child);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
let remove = (node: GridNode<T>) => {
|
|
95
|
-
this.keyMap.delete(node.key);
|
|
96
|
-
for (let child of node.childNodes) {
|
|
97
|
-
if (this.keyMap.get(child.key) === child) {
|
|
98
|
-
remove(child);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
let last: GridNode<T> | null = null;
|
|
104
|
-
for (let [i, node] of opts.items.entries()) {
|
|
105
|
-
let rowNode: GridNode<T> = {
|
|
106
|
-
...node,
|
|
107
|
-
level: node.level ?? 0,
|
|
108
|
-
key: node.key ?? 'row-' + i,
|
|
109
|
-
type: node.type ?? 'row',
|
|
110
|
-
value: node.value ?? null,
|
|
111
|
-
hasChildNodes: true,
|
|
112
|
-
childNodes: [...node.childNodes],
|
|
113
|
-
rendered: node.rendered,
|
|
114
|
-
textValue: node.textValue ?? '',
|
|
115
|
-
index: node.index ?? i
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
if (last) {
|
|
119
|
-
last.nextKey = rowNode.key;
|
|
120
|
-
rowNode.prevKey = last.key;
|
|
121
|
-
} else {
|
|
122
|
-
rowNode.prevKey = null;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
this.rows.push(rowNode);
|
|
126
|
-
visit(rowNode);
|
|
127
|
-
|
|
128
|
-
last = rowNode;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (last) {
|
|
132
|
-
last.nextKey = null;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
*[Symbol.iterator](): IterableIterator<GridNode<T>> {
|
|
137
|
-
yield* [...this.rows];
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
get size(): number {
|
|
141
|
-
return [...this.rows].length;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
getKeys(): IterableIterator<Key> {
|
|
145
|
-
return this.keyMap.keys();
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
getKeyBefore(key: Key): Key | null {
|
|
149
|
-
let node = this.keyMap.get(key);
|
|
150
|
-
return node ? node.prevKey ?? null : null;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
getKeyAfter(key: Key): Key | null {
|
|
154
|
-
let node = this.keyMap.get(key);
|
|
155
|
-
return node ? node.nextKey ?? null : null;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
getFirstKey(): Key | null {
|
|
159
|
-
return [...this.rows][0]?.key;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
getLastKey(): Key | null {
|
|
163
|
-
let rows = [...this.rows];
|
|
164
|
-
return rows[rows.length - 1]?.key;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
getItem(key: Key): GridNode<T> | null {
|
|
168
|
-
return this.keyMap.get(key) ?? null;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
at(idx: number): GridNode<T> | null {
|
|
172
|
-
const keys = [...this.getKeys()];
|
|
173
|
-
return this.getItem(keys[idx]);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
getChildren(key: Key): Iterable<GridNode<T>> {
|
|
177
|
-
let node = this.keyMap.get(key);
|
|
178
|
-
return node?.childNodes || [];
|
|
179
|
-
}
|
|
180
|
-
}
|
package/src/useGridState.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import {getChildNodes, getFirstItem, getLastItem} from '@react-stately/collections';
|
|
2
|
-
import {GridCollection, GridNode} from '@react-types/grid';
|
|
3
|
-
import {Key} from '@react-types/shared';
|
|
4
|
-
import {MultipleSelectionState, MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';
|
|
5
|
-
import {useEffect, useMemo, useRef} from 'react';
|
|
6
|
-
|
|
7
|
-
export interface GridState<T, C extends GridCollection<T>> {
|
|
8
|
-
collection: C,
|
|
9
|
-
/** A set of keys for rows that are disabled. */
|
|
10
|
-
disabledKeys: Set<Key>,
|
|
11
|
-
/** A selection manager to read and update row selection state. */
|
|
12
|
-
selectionManager: SelectionManager,
|
|
13
|
-
/** Whether keyboard navigation is disabled, such as when the arrow keys should be handled by a component within a cell. */
|
|
14
|
-
isKeyboardNavigationDisabled: boolean
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface GridStateOptions<T, C extends GridCollection<T>> extends MultipleSelectionStateProps {
|
|
18
|
-
collection: C,
|
|
19
|
-
disabledKeys?: Iterable<Key>,
|
|
20
|
-
focusMode?: 'row' | 'cell',
|
|
21
|
-
/** @private - do not use unless you know what you're doing. */
|
|
22
|
-
UNSAFE_selectionState?: MultipleSelectionState
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Provides state management for a grid component. Handles row selection and focusing a grid cell's focusable child if applicable.
|
|
27
|
-
*/
|
|
28
|
-
export function useGridState<T extends object, C extends GridCollection<T>>(props: GridStateOptions<T, C>): GridState<T, C> {
|
|
29
|
-
let {collection, focusMode} = props;
|
|
30
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
31
|
-
let selectionState = props.UNSAFE_selectionState || useMultipleSelectionState(props);
|
|
32
|
-
let disabledKeys = useMemo(() =>
|
|
33
|
-
props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()
|
|
34
|
-
, [props.disabledKeys]);
|
|
35
|
-
|
|
36
|
-
let setFocusedKey = selectionState.setFocusedKey;
|
|
37
|
-
selectionState.setFocusedKey = (key, child) => {
|
|
38
|
-
// If focusMode is cell and an item is focused, focus a child cell instead.
|
|
39
|
-
if (focusMode === 'cell' && key != null) {
|
|
40
|
-
let item = collection.getItem(key);
|
|
41
|
-
if (item?.type === 'item') {
|
|
42
|
-
let children = getChildNodes(item, collection);
|
|
43
|
-
if (child === 'last') {
|
|
44
|
-
key = getLastItem(children)?.key ?? null;
|
|
45
|
-
} else {
|
|
46
|
-
key = getFirstItem(children)?.key ?? null;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
setFocusedKey(key, child);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
let selectionManager = useMemo(() =>
|
|
55
|
-
new SelectionManager(collection, selectionState)
|
|
56
|
-
, [collection, selectionState]
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
// Reset focused key if that item is deleted from the collection.
|
|
60
|
-
const cachedCollection = useRef<C | null>(null);
|
|
61
|
-
useEffect(() => {
|
|
62
|
-
if (selectionState.focusedKey != null && cachedCollection.current && !collection.getItem(selectionState.focusedKey)) {
|
|
63
|
-
const node = cachedCollection.current.getItem(selectionState.focusedKey);
|
|
64
|
-
const parentNode =
|
|
65
|
-
node?.parentKey != null && (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column') ?
|
|
66
|
-
cachedCollection.current.getItem(node.parentKey) :
|
|
67
|
-
node;
|
|
68
|
-
if (!parentNode) {
|
|
69
|
-
selectionState.setFocusedKey(null);
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
const cachedRows = cachedCollection.current.rows;
|
|
73
|
-
const rows = collection.rows;
|
|
74
|
-
const diff = cachedRows.length - rows.length;
|
|
75
|
-
let index = Math.min(
|
|
76
|
-
(
|
|
77
|
-
diff > 1 ?
|
|
78
|
-
Math.max(parentNode.index - diff + 1, 0) :
|
|
79
|
-
parentNode.index
|
|
80
|
-
),
|
|
81
|
-
rows.length - 1);
|
|
82
|
-
let newRow: GridNode<T> | null = null;
|
|
83
|
-
while (index >= 0) {
|
|
84
|
-
if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') {
|
|
85
|
-
newRow = rows[index];
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
// Find next, not disabled row.
|
|
89
|
-
if (index < rows.length - 1) {
|
|
90
|
-
index++;
|
|
91
|
-
// Otherwise, find previous, not disabled row.
|
|
92
|
-
} else {
|
|
93
|
-
if (index > parentNode.index) {
|
|
94
|
-
index = parentNode.index;
|
|
95
|
-
}
|
|
96
|
-
index--;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (newRow) {
|
|
100
|
-
const childNodes = newRow.hasChildNodes ? [...getChildNodes(newRow, collection)] : [];
|
|
101
|
-
const keyToFocus =
|
|
102
|
-
newRow.hasChildNodes &&
|
|
103
|
-
parentNode !== node &&
|
|
104
|
-
node &&
|
|
105
|
-
node.index < childNodes.length ?
|
|
106
|
-
childNodes[node.index].key :
|
|
107
|
-
newRow.key;
|
|
108
|
-
selectionState.setFocusedKey(keyToFocus);
|
|
109
|
-
} else {
|
|
110
|
-
selectionState.setFocusedKey(null);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
cachedCollection.current = collection;
|
|
114
|
-
}, [collection, selectionManager, selectionState, selectionState.focusedKey]);
|
|
115
|
-
|
|
116
|
-
return {
|
|
117
|
-
collection,
|
|
118
|
-
disabledKeys,
|
|
119
|
-
isKeyboardNavigationDisabled: false,
|
|
120
|
-
selectionManager
|
|
121
|
-
};
|
|
122
|
-
}
|