@@ -95,8 +95,6 @@ export class SurveyElementActionContainer extends AdaptiveActionContainer {
95
95
96
96
export class SurveyElementAdornerBase < T extends SurveyElement = SurveyElement > extends Base {
97
97
public static AdornerValueName = "__sjs_creator_adorner" ;
98
- public actionContainer : SurveyElementActionContainer ;
99
- public topActionContainer : ActionContainer ;
100
98
protected expandCollapseAction : IAction ;
101
99
@property ( { defaultValue : true } ) allowDragging : boolean ;
102
100
@property ( { defaultValue : false } ) expandCollapseAnimationRunning : boolean ;
@@ -228,20 +226,20 @@ export class SurveyElementAdornerBase<T extends SurveyElement = SurveyElement> e
228
226
public get renderedCollapsed ( ) : boolean {
229
227
return ! ! this . _renderedCollapsed ;
230
228
}
231
- protected createActionContainers ( ) {
232
- this . actionContainer = this . createActionContainer ( ) ;
233
- this . topActionContainer = new ActionContainer ( ) ;
234
- this . topActionContainer . sizeMode = "small" ;
229
+ protected createTopActionContainer ( ) : ActionContainer {
230
+ const actionContainer = new ActionContainer ( ) ;
231
+ actionContainer . sizeMode = "small" ;
235
232
if ( this . creator . expandCollapseButtonVisibility != "never" ) {
236
- this . topActionContainer . setItems ( [ this . expandCollapseAction ] ) ;
237
- this . topActionContainer . cssClasses = {
233
+ actionContainer . setItems ( [ this . expandCollapseAction ] ) ;
234
+ actionContainer . cssClasses = {
238
235
root : "svc-survey-element-top-toolbar sv-action-bar" ,
239
236
item : "svc-survey-element-top-toolbar__item" ,
240
237
itemIcon : "svc-survey-element-toolbar-item__icon" ,
241
238
itemTitle : "svc-survey-element-toolbar-item__title" ,
242
239
itemTitleWithIcon : "svc-survey-element-toolbar-item__title--with-icon" ,
243
240
} ;
244
241
}
242
+ return actionContainer ;
245
243
}
246
244
247
245
protected createActionContainer ( ) : SurveyElementActionContainer {
@@ -302,9 +300,33 @@ export class SurveyElementAdornerBase<T extends SurveyElement = SurveyElement> e
302
300
) {
303
301
super ( ) ;
304
302
this . expandCollapseAction = this . getExpandCollapseAction ( ) ;
305
- this . createActionContainers ( ) ;
306
303
this . attachToUI ( surveyElement ) ;
307
304
}
305
+ private actionContainerValue : SurveyElementActionContainer ;
306
+ protected get isActionContainerCreated ( ) : boolean {
307
+ return ! ! this . actionContainerValue ;
308
+ }
309
+ public get actionContainer ( ) : SurveyElementActionContainer {
310
+ if ( ! this . actionContainerValue ) {
311
+ this . actionContainerValue = this . createActionContainer ( ) ;
312
+ if ( this . surveyElement ) {
313
+ this . updateActionsContainer ( this . surveyElement ) ;
314
+ this . updateActionsVisibility ( false ) ;
315
+ }
316
+ }
317
+ return this . actionContainerValue ;
318
+ }
319
+ private topActionContainerValue : ActionContainer ;
320
+ public get topActionContainer ( ) : ActionContainer {
321
+ if ( ! this . topActionContainerValue ) {
322
+ this . topActionContainerValue = this . createTopActionContainer ( ) ;
323
+ if ( this . surveyElement ) {
324
+ this . updateActionsVisibility ( true ) ;
325
+ }
326
+ }
327
+ return this . topActionContainerValue ;
328
+ }
329
+
308
330
private creatorOnLocaleChanged : ( sender : Base , options : any ) => void = ( _ , options ) => {
309
331
if ( this . surveyElement ) {
310
332
this . updateActionsContainer ( this . surveyElement ) ;
@@ -389,13 +411,17 @@ export class SurveyElementAdornerBase<T extends SurveyElement = SurveyElement> e
389
411
}
390
412
public dispose ( ) : void {
391
413
this . detachFromUI ( ) ;
392
- if ( ! this . actionContainer . isDisposed ) {
393
- this . actionContainer . dispose ( ) ;
394
- }
414
+ this . disposeActions ( this . actionContainerValue ) ;
415
+ this . disposeActions ( this . topActionContainerValue ) ;
395
416
super . dispose ( ) ;
396
417
this . sidebarFlyoutModeChangedFunc = undefined ;
397
418
this . animationCollapsed = undefined ;
398
419
}
420
+ private disposeActions ( container : ActionContainer ) : void {
421
+ if ( ! ! container && ! container . isDisposed ) {
422
+ container . dispose ( ) ;
423
+ }
424
+ }
399
425
protected onElementSelectedChanged ( isSelected : boolean ) : void {
400
426
if ( ! isSelected ) return ;
401
427
this . updateActionsProperties ( ) ;
@@ -415,18 +441,24 @@ export class SurveyElementAdornerBase<T extends SurveyElement = SurveyElement> e
415
441
} ;
416
442
}
417
443
protected cleanActionsContainer ( ) {
418
- const actions = this . actionContainer . actions ;
419
- this . actionContainer . setItems ( [ ] ) ;
444
+ const container = this . actionContainerValue ;
445
+ if ( ! container ) return ;
446
+ const actions = container . actions ;
447
+ container . setItems ( [ ] ) ;
420
448
actions . forEach ( action => action . dispose && action . dispose ( ) ) ;
421
449
}
422
450
protected updateActionsContainer ( surveyElement : SurveyElement ) {
451
+ if ( ! this . actionContainerValue ) return ;
423
452
const actions : Array < Action > = [ ] ;
424
453
this . buildActions ( actions ) ;
425
454
this . creator . onElementMenuItemsChanged ( surveyElement , actions ) ;
426
- this . actionContainer . setItems ( actions ) ;
455
+ this . actionContainerValue . setItems ( actions ) ;
427
456
}
428
457
protected updateActionsProperties ( ) : void {
429
458
if ( this . isDisposed ) return ;
459
+ this . updateActionsPropertiesCore ( ) ;
460
+ }
461
+ protected updateActionsPropertiesCore ( ) : void {
430
462
this . updateElementAllowOptions (
431
463
this . creator . getElementAllowOperations ( this . surveyElement ) ,
432
464
this . isOperationsAllow ( )
@@ -456,11 +488,21 @@ export class SurveyElementAdornerBase<T extends SurveyElement = SurveyElement> e
456
488
protected isOperationsAllow ( ) : boolean {
457
489
return ! this . creator . readOnly ;
458
490
}
491
+ private actionVisibilityCache : { [ index : string ] : boolean } = { } ;
459
492
protected updateActionVisibility ( id : string , isVisible : boolean ) {
460
- var action = this . getActionById ( id ) ;
461
- if ( ! action ) return ;
462
- if ( action . visible == isVisible ) return ;
463
- action . visible = isVisible ;
493
+ var action = this . actionContainerValue ?. getActionById ( id ) || this . topActionContainerValue ?. getActionById ( id ) ;
494
+ if ( ! action ) {
495
+ this . actionVisibilityCache [ id ] = isVisible ;
496
+ } else {
497
+ if ( action . visible !== isVisible ) {
498
+ action . visible = isVisible ;
499
+ }
500
+ }
501
+ }
502
+ protected updateActionsVisibility ( isTop : boolean ) : void {
503
+ for ( var key in this . actionVisibilityCache ) {
504
+ this . updateActionVisibility ( key , this . actionVisibilityCache [ key ] ) ;
505
+ }
464
506
}
465
507
public getActionById ( id : string ) : Action {
466
508
return this . actionContainer . getActionById ( id ) || this . topActionContainer . getActionById ( id ) ;
0 commit comments