-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b937c3b
commit 67d5cc2
Showing
3 changed files
with
41 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,50 @@ | ||
import { DragSource, DropTarget } from 'react-dnd'; | ||
import { DragSource, DropTarget } from 'react-dnd' | ||
|
||
const ItemTypes = { | ||
ITEM: 'subblock', | ||
} | ||
|
||
const itemSource = { | ||
beginDrag(props) { | ||
return { | ||
id: props.id, | ||
index: props.index, | ||
}; | ||
} | ||
}, | ||
}; | ||
|
||
const ItemTypes = { | ||
ITEM: 'subblock', | ||
}; | ||
} | ||
|
||
const itemTarget = { | ||
hover(props, monitor, component) { | ||
const dragIndex = monitor.getItem().index; | ||
const hoverIndex = props.index; | ||
const dragIndex = monitor.getItem().index | ||
const hoverIndex = props.index | ||
|
||
// Don't replace items with themselves | ||
if (dragIndex === hoverIndex) { | ||
return; | ||
return | ||
} | ||
|
||
// Time to actually perform the action | ||
props.onMoveSubblock(dragIndex, hoverIndex); | ||
props.onMoveSubblock(dragIndex, hoverIndex) | ||
|
||
// Note: we're mutating the monitor item here! | ||
// Generally it's better to avoid mutations, | ||
// but it's good here for the sake of performance | ||
// to avoid expensive index searches. | ||
monitor.getItem().index = hoverIndex; | ||
monitor.getItem().index = hoverIndex | ||
}, | ||
}; | ||
} | ||
|
||
const DNDSubblocks = [ | ||
DropTarget(ItemTypes.ITEM, itemTarget, (connect) => ({ | ||
DropTarget(ItemTypes.ITEM, itemTarget, (connect, monitor) => ({ | ||
connectDropTarget: connect.dropTarget(), | ||
highlighted: monitor.canDrop(), | ||
hovered: monitor.isOver(), | ||
})), | ||
DragSource(ItemTypes.ITEM, itemSource, (connect, monitor) => ({ | ||
connectDragSource: connect.dragSource(), | ||
connectDragPreview: connect.dragPreview(), | ||
isDragging: monitor.isDragging(), | ||
})), | ||
]; | ||
] | ||
|
||
export default DNDSubblocks; | ||
export default DNDSubblocks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters