@react-stately/list 3.4.2-nightly.3040 → 3.4.2-nightly.3064

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -1,204 +1,175 @@
1
- var {
2
- useControlledState
3
- } = require("@react-stately/utils");
4
-
5
- var _babelRuntimeHelpersExtends = $parcel$interopDefault(require("@babel/runtime/helpers/extends"));
6
-
7
- var {
8
- useCollection
9
- } = require("@react-stately/collections");
10
-
11
- var {
12
- SelectionManager,
13
- useMultipleSelectionState
14
- } = require("@react-stately/selection");
1
+ var $12Xhq$react = require("react");
2
+ var $12Xhq$reactstatelyselection = require("@react-stately/selection");
3
+ var $12Xhq$reactstatelycollections = require("@react-stately/collections");
4
+ var $12Xhq$reactstatelyutils = require("@react-stately/utils");
5
+
6
+ function $parcel$exportWildcard(dest, source) {
7
+ Object.keys(source).forEach(function(key) {
8
+ if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
9
+ return;
10
+ }
15
11
 
16
- var {
17
- useEffect,
18
- useMemo
19
- } = require("react");
12
+ Object.defineProperty(dest, key, {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return source[key];
16
+ }
17
+ });
18
+ });
20
19
 
21
- function $parcel$interopDefault(a) {
22
- return a && a.__esModule ? a.default : a;
20
+ return dest;
23
21
  }
