-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add toggle to enable auto queue when graph is changed * type fix * better * better alignment * Change undoredo to not ignore inputs when autoqueue in change mode
- Loading branch information
1 parent
f9e55d8
commit 93bbe3f
Showing
5 changed files
with
161 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { $el } from "../ui.js"; | ||
|
||
/** | ||
* @typedef { { text: string, value?: string, tooltip?: string } } ToggleSwitchItem | ||
*/ | ||
/** | ||
* Creates a toggle switch element | ||
* @param { string } name | ||
* @param { Array<string | ToggleSwitchItem } items | ||
* @param { Object } [opts] | ||
* @param { (e: { item: ToggleSwitchItem, prev?: ToggleSwitchItem }) => void } [opts.onChange] | ||
*/ | ||
export function toggleSwitch(name, items, { onChange } = {}) { | ||
let selectedIndex; | ||
let elements; | ||
|
||
function updateSelected(index) { | ||
if (selectedIndex != null) { | ||
elements[selectedIndex].classList.remove("comfy-toggle-selected"); | ||
} | ||
onChange?.({ item: items[index], prev: selectedIndex == null ? undefined : items[selectedIndex] }); | ||
selectedIndex = index; | ||
elements[selectedIndex].classList.add("comfy-toggle-selected"); | ||
} | ||
|
||
elements = items.map((item, i) => { | ||
if (typeof item === "string") item = { text: item }; | ||
if (!item.value) item.value = item.text; | ||
|
||
const toggle = $el( | ||
"label", | ||
{ | ||
textContent: item.text, | ||
title: item.tooltip ?? "", | ||
}, | ||
$el("input", { | ||
name, | ||
type: "radio", | ||
value: item.value ?? item.text, | ||
checked: item.selected, | ||
onchange: () => { | ||
updateSelected(i); | ||
}, | ||
}) | ||
); | ||
if (item.selected) { | ||
updateSelected(i); | ||
} | ||
return toggle; | ||
}); | ||
|
||
const container = $el("div.comfy-toggle-switch", elements); | ||
|
||
if (selectedIndex == null) { | ||
elements[0].children[0].checked = true; | ||
updateSelected(0); | ||
} | ||
|
||
return container; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters