|
1 | 1 | import { FeatureImplementation } from "../../types/core"; |
2 | | -import { DndDataRef, DragLineData } from "./types"; |
| 2 | +import { DndDataRef, DragLineData, DragTarget } from "./types"; |
3 | 3 | import { |
4 | 4 | canDrop, |
5 | 5 | getDragCode, |
@@ -83,10 +83,38 @@ export const dragAndDropFeature: FeatureImplementation = { |
83 | 83 | : { display: "none" }; |
84 | 84 | }, |
85 | 85 |
|
86 | | - getContainerProps: ({ prev }, treeLabel) => { |
| 86 | + getContainerProps: ({ prev, tree }, treeLabel) => { |
87 | 87 | const prevProps = prev?.(treeLabel); |
88 | 88 | return { |
89 | 89 | ...prevProps, |
| 90 | + |
| 91 | + onDragOver: (e: DragEvent) => { |
| 92 | + e.preventDefault(); |
| 93 | + }, |
| 94 | + |
| 95 | + onDrop: async (e: DragEvent) => { |
| 96 | + // TODO merge implementation with itemInstance.onDrop |
| 97 | + const dataRef = tree.getDataRef<DndDataRef>(); |
| 98 | + const target: DragTarget<any> = { item: tree.getRootItem() }; |
| 99 | + |
| 100 | + if (!canDrop(e.dataTransfer, target, tree)) { |
| 101 | + return; |
| 102 | + } |
| 103 | + |
| 104 | + e.preventDefault(); |
| 105 | + const config = tree.getConfig(); |
| 106 | + const draggedItems = tree.getState().dnd?.draggedItems; |
| 107 | + |
| 108 | + dataRef.current.lastDragCode = undefined; |
| 109 | + tree.applySubStateUpdate("dnd", null); |
| 110 | + |
| 111 | + if (draggedItems) { |
| 112 | + await config.onDrop?.(draggedItems, target); |
| 113 | + } else if (e.dataTransfer) { |
| 114 | + await config.onDropForeignDragObject?.(e.dataTransfer, target); |
| 115 | + } |
| 116 | + }, |
| 117 | + |
90 | 118 | style: { |
91 | 119 | ...prevProps?.style, |
92 | 120 | position: "relative", |
@@ -193,6 +221,7 @@ export const dragAndDropFeature: FeatureImplementation = { |
193 | 221 | }, |
194 | 222 |
|
195 | 223 | onDrop: async (e: DragEvent) => { |
| 224 | + e.stopPropagation(); |
196 | 225 | const dataRef = tree.getDataRef<DndDataRef>(); |
197 | 226 | const target = getDragTarget(e, item, tree); |
198 | 227 |
|
|
0 commit comments