Skip to content

Build your personal knowledge base with Trilium Notes

chore(mermaid): add view changer

Elian Doranb6144f3d09f8
diff --git a/apps/client/src/widgets/FloatingButtonsDefinitions.tsx b/apps/client/src/widgets/FloatingButtonsDefinitions.tsx
index 2c1b63d0c8..4eabe122aa 100644
--- a/apps/client/src/widgets/FloatingButtonsDefinitions.tsx
+++ b/apps/client/src/widgets/FloatingButtonsDefinitions.tsx
@@ -81,9 +81,13 @@ function RefreshBackendLogButton({ note, parentComponent, noteContext, isDefault
}
function SwitchSplitOrientationButton({ note, isReadOnly, isDefaultViewMode }: FloatingButtonContext) {
- const isEnabled = note.type === "mermaid" && note.isContentAvailable() && !isReadOnly && isDefaultViewMode;
+ const [ displayMode ] = useNoteLabel(note, "displayMode");
const [ splitEditorOrientation, setSplitEditorOrientation ] = useTriliumOption("splitEditorOrientation");
const upcomingOrientation = splitEditorOrientation === "horizontal" ? "vertical" : "horizontal";
+ const effectiveMode = displayMode === "source" || displayMode === "split" || displayMode === "preview"
+ ? displayMode
+ : isReadOnly ? "preview" : "split";
+ const isEnabled = note.type === "mermaid" && note.isContentAvailable() && effectiveMode === "split" && isDefaultViewMode;
return isEnabled && <FloatingButton
text={upcomingOrientation === "vertical" ? t("switch_layout_button.title_vertical") : t("switch_layout_button.title_horizontal")}
@@ -95,7 +99,7 @@ function SwitchSplitOrientationButton({ note, isReadOnly, isDefaultViewMode }: F
function ToggleReadOnlyButton({ note, isDefaultViewMode }: FloatingButtonContext) {
const [ isReadOnly, setReadOnly ] = useNoteLabelBoolean(note, "readOnly");
const isSavedSqlite = note.isTriliumSqlite() && !note.isHiddenCompletely();
- const isEnabled = ([ "mermaid", "mindMap", "canvas" ].includes(note.type) || isSavedSqlite)
+ const isEnabled = ([ "mindMap", "canvas" ].includes(note.type) || isSavedSqlite)
&& note.isContentAvailable() && isDefaultViewMode;
return isEnabled && <FloatingButton
@@ -107,7 +111,8 @@ function ToggleReadOnlyButton({ note, isDefaultViewMode }: FloatingButtonContext
function DisplayModeSwitcher({ note, isDefaultViewMode }: FloatingButtonContext) {
const [ displayMode, setDisplayMode ] = useNoteLabel(note, "displayMode");
- if (!note.isMarkdown() || !note.isContentAvailable() || !isDefaultViewMode) return false;
+ const isEnabled = (note.isMarkdown() || note.type === "mermaid") && note.isContentAvailable() && isDefaultViewMode;
+ if (!isEnabled) return false;
const mode = displayMode === "source" || displayMode === "preview" ? displayMode : "split";
const buttons: Array<{ value: "source" | "split" | "preview"; icon: string; text: string }> = [
diff --git a/apps/client/src/widgets/ribbon/NoteActionsCustom.tsx b/apps/client/src/widgets/ribbon/NoteActionsCustom.tsx
index 96c07d0cf9..e072dbb446 100644
--- a/apps/client/src/widgets/ribbon/NoteActionsCustom.tsx
+++ b/apps/client/src/widgets/ribbon/NoteActionsCustom.tsx
@@ -71,9 +71,9 @@ export default function NoteActionsCustom(props: NoteActionsCustomProps) {
>
<AddChildButton {...innerProps} />
<RunActiveNoteButton {...innerProps } />
- <SwitchSplitOrientationButton {...innerProps} />
<ToggleReadOnlyButton {...innerProps} />
<DisplayModeSwitcher {...innerProps} />
+ <SwitchSplitOrientationButton {...innerProps} />
<SaveToNoteButton {...innerProps} />
<RefreshButton {...innerProps} />
<CopyReferenceToClipboardButton {...innerProps} />
@@ -190,21 +190,25 @@ function RefreshButton({ note, noteType, isDefaultViewMode, parentComponent, not
function SwitchSplitOrientationButton({ note, isReadOnly, isDefaultViewMode }: NoteActionsCustomInnerProps) {
const isShown = note.type === "mermaid" && !cachedIsMobile && note.isContentAvailable() && isDefaultViewMode;
+ const [ displayMode ] = useNoteLabel(note, "displayMode");
const [ splitEditorOrientation, setSplitEditorOrientation ] = useTriliumOption("splitEditorOrientation");
const upcomingOrientation = splitEditorOrientation === "horizontal" ? "vertical" : "horizontal";
+ const effectiveMode = displayMode === "source" || displayMode === "split" || displayMode === "preview"
+ ? displayMode
+ : isReadOnly ? "preview" : "split";
return isShown && <NoteAction
text={upcomingOrientation === "vertical" ? t("switch_layout_button.title_vertical") : t("switch_layout_button.title_horizontal")}
icon={upcomingOrientation === "vertical" ? "bx bxs-dock-bottom" : "bx bxs-dock-left"}
onClick={() => setSplitEditorOrientation(upcomingOrientation)}
- disabled={isReadOnly}
+ disabled={effectiveMode !== "split"}
/>;
}
export function ToggleReadOnlyButton({ note, isDefaultViewMode }: NoteActionsCustomInnerProps) {
const [ isReadOnly, setReadOnly ] = useNoteLabelBoolean(note, "readOnly");
const isSavedSqlite = note.isTriliumSqlite() && !note.isHiddenCompletely();
- const isEnabled = ([ "mermaid", "mindMap", "canvas", "spreadsheet" ].includes(note.type) || isSavedSqlite)
+ const isEnabled = ([ "mindMap", "canvas", "spreadsheet" ].includes(note.type) || isSavedSqlite)
&& note.isContentAvailable() && isDefaultViewMode;
return isEnabled && <NoteAction
@@ -216,7 +220,8 @@ export function ToggleReadOnlyButton({ note, isDefaultViewMode }: NoteActionsCus
function DisplayModeSwitcher({ note, isDefaultViewMode }: NoteActionsCustomInnerProps) {
const [ displayMode, setDisplayMode ] = useNoteLabel(note, "displayMode");
- if (!note.isMarkdown() || !note.isContentAvailable() || !isDefaultViewMode) return null;
+ const isEnabled = (note.isMarkdown() || note.type === "mermaid") && note.isContentAvailable() && isDefaultViewMode;
+ if (!isEnabled) return null;
const mode = displayMode === "source" || displayMode === "preview" ? displayMode : "split";
const buttons: Array<{ value: "source" | "split" | "preview"; icon: string; text: string }> = [