[TS] Type Clipspace.widgets (#2981)

This commit is contained in:
Chenlei Hu
2025-03-11 10:49:50 -04:00
committed by GitHub
parent ebb030c401
commit d4c3685326

View File

@@ -7,12 +7,13 @@ import {
LiteGraph, LiteGraph,
strokeShape strokeShape
} from '@comfyorg/litegraph' } from '@comfyorg/litegraph'
import type { Rect, Vector2 } from '@comfyorg/litegraph' import type { IWidget, Rect, Vector2 } from '@comfyorg/litegraph'
import _ from 'lodash' import _ from 'lodash'
import type { ToastMessageOptions } from 'primevue/toast' import type { ToastMessageOptions } from 'primevue/toast'
import { reactive } from 'vue' import { reactive } from 'vue'
import { st } from '@/i18n' import { st } from '@/i18n'
import type { ResultItem } from '@/schemas/apiSchema'
import { import {
type ComfyWorkflowJSON, type ComfyWorkflowJSON,
type ModelFile, type ModelFile,
@@ -77,7 +78,7 @@ function sanitizeNodeName(string) {
} }
type Clipspace = { type Clipspace = {
widgets?: { type?: string; name?: string; value?: any }[] | null widgets?: Pick<IWidget, 'type' | 'name' | 'value'>[] | null
imgs?: HTMLImageElement[] | null imgs?: HTMLImageElement[] | null
original_imgs?: HTMLImageElement[] | null original_imgs?: HTMLImageElement[] | null
images?: any[] | null images?: any[] | null
@@ -301,7 +302,7 @@ export class ComfyApp {
} }
} }
static pasteFromClipspace(node) { static pasteFromClipspace(node: LGraphNode) {
if (ComfyApp.clipspace) { if (ComfyApp.clipspace) {
// image paste // image paste
if (ComfyApp.clipspace.imgs && node.imgs) { if (ComfyApp.clipspace.imgs && node.imgs) {
@@ -344,6 +345,7 @@ export class ComfyApp {
const index = node.widgets.findIndex((obj) => obj.name === 'image') const index = node.widgets.findIndex((obj) => obj.name === 'image')
if (index >= 0) { if (index >= 0) {
if ( if (
// @ts-expect-error custom widget type
node.widgets[index].type != 'image' && node.widgets[index].type != 'image' &&
typeof node.widgets[index].value == 'string' && typeof node.widgets[index].value == 'string' &&
clip_image.filename clip_image.filename
@@ -360,27 +362,23 @@ export class ComfyApp {
if (ComfyApp.clipspace.widgets) { if (ComfyApp.clipspace.widgets) {
ComfyApp.clipspace.widgets.forEach(({ type, name, value }) => { ComfyApp.clipspace.widgets.forEach(({ type, name, value }) => {
const prop = Object.values(node.widgets).find( const prop = Object.values(node.widgets).find(
// @ts-expect-errorg
(obj) => obj.type === type && obj.name === name (obj) => obj.type === type && obj.name === name
) )
// @ts-expect-error
if (prop && prop.type != 'button') { if (prop && prop.type != 'button') {
if ( if (
// @ts-expect-error // @ts-expect-error Custom widget type
prop.type != 'image' && prop.type != 'image' &&
// @ts-expect-error
typeof prop.value == 'string' && typeof prop.value == 'string' &&
// @ts-expect-error Custom widget value
value.filename value.filename
) { ) {
// @ts-expect-error const resultItem = value as ResultItem
prop.value = prop.value =
(value.subfolder ? value.subfolder + '/' : '') + (resultItem.subfolder ? resultItem.subfolder + '/' : '') +
value.filename + resultItem.filename +
(value.type ? ` [${value.type}]` : '') (resultItem.type ? ` [${resultItem.type}]` : '')
} else { } else {
// @ts-expect-error
prop.value = value prop.value = value
// @ts-expect-error
prop.callback?.(value) prop.callback?.(value)
} }
} }
@@ -1166,10 +1164,10 @@ export class ComfyApp {
) { ) {
if (widget.name == 'control_after_generate') { if (widget.name == 'control_after_generate') {
if (widget.value === true) { if (widget.value === true) {
// @ts-expect-error change widget type from boolean to string // @ts-expect-error string is not assignable to boolean
widget.value = 'randomize' widget.value = 'randomize'
} else if (widget.value === false) { } else if (widget.value === false) {
// @ts-expect-error change widget type from boolean to string // @ts-expect-error string is not assignable to boolean
widget.value = 'fixed' widget.value = 'fixed'
} }
} }