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yright 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 {AriaButtonProps} from '../button/useButton';\n\nimport {Collection, FocusableElement, Node, RefObject} from '@react-types/shared';\nimport {getRowLabelledBy} from './utils';\nimport {GridRowAria, GridRowProps, useGridRow} from '../grid/useGridRow';\nimport {HTMLAttributes} from 'react';\n// @ts-ignore\nimport intlMessages from '../../intl/table/*.json';\nimport {ITableCollection} from 'react-stately/private/table/TableCollection';\nimport {mergeProps} from '../utils/mergeProps';\nimport {TableState} from 'react-stately/useTableState';\nimport {TreeGridState} from 'react-stately/private/table/useTreeGridState';\nimport {useLabels} from '../utils/useLabels';\nimport {useLocale} from '../i18n/I18nProvider';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\nimport {useSyntheticLinkProps} from '../utils/openLink';\n\nconst EXPANSION_KEYS = {\n expand: {\n ltr: 'ArrowRight',\n rtl: 'ArrowLeft'\n },\n collapse: {\n ltr: 'ArrowLeft',\n rtl: 'ArrowRight'\n }\n};\n\nexport interface TableRowAria extends GridRowAria {\n expandButtonProps: AriaButtonProps;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a row in a table.\n *\n * @param props - Props for the row.\n * @param state - State of the table, as returned by `useTableState`.\n */\nexport function useTableRow<T>(\n props: GridRowProps<T>,\n state: TableState<T> | TreeGridState<T>,\n ref: RefObject<FocusableElement | null>\n): TableRowAria {\n let {node, isVirtualized} = props;\n let {rowProps, ...states} = useGridRow<T, ITableCollection<T>, TableState<T>>(\n props,\n state as TableState<T>,\n ref\n );\n let {direction} = useLocale();\n\n if (isVirtualized && state.treeColumn == null) {\n rowProps['aria-rowindex'] = node.index + 1 + state.collection.headerRows.length; // aria-rowindex is 1 based\n } else {\n delete rowProps['aria-rowindex'];\n }\n\n let isExpanded =\n state.treeColumn != null && (state.expandedKeys === 'all' || state.expandedKeys.has(node.key));\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/table');\n let labelProps = useLabels({\n 'aria-label': isExpanded\n ? stringFormatter.format('collapse')\n : stringFormatter.format('expand'),\n 'aria-labelledby': getRowLabelledBy(state as TableState<T>, node.key)\n });\n\n let treeGridRowProps: HTMLAttributes<HTMLElement> = {};\n let expandButtonProps: AriaButtonProps = {};\n if (state.treeColumn != null) {\n let treeNode = state.collection.getItem(node.key);\n if (treeNode != null) {\n let lastChild = getLastChild(state.collection, node);\n let hasChildRows =\n treeNode.props?.hasChildRows ||\n treeNode.props?.UNSTABLE_childItems ||\n lastChild?.type !== 'cell';\n let parent = state.collection.getItem(node.parentKey!)!;\n let isParentBody = parent.type === 'tablebody' || parent.type === 'body';\n let lastSibling = getLastChild(state.collection, parent)!;\n while (lastSibling && lastSibling.type !== 'item' && lastSibling.prevKey != null) {\n lastSibling = state.collection.getItem(lastSibling.prevKey)!;\n }\n\n treeGridRowProps = {\n onKeyDown: e => {\n if (\n e.key === EXPANSION_KEYS['expand'][direction] &&\n state.selectionManager.focusedKey === treeNode.key &&\n hasChildRows &&\n state.expandedKeys !== 'all' &&\n !state.expandedKeys.has(treeNode.key)\n ) {\n state.toggleKey(treeNode.key);\n e.stopPropagation();\n } else if (\n e.key === EXPANSION_KEYS['collapse'][direction] &&\n state.selectionManager.focusedKey === treeNode.key\n ) {\n if (state.expandedKeys !== 'all') {\n if (hasChildRows && state.expandedKeys.has(treeNode.key)) {\n state.toggleKey(treeNode.key);\n e.stopPropagation();\n } else if (\n !state.expandedKeys.has(treeNode.key) &&\n treeNode.parentKey != null &&\n treeNode.level > 0\n ) {\n // Item is a leaf or already collapsed, move focus to parent\n state.selectionManager.setFocusedKey(treeNode.parentKey);\n e.stopPropagation();\n }\n } else if (state.expandedKeys === 'all') {\n state.toggleKey(treeNode.key);\n e.stopPropagation();\n }\n }\n },\n 'aria-expanded': hasChildRows\n ? state.expandedKeys === 'all' || state.expandedKeys.has(node.key)\n : undefined,\n 'aria-level': treeNode.level + 1,\n 'aria-posinset': treeNode.index - (isParentBody ? 0 : state.collection.columnCount) + 1,\n 'aria-setsize': lastSibling.index - (isParentBody ? 0 : state.collection.columnCount) + 1\n };\n\n expandButtonProps = {\n isDisabled: states.isDisabled,\n onPress: () => {\n if (!states.isDisabled) {\n state.toggleKey(node.key);\n state.selectionManager.setFocused(true);\n state.selectionManager.setFocusedKey(node.key);\n }\n },\n excludeFromTabOrder: true,\n preventFocusOnPress: true,\n // @ts-ignore\n 'data-react-aria-prevent-focus': true,\n ...labelProps\n };\n }\n }\n\n let syntheticLinkProps = useSyntheticLinkProps(node.props);\n let linkProps = states.hasAction ? syntheticLinkProps : {};\n return {\n rowProps: {\n ...mergeProps(rowProps, treeGridRowProps, linkProps),\n 'aria-labelledby': getRowLabelledBy(state as TableState<T>, node.key)\n },\n expandButtonProps,\n ...states\n };\n}\n\nfunction getLastChild(collection: Collection<Node<unknown>>, node: Node<unknown>) {\n if ('lastChildKey' in node) {\n return node.lastChildKey != null ? collection.getItem(node.lastChildKey) : null;\n } else {\n return Array.from(node.childNodes).findLast(item => item.parentKey === node.key);\n }\n}\n"],"names":[],"version":3,"file":"useTableRow.mjs.map"}