@@ -48,22 +48,22 @@ export class MermaidState {
48
48
transitions . push ( ...this . dataConditionsTransitions ( ) ) ;
49
49
transitions . push ( ...this . eventConditionsTransition ( ) ) ;
50
50
transitions . push ( ...this . errorTransitions ( ) ) ;
51
- transitions . push ( ...this . naturalTransition ( this . stateName ( ) , this . state . transition ) ) ;
51
+ transitions . push ( ...this . naturalTransition ( this . stateKeyDiagram ( this . state . name ) , this . state . transition ) ) ;
52
52
transitions . push ( ...this . endTransition ( ) ) ;
53
53
54
54
return transitions . reduce ( ( p , c ) => {
55
55
return p + '\n' + c ;
56
56
} ) ;
57
57
}
58
58
59
- private stateName ( ) {
60
- return this . state . name ?. replace ( ' ' , '_' ) ;
59
+ private stateKeyDiagram ( name : string | undefined ) {
60
+ return name ?. replace ( / / g , '_' ) ;
61
61
}
62
62
63
63
private startTransition ( ) {
64
64
const transitions : string [ ] = [ ] ;
65
65
if ( this . isFirstState ) {
66
- const stateName = this . stateName ( ) ;
66
+ const stateName = this . stateKeyDiagram ( this . state . name ) ;
67
67
transitions . push ( this . transitionDescription ( '[*]' , stateName ) ) ;
68
68
}
69
69
return transitions ;
@@ -74,7 +74,7 @@ export class MermaidState {
74
74
75
75
const dataBasedSwitchState = this . state as Specification . Databasedswitch ;
76
76
if ( dataBasedSwitchState . dataConditions ) {
77
- const stateName = this . stateName ( ) ;
77
+ const stateName = this . state . name ;
78
78
dataBasedSwitchState . dataConditions . forEach ( ( dataCondition ) => {
79
79
const transitionDataCondition = dataCondition as Specification . Transitiondatacondition ;
80
80
@@ -98,7 +98,7 @@ export class MermaidState {
98
98
99
99
const eventBasedSwitchState = this . state as Specification . Eventbasedswitch ;
100
100
if ( eventBasedSwitchState . eventConditions ) {
101
- const stateName = this . stateName ( ) ;
101
+ const stateName = this . state . name ;
102
102
eventBasedSwitchState . eventConditions . forEach ( ( eventCondition ) => {
103
103
const transitionEventCondition = eventCondition as Specification . Transitioneventcondition ;
104
104
@@ -121,7 +121,7 @@ export class MermaidState {
121
121
const transitions : string [ ] = [ ] ;
122
122
123
123
if ( state . defaultCondition ) {
124
- transitions . push ( ...this . naturalTransition ( this . stateName ( ) , state . defaultCondition . transition , 'default' ) ) ;
124
+ transitions . push ( ...this . naturalTransition ( this . state . name , state . defaultCondition . transition , 'default' ) ) ;
125
125
}
126
126
return transitions ;
127
127
}
@@ -130,7 +130,7 @@ export class MermaidState {
130
130
const transitions : string [ ] = [ ] ;
131
131
132
132
if ( this . state . end ) {
133
- const stateName = this . stateName ( ) ;
133
+ const stateName = this . state . name ;
134
134
let transitionLabel = undefined ;
135
135
136
136
if ( isObject ( this . state . end ) ) {
@@ -147,20 +147,20 @@ export class MermaidState {
147
147
}
148
148
149
149
private naturalTransition (
150
- start ?: string ,
151
- end ?: string | Specification . Transition ,
150
+ source ?: string ,
151
+ target ?: string | Specification . Transition ,
152
152
label : string | undefined = undefined
153
153
) {
154
154
const transitions : string [ ] = [ ] ;
155
155
156
- if ( end ) {
156
+ if ( target ) {
157
157
let descTransition = '' ;
158
- if ( isObject ( end ) ) {
159
- descTransition = ( end as Specification . Transition ) . nextState ;
160
- } else if ( typeof end === 'string' ) {
161
- descTransition = end ;
158
+ if ( isObject ( target ) ) {
159
+ descTransition = ( target as Specification . Transition ) . nextState ;
160
+ } else if ( typeof target === 'string' ) {
161
+ descTransition = target ;
162
162
}
163
- transitions . push ( this . transitionDescription ( start , descTransition , label ? label : undefined ) ) ;
163
+ transitions . push ( this . transitionDescription ( source , descTransition , label ? label : undefined ) ) ;
164
164
}
165
165
return transitions ;
166
166
}
@@ -170,7 +170,7 @@ export class MermaidState {
170
170
171
171
if ( this . state . onErrors ) {
172
172
this . state . onErrors . forEach ( ( error ) => {
173
- transitions . push ( ...this . naturalTransition ( this . stateName ( ) , error . transition , error . errorRef ) ) ;
173
+ transitions . push ( ...this . naturalTransition ( this . stateKeyDiagram ( this . state . name ) , error . transition , error . errorRef ) ) ;
174
174
} ) ;
175
175
}
176
176
return transitions ;
@@ -208,7 +208,7 @@ export class MermaidState {
208
208
209
209
private definitionType ( ) {
210
210
const type = this . state . type ;
211
- return this . stateDescription ( this . stateName ( ) , 'type' , type ! . charAt ( 0 ) . toUpperCase ( ) + type ! . slice ( 1 ) + ' State' ) ;
211
+ return this . stateDescription ( this . stateKeyDiagram ( this . state . name ) , 'type' , type ! . charAt ( 0 ) . toUpperCase ( ) + type ! . slice ( 1 ) + ' State' ) ;
212
212
}
213
213
214
214
private parallelStateDetails ( ) : string | undefined {
@@ -217,12 +217,12 @@ export class MermaidState {
217
217
const descriptions : string [ ] = [ ] ;
218
218
219
219
if ( parallelState . completionType ) {
220
- descriptions . push ( this . stateDescription ( this . stateName ( ) , 'Completion type' , parallelState . completionType ) ) ;
220
+ descriptions . push ( this . stateDescription ( this . stateKeyDiagram ( this . state . name ) , 'Completion type' , parallelState . completionType ) ) ;
221
221
}
222
222
223
223
if ( parallelState . branches ) {
224
224
descriptions . push (
225
- this . stateDescription ( this . stateName ( ) , 'Num. of branches' , parallelState . branches ?. length + '' )
225
+ this . stateDescription ( this . stateKeyDiagram ( this . state . name ) , 'Num. of branches' , parallelState . branches ?. length + '' )
226
226
) ;
227
227
}
228
228
@@ -234,11 +234,11 @@ export class MermaidState {
234
234
}
235
235
236
236
private eventBasedSwitchStateDetails ( ) {
237
- return this . stateDescription ( this . stateName ( ) , `Condition type` , `event-based` ) ;
237
+ return this . stateDescription ( this . stateKeyDiagram ( this . state . name ) , `Condition type` , `event-based` ) ;
238
238
}
239
239
240
240
private dataBasedSwitchStateDetails ( ) {
241
- return this . stateDescription ( this . stateName ( ) , `Condition type` , `data-based` ) ;
241
+ return this . stateDescription ( this . stateKeyDiagram ( this . state . name ) , `Condition type` , `data-based` ) ;
242
242
}
243
243
244
244
private operationStateDetails ( ) {
@@ -247,11 +247,11 @@ export class MermaidState {
247
247
const descriptions : string [ ] = [ ] ;
248
248
249
249
if ( state . actionMode ) {
250
- descriptions . push ( this . stateDescription ( this . stateName ( ) , 'Action mode' , state . actionMode ) ) ;
250
+ descriptions . push ( this . stateDescription ( this . stateKeyDiagram ( this . state . name ) , 'Action mode' , state . actionMode ) ) ;
251
251
}
252
252
253
253
if ( state . actions ) {
254
- descriptions . push ( this . stateDescription ( this . stateName ( ) , 'Num. of actions' , state . actions ?. length + '' ) ) ;
254
+ descriptions . push ( this . stateDescription ( this . stateKeyDiagram ( this . state . name ) , 'Num. of actions' , state . actions ?. length + '' ) ) ;
255
255
}
256
256
257
257
return descriptions . length > 0
@@ -264,7 +264,7 @@ export class MermaidState {
264
264
private sleepStateDetails ( ) {
265
265
const state = this . state as Specification . Sleepstate ;
266
266
if ( state . duration ) {
267
- return this . stateDescription ( this . stateName ( ) , 'Duration' , state . duration ) ;
267
+ return this . stateDescription ( this . stateKeyDiagram ( this . state . name ) , 'Duration' , state . duration ) ;
268
268
}
269
269
270
270
return undefined ;
@@ -276,11 +276,11 @@ export class MermaidState {
276
276
const descriptions : string [ ] = [ ] ;
277
277
278
278
if ( state . inputCollection ) {
279
- descriptions . push ( this . stateDescription ( this . stateName ( ) , 'Input collection' , state . inputCollection ) ) ;
279
+ descriptions . push ( this . stateDescription ( this . stateKeyDiagram ( this . state . name ) , 'Input collection' , state . inputCollection ) ) ;
280
280
}
281
281
282
282
if ( state . actions ) {
283
- descriptions . push ( this . stateDescription ( this . stateName ( ) , 'Num. of actions' , state . actions ?. length + '' ) ) ;
283
+ descriptions . push ( this . stateDescription ( this . stateKeyDiagram ( this . state . name ) , 'Num. of actions' , state . actions ?. length + '' ) ) ;
284
284
}
285
285
286
286
return descriptions . length > 0
@@ -303,11 +303,11 @@ export class MermaidState {
303
303
} else if ( typeof functionRef === 'string' ) {
304
304
functionRefDescription = functionRef as string ;
305
305
}
306
- descriptions . push ( this . stateDescription ( this . stateName ( ) , 'Callback function' , functionRefDescription ) ) ;
306
+ descriptions . push ( this . stateDescription ( this . stateKeyDiagram ( this . state . name ) , 'Callback function' , functionRefDescription ) ) ;
307
307
}
308
308
309
309
if ( state . eventRef ) {
310
- descriptions . push ( this . stateDescription ( this . stateName ( ) , 'Callback event' , state . eventRef ) ) ;
310
+ descriptions . push ( this . stateDescription ( this . stateKeyDiagram ( this . state . name ) , 'Callback event' , state . eventRef ) ) ;
311
311
}
312
312
313
313
return descriptions . length > 0
@@ -318,15 +318,15 @@ export class MermaidState {
318
318
}
319
319
320
320
private definitionName ( ) {
321
- return this . stateName ( ) + ' : ' + this . stateName ( ) ;
321
+ return this . stateKeyDiagram ( this . state . name ) + ' : ' + this . state . name ;
322
322
}
323
323
324
324
private transitionDescription (
325
- start : string | undefined ,
326
- end : string | undefined ,
325
+ source : string | undefined ,
326
+ target : string | undefined ,
327
327
label : string | undefined = undefined
328
328
) {
329
- return start + ' --> ' + end + ( label ? ' : ' + label : '' ) ;
329
+ return this . stateKeyDiagram ( source ) + ' --> ' + this . stateKeyDiagram ( target ) + ( label ? ' : ' + label : '' ) ;
330
330
}
331
331
332
332
private stateDescription ( stateName : string | undefined , description : string , value : string ) {
0 commit comments