24
-
25
- let $b42f1d5166481a4c34c86bbfb4215e1$var$_Symbol$iterator;
26
- $b42f1d5166481a4c34c86bbfb4215e1$var$_Symbol$iterator = Symbol.iterator;
27
-
28
- /*
29
- * Copyright 2020 Adobe. All rights reserved.
30
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
31
- * you may not use this file except in compliance with the License. You may obtain a copy
32
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
33
- *
34
- * Unless required by applicable law or agreed to in writing, software distributed under
35
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
36
- * OF ANY KIND, either express or implied. See the License for the specific language
37
- * governing permissions and limitations under the License.
38
- */
39
- class ListCollection {
40
- constructor(nodes) {
41
- var _last;
42
-
43
- this.keyMap = new Map();
44
- this.iterable = void 0;
45
- this.firstKey = void 0;
46
- this.lastKey = void 0;
47
- this.iterable = nodes;
48
-
49
- let visit = node => {
50
- this.keyMap.set(node.key, node);
51
-
52
- if (node.childNodes && node.type === 'section') {
53
- for (let child of node.childNodes) {
54
- visit(child);
22
+ function $parcel$export(e, n, v, s) {
23
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
24
+ }
25
+ var $0ca6fb377e78c376$exports = {};
26
+
27
+ $parcel$export($0ca6fb377e78c376$exports, "useListState", () => $0ca6fb377e78c376$export$2f645645f7bca764);
28
+
29
+ var $99881fbe031fe9b4$exports = {};
30
+
31
+ $parcel$export($99881fbe031fe9b4$exports, "ListCollection", () => $99881fbe031fe9b4$export$d085fb9e920b5ca7);
32
+ class $99881fbe031fe9b4$export$d085fb9e920b5ca7 {
33
+ constructor(nodes){
34
+ this.keyMap = new Map();
35
+ this.iterable = nodes;
36
+ let visit = (node)=>{
37
+ this.keyMap.set(node.key, node);
38
+ if (node.childNodes && node.type === 'section') for (let child of node.childNodes)visit(child);
39
+ };
40
+ for (let node2 of nodes)visit(node2);
41
+ let last;
42
+ let index = 0;
43
+ for (let [key, node1] of this.keyMap){
44
+ if (last) {
45
+ last.nextKey = key;
46
+ node1.prevKey = last.key;
47
+ } else {
48
+ this.firstKey = key;
49
+ node1.prevKey = undefined;
50
+ }
51
+ if (node1.type === 'item') node1.index = index++;
52
+ last = node1;
53
+ // Set nextKey as undefined since this might be the last node
54
+ // If it isn't the last node, last.nextKey will properly set at start of new loop
55
+ last.nextKey = undefined;
55
56
  }
56
- }
57
- };
58
-
59
- for (let node of nodes) {
60
- visit(node);
57
+ this.lastKey = last?.key;
61
58
  }
62
-
63
- let last;
64
- let index = 0;
65
-
66
- for (let [key, node] of this.keyMap) {
67
- if (last) {
68
- last.nextKey = key;
69
- node.prevKey = last.key;
70
- } else {
71
- this.firstKey = key;
72
- node.prevKey = undefined;
73
- }
74
-
75
- if (node.type === 'item') {
76
- node.index = index++;
77
- }
78
-
79
- last = node; // 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
-
82
- last.nextKey = undefined;
59
+ *[Symbol.iterator]() {
60
+ yield* this.iterable;
83
61
  }
62
+ get size() {
63
+ return this.keyMap.size;
64
+ }
65
+ getKeys() {
66
+ return this.keyMap.keys();
67
+ }
68
+ getKeyBefore(key) {
69
+ let node = this.keyMap.get(key);
70
+ return node ? node.prevKey : null;
71
+ }
72
+ getKeyAfter(key) {
73
+ let node = this.keyMap.get(key);
74
+ return node ? node.nextKey : null;
75
+ }
76
+ getFirstKey() {
77
+ return this.firstKey;
78
+ }
79
+ getLastKey() {
80
+ return this.lastKey;
81
+ }
82
+ getItem(key) {
83
+ return this.keyMap.get(key);
84
+ }
85
+ at(idx) {
86
+ const keys = [
87
+ ...this.getKeys()
88
+ ];
89
+ return this.getItem(keys[idx]);
90
+ }
91
+ }
84
92
 
85
- this.lastKey = (_last = last) == null ? void 0 : _last.key;
86
- }
87
-
88
- *[$b42f1d5166481a4c34c86bbfb4215e1$var$_Symbol$iterator]() {
89
- yield* this.iterable;
90
- }
91
-
92
- get size() {
93
- return this.keyMap.size;
94
- }
95
-
96
- getKeys() {
97
- return this.keyMap.keys();
98
- }
99
-
100
- getKeyBefore(key) {
101
- let node = this.keyMap.get(key);
102
- return node ? node.prevKey : null;
103
- }
104
-
105
- getKeyAfter(key) {
106
- let node = this.keyMap.get(key);
107
- return node ? node.nextKey : null;
108
- }
109
93
 
110
- getFirstKey() {
111
- return this.firstKey;
112
- }
113
94
 
114
- getLastKey() {
115
- return this.lastKey;
116
- }
117
95
 
118
- getItem(key) {
119
- return this.keyMap.get(key);
120
- }
96
+ function $0ca6fb377e78c376$export$2f645645f7bca764(props) {
97
+ let { filter: filter } = props;
98
+ let selectionState = $12Xhq$reactstatelyselection.useMultipleSelectionState(props);
99
+ let disabledKeys = $12Xhq$react.useMemo(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set()
100
+ , [
101
+ props.disabledKeys
102
+ ]);
103
+ let factory = (nodes)=>filter ? new $99881fbe031fe9b4$export$d085fb9e920b5ca7(filter(nodes)) : new $99881fbe031fe9b4$export$d085fb9e920b5ca7(nodes)
104
+ ;
105
+ let context = $12Xhq$react.useMemo(()=>({
106
+ suppressTextValueWarning: props.suppressTextValueWarning
107
+ })
108
+ , [
109
+ props.suppressTextValueWarning
110
+ ]);
111
+ let collection = $12Xhq$reactstatelycollections.useCollection(props, factory, context, [
112
+ filter
113
+ ]);
114
+ // Reset focused key if that item is deleted from the collection.
115
+ $12Xhq$react.useEffect(()=>{
116
+ if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
117
+ }, [
118
+ collection,
119
+ selectionState.focusedKey
120
+ ]);
121
+ return {
122
+ collection: collection,
123
+ disabledKeys: disabledKeys,
124
+ selectionManager: new $12Xhq$reactstatelyselection.SelectionManager(collection, selectionState)
125
+ };
126
+ }
121
127
 
122
- at(idx) {
123
- const keys = [...this.getKeys()];
124
- return this.getItem(keys[idx]);
125
- }
126
128
 
129
+ var $c2295dabe3bb5bbb$exports = {};
130
+
131
+ $parcel$export($c2295dabe3bb5bbb$exports, "useSingleSelectListState", () => $c2295dabe3bb5bbb$export$e7f05e985daf4b5f);
132
+
133
+
134
+
135
+ function $c2295dabe3bb5bbb$export$e7f05e985daf4b5f(props) {
136
+ let [selectedKey, setSelectedKey] = $12Xhq$reactstatelyutils.useControlledState(props.selectedKey, props.defaultSelectedKey ?? null, props.onSelectionChange);
137
+ let selectedKeys = $12Xhq$react.useMemo(()=>selectedKey != null ? [
138
+ selectedKey
139
+ ] : []
140
+ , [
141
+ selectedKey
142
+ ]);
143
+ let { collection: collection , disabledKeys: disabledKeys , selectionManager: selectionManager } = $0ca6fb377e78c376$export$2f645645f7bca764({
144
+ ...props,
145
+ selectionMode: 'single',
146
+ disallowEmptySelection: true,
147
+ allowDuplicateSelectionEvents: true,
148
+ selectedKeys: selectedKeys,
149
+ onSelectionChange: (keys)=>{
150
+ let key = keys.values().next().value;
151
+ // Always fire onSelectionChange, even if the key is the same
152
+ // as the current key (useControlledState does not).
153
+ if (key === selectedKey && props.onSelectionChange) props.onSelectionChange(key);
154
+ setSelectedKey(key);
155
+ }
156
+ });
157
+ let selectedItem = selectedKey != null ? collection.getItem(selectedKey) : null;
158
+ return {
159
+ collection: collection,
160
+ disabledKeys: disabledKeys,
161
+ selectionManager: selectionManager,
162
+ selectedKey: selectedKey,
163
+ setSelectedKey: setSelectedKey,
164
+ selectedItem: selectedItem
165
+ };
127
166
  }
128
167
 
129
- exports.ListCollection = ListCollection;
130
-
131
- /**
132
- * Provides state management for list-like components. Handles building a collection
133
- * of items from props, and manages multiple selection state.
134
- */
135
- function useListState(props) {
136
- let {
137
- filter
138
- } = props;
139
- let selectionState = useMultipleSelectionState(props);
140
- let disabledKeys = useMemo(() => props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [props.disabledKeys]);
141
-
142
- let factory = nodes => filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes);
143
-
144
- let context = useMemo(() => ({
145
- suppressTextValueWarning: props.suppressTextValueWarning
146
- }), [props.suppressTextValueWarning]);
147
- let collection = useCollection(props, factory, context, [filter]); // Reset focused key if that item is deleted from the collection.
148
-
149
- useEffect(() => {
150
- if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {
151
- selectionState.setFocusedKey(null);
152
- }
153
- }, [collection, selectionState.focusedKey]);
154
- return {
155
- collection,
156
- disabledKeys,
157
- selectionManager: new SelectionManager(collection, selectionState)
158
- };
159
- }
160
168
 
161
- exports.useListState = useListState;
162
-
163
- /**
164
- * Provides state management for list-like components with single selection.
165
- * Handles building a collection of items from props, and manages selection state.
166
- */
167
- function useSingleSelectListState(props) {
168
- var _props$defaultSelecte;
169
-
170
- let [selectedKey, setSelectedKey] = useControlledState(props.selectedKey, (_props$defaultSelecte = props.defaultSelectedKey) != null ? _props$defaultSelecte : null, props.onSelectionChange);
171
- let selectedKeys = useMemo(() => selectedKey != null ? [selectedKey] : [], [selectedKey]);
172
- let {
173
- collection,
174
- disabledKeys,
175
- selectionManager
176
- } = useListState(_babelRuntimeHelpersExtends({}, props, {
177
- selectionMode: 'single',
178
- disallowEmptySelection: true,
179
- allowDuplicateSelectionEvents: true,
180
- selectedKeys,
181
- onSelectionChange: keys => {
182
- let key = keys.values().next().value; // Always fire onSelectionChange, even if the key is the same
183
- // as the current key (useControlledState does not).
184
-
185
- if (key === selectedKey && props.onSelectionChange) {
186
- props.onSelectionChange(key);
187
- }
188
169
 
189
- setSelectedKey(key);
190
- }
191
- }));
192
- let selectedItem = selectedKey != null ? collection.getItem(selectedKey) : null;
193
- return {
194
- collection,
195
- disabledKeys,
196
- selectionManager,
197
- selectedKey,
198
- setSelectedKey,
199
- selectedItem
200
- };
201
- }
170
+ $parcel$exportWildcard(module.exports, $0ca6fb377e78c376$exports);
171
+ $parcel$exportWildcard(module.exports, $c2295dabe3bb5bbb$exports);
172
+ $parcel$exportWildcard(module.exports, $99881fbe031fe9b4$exports);
173
+
202
174
 
203
- exports.useSingleSelectListState = useSingleSelectListState;
204
175
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,SAASA,sBAAT,CAAgCC,CAAhC,EAAmC;AACjC,SAAOA,CAAC,IAAIA,CAAC,CAACC,UAAP,GAAoBD,CAAC,CAACE,OAAtB,GAAgCF,CAAvC;AACD;;;wDC6DGG,MAAM,CAACC,Q;;AA/DX;;;;;;;;;;;AAeO,MAAMC,cAAN,CAAuD;AAM5DC,EAAAA,WAAW,CAACC,KAAD,EAA2B;AAAA;;AAAA,SAL9BC,MAK8B,GALF,IAAIC,GAAJ,EAKE;AAAA,SAJ9BC,QAI8B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CAC9Cf,KAD8C;AAEjDwB,IAAAA,aAAa,EAAE,QAFkC;AAGjDC,IAAAA,sBAAsB,EAAE,IAHyB;AAIjDC,IAAAA,6BAA6B,EAAE,IAJkB;AAKjDH,IAAAA,YALiD;AAMjDD,IAAAA,iBAAiB,EAAGhC,IAAD,IAAoB;AACrC,UAAIX,GAAG,GAAGW,IAAI,CAACqC,MAAL,GAAcC,IAAd,GAAqBC,KAA/B,CADqC,CAGrC;AACA;;AACA,UAAIlD,GAAG,KAAKuC,WAAR,IAAuBlB,KAAK,CAACsB,iBAAjC,EAAoD;AAClDtB,QAAAA,KAAK,CAACsB,iBAAN,CAAwB3C,GAAxB;AACD;;AAEDwC,MAAAA,cAAc,CAACxC,GAAD,CAAd;AACD;AAhBgD,KAAnD;AAmBA,MAAImD,YAAY,GAAGZ,WAAW,IAAI,IAAf,GACfR,UAAU,CAACd,OAAX,CAAmBsB,WAAnB,CADe,GAEf,IAFJ;AAIA,SAAO;AACLR,IAAAA,UADK;AAELN,IAAAA,YAFK;AAGLW,IAAAA,gBAHK;AAILG,IAAAA,WAJK;AAKLC,IAAAA,cALK;AAMLW,IAAAA;AANK,GAAP;AAQD","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/@react-stately/list/src/ListCollection.ts","./packages/@react-stately/list/src/useListState.ts","./packages/@react-stately/list/src/useSingleSelectListState.ts"],"sourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\n","/*\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, Node} from '@react-types/shared';\nimport {Key} from 'react';\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;\n private lastKey: Key;\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>;\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;\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;\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.firstKey;\n }\n\n getLastKey() {\n return this.lastKey;\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","/*\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, CollectionBase, Node} from '@react-types/shared';\nimport {Key, useEffect, useMemo} from 'react';\nimport {ListCollection} from './ListCollection';\nimport {MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {useCollection} from '@react-stately/collections';\n\nexport interface ListProps<T> extends CollectionBase<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 = nodes => filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes as Iterable<Node<T>>);\n let context = useMemo(() => ({suppressTextValueWarning: props.suppressTextValueWarning}), [props.suppressTextValueWarning]);\n\n let collection = useCollection(props, factory, context, [filter]);\n\n // Reset focused key if that item is deleted from the collection.\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {\n selectionState.setFocusedKey(null);\n }\n }, [collection, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n selectionManager: new SelectionManager(collection, selectionState)\n };\n}\n","/*\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 {CollectionBase, SingleSelection} from '@react-types/shared';\nimport {Key, useMemo} from 'react';\nimport {ListState, useListState} from './useListState';\nimport {Node} from '@react-types/shared';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface SingleSelectListProps<T> extends CollectionBase<T>, Omit<SingleSelection, 'disallowEmptySelection'> {\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 SingleSelectListState<T> extends ListState<T> {\n /** The key for the currently selected item. */\n readonly selectedKey: Key,\n\n /** Sets the selected key. */\n setSelectedKey(key: Key): void,\n\n /** The value of the currently selected item. */\n readonly selectedItem: Node<T>\n}\n\n/**\n * Provides state management for list-like components with single selection.\n * Handles building a collection of items from props, and manages selection state.\n */\nexport function useSingleSelectListState<T extends object>(props: SingleSelectListProps<T>): SingleSelectListState<T> {\n let [selectedKey, setSelectedKey] = useControlledState(props.selectedKey, props.defaultSelectedKey ?? null, props.onSelectionChange);\n let selectedKeys = useMemo(() => selectedKey != null ? [selectedKey] : [], [selectedKey]);\n let {collection, disabledKeys, selectionManager} = useListState({\n ...props,\n selectionMode: 'single',\n disallowEmptySelection: true,\n allowDuplicateSelectionEvents: true,\n selectedKeys,\n onSelectionChange: (keys: Set<Key>) => {\n let key = keys.values().next().value;\n\n // Always fire onSelectionChange, even if the key is the same\n // as the current key (useControlledState does not).\n if (key === selectedKey && props.onSelectionChange) {\n props.onSelectionChange(key);\n }\n\n setSelectedKey(key);\n }\n });\n\n let selectedItem = selectedKey != null\n ? collection.getItem(selectedKey)\n : null;\n\n return {\n collection,\n disabledKeys,\n selectionManager,\n selectedKey,\n setSelectedKey,\n selectedItem\n };\n}\n"],"names":["$parcel$interopDefault","a","__esModule","default","Symbol","iterator","ListCollection","constructor","nodes","keyMap","Map","iterable","firstKey","lastKey","visit","node","set","key","childNodes","type","child","last","index","nextKey","prevKey","undefined","size","getKeys","keys","getKeyBefore","get","getKeyAfter","getFirstKey","getLastKey","getItem","at","idx","useListState","props","filter","selectionState","useMultipleSelectionState","disabledKeys","useMemo","Set","factory","context","suppressTextValueWarning","collection","useCollection","useEffect","focusedKey","setFocusedKey","selectionManager","SelectionManager","useSingleSelectListState","selectedKey","setSelectedKey","useControlledState","defaultSelectedKey","onSelectionChange","selectedKeys","selectionMode","disallowEmptySelection","allowDuplicateSelectionEvents","values","next","value","selectedItem"],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MEea,yCAAc;gBAMb,KAAwB,CAAE,CAAC;QANlC,IAsFN,CArFS,MAAM,GAAsB,GAAG,CAAC,GAAG;QAMzC,IAAI,CAAC,QAAQ,GAAG,KAAK;QAErB,GAAG,CAAC,KAAK,IAAI,IAAa,GAAK,CAAC;YAC9B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI;YAE9B,EAAE,EAAE,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,IAAI,KAAK,CAAS,UAC5C,GAAG,EAAE,GAAG,CAAC,KAAK,I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E,GAAG,KAAK,WAAW,IAAI,KAAK,CAAC,iBAAiB,EAChD,KAAK,CAAC,iBAAiB,CAAC,GAAG;YAG7B,cAAc,CAAC,GAAG;QACpB,CAAC;IACH,CAAC;IAED,GAAG,CAAC,YAAY,GAAG,WAAW,IAAI,IAAI,GAClC,UAAU,CAAC,OAAO,CAAC,WAAW,IAC9B,IAAI;IAER,MAAM,CAAC,CAAC;oBACN,UAAU;sBACV,YAAY;0BACZ,gBAAgB;qBAChB,WAAW;wBACX,cAAc;sBACd,YAAY;IACd,CAAC;AACH,CAAC;;","sources":["packages/@react-stately/list/src/index.ts","packages/@react-stately/list/src/useListState.ts","packages/@react-stately/list/src/ListCollection.ts","packages/@react-stately/list/src/useSingleSelectListState.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 * from './useListState';\nexport * from './useSingleSelectListState';\nexport * from './ListCollection';\n","/*\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, CollectionBase, Node} from '@react-types/shared';\nimport {Key, useEffect, useMemo} from 'react';\nimport {ListCollection} from './ListCollection';\nimport {MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {useCollection} from '@react-stately/collections';\n\nexport interface ListProps<T> extends CollectionBase<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 = nodes => filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes as Iterable<Node<T>>);\n let context = useMemo(() => ({suppressTextValueWarning: props.suppressTextValueWarning}), [props.suppressTextValueWarning]);\n\n let collection = useCollection(props, factory, context, [filter]);\n\n // Reset focused key if that item is deleted from the collection.\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {\n selectionState.setFocusedKey(null);\n }\n }, [collection, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n selectionManager: new SelectionManager(collection, selectionState)\n };\n}\n","/*\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, Node} from '@react-types/shared';\nimport {Key} from 'react';\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;\n private lastKey: Key;\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>;\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;\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;\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.firstKey;\n }\n\n getLastKey() {\n return this.lastKey;\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","/*\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 {CollectionBase, SingleSelection} from '@react-types/shared';\nimport {Key, useMemo} from 'react';\nimport {ListState, useListState} from './useListState';\nimport {Node} from '@react-types/shared';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface SingleSelectListProps<T> extends CollectionBase<T>, Omit<SingleSelection, 'disallowEmptySelection'> {\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 SingleSelectListState<T> extends ListState<T> {\n /** The key for the currently selected item. */\n readonly selectedKey: Key,\n\n /** Sets the selected key. */\n setSelectedKey(key: Key): void,\n\n /** The value of the currently selected item. */\n readonly selectedItem: Node<T>\n}\n\n/**\n * Provides state management for list-like components with single selection.\n * Handles building a collection of items from props, and manages selection state.\n */\nexport function useSingleSelectListState<T extends object>(props: SingleSelectListProps<T>): SingleSelectListState<T> {\n let [selectedKey, setSelectedKey] = useControlledState(props.selectedKey, props.defaultSelectedKey ?? null, props.onSelectionChange);\n let selectedKeys = useMemo(() => selectedKey != null ? [selectedKey] : [], [selectedKey]);\n let {collection, disabledKeys, selectionManager} = useListState({\n ...props,\n selectionMode: 'single',\n disallowEmptySelection: true,\n allowDuplicateSelectionEvents: true,\n selectedKeys,\n onSelectionChange: (keys: Set<Key>) => {\n let key = keys.values().next().value;\n\n // Always fire onSelectionChange, even if the key is the same\n // as the current key (useControlledState does not).\n if (key === selectedKey && props.onSelectionChange) {\n props.onSelectionChange(key);\n }\n\n setSelectedKey(key);\n }\n });\n\n let selectedItem = selectedKey != null\n ? collection.getItem(selectedKey)\n : null;\n\n return {\n collection,\n disabledKeys,\n selectionManager,\n selectedKey,\n setSelectedKey,\n selectedItem\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,179 +1,157 @@
1
- import { useControlledState } from "@react-stately/utils";
2
- import _babelRuntimeHelpersEsmExtends from "@babel/runtime/helpers/esm/extends";
3
- import { useCollection } from "@react-stately/collections";
4
- import { SelectionManager, useMultipleSelectionState } from "@react-stately/selection";
5
- import { useEffect, useMemo } from "react";
6
- let $ed5d55e571caf578a4f08babbaa26be$var$_Symbol$iterator;
7
- $ed5d55e571caf578a4f08babbaa26be$var$_Symbol$iterator = Symbol.iterator;
8
-
9
- /*
10
- * Copyright 2020 Adobe. All rights reserved.
11
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License. You may obtain a copy
13
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
- *
15
- * Unless required by applicable law or agreed to in writing, software distributed under
16
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
- * OF ANY KIND, either express or implied. See the License for the specific language
18
- * governing permissions and limitations under the License.
19
- */
20
- export class ListCollection {
21
- constructor(nodes) {
22
- var _last;
23
-
24
- this.keyMap = new Map();
25
- this.iterable = void 0;
26
- this.firstKey = void 0;
27
- this.lastKey = void 0;
28
- this.iterable = nodes;
29
-
30
- let visit = node => {
31
- this.keyMap.set(node.key, node);
32
-
33
- if (node.childNodes && node.type === 'section') {
34
- for (let child of node.childNodes) {
35
- visit(child);
36
- }
37
- }
38
- };
1
+ import {useMemo as $lSmZo$useMemo, useEffect as $lSmZo$useEffect} from "react";
2
+ import {useMultipleSelectionState as $lSmZo$useMultipleSelectionState, SelectionManager as $lSmZo$SelectionManager} from "@react-stately/selection";
3
+ import {useCollection as $lSmZo$useCollection} from "@react-stately/collections";
4
+ import {useControlledState as $lSmZo$useControlledState} from "@react-stately/utils";
39
5
 
40
- for (let node of nodes) {
41
- visit(node);
6
+ function $parcel$export(e, n, v, s) {
7
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
+ }
9
+ var $fb0a1a056c6baecb$exports = {};
10
+
11
+ $parcel$export($fb0a1a056c6baecb$exports, "useListState", () => $fb0a1a056c6baecb$export$2f645645f7bca764);
12
+
13
+ var $c43ff68ee1e9bc26$exports = {};
14
+
15
+ $parcel$export($c43ff68ee1e9bc26$exports, "ListCollection", () => $c43ff68ee1e9bc26$export$d085fb9e920b5ca7);
16
+ class $c43ff68ee1e9bc26$export$d085fb9e920b5ca7 {
17
+ constructor(nodes){
18
+ this.keyMap = new Map();
19
+ this.iterable = nodes;
20
+ let visit = (node)=>{
21
+ this.keyMap.set(node.key, node);
22
+ if (node.childNodes && node.type === 'section') for (let child of node.childNodes)visit(child);
23
+ };
24
+ for (let node2 of nodes)visit(node2);
25
+ let last;
26
+ let index = 0;
27
+ for (let [key, node1] of this.keyMap){
28
+ if (last) {
29
+ last.nextKey = key;
30
+ node1.prevKey = last.key;
31
+ } else {
32
+ this.firstKey = key;
33
+ node1.prevKey = undefined;
34
+ }
35
+ if (node1.type === 'item') node1.index = index++;
36
+ last = node1;
37
+ // Set nextKey as undefined since this might be the last node
38
+ // If it isn't the last node, last.nextKey will properly set at start of new loop
39
+ last.nextKey = undefined;
40
+ }
41
+ this.lastKey = last?.key;
42
42
  }
43
-
44
- let last;
45
- let index = 0;
46
-
47
- for (let [key, node] of this.keyMap) {
48
- if (last) {
49
- last.nextKey = key;
50
- node.prevKey = last.key;
51
- } else {
52
- this.firstKey = key;
53
- node.prevKey = undefined;
54
- }
55
-
56
- if (node.type === 'item') {
57
- node.index = index++;
58
- }
59
-
60
- last = node; // Set nextKey as undefined since this might be the last node
61
- // If it isn't the last node, last.nextKey will properly set at start of new loop
62
-
63
- last.nextKey = undefined;
43
+ *[Symbol.iterator]() {
44
+ yield* this.iterable;
64
45
  }
46
+ get size() {
47
+ return this.keyMap.size;
48
+ }
49
+ getKeys() {
50
+ return this.keyMap.keys();
51
+ }
52
+ getKeyBefore(key) {
53
+ let node = this.keyMap.get(key);
54
+ return node ? node.prevKey : null;
55
+ }
56
+ getKeyAfter(key) {
57
+ let node = this.keyMap.get(key);
58
+ return node ? node.nextKey : null;
59
+ }
60
+ getFirstKey() {
61
+ return this.firstKey;
62
+ }
63
+ getLastKey() {
64
+ return this.lastKey;
65
+ }
66
+ getItem(key) {
67
+ return this.keyMap.get(key);
68
+ }
69
+ at(idx) {
70
+ const keys = [
71
+ ...this.getKeys()
72
+ ];
73
+ return this.getItem(keys[idx]);
74
+ }
75
+ }
65
76
 
66
- this.lastKey = (_last = last) == null ? void 0 : _last.key;
67
- }
68
-
69
- *[$ed5d55e571caf578a4f08babbaa26be$var$_Symbol$iterator]() {
70
- yield* this.iterable;
71
- }
72
-
73
- get size() {
74
- return this.keyMap.size;
75
- }
76
77
 
77
- getKeys() {
78
- return this.keyMap.keys();
79
- }
80
78
 
81
- getKeyBefore(key) {
82
- let node = this.keyMap.get(key);
83
- return node ? node.prevKey : null;
84
- }
85
79
 
86
- getKeyAfter(key) {
87
- let node = this.keyMap.get(key);
88
- return node ? node.nextKey : null;
89
- }
80
+ function $fb0a1a056c6baecb$export$2f645645f7bca764(props) {
81
+ let { filter: filter } = props;
82
+ let selectionState = $lSmZo$useMultipleSelectionState(props);
83
+ let disabledKeys = $lSmZo$useMemo(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set()
84
+ , [
85
+ props.disabledKeys
86
+ ]);
87
+ let factory = (nodes)=>filter ? new $c43ff68ee1e9bc26$export$d085fb9e920b5ca7(filter(nodes)) : new $c43ff68ee1e9bc26$export$d085fb9e920b5ca7(nodes)
88
+ ;
89
+ let context = $lSmZo$useMemo(()=>({
90
+ suppressTextValueWarning: props.suppressTextValueWarning
91
+ })
92
+ , [
93
+ props.suppressTextValueWarning
94
+ ]);
95
+ let collection = $lSmZo$useCollection(props, factory, context, [
96
+ filter
97
+ ]);
98
+ // Reset focused key if that item is deleted from the collection.
99
+ $lSmZo$useEffect(()=>{
100
+ if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
101
+ }, [
102
+ collection,
103
+ selectionState.focusedKey
104
+ ]);
105
+ return {
106
+ collection: collection,
107
+ disabledKeys: disabledKeys,
108
+ selectionManager: new $lSmZo$SelectionManager(collection, selectionState)
109
+ };
110
+ }
90
111
 
91
- getFirstKey() {
92
- return this.firstKey;
93
- }
94
112
 
95
- getLastKey() {
96
- return this.lastKey;
97
- }
113
+ var $1c80eb4391abdea4$exports = {};
114
+
115
+ $parcel$export($1c80eb4391abdea4$exports, "useSingleSelectListState", () => $1c80eb4391abdea4$export$e7f05e985daf4b5f);
116
+
117
+
118
+
119
+ function $1c80eb4391abdea4$export$e7f05e985daf4b5f(props) {
120
+ let [selectedKey, setSelectedKey] = $lSmZo$useControlledState(props.selectedKey, props.defaultSelectedKey ?? null, props.onSelectionChange);
121
+ let selectedKeys = $lSmZo$useMemo(()=>selectedKey != null ? [
122
+ selectedKey
123
+ ] : []
124
+ , [
125
+ selectedKey
126
+ ]);
127
+ let { collection: collection , disabledKeys: disabledKeys , selectionManager: selectionManager } = $fb0a1a056c6baecb$export$2f645645f7bca764({
128
+ ...props,
129
+ selectionMode: 'single',
130
+ disallowEmptySelection: true,
131
+ allowDuplicateSelectionEvents: true,
132
+ selectedKeys: selectedKeys,
133
+ onSelectionChange: (keys)=>{
134
+ let key = keys.values().next().value;
135
+ // Always fire onSelectionChange, even if the key is the same
136
+ // as the current key (useControlledState does not).
137
+ if (key === selectedKey && props.onSelectionChange) props.onSelectionChange(key);
138
+ setSelectedKey(key);
139
+ }
140
+ });
141
+ let selectedItem = selectedKey != null ? collection.getItem(selectedKey) : null;
142
+ return {
143
+ collection: collection,
144
+ disabledKeys: disabledKeys,
145
+ selectionManager: selectionManager,
146
+ selectedKey: selectedKey,
147
+ setSelectedKey: setSelectedKey,
148
+ selectedItem: selectedItem
149
+ };
150
+ }
98
151
 
99
- getItem(key) {
100
- return this.keyMap.get(key);
101
- }
102
152
 
103
- at(idx) {
104
- const keys = [...this.getKeys()];
105
- return this.getItem(keys[idx]);
106
- }
107
153
 
108
- }
109
154
 
110
- /**
111
- * Provides state management for list-like components. Handles building a collection
112
- * of items from props, and manages multiple selection state.
113
- */
114
- export function useListState(props) {
115
- let {
116
- filter
117
- } = props;
118
- let selectionState = useMultipleSelectionState(props);
119
- let disabledKeys = useMemo(() => props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [props.disabledKeys]);
120
-
121
- let factory = nodes => filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes);
122
-
123
- let context = useMemo(() => ({
124
- suppressTextValueWarning: props.suppressTextValueWarning
125
- }), [props.suppressTextValueWarning]);
126
- let collection = useCollection(props, factory, context, [filter]); // Reset focused key if that item is deleted from the collection.
127
-
128
- useEffect(() => {
129
- if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {
130
- selectionState.setFocusedKey(null);
131
- }
132
- }, [collection, selectionState.focusedKey]);
133
- return {
134
- collection,
135
- disabledKeys,
136
- selectionManager: new SelectionManager(collection, selectionState)
137
- };
138
- }
139
155
 
140
- /**
141
- * Provides state management for list-like components with single selection.
142
- * Handles building a collection of items from props, and manages selection state.
143
- */
144
- export function useSingleSelectListState(props) {
145
- var _props$defaultSelecte;
146
-
147
- let [selectedKey, setSelectedKey] = useControlledState(props.selectedKey, (_props$defaultSelecte = props.defaultSelectedKey) != null ? _props$defaultSelecte : null, props.onSelectionChange);
148
- let selectedKeys = useMemo(() => selectedKey != null ? [selectedKey] : [], [selectedKey]);
149
- let {
150
- collection,
151
- disabledKeys,
152
- selectionManager
153
- } = useListState(_babelRuntimeHelpersEsmExtends({}, props, {
154
- selectionMode: 'single',
155
- disallowEmptySelection: true,
156
- allowDuplicateSelectionEvents: true,
157
- selectedKeys,
158
- onSelectionChange: keys => {
159
- let key = keys.values().next().value; // Always fire onSelectionChange, even if the key is the same
160
- // as the current key (useControlledState does not).
161
-
162
- if (key === selectedKey && props.onSelectionChange) {
163
- props.onSelectionChange(key);
164
- }
165
-
166
- setSelectedKey(key);
167
- }
168
- }));
169
- let selectedItem = selectedKey != null ? collection.getItem(selectedKey) : null;
170
- return {
171
- collection,
172
- disabledKeys,
173
- selectionManager,
174
- selectedKey,
175
- setSelectedKey,
176
- selectedItem
177
- };
178
- }
156
+ export {$fb0a1a056c6baecb$export$2f645645f7bca764 as useListState, $1c80eb4391abdea4$export$e7f05e985daf4b5f as useSingleSelectListState, $c43ff68ee1e9bc26$export$d085fb9e920b5ca7 as ListCollection};
179
157
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
1
- {"mappings":";;;;;;wDA+DIA,MAAM,CAACC,Q;;AA/DX;;;;;;;;;;;OAeO,MAAMC,cAAN,CAAuD;AAM5DC,EAAAA,WAAW,CAACC,KAAD,EAA2B;AAAA;;AAAA,SAL9BC,MAK8B,GALF,IAAIC,GAAJ,EAKE;AAAA,SAJ9BC,QAI8B;AAAA,SAH9BC,QAG8B;AAAA,SAF9BC,OAE8B;AACpC,SAAKF,QAAL,GAAgBH,KAAhB;;AAEA,QAAIM,KAAK,GAAIC,IAAD,IAAmB;AAC7B,WAAKN,MAAL,CAAYO,GAAZ,CAAgBD,IAAI,CAACE,GAArB,EAA0BF,IAA1B;;AAEA,UAAIA,IAAI,CAACG,UAAL,IAAmBH,IAAI,CAACI,IAAL,KAAc,SAArC,EAAgD;AAC9C,aAAK,IAAIC,KAAT,IAAkBL,IAAI,CAACG,UAAvB,EAAmC;AACjCJ,UAAAA,KAAK,CAACM,KAAD,CAAL;AACD;AACF;AACF,KARD;;AAUA,SAAK,IAAIL,IAAT,IAAiBP,KAAjB,EAAwB;AACtBM,MAAAA,KAAK,CAACC,IAAD,CAAL;AACD;;AAED,QAAIM,IAAJ;AACA,QAAIC,KAAK,GAAG,CAAZ;;AACA,SAAK,IAAI,CAACL,GAAD,EAAMF,IAAN,CAAT,IAAwB,KAAKN,MAA7B,EAAqC;AACnC,UAAIY,IAAJ,EAAU;AACRA,QAAAA,IAAI,CAACE,OAAL,GAAeN,GAAf;AACAF,QAAAA,IAAI,CAACS,OAAL,GAAeH,IAAI,CAACJ,GAApB;AACD,OAHD,MAGO;AACL,aAAKL,QAAL,GAAgBK,GAAhB;AACAF,QAAAA,IAAI,CAACS,OAAL,GAAeC,SAAf;AACD;;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I,CAACkB,WAAD,EAAcC,cAAd,IAAgCC,kBAAkB,CAACpB,KAAK,CAACkB,WAAP,2BAAoBlB,KAAK,CAACqB,kBAA1B,oCAAgD,IAAhD,EAAsDrB,KAAK,CAACsB,iBAA5D,CAAtD;AACA,MAAIC,YAAY,GAAGlB,OAAO,CAAC,MAAMa,WAAW,IAAI,IAAf,GAAsB,CAACA,WAAD,CAAtB,GAAsC,EAA7C,EAAiD,CAACA,WAAD,CAAjD,CAA1B;AACA,MAAI;AAACR,IAAAA,UAAD;AAAaN,IAAAA,YAAb;AAA2BW,IAAAA;AAA3B,MAA+C,gDAC9Cf,KAD8C;AAEjDwB,IAAAA,aAAa,EAAE,QAFkC;AAGjDC,IAAAA,sBAAsB,EAAE,IAHyB;AAIjDC,IAAAA,6BAA6B,EAAE,IAJkB;AAKjDH,IAAAA,YALiD;AAMjDD,IAAAA,iBAAiB,EAAGhC,IAAD,IAAoB;AACrC,UAAIX,GAAG,GAAGW,IAAI,CAACqC,MAAL,GAAcC,IAAd,GAAqBC,KAA/B,CADqC,CAGrC;AACA;;AACA,UAAIlD,GAAG,KAAKuC,WAAR,IAAuBlB,KAAK,CAACsB,iBAAjC,EAAoD;AAClDtB,QAAAA,KAAK,CAACsB,iBAAN,CAAwB3C,GAAxB;AACD;;AAEDwC,MAAAA,cAAc,CAACxC,GAAD,CAAd;AACD;AAhBgD,KAAnD;AAmBA,MAAImD,YAAY,GAAGZ,WAAW,IAAI,IAAf,GACfR,UAAU,CAACd,OAAX,CAAmBsB,WAAnB,CADe,GAEf,IAFJ;AAIA,SAAO;AACLR,IAAAA,UADK;AAELN,IAAAA,YAFK;AAGLW,IAAAA,gBAHK;AAILG,IAAAA,WAJK;AAKLC,IAAAA,cALK;AAMLW,IAAAA;AANK,GAAP;AAQD","sources":["./packages/@react-stately/list/src/ListCollection.ts","./packages/@react-stately/list/src/useListState.ts","./packages/@react-stately/list/src/useSingleSelectListState.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, Node} from '@react-types/shared';\nimport {Key} from 'react';\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;\n private lastKey: Key;\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>;\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;\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;\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.firstKey;\n }\n\n getLastKey() {\n return this.lastKey;\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","/*\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, CollectionBase, Node} from '@react-types/shared';\nimport {Key, useEffect, useMemo} from 'react';\nimport {ListCollection} from './ListCollection';\nimport {MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {useCollection} from '@react-stately/collections';\n\nexport interface ListProps<T> extends CollectionBase<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 = nodes => filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes as Iterable<Node<T>>);\n let context = useMemo(() => ({suppressTextValueWarning: props.suppressTextValueWarning}), [props.suppressTextValueWarning]);\n\n let collection = useCollection(props, factory, context, [filter]);\n\n // Reset focused key if that item is deleted from the collection.\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {\n selectionState.setFocusedKey(null);\n }\n }, [collection, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n selectionManager: new SelectionManager(collection, selectionState)\n };\n}\n","/*\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 {CollectionBase, SingleSelection} from '@react-types/shared';\nimport {Key, useMemo} from 'react';\nimport {ListState, useListState} from './useListState';\nimport {Node} from '@react-types/shared';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface SingleSelectListProps<T> extends CollectionBase<T>, Omit<SingleSelection, 'disallowEmptySelection'> {\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 SingleSelectListState<T> extends ListState<T> {\n /** The key for the currently selected item. */\n readonly selectedKey: Key,\n\n /** Sets the selected key. */\n setSelectedKey(key: Key): void,\n\n /** The value of the currently selected item. */\n readonly selectedItem: Node<T>\n}\n\n/**\n * Provides state management for list-like components with single selection.\n * Handles building a collection of items from props, and manages selection state.\n */\nexport function useSingleSelectListState<T extends object>(props: SingleSelectListProps<T>): SingleSelectListState<T> {\n let [selectedKey, setSelectedKey] = useControlledState(props.selectedKey, props.defaultSelectedKey ?? null, props.onSelectionChange);\n let selectedKeys = useMemo(() => selectedKey != null ? [selectedKey] : [], [selectedKey]);\n let {collection, disabledKeys, selectionManager} = useListState({\n ...props,\n selectionMode: 'single',\n disallowEmptySelection: true,\n allowDuplicateSelectionEvents: true,\n selectedKeys,\n onSelectionChange: (keys: Set<Key>) => {\n let key = keys.values().next().value;\n\n // Always fire onSelectionChange, even if the key is the same\n // as the current key (useControlledState does not).\n if (key === selectedKey && props.onSelectionChange) {\n props.onSelectionChange(key);\n }\n\n setSelectedKey(key);\n }\n });\n\n let selectedItem = selectedKey != null\n ? collection.getItem(selectedKey)\n : null;\n\n return {\n collection,\n disabledKeys,\n selectionManager,\n selectedKey,\n setSelectedKey,\n selectedItem\n };\n}\n"],"names":["Symbol","iterator","ListCollection","constructor","nodes","keyMap","Map","iterable","firstKey","lastKey","visit","node","set","key","childNodes","type","child","last","index","nextKey","prevKey","undefined","size","getKeys","keys","getKeyBefore","get","getKeyAfter","getFirstKey","getLastKey","getItem","at","idx","useListState","props","filter","selectionState","useMultipleSelectionState","disabledKeys","useMemo","Set","factory","context","suppressTextValueWarning","collection","useCollection","useEffect","focusedKey","setFocusedKey","selectionManager","SelectionManager","useSingleSelectListState","selectedKey","setSelectedKey","useControlledState","defaultSelectedKey","onSelectionChange","selectedKeys","selectionMode","disallowEmptySelection","allowDuplicateSelectionEvents","values","next","value","selectedItem"],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;MEea,yCAAc;gBAMb,KAAwB,CAAE,CAAC;QANlC,IAsFN,CArFS,MAAM,GAAsB,GAAG,CAAC,GAAG;QAMzC,IAAI,CAAC,QAAQ,GAAG,KAAK;QAErB,GAAG,CAAC,KAAK,IAAI,IAAa,GAAK,CAAC;YAC9B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI;YAE9B,EAAE,EAAE,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,IAAI,KAAK,CAAS,UAC5C,GAAG,EAAE,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,UAAU,CAC/B,KAAK,CAAC,KAAK;QAGjB,CAAC;QAED,GAAG,EAAE,GAAG,CAAC,KAAI,IAAI,KAAK,CACpB,KAAK,CAAC,KAAI;QAGZ,GAAG,CAAC,IAAI;QACR,GAAG,CAAC,KAAK,GAAG,C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,CAAC,OAAO,CAAC,WAAW,IAC9B,IAAI;IAER,MAAM,CAAC,CAAC;oBACN,UAAU;sBACV,YAAY;0BACZ,gBAAgB;qBAChB,WAAW;wBACX,cAAc;sBACd,YAAY;IACd,CAAC;AACH,CAAC;;","sources":["packages/@react-stately/list/src/index.ts","packages/@react-stately/list/src/useListState.ts","packages/@react-stately/list/src/ListCollection.ts","packages/@react-stately/list/src/useSingleSelectListState.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 * from './useListState';\nexport * from './useSingleSelectListState';\nexport * from './ListCollection';\n","/*\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, CollectionBase, Node} from '@react-types/shared';\nimport {Key, useEffect, useMemo} from 'react';\nimport {ListCollection} from './ListCollection';\nimport {MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {useCollection} from '@react-stately/collections';\n\nexport interface ListProps<T> extends CollectionBase<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 = nodes => filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes as Iterable<Node<T>>);\n let context = useMemo(() => ({suppressTextValueWarning: props.suppressTextValueWarning}), [props.suppressTextValueWarning]);\n\n let collection = useCollection(props, factory, context, [filter]);\n\n // Reset focused key if that item is deleted from the collection.\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {\n selectionState.setFocusedKey(null);\n }\n }, [collection, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n selectionManager: new SelectionManager(collection, selectionState)\n };\n}\n","/*\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, Node} from '@react-types/shared';\nimport {Key} from 'react';\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;\n private lastKey: Key;\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>;\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;\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;\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.firstKey;\n }\n\n getLastKey() {\n return this.lastKey;\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","/*\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 {CollectionBase, SingleSelection} from '@react-types/shared';\nimport {Key, useMemo} from 'react';\nimport {ListState, useListState} from './useListState';\nimport {Node} from '@react-types/shared';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface SingleSelectListProps<T> extends CollectionBase<T>, Omit<SingleSelection, 'disallowEmptySelection'> {\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 SingleSelectListState<T> extends ListState<T> {\n /** The key for the currently selected item. */\n readonly selectedKey: Key,\n\n /** Sets the selected key. */\n setSelectedKey(key: Key): void,\n\n /** The value of the currently selected item. */\n readonly selectedItem: Node<T>\n}\n\n/**\n * Provides state management for list-like components with single selection.\n * Handles building a collection of items from props, and manages selection state.\n */\nexport function useSingleSelectListState<T extends object>(props: SingleSelectListProps<T>): SingleSelectListState<T> {\n let [selectedKey, setSelectedKey] = useControlledState(props.selectedKey, props.defaultSelectedKey ?? null, props.onSelectionChange);\n let selectedKeys = useMemo(() => selectedKey != null ? [selectedKey] : [], [selectedKey]);\n let {collection, disabledKeys, selectionManager} = useListState({\n ...props,\n selectionMode: 'single',\n disallowEmptySelection: true,\n allowDuplicateSelectionEvents: true,\n selectedKeys,\n onSelectionChange: (keys: Set<Key>) => {\n let key = keys.values().next().value;\n\n // Always fire onSelectionChange, even if the key is the same\n // as the current key (useControlledState does not).\n if (key === selectedKey && props.onSelectionChange) {\n props.onSelectionChange(key);\n }\n\n setSelectedKey(key);\n }\n });\n\n let selectedItem = selectedKey != null\n ? collection.getItem(selectedKey)\n : null;\n\n return {\n collection,\n disabledKeys,\n selectionManager,\n selectedKey,\n setSelectedKey,\n selectedItem\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -5,11 +5,11 @@ export class ListCollection<T> implements Collection<Node<T>> {
5
5
  constructor(nodes: Iterable<Node<T>>);
6
6
  [Symbol.iterator](): Generator<Node<T>, void, undefined>;
7
7
  get size(): number;
8
- getKeys(): IterableIterator<string | number>;
9
- getKeyBefore(key: Key): string | number;
10
- getKeyAfter(key: Key): string | number;
11
- getFirstKey(): string | number;
12
- getLastKey(): string | number;
8
+ getKeys(): IterableIterator<Key>;
9
+ getKeyBefore(key: Key): Key;
10
+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,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,CAAC;IAE1B,6BAA6B;IAC7B,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;IAE/B,gDAAgD;IAChD,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,CAAA;CAC/B;AAED;A;A;GAGG;AACH,yCAAyC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,sBAAsB,CAAC,CAAC,GAAG,sBAAsB,CAAC,CAAC,CAkCpH","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"],"sourcesContent":[null,null,null,null],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;;AAeA,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;CAIf;ACnFD,2BAA2B,CAAC,CAAE,SAAQ,eAAe,CAAC,CAAC,EA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/@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 * from './useListState';\nexport * from './useSingleSelectListState';\nexport * from './ListCollection';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/list",
3
- "version": "3.4.2-nightly.3040+e2b459ab9",
3
+ "version": "3.4.2-nightly.3064+5115b76b6",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -18,10 +18,10 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@babel/runtime": "^7.6.2",
21
- "@react-stately/collections": "3.0.0-nightly.1349+e2b459ab9",
22
- "@react-stately/selection": "3.0.0-nightly.1349+e2b459ab9",
23
- "@react-stately/utils": "3.0.0-nightly.1349+e2b459ab9",
24
- "@react-types/shared": "3.0.0-nightly.1349+e2b459ab9"
21
+ "@react-stately/collections": "3.0.0-nightly.1373+5115b76b6",
22
+ "@react-stately/selection": "3.0.0-nightly.1373+5115b76b6",
23
+ "@react-stately/utils": "3.0.0-nightly.1373+5115b76b6",
24
+ "@react-types/shared": "3.0.0-nightly.1373+5115b76b6"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "react": "^16.8.0 || ^17.0.0-rc.1"
@@ -29,5 +29,5 @@
29
29
  "publishConfig": {
30
30
  "access": "public"
31
31
  },
32
- "gitHead": "e2b459ab996abd06b0913942e9801b88493ed940"
32
+ "gitHead": "5115b76b63cba6843d5e7de2ef5ec3a41a1bff3c"
33
33
  }