chore(react): bring back interaction with nodes

This commit is contained in:
Elian Doran
2025-10-04 13:17:57 +03:00
parent 35438d2599
commit a4d6da72a1
2 changed files with 19 additions and 11 deletions

View File

@@ -84,16 +84,7 @@ export default class NoteMapWidget extends NoteContextAwareWidget {
// Rendering code was here // Rendering code was here
.onNodeClick((node) => {
if (node.id) {
appContext.tabManager.getActiveContext()?.setNote((node as Node).id);
}
})
.onNodeRightClick((node, e) => {
if (node.id) {
linkContextMenuService.openContextMenu((node as Node).id, e);
}
});
const nodeLinkRatio = data.nodes.length / data.links.length; const nodeLinkRatio = data.nodes.length / data.links.length;
const magnifiedRatio = Math.pow(nodeLinkRatio, 1.5); const magnifiedRatio = Math.pow(nodeLinkRatio, 1.5);

View File

@@ -5,10 +5,12 @@ import { RefObject } from "preact";
import FNote from "../../entities/fnote"; import FNote from "../../entities/fnote";
import { useElementSize, useNoteContext, useNoteLabel } from "../react/hooks"; import { useElementSize, useNoteContext, useNoteLabel } from "../react/hooks";
import ForceGraph, { LinkObject, NodeObject } from "force-graph"; import ForceGraph, { LinkObject, NodeObject } from "force-graph";
import { loadNotesAndRelations, NotesAndRelationsData } from "./data"; import { loadNotesAndRelations, Node, NotesAndRelationsData } from "./data";
import { CssData, setupRendering } from "./rendering"; import { CssData, setupRendering } from "./rendering";
import ActionButton from "../react/ActionButton"; import ActionButton from "../react/ActionButton";
import { t } from "../../services/i18n"; import { t } from "../../services/i18n";
import link_context_menu from "../../menus/link_context_menu";
import appContext from "../../components/app_context";
interface NoteMapProps { interface NoteMapProps {
note: FNote; note: FNote;
@@ -42,6 +44,8 @@ export default function NoteMap({ note, widgetMode, parentRef }: NoteMapProps) {
loadNotesAndRelations(mapRootId, excludeRelations, includeRelations, mapType).then((notesAndRelations) => { loadNotesAndRelations(mapRootId, excludeRelations, includeRelations, mapType).then((notesAndRelations) => {
if (!containerRef.current || !styleResolverRef.current) return; if (!containerRef.current || !styleResolverRef.current) return;
const cssData = getCssData(containerRef.current, styleResolverRef.current); const cssData = getCssData(containerRef.current, styleResolverRef.current);
// Configure rendering properties.
setupRendering(graph, { setupRendering(graph, {
cssData, cssData,
noteId: note.noteId, noteId: note.noteId,
@@ -51,6 +55,19 @@ export default function NoteMap({ note, widgetMode, parentRef }: NoteMapProps) {
widgetMode, widgetMode,
mapType mapType
}); });
// Interaction
graph
.onNodeClick((node) => {
if (!node.id) return;
appContext.tabManager.getActiveContext()?.setNote((node as Node).id);
})
.onNodeRightClick((node, e) => {
if (!node.id) return;
link_context_menu.openContextMenu((node as Node).id, e);
});
// Set data
graph.graphData(notesAndRelations); graph.graphData(notesAndRelations);
}); });