import { Box, TLArrowShape, useEditor, useValue, VecLike } from '@tldraw/editor'
import { SVGProps } from 'react'
import { getArrowBindings } from '../shared'
import { ElbowArrowEdge } from './definitions'
import { getElbowArrowInfo } from './getElbowArrowInfo'
export function ElbowArrowDebug({ arrow }: { arrow: TLArrowShape }) {
const editor = useEditor()
const info = useValue(
'elbow arrow grid',
() => {
try {
const info = getElbowArrowInfo(
editor,
editor.getShape(arrow.id)!,
getArrowBindings(editor, arrow)
)
return info
} catch (err) {
console.error(err)
return undefined
}
},
[editor, arrow.id]
)
if (!info) return null
const fullBox = Box.Common([info.A.original, info.B.original]).expandBy(50)
const label = info.route?.name ?? ''
const midPoint = info.route?.midpointHandle
return (
<>
{info.midX !== null && (
)}
{info.midY !== null && (
)}
{midPoint?.axis === 'x' && info.midXRange && (
)}
{midPoint?.axis === 'y' && info.midYRange && (
)}
{info.route && }
{label}
A{info.route && `, ${info.route.aEdgePicking}`}
{info.A.isPoint && `, point`}
B{info.route && `, ${info.route.bEdgePicking}`}
{info.B.isPoint && `, point`}
>
)
}
function DebugLine({ a, b, ...props }: { a: VecLike; b: VecLike } & SVGProps) {
return (
)
}
function DebugRoute({ route, ...props }: { route: VecLike[] } & SVGProps) {
return (
`${r.x},${r.y}`).join(' ')}
{...props}
/>
)
}
function DebugEdge({
edge,
axis,
...props
}: {
edge: ElbowArrowEdge | null
axis: 'x' | 'y'
} & Omit, 'scale'>) {
if (!edge || edge.expanded === null) return null
const vec = (vec: VecLike) => (axis === 'x' ? { x: vec.y, y: vec.x } : vec)
return (
)
}
function DebugBox({ box, ...props }: { box: Box } & SVGProps) {
return (
)
}