mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 03:01:54 +00:00
Allow dynamic widgets values (#162)
This commit is contained in:
@@ -49,14 +49,7 @@ const zVector2 = z.union([
|
|||||||
z.tuple([z.number(), z.number()]),
|
z.tuple([z.number(), z.number()]),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const zWidgetValues = z.union([
|
const zWidgetValues = z.union([z.array(z.any()), z.record(z.any())]);
|
||||||
z.array(z.any()),
|
|
||||||
z.record(z.any()).transform((v) =>
|
|
||||||
Object.keys(v)
|
|
||||||
.sort((a, b) => Number(a) - Number(b))
|
|
||||||
.map((key) => v[key])
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
|
|
||||||
const zComfyNode = z
|
const zComfyNode = z
|
||||||
.object({
|
.object({
|
||||||
|
|||||||
@@ -82,9 +82,10 @@ describe("parseComfyWorkflow", () => {
|
|||||||
workflow.nodes[0].widgets_values = undefined;
|
workflow.nodes[0].widgets_values = undefined;
|
||||||
await expect(parseComfyWorkflow(JSON.stringify(workflow))).resolves.not.toThrow();
|
await expect(parseComfyWorkflow(JSON.stringify(workflow))).resolves.not.toThrow();
|
||||||
|
|
||||||
// Should automatically transform the legacy format object to array.
|
// The object format of widgets_values is used by VHS nodes to perform
|
||||||
workflow.nodes[0].widgets_values = {0: "foo", 1: "bar"};
|
// dynamic widgets display.
|
||||||
|
workflow.nodes[0].widgets_values = {"foo": "bar"};
|
||||||
const parsedWorkflow = await parseComfyWorkflow(JSON.stringify(workflow));
|
const parsedWorkflow = await parseComfyWorkflow(JSON.stringify(workflow));
|
||||||
expect(parsedWorkflow.nodes[0].widgets_values).toEqual(["foo", "bar"]);
|
expect(parsedWorkflow.nodes[0].widgets_values).toEqual({"foo": "bar"});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user