@react-stately/grid 3.9.3-nightly.5042 → 3.10.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/GridCollection.main.js +19 -14
- package/dist/GridCollection.main.js.map +1 -1
- package/dist/GridCollection.mjs +19 -14
- package/dist/GridCollection.module.js +19 -14
- package/dist/GridCollection.module.js.map +1 -1
- package/dist/types.d.ts +7 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/useGridState.main.js +11 -6
- package/dist/useGridState.main.js.map +1 -1
- package/dist/useGridState.mjs +11 -6
- package/dist/useGridState.module.js +11 -6
- package/dist/useGridState.module.js.map +1 -1
- package/package.json +7 -7
- package/src/GridCollection.ts +20 -19
- package/src/useGridState.ts +11 -6
|
@@ -30,11 +30,13 @@ $parcel$export(module.exports, "GridCollection", () => $8bb6a9101b052a66$export$
|
|
|
30
30
|
}
|
|
31
31
|
getKeyBefore(key) {
|
|
32
32
|
let node = this.keyMap.get(key);
|
|
33
|
-
|
|
33
|
+
var _node_prevKey;
|
|
34
|
+
return node ? (_node_prevKey = node.prevKey) !== null && _node_prevKey !== void 0 ? _node_prevKey : null : null;
|
|
34
35
|
}
|
|
35
36
|
getKeyAfter(key) {
|
|
36
37
|
let node = this.keyMap.get(key);
|
|
37
|
-
|
|
38
|
+
var _node_nextKey;
|
|
39
|
+
return node ? (_node_nextKey = node.nextKey) !== null && _node_nextKey !== void 0 ? _node_nextKey : null : null;
|
|
38
40
|
}
|
|
39
41
|
getFirstKey() {
|
|
40
42
|
var _;
|
|
@@ -50,7 +52,8 @@ $parcel$export(module.exports, "GridCollection", () => $8bb6a9101b052a66$export$
|
|
|
50
52
|
return (_rows_ = rows[rows.length - 1]) === null || _rows_ === void 0 ? void 0 : _rows_.key;
|
|
51
53
|
}
|
|
52
54
|
getItem(key) {
|
|
53
|
-
|
|
55
|
+
var _this_keyMap_get;
|
|
56
|
+
return (_this_keyMap_get = this.keyMap.get(key)) !== null && _this_keyMap_get !== void 0 ? _this_keyMap_get : null;
|
|
54
57
|
}
|
|
55
58
|
at(idx) {
|
|
56
59
|
const keys = [
|
|
@@ -75,7 +78,7 @@ $parcel$export(module.exports, "GridCollection", () => $8bb6a9101b052a66$export$
|
|
|
75
78
|
if (opts.visitNode) node = opts.visitNode(node);
|
|
76
79
|
this.keyMap.set(node.key, node);
|
|
77
80
|
let childKeys = new Set();
|
|
78
|
-
let last;
|
|
81
|
+
let last = null;
|
|
79
82
|
for (let child of node.childNodes){
|
|
80
83
|
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
|
|
81
84
|
child.parentKey = node.key;
|
|
@@ -97,20 +100,22 @@ $parcel$export(module.exports, "GridCollection", () => $8bb6a9101b052a66$export$
|
|
|
97
100
|
this.keyMap.delete(node.key);
|
|
98
101
|
for (let child of node.childNodes)if (this.keyMap.get(child.key) === child) remove(child);
|
|
99
102
|
};
|
|
100
|
-
let last;
|
|
101
|
-
opts.items.
|
|
103
|
+
let last = null;
|
|
104
|
+
for (let [i, node] of opts.items.entries()){
|
|
105
|
+
var _node_level, _node_key, _node_type, _node_value, _node_textValue, _node_index;
|
|
102
106
|
let rowNode = {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
+
...node,
|
|
108
|
+
level: (_node_level = node.level) !== null && _node_level !== void 0 ? _node_level : 0,
|
|
109
|
+
key: (_node_key = node.key) !== null && _node_key !== void 0 ? _node_key : 'row-' + i,
|
|
110
|
+
type: (_node_type = node.type) !== null && _node_type !== void 0 ? _node_type : 'row',
|
|
111
|
+
value: (_node_value = node.value) !== null && _node_value !== void 0 ? _node_value : null,
|
|
107
112
|
hasChildNodes: true,
|
|
108
113
|
childNodes: [
|
|
109
114
|
...node.childNodes
|
|
110
115
|
],
|
|
111
|
-
rendered:
|
|
112
|
-
textValue:
|
|
113
|
-
|
|
116
|
+
rendered: node.rendered,
|
|
117
|
+
textValue: (_node_textValue = node.textValue) !== null && _node_textValue !== void 0 ? _node_textValue : '',
|
|
118
|
+
index: (_node_index = node.index) !== null && _node_index !== void 0 ? _node_index : i
|
|
114
119
|
};
|
|
115
120
|
if (last) {
|
|
116
121
|
last.nextKey = rowNode.key;
|
|
@@ -119,7 +124,7 @@ $parcel$export(module.exports, "GridCollection", () => $8bb6a9101b052a66$export$
|
|
|
119
124
|
this.rows.push(rowNode);
|
|
120
125
|
visit(rowNode);
|
|
121
126
|
last = rowNode;
|
|
122
|
-
}
|
|
127
|
+
}
|
|
123
128
|
if (last) last.nextKey = null;
|
|
124
129
|
}
|
|
125
130
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GAWM,MAAM;
|
|
1
|
+
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GAWM,MAAM;IAiGX,CAAC,CAAC,OAAO,QAAQ,CAAC,GAAG;QACnB,OAAO;eAAI,IAAI,CAAC,IAAI;SAAC;IACvB;IAEA,IAAI,OAAO;QACT,OAAO;eAAI,IAAI,CAAC,IAAI;SAAC,CAAC,MAAM;IAC9B;IAEA,UAAU;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB;IAEA,aAAa,GAAQ,EAAE;QACrB,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;YACb;QAAd,OAAO,OAAO,CAAA,gBAAA,KAAK,OAAO,cAAZ,2BAAA,gBAAgB,OAAO;IACvC;IAEA,YAAY,GAAQ,EAAE;QACpB,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,CAAC,IAAI;SAAC,CAAC,EAAE,cAAjB,wBAAA,EAAmB,GAAG;IAC/B;IAEA,aAAyB;YAEhB;QADP,IAAI,O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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 for (let child of node.childNodes) {\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]() {\n yield* [...this.rows];\n }\n\n get size() {\n return [...this.rows].length;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.prevKey ?? null : null;\n }\n\n getKeyAfter(key: Key) {\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) {\n return this.keyMap.get(key) ?? null;\n }\n\n at(idx: number) {\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
CHANGED
|
@@ -24,11 +24,13 @@
|
|
|
24
24
|
}
|
|
25
25
|
getKeyBefore(key) {
|
|
26
26
|
let node = this.keyMap.get(key);
|
|
27
|
-
|
|
27
|
+
var _node_prevKey;
|
|
28
|
+
return node ? (_node_prevKey = node.prevKey) !== null && _node_prevKey !== void 0 ? _node_prevKey : null : null;
|
|
28
29
|
}
|
|
29
30
|
getKeyAfter(key) {
|
|
30
31
|
let node = this.keyMap.get(key);
|
|
31
|
-
|
|
32
|
+
var _node_nextKey;
|
|
33
|
+
return node ? (_node_nextKey = node.nextKey) !== null && _node_nextKey !== void 0 ? _node_nextKey : null : null;
|
|
32
34
|
}
|
|
33
35
|
getFirstKey() {
|
|
34
36
|
var _;
|
|
@@ -44,7 +46,8 @@
|
|
|
44
46
|
return (_rows_ = rows[rows.length - 1]) === null || _rows_ === void 0 ? void 0 : _rows_.key;
|
|
45
47
|
}
|
|
46
48
|
getItem(key) {
|
|
47
|
-
|
|
49
|
+
var _this_keyMap_get;
|
|
50
|
+
return (_this_keyMap_get = this.keyMap.get(key)) !== null && _this_keyMap_get !== void 0 ? _this_keyMap_get : null;
|
|
48
51
|
}
|
|
49
52
|
at(idx) {
|
|
50
53
|
const keys = [
|
|
@@ -69,7 +72,7 @@
|
|
|
69
72
|
if (opts.visitNode) node = opts.visitNode(node);
|
|
70
73
|
this.keyMap.set(node.key, node);
|
|
71
74
|
let childKeys = new Set();
|
|
72
|
-
let last;
|
|
75
|
+
let last = null;
|
|
73
76
|
for (let child of node.childNodes){
|
|
74
77
|
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
|
|
75
78
|
child.parentKey = node.key;
|
|
@@ -91,20 +94,22 @@
|
|
|
91
94
|
this.keyMap.delete(node.key);
|
|
92
95
|
for (let child of node.childNodes)if (this.keyMap.get(child.key) === child) remove(child);
|
|
93
96
|
};
|
|
94
|
-
let last;
|
|
95
|
-
opts.items.
|
|
97
|
+
let last = null;
|
|
98
|
+
for (let [i, node] of opts.items.entries()){
|
|
99
|
+
var _node_level, _node_key, _node_type, _node_value, _node_textValue, _node_index;
|
|
96
100
|
let rowNode = {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
...node,
|
|
102
|
+
level: (_node_level = node.level) !== null && _node_level !== void 0 ? _node_level : 0,
|
|
103
|
+
key: (_node_key = node.key) !== null && _node_key !== void 0 ? _node_key : 'row-' + i,
|
|
104
|
+
type: (_node_type = node.type) !== null && _node_type !== void 0 ? _node_type : 'row',
|
|
105
|
+
value: (_node_value = node.value) !== null && _node_value !== void 0 ? _node_value : null,
|
|
101
106
|
hasChildNodes: true,
|
|
102
107
|
childNodes: [
|
|
103
108
|
...node.childNodes
|
|
104
109
|
],
|
|
105
|
-
rendered:
|
|
106
|
-
textValue:
|
|
107
|
-
|
|
110
|
+
rendered: node.rendered,
|
|
111
|
+
textValue: (_node_textValue = node.textValue) !== null && _node_textValue !== void 0 ? _node_textValue : '',
|
|
112
|
+
index: (_node_index = node.index) !== null && _node_index !== void 0 ? _node_index : i
|
|
108
113
|
};
|
|
109
114
|
if (last) {
|
|
110
115
|
last.nextKey = rowNode.key;
|
|
@@ -113,7 +118,7 @@
|
|
|
113
118
|
this.rows.push(rowNode);
|
|
114
119
|
visit(rowNode);
|
|
115
120
|
last = rowNode;
|
|
116
|
-
}
|
|
121
|
+
}
|
|
117
122
|
if (last) last.nextKey = null;
|
|
118
123
|
}
|
|
119
124
|
}
|
|
@@ -24,11 +24,13 @@
|
|
|
24
24
|
}
|
|
25
25
|
getKeyBefore(key) {
|
|
26
26
|
let node = this.keyMap.get(key);
|
|
27
|
-
|
|
27
|
+
var _node_prevKey;
|
|
28
|
+
return node ? (_node_prevKey = node.prevKey) !== null && _node_prevKey !== void 0 ? _node_prevKey : null : null;
|
|
28
29
|
}
|
|
29
30
|
getKeyAfter(key) {
|
|
30
31
|
let node = this.keyMap.get(key);
|
|
31
|
-
|
|
32
|
+
var _node_nextKey;
|
|
33
|
+
return node ? (_node_nextKey = node.nextKey) !== null && _node_nextKey !== void 0 ? _node_nextKey : null : null;
|
|
32
34
|
}
|
|
33
35
|
getFirstKey() {
|
|
34
36
|
var _;
|
|
@@ -44,7 +46,8 @@
|
|
|
44
46
|
return (_rows_ = rows[rows.length - 1]) === null || _rows_ === void 0 ? void 0 : _rows_.key;
|
|
45
47
|
}
|
|
46
48
|
getItem(key) {
|
|
47
|
-
|
|
49
|
+
var _this_keyMap_get;
|
|
50
|
+
return (_this_keyMap_get = this.keyMap.get(key)) !== null && _this_keyMap_get !== void 0 ? _this_keyMap_get : null;
|
|
48
51
|
}
|
|
49
52
|
at(idx) {
|
|
50
53
|
const keys = [
|
|
@@ -69,7 +72,7 @@
|
|
|
69
72
|
if (opts.visitNode) node = opts.visitNode(node);
|
|
70
73
|
this.keyMap.set(node.key, node);
|
|
71
74
|
let childKeys = new Set();
|
|
72
|
-
let last;
|
|
75
|
+
let last = null;
|
|
73
76
|
for (let child of node.childNodes){
|
|
74
77
|
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
|
|
75
78
|
child.parentKey = node.key;
|
|
@@ -91,20 +94,22 @@
|
|
|
91
94
|
this.keyMap.delete(node.key);
|
|
92
95
|
for (let child of node.childNodes)if (this.keyMap.get(child.key) === child) remove(child);
|
|
93
96
|
};
|
|
94
|
-
let last;
|
|
95
|
-
opts.items.
|
|
97
|
+
let last = null;
|
|
98
|
+
for (let [i, node] of opts.items.entries()){
|
|
99
|
+
var _node_level, _node_key, _node_type, _node_value, _node_textValue, _node_index;
|
|
96
100
|
let rowNode = {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
...node,
|
|
102
|
+
level: (_node_level = node.level) !== null && _node_level !== void 0 ? _node_level : 0,
|
|
103
|
+
key: (_node_key = node.key) !== null && _node_key !== void 0 ? _node_key : 'row-' + i,
|
|
104
|
+
type: (_node_type = node.type) !== null && _node_type !== void 0 ? _node_type : 'row',
|
|
105
|
+
value: (_node_value = node.value) !== null && _node_value !== void 0 ? _node_value : null,
|
|
101
106
|
hasChildNodes: true,
|
|
102
107
|
childNodes: [
|
|
103
108
|
...node.childNodes
|
|
104
109
|
],
|
|
105
|
-
rendered:
|
|
106
|
-
textValue:
|
|
107
|
-
|
|
110
|
+
rendered: node.rendered,
|
|
111
|
+
textValue: (_node_textValue = node.textValue) !== null && _node_textValue !== void 0 ? _node_textValue : '',
|
|
112
|
+
index: (_node_index = node.index) !== null && _node_index !== void 0 ? _node_index : i
|
|
108
113
|
};
|
|
109
114
|
if (last) {
|
|
110
115
|
last.nextKey = rowNode.key;
|
|
@@ -113,7 +118,7 @@
|
|
|
113
118
|
this.rows.push(rowNode);
|
|
114
119
|
visit(rowNode);
|
|
115
120
|
last = rowNode;
|
|
116
|
-
}
|
|
121
|
+
}
|
|
117
122
|
if (last) last.nextKey = null;
|
|
118
123
|
}
|
|
119
124
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA;;;;;;;;;;CAUC,GAWM,MAAM;
|
|
1
|
+
{"mappings":"AAAA;;;;;;;;;;CAUC,GAWM,MAAM;IAiGX,CAAC,CAAC,OAAO,QAAQ,CAAC,GAAG;QACnB,OAAO;eAAI,IAAI,CAAC,IAAI;SAAC;IACvB;IAEA,IAAI,OAAO;QACT,OAAO;eAAI,IAAI,CAAC,IAAI;SAAC,CAAC,MAAM;IAC9B;IAEA,UAAU;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB;IAEA,aAAa,GAAQ,EAAE;QACrB,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;YACb;QAAd,OAAO,OAAO,CAAA,gBAAA,KAAK,OAAO,cAAZ,2BAAA,gBAAgB,OAAO;IACvC;IAEA,YAAY,GAAQ,EAAE;QACpB,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,QAA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R,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 for (let child of node.childNodes) {\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]() {\n yield* [...this.rows];\n }\n\n get size() {\n return [...this.rows].length;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.prevKey ?? null : null;\n }\n\n getKeyAfter(key: Key) {\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) {\n return this.keyMap.get(key) ?? null;\n }\n\n at(idx: number) {\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
CHANGED
|
@@ -30,16 +30,16 @@ export class GridCollection<T> implements _GridCollection1<T> {
|
|
|
30
30
|
keyMap: Map<Key, GridNode<T>>;
|
|
31
31
|
columnCount: number;
|
|
32
32
|
rows: GridNode<T>[];
|
|
33
|
-
constructor(opts
|
|
33
|
+
constructor(opts: GridCollectionOptions<T>);
|
|
34
34
|
[Symbol.iterator](): Generator<GridNode<T>, void, undefined>;
|
|
35
35
|
get size(): number;
|
|
36
36
|
getKeys(): IterableIterator<Key>;
|
|
37
|
-
getKeyBefore(key: Key): Key;
|
|
38
|
-
getKeyAfter(key: Key): Key;
|
|
39
|
-
getFirstKey(): Key;
|
|
40
|
-
getLastKey(): Key;
|
|
41
|
-
getItem(key: Key): GridNode<T
|
|
42
|
-
at(idx: number): GridNode<T
|
|
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): GridNode<T> | null;
|
|
43
43
|
getChildren(key: Key): Iterable<GridNode<T>>;
|
|
44
44
|
}
|
|
45
45
|
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAMA,2BAA2B,CAAC,EAAE,CAAC,SAAS,iBAAe,CAAC,CAAC;IACvD,UAAU,EAAE,CAAC,CAAC;IACd,gDAAgD;IAChD,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IACvB,kEAAkE;IAClE,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,2HAA2H;IAC3H,4BAA4B,EAAE,OAAO,CAAA;CACtC;AAED,kCAAkC,CAAC,EAAE,CAAC,SAAS,iBAAe,CAAC,CAAC,CAAE,SAAQ,2BAA2B;IACnG,UAAU,EAAE,CAAC,CAAC;IACd,YAAY,CAAC,EAAE,QAAQ,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C;AAED,4BAA4B,CAAC,CAAE,YAAW,iBAAgB,CAAC,CAAC;IAC1D,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,CAAa;IAC1C,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC;gBAER,IAAI,EAAE,sBAAsB,CAAC,CAAC;IA4FzC,CAAC,MAAM,CAAC,QAAQ,CAAC;IAIlB,IAAI,IAAI,WAEP;IAED,OAAO;IAIP,YAAY,CAAC,GAAG,EAAE,GAAG;IAKrB,WAAW,CAAC,GAAG,EAAE,GAAG;IAKpB,WAAW,IAAI,GAAG,GAAG,IAAI;IAIzB,UAAU,IAAI,GAAG,GAAG,IAAI;IAKxB,OAAO,CAAC,GAAG,EAAE,GAAG;IAIhB,EAAE,CAAC,GAAG,EAAE,MAAM;IAKd,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"}
|
|
@@ -26,8 +26,9 @@ function $38009b28e45912ea$export$4007ac09ff9c68ed(props) {
|
|
|
26
26
|
if ((item === null || item === void 0 ? void 0 : item.type) === 'item') {
|
|
27
27
|
var _getLastItem, _getFirstItem;
|
|
28
28
|
let children = (0, $5Cus8$reactstatelycollections.getChildNodes)(item, collection);
|
|
29
|
-
|
|
30
|
-
|
|
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;
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
setFocusedKey(key, child);
|
|
@@ -39,14 +40,18 @@ function $38009b28e45912ea$export$4007ac09ff9c68ed(props) {
|
|
|
39
40
|
// Reset focused key if that item is deleted from the collection.
|
|
40
41
|
const cachedCollection = (0, $5Cus8$react.useRef)(null);
|
|
41
42
|
(0, $5Cus8$react.useEffect)(()=>{
|
|
42
|
-
if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {
|
|
43
|
+
if (selectionState.focusedKey != null && cachedCollection.current && !collection.getItem(selectionState.focusedKey)) {
|
|
43
44
|
const node = cachedCollection.current.getItem(selectionState.focusedKey);
|
|
44
|
-
const parentNode = node.parentKey != null && (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column') ? cachedCollection.current.getItem(node.parentKey) : node;
|
|
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
|
+
}
|
|
45
50
|
const cachedRows = cachedCollection.current.rows;
|
|
46
51
|
const rows = collection.rows;
|
|
47
52
|
const diff = cachedRows.length - rows.length;
|
|
48
53
|
let index = Math.min(diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index, rows.length - 1);
|
|
49
|
-
let newRow;
|
|
54
|
+
let newRow = null;
|
|
50
55
|
while(index >= 0){
|
|
51
56
|
if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') {
|
|
52
57
|
newRow = rows[index];
|
|
@@ -63,7 +68,7 @@ function $38009b28e45912ea$export$4007ac09ff9c68ed(props) {
|
|
|
63
68
|
const childNodes = newRow.hasChildNodes ? [
|
|
64
69
|
...(0, $5Cus8$reactstatelycollections.getChildNodes)(newRow, collection)
|
|
65
70
|
] : [];
|
|
66
|
-
const keyToFocus = newRow.hasChildNodes && parentNode !== node && node.index < childNodes.length ? childNodes[node.index].key : newRow.key;
|
|
71
|
+
const keyToFocus = newRow.hasChildNodes && parentNode !== node && node && node.index < childNodes.length ? childNodes[node.index].key : newRow.key;
|
|
67
72
|
selectionState.setFocusedKey(keyToFocus);
|
|
68
73
|
} else selectionState.setFocusedKey(null);
|
|
69
74
|
}
|
|
@@ -1 +1 @@
|
|
|
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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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
CHANGED
|
@@ -20,8 +20,9 @@ function $62967d126f3aa823$export$4007ac09ff9c68ed(props) {
|
|
|
20
20
|
if ((item === null || item === void 0 ? void 0 : item.type) === 'item') {
|
|
21
21
|
var _getLastItem, _getFirstItem;
|
|
22
22
|
let children = (0, $7nPCv$getChildNodes)(item, collection);
|
|
23
|
-
|
|
24
|
-
|
|
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;
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
setFocusedKey(key, child);
|
|
@@ -33,14 +34,18 @@ function $62967d126f3aa823$export$4007ac09ff9c68ed(props) {
|
|
|
33
34
|
// Reset focused key if that item is deleted from the collection.
|
|
34
35
|
const cachedCollection = (0, $7nPCv$useRef)(null);
|
|
35
36
|
(0, $7nPCv$useEffect)(()=>{
|
|
36
|
-
if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {
|
|
37
|
+
if (selectionState.focusedKey != null && cachedCollection.current && !collection.getItem(selectionState.focusedKey)) {
|
|
37
38
|
const node = cachedCollection.current.getItem(selectionState.focusedKey);
|
|
38
|
-
const parentNode = node.parentKey != null && (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column') ? cachedCollection.current.getItem(node.parentKey) : node;
|
|
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
|
+
}
|
|
39
44
|
const cachedRows = cachedCollection.current.rows;
|
|
40
45
|
const rows = collection.rows;
|
|
41
46
|
const diff = cachedRows.length - rows.length;
|
|
42
47
|
let index = Math.min(diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index, rows.length - 1);
|
|
43
|
-
let newRow;
|
|
48
|
+
let newRow = null;
|
|
44
49
|
while(index >= 0){
|
|
45
50
|
if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') {
|
|
46
51
|
newRow = rows[index];
|
|
@@ -57,7 +62,7 @@ function $62967d126f3aa823$export$4007ac09ff9c68ed(props) {
|
|
|
57
62
|
const childNodes = newRow.hasChildNodes ? [
|
|
58
63
|
...(0, $7nPCv$getChildNodes)(newRow, collection)
|
|
59
64
|
] : [];
|
|
60
|
-
const keyToFocus = newRow.hasChildNodes && parentNode !== node && node.index < childNodes.length ? childNodes[node.index].key : newRow.key;
|
|
65
|
+
const keyToFocus = newRow.hasChildNodes && parentNode !== node && node && node.index < childNodes.length ? childNodes[node.index].key : newRow.key;
|
|
61
66
|
selectionState.setFocusedKey(keyToFocus);
|
|
62
67
|
} else selectionState.setFocusedKey(null);
|
|
63
68
|
}
|
|
@@ -20,8 +20,9 @@ function $62967d126f3aa823$export$4007ac09ff9c68ed(props) {
|
|
|
20
20
|
if ((item === null || item === void 0 ? void 0 : item.type) === 'item') {
|
|
21
21
|
var _getLastItem, _getFirstItem;
|
|
22
22
|
let children = (0, $7nPCv$getChildNodes)(item, collection);
|
|
23
|
-
|
|
24
|
-
|
|
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;
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
setFocusedKey(key, child);
|
|
@@ -33,14 +34,18 @@ function $62967d126f3aa823$export$4007ac09ff9c68ed(props) {
|
|
|
33
34
|
// Reset focused key if that item is deleted from the collection.
|
|
34
35
|
const cachedCollection = (0, $7nPCv$useRef)(null);
|
|
35
36
|
(0, $7nPCv$useEffect)(()=>{
|
|
36
|
-
if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {
|
|
37
|
+
if (selectionState.focusedKey != null && cachedCollection.current && !collection.getItem(selectionState.focusedKey)) {
|
|
37
38
|
const node = cachedCollection.current.getItem(selectionState.focusedKey);
|
|
38
|
-
const parentNode = node.parentKey != null && (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column') ? cachedCollection.current.getItem(node.parentKey) : node;
|
|
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
|
+
}
|
|
39
44
|
const cachedRows = cachedCollection.current.rows;
|
|
40
45
|
const rows = collection.rows;
|
|
41
46
|
const diff = cachedRows.length - rows.length;
|
|
42
47
|
let index = Math.min(diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index, rows.length - 1);
|
|
43
|
-
let newRow;
|
|
48
|
+
let newRow = null;
|
|
44
49
|
while(index >= 0){
|
|
45
50
|
if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') {
|
|
46
51
|
newRow = rows[index];
|
|
@@ -57,7 +62,7 @@ function $62967d126f3aa823$export$4007ac09ff9c68ed(props) {
|
|
|
57
62
|
const childNodes = newRow.hasChildNodes ? [
|
|
58
63
|
...(0, $7nPCv$getChildNodes)(newRow, collection)
|
|
59
64
|
] : [];
|
|
60
|
-
const keyToFocus = newRow.hasChildNodes && parentNode !== node && node.index < childNodes.length ? childNodes[node.index].key : newRow.key;
|
|
65
|
+
const keyToFocus = newRow.hasChildNodes && parentNode !== node && node && node.index < childNodes.length ? childNodes[node.index].key : newRow.key;
|
|
61
66
|
selectionState.setFocusedKey(keyToFocus);
|
|
62
67
|
} else selectionState.setFocusedKey(null);
|
|
63
68
|
}
|
|
@@ -1 +1 @@
|
|
|
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,eAAe,aAAa,GAAG,CAAC,KAAK;QACnC,2EAA2E;QAC3E,IAAI,cAAc,UAAU,OAAO,MAAM;YACvC,IAAI,OAAO,WAAW,OAAO,CAAC;YAC9B,IAAI,CAAA,iBAAA,2BAAA,KAAM,IAAI,MAAK,QAAQ;oBAGjB,cAEA;gBAJR,IAAI,WAAW,CAAA,GAAA,oBAAY,EAAE,MAAM;
|
|
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;IAC9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FirstItem, 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/grid",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,17 +22,17 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-stately/collections": "3.
|
|
26
|
-
"@react-stately/selection": "3.
|
|
27
|
-
"@react-types/grid": "3.2.
|
|
28
|
-
"@react-types/shared": "3.
|
|
25
|
+
"@react-stately/collections": "^3.12.0",
|
|
26
|
+
"@react-stately/selection": "^3.18.0",
|
|
27
|
+
"@react-types/grid": "^3.2.10",
|
|
28
|
+
"@react-types/shared": "^3.26.0",
|
|
29
29
|
"@swc/helpers": "^0.5.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
|
|
32
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "71f0ef23053f9e03ee7e97df736e8b083e006849"
|
|
38
38
|
}
|
package/src/GridCollection.ts
CHANGED
|
@@ -24,7 +24,7 @@ export class GridCollection<T> implements IGridCollection<T> {
|
|
|
24
24
|
columnCount: number;
|
|
25
25
|
rows: GridNode<T>[];
|
|
26
26
|
|
|
27
|
-
constructor(opts
|
|
27
|
+
constructor(opts: GridCollectionOptions<T>) {
|
|
28
28
|
this.keyMap = new Map();
|
|
29
29
|
this.columnCount = opts?.columnCount;
|
|
30
30
|
this.rows = [];
|
|
@@ -41,7 +41,7 @@ export class GridCollection<T> implements IGridCollection<T> {
|
|
|
41
41
|
this.keyMap.set(node.key, node);
|
|
42
42
|
|
|
43
43
|
let childKeys = new Set();
|
|
44
|
-
let last: GridNode<T
|
|
44
|
+
let last: GridNode<T> | null = null;
|
|
45
45
|
for (let child of node.childNodes) {
|
|
46
46
|
if (child.type === 'cell' && child.parentKey == null) {
|
|
47
47
|
// if child is a cell parent key isn't already established by the collection, match child node to parent row
|
|
@@ -83,19 +83,20 @@ export class GridCollection<T> implements IGridCollection<T> {
|
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
85
|
|
|
86
|
-
let last: GridNode<T
|
|
87
|
-
opts.items.
|
|
88
|
-
let rowNode = {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
86
|
+
let last: GridNode<T> | null = null;
|
|
87
|
+
for (let [i, node] of opts.items.entries()) {
|
|
88
|
+
let rowNode: GridNode<T> = {
|
|
89
|
+
...node,
|
|
90
|
+
level: node.level ?? 0,
|
|
91
|
+
key: node.key ?? 'row-' + i,
|
|
92
|
+
type: node.type ?? 'row',
|
|
93
|
+
value: node.value ?? null,
|
|
93
94
|
hasChildNodes: true,
|
|
94
95
|
childNodes: [...node.childNodes],
|
|
95
|
-
rendered:
|
|
96
|
-
textValue:
|
|
97
|
-
|
|
98
|
-
}
|
|
96
|
+
rendered: node.rendered,
|
|
97
|
+
textValue: node.textValue ?? '',
|
|
98
|
+
index: node.index ?? i
|
|
99
|
+
};
|
|
99
100
|
|
|
100
101
|
if (last) {
|
|
101
102
|
last.nextKey = rowNode.key;
|
|
@@ -108,7 +109,7 @@ export class GridCollection<T> implements IGridCollection<T> {
|
|
|
108
109
|
visit(rowNode);
|
|
109
110
|
|
|
110
111
|
last = rowNode;
|
|
111
|
-
}
|
|
112
|
+
}
|
|
112
113
|
|
|
113
114
|
if (last) {
|
|
114
115
|
last.nextKey = null;
|
|
@@ -129,25 +130,25 @@ export class GridCollection<T> implements IGridCollection<T> {
|
|
|
129
130
|
|
|
130
131
|
getKeyBefore(key: Key) {
|
|
131
132
|
let node = this.keyMap.get(key);
|
|
132
|
-
return node ? node.prevKey : null;
|
|
133
|
+
return node ? node.prevKey ?? null : null;
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
getKeyAfter(key: Key) {
|
|
136
137
|
let node = this.keyMap.get(key);
|
|
137
|
-
return node ? node.nextKey : null;
|
|
138
|
+
return node ? node.nextKey ?? null : null;
|
|
138
139
|
}
|
|
139
140
|
|
|
140
|
-
getFirstKey() {
|
|
141
|
+
getFirstKey(): Key | null {
|
|
141
142
|
return [...this.rows][0]?.key;
|
|
142
143
|
}
|
|
143
144
|
|
|
144
|
-
getLastKey() {
|
|
145
|
+
getLastKey(): Key | null {
|
|
145
146
|
let rows = [...this.rows];
|
|
146
147
|
return rows[rows.length - 1]?.key;
|
|
147
148
|
}
|
|
148
149
|
|
|
149
150
|
getItem(key: Key) {
|
|
150
|
-
return this.keyMap.get(key);
|
|
151
|
+
return this.keyMap.get(key) ?? null;
|
|
151
152
|
}
|
|
152
153
|
|
|
153
154
|
at(idx: number) {
|
package/src/useGridState.ts
CHANGED
|
@@ -41,9 +41,9 @@ export function useGridState<T extends object, C extends GridCollection<T>>(prop
|
|
|
41
41
|
if (item?.type === 'item') {
|
|
42
42
|
let children = getChildNodes(item, collection);
|
|
43
43
|
if (child === 'last') {
|
|
44
|
-
key = getLastItem(children)?.key;
|
|
44
|
+
key = getLastItem(children)?.key ?? null;
|
|
45
45
|
} else {
|
|
46
|
-
key = getFirstItem(children)?.key;
|
|
46
|
+
key = getFirstItem(children)?.key ?? null;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -57,14 +57,18 @@ export function useGridState<T extends object, C extends GridCollection<T>>(prop
|
|
|
57
57
|
);
|
|
58
58
|
|
|
59
59
|
// Reset focused key if that item is deleted from the collection.
|
|
60
|
-
const cachedCollection = useRef(null);
|
|
60
|
+
const cachedCollection = useRef<C | null>(null);
|
|
61
61
|
useEffect(() => {
|
|
62
|
-
if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {
|
|
62
|
+
if (selectionState.focusedKey != null && cachedCollection.current && !collection.getItem(selectionState.focusedKey)) {
|
|
63
63
|
const node = cachedCollection.current.getItem(selectionState.focusedKey);
|
|
64
64
|
const parentNode =
|
|
65
|
-
node
|
|
65
|
+
node?.parentKey != null && (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column') ?
|
|
66
66
|
cachedCollection.current.getItem(node.parentKey) :
|
|
67
67
|
node;
|
|
68
|
+
if (!parentNode) {
|
|
69
|
+
selectionState.setFocusedKey(null);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
68
72
|
const cachedRows = cachedCollection.current.rows;
|
|
69
73
|
const rows = collection.rows;
|
|
70
74
|
const diff = cachedRows.length - rows.length;
|
|
@@ -75,7 +79,7 @@ export function useGridState<T extends object, C extends GridCollection<T>>(prop
|
|
|
75
79
|
parentNode.index
|
|
76
80
|
),
|
|
77
81
|
rows.length - 1);
|
|
78
|
-
let newRow:GridNode<T
|
|
82
|
+
let newRow: GridNode<T> | null = null;
|
|
79
83
|
while (index >= 0) {
|
|
80
84
|
if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') {
|
|
81
85
|
newRow = rows[index];
|
|
@@ -97,6 +101,7 @@ export function useGridState<T extends object, C extends GridCollection<T>>(prop
|
|
|
97
101
|
const keyToFocus =
|
|
98
102
|
newRow.hasChildNodes &&
|
|
99
103
|
parentNode !== node &&
|
|
104
|
+
node &&
|
|
100
105
|
node.index < childNodes.length ?
|
|
101
106
|
childNodes[node.index].key :
|
|
102
107
|
newRow.key;
|