@react-stately/combobox 3.0.2-nightly.3038 → 3.0.2-nightly.3062

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,320 +1,238 @@
1
- var {
2
- useMenuTriggerState
3
- } = require("@react-stately/menu");
4
-
5
- var {
6
- useEffect,
7
- useMemo,
8
- useRef,
9
- useState
10
- } = require("react");
11
-
12
- var {
13
- useControlledState
14
- } = require("@react-stately/utils");
15
-
16
- var {
17
- ListCollection,
18
- useSingleSelectListState
19
- } = require("@react-stately/list");
20
-
21
- var _babelRuntimeHelpersExtends = $parcel$interopDefault(require("@babel/runtime/helpers/extends"));
22
-
23
- function $parcel$interopDefault(a) {
24
- return a && a.__esModule ? a.default : a;
25
- }
26
-
27
- /**
28
- * Provides state management for a combo box component. Handles building a collection
29
- * of items from props and manages the option selection state of the combo box. In addition, it tracks the input value,
30
- * focus state, and other properties of the combo box.
31
- */
32
- function useComboBoxState(props) {
33
- var _props$defaultInputVa, _props$items, _ref, _props$selectedKey, _collection$getItem$t2, _collection$getItem2;
34
-
35
- let {
36
- defaultFilter,
37
- menuTrigger = 'input',
38
- allowsEmptyCollection = false,
39
- allowsCustomValue,
40
- shouldCloseOnBlur = true
41
- } = props;
42
- let [showAllItems, setShowAllItems] = useState(false);
43
- let [isFocused, setFocusedState] = useState(false);
44
- let [inputValue, setInputValue] = useControlledState(props.inputValue, (_props$defaultInputVa = props.defaultInputValue) != null ? _props$defaultInputVa : '', props.onInputChange);
45
-
46
- let onSelectionChange = key => {
47
- if (props.onSelectionChange) {
48
- props.onSelectionChange(key);
49
- } // If key is the same, reset the inputValue and close the menu
50
- // (scenario: user clicks on already selected option)
51
-
52
-
53
- if (key === selectedKey) {
54
- resetInputValue();
55
- triggerState.close();
56
- }
57
- };
58
-
59
- let {
60
- collection,
61
- selectionManager,
62
- selectedKey,
63
- setSelectedKey,
64
- selectedItem,
65
- disabledKeys
66
- } = useSingleSelectListState(_babelRuntimeHelpersExtends({}, props, {
67
- onSelectionChange,
68
- items: (_props$items = props.items) != null ? _props$items : props.defaultItems
69
- })); // Preserve original collection so we can show all items on demand
70
-
71
- let originalCollection = collection;
72
- let filteredCollection = useMemo(() => // No default filter if items are controlled.
73
- props.items != null || !defaultFilter ? collection : $a21047c5b4305a7d5e80cc48828d4cd$var$filterCollection(collection, inputValue, defaultFilter), [collection, inputValue, defaultFilter, props.items]); // Track what action is attempting to open the menu
74
-
75
- let menuOpenTrigger = useRef('focus');
76
-
77
- let onOpenChange = open => {
78
- if (props.onOpenChange) {
79
- props.onOpenChange(open, open ? menuOpenTrigger.current : undefined);
80
- }
81
- };
82
-
83
- let triggerState = useMenuTriggerState(_babelRuntimeHelpersExtends({}, props, {
84
- onOpenChange,
85
- isOpen: undefined,
86
- defaultOpen: undefined
87
- }));
88
-
89
- let open = (focusStrategy, trigger) => {
90
- let displayAllItems = trigger === 'manual' || trigger === 'focus' && menuTrigger === 'focus'; // Prevent open operations from triggering if there is nothing to display
91
- // Also prevent open operations from triggering if items are uncontrolled but defaultItems is empty, even if displayAllItems is true.
92
- // This is to prevent comboboxes with empty defaultItems from opening but allow controlled items comboboxes to open even if the inital list is empty (assumption is user will provide swap the empty list with a base list via onOpenChange returning `menuTrigger` manual)
93
-
94
- if (allowsEmptyCollection || filteredCollection.size > 0 || displayAllItems && originalCollection.size > 0 || props.items) {
95
- if (displayAllItems && !triggerState.isOpen && props.items === undefined) {
96
- // Show all items if menu is manually opened. Only care about this if items are undefined
97
- setShowAllItems(true);
98
- }
99
-
100
- menuOpenTrigger.current = trigger;
101
- triggerState.open(focusStrategy);
102
- }
103
- };
104
-
105
- let toggle = (focusStrategy, trigger) => {
106
- let displayAllItems = trigger === 'manual' || trigger === 'focus' && menuTrigger === 'focus'; // If the menu is closed and there is nothing to display, early return so toggle isn't called to prevent extraneous onOpenChange
107
-
108
- if (!(allowsEmptyCollection || filteredCollection.size > 0 || displayAllItems && originalCollection.size > 0 || props.items) && !triggerState.isOpen) {
1
+ var $6wEwz$reactstatelylist = require("@react-stately/list");
2
+ var $6wEwz$reactstatelyutils = require("@react-stately/utils");
3
+ var $6wEwz$react = require("react");
4
+ var $6wEwz$reactstatelymenu = require("@react-stately/menu");
5
+
6
+ function $parcel$exportWildcard(dest, source) {
7
+ Object.keys(source).forEach(function(key) {
8
+ if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
109
9
  return;
110
10
  }
111
11
 
112
- if (displayAllItems && !triggerState.isOpen && props.items === undefined) {
113
- // Show all items if menu is toggled open. Only care about this if items are undefined
114
- setShowAllItems(true);
115
- } // Only update the menuOpenTrigger if menu is currently closed
116
-
117
-
118
- if (!triggerState.isOpen) {
119
- menuOpenTrigger.current = trigger;
120
- }
121
-
122
- triggerState.toggle(focusStrategy);
123
- };
124
-
125
- let lastValue = useRef(inputValue);
126
-
127
- let resetInputValue = () => {
128
- var _collection$getItem$t, _collection$getItem;
129
-
130
- let itemText = (_collection$getItem$t = (_collection$getItem = collection.getItem(selectedKey)) == null ? void 0 : _collection$getItem.textValue) != null ? _collection$getItem$t : '';
131
- lastValue.current = itemText;
132
- setInputValue(itemText);
133
- };
134
-
135
- let isInitialRender = useRef(true);
136
- let lastSelectedKey = useRef((_ref = (_props$selectedKey = props.selectedKey) != null ? _props$selectedKey : props.defaultSelectedKey) != null ? _ref : null);
137
- let lastSelectedKeyText = useRef((_collection$getItem$t2 = (_collection$getItem2 = collection.getItem(selectedKey)) == null ? void 0 : _collection$getItem2.textValue) != null ? _collection$getItem$t2 : ''); // intentional omit dependency array, want this to happen on every render
138
- // eslint-disable-next-line react-hooks/exhaustive-deps
139
-
140
- useEffect(() => {
141
- var _collection$getItem$t3, _collection$getItem3;
142
-
143
- // Open and close menu automatically when the input value changes if the input is focused,
144
- // and there are items in the collection or allowEmptyCollection is true.
145
- if (isFocused && (filteredCollection.size > 0 || allowsEmptyCollection) && !triggerState.isOpen && inputValue !== lastValue.current && menuTrigger !== 'manual') {
146
- open(null, 'input');
147
- } // Close the menu if the collection is empty. Don't close menu if filtered collection size is 0
148
- // but we are currently showing all items via button press
149
-
150
-
151
- if (!showAllItems && !allowsEmptyCollection && triggerState.isOpen && filteredCollection.size === 0) {
152
- triggerState.close();
153
- } // Close when an item is selected.
154
-
155
-
156
- if (selectedKey != null && selectedKey !== lastSelectedKey.current) {
157
- triggerState.close();
158
- } // Clear focused key when input value changes and display filtered collection again.
159
-
160
-
161
- if (inputValue !== lastValue.current) {
162
- selectionManager.setFocusedKey(null);
163
- setShowAllItems(false); // Set selectedKey to null when the user clears the input.
164
- // If controlled, this is the application developer's responsibility.
165
-
166
- if (inputValue === '' && (props.inputValue === undefined || props.selectedKey === undefined)) {
167
- setSelectedKey(null);
12
+ Object.defineProperty(dest, key, {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return source[key];
168
16
  }
169
- } // If it is the intial render and inputValue isn't controlled nor has an intial value, set input to match current selected key if any
170
-
171
-
172
- if (isInitialRender.current && props.inputValue === undefined && props.defaultInputValue === undefined) {
173
- resetInputValue();
174
- } // If the selectedKey changed, update the input value.
175
- // Do nothing if both inputValue and selectedKey are controlled.
176
- // In this case, it's the user's responsibility to update inputValue in onSelectionChange.
177
-
178
-
179
- if (selectedKey !== lastSelectedKey.current && (props.inputValue === undefined || props.selectedKey === undefined)) {
180
- resetInputValue();
181
- } else {
182
- lastValue.current = inputValue;
183
- } // Update the inputValue if the selected item's text changes from its last tracked value.
184
- // This is to handle cases where a selectedKey is specified but the items aren't available (async loading) or the selected item's text value updates.
185
- // Only reset if the user isn't currently within the field so we don't erroneously modify user input.
186
- // If inputValue is controlled, it is the user's responsibility to update the inputValue when items change.
187
-
188
-
189
- let selectedItemText = (_collection$getItem$t3 = (_collection$getItem3 = collection.getItem(selectedKey)) == null ? void 0 : _collection$getItem3.textValue) != null ? _collection$getItem$t3 : '';
190
-
191
- if (!isFocused && selectedKey != null && props.inputValue === undefined && selectedKey === lastSelectedKey.current) {
192
- if (lastSelectedKeyText.current !== selectedItemText) {
193
- lastValue.current = selectedItemText;
194
- setInputValue(selectedItemText);
195
- }
196
- }
197
-
198
- isInitialRender.current = false;
199
- lastSelectedKey.current = selectedKey;
200
- lastSelectedKeyText.current = selectedItemText;
17
+ });
201
18
  });
202
- useEffect(() => {
203
- // Reset focused key when the menu closes
204
- if (!triggerState.isOpen) {
205
- selectionManager.setFocusedKey(null);
206
- }
207
- }, [triggerState.isOpen, selectionManager]); // Revert input value and close menu
208
-
209
- let revert = () => {
210
- if (allowsCustomValue && selectedKey == null) {
211
- commitCustomValue();
212
- } else {
213
- commitSelection();
214
- }
215
- };
216
-
217
- let commitCustomValue = () => {
218
- lastSelectedKey.current = null;
219
- setSelectedKey(null);
220
- triggerState.close();
221
- };
222
-
223
- let commitSelection = () => {
224
- // If multiple things are controlled, call onSelectionChange
225
- if (props.selectedKey !== undefined && props.inputValue !== undefined) {
226
- var _collection$getItem$t4, _collection$getItem4;
227
-
228
- props.onSelectionChange(selectedKey); // Stop menu from reopening from useEffect
229
-
230
- let itemText = (_collection$getItem$t4 = (_collection$getItem4 = collection.getItem(selectedKey)) == null ? void 0 : _collection$getItem4.textValue) != null ? _collection$getItem$t4 : '';
231
- lastValue.current = itemText;
232
- triggerState.close();
233
- } else {
234
- // If only a single aspect of combobox is controlled, reset input value and close menu for the user
235
- resetInputValue();
236
- triggerState.close();
237
- }
238
- };
239
-
240
- let commit = () => {
241
- if (triggerState.isOpen && selectionManager.focusedKey != null) {
242
- // Reset inputValue and close menu here if the selected key is already the focused key. Otherwise
243
- // fire onSelectionChange to allow the application to control the closing.
244
- if (selectedKey === selectionManager.focusedKey) {
245
- commitSelection();
246
- } else {
247
- setSelectedKey(selectionManager.focusedKey);
248
- }
249
- } else if (allowsCustomValue) {
250
- commitCustomValue();
251
- } else {
252
- // Reset inputValue and close menu if no item is focused but user triggers a commit
253
- commitSelection();
254
- }
255
- };
256
-
257
- let setFocused = isFocused => {
258
- if (isFocused) {
259
- if (menuTrigger === 'focus') {
260
- open(null, 'focus');
261
- }
262
- } else if (shouldCloseOnBlur) {
263
- var _collection$getItem$t5, _collection$getItem5;
264
-
265
- let itemText = (_collection$getItem$t5 = (_collection$getItem5 = collection.getItem(selectedKey)) == null ? void 0 : _collection$getItem5.textValue) != null ? _collection$getItem$t5 : '';
266
19
 
267
- if (allowsCustomValue && inputValue !== itemText) {
268
- commitCustomValue();
269
- } else {
20
+ return dest;
21
+ }
22
+ function $parcel$export(e, n, v, s) {
23
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
24
+ }
25
+ var $1e7015be92cd531f$exports = {};
26
+
27
+ $parcel$export($1e7015be92cd531f$exports, "useComboBoxState", () => $1e7015be92cd531f$export$b453a3bfd4a5fa9e);
28
+
29
+
30
+
31
+
32
+ function $1e7015be92cd531f$export$b453a3bfd4a5fa9e(props) {
33
+ let { defaultFilter: defaultFilter , menuTrigger: menuTrigger = 'input' , allowsEmptyCollection: allowsEmptyCollection = false , allowsCustomValue: allowsCustomValue , shouldCloseOnBlur: shouldCloseOnBlur = true } = props;
34
+ let [showAllItems, setShowAllItems] = $6wEwz$react.useState(false);
35
+ let [isFocused1, setFocusedState] = $6wEwz$react.useState(false);
36
+ let [inputValue, setInputValue] = $6wEwz$reactstatelyutils.useControlledState(props.inputValue, props.defaultInputValue ?? '', props.onInputChange);
37
+ let onSelectionChange = (key)=>{
38
+ if (props.onSelectionChange) props.onSelectionChange(key);
39
+ // If key is the same, reset the inputValue and close the menu
40
+ // (scenario: user clicks on already selected option)
41
+ if (key === selectedKey) {
42
+ resetInputValue();
43
+ triggerState.close();
44
+ }
45
+ };
46
+ let { collection: collection , selectionManager: selectionManager , selectedKey: selectedKey , setSelectedKey: setSelectedKey , selectedItem: selectedItem , disabledKeys: disabledKeys } = $6wEwz$reactstatelylist.useSingleSelectListState({
47
+ ...props,
48
+ onSelectionChange: onSelectionChange,
49
+ items: props.items ?? props.defaultItems
50
+ });
51
+ // Preserve original collection so we can show all items on demand
52
+ let originalCollection = collection;
53
+ let filteredCollection = $6wEwz$react.useMemo(()=>// No default filter if items are controlled.
54
+ props.items != null || !defaultFilter ? collection : $1e7015be92cd531f$var$filterCollection(collection, inputValue, defaultFilter)
55
+ , [
56
+ collection,
57
+ inputValue,
58
+ defaultFilter,
59
+ props.items
60
+ ]);
61
+ // Track what action is attempting to open the menu
62
+ let menuOpenTrigger = $6wEwz$react.useRef('focus');
63
+ let onOpenChange = (open)=>{
64
+ if (props.onOpenChange) props.onOpenChange(open, open ? menuOpenTrigger.current : undefined);
65
+ };
66
+ let triggerState = $6wEwz$reactstatelymenu.useMenuTriggerState({
67
+ ...props,
68
+ onOpenChange: onOpenChange,
69
+ isOpen: undefined,
70
+ defaultOpen: undefined
71
+ });
72
+ let open1 = (focusStrategy, trigger)=>{
73
+ let displayAllItems = trigger === 'manual' || trigger === 'focus' && menuTrigger === 'focus';
74
+ // Prevent open operations from triggering if there is nothing to display
75
+ // Also prevent open operations from triggering if items are uncontrolled but defaultItems is empty, even if displayAllItems is true.
76
+ // This is to prevent comboboxes with empty defaultItems from opening but allow controlled items comboboxes to open even if the inital list is empty (assumption is user will provide swap the empty list with a base list via onOpenChange returning `menuTrigger` manual)
77
+ if (allowsEmptyCollection || filteredCollection.size > 0 || displayAllItems && originalCollection.size > 0 || props.items) {
78
+ if (displayAllItems && !triggerState.isOpen && props.items === undefined) // Show all items if menu is manually opened. Only care about this if items are undefined
79
+ setShowAllItems(true);
80
+ menuOpenTrigger.current = trigger;
81
+ triggerState.open(focusStrategy);
82
+ }
83
+ };
84
+ let toggle = (focusStrategy, trigger)=>{
85
+ let displayAllItems = trigger === 'manual' || trigger === 'focus' && menuTrigger === 'focus';
86
+ // If the menu is closed and there is nothing to display, early return so toggle isn't called to prevent extraneous onOpenChange
87
+ if (!(allowsEmptyCollection || filteredCollection.size > 0 || displayAllItems && originalCollection.size > 0 || props.items) && !triggerState.isOpen) return;
88
+ if (displayAllItems && !triggerState.isOpen && props.items === undefined) // Show all items if menu is toggled open. Only care about this if items are undefined
89
+ setShowAllItems(true);
90
+ // Only update the menuOpenTrigger if menu is currently closed
91
+ if (!triggerState.isOpen) menuOpenTrigger.current = trigger;
92
+ triggerState.toggle(focusStrategy);
93
+ };
94
+ let lastValue = $6wEwz$react.useRef(inputValue);
95
+ let resetInputValue = ()=>{
96
+ let itemText = collection.getItem(selectedKey)?.textValue ?? '';
97
+ lastValue.current = itemText;
98
+ setInputValue(itemText);
99
+ };
100
+ let isInitialRender = $6wEwz$react.useRef(true);
101
+ let lastSelectedKey = $6wEwz$react.useRef((props.selectedKey ?? props.defaultSelectedKey) ?? null);
102
+ let lastSelectedKeyText = $6wEwz$react.useRef(collection.getItem(selectedKey)?.textValue ?? '');
103
+ // intentional omit dependency array, want this to happen on every render
104
+ // eslint-disable-next-line react-hooks/exhaustive-deps
105
+ $6wEwz$react.useEffect(()=>{
106
+ // Open and close menu automatically when the input value changes if the input is focused,
107
+ // and there are items in the collection or allowEmptyCollection is true.
108
+ if (isFocused1 && (filteredCollection.size > 0 || allowsEmptyCollection) && !triggerState.isOpen && inputValue !== lastValue.current && menuTrigger !== 'manual') open1(null, 'input');
109
+ // Close the menu if the collection is empty. Don't close menu if filtered collection size is 0
110
+ // but we are currently showing all items via button press
111
+ if (!showAllItems && !allowsEmptyCollection && triggerState.isOpen && filteredCollection.size === 0) triggerState.close();
112
+ // Close when an item is selected.
113
+ if (selectedKey != null && selectedKey !== lastSelectedKey.current) triggerState.close();
114
+ // Clear focused key when input value changes and display filtered collection again.
115
+ if (inputValue !== lastValue.current) {
116
+ selectionManager.setFocusedKey(null);
117
+ setShowAllItems(false);
118
+ // Set selectedKey to null when the user clears the input.
119
+ // If controlled, this is the application developer's responsibility.
120
+ if (inputValue === '' && (props.inputValue === undefined || props.selectedKey === undefined)) setSelectedKey(null);
121
+ }
122
+ // If it is the intial render and inputValue isn't controlled nor has an intial value, set input to match current selected key if any
123
+ if (isInitialRender.current && props.inputValue === undefined && props.defaultInputValue === undefined) resetInputValue();
124
+ // If the selectedKey changed, update the input value.
125
+ // Do nothing if both inputValue and selectedKey are controlled.
126
+ // In this case, it's the user's responsibility to update inputValue in onSelectionChange.
127
+ if (selectedKey !== lastSelectedKey.current && (props.inputValue === undefined || props.selectedKey === undefined)) resetInputValue();
128
+ else lastValue.current = inputValue;
129
+ // Update the inputValue if the selected item's text changes from its last tracked value.
130
+ // This is to handle cases where a selectedKey is specified but the items aren't available (async loading) or the selected item's text value updates.
131
+ // Only reset if the user isn't currently within the field so we don't erroneously modify user input.
132
+ // If inputValue is controlled, it is the user's responsibility to update the inputValue when items change.
133
+ let selectedItemText = collection.getItem(selectedKey)?.textValue ?? '';
134
+ if (!isFocused1 && selectedKey != null && props.inputValue === undefined && selectedKey === lastSelectedKey.current) {
135
+ if (lastSelectedKeyText.current !== selectedItemText) {
136
+ lastValue.current = selectedItemText;
137
+ setInputValue(selectedItemText);
138
+ }
139
+ }
140
+ isInitialRender.current = false;
141
+ lastSelectedKey.current = selectedKey;
142
+ lastSelectedKeyText.current = selectedItemText;
143
+ });
144
+ $6wEwz$react.useEffect(()=>{
145
+ // Reset focused key when the menu closes
146
+ if (!triggerState.isOpen) selectionManager.setFocusedKey(null);
147
+ }, [
148
+ triggerState.isOpen,
149
+ selectionManager
150
+ ]);
151
+ // Revert input value and close menu
152
+ let revert = ()=>{
153
+ if (allowsCustomValue && selectedKey == null) commitCustomValue();
154
+ else commitSelection();
155
+ };
156
+ let commitCustomValue = ()=>{
157
+ lastSelectedKey.current = null;
158
+ setSelectedKey(null);
159
+ triggerState.close();
160
+ };
161
+ let commitSelection = ()=>{
162
+ // If multiple things are controlled, call onSelectionChange
163
+ if (props.selectedKey !== undefined && props.inputValue !== undefined) {
164
+ props.onSelectionChange(selectedKey);
165
+ // Stop menu from reopening from useEffect
166
+ let itemText = collection.getItem(selectedKey)?.textValue ?? '';
167
+ lastValue.current = itemText;
168
+ triggerState.close();
169
+ } else {
170
+ // If only a single aspect of combobox is controlled, reset input value and close menu for the user
171
+ resetInputValue();
172
+ triggerState.close();
173
+ }
174
+ };
175
+ let commit = ()=>{
176
+ if (triggerState.isOpen && selectionManager.focusedKey != null) {
177
+ // Reset inputValue and close menu here if the selected key is already the focused key. Otherwise
178
+ // fire onSelectionChange to allow the application to control the closing.
179
+ if (selectedKey === selectionManager.focusedKey) commitSelection();
180
+ else setSelectedKey(selectionManager.focusedKey);
181
+ } else if (allowsCustomValue) commitCustomValue();
182
+ else // Reset inputValue and close menu if no item is focused but user triggers a commit
270
183
  commitSelection();
271
- }
272
- }
273
-
274
- setFocusedState(isFocused);
275
- };
276
-
277
- return _babelRuntimeHelpersExtends({}, triggerState, {
278
- toggle,
279
- open,
280
- selectionManager,
281
- selectedKey,
282
- setSelectedKey,
283
- disabledKeys,
284
- isFocused,
285
- setFocused,
286
- selectedItem,
287
- collection: showAllItems ? originalCollection : filteredCollection,
288
- inputValue,
289
- setInputValue,
290
- commit,
291
- revert
292
- });
184
+ };
185
+ let setFocused = (isFocused)=>{
186
+ if (isFocused) {
187
+ if (menuTrigger === 'focus') open1(null, 'focus');
188
+ } else if (shouldCloseOnBlur) {
189
+ let itemText = collection.getItem(selectedKey)?.textValue ?? '';
190
+ if (allowsCustomValue && inputValue !== itemText) commitCustomValue();
191
+ else commitSelection();
192
+ }
193
+ setFocusedState(isFocused);
194
+ };
195
+ return {
196
+ ...triggerState,
197
+ toggle: toggle,
198
+ open: open1,
199
+ selectionManager: selectionManager,
200
+ selectedKey: selectedKey,
201
+ setSelectedKey: setSelectedKey,
202
+ disabledKeys: disabledKeys,
203
+ isFocused: isFocused1,
204
+ setFocused: setFocused,
205
+ selectedItem: selectedItem,
206
+ collection: showAllItems ? originalCollection : filteredCollection,
207
+ inputValue: inputValue,
208
+ setInputValue: setInputValue,
209
+ commit: commit,
210
+ revert: revert
211
+ };
293
212
  }
294
-
295
- exports.useComboBoxState = useComboBoxState;
296
-
297
- function $a21047c5b4305a7d5e80cc48828d4cd$var$filterCollection(collection, inputValue, filter) {
298
- return new ListCollection($a21047c5b4305a7d5e80cc48828d4cd$var$filterNodes(collection, inputValue, filter));
213
+ function $1e7015be92cd531f$var$filterCollection(collection, inputValue, filter) {
214
+ return new $6wEwz$reactstatelylist.ListCollection($1e7015be92cd531f$var$filterNodes(collection, inputValue, filter));
215
+ }
216
+ function $1e7015be92cd531f$var$filterNodes(nodes, inputValue, filter) {
217
+ let filteredNode = [];
218
+ for (let node of nodes){
219
+ if (node.type === 'section' && node.hasChildNodes) {
220
+ let filtered = $1e7015be92cd531f$var$filterNodes(node.childNodes, inputValue, filter);
221
+ if ([
222
+ ...filtered
223
+ ].length > 0) filteredNode.push({
224
+ ...node,
225
+ childNodes: filtered
226
+ });
227
+ } else if (node.type !== 'section' && filter(node.textValue, inputValue)) filteredNode.push({
228
+ ...node
229
+ });
230
+ }
231
+ return filteredNode;
299
232
  }
300
233
 
301
- function $a21047c5b4305a7d5e80cc48828d4cd$var$filterNodes(nodes, inputValue, filter) {
302
- let filteredNode = [];
303
234
 
304
- for (let node of nodes) {
305
- if (node.type === 'section' && node.hasChildNodes) {
306
- let filtered = $a21047c5b4305a7d5e80cc48828d4cd$var$filterNodes(node.childNodes, inputValue, filter);
235
+ $parcel$exportWildcard(module.exports, $1e7015be92cd531f$exports);
307
236
 
308
- if ([...filtered].length > 0) {
309
- filteredNode.push(_babelRuntimeHelpersExtends({}, node, {
310
- childNodes: filtered
311
- }));
312
- }
313
- } else if (node.type !== 'section' && filter(node.textValue, inputValue)) {
314
- filteredNode.push(_babelRuntimeHelpersExtends({}, node));
315
- }
316
- }
317
237
 
318
- return filteredNode;
319
- }
320
238
  //# 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,CAA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AApC,EAAmD;AACjD,UAAIC,QAAQ,GAAGN,gDAAW,CAACG,IAAI,CAACI,UAAN,EAAkB/D,UAAlB,EAA8BsD,MAA9B,CAA1B;;AACA,UAAI,CAAC,GAAGQ,QAAJ,EAAcE,MAAd,GAAuB,CAA3B,EAA8B;AAC5BN,QAAAA,YAAY,CAACO,IAAb,iCAAsBN,IAAtB;AAA4BI,UAAAA,UAAU,EAAED;AAAxC;AACD;AACF,KALD,MAKO,IAAIH,IAAI,CAACC,IAAL,KAAc,SAAd,IAA2BN,MAAM,CAACK,IAAI,CAACnB,SAAN,EAAiBxC,UAAjB,CAArC,EAAmE;AACxE0D,MAAAA,YAAY,CAACO,IAAb,iCAAsBN,IAAtB;AACD;AACF;;AACD,SAAOD,YAAP;AACD","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/@react-stately/combobox/src/useComboBoxState.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, FocusStrategy, Node} from '@react-types/shared';\nimport {ComboBoxProps, MenuTriggerAction} from '@react-types/combobox';\nimport {ListCollection, useSingleSelectListState} from '@react-stately/list';\nimport {SelectState} from '@react-stately/select';\nimport {useControlledState} from '@react-stately/utils';\nimport {useEffect, useMemo, useRef, useState} from 'react';\nimport {useMenuTriggerState} from '@react-stately/menu';\n\nexport interface ComboBoxState<T> extends SelectState<T> {\n /** The current value of the combo box input. */\n inputValue: string,\n /** Sets the value of the combo box input. */\n setInputValue(value: string): void,\n /** Selects the currently focused item and updates the input value. */\n commit(): void,\n /** Opens the menu. */\n open(focusStrategy?: FocusStrategy | null, trigger?: MenuTriggerAction): void,\n /** Toggles the menu. */\n toggle(focusStrategy?: FocusStrategy | null, trigger?: MenuTriggerAction): void,\n /** Resets the input value to the previously selected item's text if any and closes the menu. */\n revert(): void\n}\n\ntype FilterFn = (textValue: string, inputValue: string) => boolean;\ninterface ComboBoxStateProps<T> extends ComboBoxProps<T> {\n /** The filter function used to determine if a option should be included in the combo box list. */\n defaultFilter?: FilterFn,\n /** Whether the combo box allows the menu to be open when the collection is empty. */\n allowsEmptyCollection?: boolean,\n /** Whether the combo box menu should close on blur. */\n shouldCloseOnBlur?: boolean\n}\n\n/**\n * Provides state management for a combo box component. Handles building a collection\n * of items from props and manages the option selection state of the combo box. In addition, it tracks the input value,\n * focus state, and other properties of the combo box.\n */\nexport function useComboBoxState<T extends object>(props: ComboBoxStateProps<T>): ComboBoxState<T> {\n let {\n defaultFilter,\n menuTrigger = 'input',\n allowsEmptyCollection = false,\n allowsCustomValue,\n shouldCloseOnBlur = true\n } = props;\n\n let [showAllItems, setShowAllItems] = useState(false);\n let [isFocused, setFocusedState] = useState(false);\n let [inputValue, setInputValue] = useControlledState(\n props.inputValue,\n props.defaultInputValue ?? '',\n props.onInputChange\n );\n\n let onSelectionChange = (key) => {\n if (props.onSelectionChange) {\n props.onSelectionChange(key);\n }\n\n // If key is the same, reset the inputValue and close the menu\n // (scenario: user clicks on already selected option)\n if (key === selectedKey) {\n resetInputValue();\n triggerState.close();\n }\n };\n\n let {collection, selectionManager, selectedKey, setSelectedKey, selectedItem, disabledKeys} = useSingleSelectListState({\n ...props,\n onSelectionChange,\n items: props.items ?? props.defaultItems\n });\n\n // Preserve original collection so we can show all items on demand\n let originalCollection = collection;\n let filteredCollection = useMemo(() => (\n // No default filter if items are controlled.\n props.items != null || !defaultFilter\n ? collection\n : filterCollection(collection, inputValue, defaultFilter)\n ), [collection, inputValue, defaultFilter, props.items]);\n\n // Track what action is attempting to open the menu\n let menuOpenTrigger = useRef('focus' as MenuTriggerAction);\n let onOpenChange = (open: boolean) => {\n if (props.onOpenChange) {\n props.onOpenChange(open, open ? menuOpenTrigger.current : undefined);\n }\n };\n\n let triggerState = useMenuTriggerState({...props, onOpenChange, isOpen: undefined, defaultOpen: undefined});\n let open = (focusStrategy?: FocusStrategy, trigger?: MenuTriggerAction) => {\n let displayAllItems = (trigger === 'manual' || (trigger === 'focus' && menuTrigger === 'focus'));\n // Prevent open operations from triggering if there is nothing to display\n // Also prevent open operations from triggering if items are uncontrolled but defaultItems is empty, even if displayAllItems is true.\n // This is to prevent comboboxes with empty defaultItems from opening but allow controlled items comboboxes to open even if the inital list is empty (assumption is user will provide swap the empty list with a base list via onOpenChange returning `menuTrigger` manual)\n if (allowsEmptyCollection || filteredCollection.size > 0 || (displayAllItems && originalCollection.size > 0) || props.items) {\n if (displayAllItems && !triggerState.isOpen && props.items === undefined) {\n // Show all items if menu is manually opened. Only care about this if items are undefined\n setShowAllItems(true);\n }\n\n menuOpenTrigger.current = trigger;\n triggerState.open(focusStrategy);\n }\n };\n\n let toggle = (focusStrategy?: FocusStrategy, trigger?: MenuTriggerAction) => {\n let displayAllItems = (trigger === 'manual' || (trigger === 'focus' && menuTrigger === 'focus'));\n // If the menu is closed and there is nothing to display, early return so toggle isn't called to prevent extraneous onOpenChange\n if (!(allowsEmptyCollection || filteredCollection.size > 0 || (displayAllItems && originalCollection.size > 0) || props.items) && !triggerState.isOpen) {\n return;\n }\n\n if (displayAllItems && !triggerState.isOpen && props.items === undefined) {\n // Show all items if menu is toggled open. Only care about this if items are undefined\n setShowAllItems(true);\n }\n\n // Only update the menuOpenTrigger if menu is currently closed\n if (!triggerState.isOpen) {\n menuOpenTrigger.current = trigger;\n }\n\n triggerState.toggle(focusStrategy);\n };\n\n let lastValue = useRef(inputValue);\n let resetInputValue = () => {\n let itemText = collection.getItem(selectedKey)?.textValue ?? '';\n lastValue.current = itemText;\n setInputValue(itemText);\n };\n\n let isInitialRender = useRef(true);\n let lastSelectedKey = useRef(props.selectedKey ?? props.defaultSelectedKey ?? null);\n let lastSelectedKeyText = useRef(collection.getItem(selectedKey)?.textValue ?? '');\n // intentional omit dependency array, want this to happen on every render\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(() => {\n // Open and close menu automatically when the input value changes if the input is focused,\n // and there are items in the collection or allowEmptyCollection is true.\n if (\n isFocused &&\n (filteredCollection.size > 0 || allowsEmptyCollection) &&\n !triggerState.isOpen &&\n inputValue !== lastValue.current &&\n menuTrigger !== 'manual'\n ) {\n open(null, 'input');\n }\n\n // Close the menu if the collection is empty. Don't close menu if filtered collection size is 0\n // but we are currently showing all items via button press\n if (\n !showAllItems &&\n !allowsEmptyCollection &&\n triggerState.isOpen &&\n filteredCollection.size === 0\n ) {\n triggerState.close();\n }\n\n // Close when an item is selected.\n if (\n selectedKey != null &&\n selectedKey !== lastSelectedKey.current\n ) {\n triggerState.close();\n }\n\n // Clear focused key when input value changes and display filtered collection again.\n if (inputValue !== lastValue.current) {\n selectionManager.setFocusedKey(null);\n setShowAllItems(false);\n\n // Set selectedKey to null when the user clears the input.\n // If controlled, this is the application developer's responsibility.\n if (inputValue === '' && (props.inputValue === undefined || props.selectedKey === undefined)) {\n setSelectedKey(null);\n }\n }\n\n // If it is the intial render and inputValue isn't controlled nor has an intial value, set input to match current selected key if any\n if (isInitialRender.current && (props.inputValue === undefined && props.defaultInputValue === undefined)) {\n resetInputValue();\n }\n\n // If the selectedKey changed, update the input value.\n // Do nothing if both inputValue and selectedKey are controlled.\n // In this case, it's the user's responsibility to update inputValue in onSelectionChange.\n if (\n selectedKey !== lastSelectedKey.current &&\n (props.inputValue === undefined || props.selectedKey === undefined)\n ) {\n resetInputValue();\n } else {\n lastValue.current = inputValue;\n }\n\n // Update the inputValue if the selected item's text changes from its last tracked value.\n // This is to handle cases where a selectedKey is specified but the items aren't available (async loading) or the selected item's text value updates.\n // Only reset if the user isn't currently within the field so we don't erroneously modify user input.\n // If inputValue is controlled, it is the user's responsibility to update the inputValue when items change.\n let selectedItemText = collection.getItem(selectedKey)?.textValue ?? '';\n if (!isFocused && selectedKey != null && props.inputValue === undefined && selectedKey === lastSelectedKey.current) {\n if (lastSelectedKeyText.current !== selectedItemText) {\n lastValue.current = selectedItemText;\n setInputValue(selectedItemText);\n }\n }\n\n isInitialRender.current = false;\n lastSelectedKey.current = selectedKey;\n lastSelectedKeyText.current = selectedItemText;\n });\n\n useEffect(() => {\n // Reset focused key when the menu closes\n if (!triggerState.isOpen) {\n selectionManager.setFocusedKey(null);\n }\n }, [triggerState.isOpen, selectionManager]);\n\n // Revert input value and close menu\n let revert = () => {\n if (allowsCustomValue && selectedKey == null) {\n commitCustomValue();\n } else {\n commitSelection();\n }\n };\n\n let commitCustomValue = () => {\n lastSelectedKey.current = null;\n setSelectedKey(null);\n triggerState.close();\n };\n\n let commitSelection = () => {\n // If multiple things are controlled, call onSelectionChange\n if (props.selectedKey !== undefined && props.inputValue !== undefined) {\n props.onSelectionChange(selectedKey);\n\n // Stop menu from reopening from useEffect\n let itemText = collection.getItem(selectedKey)?.textValue ?? '';\n lastValue.current = itemText;\n triggerState.close();\n } else {\n // If only a single aspect of combobox is controlled, reset input value and close menu for the user\n resetInputValue();\n triggerState.close();\n }\n };\n\n let commit = () => {\n if (triggerState.isOpen && selectionManager.focusedKey != null) {\n // Reset inputValue and close menu here if the selected key is already the focused key. Otherwise\n // fire onSelectionChange to allow the application to control the closing.\n if (selectedKey === selectionManager.focusedKey) {\n commitSelection();\n } else {\n setSelectedKey(selectionManager.focusedKey);\n }\n } else if (allowsCustomValue) {\n commitCustomValue();\n } else {\n // Reset inputValue and close menu if no item is focused but user triggers a commit\n commitSelection();\n }\n };\n\n let setFocused = (isFocused: boolean) => {\n if (isFocused) {\n if (menuTrigger === 'focus') {\n open(null, 'focus');\n }\n } else if (shouldCloseOnBlur) {\n let itemText = collection.getItem(selectedKey)?.textValue ?? '';\n if (allowsCustomValue && inputValue !== itemText) {\n commitCustomValue();\n } else {\n commitSelection();\n }\n }\n\n setFocusedState(isFocused);\n };\n\n return {\n ...triggerState,\n toggle,\n open,\n selectionManager,\n selectedKey,\n setSelectedKey,\n disabledKeys,\n isFocused,\n setFocused,\n selectedItem,\n collection: showAllItems ? originalCollection : filteredCollection,\n inputValue,\n setInputValue,\n commit,\n revert\n };\n}\n\nfunction filterCollection<T extends object>(collection: Collection<Node<T>>, inputValue: string, filter: FilterFn): Collection<Node<T>> {\n return new ListCollection(filterNodes(collection, inputValue, filter));\n}\n\nfunction filterNodes<T>(nodes: Iterable<Node<T>>, inputValue: string, filter: FilterFn): Iterable<Node<T>> {\n let filteredNode = [];\n for (let node of nodes) {\n if (node.type === 'section' && node.hasChildNodes) {\n let filtered = filterNodes(node.childNodes, inputValue, filter);\n if ([...filtered].length > 0) {\n filteredNode.push({...node, childNodes: filtered});\n }\n } else if (node.type !== 'section' && filter(node.textValue, inputValue)) {\n filteredNode.push({...node});\n }\n }\n return filteredNode;\n}\n"],"names":["$parcel$interopDefault","a","__esModule","default","useComboBoxState","props","defaultFilter","menuTrigger","allowsEmptyCollection","allowsCustomValue","shouldCloseOnBlur","showAllItems","setShowAllItems","useState","isFocused","setFocusedState","inputValue","setInputValue","useControlledState","defaultInputValue","onInputChange","onSelectionChange","key","selectedKey","resetInputValue","triggerState","close","collection","selectionManager","setSelectedKey","selectedItem","disabledKeys","useSingleSelectListState","items","defaultItems","originalCollection","filteredCollection","useMemo","filterCollection","menuOpenTrigger","useRef","onOpenChange","open","current","undefined","useMenuTriggerState","isOpen","defaultOpen","focusStrategy","trigger","displayAllItems","size","toggle","lastValue","itemText","getItem","textValue","isInitialRender","lastSelectedKey","defaultSelectedKey","lastSelectedKeyText","useEffect","setFocusedKey","selectedItemText","revert","commitCustomValue","commitSelection","commit","focusedKey","setFocused","filter","ListCollection","filterNodes","nodes","filteredNode","node","type","hasChildNodes","filtered","childNodes","length","push"],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SCkDgB,yCAAgB,CAAmB,KAA4B,EAAoB,CAAC;IAClG,GAAG,CAAC,CAAC,gBACH,aAAa,gBACb,WAAW,GAAG,CAAO,gCACrB,qBAAqB,GAAG,KAAK,sBAC7B,iBAAiB,sBACjB,iBAAiB,GAAG,IAAI,EAC1B,CAAC,GAAG,KAAK;IAET,GAAG,EAAE,YAAY,EAAE,eAAe,IAAI,qBAAQ,CAAC,KAAK;IACpD,GAAG,EAAE,UAAS,EAAE,eAAe,IAAI,qBAAQ,CAAC,KAAK;IACjD,GAAG,EAAE,UAAU,EAAE,aAAa,IAAI,2CAAkB,CAClD,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,iBAAiB,IAAI,CAAE,GAC7B,KAAK,CAAC,aAAa;IAGrB,GAAG,CAAC,iBAAiB,IAAI,GAAG,GAAK,CAAC;QAChC,EAAE,EAAE,KAAK,CAAC,iBAAiB,EACzB,KAAK,CAAC,iBAAiB,CAAC,GAAG;QAG7B,EAA8D,AAA9D,4DAA8D;QAC9D,EAAqD,AAArD,mDAAqD;QACrD,EAAE,EAAE,GAAG,KAAK,WAAW,EAAE,CAAC;YACxB,eAAe;YACf,YAAY,CAAC,KAAK;QACpB,CAAC;I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mBAAG,QAAQ;YAAA,CAAC,CAAC,MAAM,GAAG,CAAC,EAC1B,YAAY,CAAC,IAAI,CAAC,CAAC;mBAAG,IAAI;gBAAE,UAAU,EAAE,QAAQ;YAAA,CAAC;QAErD,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,IAAI,KAAK,CAAS,YAAI,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,GACrE,YAAY,CAAC,IAAI,CAAC,CAAC;eAAG,IAAI;QAAA,CAAC;IAE/B,CAAC;IACD,MAAM,CAAC,YAAY;AACrB,CAAC","sources":["packages/@react-stately/combobox/src/index.ts","packages/@react-stately/combobox/src/useComboBoxState.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 './useComboBoxState';\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, FocusStrategy, Node} from '@react-types/shared';\nimport {ComboBoxProps, MenuTriggerAction} from '@react-types/combobox';\nimport {ListCollection, useSingleSelectListState} from '@react-stately/list';\nimport {SelectState} from '@react-stately/select';\nimport {useControlledState} from '@react-stately/utils';\nimport {useEffect, useMemo, useRef, useState} from 'react';\nimport {useMenuTriggerState} from '@react-stately/menu';\n\nexport interface ComboBoxState<T> extends SelectState<T> {\n /** The current value of the combo box input. */\n inputValue: string,\n /** Sets the value of the combo box input. */\n setInputValue(value: string): void,\n /** Selects the currently focused item and updates the input value. */\n commit(): void,\n /** Opens the menu. */\n open(focusStrategy?: FocusStrategy | null, trigger?: MenuTriggerAction): void,\n /** Toggles the menu. */\n toggle(focusStrategy?: FocusStrategy | null, trigger?: MenuTriggerAction): void,\n /** Resets the input value to the previously selected item's text if any and closes the menu. */\n revert(): void\n}\n\ntype FilterFn = (textValue: string, inputValue: string) => boolean;\ninterface ComboBoxStateProps<T> extends ComboBoxProps<T> {\n /** The filter function used to determine if a option should be included in the combo box list. */\n defaultFilter?: FilterFn,\n /** Whether the combo box allows the menu to be open when the collection is empty. */\n allowsEmptyCollection?: boolean,\n /** Whether the combo box menu should close on blur. */\n shouldCloseOnBlur?: boolean\n}\n\n/**\n * Provides state management for a combo box component. Handles building a collection\n * of items from props and manages the option selection state of the combo box. In addition, it tracks the input value,\n * focus state, and other properties of the combo box.\n */\nexport function useComboBoxState<T extends object>(props: ComboBoxStateProps<T>): ComboBoxState<T> {\n let {\n defaultFilter,\n menuTrigger = 'input',\n allowsEmptyCollection = false,\n allowsCustomValue,\n shouldCloseOnBlur = true\n } = props;\n\n let [showAllItems, setShowAllItems] = useState(false);\n let [isFocused, setFocusedState] = useState(false);\n let [inputValue, setInputValue] = useControlledState(\n props.inputValue,\n props.defaultInputValue ?? '',\n props.onInputChange\n );\n\n let onSelectionChange = (key) => {\n if (props.onSelectionChange) {\n props.onSelectionChange(key);\n }\n\n // If key is the same, reset the inputValue and close the menu\n // (scenario: user clicks on already selected option)\n if (key === selectedKey) {\n resetInputValue();\n triggerState.close();\n }\n };\n\n let {collection, selectionManager, selectedKey, setSelectedKey, selectedItem, disabledKeys} = useSingleSelectListState({\n ...props,\n onSelectionChange,\n items: props.items ?? props.defaultItems\n });\n\n // Preserve original collection so we can show all items on demand\n let originalCollection = collection;\n let filteredCollection = useMemo(() => (\n // No default filter if items are controlled.\n props.items != null || !defaultFilter\n ? collection\n : filterCollection(collection, inputValue, defaultFilter)\n ), [collection, inputValue, defaultFilter, props.items]);\n\n // Track what action is attempting to open the menu\n let menuOpenTrigger = useRef('focus' as MenuTriggerAction);\n let onOpenChange = (open: boolean) => {\n if (props.onOpenChange) {\n props.onOpenChange(open, open ? menuOpenTrigger.current : undefined);\n }\n };\n\n let triggerState = useMenuTriggerState({...props, onOpenChange, isOpen: undefined, defaultOpen: undefined});\n let open = (focusStrategy?: FocusStrategy, trigger?: MenuTriggerAction) => {\n let displayAllItems = (trigger === 'manual' || (trigger === 'focus' && menuTrigger === 'focus'));\n // Prevent open operations from triggering if there is nothing to display\n // Also prevent open operations from triggering if items are uncontrolled but defaultItems is empty, even if displayAllItems is true.\n // This is to prevent comboboxes with empty defaultItems from opening but allow controlled items comboboxes to open even if the inital list is empty (assumption is user will provide swap the empty list with a base list via onOpenChange returning `menuTrigger` manual)\n if (allowsEmptyCollection || filteredCollection.size > 0 || (displayAllItems && originalCollection.size > 0) || props.items) {\n if (displayAllItems && !triggerState.isOpen && props.items === undefined) {\n // Show all items if menu is manually opened. Only care about this if items are undefined\n setShowAllItems(true);\n }\n\n menuOpenTrigger.current = trigger;\n triggerState.open(focusStrategy);\n }\n };\n\n let toggle = (focusStrategy?: FocusStrategy, trigger?: MenuTriggerAction) => {\n let displayAllItems = (trigger === 'manual' || (trigger === 'focus' && menuTrigger === 'focus'));\n // If the menu is closed and there is nothing to display, early return so toggle isn't called to prevent extraneous onOpenChange\n if (!(allowsEmptyCollection || filteredCollection.size > 0 || (displayAllItems && originalCollection.size > 0) || props.items) && !triggerState.isOpen) {\n return;\n }\n\n if (displayAllItems && !triggerState.isOpen && props.items === undefined) {\n // Show all items if menu is toggled open. Only care about this if items are undefined\n setShowAllItems(true);\n }\n\n // Only update the menuOpenTrigger if menu is currently closed\n if (!triggerState.isOpen) {\n menuOpenTrigger.current = trigger;\n }\n\n triggerState.toggle(focusStrategy);\n };\n\n let lastValue = useRef(inputValue);\n let resetInputValue = () => {\n let itemText = collection.getItem(selectedKey)?.textValue ?? '';\n lastValue.current = itemText;\n setInputValue(itemText);\n };\n\n let isInitialRender = useRef(true);\n let lastSelectedKey = useRef(props.selectedKey ?? props.defaultSelectedKey ?? null);\n let lastSelectedKeyText = useRef(collection.getItem(selectedKey)?.textValue ?? '');\n // intentional omit dependency array, want this to happen on every render\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(() => {\n // Open and close menu automatically when the input value changes if the input is focused,\n // and there are items in the collection or allowEmptyCollection is true.\n if (\n isFocused &&\n (filteredCollection.size > 0 || allowsEmptyCollection) &&\n !triggerState.isOpen &&\n inputValue !== lastValue.current &&\n menuTrigger !== 'manual'\n ) {\n open(null, 'input');\n }\n\n // Close the menu if the collection is empty. Don't close menu if filtered collection size is 0\n // but we are currently showing all items via button press\n if (\n !showAllItems &&\n !allowsEmptyCollection &&\n triggerState.isOpen &&\n filteredCollection.size === 0\n ) {\n triggerState.close();\n }\n\n // Close when an item is selected.\n if (\n selectedKey != null &&\n selectedKey !== lastSelectedKey.current\n ) {\n triggerState.close();\n }\n\n // Clear focused key when input value changes and display filtered collection again.\n if (inputValue !== lastValue.current) {\n selectionManager.setFocusedKey(null);\n setShowAllItems(false);\n\n // Set selectedKey to null when the user clears the input.\n // If controlled, this is the application developer's responsibility.\n if (inputValue === '' && (props.inputValue === undefined || props.selectedKey === undefined)) {\n setSelectedKey(null);\n }\n }\n\n // If it is the intial render and inputValue isn't controlled nor has an intial value, set input to match current selected key if any\n if (isInitialRender.current && (props.inputValue === undefined && props.defaultInputValue === undefined)) {\n resetInputValue();\n }\n\n // If the selectedKey changed, update the input value.\n // Do nothing if both inputValue and selectedKey are controlled.\n // In this case, it's the user's responsibility to update inputValue in onSelectionChange.\n if (\n selectedKey !== lastSelectedKey.current &&\n (props.inputValue === undefined || props.selectedKey === undefined)\n ) {\n resetInputValue();\n } else {\n lastValue.current = inputValue;\n }\n\n // Update the inputValue if the selected item's text changes from its last tracked value.\n // This is to handle cases where a selectedKey is specified but the items aren't available (async loading) or the selected item's text value updates.\n // Only reset if the user isn't currently within the field so we don't erroneously modify user input.\n // If inputValue is controlled, it is the user's responsibility to update the inputValue when items change.\n let selectedItemText = collection.getItem(selectedKey)?.textValue ?? '';\n if (!isFocused && selectedKey != null && props.inputValue === undefined && selectedKey === lastSelectedKey.current) {\n if (lastSelectedKeyText.current !== selectedItemText) {\n lastValue.current = selectedItemText;\n setInputValue(selectedItemText);\n }\n }\n\n isInitialRender.current = false;\n lastSelectedKey.current = selectedKey;\n lastSelectedKeyText.current = selectedItemText;\n });\n\n useEffect(() => {\n // Reset focused key when the menu closes\n if (!triggerState.isOpen) {\n selectionManager.setFocusedKey(null);\n }\n }, [triggerState.isOpen, selectionManager]);\n\n // Revert input value and close menu\n let revert = () => {\n if (allowsCustomValue && selectedKey == null) {\n commitCustomValue();\n } else {\n commitSelection();\n }\n };\n\n let commitCustomValue = () => {\n lastSelectedKey.current = null;\n setSelectedKey(null);\n triggerState.close();\n };\n\n let commitSelection = () => {\n // If multiple things are controlled, call onSelectionChange\n if (props.selectedKey !== undefined && props.inputValue !== undefined) {\n props.onSelectionChange(selectedKey);\n\n // Stop menu from reopening from useEffect\n let itemText = collection.getItem(selectedKey)?.textValue ?? '';\n lastValue.current = itemText;\n triggerState.close();\n } else {\n // If only a single aspect of combobox is controlled, reset input value and close menu for the user\n resetInputValue();\n triggerState.close();\n }\n };\n\n let commit = () => {\n if (triggerState.isOpen && selectionManager.focusedKey != null) {\n // Reset inputValue and close menu here if the selected key is already the focused key. Otherwise\n // fire onSelectionChange to allow the application to control the closing.\n if (selectedKey === selectionManager.focusedKey) {\n commitSelection();\n } else {\n setSelectedKey(selectionManager.focusedKey);\n }\n } else if (allowsCustomValue) {\n commitCustomValue();\n } else {\n // Reset inputValue and close menu if no item is focused but user triggers a commit\n commitSelection();\n }\n };\n\n let setFocused = (isFocused: boolean) => {\n if (isFocused) {\n if (menuTrigger === 'focus') {\n open(null, 'focus');\n }\n } else if (shouldCloseOnBlur) {\n let itemText = collection.getItem(selectedKey)?.textValue ?? '';\n if (allowsCustomValue && inputValue !== itemText) {\n commitCustomValue();\n } else {\n commitSelection();\n }\n }\n\n setFocusedState(isFocused);\n };\n\n return {\n ...triggerState,\n toggle,\n open,\n selectionManager,\n selectedKey,\n setSelectedKey,\n disabledKeys,\n isFocused,\n setFocused,\n selectedItem,\n collection: showAllItems ? originalCollection : filteredCollection,\n inputValue,\n setInputValue,\n commit,\n revert\n };\n}\n\nfunction filterCollection<T extends object>(collection: Collection<Node<T>>, inputValue: string, filter: FilterFn): Collection<Node<T>> {\n return new ListCollection(filterNodes(collection, inputValue, filter));\n}\n\nfunction filterNodes<T>(nodes: Iterable<Node<T>>, inputValue: string, filter: FilterFn): Iterable<Node<T>> {\n let filteredNode = [];\n for (let node of nodes) {\n if (node.type === 'section' && node.hasChildNodes) {\n let filtered = filterNodes(node.childNodes, inputValue, filter);\n if ([...filtered].length > 0) {\n filteredNode.push({...node, childNodes: filtered});\n }\n } else if (node.type !== 'section' && filter(node.textValue, inputValue)) {\n filteredNode.push({...node});\n }\n }\n return filteredNode;\n}\n"],"names":[],"version":3,"file":"main.js.map"}