chore(react/type_widgets): bring back dragging notes in relation map

This commit is contained in:
Elian Doran 2025-10-03 22:40:22 +03:00
parent e8e93e985d
commit f687d91201
No known key found for this signature in database
3 changed files with 18 additions and 28 deletions

View File

@ -360,7 +360,7 @@ function NoteBox({ noteId, x, y, mapApiRef }: MapDataNoteEntry & { mapApiRef: Re
return note && ( return note && (
<JsPlumbItem <JsPlumbItem
id={idToNoteId(note.noteId)} id={noteIdToId(noteId)}
className={`note-box ${note?.getCssClass()}`} className={`note-box ${note?.getCssClass()}`}
onContextMenu={contextMenuHandler} onContextMenu={contextMenuHandler}
x={x} y={y} x={x} y={y}
@ -368,7 +368,9 @@ function NoteBox({ noteId, x, y, mapApiRef }: MapDataNoteEntry & { mapApiRef: Re
start() {}, start() {},
drag() {}, drag() {},
stop(params) { stop(params) {
const noteId = idToNoteId(params.el.id);
const [ x, y ] = params.pos;
mapApiRef.current?.moveNote(noteId, x, y);
}, },
}} }}
> >

View File

@ -1,4 +1,5 @@
import FNote from "../../../entities/fnote"; import FNote from "../../../entities/fnote";
import { t } from "../../../services/i18n";
import server from "../../../services/server"; import server from "../../../services/server";
import utils from "../../../services/utils"; import utils from "../../../services/utils";
@ -65,4 +66,17 @@ export default class RelationMapApi {
} }
} }
moveNote(noteId: string, x: number, y: number) {
const note = this.data?.notes.find((note) => note.noteId === noteId);
if (!note) {
logError(t("relation_map.note_not_found", { noteId }));
return;
}
note.x = x;
note.y = y;
this.onDataChange(false);
}
} }

View File

@ -215,32 +215,6 @@ export default class RelationMapTypeWidget extends TypeWidget {
} }
async createNoteBox(noteId: string, title: string, x: number, y: number) { async createNoteBox(noteId: string, title: string, x: number, y: number) {
if (!this.jsPlumbInstance) {
return;
}
this.jsPlumbInstance.getContainer().appendChild($noteBox[0]);
this.jsPlumbInstance.draggable($noteBox[0], {
start: (params) => {},
drag: (params) => {},
stop: (params) => {
const noteId = this.idToNoteId(params.el.id);
const note = this.mapData?.notes.find((note) => note.noteId === noteId);
if (!note) {
logError(t("relation_map.note_not_found", { noteId }));
return;
}
//@ts-expect-error TODO: Check if this is still valid.
[note.x, note.y] = params.finalPos;
this.saveData();
}
});
this.jsPlumbInstance.makeSource($noteBox[0], { this.jsPlumbInstance.makeSource($noteBox[0], {
filter: ".endpoint", filter: ".endpoint",
anchor: "Continuous", anchor: "Continuous",