mirror of
https://github.com/zadam/trilium.git
synced 2025-12-17 21:59:55 +01:00
feat(layout/note_actions): export as image
This commit is contained in:
@@ -696,6 +696,9 @@
|
|||||||
"convert_into_attachment_successful": "Note '{{title}}' has been converted to attachment.",
|
"convert_into_attachment_successful": "Note '{{title}}' has been converted to attachment.",
|
||||||
"convert_into_attachment_prompt": "Are you sure you want to convert note '{{title}}' into an attachment of the parent note?",
|
"convert_into_attachment_prompt": "Are you sure you want to convert note '{{title}}' into an attachment of the parent note?",
|
||||||
"print_pdf": "Export as PDF...",
|
"print_pdf": "Export as PDF...",
|
||||||
|
"export_as_image": "Export as image",
|
||||||
|
"export_as_image_png": "PNG (raster)",
|
||||||
|
"export_as_image_svg": "SVG (vector)",
|
||||||
"note_map": "Note map"
|
"note_map": "Note map"
|
||||||
},
|
},
|
||||||
"onclick_button": {
|
"onclick_button": {
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ function CopyImageReferenceButton({ note, isDefaultViewMode }: FloatingButtonCon
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ExportImageButtons({ note, triggerEvent, isDefaultViewMode }: FloatingButtonContext) {
|
function ExportImageButtons({ note, triggerEvent, isDefaultViewMode }: FloatingButtonContext) {
|
||||||
const isEnabled = ["mermaid", "mindMap"].includes(note?.type ?? "")
|
const isEnabled = !isNewLayout && ["mermaid", "mindMap"].includes(note?.type ?? "")
|
||||||
&& note?.isContentAvailable() && isDefaultViewMode;
|
&& note?.isContentAvailable() && isDefaultViewMode;
|
||||||
return isEnabled && (
|
return isEnabled && (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { ConvertToAttachmentResponse } from "@triliumnext/commons";
|
|||||||
import { useContext } from "preact/hooks";
|
import { useContext } from "preact/hooks";
|
||||||
|
|
||||||
import appContext, { CommandNames } from "../../components/app_context";
|
import appContext, { CommandNames } from "../../components/app_context";
|
||||||
|
import Component from "../../components/component";
|
||||||
import NoteContext from "../../components/note_context";
|
import NoteContext from "../../components/note_context";
|
||||||
import FNote from "../../entities/fnote";
|
import FNote from "../../entities/fnote";
|
||||||
import branches from "../../services/branches";
|
import branches from "../../services/branches";
|
||||||
@@ -66,6 +67,8 @@ function NoteContextMenu({ note, noteContext }: { note: FNote, noteContext?: Not
|
|||||||
const isSearchable = ["text", "code", "book", "mindMap", "doc"].includes(noteType);
|
const isSearchable = ["text", "code", "book", "mindMap", "doc"].includes(noteType);
|
||||||
const isInOptionsOrHelp = note?.noteId.startsWith("_options") || note?.noteId.startsWith("_help");
|
const isInOptionsOrHelp = note?.noteId.startsWith("_options") || note?.noteId.startsWith("_help");
|
||||||
const isPrintable = ["text", "code"].includes(noteType) || (noteType === "book" && ["presentation", "list", "table"].includes(viewType ?? ""));
|
const isPrintable = ["text", "code"].includes(noteType) || (noteType === "book" && ["presentation", "list", "table"].includes(viewType ?? ""));
|
||||||
|
const isExportableToImage = ["mermaid", "mindMap"].includes(noteType);
|
||||||
|
const isContentAvailable = note.isContentAvailable();
|
||||||
const isElectron = getIsElectron();
|
const isElectron = getIsElectron();
|
||||||
const isMac = getIsMac();
|
const isMac = getIsMac();
|
||||||
const hasSource = ["text", "code", "relationMap", "mermaid", "canvas", "mindMap", "aiChat"].includes(noteType);
|
const hasSource = ["text", "code", "relationMap", "mermaid", "canvas", "mindMap", "aiChat"].includes(noteType);
|
||||||
@@ -110,6 +113,7 @@ function NoteContextMenu({ note, noteContext }: { note: FNote, noteContext?: Not
|
|||||||
defaultType: "single"
|
defaultType: "single"
|
||||||
})} />
|
})} />
|
||||||
{isElectron && <CommandItem command="exportAsPdf" icon="bx bxs-file-pdf" disabled={!isPrintable} text={t("note_actions.print_pdf")} />}
|
{isElectron && <CommandItem command="exportAsPdf" icon="bx bxs-file-pdf" disabled={!isPrintable} text={t("note_actions.print_pdf")} />}
|
||||||
|
{isExportableToImage && isNormalViewMode && isContentAvailable && <ExportAsImage ntxId={noteContext.ntxId} parentComponent={parentComponent} />}
|
||||||
<CommandItem command="printActiveNote" icon="bx bx-printer" disabled={!isPrintable} text={t("note_actions.print_note")} />
|
<CommandItem command="printActiveNote" icon="bx bx-printer" disabled={!isPrintable} text={t("note_actions.print_note")} />
|
||||||
|
|
||||||
<FormDropdownDivider />
|
<FormDropdownDivider />
|
||||||
@@ -280,3 +284,23 @@ function ConvertToAttachment({ note }: { note: FNote }) {
|
|||||||
>{t("note_actions.convert_into_attachment")}</FormListItem>
|
>{t("note_actions.convert_into_attachment")}</FormListItem>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ExportAsImage({ ntxId, parentComponent }: { ntxId: string | null | undefined, parentComponent: Component | null | undefined }) {
|
||||||
|
return (
|
||||||
|
<FormDropdownSubmenu
|
||||||
|
icon="bx bxs-file-image"
|
||||||
|
title={t("note_actions.export_as_image")}
|
||||||
|
dropStart
|
||||||
|
>
|
||||||
|
<FormListItem
|
||||||
|
icon="bx bxs-file-png"
|
||||||
|
onClick={() => parentComponent?.triggerEvent("exportPng", { ntxId })}
|
||||||
|
>{t("note_actions.export_as_image_png")}</FormListItem>
|
||||||
|
|
||||||
|
<FormListItem
|
||||||
|
icon="bx bx-shape-polygon"
|
||||||
|
onClick={() => parentComponent?.triggerEvent("exportSvg", { ntxId })}
|
||||||
|
>{t("note_actions.export_as_image_svg")}</FormListItem>
|
||||||
|
</FormDropdownSubmenu>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user