-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
81 lines (69 loc) · 2.41 KB
/
main.js
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
// main.js
const { convertToUML } = require('./mermaidParser');
const { convertToMermaid } = require('./umlProcessor');
const { generateUML } = require('./umlGenerator');
function aboutMermaid() {
app.dialogs.showInfoDialog(
"Mermaid Bridge is a plugin for StarUML that allows you \n" +
"to import and export UML diagrams using Mermaid syntax. \n" +
"For more information, visit: \n" +
"https://github.com/petervdpas/mermaid-bridge");
}
function importMermaid() {
app.dialogs.showTextDialog("Enter your Mermaid-diagram")
.then(async function ({ buttonId, returnValue }) {
if (buttonId === 'ok') {
var mermaidCode = returnValue;
if (mermaidCode) {
try {
var parsedDiagram = convertToUML(mermaidCode);
var diagramString = JSON.stringify(parsedDiagram, null, 2); // Convert to string with pretty formatting (2 spaces)
console.log("Parsed diagram (as string):", diagramString);
generateUML(parsedDiagram);
} catch (err) {
console.error(err);
app.toast.error(err || "An unknown error occurred.");
}
}
} else {
app.toast.info("Input was cancelled")
}
});
}
function exportToMermaid() {
try {
var selectedModels = app.selections.getSelectedModels()
if (selectedModels.length === 0) {
app.toast.info("No models selected");
return;
}
var selectedModel = selectedModels[0];
var mermaidCode = convertToMermaid(selectedModel);
if (!mermaidCode) {
app.toast.error("Could not convert model to Mermaid code or model type is unknown");
return;
}
app.dialogs.showTextDialog("Generated Mermaid Code:", mermaidCode);
}
catch (err) {
app.toast.error(err.message);
}
}
function init() {
app.commands.register(
"mermaid-bridge:about",
aboutMermaid,
"About Mermaid Bridge"
);
app.commands.register(
"mermaid-bridge:import",
importMermaid,
"Import from Mermaid"
);
app.commands.register(
"mermaid-bridge:export",
exportToMermaid,
"Export to Mermaid"
);
}
exports.init = init;