-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix(mind-map): show text in links between nodes on export #7938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
5c95037
ce1fd64
4b8c888
2666c1e
2d3aa3a
f976dd8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import { useEditorSpacedUpdate, useNoteLabelBoolean, useSyncedRef, useTriliumEve | |
| import { refToJQuerySelector } from "../react/react_utils"; | ||
| import utils from "../../services/utils"; | ||
| import { DISPLAYABLE_LOCALE_IDS } from "@triliumnext/commons"; | ||
| import { snapdom, SnapdomOptions } from "@zumer/snapdom"; | ||
|
|
||
| const NEW_TOPIC_NAME = ""; | ||
|
|
||
|
|
@@ -45,19 +46,32 @@ export default function MindMap({ note, ntxId, noteContext }: TypeWidgetProps) { | |
| const apiRef = useRef<MindElixirInstance>(null); | ||
| const containerRef = useRef<HTMLDivElement>(null); | ||
| const [ isReadOnly ] = useNoteLabelBoolean(note, "readOnly"); | ||
|
|
||
|
|
||
| const spacedUpdate = useEditorSpacedUpdate({ | ||
| note, | ||
| noteContext, | ||
| getData: async () => { | ||
| if (!apiRef.current) return; | ||
|
|
||
| const result = await snapdom(apiRef.current.nodes, { | ||
| backgroundColor: "transparent", | ||
| scale: 2 | ||
| }); | ||
|
Comment on lines
+57
to
+60
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is needed at this point, if we use it in more places then I would say lets put it into its own object. |
||
|
|
||
| // a data URL in the format: "data:image/svg+xml;charset=utf-8,<url-encoded-svg>" | ||
| // We need to extract the content after the comma and decode the URL encoding (%3C to <, %20 to space, etc.) | ||
| // to get raw SVG content that Trilium's backend can store as an attachment | ||
| const svgContent = decodeURIComponent(result.url.split(',')[1]); | ||
|
|
||
| return { | ||
| content: apiRef.current.getDataString(), | ||
| attachments: [ | ||
| { | ||
| role: "image", | ||
| title: "mindmap-export.svg", | ||
| mime: "image/svg+xml", | ||
| content: await apiRef.current.exportSvg().text(), | ||
| content: svgContent, | ||
| position: 0 | ||
| } | ||
| ] | ||
|
|
@@ -88,13 +102,13 @@ export default function MindMap({ note, ntxId, noteContext }: TypeWidgetProps) { | |
| // 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(); | ||
| const nodes = apiRef.current.nodes; | ||
lzinga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (eventName === "exportSvg") { | ||
| utils.downloadSvg(title, svg); | ||
| await utils.downloadAsSvg(note.title, nodes); | ||
| } else { | ||
| utils.downloadSvgAsPng(title, svg); | ||
| await utils.downloadAsPng(note.title, nodes); | ||
| } | ||
|
|
||
| }); | ||
|
|
||
| const onKeyDown = useCallback((e: KeyboardEvent) => { | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The options for
snapdomare duplicated indownloadAsPngon line 725. To improve maintainability and ensure consistency, consider extracting these options into a shared constant defined above both functions. For example:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is needed at this point, if we use it in more places then I would say lets put it into its own object.