@@ -140,7 +140,7 @@ export class NavbarComponent extends Component<
140140 < DropdownButton
141141 class = ""
142142 mainBgColorClass = "bg-slate-500"
143- bgColorClasses = "bg-slate-500 hover:bg-slate-600 "
143+ bgColorClasses = "bg-slate-500 "
144144 textColorClasses = "text-white"
145145 caption = "Export"
146146 onClick = { ( ) => {
@@ -153,6 +153,12 @@ export class NavbarComponent extends Component<
153153 this . export ( true ) ;
154154 } ,
155155 } ,
156+ {
157+ caption : 'Export as mermaid' ,
158+ onClick : ( ) => {
159+ this . exportToMermaid ( ) ;
160+ } ,
161+ } ,
156162 ] }
157163 /> ,
158164 this . exportButton
@@ -438,6 +444,47 @@ export class NavbarComponent extends Component<
438444 ) ;
439445 } ;
440446
447+ exportToMermaid = ( ) => {
448+ const canvasApp = this . props . getCanvasApp ( ) ;
449+ if ( ! canvasApp ) {
450+ return ;
451+ }
452+ const data = serializeElementsMap ( canvasApp . elements ) ;
453+ // const compositions = serializeCompositions<NodeInfo>(
454+ // canvasApp.compositons.getAllCompositions()
455+ // );
456+
457+ let mermaid = 'flowchart TD\n' ;
458+ for ( const node of data ) {
459+ if ( node . nodeType === 'Shape' ) {
460+ let isNodeExported = false ;
461+ data . forEach ( ( n ) => {
462+ if ( n . nodeType === 'Connection' ) {
463+ const connection = n ;
464+ if ( connection . startNodeId === node . id && connection . endNodeId ) {
465+ const endNode = data . find ( ( n ) => n . id === connection . endNodeId ) ;
466+ if ( endNode ) {
467+ isNodeExported = true ;
468+ mermaid += ` ${ node . id } [${ node . nodeInfo ?. type } ] --> ${ endNode ?. id } [${ endNode . nodeInfo ?. type } ]\n` ;
469+ }
470+ }
471+ }
472+ } ) ;
473+ if ( ! isNodeExported ) {
474+ mermaid += ` ${ node . id } [${ node . nodeInfo ?. type } ]\n` ;
475+ }
476+ }
477+ }
478+
479+ saveFile (
480+ mermaid ,
481+ 'vps-flow' ,
482+ 'text/vnd.mermaid' ,
483+ '.mermaid' ,
484+ 'vps-flow-mermaid'
485+ ) ;
486+ } ;
487+
441488 onClickImport = ( event : Event ) => {
442489 event . preventDefault ( ) ;
443490 const input = document . createElement ( 'input' ) as HTMLInputElement & {
0 commit comments