File size: 13,226 Bytes
86d4cbe |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
import { app } from "../../scripts/app.js";
import { api } from "../../scripts/api.js";
import { $el } from "../../scripts/ui.js";
// Dialog manager to create custom modal dialogs for FramerComfy
class FramerComfyDialog {
constructor() {
this.dialogContainer = null;
this.overlay = null;
this.dialog = null;
this.inputFields = [];
this.resolvePromise = null;
this.rejectPromise = null;
this.setupStyles();
}
setupStyles() {
// Add custom styles for the dialog
const style = document.createElement("style");
style.textContent = `
.framer-comfy-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
z-index: 9999;
}
.framer-comfy-dialog {
background-color: #1a1a1a;
border-radius: 8px;
padding: 20px;
width: 80%;
max-width: 600px;
max-height: 80vh;
overflow-y: auto;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
color: #fff;
}
.framer-comfy-dialog h2 {
margin-top: 0;
margin-bottom: 16px;
font-size: 18px;
border-bottom: 1px solid #333;
padding-bottom: 10px;
}
.framer-comfy-input-group {
margin-bottom: 16px;
}
.framer-comfy-input-label {
display: block;
margin-bottom: 6px;
font-size: 14px;
}
.framer-comfy-input {
width: 100%;
background-color: #333;
border: 1px solid #444;
border-radius: 4px;
padding: 8px 10px;
color: #fff;
font-size: 14px;
}
.framer-comfy-node-info {
font-size: 12px;
color: #999;
margin-top: 4px;
}
.framer-comfy-buttons {
display: flex;
justify-content: flex-end;
gap: 10px;
margin-top: 20px;
}
.framer-comfy-button {
background-color: #555;
color: white;
border: none;
border-radius: 4px;
padding: 8px 16px;
cursor: pointer;
font-size: 14px;
transition: background-color 0.2s;
}
.framer-comfy-button:hover {
background-color: #666;
}
.framer-comfy-button-primary {
background-color: #2d8cff;
}
.framer-comfy-button-primary:hover {
background-color: #1a7ae8;
}
`;
document.head.appendChild(style);
}
createDialogContainer() {
// Create container if it doesn't exist
if (!this.dialogContainer) {
this.dialogContainer = document.createElement("div");
document.body.appendChild(this.dialogContainer);
}
return this.dialogContainer;
}
showModelUrlsDialog(modelInputs) {
this.inputFields = [];
const container = this.createDialogContainer();
return new Promise((resolve, reject) => {
this.resolvePromise = resolve;
this.rejectPromise = reject;
// Create overlay
this.overlay = document.createElement("div");
this.overlay.className = "framer-comfy-overlay";
// Prevent events from propagating to ComfyUI
this.overlay.addEventListener("click", (e) => {
e.stopPropagation();
});
// Stop keydown events from reaching ComfyUI
this.overlay.addEventListener("keydown", (e) => {
e.stopPropagation();
});
// Create dialog
this.dialog = document.createElement("div");
this.dialog.className = "framer-comfy-dialog";
// Prevent clicks within dialog from propagating
this.dialog.addEventListener("click", (e) => {
e.stopPropagation();
});
// Dialog title
const title = document.createElement("h2");
title.textContent = "Enter Information for FramerComfy";
this.dialog.appendChild(title);
// Create form content
const form = document.createElement("form");
form.onsubmit = (e) => {
e.preventDefault();
e.stopPropagation();
this.handleSubmit();
};
// Prevent paste events from propagating
form.addEventListener("paste", (e) => {
e.stopPropagation();
});
// Handle keyboard events at the form level
form.addEventListener("keydown", (e) => {
e.stopPropagation();
});
// Add required workflow inputs
const requiredInputsGroup = document.createElement("div");
requiredInputsGroup.className = "framer-comfy-input-group";
// Workflow Name input
const workflowNameLabel = document.createElement("label");
workflowNameLabel.className = "framer-comfy-input-label";
workflowNameLabel.textContent = "Workflow Name (required)";
requiredInputsGroup.appendChild(workflowNameLabel);
const workflowNameInput = document.createElement("input");
workflowNameInput.className = "framer-comfy-input";
workflowNameInput.type = "text";
workflowNameInput.placeholder = "Enter workflow name";
workflowNameInput.required = true;
workflowNameInput.dataset.inputType = "workflow_name";
// Add event listeners to prevent propagation
workflowNameInput.addEventListener("paste", (e) => e.stopPropagation());
workflowNameInput.addEventListener("keydown", (e) => e.stopPropagation());
workflowNameInput.addEventListener("focus", (e) => e.stopPropagation());
workflowNameInput.addEventListener("blur", (e) => e.stopPropagation());
this.inputFields.push(workflowNameInput);
requiredInputsGroup.appendChild(workflowNameInput);
// Hugging Face Access Token input
const tokenLabel = document.createElement("label");
tokenLabel.className = "framer-comfy-input-label";
tokenLabel.textContent = "Hugging Face Access Token (required)";
tokenLabel.style.marginTop = "16px";
requiredInputsGroup.appendChild(tokenLabel);
const tokenInput = document.createElement("input");
tokenInput.className = "framer-comfy-input";
tokenInput.type = "password";
tokenInput.placeholder = "Enter your Hugging Face access token";
tokenInput.required = true;
tokenInput.dataset.inputType = "huggingface_access_token";
// Add event listeners to prevent propagation
tokenInput.addEventListener("paste", (e) => e.stopPropagation());
tokenInput.addEventListener("keydown", (e) => e.stopPropagation());
tokenInput.addEventListener("focus", (e) => e.stopPropagation());
tokenInput.addEventListener("blur", (e) => e.stopPropagation());
this.inputFields.push(tokenInput);
requiredInputsGroup.appendChild(tokenInput);
form.appendChild(requiredInputsGroup);
// Add a separator
const separator = document.createElement("hr");
separator.style.margin = "20px 0";
separator.style.borderColor = "#333";
form.appendChild(separator);
// Model inputs section title if there are any
if (modelInputs.length > 0) {
const modelSectionTitle = document.createElement("h3");
modelSectionTitle.textContent = "Model URLs";
modelSectionTitle.style.fontSize = "16px";
modelSectionTitle.style.marginBottom = "16px";
form.appendChild(modelSectionTitle);
}
// Add inputs for each model
modelInputs.forEach((input, index) => {
const { nodeId, nodeTitle, inputName, promptMessage } = input;
const inputGroup = document.createElement("div");
inputGroup.className = "framer-comfy-input-group";
const label = document.createElement("label");
label.className = "framer-comfy-input-label";
label.textContent = promptMessage;
inputGroup.appendChild(label);
const inputField = document.createElement("input");
inputField.className = "framer-comfy-input";
inputField.type = "text";
inputField.placeholder = "https://huggingface.co/...";
inputField.dataset.nodeId = nodeId;
inputField.dataset.inputName = inputName;
inputField.dataset.inputType = "model_url";
// Add event listeners to prevent propagation
inputField.addEventListener("paste", (e) => e.stopPropagation());
inputField.addEventListener("keydown", (e) => e.stopPropagation());
inputField.addEventListener("focus", (e) => e.stopPropagation());
inputField.addEventListener("blur", (e) => e.stopPropagation());
this.inputFields.push(inputField);
inputGroup.appendChild(inputField);
const nodeInfo = document.createElement("div");
nodeInfo.className = "framer-comfy-node-info";
nodeInfo.textContent = `Node: ${nodeTitle} (ID: ${nodeId})`;
inputGroup.appendChild(nodeInfo);
form.appendChild(inputGroup);
});
// Action buttons
const buttonsContainer = document.createElement("div");
buttonsContainer.className = "framer-comfy-buttons";
const cancelButton = document.createElement("button");
cancelButton.className = "framer-comfy-button";
cancelButton.textContent = "Cancel";
cancelButton.type = "button";
cancelButton.onclick = (e) => {
e.stopPropagation();
this.handleCancel();
};
buttonsContainer.appendChild(cancelButton);
const submitButton = document.createElement("button");
submitButton.className = "framer-comfy-button framer-comfy-button-primary";
submitButton.textContent = "Submit";
submitButton.type = "submit";
submitButton.addEventListener("click", (e) => e.stopPropagation());
buttonsContainer.appendChild(submitButton);
form.appendChild(buttonsContainer);
this.dialog.appendChild(form);
// Append dialog to overlay
this.overlay.appendChild(this.dialog);
// Add to container
container.appendChild(this.overlay);
});
}
handleSubmit() {
// Validate required fields
const requiredInputs = this.inputFields.filter(input =>
input.dataset.inputType === "workflow_name" ||
input.dataset.inputType === "huggingface_access_token"
);
for (const input of requiredInputs) {
if (!input.value.trim()) {
alert(`${input.dataset.inputType === "workflow_name" ? "Workflow Name" : "Hugging Face Access Token"} is required.`);
return;
}
}
// Extract required workflow information
const workflowInfo = {
workflow_name: "",
huggingface_access_token: ""
};
// Collect values from all input fields
const modelResults = [];
for (const input of this.inputFields) {
const value = input.value.trim();
if (input.dataset.inputType === "workflow_name") {
workflowInfo.workflow_name = value;
} else if (input.dataset.inputType === "huggingface_access_token") {
workflowInfo.huggingface_access_token = value;
} else if (input.dataset.inputType === "model_url" && value) {
modelResults.push({
nodeId: input.dataset.nodeId,
inputName: input.dataset.inputName,
value: value
});
}
}
this.closeDialog();
this.resolvePromise({
workflowInfo: workflowInfo,
modelResults: modelResults
});
}
handleCancel() {
this.closeDialog();
this.resolvePromise([]);
}
closeDialog() {
if (this.overlay && this.dialogContainer) {
this.dialogContainer.removeChild(this.overlay);
this.overlay = null;
this.dialog = null;
}
}
}
// Export the dialog manager
export const framerComfyDialog = new FramerComfyDialog();
|