{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AA6BM,SAAS,0CAA2C,KAA+B;IACxF,IAAI,CAAC,aAAa,eAAe,GAAG,CAAA,GAAA,4CAAiB,EAAE,MAAM,WAAW,EAAE,MAAM,kBAAkB,IAAI,MAAM,MAAM,iBAAiB;IACnI,IAAI,eAAe,CAAA,GAAA,oBAAM,EAAE,IAAM,eAAe,OAAO;YAAC;SAAY,GAAG,EAAE,EAAE;QAAC;KAAY;IACxF,IAAI,cAAC,UAAU,gBAAE,YAAY,oBAAE,gBAAgB,EAAC,GAAG,CAAA,GAAA,sCAAW,EAAE;QAC9D,GAAG,KAAK;QACR,eAAe;QACf,wBAAwB;QACxB,+BAA+B;sBAC/B;QACA,mBAAmB,CAAC;YAClB,uCAAuC;YACvC,IAAI,SAAS,OACX;YAEF,IAAI,MAAM,KAAK,MAAM,GAAG,IAAI,GAAG,KAAK,IAAI;YAExC,6DAA6D;YAC7D,oDAAoD;YACpD,IAAI,QAAQ,eAAe,MAAM,iBAAiB,EAChD,MAAM,iBAAiB,CAAC;YAG1B,eAAe;QACjB;IACF;IAEA,IAAI,eAAe,eAAe,OAC9B,WAAW,OAAO,CAAC,eACnB;IAEJ,OAAO;oBACL;sBACA;0BACA;qBACA;wBACA;sBACA;IACF;AACF","sources":["packages/react-stately/src/list/useSingleSelectListState.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\nimport {CollectionStateBase, Key, Node, Selection, SingleSelection} from '@react-types/shared';\nimport {ListState, useListState} from './useListState';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo} from 'react';\n\nexport interface SingleSelectListProps<T> extends CollectionStateBase<T>, Omit<SingleSelection, 'disallowEmptySelection'> {\n  /** Filter function to generate a filtered list of nodes. */\n  filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>,\n  /** @private */\n  suppressTextValueWarning?: boolean\n}\n\nexport interface SingleSelectListState<T> extends ListState<T> {\n  /** The key for the currently selected item. */\n  readonly selectedKey: Key | null,\n\n  /** Sets the selected key. */\n  setSelectedKey(key: Key | null): void,\n\n  /** The value of the currently selected item. */\n  readonly selectedItem: Node<T> | null\n}\n\n/**\n * Provides state management for list-like components with single selection.\n * Handles building a collection of items from props, and manages selection state.\n */\nexport function useSingleSelectListState<T extends object>(props: SingleSelectListProps<T>): SingleSelectListState<T>  {\n  let [selectedKey, setSelectedKey] = useControlledState(props.selectedKey, props.defaultSelectedKey ?? null, props.onSelectionChange);\n  let selectedKeys = useMemo(() => selectedKey != null ? [selectedKey] : [], [selectedKey]);\n  let {collection, disabledKeys, selectionManager} = useListState({\n    ...props,\n    selectionMode: 'single',\n    disallowEmptySelection: true,\n    allowDuplicateSelectionEvents: true,\n    selectedKeys,\n    onSelectionChange: (keys: Selection) => {\n      // impossible, but TS doesn't know that\n      if (keys === 'all') {\n        return;\n      }\n      let key = keys.values().next().value ?? null;\n\n      // Always fire onSelectionChange, even if the key is the same\n      // as the current key (useControlledState does not).\n      if (key === selectedKey && props.onSelectionChange) {\n        props.onSelectionChange(key);\n      }\n\n      setSelectedKey(key);\n    }\n  });\n\n  let selectedItem = selectedKey != null\n    ? collection.getItem(selectedKey)\n    : null;\n\n  return {\n    collection,\n    disabledKeys,\n    selectionManager,\n    selectedKey,\n    setSelectedKey,\n    selectedItem\n  };\n}\n"],"names":[],"version":3,"file":"useSingleSelectListState.cjs.map"}