mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-21 23:09:39 +00:00
[Refactor] Update Litegraph widget types / cleanup (#3782)
This commit is contained in:
@@ -71,10 +71,12 @@ const addComboWidget = (node: LGraphNode, inputSpec: ComboInputSpec) => {
|
|||||||
if (inputSpec.remote.refresh_button) remoteWidget.addRefreshButton()
|
if (inputSpec.remote.refresh_button) remoteWidget.addRefreshButton()
|
||||||
|
|
||||||
const origOptions = widget.options
|
const origOptions = widget.options
|
||||||
widget.options = new Proxy(origOptions as Record<string | symbol, any>, {
|
widget.options = new Proxy(origOptions, {
|
||||||
get(target, prop: string | symbol) {
|
get(target, prop) {
|
||||||
if (prop !== 'values') return target[prop]
|
// Assertion: Proxy handler passthrough
|
||||||
return remoteWidget.getValue()
|
return prop !== 'values'
|
||||||
|
? target[prop as keyof typeof target]
|
||||||
|
: remoteWidget.getValue()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -237,14 +237,14 @@ const renderPreview = (
|
|||||||
class ImagePreviewWidget implements ICustomWidget {
|
class ImagePreviewWidget implements ICustomWidget {
|
||||||
readonly type: 'custom'
|
readonly type: 'custom'
|
||||||
readonly name: string
|
readonly name: string
|
||||||
readonly options: IWidgetOptions<unknown>
|
readonly options: IWidgetOptions<string | object>
|
||||||
/** Dummy value to satisfy type requirements. */
|
/** Dummy value to satisfy type requirements. */
|
||||||
value: string
|
value: string
|
||||||
y: number = 0
|
y: number = 0
|
||||||
/** Don't serialize the widget value. */
|
/** Don't serialize the widget value. */
|
||||||
serialize: boolean = false
|
serialize: boolean = false
|
||||||
|
|
||||||
constructor(name: string, options: IWidgetOptions<unknown>) {
|
constructor(name: string, options: IWidgetOptions<string | object>) {
|
||||||
this.type = 'custom'
|
this.type = 'custom'
|
||||||
this.name = name
|
this.name = name
|
||||||
this.options = options
|
this.options = options
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ const ext = {
|
|||||||
w.type === 'combo' && w.options.values?.length === values.length
|
w.type === 'combo' && w.options.values?.length === values.length
|
||||||
)
|
)
|
||||||
.find((w) =>
|
.find((w) =>
|
||||||
|
// @ts-ignore Poorly typed; filter above "should" mitigate exceptions
|
||||||
w.options.values?.every((v, i) => v === values[i])
|
w.options.values?.every((v, i) => v === values[i])
|
||||||
)?.value
|
)?.value
|
||||||
|
|
||||||
|
|||||||
@@ -139,6 +139,7 @@ useExtensionService().registerExtension({
|
|||||||
|
|
||||||
if (uploadPath && modelWidget) {
|
if (uploadPath && modelWidget) {
|
||||||
if (!modelWidget.options?.values?.includes(uploadPath)) {
|
if (!modelWidget.options?.values?.includes(uploadPath)) {
|
||||||
|
// @ts-ignore Fails due to earlier type-assertion of IStringWidget
|
||||||
modelWidget.options?.values?.push(uploadPath)
|
modelWidget.options?.values?.push(uploadPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,6 +297,7 @@ useExtensionService().registerExtension({
|
|||||||
|
|
||||||
if (uploadPath && modelWidget) {
|
if (uploadPath && modelWidget) {
|
||||||
if (!modelWidget.options?.values?.includes(uploadPath)) {
|
if (!modelWidget.options?.values?.includes(uploadPath)) {
|
||||||
|
// @ts-ignore Fails due to earlier type-assertion of IStringWidget
|
||||||
modelWidget.options?.values?.push(uploadPath)
|
modelWidget.options?.values?.push(uploadPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ export function addValueControlWidgets(
|
|||||||
const isCombo = targetWidget.type === 'combo'
|
const isCombo = targetWidget.type === 'combo'
|
||||||
let comboFilter: IStringWidget
|
let comboFilter: IStringWidget
|
||||||
if (isCombo && valueControl.options.values) {
|
if (isCombo && valueControl.options.values) {
|
||||||
|
// @ts-ignore Combo widget values may be a dictionary or legacy function type
|
||||||
valueControl.options.values.push('increment-wrap')
|
valueControl.options.values.push('increment-wrap')
|
||||||
}
|
}
|
||||||
if (isCombo && options.addFilterList !== false) {
|
if (isCombo && options.addFilterList !== false) {
|
||||||
@@ -183,6 +184,7 @@ export function addValueControlWidgets(
|
|||||||
const lower = filter.toLocaleLowerCase()
|
const lower = filter.toLocaleLowerCase()
|
||||||
check = (item: string) => item.toLocaleLowerCase().includes(lower)
|
check = (item: string) => item.toLocaleLowerCase().includes(lower)
|
||||||
}
|
}
|
||||||
|
// @ts-ignore Combo widget values may be a dictionary or legacy function type
|
||||||
values = values.filter((item: string) => check(item))
|
values = values.filter((item: string) => check(item))
|
||||||
if (!values.length && targetWidget.options.values?.length) {
|
if (!values.length && targetWidget.options.values?.length) {
|
||||||
console.warn(
|
console.warn(
|
||||||
@@ -209,14 +211,17 @@ export function addValueControlWidgets(
|
|||||||
current_index -= 1
|
current_index -= 1
|
||||||
break
|
break
|
||||||
case 'randomize':
|
case 'randomize':
|
||||||
|
// @ts-ignore Combo widget values may be a dictionary or legacy function type
|
||||||
current_index = Math.floor(Math.random() * current_length)
|
current_index = Math.floor(Math.random() * current_length)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
current_index = Math.max(0, current_index)
|
current_index = Math.max(0, current_index)
|
||||||
|
// @ts-ignore Combo widget values may be a dictionary or legacy function type
|
||||||
current_index = Math.min(current_length - 1, current_index)
|
current_index = Math.min(current_length - 1, current_index)
|
||||||
if (current_index >= 0) {
|
if (current_index >= 0) {
|
||||||
|
// @ts-ignore Combo widget values may be a dictionary or legacy function type
|
||||||
let value = values[current_index]
|
let value = values[current_index]
|
||||||
targetWidget.value = value
|
targetWidget.value = value
|
||||||
targetWidget.callback?.(value)
|
targetWidget.callback?.(value)
|
||||||
|
|||||||
@@ -35,7 +35,11 @@ export function isAudioNode(node: LGraphNode | undefined): boolean {
|
|||||||
export function addToComboValues(widget: IComboWidget, value: string) {
|
export function addToComboValues(widget: IComboWidget, value: string) {
|
||||||
if (!widget.options) widget.options = { values: [] }
|
if (!widget.options) widget.options = { values: [] }
|
||||||
if (!widget.options.values) widget.options.values = []
|
if (!widget.options.values) widget.options.values = []
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore Combo widget values may be a dictionary or legacy function type
|
||||||
if (!widget.options.values.includes(value)) {
|
if (!widget.options.values.includes(value)) {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore Combo widget values may be a dictionary or legacy function type
|
||||||
widget.options.values.push(value)
|
widget.options.values.push(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user