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odes, getFirstItem, getLastItem} from '../collections/getChildNodes';\nimport {GridNode, IGridCollection} from './GridCollection';\nimport {Key} from '@react-types/shared';\nimport {MultipleSelectionState} from '../selection/types';\nimport {\n MultipleSelectionStateProps,\n useMultipleSelectionState\n} from '../selection/useMultipleSelectionState';\nimport {SelectionManager} from '../selection/SelectionManager';\nimport {useEffect, useMemo, useRef} from 'react';\n\nexport interface GridState<T, C extends IGridCollection<T>> {\n collection: C;\n /** A set of keys for rows that are disabled. */\n disabledKeys: Set<Key>;\n /** A selection manager to read and update row selection state. */\n selectionManager: SelectionManager;\n /**\n * Whether keyboard navigation is disabled, such as when the arrow keys should be handled by a\n * component within a cell.\n */\n isKeyboardNavigationDisabled: boolean;\n}\n\nexport interface GridStateOptions<\n T,\n C extends IGridCollection<T>\n> extends MultipleSelectionStateProps {\n collection: C;\n disabledKeys?: Iterable<Key>;\n focusMode?: 'row' | 'cell';\n /** @private - Do not use unless you know what you're doing. */\n UNSAFE_selectionState?: MultipleSelectionState;\n}\n\n/**\n * Provides state management for a grid component. Handles row selection and focusing a grid cell's\n * focusable child if applicable.\n */\nexport function useGridState<T extends object, C extends IGridCollection<T>>(\n props: GridStateOptions<T, C>\n): GridState<T, C> {\n let {collection, focusMode} = props;\n // eslint-disable-next-line react-hooks/rules-of-hooks\n let selectionState = props.UNSAFE_selectionState || useMultipleSelectionState(props);\n let disabledKeys = useMemo(\n () => (props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()),\n [props.disabledKeys]\n );\n\n let setFocusedKey = selectionState.setFocusedKey;\n selectionState.setFocusedKey = (key, child) => {\n // If focusMode is cell and an item is focused, focus a child cell instead.\n if (focusMode === 'cell' && key != null) {\n let item = collection.getItem(key);\n if (item?.type === 'item') {\n let children = getChildNodes(item, collection);\n if (child === 'last') {\n key = getLastItem(children)?.key ?? null;\n } else {\n key = getFirstItem(children)?.key ?? null;\n }\n }\n }\n\n setFocusedKey(key, child);\n };\n\n let selectionManager = useMemo(\n () => new SelectionManager(collection, selectionState),\n [collection, selectionState]\n );\n\n // Reset focused key if that item is deleted from the collection.\n const cachedCollection = useRef<C | null>(null);\n useEffect(() => {\n if (\n selectionState.focusedKey != null &&\n cachedCollection.current &&\n !collection.getItem(selectionState.focusedKey)\n ) {\n const node = cachedCollection.current.getItem(selectionState.focusedKey);\n const parentNode =\n node?.parentKey != null &&\n (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column')\n ? cachedCollection.current.getItem(node.parentKey)\n : node;\n if (!parentNode) {\n selectionState.setFocusedKey(null);\n return;\n }\n const cachedRows = cachedCollection.current.rows;\n const rows = collection.rows;\n const diff = cachedRows.length - rows.length;\n let index = Math.min(\n diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index,\n rows.length - 1\n );\n let newRow: GridNode<T> | null = null;\n while (index >= 0) {\n if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') {\n newRow = rows[index];\n break;\n }\n // Find next, not disabled row.\n if (index < rows.length - 1) {\n index++;\n // Otherwise, find previous, not disabled row.\n } else {\n if (index > parentNode.index) {\n index = parentNode.index;\n }\n index--;\n }\n }\n if (newRow) {\n const childNodes = newRow.hasChildNodes ? [...getChildNodes(newRow, collection)] : [];\n const keyToFocus =\n newRow.hasChildNodes && parentNode !== node && node && node.index < childNodes.length\n ? childNodes[node.index].key\n : newRow.key;\n selectionState.setFocusedKey(keyToFocus);\n } else {\n selectionState.setFocusedKey(null);\n }\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager, selectionState, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n isKeyboardNavigationDisabled: false,\n selectionManager\n };\n}\n"],"names":[],"version":3,"file":"useGridState.cjs.map"}