Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function TwoDMedia(props) {
// A mutable ref object that is initialized to null and will persist for the
// entire lifetime of the component
const reference = useRef(null);
const [{isDragging}, drag] = useDrag({
item: {id: props.id,
name: props.name,
order: props.order,
type: ItemTypes.TWOD,
url: props.url},
canDrag: () => props.editMode,
collect: (monitor) => ({
isDragging: !!monitor.isDragging()
})
});
const [, drop] = useDrop({
accept: [ItemTypes.TWOD, ItemTypes.OBJ, ItemTypes.GLTF],
canDrop: () => props.editMode,
hover(item) {
if (item.order !== props.order){
displaySetInstanceUid,
imageId,
imageSrc,
instanceNumber,
numImageFrames,
seriesDescription,
seriesNumber,
stackPercentComplete,
studyInstanceUid,
onClick,
onDoubleClick,
onMouseDown,
supportsDrag,
} = props;
const [collectedProps, drag, dragPreview] = useDrag({
// `droppedItem` in `dropTarget`
// The only data it will have access to
item: {
studyInstanceUid,
displaySetInstanceUid,
type: 'thumbnail', // Has to match `dropTarget`'s type
},
canDrag: function(monitor) {
return supportsDrag;
},
});
const hasImage = imageSrc || imageId;
const hasAltText = altImageText !== undefined;
return (
return
}
// Dragging upwards
if (dragIndex > hoverIndex && hoverClientY > hoverMiddleY) {
return
}
// Time to actually perform the action
moveCard(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.
item.index = hoverIndex
}
})
const [{ isDragging }, drag] = useDrag({
item: { type: 'COMPONENT', id, index },
collect: monitor => ({
isDragging: monitor.isDragging(),
}),
})
const opacity = isDragging ? 0 : 1
drag(drop(ref))
return (
<div style="{{opacity}}">
</div>
e => {
onChangeName(node, e.target.value);
},
[node, onChangeName]
);
const onSubmitNodeName = useCallback(
e => {
onRenameSubmit(node, e.target.value);
},
[onRenameSubmit, node]
);
const renaming = renamingNode && renamingNode.id === node.id;
const [_dragProps, drag, preview] = useDrag({
item: { type: ItemTypes.Node },
begin() {
const multiple = editor.selected.length > 1;
return { type: ItemTypes.Node, multiple, value: multiple ? editor.selected : editor.selected[0] };
},
canDrag() {
return !editor.selected.some(selectedObj => !selectedObj.parent);
},
collect: monitor => ({
isDragging: !!monitor.isDragging()
})
});
useEffect(() => {
preview(getEmptyImage(), { captureDraggingState: true });
}, [preview]);
function ComponentElement({ componentName }: ComponentElementProps) {
const [, drag] = useDrag({
item: {
componentName: componentName,
type: dndComponnent,
},
});
const component = usePageComponentStore(s => s[componentName]);
return (
<div>
{component ? (
) : (</div>
function ListItem({
data,
findRelation,
mainField,
moveRelation,
nextSearch,
onRemove,
targetModel,
}) {
const to = `/plugins/${pluginId}/${targetModel}/${data.id}?redirectUrl=${nextSearch}`;
const originalIndex = findRelation(data.id).index;
const [{ isDragging }, drag, preview] = useDrag({
item: {
type: ItemTypes.RELATION,
id: data.id,
originalIndex,
data,
mainField,
},
collect: monitor => ({
isDragging: monitor.isDragging(),
}),
});
const [, drop] = useDrop({
accept: ItemTypes.RELATION,
canDrop: () => false,
hover({ id: draggedId }) {
if (draggedId !== data.id) {
iconComponent={item.iconComponent}
onClick={onClickItem}
data-tip={item.id}
data-for={tooltipId}
data-effect="solid"
label={item.label}
{...rest}
/>
);
} else {
content = (
);
}
const [_dragProps, drag, preview] = useDrag({
item: { type: item.type },
begin() {
return { type: item.type, multiple: false, value: item };
}
});
useEffect(() => {
preview(getEmptyImage(), { captureDraggingState: true });
}, [preview]);
return (
<div>
{content}
</div>
export default function QuestionsListItem({
item: listItem,
onMove,
questionId
}) {
const Draggable = useRef(null);
const [{ opacity }, drag] = useDrag({
item: { type: ItemTypes.LIST_ITEM, questionId: questionId },
collect: monitor => ({
opacity: monitor.isDragging() ? 0 : 1
})
});
const [, drop] = useDrop({
accept: ItemTypes.LIST_ITEM,
hover(item) {
if (!Draggable.current) {
return;
}
if (item.questionId === questionId) {
return;
}
onMove({ sourceId: item.questionId, targetId: questionId });
}
function Item(props: ItemProps) {
const { setDragMonitor, setConnectedDragSource, setInitialDepth } = React.useContext(context);
const wasHoveredRef = React.useRef(false);
const connectedDragRef = React.useRef();
const connectedDropRef = React.useRef();
const {
type, index, id, depth, data, children, onHoverEnd, onHoverBegin, isClosestDragging
} = props;
const t = typeof type === 'function' ? type() : type;
const [{ isDragging }, dndDrag, preview] = useDrag({
item: {
id,
type: t,
data
},
collect: (monitor) => ({
isDragging: monitor.isDragging(),
}),
isDragging: (monitor) => id === monitor.getItem().id,
begin: (monitor) => {
setInitialDepth(depth);
setDragMonitor(monitor);
setConnectedDragSource(connectedDragRef);
},
end: () => {
setInitialDepth(undefined);
export default function SortableThumb({ id, onMove, video }) {
const [onTitleHover, setOnTitleHover] = useState(false);
const Draggable = useRef(null);
const ThumbLabelRef = useRef(null);
const [{ isDragging }, drag] = useDrag({
item: { type: ItemTypes.THUMB, id },
isDragging: monitor => !!monitor.isDragging()
});
const [, drop] = useDrop({
accept: ItemTypes.THUMB,
hover(item, monitor) {
if (!Draggable.current) {
return;
}
if (item.id !== id) {
onMove({ sourceId: item.id, targetId: id });
}
}
});
return (