mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-20 12:44:18 +01:00
fix Async rendering
This commit is contained in:
@@ -36,7 +36,7 @@ Pushes in a directive to the configuration
|
||||
|
||||
#### Defined in
|
||||
|
||||
[config.ts:193](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L193)
|
||||
[config.ts:194](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L194)
|
||||
|
||||
---
|
||||
|
||||
@@ -60,7 +60,7 @@ The currentConfig
|
||||
|
||||
#### Defined in
|
||||
|
||||
[config.ts:138](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L138)
|
||||
[config.ts:139](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L139)
|
||||
|
||||
---
|
||||
|
||||
@@ -84,7 +84,7 @@ The siteConfig
|
||||
|
||||
#### Defined in
|
||||
|
||||
[config.ts:97](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L97)
|
||||
[config.ts:98](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L98)
|
||||
|
||||
---
|
||||
|
||||
@@ -118,7 +118,7 @@ The siteConfig
|
||||
|
||||
#### Defined in
|
||||
|
||||
[config.ts:225](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L225)
|
||||
[config.ts:226](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L226)
|
||||
|
||||
---
|
||||
|
||||
@@ -147,7 +147,7 @@ options in-place
|
||||
|
||||
#### Defined in
|
||||
|
||||
[config.ts:153](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L153)
|
||||
[config.ts:154](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L154)
|
||||
|
||||
---
|
||||
|
||||
@@ -167,7 +167,7 @@ options in-place
|
||||
|
||||
#### Defined in
|
||||
|
||||
[config.ts:76](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L76)
|
||||
[config.ts:77](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L77)
|
||||
|
||||
---
|
||||
|
||||
@@ -199,7 +199,7 @@ The currentConfig merged with the sanitized conf
|
||||
|
||||
#### Defined in
|
||||
|
||||
[config.ts:114](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L114)
|
||||
[config.ts:115](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L115)
|
||||
|
||||
---
|
||||
|
||||
@@ -273,4 +273,4 @@ The new siteConfig
|
||||
|
||||
#### Defined in
|
||||
|
||||
[config.ts:80](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L80)
|
||||
[config.ts:81](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L81)
|
||||
|
||||
@@ -267,16 +267,16 @@ A relationship is a general term covering the specific types of logical connecti
|
||||
|
||||
There are eight different types of relations defined for classes under UML which are currently supported:
|
||||
|
||||
| Type | Description |
|
||||
| ---- | ------------- | ----------- |
|
||||
| < | -- | Inheritance |
|
||||
| \*-- | Composition |
|
||||
| o-- | Aggregation |
|
||||
| --> | Association |
|
||||
| -- | Link (Solid) |
|
||||
| ..> | Dependency |
|
||||
| .. | > | Realization |
|
||||
| .. | Link (Dashed) |
|
||||
| Type | Description |
|
||||
| ------- | ------------- |
|
||||
| `<\|--` | Inheritance |
|
||||
| `\*--` | Composition |
|
||||
| `o--` | Aggregation |
|
||||
| `-->` | Association |
|
||||
| `--` | Link (Solid) |
|
||||
| `..>` | Dependency |
|
||||
| `..\|>` | Realization |
|
||||
| `..` | Link (Dashed) |
|
||||
|
||||
```mermaid-example
|
||||
classDiagram
|
||||
@@ -372,14 +372,14 @@ Here is the syntax:
|
||||
|
||||
Where `Relation Type` can be one of:
|
||||
|
||||
| Type | Description |
|
||||
| ---- | ----------- | ----------- |
|
||||
| < | | Inheritance |
|
||||
| \* | Composition |
|
||||
| o | Aggregation |
|
||||
| > | Association |
|
||||
| < | Association |
|
||||
| | > | Realization |
|
||||
| Type | Description |
|
||||
| ----- | ----------- |
|
||||
| `<\|` | Inheritance |
|
||||
| `\*` | Composition |
|
||||
| `o` | Aggregation |
|
||||
| `>` | Association |
|
||||
| `<` | Association |
|
||||
| `\|>` | Realization |
|
||||
|
||||
And `Link` can be one of:
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ const MermaidExample = async (md: MarkdownRenderer) => {
|
||||
</div>`;
|
||||
} else if (token.info.trim() === 'mermaid') {
|
||||
const key = index;
|
||||
return ` ${key}
|
||||
return `
|
||||
<Suspense>
|
||||
<template #default>
|
||||
<Mermaid id="mermaid-${key}" graph="${encodeURIComponent(token.content)}"></Mermaid>
|
||||
|
||||
@@ -3,13 +3,8 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onMounted, onUnmounted, ref, toRaw } from 'vue';
|
||||
import mermaid from 'mermaid';
|
||||
import mindmap from '@mermaid-js/mermaid-mindmap';
|
||||
import { useData } from 'vitepress';
|
||||
try {
|
||||
await mermaid.registerExternalDiagrams([mindmap]);
|
||||
} catch (e) {}
|
||||
import { onMounted, onUnmounted, ref } from 'vue';
|
||||
import { render } from './mermaid';
|
||||
|
||||
const props = defineProps({
|
||||
graph: {
|
||||
@@ -25,10 +20,7 @@ const props = defineProps({
|
||||
const svg = ref(null);
|
||||
let mut = null;
|
||||
|
||||
const { page } = useData();
|
||||
const { frontmatter } = toRaw(page.value);
|
||||
const mermaidPageTheme = frontmatter.mermaidTheme || '';
|
||||
let mermaidConfig = {
|
||||
const mermaidConfig = {
|
||||
securityLevel: 'loose',
|
||||
startOnLoad: false,
|
||||
};
|
||||
@@ -65,14 +57,10 @@ onUnmounted(() => mut.disconnect());
|
||||
|
||||
const renderChart = async () => {
|
||||
console.log('rendering chart' + props.id + props.graph);
|
||||
let hasDarkClass = document.documentElement.classList.contains('dark');
|
||||
mermaidConfig.theme = mermaidPageTheme || mermaidConfig.theme;
|
||||
if (hasDarkClass) mermaidConfig.theme = 'dark';
|
||||
const hasDarkClass = document.documentElement.classList.contains('dark');
|
||||
mermaidConfig.theme = hasDarkClass ? 'dark' : 'default';
|
||||
|
||||
mermaid.initialize({
|
||||
...mermaidConfig,
|
||||
theme: hasDarkClass ? 'dark' : mermaidPageTheme,
|
||||
});
|
||||
svg.value = await mermaid.renderAsync(props.id, decodeURIComponent(props.graph));
|
||||
console.log({ mermaidConfig });
|
||||
svg.value = await render(props.id, decodeURIComponent(props.graph), mermaidConfig);
|
||||
};
|
||||
</script>
|
||||
|
||||
16
packages/mermaid/src/docs/.vitepress/theme/mermaid.ts
Normal file
16
packages/mermaid/src/docs/.vitepress/theme/mermaid.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
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);
|
||||
// console.log('rendering', id, code);
|
||||
const svg = await mermaid.renderAsync(id, code);
|
||||
// console.log('rendered', id, code);
|
||||
return svg;
|
||||
};
|
||||
Reference in New Issue
Block a user