mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
Merge pull request #4334 from mermaid-js/sidv/zenuml
Add `@mermaid-js/mermaid-zenuml` package for zenuml Integration
This commit is contained in:
commit
1b40f552b2
@ -4,4 +4,5 @@ docs/Setup.md
|
|||||||
cypress.config.js
|
cypress.config.js
|
||||||
cypress/plugins/index.js
|
cypress/plugins/index.js
|
||||||
coverage
|
coverage
|
||||||
*.json
|
*.json
|
||||||
|
node_modules
|
||||||
|
@ -44,6 +44,11 @@ const packageOptions = {
|
|||||||
packageName: 'mermaid-example-diagram',
|
packageName: 'mermaid-example-diagram',
|
||||||
file: 'detector.ts',
|
file: 'detector.ts',
|
||||||
},
|
},
|
||||||
|
'mermaid-zenuml': {
|
||||||
|
name: 'mermaid-zenuml',
|
||||||
|
packageName: 'mermaid-zenuml',
|
||||||
|
file: 'detector.ts',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
interface BuildOptions {
|
interface BuildOptions {
|
||||||
@ -146,6 +151,7 @@ if (watch) {
|
|||||||
build(getBuildConfig({ minify: false, watch, core: false, entryName: 'mermaid' }));
|
build(getBuildConfig({ minify: false, watch, core: false, entryName: 'mermaid' }));
|
||||||
if (!mermaidOnly) {
|
if (!mermaidOnly) {
|
||||||
build(getBuildConfig({ minify: false, watch, entryName: 'mermaid-example-diagram' }));
|
build(getBuildConfig({ minify: false, watch, entryName: 'mermaid-example-diagram' }));
|
||||||
|
build(getBuildConfig({ minify: false, watch, entryName: 'mermaid-zenuml' }));
|
||||||
}
|
}
|
||||||
} else if (visualize) {
|
} else if (visualize) {
|
||||||
await build(getBuildConfig({ minify: false, core: true, entryName: 'mermaid' }));
|
await build(getBuildConfig({ minify: false, core: true, entryName: 'mermaid' }));
|
||||||
|
@ -15,6 +15,7 @@ async function createServer() {
|
|||||||
|
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
app.use(express.static('./packages/mermaid/dist'));
|
app.use(express.static('./packages/mermaid/dist'));
|
||||||
|
app.use(express.static('./packages/mermaid-zenuml/dist'));
|
||||||
app.use(express.static('./packages/mermaid-example-diagram/dist'));
|
app.use(express.static('./packages/mermaid-example-diagram/dist'));
|
||||||
app.use(vite.middlewares);
|
app.use(vite.middlewares);
|
||||||
app.use(express.static('demos'));
|
app.use(express.static('demos'));
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
"alois",
|
"alois",
|
||||||
"aloisklink",
|
"aloisklink",
|
||||||
"antiscript",
|
"antiscript",
|
||||||
|
"antlr",
|
||||||
"appli",
|
"appli",
|
||||||
"applitools",
|
"applitools",
|
||||||
"asciidoctor",
|
"asciidoctor",
|
||||||
@ -134,7 +135,8 @@
|
|||||||
"vitepress",
|
"vitepress",
|
||||||
"vueuse",
|
"vueuse",
|
||||||
"xlink",
|
"xlink",
|
||||||
"yash"
|
"yash",
|
||||||
|
"zenuml"
|
||||||
],
|
],
|
||||||
"patterns": [
|
"patterns": [
|
||||||
{ "name": "Markdown links", "pattern": "\\((.*)\\)", "description": "" },
|
{ "name": "Markdown links", "pattern": "\\((.*)\\)", "description": "" },
|
||||||
|
19
cypress/integration/rendering/zenuml.spec.js
Normal file
19
cypress/integration/rendering/zenuml.spec.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { imgSnapshotTest } from '../../helpers/util.js';
|
||||||
|
|
||||||
|
describe('Zen UML', () => {
|
||||||
|
it('Basic Zen UML diagram', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
zenuml
|
||||||
|
A.method() {
|
||||||
|
if(x) {
|
||||||
|
B.method() {
|
||||||
|
selfCall() { return X }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
@ -1,5 +1,6 @@
|
|||||||
import mermaid2 from './mermaid.esm.mjs';
|
import mermaid2 from './mermaid.esm.mjs';
|
||||||
import externalExample from '../../packages/mermaid-example-diagram/dist/mermaid-example-diagram.core.mjs';
|
import externalExample from '../../packages/mermaid-example-diagram/dist/mermaid-example-diagram.core.mjs';
|
||||||
|
import zenUml from '../../packages/mermaid-zenuml/dist/mermaid-zenuml.core.mjs';
|
||||||
|
|
||||||
function b64ToUtf8(str) {
|
function b64ToUtf8(str) {
|
||||||
return decodeURIComponent(escape(window.atob(str)));
|
return decodeURIComponent(escape(window.atob(str)));
|
||||||
@ -44,7 +45,7 @@ const contentLoaded = async function () {
|
|||||||
document.getElementsByTagName('body')[0].appendChild(div);
|
document.getElementsByTagName('body')[0].appendChild(div);
|
||||||
}
|
}
|
||||||
|
|
||||||
await mermaid2.registerExternalDiagrams([externalExample]);
|
await mermaid2.registerExternalDiagrams([externalExample, zenUml]);
|
||||||
mermaid2.initialize(graphObj.mermaid);
|
mermaid2.initialize(graphObj.mermaid);
|
||||||
await mermaid2.run();
|
await mermaid2.run();
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,9 @@
|
|||||||
<li>
|
<li>
|
||||||
<h2><a href="./state.html">State</a></h2>
|
<h2><a href="./state.html">State</a></h2>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<h2><a href="./zenuml.html">ZenUML</a></h2>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
53
demos/zenuml.html
Normal file
53
demos/zenuml.html
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||||
|
<title>Mermaid Zenuml Test Page</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>Zenuml demos</h1>
|
||||||
|
<pre class="mermaid">
|
||||||
|
zenuml
|
||||||
|
title Sync Messages (Design Pattern: Adapter)
|
||||||
|
@Starter(Client)
|
||||||
|
Adapter.interfaceMethod() {
|
||||||
|
translateParameter(parameter)
|
||||||
|
|
||||||
|
result = Implementation.implementationMethod()
|
||||||
|
|
||||||
|
translateResult()
|
||||||
|
return translatedResult
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
<pre class="mermaid">
|
||||||
|
zenuml
|
||||||
|
title Async Messages (SPA Authentication)
|
||||||
|
// ```
|
||||||
|
// GET https://${account.namespace}/authorize/?
|
||||||
|
// response_type=token
|
||||||
|
// &client_id=${account.clientId}
|
||||||
|
// &redirect_url=YOUR_CALLBACK_URL
|
||||||
|
// &state=VALUE_THAT_SURVIVES_REDIRECTS
|
||||||
|
// &scope=openid
|
||||||
|
// ```
|
||||||
|
Browser->Auth0: 1. initiate the authentication
|
||||||
|
Auth0->"Identity Provider": 2. OAuth2 / SAML, etc
|
||||||
|
"Identity Provider"->"Identity Provider": 3. user gets authenticated
|
||||||
|
Auth0->Browser: 4. redirect to ${YOUR_CALLBACK_URL}/#id_token=e68...
|
||||||
|
Browser->Auth0: 5. validate id_token and get user profile
|
||||||
|
Browser->"Your API": 6. call API sending JWT in Authorization header
|
||||||
|
"Your API"->"Your API": 7. validate token
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<script type="module">
|
||||||
|
import mermaid from './mermaid.esm.mjs';
|
||||||
|
import zenuml from './mermaid-zenuml.esm.mjs';
|
||||||
|
await mermaid.registerExternalDiagrams([zenuml]);
|
||||||
|
mermaid.initialize({
|
||||||
|
logLevel: 3,
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
BIN
docs/syntax/img/zenuml-participant-annotators.png
Normal file
BIN
docs/syntax/img/zenuml-participant-annotators.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 255 KiB |
472
docs/syntax/zenuml.md
Normal file
472
docs/syntax/zenuml.md
Normal file
@ -0,0 +1,472 @@
|
|||||||
|
> **Warning**
|
||||||
|
>
|
||||||
|
> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
|
||||||
|
>
|
||||||
|
> ## Please edit the corresponding file in [/packages/mermaid/src/docs/syntax/zenuml.md](../../packages/mermaid/src/docs/syntax/zenuml.md).
|
||||||
|
|
||||||
|
# ZenUML
|
||||||
|
|
||||||
|
> A Sequence diagram is an interaction diagram that shows how processes operate with one another and in what order.
|
||||||
|
|
||||||
|
Mermaid can render sequence diagrams with [ZenUML](https://zenuml.com). Note that ZenUML uses a different
|
||||||
|
syntax than the original Sequence Diagram in mermaid.
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
title Demo
|
||||||
|
Alice->John: Hello John, how are you?
|
||||||
|
John->Alice: Great!
|
||||||
|
Alice->John: See you later!
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
zenuml
|
||||||
|
title Demo
|
||||||
|
Alice->John: Hello John, how are you?
|
||||||
|
John->Alice: Great!
|
||||||
|
Alice->John: See you later!
|
||||||
|
```
|
||||||
|
|
||||||
|
## Syntax
|
||||||
|
|
||||||
|
### Participants
|
||||||
|
|
||||||
|
The participants can be defined implicitly as in the first example on this page. The participants or actors are
|
||||||
|
rendered in order of appearance in the diagram source text. Sometimes you might want to show the participants in a
|
||||||
|
different order than how they appear in the first message. It is possible to specify the actor's order of
|
||||||
|
appearance by doing the following:
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
title Declare participant (optional)
|
||||||
|
Bob
|
||||||
|
Alice
|
||||||
|
Alice->Bob: Hi Bob
|
||||||
|
Bob->Alice: Hi Alice
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
zenuml
|
||||||
|
title Declare participant (optional)
|
||||||
|
Bob
|
||||||
|
Alice
|
||||||
|
Alice->Bob: Hi Bob
|
||||||
|
Bob->Alice: Hi Alice
|
||||||
|
```
|
||||||
|
|
||||||
|
### Annotators
|
||||||
|
|
||||||
|
If you specifically want to use symbols instead of just rectangles with text you can do so by using the annotator syntax to declare participants as per below.
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
title Annotators
|
||||||
|
@Actor Alice
|
||||||
|
@Database Bob
|
||||||
|
Alice->Bob: Hi Bob
|
||||||
|
Bob->Alice: Hi Alice
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
zenuml
|
||||||
|
title Annotators
|
||||||
|
@Actor Alice
|
||||||
|
@Database Bob
|
||||||
|
Alice->Bob: Hi Bob
|
||||||
|
Bob->Alice: Hi Alice
|
||||||
|
```
|
||||||
|
|
||||||
|
Here are the available annotators:
|
||||||
|
![img.png](img/zenuml-participant-annotators.png)
|
||||||
|
|
||||||
|
### Aliases
|
||||||
|
|
||||||
|
The participants can have a convenient identifier and a descriptive label.
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
title Aliases
|
||||||
|
A as Alice
|
||||||
|
J as John
|
||||||
|
A->J: Hello John, how are you?
|
||||||
|
J->A: Great!
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
zenuml
|
||||||
|
title Aliases
|
||||||
|
A as Alice
|
||||||
|
J as John
|
||||||
|
A->J: Hello John, how are you?
|
||||||
|
J->A: Great!
|
||||||
|
```
|
||||||
|
|
||||||
|
## Messages
|
||||||
|
|
||||||
|
Messages can be one of:
|
||||||
|
|
||||||
|
1. Sync message
|
||||||
|
2. Async message
|
||||||
|
3. Creation message
|
||||||
|
4. Reply message
|
||||||
|
|
||||||
|
### Sync message
|
||||||
|
|
||||||
|
You can think of a sync (blocking) method in a programming language.
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
title Sync message
|
||||||
|
A.SyncMessage
|
||||||
|
A.SyncMessage(with, parameters) {
|
||||||
|
B.nestedSyncMessage()
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
zenuml
|
||||||
|
title Sync message
|
||||||
|
A.SyncMessage
|
||||||
|
A.SyncMessage(with, parameters) {
|
||||||
|
B.nestedSyncMessage()
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Async message
|
||||||
|
|
||||||
|
You can think of an async (non-blocking) method in a programming language.
|
||||||
|
Fire an event and forget about it.
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
title Async message
|
||||||
|
Alice->Bob: How are you?
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
zenuml
|
||||||
|
title Async message
|
||||||
|
Alice->Bob: How are you?
|
||||||
|
```
|
||||||
|
|
||||||
|
### Creation message
|
||||||
|
|
||||||
|
We use `new` keyword to create an object.
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
new A1
|
||||||
|
new A2(with, parameters)
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
zenuml
|
||||||
|
new A1
|
||||||
|
new A2(with, parameters)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Reply message
|
||||||
|
|
||||||
|
There are three ways to express a reply message:
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
// 1. assign a variable from a sync message.
|
||||||
|
a = A.SyncMessage()
|
||||||
|
|
||||||
|
// 1.1. optionally give the variable a type
|
||||||
|
SomeType a = A.SyncMessage()
|
||||||
|
|
||||||
|
// 2. use return keyword
|
||||||
|
A.SyncMessage() {
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. use @return or @reply annotator on an async message
|
||||||
|
@return
|
||||||
|
A->B: result
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
zenuml
|
||||||
|
// 1. assign a variable from a sync message.
|
||||||
|
a = A.SyncMessage()
|
||||||
|
|
||||||
|
// 1.1. optionally give the variable a type
|
||||||
|
SomeType a = A.SyncMessage()
|
||||||
|
|
||||||
|
// 2. use return keyword
|
||||||
|
A.SyncMessage() {
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. use @return or @reply annotator on an async message
|
||||||
|
@return
|
||||||
|
A->B: result
|
||||||
|
```
|
||||||
|
|
||||||
|
The third way `@return` is rarely used, but it is useful when you want to return to one level up.
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
title Reply message
|
||||||
|
Client->A.method() {
|
||||||
|
B.method() {
|
||||||
|
if(condition) {
|
||||||
|
return x1
|
||||||
|
// return early
|
||||||
|
@return
|
||||||
|
A->Client: x11
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return x2
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
zenuml
|
||||||
|
title Reply message
|
||||||
|
Client->A.method() {
|
||||||
|
B.method() {
|
||||||
|
if(condition) {
|
||||||
|
return x1
|
||||||
|
// return early
|
||||||
|
@return
|
||||||
|
A->Client: x11
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return x2
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Nesting
|
||||||
|
|
||||||
|
Sync messages and Creation messages are naturally nestable with `{}`.
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
A.method() {
|
||||||
|
B.nested_sync_method()
|
||||||
|
B->C: nested async message
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
zenuml
|
||||||
|
A.method() {
|
||||||
|
B.nested_sync_method()
|
||||||
|
B->C: nested async message
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Comments
|
||||||
|
|
||||||
|
It is possible to add comments to a sequence diagram with `// comment` syntax.
|
||||||
|
Comments will be rendered above the messages or fragments. Comments on other places
|
||||||
|
are ignored. Markdown is supported.
|
||||||
|
|
||||||
|
See the example below:
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
// a comment on a participant will not be rendered
|
||||||
|
BookService
|
||||||
|
// a comment on a message.
|
||||||
|
// **Markdown** is supported.
|
||||||
|
BookService.getBook()
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
zenuml
|
||||||
|
// a comment on a participant will not be rendered
|
||||||
|
BookService
|
||||||
|
// a comment on a message.
|
||||||
|
// **Markdown** is supported.
|
||||||
|
BookService.getBook()
|
||||||
|
```
|
||||||
|
|
||||||
|
## Loops
|
||||||
|
|
||||||
|
It is possible to express loops in a ZenUML diagram. This is done by any of the
|
||||||
|
following notations:
|
||||||
|
|
||||||
|
1. while
|
||||||
|
2. for
|
||||||
|
3. forEach, foreach
|
||||||
|
4. loop
|
||||||
|
|
||||||
|
```zenuml
|
||||||
|
while(condition) {
|
||||||
|
...statements...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
See the example below:
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
Alice->John: Hello John, how are you?
|
||||||
|
while(true) {
|
||||||
|
John->Alice: Great!
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
zenuml
|
||||||
|
Alice->John: Hello John, how are you?
|
||||||
|
while(true) {
|
||||||
|
John->Alice: Great!
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Alt
|
||||||
|
|
||||||
|
It is possible to express alternative paths in a sequence diagram. This is done by the notation
|
||||||
|
|
||||||
|
```zenuml
|
||||||
|
if(condition1) {
|
||||||
|
...statements...
|
||||||
|
} else if(condition2) {
|
||||||
|
...statements...
|
||||||
|
} else {
|
||||||
|
...statements...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
See the example below:
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
Alice->Bob: Hello Bob, how are you?
|
||||||
|
if(is_sick) {
|
||||||
|
Bob->Alice: Not so good :(
|
||||||
|
} else {
|
||||||
|
Bob->Alice: Feeling fresh like a daisy
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
zenuml
|
||||||
|
Alice->Bob: Hello Bob, how are you?
|
||||||
|
if(is_sick) {
|
||||||
|
Bob->Alice: Not so good :(
|
||||||
|
} else {
|
||||||
|
Bob->Alice: Feeling fresh like a daisy
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Opt
|
||||||
|
|
||||||
|
It is possible to render an `opt` fragment. This is done by the notation
|
||||||
|
|
||||||
|
```zenuml
|
||||||
|
opt {
|
||||||
|
...statements...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
See the example below:
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
Alice->Bob: Hello Bob, how are you?
|
||||||
|
Bob->Alice: Not so good :(
|
||||||
|
opt {
|
||||||
|
Bob->Alice: Thanks for asking
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
zenuml
|
||||||
|
Alice->Bob: Hello Bob, how are you?
|
||||||
|
Bob->Alice: Not so good :(
|
||||||
|
opt {
|
||||||
|
Bob->Alice: Thanks for asking
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parallel
|
||||||
|
|
||||||
|
It is possible to show actions that are happening in parallel.
|
||||||
|
|
||||||
|
This is done by the notation
|
||||||
|
|
||||||
|
```zenuml
|
||||||
|
par {
|
||||||
|
statement1
|
||||||
|
statement2
|
||||||
|
statement3
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
See the example below:
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
par {
|
||||||
|
Alice->Bob: Hello guys!
|
||||||
|
Alice->John: Hello guys!
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
zenuml
|
||||||
|
par {
|
||||||
|
Alice->Bob: Hello guys!
|
||||||
|
Alice->John: Hello guys!
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Try/Catch/Finally (Break)
|
||||||
|
|
||||||
|
It is possible to indicate a stop of the sequence within the flow (usually used to model exceptions).
|
||||||
|
|
||||||
|
This is done by the notation
|
||||||
|
|
||||||
|
try {
|
||||||
|
...statements...
|
||||||
|
} catch {
|
||||||
|
...statements...
|
||||||
|
} finally {
|
||||||
|
...statements...
|
||||||
|
}
|
||||||
|
|
||||||
|
See the example below:
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
try {
|
||||||
|
Consumer->API: Book something
|
||||||
|
API->BookingService: Start booking process
|
||||||
|
} catch {
|
||||||
|
API->Consumer: show failure
|
||||||
|
} finally {
|
||||||
|
API->BookingService: rollback status
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
zenuml
|
||||||
|
try {
|
||||||
|
Consumer->API: Book something
|
||||||
|
API->BookingService: Start booking process
|
||||||
|
} catch {
|
||||||
|
API->Consumer: show failure
|
||||||
|
} finally {
|
||||||
|
API->BookingService: rollback status
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Integrating with your library/website.
|
||||||
|
|
||||||
|
Zenuml uses the experimental lazy loading & async rendering features which could change in the future.
|
||||||
|
|
||||||
|
You can use this method to add mermaid including the zenuml diagram to a web page:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<script type="module">
|
||||||
|
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
|
||||||
|
import zenuml from 'https://cdn.jsdelivr.net/npm/@mermaid-js/mermaid-zenuml@0.1.0/dist/mermaid-zenuml.esm.min.mjs';
|
||||||
|
await mermaid.registerExternalDiagrams([zenuml]);
|
||||||
|
</script>
|
||||||
|
```
|
@ -18,7 +18,7 @@
|
|||||||
"build:vite": "ts-node-esm --transpileOnly .vite/build.ts",
|
"build:vite": "ts-node-esm --transpileOnly .vite/build.ts",
|
||||||
"build:mermaid": "pnpm build:vite --mermaid",
|
"build:mermaid": "pnpm build:vite --mermaid",
|
||||||
"build:viz": "pnpm build:mermaid --visualize",
|
"build:viz": "pnpm build:mermaid --visualize",
|
||||||
"build:types": "tsc -p ./packages/mermaid/tsconfig.json --emitDeclarationOnly && tsc -p ./packages/mermaid-example-diagram/tsconfig.json --emitDeclarationOnly",
|
"build:types": "tsc -p ./packages/mermaid/tsconfig.json --emitDeclarationOnly && tsc -p ./packages/mermaid-zenuml/tsconfig.json --emitDeclarationOnly && tsc -p ./packages/mermaid-example-diagram/tsconfig.json --emitDeclarationOnly",
|
||||||
"build:watch": "pnpm build:vite --watch",
|
"build:watch": "pnpm build:vite --watch",
|
||||||
"build": "pnpm run -r clean && pnpm build:types && pnpm build:vite",
|
"build": "pnpm run -r clean && pnpm build:types && pnpm build:vite",
|
||||||
"dev": "concurrently \"pnpm build:vite --watch\" \"ts-node-esm .vite/server.ts\"",
|
"dev": "concurrently \"pnpm build:vite --watch\" \"ts-node-esm .vite/server.ts\"",
|
||||||
|
1
packages/mermaid-zenuml/README.md
Symbolic link
1
packages/mermaid-zenuml/README.md
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../mermaid/src/docs/syntax/zenuml.md
|
47
packages/mermaid-zenuml/package.json
Normal file
47
packages/mermaid-zenuml/package.json
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
{
|
||||||
|
"name": "@mermaid-js/mermaid-zenuml",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "MermaidJS plugin for ZenUML integration",
|
||||||
|
"module": "dist/mermaid-zenuml.core.mjs",
|
||||||
|
"types": "dist/detector.d.ts",
|
||||||
|
"type": "module",
|
||||||
|
"exports": {
|
||||||
|
".": {
|
||||||
|
"import": "./dist/mermaid-zenuml.core.mjs",
|
||||||
|
"types": "./dist/detector.d.ts"
|
||||||
|
},
|
||||||
|
"./*": "./*"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"diagram",
|
||||||
|
"markdown",
|
||||||
|
"zenuml",
|
||||||
|
"mermaid"
|
||||||
|
],
|
||||||
|
"scripts": {
|
||||||
|
"prepublishOnly": "pnpm -w run build"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/mermaid-js/mermaid",
|
||||||
|
"directory": "packages/mermaid-zenuml"
|
||||||
|
},
|
||||||
|
"contributors": [
|
||||||
|
"Peng Xiao (https://github.com/MrCoder)",
|
||||||
|
"Sidharth Vinod (https://sidharth.dev)",
|
||||||
|
"Dong Cai (https://github.com/dontry)"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@zenuml/core": "^3.0.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"mermaid": "workspace:^"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"mermaid": "workspace:>=10.0.0"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
]
|
||||||
|
}
|
21
packages/mermaid-zenuml/src/detector.ts
Normal file
21
packages/mermaid-zenuml/src/detector.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import type { ExternalDiagramDefinition } from 'mermaid';
|
||||||
|
|
||||||
|
const id = 'zenuml';
|
||||||
|
const regexp = /^\s*zenuml/;
|
||||||
|
|
||||||
|
const detector = (txt: string) => {
|
||||||
|
return txt.match(regexp) !== null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const loader = async () => {
|
||||||
|
const { diagram } = await import('./zenuml-definition.js');
|
||||||
|
return { id, diagram };
|
||||||
|
};
|
||||||
|
|
||||||
|
const plugin: ExternalDiagramDefinition = {
|
||||||
|
id,
|
||||||
|
detector,
|
||||||
|
loader,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default plugin;
|
58
packages/mermaid-zenuml/src/mermaidUtils.ts
Normal file
58
packages/mermaid-zenuml/src/mermaidUtils.ts
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import type { MermaidConfig } from 'mermaid';
|
||||||
|
|
||||||
|
const warning = (s: string) => {
|
||||||
|
// Todo remove debug code
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error('Log function was called before initialization', s);
|
||||||
|
};
|
||||||
|
|
||||||
|
export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
||||||
|
|
||||||
|
export const LEVELS: Record<LogLevel, number> = {
|
||||||
|
trace: 0,
|
||||||
|
debug: 1,
|
||||||
|
info: 2,
|
||||||
|
warn: 3,
|
||||||
|
error: 4,
|
||||||
|
fatal: 5,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const log: Record<keyof typeof LEVELS, typeof console.log> = {
|
||||||
|
trace: warning,
|
||||||
|
debug: warning,
|
||||||
|
info: warning,
|
||||||
|
warn: warning,
|
||||||
|
error: warning,
|
||||||
|
fatal: warning,
|
||||||
|
};
|
||||||
|
|
||||||
|
export let setLogLevel: (level: keyof typeof LEVELS | number | string) => void;
|
||||||
|
export let getConfig: () => MermaidConfig;
|
||||||
|
export let sanitizeText: (str: string) => string;
|
||||||
|
// eslint-disable @typescript-eslint/no-explicit-any
|
||||||
|
export let setupGraphViewbox: (
|
||||||
|
graph: any,
|
||||||
|
svgElem: any,
|
||||||
|
padding: any,
|
||||||
|
useMaxWidth: boolean
|
||||||
|
) => void;
|
||||||
|
|
||||||
|
export const injectUtils = (
|
||||||
|
_log: Record<keyof typeof LEVELS, typeof console.log>,
|
||||||
|
_setLogLevel: any,
|
||||||
|
_getConfig: any,
|
||||||
|
_sanitizeText: any,
|
||||||
|
_setupGraphViewbox: any
|
||||||
|
) => {
|
||||||
|
_log.info('Mermaid utils injected');
|
||||||
|
log.trace = _log.trace;
|
||||||
|
log.debug = _log.debug;
|
||||||
|
log.info = _log.info;
|
||||||
|
log.warn = _log.warn;
|
||||||
|
log.error = _log.error;
|
||||||
|
log.fatal = _log.fatal;
|
||||||
|
setLogLevel = _setLogLevel;
|
||||||
|
getConfig = _getConfig;
|
||||||
|
sanitizeText = _sanitizeText;
|
||||||
|
setupGraphViewbox = _setupGraphViewbox;
|
||||||
|
};
|
12
packages/mermaid-zenuml/src/parser.ts
Normal file
12
packages/mermaid-zenuml/src/parser.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* ZenUML manage parsing internally. It uses Antlr4 to parse the DSL.
|
||||||
|
* The parser is defined in https://github.com/ZenUml/vue-sequence/blob/main/src/parser/index.js
|
||||||
|
*
|
||||||
|
* This is a dummy parser that satisfies the mermaid API logic.
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
parser: { yy: {} },
|
||||||
|
parse: () => {
|
||||||
|
// no op
|
||||||
|
},
|
||||||
|
};
|
17
packages/mermaid-zenuml/src/zenuml-definition.ts
Normal file
17
packages/mermaid-zenuml/src/zenuml-definition.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { injectUtils } from './mermaidUtils.js';
|
||||||
|
import parser from './parser.js';
|
||||||
|
import renderer from './zenumlRenderer.js';
|
||||||
|
|
||||||
|
export const diagram = {
|
||||||
|
db: {
|
||||||
|
clear: () => {
|
||||||
|
// no-op
|
||||||
|
},
|
||||||
|
},
|
||||||
|
renderer,
|
||||||
|
parser,
|
||||||
|
styles: () => {
|
||||||
|
// no-op
|
||||||
|
},
|
||||||
|
injectUtils,
|
||||||
|
};
|
68
packages/mermaid-zenuml/src/zenumlRenderer.ts
Normal file
68
packages/mermaid-zenuml/src/zenumlRenderer.ts
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import { getConfig, log } from './mermaidUtils.js';
|
||||||
|
import ZenUml from '@zenuml/core';
|
||||||
|
|
||||||
|
const regexp = /^\s*zenuml/;
|
||||||
|
|
||||||
|
// Create a Zen UML container outside the svg first for rendering, otherwise the Zen UML diagram cannot be rendered properly
|
||||||
|
function createTemporaryZenumlContainer(id: string) {
|
||||||
|
const container = document.createElement('div');
|
||||||
|
container.id = `container-${id}`;
|
||||||
|
container.style.display = 'flex';
|
||||||
|
container.innerHTML = `<div id="zenUMLApp-${id}"></div>`;
|
||||||
|
const app = container.querySelector(`#zenUMLApp-${id}`) as HTMLElement;
|
||||||
|
return { container, app };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a foreignObject to wrap the Zen UML container in the svg
|
||||||
|
function createForeignObject(id: string) {
|
||||||
|
const foreignObject = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
|
||||||
|
foreignObject.setAttribute('x', '0');
|
||||||
|
foreignObject.setAttribute('y', '0');
|
||||||
|
foreignObject.setAttribute('width', '100%');
|
||||||
|
foreignObject.setAttribute('height', '100%');
|
||||||
|
const { container, app } = createTemporaryZenumlContainer(id);
|
||||||
|
foreignObject.appendChild(container);
|
||||||
|
return { foreignObject, container, app };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws a Zen UML in the tag with id: id based on the graph definition in text.
|
||||||
|
*
|
||||||
|
* @param text - The text of the diagram
|
||||||
|
* @param id - The id of the diagram which will be used as a DOM element id¨
|
||||||
|
*/
|
||||||
|
export const draw = async function (text: string, id: string) {
|
||||||
|
log.info('draw with Zen UML renderer', ZenUml);
|
||||||
|
|
||||||
|
text = text.replace(regexp, '');
|
||||||
|
const { securityLevel } = getConfig();
|
||||||
|
// Handle root and Document for when rendering in sandbox mode
|
||||||
|
let sandboxElement: HTMLIFrameElement | null = null;
|
||||||
|
if (securityLevel === 'sandbox') {
|
||||||
|
sandboxElement = document.getElementById('i' + id) as HTMLIFrameElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
const root = securityLevel === 'sandbox' ? sandboxElement?.contentWindow?.document : document;
|
||||||
|
|
||||||
|
const svgContainer = root?.querySelector(`svg#${id}`);
|
||||||
|
|
||||||
|
if (!root || !svgContainer) {
|
||||||
|
log.error('Cannot find root or svgContainer');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { foreignObject, container, app } = createForeignObject(id);
|
||||||
|
svgContainer.appendChild(foreignObject);
|
||||||
|
// @ts-expect-error @zenuml/core@3.0.0 exports the wrong type for ZenUml
|
||||||
|
const zenuml = new ZenUml(app);
|
||||||
|
// default is a theme name. More themes to be added and will be configurable in the future
|
||||||
|
await zenuml.render(text, 'theme-mermaid');
|
||||||
|
|
||||||
|
const { width, height } = window.getComputedStyle(container);
|
||||||
|
log.debug('zenuml diagram size', width, height);
|
||||||
|
svgContainer.setAttribute('style', `width: ${width}; height: ${height};`);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
draw,
|
||||||
|
};
|
9
packages/mermaid-zenuml/tsconfig.json
Normal file
9
packages/mermaid-zenuml/tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"rootDir": "./src",
|
||||||
|
"outDir": "./dist"
|
||||||
|
},
|
||||||
|
"include": ["./src/**/*.ts"],
|
||||||
|
"typeRoots": ["./src/types"]
|
||||||
|
}
|
@ -121,6 +121,7 @@ function sidebarSyntax() {
|
|||||||
{ text: 'C4C Diagram (Context) Diagram 🦺⚠️', link: '/syntax/c4c' },
|
{ text: 'C4C Diagram (Context) Diagram 🦺⚠️', link: '/syntax/c4c' },
|
||||||
{ text: 'Mindmaps 🔥', link: '/syntax/mindmap' },
|
{ text: 'Mindmaps 🔥', link: '/syntax/mindmap' },
|
||||||
{ text: 'Timeline 🔥', link: '/syntax/timeline' },
|
{ text: 'Timeline 🔥', link: '/syntax/timeline' },
|
||||||
|
{ text: 'Zenuml 🔥', link: '/syntax/zenuml' },
|
||||||
{ text: 'Other Examples', link: '/syntax/examples' },
|
{ text: 'Other Examples', link: '/syntax/examples' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
import mermaid, { type MermaidConfig } from 'mermaid';
|
import mermaid, { type MermaidConfig } from 'mermaid';
|
||||||
|
import zenuml from '../../../../../mermaid-zenuml/dist/mermaid-zenuml.core.mjs';
|
||||||
|
|
||||||
|
const init = mermaid.registerExternalDiagrams([zenuml]);
|
||||||
|
|
||||||
export const render = async (id: string, code: string, config: MermaidConfig): Promise<string> => {
|
export const render = async (id: string, code: string, config: MermaidConfig): Promise<string> => {
|
||||||
|
await init;
|
||||||
mermaid.initialize(config);
|
mermaid.initialize(config);
|
||||||
const { svg } = await mermaid.render(id, code);
|
const { svg } = await mermaid.render(id, code);
|
||||||
return svg;
|
return svg;
|
||||||
|
Binary file not shown.
After Width: | Height: | Size: 255 KiB |
314
packages/mermaid/src/docs/syntax/zenuml.md
Normal file
314
packages/mermaid/src/docs/syntax/zenuml.md
Normal file
@ -0,0 +1,314 @@
|
|||||||
|
# ZenUML
|
||||||
|
|
||||||
|
> A Sequence diagram is an interaction diagram that shows how processes operate with one another and in what order.
|
||||||
|
|
||||||
|
Mermaid can render sequence diagrams with [ZenUML](https://zenuml.com). Note that ZenUML uses a different
|
||||||
|
syntax than the original Sequence Diagram in mermaid.
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
title Demo
|
||||||
|
Alice->John: Hello John, how are you?
|
||||||
|
John->Alice: Great!
|
||||||
|
Alice->John: See you later!
|
||||||
|
```
|
||||||
|
|
||||||
|
## Syntax
|
||||||
|
|
||||||
|
### Participants
|
||||||
|
|
||||||
|
The participants can be defined implicitly as in the first example on this page. The participants or actors are
|
||||||
|
rendered in order of appearance in the diagram source text. Sometimes you might want to show the participants in a
|
||||||
|
different order than how they appear in the first message. It is possible to specify the actor's order of
|
||||||
|
appearance by doing the following:
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
title Declare participant (optional)
|
||||||
|
Bob
|
||||||
|
Alice
|
||||||
|
Alice->Bob: Hi Bob
|
||||||
|
Bob->Alice: Hi Alice
|
||||||
|
```
|
||||||
|
|
||||||
|
### Annotators
|
||||||
|
|
||||||
|
If you specifically want to use symbols instead of just rectangles with text you can do so by using the annotator syntax to declare participants as per below.
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
title Annotators
|
||||||
|
@Actor Alice
|
||||||
|
@Database Bob
|
||||||
|
Alice->Bob: Hi Bob
|
||||||
|
Bob->Alice: Hi Alice
|
||||||
|
```
|
||||||
|
|
||||||
|
Here are the available annotators:
|
||||||
|
![img.png](img/zenuml-participant-annotators.png)
|
||||||
|
|
||||||
|
### Aliases
|
||||||
|
|
||||||
|
The participants can have a convenient identifier and a descriptive label.
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
title Aliases
|
||||||
|
A as Alice
|
||||||
|
J as John
|
||||||
|
A->J: Hello John, how are you?
|
||||||
|
J->A: Great!
|
||||||
|
```
|
||||||
|
|
||||||
|
## Messages
|
||||||
|
|
||||||
|
Messages can be one of:
|
||||||
|
|
||||||
|
1. Sync message
|
||||||
|
2. Async message
|
||||||
|
3. Creation message
|
||||||
|
4. Reply message
|
||||||
|
|
||||||
|
### Sync message
|
||||||
|
|
||||||
|
You can think of a sync (blocking) method in a programming language.
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
title Sync message
|
||||||
|
A.SyncMessage
|
||||||
|
A.SyncMessage(with, parameters) {
|
||||||
|
B.nestedSyncMessage()
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Async message
|
||||||
|
|
||||||
|
You can think of an async (non-blocking) method in a programming language.
|
||||||
|
Fire an event and forget about it.
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
title Async message
|
||||||
|
Alice->Bob: How are you?
|
||||||
|
```
|
||||||
|
|
||||||
|
### Creation message
|
||||||
|
|
||||||
|
We use `new` keyword to create an object.
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
new A1
|
||||||
|
new A2(with, parameters)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Reply message
|
||||||
|
|
||||||
|
There are three ways to express a reply message:
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
// 1. assign a variable from a sync message.
|
||||||
|
a = A.SyncMessage()
|
||||||
|
|
||||||
|
// 1.1. optionally give the variable a type
|
||||||
|
SomeType a = A.SyncMessage()
|
||||||
|
|
||||||
|
// 2. use return keyword
|
||||||
|
A.SyncMessage() {
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. use @return or @reply annotator on an async message
|
||||||
|
@return
|
||||||
|
A->B: result
|
||||||
|
```
|
||||||
|
|
||||||
|
The third way `@return` is rarely used, but it is useful when you want to return to one level up.
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
title Reply message
|
||||||
|
Client->A.method() {
|
||||||
|
B.method() {
|
||||||
|
if(condition) {
|
||||||
|
return x1
|
||||||
|
// return early
|
||||||
|
@return
|
||||||
|
A->Client: x11
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return x2
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Nesting
|
||||||
|
|
||||||
|
Sync messages and Creation messages are naturally nestable with `{}`.
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
A.method() {
|
||||||
|
B.nested_sync_method()
|
||||||
|
B->C: nested async message
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Comments
|
||||||
|
|
||||||
|
It is possible to add comments to a sequence diagram with `// comment` syntax.
|
||||||
|
Comments will be rendered above the messages or fragments. Comments on other places
|
||||||
|
are ignored. Markdown is supported.
|
||||||
|
|
||||||
|
See the example below:
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
// a comment on a participant will not be rendered
|
||||||
|
BookService
|
||||||
|
// a comment on a message.
|
||||||
|
// **Markdown** is supported.
|
||||||
|
BookService.getBook()
|
||||||
|
```
|
||||||
|
|
||||||
|
## Loops
|
||||||
|
|
||||||
|
It is possible to express loops in a ZenUML diagram. This is done by any of the
|
||||||
|
following notations:
|
||||||
|
|
||||||
|
1. while
|
||||||
|
2. for
|
||||||
|
3. forEach, foreach
|
||||||
|
4. loop
|
||||||
|
|
||||||
|
```zenuml
|
||||||
|
while(condition) {
|
||||||
|
...statements...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
See the example below:
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
Alice->John: Hello John, how are you?
|
||||||
|
while(true) {
|
||||||
|
John->Alice: Great!
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Alt
|
||||||
|
|
||||||
|
It is possible to express alternative paths in a sequence diagram. This is done by the notation
|
||||||
|
|
||||||
|
```zenuml
|
||||||
|
if(condition1) {
|
||||||
|
...statements...
|
||||||
|
} else if(condition2) {
|
||||||
|
...statements...
|
||||||
|
} else {
|
||||||
|
...statements...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
See the example below:
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
Alice->Bob: Hello Bob, how are you?
|
||||||
|
if(is_sick) {
|
||||||
|
Bob->Alice: Not so good :(
|
||||||
|
} else {
|
||||||
|
Bob->Alice: Feeling fresh like a daisy
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Opt
|
||||||
|
|
||||||
|
It is possible to render an `opt` fragment. This is done by the notation
|
||||||
|
|
||||||
|
```zenuml
|
||||||
|
opt {
|
||||||
|
...statements...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
See the example below:
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
Alice->Bob: Hello Bob, how are you?
|
||||||
|
Bob->Alice: Not so good :(
|
||||||
|
opt {
|
||||||
|
Bob->Alice: Thanks for asking
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parallel
|
||||||
|
|
||||||
|
It is possible to show actions that are happening in parallel.
|
||||||
|
|
||||||
|
This is done by the notation
|
||||||
|
|
||||||
|
```zenuml
|
||||||
|
par {
|
||||||
|
statement1
|
||||||
|
statement2
|
||||||
|
statement3
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
See the example below:
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
par {
|
||||||
|
Alice->Bob: Hello guys!
|
||||||
|
Alice->John: Hello guys!
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Try/Catch/Finally (Break)
|
||||||
|
|
||||||
|
It is possible to indicate a stop of the sequence within the flow (usually used to model exceptions).
|
||||||
|
|
||||||
|
This is done by the notation
|
||||||
|
|
||||||
|
```
|
||||||
|
try {
|
||||||
|
...statements...
|
||||||
|
} catch {
|
||||||
|
...statements...
|
||||||
|
} finally {
|
||||||
|
...statements...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
See the example below:
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
zenuml
|
||||||
|
try {
|
||||||
|
Consumer->API: Book something
|
||||||
|
API->BookingService: Start booking process
|
||||||
|
} catch {
|
||||||
|
API->Consumer: show failure
|
||||||
|
} finally {
|
||||||
|
API->BookingService: rollback status
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Integrating with your library/website.
|
||||||
|
|
||||||
|
Zenuml uses the experimental lazy loading & async rendering features which could change in the future.
|
||||||
|
|
||||||
|
You can use this method to add mermaid including the zenuml diagram to a web page:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<script type="module">
|
||||||
|
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
|
||||||
|
import zenuml from 'https://cdn.jsdelivr.net/npm/@mermaid-js/mermaid-zenuml@0.1.0/dist/mermaid-zenuml.esm.min.mjs';
|
||||||
|
await mermaid.registerExternalDiagrams([zenuml]);
|
||||||
|
</script>
|
||||||
|
```
|
@ -70,7 +70,6 @@ export const setupGraphViewbox = function (graph, svgElem, padding, useMaxWidth)
|
|||||||
height = sHeight + padding * 2;
|
height = sHeight + padding * 2;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// width =
|
|
||||||
log.info(`Calculated bounds: ${width}x${height}`);
|
log.info(`Calculated bounds: ${width}x${height}`);
|
||||||
configureSvgSize(svgElem, height, width, useMaxWidth);
|
configureSvgSize(svgElem, height, width, useMaxWidth);
|
||||||
|
|
||||||
|
586
pnpm-lock.yaml
generated
586
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user