@react-stately/grid 3.9.3 → 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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2019 Adobe
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -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
- return node ? node.prevKey : null;
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
- return node ? node.nextKey : null;
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
- return this.keyMap.get(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;
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.forEach((node, i)=>{
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
- level: 0,
104
- key: 'row-' + i,
105
- type: 'row',
106
- value: undefined,
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: undefined,
112
- textValue: undefined,
113
- ...node
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;IAgGX,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;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C;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>;\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>;\n opts.items.forEach((node, i) => {\n let rowNode = {\n level: 0,\n key: 'row-' + i,\n type: 'row',\n value: undefined,\n hasChildNodes: true,\n childNodes: [...node.childNodes],\n rendered: undefined,\n textValue: undefined,\n ...node\n } as GridNode<T>;\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;\n }\n\n getKeyAfter(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.nextKey : null;\n }\n\n getFirstKey() {\n return [...this.rows][0]?.key;\n }\n\n getLastKey() {\n let rows = [...this.rows];\n return rows[rows.length - 1]?.key;\n }\n\n getItem(key: Key) {\n return this.keyMap.get(key);\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"}
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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,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 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"}
@@ -24,11 +24,13 @@
24
24
  }
25
25
  getKeyBefore(key) {
26
26
  let node = this.keyMap.get(key);
27
- return node ? node.prevKey : null;
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
- return node ? node.nextKey : null;
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
- return this.keyMap.get(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;
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.forEach((node, i)=>{
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
- level: 0,
98
- key: 'row-' + i,
99
- type: 'row',
100
- value: undefined,
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: undefined,
106
- textValue: undefined,
107
- ...node
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
- return node ? node.prevKey : null;
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
- return node ? node.nextKey : null;
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
- return this.keyMap.get(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;
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.forEach((node, i)=>{
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
- level: 0,
98
- key: 'row-' + i,
99
- type: 'row',
100
- value: undefined,
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: undefined,
106
- textValue: undefined,
107
- ...node
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;IAgGX,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;QAC3B,OAAO,OAAO,KAAK,OAAO,GAAG;IAC/B;IAEA,YAAY,GAAQ,EAAE;QACpB,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;QAC3B,OAAO,OAAO,KAAK,OAAO,GAAG;IAC/B;IAEA,cAAc;YACL;QAAP,QAAO,IAAA;eAAI,IAAI,CAAC,IAAI;SAAC,CAAC,EAAE,cAAjB,wBAAA,EAAmB,GAAG;IAC/B;IAEA,aAAa;YAEJ;QADP,IAAI,OAAO;eAAI,IAAI,CAAC,IAAI;SAAC;QACzB,QAAO,SAAA,IAAI,CAAC,KAAK,MAAM,GAAG,EAAE,cAArB,6BAAA,OAAuB,GAAG;IACnC;IAEA,QAAQ,GAAQ,EAAE;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;IACzB;IAEA,GAAG,GAAW,EAAE;QACd,MAAM,OAAO;eAAI,IAAI,CAAC,OAAO;SAAG;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI;IAC/B;IAE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SAAS,KAAK,UAAU,CAC/B,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,OACjC,OAAO;QAGb;QAEA,IAAI;QACJ,KAAK,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM;YACxB,IAAI,UAAU;gBACZ,OAAO;gBACP,KAAK,SAAS;gBACd,MAAM;gBACN,OAAO;gBACP,eAAe;gBACf,YAAY;uBAAI,KAAK,UAAU;iBAAC;gBAChC,UAAU;gBACV,WAAW;gBACX,GAAG,IAAI;YACT;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>;\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>;\n opts.items.forEach((node, i) => {\n let rowNode = {\n level: 0,\n key: 'row-' + i,\n type: 'row',\n value: undefined,\n hasChildNodes: true,\n childNodes: [...node.childNodes],\n rendered: undefined,\n textValue: undefined,\n ...node\n } as GridNode<T>;\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;\n }\n\n getKeyAfter(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.nextKey : null;\n }\n\n getFirstKey() {\n return [...this.rows][0]?.key;\n }\n\n getLastKey() {\n let rows = [...this.rows];\n return rows[rows.length - 1]?.key;\n }\n\n getItem(key: Key) {\n return this.keyMap.get(key);\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"}
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,OAAO;eAAI,IAAI,CAAC,IAAI;SAAC;QACzB,QAAO,SAAA,IAAI,CAAC,KAAK,MAAM,GAAG,EAAE,cAArB,6BAAA,OAAuB,GAAG;IACnC;IAEA,QAAQ,GAAQ,EAAE;YACT;QAAP,OAAO,CAAA,mBAAA,IAAI,CAAC,MAAM,CAAC,GAAG,C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AS,UAAU,CACnC,IAAI,CAAC,UAAU,GAAG,CAAC,MAAM,GAAG,GAC1B,OAAO;YAGb;QACF;QAEA,IAAI,SAAS,CAAC;YACZ,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,GAAG;YAC3B,KAAK,IAAI,SAAS,KAAK,UAAU,CAC/B,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,OACjC,OAAO;QAGb;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 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?: GridCollectionOptions<T>);
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
 
@@ -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,CAAC,GAAG,CAAC,CAAC;IAC7B,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAC3B,+DAA+D;IAC/D,qBAAqB,CAAC,EAAE,sBAAsB,CAAA;CAC/C;AAED;;GAEG;AACH,6BAA6B,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,iBAAe,CAAC,CAAC,EAAE,KAAK,EAAE,iBAAiB,CAAC,EAAE,CAAC,CAAC,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC,CAyF1H;ACrGD,gCAAgC,CAAC;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC;IACpB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAA;CAC/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,CAAC,EAAE,sBAAsB,CAAC,CAAC;IA2F1C,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;IAIX,UAAU;IAKV,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"}
1
+ {"mappings":";;;AAMA,2BAA2B,CAAC,EAAE,CAAC,SAAS,iBAAe,CAAC,CAAC;IACvD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G;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
- if (child === 'last') key = (_getLastItem = (0, $5Cus8$reactstatelycollections.getLastItem)(children)) === null || _getLastItem === void 0 ? void 0 : _getLastItem.key;
30
- else key = (_getFirstItem = (0, $5Cus8$reactstatelycollections.getFirstItem)(children)) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
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,OAAO,MAAM;YACvC,IAAI,OAAO,WAAW,OAAO,CAAC;YAC9B,IAAI,CAAA,iBAAA,2BAAA,KAAM,IAAI,MAAK,QAAQ;oBAGjB,cAEA;gBAJR,IAAI,WAAW,CAAA,GAAA,4CAAY,EAAE,MAAM;gBACnC,IAAI,UAAU,QACZ,OAAM,eAAA,CAAA,GAAA,0CAAU,EAAE,uBAAZ,mCAAA,aAAuB,GAAG;qBAEhC,OAAM,gBAAA,CAAA,GAAA,2CAAW,EAAE,uBAAb,oCAAA,cAAwB,GAAG;YAErC;QACF;QAEA,cAAc,KAAK;IACrB;IAEA,IAAI,mBAAmB,CAAA,GAAA,oBAAM,EAAE,IAC7B,IAAI,CAAA,GAAA,6CAAe,EAAE,YAAY,iBAC/B;QAAC;QAAY;KAAe;IAGhC,iEAAiE;IACjE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,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;\n } else {\n key = getFirstItem(children)?.key;\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(null);\n useEffect(() => {\n if (selectionState.focusedKey != null && !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 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>;\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.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"}
1
+ {"mappings":";;;;;;;;;;;;;AA2BO,SAAS,0CAA4D,KAA6B;IACvG,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gB,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"}
@@ -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
- if (child === 'last') key = (_getLastItem = (0, $7nPCv$getLastItem)(children)) === null || _getLastItem === void 0 ? void 0 : _getLastItem.key;
24
- else key = (_getFirstItem = (0, $7nPCv$getFirstItem)(children)) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
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
- if (child === 'last') key = (_getLastItem = (0, $7nPCv$getLastItem)(children)) === null || _getLastItem === void 0 ? void 0 : _getLastItem.key;
24
- else key = (_getFirstItem = (0, $7nPCv$getFirstItem)(children)) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
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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YACF,MAAM,aAAa,iBAAiB,OAAO,CAAC,IAAI;YAChD,MAAM,OAAO,WAAW,IAAI;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;YACJ,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,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;\n } else {\n key = getFirstItem(children)?.key;\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(null);\n useEffect(() => {\n if (selectionState.focusedKey != null && !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 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>;\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.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"}
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,WA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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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/grid",
3
- "version": "3.9.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,16 +22,17 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-stately/collections": "^3.11.0",
26
- "@react-stately/selection": "^3.17.0",
27
- "@react-types/grid": "^3.2.9",
28
- "@react-types/shared": "^3.25.0",
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
- }
37
- }
36
+ },
37
+ "gitHead": "71f0ef23053f9e03ee7e97df736e8b083e006849"
38
+ }
@@ -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?: GridCollectionOptions<T>) {
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.forEach((node, i) => {
88
- let rowNode = {
89
- level: 0,
90
- key: 'row-' + i,
91
- type: 'row',
92
- value: undefined,
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: undefined,
96
- textValue: undefined,
97
- ...node
98
- } as GridNode<T>;
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) {
@@ -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.parentKey != null && (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column') ?
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;