@@ -9,7 +9,16 @@ export enum ControlSignal {
99 Retry ,
1010 Exit ,
1111 Back ,
12- Continue ,
12+ Skip ,
13+ }
14+
15+ /**
16+ * Value for indicating current direction of the wizard
17+ * Created mainly to support skipping prompters
18+ */
19+ export enum DIRECTON {
20+ Forward ,
21+ Backward ,
1322}
1423
1524export interface StepResult < TState > {
@@ -39,9 +48,11 @@ export class StateMachineController<TState> {
3948 private extraSteps = new Map < number , Branch < TState > > ( )
4049 private steps : Branch < TState > = [ ]
4150 private internalStep : number = 0
51+ private direction : DIRECTON
4252
4353 public constructor ( private state : TState = { } as TState ) {
4454 this . previousStates = [ _ . cloneDeep ( state ) ]
55+ this . direction = DIRECTON . Forward
4556 }
4657
4758 public addStep ( step : StepFunction < TState > ) : void {
@@ -71,12 +82,14 @@ export class StateMachineController<TState> {
7182
7283 this . state = this . previousStates . pop ( ) !
7384 this . internalStep -= 1
85+ this . direction = DIRECTON . Backward
7486 }
7587
7688 protected advanceState ( nextState : TState ) : void {
7789 this . previousStates . push ( this . state )
7890 this . state = nextState
7991 this . internalStep += 1
92+ this . direction = DIRECTON . Forward
8093 }
8194
8295 protected detectCycle ( step : StepFunction < TState > ) : TState | undefined {
@@ -105,6 +118,12 @@ export class StateMachineController<TState> {
105118 }
106119
107120 if ( isMachineResult ( result ) ) {
121+ if ( result . controlSignal === ControlSignal . Skip ) {
122+ /**
123+ * Depending on current wizard direction, skip signal get converted to forward or backward control signal
124+ */
125+ result . controlSignal = this . direction === DIRECTON . Forward ? undefined : ControlSignal . Back
126+ }
108127 return result
109128 } else {
110129 return { nextState : result }
0 commit comments