mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-07 06:00:03 +00:00
alias old float/int widgets
This commit is contained in:
@@ -1,21 +1,40 @@
|
||||
import type { LGraphNode } from '@comfyorg/litegraph'
|
||||
import { ref } from 'vue'
|
||||
import { reactive, ref } from 'vue'
|
||||
|
||||
import BadgedNumberInput from '@/components/graph/widgets/BadgedNumberInput.vue'
|
||||
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
|
||||
import { ComponentWidgetImpl, addWidget } from '@/scripts/domWidget'
|
||||
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
|
||||
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
|
||||
|
||||
const PADDING = 8
|
||||
|
||||
type BadgeState = 'normal' | 'random' | 'lock' | 'increment' | 'decrement'
|
||||
|
||||
type NumberWidgetMode = 'int' | 'float'
|
||||
|
||||
interface BadgedNumberInputOptions {
|
||||
defaultValue?: number
|
||||
badgeState?: BadgeState
|
||||
disabled?: boolean
|
||||
minHeight?: number
|
||||
serialize?: boolean
|
||||
mode?: NumberWidgetMode
|
||||
}
|
||||
|
||||
// Helper function to map control widget values to badge states
|
||||
const mapControlValueToBadgeState = (controlValue: string): BadgeState => {
|
||||
switch (controlValue) {
|
||||
case 'fixed':
|
||||
return 'lock'
|
||||
case 'increment':
|
||||
return 'increment'
|
||||
case 'decrement':
|
||||
return 'decrement'
|
||||
case 'randomize':
|
||||
return 'random'
|
||||
default:
|
||||
return 'normal'
|
||||
}
|
||||
}
|
||||
|
||||
export const useBadgedNumberInput = (
|
||||
@@ -23,10 +42,10 @@ export const useBadgedNumberInput = (
|
||||
) => {
|
||||
const {
|
||||
defaultValue = 0,
|
||||
badgeState = 'normal',
|
||||
disabled = false,
|
||||
minHeight = 40,
|
||||
serialize = true
|
||||
serialize = true,
|
||||
mode = 'int'
|
||||
} = options
|
||||
|
||||
const widgetConstructor: ComfyWidgetConstructorV2 = (
|
||||
@@ -36,7 +55,23 @@ export const useBadgedNumberInput = (
|
||||
// Initialize widget value as string to conform to ComponentWidgetImpl requirements
|
||||
const widgetValue = ref<string>(defaultValue.toString())
|
||||
|
||||
// Create the widget instance
|
||||
// Determine if we should show control widget and badge
|
||||
const shouldShowControlWidget =
|
||||
inputSpec.control_after_generate ??
|
||||
// Legacy compatibility: seed inputs get control widgets
|
||||
['seed', 'noise_seed'].includes(inputSpec.name)
|
||||
|
||||
// Create reactive props object for the component
|
||||
const componentProps = reactive({
|
||||
badgeState:
|
||||
options.badgeState ??
|
||||
(shouldShowControlWidget ? 'random' : ('normal' as BadgeState)),
|
||||
disabled
|
||||
})
|
||||
|
||||
const controlWidget: any = null
|
||||
|
||||
// Create the main widget instance
|
||||
const widget = new ComponentWidgetImpl<
|
||||
string | object,
|
||||
Omit<
|
||||
@@ -48,24 +83,34 @@ export const useBadgedNumberInput = (
|
||||
name: inputSpec.name,
|
||||
component: BadgedNumberInput,
|
||||
inputSpec,
|
||||
props: {
|
||||
badgeState,
|
||||
disabled
|
||||
},
|
||||
props: componentProps,
|
||||
options: {
|
||||
// Required: getter for widget value - return as string
|
||||
getValue: () => widgetValue.value as string | object,
|
||||
|
||||
// Required: setter for widget value - accept number, string or object
|
||||
setValue: (value: string | object | number) => {
|
||||
let stringValue: string
|
||||
let numValue: number
|
||||
if (typeof value === 'object') {
|
||||
stringValue = JSON.stringify(value)
|
||||
numValue = parseFloat(JSON.stringify(value))
|
||||
} else {
|
||||
stringValue = String(value)
|
||||
numValue =
|
||||
typeof value === 'number' ? value : parseFloat(String(value))
|
||||
}
|
||||
const numValue = parseFloat(stringValue)
|
||||
|
||||
if (!isNaN(numValue)) {
|
||||
// Apply int/float specific value processing
|
||||
if (mode === 'int') {
|
||||
const step = (inputSpec as any).step ?? 1
|
||||
if (step === 1) {
|
||||
numValue = Math.round(numValue)
|
||||
} else {
|
||||
const min = (inputSpec as any).min ?? 0
|
||||
const offset = min % step
|
||||
numValue =
|
||||
Math.round((numValue - offset) / step) * step + offset
|
||||
}
|
||||
}
|
||||
widgetValue.value = numValue.toString()
|
||||
}
|
||||
},
|
||||
@@ -78,6 +123,41 @@ export const useBadgedNumberInput = (
|
||||
}
|
||||
})
|
||||
|
||||
// Add control widget if needed - temporarily disabled to fix circular dependency
|
||||
if (shouldShowControlWidget) {
|
||||
// TODO: Re-implement control widget functionality without circular dependency
|
||||
console.warn(
|
||||
'Control widget functionality temporarily disabled due to circular dependency'
|
||||
)
|
||||
// controlWidget = addValueControlWidget(
|
||||
// node,
|
||||
// widget as any, // Cast to satisfy the interface
|
||||
// 'randomize',
|
||||
// undefined,
|
||||
// undefined,
|
||||
// transformInputSpecV2ToV1(inputSpec)
|
||||
// )
|
||||
|
||||
// Set up reactivity to update badge state when control widget changes
|
||||
if (controlWidget) {
|
||||
const originalCallback = controlWidget.callback
|
||||
controlWidget.callback = function (value: string) {
|
||||
componentProps.badgeState = mapControlValueToBadgeState(value)
|
||||
if (originalCallback) {
|
||||
originalCallback.call(this, value)
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize badge state
|
||||
componentProps.badgeState = mapControlValueToBadgeState(
|
||||
controlWidget.value || 'randomize'
|
||||
)
|
||||
|
||||
// Link the widgets
|
||||
;(widget as any).linkedWidgets = [controlWidget]
|
||||
}
|
||||
}
|
||||
|
||||
// Register the widget with the node
|
||||
addWidget(node, widget)
|
||||
|
||||
@@ -88,4 +168,4 @@ export const useBadgedNumberInput = (
|
||||
}
|
||||
|
||||
// Export types for use in other modules
|
||||
export type { BadgeState, BadgedNumberInputOptions }
|
||||
export type { BadgeState, BadgedNumberInputOptions, NumberWidgetMode }
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
type InputSpec,
|
||||
isBooleanInputSpec
|
||||
} from '@/schemas/nodeDef/nodeDefSchemaV2'
|
||||
import { type ComfyWidgetConstructorV2 } from '@/scripts/widgets'
|
||||
import { type ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
|
||||
|
||||
export const useBooleanWidget = () => {
|
||||
const widgetConstructor: ComfyWidgetConstructorV2 = (
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ref } from 'vue'
|
||||
import ChatHistoryWidget from '@/components/graph/widgets/ChatHistoryWidget.vue'
|
||||
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
|
||||
import { ComponentWidgetImpl, addWidget } from '@/scripts/domWidget'
|
||||
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
|
||||
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
|
||||
|
||||
const PADDING = 16
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ import type { IComboWidget } from '@comfyorg/litegraph/dist/types/widgets'
|
||||
import { ref } from 'vue'
|
||||
|
||||
import MultiSelectWidget from '@/components/graph/widgets/MultiSelectWidget.vue'
|
||||
import { transformInputSpecV2ToV1 } from '@/schemas/nodeDef/migration'
|
||||
import {
|
||||
ComboInputSpec,
|
||||
type InputSpec,
|
||||
@@ -14,10 +13,7 @@ import {
|
||||
ComponentWidgetImpl,
|
||||
addWidget
|
||||
} from '@/scripts/domWidget'
|
||||
import {
|
||||
type ComfyWidgetConstructorV2,
|
||||
addValueControlWidgets
|
||||
} from '@/scripts/widgets'
|
||||
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
|
||||
|
||||
import { useRemoteWidget } from './useRemoteWidget'
|
||||
|
||||
@@ -82,13 +78,17 @@ const addComboWidget = (node: LGraphNode, inputSpec: ComboInputSpec) => {
|
||||
}
|
||||
|
||||
if (inputSpec.control_after_generate) {
|
||||
widget.linkedWidgets = addValueControlWidgets(
|
||||
node,
|
||||
widget,
|
||||
undefined,
|
||||
undefined,
|
||||
transformInputSpecV2ToV1(inputSpec)
|
||||
// TODO: Re-implement control widget functionality without circular dependency
|
||||
console.warn(
|
||||
'Control widget functionality temporarily disabled for combo widgets due to circular dependency'
|
||||
)
|
||||
// widget.linkedWidgets = addValueControlWidgets(
|
||||
// node,
|
||||
// widget,
|
||||
// undefined,
|
||||
// undefined,
|
||||
// transformInputSpecV2ToV1(inputSpec)
|
||||
// )
|
||||
}
|
||||
|
||||
return widget
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
type InputSpec,
|
||||
isFloatInputSpec
|
||||
} from '@/schemas/nodeDef/nodeDefSchemaV2'
|
||||
import { type ComfyWidgetConstructorV2 } from '@/scripts/widgets'
|
||||
import { type ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
|
||||
import { useSettingStore } from '@/stores/settingStore'
|
||||
|
||||
function onFloatValueChange(this: INumericWidget, v: number) {
|
||||
|
||||
@@ -12,7 +12,7 @@ import type {
|
||||
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
|
||||
import { app } from '@/scripts/app'
|
||||
import { calculateImageGrid } from '@/scripts/ui/imagePreview'
|
||||
import { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
|
||||
import { ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
|
||||
import { useCanvasStore } from '@/stores/graphStore'
|
||||
import { useSettingStore } from '@/stores/settingStore'
|
||||
import { is_all_same_aspect_ratio } from '@/utils/imageUtil'
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
import type { LGraphNode } from '@comfyorg/litegraph'
|
||||
import type { INumericWidget } from '@comfyorg/litegraph/dist/types/widgets'
|
||||
|
||||
import { transformInputSpecV2ToV1 } from '@/schemas/nodeDef/migration'
|
||||
import {
|
||||
type InputSpec,
|
||||
isIntInputSpec
|
||||
} from '@/schemas/nodeDef/nodeDefSchemaV2'
|
||||
import {
|
||||
type ComfyWidgetConstructorV2,
|
||||
addValueControlWidget
|
||||
} from '@/scripts/widgets'
|
||||
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
|
||||
import { useSettingStore } from '@/stores/settingStore'
|
||||
|
||||
function onValueChange(this: INumericWidget, v: number) {
|
||||
@@ -81,15 +77,19 @@ export const useIntWidget = () => {
|
||||
['seed', 'noise_seed'].includes(inputSpec.name)
|
||||
|
||||
if (controlAfterGenerate) {
|
||||
const seedControl = addValueControlWidget(
|
||||
node,
|
||||
widget,
|
||||
'randomize',
|
||||
undefined,
|
||||
undefined,
|
||||
transformInputSpecV2ToV1(inputSpec)
|
||||
// TODO: Re-implement control widget functionality without circular dependency
|
||||
console.warn(
|
||||
'Control widget functionality temporarily disabled for int widgets due to circular dependency'
|
||||
)
|
||||
widget.linkedWidgets = [seedControl]
|
||||
// const seedControl = addValueControlWidget(
|
||||
// node,
|
||||
// widget,
|
||||
// 'randomize',
|
||||
// undefined,
|
||||
// undefined,
|
||||
// transformInputSpecV2ToV1(inputSpec)
|
||||
// )
|
||||
// widget.linkedWidgets = [seedControl]
|
||||
}
|
||||
|
||||
return widget
|
||||
|
||||
@@ -10,7 +10,7 @@ import { Markdown as TiptapMarkdown } from 'tiptap-markdown'
|
||||
|
||||
import { type InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
|
||||
import { app } from '@/scripts/app'
|
||||
import { type ComfyWidgetConstructorV2 } from '@/scripts/widgets'
|
||||
import { type ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
|
||||
|
||||
function addMarkdownWidget(
|
||||
node: LGraphNode,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ref } from 'vue'
|
||||
import TextPreviewWidget from '@/components/graph/widgets/TextPreviewWidget.vue'
|
||||
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
|
||||
import { ComponentWidgetImpl, addWidget } from '@/scripts/domWidget'
|
||||
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
|
||||
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
|
||||
|
||||
const PADDING = 16
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
isStringInputSpec
|
||||
} from '@/schemas/nodeDef/nodeDefSchemaV2'
|
||||
import { app } from '@/scripts/app'
|
||||
import { type ComfyWidgetConstructorV2 } from '@/scripts/widgets'
|
||||
import { type ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
|
||||
import { useSettingStore } from '@/stores/settingStore'
|
||||
|
||||
function addMultilineWidget(
|
||||
|
||||
Reference in New Issue
Block a user