@react-stately/list 3.0.0-alpha.1 → 3.0.0-nightly-4980928d3-240906

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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @react-stately/list
2
+
3
+ This package is part of [react-spectrum](https://github.com/adobe/react-spectrum). See the repo for more details.
@@ -0,0 +1,89 @@
1
+
2
+ function $parcel$export(e, n, v, s) {
3
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
4
+ }
5
+
6
+ $parcel$export(module.exports, "ListCollection", () => $c9aa5a224613c979$export$d085fb9e920b5ca7);
7
+ /*
8
+ * Copyright 2020 Adobe. All rights reserved.
9
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License. You may obtain a copy
11
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software distributed under
14
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
+ * OF ANY KIND, either express or implied. See the License for the specific language
16
+ * governing permissions and limitations under the License.
17
+ */ class $c9aa5a224613c979$export$d085fb9e920b5ca7 {
18
+ *[Symbol.iterator]() {
19
+ yield* this.iterable;
20
+ }
21
+ get size() {
22
+ return this.keyMap.size;
23
+ }
24
+ getKeys() {
25
+ return this.keyMap.keys();
26
+ }
27
+ getKeyBefore(key) {
28
+ let node = this.keyMap.get(key);
29
+ var _node_prevKey;
30
+ return node ? (_node_prevKey = node.prevKey) !== null && _node_prevKey !== void 0 ? _node_prevKey : null : null;
31
+ }
32
+ getKeyAfter(key) {
33
+ let node = this.keyMap.get(key);
34
+ var _node_nextKey;
35
+ return node ? (_node_nextKey = node.nextKey) !== null && _node_nextKey !== void 0 ? _node_nextKey : null : null;
36
+ }
37
+ getFirstKey() {
38
+ return this.firstKey;
39
+ }
40
+ getLastKey() {
41
+ return this.lastKey;
42
+ }
43
+ getItem(key) {
44
+ var _this_keyMap_get;
45
+ return (_this_keyMap_get = this.keyMap.get(key)) !== null && _this_keyMap_get !== void 0 ? _this_keyMap_get : null;
46
+ }
47
+ at(idx) {
48
+ const keys = [
49
+ ...this.getKeys()
50
+ ];
51
+ return this.getItem(keys[idx]);
52
+ }
53
+ getChildren(key) {
54
+ let node = this.keyMap.get(key);
55
+ return (node === null || node === void 0 ? void 0 : node.childNodes) || [];
56
+ }
57
+ constructor(nodes){
58
+ this.keyMap = new Map();
59
+ this.firstKey = null;
60
+ this.lastKey = null;
61
+ this.iterable = nodes;
62
+ let visit = (node)=>{
63
+ this.keyMap.set(node.key, node);
64
+ if (node.childNodes && node.type === 'section') for (let child of node.childNodes)visit(child);
65
+ };
66
+ for (let node of nodes)visit(node);
67
+ let last = null;
68
+ let index = 0;
69
+ for (let [key, node] of this.keyMap){
70
+ if (last) {
71
+ last.nextKey = key;
72
+ node.prevKey = last.key;
73
+ } else {
74
+ this.firstKey = key;
75
+ node.prevKey = undefined;
76
+ }
77
+ if (node.type === 'item') node.index = index++;
78
+ last = node;
79
+ // Set nextKey as undefined since this might be the last node
80
+ // If it isn't the last node, last.nextKey will properly set at start of new loop
81
+ last.nextKey = undefined;
82
+ }
83
+ var _last_key;
84
+ this.lastKey = (_last_key = last === null || last === void 0 ? void 0 : last.key) !== null && _last_key !== void 0 ? _last_key : null;
85
+ }
86
+ }
87
+
88
+
89
+ //# sourceMappingURL=ListCollection.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GAIM,MAAM;IAgDX,CAAC,CAAC,OAAO,QAAQ,CAAC,GAAG;QACnB,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB;IAEA,UAAU;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB;IAEA,aAAa,GAAQ,EAAE;QACrB,IAAI,OAAO,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AM;gBACR,KAAK,OAAO,GAAG;gBACf,KAAK,OAAO,GAAG,KAAK,GAAG;YACzB,OAAO;gBACL,IAAI,CAAC,QAAQ,GAAG;gBAChB,KAAK,OAAO,GAAG;YACjB;YAEA,IAAI,KAAK,IAAI,KAAK,QAChB,KAAK,KAAK,GAAG;YAGf,OAAO;YAEP,6DAA6D;YAC7D,iFAAiF;YACjF,KAAK,OAAO,GAAG;QACjB;YAEe;QAAf,IAAI,CAAC,OAAO,GAAG,CAAA,YAAA,iBAAA,2BAAA,KAAM,GAAG,cAAT,uBAAA,YAAa;IAC9B;AA6CF","sources":["packages/@react-stately/list/src/ListCollection.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 {Collection, Key, Node} from '@react-types/shared';\n\nexport class ListCollection<T> implements Collection<Node<T>> {\n private keyMap: Map<Key, Node<T>> = new Map();\n private iterable: Iterable<Node<T>>;\n private firstKey: Key | null = null;\n private lastKey: Key | null = null;\n\n constructor(nodes: Iterable<Node<T>>) {\n this.iterable = nodes;\n\n let visit = (node: Node<T>) => {\n this.keyMap.set(node.key, node);\n\n if (node.childNodes && node.type === 'section') {\n for (let child of node.childNodes) {\n visit(child);\n }\n }\n };\n\n for (let node of nodes) {\n visit(node);\n }\n\n let last: Node<T> | null = null;\n let index = 0;\n for (let [key, node] of this.keyMap) {\n if (last) {\n last.nextKey = key;\n node.prevKey = last.key;\n } else {\n this.firstKey = key;\n node.prevKey = undefined;\n }\n\n if (node.type === 'item') {\n node.index = index++;\n }\n\n last = node;\n\n // Set nextKey as undefined since this might be the last node\n // If it isn't the last node, last.nextKey will properly set at start of new loop\n last.nextKey = undefined;\n }\n\n this.lastKey = last?.key ?? null;\n }\n\n *[Symbol.iterator]() {\n yield* this.iterable;\n }\n\n get size() {\n return this.keyMap.size;\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() {\n return this.firstKey;\n }\n\n getLastKey() {\n return this.lastKey;\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<Node<T>> {\n let node = this.keyMap.get(key);\n return node?.childNodes || [];\n }\n}\n"],"names":[],"version":3,"file":"ListCollection.main.js.map"}
@@ -0,0 +1,84 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */ class $a02d57049d202695$export$d085fb9e920b5ca7 {
12
+ *[Symbol.iterator]() {
13
+ yield* this.iterable;
14
+ }
15
+ get size() {
16
+ return this.keyMap.size;
17
+ }
18
+ getKeys() {
19
+ return this.keyMap.keys();
20
+ }
21
+ getKeyBefore(key) {
22
+ let node = this.keyMap.get(key);
23
+ var _node_prevKey;
24
+ return node ? (_node_prevKey = node.prevKey) !== null && _node_prevKey !== void 0 ? _node_prevKey : null : null;
25
+ }
26
+ getKeyAfter(key) {
27
+ let node = this.keyMap.get(key);
28
+ var _node_nextKey;
29
+ return node ? (_node_nextKey = node.nextKey) !== null && _node_nextKey !== void 0 ? _node_nextKey : null : null;
30
+ }
31
+ getFirstKey() {
32
+ return this.firstKey;
33
+ }
34
+ getLastKey() {
35
+ return this.lastKey;
36
+ }
37
+ getItem(key) {
38
+ var _this_keyMap_get;
39
+ return (_this_keyMap_get = this.keyMap.get(key)) !== null && _this_keyMap_get !== void 0 ? _this_keyMap_get : null;
40
+ }
41
+ at(idx) {
42
+ const keys = [
43
+ ...this.getKeys()
44
+ ];
45
+ return this.getItem(keys[idx]);
46
+ }
47
+ getChildren(key) {
48
+ let node = this.keyMap.get(key);
49
+ return (node === null || node === void 0 ? void 0 : node.childNodes) || [];
50
+ }
51
+ constructor(nodes){
52
+ this.keyMap = new Map();
53
+ this.firstKey = null;
54
+ this.lastKey = null;
55
+ this.iterable = nodes;
56
+ let visit = (node)=>{
57
+ this.keyMap.set(node.key, node);
58
+ if (node.childNodes && node.type === 'section') for (let child of node.childNodes)visit(child);
59
+ };
60
+ for (let node of nodes)visit(node);
61
+ let last = null;
62
+ let index = 0;
63
+ for (let [key, node] of this.keyMap){
64
+ if (last) {
65
+ last.nextKey = key;
66
+ node.prevKey = last.key;
67
+ } else {
68
+ this.firstKey = key;
69
+ node.prevKey = undefined;
70
+ }
71
+ if (node.type === 'item') node.index = index++;
72
+ last = node;
73
+ // Set nextKey as undefined since this might be the last node
74
+ // If it isn't the last node, last.nextKey will properly set at start of new loop
75
+ last.nextKey = undefined;
76
+ }
77
+ var _last_key;
78
+ this.lastKey = (_last_key = last === null || last === void 0 ? void 0 : last.key) !== null && _last_key !== void 0 ? _last_key : null;
79
+ }
80
+ }
81
+
82
+
83
+ export {$a02d57049d202695$export$d085fb9e920b5ca7 as ListCollection};
84
+ //# sourceMappingURL=ListCollection.module.js.map
@@ -0,0 +1,84 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */ class $a02d57049d202695$export$d085fb9e920b5ca7 {
12
+ *[Symbol.iterator]() {
13
+ yield* this.iterable;
14
+ }
15
+ get size() {
16
+ return this.keyMap.size;
17
+ }
18
+ getKeys() {
19
+ return this.keyMap.keys();
20
+ }
21
+ getKeyBefore(key) {
22
+ let node = this.keyMap.get(key);
23
+ var _node_prevKey;
24
+ return node ? (_node_prevKey = node.prevKey) !== null && _node_prevKey !== void 0 ? _node_prevKey : null : null;
25
+ }
26
+ getKeyAfter(key) {
27
+ let node = this.keyMap.get(key);
28
+ var _node_nextKey;
29
+ return node ? (_node_nextKey = node.nextKey) !== null && _node_nextKey !== void 0 ? _node_nextKey : null : null;
30
+ }
31
+ getFirstKey() {
32
+ return this.firstKey;
33
+ }
34
+ getLastKey() {
35
+ return this.lastKey;
36
+ }
37
+ getItem(key) {
38
+ var _this_keyMap_get;
39
+ return (_this_keyMap_get = this.keyMap.get(key)) !== null && _this_keyMap_get !== void 0 ? _this_keyMap_get : null;
40
+ }
41
+ at(idx) {
42
+ const keys = [
43
+ ...this.getKeys()
44
+ ];
45
+ return this.getItem(keys[idx]);
46
+ }
47
+ getChildren(key) {
48
+ let node = this.keyMap.get(key);
49
+ return (node === null || node === void 0 ? void 0 : node.childNodes) || [];
50
+ }
51
+ constructor(nodes){
52
+ this.keyMap = new Map();
53
+ this.firstKey = null;
54
+ this.lastKey = null;
55
+ this.iterable = nodes;
56
+ let visit = (node)=>{
57
+ this.keyMap.set(node.key, node);
58
+ if (node.childNodes && node.type === 'section') for (let child of node.childNodes)visit(child);
59
+ };
60
+ for (let node of nodes)visit(node);
61
+ let last = null;
62
+ let index = 0;
63
+ for (let [key, node] of this.keyMap){
64
+ if (last) {
65
+ last.nextKey = key;
66
+ node.prevKey = last.key;
67
+ } else {
68
+ this.firstKey = key;
69
+ node.prevKey = undefined;
70
+ }
71
+ if (node.type === 'item') node.index = index++;
72
+ last = node;
73
+ // Set nextKey as undefined since this might be the last node
74
+ // If it isn't the last node, last.nextKey will properly set at start of new loop
75
+ last.nextKey = undefined;
76
+ }
77
+ var _last_key;
78
+ this.lastKey = (_last_key = last === null || last === void 0 ? void 0 : last.key) !== null && _last_key !== void 0 ? _last_key : null;
79
+ }
80
+ }
81
+
82
+
83
+ export {$a02d57049d202695$export$d085fb9e920b5ca7 as ListCollection};
84
+ //# sourceMappingURL=ListCollection.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAAA;;;;;;;;;;CAUC,GAIM,MAAM;IAgDX,CAAC,CAAC,OAAO,QAAQ,CAAC,GAAG;QACnB,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB;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,cAAc;QACZ,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA,aAAa;QACX,OAAO,IAAI,CAAC,OAAO;IACrB;IAEA,QAAQ,GAAQ,EAAE;YACT;QAAP,OAAO,CAAA,mBAAA,IA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. 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 {Collection, Key, Node} from '@react-types/shared';\n\nexport class ListCollection<T> implements Collection<Node<T>> {\n private keyMap: Map<Key, Node<T>> = new Map();\n private iterable: Iterable<Node<T>>;\n private firstKey: Key | null = null;\n private lastKey: Key | null = null;\n\n constructor(nodes: Iterable<Node<T>>) {\n this.iterable = nodes;\n\n let visit = (node: Node<T>) => {\n this.keyMap.set(node.key, node);\n\n if (node.childNodes && node.type === 'section') {\n for (let child of node.childNodes) {\n visit(child);\n }\n }\n };\n\n for (let node of nodes) {\n visit(node);\n }\n\n let last: Node<T> | null = null;\n let index = 0;\n for (let [key, node] of this.keyMap) {\n if (last) {\n last.nextKey = key;\n node.prevKey = last.key;\n } else {\n this.firstKey = key;\n node.prevKey = undefined;\n }\n\n if (node.type === 'item') {\n node.index = index++;\n }\n\n last = node;\n\n // Set nextKey as undefined since this might be the last node\n // If it isn't the last node, last.nextKey will properly set at start of new loop\n last.nextKey = undefined;\n }\n\n this.lastKey = last?.key ?? null;\n }\n\n *[Symbol.iterator]() {\n yield* this.iterable;\n }\n\n get size() {\n return this.keyMap.size;\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() {\n return this.firstKey;\n }\n\n getLastKey() {\n return this.lastKey;\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<Node<T>> {\n let node = this.keyMap.get(key);\n return node?.childNodes || [];\n }\n}\n"],"names":[],"version":3,"file":"ListCollection.module.js.map"}
@@ -0,0 +1,21 @@
1
+ import {useListState as $e72dd72e1c76a225$export$2f645645f7bca764} from "./useListState.mjs";
2
+ import {useSingleSelectListState as $a0d645289fe9b86b$export$e7f05e985daf4b5f} from "./useSingleSelectListState.mjs";
3
+ import {ListCollection as $a02d57049d202695$export$d085fb9e920b5ca7} from "./ListCollection.mjs";
4
+
5
+ /*
6
+ * Copyright 2020 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+
19
+
20
+ export {$e72dd72e1c76a225$export$2f645645f7bca764 as useListState, $a0d645289fe9b86b$export$e7f05e985daf4b5f as useSingleSelectListState, $a02d57049d202695$export$d085fb9e920b5ca7 as ListCollection};
21
+ //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,38 +1,28 @@
1
- var _temp = require("@react-stately/collections");
1
+ var $5450691d3629f6ea$exports = require("./useListState.main.js");
2
+ var $b9e99587a092d199$exports = require("./useSingleSelectListState.main.js");
3
+ var $c9aa5a224613c979$exports = require("./ListCollection.main.js");
2
4
 
3
- var CollectionBuilder = _temp.CollectionBuilder;
4
- var TreeCollection = _temp.TreeCollection;
5
5
 
6
- var useMemo = require("react").useMemo;
6
+ function $parcel$export(e, n, v, s) {
7
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
+ }
9
+
10
+ $parcel$export(module.exports, "useListState", () => $5450691d3629f6ea$exports.useListState);
11
+ $parcel$export(module.exports, "useSingleSelectListState", () => $b9e99587a092d199$exports.useSingleSelectListState);
12
+ $parcel$export(module.exports, "ListCollection", () => $c9aa5a224613c979$exports.ListCollection);
13
+ /*
14
+ * Copyright 2020 Adobe. All rights reserved.
15
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
16
+ * you may not use this file except in compliance with the License. You may obtain a copy
17
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software distributed under
20
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21
+ * OF ANY KIND, either express or implied. See the License for the specific language
22
+ * governing permissions and limitations under the License.
23
+ */
7
24
 
8
- var _temp2 = require("@react-stately/selection");
9
25
 
10
- var SelectionManager = _temp2.SelectionManager;
11
- var useMultipleSelectionState = _temp2.useMultipleSelectionState;
12
26
 
13
- function useListState(props) {
14
- var selectionState = useMultipleSelectionState(props);
15
- var disabledKeys = useMemo(function () {
16
- return props.disabledKeys ? new Set(props.disabledKeys) : new Set();
17
- }, [props.disabledKeys]);
18
- var builder = useMemo(function () {
19
- return new CollectionBuilder(props.itemKey);
20
- }, [props.itemKey]);
21
- var collection = useMemo(function () {
22
- var nodes = builder.build(props, function (key) {
23
- return {
24
- isSelected: selectionState.selectedKeys.has(key),
25
- isDisabled: disabledKeys.has(key),
26
- isFocused: key === selectionState.focusedKey
27
- };
28
- });
29
- return new TreeCollection(nodes);
30
- }, [builder, props, selectionState.selectedKeys, selectionState.focusedKey, disabledKeys]);
31
- return {
32
- collection: collection,
33
- disabledKeys: disabledKeys,
34
- selectionManager: new SelectionManager(collection, selectionState)
35
- };
36
- }
37
27
 
38
- exports.useListState = useListState;
28
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/list/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {ListProps, ListState} from './useListState';\nexport type {SingleSelectListProps, SingleSelectListState} from './useSingleSelectListState';\nexport {useListState} from './useListState';\nexport {useSingleSelectListState} from './useSingleSelectListState';\nexport {ListCollection} from './ListCollection';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,21 +1,21 @@
1
- import { CollectionBuilder, TreeCollection } from "@react-stately/collections";
2
- import { useMemo } from "react";
3
- import { SelectionManager, useMultipleSelectionState } from "@react-stately/selection";
4
- export function useListState(props) {
5
- let selectionState = useMultipleSelectionState(props);
6
- let disabledKeys = useMemo(() => props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [props.disabledKeys]);
7
- let builder = useMemo(() => new CollectionBuilder(props.itemKey), [props.itemKey]);
8
- let collection = useMemo(() => {
9
- let nodes = builder.build(props, key => ({
10
- isSelected: selectionState.selectedKeys.has(key),
11
- isDisabled: disabledKeys.has(key),
12
- isFocused: key === selectionState.focusedKey
13
- }));
14
- return new TreeCollection(nodes);
15
- }, [builder, props, selectionState.selectedKeys, selectionState.focusedKey, disabledKeys]);
16
- return {
17
- collection,
18
- disabledKeys,
19
- selectionManager: new SelectionManager(collection, selectionState)
20
- };
21
- }
1
+ import {useListState as $e72dd72e1c76a225$export$2f645645f7bca764} from "./useListState.module.js";
2
+ import {useSingleSelectListState as $a0d645289fe9b86b$export$e7f05e985daf4b5f} from "./useSingleSelectListState.module.js";
3
+ import {ListCollection as $a02d57049d202695$export$d085fb9e920b5ca7} from "./ListCollection.module.js";
4
+
5
+ /*
6
+ * Copyright 2020 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+
19
+
20
+ export {$e72dd72e1c76a225$export$2f645645f7bca764 as useListState, $a0d645289fe9b86b$export$e7f05e985daf4b5f as useSingleSelectListState, $a02d57049d202695$export$d085fb9e920b5ca7 as ListCollection};
21
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/list/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {ListProps, ListState} from './useListState';\nexport type {SingleSelectListProps, SingleSelectListState} from './useSingleSelectListState';\nexport {useListState} from './useListState';\nexport {useSingleSelectListState} from './useSingleSelectListState';\nexport {ListCollection} from './ListCollection';\n"],"names":[],"version":3,"file":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -1,12 +1,55 @@
1
- import { Collection, Node } from "@react-stately/collections";
2
- import { CollectionBase, MultipleSelection } from "@react-types/shared";
3
- import { Key } from "react";
4
- import { SelectionManager } from "@react-stately/selection";
1
+ import { Collection, Key, Node, CollectionStateBase, SingleSelection } from "@react-types/shared";
2
+ import { MultipleSelectionStateProps, SelectionManager } from "@react-stately/selection";
3
+ export class ListCollection<T> implements Collection<Node<T>> {
4
+ constructor(nodes: Iterable<Node<T>>);
5
+ [Symbol.iterator](): Generator<Node<T>, void, undefined>;
6
+ get size(): number;
7
+ getKeys(): IterableIterator<Key>;
8
+ getKeyBefore(key: Key): Key;
9
+ getKeyAfter(key: Key): Key;
10
+ getFirstKey(): Key;
11
+ getLastKey(): Key;
12
+ getItem(key: Key): Node<T>;
13
+ at(idx: number): Node<T>;
14
+ getChildren(key: Key): Iterable<Node<T>>;
15
+ }
16
+ export interface ListProps<T> extends CollectionStateBase<T>, MultipleSelectionStateProps {
17
+ /** Filter function to generate a filtered list of nodes. */
18
+ filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>;
19
+ /** @private */
20
+ suppressTextValueWarning?: boolean;
21
+ }
5
22
  export interface ListState<T> {
23
+ /** A collection of items in the list. */
6
24
  collection: Collection<Node<T>>;
25
+ /** A set of items that are disabled. */
7
26
  disabledKeys: Set<Key>;
27
+ /** A selection manager to read and update multiple selection state. */
8
28
  selectionManager: SelectionManager;
9
29
  }
