/* eslint-disable react-perf/jsx-no-new-object-as-prop */ import { createElements, createLinks, GraphProvider, MeasuredNode, Paper, useElements, type InferElement, } from '@joint/react'; import '../index.css'; import { useCallback, useRef } from 'react'; import { PAPER_CLASSNAME, PRIMARY } from 'storybook-config/theme'; const initialElements = createElements([ { id: '1', label: 'Node 1', x: 100, y: 0 }, { id: '2', label: 'Node 2', x: 100, y: 200 }, ]); const initialEdges = createLinks([ { id: 'e1-2', source: '1', target: '2', attrs: { line: { stroke: PRIMARY, }, }, }, ]); type BaseElementWithData = InferElement; function ResizableNode({ width, height, label }: Readonly) { const nodeRef = useRef(null); const handleMouseDown = useCallback((event: React.MouseEvent) => { const node = nodeRef.current; if (!node) return; // Get the node’s bounding rectangle const rect = node.getBoundingClientRect(); const threshold = 20; // pixels from the bottom-right corner considered as resize area // Calculate how far from the left/top the click was const offsetX = event.clientX - rect.left; const offsetY = event.clientY - rect.top; // If the click is within the bottom-right "resize" zone, // stop propagation so that JointJS doesn't start dragging the node. if (rect.width - offsetX < threshold && rect.height - offsetY < threshold) { event.stopPropagation(); } }, []); return (
{label}
); } function Main() { const elementsSize = useElements((items) => items.map(({ width, height }) => `${width} x ${height}`) ); return (
width & height {elementsSize.map((size, index) => ( // eslint-disable-next-line @eslint-react/no-array-index-key
{index + 1}. {size}
))}
); } export default function App() { return (
); }