From 1913355069700f7d08c4bdd739e0b2e4ae3079c3 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 4 Oct 2025 08:56:53 +0300 Subject: [PATCH] chore(react/type_widgets): relation map source/target config --- .../type_widgets/relation_map/RelationMap.tsx | 18 ++++++++++++++++++ .../type_widgets/relation_map/jsplumb.tsx | 14 +++++++++++++- .../widgets/type_widgets_old/relation_map.ts | 18 ------------------ 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx b/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx index 06b224202..ef98fa226 100644 --- a/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx +++ b/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx @@ -307,6 +307,22 @@ function useNoteCreation({ ntxId, note, containerRef, mapApiRef }: { return onClickHandler; } +const NOTE_BOX_SOURCE_CONFIG = { + filter: ".endpoint", + anchor: "Continuous", + connectorStyle: { stroke: "#000", strokeWidth: 1 }, + connectionType: "basic", + extract: { + action: "the-action" + } +}; + +const NOTE_BOX_TARGET_CONFIG = { + dropOptions: { hoverClass: "dragHover" }, + anchor: "Continuous", + allowLoopback: true +}; + function NoteBox({ noteId, x, y, mapApiRef }: MapDataNoteEntry & { mapApiRef: RefObject }) { const [ note, setNote ] = useState(); const title = useNoteProperty(note, "title"); @@ -373,6 +389,8 @@ function NoteBox({ noteId, x, y, mapApiRef }: MapDataNoteEntry & { mapApiRef: Re mapApiRef.current?.moveNote(noteId, x, y); }, }} + sourceConfig={NOTE_BOX_SOURCE_CONFIG} + targetConfig={NOTE_BOX_TARGET_CONFIG} >
diff --git a/apps/client/src/widgets/type_widgets/relation_map/jsplumb.tsx b/apps/client/src/widgets/type_widgets/relation_map/jsplumb.tsx index 2aab703db..d304b41a9 100644 --- a/apps/client/src/widgets/type_widgets/relation_map/jsplumb.tsx +++ b/apps/client/src/widgets/type_widgets/relation_map/jsplumb.tsx @@ -45,11 +45,13 @@ export function JsPlumb({ className, props, children, containerRef: externalCont ) } -export function JsPlumbItem({ x, y, children, draggable, ...restProps }: { +export function JsPlumbItem({ x, y, children, draggable, sourceConfig, targetConfig, ...restProps }: { x: number; y: number; children: ComponentChildren; draggable?: DragOptions; + sourceConfig?: object; + targetConfig?: object; } & Pick, "id" | "className" | "onContextMenu">) { const containerRef = useRef(null); const apiRef = useContext(JsPlumbInstance); @@ -59,6 +61,16 @@ export function JsPlumbItem({ x, y, children, draggable, ...restProps }: { apiRef.current.draggable(containerRef.current, draggable); }, [ draggable ]); + useEffect(() => { + if (!sourceConfig || !apiRef?.current || !containerRef.current) return; + apiRef.current.makeSource(containerRef.current, sourceConfig); + }, [ sourceConfig ]); + + useEffect(() => { + if (!targetConfig || !apiRef?.current || !containerRef.current) return; + apiRef.current.makeSource(containerRef.current, targetConfig); + }, [ targetConfig ]); + return (