/* * Copyright 2026 Hypergiant Galactic Systems Inc. All rights reserved. * This file is licensed to you under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. You may obtain a copy * of the License at https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS * OF ANY KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ import { ReactElement } from "react"; import { DropTarget, Selection } from "react-aria-components/Tree"; import { DragItem, DroppableCollectionInsertDropEvent, DroppableCollectionOnItemDropEvent, DroppableCollectionReorderEvent, DroppableCollectionRootDropEvent, Key } from "@react-types/shared"; //#region src/hooks/use-tree/types.d.ts /** Configuration for tree drag-and-drop behavior */ type DragAndDropConfig = { /** Returns drag items for the given keys */ getItems: (key: Set) => DragItem[]; /** * Handler that is called when external items are dropped on the droppable collection's root. */ onRootDrop?: (e: DroppableCollectionRootDropEvent) => void; /** * Handler that is called when items are reordered within the collection. * This handler only allows dropping between items, not on items. * It does not allow moving items to a different parent item within a tree. */ onReorder?: (e: DroppableCollectionReorderEvent) => void; /** * Handler that is called when items are moved within the source collection. * This handler allows dropping both on or between items, and items may be * moved to a different parent item within a tree. */ onMove?: (e: DroppableCollectionReorderEvent) => void; /** Custom drag preview renderer */ renderDragPreview?: (items: DragItem[]) => ReactElement; /** Custom drop indicator renderer */ renderDropIndicator?: (target: DropTarget) => ReactElement; /** Accepted MIME types for drops */ acceptedDragTypes?: string[]; /** * Handler that is called when external items are dropped "between" items. */ onInsert?: (e: DroppableCollectionInsertDropEvent) => void; /** * Handler that is called when items are dropped "on" an item. */ onItemDrop?: (e: DroppableCollectionOnItemDropEvent) => void; }; /** * Options for the useTreeState hook. * * @template T - The type of custom values stored in tree nodes (accessed via `node.values`). */ type UseTreeStateOptions = { /** Initial root items in the tree. If omitted, will return an empty tree. */ items: TreeNode[]; /** * Enable semantic cascade selection mode. When true, selecting a parent * automatically selects all descendants, and parent state reflects children * (selected/indeterminate/unselected). Only works with dynamic collections. * @default false */ selectionCascade?: boolean; }; /** * Return value from the useTreeState hook. * * @template T - The type of custom values stored in tree nodes (accessed via `node.values`). */ type UseTreeState = { /** Current tree nodes */ nodes: TreeNode[]; /** Drag-and-drop configuration for the tree */ dragAndDropConfig: DragAndDropConfig; /** Tree manipulation actions */ actions: { /** Collapse all nodes */ collapseAll: () => void; /** Expand all nodes */ expandAll: () => void; /** Handle expansion state changes */ onExpandedChange: (keys: Set) => void; /** Select all nodes */ selectAll: () => void; /** Unselect all nodes */ unselectAll: () => void; /** Handle selection state changes */ onSelectionChange: (keys: Selection) => void; /** Hide all nodes */ hideAll: () => void; /** Reveal all nodes */ revealAll: () => void; /** Handle visibility state changes */ onVisibilityChange: (keys: Set) => void; }; }; /** * Array of tree nodes representing tree data. * * @template T - The type of custom values stored in tree nodes (accessed via `node.values`). */ type TreeData = TreeNode[]; /** * The TreeNode is a wrapper that describes the relationship of this node * to other nodes in the tree. * TreeNode properties describe the metadata - state and position of the node. * The item property represents the action tree item data. * * @template T - The type of custom values stored in the node (accessed via `node.values`). */ type TreeNodeBase = { /** A unique key for the tree node. */ key: Key; /** Label string **/ label: string; /** Application specific values in node **/ values?: T; /** Whether node has interactive capability **/ isDisabled?: boolean; /** Whether node children are rendered **/ isExpanded?: boolean; /** Node selection marker **/ isSelected?: boolean; /** Whether node visibility is marked on or off **/ isVisible?: boolean; /** Computed actual visibility based on ancestors and self visibility **/ isVisibleComputed?: boolean; /** Computed indeterminate state for cascade selection (some but not all descendants selected) **/ isIndeterminate?: boolean; }; /** * A tree node including parent and child relationships. * * Extends {@link TreeNodeBase} with structural position metadata — * the parent key and nested children — used to represent the full tree hierarchy. * * @template T - The type of custom values stored in the node (accessed via `node.values`). */ type TreeNode = TreeNodeBase & { /** The key of the parent node. */ parentKey?: Key | null; /** Children of the tree node. */ children?: TreeNode[]; }; /** * Options for the useTreeActions hook. * * @template T - The type of custom values stored in tree nodes (accessed via `node.values`). */ type UseTreeActionsOptions = { /** Current tree nodes to operate on */ nodes: TreeNode[]; /** * Enable semantic cascade selection mode. * @default false */ selectionCascade?: boolean; }; /** * Stateless collection of transform actions to simplify tree operations. * * @template T - The type of custom values stored in tree nodes (accessed via `node.values`). */ type TreeActions = { /** * Retrieves a specific tree node by key * If not found, throws error */ getNode: (key: Key) => TreeNode; /** * Inserts nodes as children of the target node */ insertInto: (target: Key | null, nodes: TreeNode[]) => TreeData; /** * Inserts nodes before the target node */ insertBefore: (target: Key | null, nodes: TreeNode[]) => TreeData; /** * Inserts nodes after the target node */ insertAfter: (target: Key | null, nodes: TreeNode[]) => TreeData; /** * Removes one or more nodes from the tree by their keys. * Does nothing if the key is not found. */ remove: (keys: Set) => TreeData; /** * Updates a specific node using a callback function */ updateNode: (key: Key, callback: (node: TreeNode) => TreeNode) => TreeData; /** * Moves nodes as children of the target node */ moveInto: (target: Key | null, nodes: Set) => TreeData; /** * Moves nodes before the target node */ moveBefore: (target: Key | null, nodes: Set) => TreeData; /** * Moves nodes after the target node */ moveAfter: (target: Key | null, nodes: Set) => TreeData; /** * Updates the expansion state of nodes. If a key is not * in the set, it is collapsed. */ onExpandedChange: (keys: Set) => TreeData; /** * Expands all nodes in the tree */ expandAll: () => TreeData; /** * Collapses all nodes in the tree */ collapseAll: () => TreeData; /** * Updates the selection state of nodes. If a key is * not in the Set, it is unselected. */ onSelectionChange: (keys: Set) => TreeData; /** * Selects all nodes in the tree */ selectAll: () => TreeData; /** * Unselects all nodes in the tree */ unselectAll: () => TreeData; /** * Changes visibility of nodes. Updates both isVisible and isViewable properties. * If a key is not in the Set, it will be hidden. */ onVisibilityChange: (keys: Set) => TreeData; /** * Makes all nodes visible in the tree */ revealAll: () => TreeData; /** * Hides all nodes in the tree */ hideAll: () => TreeData; }; //#endregion export { DragAndDropConfig, TreeActions, TreeData, TreeNode, TreeNodeBase, UseTreeActionsOptions, UseTreeState, UseTreeStateOptions }; //# sourceMappingURL=types.d.ts.map