@@ -154,27 +154,46 @@ function general_ext(tab_name, extension_name, root_container) {
154154
155155 }
156156
157- function handleSelect ( select , store ) {
157+ function handleSelect ( select , index , store ) {
158158 let translations = state . utils . reverseTranslation ( select . querySelector ( 'label' ) . firstChild . textContent )
159- for ( var text of translations ) {
160- var id = state . utils . txtToId ( text ) ;
161- var value = store . get ( id ) ;
162- if ( value ) { break }
163- }
159+ // for (var text of translations){
160+ // var id = state.utils.txtToId(text);
161+ // var value = store.get(id);
162+ // if (value) {break}
163+ // }
164164 //id = state.utils.txtToId(translations[0]);
165165 //if (value) { //前面不需要判断是否有值,因为需要执行handleSelect绑定onchange事件
166- state . utils . handleSelect ( select , id , store , force = true ) ;
166+ // state.utils.handleSelect(select, id, store, force=true);
167167 //}
168+
169+ let id = state . constants . LS_PREFIX + LS_PREFIX + "dropdown_" + index
170+ state . utils . onContentChange ( select , function ( el ) {
171+ console . log ( `onContentChange ${ id } ` )
172+ let selected = el . querySelector ( 'span.single-select' ) ;
173+ if ( selected ) {
174+ store . setWithNoPrefix ( id , selected . textContent ) ;
175+ } else {
176+ // new gradio version...
177+ let input = el . querySelector ( 'input' ) ;
178+ if ( input ) {
179+ store . setWithNoPrefix ( id , input . value ) ;
180+ }
181+ }
182+
183+ } ) ;
184+
168185 if ( id === 'preprocessor' && value && value . toLowerCase ( ) !== 'none' ) {
169186 state . utils . onNextUiUpdates ( handleSliders ) ; // update new sliders if needed
170187 }
171188 }
172189 function handleSelects ( ) {
173-
190+ //let select_index = 0
174191 let root_selects = root_not_tabs . container . querySelectorAll ( '.gradio-dropdown' ) ;
175192 root_selects . forEach ( function ( root_select ) {
176193 if ( cnTabs . length == 0 ) {
177- handleSelect ( root_select , root_not_tabs . store )
194+ handleSelect ( root_select , global_dropdown_index [ ext_name ] , root_not_tabs . store )
195+ global_dropdown_index [ ext_name ] += 1
196+ console . log ( `global_dropdown_index = ${ global_dropdown_index [ ext_name ] } ` )
178197 }
179198 else {
180199 let needsHandle = true
@@ -184,13 +203,19 @@ function general_ext(tab_name, extension_name, root_container) {
184203 break
185204 }
186205 }
187- if ( needsHandle ) { handleSelect ( root_select , root_not_tabs . store ) }
206+ if ( needsHandle ) {
207+ handleSelect ( root_select , global_dropdown_index [ ext_name ] , root_not_tabs . store )
208+ global_dropdown_index [ ext_name ] += 1
209+ console . log ( `global_dropdown_index = ${ global_dropdown_index [ ext_name ] } ` )
210+ }
188211 } // else
189212 } ) ;
190213
191214 cnTabs . forEach ( ( { container, store } ) => {
192215 container . querySelectorAll ( '.gradio-dropdown' ) . forEach ( select => {
193- handleSelect ( select , store )
216+ handleSelect ( select , global_dropdown_index [ ext_name ] , store )
217+ global_dropdown_index [ ext_name ] += 1
218+ console . log ( `global_dropdown_index = ${ global_dropdown_index [ ext_name ] } ` )
194219 } ) ;
195220 } ) ;
196221
@@ -302,7 +327,7 @@ function general_ext(tab_name, extension_name, root_container) {
302327 handleTabs ( ) ;
303328 handleCheckboxes ( ) ;
304329 handleTextAreas ( ) ;
305- handleSelects ( ) ;
330+ // handleSelects();
306331 handleSliders ( ) ;
307332 handleRadioButtons ( ) ;
308333 } , 500 ) ;
@@ -393,17 +418,23 @@ function general_ext_main(tab){
393418 reg = / ( .+ ) v [ 0 - 9 \. ] + /
394419 if ( reg . test ( title ) ) { title = RegExp . $1 } // 匹配 xxx v0.0.0 格式的标题,把后半部分的版本号去掉
395420
396- if ( title == "ControlNet" ) { title = "Control Net" } // 兼容旧命名
421+ // if(title == "ControlNet"){title = "Control Net"} // 兼容旧命名
397422
398423 let ext_name = title . replace ( " " , "-" ) . toLowerCase ( )
399424 console . log ( ext_name )
425+
426+ if ( ! global_dropdown_index [ ext_name ] ) {
427+ global_dropdown_index [ ext_name ] = 0
428+ }
400429 general_ext ( cur_tab_name , ext_name , root_container ) . init ( ) ;
401430 }
402431
403432 }
404433 return { init}
405434}
406435
436+ global_dropdown_index = { } // py里是不分txt2img和img2img的,但是这里是需要区分的。。
437+
407438const TABS = [ 'txt2img' , 'img2img' ] ;
408439for ( tab of TABS ) {
409440 state . extensions [ `${ tab } -ext-general` ] = general_ext_main ( tab ) ;
0 commit comments