@@ -622,7 +622,7 @@ var SnippetEditor = Widget.extend({
622
622
if ( editorUIsToUpdate . length > 0 && ! optionsSectionVisible ) {
623
623
return null ;
624
624
}
625
- return this . _customize$Elements ;
625
+ return this . getOptions ( ) ;
626
626
} ,
627
627
/**
628
628
* Returns the OWL Options templates to mount their widgets.
@@ -860,6 +860,7 @@ var SnippetEditor = Widget.extend({
860
860
option . isTopOption = true ;
861
861
}
862
862
} else {
863
+ return ;
863
864
option = new ( options . registry [ optionName ] || options . Class ) (
864
865
this ,
865
866
val . $el . children ( ) ,
@@ -1892,6 +1893,59 @@ var SnippetEditor = Widget.extend({
1892
1893
} ,
1893
1894
} ) ;
1894
1895
1896
+ class SnippetOptionsManager extends Component {
1897
+ static props = {
1898
+ editors : { type : Object } ,
1899
+ enabledEditors : { type : Array } ,
1900
+ onOptionMounted : { type : Function } ,
1901
+ activateTab : { type : Function } ,
1902
+ execWithLoadingEffect : { type : Function } ,
1903
+ } ;
1904
+ static template = "web_editor.SnippetOptionsManager" ;
1905
+
1906
+ setup ( ) {
1907
+ useEffect (
1908
+ ( ) => {
1909
+ this . props . execWithLoadingEffect ( async ( ) => {
1910
+ const editorToEnable = this . props . enabledEditors [ 0 ] ;
1911
+ let enabledOptions ;
1912
+ if ( editorToEnable ) {
1913
+ enabledOptions = await editorToEnable . toggleOptions ( true ) ;
1914
+ if ( ! enabledOptions ) {
1915
+ // As some options can only be generated using JavaScript
1916
+ // (e.g. 'SwitchableViews'), it may happen at this point
1917
+ // that the overlay is activated even though there are no
1918
+ // options. That's why we disable the overlay if there are
1919
+ // no options to enable.
1920
+ editorToEnable . toggleOverlay ( false ) ;
1921
+ }
1922
+ }
1923
+ if ( enabledOptions ) {
1924
+ this . props . activateTab ( SnippetsMenu . tabs . OPTIONS ) ;
1925
+ }
1926
+ } ) ;
1927
+ } ,
1928
+ ( ) => {
1929
+ // The compute dependencies can never return an empty array or
1930
+ // the effect will not be reapplied, and therefore the tab will
1931
+ // not change to blocks.
1932
+ if ( this . props . enabledEditors . length ) {
1933
+ return this . props . enabledEditors ;
1934
+ } else {
1935
+ return [ false ] ;
1936
+ }
1937
+ }
1938
+ ) ;
1939
+ }
1940
+
1941
+ getEditors ( ) {
1942
+ return [ ...this . props . editors ] . sort ( ( e1 , e2 ) => {
1943
+ return this . props . enabledEditors . indexOf ( e1 ) < this . props . enabledEditors . indexOf ( e2 ) ;
1944
+ } ) ;
1945
+ }
1946
+ }
1947
+
1948
+
1895
1949
/**
1896
1950
* Management of drag&drop menu and snippet related behaviors in the page.
1897
1951
*/
@@ -1958,7 +2012,7 @@ class SnippetsMenu extends Component {
1958
2012
1959
2013
static template = "web_editor.SnippetsMenu" ;
1960
2014
1961
- static components = { Toolbar, LinkTools } ;
2015
+ static components = { Toolbar, LinkTools, SnippetOptionsManager } ;
1962
2016
1963
2017
setup ( ) {
1964
2018
super . setup ( ...arguments ) ;
@@ -3013,17 +3067,11 @@ class SnippetsMenu extends Component {
3013
3067
|| ifInactiveOptions && this . state . enabledEditorHierarchy . includes ( editorToEnable ) ) {
3014
3068
return editorToEnable ;
3015
3069
}
3016
- // TODO: @owl -options remove when legacy is completely converted.
3017
- let hasOwlOptions = false ;
3018
3070
3019
3071
if ( ! previewMode ) {
3020
3072
this . state . enabledEditorHierarchy = [ ] ;
3021
3073
let current = editorToEnable ;
3022
3074
while ( current && current . $target ) {
3023
- // TODO: @owl -options remove when legacy is completely converted.
3024
- hasOwlOptions = current . _hasOwlOptions ;
3025
- // TODO: @owl -options, make sure changes to instances
3026
- // of SnippetEditor should not trigger re-renders.
3027
3075
this . state . enabledEditorHierarchy . push ( markRaw ( current ) ) ;
3028
3076
current = current . getParent ( ) ;
3029
3077
}
@@ -3054,33 +3102,21 @@ class SnippetsMenu extends Component {
3054
3102
parentEditor . toggleOverlay ( true , previewMode ) ;
3055
3103
}
3056
3104
}
3057
- customize$Elements = await editorToEnable . toggleOptions ( true ) ;
3058
- this . state . options = editorToEnable . getOptions ( ) ;
3105
+ // TODO: this code is handled by SnippetOptionsManager now
3106
+ // customize$Elements = await editorToEnable.toggleOptions(true );
3059
3107
} else {
3060
3108
for ( const editor of this . snippetEditors ) {
3061
3109
if ( editor . isSticky ( ) ) {
3062
3110
editor . toggleOverlay ( true , false ) ;
3063
- customize$Elements = await editor . toggleOptions ( true ) ;
3111
+ // customize$Elements = await editor.toggleOptions(true);
3112
+ this . state . enabledEditorHierarchy . push ( editor ) ;
3064
3113
}
3065
3114
}
3066
3115
}
3067
-
3068
- if ( ! previewMode ) {
3069
- // As some options can only be generated using JavaScript
3070
- // (e.g. 'SwitchableViews'), it may happen at this point
3071
- // that the overlay is activated even though there are no
3072
- // options. That's why we disable the overlay if there are
3073
- // no options to enable.
3074
- if ( editorToEnable && ! customize$Elements ) {
3075
- editorToEnable . toggleOverlay ( false ) ;
3076
- }
3116
+ if ( ! editorToEnable || this . state . enabledEditorHierarchy . lenght === 0 ) {
3077
3117
this . _updateRightPanelContent ( {
3078
- content : customize$Elements || [ ] ,
3079
- // TODO: @owl -options, disable the change of tab,
3080
- // here, instead let the onOptionMounted do it. To review
3081
- // tab: customize$Elements ? this.tabs.OPTIONS : this.tabs.BLOCKS,
3082
- tab : ! hasOwlOptions && customize$Elements ? this . tabs . OPTIONS : this . tabs . BLOCKS ,
3083
- } ) ;
3118
+ tab : this . tabs . BLOCKS
3119
+ } )
3084
3120
}
3085
3121
3086
3122
return editorToEnable ;
@@ -4027,7 +4063,7 @@ class SnippetsMenu extends Component {
4027
4063
* the new content of the customizePanel
4028
4064
* @param {this.tabs.VALUE } [tab='blocks'] - the tab to select
4029
4065
*/
4030
- _updateRightPanelContent ( { content , tab, ...options } ) {
4066
+ _updateRightPanelContent ( { tab, ...options } ) {
4031
4067
this . _hideTooltips ( ) ;
4032
4068
this . _closeWidgets ( ) ;
4033
4069
@@ -4036,30 +4072,15 @@ class SnippetsMenu extends Component {
4036
4072
tab = SnippetsMenu . tabs . OPTIONS ;
4037
4073
}
4038
4074
4039
- this . state . currentTab = tab || SnippetsMenu . tabs . BLOCKS ;
4040
-
4041
- if ( this . _$toolbarContainer ) {
4042
- this . _$toolbarContainer [ 0 ] . remove ( ) ;
4043
- }
4044
4075
this . state . showToolbar = false ;
4045
4076
this . _$toolbarContainer = null ;
4046
- if ( content ) {
4047
- // The toolbar component will be hidden or shown by state.showToolbar
4048
- // as it is an OWL Component, OWL is in charge of the HTML for that
4049
- // component. So we do not want to remove it.
4050
- // TODO: This should be improved when SnippetEditor / SnippetOptions
4051
- // are converted to OWL.
4052
- while ( this . customizePanel . firstChild ?. id !== "legacyOptionsLimiter" ) {
4053
- this . customizePanel . removeChild ( this . customizePanel . firstChild ) ;
4054
- }
4055
- $ ( this . customizePanel ) . prepend ( content ) ;
4056
- if ( this . state . currentTab === this . tabs . OPTIONS && ! options . forceEmptyTab ) {
4057
- this . _addToolbar ( ) ;
4058
- }
4077
+ if ( this . state . currentTab === this . tabs . OPTIONS && ! options . forceEmptyTab ) {
4078
+ this . _addToolbar ( ) ;
4059
4079
}
4060
4080
if ( options . forceEmptyTab ) {
4061
4081
this . state . showToolbar = false ;
4062
4082
}
4083
+ this . state . currentTab = tab ;
4063
4084
}
4064
4085
/**
4065
4086
* Scrolls to given snippet.
@@ -5157,7 +5178,6 @@ class SnippetsMenu extends Component {
5157
5178
this . execWithLoadingEffect ( async ( ) => {
5158
5179
await Promise . all ( this . state . enabledEditorHierarchy . map ( editor => editor . updateOptionsUI ( ) ) ) ;
5159
5180
await Promise . all ( this . state . enabledEditorHierarchy . map ( editor => editor . updateOptionsUIVisibility ( ) ) ) ;
5160
- this . state . currentTab = this . tabs . OPTIONS ;
5161
5181
} ) ;
5162
5182
}
5163
5183
@@ -5427,6 +5447,9 @@ class SnippetsMenu extends Component {
5427
5447
}
5428
5448
snippet . renaming = false ;
5429
5449
}
5450
+ activateTab ( tab ) {
5451
+ this . _updateRightPanelContent ( { tab} ) ;
5452
+ }
5430
5453
}
5431
5454
5432
5455
export default {
0 commit comments