30 lines
51 KiB
JavaScript
30 lines
51 KiB
JavaScript
import{j as e}from"./vendor-markdown-Dek94WS0.js";import{r as j}from"./vendor-react-V04_Axys.js";import{r as et,g as tt,m as st,i as rt}from"./workflowChat--6TDkP1M.js";import{a as Z,u as Ee,g as Ne,W as xe}from"./message-components-yQk9DI7R.js";import"./input.js";import"./App-By_5x9Zk.js";function nt(l,o){try{if(!l)return console.error("Invalid prompt_output: ",l),l;for(const r of o){if(!l[r.nodeId]){console.error(`Node with ID ${r.nodeId} not found`);continue}if(!l[r.nodeId].inputs){console.error(`Inputs not found for node with ID ${r.nodeId}`);continue}l[r.nodeId].inputs[r.paramName]=r.paramValue}return l}catch(r){return console.error("Error updating prompt:",r),l}}async function ot(l){const o=await Z.graphToPrompt(),r=nt(o.output,l);console.log("queuePrompt updated_prompt:",r);const u={prompt:r,client_id:Z.api.clientId,extra_data:{extra_pageinfo:{workflow:o.workflow}}};console.debug("queuePrompt request_body.prompt:",r);const f=await et(u);return console.debug("queuePrompt response:",f),f}function _e(l){const o=document.createElement("canvas"),r=o.getContext("2d");if(o.width=512,o.height=512,r){r.fillStyle="#f8d7da",r.fillRect(0,0,o.width,o.height),r.strokeStyle="#dc3545",r.lineWidth=4,r.strokeRect(10,10,o.width-20,o.height-20),r.fillStyle="#dc3545",r.beginPath(),r.arc(o.width/2,150,50,0,2*Math.PI),r.fill(),r.fillStyle="white",r.font="bold 80px Arial",r.textAlign="center",r.textBaseline="middle",r.fillText("!",o.width/2,150),r.fillStyle="#721c24",r.font="20px Arial",r.textAlign="center",r.textBaseline="middle";const u=o.width-60,f=30,m=l.split(" ");let c="",h=250;for(let w=0;w<m.length;w++){const E=c+m[w]+" ";r.measureText(E).width>u&&w>0?(r.fillText(c,o.width/2,h),c=m[w]+" ",h+=f):c=E}r.fillText(c,o.width/2,h)}return o.toDataURL("image/png")}async function at(l){try{if(!l||l==="")return console.log("No prompt ID provided"),{1:[_e("Fail to generate prompt ID")]};const o=await tt(l);if(!o||!o[l])return console.log("Not finished for prompt ID:",l),{};const r=o[l];if(r.status&&r.status.status_str==="error"){console.error("Error for prompt ID:",l);const f=r.status.messages;if(f&&f.length>0){const m=f[f.length-1];if(m&&m.length>0){const c=m[0];return{1:[_e(c)]}}}}const u={};if(r.outputs)for(const f in r.outputs){const m=r.outputs[f];if(m&&m.images){u[f]=[];for(const c of m.images)if(c&&c.filename&&c.type){const h=Z.graph._nodes_by_id[f].imgs[0].currentSrc.split("?")[0];u[f].push(h+"?filename="+encodeURIComponent(c.filename)+"&type="+encodeURIComponent(c.type)+(c.subfolder?"&subfolder="+encodeURIComponent(c.subfolder):""))}console.log("outputImages for nodeId:",f,u[f])}}return u}catch(o){throw console.error("Error getting output images from prompt:",o),o}}function lt(){const l=Object.values(Z.graph._nodes_by_id),o=[],r=[];for(const u of l)u.type==="SaveImage"?o.push(u.id):u.type==="PreviewImage"&&r.push(u.id);if(console.log("saveNodeIds:",o),console.log("previewNodeIds:",r),o.length===0&&r.length===0)throw new Error("No SaveImage or PreviewImage node found, please add one to the graph");return o.length===1?o[0]:o.length==0&&r.length===1?r[0]:null}async function it(l,o){const r=await at(l);return Object.keys(r).length===0?null:r[o.toString()]&&r[o.toString()].length>0?r[o.toString()][0]:null}const ct=({selectedNodes:l,handleParamSelect:o,selectedParams:r,handleNext:u,handleClose:f})=>{const c=l.flatMap(h=>(h.widgets||[]).map(w=>w.name)).some(h=>r[h]===!0);return e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Select Parameters for Testing"}),e.jsx("p",{className:"text-xs text-gray-500",children:"Choose the parameters you want to include in your batch test"})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:f,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),l.map((h,w)=>{const E=h.title||"Unknown Node",C=h.widgets||[];return e.jsxs("div",{className:"border rounded-md mb-4 overflow-hidden",children:[e.jsx("div",{className:"bg-gray-50 px-3 py-2 text-sm font-medium text-gray-700 border-b",children:E}),e.jsx("div",{className:"p-4 space-y-3",children:e.jsx("div",{className:"flex items-center gap-3 flex-wrap",children:C.map((S,_)=>{const F=S.name;return e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:`w-5 h-5 rounded-full border flex items-center justify-center ${r[F]?"border-red-500 bg-red-100":"border-gray-300"}`,onClick:$=>o(F,$),children:r[F]&&e.jsx("div",{className:"w-3 h-3 rounded-full bg-red-500"})}),e.jsx("span",{className:"ml-2 text-gray-700 text-xs",children:F})]},`widget-${_}`)})})})]},`node-${w}`)}),e.jsx("div",{className:"mt-6 flex justify-center",children:e.jsx("button",{onClick:h=>u(h),disabled:!c,className:`px-3 py-1.5 text-xs ${c?"bg-pink-200 text-pink-700 hover:bg-pink-300":"bg-gray-200 text-gray-500 cursor-not-allowed"} rounded-md transition-colors`,children:"Next"})})]})},dt=({selectedNodes:l,paramTestValues:o,selectedParams:r,updateParamTestValues:u,toggleDropdown:f,openDropdowns:m,handleTestValueSelect:c,searchTerms:h,handleSearch:w,handleSelectAll:E,handleNext:C,handlePrevious:S,handleClose:_,inputValues:F,setInputValues:$,textInputs:H,handleTextInputChange:W,handleAddTextInput:A,handleRemoveTextInput:N,openAiWritingModal:T})=>{const D=(d,k,V,Y=0)=>{if(d=isNaN(d)?0:d,k=isNaN(k)?100:k,V=isNaN(V)||V<=0?1:V,k<d&&(k=d),Math.floor((k-d)/V)+1<=1)return[d];const M=[];let Q=d;for(;Q<=k;){const x=Math.pow(10,Y),G=Math.round(Q*x)/x;M.push(G),Q+=V}return M};return j.useEffect(()=>{!l||l.length===0||l.forEach(d=>{const k=d.id.toString(),V=d.widgets||{};Object.values(V).forEach(p=>{const M=p.name;if(!r[M])return;if(!(o[k]?.[M]?.length>0)&&p.type==="number"){const x=p.options?.min||0,G=p.options?.max||100,I=(p.options?.step||10)/10,L=p.options?.precision||0,O=D(x,G,I,L);if(O.length>0){u(k,M,O);const B=`${k}_${M}`;$(g=>({...g,[B]:{min:x.toString(),max:G.toString(),step:I.toString()}}))}}if(p.type==="customtext"||p.type.toLowerCase().includes("text")){const x=`${k}_${M}`,G=H[x]||[""];JSON.stringify(G)!==JSON.stringify(o[k]?.[M]||[""])&&u(k,M,G)}})})},[l,r,o,H,u,$,D]),e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Parameter Options"}),e.jsx("p",{className:"text-xs text-gray-500",children:"Configure the test values for each parameter"})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:_,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),l.length>0?l.map((d,k)=>{const V=d.widgets||{},Y=Object.values(V),p=d.id;return e.jsxs("div",{className:"border rounded-md mb-4 overflow-hidden",children:[e.jsxs("div",{className:"bg-gray-50 px-3 py-2 text-xs font-medium text-gray-700 border-b flex justify-between items-center",children:[e.jsxs("span",{children:[d.type," (ID: ",p,")"]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:M=>_(M,k),children:e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx("div",{className:"p-4 space-y-4",children:Y.map((M,Q)=>{const x=M.name;if(!r[x])return null;const G=`${p}_${x}`;if(M.type==="customtext"||M.type.toLowerCase().includes("text")){const I=H[G]||[""];return e.jsxs("div",{className:"border-b pb-3",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("label",{className:"text-xs font-medium text-gray-700",children:[x,":"]}),e.jsxs("button",{className:"px-2 py-1 bg-blue-100 text-blue-700 rounded text-xs flex items-center hover:bg-blue-200 transition-colors",onClick:()=>T(p,x),children:[e.jsx("svg",{className:"w-3 h-3 mr-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"})}),"AI Writing"]})]}),e.jsx("div",{className:"space-y-2",children:I.map((L,O)=>e.jsxs("div",{className:"flex items-start",children:[e.jsx("textarea",{className:`flex-1 border ${L?"border-gray-300":"border-red-500"} rounded p-2 text-xs resize-y`,rows:2,placeholder:"Enter text...",value:L,onChange:B=>W(p,x,O,B.target.value),required:!0}),e.jsx("button",{className:"ml-2 text-red-500 hover:text-red-700",onClick:()=>N(p,x,O),title:"Remove",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]},O))}),e.jsxs("button",{className:"mt-2 px-2 py-1 border border-dashed border-gray-300 rounded text-xs text-gray-600 hover:bg-gray-50 flex items-center",onClick:()=>A(p,x),children:[e.jsx("svg",{className:"w-3 h-3 mr-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})}),"Add Text"]})]},Q)}if(M.type==="number"){const I=M.options?.min||0,L=M.options?.max||100,O=(M.options?.step||10)/10,B=M.options?.precision||0,g=D(I,L,O,B),U=F[G]||{min:I.toString(),max:L.toString(),step:O.toString()};return e.jsxs("div",{className:"border-b pb-3",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("label",{className:"text-xs font-medium text-gray-700",children:[x,":"]}),e.jsx("div",{className:"w-4"})]}),e.jsxs("div",{className:"flex space-x-2 items-center",children:[e.jsx("label",{className:"text-xs text-gray-600",children:"Min"}),e.jsx("input",{type:"text",className:"w-12 h-6 border border-gray-300 rounded text-xs px-2",value:U.min,required:!0,onClick:v=>{v.preventDefault(),v.stopPropagation()},onChange:v=>{v.preventDefault(),v.stopPropagation();const P=v.target.value;if($(R=>({...R,[G]:{...R[G],min:P}})),P===""||!isNaN(parseFloat(P))){const R=P===""?0:parseFloat(P),q=parseFloat(U.max||L.toString()),K=parseFloat(U.step||O.toString()),J=D(R,q,K,B);u(p,x,J)}}}),e.jsx("label",{className:"text-xs text-gray-600",children:"Max"}),e.jsx("input",{type:"text",className:"w-12 h-6 border border-gray-300 rounded text-xs px-2",value:U.max,onClick:v=>{v.preventDefault(),v.stopPropagation()},required:!0,onChange:v=>{v.preventDefault(),v.stopPropagation();const P=v.target.value;if($(R=>({...R,[G]:{...R[G],max:P}})),P===""||!isNaN(parseFloat(P))){const R=parseFloat(U.min||I.toString()),q=P===""?R:parseFloat(P),K=parseFloat(U.step||O.toString()),J=D(R,q,K,B);u(p,x,J)}}}),e.jsx("label",{className:"text-xs text-gray-600",children:"Step"}),e.jsx("input",{type:"text",className:"w-12 h-6 border border-gray-300 rounded text-xs px-2",value:U.step,required:!0,onClick:v=>{v.preventDefault(),v.stopPropagation()},onChange:v=>{v.preventDefault(),v.stopPropagation();const P=v.target.value;if($(R=>({...R,[G]:{...R[G],step:P}})),P===""||!isNaN(parseFloat(P))&&parseFloat(P)>0){const R=parseFloat(U.min||I.toString()),q=parseFloat(U.max||L.toString()),K=P===""?1:parseFloat(P),J=D(R,q,K,B);u(p,x,J)}}})]}),e.jsxs("div",{className:"mt-1",children:[e.jsx("label",{className:"text-xs text-gray-600",children:"Test values"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:(()=>{const v=o[p]?.[x]||g;if(v.length<=10)return v.map((P,R)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs cursor-pointer hover:bg-blue-200",onClick:q=>{q.stopPropagation(),c(p,x,P,q)},children:[e.jsx("span",{children:P}),e.jsx("svg",{className:"w-4 h-4 ml-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},R));{const P=v.slice(0,5),R=v.slice(v.length-5);return e.jsxs(e.Fragment,{children:[P.map((q,K)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs cursor-pointer hover:bg-blue-200",onClick:J=>{J.stopPropagation(),c(p,x,q,J)},children:[e.jsx("span",{children:q}),e.jsx("svg",{className:"w-4 h-4 ml-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},`first-${K}`)),e.jsx("div",{className:"px-2 py-0.5 bg-gray-100 text-gray-600 rounded-md flex items-center text-xs",children:"..."}),R.map((q,K)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs cursor-pointer hover:bg-blue-200",onClick:J=>{J.stopPropagation(),c(p,x,q,J)},children:[e.jsx("span",{children:q}),e.jsx("svg",{className:"w-4 h-4 ml-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},`last-${K}`))]})}})()})]}),e.jsx("div",{className:"mt-1",children:e.jsx("p",{className:"text-xs text-gray-500",children:"Values are distributed evenly between Min and Max"})})]},Q)}else if(M.type==="combo"){const I=M.options?.values||[],L=`${p}_${x}`,O=g=>typeof g=="string"?g:g&&typeof g=="object"&&"name"in g?g.name:String(g),B=g=>typeof g=="object"&&g!==null&&"name"in g?g.name:g;return e.jsxs("div",{className:"border-b pb-3",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("label",{className:"text-xs font-medium text-gray-700",children:x}),e.jsxs("div",{className:"relative dropdown-container",children:[e.jsxs("button",{className:`appearance-none border ${(o[p]?.[x]||[]).length===0?"border-red-500":"border-gray-300"} rounded px-2 py-0.5 pr-6 text-xs flex items-center bg-white text-gray-700`,onClick:g=>{g.preventDefault(),g.stopPropagation(),f(p,x,g)},"data-dropdown":L,children:[e.jsx("span",{children:(o[p]?.[x]||[]).length>0?`${x}: ${(o[p]?.[x]||[]).length} selected`:`Select ${x}`}),e.jsx("div",{className:"ml-2",children:e.jsx("svg",{className:"fill-current h-4 w-4",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",children:e.jsx("path",{d:"M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z"})})})]}),m[L]&&e.jsxs("div",{className:"absolute z-[9999] mt-1 w-64 bg-white border border-gray-300 rounded-md shadow-lg dropdown-menu",style:{position:"fixed",top:typeof m[L]=="object"?`${m[L].y}px`:"0px",left:typeof m[L]=="object"?`${m[L].x}px`:"0px",maxHeight:"300px",overflowY:"auto"},children:[e.jsx("div",{className:"p-2 border-b sticky top-0 bg-white",children:e.jsx("input",{type:"text",className:"w-full px-2 py-0.5 text-xs border border-gray-300 rounded",placeholder:"Search...",value:h[L]||"",onChange:g=>{g.preventDefault(),g.stopPropagation(),w(p,x,g.target.value)},onClick:g=>{g.preventDefault(),g.stopPropagation()},autoFocus:!0})}),e.jsxs("div",{className:"px-3 py-1.5 bg-gray-50 border-b cursor-pointer text-xs flex items-center text-gray-700 hover:bg-gray-100",onClick:g=>{g.preventDefault(),g.stopPropagation();const v=I.filter(P=>!h[L]||O(P).toLowerCase().includes((h[L]||"").toLowerCase())).map(B);E(p,x,v)},children:[e.jsx("div",{className:`w-4 h-4 mr-2 border rounded-sm flex items-center justify-center ${I.length>0&&(o[p]?.[x]||[]).length===I.length?"bg-blue-500 border-blue-500":(o[p]?.[x]||[]).length>0?"bg-blue-500 border-blue-500 opacity-50":"border-gray-300"}`,children:(o[p]?.[x]||[]).length>0&&e.jsx("svg",{className:"w-3 h-3 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}),e.jsx("span",{className:"font-medium",children:I.length>0&&(o[p]?.[x]||[]).length===I.length?"Deselect All":"Select All"})]}),e.jsxs("div",{className:"max-h-60 overflow-y-auto",children:[I.filter(g=>!h[L]||O(g).toLowerCase().includes((h[L]||"").toLowerCase())).map((g,U)=>e.jsxs("div",{className:"px-3 py-1.5 hover:bg-gray-100 cursor-pointer text-xs flex items-center text-gray-700",onClick:v=>{v.preventDefault(),v.stopPropagation(),c(p,x,B(g),v)},children:[e.jsx("div",{className:`w-4 h-4 mr-2 border rounded-sm flex items-center justify-center ${(o[p]?.[x]||[]).includes(B(g))?"bg-blue-500 border-blue-500":"border-gray-300"}`,children:(o[p]?.[x]||[]).includes(B(g))&&e.jsx("svg",{className:"w-3 h-3 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}),e.jsx("span",{className:"whitespace-normal overflow-hidden text-ellipsis",children:O(g)})]},U)),I.filter(g=>!h[L]||O(g).toLowerCase().includes((h[L]||"").toLowerCase())).length===0&&e.jsx("div",{className:"px-3 py-4 text-sm text-gray-500 text-center",children:"No matching options"})]})]})]})]}),e.jsxs("div",{className:"mt-2",children:[e.jsx("label",{className:"text-xs text-gray-600",children:"Test values"}),(o[p]?.[x]||[]).length===0&&e.jsx("div",{className:"text-xs text-red-500 mt-1",children:"Please select at least one value"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:(o[p]?.[x]||[]).map((g,U)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs",children:[e.jsx("span",{children:g}),e.jsx("svg",{className:"w-4 h-4 ml-1 cursor-pointer hover:text-blue-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",onClick:v=>{v.preventDefault(),v.stopPropagation(),c(p,x,g,v)},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},U))})]})]},Q)}else return e.jsxs("div",{className:"border-b pb-3",children:[e.jsx("div",{className:"flex justify-between items-center",children:e.jsx("label",{className:"text-xs font-medium text-gray-700",children:x})}),e.jsxs("div",{className:"mt-2",children:[e.jsx("label",{className:"text-xs text-gray-600",children:"Test values"}),e.jsxs("div",{className:"mt-1 flex flex-wrap gap-1",children:[(o[p]?.[x]||[]).map((I,L)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs",children:[e.jsx("span",{children:I}),e.jsx("svg",{className:"w-4 h-4 ml-1 cursor-pointer hover:text-blue-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",onClick:O=>{O.preventDefault(),O.stopPropagation(),c(p,x,I,O)},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},L)),e.jsxs("button",{className:"px-2 py-0.5 border border-dashed border-blue-300 text-blue-600 rounded-md text-xs flex items-center hover:bg-blue-50",onClick:I=>{I.preventDefault(),I.stopPropagation();const L=`${x}${(o[p]?.[x]||[]).length+1}`;u(p,x,[...o[p]?.[x]||[],L])},children:[e.jsx("svg",{className:"w-4 h-4 mr-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})}),e.jsx("span",{children:"Add"})]})]})]})]},Q)})})]},k)}):e.jsx("div",{className:"border rounded-md mb-4 p-4 text-center text-gray-500",children:"No nodes selected. Please select a node in the workflow to configure parameters."}),e.jsxs("div",{className:"mt-6 flex justify-between",children:[e.jsx("button",{onClick:d=>S(d),className:"px-3 py-1.5 text-xs bg-gray-100 text-gray-800 rounded-md hover:bg-gray-200 transition-colors",children:"Previous"}),e.jsx("button",{onClick:d=>C(d),className:"px-3 py-1.5 text-xs bg-pink-200 text-pink-700 rounded-md hover:bg-pink-300 transition-colors",children:"Next"})]})]})},xt=({selectedNodes:l,paramTestValues:o,selectedParams:r,totalCount:u,errorMessage:f,handlePrevious:m,handleStartGeneration:c,handleClose:h})=>{const[w,E]=j.useState([]),[C,S]=j.useState(null),[_,F]=j.useState(!1);Ee();const $=()=>{const W=Object.values(Z.graph._nodes_by_id),A=[],N=[];for(const D of W)D.type==="SaveImage"?A.push(D.id):D.type==="PreviewImage"&&N.push(D.id);const T=[...A,...N];E(T),T.length===1?S(T[0]):T.length>1&&(F(!0),S(null))};j.useEffect(()=>{$()},[]),j.useEffect(()=>{const W=()=>{if(!Z.canvas.selected_nodes)return;const A=Object.values(Z.canvas.selected_nodes);if(A.length===0)return;const N=A[0];N&&(N.type==="SaveImage"||N.type==="PreviewImage")&&(console.log("Selected image node:",N.id),S(N.id))};return document.addEventListener("click",W),()=>{document.removeEventListener("click",W)}},[]);const H=W=>{if(W&&(W.preventDefault(),W.stopPropagation()),w.length>1&&!C){F(!0);return}c(W,C||void 0)};return e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Confirm Test Configuration"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["In the selected parameter combinations, there are ",u," total runs. Each run will generate a separate image."]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:h,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),_&&w.length>1&&e.jsx("div",{className:"mb-4 p-3 bg-yellow-50 border border-yellow-200 rounded-md text-amber-600 text-xs",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:e.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),e.jsx("div",{className:"ml-2",children:C===null?`Multiple SaveImage and PreviewImage nodes detected with IDs ${w.join(",")}. Please click the node on canvas.`:`Current node ID is ${C}, please click Start Generation again`})]})}),f&&e.jsx("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-md text-red-600 text-xs",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:e.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),e.jsx("div",{className:"ml-2",children:f})]})}),l.length>0?l.map((W,A)=>{const N=W.type||"Unknown Node",T=W.widgets||[],D=W.id;return e.jsxs("div",{className:"border rounded-md mb-4 overflow-hidden",children:[e.jsxs("div",{className:"bg-gray-50 px-3 py-2 text-xs font-medium text-gray-700 border-b",children:[N," (ID: ",D,")"]}),e.jsx("div",{className:"p-4 space-y-3",children:T.map((d,k)=>{const V=d.name;if(!r[V])return null;const Y=o[D]?.[V]||[],p=Array.isArray(Y)?`[${Y.join(", ")}]`:JSON.stringify(Y);return e.jsxs("div",{className:k<T.length-1?"flex justify-between items-center border-b pb-2":"flex justify-between items-center",children:[e.jsx("label",{className:"font-medium text-gray-700 text-xs",children:V}),e.jsx("div",{className:"flex space-x-2 items-center",children:e.jsx("input",{type:"text",className:"w-64 h-7 border border-gray-300 rounded text-xs px-2 bg-gray-50 cursor-not-allowed text-gray-500",readOnly:!0,disabled:!0,value:p,onClick:M=>M.preventDefault()})})]},k)})})]},A)}):e.jsx("div",{className:"border rounded-md mb-4 p-4 text-center text-gray-500 text-xs",children:"No nodes selected. Please select a node in the workflow to configure parameters."}),e.jsxs("div",{className:"mt-6 flex justify-between",children:[e.jsx("button",{onClick:W=>m(W),className:"px-3 py-1.5 text-xs bg-gray-100 text-gray-800 rounded-md hover:bg-gray-200 transition-colors",children:"Previous"}),e.jsx("button",{onClick:W=>H(W),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${w.length>1&&!C?"bg-gray-200 text-gray-500 cursor-not-allowed":"bg-pink-200 text-pink-700 hover:bg-pink-300"}`,disabled:w.length>1&&!C,children:"Start Generation"})]})]})},ut=({selectedNodes:l,paramTestValues:o,selectedParams:r,totalCount:u,completedCount:f,errorMessage:m,handleClose:c,setIsProcessing:h,setCurrentScreen:w,cleanupPolling:E})=>{const C=S=>{S.preventDefault(),S.stopPropagation(),st({clear:!0}),rt(),E&&E(),h(!1),w(2)};return e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4 relative",children:[e.jsx("div",{className:"absolute inset-0 bg-gray-500 bg-opacity-30 flex flex-col items-center justify-center z-10",children:e.jsxs("div",{className:"text-center text-gray-800 bg-white p-4 rounded-lg shadow-lg",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:"Processing..."}),e.jsxs("div",{className:"text-xs mb-3",children:["Completed ",f," of ",u," runs"]}),e.jsx("div",{className:"w-48 h-2 bg-gray-200 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-pink-500 transition-all duration-200",style:{width:`${f/u*100}%`}})}),e.jsxs("div",{className:"mt-2 text-xs text-gray-600",children:["Already generated ",f," images"]}),e.jsx("button",{onClick:C,className:"mt-4 px-3 py-1.5 text-xs bg-gray-200 text-gray-800 rounded-md hover:bg-gray-300 transition-colors",children:"Cancel"})]})}),e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Confirm Test Configuration"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["In the selected parameter combinations, there are ",u," total runs. Each run will generate a separate image."]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:c,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),m&&e.jsx("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-md text-red-600 text-xs",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:e.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),e.jsx("div",{className:"ml-2",children:m})]})}),l.length>0?l.map((S,_)=>{const F=S.type||"Unknown Node",$=S.widgets||[],H=S.id;return e.jsxs("div",{className:"border rounded-md mb-4 overflow-hidden",children:[e.jsxs("div",{className:"bg-gray-50 px-3 py-2 text-xs font-medium text-gray-700 border-b",children:[F," (ID: ",H,")"]}),e.jsx("div",{className:"p-4 space-y-3",children:$.map((W,A)=>{const N=W.name;if(!r[N])return null;const T=o[H]?.[N]||[],D=Array.isArray(T)?`[${T.join(", ")}]`:JSON.stringify(T);return e.jsxs("div",{className:A<$.length-1?"flex justify-between items-center border-b pb-2":"flex justify-between items-center",children:[e.jsx("label",{className:"font-medium text-gray-700",children:N}),e.jsx("div",{className:"flex space-x-2 items-center",children:e.jsx("input",{type:"text",className:"w-64 h-7 border border-gray-300 rounded text-sm px-2 bg-gray-50 cursor-not-allowed text-gray-500",readOnly:!0,disabled:!0,value:D,onClick:d=>d.preventDefault()})})]},A)})})]},_)}):e.jsx("div",{className:"border rounded-md mb-4 p-4 text-center text-gray-500",children:"No nodes selected. Please select a node in the workflow to configure parameters."})]})},mt=({generatedImages:l,selectedImageIndex:o,handleSelectImage:r,handleApplySelected:u,handlePrevious:f,handleClose:m,currentPage:c,handlePageChange:h,imagesPerPage:w,notificationVisible:E,modalVisible:C,modalImageUrl:S,openImageModal:_,closeImageModal:F})=>{const $=Math.ceil(l.length/w),H=(c-1)*w,W=Math.min(H+w,l.length),A=l.slice(H,W);return e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Generation Complete"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["All ",l.length," images have been generated."]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:m,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),E&&e.jsx("div",{className:"fixed top-4 right-4 bg-green-100 border-l-4 border-green-500 text-green-700 p-3 shadow-md rounded animate-fade-in-out z-50",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"py-1",children:e.jsx("svg",{className:"h-4 w-4 text-green-500 mr-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}),e.jsx("p",{className:"text-xs",children:"Parameters has been applied."})]})}),C&&e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-75 flex items-center justify-center z-50",onClick:F,children:e.jsxs("div",{className:"bg-white rounded-lg p-2 max-w-4xl max-h-[90vh] relative",onClick:N=>N.stopPropagation(),children:[e.jsx("button",{className:"absolute top-2 right-2 text-gray-700 hover:text-gray-900 rounded-full hover:bg-gray-200 p-1",onClick:F,children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),e.jsx("div",{className:"overflow-auto max-h-[calc(90vh-4rem)]",children:e.jsx("img",{src:S,alt:"Enlarged image",className:"max-w-full h-auto"})})]})}),e.jsx("div",{className:"grid grid-cols-3 gap-4 mb-6",children:A.map((N,T)=>{const D=H+T;return e.jsxs("div",{className:`relative rounded-lg overflow-hidden border ${o===D?"border-pink-500 ring-2 ring-pink-300":"border-gray-200"}`,onClick:d=>r(D,d),children:[e.jsx("button",{className:"absolute top-2 right-2 bg-white bg-opacity-75 rounded-full p-0.5 text-gray-600 hover:text-gray-900 shadow-sm z-10",onClick:d=>_(N.url,d),children:e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5v-4m0 4h-4m4 0l-5-5"})})}),e.jsx("div",{className:"aspect-square",children:e.jsx("img",{src:N.url,alt:`Generated image ${D+1}`,className:"w-full h-full object-cover"})}),e.jsx("div",{className:"p-2 text-xs text-gray-600 bg-white max-h-16 overflow-y-auto",children:Object.entries(N.params).filter(([d,k])=>d!=="nodeParams"&&typeof k!="object").map(([d,k])=>e.jsxs("div",{children:[d,": ",String(k)]},d))})]},D)})}),$>1&&e.jsxs("div",{className:"flex justify-center items-center space-x-2 mt-4 mb-4",children:[e.jsx("button",{onClick:N=>h(1,N),disabled:c===1,className:`px-2 py-1 rounded ${c===1?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:[e.jsx("path",{fillRule:"evenodd",d:"M15.707 15.707a1 1 0 01-1.414 0l-5-5a1 1 0 010-1.414l5-5a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 010 1.414z",clipRule:"evenodd"}),e.jsx("path",{fillRule:"evenodd",d:"M8.707 15.707a1 1 0 01-1.414 0l-5-5a1 1 0 010-1.414l5-5a1 1 0 111.414 1.414L4.414 10l4.293 4.293a1 1 0 010 1.414z",clipRule:"evenodd"})]})}),e.jsx("button",{onClick:N=>h(c-1,N),disabled:c===1,className:`px-2 py-1 rounded ${c===1?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"px-2 py-1 text-xs text-gray-800",children:["Page ",c," of ",$]}),e.jsx("button",{onClick:N=>h(c+1,N),disabled:c===$,className:`px-2 py-1 rounded ${c===$?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z",clipRule:"evenodd"})})}),e.jsx("button",{onClick:N=>h($,N),disabled:c===$,className:`px-2 py-1 rounded ${c===$?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:[e.jsx("path",{fillRule:"evenodd",d:"M4.293 15.707a1 1 0 001.414 0l5-5a1 1 0 000-1.414l-5-5a1 1 0 00-1.414 1.414L8.586 10 4.293 14.293a1 1 0 000 1.414z",clipRule:"evenodd"}),e.jsx("path",{fillRule:"evenodd",d:"M11.293 15.707a1 1 0 001.414 0l5-5a1 1 0 000-1.414l-5-5a1 1 0 00-1.414 1.414L15.586 10l-4.293 4.293a1 1 0 000 1.414z",clipRule:"evenodd"})]})})]}),e.jsxs("div",{className:"mt-6 flex justify-between",children:[e.jsx("button",{onClick:N=>f(N),className:"px-3 py-1.5 text-xs bg-gray-100 text-gray-800 rounded-md hover:bg-gray-200 transition-colors",children:"Previous"}),e.jsx("button",{onClick:N=>u(N),className:"px-3 py-1.5 text-xs bg-pink-200 text-pink-700 rounded-md hover:bg-pink-300 transition-colors",disabled:o===null,children:"Apply Selected"})]})]})},ht=({visible:l,aiWritingModalText:o,setAiWritingModalText:r,aiGeneratedTexts:u,aiSelectedTexts:f,aiWritingLoading:m,aiWritingError:c,handleAiWriting:h,toggleTextSelection:w,addSelectedTexts:E,onClose:C})=>l?e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white rounded-lg shadow-lg w-full max-w-2xl max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"p-4 border-b flex justify-between items-center",children:[e.jsx("h3",{className:"text-lg font-medium",children:"AI Writing Assistant"}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:C,children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("div",{className:"p-4 overflow-y-auto flex-1",children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"text-sm text-gray-600 mb-2",children:"Enter text and AI will generate variations"}),e.jsx("textarea",{className:"w-full border border-gray-300 rounded-md p-2 text-sm",rows:3,placeholder:"Enter some text here...",value:o,onChange:S=>r(S.target.value)}),e.jsx("button",{className:"mt-2 px-4 py-2 bg-blue-100 text-blue-700 rounded-md text-sm flex items-center hover:bg-blue-200 transition-colors",onClick:h,disabled:m,children:m?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin -ml-1 mr-2 h-4 w-4 text-blue-700",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Generating..."]}):e.jsx(e.Fragment,{children:"Generate"})})]}),c&&e.jsx("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-md text-red-600 text-sm",children:c}),u.length>0&&e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"Generated variations (select items to add):"}),e.jsx("div",{className:"space-y-2 max-h-[40vh] overflow-y-auto p-2",children:u.map((S,_)=>e.jsxs("div",{className:"flex items-start border border-gray-200 rounded-md p-2",children:[e.jsx("div",{className:"mr-2 mt-1",children:e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"checkbox",id:`text${_+1}`,checked:!!f[`text${_+1}`],onChange:()=>w(`text${_+1}`),className:"sr-only"}),e.jsx("div",{className:`h-4 w-4 rounded border ${f[`text${_+1}`]?"bg-blue-600 border-blue-600":"bg-white border-gray-300"} flex items-center justify-center`,onClick:()=>w(`text${_+1}`),children:f[`text${_+1}`]&&e.jsx("svg",{className:"h-3 w-3 text-white",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})})]})}),e.jsx("label",{htmlFor:`text${_+1}`,className:"text-sm text-gray-700 cursor-pointer flex-1",children:S})]},_))})]})]}),e.jsxs("div",{className:"p-4 border-t flex justify-end flex-shrink-0",children:[e.jsx("button",{className:"px-4 py-2 bg-gray-100 text-gray-700 rounded-md text-sm mr-2 hover:bg-gray-200 transition-colors",onClick:C,children:"Cancel"}),e.jsx("button",{className:"px-4 py-2 bg-blue-500 text-white rounded-md text-sm hover:bg-blue-600 transition-colors",onClick:E,disabled:Object.values(f).every(S=>!S),children:"Add Selected"})]})]})}):null,ke=l=>{const o=[],r={};if(Object.keys(l).forEach(m=>{const c=parseInt(m),h=l[m]||{},w=Object.keys(h).filter(C=>h[C]&&h[C].length>0);if(w.length===0)return;const E=[[]];w.forEach(C=>{const S=h[C],_=[];E.forEach(F=>{S.forEach($=>{const H=[...F,{nodeId:c,paramName:C,paramValue:String($)}];_.push(H)})}),E.length=0,E.push(..._)}),r[m]=E}),Object.keys(r).length===0)return o;if(Object.keys(r).length===1){const m=Object.keys(r)[0];return r[m]}const u=Object.keys(r);let f=r[u[0]];for(let m=1;m<u.length;m++){const c=r[u[m]],h=[];f.forEach(w=>{c.forEach(E=>{h.push([...w,...E])})}),f=h}return f},pt=(l,o)=>{const r={};r.nodeParams={};const u=ke(l);return o<u.length&&u[o].forEach(m=>{const c=m.nodeId.toString(),h=m.paramName,w=m.paramValue;r.nodeParams[c]||(r.nodeParams[c]={}),r.nodeParams[c][h]=w,r[h]=w}),r},gt=`
|
|
@keyframes highlight-pulse {
|
|
0% {
|
|
box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.5);
|
|
}
|
|
70% {
|
|
box-shadow: 0 0 0 15px rgba(59, 130, 246, 0);
|
|
}
|
|
100% {
|
|
box-shadow: 0 0 0 0 rgba(59, 130, 246, 0);
|
|
}
|
|
}
|
|
|
|
.highlight-pulse {
|
|
animation: highlight-pulse 1.5s infinite;
|
|
border: 2px solid #3b82f6;
|
|
}
|
|
|
|
@keyframes fade-in-out {
|
|
0% { opacity: 0; transform: translateY(-20px); }
|
|
10% { opacity: 1; transform: translateY(0); }
|
|
90% { opacity: 1; transform: translateY(0); }
|
|
100% { opacity: 0; transform: translateY(-20px); }
|
|
}
|
|
|
|
.animate-fade-in-out {
|
|
animation: fade-in-out 3s forwards;
|
|
}
|
|
`,Nt=({selectedNodes:l,visible:o,onClose:r})=>{const[u,f]=j.useState(0),[m,c]=j.useState({Steps:!0,CFG:!0,sampler_name:!0,threshold:!1,prompt:!1}),[h,w]=j.useState(Ne()),[E,C]=j.useState(!1),[S,_]=j.useState(!1),[F,$]=j.useState(0),[H,W]=j.useState(12),[A,N]=j.useState(null),[T,D]=j.useState(()=>Array(12).fill(null).map((t,s)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:{step:s%3===0?5:s%3===1?10:15,sampler_name:"euler",cfg:1}}))),[d,k]=j.useState({}),[V,Y]=j.useState({}),[p,M]=j.useState({}),[Q,x]=j.useState({}),[G,I]=j.useState(1),L=6,[O,B]=j.useState(null),[g,U]=j.useState(!1),[v,P]=j.useState(!1),[R,q]=j.useState(""),[K,J]=j.useState({}),[$e,ue]=j.useState(!1),[ne,be]=j.useState(""),[ye,me]=j.useState([]),[We,he]=j.useState(!1),[Ce,Se]=j.useState(""),[Le,Pe]=j.useState(""),[De,oe]=j.useState(null),[Me,ae]=j.useState({}),{dispatch:le}=Ee(),pe=j.useRef(null),ie=j.useRef(null),Oe=async()=>{if(!ne.trim()){oe("Please enter some text to generate variations");return}he(!0),oe(null),me([]),ae({});try{const t=await xe.generateSDPrompts(ne);me(t),xe.trackEvent({event_type:"prompt_generate",message_type:"parameter_debug",message_id:h,data:{input_text:ne,generated_texts:t}});const s={};t.forEach((i,n)=>{s[`text${n+1}`]=!1}),ae(s)}catch(t){console.error("Error generating text:",t),oe("Failed to generate text variations. Please try again.")}finally{he(!1)}},Ae=(t,s,i,n)=>{const a=`${t}_${s}`;J(y=>{const z=[...y[a]||[]];return z[i]=n,{...y,[a]:z}});const b=[...K[a]||[]];b[i]=n,te(t,s,b)},Te=(t,s)=>{const i=`${t}_${s}`;J(a=>{const b=[...a[i]||[]];return b.push(""),{...a,[i]:b}});const n=[...K[i]||[],""];te(t,s,n)},Be=(t,s,i)=>{const n=`${t}_${s}`;J(b=>{const y=[...b[n]||[]];return y.splice(i,1),{...b,[n]:y}});const a=[...K[n]||[]];a.splice(i,1),te(t,s,a)},Re=t=>{ae(s=>({...s,[t]:!s[t]}))},ze=()=>{const t=`${Ce}_${Le}`,s=Object.entries(Me).filter(([n,a])=>a).map(([n])=>{const a=parseInt(n.replace("text",""))-1;return ye[a]});if(s.length===0)return;J(n=>{const a=[...n[t]||[]];return{...n,[t]:[...a,...s]}}),xe.trackEvent({event_type:"prompt_apply",message_type:"parameter_debug",message_id:h,data:{input_text:ne,generated_texts:ye,selected_texts:s}});const i=[...K[t]||[],...s];te(Ce,Le,i),ue(!1)},Fe=(t,s)=>{ue(!0),Se(t),Pe(s),be(""),me([]),ae({}),he(!1),oe(null)};j.useEffect(()=>{if(!l||l.length===0)return;const t={...d},s=l.map(n=>n.id.toString());Object.keys(t).forEach(n=>{s.includes(n)||delete t[n]}),l.forEach(n=>{const a=n.id.toString();t[a]||(t[a]={})}),JSON.stringify(t)!==JSON.stringify(d)&&k(t)},[l,d]),j.useEffect(()=>{le({type:"SET_SCREEN_STATE",payload:{currentScreen:u,isProcessing:E,isCompleted:S}})},[u,E,S,le]),j.useEffect(()=>{const t=document.createElement("style");return t.textContent=gt,document.head.appendChild(t),()=>{document.head.removeChild(t)}},[]),j.useEffect(()=>{const t=s=>{if(Object.values(V).some(i=>i)){const i=s.target,n=!!i.closest(".dropdown-menu"),a=!!i.closest("[data-dropdown]");!n&&!a&&Y({})}};return document.addEventListener("mousedown",t),()=>{document.removeEventListener("mousedown",t)}},[V]),j.useEffect(()=>{o&&w(Ne())},[o]);const Ie=t=>{if(t&&(t.preventDefault(),t.stopPropagation()),u===0){const s={...d};Object.keys(s).forEach(i=>{const n=s[i];Object.keys(n).forEach(a=>{m[a]||delete n[a]})}),k(s)}if(u===1){const s={...d};l.forEach(n=>{const a=n.id.toString(),b=n.widgets||{};Object.values(b).forEach(y=>{const z=y.name;if(m[z]&&(y.type==="customtext"||y.type.toLowerCase().includes("text"))){const ee=`${a}_${z}`,se=K[ee]||[""];s[a]=s[a]||{},s[a][z]=se}})}),k(s);const i=ke(s);W(i.length)}B(null),f(s=>Math.min(s+1,2))},je=t=>{if(t&&(t.preventDefault(),t.stopPropagation()),B(null),S&&_(!1),u===1){const s=l.map(a=>a.id.toString()),i=Object.keys(d),n={...d};i.forEach(a=>{s.includes(a)||delete n[a]}),k(n)}if(u===2||S){const s={...d};Object.entries(K).forEach(([i,n])=>{if(!n||n.length===0)return;const[a,b]=i.split("_");l.some(y=>y.id.toString()===a)&&(s[a]=s[a]||{},JSON.stringify(s[a][b])!==JSON.stringify(n)&&(s[a][b]=n))}),k(s)}f(s=>Math.max(s-1,0))},Ve=(t,s)=>{s&&(s.preventDefault(),s.stopPropagation());const i=m[t];if(c(n=>({...n,[t]:!i})),i){const n={...d};Object.keys(n).forEach(a=>{n[a][t]&&delete n[a][t]}),k(n)}},Ge=(t,s,i)=>{i.preventDefault(),i.stopPropagation();const n=`${t}_${s}`;Y(a=>{if(a[n]&&typeof a[n]=="object"?a[n].isOpen:!!a[n])return{...a,[n]:!1};{let y=0,z=0;if(i.currentTarget){const de=i.currentTarget.getBoundingClientRect();y=de.left,z=de.bottom}else y=i.clientX,z=i.clientY+20;const ee=window.innerWidth,se=250;return y+se>ee&&(y=ee-se-10),y<0&&(y=10),{...a,[n]:{isOpen:!0,x:y,y:z}}}})},te=(t,s,i)=>{k(n=>{const a={...n};return a[t]||(a[t]={}),a[t][s]=i,a})},Ue=(t,s,i,n)=>{n&&(n.preventDefault(),n.stopPropagation()),k(a=>{const b={...a};b[t]||(b[t]={}),b[t][s]||(b[t][s]=[]);const y=b[t][s];return y.includes(i)?b[t][s]=y.filter(z=>z!==i):b[t][s]=[...y,i],b})},He=(t,s,i)=>{const n=`${t}_${s}`;M(a=>({...a,[n]:i}))},qe=(t,s,i)=>{if(!d[t]){te(t,s,i);return}const n=d[t][s]||[];i.length===n.length?te(t,s,[]):te(t,s,[...i])},Ke=(t,s)=>{s&&(s.preventDefault(),s.stopPropagation()),I(Math.max(1,Math.min(t,Math.ceil(T.length/L))))},ge=()=>{pe.current&&(clearTimeout(pe.current),pe.current=null),ie.current=null};j.useEffect(()=>()=>{ge()},[]);const Je=async(t,s)=>{t&&(t.preventDefault(),t.stopPropagation()),ge();const i=ke(d),n=i.length;if(n>100){B(`Cannot generate more than 100 images at once (currently: ${n} images)`);return}if(B(null),C(!0),$(0),console.log("Generated parameter combinations:",i),xe.trackEvent({event_type:"start_generation",message_type:"parameter_debug",message_id:h,data:{workflow:(await Z.graphToPrompt()).output,all_params:d,count:n}}),i.length===0){B("No valid parameter combinations found. Please check your parameter selections."),C(!1);return}let a=s||null;if(a===null){const y=lt();y!==null&&(a=y)}if(a===null){B("Please select a SaveImage or PreviewImage node first."),C(!1);return}const b=[];try{const y=Date.now().toString();ie.current=y;for(const re of i){const X=await ot(re);X.prompt_id?b.push(X.prompt_id):(console.error("Failed to get prompt_id from response:",X),b.push(""))}const z=Array(i.length).fill(null).map((re,X)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:pt(d,X)}));D(z);const ee=Date.now(),se=5*60*1e3,de=async()=>{if(ie.current!==y){console.log("Another polling session has started, stopping this one");return}if(Date.now()-ee>se){console.log("Timeout reached while waiting for images"),ie.current===y&&(C(!1),_(!0),I(1));return}let re=0;for(let X=0;X<b.length;X++){const we=b[X];if(we)try{const fe=await it(we,Number(a));fe&&(z[X]={...z[X],url:fe},re++)}catch(fe){console.error(`Error fetching image for prompt ID ${we}:`,fe)}}ie.current===y&&(D([...z]),$(re),re===b.length?(console.log("All images ready, completing session"),C(!1),_(!0),I(1)):pe.current=setTimeout(de,3e3))};de()}catch(y){console.error("Error generating images:",y),C(!1)}},Ye=(t,s)=>{s&&(s.preventDefault(),s.stopPropagation()),N(t)},Qe=(t,s)=>{s.preventDefault(),s.stopPropagation(),q(t),P(!0)},Xe=t=>{t&&(t.preventDefault(),t.stopPropagation()),P(!1)},Ze=async t=>{if(t&&(t.preventDefault(),t.stopPropagation()),A!==null){console.log(`Applied image ${A+1} with parameters:`,T[A].params);let s=1;if(d){for(const n in d)if(d[n])for(const a in d[n]){const b=d[n][a];if(b){let y=1;Array.isArray(b)?y=b.length>0?b.length:1:typeof b=="object"&&b!==null&&(y=Object.keys(b).length>0?Object.keys(b).length:1),s=s*y}}}xe.trackEvent({event_type:"parameter_debug_apply",message_type:"parameter_debug",message_id:h,data:{workflow:(await Z.graphToPrompt()).output,selected_params:T[A].params,all_params:d,count:s}});const i=T[A].params;i.nodeParams&&(Object.entries(i.nodeParams).forEach(([n,a])=>{const b=Z.graph._nodes_by_id[n];!b||!b.widgets||Object.entries(a).forEach(([y,z])=>{for(const ee of b.widgets)if(ee.name===y){ee.value=z;break}})}),Z.graph.setDirtyCanvas(!1,!0),U(!0),setTimeout(()=>{U(!1)},3e3))}},ce=(t,s)=>{if(t&&(t.preventDefault(),t.stopPropagation()),u===1&&s!==void 0){const i=[...l],n=i[s];if(i.splice(s,1),n){const a=n.id.toString();k(b=>{const y={...b};return delete y[a],y})}i.length===0?r&&(le({type:"SET_SCREEN_STATE",payload:null}),ve(),r()):le({type:"SET_SELECTED_NODE",payload:i});return}r?(le({type:"SET_SCREEN_STATE",payload:null}),ve(),r()):ve()},ve=()=>{f(0),c({Steps:!0,CFG:!0,sampler_name:!0,threshold:!1,prompt:!1}),w(Ne()),ge(),C(!1),_(!1),$(0),W(12),N(null),D(Array(12).fill(null).map((t,s)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:{step:s%3===0?5:s%3===1?10:15,sampler_name:"euler",cfg:1}}))),k({}),Y({}),M({}),x({}),I(1),B(null),U(!1),P(!1),q(""),J({}),ue(!1),be(""),me([]),he(!1),Se(""),Pe(""),oe(null),ae({})};return!o||l.length===0?e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center p-8 bg-gray-50 overflow-y-auto",onClick:t=>t.stopPropagation(),children:e.jsxs("div",{className:"max-w-lg p-8 bg-white rounded-lg shadow-sm border border-blue-100 relative",children:[e.jsxs("div",{className:"mb-6 text-center",children:[e.jsx("h3",{className:"text-base font-bold text-blue-800 mb-2",children:"GenLab"}),e.jsx("div",{className:"h-1 w-16 bg-blue-500 mx-auto rounded-full mb-4"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx("div",{className:"bg-blue-100 p-2 rounded-full text-blue-600",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{d:"M5 3a2 2 0 00-2 2v2a2 2 0 002 2h2a2 2 0 002-2V5a2 2 0 00-2-2H5zM5 11a2 2 0 00-2 2v2a2 2 0 002 2h2a2 2 0 002-2v-2a2 2 0 00-2-2H5zM11 5a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V5zM11 13a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z"})})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-800",children:"Batch Test Parameter Pairs"}),e.jsx("p",{className:"text-xs text-gray-600",children:"Select a node to batch test parameter pairs"})]})]}),e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx("div",{className:"bg-indigo-100 p-2 rounded-full text-indigo-600",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z",clipRule:"evenodd"})})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-800",children:"How To Use"}),e.jsx("p",{className:"text-xs text-gray-600",children:"Click on any node in your workflow to start the parameter testing process"})]})]}),e.jsx("div",{className:"mt-6 text-center",children:e.jsx("p",{className:"text-xs text-gray-600 mb-3",children:"No node is currently selected"})})]})]})}):S?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:t=>t.stopPropagation(),children:e.jsx(mt,{generatedImages:T,selectedImageIndex:A,handleSelectImage:Ye,handleApplySelected:Ze,handlePrevious:je,handleClose:ce,currentPage:G,handlePageChange:Ke,imagesPerPage:L,notificationVisible:g,modalVisible:v,modalImageUrl:R,openImageModal:Qe,closeImageModal:Xe})}):E?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:t=>t.stopPropagation(),children:e.jsx(ut,{selectedNodes:l,paramTestValues:d,selectedParams:m,totalCount:H,completedCount:F,errorMessage:O,handleClose:ce,setIsProcessing:C,setCurrentScreen:f,cleanupPolling:ge})}):u===0?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4 flex flex-col h-full max-h-[80vh]",onClick:t=>t.stopPropagation(),children:e.jsx(ct,{selectedNodes:l,handleParamSelect:Ve,selectedParams:m,handleNext:Ie,handleClose:ce})}):u===1?e.jsxs("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4 flex flex-col h-full max-h-[80vh]",onClick:t=>t.stopPropagation(),children:[e.jsx(dt,{selectedNodes:l,paramTestValues:d,selectedParams:m,updateParamTestValues:te,toggleDropdown:Ge,openDropdowns:V,handleTestValueSelect:Ue,searchTerms:p,handleSearch:He,handleSelectAll:qe,handleNext:Ie,handlePrevious:je,handleClose:ce,inputValues:Q,setInputValues:x,textInputs:K,handleTextInputChange:Ae,handleAddTextInput:Te,handleRemoveTextInput:Be,openAiWritingModal:Fe}),e.jsx(ht,{visible:$e,aiWritingModalText:ne,setAiWritingModalText:be,aiGeneratedTexts:ye,aiSelectedTexts:Me,aiWritingLoading:We,aiWritingError:De,handleAiWriting:Oe,toggleTextSelection:Re,addSelectedTexts:ze,onClose:()=>ue(!1)})]}):e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4 flex flex-col h-full max-h-[80vh]",onClick:t=>t.stopPropagation(),children:e.jsx(xt,{selectedNodes:l,paramTestValues:d,selectedParams:m,totalCount:H,errorMessage:O,handlePrevious:je,handleStartGeneration:Je,handleClose:ce})})};export{Nt as ParameterDebugInterface};
|