mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-23 10:16:43 +02:00
Compare commits
49 Commits
release_9.
...
v9.2.2
Author | SHA1 | Date | |
---|---|---|---|
![]() |
9bb0ed2040 | ||
![]() |
2f9d6e0aff | ||
![]() |
ecc51d7cb8 | ||
![]() |
c309e3e3d6 | ||
![]() |
f52df3037f | ||
![]() |
649ab17806 | ||
![]() |
89da6ea31a | ||
![]() |
c7f7ff39ce | ||
![]() |
8e63a072e4 | ||
![]() |
b03ac389fa | ||
![]() |
d2511f6a8c | ||
![]() |
5b53cee673 | ||
![]() |
1b2dce99c9 | ||
![]() |
ba7f83019f | ||
![]() |
745abb81dc | ||
![]() |
e64e98fbfc | ||
![]() |
605f288554 | ||
![]() |
6d2552ea6e | ||
![]() |
20b4358c0e | ||
![]() |
7ca525622b | ||
![]() |
aab8f9273f | ||
![]() |
166dca4924 | ||
![]() |
75d276e19e | ||
![]() |
1e417833f4 | ||
![]() |
97a7f1fd71 | ||
![]() |
c86d46eb8a | ||
![]() |
361dd6a96e | ||
![]() |
17adec38af | ||
![]() |
638b9d9aae | ||
![]() |
c8f6994895 | ||
![]() |
1117a80500 | ||
![]() |
5d83ec6fa2 | ||
![]() |
bab5937426 | ||
![]() |
099a26977a | ||
![]() |
0b834485a8 | ||
![]() |
41f21d4f72 | ||
![]() |
312e5f3d96 | ||
![]() |
6ef3e7f536 | ||
![]() |
4f5228aec4 | ||
![]() |
b9daa35558 | ||
![]() |
21304a9677 | ||
![]() |
3f6613ea9f | ||
![]() |
c8635c0b9b | ||
![]() |
7a47fcfcbc | ||
![]() |
5d048ce21e | ||
![]() |
f41e34e61a | ||
![]() |
89d3d297b7 | ||
![]() |
41249fd064 | ||
![]() |
c5d859e52e |
43
.github/ISSUE_TEMPLATE/bug_report.md
vendored
43
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -1,43 +0,0 @@
|
|||||||
---
|
|
||||||
name: Bug report
|
|
||||||
about: Create a report to help us improve
|
|
||||||
title: ''
|
|
||||||
labels: 'Status: Triage, Type: Bug / Error'
|
|
||||||
assignees: ''
|
|
||||||
---
|
|
||||||
|
|
||||||
**Describe the bug**
|
|
||||||
A clear and concise description of what the bug is.
|
|
||||||
|
|
||||||
**To Reproduce**
|
|
||||||
Steps to reproduce the behavior:
|
|
||||||
|
|
||||||
1. Go to '...'
|
|
||||||
2. Click on '....'
|
|
||||||
3. Scroll down to '....'
|
|
||||||
4. See error
|
|
||||||
|
|
||||||
**Expected behavior**
|
|
||||||
A clear and concise description of what you expected to happen.
|
|
||||||
|
|
||||||
**Screenshots**
|
|
||||||
If applicable, add screenshots to help explain your problem.
|
|
||||||
|
|
||||||
**Code Sample**
|
|
||||||
If applicable, add the code sample or a link to the [live editor](https://mermaid.live).
|
|
||||||
|
|
||||||
**Desktop (please complete the following information):**
|
|
||||||
|
|
||||||
- OS: [e.g. iOS]
|
|
||||||
- Browser [e.g. chrome, safari]
|
|
||||||
- Version [e.g. 22]
|
|
||||||
|
|
||||||
**Smartphone (please complete the following information):**
|
|
||||||
|
|
||||||
- Device: [e.g. iPhone6]
|
|
||||||
- OS: [e.g. iOS8.1]
|
|
||||||
- Browser [e.g. stock browser, safari]
|
|
||||||
- Version [e.g. 22]
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context about the problem here.
|
|
69
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
69
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
name: Bug Report
|
||||||
|
description: Create a report to help us improve
|
||||||
|
labels:
|
||||||
|
- 'Status: Triage'
|
||||||
|
- 'Type: Bug / Error'
|
||||||
|
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |-
|
||||||
|
## Security vulnerabilities
|
||||||
|
Please refer our [Security Policy](https://github.com/mermaid-js/.github/blob/main/SECURITY.md) and report to keep vulnerabilities confidential so we can release fixes first.
|
||||||
|
|
||||||
|
## Before you submit...
|
||||||
|
We like to help you, but in order to do that should you make a few things first:
|
||||||
|
|
||||||
|
- Use a clear and concise title
|
||||||
|
- Fill out the text fields with as much detail as possible.
|
||||||
|
- Never be shy to give us screenshots and/or code samples. It will help!
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Description
|
||||||
|
description: Give a clear and concise description of what the bug is.
|
||||||
|
placeholder: When I do ... does ... happen.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Steps to reproduce
|
||||||
|
description: Give a step-by-step example on how to reproduce the bug.
|
||||||
|
placeholder: |-
|
||||||
|
1. Do this
|
||||||
|
2. Do that
|
||||||
|
3. ...
|
||||||
|
4. Bug!
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Screenshots
|
||||||
|
description: If applicable, add screenshots to help explain your issue.
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Code Sample
|
||||||
|
description: |-
|
||||||
|
If applicable, add the code sample or a link to the [Live Editor](https://mermaid.live).
|
||||||
|
Any text pasted here will be rendered as a Code block.
|
||||||
|
render: text
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Setup
|
||||||
|
description: |-
|
||||||
|
Please fill out the below info.
|
||||||
|
Note that you only need to fill out one and not both sections.
|
||||||
|
value: |-
|
||||||
|
**Desktop**
|
||||||
|
|
||||||
|
- OS and Version: [Windows, Linux, Mac, ...]
|
||||||
|
- Browser and Version: [Chrome, Edge, Firefox]
|
||||||
|
|
||||||
|
**Smartphone**
|
||||||
|
|
||||||
|
- Device: [Samsung, iPhone, ...]
|
||||||
|
- OS and Version: [Android, iOS, ...]
|
||||||
|
- Browser and Version: [Chrome, Safari, ...]
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Additional Context
|
||||||
|
description: Anything else to add?
|
17
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
17
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
blank_issues_enabled: false
|
||||||
|
contact_links:
|
||||||
|
- name: GitHub Discussions
|
||||||
|
url: https://github.com/mermaid-js/mermaid/discussions
|
||||||
|
about: Ask the Community questions or share your own graphs in our discussions.
|
||||||
|
- name: Security Vulnerability
|
||||||
|
url: https://github.com/mermaid-js/.github/blob/main/SECURITY.md
|
||||||
|
about: Report security issues confidentially.
|
||||||
|
- name: Slack
|
||||||
|
url: https://join.slack.com/t/mermaid-talk/shared_invite/enQtNzc4NDIyNzk4OTAyLWVhYjQxOTI2OTg4YmE1ZmJkY2Y4MTU3ODliYmIwOTY3NDJlYjA0YjIyZTdkMDMyZTUwOGI0NjEzYmEwODcwOTE
|
||||||
|
about: Join our Community on Slack for Help and a casual chat.
|
||||||
|
- name: Documentation
|
||||||
|
url: https://mermaid-js.github.io
|
||||||
|
about: Read our documentation for all that Mermaid.js can offer.
|
||||||
|
- name: Live Editor
|
||||||
|
url: https://mermaid.live
|
||||||
|
about: Try the live editor to preview graphs in no time.
|
42
.github/ISSUE_TEMPLATE/diagram_proposal.yml
vendored
Normal file
42
.github/ISSUE_TEMPLATE/diagram_proposal.yml
vendored
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
name: Diagram Proposal
|
||||||
|
description: Suggest a new Diagram Type to add to Mermaid.
|
||||||
|
labels:
|
||||||
|
- 'Status: Triage'
|
||||||
|
- 'Type: Enhancement'
|
||||||
|
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |-
|
||||||
|
## Before you submit...
|
||||||
|
First of all, thank you for proposing a new Diagram to us.
|
||||||
|
We are always happy about new ideas to improve Mermaid.js wherever possible.
|
||||||
|
|
||||||
|
To get the fastest and best response possible, make sure you do the following:
|
||||||
|
|
||||||
|
- Use a clear and concise title
|
||||||
|
- Fill out the text fields with as much detail as possible.
|
||||||
|
- Never be shy to give us screenshots and/or code samples. It will help!
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Proposal
|
||||||
|
description: A clear and concise description of what should be added to Mermaid.js.
|
||||||
|
placeholder: Mermaid.js should add ... because ...
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Use Cases
|
||||||
|
description: If applicable, give some use cases for where this diagram would be useful.
|
||||||
|
placeholder: The Diagram could be used for ...
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Screenshots
|
||||||
|
description: If applicable, add screenshots to show possible examples of how the diagram may look like.
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Code Sample
|
||||||
|
description: |-
|
||||||
|
If applicable, add a code sample for how to implement this new diagram.
|
||||||
|
The text will automatically be rendered as JavaScript code.
|
||||||
|
render: javascript
|
19
.github/ISSUE_TEMPLATE/feature_request.md
vendored
19
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@@ -1,19 +0,0 @@
|
|||||||
---
|
|
||||||
name: Feature request
|
|
||||||
about: Suggest an idea for this project
|
|
||||||
title: ''
|
|
||||||
labels: 'Status: Triage, Type: Enhancement'
|
|
||||||
assignees: ''
|
|
||||||
---
|
|
||||||
|
|
||||||
**Is your feature request related to a problem? Please describe.**
|
|
||||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
|
||||||
|
|
||||||
**Describe the solution you'd like**
|
|
||||||
A clear and concise description of what you want to happen.
|
|
||||||
|
|
||||||
**Describe alternatives you've considered**
|
|
||||||
A clear and concise description of any alternative solutions or features you've considered.
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context or screenshots about the feature request here.
|
|
16
.github/ISSUE_TEMPLATE/question.md
vendored
16
.github/ISSUE_TEMPLATE/question.md
vendored
@@ -1,16 +0,0 @@
|
|||||||
---
|
|
||||||
name: Question
|
|
||||||
about: Get some help from the community.
|
|
||||||
title: ''
|
|
||||||
labels: 'Help wanted!, Type: Other'
|
|
||||||
assignees: ''
|
|
||||||
---
|
|
||||||
|
|
||||||
## Help us help you!
|
|
||||||
|
|
||||||
You want an answer. Here are some ways to get it quicker:
|
|
||||||
|
|
||||||
- Use a clear and concise title.
|
|
||||||
- Try to pose a clear and concise question.
|
|
||||||
- Include as much, or as little, code as necessary.
|
|
||||||
- Don't be shy to give us some screenshots, if it helps!
|
|
34
.github/ISSUE_TEMPLATE/syntax_proposal.yml
vendored
Normal file
34
.github/ISSUE_TEMPLATE/syntax_proposal.yml
vendored
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
name: Syntax Proposal
|
||||||
|
description: Suggest a new Syntax to add to Mermaid.js.
|
||||||
|
labels:
|
||||||
|
- 'Status: Triage'
|
||||||
|
- 'Type: Enhancement'
|
||||||
|
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |-
|
||||||
|
## Before you submit...
|
||||||
|
First of all, thank you for proposing a new Syntax to us.
|
||||||
|
We are always happy about new ideas to improve Mermaid.js wherever possible.
|
||||||
|
|
||||||
|
To get the fastest and best response possible, make sure you do the following:
|
||||||
|
|
||||||
|
- Use a clear and concise title
|
||||||
|
- Fill out the text fields with as much detail as possible. Examples are always welcome.
|
||||||
|
- Never be shy to give us screenshots and/or code samples. It will help!
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Proposal
|
||||||
|
description: A clear and concise description of what Syntax should be added to Mermaid.js.
|
||||||
|
placeholder: Mermaid.js should add ... because ...
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Example
|
||||||
|
description: If applicable, provide an example of the new Syntax.
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Screenshots
|
||||||
|
description: If applicable, add screenshots to show possible examples of how the theme may look like.
|
42
.github/ISSUE_TEMPLATE/theme_proposal.yml
vendored
Normal file
42
.github/ISSUE_TEMPLATE/theme_proposal.yml
vendored
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
name: Theme Proposal
|
||||||
|
description: Suggest a new theme to add to Mermaid.js.
|
||||||
|
labels:
|
||||||
|
- 'Status: Triage'
|
||||||
|
- 'Type: Enhancement'
|
||||||
|
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |-
|
||||||
|
## Before you submit...
|
||||||
|
First of all, thank you for proposing a new Theme to us.
|
||||||
|
We are always happy about new ideas to improve Mermaid.js wherever possible.
|
||||||
|
|
||||||
|
To get the fastest and best response possible, make sure you do the following:
|
||||||
|
|
||||||
|
- Use a clear and concise title
|
||||||
|
- Fill out the text fields with as much detail as possible. Examples are always welcome!
|
||||||
|
- Never be shy to give us screenshots and/or code samples. It will help!
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Proposal
|
||||||
|
description: A clear and concise description of what theme should be added to Mermaid.js.
|
||||||
|
placeholder: Mermaid.js should add ... because ...
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Colors
|
||||||
|
description: |-
|
||||||
|
A detailed list of the different colour values to use.
|
||||||
|
A list of currently used variable names can be found [here](https://mermaid-js.github.io/mermaid/#/theming?id=theme-variables-reference-table)
|
||||||
|
placeholder: |-
|
||||||
|
- background: #f4f4f4
|
||||||
|
- primaryColor: #fff4dd
|
||||||
|
- ...
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Screenshots
|
||||||
|
description: If applicable, add screenshots to show possible examples of how the theme may look like.
|
1
.npmrc
1
.npmrc
@@ -1 +1,2 @@
|
|||||||
auto-install-peers=true
|
auto-install-peers=true
|
||||||
|
strict-peer-dependencies=false
|
@@ -23,23 +23,13 @@ const packageOptions = {
|
|||||||
'mermaid-mindmap': {
|
'mermaid-mindmap': {
|
||||||
name: 'mermaid-mindmap',
|
name: 'mermaid-mindmap',
|
||||||
packageName: 'mermaid-mindmap',
|
packageName: 'mermaid-mindmap',
|
||||||
file: 'diagram-definition.ts',
|
|
||||||
},
|
|
||||||
'mermaid-mindmap-detector': {
|
|
||||||
name: 'mermaid-mindmap-detector',
|
|
||||||
packageName: 'mermaid-mindmap',
|
|
||||||
file: 'detector.ts',
|
|
||||||
},
|
|
||||||
'mermaid-example-diagram': {
|
|
||||||
name: 'mermaid-example-diagram',
|
|
||||||
packageName: 'mermaid-example-diagram',
|
|
||||||
file: 'diagram-definition.ts',
|
|
||||||
},
|
|
||||||
'mermaid-example-diagram-detector': {
|
|
||||||
name: 'mermaid-example-diagram-detector',
|
|
||||||
packageName: 'mermaid-example-diagram',
|
|
||||||
file: 'detector.ts',
|
file: 'detector.ts',
|
||||||
},
|
},
|
||||||
|
// 'mermaid-example-diagram-detector': {
|
||||||
|
// name: 'mermaid-example-diagram-detector',
|
||||||
|
// packageName: 'mermaid-example-diagram',
|
||||||
|
// file: 'detector.ts',
|
||||||
|
// },
|
||||||
};
|
};
|
||||||
|
|
||||||
interface BuildOptions {
|
interface BuildOptions {
|
||||||
@@ -111,7 +101,7 @@ export const getBuildConfig = ({ minify, core, watch, entryName }: BuildOptions)
|
|||||||
include: [
|
include: [
|
||||||
'packages/mermaid-mindmap/src/**',
|
'packages/mermaid-mindmap/src/**',
|
||||||
'packages/mermaid/src/**',
|
'packages/mermaid/src/**',
|
||||||
'packages/mermaid-example-diagram/src/**',
|
// 'packages/mermaid-example-diagram/src/**',
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -141,7 +131,7 @@ if (watch) {
|
|||||||
build(getBuildConfig({ minify: false, watch, core: true, entryName: 'mermaid' }));
|
build(getBuildConfig({ minify: false, watch, core: true, entryName: 'mermaid' }));
|
||||||
if (!mermaidOnly) {
|
if (!mermaidOnly) {
|
||||||
build(getBuildConfig({ minify: false, watch, entryName: 'mermaid-mindmap' }));
|
build(getBuildConfig({ minify: false, watch, entryName: 'mermaid-mindmap' }));
|
||||||
build(getBuildConfig({ minify: false, watch, entryName: 'mermaid-example-diagram' }));
|
// build(getBuildConfig({ minify: false, watch, entryName: 'mermaid-example-diagram' }));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
void main();
|
void main();
|
||||||
|
@@ -15,5 +15,5 @@ module.exports = defineConfig({
|
|||||||
// { deviceName: 'Pixel 2', screenOrientation: 'portrait' },
|
// { deviceName: 'Pixel 2', screenOrientation: 'portrait' },
|
||||||
],
|
],
|
||||||
// set batch name to the configuration
|
// set batch name to the configuration
|
||||||
batchName: `Mermaid ${process.env.APPLI_BRANCH ?? "'no APPLI_BRANCH set'"}`,
|
// batchName: `Mermaid ${process.env.APPLI_BRANCH ?? "'no APPLI_BRANCH set'"}`,
|
||||||
});
|
});
|
||||||
|
@@ -2,6 +2,8 @@ const utf8ToB64 = (str) => {
|
|||||||
return window.btoa(unescape(encodeURIComponent(str)));
|
return window.btoa(unescape(encodeURIComponent(str)));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const batchId = 'mermid-batch' + new Date().getTime();
|
||||||
|
|
||||||
export const mermaidUrl = (graphStr, options, api) => {
|
export const mermaidUrl = (graphStr, options, api) => {
|
||||||
const obj = {
|
const obj = {
|
||||||
code: graphStr,
|
code: graphStr,
|
||||||
@@ -50,9 +52,12 @@ export const imgSnapshotTest = (graphStr, _options, api = false, validation) =>
|
|||||||
const name = (options.name || cy.state('runnable').fullTitle()).replace(/\s+/g, '-');
|
const name = (options.name || cy.state('runnable').fullTitle()).replace(/\s+/g, '-');
|
||||||
|
|
||||||
if (useAppli) {
|
if (useAppli) {
|
||||||
|
cy.log('Opening eyes ' + Cypress.spec.name + ' --- ' + name);
|
||||||
cy.eyesOpen({
|
cy.eyesOpen({
|
||||||
appName: 'Mermaid',
|
appName: 'Mermaid',
|
||||||
testName: name,
|
testName: name,
|
||||||
|
batchName: Cypress.spec.name,
|
||||||
|
batchId: batchId + Cypress.spec.name,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +69,9 @@ export const imgSnapshotTest = (graphStr, _options, api = false, validation) =>
|
|||||||
// Default name to test title
|
// Default name to test title
|
||||||
|
|
||||||
if (useAppli) {
|
if (useAppli) {
|
||||||
|
cy.log('Check eyes' + Cypress.spec.name);
|
||||||
cy.eyesCheckWindow('Click!');
|
cy.eyesCheckWindow('Click!');
|
||||||
|
cy.log('Closing eyes: ' + Cypress.spec.name);
|
||||||
cy.eyesClose();
|
cy.eyesClose();
|
||||||
} else {
|
} else {
|
||||||
cy.matchImageSnapshot(name);
|
cy.matchImageSnapshot(name);
|
||||||
@@ -100,9 +107,12 @@ export const urlSnapshotTest = (url, _options, api = false, validation) => {
|
|||||||
const name = (options.name || cy.state('runnable').fullTitle()).replace(/\s+/g, '-');
|
const name = (options.name || cy.state('runnable').fullTitle()).replace(/\s+/g, '-');
|
||||||
|
|
||||||
if (useAppli) {
|
if (useAppli) {
|
||||||
|
cy.log('Opening eyes 2' + Cypress.spec.name);
|
||||||
cy.eyesOpen({
|
cy.eyesOpen({
|
||||||
appName: 'Mermaid',
|
appName: 'Mermaid',
|
||||||
testName: name,
|
testName: name,
|
||||||
|
batchName: Cypress.spec.name,
|
||||||
|
batchId: batchId + Cypress.spec.name,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +122,9 @@ export const urlSnapshotTest = (url, _options, api = false, validation) => {
|
|||||||
// Default name to test title
|
// Default name to test title
|
||||||
|
|
||||||
if (useAppli) {
|
if (useAppli) {
|
||||||
|
cy.log('Check eyes 2' + Cypress.spec.name);
|
||||||
cy.eyesCheckWindow('Click!');
|
cy.eyesCheckWindow('Click!');
|
||||||
|
cy.log('Closing eyes 2' + Cypress.spec.name);
|
||||||
cy.eyesClose();
|
cy.eyesClose();
|
||||||
} else {
|
} else {
|
||||||
cy.matchImageSnapshot(name);
|
cy.matchImageSnapshot(name);
|
||||||
|
13
cypress/integration/other/external-diagrams.spec.js
Normal file
13
cypress/integration/other/external-diagrams.spec.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
describe('mermaid', () => {
|
||||||
|
describe('registerDiagram', () => {
|
||||||
|
it('should work on @mermaid-js/mermaid-mindmap and mermaid-example-diagram', () => {
|
||||||
|
const url = 'http://localhost:9000/external-diagrams-mindmap.html';
|
||||||
|
cy.visit(url);
|
||||||
|
|
||||||
|
cy.get('svg', {
|
||||||
|
// may be a bit slower than normal, since vite might need to re-compile mermaid/mermaid-mindmap/mermaid-example-diagram
|
||||||
|
timeout: 10000,
|
||||||
|
}).matchImageSnapshot();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
49
cypress/platform/external-diagrams-mindmap.html
Normal file
49
cypress/platform/external-diagrams-mindmap.html
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<h1>Should correctly load a third-party diagram using registerDiagram</h1>
|
||||||
|
<pre id="diagram" class="mermaid">
|
||||||
|
mindmap
|
||||||
|
root
|
||||||
|
A
|
||||||
|
B
|
||||||
|
C
|
||||||
|
D
|
||||||
|
E
|
||||||
|
A2
|
||||||
|
B2
|
||||||
|
C2
|
||||||
|
D2
|
||||||
|
E2
|
||||||
|
child1((Circle))
|
||||||
|
grandchild 1
|
||||||
|
grandchild 2
|
||||||
|
child2(Round rectangle)
|
||||||
|
grandchild 3
|
||||||
|
grandchild 4
|
||||||
|
child3[Square]
|
||||||
|
grandchild 5
|
||||||
|
::icon(mdi mdi-fire)
|
||||||
|
gc6((grand<br/>child 6))
|
||||||
|
::icon(mdi mdi-fire)
|
||||||
|
gc7((grand<br/>grand<br/>child 8))
|
||||||
|
</pre>
|
||||||
|
<!-- <pre id="diagram" class="mermaid2">
|
||||||
|
example-diagram
|
||||||
|
</pre> -->
|
||||||
|
|
||||||
|
<!-- <div id="cy"></div> -->
|
||||||
|
<!-- <script src="http://localhost:9000/packages/mermaid-mindmap/dist/mermaid-mindmap-detector.js"></script> -->
|
||||||
|
<!-- <script src="./mermaid-example-diagram-detector.js"></script> -->
|
||||||
|
<!-- <script src="//cdn.jsdelivr.net/npm/mermaid@9.1.7/dist/mermaid.min.js"></script> -->
|
||||||
|
<!-- <script type="module" src="./external-diagrams-mindmap.mjs" /> -->
|
||||||
|
<script type="module">
|
||||||
|
import mindmap from '../../packages/mermaid-mindmap/src/detector';
|
||||||
|
// import example from '../../packages/mermaid-example-diagram/src/detector';
|
||||||
|
import mermaid from '../../packages/mermaid/src/mermaid';
|
||||||
|
|
||||||
|
await mermaid.registerExternalDiagrams([mindmap]);
|
||||||
|
await mermaid.initialize({ logLevel: 0 });
|
||||||
|
await mermaid.initThrowsErrorsAsync();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@@ -1,4 +1,5 @@
|
|||||||
import mermaid2 from '../../packages/mermaid/src/mermaid';
|
import mermaid2 from '../../packages/mermaid/src/mermaid';
|
||||||
|
import mindmap from '../../packages/mermaid-mindmap/src/detector';
|
||||||
|
|
||||||
function b64ToUtf8(str) {
|
function b64ToUtf8(str) {
|
||||||
return decodeURIComponent(escape(window.atob(str)));
|
return decodeURIComponent(escape(window.atob(str)));
|
||||||
@@ -9,7 +10,7 @@ function b64ToUtf8(str) {
|
|||||||
* configuration for mermaid rendering and calls init for rendering the mermaid diagrams on the
|
* configuration for mermaid rendering and calls init for rendering the mermaid diagrams on the
|
||||||
* page.
|
* page.
|
||||||
*/
|
*/
|
||||||
const contentLoaded = function () {
|
const contentLoaded = async function () {
|
||||||
let pos = document.location.href.indexOf('?graph=');
|
let pos = document.location.href.indexOf('?graph=');
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
pos = pos + 7;
|
pos = pos + 7;
|
||||||
@@ -36,8 +37,7 @@ const contentLoaded = function () {
|
|||||||
document.getElementsByTagName('body')[0].appendChild(div);
|
document.getElementsByTagName('body')[0].appendChild(div);
|
||||||
}
|
}
|
||||||
|
|
||||||
graphObj.mermaid.lazyLoadedDiagrams = ['/mermaid-mindmap-detector.esm.mjs'];
|
await mermaid2.registerExternalDiagrams([mindmap]);
|
||||||
|
|
||||||
mermaid2.initialize(graphObj.mermaid);
|
mermaid2.initialize(graphObj.mermaid);
|
||||||
mermaid2.init();
|
mermaid2.init();
|
||||||
}
|
}
|
||||||
|
@@ -49,10 +49,10 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
// import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@9/dist/mermaid.esm.min.mjs';
|
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@9/dist/mermaid.esm.min.mjs';
|
||||||
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@9.2.0-rc6/dist/mermaid.esm.min.mjs';
|
import mindmap from 'https://cdn.jsdelivr.net/npm/@mermaid-js/mermaid-mindmap@9/dist/mermaid-mindmap.esm.mjs';
|
||||||
// import mermaid from 'http://localhost:9000/mermaid.esm.mjs';
|
await mermaid.registerExternalDiagrams([mindmap]);
|
||||||
console.log(mermaid); // eslint-disable-line
|
|
||||||
window.mermaid = mermaid;
|
window.mermaid = mermaid;
|
||||||
const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||||
|
|
||||||
@@ -60,20 +60,18 @@
|
|||||||
logLevel: 4,
|
logLevel: 4,
|
||||||
startOnLoad: true,
|
startOnLoad: true,
|
||||||
themeCSS: '.label { font-family: Source Sans Pro,Helvetica Neue,Arial,sans-serif; }',
|
themeCSS: '.label { font-family: Source Sans Pro,Helvetica Neue,Arial,sans-serif; }',
|
||||||
lazyLoadedDiagrams: [
|
|
||||||
'https://cdn.jsdelivr.net/npm/@mermaid-js/mermaid-mindmap@9.2.0-rc3/dist/mermaid-mindmap-detector.esm.mjs',
|
|
||||||
// 'http://localhost:9000/mermaid-mindmap-detector.esm.mjs',
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
if (isDarkMode) conf.theme = 'dark';
|
if (isDarkMode) conf.theme = 'dark';
|
||||||
|
|
||||||
async function loadMermaid() {
|
async function loadMermaid() {
|
||||||
await mermaid.initialize(conf);
|
mermaid.parseError = (e) => {
|
||||||
|
console.log('parse error', e); // eslint-disable-line
|
||||||
|
};
|
||||||
|
await mermaid.registerExternalDiagrams([mindmap]);
|
||||||
|
mermaid.initialize(conf);
|
||||||
console.log('mermaid initialized'); // eslint-disable-line
|
console.log('mermaid initialized'); // eslint-disable-line
|
||||||
}
|
}
|
||||||
mermaid.parseError = (e) => {
|
|
||||||
console.log('parse error', e); // eslint-disable-line
|
|
||||||
};
|
|
||||||
await loadMermaid();
|
await loadMermaid();
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
|
14
package.json
14
package.json
@@ -3,19 +3,8 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"version": "9.2.0-rc4",
|
"version": "9.2.0-rc4",
|
||||||
"description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
|
"description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
|
||||||
"main": "dist/mermaid.core.mjs",
|
|
||||||
"module": "dist/mermaid.core.mjs",
|
|
||||||
"types": "dist/mermaid.d.ts",
|
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"packageManager": "pnpm@7.13.2",
|
"packageManager": "pnpm@7.13.2",
|
||||||
"exports": {
|
|
||||||
".": {
|
|
||||||
"require": "./dist/mermaid.min.js",
|
|
||||||
"import": "./dist/mermaid.core.mjs",
|
|
||||||
"types": "./dist/mermaid.d.ts"
|
|
||||||
},
|
|
||||||
"./*": "./*"
|
|
||||||
},
|
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"diagram",
|
"diagram",
|
||||||
"markdown",
|
"markdown",
|
||||||
@@ -147,9 +136,6 @@
|
|||||||
"resolutions": {
|
"resolutions": {
|
||||||
"d3": "^7.0.0"
|
"d3": "^7.0.0"
|
||||||
},
|
},
|
||||||
"files": [
|
|
||||||
"dist"
|
|
||||||
],
|
|
||||||
"sideEffects": [
|
"sideEffects": [
|
||||||
"**/*.css",
|
"**/*.css",
|
||||||
"**/*.scss"
|
"**/*.scss"
|
||||||
|
3
packages/mermaid-example-diagram/Readme.md
Normal file
3
packages/mermaid-example-diagram/Readme.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
### Do not refer this package. It is not ready.
|
||||||
|
|
||||||
|
### Refer mermaid-mindmap instead.
|
@@ -12,3 +12,5 @@ export const diagram = {
|
|||||||
styles,
|
styles,
|
||||||
injectUtils,
|
injectUtils,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export { detector, id } from './detector';
|
||||||
|
@@ -1,14 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "@mermaid-js/mermaid-mindmap",
|
"name": "@mermaid-js/mermaid-mindmap",
|
||||||
"version": "9.2.0",
|
"version": "9.2.2-rc.2",
|
||||||
"description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
|
"description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
|
||||||
"main": "dist/mermaid-mindmap.core.mjs",
|
|
||||||
"module": "dist/mermaid-mindmap.core.mjs",
|
"module": "dist/mermaid-mindmap.core.mjs",
|
||||||
|
"types": "dist/detector.d.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"require": "./dist/mermaid-mindmap.min.js",
|
"import": "./dist/mermaid-mindmap.core.mjs",
|
||||||
"import": "./dist/mermaid-mindmap.core.mjs"
|
"types": "./dist/detector.d.ts"
|
||||||
},
|
},
|
||||||
"./*": "./*"
|
"./*": "./*"
|
||||||
},
|
},
|
||||||
|
@@ -1,10 +1,20 @@
|
|||||||
export const id = 'mindmap';
|
import type { ExternalDiagramDefinition } from 'mermaid';
|
||||||
|
|
||||||
export const detector = (txt: string) => {
|
const id = 'mindmap';
|
||||||
|
|
||||||
|
const detector = (txt: string) => {
|
||||||
return txt.match(/^\s*mindmap/) !== null;
|
return txt.match(/^\s*mindmap/) !== null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const loadDiagram = async () => {
|
const loader = async () => {
|
||||||
const { diagram } = await import('./diagram-definition');
|
const { diagram } = await import('./diagram-definition');
|
||||||
return { id, diagram };
|
return { id, diagram };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const plugin: ExternalDiagramDefinition = {
|
||||||
|
id,
|
||||||
|
detector,
|
||||||
|
loader,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default plugin;
|
||||||
|
1
packages/mermaid/README.md
Symbolic link
1
packages/mermaid/README.md
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../README.md
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "mermaid",
|
"name": "mermaid",
|
||||||
"version": "9.2.0",
|
"version": "9.2.2-rc.2",
|
||||||
"description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
|
"description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
|
||||||
"main": "./dist/mermaid.min.js",
|
"main": "./dist/mermaid.min.js",
|
||||||
"module": "./dist/mermaid.core.mjs",
|
"module": "./dist/mermaid.core.mjs",
|
||||||
@@ -127,7 +127,8 @@
|
|||||||
"d3": "^7.0.0"
|
"d3": "^7.0.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist"
|
"dist",
|
||||||
|
"README.md"
|
||||||
],
|
],
|
||||||
"sideEffects": [
|
"sideEffects": [
|
||||||
"**/*.css",
|
"**/*.css",
|
||||||
|
@@ -106,11 +106,10 @@ export const getDiagramFromText = (
|
|||||||
// registerDiagram(type, diagram, undefined, diagram.injectUtils);
|
// registerDiagram(type, diagram, undefined, diagram.injectUtils);
|
||||||
// // new diagram will try getDiagram again and if fails then it is a valid throw
|
// // new diagram will try getDiagram again and if fails then it is a valid throw
|
||||||
return loader().then(({ diagram }) => {
|
return loader().then(({ diagram }) => {
|
||||||
registerDiagram(type, diagram, undefined, diagram.injectUtils);
|
registerDiagram(type, diagram, undefined);
|
||||||
return new Diagram(txt, parseError);
|
return new Diagram(txt, parseError);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// return new Diagram(txt, parseError);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Diagram;
|
export default Diagram;
|
||||||
|
@@ -40,7 +40,8 @@ export const updateCurrentConfig = (siteCfg: MermaidConfig, _directives: any[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
currentConfig = cfg;
|
currentConfig = cfg;
|
||||||
return cfg;
|
checkConfig(currentConfig);
|
||||||
|
return currentConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,7 +69,7 @@ export const setSiteConfig = (conf: MermaidConfig): MermaidConfig => {
|
|||||||
siteConfig.themeVariables = theme[conf.theme].getThemeVariables(conf.themeVariables);
|
siteConfig.themeVariables = theme[conf.theme].getThemeVariables(conf.themeVariables);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentConfig = updateCurrentConfig(siteConfig, directives);
|
updateCurrentConfig(siteConfig, directives);
|
||||||
return siteConfig;
|
return siteConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -117,6 +118,7 @@ export const setConfig = (conf: MermaidConfig): MermaidConfig => {
|
|||||||
// conf[key] = manipulator ? manipulator(conf[key]) : conf[key];
|
// conf[key] = manipulator ? manipulator(conf[key]) : conf[key];
|
||||||
// });
|
// });
|
||||||
|
|
||||||
|
checkConfig(conf);
|
||||||
assignWithDepth(currentConfig, conf);
|
assignWithDepth(currentConfig, conf);
|
||||||
|
|
||||||
return getConfig();
|
return getConfig();
|
||||||
@@ -224,3 +226,25 @@ export const reset = (config = siteConfig): void => {
|
|||||||
directives = [];
|
directives = [];
|
||||||
updateCurrentConfig(config, directives);
|
updateCurrentConfig(config, directives);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum ConfigWarning {
|
||||||
|
'LAZY_LOAD_DEPRECATED' = 'The configuration options lazyLoadedDiagrams and loadExternalDiagramsAtStartup are deprecated. Please use registerExternalDiagrams instead.',
|
||||||
|
}
|
||||||
|
type ConfigWarningStrings = keyof typeof ConfigWarning;
|
||||||
|
const issuedWarnings: { [key in ConfigWarningStrings]?: boolean } = {};
|
||||||
|
const issueWarning = (warning: ConfigWarningStrings) => {
|
||||||
|
if (issuedWarnings[warning]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log.warn(ConfigWarning[warning]);
|
||||||
|
issuedWarnings[warning] = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkConfig = (config: MermaidConfig) => {
|
||||||
|
if (!config) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (config.lazyLoadedDiagrams || config.loadExternalDiagramsAtStartup) {
|
||||||
|
issueWarning('LAZY_LOAD_DEPRECATED');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@@ -3,7 +3,9 @@
|
|||||||
import DOMPurify from 'dompurify';
|
import DOMPurify from 'dompurify';
|
||||||
|
|
||||||
export interface MermaidConfig {
|
export interface MermaidConfig {
|
||||||
|
/** @deprecated use mermaid.registerLazyDiagrams instead */
|
||||||
lazyLoadedDiagrams?: string[];
|
lazyLoadedDiagrams?: string[];
|
||||||
|
/** @deprecated use mermaid.registerLazyDiagrams instead */
|
||||||
loadExternalDiagramsAtStartup?: boolean;
|
loadExternalDiagramsAtStartup?: boolean;
|
||||||
theme?: string;
|
theme?: string;
|
||||||
themeVariables?: any;
|
themeVariables?: any;
|
||||||
|
@@ -115,7 +115,6 @@ const config: Partial<MermaidConfig> = {
|
|||||||
* Default value: ['secure', 'securityLevel', 'startOnLoad', 'maxTextSize']
|
* Default value: ['secure', 'securityLevel', 'startOnLoad', 'maxTextSize']
|
||||||
*/
|
*/
|
||||||
secure: ['secure', 'securityLevel', 'startOnLoad', 'maxTextSize'],
|
secure: ['secure', 'securityLevel', 'startOnLoad', 'maxTextSize'],
|
||||||
lazyLoadedDiagrams: [],
|
|
||||||
/**
|
/**
|
||||||
* This option controls if the generated ids of nodes in the SVG are generated randomly or based
|
* This option controls if the generated ids of nodes in the SVG are generated randomly or based
|
||||||
* on a seed. If set to false, the IDs are generated based on the current date and thus are not
|
* on a seed. If set to false, the IDs are generated based on the current date and thus are not
|
||||||
|
@@ -22,17 +22,19 @@ export interface Detectors {
|
|||||||
[key: string]: DiagramDetector;
|
[key: string]: DiagramDetector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers the given diagram with Mermaid.
|
||||||
|
*
|
||||||
|
* Can be used for third-party custom diagrams.
|
||||||
|
*
|
||||||
|
* @param id - A unique ID for the given diagram.
|
||||||
|
* @param diagram - The diagram definition.
|
||||||
|
* @param detector - Function that returns `true` if a given mermaid text is this diagram definition.
|
||||||
|
*/
|
||||||
export const registerDiagram = (
|
export const registerDiagram = (
|
||||||
id: string,
|
id: string,
|
||||||
diagram: DiagramDefinition,
|
diagram: DiagramDefinition,
|
||||||
detector?: DiagramDetector,
|
detector?: DiagramDetector
|
||||||
callback?: (
|
|
||||||
_log: any,
|
|
||||||
_setLogLevel: any,
|
|
||||||
_getConfig: any,
|
|
||||||
_sanitizeText: any,
|
|
||||||
_setupGraphViewbox: any
|
|
||||||
) => void
|
|
||||||
) => {
|
) => {
|
||||||
log.debug(`Registering diagram ${id}`);
|
log.debug(`Registering diagram ${id}`);
|
||||||
if (diagrams[id]) {
|
if (diagrams[id]) {
|
||||||
@@ -48,8 +50,9 @@ export const registerDiagram = (
|
|||||||
addDetector(id, detector);
|
addDetector(id, detector);
|
||||||
}
|
}
|
||||||
addStylesForDiagram(id, diagram.styles);
|
addStylesForDiagram(id, diagram.styles);
|
||||||
if (typeof callback !== 'undefined') {
|
|
||||||
callback(log, setLogLevel, getConfig, sanitizeText, setupGraphViewbox);
|
if (diagram.injectUtils) {
|
||||||
|
diagram.injectUtils(log, setLogLevel, getConfig, sanitizeText, setupGraphViewbox);
|
||||||
}
|
}
|
||||||
log.debug(`Registered diagram ${id}. ${Object.keys(diagrams).join(', ')} diagrams registered.`);
|
log.debug(`Registered diagram ${id}. ${Object.keys(diagrams).join(', ')} diagrams registered.`);
|
||||||
};
|
};
|
||||||
|
@@ -14,7 +14,13 @@ export interface DiagramDefinition {
|
|||||||
parser: any;
|
parser: any;
|
||||||
styles: any;
|
styles: any;
|
||||||
init?: (config: MermaidConfig) => void;
|
init?: (config: MermaidConfig) => void;
|
||||||
injectUtils?: (utils: InjectUtils) => void;
|
injectUtils?: (
|
||||||
|
_log: InjectUtils['_log'],
|
||||||
|
_setLogLevel: InjectUtils['_setLogLevel'],
|
||||||
|
_getConfig: InjectUtils['_getConfig'],
|
||||||
|
_sanitizeText: InjectUtils['_sanitizeText'],
|
||||||
|
_setupGraphViewbox: InjectUtils['_setupGraphViewbox']
|
||||||
|
) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DetectorRecord {
|
export interface DetectorRecord {
|
||||||
@@ -22,5 +28,11 @@ export interface DetectorRecord {
|
|||||||
loader?: DiagramLoader;
|
loader?: DiagramLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ExternalDiagramDefinition {
|
||||||
|
id: string;
|
||||||
|
detector: DiagramDetector;
|
||||||
|
loader: DiagramLoader;
|
||||||
|
}
|
||||||
|
|
||||||
export type DiagramDetector = (text: string, config?: MermaidConfig) => boolean;
|
export type DiagramDetector = (text: string, config?: MermaidConfig) => boolean;
|
||||||
export type DiagramLoader = (() => Promise<{ id: string; diagram: DiagramDefinition }>) | null;
|
export type DiagramLoader = () => Promise<{ id: string; diagram: DiagramDefinition }>;
|
||||||
|
@@ -49,10 +49,10 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
// import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@<MERMAID_VERSION>/dist/mermaid.esm.min.mjs';
|
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@<MERMAID_VERSION>/dist/mermaid.esm.min.mjs';
|
||||||
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@9.2.0-rc6/dist/mermaid.esm.min.mjs';
|
import mindmap from 'https://cdn.jsdelivr.net/npm/@mermaid-js/mermaid-mindmap@<MERMAID_VERSION>/dist/mermaid-mindmap.esm.mjs';
|
||||||
// import mermaid from 'http://localhost:9000/mermaid.esm.mjs';
|
await mermaid.registerExternalDiagrams([mindmap]);
|
||||||
console.log(mermaid); // eslint-disable-line
|
|
||||||
window.mermaid = mermaid;
|
window.mermaid = mermaid;
|
||||||
const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||||
|
|
||||||
@@ -60,20 +60,18 @@
|
|||||||
logLevel: 4,
|
logLevel: 4,
|
||||||
startOnLoad: true,
|
startOnLoad: true,
|
||||||
themeCSS: '.label { font-family: Source Sans Pro,Helvetica Neue,Arial,sans-serif; }',
|
themeCSS: '.label { font-family: Source Sans Pro,Helvetica Neue,Arial,sans-serif; }',
|
||||||
lazyLoadedDiagrams: [
|
|
||||||
'https://cdn.jsdelivr.net/npm/@mermaid-js/mermaid-mindmap@9.2.0-rc3/dist/mermaid-mindmap-detector.esm.mjs',
|
|
||||||
// 'http://localhost:9000/mermaid-mindmap-detector.esm.mjs',
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
if (isDarkMode) conf.theme = 'dark';
|
if (isDarkMode) conf.theme = 'dark';
|
||||||
|
|
||||||
async function loadMermaid() {
|
async function loadMermaid() {
|
||||||
await mermaid.initialize(conf);
|
mermaid.parseError = (e) => {
|
||||||
|
console.log('parse error', e); // eslint-disable-line
|
||||||
|
};
|
||||||
|
await mermaid.registerExternalDiagrams([mindmap]);
|
||||||
|
mermaid.initialize(conf);
|
||||||
console.log('mermaid initialized'); // eslint-disable-line
|
console.log('mermaid initialized'); // eslint-disable-line
|
||||||
}
|
}
|
||||||
mermaid.parseError = (e) => {
|
|
||||||
console.log('parse error', e); // eslint-disable-line
|
|
||||||
};
|
|
||||||
await loadMermaid();
|
await loadMermaid();
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
|
@@ -54,24 +54,83 @@ describe('when using mermaid and ', function () {
|
|||||||
expect(mermaidAPI.render).toHaveBeenCalled();
|
expect(mermaidAPI.render).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('when using #initThrowsErrorsAsync', function () {
|
describe('when using #registerExternalDiagrams', function () {
|
||||||
it('should throw error (but still render) if lazyLoadedDiagram fails', async () => {
|
it('should throw error (but still render) if registerExternalDiagrams fails', async () => {
|
||||||
const node = document.createElement('div');
|
const node = document.createElement('div');
|
||||||
node.appendChild(document.createTextNode('graph TD;\na;'));
|
node.appendChild(document.createTextNode('graph TD;\na;'));
|
||||||
|
|
||||||
mermaidAPI.setConfig({
|
await expect(
|
||||||
lazyLoadedDiagrams: ['this-file-does-not-exist.mjs'],
|
mermaid.registerExternalDiagrams(
|
||||||
});
|
[
|
||||||
await expect(mermaid.initThrowsErrorsAsync(undefined, node)).rejects.toThrowError(
|
{
|
||||||
// this error message is probably different on every platform
|
id: 'dummy',
|
||||||
// this one is just for vite-note (node/jest/browser may be different)
|
detector: (text) => /dummy/.test(text),
|
||||||
'Failed to load this-file-does-not-exist.mjs'
|
loader: () => Promise.reject('error'),
|
||||||
);
|
},
|
||||||
|
],
|
||||||
|
{ lazyLoad: false }
|
||||||
|
)
|
||||||
|
).rejects.toThrow('Failed to load 1 external diagrams');
|
||||||
|
|
||||||
|
expect(() => mermaid.initThrowsErrorsAsync(undefined, node)).not.toThrow();
|
||||||
// should still render, even if lazyLoadedDiagrams fails
|
// should still render, even if lazyLoadedDiagrams fails
|
||||||
expect(mermaidAPI.renderAsync).toHaveBeenCalled();
|
expect(mermaidAPI.renderAsync).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should defer diagram load based on parameter', async () => {
|
||||||
|
let loaded = false;
|
||||||
|
const dummyDiagram = {
|
||||||
|
db: {},
|
||||||
|
renderer: () => {
|
||||||
|
// do nothing
|
||||||
|
},
|
||||||
|
parser: () => {
|
||||||
|
// do nothing
|
||||||
|
},
|
||||||
|
styles: () => {
|
||||||
|
// do nothing
|
||||||
|
},
|
||||||
|
};
|
||||||
|
await expect(
|
||||||
|
mermaid.registerExternalDiagrams(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: 'dummy',
|
||||||
|
detector: (text) => /dummy/.test(text),
|
||||||
|
loader: () => {
|
||||||
|
loaded = true;
|
||||||
|
return Promise.resolve({
|
||||||
|
id: 'dummy',
|
||||||
|
diagram: dummyDiagram,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
{ lazyLoad: true }
|
||||||
|
)
|
||||||
|
).resolves.toBe(undefined);
|
||||||
|
expect(loaded).toBe(false);
|
||||||
|
await expect(
|
||||||
|
mermaid.registerExternalDiagrams(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: 'dummy2',
|
||||||
|
detector: (text) => /dummy2/.test(text),
|
||||||
|
loader: () => {
|
||||||
|
loaded = true;
|
||||||
|
return Promise.resolve({
|
||||||
|
id: 'dummy2',
|
||||||
|
diagram: dummyDiagram,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
{ lazyLoad: false }
|
||||||
|
)
|
||||||
|
).resolves.toBe(undefined);
|
||||||
|
expect(loaded).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
// we modify mermaid config in some tests, so we need to make sure to reset them
|
// we modify mermaid config in some tests, so we need to make sure to reset them
|
||||||
mermaidAPI.reset();
|
mermaidAPI.reset();
|
||||||
|
@@ -9,8 +9,11 @@ import { mermaidAPI } from './mermaidAPI';
|
|||||||
import { addDetector } from './diagram-api/detectType';
|
import { addDetector } from './diagram-api/detectType';
|
||||||
import { isDetailedError, type DetailedError } from './utils';
|
import { isDetailedError, type DetailedError } from './utils';
|
||||||
import { registerDiagram } from './diagram-api/diagramAPI';
|
import { registerDiagram } from './diagram-api/diagramAPI';
|
||||||
|
import { ExternalDiagramDefinition } from './diagram-api/types';
|
||||||
|
|
||||||
export type { MermaidConfig, DetailedError };
|
export type { MermaidConfig, DetailedError, ExternalDiagramDefinition };
|
||||||
|
|
||||||
|
let externalDiagramsRegistered = false;
|
||||||
/**
|
/**
|
||||||
* ## init
|
* ## init
|
||||||
*
|
*
|
||||||
@@ -47,8 +50,8 @@ const init = async function (
|
|||||||
callback?: Function
|
callback?: Function
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const conf = mermaidAPI.getConfig();
|
// Not really sure if we need to check this, or simply call initThrowsErrorsAsync directly.
|
||||||
if (conf?.lazyLoadedDiagrams && conf.lazyLoadedDiagrams.length > 0) {
|
if (externalDiagramsRegistered) {
|
||||||
await initThrowsErrorsAsync(config, nodes, callback);
|
await initThrowsErrorsAsync(config, nodes, callback);
|
||||||
} else {
|
} else {
|
||||||
initThrowsErrors(config, nodes, callback);
|
initThrowsErrors(config, nodes, callback);
|
||||||
@@ -89,6 +92,7 @@ const handleError = (error: unknown, errors: DetailedError[], parseError?: Funct
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const initThrowsErrors = function (
|
const initThrowsErrors = function (
|
||||||
config?: MermaidConfig,
|
config?: MermaidConfig,
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
@@ -177,45 +181,39 @@ const initThrowsErrors = function (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let lazyLoadingPromise: Promise<PromiseSettledResult<void>[]> | undefined = undefined;
|
|
||||||
/**
|
/**
|
||||||
* This is an internal function and should not be made public, as it will likely change.
|
* This is an internal function and should not be made public, as it will likely change.
|
||||||
* @internal
|
* @internal
|
||||||
* @param conf - Mermaid config.
|
* @param diagrams - Array of {@link ExternalDiagramDefinition}.
|
||||||
* @returns An array of {@link PromiseSettledResult}, showing the status of imports.
|
|
||||||
*/
|
*/
|
||||||
const registerLazyLoadedDiagrams = async (conf: MermaidConfig) => {
|
const registerLazyLoadedDiagrams = (diagrams: ExternalDiagramDefinition[]) => {
|
||||||
// Only lazy load once
|
for (const { id, detector, loader } of diagrams) {
|
||||||
// TODO: This is a hack. We should either throw error when new diagrams are added, or load them anyway.
|
addDetector(id, detector, loader);
|
||||||
if (lazyLoadingPromise === undefined) {
|
|
||||||
// Load all lazy loaded diagrams in parallel
|
|
||||||
lazyLoadingPromise = Promise.allSettled(
|
|
||||||
(conf?.lazyLoadedDiagrams ?? []).map(async (diagram: string) => {
|
|
||||||
const { id, detector, loadDiagram } = await import(diagram);
|
|
||||||
addDetector(id, detector, loadDiagram);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return await lazyLoadingPromise;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let loadingPromise: Promise<unknown> | undefined = undefined;
|
/**
|
||||||
|
* This is an internal function and should not be made public, as it will likely change.
|
||||||
const loadExternalDiagrams = async (conf: MermaidConfig) => {
|
* @internal
|
||||||
// Only lazy load once
|
* @param diagrams - Array of {@link ExternalDiagramDefinition}.
|
||||||
// TODO: This is a hack. We should either throw error when new diagrams are added, or load them anyway.
|
*/
|
||||||
if (loadingPromise === undefined) {
|
const loadExternalDiagrams = async (diagrams: ExternalDiagramDefinition[]) => {
|
||||||
log.debug(`Loading ${conf?.lazyLoadedDiagrams?.length} external diagrams`);
|
log.debug(`Loading ${diagrams.length} external diagrams`);
|
||||||
// Load all lazy loaded diagrams in parallel
|
// Load all lazy loaded diagrams in parallel
|
||||||
loadingPromise = Promise.allSettled(
|
const results = await Promise.allSettled(
|
||||||
(conf?.lazyLoadedDiagrams ?? []).map(async (url: string) => {
|
diagrams.map(async ({ id, detector, loader }) => {
|
||||||
const { id, detector, loadDiagram } = await import(url);
|
const { diagram } = await loader();
|
||||||
const { diagram } = await loadDiagram();
|
registerDiagram(id, diagram, detector);
|
||||||
registerDiagram(id, diagram, detector, diagram.injectUtils);
|
})
|
||||||
})
|
);
|
||||||
);
|
const failed = results.filter((result) => result.status === 'rejected');
|
||||||
|
if (failed.length > 0) {
|
||||||
|
log.error(`Failed to load ${failed.length} external diagrams`);
|
||||||
|
for (const res of failed) {
|
||||||
|
log.error(res);
|
||||||
|
}
|
||||||
|
throw new Error(`Failed to load ${failed.length} external diagrams`);
|
||||||
}
|
}
|
||||||
await loadingPromise;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -242,13 +240,6 @@ const initThrowsErrorsAsync = async function (
|
|||||||
) {
|
) {
|
||||||
const conf = mermaidAPI.getConfig();
|
const conf = mermaidAPI.getConfig();
|
||||||
|
|
||||||
const registerLazyLoadedDiagramsErrors: Error[] = [];
|
|
||||||
for (const registerResult of await registerLazyLoadedDiagrams(conf)) {
|
|
||||||
if (registerResult.status == 'rejected') {
|
|
||||||
registerLazyLoadedDiagramsErrors.push(registerResult.reason);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config) {
|
if (config) {
|
||||||
// This is a legacy way of setting config. It is not documented and should be removed in the future.
|
// This is a legacy way of setting config. It is not documented and should be removed in the future.
|
||||||
// @ts-ignore: TODO Fix ts errors
|
// @ts-ignore: TODO Fix ts errors
|
||||||
@@ -323,10 +314,9 @@ const initThrowsErrorsAsync = async function (
|
|||||||
handleError(error, errors, mermaid.parseError);
|
handleError(error, errors, mermaid.parseError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const allErrors = [...registerLazyLoadedDiagramsErrors, ...errors];
|
if (errors.length > 0) {
|
||||||
if (allErrors.length > 0) {
|
|
||||||
// TODO: We should be throwing an error object.
|
// TODO: We should be throwing an error object.
|
||||||
throw allErrors[0];
|
throw errors[0];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -335,16 +325,25 @@ const initialize = function (config: MermaidConfig) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param config
|
* Used to register external diagram types.
|
||||||
* @deprecated This is an internal function and should not be used. Will be removed in v10.
|
* @param diagrams - Array of {@link ExternalDiagramDefinition}.
|
||||||
|
* @param opts
|
||||||
|
* @param opts.lazyLoad - If true, the diagram will be loaded on demand.
|
||||||
*/
|
*/
|
||||||
const initializeAsync = async function (config: MermaidConfig) {
|
const registerExternalDiagrams = async (
|
||||||
if (config.loadExternalDiagramsAtStartup) {
|
diagrams: ExternalDiagramDefinition[],
|
||||||
await loadExternalDiagrams(config);
|
{
|
||||||
|
lazyLoad = true,
|
||||||
|
}: {
|
||||||
|
lazyLoad?: boolean;
|
||||||
|
} = {}
|
||||||
|
) => {
|
||||||
|
if (lazyLoad) {
|
||||||
|
registerLazyLoadedDiagrams(diagrams);
|
||||||
} else {
|
} else {
|
||||||
await registerLazyLoadedDiagrams(config);
|
await loadExternalDiagrams(diagrams);
|
||||||
}
|
}
|
||||||
mermaidAPI.initialize(config);
|
externalDiagramsRegistered = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -414,7 +413,7 @@ const executeQueue = async () => {
|
|||||||
* @param txt
|
* @param txt
|
||||||
* @deprecated This is an internal function and should not be used. Will be removed in v10.
|
* @deprecated This is an internal function and should not be used. Will be removed in v10.
|
||||||
*/
|
*/
|
||||||
const parseAsync = (txt: string) => {
|
const parseAsync = (txt: string): Promise<boolean> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// This promise will resolve when the mermaidAPI.render call is done.
|
// This promise will resolve when the mermaidAPI.render call is done.
|
||||||
// It will be queued first and will be executed when it is first in line
|
// It will be queued first and will be executed when it is first in line
|
||||||
@@ -424,7 +423,7 @@ const parseAsync = (txt: string) => {
|
|||||||
(r) => {
|
(r) => {
|
||||||
// This resolves for the promise for the queue handling
|
// This resolves for the promise for the queue handling
|
||||||
res(r);
|
res(r);
|
||||||
// This fullfills the promise sent to the value back to the original caller
|
// This fulfills the promise sent to the value back to the original caller
|
||||||
resolve(r);
|
resolve(r);
|
||||||
},
|
},
|
||||||
(e) => {
|
(e) => {
|
||||||
@@ -522,8 +521,8 @@ const mermaid: {
|
|||||||
init: typeof init;
|
init: typeof init;
|
||||||
initThrowsErrors: typeof initThrowsErrors;
|
initThrowsErrors: typeof initThrowsErrors;
|
||||||
initThrowsErrorsAsync: typeof initThrowsErrorsAsync;
|
initThrowsErrorsAsync: typeof initThrowsErrorsAsync;
|
||||||
|
registerExternalDiagrams: typeof registerExternalDiagrams;
|
||||||
initialize: typeof initialize;
|
initialize: typeof initialize;
|
||||||
initializeAsync: typeof initializeAsync;
|
|
||||||
contentLoaded: typeof contentLoaded;
|
contentLoaded: typeof contentLoaded;
|
||||||
setParseErrorHandler: typeof setParseErrorHandler;
|
setParseErrorHandler: typeof setParseErrorHandler;
|
||||||
} = {
|
} = {
|
||||||
@@ -537,8 +536,8 @@ const mermaid: {
|
|||||||
init,
|
init,
|
||||||
initThrowsErrors,
|
initThrowsErrors,
|
||||||
initThrowsErrorsAsync,
|
initThrowsErrorsAsync,
|
||||||
|
registerExternalDiagrams,
|
||||||
initialize,
|
initialize,
|
||||||
initializeAsync,
|
|
||||||
parseError: undefined,
|
parseError: undefined,
|
||||||
contentLoaded,
|
contentLoaded,
|
||||||
setParseErrorHandler,
|
setParseErrorHandler,
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
packages:
|
packages:
|
||||||
# all packages in direct subdirs of packages/
|
# all packages in direct subdirs of packages/
|
||||||
- 'packages/*'
|
- 'packages/*'
|
||||||
|
# - 'tests/*'
|
||||||
|
23
tests/webpack/package.json
Normal file
23
tests/webpack/package.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"name": "webpack",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"private": true,
|
||||||
|
"module": "commonjs",
|
||||||
|
"scripts": {
|
||||||
|
"build": "webpack",
|
||||||
|
"serve": "webpack serve"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"devDependencies": {
|
||||||
|
"webpack": "^5.74.0",
|
||||||
|
"webpack-cli": "^4.10.0",
|
||||||
|
"webpack-dev-server": "^4.11.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"mermaid": "workspace:*",
|
||||||
|
"@mermaid-js/mermaid-mindmap": "workspace:*"
|
||||||
|
}
|
||||||
|
}
|
11
tests/webpack/public/index.html
Normal file
11
tests/webpack/public/index.html
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>Getting Started</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="graphDiv"></div>
|
||||||
|
<script src="./main.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
38
tests/webpack/src/index.js
Normal file
38
tests/webpack/src/index.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||||
|
/* eslint-disable no-console */
|
||||||
|
const mermaid = require('mermaid');
|
||||||
|
import mindmap from '@mermaid-js/mermaid-mindmap';
|
||||||
|
|
||||||
|
const render = async (graph) => {
|
||||||
|
const svg = await mermaid.renderAsync('dummy', graph);
|
||||||
|
console.log(svg);
|
||||||
|
document.getElementById('graphDiv').innerHTML = svg;
|
||||||
|
};
|
||||||
|
|
||||||
|
const load = async () => {
|
||||||
|
await mermaid.registerExternalDiagrams([mindmap]);
|
||||||
|
await render('info');
|
||||||
|
|
||||||
|
setTimeout(async () => {
|
||||||
|
await render(`mindmap
|
||||||
|
root((mindmap))
|
||||||
|
Origins
|
||||||
|
Long history
|
||||||
|
::icon(fa fa-book)
|
||||||
|
Popularisation
|
||||||
|
British popular psychology author Tony Buzan
|
||||||
|
Research
|
||||||
|
On effectivness<br/>and features
|
||||||
|
On Automatic creation
|
||||||
|
Uses
|
||||||
|
Creative techniques
|
||||||
|
Strategic planning
|
||||||
|
Argument mapping
|
||||||
|
Tools
|
||||||
|
Pen and paper
|
||||||
|
Mermaid
|
||||||
|
`);
|
||||||
|
}, 2500);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('load', load, false);
|
10
tests/webpack/webpack.config.js
Normal file
10
tests/webpack/webpack.config.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
entry: './src/index.js',
|
||||||
|
output: {
|
||||||
|
filename: 'main.js',
|
||||||
|
path: path.resolve(__dirname, 'dist'),
|
||||||
|
},
|
||||||
|
};
|
Reference in New Issue
Block a user