Skip to content

Commit a503449

Browse files
author
Cat
committed
Tree: fix type definition error and format code
1 parent cc39bf1 commit a503449

File tree

1 file changed

+53
-72
lines changed

1 file changed

+53
-72
lines changed

types/tree.d.ts

Lines changed: 53 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { CreateElement, VNode } from 'vue'
2-
import { ElementUIComponent } from './component'
1+
import { CreateElement, VNode } from 'vue';
2+
import { ElementUIComponent } from './component';
33

44
export interface TreeData {
5-
id?: any,
6-
label?: string,
7-
isLeaf?: boolean,
8-
children?: TreeData[]
5+
id?: any;
6+
label?: string;
7+
isLeaf?: boolean;
8+
children?: TreeData[];
99
}
1010

1111
export interface TreeNode<K, D> {
1212
checked: boolean;
13-
childNodes: TreeNode[];
13+
childNodes: TreeNode<K, D>[];
1414
data: D;
1515
expanded: boolean;
1616
id: number;
@@ -19,93 +19,74 @@ export interface TreeNode<K, D> {
1919
level: number;
2020
loaded: boolean;
2121
loading: boolean;
22-
parent: TreeNode | null;
22+
parent: TreeNode<K, D> | null;
2323
store: any;
2424
visible: boolean;
2525
disabled: boolean;
2626
icon: string;
2727
key: K;
28-
nextSibling: TreeNode | null;
29-
previousSibling: TreeNode | null;
28+
nextSibling: TreeNode<K, D> | null;
29+
previousSibling: TreeNode<K, D> | null;
3030
}
3131

3232
/** incomplete, you can convert to any to use other properties */
3333
export interface TreeStore<K, D> {
34-
_getAllNodes: () => TreeNode<K, D>;
35-
}
36-
37-
export interface AllowDragMethod {
38-
/**
39-
* Function executed before dragging a node
40-
*
41-
* @param node The node to be dragged
42-
*/
43-
(node: any): boolean
44-
}
45-
46-
export interface AllowDropMethod {
47-
/**
48-
* Function executed before the dragging node is dropped
49-
*
50-
* @param draggingNode The dragging node
51-
* @param dropNode The target node
52-
* @param type Drop type
53-
*/
54-
(draggingNode: any, dropNode: any, type: string): boolean
34+
_getAllNodes: () => TreeNode<K, D>[];
5535
}
5636

5737
/** Tree Component */
5838
export declare class ElTree<K = any, D = TreeData> extends ElementUIComponent {
39+
/** TreeStore */
40+
store: TreeStore<K, D>;
41+
5942
/** Tree data */
60-
data: D[]
43+
data: D[];
6144

6245
/** Text displayed when data is void */
63-
emptyText: string
46+
emptyText: string;
6447

6548
/** Unique identity key name for nodes, its value should be unique across the whole tree */
66-
nodeKey: string
49+
nodeKey: string;
6750

6851
/** Configuration options, see the following table */
69-
props: object
52+
props: object;
7053

7154
/** Method for loading subtree data */
72-
load: (data: D, resolve: Function) => void
73-
74-
/** Render function for tree node */
55+
load: (data: D, resolve: Function) => void;
7556

7657
/**
7758
* Render function for a specific node
7859
*
7960
* @param h The render function
8061
*/
81-
renderContent: (h: CreateElement, context: { node: TreeNode, data: D, store: TreeStore<K, D> }) => VNode
62+
renderContent: (h: CreateElement, context: { node: TreeNode<K, D>; data: D; store: TreeStore<K, D> }) => VNode;
8263

8364
/** Whether current node is highlighted */
84-
highlightCurrent: boolean
65+
highlightCurrent: boolean;
8566

8667
/** Whether to expand all nodes by default */
87-
defaultExpandAll: boolean
68+
defaultExpandAll: boolean;
8869

8970
/** 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. */
90-
expandOnClickNode: boolean
71+
expandOnClickNode: boolean;
9172

9273
/** 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. */
93-
checkOnClickNode: boolean
74+
checkOnClickNode: boolean;
9475

9576
/** Whether to expand father node when a child node is expanded */
96-
autoExpandParent: boolean
77+
autoExpandParent: boolean;
9778

9879
/** Array of keys of initially expanded nodes */
99-
defaultExpandedKeys: K[]
80+
defaultExpandedKeys: K[];
10081

10182
/** Whether node is selectable */
102-
showCheckbox: boolean
83+
showCheckbox: boolean;
10384

10485
/** Whether checked state of a node not affects its father and child nodes when show-checkbox is true */
105-
checkStrictly: boolean
86+
checkStrictly: boolean;
10687

10788
/** Array of keys of initially checked nodes */
108-
defaultCheckedKeys: K[]
89+
defaultCheckedKeys: K[];
10990

11091
/**
11192
* This function will be executed on each node when use filter method. If return false, tree node will be hidden.
@@ -114,23 +95,23 @@ export declare class ElTree<K = any, D = TreeData> extends ElementUIComponent {
11495
* @param data The original data object
11596
* @param node Tree node
11697
*/
117-
filterNodeMethod: (value: string, data: D, node: TreeNode<K, D>) => boolean
98+
filterNodeMethod: (value: string, data: D, node: TreeNode<K, D>) => boolean;
11899

119100
/** Whether only one node among the same level can be expanded at one time */
120-
accordion: boolean
101+
accordion: boolean;
121102

122103
/** Horizontal indentation of nodes in adjacent levels in pixels */
123-
indent: number
104+
indent: number;
124105

125106
/** Whether enable tree nodes drag and drop */
126-
draggable: boolean
107+
draggable: boolean;
127108

128109
/**
129110
* Function to be executed before dragging a node
130111
*
131112
* @param node The node to be dragged
132113
*/
133-
allowDrag: (node: TreeNode<K, D>) => boolean
114+
allowDrag: (node: TreeNode<K, D>) => boolean;
134115

135116
/**
136117
* Function to be executed before the dragging node is dropped
@@ -139,53 +120,53 @@ export declare class ElTree<K = any, D = TreeData> extends ElementUIComponent {
139120
* @param dropNode The target node
140121
* @param type Drop type
141122
*/
142-
allowDrop: (draggingNode: TreeNode<K, D>, dropNode: TreeNode<K, D>, type: 'prev' | 'inner' | 'next') => boolean
123+
allowDrop: (draggingNode: TreeNode<K, D>, dropNode: TreeNode<K, D>, type: 'prev' | 'inner' | 'next') => boolean;
143124

144125
/**
145126
* Filter all tree nodes. Filtered nodes will be hidden
146127
*
147128
* @param value The value to be used as first parameter for `filter-node-method`
148129
*/
149-
filter (value: any): void
130+
filter(value: any): void;
150131

151132
/**
152133
* Update the children of the node which specified by the key
153134
*
154135
* @param key the key of the node which children will be updated
155136
* @param data the children data
156137
*/
157-
updateKeyChildren (key: K, data: D[]): void
138+
updateKeyChildren(key: K, data: D[]): void;
158139

159140
/**
160141
* If the node can be selected (`show-checkbox` is `true`), it returns the currently selected array of nodes
161142
*
162143
* @param leafOnly If the `leafOnly` is `true`, it only returns the currently selected array of sub-nodes
163144
* @param includeHalfChecked If the `includeHalfChecked` is `true`, the return value contains halfchecked nodes
164145
*/
165-
getCheckedNodes (leafOnly?: boolean, includeHalfChecked?: boolean): D[]
146+
getCheckedNodes(leafOnly?: boolean, includeHalfChecked?: boolean): D[];
166147

167148
/**
168149
* Set certain nodes to be checked. Only works when `node-key` is assigned
169150
*
170151
* @param nodes An array of nodes to be checked
171152
* @param leafOnly If the parameter is true, it only returns the currently selected array of sub-nodes
172153
*/
173-
setCheckedNodes (data: D[], leafOnly?: boolean): void
154+
setCheckedNodes(data: D[], leafOnly?: boolean): void;
174155

175156
/**
176157
* If the node can be selected (`show-checkbox` is `true`), it returns the currently selected array of nodes' keys
177158
*
178159
* @param leafOnly If the `leafOnly` is `true`, it only returns the currently selected array of sub-nodes
179160
*/
180-
getCheckedKeys (leafOnly?: boolean): K[]
161+
getCheckedKeys(leafOnly?: boolean): K[];
181162

182163
/**
183164
* Set certain nodes to be checked. Only works when `node-key` is assigned
184165
*
185166
* @param keys An array of node's keys to be checked
186167
* @param leafOnly If the parameter is true, it only returns the currently selected array of sub-nodes
187168
*/
188-
setCheckedKeys (keys: K[], leafOnly?: boolean): void
169+
setCheckedKeys(keys: K[], leafOnly?: boolean): void;
189170

190171
/**
191172
* Set node to be checked or not. Only works when `node-key` is assigned
@@ -194,77 +175,77 @@ export declare class ElTree<K = any, D = TreeData> extends ElementUIComponent {
194175
* @param checked Indicating the node checked or not
195176
* @param deep Indicating whether to checked state deeply or not
196177
*/
197-
setChecked (data: D | K, checked: boolean, deep: boolean): void
178+
setChecked(data: D | K, checked: boolean, deep: boolean): void;
198179

199180
/**
200181
* If the node can be selected (`show-checkbox` is `true`), it returns the currently half selected array of nodes
201182
*/
202-
getHalfCheckedNodes (): D[]
183+
getHalfCheckedNodes(): D[];
203184

204185
/**
205186
* If the node can be selected (`show-checkbox` is `true`), it returns the currently half selected array of nodes' keys
206187
*/
207-
getHalfCheckedKeys (): K[];
188+
getHalfCheckedKeys(): K[];
208189

209190
/**
210191
* Return the highlight node's key (null if no node is highlighted)
211192
*/
212-
getCurrentKey (): K
193+
getCurrentKey(): K;
213194

214195
/**
215196
* Set highlighted node by key, only works when node-key is assigned
216197
*
217198
* @param key The node's key to be highlighted
218199
*/
219-
setCurrentKey (key: K): void
200+
setCurrentKey(key: K): void;
220201

221202
/**
222203
* Return the highlight node (null if no node is highlighted)
223204
*/
224-
getCurrentNode (): D
205+
getCurrentNode(): D;
225206

226207
/**
227208
* Set highlighted node, only works when node-key is assigned
228209
*
229210
* @param node The node to be highlighted
230211
*/
231-
setCurrentNode (data: D): void
212+
setCurrentNode(data: D): void;
232213

233214
/**
234215
* Get node by node key or node data
235216
*
236217
* @param by node key or node data
237218
*/
238-
getNode (by: D | K): D
219+
getNode(by: D | K): D;
239220

240221
/**
241222
* Remove node by key or node data or node instance
242223
*
243224
* @param by key or node data or node instance
244225
*/
245-
remove (by: D | K): void
226+
remove(by: D | K): void;
246227

247228
/**
248229
* Append a child node to specified node
249230
*
250231
* @param childData the data of appended node
251232
* @param parent key or node data or node instance of the parent node
252233
*/
253-
append (childData: D, parent: D | K): void
234+
append(childData: D, parent: D | K): void;
254235

255236
/**
256237
* insert a node before specified node
257238
*
258239
* @param data the data of inserted node
259240
* @param ref key or node data or node instance of the reference node
260241
*/
261-
insertBefore (data: D, ref: D | K): void
242+
insertBefore(data: D, ref: D | K): void;
262243

263244
/**
264245
* insert a node after specified node
265246
*
266247
* @param data the data of inserted node
267248
* @param ref key or node data or node instance of the reference node
268249
*/
269-
insertAfter (data: D, ref: D | K): void
250+
insertAfter(data: D, ref: D | K): void;
270251
}

0 commit comments

Comments
 (0)