@react-spectrum/card 3.0.0-alpha.33 → 3.0.0-alpha.34

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.
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;;;AAqBD,SAAS,+BAA2B,KAA+B,EAAE,GAA2B;IAC9F,IAAI,SAAC,KAAK,EAAC,GAAG,CAAA,GAAA,wCAAU;IACxB,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,uCAAY,EAAE;IACjC,IAAI,SAAS,CAAA,GAAA,mCAAQ,EAAE;IACvB,IAAI,WACF,OAAO,oBACP,gBAAgB,UAChB,MAAM,gBACN,YAAY,cACZ,UAAU,mBACV,kBAAkB,YACnB,GAAG;IAEJ,IAAI,WAAW,CAAA,GAAA,gCAAU,EAAE;QAAC,OAAO;QAAU,aAAa;IAAM;IAChE,IAAI,YAAY,iBAAiB,aAAa,iBAAiB;IAC/D,IAAI,iBAAiB,CAAA,GAAA,oBAAM,EAAE,IAAM,OAAO,WAAW,aAAa,IAAI,OAAO;sBAAC;6BAAU;mBAAiB;QAAK,KAAK,QAAQ;QAAC;QAAQ;QAAU;QAAiB;KAAM;IACrK,IAAI,aAAa,eAAe,UAAU;IAE1C,IAAI,kBAAkB,CAAA,GAAA,gDAA0B,EAAE,CAAA,GAAA,mDAAW,GAAG;IAChE,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,8BAAQ;IAC1B,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,oCAAW,EAAE;IAEhC,IAAI,iBAAiB,CAAA,GAAA,oBAAM,EAAE,IAAM,IAAI,CAAA,GAAA,sCAAa,EAAK;YACvD,aAAa;YACb,OAAO;mBAAI;aAAW,CAAC,GAAG,CAAC,CAAA,OAAS,CAAA;oBAClC,iIAAiI;oBACjI,GAAG,IAAI;oBACP,eAAe;oBACf,Y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AAa,OAAO,UAAU;IAClC,IAAI,SAAS,CAAA,GAAA,mBAAK;IAClB,IAAI,UAAU,CAAA,GAAA,mBAAK;IACnB,IAAI,eAAe,CAAA,GAAA,yCAAc,EAAE;IAEnC,IAAI,EAAC,UAAU,YAAY,EAAC,GAAG,CAAA,GAAA,+BAAS,EAAE;QACxC,MAAM;QACN,eAAe;IACjB,GAAG,OAAO;IAEV,IAAI,iBAAC,aAAa,EAAC,GAAG,CAAA,GAAA,gCAAU,EAAE;QAChC,MAAM;QACN,WAAW;IACb,GAAG,OAAO;IAEV,iIAAiI;IACjI,IAAI,oBAAoB,MAAM,gBAAgB,CAAC,aAAa,KAAK;IACjE,IAAI,aAAa,CAAC,qBAAqB,MAAM,YAAY,CAAC,GAAG,CAAC,KAAK,GAAG;IAEtE,IAAI,YAAY,CAAC;QACf,IAAI,EAAE,GAAG,KAAK,OAAO,YACnB,EAAE,cAAc;IAEpB;IAEA,IAAI,WAAW,CAAA,GAAA,gCAAS,EACtB,cACA;mBAAC;IAAS;IAGZ,IAAI,eAAe,UAAU,eAAe,WAC1C,UAAU;IAGZ,IAAI,eAAe,QACjB,kBAAkB;IAGpB,wFAAwF;IACxF,oGAAoG;IACpG,sFAAsF;IACtF,OAAO,cAAc,gBAAgB;IACrC,qBACE,0DAAC;QAAK,GAAG,QAAQ;QAAE,KAAK;QAAQ,WAAW,CAAA,GAAA,oCAAS,EAAE,CAAA,GAAA,mDAAK,GAAG;qBAC5D,0DAAC,CAAA,GAAA,kCAAO;QACN,KAAK;QACL,cAAc;QACd,SAAS;QACT,aAAa;QACb,MAAM;QACN,QAAQ;OACP,KAAK,QAAQ;AAItB;AAEA;;CAEC,GACD,MAAM,0DAAY,CAAA,GAAA,sCAAI,EAAE,UAAU,CAAC","sources":["packages/@react-spectrum/card/src/CardView.tsx"],"sourcesContent":["/*\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, useDOMRef, useStyleProps, useUnwrapDOMRef} from '@react-spectrum/utils';\nimport {DOMRef, DOMRefValue, Node} from '@react-types/shared';\nimport {GridCollection, useGridState} from '@react-stately/grid';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {mergeProps} from '@react-aria/utils';\nimport {ProgressCircle} from '@react-spectrum/progress';\nimport React, {ReactElement, ReactNode, useCallback, useMemo, useRef} from 'react';\nimport {ReusableView} from '@react-stately/virtualizer';\nimport {SpectrumCardViewProps} from '@react-types/card';\nimport styles from '@adobe/spectrum-css-temp/components/card/vars.css';\nimport {useCollator, useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useGrid, useGridCell, useGridRow} from '@react-aria/grid';\nimport {useListState} from '@react-stately/list';\nimport {useProvider} from '@react-spectrum/provider';\nimport {Virtualizer, VirtualizerItem} from '@react-aria/virtualizer';\n\nfunction CardView<T extends object>(props: SpectrumCardViewProps<T>, ref: DOMRef<HTMLDivElement>) {\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(() => typeof layout === 'function' ? new layout({collator, cardOrientation, scale}) : layout, [layout, collator, cardOrientation, scale]);\n let layoutType = cardViewLayout.layoutType;\n\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/card');\n let {direction} = useLocale();\n let {collection} = useListState(props);\n\n let gridCollection = useMemo(() => 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 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 }), [collection]);\n\n let state = useGridState({\n ...props,\n selectionMode: 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 cardViewLayout.isLoading = isLoading;\n cardViewLayout.direction = direction;\n\n let {gridProps} = useGrid({\n ...props,\n isVirtualized: true,\n keyboardDelegate: cardViewLayout\n }, state, domRef);\n\n type View = ReusableView<Node<T>, ReactNode>;\n let renderWrapper = (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 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 margin = cardViewLayout.margin || 0;\n let virtualizer = cardViewLayout.virtualizer;\n let scrollToItem = useCallback((key) => {\n virtualizer && virtualizer.scrollToItem(key, {\n duration: 0,\n offsetY: margin\n });\n }, [margin, virtualizer]);\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 value={{state, isQuiet, layout: cardViewLayout, cardOrientation}}>\n <Virtualizer\n {...gridProps}\n {...styleProps}\n className={classNames(styles, 'spectrum-CardView')}\n ref={domRef}\n focusedKey={focusedKey}\n scrollDirection=\"vertical\"\n layout={cardViewLayout}\n collection={gridCollection}\n isLoading={isLoading}\n onLoadMore={onLoadMore}\n renderWrapper={renderWrapper}\n transitionDuration={isLoading ? 160 : 220}\n scrollToItem={scrollToItem}>\n {(type, item) => {\n if (type === 'item') {\n return (\n <InternalCard item={item} />\n );\n } else if (type === 'loader') {\n return (\n <CenteredWrapper>\n <ProgressCircle\n isIndeterminate\n aria-label={state.collection.size > 0 ? stringFormatter.format('loadingMore') : stringFormatter.format('loading')} />\n </CenteredWrapper>\n );\n } else if (type === 'placeholder') {\n let emptyState = renderEmptyState ? renderEmptyState() : null;\n if (emptyState == null) {\n return null;\n }\n\n return (\n <CenteredWrapper>\n {emptyState}\n </CenteredWrapper>\n );\n }\n }}\n </Virtualizer>\n </CardViewContext.Provider>\n\n );\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\">\n {children}\n </div>\n </div>\n );\n}\n\nfunction InternalCard(props) {\n let {\n item\n } = props;\n let cellNode = [...item.childNodes][0];\n let {state, cardOrientation, isQuiet, layout} = useCardViewContext();\n\n let layoutType = layout.layoutType;\n let rowRef = useRef();\n let cellRef = useRef<DOMRefValue<HTMLDivElement>>();\n let unwrappedRef = useUnwrapDOMRef(cellRef);\n\n let {rowProps: gridRowProps} = useGridRow({\n node: item,\n isVirtualized: true\n }, state, rowRef);\n\n let {gridCellProps} = useGridCell({\n node: cellNode,\n focusMode: 'cell'\n }, state, unwrappedRef);\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(\n gridRowProps,\n {onKeyDown}\n );\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\n/**\n * TODO: Add description of component here.\n */\nconst _CardView = React.forwardRef(CardView) as <T>(props: SpectrumCardViewProps<T> & {ref?: DOMRef<HTMLDivElement>}) => ReactElement;\nexport {_CardView as CardView};\n"],"names":[],"version":3,"file":"CardView.main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;;;AAqBD,SAAS,+BAA2B,KAA+B,EAAE,GAA2B;IAC9F,IAAI,SAAC,KAAK,EAAC,GAAG,CAAA,GAAA,wCAAU;IACxB,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,uCAAY,EAAE;IACjC,IAAI,SAAS,CAAA,GAAA,mCAAQ,EAAE;IACvB,IAAI,WACF,OAAO,oBACP,gBAAgB,UAChB,MAAM,gBACN,YAAY,cACZ,UAAU,mBACV,kBAAkB,YACnB,GAAG;IAEJ,IAAI,WAAW,CAAA,GAAA,gCAAU,EAAE;QAAC,OAAO;QAAU,aAAa;IAAM;IAChE,IAAI,YAAY,iBAAiB,aAAa,iBAAiB;IAC/D,IAAI,iBAAiB,CAAA,GAAA,oBAAM,EAAE,IAAM,OAAO,WAAW,aAAa,IAAI,OAAO;sBAAC;6BAAU;mBAAiB;QAAK,KAAK,QAAQ;QAAC;QAAQ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CAAC;QACf,IAAI,EAAE,GAAG,KAAK,OAAO,YACnB,EAAE,cAAc;IAEpB;IAEA,IAAI,WAAW,CAAA,GAAA,gCAAS,EACtB,cACA;mBAAC;IAAS;IAGZ,IAAI,eAAe,UAAU,eAAe,WAC1C,UAAU;IAGZ,IAAI,eAAe,QACjB,kBAAkB;IAGpB,wFAAwF;IACxF,oGAAoG;IACpG,sFAAsF;IACtF,OAAO,cAAc,gBAAgB;IACrC,qBACE,0DAAC;QAAK,GAAG,QAAQ;QAAE,KAAK;QAAQ,WAAW,CAAA,GAAA,oCAAS,EAAE,CAAA,GAAA,mDAAK,GAAG;qBAC5D,0DAAC,CAAA,GAAA,kCAAO;QACN,KAAK;QACL,cAAc;QACd,SAAS;QACT,aAAa;QACb,MAAM;QACN,QAAQ;OACP,KAAK,QAAQ;AAItB;AAEA;;CAEC,GACD,MAAM,0DAAY,CAAA,GAAA,sCAAI,EAAE,UAAU,CAAC","sources":["packages/@react-spectrum/card/src/CardView.tsx"],"sourcesContent":["/*\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, useDOMRef, useStyleProps, useUnwrapDOMRef} from '@react-spectrum/utils';\nimport {DOMRef, DOMRefValue, Node} from '@react-types/shared';\nimport {GridCollection, useGridState} from '@react-stately/grid';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {mergeProps} from '@react-aria/utils';\nimport {ProgressCircle} from '@react-spectrum/progress';\nimport React, {ReactElement, ReactNode, useCallback, useMemo, useRef} from 'react';\nimport {ReusableView} from '@react-stately/virtualizer';\nimport {SpectrumCardViewProps} from '@react-types/card';\nimport styles from '@adobe/spectrum-css-temp/components/card/vars.css';\nimport {useCollator, useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useGrid, useGridCell, useGridRow} from '@react-aria/grid';\nimport {useListState} from '@react-stately/list';\nimport {useProvider} from '@react-spectrum/provider';\nimport {Virtualizer, VirtualizerItem} from '@react-aria/virtualizer';\n\nfunction CardView<T extends object>(props: SpectrumCardViewProps<T>, ref: DOMRef<HTMLDivElement>) {\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(() => typeof layout === 'function' ? new layout({collator, cardOrientation, scale}) : layout, [layout, collator, cardOrientation, scale]);\n let layoutType = cardViewLayout.layoutType;\n\n let {direction} = useLocale();\n let {collection} = useListState(props);\n\n let gridCollection = useMemo(() => 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 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 }), [collection]);\n\n let state = useGridState({\n ...props,\n selectionMode: 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 ...props,\n isVirtualized: true,\n keyboardDelegate: cardViewLayout\n }, state, domRef);\n\n type View = ReusableView<Node<T>, ReactNode>;\n let renderWrapper = useCallback((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 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(() => focusedKey != null ? new Set([focusedKey]) : null, [focusedKey]);\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 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 (\n <InternalCard item={item} />\n );\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 );\n}\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={state.collection.size > 0 ? stringFormatter.format('loadingMore') : stringFormatter.format('loading')} />\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 (\n <CenteredWrapper>\n {emptyState}\n </CenteredWrapper>\n );\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\">\n {children}\n </div>\n </div>\n );\n}\n\nfunction InternalCard(props) {\n let {\n item\n } = 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 node: item,\n isVirtualized: true\n }, state, rowRef);\n\n let {gridCellProps} = useGridCell({\n node: cellNode,\n focusMode: 'cell'\n }, state, unwrappedRef);\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(\n gridRowProps,\n {onKeyDown}\n );\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\n/**\n * TODO: Add description of component here.\n */\nconst _CardView = React.forwardRef(CardView) as <T>(props: SpectrumCardViewProps<T> & {ref?: DOMRef<HTMLDivElement>}) => ReactElement;\nexport {_CardView as CardView};\n"],"names":[],"version":3,"file":"CardView.main.js.map"}
package/dist/CardView.mjs CHANGED
@@ -8,7 +8,7 @@ import {GridCollection as $iOsT7$GridCollection, useGridState as $iOsT7$useGridS
8
8
  import {mergeProps as $iOsT7$mergeProps} from "@react-aria/utils";
9
9
  import {ProgressCircle as $iOsT7$ProgressCircle} from "@react-spectrum/progress";
10
10
  import $iOsT7$react, {useMemo as $iOsT7$useMemo, useCallback as $iOsT7$useCallback, useRef as $iOsT7$useRef} from "react";
11
- import {useCollator as $iOsT7$useCollator, useLocalizedStringFormatter as $iOsT7$useLocalizedStringFormatter, useLocale as $iOsT7$useLocale} from "@react-aria/i18n";
11
+ import {useCollator as $iOsT7$useCollator, useLocale as $iOsT7$useLocale, useLocalizedStringFormatter as $iOsT7$useLocalizedStringFormatter} from "@react-aria/i18n";
12
12
  import {useGrid as $iOsT7$useGrid, useGridRow as $iOsT7$useGridRow, useGridCell as $iOsT7$useGridCell} from "@react-aria/grid";
13
13
  import {useListState as $iOsT7$useListState} from "@react-stately/list";
14
14
  import {useProvider as $iOsT7$useProvider} from "@react-spectrum/provider";
@@ -63,7 +63,6 @@ function $81a52da995c19652$var$CardView(props, ref) {
63
63
  scale
64
64
  ]);
