@react-stately/combobox 3.13.0 → 3.14.0

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/import.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import {useComboBoxState as $a9e7382a7d111cb5$export$b453a3bfd4a5fa9e} from "./useComboBoxState.mjs";
1
+ import {useComboBoxState as $b34e662dca7039b9$re_export$useComboBoxState} from "react-stately/useComboBoxState";
2
2
 
3
3
  /*
4
4
  * Copyright 2020 Adobe. All rights reserved.
@@ -13,5 +13,5 @@ import {useComboBoxState as $a9e7382a7d111cb5$export$b453a3bfd4a5fa9e} from "./u
13
13
  */
14
14
 
15
15
 
16
- export {$a9e7382a7d111cb5$export$b453a3bfd4a5fa9e as useComboBoxState};
16
+ export {$b34e662dca7039b9$re_export$useComboBoxState as useComboBoxState};
17
17
  //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,11 +1,11 @@
1
- var $e563f9c9469ad14c$exports = require("./useComboBoxState.main.js");
1
+ var $iy7zD$reactstatelyuseComboBoxState = require("react-stately/useComboBoxState");
2
2
 
3
3
 
4
4
  function $parcel$export(e, n, v, s) {
5
5
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
6
  }
7
7
 
8
- $parcel$export(module.exports, "useComboBoxState", () => $e563f9c9469ad14c$exports.useComboBoxState);
8
+ $parcel$export(module.exports, "useComboBoxState", function () { return $iy7zD$reactstatelyuseComboBoxState.useComboBoxState; });
9
9
  /*
10
10
  * Copyright 2020 Adobe. All rights reserved.
11
11
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
package/dist/main.js.map CHANGED
@@ -1 +1 @@
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"}
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 'react-stately/useComboBoxState';\n\nexport type {ComboBoxProps, ComboBoxStateOptions, ComboBoxState, ComboBoxValidationValue, MenuTriggerAction, SelectionMode} from 'react-stately/useComboBoxState';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,4 +1,4 @@
1
- import {useComboBoxState as $a9e7382a7d111cb5$export$b453a3bfd4a5fa9e} from "./useComboBoxState.module.js";
1
+ import {useComboBoxState as $b34e662dca7039b9$re_export$useComboBoxState} from "react-stately/useComboBoxState";
2
2
 
3
3
  /*
4
4
  * Copyright 2020 Adobe. All rights reserved.
@@ -13,5 +13,5 @@ import {useComboBoxState as $a9e7382a7d111cb5$export$b453a3bfd4a5fa9e} from "./u
13
13
  */
14
14
 
15
15
 
16
- export {$a9e7382a7d111cb5$export$b453a3bfd4a5fa9e as useComboBoxState};
16
+ export {$b34e662dca7039b9$re_export$useComboBoxState as useComboBoxState};
17
17
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
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":"module.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 'react-stately/useComboBoxState';\n\nexport type {ComboBoxProps, ComboBoxStateOptions, ComboBoxState, ComboBoxValidationValue, MenuTriggerAction, SelectionMode} from 'react-stately/useComboBoxState';\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,2 @@
1
+ export { useComboBoxState } from 'react-stately/useComboBoxState';
2
+ export type { ComboBoxProps, ComboBoxStateOptions, ComboBoxState, ComboBoxValidationValue, MenuTriggerAction, SelectionMode } from 'react-stately/useComboBoxState';
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@react-stately/combobox",
3
- "version": "3.13.0",
3
+ "version": "3.14.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/module.js",
8
8
  "exports": {
9
- "source": "./src/index.ts",
10
- "types": [
11
- "./dist/types.d.ts",
12
- "./src/index.ts"
13
- ],
14
- "import": "./dist/import.mjs",
15
- "require": "./dist/main.js"
9
+ ".": {
10
+ "source": "./src/index.ts",
11
+ "types": "./dist/types/src/index.d.ts",
12
+ "import": "./dist/import.mjs",
13
+ "require": "./dist/main.js"
14
+ },
15
+ "./package.json": "./package.json"
16
16
  },
17
- "types": "dist/types.d.ts",
17
+ "types": "dist/types/src/index.d.ts",
18
18
  "source": "src/index.ts",
19
19
  "files": [
20
20
  "dist",
@@ -26,20 +26,18 @@
26
26
  "url": "https://github.com/adobe/react-spectrum"
27
27
  },
