@@ -154,46 +154,73 @@ function general_ext(tab_name, extension_name, root_container) {
154154
155155 }
156156
157- function handleSelect ( select , index , store ) {
157+ function handleSelect ( select , 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 //}
168168
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- } ) ;
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+ // });
184183
185184 if ( id === 'preprocessor' && value && value . toLowerCase ( ) !== 'none' ) {
186185 state . utils . onNextUiUpdates ( handleSliders ) ; // update new sliders if needed
187186 }
188187 }
189188 function handleSelects ( ) {
190- //let select_index = 0
189+ // let root_selects = root_not_tabs.container.querySelectorAll('.gradio-dropdown');
190+ // root_selects.forEach(function (root_select) {
191+ // if(cnTabs.length == 0){
192+ // handleSelect(root_select, global_dropdown_index[ext_name], root_not_tabs.store)
193+ // global_dropdown_index[ext_name] += 1
194+ // console.log(`global_dropdown_index = ${global_dropdown_index[ext_name]}`)
195+ // }
196+ // else{
197+ // let needsHandle = true
198+ // for(let tab of cnTabs){
199+ // if(tab.container.contains(root_select)){
200+ // needsHandle = false
201+ // break
202+ // }
203+ // }
204+ // if(needsHandle){
205+ // handleSelect(root_select, global_dropdown_index[ext_name], root_not_tabs.store)
206+ // global_dropdown_index[ext_name] += 1
207+ // console.log(`global_dropdown_index = ${global_dropdown_index[ext_name]}`)
208+ // }
209+ // } // else
210+ // });
211+
212+ // cnTabs.forEach(({ container, store }) => {
213+ // container.querySelectorAll('.gradio-dropdown').forEach(select => {
214+ // handleSelect(select, global_dropdown_index[ext_name], store)
215+ // global_dropdown_index[ext_name] += 1
216+ // console.log(`global_dropdown_index = ${global_dropdown_index[ext_name]}`)
217+ // });
218+ // });
219+
191220 let root_selects = root_not_tabs . container . querySelectorAll ( '.gradio-dropdown' ) ;
192221 root_selects . forEach ( function ( root_select ) {
193222 if ( cnTabs . length == 0 ) {
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 ] } ` )
223+ handleSelect ( root_select , root_not_tabs . store )
197224 }
198225 else {
199226 let needsHandle = true
@@ -203,19 +230,13 @@ function general_ext(tab_name, extension_name, root_container) {
203230 break
204231 }
205232 }
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- }
233+ if ( needsHandle ) { handleSelect ( root_select , root_not_tabs . store ) }
211234 } // else
212235 } ) ;
213236
214237 cnTabs . forEach ( ( { container, store } ) => {
215238 container . querySelectorAll ( '.gradio-dropdown' ) . forEach ( select => {
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 ] } ` )
239+ handleSelect ( select , store )
219240 } ) ;
220241 } ) ;
221242
@@ -327,7 +348,10 @@ function general_ext(tab_name, extension_name, root_container) {
327348 handleTabs ( ) ;
328349 handleCheckboxes ( ) ;
329350 handleTextAreas ( ) ;
330- //handleSelects();
351+ if ( state . utils . target_is_newer_version ( state . core . actions . get_sd_version ( ) , "v1.6.0" ) ) {
352+ console . log ( "-----------general handleSelects-------" )
353+ handleSelects ( ) ;
354+ }
331355 handleSliders ( ) ;
332356 handleRadioButtons ( ) ;
333357 } , 500 ) ;
@@ -423,17 +447,17 @@ function general_ext_main(tab){
423447 let ext_name = title . replace ( " " , "-" ) . toLowerCase ( )
424448 console . log ( ext_name )
425449
426- if ( ! global_dropdown_index [ ext_name ] ) {
427- global_dropdown_index [ ext_name ] = 0
428- }
450+ // if(!global_dropdown_index[ext_name]){
451+ // global_dropdown_index[ext_name] = 0
452+ // }
429453 general_ext ( cur_tab_name , ext_name , root_container ) . init ( ) ;
430454 }
431455
432456 }
433457 return { init}
434458}
435459
436- global_dropdown_index = { } // py里是不分txt2img和img2img的,但是这里是需要区分的。。
460+ // global_dropdown_index = {} // py里是不分txt2img和img2img的,但是这里是需要区分的。。
437461
438462const TABS = [ 'txt2img' , 'img2img' ] ;
439463for ( tab of TABS ) {
0 commit comments