2024-10-29 18:14:06 +00:00
|
|
|
{"version":3,"file":"widgetInputs-DdecKYqd.js","sources":["../../src/extensions/core/widgetInputs.ts"],"sourcesContent":["// @ts-strict-ignore\nimport { ComfyWidgets, addValueControlWidgets } from '../../scripts/widgets'\nimport { app } from '../../scripts/app'\nimport { applyTextReplacements } from '../../scripts/utils'\nimport { LiteGraph, LGraphNode } from '@comfyorg/litegraph'\nimport type { INodeInputSlot, IWidget } from '@comfyorg/litegraph'\nimport type { InputSpec } from '@/types/apiTypes'\n\nconst CONVERTED_TYPE = 'converted-widget'\nconst VALID_TYPES = [\n 'STRING',\n 'combo',\n 'number',\n 'toggle',\n 'BOOLEAN',\n 'text',\n 'string'\n]\nconst CONFIG = Symbol()\nconst GET_CONFIG = Symbol()\nconst TARGET = Symbol() // Used for reroutes to specify the real target widget\n\ninterface PrimitiveNode extends LGraphNode {}\n\nconst replacePropertyName = 'Run widget replace on values'\nclass PrimitiveNode extends LGraphNode {\n controlValues: any[]\n lastType: string\n static category: string\n constructor(title?: string) {\n super(title)\n this.addOutput('connect to widget input', '*')\n this.serialize_widgets = true\n this.isVirtualNode = true\n\n if (!this.properties || !(replacePropertyName in this.properties)) {\n this.addProperty(replacePropertyName, false, 'boolean')\n }\n }\n\n applyToGraph(extraLinks = []) {\n if (!this.outputs[0].links?.length) return\n\n function get_links(node) {\n let links = []\n for (const l of node.outputs[0].links) {\n const linkInfo = app.graph.links[l]\n const n = node.graph.getNodeById(linkInfo.target_id)\n if (n.type == 'Reroute') {\n links = links.concat(get_links(n))\n } else {\n links.push(l)\n }\n }\n return links\n }\n\n let links = [\n ...get_links(this).map((l) => app.graph.links[l]),\n ...extraLinks\n ]\n let v = this.widgets?.[0].value\n if (v && this.properties[replacePropertyName]) {\n v = applyTextReplacements(app, v as string)\n }\n\n // For each output link copy our value over the original widget value\n for (const linkInfo of links) {\n const node = this.graph.getNodeById(linkInfo.target_id)\n const input = node.inputs[linkInfo.target_slot]\n let widget\n if (input.widget[TARGET]) {\n widget = input.widget[TARGET]\n } else {\n const widgetName = (input.widget as { name: string }).name\n if (widgetName) {\n widget = node.widgets.find((w) => w.name === widgetName)\n }\n }\n\n if (widget) {\n widget.value = v\n if (widget.callback) {\n widget.callback(\n widget.value,\n app.canvas,\n node,\n app.canvas.graph_mouse,\n {}\n )\n }\n }\n }\n }\n\n refreshComboInNode() {\n const widget = this.widgets?.[0]\n if (widget?.type === 'combo') {\n widget.options.values = this.outputs[0].widget[GET_CONFIG]()[0]\n\n if (!widget.options.values.includes(widget.value as string)) {\n widget.value = widget.options.values[0]\n ;(widget.callback as Function)(widget.value)\n }\n }\n }\n\n onAfterGraphConfigured() {\n if (this.outputs[0].links?.length && !this.widgets?.length) {\n // TODO: Review this check\n // @ts-expect-error\n if (!this.#onFirstConnection()) return\n\n // Populate widget values from config data\n if (this.widgets) {\n for (let i = 0; i < this.widgets_values.length; i++) {\n const w = this.widgets[i]\n if (w) {\n // @ts-expect-error change widget type from string to unknown\n w.value = this.widgets_values[i]\n }\n }\n }\n\n // Merge values if required\n this.#mergeWidgetConfig()\n }\n }\n\n onConnectionsChange(_, index, connected) {\n if (app.configuringGraph) {\n // Dont run while the graph is still setting up\n return\n }\n\n const links = this.outputs[0].links\n if (connected
|