mirror of
https://github.com/zadam/trilium.git
synced 2025-11-11 00:49:00 +01:00
chore(react/type_widget): finalize mind map with export PNG/SVG
This commit is contained in:
parent
26400f2590
commit
9a3f675950
@ -7,14 +7,14 @@ import nodeMenu from "@mind-elixir/node-menu";
|
||||
import "mind-elixir/style";
|
||||
import "@mind-elixir/node-menu/dist/style.css";
|
||||
import "./MindMap.css";
|
||||
import { useEditorSpacedUpdate, useTriliumEvent } from "../react/hooks";
|
||||
import { useEditorSpacedUpdate, useTriliumEvent, useTriliumEvents } from "../react/hooks";
|
||||
import { refToJQuerySelector } from "../react/react_utils";
|
||||
import utils from "../../services/utils";
|
||||
|
||||
const NEW_TOPIC_NAME = "";
|
||||
|
||||
interface MindElixirProps {
|
||||
apiRef?: RefObject<MindElixirInstance>;
|
||||
direction: number;
|
||||
containerProps?: Omit<HTMLAttributes<HTMLDivElement>, "ref">;
|
||||
content: MindElixirData;
|
||||
onChange?: () => void;
|
||||
@ -63,6 +63,18 @@ export default function MindMap({ note, ntxId }: TypeWidgetProps) {
|
||||
resolve(refToJQuerySelector(containerRef).find(".map-canvas"));
|
||||
});
|
||||
|
||||
// Export as PNG or SVG.
|
||||
useTriliumEvents([ "exportSvg", "exportPng" ], async ({ ntxId: eventNtxId }, eventName) => {
|
||||
if (eventNtxId !== ntxId || !apiRef.current) return;
|
||||
const title = note.title;
|
||||
const svg = await apiRef.current.exportSvg().text();
|
||||
if (eventName === "exportSvg") {
|
||||
utils.downloadSvg(title, svg);
|
||||
} else {
|
||||
utils.downloadSvgAsPng(title, svg);
|
||||
}
|
||||
});
|
||||
|
||||
const onKeyDown = useCallback((e: KeyboardEvent) => {
|
||||
/*
|
||||
* Some global shortcuts interfere with the default shortcuts of the mind map,
|
||||
|
||||
@ -1,27 +0,0 @@
|
||||
import TypeWidget from "./type_widget.js";
|
||||
import utils from "../../services/utils.js";
|
||||
import type { MindElixirInstance } from "mind-elixir";
|
||||
import type FNote from "../../entities/fnote.js";
|
||||
import type { EventData } from "../../components/app_context.js";
|
||||
|
||||
export default class MindMapWidget extends TypeWidget {
|
||||
|
||||
async exportSvgEvent({ ntxId }: EventData<"exportSvg">) {
|
||||
if (!this.isNoteContext(ntxId) || this.note?.type !== "mindMap") {
|
||||
return;
|
||||
}
|
||||
|
||||
const svg = await this.renderSvg();
|
||||
utils.downloadSvg(this.note.title, svg);
|
||||
}
|
||||
|
||||
async exportPngEvent({ ntxId }: EventData<"exportPng">) {
|
||||
if (!this.isNoteContext(ntxId) || this.note?.type !== "mindMap") {
|
||||
return;
|
||||
}
|
||||
|
||||
const svg = await this.renderSvg();
|
||||
utils.downloadSvgAsPng(this.note.title, svg);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user