diff --git a/src/lib/components/actions.svelte b/src/lib/components/actions.svelte index bb418a58..d33010b7 100644 --- a/src/lib/components/actions.svelte +++ b/src/lib/components/actions.svelte @@ -2,8 +2,7 @@ import { browser } from '$app/env'; import Card from '$lib/components/card/card.svelte'; - import type { State } from '$lib/types'; - import { codeStore } from '$lib/util/state'; + import { base64State, codeStore } from '$lib/util/state'; import { toBase64 } from 'js-base64'; import moment from 'moment'; @@ -137,15 +136,15 @@ if (browser && ['mermaid.live', 'netlify'].some((path) => window.location.host.includes(path))) { isNetlify = true; } - codeStore.subscribe((state: State) => { - const stateCopy = JSON.parse(JSON.stringify(state)); + base64State.subscribe((encodedState: string) => { + const stateCopy = JSON.parse(JSON.stringify($codeStore)); if (typeof stateCopy.mermaid === 'string') { stateCopy.mermaid = JSON.parse(stateCopy.mermaid); } const b64Code = toBase64(JSON.stringify(stateCopy), true); iUrl = `https://mermaid.ink/img/${b64Code}`; svgUrl = `https://mermaid.ink/svg/${b64Code}`; - mdCode = `[![](${iUrl})](${window.location.protocol}//${window.location.host}${window.location.pathname}#${window.location.hash})`; + mdCode = `[![](${iUrl})](${window.location.protocol}//${window.location.host}${window.location.pathname}#${encodedState})`; }); diff --git a/src/lib/util/state.ts b/src/lib/util/state.ts index ee372ed2..5688493f 100644 --- a/src/lib/util/state.ts +++ b/src/lib/util/state.ts @@ -1,4 +1,5 @@ import { writable, get, derived } from 'svelte/store'; +import type { Readable } from 'svelte/store'; import { toBase64, fromBase64 } from 'js-base64'; import { persist, localStorage } from '@macfja/svelte-persistent-store'; import type { State } from '$lib/types'; @@ -25,7 +26,7 @@ export const defaultState: State = { }; export const codeStore = persist(writable(defaultState), localStorage(), 'codeStore'); -export const base64State = derived([codeStore], ([code], set) => { +export const base64State: Readable = derived([codeStore], ([code], set) => { set(toBase64(JSON.stringify(code), true)); });