mirror of
https://github.com/zadam/trilium.git
synced 2025-11-10 23:35:50 +01:00
chore(react): bring back fixing nodes
This commit is contained in:
@@ -26,6 +26,7 @@ export default function NoteMap({ note, widgetMode, parentRef }: NoteMapProps) {
|
||||
|
||||
const graphRef = useRef<ForceGraph<NodeObject, LinkObject<NodeObject>>>();
|
||||
const containerSize = useElementSize(parentRef);
|
||||
const [ fixNodes, setFixNodes ] = useState(false);
|
||||
|
||||
// Build the note graph instance.
|
||||
useEffect(() => {
|
||||
@@ -80,6 +81,19 @@ export default function NoteMap({ note, widgetMode, parentRef }: NoteMapProps) {
|
||||
graphRef.current.width(containerSize.width).height(containerSize.height);
|
||||
}, [ containerSize?.width, containerSize?.height ]);
|
||||
|
||||
// Fixing nodes when dragged.
|
||||
useEffect(() => {
|
||||
graphRef.current?.onNodeDragEnd((node) => {
|
||||
if (fixNodes) {
|
||||
node.fx = node.x;
|
||||
node.fy = node.y;
|
||||
} else {
|
||||
node.fx = undefined;
|
||||
node.fy = undefined;
|
||||
}
|
||||
})
|
||||
}, [ fixNodes ]);
|
||||
|
||||
return (
|
||||
<div className="note-map-widget">
|
||||
<div className="btn-group btn-group-sm map-type-switcher content-floating-buttons top-left" role="group">
|
||||
@@ -87,6 +101,15 @@ export default function NoteMap({ note, widgetMode, parentRef }: NoteMapProps) {
|
||||
<MapTypeSwitcher type="tree" icon="bx bx-sitemap" text={t("note-map.button-tree-map")} currentMapType={mapType} setMapType={setMapType} />
|
||||
</div>
|
||||
|
||||
<div class="btn-group-sm fixnodes-type-switcher content-floating-buttons bottom-left" role="group">
|
||||
<ActionButton
|
||||
icon="bx bx-lock-alt"
|
||||
text={t("note_map.fix-nodes")}
|
||||
className={fixNodes ? "toggled" : ""}
|
||||
onClick={() => setFixNodes(!fixNodes)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div ref={styleResolverRef} class="style-resolver" />
|
||||
<div ref={containerRef} className="note-map-container" />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user