-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathmermaid.html
More file actions
128 lines (126 loc) · 4.04 KB
/
Copy pathmermaid.html
File metadata and controls
128 lines (126 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Open Workflow Specification ESM Mermaid Example</title>
<base href="/" />
<meta content="width=device-width, initial-scale=1" name="viewport" />
</head>
<body>
<p>YAML or JSON:</p>
<textarea id="input" rows="50" cols="100"></textarea>
<div id="diagram-container"></div>
<pre id="output"></pre>
<script type="module">
import { Classes, convertToMermaidCode } from '../../dist/index.mjs';
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
(async () => {
const workflowDefinition = {
document: {
dsl: '1.0.3',
namespace: 'examples',
name: 'accumulate-room-readings',
version: '0.1.0',
},
do: [
{
consumeReading: {
listen: {
to: {
all: [
{
with: {
source: 'https://my.home.com/sensor',
type: 'my.home.sensors.temperature',
},
correlate: {
roomId: {
from: '.roomid',
},
},
},
{
with: {
source: 'https://my.home.com/sensor',
type: 'my.home.sensors.humidity',
},
correlate: {
roomId: {
from: '.roomid',
},
},
},
],
},
},
output: {
as: '.data.reading',
},
},
},
{
logReading: {
for: {
each: 'reading',
in: '.readings',
},
do: [
{
callOrderService: {
call: 'openapi',
with: {
document: {
endpoint: 'http://myorg.io/ordersservices.json',
},
operationId: 'logreading',
},
},
},
],
},
},
{
generateReport: {
call: 'openapi',
with: {
document: {
endpoint: 'http://myorg.io/ordersservices.json',
},
operationId: 'produceReport',
},
},
},
],
timeout: {
after: {
hours: 1,
},
},
};
const diagramContainerEl = document.getElementById('diagram-container');
const inputTextarea = document.getElementById('input');
const processWorkflow = async () => {
try {
const workflow = Classes.Workflow.deserialize(inputTextarea.value);
const mermaidCode = convertToMermaidCode(workflow);
document.getElementById('output').innerHTML = `--- MERMAID ---\n${mermaidCode}`;
mermaid.initialize({ startOnLoad: false });
const { svg } = await mermaid.render('sw-diagram', mermaidCode);
diagramContainerEl.innerHTML = svg;
} catch (ex) {
console.error('Invalid workflow', ex);
}
};
let debounceHandle;
inputTextarea.addEventListener('keyup', () => {
if (debounceHandle) {
clearTimeout(debounceHandle);
}
debounceHandle = setTimeout(processWorkflow, 300);
});
inputTextarea.value = JSON.stringify(workflowDefinition, null, 4);
await processWorkflow();
})();
</script>
</body>
</html>