Introduce widgetType option to inputSpec (#3550)

This commit is contained in:
AustinMroz
2025-04-23 19:36:01 -05:00
committed by GitHub
parent 80517e8204
commit 3819db5ec4
2 changed files with 11 additions and 4 deletions

View File

@@ -25,6 +25,7 @@ export const zBaseInputOptions = z
tooltip: z.string().optional(),
hidden: z.boolean().optional(),
advanced: z.boolean().optional(),
widgetType: z.string().optional(),
/** Backend-only properties. */
rawLink: z.boolean().optional(),
lazy: z.boolean().optional()

View File

@@ -113,7 +113,9 @@ export const useLitegraphService = () => {
#addInputSocket(inputSpec: InputSpec) {
const inputName = inputSpec.name
const nameKey = `${this.#nodeKey}.inputs.${normalizeI18nKey(inputName)}.name`
const widgetConstructor = widgetStore.widgets.get(inputSpec.type)
const widgetConstructor = widgetStore.widgets.get(
inputSpec.widgetType ?? inputSpec.type
)
if (widgetConstructor && !inputSpec.forceInput) return
this.addInput(inputName, inputSpec.type, {
@@ -127,9 +129,13 @@ export const useLitegraphService = () => {
* (unless `socketless`), an input socket is also added.
*/
#addInputWidget(inputSpec: InputSpec) {
const widgetInputSpec = { ...inputSpec }
if (inputSpec.widgetType) {
widgetInputSpec.type = inputSpec.widgetType
}
const inputName = inputSpec.name
const nameKey = `${this.#nodeKey}.inputs.${normalizeI18nKey(inputName)}.name`
const widgetConstructor = widgetStore.widgets.get(inputSpec.type)
const widgetConstructor = widgetStore.widgets.get(widgetInputSpec.type)
if (!widgetConstructor || inputSpec.forceInput) return
const {
@@ -139,7 +145,7 @@ export const useLitegraphService = () => {
} = widgetConstructor(
this,
inputName,
transformInputSpecV2ToV1(inputSpec),
transformInputSpecV2ToV1(widgetInputSpec),
app
) ?? {}
@@ -153,7 +159,7 @@ export const useLitegraphService = () => {
}
if (!widget?.options?.socketless) {
const inputSpecV1 = transformInputSpecV2ToV1(inputSpec)
const inputSpecV1 = transformInputSpecV2ToV1(widgetInputSpec)
this.addInput(inputName, inputSpec.type, {
shape: inputSpec.isOptional ? RenderShape.HollowCircle : undefined,
localized_name: st(nameKey, inputName),