import React from 'react'; import { useCanvasStore } from '../../store/canvasStore'; import type { ArrowElement } from '../../types'; interface ArrowInspectorProps { element: ArrowElement; } const ArrowInspector: React.FC = ({ element }) => { const { updateElement } = useCanvasStore(); const update = (updates: Partial) => { updateElement(element.id, updates); }; const updateProps = (props: Partial) => { update({ props: { ...element.props, ...props } }); }; const addControlPoint = () => { const start = element.points[0]; const end = element.points[element.points.length - 1]; const currentControlPoints = element.props.controlPoints || []; if (currentControlPoints.length < 2) { const midX = (start.x + end.x) / 2; const midY = (start.y + end.y) / 2; const dx = end.x - start.x; const dy = end.y - start.y; const newPoint = currentControlPoints.length === 0 ? { x: midX - dy * 0.3, y: midY + dx * 0.3 } : { x: midX + dy * 0.3, y: midY - dx * 0.3 }; updateProps({ controlPoints: [...currentControlPoints, newPoint] }); } }; const removeControlPoint = (index: number) => { const currentControlPoints = element.props.controlPoints || []; const newControlPoints = currentControlPoints.filter((_, i) => i !== index); updateProps({ controlPoints: newControlPoints }); }; const resetControlPoints = () => { updateProps({ controlPoints: [] }); }; return (
{/* Style */}
{/* Control points for curved arrows */} {element.props.style === 'curved' && (
{(element.props.controlPoints || []).length > 0 && (
{(element.props.controlPoints || []).map((cp, index) => (
Point {index + 1}: ({Math.round(cp.x)}, {Math.round(cp.y)})
))}
)}

Drag the blue handles on the canvas to adjust the curve shape.

)} {/* Color */}
updateProps({ color: e.target.value })} className="absolute inset-[-4px] w-[200%] h-[200%] cursor-pointer p-0 m-0 border-none" />
updateProps({ color: e.target.value })} className="flex-1 bg-transparent text-white text-sm focus:outline-none font-mono" />
{/* Thickness */}
updateProps({ thickness: parseInt(e.target.value) })} className="w-full h-1.5 bg-white/10 rounded-lg appearance-none cursor-pointer accent-blue-600" min={1} max={12} />
{/* Arrow head */}
{/* Label */}
updateProps({ label: e.target.value || undefined })} placeholder="Add a label..." className="w-full bg-white/5 text-white px-3 py-2 rounded-lg text-sm border border-white/5 focus:border-blue-500/50 focus:outline-none" />
{/* Label position */} {element.props.label && (
updateProps({ labelPosition: parseInt(e.target.value) / 100 })} className="w-full h-1.5 bg-white/10 rounded-lg appearance-none cursor-pointer accent-blue-600" min={0} max={100} />
)} {/* Points info */}

Drag the white handles on the canvas to move the arrow endpoints.

); }; export default ArrowInspector;