/* eslint-disable react-perf/jsx-no-new-function-as-prop */
/* eslint-disable react-perf/jsx-no-new-object-as-prop */
import { dia, linkTools } from '@joint/core';
import '../index.css';
import {
createElements,
createLinks,
GraphProvider,
Paper,
jsx,
type InferElement,
type RenderElement,
} from '@joint/react';
import { useCallback } from 'react';
import { PRIMARY, BG, SECONDARY, PAPER_CLASSNAME } from 'storybook-config/theme';
const initialEdges = createLinks([
{
id: 'e1-2',
source: '1',
target: '2',
attrs: {
line: {
stroke: PRIMARY,
strokeDasharray: '5 5',
},
},
},
]);
const initialElements = createElements([
{ id: '1', label: 'Node 1', x: 100, y: 10, width: 120, height: 30 },
{ id: '2', label: 'Node 2', x: 100, y: 200, width: 120, height: 30 },
]);
// 1) creating link tools
const verticesTool = new linkTools.Vertices({
handleClass: linkTools.Vertices.VertexHandle.extend({
style: {
fill: BG,
stroke: SECONDARY,
strokeWidth: 2,
},
}),
});
const boundaryTool = new linkTools.Boundary({
style: { stroke: '#999' },
});
// 2) create custom link tool
const infoButton = new linkTools.Button({
// using jsx utility by joint-jsx, convert jsx to markup
markup: jsx(
<>
>
),
distance: 20,
action: () => {
alert('Info button clicked');
},
});
// 3) creating a tools view
const toolsView = new dia.ToolsView({
tools: [boundaryTool, verticesTool, infoButton],
});
type BaseElementWithData = InferElement;
function RectElement({ width, height }: BaseElementWithData) {
return (
);
}
function Main() {
const renderElement: RenderElement = useCallback(
(props) => ,
[]
);
return (
linkView.addTools(toolsView)}
onLinkMouseLeave={({ linkView }) => linkView.removeTools()}
/>
);
}
export default function App() {
return (
);
}