fix(mindmap): search not working

This commit is contained in:
Elian Doran 2025-09-21 09:35:17 +03:00
parent 7d99a92bd9
commit 26400f2590
No known key found for this signature in database
2 changed files with 10 additions and 64 deletions

View File

@ -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<MindElixirInstance>(null);
const containerRef = useRef<HTMLDivElement>(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 (
<div className="note-detail-mind-map note-detail-printable">
<div ref={containerRef} className="note-detail-mind-map note-detail-printable">
<MindElixir
apiRef={apiRef}
content={content}

View File

@ -6,58 +6,6 @@ import type { EventData } from "../../components/app_context.js";
export default class MindMapWidget extends TypeWidget {
private $content!: JQuery<HTMLElement>;
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<MindmapModel>();
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'));
}
}