fix(editor): ♿️ Improve block focus
This commit is contained in:
@ -30,6 +30,8 @@ export const BlockNode = ({ block, blockIndex }: Props) => {
|
|||||||
blocksCoordinates,
|
blocksCoordinates,
|
||||||
updateBlockCoordinates,
|
updateBlockCoordinates,
|
||||||
isReadOnly,
|
isReadOnly,
|
||||||
|
focusedBlockId,
|
||||||
|
setFocusedBlockId,
|
||||||
} = useGraph()
|
} = useGraph()
|
||||||
const { typebot, updateBlock } = useTypebot()
|
const { typebot, updateBlock } = useTypebot()
|
||||||
const { setMouseOverBlock, mouseOverBlock } = useStepDnd()
|
const { setMouseOverBlock, mouseOverBlock } = useStepDnd()
|
||||||
@ -91,7 +93,10 @@ export const BlockNode = ({ block, blockIndex }: Props) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const onDragStart = () => setIsMouseDown(true)
|
const onDragStart = () => {
|
||||||
|
setFocusedBlockId(block.id)
|
||||||
|
setIsMouseDown(true)
|
||||||
|
}
|
||||||
const onDragStop = () => setIsMouseDown(false)
|
const onDragStop = () => setIsMouseDown(false)
|
||||||
return (
|
return (
|
||||||
<ContextMenu<HTMLDivElement>
|
<ContextMenu<HTMLDivElement>
|
||||||
@ -131,6 +136,7 @@ export const BlockNode = ({ block, blockIndex }: Props) => {
|
|||||||
cursor={isMouseDown ? 'grabbing' : 'pointer'}
|
cursor={isMouseDown ? 'grabbing' : 'pointer'}
|
||||||
boxShadow="0px 0px 0px 1px #e9edf3;"
|
boxShadow="0px 0px 0px 1px #e9edf3;"
|
||||||
_hover={{ shadow: 'lg' }}
|
_hover={{ shadow: 'lg' }}
|
||||||
|
zIndex={focusedBlockId === block.id ? 10 : 1}
|
||||||
>
|
>
|
||||||
<Editable
|
<Editable
|
||||||
defaultValue={block.title}
|
defaultValue={block.title}
|
||||||
|
@ -45,8 +45,13 @@ export const StepNode = ({
|
|||||||
onMouseDown?: (stepNodePosition: NodePosition, step: DraggableStep) => void
|
onMouseDown?: (stepNodePosition: NodePosition, step: DraggableStep) => void
|
||||||
}) => {
|
}) => {
|
||||||
const { query } = useRouter()
|
const { query } = useRouter()
|
||||||
const { setConnectingIds, connectingIds, openedStepId, setOpenedStepId } =
|
const {
|
||||||
useGraph()
|
setConnectingIds,
|
||||||
|
connectingIds,
|
||||||
|
openedStepId,
|
||||||
|
setOpenedStepId,
|
||||||
|
setFocusedBlockId,
|
||||||
|
} = useGraph()
|
||||||
const { updateStep } = useTypebot()
|
const { updateStep } = useTypebot()
|
||||||
const [isConnecting, setIsConnecting] = useState(false)
|
const [isConnecting, setIsConnecting] = useState(false)
|
||||||
const [isPopoverOpened, setIsPopoverOpened] = useState(
|
const [isPopoverOpened, setIsPopoverOpened] = useState(
|
||||||
@ -113,6 +118,7 @@ export const StepNode = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleClick = (e: React.MouseEvent) => {
|
const handleClick = (e: React.MouseEvent) => {
|
||||||
|
setFocusedBlockId(step.blockId)
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
if (isTextBubbleStep(step)) setIsEditing(true)
|
if (isTextBubbleStep(step)) setIsEditing(true)
|
||||||
setOpenedStepId(step.id)
|
setOpenedStepId(step.id)
|
||||||
|
@ -75,6 +75,7 @@ export const VariableSearchInput = ({
|
|||||||
debounced(e.target.value)
|
debounced(e.target.value)
|
||||||
onOpen()
|
onOpen()
|
||||||
if (e.target.value === '') {
|
if (e.target.value === '') {
|
||||||
|
onSelectVariable(undefined)
|
||||||
setFilteredItems([...variables.slice(0, 50)])
|
setFilteredItems([...variables.slice(0, 50)])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,8 @@ const graphContext = createContext<{
|
|||||||
openedStepId?: string
|
openedStepId?: string
|
||||||
setOpenedStepId: Dispatch<SetStateAction<string | undefined>>
|
setOpenedStepId: Dispatch<SetStateAction<string | undefined>>
|
||||||
isReadOnly: boolean
|
isReadOnly: boolean
|
||||||
|
focusedBlockId?: string
|
||||||
|
setFocusedBlockId: Dispatch<SetStateAction<string | undefined>>
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
}>({
|
}>({
|
||||||
@ -98,6 +100,8 @@ export const GraphProvider = ({
|
|||||||
const [blocksCoordinates, setBlocksCoordinates] = useState<BlocksCoordinates>(
|
const [blocksCoordinates, setBlocksCoordinates] = useState<BlocksCoordinates>(
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
|
const [focusedBlockId, setFocusedBlockId] = useState<string>()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setBlocksCoordinates(
|
setBlocksCoordinates(
|
||||||
blocks.reduce(
|
blocks.reduce(
|
||||||
@ -149,6 +153,8 @@ export const GraphProvider = ({
|
|||||||
blocksCoordinates,
|
blocksCoordinates,
|
||||||
updateBlockCoordinates,
|
updateBlockCoordinates,
|
||||||
isReadOnly,
|
isReadOnly,
|
||||||
|
focusedBlockId,
|
||||||
|
setFocusedBlockId,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
Reference in New Issue
Block a user