Skip to content

Commit 6671d57

Browse files
committed
fix: Improve legacy widget compatibility in vueNodes mode
1 parent 533295a commit 6671d57

File tree

5 files changed

+55
-13
lines changed

5 files changed

+55
-13
lines changed

src/composables/graph/useGraphNodeManager.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import type {
3434
} from '@/lib/litegraph/src/litegraph'
3535
import type { TitleMode } from '@/lib/litegraph/src/types/globalEnums'
3636
import { NodeSlotType } from '@/lib/litegraph/src/types/globalEnums'
37+
import { app } from '@/scripts/app'
3738

3839
export interface WidgetSlotMetadata {
3940
index: number
@@ -47,6 +48,7 @@ export interface SafeWidgetData {
4748
borderStyle?: string
4849
callback?: ((value: unknown) => void) | undefined
4950
controlWidget?: SafeControlWidget
51+
hasLayoutSize?: boolean
5052
isDOMWidget?: boolean
5153
label?: string
5254
nodeType?: string
@@ -171,7 +173,12 @@ export function safeWidgetMapper(
171173
const callback = (v: unknown) => {
172174
const value = normalizeWidgetValue(v)
173175
widget.value = value ?? undefined
174-
widget.callback?.(value)
176+
// Match litegraph callback signature: (value, canvas, node, pos, event)
177+
// Some extensions (e.g., Impact Pack) expect node as the 3rd parameter
178+
widget.callback?.(value, app.canvas, node)
179+
// Trigger redraw for all legacy widgets on this node (e.g., mask preview)
180+
// This ensures widgets that depend on other widget values get updated
181+
node.widgets?.forEach((w) => w.triggerDraw?.())
175182
}
176183

177184
return {
@@ -181,6 +188,7 @@ export function safeWidgetMapper(
181188
borderStyle,
182189
callback,
183190
controlWidget: getControlWidget(widget),
191+
hasLayoutSize: typeof widget.computeLayoutSize === 'function',
184192
isDOMWidget: isDOMWidget(widget),
185193
label: widget.label,
186194
nodeType: getNodeType(node, widget),

src/renderer/extensions/vueNodes/components/NodeWidgets.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,13 @@ const processedWidgets = computed((): ProcessedWidget[] => {
203203
})
204204
205205
const gridTemplateRows = computed((): string => {
206-
const widgets = toValue(processedWidgets)
207-
return widgets
208-
.filter((w) => !w.simplified.options?.hidden)
209-
.map((w) => (shouldExpand(w.type) ? 'auto' : 'min-content'))
206+
if (!nodeData?.widgets) return ''
207+
const processedNames = new Set(toValue(processedWidgets).map((w) => w.name))
208+
return nodeData.widgets
209+
.filter((w) => processedNames.has(w.name) && !w.options?.hidden)
210+
.map((w) =>
211+
shouldExpand(w.type) || w.hasLayoutSize ? 'auto' : 'min-content'
212+
)
210213
.join(' ')
211214
})
212215
</script>

src/renderer/extensions/vueNodes/widgets/components/WidgetInputNumberInput.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,17 @@ const precision = computed(() => {
3131
3232
// Calculate the step value based on precision or widget options
3333
const stepValue = computed(() => {
34-
// Use step2 (correct input spec value) instead of step (legacy 10x value)
34+
// Use step2 (correct input spec value) if available
3535
if (props.widget.options?.step2 !== undefined) {
3636
return Number(props.widget.options.step2)
3737
}
38+
// Use step / 10 for custom large step values (> 10) to match litegraph behavior
39+
// This is important for extensions like Impact Pack that use custom step values (e.g., 640)
40+
// We skip default step values (1, 10) to avoid affecting normal widgets
41+
const step = props.widget.options?.step
42+
if (step !== undefined && step > 10) {
43+
return Number(step) / 10
44+
}
3845
// Otherwise, derive from precision
3946
if (precision.value !== undefined) {
4047
if (precision.value === 0) {

src/renderer/extensions/vueNodes/widgets/components/WidgetLegacy.vue

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const props = defineProps<{
1717
}>()
1818
1919
const canvasEl = ref()
20+
const containerHeight = ref(20)
2021
2122
const canvas: LGraphCanvas = useCanvasStore().canvas as LGraphCanvas
2223
let node: LGraphNode | undefined
@@ -52,9 +53,19 @@ onBeforeUnmount(() => {
5253
function draw() {
5354
if (!widgetInstance || !node) return
5455
const width = canvasEl.value.parentElement.clientWidth
55-
const height = widgetInstance.computeSize
56-
? widgetInstance.computeSize(width)[1]
57-
: 20
56+
// Priority: computedHeight (from litegraph) > computeLayoutSize > computeSize
57+
let height = 20
58+
if (widgetInstance.computedHeight) {
59+
height = widgetInstance.computedHeight
60+
} else if (widgetInstance.computeLayoutSize) {
61+
height = widgetInstance.computeLayoutSize(node).minHeight
62+
} else if (widgetInstance.computeSize) {
63+
height = widgetInstance.computeSize(width)[1]
64+
}
65+
containerHeight.value = height
66+
// Set node.canvasHeight for legacy widgets that use it (e.g., Impact Pack)
67+
// @ts-expect-error canvasHeight is a custom property used by some extensions
68+
node.canvasHeight = height
5869
widgetInstance.y = 0
5970
canvasEl.value.height = (height + 2) * scaleFactor
6071
canvasEl.value.width = width * scaleFactor
@@ -87,7 +98,10 @@ function handleMove(e: PointerEvent) {
8798
}
8899
</script>
89100
<template>
90-
<div class="relative mx-[-12px] min-w-0 basis-0">
101+
<div
102+
class="relative mx-[-12px] min-w-0 basis-0"
103+
:style="{ minHeight: `${containerHeight}px` }"
104+
>
91105
<canvas
92106
ref="canvasEl"
93107
class="absolute mt-[-13px] w-full cursor-crosshair"

src/renderer/extensions/vueNodes/widgets/composables/useNumberStepCalculation.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { computed, toValue } from 'vue'
22
import type { MaybeRefOrGetter } from 'vue'
33

44
interface NumberWidgetOptions {
5+
step?: number
56
step2?: number
67
precision?: number
78
}
@@ -17,10 +18,17 @@ export function useNumberStepCalculation(
1718
) {
1819
return computed(() => {
1920
const precision = toValue(precisionArg)
20-
// Use step2 (correct input spec value) instead of step (legacy 10x value)
21+
// Use step2 (correct input spec value) if available
2122
if (options?.step2 !== undefined) {
2223
return Number(options.step2)
2324
}
25+
// Use step / 10 for custom large step values (> 10) to match litegraph behavior
26+
// This is important for extensions like Impact Pack that use custom step values (e.g., 640)
27+
// We skip default step values (1, 10) to avoid affecting normal widgets
28+
const step = options?.step
29+
if (step !== undefined && step > 10) {
30+
return Number(step) / 10
31+
}
2432

2533
if (precision === undefined) {
2634
return returnUndefinedForDefault ? undefined : 0
@@ -29,7 +37,9 @@ export function useNumberStepCalculation(
2937
if (precision === 0) return 1
3038

3139
// For precision > 0, step = 1 / (10^precision)
32-
const step = 1 / Math.pow(10, precision)
33-
return returnUndefinedForDefault ? step : Number(step.toFixed(precision))
40+
const calculatedStep = 1 / Math.pow(10, precision)
41+
return returnUndefinedForDefault
42+
? calculatedStep
43+
: Number(calculatedStep.toFixed(precision))
3444
})
3545
}

0 commit comments

Comments
 (0)