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":["/*\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 {\n Collection,\n CollectionStateBase,\n DisabledBehavior,\n Expandable,\n Key,\n MultipleSelection,\n Node\n} from '@react-types/shared';\nimport {SelectionManager} from '../selection/SelectionManager';\nimport {TreeCollection} from './TreeCollection';\nimport {useCallback, useEffect, useMemo} from 'react';\nimport {useCollection} from '../collections/useCollection';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMultipleSelectionState} from '../selection/useMultipleSelectionState';\n\nexport interface TreeProps<T> extends CollectionStateBase<T>, Expandable, MultipleSelection {\n /** Whether `disabledKeys` applies to all interactions, or only selection. */\n disabledBehavior?: DisabledBehavior;\n}\nexport interface TreeState<T> {\n /** A collection of items in the tree. */\n readonly collection: Collection<Node<T>>;\n\n /** A set of keys for items that are disabled. */\n readonly disabledKeys: Set<Key>;\n\n /** A set of keys for items that are expanded. */\n readonly expandedKeys: Set<Key>;\n\n /** Toggles the expanded state for an item by its key. */\n toggleKey(key: Key): void;\n\n /** Replaces the set of expanded keys. */\n setExpandedKeys(keys: Set<Key>): void;\n\n /** A selection manager to read and update multiple selection state. */\n readonly selectionManager: SelectionManager;\n}\n\n/**\n * Provides state management for tree-like components. Handles building a collection\n * of items from props, item expanded state, and manages multiple selection state.\n */\nexport function useTreeState<T>(props: TreeProps<T>): TreeState<T> {\n let {onExpandedChange} = props;\n\n let [expandedKeys, setExpandedKeys] = useControlledState(\n props.expandedKeys ? new Set(props.expandedKeys) : undefined,\n props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(),\n onExpandedChange\n );\n\n let selectionState = useMultipleSelectionState(props);\n let disabledKeys = useMemo(\n () => (props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()),\n [props.disabledKeys]\n );\n\n let tree = useCollection(\n props,\n useCallback(nodes => new TreeCollection(nodes, {expandedKeys}), [expandedKeys]),\n null\n );\n\n // Reset focused key if that item is deleted from the collection.\n useEffect(() => {\n if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) {\n selectionState.setFocusedKey(null);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [tree, selectionState.focusedKey]);\n\n let onToggle = (key: Key) => {\n setExpandedKeys(toggleKey(expandedKeys, key));\n };\n\n return {\n collection: tree,\n expandedKeys,\n disabledKeys,\n toggleKey: onToggle,\n setExpandedKeys,\n selectionManager: new SelectionManager(tree, selectionState)\n };\n}\n\nfunction toggleKey(set: Set<Key>, key: Key): Set<Key> {\n let res = new Set(set);\n if (res.has(key)) {\n res.delete(key);\n } else {\n res.add(key);\n }\n\n return res;\n}\n"],"names":[],"version":3,"file":"useTreeState.mjs.map"}