fix[Tree]: Updated the draggable attribute to support DraggableConfig and DraggableFn
parent
e46d537d45
commit
73a499f137
|
@ -119,7 +119,6 @@ export const treeProps = () => {
|
||||||
selectable: booleanType(),
|
selectable: booleanType(),
|
||||||
|
|
||||||
loadedKeys: arrayType<Key[]>(),
|
loadedKeys: arrayType<Key[]>(),
|
||||||
draggable: booleanType(),
|
|
||||||
showIcon: booleanType(),
|
showIcon: booleanType(),
|
||||||
icon: functionType<(nodeProps: AntdTreeNodeAttribute) => any>(),
|
icon: functionType<(nodeProps: AntdTreeNodeAttribute) => any>(),
|
||||||
switcherIcon: PropTypes.any,
|
switcherIcon: PropTypes.any,
|
||||||
|
|
|
@ -26,7 +26,7 @@ Almost anything can be represented in a tree structure. Examples include directo
|
||||||
| checkStrictly | Check treeNode precisely; parent treeNode and children treeNodes are not associated | boolean | false | |
|
| checkStrictly | Check treeNode precisely; parent treeNode and children treeNodes are not associated | boolean | false | |
|
||||||
| defaultExpandAll | Whether to expand all treeNodes by default | boolean | false | |
|
| defaultExpandAll | Whether to expand all treeNodes by default | boolean | false | |
|
||||||
| disabled | whether disabled the tree | bool | false | |
|
| disabled | whether disabled the tree | bool | false | |
|
||||||
| draggable | Specifies whether this Tree is draggable (IE > 8) | boolean | false | |
|
| draggable | Specifies whether this Tree or the node is draggable. Use `icon: false` to disable drag handler icon (IE > 8) | boolean \| ((node: TreeNode) => boolean) \| { icon?: VNode \| false, nodeDraggable?: (node: TreeNode) => boolean } | false | |
|
||||||
| expandedKeys(v-model) | (Controlled) Specifies the keys of the expanded treeNodes | string\[] \| number\[] | \[] | |
|
| expandedKeys(v-model) | (Controlled) Specifies the keys of the expanded treeNodes | string\[] \| number\[] | \[] | |
|
||||||
| fieldNames | Replace the title,key and children fields in treeNode with the corresponding fields in treeData | object | { children:'children', title:'title', key:'key' } | 3.0.0 |
|
| fieldNames | Replace the title,key and children fields in treeNode with the corresponding fields in treeData | object | { children:'children', title:'title', key:'key' } | 3.0.0 |
|
||||||
| filterTreeNode | Defines a function to filter (highlight) treeNodes. When the function returns `true`, the corresponding treeNode will be highlighted | function(node) | - | |
|
| filterTreeNode | Defines a function to filter (highlight) treeNodes. When the function returns `true`, the corresponding treeNode will be highlighted | function(node) | - | |
|
||||||
|
|
|
@ -27,7 +27,7 @@ coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*1GeUQJPTGUYAAA
|
||||||
| checkStrictly | checkable 状态下节点选择完全受控(父子节点选中状态不再关联) | boolean | false | | |
|
| checkStrictly | checkable 状态下节点选择完全受控(父子节点选中状态不再关联) | boolean | false | | |
|
||||||
| defaultExpandAll | 默认展开所有树节点, 如果是异步数据,需要在数据返回后再实例化,建议用 v-if="data.length";当有 expandedKeys 时,defaultExpandAll 将失效 | boolean | false | | |
|
| defaultExpandAll | 默认展开所有树节点, 如果是异步数据,需要在数据返回后再实例化,建议用 v-if="data.length";当有 expandedKeys 时,defaultExpandAll 将失效 | boolean | false | | |
|
||||||
| disabled | 将树禁用 | bool | false | | |
|
| disabled | 将树禁用 | bool | false | | |
|
||||||
| draggable | 设置节点可拖拽 | boolean | false | | |
|
| draggable | 设置节点可拖拽,可以通过 `icon: false` 关闭拖拽提示图标 | boolean \| ((node: TreeNode) => boolean) \| { icon?: VNode \| false, nodeDraggable?: (node: TreeNode) => boolean } | false | | |
|
||||||
| expandedKeys(v-model) | (受控)展开指定的树节点 | string\[] \| number\[] | \[] | | |
|
| expandedKeys(v-model) | (受控)展开指定的树节点 | string\[] \| number\[] | \[] | | |
|
||||||
| fieldNames | 替换 treeNode 中 title,key,children 字段为 treeData 中对应的字段 | object | {children:'children', title:'title', key:'key' } | 3.0.0 | |
|
| fieldNames | 替换 treeNode 中 title,key,children 字段为 treeData 中对应的字段 | object | {children:'children', title:'title', key:'key' } | 3.0.0 | |
|
||||||
| filterTreeNode | 按需筛选树节点(高亮),返回 true | function(node) | - | | |
|
| filterTreeNode | 按需筛选树节点(高亮),返回 true | function(node) | - | | |
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/** Two char of 't' 'b' 'c' 'l' 'r'. Example: 'lt' */
|
/** Two char of 't' 'b' 'c' 'l' 'r'. Example: 'lt' */
|
||||||
export type AlignPoint = string;
|
export type AlignPoint = string;
|
||||||
|
export type OffsetType = number | `${number}%`;
|
||||||
|
|
||||||
export interface AlignType {
|
export interface AlignType {
|
||||||
/**
|
/**
|
||||||
|
@ -11,12 +12,12 @@ export interface AlignType {
|
||||||
* offset source node by offset[0] in x and offset[1] in y.
|
* offset source node by offset[0] in x and offset[1] in y.
|
||||||
* If offset contains percentage string value, it is relative to sourceNode region.
|
* If offset contains percentage string value, it is relative to sourceNode region.
|
||||||
*/
|
*/
|
||||||
offset?: number[];
|
offset?: OffsetType[];
|
||||||
/**
|
/**
|
||||||
* offset target node by offset[0] in x and offset[1] in y.
|
* offset target node by offset[0] in x and offset[1] in y.
|
||||||
* If targetOffset contains percentage string value, it is relative to targetNode region.
|
* If targetOffset contains percentage string value, it is relative to targetNode region.
|
||||||
*/
|
*/
|
||||||
targetOffset?: number[];
|
targetOffset?: OffsetType[];
|
||||||
/**
|
/**
|
||||||
* If adjustX field is true, will adjust source node in x direction if source node is invisible.
|
* If adjustX field is true, will adjust source node in x direction if source node is invisible.
|
||||||
* If adjustY field is true, will adjust source node in y direction if source node is invisible.
|
* If adjustY field is true, will adjust source node in y direction if source node is invisible.
|
||||||
|
|
|
@ -35,21 +35,17 @@ import {
|
||||||
toRaw,
|
toRaw,
|
||||||
} from 'vue';
|
} from 'vue';
|
||||||
import initDefaultProps from '../_util/props-util/initDefaultProps';
|
import initDefaultProps from '../_util/props-util/initDefaultProps';
|
||||||
import type { CheckInfo, DraggableFn } from './props';
|
import type { CheckInfo, DraggableConfig, DraggableFn } from './props';
|
||||||
import { treeProps } from './props';
|
import { treeProps } from './props';
|
||||||
import { warning } from '../vc-util/warning';
|
import { warning } from '../vc-util/warning';
|
||||||
import KeyCode from '../_util/KeyCode';
|
import KeyCode from '../_util/KeyCode';
|
||||||
import classNames from '../_util/classNames';
|
import classNames from '../_util/classNames';
|
||||||
import pickAttrs from '../_util/pickAttrs';
|
import pickAttrs from '../_util/pickAttrs';
|
||||||
import useMaxLevel from './useMaxLevel';
|
import useMaxLevel from './useMaxLevel';
|
||||||
|
import { HolderOutlined } from '@ant-design/icons-vue';
|
||||||
|
|
||||||
const MAX_RETRY_TIMES = 10;
|
const MAX_RETRY_TIMES = 10;
|
||||||
|
|
||||||
export type DraggableConfig = {
|
|
||||||
icon?: any;
|
|
||||||
nodeDraggable?: DraggableFn;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
compatConfig: { MODE: 3 },
|
compatConfig: { MODE: 3 },
|
||||||
name: 'Tree',
|
name: 'Tree',
|
||||||
|
@ -1145,10 +1141,12 @@ export default defineComponent({
|
||||||
draggableConfig = draggable;
|
draggableConfig = draggable;
|
||||||
} else if (typeof draggable === 'function') {
|
} else if (typeof draggable === 'function') {
|
||||||
draggableConfig = {
|
draggableConfig = {
|
||||||
nodeDraggable: draggable,
|
nodeDraggable: draggable as DraggableFn,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
draggableConfig = {};
|
draggableConfig = {
|
||||||
|
icon: <HolderOutlined />,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
draggableConfig = false;
|
draggableConfig = false;
|
||||||
|
|
|
@ -15,8 +15,7 @@ import type {
|
||||||
Direction,
|
Direction,
|
||||||
FlattenNode,
|
FlattenNode,
|
||||||
} from './interface';
|
} from './interface';
|
||||||
|
import { DraggableConfig } from './props';
|
||||||
import type { DraggableConfig } from './Tree';
|
|
||||||
|
|
||||||
export type NodeMouseEventParams = {
|
export type NodeMouseEventParams = {
|
||||||
event: MouseEvent;
|
event: MouseEvent;
|
||||||
|
|
|
@ -110,6 +110,10 @@ export type AllowDrop<TreeDataType extends BasicDataNode = DataNode> = (
|
||||||
) => boolean;
|
) => boolean;
|
||||||
|
|
||||||
export type DraggableFn = (node: DataNode) => boolean;
|
export type DraggableFn = (node: DataNode) => boolean;
|
||||||
|
export type DraggableConfig = {
|
||||||
|
icon?: any;
|
||||||
|
nodeDraggable?: DraggableFn;
|
||||||
|
};
|
||||||
export type ExpandAction = false | 'click' | 'doubleclick' | 'dblclick';
|
export type ExpandAction = false | 'click' | 'doubleclick' | 'dblclick';
|
||||||
export const treeProps = () => ({
|
export const treeProps = () => ({
|
||||||
prefixCls: String,
|
prefixCls: String,
|
||||||
|
@ -131,7 +135,7 @@ export const treeProps = () => ({
|
||||||
multiple: { type: Boolean, default: undefined },
|
multiple: { type: Boolean, default: undefined },
|
||||||
checkable: { type: Boolean, default: undefined },
|
checkable: { type: Boolean, default: undefined },
|
||||||
checkStrictly: { type: Boolean, default: undefined },
|
checkStrictly: { type: Boolean, default: undefined },
|
||||||
draggable: { type: [Function, Boolean] as PropType<DraggableFn | boolean> },
|
draggable: { type: [Function, Boolean] as PropType<DraggableConfig | DraggableFn | boolean> },
|
||||||
defaultExpandParent: { type: Boolean, default: undefined },
|
defaultExpandParent: { type: Boolean, default: undefined },
|
||||||
autoExpandParent: { type: Boolean, default: undefined },
|
autoExpandParent: { type: Boolean, default: undefined },
|
||||||
defaultExpandAll: { type: Boolean, default: undefined },
|
defaultExpandAll: { type: Boolean, default: undefined },
|
||||||
|
|
Loading…
Reference in New Issue