mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-06 07:39:48 +02:00
Made mermaidConfig a local variable so that it cannot be shared cross rendering.
This commit is contained in:
@@ -20,11 +20,6 @@ const props = defineProps({
|
|||||||
const svg = ref(null);
|
const svg = ref(null);
|
||||||
let mut = null;
|
let mut = null;
|
||||||
|
|
||||||
const mermaidConfig = {
|
|
||||||
securityLevel: 'loose',
|
|
||||||
startOnLoad: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
mut = new MutationObserver(() => renderChart());
|
mut = new MutationObserver(() => renderChart());
|
||||||
mut.observe(document.documentElement, { attributes: true });
|
mut.observe(document.documentElement, { attributes: true });
|
||||||
@@ -58,7 +53,11 @@ onUnmounted(() => mut.disconnect());
|
|||||||
const renderChart = async () => {
|
const renderChart = async () => {
|
||||||
console.log('rendering chart' + props.id + props.graph);
|
console.log('rendering chart' + props.id + props.graph);
|
||||||
const hasDarkClass = document.documentElement.classList.contains('dark');
|
const hasDarkClass = document.documentElement.classList.contains('dark');
|
||||||
mermaidConfig.theme = hasDarkClass ? 'dark' : 'default';
|
const mermaidConfig = {
|
||||||
|
securityLevel: 'loose',
|
||||||
|
startOnLoad: false,
|
||||||
|
theme: hasDarkClass ? 'dark' : 'default',
|
||||||
|
};
|
||||||
|
|
||||||
console.log({ mermaidConfig });
|
console.log({ mermaidConfig });
|
||||||
let svgCode = await render(props.id, decodeURIComponent(props.graph), mermaidConfig);
|
let svgCode = await render(props.id, decodeURIComponent(props.graph), mermaidConfig);
|
||||||
|
@@ -8,9 +8,7 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const render = async (id: string, code: string, config: MermaidConfig): Promise<string> => {
|
export const render = async (id: string, code: string, config: MermaidConfig): Promise<string> => {
|
||||||
// make a clone of config, so we don't mutate the original
|
mermaid.initialize(config);
|
||||||
const mermaidConfig = { ...config };
|
|
||||||
mermaid.initialize(mermaidConfig);
|
|
||||||
const svg = await mermaid.renderAsync(id, code);
|
const svg = await mermaid.renderAsync(id, code);
|
||||||
return svg;
|
return svg;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user