@@ -757,6 +757,8 @@ define('format/format-plugin', [
757
757
} ,
758
758
759
759
activeTypography : null ,
760
+ formatOptions : [ ] ,
761
+ typographyOptions : [ ] ,
760
762
761
763
/**
762
764
* Initialize the plugin and set initialize flag on true
@@ -881,6 +883,32 @@ define('format/format-plugin', [
881
883
button . handle . show ( ) ;
882
884
}
883
885
} ) ;
886
+
887
+ plugin . typographyOptions = Object . entries ( plugin . buttonConfig ) . map ( function ( entry ) {
888
+ var name = entry [ 0 ] ;
889
+ var elemConfig = entry [ 1 ] ;
890
+
891
+ // Ignore non-typography elements
892
+ if ( ! elemConfig . typography ) {
893
+ return null ;
894
+ }
895
+
896
+ // Skip elements which aren't allowed
897
+ if ( ! ContentRules . isAllowed ( editable , name ) || ! config . includes ( name ) ) {
898
+ return null ;
899
+ }
900
+
901
+ return name ;
902
+ } ) . filter ( function ( value ) {
903
+ return value != null ;
904
+ } ) ;
905
+
906
+ // We need at least two options, otherwise the button/selection wouldn't make sense
907
+ if ( plugin . typographyOptions . length <= 1 ) {
908
+ plugin . typographyButton . hide ( ) ;
909
+ } else {
910
+ plugin . typographyButton . show ( ) ;
911
+ }
884
912
} ,
885
913
886
914
/**
@@ -922,7 +950,12 @@ define('format/format-plugin', [
922
950
iconOnly : false ,
923
951
924
952
click : function ( ) {
925
- var data = Dropdown . openDynamicDropdown ( plugin . typographyButton . name , plugin . _createTypographyContext ( ) ) ;
953
+ var context = plugin . _createTypographyContext ( ) ;
954
+ if ( context == null ) {
955
+ return ;
956
+ }
957
+
958
+ var data = Dropdown . openDynamicDropdown ( plugin . typographyButton . name , context ) ;
926
959
if ( ! data ) {
927
960
return ;
928
961
}
@@ -968,7 +1001,7 @@ define('format/format-plugin', [
968
1001
} ,
969
1002
970
1003
_createTypographyContext : function ( ) {
971
- var latestOptions = ( plugin . config || [ ] ) . map ( function ( nodeName ) {
1004
+ var latestOptions = ( plugin . typographyOptions || [ ] ) . map ( function ( nodeName ) {
972
1005
var settings = plugin . buttonConfig [ nodeName ] ;
973
1006
974
1007
// If there's no settings, we have to ignore it
@@ -992,6 +1025,13 @@ define('format/format-plugin', [
992
1025
return option != null ;
993
1026
} ) ;
994
1027
1028
+ // In case there's only one option, and we already have it selected,
1029
+ // then we can skip opening the context all together, as the user can't
1030
+ // change it to something else anyways.
1031
+ if ( latestOptions . length === 1 && latestOptions [ 0 ] . id === plugin . activeTypography ) {
1032
+ return null ;
1033
+ }
1034
+
995
1035
return {
996
1036
type : 'select-menu' ,
997
1037
options : {
0 commit comments