65
65
  let layoutType = cardViewLayout.layoutType;
66
- let stringFormatter = (0, $iOsT7$useLocalizedStringFormatter)((0, ($parcel$interopDefault($iOsT7$intlStringsmodulejs))), '@react-spectrum/card');
67
66
  let { direction: direction } = (0, $iOsT7$useLocale)();
68
67
  let { collection: collection } = (0, $iOsT7$useListState)(props);
69
68
  let gridCollection = (0, $iOsT7$useMemo)(()=>new (0, $iOsT7$GridCollection)({
@@ -98,32 +97,24 @@ function $81a52da995c19652$var$CardView(props, ref) {
98
97
  });
99
98
  cardViewLayout.collection = gridCollection;
100
99
  cardViewLayout.disabledKeys = state.disabledKeys;
101
- cardViewLayout.isLoading = isLoading;
102
- cardViewLayout.direction = direction;
103
100
  let { gridProps: gridProps } = (0, $iOsT7$useGrid)({
104
101
  ...props,
105
102
  isVirtualized: true,
106
103
  keyboardDelegate: cardViewLayout
107
104
  }, state, domRef);
108
- let renderWrapper = (parent, reusableView)=>/*#__PURE__*/ (0, $iOsT7$react).createElement((0, $iOsT7$VirtualizerItem), {
105
+ let renderWrapper = (0, $iOsT7$useCallback)((parent, reusableView)=>/*#__PURE__*/ (0, $iOsT7$react).createElement((0, $iOsT7$VirtualizerItem), {
109
106
  key: reusableView.key,
110
107
  layoutInfo: reusableView.layoutInfo,
111
108
  virtualizer: reusableView.virtualizer,
112
109
  parent: parent === null || parent === void 0 ? void 0 : parent.layoutInfo
113
- }, reusableView.rendered);
110
+ }, reusableView.rendered), []);
114
111
  let focusedKey = state.selectionManager.focusedKey;
115
112
  let focusedItem = gridCollection.getItem(state.selectionManager.focusedKey);
116
113
  if ((focusedItem === null || focusedItem === void 0 ? void 0 : focusedItem.parentKey) != null) focusedKey = focusedItem.parentKey;
117
- let margin = cardViewLayout.margin || 0;
118
- let virtualizer = cardViewLayout.virtualizer;
119
- let scrollToItem = (0, $iOsT7$useCallback)((key)=>{
120
- virtualizer && virtualizer.scrollToItem(key, {
121
- duration: 0,
122
- offsetY: margin
123
- });
124
- }, [
125
- margin,
126
- virtualizer
114
+ let persistedKeys = (0, $iOsT7$useMemo)(()=>focusedKey != null ? new Set([
115
+ focusedKey
116
+ ]) : null, [
117
+ focusedKey
127
118
  ]);
128
119
  // TODO: does aria-row count and aria-col count need to be modified? Perhaps aria-col count needs to be omitted
129
120
  return /*#__PURE__*/ (0, $iOsT7$react).createElement((0, $8d180a244893de14$export$64992ac69f286e5c).Provider, {
@@ -131,37 +122,54 @@ function $81a52da995c19652$var$CardView(props, ref) {
131
122
  state: state,
132
123
  isQuiet: isQuiet,
133
124
  layout: cardViewLayout,
134
- cardOrientation: cardOrientation
125
+ cardOrientation: cardOrientation,
126
+ renderEmptyState: renderEmptyState
135
127
  }
136
128
  }, /*#__PURE__*/ (0, $iOsT7$react).createElement((0, $iOsT7$Virtualizer), {
137
129
  ...gridProps,
138
130
  ...styleProps,
139
131
  className: (0, $iOsT7$classNames)((0, ($parcel$interopDefault($iOsT7$card_vars_cssmodulejs))), 'spectrum-CardView'),
140
132
  ref: domRef,
141
- focusedKey: focusedKey,
133
+ persistedKeys: persistedKeys,
142
134
  scrollDirection: "vertical",
143
135
  layout: cardViewLayout,
144
136
  collection: gridCollection,
145
137
  isLoading: isLoading,
146
138
  onLoadMore: onLoadMore,
139
+ layoutOptions: (0, $iOsT7$useMemo)(()=>({
140
+ isLoading: isLoading,
141
+ direction: direction
142
+ }), [
143
+ isLoading,
144
+ direction
145
+ ]),
147
146
  renderWrapper: renderWrapper,
148
- transitionDuration: isLoading ? 160 : 220,
149
- scrollToItem: scrollToItem
150
- }, (type, item)=>{
147
+ style: {
148
+ ...styleProps.style,
149
+ scrollPaddingTop: cardViewLayout.margin || 0
150
+ }
151
+ }, (0, $iOsT7$useCallback)((type, item)=>{
151
152
  if (type === 'item') return /*#__PURE__*/ (0, $iOsT7$react).createElement($81a52da995c19652$var$InternalCard, {
152
153
  item: item
153
154
  });
154
- else if (type === 'loader') return /*#__PURE__*/ (0, $iOsT7$react).createElement($81a52da995c19652$var$CenteredWrapper, null, /*#__PURE__*/ (0, $iOsT7$react).createElement((0, $iOsT7$ProgressCircle), {
155
- isIndeterminate: true,
156
- "aria-label": state.collection.size > 0 ? stringFormatter.format('loadingMore') : stringFormatter.format('loading')
157
- }));
158
- else if (type === 'placeholder') {
159
- let emptyState = renderEmptyState ? renderEmptyState() : null;
160
- if (emptyState == null) return null;
161
- return /*#__PURE__*/ (0, $iOsT7$react).createElement($81a52da995c19652$var$CenteredWrapper, null, emptyState);
162
- }
155
+ else if (type === 'loader') return /*#__PURE__*/ (0, $iOsT7$react).createElement($81a52da995c19652$var$LoadingState, null);
156
+ else if (type === 'placeholder') return /*#__PURE__*/ (0, $iOsT7$react).createElement($81a52da995c19652$var$EmptyState, null);
157
+ }, [])));
158
+ }
159
+ function $81a52da995c19652$var$LoadingState() {
160
+ let { state: state } = (0, $8d180a244893de14$export$fea0b38586ec8f13)();
161
+ let stringFormatter = (0, $iOsT7$useLocalizedStringFormatter)((0, ($parcel$interopDefault($iOsT7$intlStringsmodulejs))), '@react-spectrum/card');
162
+ return /*#__PURE__*/ (0, $iOsT7$react).createElement($81a52da995c19652$var$CenteredWrapper, null, /*#__PURE__*/ (0, $iOsT7$react).createElement((0, $iOsT7$ProgressCircle), {
163
+ isIndeterminate: true,
164
+ "aria-label": state.collection.size > 0 ? stringFormatter.format('loadingMore') : stringFormatter.format('loading')
163
165
  }));
164
166
  }
167
+ function $81a52da995c19652$var$EmptyState() {
168
+ let { renderEmptyState: renderEmptyState } = (0, $8d180a244893de14$export$fea0b38586ec8f13)();
169
+ let emptyState = renderEmptyState ? renderEmptyState() : null;
170
+ if (emptyState == null) return null;
171
+ return /*#__PURE__*/ (0, $iOsT7$react).createElement($81a52da995c19652$var$CenteredWrapper, null, emptyState);
172
+ }
165
173
  function $81a52da995c19652$var$CenteredWrapper({ children: children }) {
166
174
  let { state: state } = (0, $8d180a244893de14$export$fea0b38586ec8f13)();
167
175
  return /*#__PURE__*/ (0, $iOsT7$react).createElement("div", {
@@ -179,8 +187,8 @@ function $81a52da995c19652$var$InternalCard(props) {
179
187
  ][0];
180
188
  let { state: state, cardOrientation: cardOrientation, isQuiet: isQuiet, layout: layout } = (0, $8d180a244893de14$export$fea0b38586ec8f13)();
181
189
  let layoutType = layout.layoutType;
182
- let rowRef = (0, $iOsT7$useRef)();
183
- let cellRef = (0, $iOsT7$useRef)();
190
+ let rowRef = (0, $iOsT7$useRef)(undefined);
191
+ let cellRef = (0, $iOsT7$useRef)(undefined);
184
192
  let unwrappedRef = (0, $iOsT7$useUnwrapDOMRef)(cellRef);
185
193
  let { rowProps: gridRowProps } = (0, $iOsT7$useGridRow)({
186
194
  node: item,
@@ -8,7 +8,7 @@ import {GridCollection as $iOsT7$GridCollection, useGridState as $iOsT7$useGridS
8
8
  import {mergeProps as $iOsT7$mergeProps} from "@react-aria/utils";
9
9
  import {ProgressCircle as $iOsT7$ProgressCircle} from "@react-spectrum/progress";
10
10
  import $iOsT7$react, {useMemo as $iOsT7$useMemo, useCallback as $iOsT7$useCallback, useRef as $iOsT7$useRef} from "react";
11
- import {useCollator as $iOsT7$useCollator, useLocalizedStringFormatter as $iOsT7$useLocalizedStringFormatter, useLocale as $iOsT7$useLocale} from "@react-aria/i18n";
11
+ import {useCollator as $iOsT7$useCollator, useLocale as $iOsT7$useLocale, useLocalizedStringFormatter as $iOsT7$useLocalizedStringFormatter} from "@react-aria/i18n";
12
12
  import {useGrid as $iOsT7$useGrid, useGridRow as $iOsT7$useGridRow, useGridCell as $iOsT7$useGridCell} from "@react-aria/grid";
13
13
  import {useListState as $iOsT7$useListState} from "@react-stately/list";
14
14
  import {useProvider as $iOsT7$useProvider} from "@react-spectrum/provider";
@@ -63,7 +63,6 @@ function $81a52da995c19652$var$CardView(props, ref) {
63
63
  scale
64
64
  ]);
65
65
  let layoutType = cardViewLayout.layoutType;
66
- let stringFormatter = (0, $iOsT7$useLocalizedStringFormatter)((0, ($parcel$interopDefault($iOsT7$intlStringsmodulejs))), '@react-spectrum/card');
67
66
  let { direction: direction } = (0, $iOsT7$useLocale)();
68
67
  let { collection: collection } = (0, $iOsT7$useListState)(props);
69
68
  let gridCollection = (0, $iOsT7$useMemo)(()=>new (0, $iOsT7$GridCollection)({
@@ -98,32 +97,24 @@ function $81a52da995c19652$var$CardView(props, ref) {
98
97
  });
99
98
  cardViewLayout.collection = gridCollection;
100
99
  cardViewLayout.disabledKeys = state.disabledKeys;
101
- cardViewLayout.isLoading = isLoading;
102
- cardViewLayout.direction = direction;
103
100
  let { gridProps: gridProps } = (0, $iOsT7$useGrid)({
104
101
  ...props,
105
102
  isVirtualized: true,
106
103
  keyboardDelegate: cardViewLayout
107
104
  }, state, domRef);
108
- let renderWrapper = (parent, reusableView)=>/*#__PURE__*/ (0, $iOsT7$react).createElement((0, $iOsT7$VirtualizerItem), {
105
+ let renderWrapper = (0, $iOsT7$useCallback)((parent, reusableView)=>/*#__PURE__*/ (0, $iOsT7$react).createElement((0, $iOsT7$VirtualizerItem), {
109
106
  key: reusableView.key,
110
107
  layoutInfo: reusableView.layoutInfo,
111
108
  virtualizer: reusableView.virtualizer,
112
109
  parent: parent === null || parent === void 0 ? void 0 : parent.layoutInfo
113
- }, reusableView.rendered);
110
+ }, reusableView.rendered), []);
114
111
  let focusedKey = state.selectionManager.focusedKey;
115
112
  let focusedItem = gridCollection.getItem(state.selectionManager.focusedKey);
116
113
  if ((focusedItem === null || focusedItem === void 0 ? void 0 : focusedItem.parentKey) != null) focusedKey = focusedItem.parentKey;
117
- let margin = cardViewLayout.margin || 0;
118
- let virtualizer = cardViewLayout.virtualizer;
119
- let scrollToItem = (0, $iOsT7$useCallback)((key)=>{
120
- virtualizer && virtualizer.scrollToItem(key, {
121
- duration: 0,
122
- offsetY: margin
123
- });
124
- }, [
125
- margin,
126
- virtualizer
114
+ let persistedKeys = (0, $iOsT7$useMemo)(()=>focusedKey != null ? new Set([
115
+ focusedKey
116
+ ]) : null, [
117
+ focusedKey
127
118
  ]);
128
119
  // TODO: does aria-row count and aria-col count need to be modified? Perhaps aria-col count needs to be omitted
129
120
  return /*#__PURE__*/ (0, $iOsT7$react).createElement((0, $8d180a244893de14$export$64992ac69f286e5c).Provider, {
@@ -131,37 +122,54 @@ function $81a52da995c19652$var$CardView(props, ref) {
131
122
  state: state,
132
123
  isQuiet: isQuiet,
133
124
  layout: cardViewLayout,
134
- cardOrientation: cardOrientation
125
+ cardOrientation: cardOrientation,
126
+ renderEmptyState: renderEmptyState
135
127
  }
136
128
  }, /*#__PURE__*/ (0, $iOsT7$react).createElement((0, $iOsT7$Virtualizer), {
137
129
  ...gridProps,
138
130
  ...styleProps,
139
131
  className: (0, $iOsT7$classNames)((0, ($parcel$interopDefault($iOsT7$card_vars_cssmodulejs))), 'spectrum-CardView'),
140
132
  ref: domRef,
141
- focusedKey: focusedKey,
133
+ persistedKeys: persistedKeys,
142
134
  scrollDirection: "vertical",
143
135
  layout: cardViewLayout,
144
136
  collection: gridCollection,
145
137
  isLoading: isLoading,
146
138
  onLoadMore: onLoadMore,
139
+ layoutOptions: (0, $iOsT7$useMemo)(()=>({
140
+ isLoading: isLoading,
141
+ direction: direction
142
+ }), [
143
+ isLoading,
144
+ direction
145
+ ]),
147
146
  renderWrapper: renderWrapper,
148
- transitionDuration: isLoading ? 160 : 220,
149
- scrollToItem: scrollToItem
150
- }, (type, item)=>{
147
+ style: {
148
+ ...styleProps.style,
149
+ scrollPaddingTop: cardViewLayout.margin || 0
150
+ }
151
+ }, (0, $iOsT7$useCallback)((type, item)=>{
151
152
  if (type === 'item') return /*#__PURE__*/ (0, $iOsT7$react).createElement($81a52da995c19652$var$InternalCard, {
152
153
  item: item
153
154
  });
154
- else if (type === 'loader') return /*#__PURE__*/ (0, $iOsT7$react).createElement($81a52da995c19652$var$CenteredWrapper, null, /*#__PURE__*/ (0, $iOsT7$react).createElement((0, $iOsT7$ProgressCircle), {
155
- isIndeterminate: true,
156
- "aria-label": state.collection.size > 0 ? stringFormatter.format('loadingMore') : stringFormatter.format('loading')
157
- }));
158
- else if (type === 'placeholder') {
159
- let emptyState = renderEmptyState ? renderEmptyState() : null;
160
- if (emptyState == null) return null;
161
- return /*#__PURE__*/ (0, $iOsT7$react).createElement($81a52da995c19652$var$CenteredWrapper, null, emptyState);
162
- }
155
+ else if (type === 'loader') return /*#__PURE__*/ (0, $iOsT7$react).createElement($81a52da995c19652$var$LoadingState, null);
156
+ else if (type === 'placeholder') return /*#__PURE__*/ (0, $iOsT7$react).createElement($81a52da995c19652$var$EmptyState, null);
157
+ }, [])));
158
+ }
159
+ function $81a52da995c19652$var$LoadingState() {
160
+ let { state: state } = (0, $8d180a244893de14$export$fea0b38586ec8f13)();
161
+ let stringFormatter = (0, $iOsT7$useLocalizedStringFormatter)((0, ($parcel$interopDefault($iOsT7$intlStringsmodulejs))), '@react-spectrum/card');
162
+ return /*#__PURE__*/ (0, $iOsT7$react).createElement($81a52da995c19652$var$CenteredWrapper, null, /*#__PURE__*/ (0, $iOsT7$react).createElement((0, $iOsT7$ProgressCircle), {
163
+ isIndeterminate: true,
164
+ "aria-label": state.collection.size > 0 ? stringFormatter.format('loadingMore') : stringFormatter.format('loading')
163
165
  }));
164
166
  }
167
+ function $81a52da995c19652$var$EmptyState() {
168
+ let { renderEmptyState: renderEmptyState } = (0, $8d180a244893de14$export$fea0b38586ec8f13)();
169
+ let emptyState = renderEmptyState ? renderEmptyState() : null;
170
+ if (emptyState == null) return null;
171
+ return /*#__PURE__*/ (0, $iOsT7$react).createElement($81a52da995c19652$var$CenteredWrapper, null, emptyState);
172
+ }
165
173
  function $81a52da995c19652$var$CenteredWrapper({ children: children }) {
166
174
  let { state: state } = (0, $8d180a244893de14$export$fea0b38586ec8f13)();
167
175
  return /*#__PURE__*/ (0, $iOsT7$react).createElement("div", {
@@ -179,8 +187,8 @@ function $81a52da995c19652$var$InternalCard(props) {
179
187
  ][0];
180
188
  let { state: state, cardOrientation: cardOrientation, isQuiet: isQuiet, layout: layout } = (0, $8d180a244893de14$export$fea0b38586ec8f13)();
181
189
  let layoutType = layout.layoutType;
182
- let rowRef = (0, $iOsT7$useRef)();
183
- let cellRef = (0, $iOsT7$useRef)();
190
+ let rowRef = (0, $iOsT7$useRef)(undefined);
191
+ let cellRef = (0, $iOsT7$useRef)(undefined);
184
192
  let unwrappedRef = (0, $iOsT7$useUnwrapDOMRef)(cellRef);
185
193
  let { rowProps: gridRowProps } = (0, $iOsT7$useGridRow)({
186
194
  node: item,
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;;;AAqBD,SAAS,+BAA2B,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,IAAI,iBAAC,aAAa,EAAC,GAAG,CAAA,GAAA,kBAAU,EAAE;QAChC,MAAM;QACN,WAAW;IACb,GAAG,OAAO;IAEV,iIAAiI;IACjI,IAAI,oBAAoB,MAAM,gBAAgB,CAAC,aAAa,KAAK;IACjE,IAAI,aAAa,CAAC,qBAAqB,MAAM,YAAY,CAAC,GAAG,CAAC,KAAK,GAAG;IAEtE,IAAI,YAAY,CAAC;QACf,IAAI,EAAE,GAAG,KAAK,OAAO,YACnB,EAAE,cAAc;IAEpB;IAEA,IAAI,WAAW,CAAA,GAAA,iBAAS,EACtB,cACA;mBAAC;IAAS;IAGZ,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,iBAAS,EAAE,CAAA,GAAA,sDAAK,GAAG;qBAC5D,gCAAC,CAAA,GAAA,yCAAO;QACN,KAAK;QACL,cAAc;QACd,SAAS;QACT,aAAa;QACb,MAAM;QACN,QAAQ;OACP,KAAK,QAAQ;AAItB;AAEA;;CAEC,GACD,MAAM,0DAAY,CAAA,GAAA,YAAI,EAAE,UAAU,CAAC","sources":["packages/@react-spectrum/card/src/CardView.tsx"],"sourcesContent":["/*\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, useDOMRef, useStyleProps, useUnwrapDOMRef} from '@react-spectrum/utils';\nimport {DOMRef, DOMRefValue, Node} from '@react-types/shared';\nimport {GridCollection, useGridState} from '@react-stately/grid';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {mergeProps} from '@react-aria/utils';\nimport {ProgressCircle} from '@react-spectrum/progress';\nimport React, {ReactElement, ReactNode, useCallback, useMemo, useRef} from 'react';\nimport {ReusableView} from '@react-stately/virtualizer';\nimport {SpectrumCardViewProps} from '@react-types/card';\nimport styles from '@adobe/spectrum-css-temp/components/card/vars.css';\nimport {useCollator, useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useGrid, useGridCell, useGridRow} from '@react-aria/grid';\nimport {useListState} from '@react-stately/list';\nimport {useProvider} from '@react-spectrum/provider';\nimport {Virtualizer, VirtualizerItem} from '@react-aria/virtualizer';\n\nfunction CardView<T extends object>(props: SpectrumCardViewProps<T>, ref: DOMRef<HTMLDivElement>) {\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(() => typeof layout === 'function' ? new layout({collator, cardOrientation, scale}) : layout, [layout, collator, cardOrientation, scale]);\n let layoutType = cardViewLayout.layoutType;\n\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/card');\n let {direction} = useLocale();\n let {collection} = useListState(props);\n\n let gridCollection = useMemo(() => 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 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 }), [collection]);\n\n let state = useGridState({\n ...props,\n selectionMode: 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 cardViewLayout.isLoading = isLoading;\n cardViewLayout.direction = direction;\n\n let {gridProps} = useGrid({\n ...props,\n isVirtualized: true,\n keyboardDelegate: cardViewLayout\n }, state, domRef);\n\n type View = ReusableView<Node<T>, ReactNode>;\n let renderWrapper = (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 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 margin = cardViewLayout.margin || 0;\n let virtualizer = cardViewLayout.virtualizer;\n let scrollToItem = useCallback((key) => {\n virtualizer && virtualizer.scrollToItem(key, {\n duration: 0,\n offsetY: margin\n });\n }, [margin, virtualizer]);\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 value={{state, isQuiet, layout: cardViewLayout, cardOrientation}}>\n <Virtualizer\n {...gridProps}\n {...styleProps}\n className={classNames(styles, 'spectrum-CardView')}\n ref={domRef}\n focusedKey={focusedKey}\n scrollDirection=\"vertical\"\n layout={cardViewLayout}\n collection={gridCollection}\n isLoading={isLoading}\n onLoadMore={onLoadMore}\n renderWrapper={renderWrapper}\n transitionDuration={isLoading ? 160 : 220}\n scrollToItem={scrollToItem}>\n {(type, item) => {\n if (type === 'item') {\n return (\n <InternalCard item={item} />\n );\n } else if (type === 'loader') {\n return (\n <CenteredWrapper>\n <ProgressCircle\n isIndeterminate\n aria-label={state.collection.size > 0 ? stringFormatter.format('loadingMore') : stringFormatter.format('loading')} />\n </CenteredWrapper>\n );\n } else if (type === 'placeholder') {\n let emptyState = renderEmptyState ? renderEmptyState() : null;\n if (emptyState == null) {\n return null;\n }\n\n return (\n <CenteredWrapper>\n {emptyState}\n </CenteredWrapper>\n );\n }\n }}\n </Virtualizer>\n </CardViewContext.Provider>\n\n );\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\">\n {children}\n </div>\n </div>\n );\n}\n\nfunction InternalCard(props) {\n let {\n item\n } = props;\n let cellNode = [...item.childNodes][0];\n let {state, cardOrientation, isQuiet, layout} = useCardViewContext();\n\n let layoutType = layout.layoutType;\n let rowRef = useRef();\n let cellRef = useRef<DOMRefValue<HTMLDivElement>>();\n let unwrappedRef = useUnwrapDOMRef(cellRef);\n\n let {rowProps: gridRowProps} = useGridRow({\n node: item,\n isVirtualized: true\n }, state, rowRef);\n\n let {gridCellProps} = useGridCell({\n node: cellNode,\n focusMode: 'cell'\n }, state, unwrappedRef);\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(\n gridRowProps,\n {onKeyDown}\n );\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\n/**\n * TODO: Add description of component here.\n */\nconst _CardView = React.forwardRef(CardView) as <T>(props: SpectrumCardViewProps<T> & {ref?: DOMRef<HTMLDivElement>}) => ReactElement;\nexport {_CardView as CardView};\n"],"names":[],"version":3,"file":"CardView.module.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;;;AAqBD,SAAS,+BAA2B,KAA+B,EAAE,GAA2B;IAC9F,IAAI,SAAC,KAAK,EAAC,GAAG,CAAA,GAAA,kBAAU;IACxB,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,oBAAY,EAAE;IACjC,IAAI,SAAS,CAAA,GAAA,gBAAQ,EAAE;IACvB,IAAI,WACF,OAAO,oBACP,gBAAgB,UAChB,MAAM,gBACN,YAAY,cACZ,UAAU,mBACV,kBAAkB,YACnB,GAAG;IAEJ,IAAI,WAAW,CAAA,GAAA,kBAAU,EAAE;QAAC,OAAO;QAAU,aAAa;IAAM;IAChE,IAAI,YAAY,iBAAiB,aAAa,iBAAiB;IAC/D,IAAI,iBAAiB,CAAA,GAAA,cAAM,EAAE,IAAM,OAAO,WAAW,aAAa,IAAI,OAAO;sBAAC;6BAAU;mBAAiB;QAAK,KAAK,QAAQ;QAAC;QAAQ;QAAU;QAAiB;KAAM;IACrK,IAAI,aAAa,eAAe,UAAU;IAE1C,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAC1B,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,mBAAW,EAAE;IAEhC,IAAI,iBAAiB,CAAA,GAAA,cAAM,EAAE,IAAM,IAAI,CAAA,GAAA,qBAAa,EAAK;YACv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c,gBAAgB;IACrC,qBACE,gCAAC;QAAK,GAAG,QAAQ;QAAE,KAAK;QAAQ,WAAW,CAAA,GAAA,iBAAS,EAAE,CAAA,GAAA,sDAAK,GAAG;qBAC5D,gCAAC,CAAA,GAAA,yCAAO;QACN,KAAK;QACL,cAAc;QACd,SAAS;QACT,aAAa;QACb,MAAM;QACN,QAAQ;OACP,KAAK,QAAQ;AAItB;AAEA;;CAEC,GACD,MAAM,0DAAY,CAAA,GAAA,YAAI,EAAE,UAAU,CAAC","sources":["packages/@react-spectrum/card/src/CardView.tsx"],"sourcesContent":["/*\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, useDOMRef, useStyleProps, useUnwrapDOMRef} from '@react-spectrum/utils';\nimport {DOMRef, DOMRefValue, Node} from '@react-types/shared';\nimport {GridCollection, useGridState} from '@react-stately/grid';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {mergeProps} from '@react-aria/utils';\nimport {ProgressCircle} from '@react-spectrum/progress';\nimport React, {ReactElement, ReactNode, useCallback, useMemo, useRef} from 'react';\nimport {ReusableView} from '@react-stately/virtualizer';\nimport {SpectrumCardViewProps} from '@react-types/card';\nimport styles from '@adobe/spectrum-css-temp/components/card/vars.css';\nimport {useCollator, useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useGrid, useGridCell, useGridRow} from '@react-aria/grid';\nimport {useListState} from '@react-stately/list';\nimport {useProvider} from '@react-spectrum/provider';\nimport {Virtualizer, VirtualizerItem} from '@react-aria/virtualizer';\n\nfunction CardView<T extends object>(props: SpectrumCardViewProps<T>, ref: DOMRef<HTMLDivElement>) {\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(() => typeof layout === 'function' ? new layout({collator, cardOrientation, scale}) : layout, [layout, collator, cardOrientation, scale]);\n let layoutType = cardViewLayout.layoutType;\n\n let {direction} = useLocale();\n let {collection} = useListState(props);\n\n let gridCollection = useMemo(() => 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 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 }), [collection]);\n\n let state = useGridState({\n ...props,\n selectionMode: 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 ...props,\n isVirtualized: true,\n keyboardDelegate: cardViewLayout\n }, state, domRef);\n\n type View = ReusableView<Node<T>, ReactNode>;\n let renderWrapper = useCallback((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 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(() => focusedKey != null ? new Set([focusedKey]) : null, [focusedKey]);\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 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 (\n <InternalCard item={item} />\n );\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 );\n}\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={state.collection.size > 0 ? stringFormatter.format('loadingMore') : stringFormatter.format('loading')} />\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 (\n <CenteredWrapper>\n {emptyState}\n </CenteredWrapper>\n );\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\">\n {children}\n </div>\n </div>\n );\n}\n\nfunction InternalCard(props) {\n let {\n item\n } = 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 node: item,\n isVirtualized: true\n }, state, rowRef);\n\n let {gridCellProps} = useGridCell({\n node: cellNode,\n focusMode: 'cell'\n }, state, unwrappedRef);\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(\n gridRowProps,\n {onKeyDown}\n );\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\n/**\n * TODO: Add description of component here.\n */\nconst _CardView = React.forwardRef(CardView) as <T>(props: SpectrumCardViewProps<T> & {ref?: DOMRef<HTMLDivElement>}) => ReactElement;\nexport {_CardView as CardView};\n"],"names":[],"version":3,"file":"CardView.module.js.map"}
@@ -64,30 +64,6 @@ class $71b727f94b595b1a$export$7d2b12578154a735 extends (0, $5ee605f09afaa4de$ex
64
64
  let itemWidth = this.itemSize.width + this.horizontalSpacing;
65
65
  return Math.max(0, Math.min(this.collection.size - (allowInsertingAtEnd ? 0 : 1), Math.floor(y / itemHeight) * this.numColumns + Math.floor((x - this.horizontalSpacing) / itemWidth)));
66
66
  }
67
- getVisibleLayoutInfos(rect) {
68
- let res = [];
69
- let numItems = this.collection.size;
70
- if (numItems <= 0 || !this.itemSize) // If there aren't any items in the collection, we are in a loader/placeholder state. Return those layoutInfos as
71
- // the currently visible items
72
- {
73
- if (this.layoutInfos.size > 0) {
74
- for (let layoutInfo of this.layoutInfos.values())if (this.isVisible(layoutInfo, rect)) res.push(layoutInfo);
75
- }
76
- } else {
77
- // The approach from v2 uses indexes where other v3 layouts iterate through every node/root node. This feels more efficient
78
- let firstVisibleItem = this.getIndexAtPoint(rect.x, rect.y);
79
- let lastVisibleItem = this.getIndexAtPoint(rect.maxX, rect.maxY);
80
- for(let index = firstVisibleItem; index <= lastVisibleItem; index++){
81
- let keyFromIndex = this.collection.rows[index].key;
82
- let layoutInfo = this.layoutInfos.get(keyFromIndex);
83
- if (layoutInfo && this.isVisible(layoutInfo, rect)) res.push(layoutInfo);
84
- }
85
- // Check if loader is in view and add to res if so
86
- let loader = this.layoutInfos.get('loader');
87
- if (loader && this.isVisible(loader, rect)) res.push(loader);
88
- }
89
- return res;
90
- }
91
67
  buildCollection() {
92
68
  let visibleWidth = this.virtualizer.visibleRect.width;
93
69
  let visibleHeight = this.virtualizer.visibleRect.height;
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AA4CD,MAAM,wCAAkB;IACtB,GAAG;QACD,aAAa;QACb,aAAa;YACX,YAAY,IAAI,CAAA,GAAA,mCAAG,EAAE,IAAI;QAC3B;QACA,aAAa,IAAI,CAAA,GAAA,mCAAG,EAAE,UAAU;QAChC,QAAQ;QACR,UAAU,IAAI,CAAA,GAAA,mCAAG,EAAE,GAAG;QACtB,YAAY;QACZ,aAAa;IACf;IACA,GAAG;QACD,aAAa;YACX,YAAY;gBACV,U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AAA,GAAA,2CAAW,EAAE,CAAA,GAAA,4CAAY,EAAE,KAAK,IAAI,CAAC,UAAU,gBAA/C,oCAAA,cAAmD,GAAG,GAAG;IACxE;IA7KA,YAAY,UAA6B,CAAC,CAAC,CAAE;QAC3C,KAAK,CAAC;QACN,IAAI,WAAW;QACf,IAAI,CAAC,eAAe,GAAG,QAAQ,eAAe,IAAI;QAClD,IAAI,CAAC,WAAW,GAAG,QAAQ,WAAW,IAAI,qCAAe,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC;QACrG,IAAI,CAAC,WAAW,GAAG,QAAQ,WAAW,IAAI,qCAAe,CAAC,SAAS,CAAC,WAAW;QAC/E,IAAI,CAAC,MAAM,GAAG,QAAQ,MAAM,IAAI,OAAO,QAAQ,MAAM,GAAG,qCAAe,CAAC,SAAS,CAAC,MAAM;QACxF,IAAI,CAAC,QAAQ,GAAG,QAAQ,QAAQ,IAAI,qCAAe,CAAC,SAAS,CAAC,QAAQ;QACtE,IAAI,CAAC,UAAU,GAAG,QAAQ,UAAU,IAAI,qCAAe,CAAC,SAAS,CAAC,UAAU;QAC5E,IAAI,CAAC,WAAW,GAAG,QAAQ,WAAW,IAAI,OAAO,QAAQ,WAAW,GAAG,qCAAe,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;QAC9I,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,CAAC,UAAU,GAAG;QAClB,IAAI,CAAC,OAAO,GAAG;QACf,IAAI,CAAC,iBAAiB,GAAG;IAC3B;AAgKF","sources":["packages/@react-spectrum/card/src/GridLayout.tsx"],"sourcesContent":["/*\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 {BaseLayout, BaseLayoutOptions} from './BaseLayout';\nimport {getChildNodes, getFirstItem} from '@react-stately/collections';\nimport {Key, Node, Orientation} from '@react-types/shared';\nimport {LayoutInfo, Rect, Size} from '@react-stately/virtualizer';\n\nexport interface GridLayoutOptions extends BaseLayoutOptions {\n // /**\n // * The card size in the grid.\n // */\n // cardSize?: 'S' | 'M' | 'L',\n /**\n * The minimum item size.\n * @default 208 x 208 for horizontal card orientation. 102 x 102 for vertical card orientation.\n */\n minItemSize?: Size,\n /**\n * The maximum item size.\n * @default Infinity\n */\n maxItemSize?: Size,\n /**\n * The minimum space required between items.\n * @default 18 x 18\n */\n minSpace?: Size,\n /**\n * The maximum number of columns.\n * @default Infinity\n */\n maxColumns?: number,\n /**\n * The additional padding along the card's main axis. Affects the sizing of the content area following the card image.\n * @default 95\n */\n itemPadding?: number,\n /**\n * The orientation of the cards withn the grid.\n * @default vertical\n */\n cardOrientation?: Orientation\n}\n\nconst DEFAULT_OPTIONS = {\n S: {\n itemPadding: 20,\n minItemSize: {\n 'vertical': new Size(96, 96)\n },\n maxItemSize: new Size(Infinity, Infinity),\n margin: 8,\n minSpace: new Size(6, 6),\n maxColumns: Infinity,\n dropSpacing: 50\n },\n L: {\n itemPadding: {\n 'vertical': {\n 'medium': 78,\n 'large': 98\n },\n 'horizontal': {\n 'medium': 150,\n 'large': 170\n }\n },\n minItemSize: {\n 'vertical': new Size(208, 208),\n 'horizontal': new Size(102, 102)\n },\n maxItemSize: new Size(Infinity, Infinity),\n margin: 24,\n minSpace: new Size(18, 18),\n maxColumns: Infinity,\n dropSpacing: 100\n }\n};\n\nexport class GridLayout<T> extends BaseLayout<T> {\n protected minItemSize: Size;\n protected maxItemSize: Size;\n protected minSpace: Size;\n protected maxColumns: number;\n itemPadding: number;\n cardOrientation: Orientation;\n protected itemSize: Size;\n protected numColumns: number;\n protected numRows: number;\n protected horizontalSpacing: number;\n\n constructor(options: GridLayoutOptions = {}) {\n super(options);\n let cardSize = 'L';\n this.cardOrientation = options.cardOrientation || 'vertical';\n this.minItemSize = options.minItemSize || DEFAULT_OPTIONS[cardSize].minItemSize[this.cardOrientation];\n this.maxItemSize = options.maxItemSize || DEFAULT_OPTIONS[cardSize].maxItemSize;\n this.margin = options.margin != null ? options.margin : DEFAULT_OPTIONS[cardSize].margin;\n this.minSpace = options.minSpace || DEFAULT_OPTIONS[cardSize].minSpace;\n this.maxColumns = options.maxColumns || DEFAULT_OPTIONS[cardSize].maxColumns;\n this.itemPadding = options.itemPadding != null ? options.itemPadding : DEFAULT_OPTIONS[cardSize].itemPadding[this.cardOrientation][this.scale];\n this.itemSize = null;\n this.numColumns = 0;\n this.numRows = 0;\n this.horizontalSpacing = 0;\n }\n\n get layoutType() {\n return 'grid';\n }\n\n getIndexAtPoint(x, y, allowInsertingAtEnd = false) {\n let itemHeight = this.itemSize.height + this.minSpace.height;\n let itemWidth = this.itemSize.width + this.horizontalSpacing;\n return Math.max(0,\n Math.min(\n this.collection.size - (allowInsertingAtEnd ? 0 : 1),\n Math.floor(y / itemHeight) * this.numColumns + Math.floor((x - this.horizontalSpacing) / itemWidth)\n )\n );\n }\n\n getVisibleLayoutInfos(rect) {\n let res: LayoutInfo[] = [];\n let numItems = this.collection.size;\n if (numItems <= 0 || !this.itemSize) {\n // If there aren't any items in the collection, we are in a loader/placeholder state. Return those layoutInfos as\n // the currently visible items\n if (this.layoutInfos.size > 0) {\n for (let layoutInfo of this.layoutInfos.values()) {\n if (this.isVisible(layoutInfo, rect)) {\n res.push(layoutInfo);\n }\n }\n }\n } else {\n // The approach from v2 uses indexes where other v3 layouts iterate through every node/root node. This feels more efficient\n let firstVisibleItem = this.getIndexAtPoint(rect.x, rect.y);\n let lastVisibleItem = this.getIndexAtPoint(rect.maxX, rect.maxY);\n for (let index = firstVisibleItem; index <= lastVisibleItem; index++) {\n let keyFromIndex = this.collection.rows[index].key;\n let layoutInfo = this.layoutInfos.get(keyFromIndex);\n if (layoutInfo && this.isVisible(layoutInfo, rect)) {\n res.push(layoutInfo);\n }\n }\n\n // Check if loader is in view and add to res if so\n let loader = this.layoutInfos.get('loader');\n if (loader && this.isVisible(loader, rect)) {\n res.push(loader);\n }\n }\n\n return res;\n }\n\n buildCollection() {\n let visibleWidth = this.virtualizer.visibleRect.width;\n let visibleHeight = this.virtualizer.visibleRect.height;\n let horizontalItemPadding = this.cardOrientation === 'horizontal' ? this.itemPadding : 0;\n let verticalItemPadding = this.cardOrientation === 'vertical' ? this.itemPadding : 0;\n let minCardWidth = this.minItemSize.width + horizontalItemPadding;\n\n // Compute the number of rows and columns needed to display the content\n let availableWidth = visibleWidth - this.margin * 2;\n let columns = Math.floor((availableWidth + this.minSpace.width) / (minCardWidth + this.minSpace.width));\n this.numColumns = Math.max(1, Math.min(this.maxColumns, columns));\n this.numRows = Math.ceil(this.collection.size / this.numColumns);\n\n // Compute the available width (minus the space between items)\n let width = availableWidth - (this.minSpace.width * Math.max(0, this.numColumns - 1));\n\n // Compute the item width based on the space available\n let itemWidth = Math.floor(width / this.numColumns);\n itemWidth = Math.max(minCardWidth, Math.min(this.maxItemSize.width, itemWidth));\n // Compute the item height, which is proportional to the item width\n let t = ((itemWidth - minCardWidth) / minCardWidth);\n let itemHeight = Math.floor(this.minItemSize.height + this.minItemSize.height * t);\n itemHeight = Math.max(this.minItemSize.height, Math.min(this.maxItemSize.height, itemHeight)) + verticalItemPadding;\n this.itemSize = new Size(itemWidth, itemHeight);\n\n // Compute the horizontal spacing and content height\n this.horizontalSpacing = this.numColumns < 2 ? 0 : Math.floor((availableWidth - this.numColumns * this.itemSize.width) / (this.numColumns - 1));\n\n let y = this.margin;\n let index = 0;\n for (let node of this.collection) {\n let layoutInfo = this.buildChild(node, y, index);\n y = layoutInfo.rect.maxY;\n index++;\n }\n\n if (this.isLoading) {\n let loaderY = y;\n let loaderHeight = 60;\n // If there aren't any items, make loader take all avaliable room and remove margin from y calculation\n // so it doesn't scroll\n if (this.collection.size === 0) {\n loaderY = 0;\n loaderHeight = visibleHeight || 60;\n }\n\n let rect = new Rect(0, loaderY, visibleWidth, loaderHeight);\n let loader = new LayoutInfo('loader', 'loader', rect);\n this.layoutInfos.set('loader', loader);\n y = loader.rect.maxY;\n }\n\n if (this.collection.size === 0 && !this.isLoading) {\n let rect = new Rect(0, 0, visibleWidth, visibleHeight);\n let placeholder = new LayoutInfo('placeholder', 'placeholder', rect);\n this.layoutInfos.set('placeholder', placeholder);\n y = placeholder.rect.maxY;\n }\n\n this.contentSize = new Size(visibleWidth, y);\n }\n\n buildChild(node: Node<T>, y: number, index: number): LayoutInfo {\n let row = Math.floor(index / this.numColumns);\n let column = index % this.numColumns;\n let x = this.margin + column * (this.itemSize.width + this.horizontalSpacing);\n y = this.margin + row * (this.itemSize.height + this.minSpace.height);\n\n let rect = new Rect(x, y, this.itemSize.width, this.itemSize.height);\n // TODO: Perhaps have it so that the child key for each row is stored with the layoutInfo?\n let layoutInfo = new LayoutInfo(node.type, node.key, rect);\n layoutInfo.allowOverflow = true;\n this.layoutInfos.set(node.key, layoutInfo);\n return layoutInfo;\n }\n\n // Since the collection doesn't represent the visual layout, need to calculate what row and column the current key is in,\n // then return the key that occupies the row + column below. This can be done by figuring out how many cards exist per column then dividing the\n // collection contents by that number (which will give us the row distribution)\n getKeyBelow(key: Key) {\n // Expected key is the currently focused cell so we need the parent row key\n let parentRowKey = this.collection.getItem(key).parentKey;\n let indexRowBelow;\n let index = this.collection.rows.findIndex(card => card.key === parentRowKey);\n if (index !== -1) {\n indexRowBelow = index + this.numColumns;\n } else {\n return null;\n }\n\n let row = this.collection.rows[indexRowBelow];\n return row ? getFirstItem(getChildNodes(row, this.collection))?.key : null;\n }\n\n getKeyAbove(key: Key) {\n // Expected key is the currently focused cell so we need the parent row key\n let parentRowKey = this.collection.getItem(key).parentKey;\n let indexRowAbove;\n let index = this.collection.rows.findIndex(card => card.key === parentRowKey);\n if (index !== -1) {\n indexRowAbove = index - this.numColumns;\n } else {\n return null;\n }\n\n let row = this.collection.rows[indexRowAbove];\n return row ? getFirstItem(getChildNodes(row, this.collection))?.key : null;\n }\n}\n"],"names":[],"version":3,"file":"GridLayout.main.js.map"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AA4CD,MAAM,wCAAkB;IACtB,GAAG;QACD,aAAa;QACb,aAAa;YACX,YAAY,IAAI,CAAA,GAAA,mCAAG,EAAE,IAAI;QAC3B;QACA,aAAa,IAAI,CAAA,GAAA,mCAAG,EAAE,UAAU;QAChC,QAAQ;QACR,UAAU,IAAI,CAAA,GAAA,mCAAG,EAAE,GAAG;QACtB,YAAY;QACZ,aAAa;IACf;IACA,GAAG;QACD,aAAa;YACX,YAAY;gBACV,UAAU;gBACV,SAAS;YACX;YACA,cAAc;gBACZ,UAAU;gBACV,SAAS;YACX;QACF;QACA,aAAa;YACX,YAAY,IAAI,CAAA,GAAA,mCAAG,EAAE,KAAK;YAC1B,cAAc,IAAI,CAAA,GAAA,mCAAG,EAAE,KAAK;QAC9B;QACA,aAAa,IAAI,CAAA,GAAA,mCAAG,EAAE,UAAU;QAChC,QAAQ;QACR,UAAU,IAAI,CAAA,GAAA,mCAAG,EAAE,IAAI;QACvB,YAAY;QACZ,aAAa;IACf;AACF;AAEO,MAAM,kDAAsB,CAAA,GAAA,oCAAS;IA4B1C,IAAI,aAAa;QACf,OAAO;IACT;IAEA,gBAAgB,CAAC,EAAE,CAAC,EAAE,sBAAsB,KAAK,EAAE;QACjD,IAAI,aAAa,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM;QAC5D,IAAI,YAAY,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,iBAAiB;QAC5D,OAAO,KAAK,GAAG,CAAC,GACd,KAAK,GAAG,CACN,IAAI,CAAC,UAAU,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AAC,MAAM,GAAG,QAAQ,MAAM,IAAI,OAAO,QAAQ,MAAM,GAAG,qCAAe,CAAC,SAAS,CAAC,MAAM;QACxF,IAAI,CAAC,QAAQ,GAAG,QAAQ,QAAQ,IAAI,qCAAe,CAAC,SAAS,CAAC,QAAQ;QACtE,IAAI,CAAC,UAAU,GAAG,QAAQ,UAAU,IAAI,qCAAe,CAAC,SAAS,CAAC,UAAU;QAC5E,IAAI,CAAC,WAAW,GAAG,QAAQ,WAAW,IAAI,OAAO,QAAQ,WAAW,GAAG,qCAAe,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;QAC9I,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,CAAC,UAAU,GAAG;QAClB,IAAI,CAAC,OAAO,GAAG;QACf,IAAI,CAAC,iBAAiB,GAAG;IAC3B;AA6HF","sources":["packages/@react-spectrum/card/src/GridLayout.tsx"],"sourcesContent":["/*\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 {BaseLayout, BaseLayoutOptions} from './BaseLayout';\nimport {getChildNodes, getFirstItem} from '@react-stately/collections';\nimport {Key, Node, Orientation} from '@react-types/shared';\nimport {LayoutInfo, Rect, Size} from '@react-stately/virtualizer';\n\nexport interface GridLayoutOptions extends BaseLayoutOptions {\n // /**\n // * The card size in the grid.\n // */\n // cardSize?: 'S' | 'M' | 'L',\n /**\n * The minimum item size.\n * @default 208 x 208 for horizontal card orientation. 102 x 102 for vertical card orientation.\n */\n minItemSize?: Size,\n /**\n * The maximum item size.\n * @default Infinity\n */\n maxItemSize?: Size,\n /**\n * The minimum space required between items.\n * @default 18 x 18\n */\n minSpace?: Size,\n /**\n * The maximum number of columns.\n * @default Infinity\n */\n maxColumns?: number,\n /**\n * The additional padding along the card's main axis. Affects the sizing of the content area following the card image.\n * @default 95\n */\n itemPadding?: number,\n /**\n * The orientation of the cards withn the grid.\n * @default vertical\n */\n cardOrientation?: Orientation\n}\n\nconst DEFAULT_OPTIONS = {\n S: {\n itemPadding: 20,\n minItemSize: {\n 'vertical': new Size(96, 96)\n },\n maxItemSize: new Size(Infinity, Infinity),\n margin: 8,\n minSpace: new Size(6, 6),\n maxColumns: Infinity,\n dropSpacing: 50\n },\n L: {\n itemPadding: {\n 'vertical': {\n 'medium': 78,\n 'large': 98\n },\n 'horizontal': {\n 'medium': 150,\n 'large': 170\n }\n },\n minItemSize: {\n 'vertical': new Size(208, 208),\n 'horizontal': new Size(102, 102)\n },\n maxItemSize: new Size(Infinity, Infinity),\n margin: 24,\n minSpace: new Size(18, 18),\n maxColumns: Infinity,\n dropSpacing: 100\n }\n};\n\nexport class GridLayout<T> extends BaseLayout<T> {\n protected minItemSize: Size;\n protected maxItemSize: Size;\n protected minSpace: Size;\n protected maxColumns: number;\n itemPadding: number;\n cardOrientation: Orientation;\n protected itemSize: Size;\n protected numColumns: number;\n protected numRows: number;\n protected horizontalSpacing: number;\n\n constructor(options: GridLayoutOptions = {}) {\n super(options);\n let cardSize = 'L';\n this.cardOrientation = options.cardOrientation || 'vertical';\n this.minItemSize = options.minItemSize || DEFAULT_OPTIONS[cardSize].minItemSize[this.cardOrientation];\n this.maxItemSize = options.maxItemSize || DEFAULT_OPTIONS[cardSize].maxItemSize;\n this.margin = options.margin != null ? options.margin : DEFAULT_OPTIONS[cardSize].margin;\n this.minSpace = options.minSpace || DEFAULT_OPTIONS[cardSize].minSpace;\n this.maxColumns = options.maxColumns || DEFAULT_OPTIONS[cardSize].maxColumns;\n this.itemPadding = options.itemPadding != null ? options.itemPadding : DEFAULT_OPTIONS[cardSize].itemPadding[this.cardOrientation][this.scale];\n this.itemSize = null;\n this.numColumns = 0;\n this.numRows = 0;\n this.horizontalSpacing = 0;\n }\n\n get layoutType() {\n return 'grid';\n }\n\n getIndexAtPoint(x, y, allowInsertingAtEnd = false) {\n let itemHeight = this.itemSize.height + this.minSpace.height;\n let itemWidth = this.itemSize.width + this.horizontalSpacing;\n return Math.max(0,\n Math.min(\n this.collection.size - (allowInsertingAtEnd ? 0 : 1),\n Math.floor(y / itemHeight) * this.numColumns + Math.floor((x - this.horizontalSpacing) / itemWidth)\n )\n );\n }\n\n buildCollection() {\n let visibleWidth = this.virtualizer.visibleRect.width;\n let visibleHeight = this.virtualizer.visibleRect.height;\n let horizontalItemPadding = this.cardOrientation === 'horizontal' ? this.itemPadding : 0;\n let verticalItemPadding = this.cardOrientation === 'vertical' ? this.itemPadding : 0;\n let minCardWidth = this.minItemSize.width + horizontalItemPadding;\n\n // Compute the number of rows and columns needed to display the content\n let availableWidth = visibleWidth - this.margin * 2;\n let columns = Math.floor((availableWidth + this.minSpace.width) / (minCardWidth + this.minSpace.width));\n this.numColumns = Math.max(1, Math.min(this.maxColumns, columns));\n this.numRows = Math.ceil(this.collection.size / this.numColumns);\n\n // Compute the available width (minus the space between items)\n let width = availableWidth - (this.minSpace.width * Math.max(0, this.numColumns - 1));\n\n // Compute the item width based on the space available\n let itemWidth = Math.floor(width / this.numColumns);\n itemWidth = Math.max(minCardWidth, Math.min(this.maxItemSize.width, itemWidth));\n // Compute the item height, which is proportional to the item width\n let t = ((itemWidth - minCardWidth) / minCardWidth);\n let itemHeight = Math.floor(this.minItemSize.height + this.minItemSize.height * t);\n itemHeight = Math.max(this.minItemSize.height, Math.min(this.maxItemSize.height, itemHeight)) + verticalItemPadding;\n this.itemSize = new Size(itemWidth, itemHeight);\n\n // Compute the horizontal spacing and content height\n this.horizontalSpacing = this.numColumns < 2 ? 0 : Math.floor((availableWidth - this.numColumns * this.itemSize.width) / (this.numColumns - 1));\n\n let y = this.margin;\n let index = 0;\n for (let node of this.collection) {\n let layoutInfo = this.buildChild(node, y, index);\n y = layoutInfo.rect.maxY;\n index++;\n }\n\n if (this.isLoading) {\n let loaderY = y;\n let loaderHeight = 60;\n // If there aren't any items, make loader take all avaliable room and remove margin from y calculation\n // so it doesn't scroll\n if (this.collection.size === 0) {\n loaderY = 0;\n loaderHeight = visibleHeight || 60;\n }\n\n let rect = new Rect(0, loaderY, visibleWidth, loaderHeight);\n let loader = new LayoutInfo('loader', 'loader', rect);\n this.layoutInfos.set('loader', loader);\n y = loader.rect.maxY;\n }\n\n if (this.collection.size === 0 && !this.isLoading) {\n let rect = new Rect(0, 0, visibleWidth, visibleHeight);\n let placeholder = new LayoutInfo('placeholder', 'placeholder', rect);\n this.layoutInfos.set('placeholder', placeholder);\n y = placeholder.rect.maxY;\n }\n\n this.contentSize = new Size(visibleWidth, y);\n }\n\n buildChild(node: Node<T>, y: number, index: number): LayoutInfo {\n let row = Math.floor(index / this.numColumns);\n let column = index % this.numColumns;\n let x = this.margin + column * (this.itemSize.width + this.horizontalSpacing);\n y = this.margin + row * (this.itemSize.height + this.minSpace.height);\n\n let rect = new Rect(x, y, this.itemSize.width, this.itemSize.height);\n // TODO: Perhaps have it so that the child key for each row is stored with the layoutInfo?\n let layoutInfo = new LayoutInfo(node.type, node.key, rect);\n layoutInfo.allowOverflow = true;\n this.layoutInfos.set(node.key, layoutInfo);\n return layoutInfo;\n }\n\n // Since the collection doesn't represent the visual layout, need to calculate what row and column the current key is in,\n // then return the key that occupies the row + column below. This can be done by figuring out how many cards exist per column then dividing the\n // collection contents by that number (which will give us the row distribution)\n getKeyBelow(key: Key) {\n // Expected key is the currently focused cell so we need the parent row key\n let parentRowKey = this.collection.getItem(key).parentKey;\n let indexRowBelow;\n let index = this.collection.rows.findIndex(card => card.key === parentRowKey);\n if (index !== -1) {\n indexRowBelow = index + this.numColumns;\n } else {\n return null;\n }\n\n let row = this.collection.rows[indexRowBelow];\n return row ? getFirstItem(getChildNodes(row, this.collection))?.key : null;\n }\n\n getKeyAbove(key: Key) {\n // Expected key is the currently focused cell so we need the parent row key\n let parentRowKey = this.collection.getItem(key).parentKey;\n let indexRowAbove;\n let index = this.collection.rows.findIndex(card => card.key === parentRowKey);\n if (index !== -1) {\n indexRowAbove = index - this.numColumns;\n } else {\n return null;\n }\n\n let row = this.collection.rows[indexRowAbove];\n return row ? getFirstItem(getChildNodes(row, this.collection))?.key : null;\n }\n}\n"],"names":[],"version":3,"file":"GridLayout.main.js.map"}
@@ -58,30 +58,6 @@ class $ed42fd44b9b9b664$export$7d2b12578154a735 extends (0, $3d424c147206bac9$ex
58
58
  let itemWidth = this.itemSize.width + this.horizontalSpacing;
59
59
  return Math.max(0, Math.min(this.collection.size - (allowInsertingAtEnd ? 0 : 1), Math.floor(y / itemHeight) * this.numColumns + Math.floor((x - this.horizontalSpacing) / itemWidth)));
60
60
  }
61
- getVisibleLayoutInfos(rect) {
62
- let res = [];
63
- let numItems = this.collection.size;
64
- if (numItems <= 0 || !this.itemSize) // If there aren't any items in the collection, we are in a loader/placeholder state. Return those layoutInfos as
65
- // the currently visible items
66
- {
67
- if (this.layoutInfos.size > 0) {
68
- for (let layoutInfo of this.layoutInfos.values())if (this.isVisible(layoutInfo, rect)) res.push(layoutInfo);
69
- }
70
- } else {
71
- // The approach from v2 uses indexes where other v3 layouts iterate through every node/root node. This feels more efficient
72
- let firstVisibleItem = this.getIndexAtPoint(rect.x, rect.y);
73
- let lastVisibleItem = this.getIndexAtPoint(rect.maxX, rect.maxY);
74
- for(let index = firstVisibleItem; index <= lastVisibleItem; index++){
75
- let keyFromIndex = this.collection.rows[index].key;
76
- let layoutInfo = this.layoutInfos.get(keyFromIndex);
77
- if (layoutInfo && this.isVisible(layoutInfo, rect)) res.push(layoutInfo);
78
- }
79
- // Check if loader is in view and add to res if so
80
- let loader = this.layoutInfos.get('loader');
81
- if (loader && this.isVisible(loader, rect)) res.push(loader);
82
- }
83
- return res;
84
- }
85
61
  buildCollection() {
86
62
  let visibleWidth = this.virtualizer.visibleRect.width;
87
63
  let visibleHeight = this.virtualizer.visibleRect.height;
@@ -58,30 +58,6 @@ class $ed42fd44b9b9b664$export$7d2b12578154a735 extends (0, $3d424c147206bac9$ex
58
58
  let itemWidth = this.itemSize.width + this.horizontalSpacing;
59
59
  return Math.max(0, Math.min(this.collection.size - (allowInsertingAtEnd ? 0 : 1), Math.floor(y / itemHeight) * this.numColumns + Math.floor((x - this.horizontalSpacing) / itemWidth)));
60
60
  }
61
- getVisibleLayoutInfos(rect) {
62
- let res = [];
63
- let numItems = this.collection.size;
64
- if (numItems <= 0 || !this.itemSize) // If there aren't any items in the collection, we are in a loader/placeholder state. Return those layoutInfos as
65
- // the currently visible items
66
- {
67
- if (this.layoutInfos.size > 0) {
68
- for (let layoutInfo of this.layoutInfos.values())if (this.isVisible(layoutInfo, rect)) res.push(layoutInfo);
69
- }
70
- } else {
71
- // The approach from v2 uses indexes where other v3 layouts iterate through every node/root node. This feels more efficient
72
- let firstVisibleItem = this.getIndexAtPoint(rect.x, rect.y);
73
- let lastVisibleItem = this.getIndexAtPoint(rect.maxX, rect.maxY);
74
- for(let index = firstVisibleItem; index <= lastVisibleItem; index++){
75
- let keyFromIndex = this.collection.rows[index].key;
76
- let layoutInfo = this.layoutInfos.get(keyFromIndex);
77
- if (layoutInfo && this.isVisible(layoutInfo, rect)) res.push(layoutInfo);
78
- }
79
- // Check if loader is in view and add to res if so
80
- let loader = this.layoutInfos.get('loader');
81
- if (loader && this.isVisible(loader, rect)) res.push(loader);
82
- }
83
- return res;
84
- }
85
61
  buildCollection() {
86
62
  let visibleWidth = this.virtualizer.visibleRect.width;
87
63
  let visibleHeight = this.virtualizer.visibleRect.height;