import { COLOR_OPTIONS, NOTE_NODE_MAX_HEIGHT, NOTE_NODE_MAX_WIDTH, NOTE_NODE_MIN_HEIGHT, NOTE_NODE_MIN_WIDTH, } from "@/constants/constants"; import { NoteDataType } from "@/types/flow"; import { cn } from "@/utils/utils"; import { NodeResizer } from "@xyflow/react"; import { useEffect, useMemo, useRef, useState } from "react"; import NodeDescription from "../GenericNode/components/NodeDescription"; import NoteToolbarComponent from "./NoteToolbarComponent"; function NoteNode({ data, selected, }: { data: NoteDataType; selected?: boolean; }) { const bgColor = Object.keys(COLOR_OPTIONS).find( (key) => key === data.node?.template.backgroundColor, ) ?? Object.keys(COLOR_OPTIONS)[0]; const nodeDiv = useRef(null); const [size, setSize] = useState({ width: 0, height: 0 }); //tricky to start the description with the right size useEffect(() => { if (nodeDiv.current) { setSize({ width: nodeDiv.current.offsetWidth - 25, height: nodeDiv.current.offsetHeight - 25, }); } }, []); const MemoNoteToolbarComponent = useMemo( () => selected ? (
) : ( <> ), [data, bgColor, selected], ); return ( <> { const { width, height } = params; setSize({ width: width - 25, height: height - 25 }); }} isVisible={selected} lineClassName="!border !border-muted-foreground" />
{MemoNoteToolbarComponent}
); } export default NoteNode;