Fix copy paste of widget value (#284)

* Fix copy paste of widget value

* Fix ui tests

* Allow undefined group font size

* Update test expectations [skip ci]

* nit

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Chenlei Hu
2024-08-03 14:22:43 -04:00
committed by GitHub
parent f0f867481d
commit 0cf5e647af
8 changed files with 93 additions and 88 deletions

View File

@@ -74,7 +74,7 @@ const zGroup = z
title: z.string(),
bounding: z.tuple([z.number(), z.number(), z.number(), z.number()]),
color: z.string(),
font_size: z.number(),
font_size: z.number().optional(),
locked: z.boolean().optional()
})
.passthrough()
@@ -131,16 +131,15 @@ export type ComfyLink = z.infer<typeof zComfyLink>
export type ComfyNode = z.infer<typeof zComfyNode>
export type ComfyWorkflowJSON = z.infer<typeof zComfyWorkflow>
export async function parseComfyWorkflow(
data: string
): Promise<ComfyWorkflowJSON> {
// Validate
const result = await zComfyWorkflow.safeParseAsync(JSON.parse(data))
export async function validateComfyWorkflow(
data: any,
onError: (error: string) => void = console.warn
): Promise<ComfyWorkflowJSON | null> {
const result = await zComfyWorkflow.safeParseAsync(data)
if (!result.success) {
// TODO: Pretty print the error on UI modal.
const error = fromZodError(result.error)
alert(`Invalid workflow against zod schema:\n${error}`)
throw error
onError(`Invalid workflow against zod schema:\n${error}`)
return null
}
return result.data
}