forked from JimLiu/reactree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DemoDragAndDrop.js
67 lines (55 loc) · 1.57 KB
/
DemoDragAndDrop.js
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
import { TreeDragAndDrop } from './src'
export default class DemoDragAndDrop extends TreeDragAndDrop {
constructor() {
super()
this.currentDragOver = null
}
onDragStart(context, tree, dragAndDropData, event) {
const { actions } = context
const { sources } = dragAndDropData
let source = null
if (sources.length) {
source = sources[0]
}
if (source.expanded) {
actions.collapse(source)
}
}
onDragOver(context, tree, dragAndDropData, target, event) {
let reaction = {
accept: false
}
if (!target) {
return reaction
}
const isCopy = (event.ctrlKey && !platform.isMacintosh) || (event.altKey && platform.isMacintosh)
if (target.doesHaveChildren) {
reaction.accept = true
reaction.bubble = 'DOWN'
} else {
reaction.accept = true
reaction.bubble = 'UP'
}
if (isCopy) {
reaction.effect = 'COPY'
}
return reaction
}
drop(context, tree, dragAndDropData, target, event) {
const { actions } = context
const { external, sources } = dragAndDropData
const sourceTree = external ? dragAndDropData.tree : tree
const sourceActions = external ? dragAndDropData.context.actions : actions
const isCopy = (event.ctrlKey && !platform.isMacintosh) || (event.altKey && platform.isMacintosh)
let source = null
if (sources.length) {
source = sources[0]
}
if (!isCopy) {
const parent = sourceTree.getParent(source)
sourceActions.removeChild(parent, source)
} else {
}
actions.addChild(target, source, null)
}
}