/* eslint-disable @eslint-react/no-array-index-key */ /* eslint-disable react-perf/jsx-no-new-function-as-prop */ import '../index.css'; import { useCallback, type PropsWithChildren } from 'react'; import { createElements, createLinks, GraphProvider, MeasuredNode, Paper, useUpdateElement, type InferElement, type OnSetSize, } from '@joint/react'; import { PAPER_CLASSNAME, PRIMARY } from 'storybook-config/theme'; type Data = { id: string; label: string; inputs: string[]; x: number; y: number; }; const initialElements = createElements([ { id: '1', label: 'Node 1', inputs: [], x: 100, y: 0 }, { id: '2', label: 'Node 2', inputs: [], x: 500, y: 200 }, ]); const initialEdges = createLinks([ { id: 'e1-2', source: '1', target: '2', attrs: { line: { stroke: PRIMARY, }, }, }, ]); type BaseElementWithData = InferElement; function ListElement({ id, children, width, height, inputs, }: PropsWithChildren) { const padding = 10; const headerHeight = 50; const setListSize: OnSetSize = useCallback(({ element, size }) => { const w = padding + size.width + padding; const h = headerHeight + size.height + padding; element.size(w, h, { async: false }); }, []); const setInputs = useUpdateElement(id, 'inputs'); const addInput = () => { setInputs((previous) => { return [...previous, '']; }); }; return ( <> {`${children}`}
    {inputs.map((input, index) => (
  • { const newInputs = [...inputs]; newInputs[index] = event.target.value; setInputs(newInputs); }} />
  • ))}
{inputs.length === 0 &&
No items
}
); } function Main() { const renderElement = useCallback((element: BaseElementWithData) => { return {element.label}; }, []); return ( ); } export default function App() { return (
); }