feat(lora-pool): add external value handling and config update support

- Add `onSetValue` callback to handle external updates like workflow loading
- Implement `updateConfig` method for direct widget value updates
- Add value change detection in `restoreFromConfig` to prevent unnecessary updates
- Remove debug console log on component mount
- Extend widget value type to support legacy config format
This commit is contained in:
Will Miao
2026-01-11 20:37:17 +08:00
parent b44ef9ceaa
commit 7a5f4514f3
6 changed files with 84 additions and 25 deletions

View File

@@ -76,8 +76,6 @@ const openModal = (modal: ModalType) => {
// Lifecycle
onMounted(async () => {
console.log('[LoraPoolWidget] Mounted, node ID:', props.node.id)
// Setup serialization
props.widget.serializeValue = async () => {
const config = state.buildConfig()
@@ -85,6 +83,12 @@ onMounted(async () => {
return config
}
// Handle external value updates (e.g., loading workflow, paste)
props.widget.onSetValue = (v) => {
state.restoreFromConfig(v)
state.refreshPreview()
}
// Restore from saved value
if (props.widget.value) {
console.log('[LoraPoolWidget] Restoring from saved value:', props.widget.value)

View File

@@ -39,7 +39,9 @@ export interface FolderTreeNode {
export interface ComponentWidget {
serializeValue?: () => Promise<LoraPoolConfig>
value?: LoraPoolConfig
value?: LoraPoolConfig | LegacyLoraPoolConfig
onSetValue?: (v: LoraPoolConfig | LegacyLoraPoolConfig) => void
updateConfig?: (v: LoraPoolConfig) => void
}
// Legacy config for migration (v1)

View File

@@ -58,7 +58,11 @@ export function useLoraPoolState(widget: ComponentWidget) {
}
// Update widget value
widget.value = config
if (widget.updateConfig) {
widget.updateConfig(config)
} else {
widget.value = config
}
return config
}
@@ -95,13 +99,23 @@ export function useLoraPoolState(widget: ComponentWidget) {
if (!config?.filters) return
const { filters, preview } = config
selectedBaseModels.value = filters.baseModels || []
includeTags.value = filters.tags?.include || []
excludeTags.value = filters.tags?.exclude || []
includeFolders.value = filters.folders?.include || []
excludeFolders.value = filters.folders?.exclude || []
noCreditRequired.value = filters.license?.noCreditRequired ?? false
allowSelling.value = filters.license?.allowSelling ?? false
// Helper to update ref only if value changed
const updateIfChanged = <T>(refValue: { value: T }, newValue: T) => {
if (JSON.stringify(refValue.value) !== JSON.stringify(newValue)) {
refValue.value = newValue
}
}
updateIfChanged(selectedBaseModels, filters.baseModels || [])
updateIfChanged(includeTags, filters.tags?.include || [])
updateIfChanged(excludeTags, filters.tags?.exclude || [])
updateIfChanged(includeFolders, filters.folders?.include || [])
updateIfChanged(excludeFolders, filters.folders?.exclude || [])
updateIfChanged(noCreditRequired, filters.license?.noCreditRequired ?? false)
updateIfChanged(allowSelling, filters.license?.allowSelling ?? false)
// matchCount doesn't trigger watchers, so direct assignment is fine
matchCount.value = preview?.matchCount || 0
}

View File

@@ -1,6 +1,7 @@
import { createApp, type App as VueApp } from 'vue'
import PrimeVue from 'primevue/config'
import LoraPoolWidget from '@/components/LoraPoolWidget.vue'
import type { LoraPoolConfig, LegacyLoraPoolConfig } from './composables/types'
// @ts-ignore - ComfyUI external module
import { app } from '../../../scripts/app.js'
@@ -17,16 +18,30 @@ function createLoraPoolWidget(node) {
container.style.flexDirection = 'column'
container.style.overflow = 'hidden'
let internalValue: LoraPoolConfig | LegacyLoraPoolConfig | undefined
const widget = node.addDOMWidget(
'pool_config',
'LORA_POOL_CONFIG',
container,
{
// getMinHeight: () => 680,
getValue() {
return internalValue
},
setValue(v: LoraPoolConfig | LegacyLoraPoolConfig) {
internalValue = v
if (typeof widget.onSetValue === 'function') {
widget.onSetValue(v)
}
},
serialize: true
}
)
widget.updateConfig = (v: LoraPoolConfig) => {
internalValue = v
}
const vueApp = createApp(LoraPoolWidget, {
widget,
node

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long