mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-06 16:06:28 +08:00
fix: fix tree key ts type (#23348)
* fix tree key ts type * revert snap
This commit is contained in:
parent
5e7f3cc67e
commit
c70b49a709
@ -3,7 +3,7 @@ import classNames from 'classnames';
|
|||||||
import omit from 'omit.js';
|
import omit from 'omit.js';
|
||||||
import debounce from 'lodash/debounce';
|
import debounce from 'lodash/debounce';
|
||||||
import { conductExpandParent } from 'rc-tree/lib/util';
|
import { conductExpandParent } from 'rc-tree/lib/util';
|
||||||
import { EventDataNode, DataNode } from 'rc-tree/lib/interface';
|
import { EventDataNode, DataNode, Key } from 'rc-tree/lib/interface';
|
||||||
import { convertDataToEntities, convertTreeToData } from 'rc-tree/lib/utils/treeUtil';
|
import { convertDataToEntities, convertTreeToData } from 'rc-tree/lib/utils/treeUtil';
|
||||||
import FileOutlined from '@ant-design/icons/FileOutlined';
|
import FileOutlined from '@ant-design/icons/FileOutlined';
|
||||||
import FolderOpenOutlined from '@ant-design/icons/FolderOpenOutlined';
|
import FolderOpenOutlined from '@ant-design/icons/FolderOpenOutlined';
|
||||||
@ -20,8 +20,8 @@ export interface DirectoryTreeProps extends TreeProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface DirectoryTreeState {
|
export interface DirectoryTreeState {
|
||||||
expandedKeys?: string[];
|
expandedKeys?: Key[];
|
||||||
selectedKeys?: string[];
|
selectedKeys?: Key[];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getIcon(props: AntdTreeNodeAttribute): React.ReactNode {
|
function getIcon(props: AntdTreeNodeAttribute): React.ReactNode {
|
||||||
@ -60,9 +60,9 @@ class DirectoryTree extends React.Component<DirectoryTreeProps, DirectoryTreeSta
|
|||||||
onDebounceExpand: (event: React.MouseEvent<HTMLElement>, node: EventDataNode) => void;
|
onDebounceExpand: (event: React.MouseEvent<HTMLElement>, node: EventDataNode) => void;
|
||||||
|
|
||||||
// Shift click usage
|
// Shift click usage
|
||||||
lastSelectedKey?: string;
|
lastSelectedKey?: Key;
|
||||||
|
|
||||||
cachedSelectedKeys?: string[];
|
cachedSelectedKeys?: Key[];
|
||||||
|
|
||||||
constructor(props: DirectoryTreeProps) {
|
constructor(props: DirectoryTreeProps) {
|
||||||
super(props);
|
super(props);
|
||||||
@ -93,7 +93,7 @@ class DirectoryTree extends React.Component<DirectoryTreeProps, DirectoryTreeSta
|
|||||||
}
|
}
|
||||||
|
|
||||||
onExpand = (
|
onExpand = (
|
||||||
expandedKeys: string[],
|
expandedKeys: Key[],
|
||||||
info: {
|
info: {
|
||||||
node: EventDataNode;
|
node: EventDataNode;
|
||||||
expanded: boolean;
|
expanded: boolean;
|
||||||
@ -139,7 +139,7 @@ class DirectoryTree extends React.Component<DirectoryTreeProps, DirectoryTreeSta
|
|||||||
};
|
};
|
||||||
|
|
||||||
onSelect = (
|
onSelect = (
|
||||||
keys: string[],
|
keys: Key[],
|
||||||
event: {
|
event: {
|
||||||
event: 'select';
|
event: 'select';
|
||||||
selected: boolean;
|
selected: boolean;
|
||||||
@ -167,7 +167,7 @@ class DirectoryTree extends React.Component<DirectoryTreeProps, DirectoryTreeSta
|
|||||||
const shiftPick: boolean = nativeEvent.shiftKey;
|
const shiftPick: boolean = nativeEvent.shiftKey;
|
||||||
|
|
||||||
// Generate new selected keys
|
// Generate new selected keys
|
||||||
let newSelectedKeys: string[];
|
let newSelectedKeys: Key[];
|
||||||
if (multiple && ctrlPick) {
|
if (multiple && ctrlPick) {
|
||||||
// Control click
|
// Control click
|
||||||
newSelectedKeys = keys;
|
newSelectedKeys = keys;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import RcTree, { TreeNode, TreeProps as RcTreeProps } from 'rc-tree';
|
import RcTree, { TreeNode, TreeProps as RcTreeProps } from 'rc-tree';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { DataNode } from 'rc-tree/lib/interface';
|
import { DataNode, Key } from 'rc-tree/lib/interface';
|
||||||
|
|
||||||
import DirectoryTree from './DirectoryTree';
|
import DirectoryTree from './DirectoryTree';
|
||||||
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
|
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
|
||||||
@ -34,7 +34,7 @@ export interface AntTreeNodeProps {
|
|||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
disableCheckbox?: boolean;
|
disableCheckbox?: boolean;
|
||||||
title?: string | React.ReactNode;
|
title?: string | React.ReactNode;
|
||||||
key?: string;
|
key?: Key;
|
||||||
eventKey?: string;
|
eventKey?: string;
|
||||||
isLeaf?: boolean;
|
isLeaf?: boolean;
|
||||||
checked?: boolean;
|
checked?: boolean;
|
||||||
@ -76,13 +76,13 @@ export interface AntTreeNodeMouseEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface AntTreeNodeDragEnterEvent extends AntTreeNodeMouseEvent {
|
export interface AntTreeNodeDragEnterEvent extends AntTreeNodeMouseEvent {
|
||||||
expandedKeys: string[];
|
expandedKeys: Key[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AntTreeNodeDropEvent {
|
export interface AntTreeNodeDropEvent {
|
||||||
node: AntTreeNode;
|
node: AntTreeNode;
|
||||||
dragNode: AntTreeNode;
|
dragNode: AntTreeNode;
|
||||||
dragNodesKeys: string[];
|
dragNodesKeys: Key[];
|
||||||
dropPosition: number;
|
dropPosition: number;
|
||||||
dropToGap?: boolean;
|
dropToGap?: boolean;
|
||||||
event: React.MouseEvent<HTMLElement>;
|
event: React.MouseEvent<HTMLElement>;
|
||||||
@ -109,21 +109,21 @@ export interface TreeProps extends Omit<RcTreeProps, 'prefixCls'> {
|
|||||||
/** 默认展开对应树节点 */
|
/** 默认展开对应树节点 */
|
||||||
defaultExpandParent?: boolean;
|
defaultExpandParent?: boolean;
|
||||||
/** 默认展开指定的树节点 */
|
/** 默认展开指定的树节点 */
|
||||||
defaultExpandedKeys?: string[];
|
defaultExpandedKeys?: Key[];
|
||||||
/** (受控)展开指定的树节点 */
|
/** (受控)展开指定的树节点 */
|
||||||
expandedKeys?: string[];
|
expandedKeys?: Key[];
|
||||||
/** (受控)选中复选框的树节点 */
|
/** (受控)选中复选框的树节点 */
|
||||||
checkedKeys?: string[] | { checked: string[]; halfChecked: string[] };
|
checkedKeys?: Key[] | { checked: Key[]; halfChecked: Key[] };
|
||||||
/** 默认选中复选框的树节点 */
|
/** 默认选中复选框的树节点 */
|
||||||
defaultCheckedKeys?: string[];
|
defaultCheckedKeys?: Key[];
|
||||||
/** (受控)设置选中的树节点 */
|
/** (受控)设置选中的树节点 */
|
||||||
selectedKeys?: string[];
|
selectedKeys?: Key[];
|
||||||
/** 默认选中的树节点 */
|
/** 默认选中的树节点 */
|
||||||
defaultSelectedKeys?: string[];
|
defaultSelectedKeys?: Key[];
|
||||||
selectable?: boolean;
|
selectable?: boolean;
|
||||||
/** 点击树节点触发 */
|
/** 点击树节点触发 */
|
||||||
filterAntTreeNode?: (node: AntTreeNode) => boolean;
|
filterAntTreeNode?: (node: AntTreeNode) => boolean;
|
||||||
loadedKeys?: string[];
|
loadedKeys?: Key[];
|
||||||
/** 设置节点可拖拽(IE>8) */
|
/** 设置节点可拖拽(IE>8) */
|
||||||
draggable?: boolean;
|
draggable?: boolean;
|
||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { DataNode } from 'rc-tree/lib/interface';
|
import { DataNode, Key } from 'rc-tree/lib/interface';
|
||||||
|
|
||||||
enum Record {
|
enum Record {
|
||||||
None,
|
None,
|
||||||
@ -8,7 +8,7 @@ enum Record {
|
|||||||
|
|
||||||
function traverseNodesKey(
|
function traverseNodesKey(
|
||||||
treeData: DataNode[],
|
treeData: DataNode[],
|
||||||
callback: (key: string | number | null, node: DataNode) => boolean,
|
callback: (key: Key | number | null, node: DataNode) => boolean,
|
||||||
) {
|
) {
|
||||||
function processNode(dataNode: DataNode) {
|
function processNode(dataNode: DataNode) {
|
||||||
const { key, children } = dataNode;
|
const { key, children } = dataNode;
|
||||||
@ -23,11 +23,11 @@ function traverseNodesKey(
|
|||||||
/** 计算选中范围,只考虑expanded情况以优化性能 */
|
/** 计算选中范围,只考虑expanded情况以优化性能 */
|
||||||
export function calcRangeKeys(
|
export function calcRangeKeys(
|
||||||
treeData: DataNode[],
|
treeData: DataNode[],
|
||||||
expandedKeys: string[],
|
expandedKeys: Key[],
|
||||||
startKey?: string,
|
startKey?: Key,
|
||||||
endKey?: string,
|
endKey?: Key,
|
||||||
): string[] {
|
): Key[] {
|
||||||
const keys: string[] = [];
|
const keys: Key[] = [];
|
||||||
let record: Record = Record.None;
|
let record: Record = Record.None;
|
||||||
|
|
||||||
if (startKey && startKey === endKey) {
|
if (startKey && startKey === endKey) {
|
||||||
@ -37,11 +37,11 @@ export function calcRangeKeys(
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
function matchKey(key: string) {
|
function matchKey(key: Key) {
|
||||||
return key === startKey || key === endKey;
|
return key === startKey || key === endKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
traverseNodesKey(treeData, (key: string) => {
|
traverseNodesKey(treeData, (key: Key) => {
|
||||||
if (record === Record.End) {
|
if (record === Record.End) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -71,10 +71,10 @@ export function calcRangeKeys(
|
|||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertDirectoryKeysToNodes(treeData: DataNode[], keys: string[]) {
|
export function convertDirectoryKeysToNodes(treeData: DataNode[], keys: Key[]) {
|
||||||
const restKeys: string[] = [...keys];
|
const restKeys: Key[] = [...keys];
|
||||||
const nodes: DataNode[] = [];
|
const nodes: DataNode[] = [];
|
||||||
traverseNodesKey(treeData, (key: string, node: DataNode) => {
|
traverseNodesKey(treeData, (key: Key, node: DataNode) => {
|
||||||
const index = restKeys.indexOf(key);
|
const index = restKeys.indexOf(key);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
nodes.push(node);
|
nodes.push(node);
|
||||||
|
Loading…
Reference in New Issue
Block a user