@docusaurus/theme-mermaid 3.9.1 → 3.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client/index.js +2 -3
- package/lib/client/{layouts.d.ts → loadMermaid.d.ts} +2 -1
- package/lib/client/{layouts.js → loadMermaid.js} +11 -7
- package/lib/index.js +11 -0
- package/package.json +7 -7
- package/src/client/index.ts +2 -3
- package/src/client/{layouts.ts → loadMermaid.ts} +15 -7
- package/src/index.ts +12 -0
package/lib/client/index.js
CHANGED
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { useState, useEffect, useMemo } from 'react';
|
|
8
8
|
import { useColorMode, useThemeConfig } from '@docusaurus/theme-common';
|
|
9
|
-
import
|
|
10
|
-
import { ensureLayoutsRegistered } from './layouts';
|
|
9
|
+
import { loadMermaid } from './loadMermaid';
|
|
11
10
|
// Stable className to allow users to easily target with CSS
|
|
12
11
|
export const MermaidContainerClassName = 'docusaurus-mermaid-container';
|
|
13
12
|
export function useMermaidThemeConfig() {
|
|
@@ -31,7 +30,7 @@ function useMermaidId() {
|
|
|
31
30
|
return useState(`mermaid-svg-${Math.round(Math.random() * 10000000)}`)[0];
|
|
32
31
|
}
|
|
33
32
|
async function renderMermaid({ id, text, config, }) {
|
|
34
|
-
await
|
|
33
|
+
const mermaid = await loadMermaid();
|
|
35
34
|
/*
|
|
36
35
|
Mermaid API is really weird :s
|
|
37
36
|
It is a big mutable singleton with multiple config levels
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
+
import type { Mermaid } from 'mermaid';
|
|
7
8
|
declare global {
|
|
8
9
|
const __DOCUSAURUS_MERMAID_LAYOUT_ELK_ENABLED__: boolean;
|
|
9
10
|
}
|
|
10
|
-
export declare function
|
|
11
|
+
export declare function loadMermaid(): Promise<Mermaid>;
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
async function loadMermaidAndRegisterLayouts() {
|
|
8
|
+
const mermaid = (await import('mermaid')).default;
|
|
9
9
|
// Mermaid does not support ELK layouts by default
|
|
10
10
|
// See https://github.com/mermaid-js/mermaid/tree/develop/packages/mermaid-layout-elk
|
|
11
11
|
// ELK layouts are heavy, so we made it an optional peer dependency
|
|
@@ -14,12 +14,16 @@ async function registerOptionalElkLayout() {
|
|
|
14
14
|
const elkLayout = (await import('@mermaid-js/layout-elk')).default;
|
|
15
15
|
mermaid.registerLayoutLoaders(elkLayout);
|
|
16
16
|
}
|
|
17
|
+
return mermaid;
|
|
17
18
|
}
|
|
18
19
|
// Ensure we only try to register layouts once
|
|
19
|
-
let
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
let MermaidPromise = null;
|
|
21
|
+
// We load Mermaid with a dynamic import to code split / lazy load the library
|
|
22
|
+
// It is only called inside a useEffect, so loading can be deferred
|
|
23
|
+
// We memoize so that we don't load and register layouts multiple times
|
|
24
|
+
export async function loadMermaid() {
|
|
25
|
+
if (!MermaidPromise) {
|
|
26
|
+
MermaidPromise = loadMermaidAndRegisterLayouts();
|
|
24
27
|
}
|
|
28
|
+
return MermaidPromise;
|
|
25
29
|
}
|
package/lib/index.js
CHANGED
|
@@ -46,6 +46,17 @@ async function themeMermaid() {
|
|
|
46
46
|
!isServer && elkLayoutEnabled),
|
|
47
47
|
}),
|
|
48
48
|
],
|
|
49
|
+
// Workaround for weird Rspack/SWC issue
|
|
50
|
+
// See https://github.com/facebook/docusaurus/issues/11430
|
|
51
|
+
resolve: {
|
|
52
|
+
alias: {
|
|
53
|
+
...(elkLayoutEnabled
|
|
54
|
+
? {}
|
|
55
|
+
: {
|
|
56
|
+
'@mermaid-js/layout-elk': false,
|
|
57
|
+
}),
|
|
58
|
+
},
|
|
59
|
+
},
|
|
49
60
|
};
|
|
50
61
|
},
|
|
51
62
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-mermaid",
|
|
3
|
-
"version": "3.9.
|
|
3
|
+
"version": "3.9.2",
|
|
4
4
|
"description": "Mermaid components for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/theme-mermaid.d.ts",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@docusaurus/core": "3.9.
|
|
37
|
-
"@docusaurus/module-type-aliases": "3.9.
|
|
38
|
-
"@docusaurus/theme-common": "3.9.
|
|
39
|
-
"@docusaurus/types": "3.9.
|
|
40
|
-
"@docusaurus/utils-validation": "3.9.
|
|
36
|
+
"@docusaurus/core": "3.9.2",
|
|
37
|
+
"@docusaurus/module-type-aliases": "3.9.2",
|
|
38
|
+
"@docusaurus/theme-common": "3.9.2",
|
|
39
|
+
"@docusaurus/types": "3.9.2",
|
|
40
|
+
"@docusaurus/utils-validation": "3.9.2",
|
|
41
41
|
"mermaid": ">=11.6.0",
|
|
42
42
|
"tslib": "^2.6.0"
|
|
43
43
|
},
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"engines": {
|
|
58
58
|
"node": ">=20.0"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "abfbe5621b08407bc3dcbe6111ff118d4c22f7a1"
|
|
61
61
|
}
|
package/src/client/index.ts
CHANGED
|
@@ -7,8 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import {useState, useEffect, useMemo} from 'react';
|
|
9
9
|
import {useColorMode, useThemeConfig} from '@docusaurus/theme-common';
|
|
10
|
-
import
|
|
11
|
-
import {ensureLayoutsRegistered} from './layouts';
|
|
10
|
+
import {loadMermaid} from './loadMermaid';
|
|
12
11
|
|
|
13
12
|
import type {RenderResult, MermaidConfig} from 'mermaid';
|
|
14
13
|
import type {ThemeConfig} from '@docusaurus/theme-mermaid';
|
|
@@ -55,7 +54,7 @@ async function renderMermaid({
|
|
|
55
54
|
text: string;
|
|
56
55
|
config: MermaidConfig;
|
|
57
56
|
}): Promise<RenderResult> {
|
|
58
|
-
await
|
|
57
|
+
const mermaid = await loadMermaid();
|
|
59
58
|
|
|
60
59
|
/*
|
|
61
60
|
Mermaid API is really weird :s
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import type {Mermaid} from 'mermaid';
|
|
9
9
|
|
|
10
10
|
declare global {
|
|
11
11
|
// Global variable provided by bundler DefinePlugin
|
|
@@ -13,7 +13,9 @@ declare global {
|
|
|
13
13
|
const __DOCUSAURUS_MERMAID_LAYOUT_ELK_ENABLED__: boolean;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
async function
|
|
16
|
+
async function loadMermaidAndRegisterLayouts(): Promise<Mermaid> {
|
|
17
|
+
const mermaid = (await import('mermaid')).default;
|
|
18
|
+
|
|
17
19
|
// Mermaid does not support ELK layouts by default
|
|
18
20
|
// See https://github.com/mermaid-js/mermaid/tree/develop/packages/mermaid-layout-elk
|
|
19
21
|
// ELK layouts are heavy, so we made it an optional peer dependency
|
|
@@ -22,13 +24,19 @@ async function registerOptionalElkLayout() {
|
|
|
22
24
|
const elkLayout = (await import('@mermaid-js/layout-elk')).default;
|
|
23
25
|
mermaid.registerLayoutLoaders(elkLayout);
|
|
24
26
|
}
|
|
27
|
+
|
|
28
|
+
return mermaid;
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
// Ensure we only try to register layouts once
|
|
28
|
-
let
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
let MermaidPromise: Promise<Mermaid> | null = null;
|
|
33
|
+
|
|
34
|
+
// We load Mermaid with a dynamic import to code split / lazy load the library
|
|
35
|
+
// It is only called inside a useEffect, so loading can be deferred
|
|
36
|
+
// We memoize so that we don't load and register layouts multiple times
|
|
37
|
+
export async function loadMermaid(): Promise<Mermaid> {
|
|
38
|
+
if (!MermaidPromise) {
|
|
39
|
+
MermaidPromise = loadMermaidAndRegisterLayouts();
|
|
33
40
|
}
|
|
41
|
+
return MermaidPromise;
|
|
34
42
|
}
|
package/src/index.ts
CHANGED
|
@@ -49,6 +49,18 @@ export default async function themeMermaid(): Promise<Plugin<void>> {
|
|
|
49
49
|
),
|
|
50
50
|
}),
|
|
51
51
|
],
|
|
52
|
+
|
|
53
|
+
// Workaround for weird Rspack/SWC issue
|
|
54
|
+
// See https://github.com/facebook/docusaurus/issues/11430
|
|
55
|
+
resolve: {
|
|
56
|
+
alias: {
|
|
57
|
+
...(elkLayoutEnabled
|
|
58
|
+
? {}
|
|
59
|
+
: {
|
|
60
|
+
'@mermaid-js/layout-elk': false,
|
|
61
|
+
}),
|
|
62
|
+
},
|
|
63
|
+
},
|
|
52
64
|
};
|
|
53
65
|
},
|
|
54
66
|
};
|