Skip to content

Commit

Permalink
Setup
Browse files Browse the repository at this point in the history
  • Loading branch information
msyk committed Oct 1, 2022
1 parent 34d1d0d commit b6d0cc0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
34 changes: 21 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
* https://github.com/INTER-Mediator/INTER-Mediator/blob/master/dist-docs/License.txt
*/
IMParts_Catalog.mermaid = {
// https://github.com/mermaid-js/mermaid/blob/develop/docs/usage.md
options: {
startOnLoad: false
},

instanciate: function (parentNode) {
'use strict'
const classOfParent = parentNode.getAttribute('class')
if (classOfParent.indexOf('_im_widget_mermaid') < 0) {
const sp = classOfParent.length == 0 ? '' : ' '
if (!classOfParent || classOfParent.length == 0 || classOfParent.indexOf('_im_widget_mermaid') < 0) {
const sp = (classOfParent && classOfParent.length > 0) ? ' ' : ''
parentNode.setAttribute('class', `${classOfParent}${sp}_im_widget_mermaid`)
const node = document.createElement('DIV')
node.setAttribute('data-im-control', 'enclosure')
node.setAttribute('class', '_im_widget_mermaid_canvas')
const newId = parentNode.getAttribute('id') + '-popupsel'
const newId = parentNode.getAttribute('id') + '-mermaid'
node.setAttribute('id', newId)
parentNode.appendChild(node)
IMParts_Catalog.mermaid.ids.push(newId)
Expand All @@ -31,23 +34,28 @@ IMParts_Catalog.mermaid = {

parentNode._im_setValue = (function () {
const theId = newId
const target = node
return function (str) {
mermaidAPI.initialize({
startOnLoad: true,
});
$(function () {
mermaidAPI.render(theId, str, function (svgGraph) {
console.log(svgGraph);
});
});
IMParts_Catalog.mermaid.values[theId] = str
}
})()
}
},

ids: [],
values: [],

finish: function () {
'use strict'
mermaid.initialize(IMParts_Catalog.mermaid.options);
for (const id in IMParts_Catalog.mermaid.values) {
if (IMParts_Catalog.mermaid.values[id].length > 0) {
const node = document.getElementById(id)
const parent = node.parentNode
mermaid.mermaidAPI.render(id, IMParts_Catalog.mermaid.values[id], function (svgCode, bindFunctions) {
parent.innerHTML = svgCode
});
}
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "inter-mediator-plugin-mermaid",
"version": "1.0.0",
"version": "1.0.1",
"description": "INTER-Mediator plug-in for mermaid-js.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit b6d0cc0

Please sign in to comment.