10
- export function useListState<T>(props: CollectionBase<T> & MultipleSelection): ListState<T>;
30
+ /**
31
+ * Provides state management for list-like components. Handles building a collection
32
+ * of items from props, and manages multiple selection state.
33
+ */
34
+ export function useListState<T extends object>(props: ListProps<T>): ListState<T>;
35
+ export interface SingleSelectListProps<T> extends CollectionStateBase<T>, Omit<SingleSelection, 'disallowEmptySelection'> {
36
+ /** Filter function to generate a filtered list of nodes. */
37
+ filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>;
38
+ /** @private */
39
+ suppressTextValueWarning?: boolean;
40
+ }
41
+ export interface SingleSelectListState<T> extends ListState<T> {
42
+ /** The key for the currently selected item. */
43
+ readonly selectedKey: Key | null;
44
+ /** Sets the selected key. */
45
+ setSelectedKey(key: Key | null): void;
46
+ /** The value of the currently selected item. */
47
+ readonly selectedItem: Node<T> | null;
48
+ }
49
+ /**
50
+ * Provides state management for list-like components with single selection.
51
+ * Handles building a collection of items from props, and manages selection state.
52
+ */
53
+ export function useSingleSelectListState<T extends object>(props: SingleSelectListProps<T>): SingleSelectListState<T>;
11
54
 
