@docusaurus/theme-mermaid 0.0.0-5335
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/LICENSE +21 -0
- package/README.md +21 -0
- package/lib/client/index.d.ts +12 -0
- package/lib/client/index.js +67 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +23 -0
- package/lib/theme/Mermaid/index.d.ts +9 -0
- package/lib/theme/Mermaid/index.js +26 -0
- package/lib/theme/Mermaid/styles.module.css +14 -0
- package/lib/validateThemeConfig.d.ts +12 -0
- package/lib/validateThemeConfig.js +32 -0
- package/package.json +58 -0
- package/src/client/index.ts +78 -0
- package/src/index.ts +23 -0
- package/src/theme/Mermaid/index.tsx +32 -0
- package/src/theme/Mermaid/styles.module.css +14 -0
- package/src/theme-mermaid.d.ts +35 -0
- package/src/validateThemeConfig.ts +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Docusaurus Theme Mermaid
|
|
2
|
+
|
|
3
|
+
The mermaid components for Docusaurus.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add `docusaurus/theme-mermaid` to your package:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm i @docusaurus/theme-mermaid
|
|
11
|
+
# or
|
|
12
|
+
yarn add @docusaurus/theme-mermaid
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Swizzling components
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
$ npm swizzle @docusaurus/theme-mermaid [component name]
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
All components used by this theme can be found [here](https://github.com/facebook/docusaurus/tree/main/packages/docusaurus-theme-mermaid/src/theme)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type mermaidAPI from 'mermaid/mermaidAPI';
|
|
8
|
+
import type { ThemeConfig } from '@docusaurus/theme-mermaid';
|
|
9
|
+
export declare const MermaidContainerClassName = "docusaurus-mermaid-container";
|
|
10
|
+
export declare function useMermaidThemeConfig(): ThemeConfig['mermaid'];
|
|
11
|
+
export declare function useMermaidConfig(): mermaidAPI.Config;
|
|
12
|
+
export declare function useMermaidSvg(txt: string, mermaidConfigParam?: mermaidAPI.Config): string;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.useMermaidSvg = exports.useMermaidConfig = exports.useMermaidThemeConfig = exports.MermaidContainerClassName = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const react_1 = require("react");
|
|
12
|
+
const theme_common_1 = require("@docusaurus/theme-common");
|
|
13
|
+
const mermaid_1 = tslib_1.__importDefault(require("mermaid"));
|
|
14
|
+
// Stable className to allow users to easily target with CSS
|
|
15
|
+
exports.MermaidContainerClassName = 'docusaurus-mermaid-container';
|
|
16
|
+
function useMermaidThemeConfig() {
|
|
17
|
+
return (0, theme_common_1.useThemeConfig)().mermaid;
|
|
18
|
+
}
|
|
19
|
+
exports.useMermaidThemeConfig = useMermaidThemeConfig;
|
|
20
|
+
function useMermaidConfig() {
|
|
21
|
+
const { colorMode } = (0, theme_common_1.useColorMode)();
|
|
22
|
+
const mermaidThemeConfig = useMermaidThemeConfig();
|
|
23
|
+
const theme = mermaidThemeConfig.theme[colorMode];
|
|
24
|
+
const { options } = mermaidThemeConfig;
|
|
25
|
+
return (0, react_1.useMemo)(() => ({ startOnLoad: false, ...options, theme }), [theme, options]);
|
|
26
|
+
}
|
|
27
|
+
exports.useMermaidConfig = useMermaidConfig;
|
|
28
|
+
function useMermaidSvg(txt, mermaidConfigParam) {
|
|
29
|
+
/*
|
|
30
|
+
For flexibility, we allow the hook to receive a custom Mermaid config
|
|
31
|
+
The user could inject a modified version of the default config for example
|
|
32
|
+
*/
|
|
33
|
+
const defaultMermaidConfig = useMermaidConfig();
|
|
34
|
+
const mermaidConfig = mermaidConfigParam ?? defaultMermaidConfig;
|
|
35
|
+
return (0, react_1.useMemo)(() => {
|
|
36
|
+
/*
|
|
37
|
+
Mermaid API is really weird :s
|
|
38
|
+
It is a big mutable singleton with multiple config levels
|
|
39
|
+
Note: most recent API type definitions are missing
|
|
40
|
+
|
|
41
|
+
There are 2 kind of configs:
|
|
42
|
+
|
|
43
|
+
- siteConfig: some kind of global/protected shared config
|
|
44
|
+
you can only set with "initialize"
|
|
45
|
+
|
|
46
|
+
- config/currentConfig
|
|
47
|
+
the config the renderer will use
|
|
48
|
+
it is reset to siteConfig before each render
|
|
49
|
+
but it can be altered by the mermaid txt content itself through directives
|
|
50
|
+
|
|
51
|
+
To use a new mermaid config (on colorMode change for example) we should
|
|
52
|
+
update siteConfig, and it can only be done with initialize()
|
|
53
|
+
*/
|
|
54
|
+
mermaid_1.default.mermaidAPI.initialize(mermaidConfig);
|
|
55
|
+
/*
|
|
56
|
+
Random client-only id, we don't care much about it
|
|
57
|
+
But mermaid want an id so...
|
|
58
|
+
*/
|
|
59
|
+
const mermaidId = `mermaid-svg-${Math.round(Math.random() * 10000000)}`;
|
|
60
|
+
/*
|
|
61
|
+
Not even documented: mermaid.render returns the svg string
|
|
62
|
+
Using the documented form is un-necessary
|
|
63
|
+
*/
|
|
64
|
+
return mermaid_1.default.render(mermaidId, txt);
|
|
65
|
+
}, [txt, mermaidConfig]);
|
|
66
|
+
}
|
|
67
|
+
exports.useMermaidSvg = useMermaidSvg;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { Plugin } from '@docusaurus/types';
|
|
8
|
+
export default function themeMermaid(): Plugin<void>;
|
|
9
|
+
export { validateThemeConfig } from './validateThemeConfig';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.validateThemeConfig = void 0;
|
|
10
|
+
function themeMermaid() {
|
|
11
|
+
return {
|
|
12
|
+
name: 'docusaurus-theme-mermaid',
|
|
13
|
+
getThemePath() {
|
|
14
|
+
return '../lib/theme';
|
|
15
|
+
},
|
|
16
|
+
getTypeScriptThemePath() {
|
|
17
|
+
return '../src/theme';
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
exports.default = themeMermaid;
|
|
22
|
+
var validateThemeConfig_1 = require("./validateThemeConfig");
|
|
23
|
+
Object.defineProperty(exports, "validateThemeConfig", { enumerable: true, get: function () { return validateThemeConfig_1.validateThemeConfig; } });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
/// <reference types="react" />
|
|
8
|
+
import type { Props } from '@theme/Mermaid';
|
|
9
|
+
export default function Mermaid(props: Props): JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import BrowserOnly from '@docusaurus/BrowserOnly';
|
|
9
|
+
import {
|
|
10
|
+
MermaidContainerClassName,
|
|
11
|
+
useMermaidSvg,
|
|
12
|
+
} from '@docusaurus/theme-mermaid/client';
|
|
13
|
+
import styles from './styles.module.css';
|
|
14
|
+
function MermaidDiagram({value}) {
|
|
15
|
+
const svg = useMermaidSvg(value);
|
|
16
|
+
return (
|
|
17
|
+
<div
|
|
18
|
+
className={`${MermaidContainerClassName} ${styles.container}`}
|
|
19
|
+
// eslint-disable-next-line react/no-danger
|
|
20
|
+
dangerouslySetInnerHTML={{__html: svg}}
|
|
21
|
+
/>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
export default function Mermaid(props) {
|
|
25
|
+
return <BrowserOnly>{() => <MermaidDiagram {...props} />}</BrowserOnly>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
.container {
|
|
9
|
+
max-width: 100%;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.container > svg {
|
|
13
|
+
max-width: 100%;
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { Joi } from '@docusaurus/utils-validation';
|
|
8
|
+
import type { ThemeConfig } from '@docusaurus/theme-mermaid';
|
|
9
|
+
import type { ThemeConfigValidationContext } from '@docusaurus/types';
|
|
10
|
+
export declare const DEFAULT_THEME_CONFIG: ThemeConfig;
|
|
11
|
+
export declare const Schema: Joi.ObjectSchema<ThemeConfig>;
|
|
12
|
+
export declare function validateThemeConfig({ validate, themeConfig, }: ThemeConfigValidationContext<ThemeConfig>): ThemeConfig;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.validateThemeConfig = exports.Schema = exports.DEFAULT_THEME_CONFIG = void 0;
|
|
10
|
+
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
11
|
+
exports.DEFAULT_THEME_CONFIG = {
|
|
12
|
+
mermaid: {
|
|
13
|
+
theme: {
|
|
14
|
+
dark: 'dark',
|
|
15
|
+
light: 'default',
|
|
16
|
+
},
|
|
17
|
+
options: {},
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
exports.Schema = utils_validation_1.Joi.object({
|
|
21
|
+
mermaid: utils_validation_1.Joi.object({
|
|
22
|
+
theme: utils_validation_1.Joi.object({
|
|
23
|
+
dark: utils_validation_1.Joi.string().default(exports.DEFAULT_THEME_CONFIG.mermaid.theme.dark),
|
|
24
|
+
light: utils_validation_1.Joi.string().default(exports.DEFAULT_THEME_CONFIG.mermaid.theme.light),
|
|
25
|
+
}).default(exports.DEFAULT_THEME_CONFIG.mermaid.theme),
|
|
26
|
+
options: utils_validation_1.Joi.object().default(exports.DEFAULT_THEME_CONFIG.mermaid.options),
|
|
27
|
+
}).default(exports.DEFAULT_THEME_CONFIG.mermaid),
|
|
28
|
+
});
|
|
29
|
+
function validateThemeConfig({ validate, themeConfig, }) {
|
|
30
|
+
return validate(exports.Schema, themeConfig);
|
|
31
|
+
}
|
|
32
|
+
exports.validateThemeConfig = validateThemeConfig;
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@docusaurus/theme-mermaid",
|
|
3
|
+
"version": "0.0.0-5335",
|
|
4
|
+
"description": "Mermaid components for Docusaurus.",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "src/theme-mermaid.d.ts",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
"./lib/*": "./lib/*",
|
|
10
|
+
"./src/*": "./src/*",
|
|
11
|
+
"./client": {
|
|
12
|
+
"type": "./lib/client/index.d.ts",
|
|
13
|
+
"default": "./lib/client/index.js"
|
|
14
|
+
},
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./src/theme-mermaid.d.ts",
|
|
17
|
+
"default": "./lib/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/facebook/docusaurus.git",
|
|
26
|
+
"directory": "packages/docusaurus-theme-mermaid"
|
|
27
|
+
},
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc --build && node ../../admin/scripts/copyUntypedFiles.js && prettier --config ../../.prettierrc --write \"lib/theme/**/*.js\"",
|
|
31
|
+
"watch": "run-p -c copy:watch build:watch",
|
|
32
|
+
"build:watch": "tsc --build --watch",
|
|
33
|
+
"copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@docusaurus/core": "0.0.0-5335",
|
|
37
|
+
"@docusaurus/module-type-aliases": "0.0.0-5335",
|
|
38
|
+
"@docusaurus/theme-common": "0.0.0-5335",
|
|
39
|
+
"@docusaurus/types": "0.0.0-5335",
|
|
40
|
+
"@docusaurus/utils-validation": "0.0.0-5335",
|
|
41
|
+
"@mdx-js/react": "^1.6.22",
|
|
42
|
+
"mermaid": "^9.1.1",
|
|
43
|
+
"tslib": "^2.4.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/mdx-js__react": "^1.5.5",
|
|
47
|
+
"@types/mermaid": "^8.2.9",
|
|
48
|
+
"react-test-renderer": "^17.0.2"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"react": "^16.8.4 || ^17.0.0",
|
|
52
|
+
"react-dom": "^16.8.4 || ^17.0.0"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=16.14"
|
|
56
|
+
},
|
|
57
|
+
"gitHead": "42c59e0828b093f765f6c37d522c02ef74846a31"
|
|
58
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {useMemo} from 'react';
|
|
9
|
+
import {useColorMode, useThemeConfig} from '@docusaurus/theme-common';
|
|
10
|
+
import mermaid from 'mermaid';
|
|
11
|
+
import type mermaidAPI from 'mermaid/mermaidAPI';
|
|
12
|
+
import type {ThemeConfig} from '@docusaurus/theme-mermaid';
|
|
13
|
+
|
|
14
|
+
// Stable className to allow users to easily target with CSS
|
|
15
|
+
export const MermaidContainerClassName = 'docusaurus-mermaid-container';
|
|
16
|
+
|
|
17
|
+
export function useMermaidThemeConfig(): ThemeConfig['mermaid'] {
|
|
18
|
+
return (useThemeConfig() as unknown as ThemeConfig).mermaid;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function useMermaidConfig(): mermaidAPI.Config {
|
|
22
|
+
const {colorMode} = useColorMode();
|
|
23
|
+
const mermaidThemeConfig = useMermaidThemeConfig();
|
|
24
|
+
|
|
25
|
+
const theme = mermaidThemeConfig.theme[colorMode];
|
|
26
|
+
const {options} = mermaidThemeConfig;
|
|
27
|
+
|
|
28
|
+
return useMemo(
|
|
29
|
+
() => ({startOnLoad: false, ...options, theme}),
|
|
30
|
+
[theme, options],
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function useMermaidSvg(
|
|
35
|
+
txt: string,
|
|
36
|
+
mermaidConfigParam?: mermaidAPI.Config,
|
|
37
|
+
): string {
|
|
38
|
+
/*
|
|
39
|
+
For flexibility, we allow the hook to receive a custom Mermaid config
|
|
40
|
+
The user could inject a modified version of the default config for example
|
|
41
|
+
*/
|
|
42
|
+
const defaultMermaidConfig = useMermaidConfig();
|
|
43
|
+
const mermaidConfig = mermaidConfigParam ?? defaultMermaidConfig;
|
|
44
|
+
|
|
45
|
+
return useMemo(() => {
|
|
46
|
+
/*
|
|
47
|
+
Mermaid API is really weird :s
|
|
48
|
+
It is a big mutable singleton with multiple config levels
|
|
49
|
+
Note: most recent API type definitions are missing
|
|
50
|
+
|
|
51
|
+
There are 2 kind of configs:
|
|
52
|
+
|
|
53
|
+
- siteConfig: some kind of global/protected shared config
|
|
54
|
+
you can only set with "initialize"
|
|
55
|
+
|
|
56
|
+
- config/currentConfig
|
|
57
|
+
the config the renderer will use
|
|
58
|
+
it is reset to siteConfig before each render
|
|
59
|
+
but it can be altered by the mermaid txt content itself through directives
|
|
60
|
+
|
|
61
|
+
To use a new mermaid config (on colorMode change for example) we should
|
|
62
|
+
update siteConfig, and it can only be done with initialize()
|
|
63
|
+
*/
|
|
64
|
+
mermaid.mermaidAPI.initialize(mermaidConfig);
|
|
65
|
+
|
|
66
|
+
/*
|
|
67
|
+
Random client-only id, we don't care much about it
|
|
68
|
+
But mermaid want an id so...
|
|
69
|
+
*/
|
|
70
|
+
const mermaidId = `mermaid-svg-${Math.round(Math.random() * 10000000)}`;
|
|
71
|
+
|
|
72
|
+
/*
|
|
73
|
+
Not even documented: mermaid.render returns the svg string
|
|
74
|
+
Using the documented form is un-necessary
|
|
75
|
+
*/
|
|
76
|
+
return mermaid.render(mermaidId, txt);
|
|
77
|
+
}, [txt, mermaidConfig]);
|
|
78
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type {Plugin} from '@docusaurus/types';
|
|
9
|
+
|
|
10
|
+
export default function themeMermaid(): Plugin<void> {
|
|
11
|
+
return {
|
|
12
|
+
name: 'docusaurus-theme-mermaid',
|
|
13
|
+
|
|
14
|
+
getThemePath() {
|
|
15
|
+
return '../lib/theme';
|
|
16
|
+
},
|
|
17
|
+
getTypeScriptThemePath() {
|
|
18
|
+
return '../src/theme';
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {validateThemeConfig} from './validateThemeConfig';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import BrowserOnly from '@docusaurus/BrowserOnly';
|
|
10
|
+
import {
|
|
11
|
+
MermaidContainerClassName,
|
|
12
|
+
useMermaidSvg,
|
|
13
|
+
} from '@docusaurus/theme-mermaid/client';
|
|
14
|
+
|
|
15
|
+
import type {Props} from '@theme/Mermaid';
|
|
16
|
+
|
|
17
|
+
import styles from './styles.module.css';
|
|
18
|
+
|
|
19
|
+
function MermaidDiagram({value}: Props): JSX.Element {
|
|
20
|
+
const svg = useMermaidSvg(value);
|
|
21
|
+
return (
|
|
22
|
+
<div
|
|
23
|
+
className={`${MermaidContainerClassName} ${styles.container}`}
|
|
24
|
+
// eslint-disable-next-line react/no-danger
|
|
25
|
+
dangerouslySetInnerHTML={{__html: svg}}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default function Mermaid(props: Props): JSX.Element {
|
|
31
|
+
return <BrowserOnly>{() => <MermaidDiagram {...props} />}</BrowserOnly>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
.container {
|
|
9
|
+
max-width: 100%;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.container > svg {
|
|
13
|
+
max-width: 100%;
|
|
14
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/// <reference types="@docusaurus/module-type-aliases" />
|
|
9
|
+
|
|
10
|
+
declare module '@docusaurus/theme-mermaid' {
|
|
11
|
+
import type {DeepPartial} from 'utility-types';
|
|
12
|
+
import type mermaidAPI from 'mermaid/mermaidAPI';
|
|
13
|
+
import type {Plugin} from '@docusaurus/types';
|
|
14
|
+
|
|
15
|
+
export type ThemeConfig = {
|
|
16
|
+
mermaid: {
|
|
17
|
+
theme: {
|
|
18
|
+
light: mermaidAPI.Theme;
|
|
19
|
+
dark: mermaidAPI.Theme;
|
|
20
|
+
};
|
|
21
|
+
options: mermaidAPI.Config;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export type UserThemeConfig = DeepPartial<ThemeConfig>;
|
|
25
|
+
|
|
26
|
+
export default function themeMermaid(): Plugin<undefined>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare module '@theme/Mermaid' {
|
|
30
|
+
export interface Props {
|
|
31
|
+
value: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default function Mermaid(props: Props): JSX.Element;
|
|
35
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {Joi} from '@docusaurus/utils-validation';
|
|
9
|
+
import type {ThemeConfig} from '@docusaurus/theme-mermaid';
|
|
10
|
+
import type mermaidAPI from 'mermaid/mermaidAPI';
|
|
11
|
+
import type {ThemeConfigValidationContext} from '@docusaurus/types';
|
|
12
|
+
|
|
13
|
+
export const DEFAULT_THEME_CONFIG: ThemeConfig = {
|
|
14
|
+
mermaid: {
|
|
15
|
+
theme: {
|
|
16
|
+
dark: 'dark' as mermaidAPI.Theme,
|
|
17
|
+
light: 'default' as mermaidAPI.Theme,
|
|
18
|
+
},
|
|
19
|
+
options: {},
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const Schema = Joi.object<ThemeConfig>({
|
|
24
|
+
mermaid: Joi.object({
|
|
25
|
+
theme: Joi.object({
|
|
26
|
+
dark: Joi.string().default(DEFAULT_THEME_CONFIG.mermaid.theme.dark),
|
|
27
|
+
light: Joi.string().default(DEFAULT_THEME_CONFIG.mermaid.theme.light),
|
|
28
|
+
}).default(DEFAULT_THEME_CONFIG.mermaid.theme),
|
|
29
|
+
options: Joi.object().default(DEFAULT_THEME_CONFIG.mermaid.options),
|
|
30
|
+
}).default(DEFAULT_THEME_CONFIG.mermaid),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export function validateThemeConfig({
|
|
34
|
+
validate,
|
|
35
|
+
themeConfig,
|
|
36
|
+
}: ThemeConfigValidationContext<ThemeConfig>): ThemeConfig {
|
|
37
|
+
return validate(Schema, themeConfig);
|
|
38
|
+
}
|