@docusaurus/theme-mermaid 2.2.0 → 2.3.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.d.ts +3 -3
- package/lib/client/index.js +13 -20
- package/package.json +8 -9
- package/src/client/index.ts +3 -4
- package/src/validateThemeConfig.ts +2 -3
package/lib/client/index.d.ts
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
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
|
|
7
|
+
import { type MermaidConfig } from 'mermaid';
|
|
8
8
|
import type { ThemeConfig } from '@docusaurus/theme-mermaid';
|
|
9
9
|
export declare const MermaidContainerClassName = "docusaurus-mermaid-container";
|
|
10
10
|
export declare function useMermaidThemeConfig(): ThemeConfig['mermaid'];
|
|
11
|
-
export declare function useMermaidConfig():
|
|
12
|
-
export declare function useMermaidSvg(txt: string, mermaidConfigParam?:
|
|
11
|
+
export declare function useMermaidConfig(): MermaidConfig;
|
|
12
|
+
export declare function useMermaidSvg(txt: string, mermaidConfigParam?: MermaidConfig): string;
|
package/lib/client/index.js
CHANGED
|
@@ -1,38 +1,32 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
3
|
*
|
|
5
4
|
* This source code is licensed under the MIT license found in the
|
|
6
5
|
* LICENSE file in the root directory of this source tree.
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const react_1 = require("react");
|
|
12
|
-
const theme_common_1 = require("@docusaurus/theme-common");
|
|
13
|
-
const mermaid_1 = tslib_1.__importDefault(require("mermaid"));
|
|
7
|
+
import { useMemo } from 'react';
|
|
8
|
+
import { useColorMode, useThemeConfig } from '@docusaurus/theme-common';
|
|
9
|
+
import mermaid from 'mermaid';
|
|
14
10
|
// Stable className to allow users to easily target with CSS
|
|
15
|
-
|
|
16
|
-
function useMermaidThemeConfig() {
|
|
17
|
-
return
|
|
11
|
+
export const MermaidContainerClassName = 'docusaurus-mermaid-container';
|
|
12
|
+
export function useMermaidThemeConfig() {
|
|
13
|
+
return useThemeConfig().mermaid;
|
|
18
14
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const { colorMode } = (0, theme_common_1.useColorMode)();
|
|
15
|
+
export function useMermaidConfig() {
|
|
16
|
+
const { colorMode } = useColorMode();
|
|
22
17
|
const mermaidThemeConfig = useMermaidThemeConfig();
|
|
23
18
|
const theme = mermaidThemeConfig.theme[colorMode];
|
|
24
19
|
const { options } = mermaidThemeConfig;
|
|
25
|
-
return
|
|
20
|
+
return useMemo(() => ({ startOnLoad: false, ...options, theme }), [theme, options]);
|
|
26
21
|
}
|
|
27
|
-
|
|
28
|
-
function useMermaidSvg(txt, mermaidConfigParam) {
|
|
22
|
+
export function useMermaidSvg(txt, mermaidConfigParam) {
|
|
29
23
|
/*
|
|
30
24
|
For flexibility, we allow the hook to receive a custom Mermaid config
|
|
31
25
|
The user could inject a modified version of the default config for example
|
|
32
26
|
*/
|
|
33
27
|
const defaultMermaidConfig = useMermaidConfig();
|
|
34
28
|
const mermaidConfig = mermaidConfigParam ?? defaultMermaidConfig;
|
|
35
|
-
return
|
|
29
|
+
return useMemo(() => {
|
|
36
30
|
/*
|
|
37
31
|
Mermaid API is really weird :s
|
|
38
32
|
It is a big mutable singleton with multiple config levels
|
|
@@ -51,7 +45,7 @@ function useMermaidSvg(txt, mermaidConfigParam) {
|
|
|
51
45
|
To use a new mermaid config (on colorMode change for example) we should
|
|
52
46
|
update siteConfig, and it can only be done with initialize()
|
|
53
47
|
*/
|
|
54
|
-
|
|
48
|
+
mermaid.mermaidAPI.initialize(mermaidConfig);
|
|
55
49
|
/*
|
|
56
50
|
Random client-only id, we don't care much about it
|
|
57
51
|
But mermaid want an id so...
|
|
@@ -61,7 +55,6 @@ function useMermaidSvg(txt, mermaidConfigParam) {
|
|
|
61
55
|
Not even documented: mermaid.render returns the svg string
|
|
62
56
|
Using the documented form is un-necessary
|
|
63
57
|
*/
|
|
64
|
-
return
|
|
58
|
+
return mermaid.render(mermaidId, txt);
|
|
65
59
|
}, [txt, mermaidConfig]);
|
|
66
60
|
}
|
|
67
|
-
exports.useMermaidSvg = useMermaidSvg;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-mermaid",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "Mermaid components for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/theme-mermaid.d.ts",
|
|
@@ -33,18 +33,17 @@
|
|
|
33
33
|
"copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@docusaurus/core": "2.
|
|
37
|
-
"@docusaurus/module-type-aliases": "2.
|
|
38
|
-
"@docusaurus/theme-common": "2.
|
|
39
|
-
"@docusaurus/types": "2.
|
|
40
|
-
"@docusaurus/utils-validation": "2.
|
|
36
|
+
"@docusaurus/core": "2.3.1",
|
|
37
|
+
"@docusaurus/module-type-aliases": "2.3.1",
|
|
38
|
+
"@docusaurus/theme-common": "2.3.1",
|
|
39
|
+
"@docusaurus/types": "2.3.1",
|
|
40
|
+
"@docusaurus/utils-validation": "2.3.1",
|
|
41
41
|
"@mdx-js/react": "^1.6.22",
|
|
42
|
-
"mermaid": "^9.
|
|
42
|
+
"mermaid": "^9.2.2",
|
|
43
43
|
"tslib": "^2.4.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/mdx-js__react": "^1.5.5",
|
|
47
|
-
"@types/mermaid": "^8.2.9",
|
|
48
47
|
"react-test-renderer": "^17.0.2"
|
|
49
48
|
},
|
|
50
49
|
"peerDependencies": {
|
|
@@ -54,5 +53,5 @@
|
|
|
54
53
|
"engines": {
|
|
55
54
|
"node": ">=16.14"
|
|
56
55
|
},
|
|
57
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "cf12f21a10f6c5439ff931e61419c4bb03a5a2dc"
|
|
58
57
|
}
|
package/src/client/index.ts
CHANGED
|
@@ -7,8 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import {useMemo} from 'react';
|
|
9
9
|
import {useColorMode, useThemeConfig} from '@docusaurus/theme-common';
|
|
10
|
-
import mermaid from 'mermaid';
|
|
11
|
-
import type mermaidAPI from 'mermaid/mermaidAPI';
|
|
10
|
+
import mermaid, {type MermaidConfig} from 'mermaid';
|
|
12
11
|
import type {ThemeConfig} from '@docusaurus/theme-mermaid';
|
|
13
12
|
|
|
14
13
|
// Stable className to allow users to easily target with CSS
|
|
@@ -18,7 +17,7 @@ export function useMermaidThemeConfig(): ThemeConfig['mermaid'] {
|
|
|
18
17
|
return (useThemeConfig() as unknown as ThemeConfig).mermaid;
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
export function useMermaidConfig():
|
|
20
|
+
export function useMermaidConfig(): MermaidConfig {
|
|
22
21
|
const {colorMode} = useColorMode();
|
|
23
22
|
const mermaidThemeConfig = useMermaidThemeConfig();
|
|
24
23
|
|
|
@@ -33,7 +32,7 @@ export function useMermaidConfig(): mermaidAPI.Config {
|
|
|
33
32
|
|
|
34
33
|
export function useMermaidSvg(
|
|
35
34
|
txt: string,
|
|
36
|
-
mermaidConfigParam?:
|
|
35
|
+
mermaidConfigParam?: MermaidConfig,
|
|
37
36
|
): string {
|
|
38
37
|
/*
|
|
39
38
|
For flexibility, we allow the hook to receive a custom Mermaid config
|
|
@@ -7,14 +7,13 @@
|
|
|
7
7
|
|
|
8
8
|
import {Joi} from '@docusaurus/utils-validation';
|
|
9
9
|
import type {ThemeConfig} from '@docusaurus/theme-mermaid';
|
|
10
|
-
import type mermaidAPI from 'mermaid/mermaidAPI';
|
|
11
10
|
import type {ThemeConfigValidationContext} from '@docusaurus/types';
|
|
12
11
|
|
|
13
12
|
export const DEFAULT_THEME_CONFIG: ThemeConfig = {
|
|
14
13
|
mermaid: {
|
|
15
14
|
theme: {
|
|
16
|
-
dark: 'dark'
|
|
17
|
-
light: 'default'
|
|
15
|
+
dark: 'dark',
|
|
16
|
+
light: 'default',
|
|
18
17
|
},
|
|
19
18
|
options: {},
|
|
20
19
|
},
|