mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-24 06:32:12 -03:00
refactor(lora-pool-widget): make ComponentWidget generic and remove legacy config
- Add generic type parameter to ComponentWidget<T> for type-safe callbacks - Remove LegacyLoraPoolConfig interface and migrateConfig function - Update LoraPoolWidget to use ComponentWidget<LoraPoolConfig> - Clean up type imports across widget files
This commit is contained in:
@@ -37,22 +37,6 @@ export interface FolderTreeNode {
|
||||
children?: FolderTreeNode[]
|
||||
}
|
||||
|
||||
// Legacy config for migration (v1)
|
||||
export interface LegacyLoraPoolConfig {
|
||||
version: 1
|
||||
filters: {
|
||||
baseModels: string[]
|
||||
tags: { include: string[]; exclude: string[] }
|
||||
folder: { path: string | null; recursive: boolean }
|
||||
favoritesOnly: boolean
|
||||
license: {
|
||||
noCreditRequired: boolean | null
|
||||
allowSellingGeneratedContent: boolean | null
|
||||
}
|
||||
}
|
||||
preview: { matchCount: number; lastUpdated: number }
|
||||
}
|
||||
|
||||
// Randomizer config
|
||||
export interface RandomizerConfig {
|
||||
count_mode: 'fixed' | 'range'
|
||||
@@ -98,14 +82,17 @@ export interface CyclerConfig {
|
||||
next_index?: number | null // Index for display after execution
|
||||
}
|
||||
|
||||
export interface ComponentWidget {
|
||||
// Widget config union type
|
||||
export type WidgetConfig = LoraPoolConfig | RandomizerConfig | CyclerConfig
|
||||
|
||||
export interface ComponentWidget<T = WidgetConfig> {
|
||||
/** @deprecated Use callback instead. Kept for backward compatibility with other widgets. */
|
||||
serializeValue?: () => Promise<LoraPoolConfig | RandomizerConfig | CyclerConfig>
|
||||
value?: LoraPoolConfig | LegacyLoraPoolConfig | RandomizerConfig | CyclerConfig
|
||||
serializeValue?: () => Promise<T>
|
||||
value?: T
|
||||
/** @deprecated Use callback instead. Kept for backward compatibility with other widgets. */
|
||||
onSetValue?: (v: LoraPoolConfig | LegacyLoraPoolConfig | RandomizerConfig | CyclerConfig) => void
|
||||
onSetValue?: (v: T) => void
|
||||
/** @deprecated Directly set widget.value instead. Kept for backward compatibility with other widgets. */
|
||||
updateConfig?: (v: LoraPoolConfig | RandomizerConfig | CyclerConfig) => void
|
||||
updateConfig?: (v: T) => void
|
||||
/** Called by ComfyUI automatically after setValue() - use this for UI sync */
|
||||
callback?: (v: LoraPoolConfig | LegacyLoraPoolConfig | RandomizerConfig | CyclerConfig) => void
|
||||
callback?: (v: T) => void
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import type {
|
||||
LoraPoolConfig,
|
||||
LegacyLoraPoolConfig,
|
||||
BaseModelOption,
|
||||
TagOption,
|
||||
FolderTreeNode,
|
||||
@@ -10,7 +9,7 @@ import type {
|
||||
} from './types'
|
||||
import { useLoraPoolApi } from './useLoraPoolApi'
|
||||
|
||||
export function useLoraPoolState(widget: ComponentWidget) {
|
||||
export function useLoraPoolState(widget: ComponentWidget<LoraPoolConfig>) {
|
||||
const api = useLoraPoolApi()
|
||||
|
||||
// Flag to prevent infinite loops during config restoration
|
||||
@@ -70,41 +69,13 @@ export function useLoraPoolState(widget: ComponentWidget) {
|
||||
return config
|
||||
}
|
||||
|
||||
// Migrate legacy config (v1) to current format (v2)
|
||||
const migrateConfig = (legacy: LegacyLoraPoolConfig): LoraPoolConfig => {
|
||||
return {
|
||||
version: 2,
|
||||
filters: {
|
||||
baseModels: legacy.filters.baseModels || [],
|
||||
tags: {
|
||||
include: legacy.filters.tags?.include || [],
|
||||
exclude: legacy.filters.tags?.exclude || []
|
||||
},
|
||||
folders: {
|
||||
include: legacy.filters.folder?.path ? [legacy.filters.folder.path] : [],
|
||||
exclude: []
|
||||
},
|
||||
license: {
|
||||
noCreditRequired: legacy.filters.license?.noCreditRequired ?? false,
|
||||
allowSelling: legacy.filters.license?.allowSellingGeneratedContent ?? false
|
||||
}
|
||||
},
|
||||
preview: legacy.preview || { matchCount: 0, lastUpdated: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
// Restore state from config
|
||||
const restoreFromConfig = (rawConfig: LoraPoolConfig | LegacyLoraPoolConfig) => {
|
||||
const restoreFromConfig = (config: LoraPoolConfig) => {
|
||||
// Set flag to prevent buildConfig from triggering widget.value updates during restoration
|
||||
// This breaks the infinite loop: callback → restoreFromConfig → watch → refreshPreview → buildConfig → widget.value = config → callback
|
||||
isRestoring = true
|
||||
|
||||
try {
|
||||
// Migrate if needed
|
||||
const config = rawConfig.version === 1
|
||||
? migrateConfig(rawConfig as LegacyLoraPoolConfig)
|
||||
: rawConfig as LoraPoolConfig
|
||||
|
||||
if (!config?.filters) return
|
||||
|
||||
const { filters, preview } = config
|
||||
|
||||
Reference in New Issue
Block a user