UNPKG

7.37 kBTypeScriptView Raw
1import { CreateElement, VNode } from 'vue';
2import { ElementUIComponent } from './component';
3
4export interface TreeData {
5 id?: any;
6 label?: string;
7 isLeaf?: boolean;
8 children?: TreeData[];
9}
10
11export interface TreeNode<K, D> {
12 checked: boolean;
13 childNodes: TreeNode<K, D>[];
14 data: D;
15 expanded: boolean;
16 id: number;
17 indeterminate: boolean;
18 isLeaf: boolean;
19 level: number;
20 loaded: boolean;
21 loading: boolean;
22 parent: TreeNode<K, D> | null;
23 store: any;
24 visible: boolean;
25 disabled: boolean;
26 icon: string;
27 key: K;
28 nextSibling: TreeNode<K, D> | null;
29 previousSibling: TreeNode<K, D> | null;
30}
31
32/** incomplete, you can convert to any to use other properties */
33export interface TreeStore<K, D> {
34 _getAllNodes: () => TreeNode<K, D>[];
35}
36
37/** Tree Component */
38export declare class ElTree<K = any, D = TreeData> extends ElementUIComponent {
39 /** TreeStore */
40 store: TreeStore<K, D>;
41
42 /** Tree data */
43 data: D[];
44
45 /** Text displayed when data is void */
46 emptyText: string;
47
48 /** Unique identity key name for nodes, its value should be unique across the whole tree */
49 nodeKey: string;
50
51 /** Configuration options, see the following table */
52 props: object;
53
54 /** Method for loading subtree data */
55 load: (data: D, resolve: Function) => void;
56
57 /**
58 * Render function for a specific node
59 *
60 * @param h The render function
61 */
62 renderContent: (h: CreateElement, context: { node: TreeNode<K, D>; data: D; store: TreeStore<K, D> }) => VNode;
63
64 /** Whether current node is highlighted */
65 highlightCurrent: boolean;
66
67 /** Whether to expand all nodes by default */
68 defaultExpandAll: boolean;
69
70 /** Whether to expand or collapse node when clicking on the node. If false, then expand or collapse node only when clicking on the arrow icon. */
71 expandOnClickNode: boolean;
72
73 /** Whether to check or uncheck node when clicking on the node, if false, the node can only be checked or unchecked by clicking on the checkbox. */
74 checkOnClickNode: boolean;
75
76 /** Whether to expand father node when a child node is expanded */
77 autoExpandParent: boolean;
78
79 /** Array of keys of initially expanded nodes */
80 defaultExpandedKeys: K[];
81
82 /** Whether node is selectable */
83 showCheckbox: boolean;
84
85 /** Whether checked state of a node not affects its father and child nodes when show-checkbox is true */
86 checkStrictly: boolean;
87
88 /** Array of keys of initially checked nodes */
89 defaultCheckedKeys: K[];
90
91 /**
92 * This function will be executed on each node when use filter method. If return false, tree node will be hidden.
93 *
94 * @param value The query string
95 * @param data The original data object
96 * @param node Tree node
97 */
98 filterNodeMethod: (value: string, data: D, node: TreeNode<K, D>) => boolean;
99
100 /** Whether only one node among the same level can be expanded at one time */
101 accordion: boolean;
102
103 /** Horizontal indentation of nodes in adjacent levels in pixels */
104 indent: number;
105
106 /** Whether enable tree nodes drag and drop */
107 draggable: boolean;
108
109 /**
110 * Function to be executed before dragging a node
111 *
112 * @param node The node to be dragged
113 */
114 allowDrag: (node: TreeNode<K, D>) => boolean;
115
116 /**
117 * Function to be executed before the dragging node is dropped
118 *
119 * @param draggingNode The dragging node
120 * @param dropNode The target node
121 * @param type Drop type
122 */
123 allowDrop: (draggingNode: TreeNode<K, D>, dropNode: TreeNode<K, D>, type: 'prev' | 'inner' | 'next') => boolean;
124
125 /**
126 * Filter all tree nodes. Filtered nodes will be hidden
127 *
128 * @param value The value to be used as first parameter for `filter-node-method`
129 */
130 filter(value: any): void;
131
132 /**
133 * Update the children of the node which specified by the key
134 *
135 * @param key the key of the node which children will be updated
136 * @param data the children data
137 */
138 updateKeyChildren(key: K, data: D[]): void;
139
140 /**
141 * If the node can be selected (`show-checkbox` is `true`), it returns the currently selected array of nodes
142 *
143 * @param leafOnly If the `leafOnly` is `true`, it only returns the currently selected array of sub-nodes
144 * @param includeHalfChecked If the `includeHalfChecked` is `true`, the return value contains halfchecked nodes
145 */
146 getCheckedNodes(leafOnly?: boolean, includeHalfChecked?: boolean): D[];
147
148 /**
149 * Set certain nodes to be checked. Only works when `node-key` is assigned
150 *
151 * @param nodes An array of nodes to be checked
152 * @param leafOnly If the parameter is true, it only returns the currently selected array of sub-nodes
153 */
154 setCheckedNodes(data: D[], leafOnly?: boolean): void;
155
156 /**
157 * If the node can be selected (`show-checkbox` is `true`), it returns the currently selected array of nodes' keys
158 *
159 * @param leafOnly If the `leafOnly` is `true`, it only returns the currently selected array of sub-nodes
160 */
161 getCheckedKeys(leafOnly?: boolean): K[];
162
163 /**
164 * Set certain nodes to be checked. Only works when `node-key` is assigned
165 *
166 * @param keys An array of node's keys to be checked
167 * @param leafOnly If the parameter is true, it only returns the currently selected array of sub-nodes
168 */
169 setCheckedKeys(keys: K[], leafOnly?: boolean): void;
170
171 /**
172 * Set node to be checked or not. Only works when `node-key` is assigned
173 *
174 * @param data Node's key or data to be checked
175 * @param checked Indicating the node checked or not
176 * @param deep Indicating whether to checked state deeply or not
177 */
178 setChecked(data: D | K, checked: boolean, deep: boolean): void;
179
180 /**
181 * If the node can be selected (`show-checkbox` is `true`), it returns the currently half selected array of nodes
182 */
183 getHalfCheckedNodes(): D[];
184
185 /**
186 * If the node can be selected (`show-checkbox` is `true`), it returns the currently half selected array of nodes' keys
187 */
188 getHalfCheckedKeys(): K[];
189
190 /**
191 * Return the highlight node's key (null if no node is highlighted)
192 */
193 getCurrentKey(): K;
194
195 /**
196 * Set highlighted node by key, only works when node-key is assigned
197 *
198 * @param key The node's key to be highlighted
199 */
200 setCurrentKey(key: K): void;
201
202 /**
203 * Return the highlight node (null if no node is highlighted)
204 */
205 getCurrentNode(): D;
206
207 /**
208 * Set highlighted node, only works when node-key is assigned
209 *
210 * @param node The node to be highlighted
211 */
212 setCurrentNode(data: D): void;
213
214 /**
215 * Get node by node key or node data
216 *
217 * @param by node key or node data
218 */
219 getNode(by: D | K): D;
220
221 /**
222 * Remove node by key or node data or node instance
223 *
224 * @param by key or node data or node instance
225 */
226 remove(by: D | K): void;
227
228 /**
229 * Append a child node to specified node
230 *
231 * @param childData the data of appended node
232 * @param parent key or node data or node instance of the parent node
233 */
234 append(childData: D, parent: D | K): void;
235
236 /**
237 * insert a node before specified node
238 *
239 * @param data the data of inserted node
240 * @param ref key or node data or node instance of the reference node
241 */
242 insertBefore(data: D, ref: D | K): void;
243
244 /**
245 * insert a node after specified node
246 *
247 * @param data the data of inserted node
248 * @param ref key or node data or node instance of the reference node
249 */
250 insertAfter(data: D, ref: D | K): void;
251}