@@ -15,6 +15,7 @@ import {
15
15
ViewChild
16
16
} from '@angular/core' ;
17
17
import {
18
+ CustomActionHandler ,
18
19
Definition ,
19
20
Designer ,
20
21
DesignerExtension ,
@@ -25,6 +26,7 @@ import {
25
26
StepEditorProvider ,
26
27
StepsConfiguration ,
27
28
ToolboxConfiguration ,
29
+ UidGenerator ,
28
30
ValidatorConfiguration
29
31
} from 'sequential-workflow-designer' ;
30
32
@@ -70,6 +72,19 @@ export class DesignerComponent implements AfterViewInit, OnChanges, OnDestroy {
70
72
public contextMenu ?: boolean ;
71
73
@Input ( 'extensions' )
72
74
public extensions ?: DesignerExtension [ ] ;
75
+ @Input ( 'customActionHandler' )
76
+ public customActionHandler ?: CustomActionHandler ;
77
+ @Input ( 'isReadonly' )
78
+ public isReadonly ?: boolean ;
79
+ @Input ( 'selectedStepId' )
80
+ public selectedStepId ?: string | null ;
81
+ @Input ( 'uidGenerator' )
82
+ public uidGenerator ?: UidGenerator ;
83
+ @Input ( 'isToolboxCollapsed' )
84
+ public isToolboxCollapsed ?: boolean ;
85
+ @Input ( 'isEditorCollapsed' )
86
+ public isEditorCollapsed ?: boolean ;
87
+
73
88
@Input ( 'areEditorsHidden' )
74
89
public areEditorsHidden ?: boolean ;
75
90
@Input ( 'globalEditor' )
@@ -83,6 +98,10 @@ export class DesignerComponent implements AfterViewInit, OnChanges, OnDestroy {
83
98
public readonly onDefinitionChanged = new EventEmitter < Definition > ( ) ;
84
99
@Output ( )
85
100
public readonly onSelectedStepIdChanged = new EventEmitter < string | null > ( ) ;
101
+ @Output ( )
102
+ public readonly onIsToolboxCollapsedChanged = new EventEmitter < boolean > ( ) ;
103
+ @Output ( )
104
+ public readonly onIsEditorCollapsedChanged = new EventEmitter < boolean > ( ) ;
86
105
87
106
public constructor ( private readonly ngZone : NgZone , private readonly applicationRef : ApplicationRef ) { }
88
107
@@ -95,9 +114,37 @@ export class DesignerComponent implements AfterViewInit, OnChanges, OnDestroy {
95
114
if ( isFirstChange ) {
96
115
return ;
97
116
}
98
- if ( this . designer && changes [ 'definition' ] && changes [ 'definition' ] . currentValue === this . designer . getDefinition ( ) ) {
99
- // The same reference = no change.
100
- return ;
117
+
118
+ if ( this . designer ) {
119
+ const isSameDefinition = ! changes [ 'definition' ] || changes [ 'definition' ] . currentValue === this . designer . getDefinition ( ) ;
120
+ if ( isSameDefinition ) {
121
+ const isReadonlyChange = changes [ 'isReadonly' ] ;
122
+ if ( isReadonlyChange && isReadonlyChange . currentValue !== this . designer . isReadonly ( ) ) {
123
+ this . designer . setIsReadonly ( isReadonlyChange . currentValue ) ;
124
+ }
125
+
126
+ const selectedStepIdChange = changes [ 'selectedStepId' ] ;
127
+ if ( selectedStepIdChange && selectedStepIdChange . currentValue !== this . designer . getSelectedStepId ( ) ) {
128
+ if ( selectedStepIdChange . currentValue ) {
129
+ this . designer . selectStepById ( selectedStepIdChange . currentValue ) ;
130
+ } else {
131
+ this . designer . clearSelectedStep ( ) ;
132
+ }
133
+ }
134
+
135
+ const isToolboxCollapsedChange = changes [ 'isToolboxCollapsed' ] ;
136
+ if ( isToolboxCollapsedChange && isToolboxCollapsedChange . currentValue !== this . designer . isToolboxCollapsed ( ) ) {
137
+ this . designer . setIsToolboxCollapsed ( isToolboxCollapsedChange . currentValue ) ;
138
+ }
139
+
140
+ const isEditorCollapsedChange = changes [ 'isEditorCollapsed' ] ;
141
+ if ( isEditorCollapsedChange && isEditorCollapsedChange . currentValue !== this . designer . isEditorCollapsed ( ) ) {
142
+ this . designer . setIsEditorCollapsed ( isEditorCollapsedChange . currentValue ) ;
143
+ }
144
+
145
+ // The same reference of the definition = no change.
146
+ return ;
147
+ }
101
148
}
102
149
103
150
this . attach ( ) ;
@@ -133,21 +180,38 @@ export class DesignerComponent implements AfterViewInit, OnChanges, OnDestroy {
133
180
this . designer = undefined ;
134
181
}
135
182
183
+ let customActionHandler = this . customActionHandler ;
184
+ if ( customActionHandler ) {
185
+ const cah = customActionHandler ;
186
+ customActionHandler = ( action , step , sequence , context ) => {
187
+ this . ngZone . run ( ( ) => cah ( action , step , sequence , context ) ) ;
188
+ } ;
189
+ }
190
+
136
191
const designer = Designer . create ( this . placeholder . nativeElement , this . definition , {
137
192
theme : this . theme ,
138
193
undoStackSize : this . undoStackSize ,
139
194
editors : this . areEditorsHidden
140
195
? false
141
196
: {
197
+ isCollapsed : this . isEditorCollapsed ,
142
198
globalEditorProvider : this . globalEditorProvider ,
143
199
stepEditorProvider : this . stepEditorProvider
144
200
} ,
145
201
steps : this . stepsConfiguration ,
146
202
validator : this . validatorConfiguration ,
147
- toolbox : this . toolboxConfiguration ,
203
+ toolbox : this . toolboxConfiguration
204
+ ? {
205
+ isCollapsed : this . isToolboxCollapsed ,
206
+ ...this . toolboxConfiguration
207
+ }
208
+ : false ,
148
209
controlBar : this . controlBar ,
149
210
contextMenu : this . contextMenu ,
150
- extensions : this . extensions
211
+ extensions : this . extensions ,
212
+ isReadonly : this . isReadonly ,
213
+ uidGenerator : this . uidGenerator ,
214
+ customActionHandler
151
215
} ) ;
152
216
designer . onReady . subscribe ( ( ) => {
153
217
this . ngZone . run ( ( ) => this . onReady . emit ( designer ) ) ;
@@ -158,7 +222,17 @@ export class DesignerComponent implements AfterViewInit, OnChanges, OnDestroy {
158
222
designer . onSelectedStepIdChanged . subscribe ( stepId => {
159
223
this . ngZone . run ( ( ) => this . onSelectedStepIdChanged . emit ( stepId ) ) ;
160
224
} ) ;
225
+ designer . onIsToolboxCollapsedChanged . subscribe ( isCollapsed => {
226
+ this . ngZone . run ( ( ) => this . onIsToolboxCollapsedChanged . emit ( isCollapsed ) ) ;
227
+ } ) ;
228
+ designer . onIsEditorCollapsedChanged . subscribe ( isCollapsed => {
229
+ this . ngZone . run ( ( ) => this . onIsEditorCollapsedChanged . emit ( isCollapsed ) ) ;
230
+ } ) ;
161
231
this . designer = designer ;
232
+
233
+ if ( this . selectedStepId ) {
234
+ this . designer . selectStepById ( this . selectedStepId ) ;
235
+ }
162
236
} ) ;
163
237
}
164
238
0 commit comments