@react-stately/combobox 3.3.1-nightly.3599 → 3.3.1-nightly.3603

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
@@ -8,17 +8,37 @@ function $parcel$export(e, n, v, s) {
8
8
  }
9
9
 
10
10
  $parcel$export(module.exports, "useComboBoxState", () => $e563f9c9469ad14c$export$b453a3bfd4a5fa9e);
11
-
11
+ /*
12
+ * Copyright 2020 Adobe. All rights reserved.
13
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License. You may obtain a copy
15
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software distributed under
18
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
+ * OF ANY KIND, either express or implied. See the License for the specific language
20
+ * governing permissions and limitations under the License.
21
+ */ /*
22
+ * Copyright 2020 Adobe. All rights reserved.
23
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
24
+ * you may not use this file except in compliance with the License. You may obtain a copy
25
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
26
+ *
27
+ * Unless required by applicable law or agreed to in writing, software distributed under
28
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
29
+ * OF ANY KIND, either express or implied. See the License for the specific language
30
+ * governing permissions and limitations under the License.
31
+ */
12
32
 
13
33
 
14
34
 
15
35
  function $e563f9c9469ad14c$export$b453a3bfd4a5fa9e(props) {
16
- var ref4;
17
- let { defaultFilter: defaultFilter , menuTrigger: menuTrigger = 'input' , allowsEmptyCollection: allowsEmptyCollection = false , allowsCustomValue: allowsCustomValue , shouldCloseOnBlur: shouldCloseOnBlur = true } = props;
18
- let [showAllItems, setShowAllItems] = $5XAuq$react.useState(false);
19
- let [isFocused1, setFocusedState] = $5XAuq$react.useState(false);
36
+ var ref;
37
+ let { defaultFilter: defaultFilter , menuTrigger: menuTrigger = "input" , allowsEmptyCollection: allowsEmptyCollection = false , allowsCustomValue: allowsCustomValue , shouldCloseOnBlur: shouldCloseOnBlur = true } = props;
38
+ let [showAllItems, setShowAllItems] = (0, $5XAuq$react.useState)(false);
39
+ let [isFocused, setFocusedState] = (0, $5XAuq$react.useState)(false);
20
40
  var _defaultInputValue;
21
- let [inputValue, setInputValue] = $5XAuq$reactstatelyutils.useControlledState(props.inputValue, (_defaultInputValue = props.defaultInputValue) !== null && _defaultInputValue !== void 0 ? _defaultInputValue : '', props.onInputChange);
41
+ let [inputValue, setInputValue] = (0, $5XAuq$reactstatelyutils.useControlledState)(props.inputValue, (_defaultInputValue = props.defaultInputValue) !== null && _defaultInputValue !== void 0 ? _defaultInputValue : "", props.onInputChange);
22
42
  let onSelectionChange = (key)=>{
23
43
  if (props.onSelectionChange) props.onSelectionChange(key);
24
44
  // If key is the same, reset the inputValue and close the menu
@@ -29,34 +49,33 @@ function $e563f9c9469ad14c$export$b453a3bfd4a5fa9e(props) {
29
49
  }
30
50
  };
31
51
  var _items;
32
- let { collection: collection , selectionManager: selectionManager , selectedKey: selectedKey , setSelectedKey: setSelectedKey , selectedItem: selectedItem , disabledKeys: disabledKeys } = $5XAuq$reactstatelylist.useSingleSelectListState({
52
+ let { collection: collection , selectionManager: selectionManager , selectedKey: selectedKey , setSelectedKey: setSelectedKey , selectedItem: selectedItem , disabledKeys: disabledKeys } = (0, $5XAuq$reactstatelylist.useSingleSelectListState)({
33
53
  ...props,
34
54
  onSelectionChange: onSelectionChange,
35
55
  items: (_items = props.items) !== null && _items !== void 0 ? _items : props.defaultItems
36
56
  });
37
57
  // Preserve original collection so we can show all items on demand
38
58
  let originalCollection = collection;
39
- let filteredCollection = $5XAuq$react.useMemo(()=>// No default filter if items are controlled.
40
- props.items != null || !defaultFilter ? collection : $e563f9c9469ad14c$var$filterCollection(collection, inputValue, defaultFilter)
41
- , [
59
+ let filteredCollection = (0, $5XAuq$react.useMemo)(()=>// No default filter if items are controlled.
60
+ props.items != null || !defaultFilter ? collection : $e563f9c9469ad14c$var$filterCollection(collection, inputValue, defaultFilter), [
42
61
  collection,
43
62
  inputValue,
44
63
  defaultFilter,
45
64
  props.items
46
65
  ]);
47
66
  // Track what action is attempting to open the menu
48
- let menuOpenTrigger = $5XAuq$react.useRef('focus');
67
+ let menuOpenTrigger = (0, $5XAuq$react.useRef)("focus");
49
68
  let onOpenChange = (open)=>{
50
69
  if (props.onOpenChange) props.onOpenChange(open, open ? menuOpenTrigger.current : undefined);
51
70
  };
52
- let triggerState = $5XAuq$reactstatelymenu.useMenuTriggerState({
71
+ let triggerState = (0, $5XAuq$reactstatelymenu.useMenuTriggerState)({
53
72
  ...props,
54
73
  onOpenChange: onOpenChange,
55
74
  isOpen: undefined,
56
75
  defaultOpen: undefined
57
76
  });
58
- let open1 = (focusStrategy, trigger)=>{
59
- let displayAllItems = trigger === 'manual' || trigger === 'focus' && menuTrigger === 'focus';
77
+ let open = (focusStrategy, trigger)=>{
78
+ let displayAllItems = trigger === "manual" || trigger === "focus" && menuTrigger === "focus";
60
79
  // Prevent open operations from triggering if there is nothing to display
61
80
  // Also prevent open operations from triggering if items are uncontrolled but defaultItems is empty, even if displayAllItems is true.
62
81
  // 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)
@@ -68,7 +87,7 @@ function $e563f9c9469ad14c$export$b453a3bfd4a5fa9e(props) {
68
87
  }
69
88
  };
70
89
  let toggle = (focusStrategy, trigger)=>{
71
- let displayAllItems = trigger === 'manual' || trigger === 'focus' && menuTrigger === 'focus';
90
+ let displayAllItems = trigger === "manual" || trigger === "focus" && menuTrigger === "focus";
72
91
  // If the menu is closed and there is nothing to display, early return so toggle isn't called to prevent extraneous onOpenChange
73
92
  if (!(allowsEmptyCollection || filteredCollection.size > 0 || displayAllItems && originalCollection.size > 0 || props.items) && !triggerState.isOpen) return;
74
93
  if (displayAllItems && !triggerState.isOpen && props.items === undefined) // Show all items if menu is toggled open. Only care about this if items are undefined
@@ -77,26 +96,26 @@ function $e563f9c9469ad14c$export$b453a3bfd4a5fa9e(props) {
77
96
  if (!triggerState.isOpen) menuOpenTrigger.current = trigger;
78
97
  triggerState.toggle(focusStrategy);
79
98
  };
80
- let lastValue = $5XAuq$react.useRef(inputValue);
99
+ let lastValue = (0, $5XAuq$react.useRef)(inputValue);
81
100
  let resetInputValue = ()=>{
82
101
  var ref;
83
- var ref3;
84
- let itemText = (ref3 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref3 !== void 0 ? ref3 : '';
102
+ var ref1;
103
+ let itemText = (ref1 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref1 !== void 0 ? ref1 : "";
85
104
  lastValue.current = itemText;
86
105
  setInputValue(itemText);
87
106
  };
88
- let isInitialRender = $5XAuq$react.useRef(true);
107
+ let isInitialRender = (0, $5XAuq$react.useRef)(true);
89
108
  var _selectedKey, ref1;
90
- let lastSelectedKey = $5XAuq$react.useRef((ref1 = (_selectedKey = props.selectedKey) !== null && _selectedKey !== void 0 ? _selectedKey : props.defaultSelectedKey) !== null && ref1 !== void 0 ? ref1 : null);
109
+ let lastSelectedKey = (0, $5XAuq$react.useRef)((ref1 = (_selectedKey = props.selectedKey) !== null && _selectedKey !== void 0 ? _selectedKey : props.defaultSelectedKey) !== null && ref1 !== void 0 ? ref1 : null);
91
110
  var ref2;
92
- let lastSelectedKeyText = $5XAuq$react.useRef((ref2 = (ref4 = collection.getItem(selectedKey)) === null || ref4 === void 0 ? void 0 : ref4.textValue) !== null && ref2 !== void 0 ? ref2 : '');
111
+ let lastSelectedKeyText = (0, $5XAuq$react.useRef)((ref2 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref2 !== void 0 ? ref2 : "");
93
112
  // intentional omit dependency array, want this to happen on every render
94
113
  // eslint-disable-next-line react-hooks/exhaustive-deps
95
- $5XAuq$react.useEffect(()=>{
114
+ (0, $5XAuq$react.useEffect)(()=>{
96
115
  var ref;
97
116
  // Open and close menu automatically when the input value changes if the input is focused,
98
117
  // and there are items in the collection or allowEmptyCollection is true.
99
- if (isFocused1 && (filteredCollection.size > 0 || allowsEmptyCollection) && !triggerState.isOpen && inputValue !== lastValue.current && menuTrigger !== 'manual') open1(null, 'input');
118
+ if (isFocused && (filteredCollection.size > 0 || allowsEmptyCollection) && !triggerState.isOpen && inputValue !== lastValue.current && menuTrigger !== "manual") open(null, "input");
100
119
  // Close the menu if the collection is empty. Don't close menu if filtered collection size is 0
101
120
  // but we are currently showing all items via button press
102
121
  if (!showAllItems && !allowsEmptyCollection && triggerState.isOpen && filteredCollection.size === 0) triggerState.close();
@@ -108,7 +127,7 @@ function $e563f9c9469ad14c$export$b453a3bfd4a5fa9e(props) {
108
127
  setShowAllItems(false);
109
128
  // Set selectedKey to null when the user clears the input.
110
129
  // If controlled, this is the application developer's responsibility.
111
- if (inputValue === '' && (props.inputValue === undefined || props.selectedKey === undefined)) setSelectedKey(null);
130
+ if (inputValue === "" && (props.inputValue === undefined || props.selectedKey === undefined)) setSelectedKey(null);
112
131
  }
113
132
  // 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
114
133
  if (isInitialRender.current && props.inputValue === undefined && props.defaultInputValue === undefined) resetInputValue();
@@ -117,13 +136,13 @@ function $e563f9c9469ad14c$export$b453a3bfd4a5fa9e(props) {
117
136
  // In this case, it's the user's responsibility to update inputValue in onSelectionChange.
118
137
  if (selectedKey !== lastSelectedKey.current && (props.inputValue === undefined || props.selectedKey === undefined)) resetInputValue();
119
138
  else lastValue.current = inputValue;
120
- var ref5;
139
+ var ref1;
121
140
  // Update the inputValue if the selected item's text changes from its last tracked value.
122
141
  // 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.
123
142
  // Only reset if the user isn't currently within the field so we don't erroneously modify user input.
124
143
  // If inputValue is controlled, it is the user's responsibility to update the inputValue when items change.
125
- let selectedItemText = (ref5 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref5 !== void 0 ? ref5 : '';
126
- if (!isFocused1 && selectedKey != null && props.inputValue === undefined && selectedKey === lastSelectedKey.current) {
144
+ let selectedItemText = (ref1 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref1 !== void 0 ? ref1 : "";
145
+ if (!isFocused && selectedKey != null && props.inputValue === undefined && selectedKey === lastSelectedKey.current) {
127
146
  if (lastSelectedKeyText.current !== selectedItemText) {
128
147
  lastValue.current = selectedItemText;
129
148
  setInputValue(selectedItemText);
@@ -133,7 +152,7 @@ function $e563f9c9469ad14c$export$b453a3bfd4a5fa9e(props) {
133
152
  lastSelectedKey.current = selectedKey;
134
153
  lastSelectedKeyText.current = selectedItemText;
135
154
  });
136
- $5XAuq$react.useEffect(()=>{
155
+ (0, $5XAuq$react.useEffect)(()=>{
137
156
  // Reset focused key when the menu closes
138
157
  if (!triggerState.isOpen) selectionManager.setFocusedKey(null);
139
158
  }, [
@@ -155,9 +174,9 @@ function $e563f9c9469ad14c$export$b453a3bfd4a5fa9e(props) {
155
174
  if (props.selectedKey !== undefined && props.inputValue !== undefined) {
156
175
  var ref;
157
176
  props.onSelectionChange(selectedKey);
158
- var ref6;
177
+ var ref1;
159
178
  // Stop menu from reopening from useEffect
160
- let itemText = (ref6 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref6 !== void 0 ? ref6 : '';
179
+ let itemText = (ref1 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref1 !== void 0 ? ref1 : "";
161
180
  lastValue.current = itemText;
162
181
  triggerState.close();
163
182
  } else {
@@ -178,11 +197,11 @@ function $e563f9c9469ad14c$export$b453a3bfd4a5fa9e(props) {
178
197
  };
179
198
  let setFocused = (isFocused)=>{
180
199
  if (isFocused) {
181
- if (menuTrigger === 'focus') open1(null, 'focus');
200
+ if (menuTrigger === "focus") open(null, "focus");
182
201
  } else if (shouldCloseOnBlur) {
183
202
  var ref;
184
- var ref7;
185
- let itemText = (ref7 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref7 !== void 0 ? ref7 : '';
203
+ var ref1;
204
+ let itemText = (ref1 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref1 !== void 0 ? ref1 : "";
186
205
  if (allowsCustomValue && inputValue !== itemText) commitCustomValue();
187
206
  else commitSelection();
188
207
  }
@@ -191,13 +210,13 @@ function $e563f9c9469ad14c$export$b453a3bfd4a5fa9e(props) {
191
210
  return {
192
211
  ...triggerState,
193
212
  toggle: toggle,
194
- open: open1,
213
+ open: open,
195
214
  close: commit,
196
215
  selectionManager: selectionManager,
197
216
  selectedKey: selectedKey,
198
217
  setSelectedKey: setSelectedKey,
199
218
  disabledKeys: disabledKeys,
200
- isFocused: isFocused1,
219
+ isFocused: isFocused,
201
220
  setFocused: setFocused,
202
221
  selectedItem: selectedItem,
203
222
  collection: showAllItems ? originalCollection : filteredCollection,
@@ -208,12 +227,12 @@ function $e563f9c9469ad14c$export$b453a3bfd4a5fa9e(props) {
208
227
  };
209
228
  }
210
229
  function $e563f9c9469ad14c$var$filterCollection(collection, inputValue, filter) {
211
- return new $5XAuq$reactstatelylist.ListCollection($e563f9c9469ad14c$var$filterNodes(collection, inputValue, filter));
230
+ return new (0, $5XAuq$reactstatelylist.ListCollection)($e563f9c9469ad14c$var$filterNodes(collection, inputValue, filter));
212
231
  }
213
232
  function $e563f9c9469ad14c$var$filterNodes(nodes, inputValue, filter) {
214
233
  let filteredNode = [];
215
234
  for (let node of nodes){
216
- if (node.type === 'section' && node.hasChildNodes) {
235
+ if (node.type === "section" && node.hasChildNodes) {
217
236
  let filtered = $e563f9c9469ad14c$var$filterNodes(node.childNodes, inputValue, filter);
218
237
  if ([
219
238
  ...filtered
@@ -221,7 +240,7 @@ function $e563f9c9469ad14c$var$filterNodes(nodes, inputValue, filter) {
221
240
  ...node,
222
241
  childNodes: filtered
223
242
  });
224
- } else if (node.type !== 'section' && filter(node.textValue, inputValue)) filteredNode.push({
243
+ } else if (node.type !== "section" && filter(node.textValue, inputValue)) filteredNode.push({
225
244
  ...node
226
245
  });
227
246
  }
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;SCmDgB,yCAAgB,CAAmB,KAA8B,EAAoB,CAAC;QAmGnE,IAA+B;IAlGhE,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;QAG/C,kBAAuB;IAFzB,GAAG,EAAE,UAAU,EAAE,aAAa,IAAI,2CAAkB,CAClD,KAAK,CAAC,UAAU,GAChB,kBAAuB,GAAvB,KAAK,CAAC,iBAAiB,cAAvB,kBAAuB,cAAvB,kBAAuB,GAAI,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;IACH,CAAC;QAKQ,MAAW;IAHpB,GAAG,CAAC,CAAC,aAAA,UAAU,qB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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 {useComboBoxState} from './useComboBoxState';\n\nexport type {ComboBoxStateOptions, ComboBoxState} 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;\n\nexport interface ComboBoxStateOptions<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: ComboBoxStateOptions<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 close: commit,\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"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED;;;;AAuCO,SAAS,0CAAmC,KAA8B,EAAoB;QAmGlE;IAlGjC,IAAI,iBACF,cAAa,eACb,cAAc,iCACd,wBAAwB,KAAK,sBAC7B,kBAAiB,qBACjB,oBAAoB,IAAI,GACzB,GAAG;IAEJ,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,qBAAO,EAAE,KAAK;IACpD,IAAI,CAAC,WAAW,gBAAgB,GAAG,CAAA,GAAA,qBAAO,EAAE,KAAK;QAG/C;IAFF,IAAI,CAAC,YAAY,cAAc,GAAG,CAAA,GAAA,2CAAiB,EACjD,MAAM,UAAU,EAChB,CAAA,qBAAA,MAAM,iBAAiB,cAAvB,gCAAA,qBAA2B,EAAE,EAC7B,MAAM,aAAa;IAGrB,IAAI,oBAAoB,CAAC,MAAQ;QAC/B,IAAI,MAAM,iBAAiB,EACzB,MAAM,iBAAiB,CAAC;QAG1B,8DAA8D;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AW,CAAA,OAAA,CAAA,MAAA,WAAW,OAAO,CAAC,0BAAnB,iBAAA,KAAA,IAAA,IAAiC,SAAS,cAA1C,kBAAA,OAA8C,EAAE;YAC/D,IAAI,qBAAqB,eAAe,UACtC;iBAEA;QAEJ,CAAC;QAED,gBAAgB;IAClB;IAEA,OAAO;QACL,GAAG,YAAY;gBACf;cACA;QACA,OAAO;0BACP;qBACA;wBACA;sBACA;mBACA;oBACA;sBACA;QACA,YAAY,eAAe,qBAAqB,kBAAkB;oBAClE;uBACA;gBACA;gBACA;IACF;AACF;AAEA,SAAS,uCAAmC,UAA+B,EAAE,UAAkB,EAAE,MAAgB,EAAuB;IACtI,OAAO,IAAI,CAAA,GAAA,sCAAc,AAAD,EAAE,kCAAY,YAAY,YAAY;AAChE;AAEA,SAAS,kCAAe,KAAwB,EAAE,UAAkB,EAAE,MAAgB,EAAqB;IACzG,IAAI,eAAe,EAAE;IACrB,KAAK,IAAI,QAAQ,MAAO;QACtB,IAAI,KAAK,IAAI,KAAK,aAAa,KAAK,aAAa,EAAE;YACjD,IAAI,WAAW,kCAAY,KAAK,UAAU,EAAE,YAAY;YACxD,IAAI;mBAAI;aAAS,CAAC,MAAM,GAAG,GACzB,aAAa,IAAI,CAAC;gBAAC,GAAG,IAAI;gBAAE,YAAY;YAAQ;QAEpD,OAAO,IAAI,KAAK,IAAI,KAAK,aAAa,OAAO,KAAK,SAAS,EAAE,aAC3D,aAAa,IAAI,CAAC;YAAC,GAAG,IAAI;QAAA;IAE9B;IACA,OAAO;AACT;;CD1UC,GAED","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 {useComboBoxState} from './useComboBoxState';\n\nexport type {ComboBoxStateOptions, ComboBoxState} 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;\n\nexport interface ComboBoxStateOptions<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: ComboBoxStateOptions<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 close: commit,\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"}
package/dist/module.mjs CHANGED
@@ -3,17 +3,37 @@ import {useControlledState as $k6Ppu$useControlledState} from "@react-stately/ut
3
3
  import {useState as $k6Ppu$useState, useMemo as $k6Ppu$useMemo, useRef as $k6Ppu$useRef, useEffect as $k6Ppu$useEffect} from "react";
4
4
  import {useMenuTriggerState as $k6Ppu$useMenuTriggerState} from "@react-stately/menu";
5
5
 
6
-
6
+ /*
7
+ * Copyright 2020 Adobe. All rights reserved.
8
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License. You may obtain a copy
10
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software distributed under
13
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
+ * OF ANY KIND, either express or implied. See the License for the specific language
15
+ * governing permissions and limitations under the License.
16
+ */ /*
17
+ * Copyright 2020 Adobe. All rights reserved.
18
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
19
+ * you may not use this file except in compliance with the License. You may obtain a copy
20
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
21
+ *
22
+ * Unless required by applicable law or agreed to in writing, software distributed under
23
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
24
+ * OF ANY KIND, either express or implied. See the License for the specific language
25
+ * governing permissions and limitations under the License.
26
+ */
7
27
 
8
28
 
9
29
 
10
30
  function $a9e7382a7d111cb5$export$b453a3bfd4a5fa9e(props) {
11
- var ref4;
12
- let { defaultFilter: defaultFilter , menuTrigger: menuTrigger = 'input' , allowsEmptyCollection: allowsEmptyCollection = false , allowsCustomValue: allowsCustomValue , shouldCloseOnBlur: shouldCloseOnBlur = true } = props;
13
- let [showAllItems, setShowAllItems] = $k6Ppu$useState(false);
14
- let [isFocused1, setFocusedState] = $k6Ppu$useState(false);
31
+ var ref;
32
+ let { defaultFilter: defaultFilter , menuTrigger: menuTrigger = "input" , allowsEmptyCollection: allowsEmptyCollection = false , allowsCustomValue: allowsCustomValue , shouldCloseOnBlur: shouldCloseOnBlur = true } = props;
33
+ let [showAllItems, setShowAllItems] = (0, $k6Ppu$useState)(false);
34
+ let [isFocused, setFocusedState] = (0, $k6Ppu$useState)(false);
15
35
  var _defaultInputValue;
16
- let [inputValue, setInputValue] = $k6Ppu$useControlledState(props.inputValue, (_defaultInputValue = props.defaultInputValue) !== null && _defaultInputValue !== void 0 ? _defaultInputValue : '', props.onInputChange);
36
+ let [inputValue, setInputValue] = (0, $k6Ppu$useControlledState)(props.inputValue, (_defaultInputValue = props.defaultInputValue) !== null && _defaultInputValue !== void 0 ? _defaultInputValue : "", props.onInputChange);
17
37
  let onSelectionChange = (key)=>{
18
38
  if (props.onSelectionChange) props.onSelectionChange(key);
19
39
  // If key is the same, reset the inputValue and close the menu
@@ -24,34 +44,33 @@ function $a9e7382a7d111cb5$export$b453a3bfd4a5fa9e(props) {
24
44
  }
25
45
  };
26
46
  var _items;
27
- let { collection: collection , selectionManager: selectionManager , selectedKey: selectedKey , setSelectedKey: setSelectedKey , selectedItem: selectedItem , disabledKeys: disabledKeys } = $k6Ppu$useSingleSelectListState({
47
+ let { collection: collection , selectionManager: selectionManager , selectedKey: selectedKey , setSelectedKey: setSelectedKey , selectedItem: selectedItem , disabledKeys: disabledKeys } = (0, $k6Ppu$useSingleSelectListState)({
28
48
  ...props,
29
49
  onSelectionChange: onSelectionChange,
30
50
  items: (_items = props.items) !== null && _items !== void 0 ? _items : props.defaultItems
31
51
  });
32
52
  // Preserve original collection so we can show all items on demand
33
53
  let originalCollection = collection;
34
- let filteredCollection = $k6Ppu$useMemo(()=>// No default filter if items are controlled.
35
- props.items != null || !defaultFilter ? collection : $a9e7382a7d111cb5$var$filterCollection(collection, inputValue, defaultFilter)
36
- , [
54
+ let filteredCollection = (0, $k6Ppu$useMemo)(()=>// No default filter if items are controlled.
55
+ props.items != null || !defaultFilter ? collection : $a9e7382a7d111cb5$var$filterCollection(collection, inputValue, defaultFilter), [
37
56
  collection,
38
57
  inputValue,
39
58
  defaultFilter,
40
59
  props.items
41
60
  ]);
42
61
  // Track what action is attempting to open the menu
43
- let menuOpenTrigger = $k6Ppu$useRef('focus');
62
+ let menuOpenTrigger = (0, $k6Ppu$useRef)("focus");
44
63
  let onOpenChange = (open)=>{
45
64
  if (props.onOpenChange) props.onOpenChange(open, open ? menuOpenTrigger.current : undefined);
46
65
  };
47
- let triggerState = $k6Ppu$useMenuTriggerState({
66
+ let triggerState = (0, $k6Ppu$useMenuTriggerState)({
48
67
  ...props,
49
68
  onOpenChange: onOpenChange,
50
69
  isOpen: undefined,
51
70
  defaultOpen: undefined
52
71
  });
53
- let open1 = (focusStrategy, trigger)=>{
54
- let displayAllItems = trigger === 'manual' || trigger === 'focus' && menuTrigger === 'focus';
72
+ let open = (focusStrategy, trigger)=>{
73
+ let displayAllItems = trigger === "manual" || trigger === "focus" && menuTrigger === "focus";
55
74
  // Prevent open operations from triggering if there is nothing to display
56
75
  // Also prevent open operations from triggering if items are uncontrolled but defaultItems is empty, even if displayAllItems is true.
57
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)
@@ -63,7 +82,7 @@ function $a9e7382a7d111cb5$export$b453a3bfd4a5fa9e(props) {
63
82
  }
64
83
  };
65
84
  let toggle = (focusStrategy, trigger)=>{
66
- let displayAllItems = trigger === 'manual' || trigger === 'focus' && menuTrigger === 'focus';
85
+ let displayAllItems = trigger === "manual" || trigger === "focus" && menuTrigger === "focus";
67
86
  // If the menu is closed and there is nothing to display, early return so toggle isn't called to prevent extraneous onOpenChange
68
87
  if (!(allowsEmptyCollection || filteredCollection.size > 0 || displayAllItems && originalCollection.size > 0 || props.items) && !triggerState.isOpen) return;
69
88
  if (displayAllItems && !triggerState.isOpen && props.items === undefined) // Show all items if menu is toggled open. Only care about this if items are undefined
@@ -72,26 +91,26 @@ function $a9e7382a7d111cb5$export$b453a3bfd4a5fa9e(props) {
72
91
  if (!triggerState.isOpen) menuOpenTrigger.current = trigger;
73
92
  triggerState.toggle(focusStrategy);
74
93
  };
75
- let lastValue = $k6Ppu$useRef(inputValue);
94
+ let lastValue = (0, $k6Ppu$useRef)(inputValue);
76
95
  let resetInputValue = ()=>{
77
96
  var ref;
78
- var ref3;
79
- let itemText = (ref3 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref3 !== void 0 ? ref3 : '';
97
+ var ref1;
98
+ let itemText = (ref1 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref1 !== void 0 ? ref1 : "";
80
99
  lastValue.current = itemText;
81
100
  setInputValue(itemText);
82
101
  };
83
- let isInitialRender = $k6Ppu$useRef(true);
102
+ let isInitialRender = (0, $k6Ppu$useRef)(true);
84
103
  var _selectedKey, ref1;
85
- let lastSelectedKey = $k6Ppu$useRef((ref1 = (_selectedKey = props.selectedKey) !== null && _selectedKey !== void 0 ? _selectedKey : props.defaultSelectedKey) !== null && ref1 !== void 0 ? ref1 : null);
104
+ let lastSelectedKey = (0, $k6Ppu$useRef)((ref1 = (_selectedKey = props.selectedKey) !== null && _selectedKey !== void 0 ? _selectedKey : props.defaultSelectedKey) !== null && ref1 !== void 0 ? ref1 : null);
86
105
  var ref2;
87
- let lastSelectedKeyText = $k6Ppu$useRef((ref2 = (ref4 = collection.getItem(selectedKey)) === null || ref4 === void 0 ? void 0 : ref4.textValue) !== null && ref2 !== void 0 ? ref2 : '');
106
+ let lastSelectedKeyText = (0, $k6Ppu$useRef)((ref2 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref2 !== void 0 ? ref2 : "");
88
107
  // intentional omit dependency array, want this to happen on every render
89
108
  // eslint-disable-next-line react-hooks/exhaustive-deps
90
- $k6Ppu$useEffect(()=>{
109
+ (0, $k6Ppu$useEffect)(()=>{
91
110
  var ref;
92
111
  // Open and close menu automatically when the input value changes if the input is focused,
93
112
  // and there are items in the collection or allowEmptyCollection is true.
94
- if (isFocused1 && (filteredCollection.size > 0 || allowsEmptyCollection) && !triggerState.isOpen && inputValue !== lastValue.current && menuTrigger !== 'manual') open1(null, 'input');
113
+ if (isFocused && (filteredCollection.size > 0 || allowsEmptyCollection) && !triggerState.isOpen && inputValue !== lastValue.current && menuTrigger !== "manual") open(null, "input");
95
114
  // Close the menu if the collection is empty. Don't close menu if filtered collection size is 0
96
115
  // but we are currently showing all items via button press
97
116
  if (!showAllItems && !allowsEmptyCollection && triggerState.isOpen && filteredCollection.size === 0) triggerState.close();
@@ -103,7 +122,7 @@ function $a9e7382a7d111cb5$export$b453a3bfd4a5fa9e(props) {
103
122
  setShowAllItems(false);
104
123
  // Set selectedKey to null when the user clears the input.
105
124
  // If controlled, this is the application developer's responsibility.
106
- if (inputValue === '' && (props.inputValue === undefined || props.selectedKey === undefined)) setSelectedKey(null);
125
+ if (inputValue === "" && (props.inputValue === undefined || props.selectedKey === undefined)) setSelectedKey(null);
107
126
  }
108
127
  // 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
109
128
  if (isInitialRender.current && props.inputValue === undefined && props.defaultInputValue === undefined) resetInputValue();
@@ -112,13 +131,13 @@ function $a9e7382a7d111cb5$export$b453a3bfd4a5fa9e(props) {
112
131
  // In this case, it's the user's responsibility to update inputValue in onSelectionChange.
113
132
  if (selectedKey !== lastSelectedKey.current && (props.inputValue === undefined || props.selectedKey === undefined)) resetInputValue();
114
133
  else lastValue.current = inputValue;
115
- var ref5;
134
+ var ref1;
116
135
  // Update the inputValue if the selected item's text changes from its last tracked value.
117
136
  // 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.
118
137
  // Only reset if the user isn't currently within the field so we don't erroneously modify user input.
119
138
  // If inputValue is controlled, it is the user's responsibility to update the inputValue when items change.
120
- let selectedItemText = (ref5 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref5 !== void 0 ? ref5 : '';
121
- if (!isFocused1 && selectedKey != null && props.inputValue === undefined && selectedKey === lastSelectedKey.current) {
139
+ let selectedItemText = (ref1 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref1 !== void 0 ? ref1 : "";
140
+ if (!isFocused && selectedKey != null && props.inputValue === undefined && selectedKey === lastSelectedKey.current) {
122
141
  if (lastSelectedKeyText.current !== selectedItemText) {
123
142
  lastValue.current = selectedItemText;
124
143
  setInputValue(selectedItemText);
@@ -128,7 +147,7 @@ function $a9e7382a7d111cb5$export$b453a3bfd4a5fa9e(props) {
128
147
  lastSelectedKey.current = selectedKey;
129
148
  lastSelectedKeyText.current = selectedItemText;
130
149
  });
131
- $k6Ppu$useEffect(()=>{
150
+ (0, $k6Ppu$useEffect)(()=>{
132
151
  // Reset focused key when the menu closes
133
152
  if (!triggerState.isOpen) selectionManager.setFocusedKey(null);
134
153
  }, [
@@ -150,9 +169,9 @@ function $a9e7382a7d111cb5$export$b453a3bfd4a5fa9e(props) {
150
169
  if (props.selectedKey !== undefined && props.inputValue !== undefined) {
151
170
  var ref;
152
171
  props.onSelectionChange(selectedKey);
153
- var ref6;
172
+ var ref1;
154
173
  // Stop menu from reopening from useEffect
155
- let itemText = (ref6 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref6 !== void 0 ? ref6 : '';
174
+ let itemText = (ref1 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref1 !== void 0 ? ref1 : "";
156
175
  lastValue.current = itemText;
157
176
  triggerState.close();
158
177
  } else {
@@ -173,11 +192,11 @@ function $a9e7382a7d111cb5$export$b453a3bfd4a5fa9e(props) {
173
192
  };
174
193
  let setFocused = (isFocused)=>{
175
194
  if (isFocused) {
176
- if (menuTrigger === 'focus') open1(null, 'focus');
195
+ if (menuTrigger === "focus") open(null, "focus");
177
196
  } else if (shouldCloseOnBlur) {
178
197
  var ref;
179
- var ref7;
180
- let itemText = (ref7 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref7 !== void 0 ? ref7 : '';
198
+ var ref1;
199
+ let itemText = (ref1 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref1 !== void 0 ? ref1 : "";
181
200
  if (allowsCustomValue && inputValue !== itemText) commitCustomValue();
182
201
  else commitSelection();
183
202
  }
@@ -186,13 +205,13 @@ function $a9e7382a7d111cb5$export$b453a3bfd4a5fa9e(props) {
186
205
  return {
187
206
  ...triggerState,
188
207
  toggle: toggle,
189
- open: open1,
208
+ open: open,
190
209
  close: commit,
191
210
  selectionManager: selectionManager,
192
211
  selectedKey: selectedKey,
193
212
  setSelectedKey: setSelectedKey,
194
213
  disabledKeys: disabledKeys,
195
- isFocused: isFocused1,
214
+ isFocused: isFocused,
196
215
  setFocused: setFocused,
197
216
  selectedItem: selectedItem,
198
217
  collection: showAllItems ? originalCollection : filteredCollection,
@@ -203,12 +222,12 @@ function $a9e7382a7d111cb5$export$b453a3bfd4a5fa9e(props) {
203
222
  };
204
223
  }
205
224
  function $a9e7382a7d111cb5$var$filterCollection(collection, inputValue, filter) {
206
- return new $k6Ppu$ListCollection($a9e7382a7d111cb5$var$filterNodes(collection, inputValue, filter));
225
+ return new (0, $k6Ppu$ListCollection)($a9e7382a7d111cb5$var$filterNodes(collection, inputValue, filter));
207
226
  }
208
227
  function $a9e7382a7d111cb5$var$filterNodes(nodes, inputValue, filter) {
209
228
  let filteredNode = [];
210
229
  for (let node of nodes){
211
- if (node.type === 'section' && node.hasChildNodes) {
230
+ if (node.type === "section" && node.hasChildNodes) {
212
231
  let filtered = $a9e7382a7d111cb5$var$filterNodes(node.childNodes, inputValue, filter);
213
232
  if ([
214
233
  ...filtered
@@ -216,7 +235,7 @@ function $a9e7382a7d111cb5$var$filterNodes(nodes, inputValue, filter) {
216
235
  ...node,
217
236
  childNodes: filtered
218
237
  });
219
- } else if (node.type !== 'section' && filter(node.textValue, inputValue)) filteredNode.push({
238
+ } else if (node.type !== "section" && filter(node.textValue, inputValue)) filteredNode.push({
220
239
  ...node
221
240
  });
222
241
  }
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;SCmDgB,yCAAgB,CAAmB,KAA8B,EAAoB,CAAC;QAmGnE,IAA+B;IAlGhE,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,eAAQ,CAAC,KAAK;IACpD,GAAG,EAAE,UAAS,EAAE,eAAe,IAAI,eAAQ,CAAC,KAAK;QAG/C,kBAAuB;IAFzB,GAAG,EAAE,UAAU,EAAE,aAAa,IAAI,yBAAkB,CAClD,KAAK,CAAC,UAAU,GAChB,kBAAuB,GAAvB,KAAK,CAAC,iBAAiB,cAAvB,kBAAuB,cAAvB,kBAAuB,GAAI,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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AI,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 {useComboBoxState} from './useComboBoxState';\n\nexport type {ComboBoxStateOptions, ComboBoxState} 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;\n\nexport interface ComboBoxStateOptions<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: ComboBoxStateOptions<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 close: commit,\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":"module.mjs.map"}
1
+ {"mappings":";;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED;;;;AAuCO,SAAS,0CAAmC,KAA8B,EAAoB;QAmGlE;IAlGjC,IAAI,iBACF,cAAa,eACb,cAAc,iCACd,wBAAwB,KAAK,sBAC7B,kBAAiB,qBACjB,oBAAoB,IAAI,GACzB,GAAG;IAEJ,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,eAAO,EAAE,KAAK;IACpD,IAAI,CAAC,WAAW,gBAAgB,GAAG,CAAA,GAAA,eAAO,EAAE,KAAK;QAG/C;IAFF,IAAI,CAAC,YAAY,cAAc,GAAG,CAAA,GAAA,yBAAiB,EACjD,MAAM,UAAU,EAChB,CAAA,qBAAA,MAAM,iBAAiB,cAAvB,gCAAA,qBAA2B,EAAE,EAC7B,MAAM,aAAa;IAGrB,IAAI,oBAAoB,C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AClB,KAAK,IAAI,EAAE;QACb,OACK,IAAI,mBAAmB;gBACb;gBAAA;YAAf,IAAI,WAAW,CAAA,OAAA,CAAA,MAAA,WAAW,OAAO,CAAC,0BAAnB,iBAAA,KAAA,IAAA,IAAiC,SAAS,cAA1C,kBAAA,OAA8C,EAAE;YAC/D,IAAI,qBAAqB,eAAe,UACtC;iBAEA;QAEJ,CAAC;QAED,gBAAgB;IAClB;IAEA,OAAO;QACL,GAAG,YAAY;gBACf;cACA;QACA,OAAO;0BACP;qBACA;wBACA;sBACA;mBACA;oBACA;sBACA;QACA,YAAY,eAAe,qBAAqB,kBAAkB;oBAClE;uBACA;gBACA;gBACA;IACF;AACF;AAEA,SAAS,uCAAmC,UAA+B,EAAE,UAAkB,EAAE,MAAgB,EAAuB;IACtI,OAAO,IAAI,CAAA,GAAA,qBAAc,AAAD,EAAE,kCAAY,YAAY,YAAY;AAChE;AAEA,SAAS,kCAAe,KAAwB,EAAE,UAAkB,EAAE,MAAgB,EAAqB;IACzG,IAAI,eAAe,EAAE;IACrB,KAAK,IAAI,QAAQ,MAAO;QACtB,IAAI,KAAK,IAAI,KAAK,aAAa,KAAK,aAAa,EAAE;YACjD,IAAI,WAAW,kCAAY,KAAK,UAAU,EAAE,YAAY;YACxD,IAAI;mBAAI;aAAS,CAAC,MAAM,GAAG,GACzB,aAAa,IAAI,CAAC;gBAAC,GAAG,IAAI;gBAAE,YAAY;YAAQ;QAEpD,OAAO,IAAI,KAAK,IAAI,KAAK,aAAa,OAAO,KAAK,SAAS,EAAE,aAC3D,aAAa,IAAI,CAAC;YAAC,GAAG,IAAI;QAAA;IAE9B;IACA,OAAO;AACT;;CD1UC,GAED","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 {useComboBoxState} from './useComboBoxState';\n\nexport type {ComboBoxStateOptions, ComboBoxState} 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;\n\nexport interface ComboBoxStateOptions<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: ComboBoxStateOptions<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 close: commit,\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":"module.mjs.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/combobox",
3
- "version": "3.3.1-nightly.3599+b35d5c02f",
3
+ "version": "3.3.1-nightly.3603+22cb32d32",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,13 +22,13 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@babel/runtime": "^7.6.2",
26
- "@react-stately/list": "3.6.1-nightly.3599+b35d5c02f",
27
- "@react-stately/menu": "3.4.4-nightly.3599+b35d5c02f",
28
- "@react-stately/select": "3.3.4-nightly.3599+b35d5c02f",
29
- "@react-stately/utils": "3.0.0-nightly.1899+b35d5c02f",
30
- "@react-types/combobox": "3.5.6-nightly.3599+b35d5c02f",
31
- "@react-types/shared": "3.0.0-nightly.1899+b35d5c02f"
25
+ "@react-stately/list": "3.6.1-nightly.3603+22cb32d32",
26
+ "@react-stately/menu": "3.4.4-nightly.3603+22cb32d32",
27
+ "@react-stately/select": "3.3.4-nightly.3603+22cb32d32",
28
+ "@react-stately/utils": "3.0.0-nightly.1903+22cb32d32",
29
+ "@react-types/combobox": "3.5.6-nightly.3603+22cb32d32",
30
+ "@react-types/shared": "3.0.0-nightly.1903+22cb32d32",
31
+ "@swc/helpers": "^0.4.14"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
@@ -36,5 +36,5 @@
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "b35d5c02fe900badccd0cf1a8f23bb593419f238"
39
+ "gitHead": "22cb32d329e66c60f55d4fc4025d1d44bb015d71"
40
40
  }