-
Notifications
You must be signed in to change notification settings - Fork 16
/
FinderListDropZone.vue
129 lines (122 loc) 路 2.62 KB
/
FinderListDropZone.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<template>
<div
class="drop-zone"
:class="{
'drag-over': dragOver,
dragging: treeModel.isDragging(),
'no-drop': treeModel.isDragging() && !canDrop
}"
:style="{
...(dragOver &&
theme.primaryColor && { borderColor: theme.primaryColor }),
...(dragOver &&
theme.dropZoneBgColor && { backgroundColor: theme.dropZoneBgColor })
}"
@dragenter.prevent="onDragEnter"
@dragleave.prevent="onDragLeave"
@dragover.prevent
@drop.prevent="onDrop"
>
<component
:is="options.dropZoneComponent"
v-if="options.dropZoneComponent"
:dragging="treeModel.isDragging()"
:drag-over="dragOver"
style="flex-grow: 1"
/>
</div>
</template>
<script>
import { get } from "lodash-es";
export default {
name: "FinderListDropZone",
props: {
treeModel: {
type: Object,
required: true
},
node: {
type: Object,
required: true
},
dragEnabled: {
type: [Boolean, Function],
default: false
},
index: {
type: Number,
default: undefined
},
options: {
type: Object,
default: () => ({})
}
},
data: () => ({
dragCounter: 0
}),
computed: {
dragOver() {
return (
this.treeModel.isDragging() && this.canDrop && this.dragCounter > 0
);
},
theme() {
return get(this, "options.theme", {});
},
canDrag() {
if (typeof this.dragEnabled === "function") {
return this.dragEnabled(this.node);
}
return this.dragEnabled;
},
canDrop() {
// Cannot drop on a descendant of itself
if (this.treeModel.isParent(this.treeModel.draggedNodeId, this.node.id)) {
return false;
}
return (
!this.options.canDrop ||
this.options.canDrop(this.node.id, this.treeModel.draggedNodeId)
);
}
},
methods: {
onDragEnter() {
this.dragCounter++;
},
onDragLeave() {
this.dragCounter--;
},
onDrop(event) {
event.preventDefault();
this.dragCounter = 0;
if (!this.canDrop || !this.treeModel.isDragging()) {
return;
}
this.treeModel.dropOnNode(this.node.id, this.index);
}
}
};
</script>
<style lang="scss" scoped>
@import "../style/colors";
.drop-zone {
transition: height 0.1s ease;
height: 0.5em;
flex-shrink: 0;
overflow: hidden;
display: flex;
flex-direction: column;
&.drag-over {
opacity: 0.5;
margin-bottom: 0;
height: 2em;
border: dashed 3px $primaryColor;
background-color: change-color($primaryColor, $alpha: 0.2);
}
}
.no-drop * {
cursor: no-drop;
}
</style>