MCPcopy Index your code
hub / github.com/pythongosssss/ComfyUI-Custom-Scripts / constructor

Method constructor

web/js/workflows.js:122–214  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

120 }
121
122 constructor() {
123 function addWorkflowMenu(type, getOptions) {
124 return $el("div.pysssss-workflow-arrow", {
125 parent: document.getElementById(`comfy-${type}-button`),
126 onclick: (e) => {
127 e.preventDefault();
128 e.stopPropagation();
129
130 LiteGraph.closeAllContextMenus();
131 const menu = new LiteGraph.ContextMenu(
132 getOptions(),
133 {
134 event: e,
135 scale: 1.3,
136 },
137 window
138 );
139 menu.root.classList.add("pysssss-workflow-popup");
140 menu.root.classList.add(`pysssss-workflow-${type}`);
141 },
142 });
143 }
144
145 this.loadMenu = addWorkflowMenu("load", () =>
146 this.getMenuOptions(async (workflow) => {
147 const json = await getWorkflow(workflow);
148 app.loadGraphData(json);
149 })
150 );
151 addWorkflowMenu("save", () => {
152 return [
153 {
154 title: "Save as",
155 callback: () => {
156 let filename = prompt("Enter filename", this.workflowName || "workflow");
157 if (filename) {
158 if (!filename.toLowerCase().endsWith(".json")) {
159 filename += ".json";
160 }
161
162 this.workflowName = filename;
163
164 const json = JSON.stringify(app.graph.serialize(), null, 2); // convert the data to a JSON string
165 const blob = new Blob([json], { type: "application/json" });
166 const url = URL.createObjectURL(blob);
167 const a = $el("a", {
168 href: url,
169 download: filename,
170 style: { display: "none" },
171 parent: document.body,
172 });
173 a.click();
174 setTimeout(function () {
175 a.remove();
176 window.URL.revokeObjectURL(url);
177 }, 0);
178 }
179 },

Callers

nothing calls this directly

Calls 4

getMenuOptionsMethod · 0.95
loadMethod · 0.95
getWorkflowFunction · 0.85
saveWorkflowFunction · 0.85

Tested by

no test coverage detected