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