|
|
@ -22,6 +22,15 @@ class ManageTemplates extends ComfyDialog { |
|
|
|
super(); |
|
|
|
super(); |
|
|
|
this.element.classList.add("comfy-manage-templates"); |
|
|
|
this.element.classList.add("comfy-manage-templates"); |
|
|
|
this.templates = this.load(); |
|
|
|
this.templates = this.load(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.importInput = $el("input", { |
|
|
|
|
|
|
|
type: "file", |
|
|
|
|
|
|
|
accept: ".json", |
|
|
|
|
|
|
|
multiple: true, |
|
|
|
|
|
|
|
style: {display: "none"}, |
|
|
|
|
|
|
|
parent: document.body, |
|
|
|
|
|
|
|
onchange: () => this.importAll(), |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
createButtons() { |
|
|
|
createButtons() { |
|
|
@ -34,6 +43,22 @@ class ManageTemplates extends ComfyDialog { |
|
|
|
onclick: () => this.save(), |
|
|
|
onclick: () => this.save(), |
|
|
|
}) |
|
|
|
}) |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
btns.unshift( |
|
|
|
|
|
|
|
$el("button", { |
|
|
|
|
|
|
|
type: "button", |
|
|
|
|
|
|
|
textContent: "Export", |
|
|
|
|
|
|
|
onclick: () => this.exportAll(), |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
btns.unshift( |
|
|
|
|
|
|
|
$el("button", { |
|
|
|
|
|
|
|
type: "button", |
|
|
|
|
|
|
|
textContent: "Import", |
|
|
|
|
|
|
|
onclick: () => { |
|
|
|
|
|
|
|
this.importInput.click(); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
); |
|
|
|
return btns; |
|
|
|
return btns; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -69,6 +94,52 @@ class ManageTemplates extends ComfyDialog { |
|
|
|
localStorage.setItem(id, JSON.stringify(this.templates)); |
|
|
|
localStorage.setItem(id, JSON.stringify(this.templates)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async importAll() { |
|
|
|
|
|
|
|
for (const file of this.importInput.files) { |
|
|
|
|
|
|
|
if (file.type === "application/json" || file.name.endsWith(".json")) { |
|
|
|
|
|
|
|
const reader = new FileReader(); |
|
|
|
|
|
|
|
reader.onload = async () => { |
|
|
|
|
|
|
|
var importFile = JSON.parse(reader.result); |
|
|
|
|
|
|
|
if (importFile && importFile?.templates) { |
|
|
|
|
|
|
|
for (const template of importFile.templates) { |
|
|
|
|
|
|
|
if (template?.name && template?.data) { |
|
|
|
|
|
|
|
this.templates.push(template); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.store(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
await reader.readAsText(file); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.importInput.value = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exportAll() { |
|
|
|
|
|
|
|
if (this.templates.length == 0) { |
|
|
|
|
|
|
|
alert("No templates to export."); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const json = JSON.stringify({templates: this.templates}, null, 2); // convert the data to a JSON string
|
|
|
|
|
|
|
|
const blob = new Blob([json], {type: "application/json"}); |
|
|
|
|
|
|
|
const url = URL.createObjectURL(blob); |
|
|
|
|
|
|
|
const a = $el("a", { |
|
|
|
|
|
|
|
href: url, |
|
|
|
|
|
|
|
download: "node_templates.json", |
|
|
|
|
|
|
|
style: {display: "none"}, |
|
|
|
|
|
|
|
parent: document.body, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
a.click(); |
|
|
|
|
|
|
|
setTimeout(function () { |
|
|
|
|
|
|
|
a.remove(); |
|
|
|
|
|
|
|
window.URL.revokeObjectURL(url); |
|
|
|
|
|
|
|
}, 0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
show() { |
|
|
|
show() { |
|
|
|
// Show list of template names + delete button
|
|
|
|
// Show list of template names + delete button
|
|
|
|
super.show( |
|
|
|
super.show( |
|
|
@ -97,19 +168,48 @@ class ManageTemplates extends ComfyDialog { |
|
|
|
}), |
|
|
|
}), |
|
|
|
] |
|
|
|
] |
|
|
|
), |
|
|
|
), |
|
|
|
$el("button", { |
|
|
|
$el( |
|
|
|
textContent: "Delete", |
|
|
|
"div", |
|
|
|
style: { |
|
|
|
{}, |
|
|
|
fontSize: "12px", |
|
|
|
[ |
|
|
|
color: "red", |
|
|
|
$el("button", { |
|
|
|
fontWeight: "normal", |
|
|
|
textContent: "Export", |
|
|
|
}, |
|
|
|
style: { |
|
|
|
onclick: (e) => { |
|
|
|
fontSize: "12px", |
|
|
|
nameInput.value = ""; |
|
|
|
fontWeight: "normal", |
|
|
|
e.target.style.display = "none"; |
|
|
|
}, |
|
|
|
e.target.previousElementSibling.style.display = "none"; |
|
|
|
onclick: (e) => { |
|
|
|
}, |
|
|
|
const json = JSON.stringify({templates: [t]}, null, 2); // convert the data to a JSON string
|
|
|
|
}), |
|
|
|
const blob = new Blob([json], {type: "application/json"}); |
|
|
|
|
|
|
|
const url = URL.createObjectURL(blob); |
|
|
|
|
|
|
|
const a = $el("a", { |
|
|
|
|
|
|
|
href: url, |
|
|
|
|
|
|
|
download: (nameInput.value || t.name) + ".json", |
|
|
|
|
|
|
|
style: {display: "none"}, |
|
|
|
|
|
|
|
parent: document.body, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
a.click(); |
|
|
|
|
|
|
|
setTimeout(function () { |
|
|
|
|
|
|
|
a.remove(); |
|
|
|
|
|
|
|
window.URL.revokeObjectURL(url); |
|
|
|
|
|
|
|
}, 0); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}), |
|
|
|
|
|
|
|
$el("button", { |
|
|
|
|
|
|
|
textContent: "Delete", |
|
|
|
|
|
|
|
style: { |
|
|
|
|
|
|
|
fontSize: "12px", |
|
|
|
|
|
|
|
color: "red", |
|
|
|
|
|
|
|
fontWeight: "normal", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
onclick: (e) => { |
|
|
|
|
|
|
|
nameInput.value = ""; |
|
|
|
|
|
|
|
e.target.parentElement.style.display = "none"; |
|
|
|
|
|
|
|
e.target.parentElement.previousElementSibling.style.display = "none"; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}), |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
), |
|
|
|
]; |
|
|
|
]; |
|
|
|
}) |
|
|
|
}) |
|
|
|
) |
|
|
|
) |
|
|
@ -164,19 +264,17 @@ app.registerExtension({ |
|
|
|
}, |
|
|
|
}, |
|
|
|
})); |
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
if (subItems.length) { |
|
|
|
subItems.push(null, { |
|
|
|
subItems.push(null, { |
|
|
|
content: "Manage", |
|
|
|
content: "Manage", |
|
|
|
callback: () => manage.show(), |
|
|
|
callback: () => manage.show(), |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
options.push({ |
|
|
|
options.push({ |
|
|
|
content: "Node Templates", |
|
|
|
content: "Node Templates", |
|
|
|
submenu: { |
|
|
|
submenu: { |
|
|
|
options: subItems, |
|
|
|
options: subItems, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return options; |
|
|
|
return options; |
|
|
|
}; |
|
|
|
}; |
|
|
|