Fix mermaid

This commit is contained in:
Sidharth Vinod
2021-05-15 23:36:50 +05:30
parent 43ffa36a8b
commit 19e00e65b0
3 changed files with 22 additions and 8 deletions
+11 -3
View File
@@ -1,7 +1,7 @@
<script lang="ts">
import Tabs from '$lib/Tabs/index.svelte';
import Card from '$lib/Card/index.svelte';
import { codeStore } from '$lib/Util/state';
import { codeStore, getStateString } from '$lib/Util/state';
import { historyStore } from '$lib/Util/history';
let historyMode: string = 'saved';
@@ -20,9 +20,16 @@
}
];
let previousState = getStateString();
setInterval(() => {
saveHistory(true);
const currentState = getStateString();
if (previousState !== currentState) {
saveHistory(true);
previousState = currentState;
}
}, 1000);
let history: HistoryEntry[] = [];
$: history = $historyStore.filter((h) => (historyMode === 'saved' ? !h.auto : h.auto));
const saveHistory = (auto = false) => {
@@ -47,7 +54,8 @@
<div class="flex"><Tabs on:select={tabSelectHandler} {tabs} /></div>
<div class="flex-grow" />
<div class="flex gap-x-4 text-white">
<button class="bg-blue-500 hover:bg-blue-700 rounded px-1" on:click={saveHistory}>Save</button
<button class="bg-blue-500 hover:bg-blue-700 rounded px-1" on:click={() => saveHistory()}
>Save</button
>
</div>
</div>
+7 -2
View File
@@ -1,4 +1,4 @@
import { writable } from 'svelte/store';
import { writable, get } from 'svelte/store';
import { encode, decode } from 'js-base64';
const defaultState: State = {
@@ -13,7 +13,8 @@ const defaultState: State = {
theme: 'default'
}),
updateEditor: false,
autoSync: true
autoSync: true,
updateDiagram: true
};
export const codeStore = writable(defaultState);
@@ -53,3 +54,7 @@ export const initURLSubscription = (): void => {
window.location.hash = encode(JSON.stringify(state), true);
});
};
export const getStateString = (): string => {
return JSON.stringify(get(codeStore));
};
+4 -3
View File
@@ -1,15 +1,16 @@
<script lang="ts">
import { errorStore } from '$lib/Util/error';
import { getMermaid } from '$lib/Util/mermaid';
import { codeStore } from '$lib/Util/state';
import { onMount } from 'svelte';
import type { Mermaid } from 'mermaid';
const mermaid: Mermaid = (window.mermaid as unknown) as Mermaid;
let container;
export let code = '';
export let errorClass = '';
onMount(async () => {
const mermaid = await getMermaid();
codeStore.subscribe((state) => {
try {
if (container && state && (state.updateDiagram || state.autoSync)) {
@@ -22,7 +23,7 @@
container.innerHTML = code;
delete container.dataset.processed;
mermaid.initialize(Object.assign({}, JSON.parse(state.mermaid)));
mermaid.init(undefined, container);
mermaid.init(container);
mermaid.render('graph-div', code, insertSvg);
}
} catch (e) {