Press n or j to go to the next uncovered block, b, p or k for the previous block.
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 | 1x 1x 1x 1x 1x 518x 4x 228x 1x 1x 4x | import {DragSource, DropTarget} from 'react-dnd'; import {isDummyPos} from './utils'; export const ItemTypes = { NODE: 'node', }; export const primitiveSource = { beginDrag(props) { return {content: props.primitive.name}; } }; export const nodeSource = { beginDrag(props) { if (isDummyPos(props.node.from) && isDummyPos(props.node.to)) { return {content: props.node.toString()}; } return {id: props.node.id}; } }; export function collectSource(connect, monitor) { return { connectDragSource: connect.dragSource(), isDragging: monitor.isDragging(), connectDragPreview: connect.dragPreview() }; } function nodeTarget(dropMethod) { return { drop(_, monitor, component) { if (monitor.didDrop()) return; return dropMethod.call(component, monitor); } }; } export function collectTarget(connect, monitor) { return { connectDropTarget: connect.dropTarget(), isOver: monitor.isOver({shallow: true}) }; } export const DragPrimitiveSource = DragSource(ItemTypes.NODE, primitiveSource, collectSource); export const DragNodeSource = DragSource(ItemTypes.NODE, nodeSource, collectSource); export const DropNodeTarget = (f) => DropTarget(ItemTypes.NODE, nodeTarget(f), collectTarget); |