import type * as React from 'react'; import type { SemanticClassName } from "../_util/classNameUtils"; import type { RequestConfig, SafeKey } from "../_util/type"; import type { CheckboxProps } from '../checkbox'; import type { SpinProps } from '../spin'; import type { ScrollTo, VirtualListProps } from '../virtual-list'; import type { NodeDragEventParams, NodeMouseEventHandler, NodeMouseEventParams } from './context'; export interface CheckInfo { event: 'check'; node: EventDataNode; checked: boolean; nativeEvent: MouseEvent; checkedNodes: TreeDataType[]; checkedNodesPositions?: { node: TreeDataType; pos: string; }[]; halfCheckedKeys?: Key[]; } export interface AllowDropOptions { dragNode: TreeDataType; dropNode: TreeDataType; dropPosition: -1 | 0 | 1; } export type AllowDrop = (options: AllowDropOptions) => boolean; export type DraggableFn = (node: DataNode) => boolean; export type DraggableConfig = { icon?: React.ReactNode | boolean; nodeDraggable?: DraggableFn; }; export type ExpandAction = false | 'click' | 'doubleClick'; export interface TreeProps { prefixCls?: string; className?: SemanticClassName<{ view?: string; node: TreeNodeProps['className']; }>; style?: React.CSSProperties; treeData?: TreeDataType[]; fieldNames?: FieldNames; showLine?: boolean | 'hover'; showIcon?: boolean; loading?: boolean | SpinProps; icon?: IconType; selectable?: boolean; expandAction?: ExpandAction; disabled?: boolean; multiple?: boolean; checkable?: boolean; checkStrictly?: boolean; draggable?: DraggableFn | boolean | DraggableConfig; autoExpandParent?: boolean; defaultExpandAll?: boolean; defaultExpandedKeys?: Key[]; expandedKeys?: Key[]; defaultCheckedKeys?: Key[]; checkedKeys?: Key[] | { checked: Key[]; halfChecked: Key[]; }; defaultSelectedKeys?: Key[]; selectedKeys?: Key[]; allowDrop?: AllowDrop; titleRender?: (node: TreeDataType) => React.ReactNode; dropIndicatorRender?: (props: { dropPosition: -1 | 0 | 1; dropLevelOffset: number; indent: number; prefixCls: string; }) => React.ReactNode; onContextMenu?: React.MouseEventHandler; onClick?: NodeMouseEventHandler; onDoubleClick?: NodeMouseEventHandler; onScroll?: VirtualListProps['onScroll']; onExpand?: (expandedKeys: Key[], info: { node: EventDataNode; expanded: boolean; nativeEvent: MouseEvent; }) => void; onCheck?: (checked: { checked: Key[]; halfChecked: Key[]; } | Key[], info: CheckInfo) => void; onSelect?: (selectedKeys: Key[], info: { event: 'select'; selected: boolean; node: EventDataNode; selectedNodes: TreeDataType[]; nativeEvent: MouseEvent; }) => void; loadedKeys?: Key[]; onMouseEnter?: (info: NodeMouseEventParams) => void; onMouseLeave?: (info: NodeMouseEventParams) => void; onRightClick?: (info: { event: React.MouseEvent; node: EventDataNode; }) => void; onDragStart?: (info: NodeDragEventParams) => void; onDragEnter?: (info: NodeDragEventParams & { expandedKeys: Key[]; }) => void; onDragOver?: (info: NodeDragEventParams) => void; onDragLeave?: (info: NodeDragEventParams) => void; onDragEnd?: (info: NodeDragEventParams) => void; onDrop?: (info: NodeDragEventParams & { dragNode: EventDataNode; dragNodesKeys: Key[]; dropPosition: number; dropToGap: boolean; }) => void; switcherIcon?: IconType; virtual?: boolean; indent?: number; lazyLoad?: LazyLoadType; request?: GetRequestType; } export type TreeRef = { scrollTo: ScrollTo; setTreeData: (data: TreeDataType[] | ((oldData: TreeDataType[]) => TreeDataType[] | undefined)) => void; }; export interface TreeNodeProps { eventKey: Key; className?: SemanticClassName<{ switcher?: string; content?: string; icon?: string; title?: string; indent?: string; checkbox?: CheckboxProps['className']; }, { selected?: boolean; checked?: boolean; halfChecked?: boolean; leaf?: boolean; expanded?: boolean; }>; style?: React.CSSProperties; id?: string; expanded?: boolean; selected?: boolean; checked?: boolean; loaded?: boolean; loading?: boolean; halfChecked?: boolean; title?: React.ReactNode | ((data: TreeDataType) => React.ReactNode); dragOver?: boolean; dragOverGapTop?: boolean; dragOverGapBottom?: boolean; pos: string; data: TreeDataType; isStart: boolean[]; isEnd: boolean[]; onMouseMove?: React.MouseEventHandler; leaf?: boolean; checkable?: boolean; selectable?: boolean; disabled?: boolean; disableCheckbox?: boolean; icon?: IconType; switcherIcon?: IconType; children?: React.ReactNode; } /** For fieldNames, we provides a abstract interface */ export interface BasicDataNode { checkable?: boolean; disableCheckbox?: boolean; icon?: IconType; selectable?: boolean; switcherIcon?: IconType; /** Set style of TreeNode. This is not recommend if you don't have any force requirement */ className?: TreeNodeProps['className']; style?: React.CSSProperties; [key: string]: any; } /** Provide a wrap type define for developer to wrap with customize fieldNames data type */ export type FieldDataNode = BasicDataNode & T & Partial[]>>; export type Key = SafeKey; export type KeyEntities = Record>; export type DataNode = FieldDataNode<{ key: Key; title?: React.ReactNode | ((data: DataNode) => React.ReactNode); }>; export type EventDataNode = { key: Key; expanded: boolean; selected: boolean; checked: boolean; loaded: boolean; loading: boolean; halfChecked: boolean; dragOver: boolean; dragOverGapTop: boolean; dragOverGapBottom: boolean; pos: string; } & TreeDataType & BasicDataNode; export type IconType = React.ReactNode | ((props: TreeNodeProps) => React.ReactNode); export type NodeElement = React.ReactElement & { selectHandle?: HTMLSpanElement; type: { isTreeNode: boolean; }; }; export interface Entity { node: NodeElement; index: number; key: Key; pos: string; parent?: Entity; children?: Entity[]; } export interface DataEntity extends Omit { node: TreeDataType; nodes: TreeDataType[]; parent?: DataEntity; children?: DataEntity[]; level: number; } export interface FlattenNode { parent: FlattenNode | null; children: FlattenNode[] | null; pos: string; data: TreeDataType; title: React.ReactNode; key: Key; isStart: boolean[]; isEnd: boolean[]; disabled?: boolean; leaf?: boolean; } export type GetKey = (record: RecordType, index?: number) => Key; export type GetCheckDisabled = (record: RecordType) => boolean; export interface FieldNames { title?: keyof TreeDataType; /** @private Internal usage for `tree-select`, safe to remove if no need */ _title?: (keyof TreeDataType)[]; key?: keyof TreeDataType; children?: keyof TreeDataType; leaf?: keyof TreeDataType; disabled?: keyof TreeDataType; } export interface FilledFieldNames { title: string; _title: string[]; key: string; children: string; leaf: string; disabled: string; } export type GetRequestType = LazyLoadType extends true ? RequestConfig : RequestConfig;