1
- <script lang="jsx">
1
+ <template >
2
+ <div class =" tree-container" >
3
+ <FinderList
4
+ v-if =" treeModel"
5
+ ref =" rootList"
6
+ :tree-model =" treeModel"
7
+ :parent =" treeModel.visibleTree"
8
+ :selectable =" selectable"
9
+ :drag-enabled =" dragEnabled"
10
+ :options =" options"
11
+ >
12
+ <template #item =" itemProps " >
13
+ <slot name =" item" v-bind =" itemProps" />
14
+ </template >
15
+ <template #arrow =" arrowProps " >
16
+ <slot name =" arrow" v-bind =" arrowProps" />
17
+ </template >
18
+ <template #drop-zone =" dropZoneProps " >
19
+ <slot name =" drop-zone" v-bind =" dropZoneProps" />
20
+ </template >
21
+ <template #drag-image =" dragImageProps " >
22
+ <slot name =" drag-image" v-bind =" dragImageProps" />
23
+ </template >
24
+ </FinderList >
25
+ </div >
26
+ </template >
27
+ <script >
2
28
import { toRaw } from " vue" ;
3
29
import TreeModel from " @/utils/tree-model" ;
4
30
import FinderList from " ./FinderList.vue" ;
5
31
6
- /**
7
- * Render the tree of an item and its selected children.
8
- *
9
- * @param {Object} h `createElement` object
10
- * @param {Object} context Context component
11
- * @param {Object} item Item to render
12
- * @return Rendering object
13
- */
14
- function renderTree(h, context, item) {
15
- if (!item || !item.children || item.children.length === 0) {
16
- return null;
17
- }
18
-
19
- const expandedChild = item.children.find((child) =>
20
- context.treeModel.isNodeExpanded(child.id),
21
- );
22
-
23
- const options = {
24
- sortBy: context.sortBy,
25
- itemComponent: context.itemComponent,
26
- arrowComponent: context.arrowComponent,
27
- dragImageComponent: context.dragImageComponent,
28
- dropZoneComponent: context.dropZoneComponent,
29
- theme: context.theme,
30
- hasDragHandle: context.hasDragHandle,
31
- canDrop: context.canDrop,
32
- };
33
-
34
- const itemList = (
35
- <FinderList
36
- ref="rootList"
37
- tree-model={context.treeModel}
38
- parent={item}
39
- items={item.children}
40
- selectable={context.selectable}
41
- drag-enabled={context.dragEnabled}
42
- options={options}
43
- has-expanded-item={!!expandedChild}
44
- />
45
- );
46
-
47
- return (
48
- <div class="list-container">
49
- {itemList}
50
- {expandedChild && renderTree(h, context, expandedChild)}
51
- </div>
52
- );
53
- }
54
-
55
32
/**
56
33
* Get a value animated by a ease out Bezier curve.
57
34
*/
@@ -185,34 +162,6 @@ export default {
185
162
type: String ,
186
163
default: undefined ,
187
164
},
188
- /**
189
- * Custom component to render items.
190
- */
191
- itemComponent: {
192
- type: [String, Object],
193
- default: undefined,
194
- },
195
- /**
196
- * Custom component to render arrows (on items with children).
197
- */
198
- arrowComponent: {
199
- type: [String, Object],
200
- default: undefined,
201
- },
202
- /**
203
- * Custom component to render drag image.
204
- */
205
- dragImageComponent: {
206
- type: [String, Object],
207
- default: undefined,
208
- },
209
- /**
210
- * Custom component to render drop zones.
211
- */
212
- dropZoneComponent: {
213
- type: [String, Object],
214
- default: undefined,
215
- },
216
165
/**
217
166
* Styling options.
218
167
*
@@ -249,6 +198,16 @@ export default {
249
198
treeModel: {},
250
199
};
251
200
},
201
+ computed: {
202
+ options () {
203
+ return {
204
+ sortBy: this .sortBy ,
205
+ theme: this .theme ,
206
+ hasDragHandle: this .hasDragHandle ,
207
+ canDrop: this .canDrop ,
208
+ };
209
+ },
210
+ },
252
211
watch: {
253
212
tree (newTree ) {
254
213
this .treeModel .root = toRaw (newTree);
@@ -420,13 +379,6 @@ export default {
420
379
window .requestAnimationFrame (step);
421
380
},
422
381
},
423
- render(h) {
424
- return (
425
- <div class="tree-container">
426
- {this.treeModel && renderTree(h, this, this.treeModel.visibleTree)}
427
- </div>
428
- );
429
- },
430
382
};
431
383
</script >
432
384
@@ -436,10 +388,5 @@ export default {
436
388
position : relative ;
437
389
display : flex ;
438
390
align-items : stretch ;
439
-
440
- .list-container {
441
- display : flex ;
442
- align-items : stretch ;
443
- }
444
391
}
445
392
</style >
0 commit comments