mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-04 04:30:04 +00:00
Move schema to dedicated file, remove cast
This commit is contained in:
@@ -6,13 +6,13 @@ import draggable from 'vuedraggable'
|
||||
import SearchBox from '@/components/common/SearchBox.vue'
|
||||
import SubgraphNodeWidget from '@/components/selectionbar/SubgraphNodeWidget.vue'
|
||||
import SidebarTabTemplate from '@/components/sidebar/tabs/SidebarTabTemplate.vue'
|
||||
import {
|
||||
type ProxyWidgetsProperty,
|
||||
parseProxyWidgets
|
||||
} from '@/extensions/core/proxyWidget'
|
||||
import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
|
||||
import { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode'
|
||||
import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets'
|
||||
import {
|
||||
type ProxyWidgetsProperty,
|
||||
parseProxyWidgets
|
||||
} from '@/schemas/proxyWidget'
|
||||
import { useCanvasStore } from '@/stores/graphStore'
|
||||
|
||||
type WidgetItem = [LGraphNode, IBaseWidget]
|
||||
|
||||
@@ -1,40 +1,13 @@
|
||||
import { z } from 'zod'
|
||||
import { fromZodError } from 'zod-validation-error'
|
||||
|
||||
import type { NodeProperty } from '@/lib/litegraph/src/LGraphNode'
|
||||
import type { LGraph, LGraphNode } from '@/lib/litegraph/src/litegraph'
|
||||
import { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode'
|
||||
import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets.ts'
|
||||
import { disconnectedWidget } from '@/lib/litegraph/src/widgets/DisconnectedWidget'
|
||||
import { parseProxyWidgets } from '@/schemas/proxyWidget'
|
||||
import { DOMWidgetImpl } from '@/scripts/domWidget'
|
||||
import { useExtensionService } from '@/services/extensionService'
|
||||
import { useDomWidgetStore } from '@/stores/domWidgetStore'
|
||||
import { useCanvasStore } from '@/stores/graphStore'
|
||||
|
||||
const canvasStore = useCanvasStore()
|
||||
|
||||
export const proxyWidgetsPropertySchema = z.array(
|
||||
z.tuple([z.string(), z.string()])
|
||||
)
|
||||
export type ProxyWidgetsProperty = z.infer<typeof proxyWidgetsPropertySchema>
|
||||
//export type proxyWidgetsProperty = [string, string][]
|
||||
|
||||
export function parseProxyWidgets(
|
||||
property: NodeProperty | undefined
|
||||
): ProxyWidgetsProperty {
|
||||
if (typeof property !== 'string') {
|
||||
console.error(`Found non-string value for properties.proxyWidgets`)
|
||||
return []
|
||||
}
|
||||
const parsed = JSON.parse(property)
|
||||
const result = proxyWidgetsPropertySchema.safeParse(parsed)
|
||||
if (result.success) return result.data ?? []
|
||||
|
||||
const error = fromZodError(result.error)
|
||||
console.error(`Invalid assignment for properties.proxyWidgets:\n${error}`)
|
||||
return []
|
||||
}
|
||||
|
||||
useExtensionService().registerExtension({
|
||||
name: 'Comfy.SubgraphProxyWidgets',
|
||||
nodeCreated(node: LGraphNode) {
|
||||
@@ -44,6 +17,7 @@ useExtensionService().registerExtension({
|
||||
}
|
||||
})
|
||||
function injectProperty(subgraphNode: SubgraphNode) {
|
||||
const canvasStore = useCanvasStore()
|
||||
subgraphNode.properties.proxyWidgets ??= []
|
||||
const proxyWidgets = subgraphNode.properties.proxyWidgets
|
||||
Object.defineProperty(subgraphNode.properties, 'proxyWidgets', {
|
||||
@@ -155,7 +129,7 @@ function addProxyFromOverlay(subgraphNode: SubgraphNode, overlay: Overlay) {
|
||||
'label'
|
||||
].includes(p)
|
||||
)
|
||||
t = overlay
|
||||
r = t = overlay
|
||||
else {
|
||||
t = bw
|
||||
if (p == 'value') r = t
|
||||
@@ -165,7 +139,7 @@ function addProxyFromOverlay(subgraphNode: SubgraphNode, overlay: Overlay) {
|
||||
return [s, func]
|
||||
})
|
||||
)
|
||||
const w = new Proxy(overlay, handler) as unknown as ProxyWidget
|
||||
const w = new Proxy(disconnectedWidget, handler)
|
||||
subgraphNode.widgets.push(w)
|
||||
return w
|
||||
}
|
||||
|
||||
25
src/schemas/proxyWidget.ts
Normal file
25
src/schemas/proxyWidget.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { z } from 'zod'
|
||||
import { fromZodError } from 'zod-validation-error'
|
||||
|
||||
import type { NodeProperty } from '@/lib/litegraph/src/LGraphNode'
|
||||
|
||||
export const proxyWidgetsPropertySchema = z.array(
|
||||
z.tuple([z.string(), z.string()])
|
||||
)
|
||||
export type ProxyWidgetsProperty = z.infer<typeof proxyWidgetsPropertySchema>
|
||||
|
||||
export function parseProxyWidgets(
|
||||
property: NodeProperty | undefined
|
||||
): ProxyWidgetsProperty {
|
||||
if (typeof property !== 'string') {
|
||||
console.error(`Found non-string value for properties.proxyWidgets`)
|
||||
return []
|
||||
}
|
||||
const parsed = JSON.parse(property)
|
||||
const result = proxyWidgetsPropertySchema.safeParse(parsed)
|
||||
if (result.success) return result.data ?? []
|
||||
|
||||
const error = fromZodError(result.error)
|
||||
console.error(`Invalid assignment for properties.proxyWidgets:\n${error}`)
|
||||
return []
|
||||
}
|
||||
Reference in New Issue
Block a user