@@ -15,6 +15,7 @@ import {
1515 ViewChild
1616} from '@angular/core' ;
1717import {
18+ CustomActionHandler ,
1819 Definition ,
1920 Designer ,
2021 DesignerExtension ,
@@ -25,6 +26,7 @@ import {
2526 StepEditorProvider ,
2627 StepsConfiguration ,
2728 ToolboxConfiguration ,
29+ UidGenerator ,
2830 ValidatorConfiguration
2931} from 'sequential-workflow-designer' ;
3032
@@ -70,6 +72,19 @@ export class DesignerComponent implements AfterViewInit, OnChanges, OnDestroy {
7072 public contextMenu ?: boolean ;
7173 @Input ( 'extensions' )
7274 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+
7388 @Input ( 'areEditorsHidden' )
7489 public areEditorsHidden ?: boolean ;
7590 @Input ( 'globalEditor' )
@@ -83,6 +98,10 @@ export class DesignerComponent implements AfterViewInit, OnChanges, OnDestroy {
8398 public readonly onDefinitionChanged = new EventEmitter < Definition > ( ) ;
8499 @Output ( )
85100 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 > ( ) ;
86105
87106 public constructor ( private readonly ngZone : NgZone , private readonly applicationRef : ApplicationRef ) { }
88107
@@ -95,9 +114,37 @@ export class DesignerComponent implements AfterViewInit, OnChanges, OnDestroy {
95114 if ( isFirstChange ) {
96115 return ;
97116 }
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+ }
101148 }
102149
103150 this . attach ( ) ;
@@ -133,21 +180,38 @@ export class DesignerComponent implements AfterViewInit, OnChanges, OnDestroy {
133180 this . designer = undefined ;
134181 }
135182
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+
136191 const designer = Designer . create ( this . placeholder . nativeElement , this . definition , {
137192 theme : this . theme ,
138193 undoStackSize : this . undoStackSize ,
139194 editors : this . areEditorsHidden
140195 ? false
141196 : {
197+ isCollapsed : this . isEditorCollapsed ,
142198 globalEditorProvider : this . globalEditorProvider ,
143199 stepEditorProvider : this . stepEditorProvider
144200 } ,
145201 steps : this . stepsConfiguration ,
146202 validator : this . validatorConfiguration ,
147- toolbox : this . toolboxConfiguration ,
203+ toolbox : this . toolboxConfiguration
204+ ? {
205+ isCollapsed : this . isToolboxCollapsed ,
206+ ...this . toolboxConfiguration
207+ }
208+ : false ,
148209 controlBar : this . controlBar ,
149210 contextMenu : this . contextMenu ,
150- extensions : this . extensions
211+ extensions : this . extensions ,
212+ isReadonly : this . isReadonly ,
213+ uidGenerator : this . uidGenerator ,
214+ customActionHandler
151215 } ) ;
152216 designer . onReady . subscribe ( ( ) => {
153217 this . ngZone . run ( ( ) => this . onReady . emit ( designer ) ) ;
@@ -158,7 +222,17 @@ export class DesignerComponent implements AfterViewInit, OnChanges, OnDestroy {
158222 designer . onSelectedStepIdChanged . subscribe ( stepId => {
159223 this . ngZone . run ( ( ) => this . onSelectedStepIdChanged . emit ( stepId ) ) ;
160224 } ) ;
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+ } ) ;
161231 this . designer = designer ;
232+
233+ if ( this . selectedStepId ) {
234+ this . designer . selectStepById ( this . selectedStepId ) ;
235+ }
162236 } ) ;
163237 }
164238
0 commit comments