2
0

feat(editor): Zoom in/out

This commit is contained in:
Baptiste Arnaud
2022-04-08 14:30:46 -05:00
parent 6314ce2f62
commit c5d3b9214d
16 changed files with 336 additions and 63 deletions

View File

@@ -403,3 +403,35 @@ export const TemplateIcon = (props: IconProps) => (
<rect x="3" y="14" width="7" height="7"></rect> <rect x="3" y="14" width="7" height="7"></rect>
</Icon> </Icon>
) )
export const MinusIcon = (props: IconProps) => (
<Icon viewBox="0 0 24 24" {...featherIconsBaseProps} {...props}>
<line x1="5" y1="12" x2="19" y2="12"></line>
</Icon>
)
export const LaptopIcon = (props: IconProps) => (
<Icon viewBox="0 0 24 24" {...featherIconsBaseProps} {...props}>
<path
d="M3.2 14.2222V4C3.2 2.89543 4.09543 2 5.2 2H18.8C19.9046 2 20.8 2.89543 20.8 4V14.2222M3.2 14.2222H20.8M3.2 14.2222L1.71969 19.4556C1.35863 20.7321 2.31762 22 3.64418 22H20.3558C21.6824 22 22.6414 20.7321 22.2803 19.4556L20.8 14.2222"
stroke="currentColor"
strokeWidth="1.5"
/>
<path
d="M11 19L13 19"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
/>
</Icon>
)
export const MouseIcon = (props: IconProps) => (
<Icon viewBox="0 0 24 24" {...featherIconsBaseProps} {...props}>
<path
d="M12 2V2C16.4183 2 20 5.58172 20 10V14C20 18.4183 16.4183 22 12 22V22C7.58172 22 4 18.4183 4 14V10C4 5.58172 7.58172 2 12 2V2ZM12 2V9"
stroke="currentColor"
strokeLinecap="round"
/>
</Icon>
)

View File

