mirror of
https://github.com/TriliumNext/Trilium.git
synced 2025-12-10 03:53:37 -06:00
refactor(react/type_widgets): use dedicated component for items
This commit is contained in:
parent
3b2f5bb09d
commit
4af842d2f2
@ -17,7 +17,7 @@ import contextMenu from "../../../menus/context_menu";
|
|||||||
import appContext from "../../../components/app_context";
|
import appContext from "../../../components/app_context";
|
||||||
import RelationMapApi, { MapData, MapDataNoteEntry } from "./api";
|
import RelationMapApi, { MapData, MapDataNoteEntry } from "./api";
|
||||||
import setupOverlays, { uniDirectionalOverlays } from "./overlays";
|
import setupOverlays, { uniDirectionalOverlays } from "./overlays";
|
||||||
import { JsPlumb } from "./jsplumb";
|
import { JsPlumb, JsPlumbItem } from "./jsplumb";
|
||||||
|
|
||||||
interface Clipboard {
|
interface Clipboard {
|
||||||
noteId: string;
|
noteId: string;
|
||||||
@ -359,18 +359,14 @@ function NoteBox({ noteId, x, y, mapApiRef }: MapDataNoteEntry & { mapApiRef: Re
|
|||||||
}, [ note ]);
|
}, [ note ]);
|
||||||
|
|
||||||
return note && (
|
return note && (
|
||||||
<div
|
<JsPlumbItem
|
||||||
id={noteIdToId(noteId)}
|
|
||||||
className={`note-box ${note?.getCssClass()}`}
|
className={`note-box ${note?.getCssClass()}`}
|
||||||
onContextMenu={contextMenuHandler}
|
onContextMenu={contextMenuHandler}
|
||||||
style={{
|
x={x} y={y}
|
||||||
left: x,
|
|
||||||
top: y
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<NoteLink className="title" title={title} notePath={noteId} noTnLink noContextMenu />
|
<NoteLink className="title" title={title} notePath={noteId} noTnLink noContextMenu />
|
||||||
<div className="endpoint" title={t("relation_map.start_dragging_relations")} />
|
<div className="endpoint" title={t("relation_map.start_dragging_relations")} />
|
||||||
</div>
|
</JsPlumbItem>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { jsPlumb, Defaults, jsPlumbInstance } from "jsplumb";
|
import { jsPlumb, Defaults, jsPlumbInstance } from "jsplumb";
|
||||||
import { ComponentChildren, RefObject } from "preact";
|
import { ComponentChildren, RefObject } from "preact";
|
||||||
|
import { HTMLProps } from "preact/compat";
|
||||||
import { useEffect, useRef } from "preact/hooks";
|
import { useEffect, useRef } from "preact/hooks";
|
||||||
|
|
||||||
export function JsPlumb({ className, props, children, containerRef: externalContainerRef, apiRef, onInstanceCreated }: {
|
export function JsPlumb({ className, props, children, containerRef: externalContainerRef, apiRef, onInstanceCreated }: {
|
||||||
@ -39,3 +40,18 @@ export function JsPlumb({ className, props, children, containerRef: externalCont
|
|||||||
</div>
|
</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>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user