import { Stack, Text, SimpleGrid, useEventListener, Portal, Flex, IconButton, Tooltip, Fade, } from '@chakra-ui/react' import { BubbleBlockType, DraggableBlockType, InputBlockType, IntegrationBlockType, LogicBlockType, } from 'models' import { useBlockDnd } from 'contexts/GraphDndContext' import React, { useState } from 'react' import { BlockCard, BlockCardOverlay } from './BlockCard' import { LockedIcon, UnlockedIcon } from 'assets/icons' import { headerHeight } from 'components/shared/TypebotHeader' export const BlocksSideBar = () => { const { setDraggedBlockType, draggedBlockType } = useBlockDnd() const [position, setPosition] = useState({ x: 0, y: 0, }) const [relativeCoordinates, setRelativeCoordinates] = useState({ x: 0, y: 0 }) const [isLocked, setIsLocked] = useState(true) const [isExtended, setIsExtended] = useState(true) const handleMouseMove = (event: MouseEvent) => { if (!draggedBlockType) return const { clientX, clientY } = event setPosition({ ...position, x: clientX - relativeCoordinates.x, y: clientY - relativeCoordinates.y, }) } useEventListener('mousemove', handleMouseMove) const handleMouseDown = (e: React.MouseEvent, type: DraggableBlockType) => { const element = e.currentTarget as HTMLDivElement const rect = element.getBoundingClientRect() setPosition({ x: rect.left, y: rect.top }) const x = e.clientX - rect.left const y = e.clientY - rect.top setRelativeCoordinates({ x, y }) setDraggedBlockType(type) } const handleMouseUp = () => { if (!draggedBlockType) return setDraggedBlockType(undefined) setPosition({ x: 0, y: 0, }) } useEventListener('mouseup', handleMouseUp) const handleLockClick = () => setIsLocked(!isLocked) const handleDockBarEnter = () => setIsExtended(true) const handleMouseLeave = () => { if (isLocked) return setIsExtended(false) } return ( : } aria-label={isLocked ? 'Unlock' : 'Lock'} size="sm" variant="outline" onClick={handleLockClick} /> Bubbles {Object.values(BubbleBlockType).map((type) => ( ))} Inputs {Object.values(InputBlockType).map((type) => ( ))} Logic {Object.values(LogicBlockType).map((type) => ( ))} Integrations {Object.values(IntegrationBlockType).map((type) => ( ))} {draggedBlockType && ( )} ) }