@react-stately/combobox 3.0.2 → 3.0.4-nightly.3120
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 +44 -31
- package/dist/main.js.map +1 -1
- package/dist/module.js +44 -31
- package/dist/module.js.map +1 -1
- package/package.json +8 -8
package/dist/main.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var $
|
|
2
|
-
var $
|
|
3
|
-
var $
|
|
4
|
-
var $
|
|
1
|
+
var $5XAuq$reactstatelylist = require("@react-stately/list");
|
|
2
|
+
var $5XAuq$reactstatelyutils = require("@react-stately/utils");
|
|
3
|
+
var $5XAuq$react = require("react");
|
|
4
|
+
var $5XAuq$reactstatelymenu = require("@react-stately/menu");
|
|
5
5
|
|
|
6
6
|
function $parcel$exportWildcard(dest, source) {
|
|
7
7
|
Object.keys(source).forEach(function(key) {
|
|
@@ -22,18 +22,20 @@ function $parcel$exportWildcard(dest, source) {
|
|
|
22
22
|
function $parcel$export(e, n, v, s) {
|
|
23
23
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
24
24
|
}
|
|
25
|
-
var $
|
|
25
|
+
var $e563f9c9469ad14c$exports = {};
|
|
26
26
|
|
|
27
|
-
$parcel$export($
|
|
27
|
+
$parcel$export($e563f9c9469ad14c$exports, "useComboBoxState", () => $e563f9c9469ad14c$export$b453a3bfd4a5fa9e);
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
function $
|
|
32
|
+
function $e563f9c9469ad14c$export$b453a3bfd4a5fa9e(props) {
|
|
33
|
+
var ref4;
|
|
33
34
|
let { defaultFilter: defaultFilter , menuTrigger: menuTrigger = 'input' , allowsEmptyCollection: allowsEmptyCollection = false , allowsCustomValue: allowsCustomValue , shouldCloseOnBlur: shouldCloseOnBlur = true } = props;
|
|
34
|
-
let [showAllItems, setShowAllItems] = $
|
|
35
|
-
let [isFocused1, setFocusedState] = $
|
|
36
|
-
|
|
35
|
+
let [showAllItems, setShowAllItems] = $5XAuq$react.useState(false);
|
|
36
|
+
let [isFocused1, setFocusedState] = $5XAuq$react.useState(false);
|
|
37
|
+
var _defaultInputValue;
|
|
38
|
+
let [inputValue, setInputValue] = $5XAuq$reactstatelyutils.useControlledState(props.inputValue, (_defaultInputValue = props.defaultInputValue) !== null && _defaultInputValue !== void 0 ? _defaultInputValue : '', props.onInputChange);
|
|
37
39
|
let onSelectionChange = (key)=>{
|
|
38
40
|
if (props.onSelectionChange) props.onSelectionChange(key);
|
|
39
41
|
// If key is the same, reset the inputValue and close the menu
|
|
@@ -43,15 +45,16 @@ function $25f859eaf3f5343a$export$b453a3bfd4a5fa9e(props) {
|
|
|
43
45
|
triggerState.close();
|
|
44
46
|
}
|
|
45
47
|
};
|
|
46
|
-
|
|
48
|
+
var _items;
|
|
49
|
+
let { collection: collection , selectionManager: selectionManager , selectedKey: selectedKey , setSelectedKey: setSelectedKey , selectedItem: selectedItem , disabledKeys: disabledKeys } = $5XAuq$reactstatelylist.useSingleSelectListState({
|
|
47
50
|
...props,
|
|
48
51
|
onSelectionChange: onSelectionChange,
|
|
49
|
-
items: props.items
|
|
52
|
+
items: (_items = props.items) !== null && _items !== void 0 ? _items : props.defaultItems
|
|
50
53
|
});
|
|
51
54
|
// Preserve original collection so we can show all items on demand
|
|
52
55
|
let originalCollection = collection;
|
|
53
|
-
let filteredCollection = $
|
|
54
|
-
props.items != null || !defaultFilter ? collection : $
|
|
56
|
+
let filteredCollection = $5XAuq$react.useMemo(()=>// No default filter if items are controlled.
|
|
57
|
+
props.items != null || !defaultFilter ? collection : $e563f9c9469ad14c$var$filterCollection(collection, inputValue, defaultFilter)
|
|
55
58
|
, [
|
|
56
59
|
collection,
|
|
57
60
|
inputValue,
|
|
@@ -59,11 +62,11 @@ function $25f859eaf3f5343a$export$b453a3bfd4a5fa9e(props) {
|
|
|
59
62
|
props.items
|
|
60
63
|
]);
|
|
61
64
|
// Track what action is attempting to open the menu
|
|
62
|
-
let menuOpenTrigger = $
|
|
65
|
+
let menuOpenTrigger = $5XAuq$react.useRef('focus');
|
|
63
66
|
let onOpenChange = (open)=>{
|
|
64
67
|
if (props.onOpenChange) props.onOpenChange(open, open ? menuOpenTrigger.current : undefined);
|
|
65
68
|
};
|
|
66
|
-
let triggerState = $
|
|
69
|
+
let triggerState = $5XAuq$reactstatelymenu.useMenuTriggerState({
|
|
67
70
|
...props,
|
|
68
71
|
onOpenChange: onOpenChange,
|
|
69
72
|
isOpen: undefined,
|
|
@@ -91,18 +94,23 @@ function $25f859eaf3f5343a$export$b453a3bfd4a5fa9e(props) {
|
|
|
91
94
|
if (!triggerState.isOpen) menuOpenTrigger.current = trigger;
|
|
92
95
|
triggerState.toggle(focusStrategy);
|
|
93
96
|
};
|
|
94
|
-
let lastValue = $
|
|
97
|
+
let lastValue = $5XAuq$react.useRef(inputValue);
|
|
95
98
|
let resetInputValue = ()=>{
|
|
96
|
-
|
|
99
|
+
var ref;
|
|
100
|
+
var ref3;
|
|
101
|
+
let itemText = (ref3 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref3 !== void 0 ? ref3 : '';
|
|
97
102
|
lastValue.current = itemText;
|
|
98
103
|
setInputValue(itemText);
|
|
99
104
|
};
|
|
100
|
-
let isInitialRender = $
|
|
101
|
-
|
|
102
|
-
let
|
|
105
|
+
let isInitialRender = $5XAuq$react.useRef(true);
|
|
106
|
+
var _selectedKey, ref1;
|
|
107
|
+
let lastSelectedKey = $5XAuq$react.useRef((ref1 = (_selectedKey = props.selectedKey) !== null && _selectedKey !== void 0 ? _selectedKey : props.defaultSelectedKey) !== null && ref1 !== void 0 ? ref1 : null);
|
|
108
|
+
var ref2;
|
|
109
|
+
let lastSelectedKeyText = $5XAuq$react.useRef((ref2 = (ref4 = collection.getItem(selectedKey)) === null || ref4 === void 0 ? void 0 : ref4.textValue) !== null && ref2 !== void 0 ? ref2 : '');
|
|
103
110
|
// intentional omit dependency array, want this to happen on every render
|
|
104
111
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
105
|
-
$
|
|
112
|
+
$5XAuq$react.useEffect(()=>{
|
|
113
|
+
var ref;
|
|
106
114
|
// Open and close menu automatically when the input value changes if the input is focused,
|
|
107
115
|
// and there are items in the collection or allowEmptyCollection is true.
|
|
108
116
|
if (isFocused1 && (filteredCollection.size > 0 || allowsEmptyCollection) && !triggerState.isOpen && inputValue !== lastValue.current && menuTrigger !== 'manual') open1(null, 'input');
|
|
@@ -126,11 +134,12 @@ function $25f859eaf3f5343a$export$b453a3bfd4a5fa9e(props) {
|
|
|
126
134
|
// In this case, it's the user's responsibility to update inputValue in onSelectionChange.
|
|
127
135
|
if (selectedKey !== lastSelectedKey.current && (props.inputValue === undefined || props.selectedKey === undefined)) resetInputValue();
|
|
128
136
|
else lastValue.current = inputValue;
|
|
137
|
+
var ref5;
|
|
129
138
|
// Update the inputValue if the selected item's text changes from its last tracked value.
|
|
130
139
|
// This is to handle cases where a selectedKey is specified but the items aren't available (async loading) or the selected item's text value updates.
|
|
131
140
|
// Only reset if the user isn't currently within the field so we don't erroneously modify user input.
|
|
132
141
|
// If inputValue is controlled, it is the user's responsibility to update the inputValue when items change.
|
|
133
|
-
let selectedItemText = collection.getItem(selectedKey)
|
|
142
|
+
let selectedItemText = (ref5 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref5 !== void 0 ? ref5 : '';
|
|
134
143
|
if (!isFocused1 && selectedKey != null && props.inputValue === undefined && selectedKey === lastSelectedKey.current) {
|
|
135
144
|
if (lastSelectedKeyText.current !== selectedItemText) {
|
|
136
145
|
lastValue.current = selectedItemText;
|
|
@@ -141,7 +150,7 @@ function $25f859eaf3f5343a$export$b453a3bfd4a5fa9e(props) {
|
|
|
141
150
|
lastSelectedKey.current = selectedKey;
|
|
142
151
|
lastSelectedKeyText.current = selectedItemText;
|
|
143
152
|
});
|
|
144
|
-
$
|
|
153
|
+
$5XAuq$react.useEffect(()=>{
|
|
145
154
|
// Reset focused key when the menu closes
|
|
146
155
|
if (!triggerState.isOpen) selectionManager.setFocusedKey(null);
|
|
147
156
|
}, [
|
|
@@ -161,9 +170,11 @@ function $25f859eaf3f5343a$export$b453a3bfd4a5fa9e(props) {
|
|
|
161
170
|
let commitSelection = ()=>{
|
|
162
171
|
// If multiple things are controlled, call onSelectionChange
|
|
163
172
|
if (props.selectedKey !== undefined && props.inputValue !== undefined) {
|
|
173
|
+
var ref;
|
|
164
174
|
props.onSelectionChange(selectedKey);
|
|
175
|
+
var ref6;
|
|
165
176
|
// Stop menu from reopening from useEffect
|
|
166
|
-
let itemText = collection.getItem(selectedKey)
|
|
177
|
+
let itemText = (ref6 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref6 !== void 0 ? ref6 : '';
|
|
167
178
|
lastValue.current = itemText;
|
|
168
179
|
triggerState.close();
|
|
169
180
|
} else {
|
|
@@ -186,7 +197,9 @@ function $25f859eaf3f5343a$export$b453a3bfd4a5fa9e(props) {
|
|
|
186
197
|
if (isFocused) {
|
|
187
198
|
if (menuTrigger === 'focus') open1(null, 'focus');
|
|
188
199
|
} else if (shouldCloseOnBlur) {
|
|
189
|
-
|
|
200
|
+
var ref;
|
|
201
|
+
var ref7;
|
|
202
|
+
let itemText = (ref7 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref7 !== void 0 ? ref7 : '';
|
|
190
203
|
if (allowsCustomValue && inputValue !== itemText) commitCustomValue();
|
|
191
204
|
else commitSelection();
|
|
192
205
|
}
|
|
@@ -210,14 +223,14 @@ function $25f859eaf3f5343a$export$b453a3bfd4a5fa9e(props) {
|
|
|
210
223
|
revert: revert
|
|
211
224
|
};
|
|
212
225
|
}
|
|
213
|
-
function $
|
|
214
|
-
return new $
|
|
226
|
+
function $e563f9c9469ad14c$var$filterCollection(collection, inputValue, filter) {
|
|
227
|
+
return new $5XAuq$reactstatelylist.ListCollection($e563f9c9469ad14c$var$filterNodes(collection, inputValue, filter));
|
|
215
228
|
}
|
|
216
|
-
function $
|
|
229
|
+
function $e563f9c9469ad14c$var$filterNodes(nodes, inputValue, filter) {
|
|
217
230
|
let filteredNode = [];
|
|
218
231
|
for (let node of nodes){
|
|
219
232
|
if (node.type === 'section' && node.hasChildNodes) {
|
|
220
|
-
let filtered = $
|
|
233
|
+
let filtered = $e563f9c9469ad14c$var$filterNodes(node.childNodes, inputValue, filter);
|
|
221
234
|
if ([
|
|
222
235
|
...filtered
|
|
223
236
|
].length > 0) filteredNode.push({
|
|
@@ -232,7 +245,7 @@ function $25f859eaf3f5343a$var$filterNodes(nodes, inputValue, filter) {
|
|
|
232
245
|
}
|
|
233
246
|
|
|
234
247
|
|
|
235
|
-
$parcel$exportWildcard(module.exports, $
|
|
248
|
+
$parcel$exportWildcard(module.exports, $e563f9c9469ad14c$exports);
|
|
236
249
|
|
|
237
250
|
|
|
238
251
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SCkDgB,yCAAgB,CAAmB,KAA4B,EAAoB,CAAC;IAClG,GAAG,CAAC,CAAC,gBACH,aAAa,gBACb,WAAW,GAAG,CAAO,gCACrB,qBAAqB,GAAG,KAAK,sBAC7B,iBAAiB,sBACjB,iBAAiB,GAAG,IAAI,EAC1B,CAAC,GAAG,KAAK;IAET,GAAG,EAAE,YAAY,EAAE,eAAe,IAAI,qBAAQ,CAAC,KAAK;IACpD,GAAG,EAAE,UAAS,EAAE,eAAe,IAAI,qBAAQ,CAAC,KAAK;IACjD,GAAG,EAAE,UAAU,EAAE,aAAa,IAAI,2CAAkB,CAClD,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,iBAAiB,IAAI,CAAE,GAC7B,KAAK,CAAC,aAAa;IAGrB,GAAG,CAAC,i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,CAAC;IACrB,GAAG,EAAE,GAAG,CAAC,IAAI,IAAI,KAAK,CAAE,CAAC;QACvB,EAAE,EAAE,IAAI,CAAC,IAAI,KAAK,CAAS,YAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YAClD,GAAG,CAAC,QAAQ,GAAG,iCAAW,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,EAAE,MAAM;YAC9D,EAAE,EAAE,CAAC;mBAAG,QAAQ;YAAA,CAAC,CAAC,MAAM,GAAG,CAAC,EAC1B,YAAY,CAAC,IAAI,CAAC,CAAC;mBAAG,IAAI;gBAAE,UAAU,EAAE,QAAQ;YAAA,CAAC;QAErD,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,IAAI,KAAK,CAAS,YAAI,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,GACrE,YAAY,CAAC,IAAI,CAAC,CAAC;eAAG,IAAI;QAAA,CAAC;IAE/B,CAAC;IACD,MAAM,CAAC,YAAY;AACrB,CAAC","sources":["packages/@react-stately/combobox/src/index.ts","packages/@react-stately/combobox/src/useComboBoxState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './useComboBoxState';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, FocusStrategy, Node} from '@react-types/shared';\nimport {ComboBoxProps, MenuTriggerAction} from '@react-types/combobox';\nimport {ListCollection, useSingleSelectListState} from '@react-stately/list';\nimport {SelectState} from '@react-stately/select';\nimport {useControlledState} from '@react-stately/utils';\nimport {useEffect, useMemo, useRef, useState} from 'react';\nimport {useMenuTriggerState} from '@react-stately/menu';\n\nexport interface ComboBoxState<T> extends SelectState<T> {\n /** The current value of the combo box input. */\n inputValue: string,\n /** Sets the value of the combo box input. */\n setInputValue(value: string): void,\n /** Selects the currently focused item and updates the input value. */\n commit(): void,\n /** Opens the menu. */\n open(focusStrategy?: FocusStrategy | null, trigger?: MenuTriggerAction): void,\n /** Toggles the menu. */\n toggle(focusStrategy?: FocusStrategy | null, trigger?: MenuTriggerAction): void,\n /** Resets the input value to the previously selected item's text if any and closes the menu. */\n revert(): void\n}\n\ntype FilterFn = (textValue: string, inputValue: string) => boolean;\ninterface ComboBoxStateProps<T> extends ComboBoxProps<T> {\n /** The filter function used to determine if a option should be included in the combo box list. */\n defaultFilter?: FilterFn,\n /** Whether the combo box allows the menu to be open when the collection is empty. */\n allowsEmptyCollection?: boolean,\n /** Whether the combo box menu should close on blur. */\n shouldCloseOnBlur?: boolean\n}\n\n/**\n * Provides state management for a combo box component. Handles building a collection\n * of items from props and manages the option selection state of the combo box. In addition, it tracks the input value,\n * focus state, and other properties of the combo box.\n */\nexport function useComboBoxState<T extends object>(props: ComboBoxStateProps<T>): ComboBoxState<T> {\n let {\n defaultFilter,\n menuTrigger = 'input',\n allowsEmptyCollection = false,\n allowsCustomValue,\n shouldCloseOnBlur = true\n } = props;\n\n let [showAllItems, setShowAllItems] = useState(false);\n let [isFocused, setFocusedState] = useState(false);\n let [inputValue, setInputValue] = useControlledState(\n props.inputValue,\n props.defaultInputValue ?? '',\n props.onInputChange\n );\n\n let onSelectionChange = (key) => {\n if (props.onSelectionChange) {\n props.onSelectionChange(key);\n }\n\n // If key is the same, reset the inputValue and close the menu\n // (scenario: user clicks on already selected option)\n if (key === selectedKey) {\n resetInputValue();\n triggerState.close();\n }\n };\n\n let {collection, selectionManager, selectedKey, setSelectedKey, selectedItem, disabledKeys} = useSingleSelectListState({\n ...props,\n onSelectionChange,\n items: props.items ?? props.defaultItems\n });\n\n // Preserve original collection so we can show all items on demand\n let originalCollection = collection;\n let filteredCollection = useMemo(() => (\n // No default filter if items are controlled.\n props.items != null || !defaultFilter\n ? collection\n : filterCollection(collection, inputValue, defaultFilter)\n ), [collection, inputValue, defaultFilter, props.items]);\n\n // Track what action is attempting to open the menu\n let menuOpenTrigger = useRef('focus' as MenuTriggerAction);\n let onOpenChange = (open: boolean) => {\n if (props.onOpenChange) {\n props.onOpenChange(open, open ? menuOpenTrigger.current : undefined);\n }\n };\n\n let triggerState = useMenuTriggerState({...props, onOpenChange, isOpen: undefined, defaultOpen: undefined});\n let open = (focusStrategy?: FocusStrategy, trigger?: MenuTriggerAction) => {\n let displayAllItems = (trigger === 'manual' || (trigger === 'focus' && menuTrigger === 'focus'));\n // Prevent open operations from triggering if there is nothing to display\n // Also prevent open operations from triggering if items are uncontrolled but defaultItems is empty, even if displayAllItems is true.\n // This is to prevent comboboxes with empty defaultItems from opening but allow controlled items comboboxes to open even if the inital list is empty (assumption is user will provide swap the empty list with a base list via onOpenChange returning `menuTrigger` manual)\n if (allowsEmptyCollection || filteredCollection.size > 0 || (displayAllItems && originalCollection.size > 0) || props.items) {\n if (displayAllItems && !triggerState.isOpen && props.items === undefined) {\n // Show all items if menu is manually opened. Only care about this if items are undefined\n setShowAllItems(true);\n }\n\n menuOpenTrigger.current = trigger;\n triggerState.open(focusStrategy);\n }\n };\n\n let toggle = (focusStrategy?: FocusStrategy, trigger?: MenuTriggerAction) => {\n let displayAllItems = (trigger === 'manual' || (trigger === 'focus' && menuTrigger === 'focus'));\n // If the menu is closed and there is nothing to display, early return so toggle isn't called to prevent extraneous onOpenChange\n if (!(allowsEmptyCollection || filteredCollection.size > 0 || (displayAllItems && originalCollection.size > 0) || props.items) && !triggerState.isOpen) {\n return;\n }\n\n if (displayAllItems && !triggerState.isOpen && props.items === undefined) {\n // Show all items if menu is toggled open. Only care about this if items are undefined\n setShowAllItems(true);\n }\n\n // Only update the menuOpenTrigger if menu is currently closed\n if (!triggerState.isOpen) {\n menuOpenTrigger.current = trigger;\n }\n\n triggerState.toggle(focusStrategy);\n };\n\n let lastValue = useRef(inputValue);\n let resetInputValue = () => {\n let itemText = collection.getItem(selectedKey)?.textValue ?? '';\n lastValue.current = itemText;\n setInputValue(itemText);\n };\n\n let isInitialRender = useRef(true);\n let lastSelectedKey = useRef(props.selectedKey ?? props.defaultSelectedKey ?? null);\n let lastSelectedKeyText = useRef(collection.getItem(selectedKey)?.textValue ?? '');\n // intentional omit dependency array, want this to happen on every render\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(() => {\n // Open and close menu automatically when the input value changes if the input is focused,\n // and there are items in the collection or allowEmptyCollection is true.\n if (\n isFocused &&\n (filteredCollection.size > 0 || allowsEmptyCollection) &&\n !triggerState.isOpen &&\n inputValue !== lastValue.current &&\n menuTrigger !== 'manual'\n ) {\n open(null, 'input');\n }\n\n // Close the menu if the collection is empty. Don't close menu if filtered collection size is 0\n // but we are currently showing all items via button press\n if (\n !showAllItems &&\n !allowsEmptyCollection &&\n triggerState.isOpen &&\n filteredCollection.size === 0\n ) {\n triggerState.close();\n }\n\n // Close when an item is selected.\n if (\n selectedKey != null &&\n selectedKey !== lastSelectedKey.current\n ) {\n triggerState.close();\n }\n\n // Clear focused key when input value changes and display filtered collection again.\n if (inputValue !== lastValue.current) {\n selectionManager.setFocusedKey(null);\n setShowAllItems(false);\n\n // Set selectedKey to null when the user clears the input.\n // If controlled, this is the application developer's responsibility.\n if (inputValue === '' && (props.inputValue === undefined || props.selectedKey === undefined)) {\n setSelectedKey(null);\n }\n }\n\n // If it is the intial render and inputValue isn't controlled nor has an intial value, set input to match current selected key if any\n if (isInitialRender.current && (props.inputValue === undefined && props.defaultInputValue === undefined)) {\n resetInputValue();\n }\n\n // If the selectedKey changed, update the input value.\n // Do nothing if both inputValue and selectedKey are controlled.\n // In this case, it's the user's responsibility to update inputValue in onSelectionChange.\n if (\n selectedKey !== lastSelectedKey.current &&\n (props.inputValue === undefined || props.selectedKey === undefined)\n ) {\n resetInputValue();\n } else {\n lastValue.current = inputValue;\n }\n\n // Update the inputValue if the selected item's text changes from its last tracked value.\n // This is to handle cases where a selectedKey is specified but the items aren't available (async loading) or the selected item's text value updates.\n // Only reset if the user isn't currently within the field so we don't erroneously modify user input.\n // If inputValue is controlled, it is the user's responsibility to update the inputValue when items change.\n let selectedItemText = collection.getItem(selectedKey)?.textValue ?? '';\n if (!isFocused && selectedKey != null && props.inputValue === undefined && selectedKey === lastSelectedKey.current) {\n if (lastSelectedKeyText.current !== selectedItemText) {\n lastValue.current = selectedItemText;\n setInputValue(selectedItemText);\n }\n }\n\n isInitialRender.current = false;\n lastSelectedKey.current = selectedKey;\n lastSelectedKeyText.current = selectedItemText;\n });\n\n useEffect(() => {\n // Reset focused key when the menu closes\n if (!triggerState.isOpen) {\n selectionManager.setFocusedKey(null);\n }\n }, [triggerState.isOpen, selectionManager]);\n\n // Revert input value and close menu\n let revert = () => {\n if (allowsCustomValue && selectedKey == null) {\n commitCustomValue();\n } else {\n commitSelection();\n }\n };\n\n let commitCustomValue = () => {\n lastSelectedKey.current = null;\n setSelectedKey(null);\n triggerState.close();\n };\n\n let commitSelection = () => {\n // If multiple things are controlled, call onSelectionChange\n if (props.selectedKey !== undefined && props.inputValue !== undefined) {\n props.onSelectionChange(selectedKey);\n\n // Stop menu from reopening from useEffect\n let itemText = collection.getItem(selectedKey)?.textValue ?? '';\n lastValue.current = itemText;\n triggerState.close();\n } else {\n // If only a single aspect of combobox is controlled, reset input value and close menu for the user\n resetInputValue();\n triggerState.close();\n }\n };\n\n let commit = () => {\n if (triggerState.isOpen && selectionManager.focusedKey != null) {\n // Reset inputValue and close menu here if the selected key is already the focused key. Otherwise\n // fire onSelectionChange to allow the application to control the closing.\n if (selectedKey === selectionManager.focusedKey) {\n commitSelection();\n } else {\n setSelectedKey(selectionManager.focusedKey);\n }\n } else if (allowsCustomValue) {\n commitCustomValue();\n } else {\n // Reset inputValue and close menu if no item is focused but user triggers a commit\n commitSelection();\n }\n };\n\n let setFocused = (isFocused: boolean) => {\n if (isFocused) {\n if (menuTrigger === 'focus') {\n open(null, 'focus');\n }\n } else if (shouldCloseOnBlur) {\n let itemText = collection.getItem(selectedKey)?.textValue ?? '';\n if (allowsCustomValue && inputValue !== itemText) {\n commitCustomValue();\n } else {\n commitSelection();\n }\n }\n\n setFocusedState(isFocused);\n };\n\n return {\n ...triggerState,\n toggle,\n open,\n selectionManager,\n selectedKey,\n setSelectedKey,\n disabledKeys,\n isFocused,\n setFocused,\n selectedItem,\n collection: showAllItems ? originalCollection : filteredCollection,\n inputValue,\n setInputValue,\n commit,\n revert\n };\n}\n\nfunction filterCollection<T extends object>(collection: Collection<Node<T>>, inputValue: string, filter: FilterFn): Collection<Node<T>> {\n return new ListCollection(filterNodes(collection, inputValue, filter));\n}\n\nfunction filterNodes<T>(nodes: Iterable<Node<T>>, inputValue: string, filter: FilterFn): Iterable<Node<T>> {\n let filteredNode = [];\n for (let node of nodes) {\n if (node.type === 'section' && node.hasChildNodes) {\n let filtered = filterNodes(node.childNodes, inputValue, filter);\n if ([...filtered].length > 0) {\n filteredNode.push({...node, childNodes: filtered});\n }\n } else if (node.type !== 'section' && filter(node.textValue, inputValue)) {\n filteredNode.push({...node});\n }\n }\n return filteredNode;\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SCkDgB,yCAAgB,CAAmB,KAA4B,EAAoB,CAAC;QAmGjE,IAA+B;IAlGhE,GAAG,CAAC,CAAC,gBACH,aAAa,gBACb,WAAW,GAAG,CAAO,g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MAAgB,EAAuB,CAAC;IACvI,MAAM,CAAC,GAAG,CAAC,sCAAc,CAAC,iCAAW,CAAC,UAAU,EAAE,UAAU,EAAE,MAAM;AACtE,CAAC;SAEQ,iCAAW,CAAI,KAAwB,EAAE,UAAkB,EAAE,MAAgB,EAAqB,CAAC;IAC1G,GAAG,CAAC,YAAY,GAAG,CAAC,CAAC;IACrB,GAAG,EAAE,GAAG,CAAC,IAAI,IAAI,KAAK,CAAE,CAAC;QACvB,EAAE,EAAE,IAAI,CAAC,IAAI,KAAK,CAAS,YAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YAClD,GAAG,CAAC,QAAQ,GAAG,iCAAW,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,EAAE,MAAM;YAC9D,EAAE,EAAE,CAAC;mBAAG,QAAQ;YAAA,CAAC,CAAC,MAAM,GAAG,CAAC,EAC1B,YAAY,CAAC,IAAI,CAAC,CAAC;mBAAG,IAAI;gBAAE,UAAU,EAAE,QAAQ;YAAA,CAAC;QAErD,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,IAAI,KAAK,CAAS,YAAI,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,GACrE,YAAY,CAAC,IAAI,CAAC,CAAC;eAAG,IAAI;QAAA,CAAC;IAE/B,CAAC;IACD,MAAM,CAAC,YAAY;AACrB,CAAC","sources":["packages/@react-stately/combobox/src/index.ts","packages/@react-stately/combobox/src/useComboBoxState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './useComboBoxState';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, FocusStrategy, Node} from '@react-types/shared';\nimport {ComboBoxProps, MenuTriggerAction} from '@react-types/combobox';\nimport {ListCollection, useSingleSelectListState} from '@react-stately/list';\nimport {SelectState} from '@react-stately/select';\nimport {useControlledState} from '@react-stately/utils';\nimport {useEffect, useMemo, useRef, useState} from 'react';\nimport {useMenuTriggerState} from '@react-stately/menu';\n\nexport interface ComboBoxState<T> extends SelectState<T> {\n /** The current value of the combo box input. */\n inputValue: string,\n /** Sets the value of the combo box input. */\n setInputValue(value: string): void,\n /** Selects the currently focused item and updates the input value. */\n commit(): void,\n /** Opens the menu. */\n open(focusStrategy?: FocusStrategy | null, trigger?: MenuTriggerAction): void,\n /** Toggles the menu. */\n toggle(focusStrategy?: FocusStrategy | null, trigger?: MenuTriggerAction): void,\n /** Resets the input value to the previously selected item's text if any and closes the menu. */\n revert(): void\n}\n\ntype FilterFn = (textValue: string, inputValue: string) => boolean;\ninterface ComboBoxStateProps<T> extends ComboBoxProps<T> {\n /** The filter function used to determine if a option should be included in the combo box list. */\n defaultFilter?: FilterFn,\n /** Whether the combo box allows the menu to be open when the collection is empty. */\n allowsEmptyCollection?: boolean,\n /** Whether the combo box menu should close on blur. */\n shouldCloseOnBlur?: boolean\n}\n\n/**\n * Provides state management for a combo box component. Handles building a collection\n * of items from props and manages the option selection state of the combo box. In addition, it tracks the input value,\n * focus state, and other properties of the combo box.\n */\nexport function useComboBoxState<T extends object>(props: ComboBoxStateProps<T>): ComboBoxState<T> {\n let {\n defaultFilter,\n menuTrigger = 'input',\n allowsEmptyCollection = false,\n allowsCustomValue,\n shouldCloseOnBlur = true\n } = props;\n\n let [showAllItems, setShowAllItems] = useState(false);\n let [isFocused, setFocusedState] = useState(false);\n let [inputValue, setInputValue] = useControlledState(\n props.inputValue,\n props.defaultInputValue ?? '',\n props.onInputChange\n );\n\n let onSelectionChange = (key) => {\n if (props.onSelectionChange) {\n props.onSelectionChange(key);\n }\n\n // If key is the same, reset the inputValue and close the menu\n // (scenario: user clicks on already selected option)\n if (key === selectedKey) {\n resetInputValue();\n triggerState.close();\n }\n };\n\n let {collection, selectionManager, selectedKey, setSelectedKey, selectedItem, disabledKeys} = useSingleSelectListState({\n ...props,\n onSelectionChange,\n items: props.items ?? props.defaultItems\n });\n\n // Preserve original collection so we can show all items on demand\n let originalCollection = collection;\n let filteredCollection = useMemo(() => (\n // No default filter if items are controlled.\n props.items != null || !defaultFilter\n ? collection\n : filterCollection(collection, inputValue, defaultFilter)\n ), [collection, inputValue, defaultFilter, props.items]);\n\n // Track what action is attempting to open the menu\n let menuOpenTrigger = useRef('focus' as MenuTriggerAction);\n let onOpenChange = (open: boolean) => {\n if (props.onOpenChange) {\n props.onOpenChange(open, open ? menuOpenTrigger.current : undefined);\n }\n };\n\n let triggerState = useMenuTriggerState({...props, onOpenChange, isOpen: undefined, defaultOpen: undefined});\n let open = (focusStrategy?: FocusStrategy, trigger?: MenuTriggerAction) => {\n let displayAllItems = (trigger === 'manual' || (trigger === 'focus' && menuTrigger === 'focus'));\n // Prevent open operations from triggering if there is nothing to display\n // Also prevent open operations from triggering if items are uncontrolled but defaultItems is empty, even if displayAllItems is true.\n // This is to prevent comboboxes with empty defaultItems from opening but allow controlled items comboboxes to open even if the inital list is empty (assumption is user will provide swap the empty list with a base list via onOpenChange returning `menuTrigger` manual)\n if (allowsEmptyCollection || filteredCollection.size > 0 || (displayAllItems && originalCollection.size > 0) || props.items) {\n if (displayAllItems && !triggerState.isOpen && props.items === undefined) {\n // Show all items if menu is manually opened. Only care about this if items are undefined\n setShowAllItems(true);\n }\n\n menuOpenTrigger.current = trigger;\n triggerState.open(focusStrategy);\n }\n };\n\n let toggle = (focusStrategy?: FocusStrategy, trigger?: MenuTriggerAction) => {\n let displayAllItems = (trigger === 'manual' || (trigger === 'focus' && menuTrigger === 'focus'));\n // If the menu is closed and there is nothing to display, early return so toggle isn't called to prevent extraneous onOpenChange\n if (!(allowsEmptyCollection || filteredCollection.size > 0 || (displayAllItems && originalCollection.size > 0) || props.items) && !triggerState.isOpen) {\n return;\n }\n\n if (displayAllItems && !triggerState.isOpen && props.items === undefined) {\n // Show all items if menu is toggled open. Only care about this if items are undefined\n setShowAllItems(true);\n }\n\n // Only update the menuOpenTrigger if menu is currently closed\n if (!triggerState.isOpen) {\n menuOpenTrigger.current = trigger;\n }\n\n triggerState.toggle(focusStrategy);\n };\n\n let lastValue = useRef(inputValue);\n let resetInputValue = () => {\n let itemText = collection.getItem(selectedKey)?.textValue ?? '';\n lastValue.current = itemText;\n setInputValue(itemText);\n };\n\n let isInitialRender = useRef(true);\n let lastSelectedKey = useRef(props.selectedKey ?? props.defaultSelectedKey ?? null);\n let lastSelectedKeyText = useRef(collection.getItem(selectedKey)?.textValue ?? '');\n // intentional omit dependency array, want this to happen on every render\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(() => {\n // Open and close menu automatically when the input value changes if the input is focused,\n // and there are items in the collection or allowEmptyCollection is true.\n if (\n isFocused &&\n (filteredCollection.size > 0 || allowsEmptyCollection) &&\n !triggerState.isOpen &&\n inputValue !== lastValue.current &&\n menuTrigger !== 'manual'\n ) {\n open(null, 'input');\n }\n\n // Close the menu if the collection is empty. Don't close menu if filtered collection size is 0\n // but we are currently showing all items via button press\n if (\n !showAllItems &&\n !allowsEmptyCollection &&\n triggerState.isOpen &&\n filteredCollection.size === 0\n ) {\n triggerState.close();\n }\n\n // Close when an item is selected.\n if (\n selectedKey != null &&\n selectedKey !== lastSelectedKey.current\n ) {\n triggerState.close();\n }\n\n // Clear focused key when input value changes and display filtered collection again.\n if (inputValue !== lastValue.current) {\n selectionManager.setFocusedKey(null);\n setShowAllItems(false);\n\n // Set selectedKey to null when the user clears the input.\n // If controlled, this is the application developer's responsibility.\n if (inputValue === '' && (props.inputValue === undefined || props.selectedKey === undefined)) {\n setSelectedKey(null);\n }\n }\n\n // If it is the intial render and inputValue isn't controlled nor has an intial value, set input to match current selected key if any\n if (isInitialRender.current && (props.inputValue === undefined && props.defaultInputValue === undefined)) {\n resetInputValue();\n }\n\n // If the selectedKey changed, update the input value.\n // Do nothing if both inputValue and selectedKey are controlled.\n // In this case, it's the user's responsibility to update inputValue in onSelectionChange.\n if (\n selectedKey !== lastSelectedKey.current &&\n (props.inputValue === undefined || props.selectedKey === undefined)\n ) {\n resetInputValue();\n } else {\n lastValue.current = inputValue;\n }\n\n // Update the inputValue if the selected item's text changes from its last tracked value.\n // This is to handle cases where a selectedKey is specified but the items aren't available (async loading) or the selected item's text value updates.\n // Only reset if the user isn't currently within the field so we don't erroneously modify user input.\n // If inputValue is controlled, it is the user's responsibility to update the inputValue when items change.\n let selectedItemText = collection.getItem(selectedKey)?.textValue ?? '';\n if (!isFocused && selectedKey != null && props.inputValue === undefined && selectedKey === lastSelectedKey.current) {\n if (lastSelectedKeyText.current !== selectedItemText) {\n lastValue.current = selectedItemText;\n setInputValue(selectedItemText);\n }\n }\n\n isInitialRender.current = false;\n lastSelectedKey.current = selectedKey;\n lastSelectedKeyText.current = selectedItemText;\n });\n\n useEffect(() => {\n // Reset focused key when the menu closes\n if (!triggerState.isOpen) {\n selectionManager.setFocusedKey(null);\n }\n }, [triggerState.isOpen, selectionManager]);\n\n // Revert input value and close menu\n let revert = () => {\n if (allowsCustomValue && selectedKey == null) {\n commitCustomValue();\n } else {\n commitSelection();\n }\n };\n\n let commitCustomValue = () => {\n lastSelectedKey.current = null;\n setSelectedKey(null);\n triggerState.close();\n };\n\n let commitSelection = () => {\n // If multiple things are controlled, call onSelectionChange\n if (props.selectedKey !== undefined && props.inputValue !== undefined) {\n props.onSelectionChange(selectedKey);\n\n // Stop menu from reopening from useEffect\n let itemText = collection.getItem(selectedKey)?.textValue ?? '';\n lastValue.current = itemText;\n triggerState.close();\n } else {\n // If only a single aspect of combobox is controlled, reset input value and close menu for the user\n resetInputValue();\n triggerState.close();\n }\n };\n\n let commit = () => {\n if (triggerState.isOpen && selectionManager.focusedKey != null) {\n // Reset inputValue and close menu here if the selected key is already the focused key. Otherwise\n // fire onSelectionChange to allow the application to control the closing.\n if (selectedKey === selectionManager.focusedKey) {\n commitSelection();\n } else {\n setSelectedKey(selectionManager.focusedKey);\n }\n } else if (allowsCustomValue) {\n commitCustomValue();\n } else {\n // Reset inputValue and close menu if no item is focused but user triggers a commit\n commitSelection();\n }\n };\n\n let setFocused = (isFocused: boolean) => {\n if (isFocused) {\n if (menuTrigger === 'focus') {\n open(null, 'focus');\n }\n } else if (shouldCloseOnBlur) {\n let itemText = collection.getItem(selectedKey)?.textValue ?? '';\n if (allowsCustomValue && inputValue !== itemText) {\n commitCustomValue();\n } else {\n commitSelection();\n }\n }\n\n setFocusedState(isFocused);\n };\n\n return {\n ...triggerState,\n toggle,\n open,\n selectionManager,\n selectedKey,\n setSelectedKey,\n disabledKeys,\n isFocused,\n setFocused,\n selectedItem,\n collection: showAllItems ? originalCollection : filteredCollection,\n inputValue,\n setInputValue,\n commit,\n revert\n };\n}\n\nfunction filterCollection<T extends object>(collection: Collection<Node<T>>, inputValue: string, filter: FilterFn): Collection<Node<T>> {\n return new ListCollection(filterNodes(collection, inputValue, filter));\n}\n\nfunction filterNodes<T>(nodes: Iterable<Node<T>>, inputValue: string, filter: FilterFn): Iterable<Node<T>> {\n let filteredNode = [];\n for (let node of nodes) {\n if (node.type === 'section' && node.hasChildNodes) {\n let filtered = filterNodes(node.childNodes, inputValue, filter);\n if ([...filtered].length > 0) {\n filteredNode.push({...node, childNodes: filtered});\n }\n } else if (node.type !== 'section' && filter(node.textValue, inputValue)) {\n filteredNode.push({...node});\n }\n }\n return filteredNode;\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import {useSingleSelectListState as $
|
|
2
|
-
import {useControlledState as $
|
|
3
|
-
import {useState as $
|
|
4
|
-
import {useMenuTriggerState as $
|
|
1
|
+
import {useSingleSelectListState as $k6Ppu$useSingleSelectListState, ListCollection as $k6Ppu$ListCollection} from "@react-stately/list";
|
|
2
|
+
import {useControlledState as $k6Ppu$useControlledState} from "@react-stately/utils";
|
|
3
|
+
import {useState as $k6Ppu$useState, useMemo as $k6Ppu$useMemo, useRef as $k6Ppu$useRef, useEffect as $k6Ppu$useEffect} from "react";
|
|
4
|
+
import {useMenuTriggerState as $k6Ppu$useMenuTriggerState} from "@react-stately/menu";
|
|
5
5
|
|
|
6
6
|
function $parcel$export(e, n, v, s) {
|
|
7
7
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
8
8
|
}
|
|
9
|
-
var $
|
|
9
|
+
var $a9e7382a7d111cb5$exports = {};
|
|
10
10
|
|
|
11
|
-
$parcel$export($
|
|
11
|
+
$parcel$export($a9e7382a7d111cb5$exports, "useComboBoxState", () => $a9e7382a7d111cb5$export$b453a3bfd4a5fa9e);
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
function $
|
|
16
|
+
function $a9e7382a7d111cb5$export$b453a3bfd4a5fa9e(props) {
|
|
17
|
+
var ref4;
|
|
17
18
|
let { defaultFilter: defaultFilter , menuTrigger: menuTrigger = 'input' , allowsEmptyCollection: allowsEmptyCollection = false , allowsCustomValue: allowsCustomValue , shouldCloseOnBlur: shouldCloseOnBlur = true } = props;
|
|
18
|
-
let [showAllItems, setShowAllItems] = $
|
|
19
|
-
let [isFocused1, setFocusedState] = $
|
|
20
|
-
|
|
19
|
+
let [showAllItems, setShowAllItems] = $k6Ppu$useState(false);
|
|
20
|
+
let [isFocused1, setFocusedState] = $k6Ppu$useState(false);
|
|
21
|
+
var _defaultInputValue;
|
|
22
|
+
let [inputValue, setInputValue] = $k6Ppu$useControlledState(props.inputValue, (_defaultInputValue = props.defaultInputValue) !== null && _defaultInputValue !== void 0 ? _defaultInputValue : '', props.onInputChange);
|
|
21
23
|
let onSelectionChange = (key)=>{
|
|
22
24
|
if (props.onSelectionChange) props.onSelectionChange(key);
|
|
23
25
|
// If key is the same, reset the inputValue and close the menu
|
|
@@ -27,15 +29,16 @@ function $6673426cab58817c$export$b453a3bfd4a5fa9e(props) {
|
|
|
27
29
|
triggerState.close();
|
|
28
30
|
}
|
|
29
31
|
};
|
|
30
|
-
|
|
32
|
+
var _items;
|
|
33
|
+
let { collection: collection , selectionManager: selectionManager , selectedKey: selectedKey , setSelectedKey: setSelectedKey , selectedItem: selectedItem , disabledKeys: disabledKeys } = $k6Ppu$useSingleSelectListState({
|
|
31
34
|
...props,
|
|
32
35
|
onSelectionChange: onSelectionChange,
|
|
33
|
-
items: props.items
|
|
36
|
+
items: (_items = props.items) !== null && _items !== void 0 ? _items : props.defaultItems
|
|
34
37
|
});
|
|
35
38
|
// Preserve original collection so we can show all items on demand
|
|
36
39
|
let originalCollection = collection;
|
|
37
|
-
let filteredCollection = $
|
|
38
|
-
props.items != null || !defaultFilter ? collection : $
|
|
40
|
+
let filteredCollection = $k6Ppu$useMemo(()=>// No default filter if items are controlled.
|
|
41
|
+
props.items != null || !defaultFilter ? collection : $a9e7382a7d111cb5$var$filterCollection(collection, inputValue, defaultFilter)
|
|
39
42
|
, [
|
|
40
43
|
collection,
|
|
41
44
|
inputValue,
|
|
@@ -43,11 +46,11 @@ function $6673426cab58817c$export$b453a3bfd4a5fa9e(props) {
|
|
|
43
46
|
props.items
|
|
44
47
|
]);
|
|
45
48
|
// Track what action is attempting to open the menu
|
|
46
|
-
let menuOpenTrigger = $
|
|
49
|
+
let menuOpenTrigger = $k6Ppu$useRef('focus');
|
|
47
50
|
let onOpenChange = (open)=>{
|
|
48
51
|
if (props.onOpenChange) props.onOpenChange(open, open ? menuOpenTrigger.current : undefined);
|
|
49
52
|
};
|
|
50
|
-
let triggerState = $
|
|
53
|
+
let triggerState = $k6Ppu$useMenuTriggerState({
|
|
51
54
|
...props,
|
|
52
55
|
onOpenChange: onOpenChange,
|
|
53
56
|
isOpen: undefined,
|
|
@@ -75,18 +78,23 @@ function $6673426cab58817c$export$b453a3bfd4a5fa9e(props) {
|
|
|
75
78
|
if (!triggerState.isOpen) menuOpenTrigger.current = trigger;
|
|
76
79
|
triggerState.toggle(focusStrategy);
|
|
77
80
|
};
|
|
78
|
-
let lastValue = $
|
|
81
|
+
let lastValue = $k6Ppu$useRef(inputValue);
|
|
79
82
|
let resetInputValue = ()=>{
|
|
80
|
-
|
|
83
|
+
var ref;
|
|
84
|
+
var ref3;
|
|
85
|
+
let itemText = (ref3 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref3 !== void 0 ? ref3 : '';
|
|
81
86
|
lastValue.current = itemText;
|
|
82
87
|
setInputValue(itemText);
|
|
83
88
|
};
|
|
84
|
-
let isInitialRender = $
|
|
85
|
-
|
|
86
|
-
let
|
|
89
|
+
let isInitialRender = $k6Ppu$useRef(true);
|
|
90
|
+
var _selectedKey, ref1;
|
|
91
|
+
let lastSelectedKey = $k6Ppu$useRef((ref1 = (_selectedKey = props.selectedKey) !== null && _selectedKey !== void 0 ? _selectedKey : props.defaultSelectedKey) !== null && ref1 !== void 0 ? ref1 : null);
|
|
92
|
+
var ref2;
|
|
93
|
+
let lastSelectedKeyText = $k6Ppu$useRef((ref2 = (ref4 = collection.getItem(selectedKey)) === null || ref4 === void 0 ? void 0 : ref4.textValue) !== null && ref2 !== void 0 ? ref2 : '');
|
|
87
94
|
// intentional omit dependency array, want this to happen on every render
|
|
88
95
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
89
|
-
$
|
|
96
|
+
$k6Ppu$useEffect(()=>{
|
|
97
|
+
var ref;
|
|
90
98
|
// Open and close menu automatically when the input value changes if the input is focused,
|
|
91
99
|
// and there are items in the collection or allowEmptyCollection is true.
|
|
92
100
|
if (isFocused1 && (filteredCollection.size > 0 || allowsEmptyCollection) && !triggerState.isOpen && inputValue !== lastValue.current && menuTrigger !== 'manual') open1(null, 'input');
|
|
@@ -110,11 +118,12 @@ function $6673426cab58817c$export$b453a3bfd4a5fa9e(props) {
|
|
|
110
118
|
// In this case, it's the user's responsibility to update inputValue in onSelectionChange.
|
|
111
119
|
if (selectedKey !== lastSelectedKey.current && (props.inputValue === undefined || props.selectedKey === undefined)) resetInputValue();
|
|
112
120
|
else lastValue.current = inputValue;
|
|
121
|
+
var ref5;
|
|
113
122
|
// Update the inputValue if the selected item's text changes from its last tracked value.
|
|
114
123
|
// 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.
|
|
115
124
|
// Only reset if the user isn't currently within the field so we don't erroneously modify user input.
|
|
116
125
|
// If inputValue is controlled, it is the user's responsibility to update the inputValue when items change.
|
|
117
|
-
let selectedItemText = collection.getItem(selectedKey)
|
|
126
|
+
let selectedItemText = (ref5 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref5 !== void 0 ? ref5 : '';
|
|
118
127
|
if (!isFocused1 && selectedKey != null && props.inputValue === undefined && selectedKey === lastSelectedKey.current) {
|
|
119
128
|
if (lastSelectedKeyText.current !== selectedItemText) {
|
|
120
129
|
lastValue.current = selectedItemText;
|
|
@@ -125,7 +134,7 @@ function $6673426cab58817c$export$b453a3bfd4a5fa9e(props) {
|
|
|
125
134
|
lastSelectedKey.current = selectedKey;
|
|
126
135
|
lastSelectedKeyText.current = selectedItemText;
|
|
127
136
|
});
|
|
128
|
-
$
|
|
137
|
+
$k6Ppu$useEffect(()=>{
|
|
129
138
|
// Reset focused key when the menu closes
|
|
130
139
|
if (!triggerState.isOpen) selectionManager.setFocusedKey(null);
|
|
131
140
|
}, [
|
|
@@ -145,9 +154,11 @@ function $6673426cab58817c$export$b453a3bfd4a5fa9e(props) {
|
|
|
145
154
|
let commitSelection = ()=>{
|
|
146
155
|
// If multiple things are controlled, call onSelectionChange
|
|
147
156
|
if (props.selectedKey !== undefined && props.inputValue !== undefined) {
|
|
157
|
+
var ref;
|
|
148
158
|
props.onSelectionChange(selectedKey);
|
|
159
|
+
var ref6;
|
|
149
160
|
// Stop menu from reopening from useEffect
|
|
150
|
-
let itemText = collection.getItem(selectedKey)
|
|
161
|
+
let itemText = (ref6 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref6 !== void 0 ? ref6 : '';
|
|
151
162
|
lastValue.current = itemText;
|
|
152
163
|
triggerState.close();
|
|
153
164
|
} else {
|
|
@@ -170,7 +181,9 @@ function $6673426cab58817c$export$b453a3bfd4a5fa9e(props) {
|
|
|
170
181
|
if (isFocused) {
|
|
171
182
|
if (menuTrigger === 'focus') open1(null, 'focus');
|
|
172
183
|
} else if (shouldCloseOnBlur) {
|
|
173
|
-
|
|
184
|
+
var ref;
|
|
185
|
+
var ref7;
|
|
186
|
+
let itemText = (ref7 = (ref = collection.getItem(selectedKey)) === null || ref === void 0 ? void 0 : ref.textValue) !== null && ref7 !== void 0 ? ref7 : '';
|
|
174
187
|
if (allowsCustomValue && inputValue !== itemText) commitCustomValue();
|
|
175
188
|
else commitSelection();
|
|
176
189
|
}
|
|
@@ -194,14 +207,14 @@ function $6673426cab58817c$export$b453a3bfd4a5fa9e(props) {
|
|
|
194
207
|
revert: revert
|
|
195
208
|
};
|
|
196
209
|
}
|
|
197
|
-
function $
|
|
198
|
-
return new $
|
|
210
|
+
function $a9e7382a7d111cb5$var$filterCollection(collection, inputValue, filter) {
|
|
211
|
+
return new $k6Ppu$ListCollection($a9e7382a7d111cb5$var$filterNodes(collection, inputValue, filter));
|
|
199
212
|
}
|
|
200
|
-
function $
|
|
213
|
+
function $a9e7382a7d111cb5$var$filterNodes(nodes, inputValue, filter) {
|
|
201
214
|
let filteredNode = [];
|
|
202
215
|
for (let node of nodes){
|
|
203
216
|
if (node.type === 'section' && node.hasChildNodes) {
|
|
204
|
-
let filtered = $
|
|
217
|
+
let filtered = $a9e7382a7d111cb5$var$filterNodes(node.childNodes, inputValue, filter);
|
|
205
218
|
if ([
|
|
206
219
|
...filtered
|
|
207
220
|
].length > 0) filteredNode.push({
|
|
@@ -218,5 +231,5 @@ function $6673426cab58817c$var$filterNodes(nodes, inputValue, filter) {
|
|
|
218
231
|
|
|
219
232
|
|
|
220
233
|
|
|
221
|
-
export {$
|
|
234
|
+
export {$a9e7382a7d111cb5$export$b453a3bfd4a5fa9e as useComboBoxState};
|
|
222
235
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;SCkDgB,yCAAgB,CAAmB,KAA4B,EAAoB,CAAC;IAClG,GAAG,CAAC,CAAC,gBACH,aAAa,gBACb,WAAW,GAAG,CAAO,gCACrB,qBAAqB,GAAG,KAAK,sBAC7B,iBAAiB,sBACjB,iBAAiB,GAAG,IAAI,EAC1B,CAAC,GAAG,KAAK;IAET,GAAG,EAAE,YAAY,EAAE,eAAe,IAAI,eAAQ,CAAC,KAAK;IACpD,GAAG,EAAE,UAAS,EAAE,eAAe,IAAI,eAAQ,CAAC,KAAK;IACjD,GAAG,EAAE,UAAU,EAAE,aAAa,IAAI,yBAAkB,CAClD,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,iBAAiB,IAAI,CAAE,GAC7B,KAAK,CAAC,aAAa;IAGrB,GAAG,CAAC,iBAAiB,IAAI,GAAG,GAAK,CAAC;QAChC,EAAE,EAAE,KAAK,CAAC,iBAAiB,EACzB,KAAK,CAAC,iBAAiB,CAAC,GAAG;QAG7B,EAA8D,AAA9D,4DAA8D;QAC9D,EAAqD,AAArD,mDAAqD;QACrD,EAAE,EAAE,GAAG,KAAK,WAAW,EAAE,CAAC;YACxB,eAAe;YACf,YAAY,CAA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E,EAAE,CAAC;mBAAG,QAAQ;YAAA,CAAC,CAAC,MAAM,GAAG,CAAC,EAC1B,YAAY,CAAC,IAAI,CAAC,CAAC;mBAAG,IAAI;gBAAE,UAAU,EAAE,QAAQ;YAAA,CAAC;QAErD,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,IAAI,KAAK,CAAS,YAAI,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,GACrE,YAAY,CAAC,IAAI,CAAC,CAAC;eAAG,IAAI;QAAA,CAAC;IAE/B,CAAC;IACD,MAAM,CAAC,YAAY;AACrB,CAAC","sources":["packages/@react-stately/combobox/src/index.ts","packages/@react-stately/combobox/src/useComboBoxState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './useComboBoxState';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, FocusStrategy, Node} from '@react-types/shared';\nimport {ComboBoxProps, MenuTriggerAction} from '@react-types/combobox';\nimport {ListCollection, useSingleSelectListState} from '@react-stately/list';\nimport {SelectState} from '@react-stately/select';\nimport {useControlledState} from '@react-stately/utils';\nimport {useEffect, useMemo, useRef, useState} from 'react';\nimport {useMenuTriggerState} from '@react-stately/menu';\n\nexport interface ComboBoxState<T> extends SelectState<T> {\n /** The current value of the combo box input. */\n inputValue: string,\n /** Sets the value of the combo box input. */\n setInputValue(value: string): void,\n /** Selects the currently focused item and updates the input value. */\n commit(): void,\n /** Opens the menu. */\n open(focusStrategy?: FocusStrategy | null, trigger?: MenuTriggerAction): void,\n /** Toggles the menu. */\n toggle(focusStrategy?: FocusStrategy | null, trigger?: MenuTriggerAction): void,\n /** Resets the input value to the previously selected item's text if any and closes the menu. */\n revert(): void\n}\n\ntype FilterFn = (textValue: string, inputValue: string) => boolean;\ninterface ComboBoxStateProps<T> extends ComboBoxProps<T> {\n /** The filter function used to determine if a option should be included in the combo box list. */\n defaultFilter?: FilterFn,\n /** Whether the combo box allows the menu to be open when the collection is empty. */\n allowsEmptyCollection?: boolean,\n /** Whether the combo box menu should close on blur. */\n shouldCloseOnBlur?: boolean\n}\n\n/**\n * Provides state management for a combo box component. Handles building a collection\n * of items from props and manages the option selection state of the combo box. In addition, it tracks the input value,\n * focus state, and other properties of the combo box.\n */\nexport function useComboBoxState<T extends object>(props: ComboBoxStateProps<T>): ComboBoxState<T> {\n let {\n defaultFilter,\n menuTrigger = 'input',\n allowsEmptyCollection = false,\n allowsCustomValue,\n shouldCloseOnBlur = true\n } = props;\n\n let [showAllItems, setShowAllItems] = useState(false);\n let [isFocused, setFocusedState] = useState(false);\n let [inputValue, setInputValue] = useControlledState(\n props.inputValue,\n props.defaultInputValue ?? '',\n props.onInputChange\n );\n\n let onSelectionChange = (key) => {\n if (props.onSelectionChange) {\n props.onSelectionChange(key);\n }\n\n // If key is the same, reset the inputValue and close the menu\n // (scenario: user clicks on already selected option)\n if (key === selectedKey) {\n resetInputValue();\n triggerState.close();\n }\n };\n\n let {collection, selectionManager, selectedKey, setSelectedKey, selectedItem, disabledKeys} = useSingleSelectListState({\n ...props,\n onSelectionChange,\n items: props.items ?? props.defaultItems\n });\n\n // Preserve original collection so we can show all items on demand\n let originalCollection = collection;\n let filteredCollection = useMemo(() => (\n // No default filter if items are controlled.\n props.items != null || !defaultFilter\n ? collection\n : filterCollection(collection, inputValue, defaultFilter)\n ), [collection, inputValue, defaultFilter, props.items]);\n\n // Track what action is attempting to open the menu\n let menuOpenTrigger = useRef('focus' as MenuTriggerAction);\n let onOpenChange = (open: boolean) => {\n if (props.onOpenChange) {\n props.onOpenChange(open, open ? menuOpenTrigger.current : undefined);\n }\n };\n\n let triggerState = useMenuTriggerState({...props, onOpenChange, isOpen: undefined, defaultOpen: undefined});\n let open = (focusStrategy?: FocusStrategy, trigger?: MenuTriggerAction) => {\n let displayAllItems = (trigger === 'manual' || (trigger === 'focus' && menuTrigger === 'focus'));\n // Prevent open operations from triggering if there is nothing to display\n // Also prevent open operations from triggering if items are uncontrolled but defaultItems is empty, even if displayAllItems is true.\n // This is to prevent comboboxes with empty defaultItems from opening but allow controlled items comboboxes to open even if the inital list is empty (assumption is user will provide swap the empty list with a base list via onOpenChange returning `menuTrigger` manual)\n if (allowsEmptyCollection || filteredCollection.size > 0 || (displayAllItems && originalCollection.size > 0) || props.items) {\n if (displayAllItems && !triggerState.isOpen && props.items === undefined) {\n // Show all items if menu is manually opened. Only care about this if items are undefined\n setShowAllItems(true);\n }\n\n menuOpenTrigger.current = trigger;\n triggerState.open(focusStrategy);\n }\n };\n\n let toggle = (focusStrategy?: FocusStrategy, trigger?: MenuTriggerAction) => {\n let displayAllItems = (trigger === 'manual' || (trigger === 'focus' && menuTrigger === 'focus'));\n // If the menu is closed and there is nothing to display, early return so toggle isn't called to prevent extraneous onOpenChange\n if (!(allowsEmptyCollection || filteredCollection.size > 0 || (displayAllItems && originalCollection.size > 0) || props.items) && !triggerState.isOpen) {\n return;\n }\n\n if (displayAllItems && !triggerState.isOpen && props.items === undefined) {\n // Show all items if menu is toggled open. Only care about this if items are undefined\n setShowAllItems(true);\n }\n\n // Only update the menuOpenTrigger if menu is currently closed\n if (!triggerState.isOpen) {\n menuOpenTrigger.current = trigger;\n }\n\n triggerState.toggle(focusStrategy);\n };\n\n let lastValue = useRef(inputValue);\n let resetInputValue = () => {\n let itemText = collection.getItem(selectedKey)?.textValue ?? '';\n lastValue.current = itemText;\n setInputValue(itemText);\n };\n\n let isInitialRender = useRef(true);\n let lastSelectedKey = useRef(props.selectedKey ?? props.defaultSelectedKey ?? null);\n let lastSelectedKeyText = useRef(collection.getItem(selectedKey)?.textValue ?? '');\n // intentional omit dependency array, want this to happen on every render\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(() => {\n // Open and close menu automatically when the input value changes if the input is focused,\n // and there are items in the collection or allowEmptyCollection is true.\n if (\n isFocused &&\n (filteredCollection.size > 0 || allowsEmptyCollection) &&\n !triggerState.isOpen &&\n inputValue !== lastValue.current &&\n menuTrigger !== 'manual'\n ) {\n open(null, 'input');\n }\n\n // Close the menu if the collection is empty. Don't close menu if filtered collection size is 0\n // but we are currently showing all items via button press\n if (\n !showAllItems &&\n !allowsEmptyCollection &&\n triggerState.isOpen &&\n filteredCollection.size === 0\n ) {\n triggerState.close();\n }\n\n // Close when an item is selected.\n if (\n selectedKey != null &&\n selectedKey !== lastSelectedKey.current\n ) {\n triggerState.close();\n }\n\n // Clear focused key when input value changes and display filtered collection again.\n if (inputValue !== lastValue.current) {\n selectionManager.setFocusedKey(null);\n setShowAllItems(false);\n\n // Set selectedKey to null when the user clears the input.\n // If controlled, this is the application developer's responsibility.\n if (inputValue === '' && (props.inputValue === undefined || props.selectedKey === undefined)) {\n setSelectedKey(null);\n }\n }\n\n // If it is the intial render and inputValue isn't controlled nor has an intial value, set input to match current selected key if any\n if (isInitialRender.current && (props.inputValue === undefined && props.defaultInputValue === undefined)) {\n resetInputValue();\n }\n\n // If the selectedKey changed, update the input value.\n // Do nothing if both inputValue and selectedKey are controlled.\n // In this case, it's the user's responsibility to update inputValue in onSelectionChange.\n if (\n selectedKey !== lastSelectedKey.current &&\n (props.inputValue === undefined || props.selectedKey === undefined)\n ) {\n resetInputValue();\n } else {\n lastValue.current = inputValue;\n }\n\n // Update the inputValue if the selected item's text changes from its last tracked value.\n // This is to handle cases where a selectedKey is specified but the items aren't available (async loading) or the selected item's text value updates.\n // Only reset if the user isn't currently within the field so we don't erroneously modify user input.\n // If inputValue is controlled, it is the user's responsibility to update the inputValue when items change.\n let selectedItemText = collection.getItem(selectedKey)?.textValue ?? '';\n if (!isFocused && selectedKey != null && props.inputValue === undefined && selectedKey === lastSelectedKey.current) {\n if (lastSelectedKeyText.current !== selectedItemText) {\n lastValue.current = selectedItemText;\n setInputValue(selectedItemText);\n }\n }\n\n isInitialRender.current = false;\n lastSelectedKey.current = selectedKey;\n lastSelectedKeyText.current = selectedItemText;\n });\n\n useEffect(() => {\n // Reset focused key when the menu closes\n if (!triggerState.isOpen) {\n selectionManager.setFocusedKey(null);\n }\n }, [triggerState.isOpen, selectionManager]);\n\n // Revert input value and close menu\n let revert = () => {\n if (allowsCustomValue && selectedKey == null) {\n commitCustomValue();\n } else {\n commitSelection();\n }\n };\n\n let commitCustomValue = () => {\n lastSelectedKey.current = null;\n setSelectedKey(null);\n triggerState.close();\n };\n\n let commitSelection = () => {\n // If multiple things are controlled, call onSelectionChange\n if (props.selectedKey !== undefined && props.inputValue !== undefined) {\n props.onSelectionChange(selectedKey);\n\n // Stop menu from reopening from useEffect\n let itemText = collection.getItem(selectedKey)?.textValue ?? '';\n lastValue.current = itemText;\n triggerState.close();\n } else {\n // If only a single aspect of combobox is controlled, reset input value and close menu for the user\n resetInputValue();\n triggerState.close();\n }\n };\n\n let commit = () => {\n if (triggerState.isOpen && selectionManager.focusedKey != null) {\n // Reset inputValue and close menu here if the selected key is already the focused key. Otherwise\n // fire onSelectionChange to allow the application to control the closing.\n if (selectedKey === selectionManager.focusedKey) {\n commitSelection();\n } else {\n setSelectedKey(selectionManager.focusedKey);\n }\n } else if (allowsCustomValue) {\n commitCustomValue();\n } else {\n // Reset inputValue and close menu if no item is focused but user triggers a commit\n commitSelection();\n }\n };\n\n let setFocused = (isFocused: boolean) => {\n if (isFocused) {\n if (menuTrigger === 'focus') {\n open(null, 'focus');\n }\n } else if (shouldCloseOnBlur) {\n let itemText = collection.getItem(selectedKey)?.textValue ?? '';\n if (allowsCustomValue && inputValue !== itemText) {\n commitCustomValue();\n } else {\n commitSelection();\n }\n }\n\n setFocusedState(isFocused);\n };\n\n return {\n ...triggerState,\n toggle,\n open,\n selectionManager,\n selectedKey,\n setSelectedKey,\n disabledKeys,\n isFocused,\n setFocused,\n selectedItem,\n collection: showAllItems ? originalCollection : filteredCollection,\n inputValue,\n setInputValue,\n commit,\n revert\n };\n}\n\nfunction filterCollection<T extends object>(collection: Collection<Node<T>>, inputValue: string, filter: FilterFn): Collection<Node<T>> {\n return new ListCollection(filterNodes(collection, inputValue, filter));\n}\n\nfunction filterNodes<T>(nodes: Iterable<Node<T>>, inputValue: string, filter: FilterFn): Iterable<Node<T>> {\n let filteredNode = [];\n for (let node of nodes) {\n if (node.type === 'section' && node.hasChildNodes) {\n let filtered = filterNodes(node.childNodes, inputValue, filter);\n if ([...filtered].length > 0) {\n filteredNode.push({...node, childNodes: filtered});\n }\n } else if (node.type !== 'section' && filter(node.textValue, inputValue)) {\n filteredNode.push({...node});\n }\n }\n return filteredNode;\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;SCkDgB,yCAAgB,CAAmB,KAA4B,EAAoB,CAAC;QAmGjE,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,aAA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CAAE,CAAC;QACvB,EAAE,EAAE,IAAI,CAAC,IAAI,KAAK,CAAS,YAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YAClD,GAAG,CAAC,QAAQ,GAAG,iCAAW,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,EAAE,MAAM;YAC9D,EAAE,EAAE,CAAC;mBAAG,QAAQ;YAAA,CAAC,CAAC,MAAM,GAAG,CAAC,EAC1B,YAAY,CAAC,IAAI,CAAC,CAAC;mBAAG,IAAI;gBAAE,UAAU,EAAE,QAAQ;YAAA,CAAC;QAErD,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,IAAI,KAAK,CAAS,YAAI,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,GACrE,YAAY,CAAC,IAAI,CAAC,CAAC;eAAG,IAAI;QAAA,CAAC;IAE/B,CAAC;IACD,MAAM,CAAC,YAAY;AACrB,CAAC","sources":["packages/@react-stately/combobox/src/index.ts","packages/@react-stately/combobox/src/useComboBoxState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './useComboBoxState';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, FocusStrategy, Node} from '@react-types/shared';\nimport {ComboBoxProps, MenuTriggerAction} from '@react-types/combobox';\nimport {ListCollection, useSingleSelectListState} from '@react-stately/list';\nimport {SelectState} from '@react-stately/select';\nimport {useControlledState} from '@react-stately/utils';\nimport {useEffect, useMemo, useRef, useState} from 'react';\nimport {useMenuTriggerState} from '@react-stately/menu';\n\nexport interface ComboBoxState<T> extends SelectState<T> {\n /** The current value of the combo box input. */\n inputValue: string,\n /** Sets the value of the combo box input. */\n setInputValue(value: string): void,\n /** Selects the currently focused item and updates the input value. */\n commit(): void,\n /** Opens the menu. */\n open(focusStrategy?: FocusStrategy | null, trigger?: MenuTriggerAction): void,\n /** Toggles the menu. */\n toggle(focusStrategy?: FocusStrategy | null, trigger?: MenuTriggerAction): void,\n /** Resets the input value to the previously selected item's text if any and closes the menu. */\n revert(): void\n}\n\ntype FilterFn = (textValue: string, inputValue: string) => boolean;\ninterface ComboBoxStateProps<T> extends ComboBoxProps<T> {\n /** The filter function used to determine if a option should be included in the combo box list. */\n defaultFilter?: FilterFn,\n /** Whether the combo box allows the menu to be open when the collection is empty. */\n allowsEmptyCollection?: boolean,\n /** Whether the combo box menu should close on blur. */\n shouldCloseOnBlur?: boolean\n}\n\n/**\n * Provides state management for a combo box component. Handles building a collection\n * of items from props and manages the option selection state of the combo box. In addition, it tracks the input value,\n * focus state, and other properties of the combo box.\n */\nexport function useComboBoxState<T extends object>(props: ComboBoxStateProps<T>): ComboBoxState<T> {\n let {\n defaultFilter,\n menuTrigger = 'input',\n allowsEmptyCollection = false,\n allowsCustomValue,\n shouldCloseOnBlur = true\n } = props;\n\n let [showAllItems, setShowAllItems] = useState(false);\n let [isFocused, setFocusedState] = useState(false);\n let [inputValue, setInputValue] = useControlledState(\n props.inputValue,\n props.defaultInputValue ?? '',\n props.onInputChange\n );\n\n let onSelectionChange = (key) => {\n if (props.onSelectionChange) {\n props.onSelectionChange(key);\n }\n\n // If key is the same, reset the inputValue and close the menu\n // (scenario: user clicks on already selected option)\n if (key === selectedKey) {\n resetInputValue();\n triggerState.close();\n }\n };\n\n let {collection, selectionManager, selectedKey, setSelectedKey, selectedItem, disabledKeys} = useSingleSelectListState({\n ...props,\n onSelectionChange,\n items: props.items ?? props.defaultItems\n });\n\n // Preserve original collection so we can show all items on demand\n let originalCollection = collection;\n let filteredCollection = useMemo(() => (\n // No default filter if items are controlled.\n props.items != null || !defaultFilter\n ? collection\n : filterCollection(collection, inputValue, defaultFilter)\n ), [collection, inputValue, defaultFilter, props.items]);\n\n // Track what action is attempting to open the menu\n let menuOpenTrigger = useRef('focus' as MenuTriggerAction);\n let onOpenChange = (open: boolean) => {\n if (props.onOpenChange) {\n props.onOpenChange(open, open ? menuOpenTrigger.current : undefined);\n }\n };\n\n let triggerState = useMenuTriggerState({...props, onOpenChange, isOpen: undefined, defaultOpen: undefined});\n let open = (focusStrategy?: FocusStrategy, trigger?: MenuTriggerAction) => {\n let displayAllItems = (trigger === 'manual' || (trigger === 'focus' && menuTrigger === 'focus'));\n // Prevent open operations from triggering if there is nothing to display\n // Also prevent open operations from triggering if items are uncontrolled but defaultItems is empty, even if displayAllItems is true.\n // This is to prevent comboboxes with empty defaultItems from opening but allow controlled items comboboxes to open even if the inital list is empty (assumption is user will provide swap the empty list with a base list via onOpenChange returning `menuTrigger` manual)\n if (allowsEmptyCollection || filteredCollection.size > 0 || (displayAllItems && originalCollection.size > 0) || props.items) {\n if (displayAllItems && !triggerState.isOpen && props.items === undefined) {\n // Show all items if menu is manually opened. Only care about this if items are undefined\n setShowAllItems(true);\n }\n\n menuOpenTrigger.current = trigger;\n triggerState.open(focusStrategy);\n }\n };\n\n let toggle = (focusStrategy?: FocusStrategy, trigger?: MenuTriggerAction) => {\n let displayAllItems = (trigger === 'manual' || (trigger === 'focus' && menuTrigger === 'focus'));\n // If the menu is closed and there is nothing to display, early return so toggle isn't called to prevent extraneous onOpenChange\n if (!(allowsEmptyCollection || filteredCollection.size > 0 || (displayAllItems && originalCollection.size > 0) || props.items) && !triggerState.isOpen) {\n return;\n }\n\n if (displayAllItems && !triggerState.isOpen && props.items === undefined) {\n // Show all items if menu is toggled open. Only care about this if items are undefined\n setShowAllItems(true);\n }\n\n // Only update the menuOpenTrigger if menu is currently closed\n if (!triggerState.isOpen) {\n menuOpenTrigger.current = trigger;\n }\n\n triggerState.toggle(focusStrategy);\n };\n\n let lastValue = useRef(inputValue);\n let resetInputValue = () => {\n let itemText = collection.getItem(selectedKey)?.textValue ?? '';\n lastValue.current = itemText;\n setInputValue(itemText);\n };\n\n let isInitialRender = useRef(true);\n let lastSelectedKey = useRef(props.selectedKey ?? props.defaultSelectedKey ?? null);\n let lastSelectedKeyText = useRef(collection.getItem(selectedKey)?.textValue ?? '');\n // intentional omit dependency array, want this to happen on every render\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(() => {\n // Open and close menu automatically when the input value changes if the input is focused,\n // and there are items in the collection or allowEmptyCollection is true.\n if (\n isFocused &&\n (filteredCollection.size > 0 || allowsEmptyCollection) &&\n !triggerState.isOpen &&\n inputValue !== lastValue.current &&\n menuTrigger !== 'manual'\n ) {\n open(null, 'input');\n }\n\n // Close the menu if the collection is empty. Don't close menu if filtered collection size is 0\n // but we are currently showing all items via button press\n if (\n !showAllItems &&\n !allowsEmptyCollection &&\n triggerState.isOpen &&\n filteredCollection.size === 0\n ) {\n triggerState.close();\n }\n\n // Close when an item is selected.\n if (\n selectedKey != null &&\n selectedKey !== lastSelectedKey.current\n ) {\n triggerState.close();\n }\n\n // Clear focused key when input value changes and display filtered collection again.\n if (inputValue !== lastValue.current) {\n selectionManager.setFocusedKey(null);\n setShowAllItems(false);\n\n // Set selectedKey to null when the user clears the input.\n // If controlled, this is the application developer's responsibility.\n if (inputValue === '' && (props.inputValue === undefined || props.selectedKey === undefined)) {\n setSelectedKey(null);\n }\n }\n\n // If it is the intial render and inputValue isn't controlled nor has an intial value, set input to match current selected key if any\n if (isInitialRender.current && (props.inputValue === undefined && props.defaultInputValue === undefined)) {\n resetInputValue();\n }\n\n // If the selectedKey changed, update the input value.\n // Do nothing if both inputValue and selectedKey are controlled.\n // In this case, it's the user's responsibility to update inputValue in onSelectionChange.\n if (\n selectedKey !== lastSelectedKey.current &&\n (props.inputValue === undefined || props.selectedKey === undefined)\n ) {\n resetInputValue();\n } else {\n lastValue.current = inputValue;\n }\n\n // Update the inputValue if the selected item's text changes from its last tracked value.\n // This is to handle cases where a selectedKey is specified but the items aren't available (async loading) or the selected item's text value updates.\n // Only reset if the user isn't currently within the field so we don't erroneously modify user input.\n // If inputValue is controlled, it is the user's responsibility to update the inputValue when items change.\n let selectedItemText = collection.getItem(selectedKey)?.textValue ?? '';\n if (!isFocused && selectedKey != null && props.inputValue === undefined && selectedKey === lastSelectedKey.current) {\n if (lastSelectedKeyText.current !== selectedItemText) {\n lastValue.current = selectedItemText;\n setInputValue(selectedItemText);\n }\n }\n\n isInitialRender.current = false;\n lastSelectedKey.current = selectedKey;\n lastSelectedKeyText.current = selectedItemText;\n });\n\n useEffect(() => {\n // Reset focused key when the menu closes\n if (!triggerState.isOpen) {\n selectionManager.setFocusedKey(null);\n }\n }, [triggerState.isOpen, selectionManager]);\n\n // Revert input value and close menu\n let revert = () => {\n if (allowsCustomValue && selectedKey == null) {\n commitCustomValue();\n } else {\n commitSelection();\n }\n };\n\n let commitCustomValue = () => {\n lastSelectedKey.current = null;\n setSelectedKey(null);\n triggerState.close();\n };\n\n let commitSelection = () => {\n // If multiple things are controlled, call onSelectionChange\n if (props.selectedKey !== undefined && props.inputValue !== undefined) {\n props.onSelectionChange(selectedKey);\n\n // Stop menu from reopening from useEffect\n let itemText = collection.getItem(selectedKey)?.textValue ?? '';\n lastValue.current = itemText;\n triggerState.close();\n } else {\n // If only a single aspect of combobox is controlled, reset input value and close menu for the user\n resetInputValue();\n triggerState.close();\n }\n };\n\n let commit = () => {\n if (triggerState.isOpen && selectionManager.focusedKey != null) {\n // Reset inputValue and close menu here if the selected key is already the focused key. Otherwise\n // fire onSelectionChange to allow the application to control the closing.\n if (selectedKey === selectionManager.focusedKey) {\n commitSelection();\n } else {\n setSelectedKey(selectionManager.focusedKey);\n }\n } else if (allowsCustomValue) {\n commitCustomValue();\n } else {\n // Reset inputValue and close menu if no item is focused but user triggers a commit\n commitSelection();\n }\n };\n\n let setFocused = (isFocused: boolean) => {\n if (isFocused) {\n if (menuTrigger === 'focus') {\n open(null, 'focus');\n }\n } else if (shouldCloseOnBlur) {\n let itemText = collection.getItem(selectedKey)?.textValue ?? '';\n if (allowsCustomValue && inputValue !== itemText) {\n commitCustomValue();\n } else {\n commitSelection();\n }\n }\n\n setFocusedState(isFocused);\n };\n\n return {\n ...triggerState,\n toggle,\n open,\n selectionManager,\n selectedKey,\n setSelectedKey,\n disabledKeys,\n isFocused,\n setFocused,\n selectedItem,\n collection: showAllItems ? originalCollection : filteredCollection,\n inputValue,\n setInputValue,\n commit,\n revert\n };\n}\n\nfunction filterCollection<T extends object>(collection: Collection<Node<T>>, inputValue: string, filter: FilterFn): Collection<Node<T>> {\n return new ListCollection(filterNodes(collection, inputValue, filter));\n}\n\nfunction filterNodes<T>(nodes: Iterable<Node<T>>, inputValue: string, filter: FilterFn): Iterable<Node<T>> {\n let filteredNode = [];\n for (let node of nodes) {\n if (node.type === 'section' && node.hasChildNodes) {\n let filtered = filterNodes(node.childNodes, inputValue, filter);\n if ([...filtered].length > 0) {\n filteredNode.push({...node, childNodes: filtered});\n }\n } else if (node.type !== 'section' && filter(node.textValue, inputValue)) {\n filteredNode.push({...node});\n }\n }\n return filteredNode;\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/combobox",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4-nightly.3120+1aa66e6e7",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.6.2",
|
|
21
|
-
"@react-stately/list": "
|
|
22
|
-
"@react-stately/menu": "
|
|
23
|
-
"@react-stately/select": "
|
|
24
|
-
"@react-stately/utils": "
|
|
25
|
-
"@react-types/combobox": "
|
|
26
|
-
"@react-types/shared": "
|
|
21
|
+
"@react-stately/list": "3.4.4-nightly.3120+1aa66e6e7",
|
|
22
|
+
"@react-stately/menu": "3.2.6-nightly.3120+1aa66e6e7",
|
|
23
|
+
"@react-stately/select": "3.1.6-nightly.3120+1aa66e6e7",
|
|
24
|
+
"@react-stately/utils": "3.0.0-nightly.1424+1aa66e6e7",
|
|
25
|
+
"@react-types/combobox": "3.2.4-nightly.3120+1aa66e6e7",
|
|
26
|
+
"@react-types/shared": "3.0.0-nightly.1424+1aa66e6e7"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"react": "^16.8.0 || ^17.0.0-rc.1"
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "1aa66e6e75e2da014f44177686c3332cd625fb9f"
|
|
35
35
|
}
|