Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(react/type_widgets): use dedicated component for items
Elian Doran4af842d2f249
diff --git a/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx b/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsxindex 9a20b12fe6..18b44936a6 100644--- a/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx+++ b/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx@@ -17,7 +17,7 @@ import contextMenu from "../../../menus/context_menu";import appContext from "../../../components/app_context";import RelationMapApi, { MapData, MapDataNoteEntry } from "./api";import setupOverlays, { uniDirectionalOverlays } from "./overlays";-import { JsPlumb } from "./jsplumb";+import { JsPlumb, JsPlumbItem } from "./jsplumb";interface Clipboard {noteId: string;@@ -359,18 +359,14 @@ function NoteBox({ noteId, x, y, mapApiRef }: MapDataNoteEntry & { mapApiRef: Re}, [ note ]);return note && (- <div- id={noteIdToId(noteId)}+ <JsPlumbItemclassName={`note-box ${note?.getCssClass()}`}onContextMenu={contextMenuHandler}- style={{- left: x,- top: y- }}+ x={x} y={y}><NoteLink className="title" title={title} notePath={noteId} noTnLink noContextMenu /><div className="endpoint" title={t("relation_map.start_dragging_relations")} />- </div>+ </JsPlumbItem>)}diff --git a/apps/client/src/widgets/type_widgets/relation_map/jsplumb.tsx b/apps/client/src/widgets/type_widgets/relation_map/jsplumb.tsxindex 88b307bc43..6da913f45d 100644--- a/apps/client/src/widgets/type_widgets/relation_map/jsplumb.tsx+++ b/apps/client/src/widgets/type_widgets/relation_map/jsplumb.tsx@@ -1,5 +1,6 @@import { jsPlumb, Defaults, jsPlumbInstance } from "jsplumb";import { ComponentChildren, RefObject } from "preact";+import { HTMLProps } from "preact/compat";import { useEffect, useRef } from "preact/hooks";export function JsPlumb({ className, props, children, containerRef: externalContainerRef, apiRef, onInstanceCreated }: {@@ -39,3 +40,18 @@ export function JsPlumb({ className, props, children, containerRef: externalCont</div>)}++export function JsPlumbItem({ x, y, children, ...restProps }: {+ x: number;+ y: number;+ children: ComponentChildren;+} & Pick<HTMLProps<HTMLDivElement>, "className" | "onContextMenu">) {+ return (+ <div+ {...restProps}+ style={{ left: x, top: y }}+ >+ {children}+ </div>+ )+}