36 lines
54 KiB
JavaScript
36 lines
54 KiB
JavaScript
import{j as e}from"./vendor-markdown-Dek94WS0.js";import{r as y}from"./vendor-react-V04_Axys.js";import{r as nt,g as ot,m as at,i as lt}from"./workflowChat-DAlFyxt6.js";import{a as Z,u as De,g as ke,W as ue}from"./message-components-DoI1VVaz.js";import"./input.js";/* empty css */function it(a,n){try{if(!a)return console.error("Invalid prompt_output: ",a),a;for(const r of n){if(!a[r.nodeId]){console.error(`Node with ID ${r.nodeId} not found`);continue}if(!a[r.nodeId].inputs){console.error(`Inputs not found for node with ID ${r.nodeId}`);continue}a[r.nodeId].inputs[r.paramName]=r.paramValue}return a}catch(r){return console.error("Error updating prompt:",r),a}}async function ct(a){const n=await Z.graphToPrompt(),r=it(n.output,a);console.log("queuePrompt updated_prompt:",r);const u={prompt:r,client_id:Z.api.clientId,extra_data:{extra_pageinfo:{workflow:n.workflow}}};console.debug("queuePrompt request_body.prompt:",r);const p=await nt(u);return console.debug("queuePrompt response:",p),p}function Oe(a){const n=document.createElement("canvas"),r=n.getContext("2d");if(n.width=512,n.height=512,r){r.fillStyle="#f8d7da",r.fillRect(0,0,n.width,n.height),r.strokeStyle="#dc3545",r.lineWidth=4,r.strokeRect(10,10,n.width-20,n.height-20),r.fillStyle="#dc3545",r.beginPath(),r.arc(n.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("!",n.width/2,150),r.fillStyle="#721c24",r.font="20px Arial",r.textAlign="center",r.textBaseline="middle";const u=n.width-60,p=30,x=a.split(" ");let d="",h=250;for(let v=0;v<x.length;v++){const I=d+x[v]+" ";r.measureText(I).width>u&&v>0?(r.fillText(d,n.width/2,h),d=x[v]+" ",h+=p):d=I}r.fillText(d,n.width/2,h)}return n.toDataURL("image/png")}async function dt(a){try{if(!a||a==="")return console.log("No prompt ID provided"),{1:[Oe("Fail to generate prompt ID")]};const n=await ot(a);if(!n||!n[a])return console.log("Not finished for prompt ID:",a),{};const r=n[a];if(r.status&&r.status.status_str==="error"){console.error("Error for prompt ID:",a);const p=r.status.messages;if(p&&p.length>0){const x=p[p.length-1];if(x&&x.length>0){const d=x[0];return{1:[Oe(d)]}}}}const u={};if(r.outputs)for(const p in r.outputs){const x=r.outputs[p];if(x&&x.images){u[p]=[];for(const d of x.images)if(d&&d.filename&&d.type){const h=Z.graph._nodes_by_id[p].imgs[0].currentSrc.split("?")[0];u[p].push(h+"?filename="+encodeURIComponent(d.filename)+"&type="+encodeURIComponent(d.type)+(d.subfolder?"&subfolder="+encodeURIComponent(d.subfolder):""))}console.log("outputImages for nodeId:",p,u[p])}}return u}catch(n){throw console.error("Error getting output images from prompt:",n),n}}function ut(){const a=Object.values(Z.graph._nodes_by_id),n=[],r=[];for(const u of a)u.type==="SaveImage"?n.push(u.id):u.type==="PreviewImage"&&r.push(u.id);if(console.log("saveNodeIds:",n),console.log("previewNodeIds:",r),n.length===0&&r.length===0)throw new Error("No SaveImage or PreviewImage node found, please add one to the graph");return n.length===1?n[0]:n.length==0&&r.length===1?r[0]:null}async function xt(a,n){const r=await dt(a);return Object.keys(r).length===0?null:r[n.toString()]&&r[n.toString()].length>0?r[n.toString()][0]:null}const mt=({selectedNodes:a,handleParamSelect:n,selectedParams:r,handleNext:u,handleClose:p})=>{const d=a.flatMap(h=>(h.widgets||[]).map(v=>v.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:p,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"})})})]}),a.map((h,v)=>{const I=h.title||"Unknown Node",S=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:I}),e.jsx("div",{className:"p-4 space-y-3",children:e.jsx("div",{className:"flex items-center gap-3 flex-wrap",children:S.map((k,E)=>{const R=k.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[R]?"border-red-500 bg-red-100":"border-gray-300"}`,onClick:$=>n(R,$),children:r[R]&&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:R})]},`widget-${E}`)})})})]},`node-${v}`)}),e.jsx("div",{className:"mt-6 flex justify-center",children:e.jsx("button",{onClick:h=>u(h),disabled:!d,className:`px-3 py-1.5 text-xs ${d?"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"})})]})},ht=({selectedNodes:a,paramTestValues:n,selectedParams:r,updateParamTestValues:u,toggleDropdown:p,openDropdowns:x,handleTestValueSelect:d,searchTerms:h,handleSearch:v,handleSelectAll:I,handleNext:S,handlePrevious:k,handleClose:E,inputValues:R,setInputValues:$,textInputs:G,handleTextInputChange:O,handleAddTextInput:T,handleRemoveTextInput:w,openAiWritingModal:W})=>{const D=(c,C,H,Q=0)=>{if(c=isNaN(c)?0:c,C=isNaN(C)?100:C,H=isNaN(H)||H<=0?1:H,C<c&&(C=c),Math.floor((C-c)/H)+1<=1)return[c];const M=[];let Y=c;for(;Y<=C;){const m=Math.pow(10,Q),z=Math.round(Y*m)/m;M.push(z),Y+=H}return M};return y.useEffect(()=>{!a||a.length===0||a.forEach(c=>{const C=c.id.toString(),H=c.widgets||{};Object.values(H).forEach(g=>{const M=g.name;if(!r[M])return;if(!(n[C]?.[M]?.length>0)&&g.type==="number"){const m=g.options?.min||0,z=g.options?.max||100;let L=(g.options?.step||10)/10;L<.1&&(L=.1);const P=g.options?.precision||0,A=D(m,z,L,P);if(A.length>0){u(C,M,A);const F=`${C}_${M}`;$(f=>({...f,[F]:{min:m.toString(),max:z.toString(),step:L.toString()}}))}}if(g.type==="customtext"||g.type.toLowerCase().includes("text")){const m=`${C}_${M}`,z=G[m]||[""];JSON.stringify(z)!==JSON.stringify(n[C]?.[M]||[""])&&u(C,M,z)}})})},[a,r,n,G,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:E,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"})})})]}),a.length>0?a.map((c,C)=>{const H=c.widgets||{},Q=Object.values(H),g=c.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:[c.type," (ID: ",g,")"]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:M=>E(M,C),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:Q.map((M,Y)=>{const m=M.name;if(!r[m])return null;const z=`${g}_${m}`;if(M.type==="customtext"||M.type.toLowerCase().includes("text")){const L=G[z]||[""];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:[m,":"]}),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:()=>W(g,m),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:L.map((P,A)=>e.jsxs("div",{className:"flex items-start",children:[e.jsx("textarea",{className:`flex-1 border ${P?"border-gray-300":"border-red-500"} rounded p-2 text-xs resize-y`,rows:2,placeholder:"Enter text...",value:P,onChange:F=>O(g,m,A,F.target.value),required:!0}),e.jsx("button",{className:"ml-2 text-red-500 hover:text-red-700",onClick:()=>w(g,m,A),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"})})})]},A))}),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:()=>T(g,m),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"]})]},Y)}if(M.type==="number"){const L=M.options?.min||0,P=M.options?.max||100,A=(M.options?.step||10)/10,F=M.options?.precision||0,f=D(L,P,A,F),q=R[z]||{min:L.toString(),max:P.toString(),step:A.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:[m,":"]}),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:q.min,required:!0,onClick:N=>{N.preventDefault(),N.stopPropagation()},onChange:N=>{N.preventDefault(),N.stopPropagation();const _=N.target.value;if($(V=>({...V,[z]:{...V[z],min:_}})),_===""||!isNaN(parseFloat(_))){const V=_===""?0:parseFloat(_),K=parseFloat(q.max||P.toString()),B=parseFloat(q.step||A.toString()),J=D(V,K,B,F);u(g,m,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:q.max,onClick:N=>{N.preventDefault(),N.stopPropagation()},required:!0,onChange:N=>{N.preventDefault(),N.stopPropagation();const _=N.target.value;if($(V=>({...V,[z]:{...V[z],max:_}})),_===""||!isNaN(parseFloat(_))){const V=parseFloat(q.min||L.toString()),K=_===""?V:parseFloat(_),B=parseFloat(q.step||A.toString()),J=D(V,K,B,F);u(g,m,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:q.step,required:!0,onClick:N=>{N.preventDefault(),N.stopPropagation()},onChange:N=>{N.preventDefault(),N.stopPropagation();const _=N.target.value;if($(V=>({...V,[z]:{...V[z],step:_}})),_===""||!isNaN(parseFloat(_))&&parseFloat(_)>0){const V=parseFloat(q.min||L.toString()),K=parseFloat(q.max||P.toString());let B=_===""?1:parseFloat(_);B<.1&&(B=.1);const J=D(V,K,B,F);u(g,m,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 N=n[g]?.[m]||f;if(N.length<=10)return N.map((_,V)=>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:K=>{K.stopPropagation(),d(g,m,_,K)},children:[e.jsx("span",{children:_}),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"})})]},V));{const _=N.slice(0,5),V=N.slice(N.length-5);return e.jsxs(e.Fragment,{children:[_.map((K,B)=>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(),d(g,m,K,J)},children:[e.jsx("span",{children:K}),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-${B}`)),e.jsx("div",{className:"px-2 py-0.5 bg-gray-100 text-gray-600 rounded-md flex items-center text-xs",children:"..."}),V.map((K,B)=>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(),d(g,m,K,J)},children:[e.jsx("span",{children:K}),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-${B}`))]})}})()})]}),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"})})]},Y)}else if(M.type==="combo"){const L=M.options?.values||[],P=`${g}_${m}`,A=f=>typeof f=="string"?f:f&&typeof f=="object"&&"name"in f?f.name:String(f),F=f=>typeof f=="object"&&f!==null&&"name"in f?f.name:f;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:m}),e.jsxs("div",{className:"relative dropdown-container",children:[e.jsxs("button",{className:`appearance-none border ${(n[g]?.[m]||[]).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:f=>{f.preventDefault(),f.stopPropagation(),p(g,m,f)},"data-dropdown":P,children:[e.jsx("span",{children:(n[g]?.[m]||[]).length>0?`${m}: ${(n[g]?.[m]||[]).length} selected`:`Select ${m}`}),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"})})})]}),x[P]&&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 x[P]=="object"?`${x[P].y}px`:"0px",left:typeof x[P]=="object"?`${x[P].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[P]||"",onChange:f=>{f.preventDefault(),f.stopPropagation(),v(g,m,f.target.value)},onClick:f=>{f.preventDefault(),f.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:f=>{f.preventDefault(),f.stopPropagation();const N=L.filter(_=>!h[P]||A(_).toLowerCase().includes((h[P]||"").toLowerCase())).map(F);I(g,m,N)},children:[e.jsx("div",{className:`w-4 h-4 mr-2 border rounded-sm flex items-center justify-center ${L.length>0&&(n[g]?.[m]||[]).length===L.length?"bg-blue-500 border-blue-500":(n[g]?.[m]||[]).length>0?"bg-blue-500 border-blue-500 opacity-50":"border-gray-300"}`,children:(n[g]?.[m]||[]).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:L.length>0&&(n[g]?.[m]||[]).length===L.length?"Deselect All":"Select All"})]}),e.jsxs("div",{className:"max-h-60 overflow-y-auto",children:[L.filter(f=>!h[P]||A(f).toLowerCase().includes((h[P]||"").toLowerCase())).map((f,q)=>e.jsxs("div",{className:"px-3 py-1.5 hover:bg-gray-100 cursor-pointer text-xs flex items-center text-gray-700",onClick:N=>{N.preventDefault(),N.stopPropagation(),d(g,m,F(f),N)},children:[e.jsx("div",{className:`w-4 h-4 mr-2 border rounded-sm flex items-center justify-center ${(n[g]?.[m]||[]).includes(F(f))?"bg-blue-500 border-blue-500":"border-gray-300"}`,children:(n[g]?.[m]||[]).includes(F(f))&&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:A(f)})]},q)),L.filter(f=>!h[P]||A(f).toLowerCase().includes((h[P]||"").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"}),(n[g]?.[m]||[]).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:(n[g]?.[m]||[]).map((f,q)=>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:f}),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:N=>{N.preventDefault(),N.stopPropagation(),d(g,m,f,N)},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},q))})]})]},Y)}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:m})}),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:[(n[g]?.[m]||[]).map((L,P)=>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:L}),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:A=>{A.preventDefault(),A.stopPropagation(),d(g,m,L,A)},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},P)),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:L=>{L.preventDefault(),L.stopPropagation();const P=`${m}${(n[g]?.[m]||[]).length+1}`;u(g,m,[...n[g]?.[m]||[],P])},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"})]})]})]})]},Y)})})]},C)}):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:c=>k(c),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:c=>S(c),className:"px-3 py-1.5 text-xs bg-pink-200 text-pink-700 rounded-md hover:bg-pink-300 transition-colors",children:"Next"})]})]})},gt=({selectedNodes:a,paramTestValues:n,selectedParams:r,totalCount:u,errorMessage:p,handlePrevious:x,handleStartGeneration:d,handleClose:h})=>{const[v,I]=y.useState([]),[S,k]=y.useState(null),[E,R]=y.useState(!1);De();const $=()=>{const O=Object.values(Z.graph._nodes_by_id),T=[],w=[];for(const D of O)D.type==="SaveImage"?T.push(D.id):D.type==="PreviewImage"&&w.push(D.id);const W=[...T,...w];I(W),W.length===1?k(W[0]):W.length>1&&(R(!0),k(null))};y.useEffect(()=>{$()},[]),y.useEffect(()=>{const O=()=>{if(!Z.canvas.selected_nodes)return;const T=Object.values(Z.canvas.selected_nodes);if(T.length===0)return;const w=T[0];w&&(w.type==="SaveImage"||w.type==="PreviewImage")&&(console.log("Selected image node:",w.id),k(w.id))};return document.addEventListener("click",O),()=>{document.removeEventListener("click",O)}},[]);const G=O=>{if(O&&(O.preventDefault(),O.stopPropagation()),v.length>1&&!S){R(!0);return}d(O,S||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"})})})]}),E&&v.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:S===null?`Multiple SaveImage and PreviewImage nodes detected with IDs ${v.join(",")}. Please click the node on canvas.`:`Current node ID is ${S}, please click Start Generation again`})]})}),p&&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:p})]})}),a.length>0?a.map((O,T)=>{const w=O.type||"Unknown Node",W=O.widgets||[],D=O.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:[w," (ID: ",D,")"]}),e.jsx("div",{className:"p-4 space-y-3",children:W.map((c,C)=>{const H=c.name;if(!r[H])return null;const Q=n[D]?.[H]||[],g=Array.isArray(Q)?`[${Q.join(", ")}]`:JSON.stringify(Q);return e.jsxs("div",{className:C<W.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:H}),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:g,onClick:M=>M.preventDefault()})})]},C)})})]},T)}):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:O=>x(O),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:O=>G(O),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${v.length>1&&!S?"bg-gray-200 text-gray-500 cursor-not-allowed":"bg-pink-200 text-pink-700 hover:bg-pink-300"}`,disabled:v.length>1&&!S,children:"Start Generation"})]})]})},pt=({selectedNodes:a,paramTestValues:n,selectedParams:r,totalCount:u,completedCount:p,errorMessage:x,handleClose:d,setIsProcessing:h,setCurrentScreen:v,cleanupPolling:I})=>{const S=k=>{k.preventDefault(),k.stopPropagation(),at({clear:!0}),lt(),I&&I(),h(!1),v(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 ",p," 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:`${p/u*100}%`}})}),e.jsxs("div",{className:"mt-2 text-xs text-gray-600",children:["Already generated ",p," images"]}),e.jsx("button",{onClick:S,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:d,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"})})})]}),x&&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:x})]})}),a.length>0?a.map((k,E)=>{const R=k.type||"Unknown Node",$=k.widgets||[],G=k.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:[R," (ID: ",G,")"]}),e.jsx("div",{className:"p-4 space-y-3",children:$.map((O,T)=>{const w=O.name;if(!r[w])return null;const W=n[G]?.[w]||[],D=Array.isArray(W)?`[${W.join(", ")}]`:JSON.stringify(W);return e.jsxs("div",{className: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",children:w}),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:c=>c.preventDefault()})})]},T)})})]},E)}):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."})]})},ft=({generatedImages:a,selectedImageIndex:n,handleSelectImage:r,handleApplySelected:u,handlePrevious:p,handleClose:x,currentPage:d,handlePageChange:h,imagesPerPage:v,notificationVisible:I,modalVisible:S,modalImageUrl:k,openImageModal:E,closeImageModal:R})=>{const $=Math.ceil(a.length/v),G=(d-1)*v,O=Math.min(G+v,a.length),T=a.slice(G,O);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 ",a.length," images have been generated."]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:x,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"})})})]}),I&&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."})]})}),S&&e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-75 flex items-center justify-center z-50",onClick:R,children:e.jsxs("div",{className:"bg-white rounded-lg p-2 max-w-4xl max-h-[90vh] relative",onClick:w=>w.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:R,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:k,alt:"Enlarged image",className:"max-w-full object-contain w-auto h-auto"})})]})}),e.jsx("div",{className:"grid grid-cols-3 gap-4 mb-6",children:T.map((w,W)=>{const D=G+W;return e.jsxs("div",{className:`relative rounded-lg overflow-hidden border ${n===D?"border-pink-500 ring-2 ring-pink-300":"border-gray-200"}`,onClick:c=>r(D,c),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:c=>E(w.url,c),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:w.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(w.params).filter(([c,C])=>c!=="nodeParams"&&typeof C!="object").map(([c,C])=>e.jsxs("div",{children:[c,": ",String(C)]},c))})]},D)})}),$>1&&e.jsxs("div",{className:"flex justify-center items-center space-x-2 mt-4 mb-4",children:[e.jsx("button",{onClick:w=>h(1,w),disabled:d===1,className:`px-2 py-1 rounded ${d===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:w=>h(d-1,w),disabled:d===1,className:`px-2 py-1 rounded ${d===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 ",d," of ",$]}),e.jsx("button",{onClick:w=>h(d+1,w),disabled:d===$,className:`px-2 py-1 rounded ${d===$?"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:w=>h($,w),disabled:d===$,className:`px-2 py-1 rounded ${d===$?"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:w=>p(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=>u(w),className:"px-3 py-1.5 text-xs bg-pink-200 text-pink-700 rounded-md hover:bg-pink-300 transition-colors",disabled:n===null,children:"Apply Selected"})]})]})},bt=({visible:a,aiWritingModalText:n,setAiWritingModalText:r,aiGeneratedTexts:u,aiSelectedTexts:p,aiWritingLoading:x,aiWritingError:d,handleAiWriting:h,toggleTextSelection:v,addSelectedTexts:I,onClose:S})=>a?e.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-xl shadow-2xl w-full max-w-2xl max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"p-4 border-b border-gray-200 dark:border-gray-700 flex justify-between items-center",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"AI Writing Assistant"}),e.jsx("button",{className:"text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200",onClick:S,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-700 dark:text-gray-300 mb-2",children:"Enter text and AI will generate variations"}),e.jsx("textarea",{className:`w-full px-4 py-3 border border-gray-200 dark:border-gray-600 rounded-lg text-gray-900 dark:text-white
|
|
bg-gray-50 dark:bg-gray-700
|
|
placeholder-gray-500 dark:placeholder-gray-400
|
|
focus:border-blue-500 dark:focus:border-blue-400
|
|
focus:ring-2 focus:ring-blue-500/20 dark:focus:ring-blue-400/20
|
|
focus:outline-none`,rows:3,placeholder:"Enter some text here...",value:n,onChange:k=>r(k.target.value)}),e.jsx("button",{className:`mt-2 px-4 py-2 rounded-lg text-sm flex items-center transition-colors ${x?"bg-gray-300 dark:bg-gray-600 text-gray-500 dark:text-gray-400 cursor-not-allowed":"bg-blue-600 hover:bg-blue-700 dark:bg-blue-500 dark:hover:bg-blue-600 text-white"}`,onClick:h,disabled:x,children:x?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin -ml-1 mr-2 h-4 w-4 text-gray-500 dark:text-gray-400",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"})})]}),d&&e.jsx("div",{className:"mb-4 p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800/20 rounded-md text-red-700 dark:text-red-400 text-sm",children:d}),u.length>0&&e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 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((k,E)=>e.jsxs("div",{className:"flex items-start border border-gray-200 dark:border-gray-600 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${E+1}`,checked:!!p[`text${E+1}`],onChange:()=>v(`text${E+1}`),className:"sr-only"}),e.jsx("div",{className:`h-4 w-4 rounded border ${p[`text${E+1}`]?"bg-blue-600 dark:bg-blue-500 border-blue-600 dark:border-blue-500":"border-gray-300 dark:border-gray-600"} flex items-center justify-center cursor-pointer`,onClick:()=>v(`text${E+1}`),children:p[`text${E+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${E+1}`,className:"text-sm text-gray-700 dark:text-gray-300 cursor-pointer flex-1",children:k})]},E))})]})]}),e.jsxs("div",{className:"p-4 border-t border-gray-200 dark:border-gray-700 flex justify-end flex-shrink-0",children:[e.jsx("button",{className:`px-5 py-2.5 text-gray-700 dark:text-gray-200 bg-white dark:bg-gray-800 hover:bg-gray-100 dark:hover:bg-gray-700
|
|
rounded-lg font-medium transition-colors mr-3`,onClick:S,children:"Cancel"}),e.jsx("button",{className:`px-5 py-2.5 rounded-lg font-medium transition-colors ${Object.values(p).every(k=>!k)?"bg-gray-300 dark:bg-gray-600 text-gray-500 dark:text-gray-400 cursor-not-allowed":"bg-blue-600 hover:bg-blue-700 dark:bg-blue-500 dark:hover:bg-blue-600 text-white"}`,onClick:I,disabled:Object.values(p).every(k=>!k),children:"Add Selected"})]})]})}):null,Ce=a=>{const n=[],r={};if(Object.keys(a).forEach(x=>{const d=parseInt(x),h=a[x]||{},v=Object.keys(h).filter(S=>h[S]&&h[S].length>0);if(v.length===0)return;const I=[[]];v.forEach(S=>{const k=h[S],E=[];I.forEach(R=>{k.forEach($=>{const G=[...R,{nodeId:d,paramName:S,paramValue:String($)}];E.push(G)})}),I.length=0,I.push(...E)}),r[x]=I}),Object.keys(r).length===0)return n;if(Object.keys(r).length===1){const x=Object.keys(r)[0];return r[x]}const u=Object.keys(r);let p=r[u[0]];for(let x=1;x<u.length;x++){const d=r[u[x]],h=[];p.forEach(v=>{d.forEach(I=>{h.push([...v,...I])})}),p=h}return p},yt=(a,n)=>{const r={};r.nodeParams={};const u=Ce(a);return n<u.length&&u[n].forEach(x=>{const d=x.nodeId.toString(),h=x.paramName,v=x.paramValue;r.nodeParams[d]||(r.nodeParams[d]={}),r.nodeParams[d][h]=v,r[h]=v}),r},ye="parameter_debug_state",jt=`
|
|
@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;
|
|
}
|
|
`,Lt=({selectedNodes:a,visible:n,onClose:r})=>{const[u,p]=y.useState(0),[x,d]=y.useState({Steps:!0,CFG:!0,sampler_name:!0,threshold:!1,prompt:!1}),[h,v]=y.useState(ke()),[I,S]=y.useState(!1),[k,E]=y.useState(!1),[R,$]=y.useState(0),[G,O]=y.useState(12),[T,w]=y.useState(null),[W,D]=y.useState(()=>Array(12).fill(null).map((s,t)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:{step:t%3===0?5:t%3===1?10:15,sampler_name:"euler",cfg:1}}))),[c,C]=y.useState({}),[H,Q]=y.useState({}),[g,M]=y.useState({}),[Y,m]=y.useState({}),[z,L]=y.useState(1),P=6,[A,F]=y.useState(null),[f,q]=y.useState(!1),[N,_]=y.useState(!1),[V,K]=y.useState(""),[B,J]=y.useState({}),[Te,xe]=y.useState(!1),[ne,je]=y.useState(""),[ve,me]=y.useState([]),[We,he]=y.useState(!1),[Se,Le]=y.useState(""),[Pe,Ie]=y.useState(""),[Ae,oe]=y.useState(null),[Me,ae]=y.useState({}),{dispatch:le}=De(),ge=y.useRef(null),ie=y.useRef(null),[Be,pe]=y.useState(()=>n),_e=s=>{try{localStorage.setItem(ye,JSON.stringify(s))}catch(t){console.error("Error saving parameter debug state:",t)}},Re=async()=>{if(!ne.trim()){oe("Please enter some text to generate variations");return}he(!0),oe(null),me([]),ae({});try{const s=await ue.generateSDPrompts(ne);me(s),ue.trackEvent({event_type:"prompt_generate",message_type:"parameter_debug",message_id:h,data:{input_text:ne,generated_texts:s}});const t={};s.forEach((i,o)=>{t[`text${o+1}`]=!1}),ae(t)}catch(s){console.error("Error generating text:",s),oe("Failed to generate text variations. Please try again.")}finally{he(!1)}},ze=(s,t,i,o)=>{const l=`${s}_${t}`;J(j=>{const U=[...j[l]||[]];return U[i]=o,{...j,[l]:U}});const b=[...B[l]||[]];b[i]=o,te(s,t,b)},Fe=(s,t)=>{const i=`${s}_${t}`;J(l=>{const b=[...l[i]||[]];return b.push(""),{...l,[i]:b}});const o=[...B[i]||[],""];te(s,t,o)},Ve=(s,t,i)=>{const o=`${s}_${t}`;J(b=>{const j=[...b[o]||[]];return j.splice(i,1),{...b,[o]:j}});const l=[...B[o]||[]];l.splice(i,1),te(s,t,l)},Ge=s=>{ae(t=>({...t,[s]:!t[s]}))},Ue=()=>{const s=`${Se}_${Pe}`,t=Object.entries(Me).filter(([o,l])=>l).map(([o])=>{const l=parseInt(o.replace("text",""))-1;return ve[l]});if(t.length===0)return;J(o=>{const l=[...o[s]||[]];return{...o,[s]:[...l,...t]}}),ue.trackEvent({event_type:"prompt_apply",message_type:"parameter_debug",message_id:h,data:{input_text:ne,generated_texts:ve,selected_texts:t}});const i=[...B[s]||[],...t];te(Se,Pe,i),xe(!1)},He=(s,t)=>{xe(!0),Le(s),Ie(t),je(""),me([]),ae({}),he(!1),oe(null)};y.useEffect(()=>{if(!a||a.length===0)return;const s={...c},t=a.map(o=>o.id.toString());Object.keys(s).forEach(o=>{t.includes(o)||delete s[o]}),a.forEach(o=>{const l=o.id.toString();s[l]||(s[l]={})}),JSON.stringify(s)!==JSON.stringify(c)&&C(s)},[a,c]),y.useEffect(()=>{le({type:"SET_SCREEN_STATE",payload:{currentScreen:u,isProcessing:I,isCompleted:k}})},[u,I,k,le]),y.useEffect(()=>{const s=document.createElement("style");return s.textContent=jt,document.head.appendChild(s),()=>{document.head.removeChild(s)}},[]),y.useEffect(()=>{const s=t=>{if(Object.values(H).some(i=>i)){const i=t.target,o=!!i.closest(".dropdown-menu"),l=!!i.closest("[data-dropdown]");!o&&!l&&Q({})}};return document.addEventListener("mousedown",s),()=>{document.removeEventListener("mousedown",s)}},[H]),y.useEffect(()=>{n&&(JSON.parse(localStorage.getItem(ye)||"{}").task_id||v(ke()))},[n]),y.useEffect(()=>{if(n){pe(!0);try{const s=localStorage.getItem(ye);if(s){const t=JSON.parse(s);if(!a||a.length===0){console.log("Not restoring parameter debug state: no nodes selected"),pe(!1);return}t.currentScreen!==void 0&&p(t.currentScreen),t.selectedParams&&d(t.selectedParams),t.task_id&&v(t.task_id);const i=t.generatedImages&&t.generatedImages.length>0;t.isProcessing!==void 0&&!t.isProcessing&&S(!1),t.isCompleted!==void 0&&i&&E(t.isCompleted),t.completedCount!==void 0&&$(t.completedCount),t.totalCount!==void 0&&O(t.totalCount),t.selectedImageIndex!==void 0&&w(t.selectedImageIndex),t.generatedImages&&D(t.generatedImages),t.paramTestValues&&C(t.paramTestValues),t.searchTerms&&M(t.searchTerms),t.inputValues&&m(t.inputValues),t.currentPage!==void 0&&L(t.currentPage),t.textInputs&&J(t.textInputs)}}catch(s){console.error("Error loading parameter debug state:",s)}finally{setTimeout(()=>{pe(!1)},50)}}else pe(!0);return()=>{if(!n)return;_e({currentScreen:u,selectedParams:x,task_id:h,isProcessing:I,isCompleted:k,completedCount:R,totalCount:G,selectedImageIndex:T,generatedImages:W,paramTestValues:c,searchTerms:g,inputValues:Y,currentPage:z,textInputs:B})}},[n]),y.useEffect(()=>{if(!n)return;const s=setTimeout(()=>{_e({currentScreen:u,selectedParams:x,task_id:h,isProcessing:I,isCompleted:k,completedCount:R,totalCount:G,selectedImageIndex:T,generatedImages:W,paramTestValues:c,searchTerms:g,inputValues:Y,currentPage:z,textInputs:B})},500);return()=>clearTimeout(s)},[n,u,x,h,I,k,R,G,T,W,c,g,Y,z,B]);const Ee=s=>{if(s&&(s.preventDefault(),s.stopPropagation()),u===0){const t={...c};Object.keys(t).forEach(i=>{const o=t[i];Object.keys(o).forEach(l=>{x[l]||delete o[l]})}),C(t)}if(u===1){const t={...c};a.forEach(o=>{const l=o.id.toString(),b=o.widgets||{};Object.values(b).forEach(j=>{const U=j.name;if(x[U]&&(j.type==="customtext"||j.type.toLowerCase().includes("text"))){const ee=`${l}_${U}`,se=B[ee]||[""];t[l]=t[l]||{},t[l][U]=se}})}),C(t);const i=Ce(t);O(i.length)}F(null),p(t=>Math.min(t+1,2))},we=s=>{if(s&&(s.preventDefault(),s.stopPropagation()),F(null),k&&E(!1),u===1){const t=a.map(l=>l.id.toString()),i=Object.keys(c),o={...c};i.forEach(l=>{t.includes(l)||delete o[l]}),C(o)}if(u===2||k){const t={...c};Object.entries(B).forEach(([i,o])=>{if(!o||o.length===0)return;const[l,b]=i.split("_");a.some(j=>j.id.toString()===l)&&(t[l]=t[l]||{},JSON.stringify(t[l][b])!==JSON.stringify(o)&&(t[l][b]=o))}),C(t)}p(t=>Math.max(t-1,0))},qe=(s,t)=>{t&&(t.preventDefault(),t.stopPropagation());const i=x[s];if(d(o=>({...o,[s]:!i})),i){const o={...c};Object.keys(o).forEach(l=>{o[l][s]&&delete o[l][s]}),C(o)}},Je=(s,t,i)=>{i.preventDefault(),i.stopPropagation();const o=`${s}_${t}`;Q(l=>{if(l[o]&&typeof l[o]=="object"?l[o].isOpen:!!l[o])return{...l,[o]:!1};{let j=0,U=0;if(i.currentTarget){const de=i.currentTarget.getBoundingClientRect();j=de.left,U=de.bottom}else j=i.clientX,U=i.clientY+20;const ee=window.innerWidth,se=250;return j+se>ee&&(j=ee-se-10),j<0&&(j=10),{...l,[o]:{isOpen:!0,x:j,y:U}}}})},te=(s,t,i)=>{C(o=>{const l={...o};return l[s]||(l[s]={}),l[s][t]=i,l})},Ke=(s,t,i,o)=>{o&&(o.preventDefault(),o.stopPropagation()),C(l=>{const b={...l};b[s]||(b[s]={}),b[s][t]||(b[s][t]=[]);const j=b[s][t];return j.includes(i)?b[s][t]=j.filter(U=>U!==i):b[s][t]=[...j,i],b})},Ye=(s,t,i)=>{const o=`${s}_${t}`;M(l=>({...l,[o]:i}))},Qe=(s,t,i)=>{if(!c[s]){te(s,t,i);return}const o=c[s][t]||[];i.length===o.length?te(s,t,[]):te(s,t,[...i])},Xe=(s,t)=>{t&&(t.preventDefault(),t.stopPropagation()),L(Math.max(1,Math.min(s,Math.ceil(W.length/P))))},fe=()=>{ge.current&&(clearTimeout(ge.current),ge.current=null),ie.current=null};y.useEffect(()=>()=>{fe()},[]);const Ze=async(s,t)=>{s&&(s.preventDefault(),s.stopPropagation()),fe();const i=Ce(c),o=i.length;if(o>100){F(`Cannot generate more than 100 images at once (currently: ${o} images)`);return}if(F(null),S(!0),$(0),console.log("Generated parameter combinations:",i),ue.trackEvent({event_type:"start_generation",message_type:"parameter_debug",message_id:h,data:{workflow:(await Z.graphToPrompt()).output,all_params:c,count:o}}),i.length===0){F("No valid parameter combinations found. Please check your parameter selections."),S(!1);return}let l=t||null;if(l===null){const j=ut();j!==null&&(l=j)}if(l===null){F("Please select a SaveImage or PreviewImage node first."),S(!1);return}const b=[];try{const j=Date.now().toString();ie.current=j;for(const re of i){const X=await ct(re);X.prompt_id?b.push(X.prompt_id):(console.error("Failed to get prompt_id from response:",X),b.push(""))}const U=Array(i.length).fill(null).map((re,X)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:yt(c,X)}));D(U);const ee=Date.now(),se=5*60*1e3,de=async()=>{if(ie.current!==j){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===j&&(S(!1),E(!0),L(1));return}let re=0;for(let X=0;X<b.length;X++){const Ne=b[X];if(Ne)try{const be=await xt(Ne,Number(l));be&&(U[X]={...U[X],url:be},re++)}catch(be){console.error(`Error fetching image for prompt ID ${Ne}:`,be)}}ie.current===j&&(D([...U]),$(re),re===b.length?(console.log("All images ready, completing session"),S(!1),E(!0),L(1)):ge.current=setTimeout(de,3e3))};de()}catch(j){console.error("Error generating images:",j),S(!1)}},et=(s,t)=>{t&&(t.preventDefault(),t.stopPropagation()),w(s)},tt=(s,t)=>{t.preventDefault(),t.stopPropagation(),K(s),_(!0)},st=s=>{s&&(s.preventDefault(),s.stopPropagation()),_(!1)},rt=async s=>{if(s&&(s.preventDefault(),s.stopPropagation()),T!==null){console.log(`Applied image ${T+1} with parameters:`,W[T].params);let t=1;if(c){for(const o in c)if(c[o])for(const l in c[o]){const b=c[o][l];if(b){let j=1;Array.isArray(b)?j=b.length>0?b.length:1:typeof b=="object"&&b!==null&&(j=Object.keys(b).length>0?Object.keys(b).length:1),t=t*j}}}ue.trackEvent({event_type:"parameter_debug_apply",message_type:"parameter_debug",message_id:h,data:{workflow:(await Z.graphToPrompt()).output,selected_params:W[T].params,all_params:c,count:t}});const i=W[T].params;i.nodeParams&&(Object.entries(i.nodeParams).forEach(([o,l])=>{const b=Z.graph._nodes_by_id[o];!b||!b.widgets||Object.entries(l).forEach(([j,U])=>{for(const ee of b.widgets)if(ee.name===j){ee.value=U;break}})}),Z.graph.setDirtyCanvas(!1,!0),q(!0),setTimeout(()=>{q(!1)},3e3))}},ce=(s,t)=>{if(s&&(s.preventDefault(),s.stopPropagation()),u===1&&t!==void 0){const i=[...a],o=i[t];if(i.splice(t,1),o){const l=o.id.toString();C(b=>{const j={...b};return delete j[l],j})}i.length===0?r&&(le({type:"SET_SCREEN_STATE",payload:null}),$e(!0),r()):le({type:"SET_SELECTED_NODE",payload:i});return}r&&(le({type:"SET_SCREEN_STATE",payload:null}),$e(!0),r())},$e=(s=!1)=>{p(0),d({Steps:!0,CFG:!0,sampler_name:!0,threshold:!1,prompt:!1}),v(ke()),fe(),S(!1),E(!1),$(0),O(12),w(null),D(Array(12).fill(null).map((t,i)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:{step:i%3===0?5:i%3===1?10:15,sampler_name:"euler",cfg:1}}))),C({}),Q({}),M({}),m({}),L(1),F(null),q(!1),_(!1),K(""),J({}),xe(!1),je(""),me([]),he(!1),Le(""),Ie(""),oe(null),ae({}),s&&localStorage.removeItem(ye)};return Be&&n&&a.length>0?e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center p-8 bg-gray-50 overflow-y-auto",onClick:s=>s.stopPropagation(),children:e.jsxs("div",{className:"p-8 rounded-lg shadow-sm relative flex flex-col items-center",children:[e.jsx("div",{className:"w-8 h-8 border-4 border-blue-500 border-t-transparent rounded-full animate-spin"}),e.jsx("div",{className:"mt-4 text-gray-600 text-sm",children:"Loading interface..."})]})}):!n||a.length===0?e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center p-8 bg-gray-50 overflow-y-auto",onClick:s=>s.stopPropagation(),children:e.jsxs("div",{className:"max-w-lg p-8 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"})})]})]})}):k?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:s=>s.stopPropagation(),children:e.jsx(ft,{generatedImages:W,selectedImageIndex:T,handleSelectImage:et,handleApplySelected:rt,handlePrevious:we,handleClose:ce,currentPage:z,handlePageChange:Xe,imagesPerPage:P,notificationVisible:f,modalVisible:N,modalImageUrl:V,openImageModal:tt,closeImageModal:st})}):I?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:s=>s.stopPropagation(),children:e.jsx(pt,{selectedNodes:a,paramTestValues:c,selectedParams:x,totalCount:G,completedCount:R,errorMessage:A,handleClose:ce,setIsProcessing:S,setCurrentScreen:p,cleanupPolling:fe})}):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:s=>s.stopPropagation(),children:e.jsx(mt,{selectedNodes:a,handleParamSelect:qe,selectedParams:x,handleNext:Ee,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:s=>s.stopPropagation(),children:[e.jsx(ht,{selectedNodes:a,paramTestValues:c,selectedParams:x,updateParamTestValues:te,toggleDropdown:Je,openDropdowns:H,handleTestValueSelect:Ke,searchTerms:g,handleSearch:Ye,handleSelectAll:Qe,handleNext:Ee,handlePrevious:we,handleClose:ce,inputValues:Y,setInputValues:m,textInputs:B,handleTextInputChange:ze,handleAddTextInput:Fe,handleRemoveTextInput:Ve,openAiWritingModal:He}),e.jsx(bt,{visible:Te,aiWritingModalText:ne,setAiWritingModalText:je,aiGeneratedTexts:ve,aiSelectedTexts:Me,aiWritingLoading:We,aiWritingError:Ae,handleAiWriting:Re,toggleTextSelection:Ge,addSelectedTexts:Ue,onClose:()=>xe(!1)})]}):e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4 flex flex-col h-full max-h-[80vh]",onClick:s=>s.stopPropagation(),children:e.jsx(gt,{selectedNodes:a,paramTestValues:c,selectedParams:x,totalCount:G,errorMessage:A,handlePrevious:we,handleStartGeneration:Ze,handleClose:ce})})};export{Lt as ParameterDebugInterface};
|