{"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AA8BM,SAAS,0CACd,KAA+B;IAE/B,IAAI,CAAC,aAAa,eAAe,GAAG,CAAA,GAAA,yCAAiB,EACnD,MAAM,WAAW,EACjB,MAAM,kBAAkB,IAAI,MAC5B,MAAM,iBAAiB;IAEzB,IAAI,eAAe,CAAA,GAAA,cAAM,EAAE,IAAO,eAAe,OAAO;YAAC;SAAY,GAAG,EAAE,EAAG;QAAC;KAAY;IAC1F,IAAI,cAAC,UAAU,gBAAE,YAAY,oBAAE,gBAAgB,EAAC,GAAG,CAAA,GAAA,yCAAW,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,OAAO,WAAW,OAAO,CAAC,eAAe;IAE3E,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>\n  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>(\n  props: SingleSelectListProps<T>\n): SingleSelectListState<T> {\n  let [selectedKey, setSelectedKey] = useControlledState(\n    props.selectedKey,\n    props.defaultSelectedKey ?? null,\n    props.onSelectionChange\n  );\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 ? collection.getItem(selectedKey) : null;\n\n  return {\n    collection,\n    disabledKeys,\n    selectionManager,\n    selectedKey,\n    setSelectedKey,\n    selectedItem\n  };\n}\n"],"names":[],"version":3,"file":"useSingleSelectListState.mjs.map"}