Skip to content

Commit 7d510e5

Browse files
committed
feat: add Mermaid converter (wip)
Signed-off-by: Jean-Baptiste Bianchi <[email protected]>
1 parent 06e5a4a commit 7d510e5

File tree

4 files changed

+692
-0
lines changed

4 files changed

+692
-0
lines changed

examples/browser/mermaid.html

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!doctype html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<title>Serveless Workflow</title>
7+
<base href="/">
8+
<meta content="width=device-width, initial-scale=1" name="viewport">
9+
</head>
10+
11+
<body>
12+
<pre id="output"></pre>
13+
<script src="../../dist/umd/index.umd.js"></script>
14+
<pre class="mermaid" id="diagram-container"></div>
15+
<script type="module">
16+
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
17+
(() => {
18+
const { Classes, Specification, validate, convertToMermaidCode } = serverWorkflowSdk;
19+
const workflowDefinition = {
20+
document: {
21+
dsl: '1.0.0',
22+
name: 'using-plain-object',
23+
version: '1.0.0',
24+
namespace: 'default',
25+
},
26+
do: [
27+
{
28+
step1: {
29+
set: {
30+
variable: 'my first workflow',
31+
},
32+
},
33+
},
34+
],
35+
}/* as Specification.Workflow // <-- If you're using TypeScript*/;
36+
try {
37+
validate('Workflow', workflowDefinition);
38+
const diagramContainerEl = document.getElementById('diagram-container');
39+
const mermaidCode = convertToMermaidCode(workflowDefinition);
40+
diagramContainerEl.innerText = mermaidCode;
41+
document.getElementById('output').innerHTML = `--- YAML ---\n${Classes.Workflow.serialize(workflowDefinition)}\n\n--- JSON ---\n${Classes.Workflow.serialize(workflowDefinition, 'json')}\n\n--- MERMAID ---\n${mermaidCode}`;
42+
mermaid.initialize({ startOnLoad: true });
43+
}
44+
catch (ex) {
45+
console.error('Invalid workflow', ex);
46+
}
47+
})();
48+
</script>
49+
</body>
50+
51+
</html>

0 commit comments

Comments
 (0)