Last active
October 29, 2020 18:24
-
-
Save paulovmr/40fbfbf689023840c4d6bd9e32889d44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const editor = DmnEditor.open({ | |
container: document.getElementById("dmn-editor-container"), | |
initialContent: Promise.resolve(""), | |
readOnly: false, | |
origin: "", | |
resources: new Map([ | |
[ | |
"MyIncludedModel.dmn", | |
{ | |
contentType: "text", | |
content: Promise.resolve("") | |
} | |
] | |
]) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<style> | |
#dmn-editor-container { | |
height: calc(100vh - 50px); | |
} | |
.toolbar { | |
height: 30px; | |
} | |
.hidden { | |
display: none; | |
} | |
</style> | |
<title></title> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<script src="https://kiegroup.github.io/kogito-online/standalone/dmn/index.js"></script> | |
</head> | |
<body> | |
<div class="toolbar"> | |
<span id="unsavedChanges" class="hidden">File contains unsaved changes.</span> | |
<button id="undo">Undo</button> | |
<button id="redo">Redo</button> | |
<button id="download">Download</button> | |
<button id="downloadSvg">Download SVG</button> | |
</div> | |
<div id="dmn-editor-container" /> | |
<script> | |
const editor = DmnEditor.open({ | |
container: document.getElementById("dmn-editor-container"), | |
initialContent: Promise.resolve(""), | |
readOnly: false | |
}); | |
document.getElementById("undo").addEventListener("click", () => { | |
editor.undo(); | |
}); | |
document.getElementById("redo").addEventListener("click", () => { | |
editor.redo(); | |
}); | |
document.getElementById("download").addEventListener("click", () => { | |
editor.getContent().then(content => { | |
const elem = window.document.createElement("a"); | |
elem.href = "data:text/plain;charset=utf-8," + encodeURIComponent(content); | |
elem.download = "model.dmn"; | |
document.body.appendChild(elem); | |
elem.click(); | |
document.body.removeChild(elem); | |
editor.markAsSaved(); | |
}); | |
}); | |
document.getElementById("downloadSvg").addEventListener("click", () => { | |
editor.getPreview().then(svgContent => { | |
const elem = window.document.createElement("a"); | |
elem.href = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(svgContent); | |
elem.download = "model.svg"; | |
document.body.appendChild(elem); | |
elem.click(); | |
document.body.removeChild(elem); | |
}); | |
}); | |
editor.subscribeToContentChanges(isDirty => { | |
if (isDirty) { | |
document.getElementById("unsavedChanges").classList.remove("hidden"); | |
} else { | |
document.getElementById("unsavedChanges").classList.add("hidden"); | |
} | |
}); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title></title> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<script src="https://kiegroup.github.io/kogito-online/standalone/dmn/index.js"></script> | |
</head> | |
<body> | |
<div class="toolbar"></div> | |
<div id="dmn-editor-container"></div> | |
<script><!-- Editor usage will go here. --></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="toolbar"> | |
<span id="unsavedChanges" class="hidden">File contains unsaved changes.</span> | |
<button id="undo">Undo</button> | |
<button id="redo">Redo</button> | |
<button id="download">Download</button> | |
<button id="downloadSvg">Download SVG</button> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const editor = DmnEditor.open({ | |
container: document.getElementById("dmn-editor-container"), | |
initialContent: Promise.resolve(""), | |
readOnly: false | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.getElementById("undo").addEventListener("click", () => { | |
editor.undo(); | |
}); | |
document.getElementById("redo").addEventListener("click", () => { | |
editor.redo(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.getElementById("download").addEventListener("click", () => { | |
editor.getContent().then(content => { | |
const elem = window.document.createElement("a"); | |
elem.href = "data:text/plain;charset=utf-8," + encodeURIComponent(content); | |
elem.download = "model.dmn"; | |
document.body.appendChild(elem); | |
elem.click(); | |
document.body.removeChild(elem); | |
editor.markAsSaved(); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.getElementById("downloadSvg").addEventListener("click", () => { | |
editor.getPreview().then(svgContent => { | |
const elem = window.document.createElement("a"); | |
elem.href = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(svgContent); | |
elem.download = "model.svg"; | |
document.body.appendChild(elem); | |
elem.click(); | |
document.body.removeChild(elem); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
editor.subscribeToContentChanges(isDirty => { | |
if (isDirty) { | |
document.getElementById("unsavedChanges").classList.remove("hidden"); | |
} else { | |
document.getElementById("unsavedChanges").classList.add("hidden"); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style> | |
#dmn-editor-container { | |
height: calc(100vh - 50px); | |
} | |
.toolbar { | |
height: 30px; | |
} | |
.hidden { | |
display: none; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment