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,CAAC,MAAM,cAAc,CAAC,SAAS,CAAC,GACvD,WAAU;YAChB;QACF;sBACA;QACA,WAAU,GAAG;YACX,gBAAgB,CAAA;gBACd,IAAI,UAAU,IAAI,IAAI;gBACtB,IAAI,QAAQ,GAAG,CAAC,MACd,QAAQ,MAAM,CAAC;qBAEf,QAAQ,GAAG,CAAC;gBAGd,OAAO;YACT;QACF;oBACA;IACF;AACF;AAKO,SAAS,0CAAiD,KAAoB,EAAE,QAA4E;IACjK,IAAI,aAAa,CAAA,GAAA,cAAM,EAAE,IAAM,WAAW,MAAM,UAAU,CAAC,MAAM,CAAE,YAAY,MAAM,UAAU,EAAE;QAAC,MAAM,UAAU;QAAE;KAAS;IAC7H,IAAI,mBAAmB,MAAM,gBAAgB,CAAC,cAAc,CAAC;IAC7D,8DAA8D;IAE9D,OAAO;QACL,GAAG,KAAK;oBACR;0BACA;IACF;AACF","sources":["packages/react-stately/src/table/useTableState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Expandable, Key, MultipleSelection, Node, SelectionMode, Sortable, SortDescriptor, SortDirection} from '@react-types/shared';\nimport {GridState, useGridState} from '../grid/useGridState';\nimport {ITableCollection, TableCollection} from './TableCollection';\nimport {MultipleSelectionState} from '../selection/types';\nimport {MultipleSelectionStateProps} from '../selection/useMultipleSelectionState';\nimport {ReactElement, useCallback, useMemo, useState} from 'react';\nimport {TableBodyProps} from './TableBody';\nimport {TableHeaderProps} from './TableHeader';\nimport {useCollection} from '../collections/useCollection';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface TableProps<T> extends MultipleSelection, Sortable, Expandable {\n  /** The elements that make up the table. Includes the TableHeader, TableBody, Columns, and Rows. */\n  children: [ReactElement<TableHeaderProps<T>>, ReactElement<TableBodyProps<T>>],\n  /** A list of row keys to disable. */\n  disabledKeys?: Iterable<Key>,\n  /**\n   * Whether pressing the escape key should clear selection in the table or not.\n   *\n   * Most experiences should not modify this option as it eliminates a keyboard user's ability to\n   * easily clear selection. Only use if the escape key is being handled externally or should not\n   * trigger selection clearing contextually.\n   * @default 'clearSelection'\n   */\n  escapeKeyBehavior?: 'clearSelection' | 'none',\n  /** Whether selection should occur on press up instead of press down. */\n  shouldSelectOnPressUp?: boolean,\n  /** The id of the column that displays hierarchical data. */\n  treeColumn?: Key\n}\n\nexport interface TableState<T> extends GridState<T, ITableCollection<T>> {\n  /** A collection of rows and columns in the table. */\n  collection: ITableCollection<T>,\n  /** Whether the row selection checkboxes should be displayed. */\n  showSelectionCheckboxes: boolean,\n  /** The current sorted column and direction. */\n  sortDescriptor: SortDescriptor | null,\n  /** Calls the provided onSortChange handler with the provided column key and sort direction. */\n  sort(columnKey: Key, direction?: 'ascending' | 'descending'): void,\n  /** Whether keyboard navigation is disabled, such as when the arrow keys should be handled by a component within a cell. */\n  isKeyboardNavigationDisabled: boolean,\n  /** Set whether keyboard navigation is disabled, such as when the arrow keys should be handled by a component within a cell. */\n  setKeyboardNavigationDisabled: (val: boolean) => void,\n  /** A set of keys for items that are expanded. */\n  expandedKeys: Set<Key>,\n  /** Toggles the expanded state for a row by its key. */\n  toggleKey(key: Key): void,\n  /** The id of the column that displays hierarchical data. */\n  treeColumn: Key | null\n}\n\nexport interface CollectionBuilderContext<T> {\n  showSelectionCheckboxes: boolean,\n  showDragButtons: boolean,\n  selectionMode: SelectionMode,\n  columns: Node<T>[]\n}\n\nexport interface TableStateProps<T> extends MultipleSelectionStateProps, Expandable, Sortable {\n  /** The elements that make up the table. Includes the TableHeader, TableBody, Columns, and Rows. */\n  children?: [ReactElement<TableHeaderProps<T>>, ReactElement<TableBodyProps<T>>],\n  /** A pre-constructed collection to use instead of building one from items and children. */\n  collection?: ITableCollection<T>,\n  /** Whether the row selection checkboxes should be displayed. */\n  showSelectionCheckboxes?: boolean,\n  /** Whether the row drag button should be displayed.\n   * @private\n   */\n  showDragButtons?: boolean,\n  /** @private - do not use unless you know what you're doing. */\n  UNSAFE_selectionState?: MultipleSelectionState,\n  /** The id of the column that displays hierarchical data. */\n  treeColumn?: Key\n}\n\nconst OPPOSITE_SORT_DIRECTION = {\n  ascending: 'descending' as SortDirection,\n  descending: 'ascending' as SortDirection\n};\n\n/**\n * Provides state management for a table component. Handles building a collection\n * of columns and rows from props. In addition, it tracks row selection and manages sort order changes.\n */\nexport function useTableState<T extends object>(props: TableStateProps<T>): TableState<T> {\n  let [isKeyboardNavigationDisabled, setKeyboardNavigationDisabled] = useState(false);\n  let {selectionMode = 'none', showSelectionCheckboxes, showDragButtons, treeColumn = null} = props;\n\n  let context = useMemo(() => ({\n    showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== 'none',\n    showDragButtons: showDragButtons,\n    selectionMode,\n    columns: []\n  // eslint-disable-next-line react-hooks/exhaustive-deps\n  }), [props.children, showSelectionCheckboxes, selectionMode, showDragButtons]);\n\n  let collection = useCollection<T, ITableCollection<T>>(\n    props,\n    useCallback((nodes) => new TableCollection(nodes, null, context), [context]),\n    context\n  );\n  let {disabledKeys, selectionManager} = useGridState({\n    ...props,\n    collection,\n    disabledBehavior: props.disabledBehavior || 'selection'\n  });\n\n  let [expandedKeys, setExpandedKeys] = useControlledState(\n    props.expandedKeys ? new Set(props.expandedKeys) : undefined,\n    props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(),\n    props.onExpandedChange\n  );\n\n  return {\n    collection,\n    disabledKeys,\n    selectionManager,\n    showSelectionCheckboxes: props.showSelectionCheckboxes || false,\n    sortDescriptor: props.sortDescriptor ?? null,\n    isKeyboardNavigationDisabled: collection.size === 0 || isKeyboardNavigationDisabled,\n    setKeyboardNavigationDisabled,\n    sort(columnKey: Key, direction?: 'ascending' | 'descending') {\n      props.onSortChange?.({\n        column: columnKey,\n        direction: direction ?? (props.sortDescriptor?.column === columnKey\n          ? OPPOSITE_SORT_DIRECTION[props.sortDescriptor.direction]\n          : 'ascending')\n      });\n    },\n    expandedKeys,\n    toggleKey(key) {\n      setExpandedKeys(keys => {\n        let newKeys = new Set(keys);\n        if (newKeys.has(key)) {\n          newKeys.delete(key);\n        } else {\n          newKeys.add(key);\n        }\n\n        return newKeys;\n      });\n    },\n    treeColumn\n  };\n}\n\n/**\n * Filters a collection using the provided filter function and returns a new TableState.\n */\nexport function UNSTABLE_useFilteredTableState<T extends object>(state: TableState<T>, filterFn: ((nodeValue: string, node: Node<T>) => boolean) | null | undefined): TableState<T> {\n  let collection = useMemo(() => filterFn ? state.collection.filter!(filterFn) : state.collection, [state.collection, filterFn]) as ITableCollection<T>;\n  let selectionManager = state.selectionManager.withCollection(collection);\n  // TODO: handle focus key reset? That logic is in useGridState\n\n  return {\n    ...state,\n    collection,\n    selectionManager\n  };\n}\n"],"names":[],"version":3,"file":"useTableState.mjs.map"}