From 26400f2590fc907116a9f3e2180f7b4011e0245c Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 21 Sep 2025 09:35:17 +0300 Subject: [PATCH] fix(mindmap): search not working --- .../src/widgets/type_widgets/MindMap.tsx | 13 +++- .../src/widgets/type_widgets_old/mind_map.ts | 61 ------------------- 2 files changed, 10 insertions(+), 64 deletions(-) diff --git a/apps/client/src/widgets/type_widgets/MindMap.tsx b/apps/client/src/widgets/type_widgets/MindMap.tsx index ef6358ec2..f886e6561 100644 --- a/apps/client/src/widgets/type_widgets/MindMap.tsx +++ b/apps/client/src/widgets/type_widgets/MindMap.tsx @@ -7,7 +7,7 @@ import nodeMenu from "@mind-elixir/node-menu"; import "mind-elixir/style"; import "@mind-elixir/node-menu/dist/style.css"; import "./MindMap.css"; -import { useEditorSpacedUpdate } from "../react/hooks"; +import { useEditorSpacedUpdate, useTriliumEvent } from "../react/hooks"; import { refToJQuerySelector } from "../react/react_utils"; const NEW_TOPIC_NAME = ""; @@ -20,9 +20,10 @@ interface MindElixirProps { onChange?: () => void; } -export default function MindMap({ note }: TypeWidgetProps) { +export default function MindMap({ note, ntxId }: TypeWidgetProps) { const content = VanillaMindElixir.new(NEW_TOPIC_NAME); const apiRef = useRef(null); + const containerRef = useRef(null); const spacedUpdate = useEditorSpacedUpdate({ note, getData: () => { @@ -56,6 +57,12 @@ export default function MindMap({ note }: TypeWidgetProps) { } }); + // Allow search. + useTriliumEvent("executeWithContentElement", ({ resolve, ntxId: eventNtxId }) => { + if (eventNtxId !== ntxId) return; + resolve(refToJQuerySelector(containerRef).find(".map-canvas")); + }); + const onKeyDown = useCallback((e: KeyboardEvent) => { /* * Some global shortcuts interfere with the default shortcuts of the mind map, @@ -73,7 +80,7 @@ export default function MindMap({ note }: TypeWidgetProps) { }, []); return ( -
+
; - private triggeredByUserOperation?: boolean; - private mind?: MindElixirInstance; - private MindElixir: any; // TODO: Fix type - - static getType() { - return "mindMap"; - } - - async doRefresh(note: FNote) { - if (this.triggeredByUserOperation) { - this.triggeredByUserOperation = false; - return; - } - - await this.#loadData(note); - } - - cleanup() { - this.triggeredByUserOperation = false; - } - - async #loadData(note: FNote) { - const blob = await note.getBlob(); - const content = blob?.getJsonContent(); - - if (!this.mind) { - await this.#initLibrary(content?.direction); - } - - this.mind!.refresh(content ?? this.MindElixir.new(NEW_TOPIC_NAME)); - this.mind!.toCenter(); - } - - async #initLibrary(direction?: number) { - const mind = new this.MindElixir({ - direction: direction ?? this.MindElixir.LEFT - }); - - this.mind = mind; - } - - async renderSvg() { - return await this.mind!.exportSvg().text(); - } - - async entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) { - if (this.noteId && loadResults.isNoteReloaded(this.noteId)) { - this.refresh(); - } - } - async exportSvgEvent({ ntxId }: EventData<"exportSvg">) { if (!this.isNoteContext(ntxId) || this.note?.type !== "mindMap") { return; @@ -76,13 +24,4 @@ export default class MindMapWidget extends TypeWidget { utils.downloadSvgAsPng(this.note.title, svg); } - async executeWithContentElementEvent({ resolve, ntxId }: EventData<"executeWithContentElement">) { - if (!this.isNoteContext(ntxId)) { - return; - } - - await this.initialized; - - resolve(this.$content.find('.main-node-container')); - } }