Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function Draggable({ content, updateContent, currentView, component: Component, id, deleteComponent, index, moveCard, theme }) {
const ref = useRef(null)
const [, drop] = useDrop({
accept: 'COMPONENT',
hover(item, monitor) {
if (!ref.current) {
return
}
const dragIndex = item.index
const hoverIndex = index
// Don't replace items with themselves
if (dragIndex === hoverIndex) {
return
}
// Determine rectangle on screen
const hoverBoundingRect = ref.current.getBoundingClientRect()
// Get vertical middle
const hoverMiddleY =
(hoverBoundingRect.bottom - hoverBoundingRect.top) / 2
// 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){
props.onHover(item, props);
}
}
});
// Initialize drag and drop reference component
drag(drop(reference))
// Background-image over img tag to be able to use background-size/position
const imageElement = (
<div style="{{backgroundImage:" name="{props.name}"></div>
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 },
collect: monitor => ({
isDragging: !!monitor.isDragging()
})
});
const [, drop] = useDrop({
accept: ItemTypes.THUMB,
hover(item) {
if (!Draggable.current) {
return;
}
if (item.id !== id) {
onMove({ sourceId: item.id, targetId: id });
}
}
});
return (
function Square(props){
const [, drop] = useDrop({
accept: [ItemTypes.TWOD, ItemTypes.THREED],
drop: (item) => props.changeState(props.x, props.y, item.id),
})
return(<div style="{{width:">
{props.children}
</div>);
}
setModalState({ type: 'close' });
})
.catch(({ statusText }: Response) => {
setModalState({
type: 'error',
label: statusText,
});
});
};
const openFile = (file: IAbstractContentDescriptor) => {
const win = window.open(fileURL(generateAbsolutePath(file)), '_blank');
win!.focus();
};
const [dropZoneProps, dropZone] = useDrop(
dropSpecs(item => {
const { files } = (item as unknown) as {
files: FileList;
items: DataTransferItemList;
};
if (dropZoneProps.isShallowOver) {
insertFiles(files, newFiles => {
if (newFiles.length > 0) {
setOpen(true);
}
});
}
}),
);
const timeoutBeforeExpend = 1000;
insertFiles,
uploadFiles,
children,
selected = false,
defaultOpen = false,
}: React.PropsWithChildren) {
const [open, setOpen] = React.useState(defaultOpen);
const uploader = React.useRef(null);
const openFile = (file: IFileDescriptor) => {
const win = window.open(fileURL(generateAbsolutePath(file)), '_blank');
win!.focus();
};
const [dropZoneProps, dropZone] = useDrop(
dropSpecs(item => {
const { files } = (item as unknown) as {
files: FileList;
items: DataTransferItemList;
};
insertFiles(files, generateAbsolutePath(file), newFiles => {
if (newFiles.length > 0) {
setOpen(true);
}
});
}),
);
const timeoutBeforeExpend = 1000;
React.useEffect(() => {
editor.initializeRenderer(canvasRef.current);
return () => {
editor.removeListener("selectionChanged", onSelectionChanged);
if (editor.spokeControls) {
editor.spokeControls.removeListener("flyModeChanged", onFlyModeChanged);
}
if (editor.renderer) {
editor.renderer.dispose();
}
};
}, [editor, canvasRef, onEditorInitialized, onSelectionChanged, onFlyModeChanged]);
const [{ canDrop, isOver }, dropRef] = useDrop({
accept: [ItemTypes.Node, ...AssetTypes],
drop(item, monitor) {
const mousePos = monitor.getClientOffset();
if (item.type === ItemTypes.Node) {
if (item.multiple) {
editor.reparentToSceneAtCursorPosition(item.value, mousePos);
} else {
editor.reparentToSceneAtCursorPosition([item.value], mousePos);
}
return;
}
addAssetAtCursorPositionOnDrop(editor, item, mousePos);
},
);
function serveBurgerCallback(res) {
if (res) {
playOnEveryInteraction();
}
}
useEffect(() => {
if (!ordersComplete) return;
setTimeout(() => {
dispatch(serveBurger(serveBurgerCallback));
}, 200);
}, [ordersComplete]);
const [{ canDrop }, drop] = useDrop({
accept: "BurgerIngredient",
drop: () => ({ name: "Burger" })
});
return ;
}
export default function useSortable(index, type, dropRef, addBlock, swapBlock) {
const [{ isDragging }, drag, preview] = useDrag({
item: {
index,
type,
},
collect: monitor => ({
isDragging: monitor.isDragging(),
})
});
const [{ isHovered }, drop] = useDrop({
accept: type,
hover: (item, monitor) => {
if (!dropRef.current) {
return;
}
if (isNaN(item.index)) {
addBlock(index, item.id);
item.index = index;
return;
}
const dragIndex = item.index
const hoverIndex = index
if (dragIndex === hoverIndex) {
},
collect: (monitor) => ({
isDragging: monitor.isDragging(),
}),
isDragging: (monitor) => id === monitor.getItem().id,
begin: (monitor) => {
setInitialDepth(depth);
setDragMonitor(monitor);
setConnectedDragSource(connectedDragRef);
},
end: () => {
setInitialDepth(undefined);
setDragMonitor(undefined);
},
});
const [{ hovered }, dndDrop] = useDrop({
accept: t,
collect: (monitor) => ({
hovered: monitor.isOver({ shallow: true }),
}),
});
React.useEffect(() => {
if (hovered) {
onHoverBegin(id, connectedDropRef);
wasHoveredRef.current = true;
} else if (wasHoveredRef.current === true) {
onHoverEnd(id);
}
}, [hovered]);
const drag = (connectable: ConnectableElement) => {