chore: simplify logic for theme -> diagram theme
Co-authored-by: Sidharth Vinod <github@sidharth.dev>
This commit is contained in:
co-authored by
Sidharth Vinod
parent
c18574c605
commit
59679abec5
@@ -103,11 +103,11 @@ export const updateConfig = (config: string, updateEditor: boolean): void => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const toggleDarkTheme = (dark: boolean, theme: string): void => {
|
export const setDiagramTheme = (theme: 'dark' | 'default' | 'forest'): void => {
|
||||||
codeStore.update((state) => {
|
codeStore.update((state) => {
|
||||||
const config = JSON.parse(state.mermaid);
|
const config = JSON.parse(state.mermaid);
|
||||||
if (!config.theme || ['dark', 'default', 'forest'].includes(config.theme)) {
|
if (!config.theme || ['dark', 'default', 'forest'].includes(config.theme)) {
|
||||||
config.theme = dark ? (theme === 'forest' ? 'forest' : 'dark') : 'default';
|
config.theme = theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
return { ...state, mermaid: JSON.stringify(config, null, 2), updateEditor: true };
|
return { ...state, mermaid: JSON.stringify(config, null, 2), updateEditor: true };
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { loadingStateStore } from '$lib/util/loading';
|
import { loadingStateStore } from '$lib/util/loading';
|
||||||
import { setTheme, themeStore } from '$lib/util/theme';
|
import { setTheme, themeStore } from '$lib/util/theme';
|
||||||
import { toggleDarkTheme } from '$lib/util/state';
|
import { setDiagramTheme } from '$lib/util/state';
|
||||||
|
|
||||||
// This can be removed once https://github.com/sveltejs/kit/issues/1612 is fixed.
|
// This can be removed once https://github.com/sveltejs/kit/issues/1612 is fixed.
|
||||||
// Then move it into src and vite will bundle it automatically.
|
// Then move it into src and vite will bundle it automatically.
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
themeStore.subscribe(({ theme, isDark }) => {
|
themeStore.subscribe(({ theme, isDark }) => {
|
||||||
if (theme) {
|
if (theme) {
|
||||||
document.getElementsByTagName('html')[0].setAttribute('data-theme', theme);
|
document.getElementsByTagName('html')[0].setAttribute('data-theme', theme);
|
||||||
toggleDarkTheme(isDark, theme);
|
setDiagramTheme(isDark ? (theme === 'forest' ? 'forest' : 'dark') : 'default');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user