-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use current mermaid version in docs. #3846
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
beab227
feat: Async mermaid docs
sidharthv96 a88a467
sync
sidharthv96 ab81b50
Merge branch 'develop' into sidv/mermaidDocs
sidharthv96 01a2429
Docs
sidharthv96 6faf54c
fix lock
sidharthv96 f8b05f7
chore: Cleanup package.json
sidharthv96 cc1c983
chore: Cleanup package.json
sidharthv96 7201c01
chore: Cleanup package.json
sidharthv96 f425a02
Merge branch 'develop' into sidv/mermaidDocs
sidharthv96 527a3df
Revert "sync"
sidharthv96 e302ee3
fix Async rendering
sidharthv96 1f147b6
Merge branch 'develop' into sidv/mermaidDocs
sidharthv96 bfbb799
fix lines
sidharthv96 3a6dd61
cleanup
sidharthv96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<template> | ||
<div v-html="svg"></div> | ||
</template> | ||
|
||
<script setup> | ||
import { onMounted, onUnmounted, ref } from 'vue'; | ||
import { render } from './mermaid'; | ||
|
||
const props = defineProps({ | ||
graph: { | ||
type: String, | ||
required: true, | ||
}, | ||
id: { | ||
type: String, | ||
required: true, | ||
}, | ||
}); | ||
|
||
const svg = ref(null); | ||
let mut = null; | ||
|
||
const mermaidConfig = { | ||
securityLevel: 'loose', | ||
startOnLoad: false, | ||
}; | ||
|
||
onMounted(async () => { | ||
mut = new MutationObserver(() => renderChart()); | ||
mut.observe(document.documentElement, { attributes: true }); | ||
await renderChart(); | ||
|
||
//refresh images on first render | ||
const hasImages = /<img([\w\W]+?)>/.exec(decodeURIComponent(props.graph))?.length > 0; | ||
if (hasImages) | ||
setTimeout(() => { | ||
let imgElements = document.getElementsByTagName('img'); | ||
let imgs = Array.from(imgElements); | ||
if (imgs.length) { | ||
Promise.all( | ||
imgs | ||
.filter((img) => !img.complete) | ||
.map( | ||
(img) => | ||
new Promise((resolve) => { | ||
img.onload = img.onerror = resolve; | ||
}) | ||
) | ||
).then(() => { | ||
renderChart(); | ||
}); | ||
} | ||
}, 100); | ||
}); | ||
|
||
onUnmounted(() => mut.disconnect()); | ||
|
||
const renderChart = async () => { | ||
console.log('rendering chart' + props.id + props.graph); | ||
const hasDarkClass = document.documentElement.classList.contains('dark'); | ||
mermaidConfig.theme = hasDarkClass ? 'dark' : 'default'; | ||
|
||
console.log({ mermaidConfig }); | ||
svg.value = await render(props.id, decodeURIComponent(props.graph), mermaidConfig); | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import mermaid, { type MermaidConfig } from 'mermaid'; | ||
import mindmap from '@mermaid-js/mermaid-mindmap'; | ||
|
||
try { | ||
await mermaid.registerExternalDiagrams([mindmap]); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
|
||
export const render = async (id: string, code: string, config: MermaidConfig): Promise<string> => { | ||
mermaid.initialize(config); | ||
const svg = await mermaid.renderAsync(id, code); | ||
return svg; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah 😄 Could not agree more