@@ -5,16 +5,19 @@ import {
MenuButtonProps, MenuButtonProps,
MenuItem, MenuItem,
MenuList, MenuList,
useDisclosure,
} from '@chakra-ui/react' } from '@chakra-ui/react'
import assert from 'assert' import assert from 'assert'
import { DownloadIcon, MoreVerticalIcon } from 'assets/icons' import { DownloadIcon, MoreVerticalIcon, SettingsIcon } from 'assets/icons'
import { useTypebot } from 'contexts/TypebotContext' import { useTypebot } from 'contexts/TypebotContext'
import React, { useState } from 'react' import React, { useState } from 'react'
import { parseDefaultPublicId } from 'services/typebots' import { parseDefaultPublicId } from 'services/typebots'
import { EditorSettingsModal } from './EditorSettingsModal'
export const BoardMenuButton = (props: MenuButtonProps) => { export const BoardMenuButton = (props: MenuButtonProps) => {
const { typebot } = useTypebot() const { typebot } = useTypebot()
const [isDownloading, setIsDownloading] = useState(false) const [isDownloading, setIsDownloading] = useState(false)
const { isOpen, onOpen, onClose } = useDisclosure()
const downloadFlow = () => { const downloadFlow = () => {
assert(typebot) assert(typebot)
@@ -36,18 +39,22 @@ export const BoardMenuButton = (props: MenuButtonProps) => {
<Menu> <Menu>
<MenuButton <MenuButton
as={IconButton} as={IconButton}
variant="outline" bgColor="white"
colorScheme="blue"
icon={<MoreVerticalIcon transform={'rotate(90deg)'} />} icon={<MoreVerticalIcon transform={'rotate(90deg)'} />}
isLoading={isDownloading} isLoading={isDownloading}
size="sm" size="sm"
shadow="lg"
{...props} {...props}
/> />
<MenuList> <MenuList>
<MenuItem icon={<SettingsIcon />} onClick={onOpen}>
Editor settings
</MenuItem>
<MenuItem icon={<DownloadIcon />} onClick={downloadFlow}> <MenuItem icon={<DownloadIcon />} onClick={downloadFlow}>
Export flow Export flow
</MenuItem> </MenuItem>
</MenuList> </MenuList>
<EditorSettingsModal isOpen={isOpen} onClose={onClose} />
</Menu> </Menu>
) )
} }

View File

@@ -0,0 +1,97 @@
import {
Heading,
Modal,
ModalBody,
ModalCloseButton,
ModalContent,
ModalOverlay,
Stack,
Text,
Radio,
VStack,
RadioGroup,
HStack,
} from '@chakra-ui/react'
import { LaptopIcon, MouseIcon } from 'assets/icons'
import { useUser } from 'contexts/UserContext'
import { GraphNavigation } from 'db'
import React, { useEffect, useState } from 'react'
type Props = {
isOpen: boolean
onClose: () => void
}
export const EditorSettingsModal = ({ isOpen, onClose }: Props) => {
return (
<Modal isOpen={isOpen} onClose={onClose} size="xl">
<ModalOverlay />
<ModalContent>
<ModalCloseButton />
<ModalBody pt="12" pb="8" px="8">
<EditorSettings />
</ModalBody>
</ModalContent>
</Modal>
)
}
const EditorSettings = () => {
const { user, saveUser } = useUser()
const [value, setValue] = useState<string>(
user?.graphNavigation ?? GraphNavigation.TRACKPAD
)
useEffect(() => {
if (user?.graphNavigation === value) return
saveUser({ graphNavigation: value as GraphNavigation }).then()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [value])
const options = [
{
value: GraphNavigation.MOUSE,
label: 'Mouse',
description:
'Move by dragging the board and zoom in/out using the scroll wheel',
icon: <MouseIcon boxSize="35px" />,
},
{
value: GraphNavigation.TRACKPAD,
label: 'Trackpad',
description: 'Move the board using 2 fingers and zoom in/out by pinching',
icon: <LaptopIcon boxSize="35px" />,
},
]
return (
<Stack spacing={4}>
<Heading size="md">Navigation</Heading>
<RadioGroup onChange={setValue} value={value}>
<HStack spacing={4} w="full">
{options.map((option) => (
<VStack
key={option.value}
as="label"
htmlFor={option.label}
cursor="pointer"
borderWidth="1px"
borderRadius="md"
w="full"
p="6"
spacing={6}
>
{option.icon}
<Stack>
<Text fontWeight="bold">{option.label}</Text>
<Text>{option.description}</Text>
</Stack>
<Radio value={option.value} id={option.label} />
</VStack>
))}
</HStack>
</RadioGroup>
</Stack>
)
}

View File

@@ -29,21 +29,23 @@ export const DrawingEdge = () => {
const sourceTop = useMemo(() => { const sourceTop = useMemo(() => {
if (!connectingIds) return 0 if (!connectingIds) return 0
return getEndpointTopOffset( return getEndpointTopOffset({
sourceEndpoints, endpoints: sourceEndpoints,
graphPosition.y, graphOffsetY: graphPosition.y,
connectingIds.source.itemId ?? connectingIds.source.stepId endpointId: connectingIds.source.itemId ?? connectingIds.source.stepId,
) graphScale: graphPosition.scale,
})
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [connectingIds, sourceEndpoints]) }, [connectingIds, sourceEndpoints])
const targetTop = useMemo(() => { const targetTop = useMemo(() => {
if (!connectingIds) return 0 if (!connectingIds) return 0
return getEndpointTopOffset( return getEndpointTopOffset({
targetEndpoints, endpoints: targetEndpoints,
graphPosition.y, graphOffsetY: graphPosition.y,
connectingIds.target?.stepId endpointId: connectingIds.target?.stepId,
) graphScale: graphPosition.scale,
})
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [connectingIds, targetEndpoints]) }, [connectingIds, targetEndpoints])
@@ -56,6 +58,7 @@ export const DrawingEdge = () => {
targetBlockCoordinates, targetBlockCoordinates,
sourceTop, sourceTop,
targetTop, targetTop,
graphScale: graphPosition.scale,
}) })
: computeEdgePathToMouse({ : computeEdgePathToMouse({
sourceBlockCoordinates, sourceBlockCoordinates,
@@ -68,13 +71,15 @@ export const DrawingEdge = () => {
targetBlockCoordinates, targetBlockCoordinates,
targetTop, targetTop,
mousePosition, mousePosition,
graphPosition.scale,
]) ])
const handleMouseMove = (e: MouseEvent) => { const handleMouseMove = (e: MouseEvent) => {
setMousePosition({ const coordinates = {
x: e.clientX - graphPosition.x, x: (e.clientX - graphPosition.x) / graphPosition.scale,
y: e.clientY - graphPosition.y, y: (e.clientY - graphPosition.y) / graphPosition.scale,
}) }
setMousePosition(coordinates)
} }
useEventListener('mousemove', handleMouseMove) useEventListener('mousemove', handleMouseMove)
useEventListener('mouseup', () => { useEventListener('mouseup', () => {

View File

@@ -58,11 +58,12 @@ export const DropOffEdge = ({
const block = publishedTypebot?.blocks.find(byId(blockId)) const block = publishedTypebot?.blocks.find(byId(blockId))
const sourceTop = useMemo( const sourceTop = useMemo(
() => () =>
getEndpointTopOffset( getEndpointTopOffset({
sourceEndpoints, endpoints: sourceEndpoints,
graphPosition.y, graphOffsetY: graphPosition.y,
block?.steps[block.steps.length - 1].id endpointId: block?.steps[block.steps.length - 1].id,
), graphScale: graphPosition.scale,
}),
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
[block?.steps, sourceEndpoints, blocksCoordinates] [block?.steps, sourceEndpoints, blocksCoordinates]
) )

View File

@@ -44,11 +44,12 @@ export const Edge = ({ edge }: { edge: EdgeProps }) => {
const sourceTop = useMemo( const sourceTop = useMemo(
() => () =>
getEndpointTopOffset( getEndpointTopOffset({
sourceEndpoints, endpoints: sourceEndpoints,
graphPosition.y, graphOffsetY: graphPosition.y,
getSourceEndpointId(edge) endpointId: getSourceEndpointId(edge),
), graphScale: graphPosition.scale,
}),
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
[sourceBlockCoordinates?.y, edge, sourceEndpoints, refreshEdge] [sourceBlockCoordinates?.y, edge, sourceEndpoints, refreshEdge]
) )
@@ -58,17 +59,28 @@ export const Edge = ({ edge }: { edge: EdgeProps }) => {
}, []) }, [])
const [targetTop, setTargetTop] = useState( const [targetTop, setTargetTop] = useState(
getEndpointTopOffset(targetEndpoints, graphPosition.y, edge?.to.stepId) getEndpointTopOffset({
endpoints: targetEndpoints,
graphOffsetY: graphPosition.y,
endpointId: edge?.to.stepId,
graphScale: graphPosition.scale,
})
) )
useLayoutEffect(() => { useLayoutEffect(() => {
setTargetTop( setTargetTop(
getEndpointTopOffset(targetEndpoints, graphPosition.y, edge?.to.stepId) getEndpointTopOffset({
endpoints: targetEndpoints,
graphOffsetY: graphPosition.y,
endpointId: edge?.to.stepId,
graphScale: graphPosition.scale,
})
) )
}, [ }, [
targetBlockCoordinates?.y, targetBlockCoordinates?.y,
targetEndpoints, targetEndpoints,
graphPosition.y, graphPosition.y,
edge?.to.stepId, edge?.to.stepId,
graphPosition.scale,
]) ])
const path = useMemo(() => { const path = useMemo(() => {
@@ -79,6 +91,7 @@ export const Edge = ({ edge }: { edge: EdgeProps }) => {
targetBlockCoordinates, targetBlockCoordinates,
sourceTop, sourceTop,
targetTop, targetTop,
graphScale: graphPosition.scale,
}) })
return computeEdgePath(anchorsPosition) return computeEdgePath(anchorsPosition)
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps

View File

@@ -2,20 +2,26 @@ import { Flex, FlexProps, useEventListener } from '@chakra-ui/react'
import React, { useRef, useMemo, useEffect, useState } from 'react' import React, { useRef, useMemo, useEffect, useState } from 'react'
import { import {
blockWidth, blockWidth,
Coordinates,
graphPositionDefaultValue, graphPositionDefaultValue,
useGraph, useGraph,
} from 'contexts/GraphContext' } from 'contexts/GraphContext'
import { useStepDnd } from 'contexts/GraphDndContext' import { useStepDnd } from 'contexts/GraphDndContext'
import { useTypebot } from 'contexts/TypebotContext/TypebotContext' import { useTypebot } from 'contexts/TypebotContext/TypebotContext'
import { headerHeight } from 'components/shared/TypebotHeader/TypebotHeader'
import { DraggableStepType, PublicTypebot, Typebot } from 'models' import { DraggableStepType, PublicTypebot, Typebot } from 'models'
import { AnswersCount } from 'services/analytics' import { AnswersCount } from 'services/analytics'
import { useDebounce } from 'use-debounce' import { useDebounce } from 'use-debounce'
import { DraggableCore, DraggableData, DraggableEvent } from 'react-draggable' import { DraggableCore, DraggableData, DraggableEvent } from 'react-draggable'
import GraphContent from './GraphContent' import GraphContent from './GraphContent'
import cuid from 'cuid' import cuid from 'cuid'
import { headerHeight } from '../TypebotHeader'
import { useUser } from 'contexts/UserContext'
import { GraphNavigation } from 'db'
import { ZoomButtons } from './ZoomButtons'
declare const window: { chrome: unknown | undefined } const maxScale = 1.5
const minScale = 0.1
const zoomButtonsScaleStep = 0.2
export const Graph = ({ export const Graph = ({
typebot, typebot,
@@ -51,6 +57,7 @@ export const Graph = ({
`translate(${graphPosition.x}px, ${graphPosition.y}px) scale(${graphPosition.scale})`, `translate(${graphPosition.x}px, ${graphPosition.y}px) scale(${graphPosition.scale})`,
[graphPosition] [graphPosition]
) )
const { user } = useUser()
useEffect(() => { useEffect(() => {
editorContainerRef.current = document.getElementById( editorContainerRef.current = document.getElementById(
@@ -65,7 +72,7 @@ export const Graph = ({
setGlobalGraphPosition({ setGlobalGraphPosition({
x: left + debouncedGraphPosition.x, x: left + debouncedGraphPosition.x,
y: top + debouncedGraphPosition.y, y: top + debouncedGraphPosition.y,
scale: 1, scale: debouncedGraphPosition.scale,
}) })
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [debouncedGraphPosition]) }, [debouncedGraphPosition])
@@ -73,22 +80,26 @@ export const Graph = ({
const handleMouseWheel = (e: WheelEvent) => { const handleMouseWheel = (e: WheelEvent) => {
e.preventDefault() e.preventDefault()
const isPinchingTrackpad = e.ctrlKey const isPinchingTrackpad = e.ctrlKey
if (isPinchingTrackpad) return user?.graphNavigation === GraphNavigation.MOUSE
setGraphPosition({ ? zoom(-e.deltaY * 0.01, { x: e.clientX, y: e.clientY })
...graphPosition, : isPinchingTrackpad
x: graphPosition.x - e.deltaX / (window.chrome ? 2 : 1), ? zoom(-e.deltaY * 0.01, { x: e.clientX, y: e.clientY })
y: graphPosition.y - e.deltaY / (window.chrome ? 2 : 1), : setGraphPosition({
}) ...graphPosition,
x: graphPosition.x - e.deltaX,
y: graphPosition.y - e.deltaY,
})
} }
const handleMouseUp = (e: MouseEvent) => { const handleMouseUp = (e: MouseEvent) => {
if (!typebot) return if (!typebot) return
if (draggedItem) setDraggedItem(undefined) if (draggedItem) setDraggedItem(undefined)
if (!draggedStep && !draggedStepType) return if (!draggedStep && !draggedStepType) return
const coordinates = {
x: e.clientX - graphPosition.x - blockWidth / 3, const coordinates = projectMouse(
y: e.clientY - graphPosition.y - 20 - headerHeight, { x: e.clientX, y: e.clientY },
} graphPosition
)
const id = cuid() const id = cuid()
updateBlockCoordinates(id, coordinates) updateBlockCoordinates(id, coordinates)
createBlock({ createBlock({
@@ -121,15 +132,40 @@ export const Graph = ({
const onDrag = (_: DraggableEvent, draggableData: DraggableData) => { const onDrag = (_: DraggableEvent, draggableData: DraggableData) => {
const { deltaX, deltaY } = draggableData const { deltaX, deltaY } = draggableData
setGraphPosition({ setGraphPosition({
...graphPosition,
x: graphPosition.x + deltaX, x: graphPosition.x + deltaX,
y: graphPosition.y + deltaY, y: graphPosition.y + deltaY,
scale: 1, })
}
const zoom = (delta = zoomButtonsScaleStep, mousePosition?: Coordinates) => {
const { x: mouseX, y } = mousePosition ?? { x: 0, y: 0 }
const mouseY = y - headerHeight
let scale = graphPosition.scale + delta
if (
(scale >= maxScale && graphPosition.scale === maxScale) ||
(scale <= minScale && graphPosition.scale === minScale)
)
return
scale = scale >= maxScale ? maxScale : scale <= minScale ? minScale : scale
const xs = (mouseX - graphPosition.x) / graphPosition.scale
const ys = (mouseY - graphPosition.y) / graphPosition.scale
setGraphPosition({
...graphPosition,
x: mouseX - xs * scale,
y: mouseY - ys * scale,
scale,
}) })
} }
return ( return (
<DraggableCore onDrag={onDrag} enableUserSelectHack={false}> <DraggableCore onDrag={onDrag} enableUserSelectHack={false}>
<Flex ref={graphContainerRef} position="relative" {...props}> <Flex ref={graphContainerRef} position="relative" {...props}>
<ZoomButtons
onZoomIn={() => zoom(zoomButtonsScaleStep)}
onZoomOut={() => zoom(-zoomButtonsScaleStep)}
/>
<Flex <Flex
flex="1" flex="1"
w="full" w="full"
@@ -150,3 +186,21 @@ export const Graph = ({
</DraggableCore> </DraggableCore>
) )
} }
const projectMouse = (
mouseCoordinates: Coordinates,
graphPosition: Coordinates & { scale: number }
) => {
return {
x:
(mouseCoordinates.x -
graphPosition.x -
blockWidth / (3 / graphPosition.scale)) /
graphPosition.scale,
y:
(mouseCoordinates.y -
graphPosition.y -
(headerHeight + 20 * graphPosition.scale)) /
graphPosition.scale,
}
}

View File

@@ -32,6 +32,7 @@ export const BlockNode = ({ block, blockIndex }: Props) => {
isReadOnly, isReadOnly,
focusedBlockId, focusedBlockId,
setFocusedBlockId, setFocusedBlockId,
graphPosition,
} = useGraph() } = useGraph()
const { typebot, updateBlock } = useTypebot() const { typebot, updateBlock } = useTypebot()
const { setMouseOverBlock, mouseOverBlock } = useStepDnd() const { setMouseOverBlock, mouseOverBlock } = useStepDnd()
@@ -86,11 +87,11 @@ export const BlockNode = ({ block, blockIndex }: Props) => {
if (connectingIds) setConnectingIds({ ...connectingIds, target: undefined }) if (connectingIds) setConnectingIds({ ...connectingIds, target: undefined })
} }
const onDrag = (event: DraggableEvent, draggableData: DraggableData) => { const onDrag = (_: DraggableEvent, draggableData: DraggableData) => {
const { deltaX, deltaY } = draggableData const { deltaX, deltaY } = draggableData
updateBlockCoordinates(block.id, { updateBlockCoordinates(block.id, {
x: blockCoordinates.x + deltaX, x: blockCoordinates.x + deltaX / graphPosition.scale,
y: blockCoordinates.y + deltaY, y: blockCoordinates.y + deltaY / graphPosition.scale,
}) })
} }

View File

@@ -3,7 +3,7 @@ import {
computeNearestPlaceholderIndex, computeNearestPlaceholderIndex,
useStepDnd, useStepDnd,
} from 'contexts/GraphDndContext' } from 'contexts/GraphDndContext'
import { Coordinates } from 'contexts/GraphContext' import { Coordinates, useGraph } from 'contexts/GraphContext'
import { useTypebot } from 'contexts/TypebotContext' import { useTypebot } from 'contexts/TypebotContext'
import { ButtonItem, StepIndices, StepWithItems } from 'models' import { ButtonItem, StepIndices, StepWithItems } from 'models'
import React, { useEffect, useRef, useState } from 'react' import React, { useEffect, useRef, useState } from 'react'
@@ -25,6 +25,7 @@ export const ItemNodesList = ({
const { typebot, createItem, detachItemFromStep } = useTypebot() const { typebot, createItem, detachItemFromStep } = useTypebot()
const { draggedItem, setDraggedItem, mouseOverBlock } = useStepDnd() const { draggedItem, setDraggedItem, mouseOverBlock } = useStepDnd()
const placeholderRefs = useRef<HTMLDivElement[]>([]) const placeholderRefs = useRef<HTMLDivElement[]>([])
const { graphPosition } = useGraph()
const blockId = typebot?.blocks[blockIndex].id const blockId = typebot?.blocks[blockIndex].id
const isDraggingOnCurrentBlock = const isDraggingOnCurrentBlock =
(draggedItem && mouseOverBlock?.id === blockId) ?? false (draggedItem && mouseOverBlock?.id === blockId) ?? false
@@ -182,8 +183,9 @@ export const ItemNodesList = ({
top="0" top="0"
left="0" left="0"
style={{ style={{
transform: `translate(${position.x}px, ${position.y}px) rotate(-2deg)`, transform: `translate(${position.x}px, ${position.y}px) rotate(-2deg) scale(${graphPosition.scale})`,
}} }}
transformOrigin="0 0 0"
/> />
</Portal> </Portal>
)} )}

View File

@@ -32,7 +32,7 @@ export const StepNodesList = ({
setDraggedStepType, setDraggedStepType,
} = useStepDnd() } = useStepDnd()
const { typebot, createStep, detachStepFromBlock } = useTypebot() const { typebot, createStep, detachStepFromBlock } = useTypebot()
const { isReadOnly } = useGraph() const { isReadOnly, graphPosition } = useGraph()
const [expandedPlaceholderIndex, setExpandedPlaceholderIndex] = useState< const [expandedPlaceholderIndex, setExpandedPlaceholderIndex] = useState<
number | undefined number | undefined
>() >()
@@ -166,8 +166,9 @@ export const StepNodesList = ({
top="0" top="0"
left="0" left="0"
style={{ style={{
transform: `translate(${position.x}px, ${position.y}px) rotate(-2deg)`, transform: `translate(${position.x}px, ${position.y}px) rotate(-2deg) scale(${graphPosition.scale})`,
}} }}
transformOrigin="0 0 0"
/> />
</Portal> </Portal>
)} )}

View File

@@ -0,0 +1,37 @@
import { Stack, IconButton } from '@chakra-ui/react'
import { PlusIcon, MinusIcon } from 'assets/icons'
import { headerHeight } from '../TypebotHeader'
type Props = {
onZoomIn: () => void
onZoomOut: () => void
}
export const ZoomButtons = ({ onZoomIn, onZoomOut }: Props) => (
<Stack
pos="fixed"
top={`calc(${headerHeight}px + 70px)`}
right="40px"
bgColor="white"
rounded="md"
zIndex={1}
spacing="0"
shadow="lg"
>
<IconButton
icon={<PlusIcon />}
aria-label={'Zoom out'}
size="sm"
onClick={onZoomIn}
bgColor="white"
borderBottomRadius={0}
/>
<IconButton
icon={<MinusIcon />}
aria-label={'Zoom out'}
size="sm"
onClick={onZoomOut}
bgColor="white"
borderTopRadius={0}
/>
</Stack>
)

View File

@@ -68,8 +68,10 @@ export const useDragDistance = ({
distanceTolerance?: number distanceTolerance?: number
isDisabled: boolean isDisabled: boolean
}) => { }) => {
const mouseDownPosition = const mouseDownPosition = useRef<{
useRef<{ absolute: Coordinates; relative: Coordinates }>() absolute: Coordinates
relative: Coordinates
}>()
const handleMouseUp = () => { const handleMouseUp = () => {
if (mouseDownPosition) mouseDownPosition.current = undefined if (mouseDownPosition) mouseDownPosition.current = undefined

View File

@@ -21,7 +21,7 @@ const userContext = createContext<{
hasUnsavedChanges: boolean hasUnsavedChanges: boolean
isOAuthProvider: boolean isOAuthProvider: boolean
updateUser: (newUser: Partial<User>) => void updateUser: (newUser: Partial<User>) => void
saveUser: (newUser?: Partial<User>) => void saveUser: (newUser?: Partial<User>) => Promise<void>
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore //@ts-ignore
}>({}) }>({})

View File

@@ -129,6 +129,7 @@ type GetAnchorsPositionParams = {
targetBlockCoordinates: Coordinates targetBlockCoordinates: Coordinates
sourceTop: number sourceTop: number
targetTop?: number targetTop?: number
graphScale: number
} }
export const getAnchorsPosition = ({ export const getAnchorsPosition = ({
sourceBlockCoordinates, sourceBlockCoordinates,
@@ -236,12 +237,14 @@ export const computeConnectingEdgePath = ({
targetBlockCoordinates, targetBlockCoordinates,
sourceTop, sourceTop,
targetTop, targetTop,
graphScale,
}: GetAnchorsPositionParams) => { }: GetAnchorsPositionParams) => {
const anchorsPosition = getAnchorsPosition({ const anchorsPosition = getAnchorsPosition({
sourceBlockCoordinates, sourceBlockCoordinates,
targetBlockCoordinates, targetBlockCoordinates,
sourceTop, sourceTop,
targetTop, targetTop,
graphScale,
}) })
return computeEdgePath(anchorsPosition) return computeEdgePath(anchorsPosition)
} }
@@ -258,8 +261,8 @@ export const computeEdgePathToMouse = ({
const sourcePosition = { const sourcePosition = {
x: x:
mousePosition.x - sourceBlockCoordinates.x > blockWidth / 2 mousePosition.x - sourceBlockCoordinates.x > blockWidth / 2
? sourceBlockCoordinates.x + blockWidth - 40 ? sourceBlockCoordinates.x + blockWidth
: sourceBlockCoordinates.x + 40, : sourceBlockCoordinates.x,
y: sourceTop, y: sourceTop,
} }
const sourceType = const sourceType =
@@ -277,19 +280,26 @@ export const computeEdgePathToMouse = ({
).path ).path
} }
export const getEndpointTopOffset = ( export const getEndpointTopOffset = ({
endpoints: IdMap<Endpoint>, endpoints,
graphOffsetY: number, graphOffsetY,
endpointId,
graphScale,
}: {
endpoints: IdMap<Endpoint>
graphOffsetY: number
endpointId?: string endpointId?: string
): number | undefined => { graphScale: number
}): number | undefined => {
if (!endpointId) return if (!endpointId) return
const endpointRef = endpoints[endpointId]?.ref const endpointRef = endpoints[endpointId]?.ref
if (!endpointRef?.current) return if (!endpointRef?.current) return
const endpointHeight = 28 const endpointHeight = 28 * graphScale
return ( return (
endpointRef.current.getBoundingClientRect().top + (endpointRef.current.getBoundingClientRect().y +
endpointHeight / 2 - endpointHeight / 2 -
graphOffsetY graphOffsetY) /
graphScale
) )
} }

View File

@@ -0,0 +1,5 @@
-- CreateEnum
CREATE TYPE "GraphNavigation" AS ENUM ('MOUSE', 'TRACKPAD');
-- AlterTable
ALTER TABLE "User" ADD COLUMN "graphNavigation" "GraphNavigation";

View File

@@ -58,6 +58,12 @@ model User {
CollaboratorsOnTypebots CollaboratorsOnTypebots[] CollaboratorsOnTypebots CollaboratorsOnTypebots[]
company String? company String?
onboardingCategories String[] onboardingCategories String[]
graphNavigation GraphNavigation?
}
enum GraphNavigation {
MOUSE
TRACKPAD
} }
model CustomDomain { model CustomDomain {