28
28
  "dependencies": {
29
- "@react-stately/collections": "^3.12.10",
30
- "@react-stately/form": "^3.2.4",
31
- "@react-stately/list": "^3.13.4",
32
- "@react-stately/overlays": "^3.6.23",
33
- "@react-stately/utils": "^3.11.0",
34
- "@react-types/combobox": "^3.14.0",
35
- "@react-types/shared": "^3.33.1",
36
- "@swc/helpers": "^0.5.0"
29
+ "@swc/helpers": "^0.5.0",
30
+ "react-stately": "3.46.0"
37
31
  },
38
32
  "peerDependencies": {
39
- "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
33
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
34
+ "react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
40
35
  },
41
36
  "publishConfig": {
42
37
  "access": "public"
43
38
  },
44
- "gitHead": "8df187370053aa35f553cb388ad670f65e1ab371"
39
+ "targets": {
40
+ "types": false
41
+ },
42
+ "gitHead": "a6999bdf494a2e9c0381a5881908328bdd22ddae"
45
43
  }
package/src/index.ts CHANGED
@@ -10,6 +10,6 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- export {useComboBoxState} from './useComboBoxState';
13
+ export {useComboBoxState} from 'react-stately/useComboBoxState';
14
14
 
15
- export type {ComboBoxStateOptions, ComboBoxState} from './useComboBoxState';
15
+ export type {ComboBoxProps, ComboBoxStateOptions, ComboBoxState, ComboBoxValidationValue, MenuTriggerAction, SelectionMode} from 'react-stately/useComboBoxState';
package/dist/types.d.ts DELETED
@@ -1,72 +0,0 @@
1
- import { CollectionStateBase, FocusStrategy, Key, Node } from "@react-types/shared";
2
- import { ComboBoxProps, MenuTriggerAction, SelectionMode, ValueType } from "@react-types/combobox";
3
- import { FormValidationState } from "@react-stately/form";
4
- import { ListState } from "@react-stately/list";
5
- import { OverlayTriggerState } from "@react-stately/overlays";
6
- export interface ComboBoxState<T, M extends SelectionMode = 'single'> extends ListState<T>, OverlayTriggerState, FormValidationState {
7
- /**
8
- * The key for the first selected item.
9
- * @deprecated
10
- */
11
- readonly selectedKey: Key | null;
12
- /**
13
- * The default selected key.
14
- * @deprecated
15
- */
16
- readonly defaultSelectedKey: Key | null;
17
- /**
18
- * Sets the selected key.
19
- * @deprecated
20
- */
21
- setSelectedKey(key: Key | null): void;
22
- /** The current combobox value. */
23
- readonly value: ValueType<M>;
24
- /** The default combobox value. */
25
- readonly defaultValue: ValueType<M>;
26
- /** Sets the combobox value. */
27
- setValue(value: Key | readonly Key[] | null): void;
28
- /**
29
- * The value of the first selected item.
30
- * @deprecated
31
- */
32
- readonly selectedItem: Node<T> | null;
33
- /** The value of the selected items. */
34
- readonly selectedItems: Node<T>[];
35
- /** The current value of the combo box input. */
36
- inputValue: string;
37
- /** The default value of the combo box input. */
38
- defaultInputValue: string;
39
- /** Sets the value of the combo box input. */
40
- setInputValue(value: string): void;
41
- /** Selects the currently focused item and updates the input value. */
42
- commit(): void;
43
- /** Controls which item will be auto focused when the menu opens. */
44
- readonly focusStrategy: FocusStrategy | null;
45
- /** Whether the select is currently focused. */
46
- readonly isFocused: boolean;
47
- /** Sets whether the select is focused. */
48
- setFocused(isFocused: boolean): void;
49
- /** Opens the menu. */
50
- open(focusStrategy?: FocusStrategy | null, trigger?: MenuTriggerAction): void;
51
- /** Toggles the menu. */
52
- toggle(focusStrategy?: FocusStrategy | null, trigger?: MenuTriggerAction): void;
53
- /** Resets the input value to the previously selected item's text if any and closes the menu. */
54
- revert(): void;
55
- }
56
- type FilterFn = (textValue: string, inputValue: string) => boolean;
57
- export interface ComboBoxStateOptions<T, M extends SelectionMode = 'single'> extends Omit<ComboBoxProps<T, M>, 'children'>, CollectionStateBase<T> {
58
- /** The filter function used to determine if a option should be included in the combo box list. */
59
- defaultFilter?: FilterFn;
60
- /** Whether the combo box allows the menu to be open when the collection is empty. */
61
- allowsEmptyCollection?: boolean;
62
- /** Whether the combo box menu should close on blur. */
63
- shouldCloseOnBlur?: boolean;
64
- }
65
- /**
66
- * Provides state management for a combo box component. Handles building a collection
67
- * of items from props and manages the option selection state of the combo box. In addition, it tracks the input value,
68
- * focus state, and other properties of the combo box.
69
- */
70
- export function useComboBoxState<T extends object, M extends SelectionMode = 'single'>(props: ComboBoxStateOptions<T, M>): ComboBoxState<T>;
71
-
72
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;AAqBA,+BAA+B,CAAC,EAAE,CAAC,SAAS,aAAa,GAAG,QAAQ,CAAE,SAAQ,UAAU,CAAC,CAAC,EAAE,mBAAmB,EAAE,mBAAmB;IAClI;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,GAAG,GAAG,IAAI,CAAC;IAEjC;;;OAGG;IACH,QAAQ,CAAC,kBAAkB,EAAE,GAAG,GAAG,IAAI,CAAC;IACxC;;;OAGG;IACH,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;IACtC,kCAAkC;IAClC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC;IAC7B,kCAAkC;IAClC,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC,CAAC;IACpC,+BAA+B;IAC/B,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,SAAS,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;IACnD;;;OAGG;IACH,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC;IACtC,uCAAuC;IACvC,QAAQ,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC;IAClC,gDAAgD;IAChD,UAAU,EAAE,MAAM,CAAC;IACnB,gDAAgD;IAChD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,6CAA6C;IAC7C,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,sEAAsE;IACtE,MAAM,IAAI,IAAI,CAAC;IACf,oEAAoE;IACpE,QAAQ,CAAC,aAAa,EAAE,aAAa,GAAG,IAAI,CAAC;IAC7C,+CAA+C;IAC/C,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,0CAA0C;IAC1C,UAAU,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,CAAC;IACrC,sBAAsB;IACtB,IAAI,CAAC,aAAa,CAAC,EAAE,aAAa,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAC9E,wBAAwB;IACxB,MAAM,CAAC,aAAa,CAAC,EAAE,aAAa,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAChF,iGAAiG;IACjG,MAAM,IAAI,IAAI,CAAA;CACf;AAED,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC;AAEnE,sCAAsC,CAAC,EAAE,CAAC,SAAS,aAAa,GAAG,QAAQ,CAAE,SAAQ,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,oBAAoB,CAAC,CAAC;IAChJ,kGAAkG;IAClG,aAAa,CAAC,EAAE,QAAQ,CAAC;IACzB,qFAAqF;IACrF,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,uDAAuD;IACvD,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC5B;AAID;;;;GAIG;AACH,iCAAiC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,aAAa,GAAG,QAAQ,EAAE,KAAK,EAAE,qBAAqB,CAAC,EAAE,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CA6X1I","sources":["packages/@react-stately/combobox/src/packages/@react-stately/combobox/src/useComboBoxState.ts","packages/@react-stately/combobox/src/packages/@react-stately/combobox/src/index.ts","packages/@react-stately/combobox/src/index.ts"],"sourcesContent":[null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useComboBoxState} from './useComboBoxState';\n\nexport type {ComboBoxStateOptions, ComboBoxState} from './useComboBoxState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -1,385 +0,0 @@
1
- var $2KOLe$reactstatelyform = require("@react-stately/form");
2
- var $2KOLe$reactstatelycollections = require("@react-stately/collections");
3
- var $2KOLe$reactstatelylist = require("@react-stately/list");
4
- var $2KOLe$reactstatelyoverlays = require("@react-stately/overlays");
5
- var $2KOLe$react = require("react");
6
- var $2KOLe$reactstatelyutils = require("@react-stately/utils");
7
-
8
-
9
- function $parcel$export(e, n, v, s) {
10
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
11
- }
12
-
13
- $parcel$export(module.exports, "useComboBoxState", () => $e563f9c9469ad14c$export$b453a3bfd4a5fa9e);
14
- /*
15
- * Copyright 2020 Adobe. All rights reserved.
16
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
17
- * you may not use this file except in compliance with the License. You may obtain a copy
18
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
19
- *
20
- * Unless required by applicable law or agreed to in writing, software distributed under
21
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
22
- * OF ANY KIND, either express or implied. See the License for the specific language
23
- * governing permissions and limitations under the License.
24
- */
25
-
26
-
27
-
28
-
29
-
30
- const $e563f9c9469ad14c$var$EMPTY_VALUE = [];
31
- function $e563f9c9469ad14c$export$b453a3bfd4a5fa9e(props) {
32
- var _collection_getItem;
33
- let { defaultFilter: defaultFilter, menuTrigger: menuTrigger = 'input', allowsEmptyCollection: allowsEmptyCollection = false, allowsCustomValue: allowsCustomValue, shouldCloseOnBlur: shouldCloseOnBlur = true, selectionMode: selectionMode = 'single' } = props;
34
- let [showAllItems, setShowAllItems] = (0, $2KOLe$react.useState)(false);
35
- let [isFocused, setFocusedState] = (0, $2KOLe$react.useState)(false);
36
- let [focusStrategy, setFocusStrategy] = (0, $2KOLe$react.useState)(null);
37
- let defaultValue = (0, $2KOLe$react.useMemo)(()=>{
38
- var _props_defaultSelectedKey;
39
- return props.defaultValue !== undefined ? props.defaultValue : selectionMode === 'single' ? (_props_defaultSelectedKey = props.defaultSelectedKey) !== null && _props_defaultSelectedKey !== void 0 ? _props_defaultSelectedKey : null : [];
40
- }, [
41
- props.defaultValue,
42
- props.defaultSelectedKey,
43
- selectionMode
44
- ]);
45
- let value = (0, $2KOLe$react.useMemo)(()=>{
46
- return props.value !== undefined ? props.value : selectionMode === 'single' ? props.selectedKey : undefined;
47
- }, [
48
- props.value,
49
- props.selectedKey,
50
- selectionMode
51
- ]);
52
- let [controlledValue, setControlledValue] = (0, $2KOLe$reactstatelyutils.useControlledState)(value, defaultValue, props.onChange);
53
- // Only display the first selected item if in single selection mode but the value is an array.
54
- let displayValue = selectionMode === 'single' && Array.isArray(controlledValue) ? controlledValue[0] : controlledValue;
55
- let setValue = (value)=>{
56
- if (selectionMode === 'single') {
57
- var _props_onSelectionChange;
58
- var _value_;
59
- let key = Array.isArray(value) ? (_value_ = value[0]) !== null && _value_ !== void 0 ? _value_ : null : value;
60
- setControlledValue(key);
61
- if (key !== displayValue) (_props_onSelectionChange = props.onSelectionChange) === null || _props_onSelectionChange === void 0 ? void 0 : _props_onSelectionChange.call(props, key);
62
- } else {
63
- let keys = [];
64
- if (Array.isArray(value)) keys = value;
65
- else if (value != null) keys = [
66
- value
67
- ];
68
- setControlledValue(keys);
69
- }
70
- };
71
- var _props_items;
72
- let { collection: collection, selectionManager: selectionManager, disabledKeys: disabledKeys } = (0, $2KOLe$reactstatelylist.useListState)({
73
- ...props,
74
- items: (_props_items = props.items) !== null && _props_items !== void 0 ? _props_items : props.defaultItems,
75
- selectionMode: selectionMode,
76
- disallowEmptySelection: selectionMode === 'single',
77
- allowDuplicateSelectionEvents: true,
78
- selectedKeys: (0, $2KOLe$react.useMemo)(()=>$e563f9c9469ad14c$var$convertValue(displayValue), [
79
- displayValue
80
- ]),
81
- onSelectionChange: (keys)=>{
82
- // impossible, but TS doesn't know that
83
- if (keys === 'all') return;
84
- if (selectionMode === 'single') {
85
- var _keys_values_next_value;
86
- let key = (_keys_values_next_value = keys.values().next().value) !== null && _keys_values_next_value !== void 0 ? _keys_values_next_value : null;
87
- if (key === displayValue) {
88
- var _props_onSelectionChange;
89
- (_props_onSelectionChange = props.onSelectionChange) === null || _props_onSelectionChange === void 0 ? void 0 : _props_onSelectionChange.call(props, key);
90
- // If key is the same, reset the inputValue and close the menu
91
- // (scenario: user clicks on already selected option)
92
- resetInputValue();
93
- closeMenu();
94
- } else setValue(key);
95
- } else setValue([
96
- ...keys
97
- ]);
98
- }
99
- });
100
- let selectedKey = selectionMode === 'single' ? selectionManager.firstSelectedKey : null;
101
- let selectedItems = (0, $2KOLe$react.useMemo)(()=>{
102
- return [
103
- ...selectionManager.selectedKeys
104
- ].map((key)=>collection.getItem(key)).filter((item)=>item != null);
105
- }, [
106
- selectionManager.selectedKeys,
107
- collection
108
- ]);
109
- let [inputValue, setInputValue] = (0, $2KOLe$reactstatelyutils.useControlledState)(props.inputValue, $e563f9c9469ad14c$var$getDefaultInputValue(props.defaultInputValue, selectedKey, collection) || '', props.onInputChange);
110
- let [initialValue] = (0, $2KOLe$react.useState)(displayValue);
111
- let [initialInputValue] = (0, $2KOLe$react.useState)(inputValue);
112
- // Preserve original collection so we can show all items on demand
113
- let originalCollection = collection;
114
- let filteredCollection = (0, $2KOLe$react.useMemo)(()=>// No default filter if items are controlled.
115
- props.items != null || !defaultFilter ? collection : $e563f9c9469ad14c$var$filterCollection(collection, inputValue, defaultFilter), [
116
- collection,
117
- inputValue,
118
- defaultFilter,
119
- props.items
120
- ]);
121
- let [lastCollection, setLastCollection] = (0, $2KOLe$react.useState)(filteredCollection);
122
- // Track what action is attempting to open the menu
123
- let menuOpenTrigger = (0, $2KOLe$react.useRef)('focus');
124
- let onOpenChange = (open)=>{
125
- if (props.onOpenChange) props.onOpenChange(open, open ? menuOpenTrigger.current : undefined);
126
- selectionManager.setFocused(open);
127
- if (!open) selectionManager.setFocusedKey(null);
128
- };
129
- let triggerState = (0, $2KOLe$reactstatelyoverlays.useOverlayTriggerState)({
130
- ...props,
131
- onOpenChange: onOpenChange,
132
- isOpen: undefined,
133
- defaultOpen: undefined
134
- });
135
- let open = (focusStrategy = null, trigger)=>{
136
- let displayAllItems = trigger === 'manual' || trigger === 'focus' && menuTrigger === 'focus';
137
- // Prevent open operations from triggering if there is nothing to display
138
- // Also prevent open operations from triggering if items are uncontrolled but defaultItems is empty, even if displayAllItems is true.
139
- // 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)
140
- if (allowsEmptyCollection || filteredCollection.size > 0 || displayAllItems && originalCollection.size > 0 || props.items) {
141
- if (displayAllItems && !triggerState.isOpen && props.items === undefined) // Show all items if menu is manually opened. Only care about this if items are undefined
142
- setShowAllItems(true);
143
- menuOpenTrigger.current = trigger;
144
- setFocusStrategy(focusStrategy);
145
- triggerState.open();
146
- }
147
- };
148
- let toggle = (focusStrategy = null, trigger)=>{
149
- let displayAllItems = trigger === 'manual' || trigger === 'focus' && menuTrigger === 'focus';
150
- // If the menu is closed and there is nothing to display, early return so toggle isn't called to prevent extraneous onOpenChange
151
- if (!(allowsEmptyCollection || filteredCollection.size > 0 || displayAllItems && originalCollection.size > 0 || props.items) && !triggerState.isOpen) return;
152
- if (displayAllItems && !triggerState.isOpen && props.items === undefined) // Show all items if menu is toggled open. Only care about this if items are undefined
153
- setShowAllItems(true);
154
- // Only update the menuOpenTrigger if menu is currently closed
155
- if (!triggerState.isOpen) menuOpenTrigger.current = trigger;
156
- toggleMenu(focusStrategy);
157
- };
158
- let updateLastCollection = (0, $2KOLe$react.useCallback)(()=>{
159
- setLastCollection(showAllItems ? originalCollection : filteredCollection);
160
- }, [
161
- showAllItems,
162
- originalCollection,
163
- filteredCollection
164
- ]);
165
- // If menu is going to close, save the current collection so we can freeze the displayed collection when the
166
- // user clicks outside the popover to close the menu. Prevents the menu contents from updating as the menu closes.
167
- let toggleMenu = (0, $2KOLe$react.useCallback)((focusStrategy = null)=>{
168
- if (triggerState.isOpen) updateLastCollection();
169
- setFocusStrategy(focusStrategy);
170
- triggerState.toggle();
171
- }, [
172
- triggerState,
173
- updateLastCollection
174
- ]);
175
- let closeMenu = (0, $2KOLe$react.useCallback)(()=>{
176
- if (triggerState.isOpen) {
177
- updateLastCollection();
178
- triggerState.close();
179
- }
180
- }, [
181
- triggerState,
182
- updateLastCollection
183
- ]);
184
- let [lastValue, setLastValue] = (0, $2KOLe$react.useState)(inputValue);
185
- let resetInputValue = ()=>{
186
- var _collection_getItem;
187
- var _collection_getItem_textValue;
188
- let itemText = selectedKey != null ? (_collection_getItem_textValue = (_collection_getItem = collection.getItem(selectedKey)) === null || _collection_getItem === void 0 ? void 0 : _collection_getItem.textValue) !== null && _collection_getItem_textValue !== void 0 ? _collection_getItem_textValue : '' : '';
189
- setLastValue(itemText);
190
- setInputValue(itemText);
191
- };
192
- let lastValueRef = (0, $2KOLe$react.useRef)(displayValue);
193
- var _collection_getItem_textValue;
194
- let lastSelectedKeyText = (0, $2KOLe$react.useRef)(selectedKey != null ? (_collection_getItem_textValue = (_collection_getItem = collection.getItem(selectedKey)) === null || _collection_getItem === void 0 ? void 0 : _collection_getItem.textValue) !== null && _collection_getItem_textValue !== void 0 ? _collection_getItem_textValue : '' : '');
195
- // intentional omit dependency array, want this to happen on every render
196
- // eslint-disable-next-line react-hooks/exhaustive-deps
197
- (0, $2KOLe$react.useEffect)(()=>{
198
- var _collection_getItem;
199
- // Open and close menu automatically when the input value changes if the input is focused,
200
- // and there are items in the collection or allowEmptyCollection is true.
201
- if (isFocused && (filteredCollection.size > 0 || allowsEmptyCollection) && !triggerState.isOpen && inputValue !== lastValue && menuTrigger !== 'manual') open(null, 'input');
202
- // Close the menu if the collection is empty. Don't close menu if filtered collection size is 0
203
- // but we are currently showing all items via button press
204
- if (!showAllItems && !allowsEmptyCollection && triggerState.isOpen && filteredCollection.size === 0) closeMenu();
205
- // Close when an item is selected.
206
- if (displayValue != null && displayValue !== lastValueRef.current && selectionMode === 'single') closeMenu();
207
- // Clear focused key when input value changes and display filtered collection again.
208
- if (inputValue !== lastValue) {
209
- selectionManager.setFocusedKey(null);
210
- setShowAllItems(false);
211
- // Set value to null when the user clears the input.
212
- // If controlled, this is the application developer's responsibility.
213
- if (selectionMode === 'single' && inputValue === '' && (props.inputValue === undefined || value === undefined)) setValue(null);
214
- }
215
- // If the value changed, update the input value.
216
- // Do nothing if both inputValue and value are controlled.
217
- // In this case, it's the user's responsibility to update inputValue in onSelectionChange.
218
- if (displayValue !== lastValueRef.current && (props.inputValue === undefined || value === undefined)) resetInputValue();
219
- else if (lastValue !== inputValue) setLastValue(inputValue);
220
- var _collection_getItem_textValue;
221
- // Update the inputValue if the selected item's text changes from its last tracked value.
222
- // 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.
223
- // Only reset if the user isn't currently within the field so we don't erroneously modify user input.
224
- // If inputValue is controlled, it is the user's responsibility to update the inputValue when items change.
225
- let selectedItemText = selectedKey != null ? (_collection_getItem_textValue = (_collection_getItem = collection.getItem(selectedKey)) === null || _collection_getItem === void 0 ? void 0 : _collection_getItem.textValue) !== null && _collection_getItem_textValue !== void 0 ? _collection_getItem_textValue : '' : '';
226
- if (!isFocused && selectedKey != null && props.inputValue === undefined && selectedKey === lastValueRef.current) {
227
- if (lastSelectedKeyText.current !== selectedItemText) {
228
- setLastValue(selectedItemText);
229
- setInputValue(selectedItemText);
230
- }
231
- }
232
- lastValueRef.current = displayValue;
233
- lastSelectedKeyText.current = selectedItemText;
234
- });
235
- let validation = (0, $2KOLe$reactstatelyform.useFormValidationState)({
236
- ...props,
237
- value: (0, $2KOLe$react.useMemo)(()=>Array.isArray(displayValue) && displayValue.length === 0 ? null : {
238
- inputValue: inputValue,
239
- value: displayValue,
240
- selectedKey: selectedKey
241
- }, [
242
- inputValue,
243
- selectedKey,
244
- displayValue
245
- ])
246
- });
247
- // Revert input value and close menu
248
- let revert = ()=>{
249
- if (allowsCustomValue && selectedKey == null) commitCustomValue();
250
- else commitSelection();
251
- };
252
- let commitCustomValue = ()=>{
253
- let value = selectionMode === 'multiple' ? $e563f9c9469ad14c$var$EMPTY_VALUE : null;
254
- lastValueRef.current = value;
255
- setValue(value);
256
- closeMenu();
257
- };
258
- let commitSelection = ()=>{
259
- // If multiple things are controlled, call onSelectionChange
260
- if (value !== undefined && props.inputValue !== undefined) {
261
- var _props_onSelectionChange, _props_onChange, _collection_getItem;
262
- (_props_onSelectionChange = props.onSelectionChange) === null || _props_onSelectionChange === void 0 ? void 0 : _props_onSelectionChange.call(props, selectedKey);
263
- (_props_onChange = props.onChange) === null || _props_onChange === void 0 ? void 0 : _props_onChange.call(props, displayValue);
264
- var _collection_getItem_textValue;
265
- // Stop menu from reopening from useEffect
266
- let itemText = selectedKey != null ? (_collection_getItem_textValue = (_collection_getItem = collection.getItem(selectedKey)) === null || _collection_getItem === void 0 ? void 0 : _collection_getItem.textValue) !== null && _collection_getItem_textValue !== void 0 ? _collection_getItem_textValue : '' : '';
267
- setLastValue(itemText);
268
- closeMenu();
269
- } else {
270
- // If only a single aspect of combobox is controlled, reset input value and close menu for the user
271
- resetInputValue();
272
- closeMenu();
273
- }
274
- };
275
- const commitValue = ()=>{
276
- if (allowsCustomValue) {
277
- var _collection_getItem;
278
- var _collection_getItem_textValue;
279
- const itemText = selectedKey != null ? (_collection_getItem_textValue = (_collection_getItem = collection.getItem(selectedKey)) === null || _collection_getItem === void 0 ? void 0 : _collection_getItem.textValue) !== null && _collection_getItem_textValue !== void 0 ? _collection_getItem_textValue : '' : '';
280
- inputValue === itemText ? commitSelection() : commitCustomValue();
281
- } else // Reset inputValue and close menu
282
- commitSelection();
283
- };
284
- let commit = ()=>{
285
- if (triggerState.isOpen && selectionManager.focusedKey != null) {
286
- // Reset inputValue and close menu here if the selected key is already the focused key. Otherwise
287
- // fire onSelectionChange to allow the application to control the closing.
288
- if (selectionManager.isSelected(selectionManager.focusedKey) && selectionMode === 'single') commitSelection();
289
- else selectionManager.select(selectionManager.focusedKey);
290
- } else commitValue();
291
- };
292
- let valueOnFocus = (0, $2KOLe$react.useRef)(inputValue);
293
- let setFocused = (isFocused)=>{
294
- if (isFocused) {
295
- valueOnFocus.current = inputValue;
296
- if (menuTrigger === 'focus' && !props.isReadOnly) open(null, 'focus');
297
- } else {
298
- if (shouldCloseOnBlur) commitValue();
299
- if (inputValue !== valueOnFocus.current) validation.commitValidation();
300
- }
301
- setFocusedState(isFocused);
302
- };
303
- let displayedCollection = (0, $2KOLe$react.useMemo)(()=>{
304
- if (triggerState.isOpen) {
305
- if (showAllItems) return originalCollection;
306
- else return filteredCollection;
307
- } else return lastCollection;
308
- }, [
309
- triggerState.isOpen,
310
- originalCollection,
311
- filteredCollection,
312
- showAllItems,
313
- lastCollection
314
- ]);
315
- var _props_defaultSelectedKey;
316
- let defaultSelectedKey = (_props_defaultSelectedKey = props.defaultSelectedKey) !== null && _props_defaultSelectedKey !== void 0 ? _props_defaultSelectedKey : selectionMode === 'single' ? initialValue : null;
317
- var _selectedItems_, _getDefaultInputValue;
318
- return {
319
- ...validation,
320
- ...triggerState,
321
- focusStrategy: focusStrategy,
322
- toggle: toggle,
323
- open: open,
324
- close: commitValue,
325
- selectionManager: selectionManager,
326
- value: displayValue,
327
- defaultValue: defaultValue !== null && defaultValue !== void 0 ? defaultValue : initialValue,
328
- setValue: setValue,
329
- selectedKey: selectedKey,
330
- selectedItems: selectedItems,
331
- defaultSelectedKey: defaultSelectedKey,
332
- setSelectedKey: setValue,
333
- disabledKeys: disabledKeys,
334
- isFocused: isFocused,
335
- setFocused: setFocused,
336
- selectedItem: (_selectedItems_ = selectedItems[0]) !== null && _selectedItems_ !== void 0 ? _selectedItems_ : null,
337
- collection: displayedCollection,
338
- inputValue: inputValue,
339
- defaultInputValue: (_getDefaultInputValue = $e563f9c9469ad14c$var$getDefaultInputValue(props.defaultInputValue, defaultSelectedKey, collection)) !== null && _getDefaultInputValue !== void 0 ? _getDefaultInputValue : initialInputValue,
340
- setInputValue: setInputValue,
341
- commit: commit,
342
- revert: revert
343
- };
344
- }
345
- function $e563f9c9469ad14c$var$filterCollection(collection, inputValue, filter) {
346
- return new (0, $2KOLe$reactstatelylist.ListCollection)($e563f9c9469ad14c$var$filterNodes(collection, collection, inputValue, filter));
347
- }
348
- function $e563f9c9469ad14c$var$filterNodes(collection, nodes, inputValue, filter) {
349
- let filteredNode = [];
350
- for (let node of nodes){
351
- if (node.type === 'section' && node.hasChildNodes) {
352
- let filtered = $e563f9c9469ad14c$var$filterNodes(collection, (0, $2KOLe$reactstatelycollections.getChildNodes)(node, collection), inputValue, filter);
353
- if ([
354
- ...filtered
355
- ].some((node)=>node.type === 'item')) filteredNode.push({
356
- ...node,
357
- childNodes: filtered
358
- });
359
- } else if (node.type === 'item' && filter(node.textValue, inputValue)) filteredNode.push({
360
- ...node
361
- });
362
- else if (node.type !== 'item') filteredNode.push({
363
- ...node
364
- });
365
- }
366
- return filteredNode;
367
- }
368
- function $e563f9c9469ad14c$var$getDefaultInputValue(defaultInputValue, selectedKey, collection) {
369
- if (defaultInputValue == null) {
370
- var _collection_getItem;
371
- var _collection_getItem_textValue;
372
- if (selectedKey != null) return (_collection_getItem_textValue = (_collection_getItem = collection.getItem(selectedKey)) === null || _collection_getItem === void 0 ? void 0 : _collection_getItem.textValue) !== null && _collection_getItem_textValue !== void 0 ? _collection_getItem_textValue : '';
373
- }
374
- return defaultInputValue;
375
- }
376
- function $e563f9c9469ad14c$var$convertValue(value) {
377
- if (value === undefined) return undefined;
378
- if (value === null) return [];
379
- return Array.isArray(value) ? value : [
380
- value
381
- ];
382
- }
383
-
384
-
385
- //# sourceMappingURL=useComboBoxState.main.js.map