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AE;IACtC,IAAI,SAAC,KAAK,mBAAE,eAAe,WAAE,OAAO,UAAE,MAAM,EAAC,GAAG,CAAA,GAAA,yCAAiB;IAEjE,IAAI,aAAa,OAAO,UAAU;IAClC,IAAI,SAAS,CAAA,GAAA,aAAK,EAAE;IACpB,IAAI,UAAU,CAAA,GAAA,aAAK,EAA+B;IAClD,IAAI,eAAe,CAAA,GAAA,yCAAc,EAAE;IAEnC,IAAI,EAAC,UAAU,YAAY,EAAC,GAAG,CAAA,GAAA,iBAAS,EACtC;QACE,MAAM;QACN,eAAe;IACjB,GACA,OACA;IAGF,IAAI,iBAAC,aAAa,EAAC,GAAG,CAAA,GAAA,kBAAU,EAC9B;QACE,MAAM;QACN,WAAW;IACb,GACA,OACA;IAGF,iIAAiI;IACjI,IAAI,oBAAoB,MAAM,gBAAgB,CAAC,aAAa,KAAK;IACjE,IAAI,aAAa,CAAC,qBAAqB,MAAM,YAAY,CAAC,GAAG,CAAC,KAAK,GAAG;IAEtE,IAAI,YAAY,CAAA;QACd,IAAI,EAAE,GAAG,KAAK,OAAO,YACnB,EAAE,cAAc;IAEpB;IAEA,IAAI,WAAW,CAAA,GAAA,iBAAS,EAAE,cAAc;mBAAC;IAAS;IAElD,IAAI,eAAe,UAAU,eAAe,WAC1C,UAAU;IAGZ,IAAI,eAAe,QACjB,kBAAkB;IAGpB,wFAAwF;IACxF,oGAAoG;IACpG,sFAAsF;IACtF,OAAO,cAAc,gBAAgB;IACrC,qBACE,gCAAC;QAAK,GAAG,QAAQ;QAAE,KAAK;QAAQ,WAAW,CAAA,GAAA,yCAAS,EAAE,CAAA,GAAA,iDAAK,GAAG;qBAC5D,gCAAC,CAAA,GAAA,yCAAO;QACN,KAAK;QACL,cAAc;QACd,SAAS;QACT,aAAa;QACb,MAAM;QACN,QAAQ;OACP,KAAK,QAAQ;AAItB","sources":["packages/@adobe/react-spectrum/src/card/CardView.tsx"],"sourcesContent":["// @ts-nocheck\n/*\n * Copyright 2021 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 {CardBase} from './CardBase';\nimport {CardViewContext, useCardViewContext} from './CardViewContext';\nimport {classNames} from '../utils/classNames';\nimport {DOMRef, DOMRefValue, Node} from '@react-types/shared';\nimport {GridCollection} from 'react-stately/private/grid/GridCollection';\nimport intlMessages from '../../intl/card/*.json';\nimport {mergeProps} from 'react-aria/mergeProps';\nimport {ProgressCircle} from '../progress/ProgressCircle';\n// @ts-ignore\nimport React, {ReactElement, ReactNode, useCallback, useMemo, useRef} from 'react';\nimport {ReusableView} from 'react-stately/useVirtualizerState';\nimport {SpectrumCardViewProps} from './types';\nimport styles from '@adobe/spectrum-css-temp/components/card/vars.css';\nimport {useCollator} from 'react-aria/useCollator';\nimport {useDOMRef, useUnwrapDOMRef} from '../utils/useDOMRef';\nimport {useGrid} from 'react-aria/private/grid/useGrid';\nimport {useGridCell} from 'react-aria/private/grid/useGridCell';\nimport {useGridRow} from 'react-aria/private/grid/useGridRow';\nimport {useGridState} from 'react-stately/private/grid/useGridState';\nimport {useListState} from 'react-stately/useListState';\nimport {useLocale} from 'react-aria/I18nProvider';\nimport {useLocalizedStringFormatter} from 'react-aria/useLocalizedStringFormatter';\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\n/**\n * TODO: Add description of component here.\n */\nexport const CardView = React.forwardRef(function CardView<T extends object>(\n  props: SpectrumCardViewProps<T>,\n  ref: DOMRef<HTMLDivElement>\n) {\n  let {scale} = useProvider();\n  let {styleProps} = useStyleProps(props);\n  let domRef = useDOMRef(ref);\n  let {\n    isQuiet,\n    renderEmptyState,\n    layout,\n    loadingState,\n    onLoadMore,\n    cardOrientation = 'vertical'\n  } = props;\n\n  let collator = useCollator({usage: 'search', sensitivity: 'base'});\n  let isLoading = loadingState === 'loading' || loadingState === 'loadingMore';\n  let cardViewLayout = useMemo(\n    () => (typeof layout === 'function' ? new layout({collator, cardOrientation, scale}) : layout),\n    [layout, collator, cardOrientation, scale]\n  );\n  let layoutType = cardViewLayout.layoutType;\n\n  let {direction} = useLocale();\n  let {collection} = useListState(props);\n\n  let gridCollection = useMemo(\n    () =>\n      new GridCollection<T>({\n        columnCount: 1,\n        items: [...collection].map(item => ({\n          // Makes the Grid row use the keys the user provides to the cards so that selection change via interactions returns the card keys\n          ...item,\n          hasChildNodes: true,\n          childNodes: [\n            {\n              key: `cell-${item.key}`,\n              type: 'cell',\n              value: null,\n              level: 0,\n              rendered: null,\n              textValue: item.textValue,\n              hasChildNodes: false,\n              childNodes: []\n            }\n          ]\n        }))\n      }),\n    [collection]\n  );\n\n  let state = useGridState({\n    ...props,\n    selectionMode:\n      cardOrientation === 'horizontal' && layoutType === 'grid' ? 'none' : props.selectionMode,\n    collection: gridCollection,\n    focusMode: 'cell'\n  });\n\n  cardViewLayout.collection = gridCollection;\n  cardViewLayout.disabledKeys = state.disabledKeys;\n\n  let {gridProps} = useGrid(\n    {\n      ...props,\n      isVirtualized: true,\n      keyboardDelegate: cardViewLayout\n    },\n    state,\n    domRef\n  );\n\n  type View = ReusableView<Node<T>, ReactNode>;\n  let renderWrapper = useCallback(\n    (parent: View, reusableView: View) => (\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  let focusedKey = state.selectionManager.focusedKey;\n  let focusedItem = gridCollection.getItem(state.selectionManager.focusedKey);\n  if (focusedItem?.parentKey != null) {\n    focusedKey = focusedItem.parentKey;\n  }\n\n  let persistedKeys = useMemo(\n    () => (focusedKey != null ? new Set([focusedKey]) : null),\n    [focusedKey]\n  );\n\n  // TODO: does aria-row count and aria-col count need to be modified? Perhaps aria-col count needs to be omitted\n  return (\n    <CardViewContext.Provider\n      value={{state, isQuiet, layout: cardViewLayout, cardOrientation, renderEmptyState}}>\n      <Virtualizer\n        {...gridProps}\n        {...styleProps}\n        className={classNames(styles, 'spectrum-CardView')}\n        ref={domRef}\n        persistedKeys={persistedKeys}\n        scrollDirection=\"vertical\"\n        layout={cardViewLayout}\n        collection={gridCollection}\n        isLoading={isLoading}\n        onLoadMore={onLoadMore}\n        layoutOptions={useMemo(() => ({isLoading, direction}), [isLoading, direction])}\n        renderWrapper={renderWrapper}\n        style={{\n          ...styleProps.style,\n          scrollPaddingTop: cardViewLayout.margin || 0\n        }}>\n        {useCallback((type, item) => {\n          if (type === 'item') {\n            return <InternalCard item={item} />;\n          } else if (type === 'loader') {\n            return <LoadingState />;\n          } else if (type === 'placeholder') {\n            return <EmptyState />;\n          }\n        }, [])}\n      </Virtualizer>\n    </CardViewContext.Provider>\n  );\n}) as <T>(props: SpectrumCardViewProps<T> & {ref?: DOMRef<HTMLDivElement>}) => ReactElement;\n\nfunction LoadingState() {\n  let {state} = useCardViewContext();\n  let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/card');\n  return (\n    <CenteredWrapper>\n      <ProgressCircle\n        isIndeterminate\n        aria-label={\n          state.collection.size > 0\n            ? stringFormatter.format('loadingMore')\n            : stringFormatter.format('loading')\n        }\n      />\n    </CenteredWrapper>\n  );\n}\n\nfunction EmptyState() {\n  let {renderEmptyState} = useCardViewContext();\n  let emptyState = renderEmptyState ? renderEmptyState() : null;\n  if (emptyState == null) {\n    return null;\n  }\n\n  return <CenteredWrapper>{emptyState}</CenteredWrapper>;\n}\n\nfunction CenteredWrapper({children}) {\n  let {state} = useCardViewContext();\n  return (\n    <div\n      role=\"row\"\n      aria-rowindex={state.collection.size + 1}\n      className={classNames(styles, 'spectrum-CardView-centeredWrapper')}>\n      <div role=\"gridcell\">{children}</div>\n    </div>\n  );\n}\n\nfunction InternalCard(props) {\n  let {item} = props;\n  let cellNode = [...item.childNodes][0];\n  let {state, cardOrientation, isQuiet, layout} = useCardViewContext();\n\n  let layoutType = layout.layoutType;\n  let rowRef = useRef(undefined);\n  let cellRef = useRef<DOMRefValue<HTMLDivElement>>(undefined);\n  let unwrappedRef = useUnwrapDOMRef(cellRef);\n\n  let {rowProps: gridRowProps} = useGridRow(\n    {\n      node: item,\n      isVirtualized: true\n    },\n    state,\n    rowRef\n  );\n\n  let {gridCellProps} = useGridCell(\n    {\n      node: cellNode,\n      focusMode: 'cell'\n    },\n    state,\n    unwrappedRef\n  );\n\n  // Prevent space key from scrolling the CardView if triggered on a disabled item or on a Card in a selectionMode=\"none\" CardView.\n  let allowsInteraction = state.selectionManager.selectionMode !== 'none';\n  let isDisabled = !allowsInteraction || state.disabledKeys.has(item.key);\n\n  let onKeyDown = e => {\n    if (e.key === ' ' && isDisabled) {\n      e.preventDefault();\n    }\n  };\n\n  let rowProps = mergeProps(gridRowProps, {onKeyDown});\n\n  if (layoutType === 'grid' || layoutType === 'gallery') {\n    isQuiet = true;\n  }\n\n  if (layoutType !== 'grid') {\n    cardOrientation = 'vertical';\n  }\n\n  // We don't want to focus the checkbox (or any other focusable elements) within the Card\n  // when pressing the arrow keys so we delete the key down handler here. Arrow key navigation between\n  // the cards in the CardView is handled by useGrid => useSelectableCollection instead.\n  delete gridCellProps.onKeyDownCapture;\n  return (\n    <div {...rowProps} ref={rowRef} className={classNames(styles, 'spectrum-CardView-row')}>\n      <CardBase\n        ref={cellRef}\n        articleProps={gridCellProps}\n        isQuiet={isQuiet}\n        orientation={cardOrientation}\n        item={item}\n        layout={layoutType}>\n        {item.rendered}\n      </CardBase>\n    </div>\n  );\n}\n"],"names":[],"version":3,"file":"CardView.mjs.map"}