Skip to content

Commit 3819db5

Browse files
authored
Introduce widgetType option to inputSpec (#3550)
1 parent 80517e8 commit 3819db5

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/schemas/nodeDefSchema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const zBaseInputOptions = z
2525
tooltip: z.string().optional(),
2626
hidden: z.boolean().optional(),
2727
advanced: z.boolean().optional(),
28+
widgetType: z.string().optional(),
2829
/** Backend-only properties. */
2930
rawLink: z.boolean().optional(),
3031
lazy: z.boolean().optional()

src/services/litegraphService.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ export const useLitegraphService = () => {
113113
#addInputSocket(inputSpec: InputSpec) {
114114
const inputName = inputSpec.name
115115
const nameKey = `${this.#nodeKey}.inputs.${normalizeI18nKey(inputName)}.name`
116-
const widgetConstructor = widgetStore.widgets.get(inputSpec.type)
116+
const widgetConstructor = widgetStore.widgets.get(
117+
inputSpec.widgetType ?? inputSpec.type
118+
)
117119
if (widgetConstructor && !inputSpec.forceInput) return
118120

119121
this.addInput(inputName, inputSpec.type, {
@@ -127,9 +129,13 @@ export const useLitegraphService = () => {
127129
* (unless `socketless`), an input socket is also added.
128130
*/
129131
#addInputWidget(inputSpec: InputSpec) {
132+
const widgetInputSpec = { ...inputSpec }
133+
if (inputSpec.widgetType) {
134+
widgetInputSpec.type = inputSpec.widgetType
135+
}
130136
const inputName = inputSpec.name
131137
const nameKey = `${this.#nodeKey}.inputs.${normalizeI18nKey(inputName)}.name`
132-
const widgetConstructor = widgetStore.widgets.get(inputSpec.type)
138+
const widgetConstructor = widgetStore.widgets.get(widgetInputSpec.type)
133139
if (!widgetConstructor || inputSpec.forceInput) return
134140

135141
const {
@@ -139,7 +145,7 @@ export const useLitegraphService = () => {
139145
} = widgetConstructor(
140146
this,
141147
inputName,
142-
transformInputSpecV2ToV1(inputSpec),
148+
transformInputSpecV2ToV1(widgetInputSpec),
143149
app
144150
) ?? {}
145151

@@ -153,7 +159,7 @@ export const useLitegraphService = () => {
153159
}
154160

155161
if (!widget?.options?.socketless) {
156-
const inputSpecV1 = transformInputSpecV2ToV1(inputSpec)
162+
const inputSpecV1 = transformInputSpecV2ToV1(widgetInputSpec)
157163
this.addInput(inputName, inputSpec.type, {
158164
shape: inputSpec.isOptional ? RenderShape.HollowCircle : undefined,
159165
localized_name: st(nameKey, inputName),

0 commit comments

Comments
 (0)