import { TextDialog } from "@/App/Modals/TextDialog"; import { TraceableError } from "../../statecharts/parser"; import {Text} from "../../statecharts/concrete_syntax"; import { Dispatch, memo, ReactElement, SetStateAction } from "react"; export const TextSVG = memo(function TextSVG(props: {text: Text, error: TraceableError|undefined, selected: boolean, highlight: boolean, onEdit: (text: Text, newText: string) => void, setModal: Dispatch>}) { const commonProps = { "data-uid": props.text.uid, "data-parts": "text", textAnchor: "middle" as "middle", className: "draggableText" + (props.selected ? " selected":"") + (props.highlight ? " highlight":""), style: {whiteSpace: "preserve"}, } let textNode; if (props.error?.data?.location) { const {start,end} = props.error.data.location; textNode = <> {props.text.text.slice(0, start.offset)} {props.text.text.slice(start.offset, end.offset)} {start.offset === end.offset && <>_} {props.text.text.slice(end.offset)} {props.error.message}; } else { textNode = {props.text.text}; } return { props.setModal( { if (newText) { props.onEdit(props.text, newText); } }} />) }}> {textNode} {props.text.text} ; });