@docusaurus/theme-mermaid 3.9.1-canary-6409 → 3.9.1
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 +3 -2
- package/lib/client/{loadMermaid.d.ts → layouts.d.ts} +1 -2
- package/lib/client/{loadMermaid.js → layouts.js} +7 -11
- package/lib/index.js +0 -11
- package/package.json +7 -7
- package/src/client/index.ts +3 -2
- package/src/client/{loadMermaid.ts → layouts.ts} +7 -15
- package/src/index.ts +0 -12
package/lib/client/index.js
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { useState, useEffect, useMemo } from 'react';
|
|
8
8
|
import { useColorMode, useThemeConfig } from '@docusaurus/theme-common';
|
|
9
|
-
import
|
|
9
|
+
import mermaid from 'mermaid';
|
|
10
|
+
import { ensureLayoutsRegistered } from './layouts';
|
|
10
11
|
// Stable className to allow users to easily target with CSS
|
|
11
12
|
export const MermaidContainerClassName = 'docusaurus-mermaid-container';
|
|
12
13
|
export function useMermaidThemeConfig() {
|
|
@@ -30,7 +31,7 @@ function useMermaidId() {
|
|
|
30
31
|
return useState(`mermaid-svg-${Math.round(Math.random() * 10000000)}`)[0];
|
|
31
32
|
}
|
|
32
33
|
async function renderMermaid({ id, text, config, }) {
|
|
33
|
-
|
|
34
|
+
await ensureLayoutsRegistered();
|
|
34
35
|
/*
|
|
35
36
|
Mermaid API is really weird :s
|
|
36
37
|
It is a big mutable singleton with multiple config levels
|
|
@@ -4,8 +4,7 @@
|
|
|
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';
|
|
8
7
|
declare global {
|
|
9
8
|
const __DOCUSAURUS_MERMAID_LAYOUT_ELK_ENABLED__: boolean;
|
|
10
9
|
}
|
|
11
|
-
export declare function
|
|
10
|
+
export declare function ensureLayoutsRegistered(): Promise<void>;
|
|
@@ -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
|
+
import mermaid from 'mermaid';
|
|
8
|
+
async function registerOptionalElkLayout() {
|
|
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,16 +14,12 @@ async function loadMermaidAndRegisterLayouts() {
|
|
|
14
14
|
const elkLayout = (await import('@mermaid-js/layout-elk')).default;
|
|
15
15
|
mermaid.registerLayoutLoaders(elkLayout);
|
|
16
16
|
}
|
|
17
|
-
return mermaid;
|
|
18
17
|
}
|
|
19
18
|
// Ensure we only try to register layouts once
|
|
20
|
-
let
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (!MermaidPromise) {
|
|
26
|
-
MermaidPromise = loadMermaidAndRegisterLayouts();
|
|
19
|
+
let layoutsRegistered = false;
|
|
20
|
+
export async function ensureLayoutsRegistered() {
|
|
21
|
+
if (!layoutsRegistered) {
|
|
22
|
+
await registerOptionalElkLayout();
|
|
23
|
+
layoutsRegistered = true;
|
|
27
24
|
}
|
|
28
|
-
return MermaidPromise;
|
|
29
25
|
}
|
package/lib/index.js
CHANGED
|
@@ -46,17 +46,6 @@ 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
|
-
},
|
|
60
49
|
};
|
|
61
50
|
},
|
|
62
51
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-mermaid",
|
|
3
|
-
"version": "3.9.1
|
|
3
|
+
"version": "3.9.1",
|
|
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.1
|
|
37
|
-
"@docusaurus/module-type-aliases": "3.9.1
|
|
38
|
-
"@docusaurus/theme-common": "3.9.1
|
|
39
|
-
"@docusaurus/types": "3.9.1
|
|
40
|
-
"@docusaurus/utils-validation": "3.9.1
|
|
36
|
+
"@docusaurus/core": "3.9.1",
|
|
37
|
+
"@docusaurus/module-type-aliases": "3.9.1",
|
|
38
|
+
"@docusaurus/theme-common": "3.9.1",
|
|
39
|
+
"@docusaurus/types": "3.9.1",
|
|
40
|
+
"@docusaurus/utils-validation": "3.9.1",
|
|
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": "c0dd59f0e712f85b6053c59e46b0514b5d2d1414"
|
|
61
61
|
}
|
package/src/client/index.ts
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
import {useState, useEffect, useMemo} from 'react';
|
|
9
9
|
import {useColorMode, useThemeConfig} from '@docusaurus/theme-common';
|
|
10
|
-
import
|
|
10
|
+
import mermaid from 'mermaid';
|
|
11
|
+
import {ensureLayoutsRegistered} from './layouts';
|
|
11
12
|
|
|
12
13
|
import type {RenderResult, MermaidConfig} from 'mermaid';
|
|
13
14
|
import type {ThemeConfig} from '@docusaurus/theme-mermaid';
|
|
@@ -54,7 +55,7 @@ async function renderMermaid({
|
|
|
54
55
|
text: string;
|
|
55
56
|
config: MermaidConfig;
|
|
56
57
|
}): Promise<RenderResult> {
|
|
57
|
-
|
|
58
|
+
await ensureLayoutsRegistered();
|
|
58
59
|
|
|
59
60
|
/*
|
|
60
61
|
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 mermaid from 'mermaid';
|
|
9
9
|
|
|
10
10
|
declare global {
|
|
11
11
|
// Global variable provided by bundler DefinePlugin
|
|
@@ -13,9 +13,7 @@ declare global {
|
|
|
13
13
|
const __DOCUSAURUS_MERMAID_LAYOUT_ELK_ENABLED__: boolean;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
async function
|
|
17
|
-
const mermaid = (await import('mermaid')).default;
|
|
18
|
-
|
|
16
|
+
async function registerOptionalElkLayout() {
|
|
19
17
|
// Mermaid does not support ELK layouts by default
|
|
20
18
|
// See https://github.com/mermaid-js/mermaid/tree/develop/packages/mermaid-layout-elk
|
|
21
19
|
// ELK layouts are heavy, so we made it an optional peer dependency
|
|
@@ -24,19 +22,13 @@ async function loadMermaidAndRegisterLayouts(): Promise<Mermaid> {
|
|
|
24
22
|
const elkLayout = (await import('@mermaid-js/layout-elk')).default;
|
|
25
23
|
mermaid.registerLayoutLoaders(elkLayout);
|
|
26
24
|
}
|
|
27
|
-
|
|
28
|
-
return mermaid;
|
|
29
25
|
}
|
|
30
26
|
|
|
31
27
|
// Ensure we only try to register layouts once
|
|
32
|
-
let
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export async function loadMermaid(): Promise<Mermaid> {
|
|
38
|
-
if (!MermaidPromise) {
|
|
39
|
-
MermaidPromise = loadMermaidAndRegisterLayouts();
|
|
28
|
+
let layoutsRegistered = false;
|
|
29
|
+
export async function ensureLayoutsRegistered(): Promise<void> {
|
|
30
|
+
if (!layoutsRegistered) {
|
|
31
|
+
await registerOptionalElkLayout();
|
|
32
|
+
layoutsRegistered = true;
|
|
40
33
|
}
|
|
41
|
-
return MermaidPromise;
|
|
42
34
|
}
|
package/src/index.ts
CHANGED
|
@@ -49,18 +49,6 @@ 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
|
-
},
|
|
64
52
|
};
|
|
65
53
|
},
|
|
66
54
|
};
|