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AAa;IACtC,IAAI,kBAAkB,CAAA,GAAA,uEAA0B,EAAE,CAAA,GAAA,mDAAW,GAAG;IAChE,OACE,uEAAuE;kBACvE,0DAAC;QACC,iEAAiE;QACjE,MAAK;QACL,OAAO;YAAC,SAAS;YAAQ,YAAY;YAAU,gBAAgB;YAAU,QAAQ;QAAM;qBACvF,0DAAC,CAAA,GAAA,wCAAa;QACZ,iBAAA;QACA,MAAK;QACL,cACE,MAAM,UAAU,CAAC,IAAI,GAAG,IACpB,gBAAgB,MAAM,CAAC,iBACvB,gBAAgB,MAAM,CAAC;QAE7B,kBAAkB,CAAA,GAAA,oCAAS,EAAE,CAAA,GAAA,mDAAK,GAAG;;AAI7C;AAEA,SAAS;IACP,IAAI,oBAAC,gBAAgB,EAAC,GAAG,CAAA,GAAA,uBAAS,EAAE,CAAA,GAAA,wCAAa;IACjD,IAAI,aAAa,mBAAmB,qBAAqB;IACzD,IAAI,cAAc,MAChB,OAAO;IAGT,qBACE,0DAAC;QACC,uEAAuE;QACvE,iEAAiE;QACjE,MAAK;OACJ;AAGP","sources":["packages/@adobe/react-spectrum/src/listbox/ListBoxBase.tsx"],"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 {\n  AriaLabelingProps,\n  AsyncLoadable,\n  DOMProps,\n  FocusStrategy,\n  Node,\n  RefObject,\n  StyleProps\n} from '@react-types/shared';\nimport {AriaListBoxOptions, AriaListBoxPropsBase, useListBox} from 'react-aria/useListBox';\nimport {classNames} from '../utils/classNames';\nimport {FocusScope} from 'react-aria/FocusScope';\nimport intlMessages from '../../intl/listbox/*.json';\n// @ts-ignore\nimport {ListBoxContext} from './ListBoxContext';\nimport {ListBoxLayout} from './ListBoxLayout';\nimport {ListBoxOption} from './ListBoxOption';\nimport {ListBoxSection} from './ListBoxSection';\nimport {ListState} from 'react-stately/useListState';\nimport {mergeProps} from 'react-aria/mergeProps';\nimport {ProgressCircle} from '../progress/ProgressCircle';\nimport React, {\n  ForwardedRef,\n  HTMLAttributes,\n  ReactElement,\n  ReactNode,\n  useCallback,\n  useContext,\n  useMemo\n} from 'react';\nimport {ReusableView} from 'react-stately/useVirtualizerState';\nimport styles from '@adobe/spectrum-css-temp/components/menu/vars.css';\nimport {useLocalizedStringFormatter} from 'react-aria/useLocalizedStringFormatter';\nimport {useObjectRef} from 'react-aria/useObjectRef';\nimport {useProvider} from '../provider/Provider';\nimport {useStyleProps} from '../utils/styleProps';\nimport {Virtualizer} from 'react-aria/private/virtualizer/Virtualizer';\nimport {VirtualizerItem} from 'react-aria/private/virtualizer/VirtualizerItem';\n\nexport interface SpectrumListBoxProps<T>\n  extends AriaListBoxPropsBase<T>, AsyncLoadable, StyleProps {}\n\ninterface ListBoxBaseProps<T>\n  extends AriaListBoxOptions<T>, DOMProps, AriaLabelingProps, StyleProps {\n  layout: ListBoxLayout<T>;\n  state: ListState<T>;\n  autoFocus?: boolean | FocusStrategy;\n  shouldFocusWrap?: boolean;\n  shouldSelectOnPressUp?: boolean;\n  focusOnPointerEnter?: boolean;\n  domProps?: HTMLAttributes<HTMLElement>;\n  disallowEmptySelection?: boolean;\n  shouldUseVirtualFocus?: boolean;\n  isLoading?: boolean;\n  showLoadingSpinner?: boolean;\n  onLoadMore?: () => void;\n  renderEmptyState?: () => ReactNode;\n  onScroll?: () => void;\n}\n\n/** @private */\nexport function useListBoxLayout<T>(): ListBoxLayout<T> {\n  let {scale} = useProvider();\n  let layout = useMemo(\n    () =>\n      new ListBoxLayout<T>({\n        estimatedRowHeight: scale === 'large' ? 48 : 32,\n        estimatedHeadingHeight: scale === 'large' ? 33 : 26,\n        paddingY: scale === 'large' ? 5 : 4, // TODO: get from DNA\n        placeholderHeight: scale === 'large' ? 48 : 32\n      }),\n    [scale]\n  );\n\n  return layout;\n}\n\n// forwardRef doesn't support generic parameters, so cast the result to the correct type\n// https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref\n/** @private */\nexport const ListBoxBase = React.forwardRef(function ListBoxBase<T extends object>(\n  props: ListBoxBaseProps<T>,\n  ref: ForwardedRef<HTMLDivElement | null>\n) {\n  let {\n    layout,\n    state,\n    shouldFocusOnHover = false,\n    shouldUseVirtualFocus = false,\n    domProps = {},\n    isLoading,\n    showLoadingSpinner = isLoading,\n    onScroll,\n    renderEmptyState\n  } = props;\n  let objectRef = useObjectRef(ref);\n  let {listBoxProps} = useListBox(\n    {\n      ...props,\n      layoutDelegate: layout,\n      isVirtualized: true\n    },\n    state,\n    objectRef\n  );\n  let {styleProps} = useStyleProps(props);\n\n  // This overrides collection view's renderWrapper to support hierarchy of items in sections.\n  // The header is extracted from the children so it can receive ARIA labeling properties.\n  type View = ReusableView<Node<T>, ReactNode>;\n  let renderWrapper = useCallback(\n    (\n      parent: View | null,\n      reusableView: View,\n      children: View[],\n      renderChildren: (views: View[]) => ReactElement[]\n    ) => {\n      if (reusableView.viewType === 'section') {\n        return (\n          <ListBoxSection\n            key={reusableView.key}\n            item={reusableView.content!}\n            layoutInfo={reusableView.layoutInfo!}\n            virtualizer={reusableView.virtualizer}\n            headerLayoutInfo={children.find(c => c.viewType === 'header')?.layoutInfo ?? null}>\n            {renderChildren(children.filter(c => c.viewType === 'item'))}\n          </ListBoxSection>\n        );\n      }\n\n      return (\n        <VirtualizerItem\n          key={reusableView.key}\n          layoutInfo={reusableView.layoutInfo!}\n          virtualizer={reusableView.virtualizer}\n          parent={parent?.layoutInfo}>\n          {reusableView.rendered}\n        </VirtualizerItem>\n      );\n    },\n    []\n  );\n\n  let focusedKey = state.selectionManager.focusedKey;\n  let persistedKeys = useMemo(\n    () => (focusedKey != null ? new Set([focusedKey]) : null),\n    [focusedKey]\n  );\n\n  return (\n    <ListBoxContext.Provider\n      value={{state, renderEmptyState, shouldFocusOnHover, shouldUseVirtualFocus}}>\n      <FocusScope>\n        <Virtualizer\n          {...styleProps}\n          {...mergeProps(listBoxProps, domProps)}\n          ref={objectRef}\n          persistedKeys={persistedKeys}\n          autoFocus={!!props.autoFocus || undefined}\n          scrollDirection=\"vertical\"\n          className={classNames(styles, 'spectrum-Menu', styleProps.className)}\n          layout={layout}\n          layoutOptions={useMemo(\n            () => ({\n              isLoading: showLoadingSpinner\n            }),\n            [showLoadingSpinner]\n          )}\n          collection={state.collection}\n          renderWrapper={renderWrapper}\n          isLoading={isLoading}\n          onLoadMore={props.onLoadMore}\n          onScroll={onScroll}>\n          {useCallback((type, item: Node<T>): ReactNode => {\n            if (type === 'item') {\n              return <ListBoxOption item={item} />;\n            } else if (type === 'loader') {\n              return <LoadingState />;\n            } else if (type === 'placeholder') {\n              return <EmptyState />;\n            } else {\n              return null;\n            }\n          }, [])}\n        </Virtualizer>\n      </FocusScope>\n    </ListBoxContext.Provider>\n  );\n}) as <T>(props: ListBoxBaseProps<T> & {ref?: RefObject<HTMLDivElement | null>}) => ReactElement;\n\nfunction LoadingState() {\n  let {state} = useContext(ListBoxContext)!;\n  let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/listbox');\n  return (\n    // aria-selected isn't needed here since this option is not selectable.\n    <div\n      // eslint-disable-next-line jsx-a11y/role-has-required-aria-props\n      role=\"option\"\n      style={{display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%'}}>\n      <ProgressCircle\n        isIndeterminate\n        size=\"S\"\n        aria-label={\n          state.collection.size > 0\n            ? stringFormatter.format('loadingMore')\n            : stringFormatter.format('loading')\n        }\n        UNSAFE_className={classNames(styles, 'spectrum-Dropdown-progressCircle')}\n      />\n    </div>\n  );\n}\n\nfunction EmptyState() {\n  let {renderEmptyState} = useContext(ListBoxContext)!;\n  let emptyState = renderEmptyState ? renderEmptyState() : null;\n  if (emptyState == null) {\n    return null;\n  }\n\n  return (\n    <div\n      // aria-selected isn't needed here since this option is not selectable.\n      // eslint-disable-next-line jsx-a11y/role-has-required-aria-props\n      role=\"option\">\n      {emptyState}\n    </div>\n  );\n}\n"],"names":[],"version":3,"file":"ListBoxBase.cjs.map"}