|
|
|
import * as React from 'react';
|
|
|
|
import HolderOutlined from '@ant-design/icons/HolderOutlined';
|
|
|
|
import RcTree, { TreeNode, TreeProps as RcTreeProps, BasicDataNode } from 'rc-tree';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import { DataNode, Key } from 'rc-tree/lib/interface';
|
|
|
|
import DirectoryTree from './DirectoryTree';
|
|
|
|
import { ConfigContext } from '../config-provider';
|
|
|
|
import collapseMotion from '../_util/motion';
|
|
|
|
import renderSwitcherIcon from './utils/iconUtil';
|
|
|
|
import dropIndicatorRender from './utils/dropIndicator';
|
|
|
|
|
|
|
|
export type SwitcherIcon = React.ReactNode | ((props: { expanded: boolean }) => React.ReactNode);
|
|
|
|
|
|
|
|
export interface AntdTreeNodeAttribute {
|
|
|
|
eventKey: string;
|
|
|
|
prefixCls: string;
|
|
|
|
className: string;
|
|
|
|
expanded: boolean;
|
|
|
|
selected: boolean;
|
|
|
|
checked: boolean;
|
|
|
|
halfChecked: boolean;
|
|
|
|
children: React.ReactNode;
|
|
|
|
title: React.ReactNode;
|
|
|
|
pos: string;
|
|
|
|
dragOver: boolean;
|
|
|
|
dragOverGapTop: boolean;
|
|
|
|
dragOverGapBottom: boolean;
|
|
|
|
isLeaf: boolean;
|
|
|
|
selectable: boolean;
|
|
|
|
disabled: boolean;
|
|
|
|
disableCheckbox: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface AntTreeNodeProps {
|
|
|
|
className?: string;
|
|
|
|
checkable?: boolean;
|
|
|
|
disabled?: boolean;
|
|
|
|
disableCheckbox?: boolean;
|
|
|
|
title?: string | React.ReactNode;
|
|
|
|
key?: Key;
|
|
|
|
eventKey?: string;
|
|
|
|
isLeaf?: boolean;
|
|
|
|
checked?: boolean;
|
|
|
|
expanded?: boolean;
|
|
|
|
loading?: boolean;
|
|
|
|
selected?: boolean;
|
|
|
|
selectable?: boolean;
|
|
|
|
icon?: ((treeNode: AntdTreeNodeAttribute) => React.ReactNode) | React.ReactNode;
|
|
|
|
children?: React.ReactNode;
|
|
|
|
[customProp: string]: any;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface AntTreeNode extends React.Component<AntTreeNodeProps, {}> {}
|
|
|
|
|
|
|
|
export interface AntTreeNodeBaseEvent {
|
|
|
|
node: AntTreeNode;
|
|
|
|
nativeEvent: MouseEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface AntTreeNodeCheckedEvent extends AntTreeNodeBaseEvent {
|
|
|
|
event: 'check';
|
|
|
|
checked?: boolean;
|
|
|
|
checkedNodes?: AntTreeNode[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface AntTreeNodeSelectedEvent extends AntTreeNodeBaseEvent {
|
|
|
|
event: 'select';
|
|
|
|
selected?: boolean;
|
|
|
|
selectedNodes?: DataNode[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface AntTreeNodeExpandedEvent extends AntTreeNodeBaseEvent {
|
|
|
|
expanded?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface AntTreeNodeMouseEvent {
|
|
|
|
node: AntTreeNode;
|
|
|
|
event: React.DragEvent<HTMLElement>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface AntTreeNodeDragEnterEvent extends AntTreeNodeMouseEvent {
|
|
|
|
expandedKeys: Key[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface AntTreeNodeDropEvent {
|
|
|
|
node: AntTreeNode;
|
|
|
|
dragNode: AntTreeNode;
|
|
|
|
dragNodesKeys: Key[];
|
|
|
|
dropPosition: number;
|
|
|
|
dropToGap?: boolean;
|
|
|
|
event: React.MouseEvent<HTMLElement>;
|
|
|
|
}
|
|
|
|
|
|
|
|
// [Legacy] Compatible for v3
|
|
|
|
export type TreeNodeNormal = DataNode;
|
|
|
|
|
|
|
|
type DraggableFn = (node: AntTreeNode) => boolean;
|
|
|
|
interface DraggableConfig {
|
|
|
|
icon?: React.ReactNode | false;
|
|
|
|
nodeDraggable?: DraggableFn;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface TreeProps<T extends BasicDataNode = DataNode>
|
|
|
|
extends Omit<RcTreeProps<T>, 'prefixCls' | 'showLine' | 'direction' | 'draggable'> {
|
|
|
|
showLine?: boolean | { showLeafIcon: boolean };
|
|
|
|
className?: string;
|
|
|
|
/** 是否支持多选 */
|
|
|
|
multiple?: boolean;
|
|
|
|
/** 是否自动展开父节点 */
|
|
|
|
autoExpandParent?: boolean;
|
|