@react-stately/combobox 3.0.0-beta.0 → 3.0.0-nightly-641446f65-240905

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.
@@ -0,0 +1,17 @@
1
+ import {useComboBoxState as $a9e7382a7d111cb5$export$b453a3bfd4a5fa9e} from "./useComboBoxState.mjs";
2
+
3
+ /*
4
+ * Copyright 2020 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+
16
+ export {$a9e7382a7d111cb5$export$b453a3bfd4a5fa9e as useComboBoxState};
17
+ //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,276 +1,22 @@
1
- var {
2
- useMenuTriggerState
3
- } = require("@react-stately/menu");
1
+ var $e563f9c9469ad14c$exports = require("./useComboBoxState.main.js");
4
2
 
5
- var {
6
- useEffect,
7
- useMemo,
8
- useRef,
9
- useState
10
- } = require("react");
11
3
 
12
- var {
13
- useControlledState
14
- } = require("@react-stately/utils");
15
-
16
- var {
17
- ListCollection,
18
- useSingleSelectListState
19
- } = require("@react-stately/list");
20
-
21
- var _babelRuntimeHelpersExtends = $parcel$interopDefault(require("@babel/runtime/helpers/extends"));
22
-
23
- function $parcel$interopDefault(a) {
24
- return a && a.__esModule ? a.default : a;
25
- }
26
-
27
- /**
28
- * Provides state management for a combo box component. Handles building a collection
29
- * of items from props and manages the option selection state of the combo box. In addition, it tracks the input value,
30
- * focus state, and other properties of the combo box.
31
- */
32
- function useComboBoxState(props) {
33
- var _props$defaultInputVa, _props$items, _ref, _props$selectedKey;
34
-
35
- let {
36
- defaultFilter,
37
- menuTrigger = 'input',
38
- allowsEmptyCollection = false,
39
- allowsCustomValue,
40
- shouldCloseOnBlur = true
41
- } = props;
42
- let [isFocused, setFocusedState] = useState(false);
43
- let [inputValue, setInputValue] = useControlledState(props.inputValue, (_props$defaultInputVa = props.defaultInputValue) != null ? _props$defaultInputVa : '', props.onInputChange);
44
-
45
- let onSelectionChange = key => {
46
- if (props.onSelectionChange) {
47
- props.onSelectionChange(key);
48
- } // If open state or selectedKey is uncontrolled and key is the same, reset the inputValue and close the menu
49
- // (scenario: user clicks on already selected option)
50
-
51
-
52
- if (props.isOpen === undefined || props.selectedKey === undefined) {
53
- if (key === selectedKey) {
54
- resetInputValue();
55
- triggerState.close();
56
- }
57
- }
58
- };
59
-
60
- let {
61
- collection,
62
- selectionManager,
63
- selectedKey,
64
- setSelectedKey,
65
- selectedItem,
66
- disabledKeys
67
- } = useSingleSelectListState(_babelRuntimeHelpersExtends({}, props, {
68
- onSelectionChange,
69
- items: (_props$items = props.items) != null ? _props$items : props.defaultItems
70
- }));
71
- let filteredCollection = useMemo(() => // No default filter if items are controlled.
72
- props.items != null || !defaultFilter ? collection : $a21047c5b4305a7d5e80cc48828d4cd$var$filterCollection(collection, inputValue, defaultFilter), [collection, inputValue, defaultFilter, props.items]);
73
- let triggerState = useMenuTriggerState(props);
74
-
75
- let open = focusStrategy => {
76
- // Prevent open operations from triggering if there is nothing to display
77
- if (allowsEmptyCollection || filteredCollection.size > 0) {
78
- triggerState.open(focusStrategy);
79
- }
80
- };
81
-
82
- let toggle = focusStrategy => {
83
- // If the menu is closed and there is nothing to display, early return so toggle isn't called to prevent extraneous onOpenChange
84
- if (!(allowsEmptyCollection || filteredCollection.size > 0) && !triggerState.isOpen) {
85
- return;
86
- }
87
-
88
- triggerState.toggle(focusStrategy);
89
- };
90
-
91
- let lastValue = useRef(inputValue);
92
-
93
- let resetInputValue = () => {
94
- var _collection$getItem$t, _collection$getItem;
95
-
96
- let itemText = (_collection$getItem$t = (_collection$getItem = collection.getItem(selectedKey)) == null ? void 0 : _collection$getItem.textValue) != null ? _collection$getItem$t : '';
97
- lastValue.current = itemText;
98
- setInputValue(itemText);
99
- };
100
-
101
- let isInitialRender = useRef(true);
102
- let lastSelectedKey = useRef((_ref = (_props$selectedKey = props.selectedKey) != null ? _props$selectedKey : props.defaultSelectedKey) != null ? _ref : null);
103
- useEffect(() => {
104
- // If open state or inputValue is uncontrolled, open and close automatically when the input value changes,
105
- // the input is if focused, and there are items in the collection or allowEmptyCollection is true.
106
- if (isFocused && (filteredCollection.size > 0 || allowsEmptyCollection) && !triggerState.isOpen && inputValue !== lastValue.current && menuTrigger !== 'manual' && (props.isOpen === undefined || props.inputValue === undefined)) {
107
- open();
108
- } // Close the menu if the collection is empty and either open state or items are uncontrolled.
109
-
110
-
111
- if (!allowsEmptyCollection && triggerState.isOpen && filteredCollection.size === 0 && (props.isOpen === undefined || props.items === undefined)) {
112
- triggerState.close();
113
- } // Close when an item is selected, if open state or selectedKey is uncontrolled.
114
-
115
-
116
- if (selectedKey != null && selectedKey !== lastSelectedKey.current && (props.isOpen === undefined || props.selectedKey === undefined)) {
117
- triggerState.close();
118
- } // Clear focused key when input value changes.
119
-
120
-
121
- if (inputValue !== lastValue.current) {
122
- selectionManager.setFocusedKey(null); // Set selectedKey to null when the user clears the input.
123
- // If controlled, this is the application developer's responsibility.
124
-
125
- if (inputValue === '' && (props.inputValue === undefined || props.selectedKey === undefined)) {
126
- setSelectedKey(null);
127
- }
128
- } // 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
129
-
130
-
131
- if (isInitialRender.current && props.inputValue === undefined && props.defaultInputValue === undefined) {
132
- resetInputValue();
133
- } // If the selectedKey changed, update the input value.
134
- // Do nothing if both inputValue and selectedKey are controlled.
135
- // In this case, it's the user's responsibility to update inputValue in onSelectionChange. In addition, we preserve the defaultInputValue
136
- // on initial render, even if it doesn't match the selected item's text.
137
-
138
-
139
- if (selectedKey !== lastSelectedKey.current && (props.inputValue === undefined || props.selectedKey === undefined)) {
140
- resetInputValue();
141
- } else {
142
- lastValue.current = inputValue;
143
- }
144
-
145
- isInitialRender.current = false;
146
- lastSelectedKey.current = selectedKey;
147
- });
148
- useEffect(() => {
149
- // Reset focused key when the menu closes
150
- if (!triggerState.isOpen) {
151
- selectionManager.setFocusedKey(null);
152
- }
153
- }, [triggerState.isOpen, selectionManager]);
154
-
155
- let commitCustomValue = () => {
156
- let shouldClose = false;
157
- lastSelectedKey.current = null;
158
- setSelectedKey(null); // If previous key was already null, need to manually call onSelectionChange since it won't be triggered by a setSelectedKey call
159
- // This allows the application to control whether or not to close the menu on custom value commit
160
-
161
- if (selectedKey === null && props.onSelectionChange) {
162
- props.onSelectionChange(null);
163
- } // Should close menu ourselves if component open state or selected key is uncontrolled and therefore won't be closed by a user defined event handler
164
-
165
-
166
- shouldClose = props.isOpen == null || props.selectedKey === undefined; // Close if no other event will be fired. Otherwise, allow the
167
- // application to control this based on that event.
168
-
169
- if (shouldClose) {
170
- triggerState.close();
171
- }
172
- };
173
-
174
- let commitSelection = () => {
175
- // If multiple things are controlled, call onSelectionChange
176
- // Note that users who control open state and input value MUST also have a onSelectionChange handler to properly close the menu and reset input value
177
- if (props.selectedKey !== undefined && props.inputValue !== undefined || props.inputValue !== undefined && props.isOpen !== undefined || props.selectedKey !== undefined && props.isOpen !== undefined) {
178
- props.onSelectionChange(selectedKey); // If multiple things are controlled but inputValue isn't, reset the input value for the user
179
-
180
- if (props.inputValue === undefined) {
181
- resetInputValue();
182
- } // If multiple things are controlled but isOpen isn't, close the menu for the user
183
-
184
-
185
- if (props.isOpen === undefined) {
186
- var _collection$getItem$t2, _collection$getItem2;
187
-
188
- // Stop menu from reopening from useEffect
189
- let itemText = (_collection$getItem$t2 = (_collection$getItem2 = collection.getItem(selectedKey)) == null ? void 0 : _collection$getItem2.textValue) != null ? _collection$getItem$t2 : '';
190
- lastValue.current = itemText;
191
- triggerState.close();
192
- }
193
- } else {
194
- // If only a single aspect of combobox is controlled, reset input value and close menu for the user
195
- resetInputValue();
196
- triggerState.close();
197
- }
198
- };
199
-
200
- let commit = () => {
201
- if (triggerState.isOpen && selectionManager.focusedKey != null) {
202
- // Reset inputValue and close menu here if the selected key is already the focused key. Otherwise
203
- // fire onSelectionChange to allow the application to control the closing.
204
- if (selectedKey === selectionManager.focusedKey) {
205
- commitSelection();
206
- } else {
207
- setSelectedKey(selectionManager.focusedKey);
208
- }
209
- } else if (allowsCustomValue) {
210
- commitCustomValue();
211
- }
212
- };
213
-
214
- let setFocused = isFocused => {
215
- if (isFocused) {
216
- if (menuTrigger === 'focus') {
217
- open();
218
- }
219
- } else if (shouldCloseOnBlur) {
220
- var _collection$getItem$t3, _collection$getItem3;
221
-
222
- let itemText = (_collection$getItem$t3 = (_collection$getItem3 = collection.getItem(selectedKey)) == null ? void 0 : _collection$getItem3.textValue) != null ? _collection$getItem$t3 : '';
223
-
224
- if (allowsCustomValue && inputValue !== itemText) {
225
- commitCustomValue();
226
- } else {
227
- commitSelection();
228
- }
229
- }
230
-
231
- setFocusedState(isFocused);
232
- };
233
-
234
- return _babelRuntimeHelpersExtends({}, triggerState, {
235
- toggle,
236
- open,
237
- selectionManager,
238
- selectedKey,
239
- setSelectedKey,
240
- disabledKeys,
241
- isFocused,
242
- setFocused,
243
- selectedItem,
244
- collection: filteredCollection,
245
- inputValue,
246
- setInputValue,
247
- commit
248
- });
249
- }
250
-
251
- exports.useComboBoxState = useComboBoxState;
252
-
253
- function $a21047c5b4305a7d5e80cc48828d4cd$var$filterCollection(collection, inputValue, filter) {
254
- return new ListCollection($a21047c5b4305a7d5e80cc48828d4cd$var$filterNodes(collection, inputValue, filter));
4
+ function $parcel$export(e, n, v, s) {
5
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
255
6
  }
256
7
 
257
- function $a21047c5b4305a7d5e80cc48828d4cd$var$filterNodes(nodes, inputValue, filter) {
258
- let filteredNode = [];
259
-
260
- for (let node of nodes) {
261
- if (node.type === 'section' && node.hasChildNodes) {
262
- let filtered = $a21047c5b4305a7d5e80cc48828d4cd$var$filterNodes(node.childNodes, inputValue, filter);
8
+ $parcel$export(module.exports, "useComboBoxState", () => $e563f9c9469ad14c$exports.useComboBoxState);
9
+ /*
10
+ * Copyright 2020 Adobe. All rights reserved.
11
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License. You may obtain a copy
13
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software distributed under
16
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
+ * OF ANY KIND, either express or implied. See the License for the specific language
18
+ * governing permissions and limitations under the License.
19
+ */
263
20
 
264
- if ([...filtered].length > 0) {
265
- filteredNode.push(_babelRuntimeHelpersExtends({}, node, {
266
- childNodes: filtered
267
- }));
268
- }
269
- } else if (node.type !== 'section' && filter(node.textValue, inputValue)) {
270
- filteredNode.push(node);
271
- }
272
- }
273
21
 
274
- return filteredNode;
275
- }
276
22
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,sBAAT,CAAgCC,CAAhC,EAAmC;AACjC,SAAOA,CAAC,IAAIA,CAAC,CAACC,UAAP,GAAoBD,CAAC,CAACE,OAAtB,GAAgCF,CAAvC;AACD;;ACqCD;;;;;AAKO,SAASG,gBAAT,CAA4CC,KAA5C,EAA4F;AAAA;;AACjG,MAAI;AACFC,IAAAA,aADE;AAEFC,IAAAA,WAAW,GAAG,OAFZ;AAGFC,IAAAA,qBAAqB,GAAG,KAHtB;AAIFC,IAAAA,iBAJE;AAKFC,IAAAA,iBAAiB,GAAG;AALlB,MAMAL,KANJ;AAQA,MAAI,CAACM,SAAD,EAAYC,eAAZ,IAA+BC,QAAQ,CAAC,KAAD,CAA3C;AACA,MAAI,CA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oxState.ts"],"sourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, FocusStrategy, Node} from '@react-types/shared';\nimport {ComboBoxProps} 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}\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 [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 open state or selectedKey is uncontrolled and key is the same, reset the inputValue and close the menu\n // (scenario: user clicks on already selected option)\n if (props.isOpen === undefined || props.selectedKey === undefined) {\n if (key === selectedKey) {\n resetInputValue();\n triggerState.close();\n }\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 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 let triggerState = useMenuTriggerState(props);\n let open = (focusStrategy?: FocusStrategy) => {\n // Prevent open operations from triggering if there is nothing to display\n if (allowsEmptyCollection || filteredCollection.size > 0) {\n triggerState.open(focusStrategy);\n }\n };\n\n let toggle = (focusStrategy?: FocusStrategy) => {\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) && !triggerState.isOpen) {\n return;\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 useEffect(() => {\n // If open state or inputValue is uncontrolled, open and close automatically when the input value changes,\n // the input is if focused, 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 (props.isOpen === undefined || props.inputValue === undefined)\n ) {\n open();\n }\n\n // Close the menu if the collection is empty and either open state or items are uncontrolled.\n if (\n !allowsEmptyCollection &&\n triggerState.isOpen &&\n filteredCollection.size === 0 &&\n (props.isOpen === undefined || props.items === undefined)\n ) {\n triggerState.close();\n }\n\n // Close when an item is selected, if open state or selectedKey is uncontrolled.\n if (\n selectedKey != null &&\n selectedKey !== lastSelectedKey.current &&\n (props.isOpen === undefined || props.selectedKey === undefined)\n ) {\n triggerState.close();\n }\n\n // Clear focused key when input value changes.\n if (inputValue !== lastValue.current) {\n selectionManager.setFocusedKey(null);\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. In addition, we preserve the defaultInputValue\n // on initial render, even if it doesn't match the selected item's text.\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 isInitialRender.current = false;\n lastSelectedKey.current = selectedKey;\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 let commitCustomValue = () => {\n let shouldClose = false;\n lastSelectedKey.current = null;\n setSelectedKey(null);\n\n // If previous key was already null, need to manually call onSelectionChange since it won't be triggered by a setSelectedKey call\n // This allows the application to control whether or not to close the menu on custom value commit\n if (selectedKey === null && props.onSelectionChange) {\n props.onSelectionChange(null);\n }\n\n // Should close menu ourselves if component open state or selected key is uncontrolled and therefore won't be closed by a user defined event handler\n shouldClose = props.isOpen == null || props.selectedKey === undefined;\n\n // Close if no other event will be fired. Otherwise, allow the\n // application to control this based on that event.\n if (shouldClose) {\n triggerState.close();\n }\n };\n\n let commitSelection = () => {\n // If multiple things are controlled, call onSelectionChange\n // Note that users who control open state and input value MUST also have a onSelectionChange handler to properly close the menu and reset input value\n if (\n (props.selectedKey !== undefined && props.inputValue !== undefined) ||\n (props.inputValue !== undefined && props.isOpen !== undefined) ||\n (props.selectedKey !== undefined && props.isOpen !== undefined)\n ) {\n props.onSelectionChange(selectedKey);\n\n // If multiple things are controlled but inputValue isn't, reset the input value for the user\n if (props.inputValue === undefined) {\n resetInputValue();\n }\n\n // If multiple things are controlled but isOpen isn't, close the menu for the user\n if (props.isOpen === undefined) {\n // Stop menu from reopening from useEffect\n let itemText = collection.getItem(selectedKey)?.textValue ?? '';\n lastValue.current = itemText;\n triggerState.close();\n }\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 }\n };\n\n let setFocused = (isFocused: boolean) => {\n if (isFocused) {\n if (menuTrigger === 'focus') {\n open();\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: filteredCollection,\n inputValue,\n setInputValue,\n commit\n };\n}\n\nfunction filterCollection<T extends object>(collection: Collection<Node<T>>, inputValue: string, filter: FilterFn): Collection<Node<T>> {\n return new ListCollection(filterNodes(collection, inputValue, filter));\n}\n\nfunction filterNodes<T>(nodes: Iterable<Node<T>>, inputValue: string, filter: FilterFn): Iterable<Node<T>> {\n let filteredNode = [];\n for (let node of nodes) {\n if (node.type === 'section' && node.hasChildNodes) {\n let filtered = filterNodes(node.childNodes, inputValue, filter);\n if ([...filtered].length > 0) {\n filteredNode.push({...node, childNodes: filtered});\n }\n } else if (node.type !== 'section' && filter(node.textValue, inputValue)) {\n filteredNode.push(node);\n }\n }\n return filteredNode;\n}\n"],"names":["$parcel$interopDefault","a","__esModule","default","useComboBoxState","props","defaultFilter","menuTrigger","allowsEmptyCollection","allowsCustomValue","shouldCloseOnBlur","isFocused","setFocusedState","useState","inputValue","setInputValue","useControlledState","defaultInputValue","onInputChange","onSelectionChange","key","isOpen","undefined","selectedKey","resetInputValue","triggerState","close","collection","selectionManager","setSelectedKey","selectedItem","disabledKeys","useSingleSelectListState","items","defaultItems","filteredCollection","useMemo","filterCollection","useMenuTriggerState","open","focusStrategy","size","toggle","lastValue","useRef","itemText","getItem","textValue","current","isInitialRender","lastSelectedKey","defaultSelectedKey","useEffect","setFocusedKey","commitCustomValue","shouldClose","commitSelection","commit","focusedKey","setFocused","filter","ListCollection","filterNodes","nodes","filteredNode","node","type","hasChildNodes","filtered","childNodes","length","push"],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/combobox/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useComboBoxState} from './useComboBoxState';\n\nexport type {ComboBoxStateOptions, ComboBoxState} from './useComboBoxState';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,254 +1,17 @@
1
- import { useMenuTriggerState } from "@react-stately/menu";
2
- import { useEffect, useMemo, useRef, useState } from "react";
3
- import { useControlledState } from "@react-stately/utils";
4
- import { ListCollection, useSingleSelectListState } from "@react-stately/list";
5
- import _babelRuntimeHelpersEsmExtends from "@babel/runtime/helpers/esm/extends";
6
-
7
- /**
8
- * Provides state management for a combo box component. Handles building a collection
9
- * of items from props and manages the option selection state of the combo box. In addition, it tracks the input value,
10
- * focus state, and other properties of the combo box.
11
- */
12
- export function useComboBoxState(props) {
13
- var _props$defaultInputVa, _props$items, _ref, _props$selectedKey;
14
-
15
- let {
16
- defaultFilter,
17
- menuTrigger = 'input',
18
- allowsEmptyCollection = false,
19
- allowsCustomValue,
20
- shouldCloseOnBlur = true
21
- } = props;
22
- let [isFocused, setFocusedState] = useState(false);
23
- let [inputValue, setInputValue] = useControlledState(props.inputValue, (_props$defaultInputVa = props.defaultInputValue) != null ? _props$defaultInputVa : '', props.onInputChange);
24
-
25
- let onSelectionChange = key => {
26
- if (props.onSelectionChange) {
27
- props.onSelectionChange(key);
28
- } // If open state or selectedKey is uncontrolled and key is the same, reset the inputValue and close the menu
29
- // (scenario: user clicks on already selected option)
30
-
31
-
32
- if (props.isOpen === undefined || props.selectedKey === undefined) {
33
- if (key === selectedKey) {
34
- resetInputValue();
35
- triggerState.close();
36
- }
37
- }
38
- };
39
-
40
- let {
41
- collection,
42
- selectionManager,
43
- selectedKey,
44
- setSelectedKey,
45
- selectedItem,
46
- disabledKeys
47
- } = useSingleSelectListState(_babelRuntimeHelpersEsmExtends({}, props, {
48
- onSelectionChange,
49
- items: (_props$items = props.items) != null ? _props$items : props.defaultItems
50
- }));
51
- let filteredCollection = useMemo(() => // No default filter if items are controlled.
52
- props.items != null || !defaultFilter ? collection : $b1b6afed698df4428b7ed319af4b90$var$filterCollection(collection, inputValue, defaultFilter), [collection, inputValue, defaultFilter, props.items]);
53
- let triggerState = useMenuTriggerState(props);
54
-
55
- let open = focusStrategy => {
56
- // Prevent open operations from triggering if there is nothing to display
57
- if (allowsEmptyCollection || filteredCollection.size > 0) {
58
- triggerState.open(focusStrategy);
59
- }
60
- };
61
-
62
- let toggle = focusStrategy => {
63
- // If the menu is closed and there is nothing to display, early return so toggle isn't called to prevent extraneous onOpenChange
64
- if (!(allowsEmptyCollection || filteredCollection.size > 0) && !triggerState.isOpen) {
65
- return;
66
- }
67
-
68
- triggerState.toggle(focusStrategy);
69
- };
70
-
71
- let lastValue = useRef(inputValue);
72
-
73
- let resetInputValue = () => {
74
- var _collection$getItem$t, _collection$getItem;
75
-
76
- let itemText = (_collection$getItem$t = (_collection$getItem = collection.getItem(selectedKey)) == null ? void 0 : _collection$getItem.textValue) != null ? _collection$getItem$t : '';
77
- lastValue.current = itemText;
78
- setInputValue(itemText);
79
- };
80
-
81
- let isInitialRender = useRef(true);
82
- let lastSelectedKey = useRef((_ref = (_props$selectedKey = props.selectedKey) != null ? _props$selectedKey : props.defaultSelectedKey) != null ? _ref : null);
83
- useEffect(() => {
84
- // If open state or inputValue is uncontrolled, open and close automatically when the input value changes,
85
- // the input is if focused, and there are items in the collection or allowEmptyCollection is true.
86
- if (isFocused && (filteredCollection.size > 0 || allowsEmptyCollection) && !triggerState.isOpen && inputValue !== lastValue.current && menuTrigger !== 'manual' && (props.isOpen === undefined || props.inputValue === undefined)) {
87
- open();
88
- } // Close the menu if the collection is empty and either open state or items are uncontrolled.
89
-
90
-
91
- if (!allowsEmptyCollection && triggerState.isOpen && filteredCollection.size === 0 && (props.isOpen === undefined || props.items === undefined)) {
92
- triggerState.close();
93
- } // Close when an item is selected, if open state or selectedKey is uncontrolled.
94
-
95
-
96
- if (selectedKey != null && selectedKey !== lastSelectedKey.current && (props.isOpen === undefined || props.selectedKey === undefined)) {
97
- triggerState.close();
98
- } // Clear focused key when input value changes.
99
-
100
-
101
- if (inputValue !== lastValue.current) {
102
- selectionManager.setFocusedKey(null); // Set selectedKey to null when the user clears the input.
103
- // If controlled, this is the application developer's responsibility.
104
-
105
- if (inputValue === '' && (props.inputValue === undefined || props.selectedKey === undefined)) {
106
- setSelectedKey(null);
107
- }
108
- } // 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
-
110
-
111
- if (isInitialRender.current && props.inputValue === undefined && props.defaultInputValue === undefined) {
112
- resetInputValue();
113
- } // If the selectedKey changed, update the input value.
114
- // Do nothing if both inputValue and selectedKey are controlled.
115
- // In this case, it's the user's responsibility to update inputValue in onSelectionChange. In addition, we preserve the defaultInputValue
116
- // on initial render, even if it doesn't match the selected item's text.
117
-
118
-
119
- if (selectedKey !== lastSelectedKey.current && (props.inputValue === undefined || props.selectedKey === undefined)) {
120
- resetInputValue();
121
- } else {
122
- lastValue.current = inputValue;
123
- }
124
-
125
- isInitialRender.current = false;
126
- lastSelectedKey.current = selectedKey;
127
- });
128
- useEffect(() => {
129
- // Reset focused key when the menu closes
130
- if (!triggerState.isOpen) {
131
- selectionManager.setFocusedKey(null);
132
- }
133
- }, [triggerState.isOpen, selectionManager]);
134
-
135
- let commitCustomValue = () => {
136
- let shouldClose = false;
137
- lastSelectedKey.current = null;
138
- setSelectedKey(null); // If previous key was already null, need to manually call onSelectionChange since it won't be triggered by a setSelectedKey call
139
- // This allows the application to control whether or not to close the menu on custom value commit
140
-
141
- if (selectedKey === null && props.onSelectionChange) {
142
- props.onSelectionChange(null);
143
- } // Should close menu ourselves if component open state or selected key is uncontrolled and therefore won't be closed by a user defined event handler
144
-
145
-
146
- shouldClose = props.isOpen == null || props.selectedKey === undefined; // Close if no other event will be fired. Otherwise, allow the
147
- // application to control this based on that event.
148
-
149
- if (shouldClose) {
150
- triggerState.close();
151
- }
152
- };
153
-
154
- let commitSelection = () => {
155
- // If multiple things are controlled, call onSelectionChange
156
- // Note that users who control open state and input value MUST also have a onSelectionChange handler to properly close the menu and reset input value
157
- if (props.selectedKey !== undefined && props.inputValue !== undefined || props.inputValue !== undefined && props.isOpen !== undefined || props.selectedKey !== undefined && props.isOpen !== undefined) {
158
- props.onSelectionChange(selectedKey); // If multiple things are controlled but inputValue isn't, reset the input value for the user
159
-
160
- if (props.inputValue === undefined) {
161
- resetInputValue();
162
- } // If multiple things are controlled but isOpen isn't, close the menu for the user
163
-
164
-
165
- if (props.isOpen === undefined) {
166
- var _collection$getItem$t2, _collection$getItem2;
167
-
168
- // Stop menu from reopening from useEffect
169
- let itemText = (_collection$getItem$t2 = (_collection$getItem2 = collection.getItem(selectedKey)) == null ? void 0 : _collection$getItem2.textValue) != null ? _collection$getItem$t2 : '';
170
- lastValue.current = itemText;
171
- triggerState.close();
172
- }
173
- } else {
174
- // If only a single aspect of combobox is controlled, reset input value and close menu for the user
175
- resetInputValue();
176
- triggerState.close();
177
- }
178
- };
179
-
180
- let commit = () => {
181
- if (triggerState.isOpen && selectionManager.focusedKey != null) {
182
- // Reset inputValue and close menu here if the selected key is already the focused key. Otherwise
183
- // fire onSelectionChange to allow the application to control the closing.
184
- if (selectedKey === selectionManager.focusedKey) {
185
- commitSelection();
186
- } else {
187
- setSelectedKey(selectionManager.focusedKey);
188
- }
189
- } else if (allowsCustomValue) {
190
- commitCustomValue();
191
- }
192
- };
193
-
194
- let setFocused = isFocused => {
195
- if (isFocused) {
196
- if (menuTrigger === 'focus') {
197
- open();
198
- }
199
- } else if (shouldCloseOnBlur) {
200
- var _collection$getItem$t3, _collection$getItem3;
201
-
202
- let itemText = (_collection$getItem$t3 = (_collection$getItem3 = collection.getItem(selectedKey)) == null ? void 0 : _collection$getItem3.textValue) != null ? _collection$getItem$t3 : '';
203
-
204
- if (allowsCustomValue && inputValue !== itemText) {
205
- commitCustomValue();
206
- } else {
207
- commitSelection();
208
- }
209
- }
210
-
211
- setFocusedState(isFocused);
212
- };
213
-
214
- return _babelRuntimeHelpersEsmExtends({}, triggerState, {
215
- toggle,
216
- open,
217
- selectionManager,
218
- selectedKey,
219
- setSelectedKey,
220
- disabledKeys,
221
- isFocused,
222
- setFocused,
223
- selectedItem,
224
- collection: filteredCollection,
225
- inputValue,
226
- setInputValue,
227
- commit
228
- });
229
- }
230
-
231
- function $b1b6afed698df4428b7ed319af4b90$var$filterCollection(collection, inputValue, filter) {
232
- return new ListCollection($b1b6afed698df4428b7ed319af4b90$var$filterNodes(collection, inputValue, filter));
233
- }
234
-
235
- function $b1b6afed698df4428b7ed319af4b90$var$filterNodes(nodes, inputValue, filter) {
236
- let filteredNode = [];
237
-
238
- for (let node of nodes) {
239
- if (node.type === 'section' && node.hasChildNodes) {
240
- let filtered = $b1b6afed698df4428b7ed319af4b90$var$filterNodes(node.childNodes, inputValue, filter);
241
-
242
- if ([...filtered].length > 0) {
243
- filteredNode.push(_babelRuntimeHelpersEsmExtends({}, node, {
244
- childNodes: filtered
245
- }));
246
- }
247
- } else if (node.type !== 'section' && filter(node.textValue, inputValue)) {
248
- filteredNode.push(node);
249
- }
250
- }
251
-
252
- return filteredNode;
253
- }
1
+ import {useComboBoxState as $a9e7382a7d111cb5$export$b453a3bfd4a5fa9e} from "./useComboBoxState.module.js";
2
+
3
+ /*
4
+ * Copyright 2020 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+
16
+ export {$a9e7382a7d111cb5$export$b453a3bfd4a5fa9e as useComboBoxState};
254
17
  //# sourceMappingURL=module.js.map