|
class PresetManagerDropdownComponent{ |
|
constructor(component){ |
|
this.component = gradioApp().getElementById(component) |
|
} |
|
updateDropdown(selection){ |
|
|
|
|
|
this.getDropDownOptions().find( e => e.value.includes(selection)).selected = true; |
|
this.component.querySelector("select").dispatchEvent(new Event("change")); |
|
} |
|
getDropDownOptions(asValues=false){ |
|
if (asValues){ |
|
let temp = new Array; |
|
Array.from(this.component.querySelector("select").querySelectorAll("option")).forEach( opt => temp.push(opt.value)) |
|
return temp |
|
} |
|
else{ |
|
return Array.from(this.component.querySelector("select").querySelectorAll("option")) |
|
} |
|
} |
|
getCurrentSelection(){ |
|
return this.component.querySelector("select").value |
|
} |
|
} |
|
|
|
class PresetManagerCheckboxGroupComponent{ |
|
constructor(component){ |
|
this.component = gradioApp().getElementById(component); |
|
this.checkBoxes = new Object; |
|
this.setCheckBoxesContainer() |
|
} |
|
setCheckBoxesContainer(){ |
|
Array.from(this.component.querySelectorAll("input")).forEach( _input => this.checkBoxes[_input.nextElementSibling.innerText] = _input) |
|
} |
|
getCheckBoxes(){ |
|
let response = new Array; |
|
for (let _component in this.checkBoxes){ |
|
response.push([_component, this.checkBoxes[_component]]) |
|
} |
|
return response |
|
} |
|
setCheckBoxesValues(iterable){ |
|
for (let _componentText in this.checkBoxes){ |
|
this.conditionalToggle(false, this.checkBoxes[_componentText]) |
|
} |
|
if (iterable instanceof Array){ |
|
setTimeout( () => |
|
iterable.forEach( _label => this.conditionalToggle(true, this.checkBoxes[_label])), |
|
2) |
|
} |
|
} |
|
conditionalToggle(desiredVal, _component){ |
|
|
|
|
|
|
|
|
|
if (desiredVal != _component.checked){ |
|
_component.dispatchEvent(new Event("change")) |
|
} |
|
} |
|
} |
|
class PresetManagerMover{ |
|
constructor(self, target, onLoadHandler){ |
|
this.presetManager = gradioApp().getElementById(self) |
|
this.target = gradioApp().getElementById(target) |
|
this.handler = gradioApp().getElementById(onLoadHandler) |
|
} |
|
move(adjacentAt='afterend'){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.target.insertAdjacentElement(adjacentAt, this.presetManager) |
|
} |
|
updateTarget(new_target){ |
|
this.target = gradioApp().getElementById(new_target) |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|