12
55
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/govett/dev/react-spectrum/packages/@react-stately/list/src/packages/@react-stately/list/src/useListState.ts"],"names":[],"mappings":";;;;AAiBA,2BAA2B,CAAC;IAC1B,UAAU,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC;IAChC,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IACvB,gBAAgB,EAAE,gBAAgB,CAAA;CACnC;AAED,6BAA6B,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,GAAG,iBAAiB,GAAG,UAAU,CAAC,CAAC,CAsB1F","file":"types.d.ts.map"}
1
+ {"mappings":";;AAcA,4BAA4B,CAAC,CAAE,YAAW,WAAW,KAAK,CAAC,CAAC,CAAC;gBAM/C,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IA0CnC,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;IAIV,OAAO,CAAC,GAAG,EAAE,GAAG;IAIhB,EAAE,CAAC,GAAG,EAAE,MAAM;IAKd,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;CAIzC;ACvFD,2BAA2B,CAAC,CAAE,SAAQ,oBAAoB,CAAC,CAAC,EAAE,2BAA2B;IACvF,4DAA4D;IAC5D,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACzD,eAAe;IACf,wBAAwB,CAAC,EAAE,OAAO,CAAA;CACnC;AAED,2BAA2B,CAAC;IAC1B,yCAAyC;IACzC,UAAU,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC;IAEhC,wCAAwC;IACxC,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAEvB,uEAAuE;IACvE,gBAAgB,EAAE,gBAAgB,CAAA;CACnC;AAED;;;GAGG;AACH,6BAA6B,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAwEhF;AC/FD,uCAAuC,CAAC,CAAE,SAAQ,oBAAoB,CAAC,CAAC,EAAE,IAAI,CAAC,eAAe,EAAE,wBAAwB,CAAC;IACvH,4DAA4D;IAC5D,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACzD,eAAe;IACf,wBAAwB,CAAC,EAAE,OAAO,CAAA;CACnC;AAED,uCAAuC,CAAC,CAAE,SAAQ,UAAU,CAAC,CAAC;IAC5D,+CAA+C;IAC/C,QAAQ,CAAC,WAAW,EAAE,GAAG,GAAG,IAAI,CAAC;IAEjC,6BAA6B;IAC7B,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;IAEtC,gDAAgD;IAChD,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,GAAG,IAAI,CAAA;CACtC;AAED;;;GAGG;AACH,yCAAyC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,sBAAsB,CAAC,CAAC,GAAG,sBAAsB,CAAC,CAAC,CAsCpH","sources":["packages/@react-stately/list/src/packages/@react-stately/list/src/ListCollection.ts","packages/@react-stately/list/src/packages/@react-stately/list/src/useListState.ts","packages/@react-stately/list/src/packages/@react-stately/list/src/useSingleSelectListState.ts","packages/@react-stately/list/src/packages/@react-stately/list/src/index.ts","packages/@react-stately/list/src/index.ts"],"sourcesContent":[null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {ListProps, ListState} from './useListState';\nexport type {SingleSelectListProps, SingleSelectListState} from './useSingleSelectListState';\nexport {useListState} from './useListState';\nexport {useSingleSelectListState} from './useSingleSelectListState';\nexport {ListCollection} from './ListCollection';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -0,0 +1,99 @@
1
+ var $c9aa5a224613c979$exports = require("./ListCollection.main.js");
2
+ var $5RsKl$reactstatelyselection = require("@react-stately/selection");
3
+ var $5RsKl$react = require("react");
4
+ var $5RsKl$reactstatelycollections = require("@react-stately/collections");
5
+
6
+
7
+ function $parcel$export(e, n, v, s) {
8
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
9
+ }
10
+
11
+ $parcel$export(module.exports, "useListState", () => $5450691d3629f6ea$export$2f645645f7bca764);
12
+ /*
13
+ * Copyright 2020 Adobe. All rights reserved.
14
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
15
+ * you may not use this file except in compliance with the License. You may obtain a copy
16
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software distributed under
19
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
20
+ * OF ANY KIND, either express or implied. See the License for the specific language
21
+ * governing permissions and limitations under the License.
22
+ */
23
+
24
+
25
+
26
+ function $5450691d3629f6ea$export$2f645645f7bca764(props) {
27
+ let { filter: filter } = props;
28
+ let selectionState = (0, $5RsKl$reactstatelyselection.useMultipleSelectionState)(props);
29
+ let disabledKeys = (0, $5RsKl$react.useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
30
+ props.disabledKeys
31
+ ]);
32
+ let factory = (0, $5RsKl$react.useCallback)((nodes)=>filter ? new (0, $c9aa5a224613c979$exports.ListCollection)(filter(nodes)) : new (0, $c9aa5a224613c979$exports.ListCollection)(nodes), [
33
+ filter
34
+ ]);
35
+ let context = (0, $5RsKl$react.useMemo)(()=>({
36
+ suppressTextValueWarning: props.suppressTextValueWarning
37
+ }), [
38
+ props.suppressTextValueWarning
39
+ ]);
40
+ let collection = (0, $5RsKl$reactstatelycollections.useCollection)(props, factory, context);
41
+ let selectionManager = (0, $5RsKl$react.useMemo)(()=>new (0, $5RsKl$reactstatelyselection.SelectionManager)(collection, selectionState), [
42
+ collection,
43
+ selectionState
44
+ ]);
45
+ // Reset focused key if that item is deleted from the collection.
46
+ const cachedCollection = (0, $5RsKl$react.useRef)(null);
47
+ (0, $5RsKl$react.useEffect)(()=>{
48
+ if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey) && cachedCollection.current) {
49
+ const startItem = cachedCollection.current.getItem(selectionState.focusedKey);
50
+ const cachedItemNodes = [
51
+ ...cachedCollection.current.getKeys()
52
+ ].map((key)=>{
53
+ const itemNode = cachedCollection.current.getItem(key);
54
+ return (itemNode === null || itemNode === void 0 ? void 0 : itemNode.type) === 'item' ? itemNode : null;
55
+ }).filter((node)=>node !== null);
56
+ const itemNodes = [
57
+ ...collection.getKeys()
58
+ ].map((key)=>{
59
+ const itemNode = collection.getItem(key);
60
+ return (itemNode === null || itemNode === void 0 ? void 0 : itemNode.type) === 'item' ? itemNode : null;
61
+ }).filter((node)=>node !== null);
62
+ var _cachedItemNodes_length, _itemNodes_length;
63
+ const diff = ((_cachedItemNodes_length = cachedItemNodes === null || cachedItemNodes === void 0 ? void 0 : cachedItemNodes.length) !== null && _cachedItemNodes_length !== void 0 ? _cachedItemNodes_length : 0) - ((_itemNodes_length = itemNodes === null || itemNodes === void 0 ? void 0 : itemNodes.length) !== null && _itemNodes_length !== void 0 ? _itemNodes_length : 0);
64
+ var _startItem_index, _startItem_index1, _itemNodes_length1;
65
+ let index = Math.min(diff > 1 ? Math.max(((_startItem_index = startItem === null || startItem === void 0 ? void 0 : startItem.index) !== null && _startItem_index !== void 0 ? _startItem_index : 0) - diff + 1, 0) : (_startItem_index1 = startItem === null || startItem === void 0 ? void 0 : startItem.index) !== null && _startItem_index1 !== void 0 ? _startItem_index1 : 0, ((_itemNodes_length1 = itemNodes === null || itemNodes === void 0 ? void 0 : itemNodes.length) !== null && _itemNodes_length1 !== void 0 ? _itemNodes_length1 : 0) - 1);
66
+ let newNode = null;
67
+ let isReverseSearching = false;
68
+ while(index >= 0){
69
+ if (!selectionManager.isDisabled(itemNodes[index].key)) {
70
+ newNode = itemNodes[index];
71
+ break;
72
+ }
73
+ // Find next, not disabled item.
74
+ if (index < itemNodes.length - 1 && !isReverseSearching) index++;
75
+ else {
76
+ isReverseSearching = true;
77
+ var _startItem_index2, _startItem_index3;
78
+ if (index > ((_startItem_index2 = startItem === null || startItem === void 0 ? void 0 : startItem.index) !== null && _startItem_index2 !== void 0 ? _startItem_index2 : 0)) index = (_startItem_index3 = startItem === null || startItem === void 0 ? void 0 : startItem.index) !== null && _startItem_index3 !== void 0 ? _startItem_index3 : 0;
79
+ index--;
80
+ }
81
+ }
82
+ selectionState.setFocusedKey(newNode ? newNode.key : null);
83
+ }
84
+ cachedCollection.current = collection;
85
+ }, [
86
+ collection,
87
+ selectionManager,
88
+ selectionState,
89
+ selectionState.focusedKey
90
+ ]);
91
+ return {
92
+ collection: collection,
93
+ disabledKeys: disabledKeys,
94
+ selectionManager: selectionManager
95
+ };
96
+ }
97
+
98
+
99
+ //# sourceMappingURL=useListState.main.js.map
@@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AAK,cAAhB,+BAAA,oBAAoB;oBAE/B;gBACF;YACF;YACA,eAAe,aAAa,CAAC,UAAU,QAAQ,GAAG,GAAG;QACvD;QACA,iBAAiB,OAAO,GAAG;IAC7B,GAAG;QAAC;QAAY;QAAkB;QAAgB,eAAe,UAAU;KAAC;IAE5E,OAAO;oBACL;sBACA;0BACA;IACF;AACF","sources":["packages/@react-stately/list/src/useListState.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 {Collection, CollectionStateBase, Key, Node} from '@react-types/shared';\nimport {ListCollection} from './ListCollection';\nimport {MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {useCallback, useEffect, useMemo, useRef} from 'react';\nimport {useCollection} from '@react-stately/collections';\n\nexport interface ListProps<T> extends CollectionStateBase<T>, MultipleSelectionStateProps {\n /** Filter function to generate a filtered list of nodes. */\n filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>,\n /** @private */\n suppressTextValueWarning?: boolean\n}\n\nexport interface ListState<T> {\n /** A collection of items in the list. */\n collection: Collection<Node<T>>,\n\n /** A set of items that are disabled. */\n disabledKeys: Set<Key>,\n\n /** A selection manager to read and update multiple selection state. */\n selectionManager: SelectionManager\n}\n\n/**\n * Provides state management for list-like components. Handles building a collection\n * of items from props, and manages multiple selection state.\n */\nexport function useListState<T extends object>(props: ListProps<T>): ListState<T> {\n let {filter} = props;\n\n let selectionState = useMultipleSelectionState(props);\n let disabledKeys = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n let factory = useCallback(nodes => filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes as Iterable<Node<T>>), [filter]);\n let context = useMemo(() => ({suppressTextValueWarning: props.suppressTextValueWarning}), [props.suppressTextValueWarning]);\n\n let collection = useCollection(props, factory, context);\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<Collection<Node<T>> | null>(null);\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey) && cachedCollection.current) {\n const startItem = cachedCollection.current.getItem(selectionState.focusedKey);\n const cachedItemNodes = [...cachedCollection.current.getKeys()].map(\n key => {\n const itemNode = cachedCollection.current!.getItem(key);\n return itemNode?.type === 'item' ? itemNode : null;\n }\n ).filter(node => node !== null);\n const itemNodes = [...collection.getKeys()].map(\n key => {\n const itemNode = collection.getItem(key);\n return itemNode?.type === 'item' ? itemNode : null;\n }\n ).filter(node => node !== null);\n const diff: number = (cachedItemNodes?.length ?? 0) - (itemNodes?.length ?? 0);\n let index = Math.min(\n (\n diff > 1 ?\n Math.max((startItem?.index ?? 0) - diff + 1, 0) :\n startItem?.index ?? 0\n ),\n (itemNodes?.length ?? 0) - 1);\n let newNode: Node<T> | null = null;\n let isReverseSearching = false;\n while (index >= 0) {\n if (!selectionManager.isDisabled(itemNodes[index].key)) {\n newNode = itemNodes[index];\n break;\n }\n // Find next, not disabled item.\n if (index < itemNodes.length - 1 && !isReverseSearching) {\n index++;\n // Otherwise, find previous, not disabled item.\n } else {\n isReverseSearching = true;\n if (index > (startItem?.index ?? 0)) {\n index = (startItem?.index ?? 0);\n }\n index--;\n }\n }\n selectionState.setFocusedKey(newNode ? newNode.key : null);\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager, selectionState, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n selectionManager\n };\n}\n"],"names":[],"version":3,"file":"useListState.main.js.map"}