@@ -42,6 +42,7 @@ export default class Preview {
42
42
public placeholderCss : KnockoutObservable < object > ;
43
43
public isPlaceholderVisible : KnockoutObservable < boolean > = ko . observable ( true ) ;
44
44
public isEmpty : KnockoutObservable < boolean > = ko . observable ( true ) ;
45
+ public previewTemplate : KnockoutObservable < string > = ko . observable ( ) ;
45
46
46
47
/**
47
48
* @deprecated
@@ -83,25 +84,11 @@ export default class Preview {
83
84
"visible" : this . isEmpty ,
84
85
"empty-placeholder-background" : this . isPlaceholderVisible ,
85
86
} ) ;
87
+ this . previewTemplate ( this . getPreviewTemplate ( ) ) ;
86
88
this . setupDataFields ( ) ;
87
89
this . bindEvents ( ) ;
88
90
}
89
91
90
- /**
91
- * Retrieve the preview template
92
- *
93
- * @returns {string }
94
- */
95
- get previewTemplate ( ) : string {
96
- const appearance = this . parent . dataStore . get ( "appearance" ) ?
97
- this . parent . dataStore . get ( "appearance" ) . toString ( ) : undefined ;
98
-
99
- return appearanceConfig (
100
- this . config . name ,
101
- appearance
102
- ) . preview_template ;
103
- }
104
-
105
92
/**
106
93
* Calls methods by event name.
107
94
*
@@ -501,8 +488,15 @@ export default class Preview {
501
488
this . updatePlaceholderVisibility ( data ) ;
502
489
// Keep a reference to the display state in an observable for adding classes to the wrapper
503
490
this . display ( ! ! data . display ) ;
491
+
504
492
} ,
505
493
) ;
494
+
495
+ // If the appearance of the content type changes, update the preview template
496
+ this . parent . dataStore . subscribe ( ( ) => {
497
+ this . previewTemplate ( this . getPreviewTemplate ( ) ) ;
498
+ } , "appearance" ) ;
499
+
506
500
if ( this . parent instanceof ContentTypeCollection ) {
507
501
this . parent . children . subscribe (
508
502
( children : any [ ] ) => {
@@ -579,6 +573,21 @@ export default class Preview {
579
573
return hasDataChanges ;
580
574
}
581
575
576
+ /**
577
+ * Retrieve the preview template
578
+ *
579
+ * @returns {string }
580
+ */
581
+ private getPreviewTemplate ( ) {
582
+ const appearance = this . parent . dataStore . get ( "appearance" ) ?
583
+ this . parent . dataStore . get ( "appearance" ) . toString ( ) : undefined ;
584
+
585
+ return appearanceConfig (
586
+ this . config . name ,
587
+ appearance
588
+ ) . preview_template ;
589
+ }
590
+
582
591
/**
583
592
* Any hidden element should block drag / drop events from uploading images from the OS. We have to block this for
584
593
* all elements as underlying elements could still receive the events if a parent is hidden.
0 commit comments