Skip to content

Build your personal knowledge base with Trilium Notes

fix(mindmap): search not working

Elian Doran26400f2590fc
diff --git a/apps/client/src/widgets/type_widgets/MindMap.tsx b/apps/client/src/widgets/type_widgets/MindMap.tsx
index ef6358ec21..f886e6561a 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<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}
diff --git a/apps/client/src/widgets/type_widgets_old/mind_map.ts b/apps/client/src/widgets/type_widgets_old/mind_map.ts
index 59a9bb6468..2dfead820e 100644
--- a/apps/client/src/widgets/type_widgets_old/mind_map.ts
+++ b/apps/client/src/widgets/type_widgets_old/mind_map.ts
@@ -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'));
- }
}