@w6w/ui 0.2.66 → 0.2.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -1
- package/README.md +5 -3
- package/dist/FormBuilder.d.ts +19 -0
- package/dist/ManualWebhookPanel.d.ts +34 -0
- package/dist/TriggerFillForm.d.ts +3 -0
- package/dist/WebhookListenPanel.d.ts +8 -1
- package/dist/components/AuthFieldsForm.d.ts +10 -0
- package/dist/components/AuthGuide.d.ts +19 -1
- package/dist/components/CallableList.d.ts +30 -4
- package/dist/components/Combobox.d.ts +5 -0
- package/dist/components/ExpressionOptions.d.ts +22 -0
- package/dist/{connection-app-meta-CKBbgN7e.js → connection-app-meta-DEC0n4PA.js} +4894 -4211
- package/dist/connection-app-meta-DEC0n4PA.js.map +1 -0
- package/dist/connection-app-meta-Dk6F3KEH.cjs +29 -0
- package/dist/connection-app-meta-Dk6F3KEH.cjs.map +1 -0
- package/dist/dynamic-fields.d.ts +3 -0
- package/dist/flow-types.d.ts +2 -0
- package/dist/flow.cjs +6 -5
- package/dist/flow.cjs.map +1 -1
- package/dist/flow.mjs +3515 -2436
- package/dist/flow.mjs.map +1 -1
- package/dist/form-schema.d.ts +236 -0
- package/dist/form-trigger.d.ts +8 -0
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +1325 -1272
- package/dist/index.mjs.map +1 -1
- package/dist/provider.d.ts +12 -0
- package/dist/resolve-params.d.ts +2 -0
- package/dist/types.d.ts +17 -1
- package/dist/workflow-connections.d.ts +11 -0
- package/package.json +2 -2
- package/src/styles/_callable-list.scss +37 -3
- package/src/styles/_connections.scss +29 -0
- package/src/styles/_expression-modal.scss +7 -0
- package/src/styles/_form-builder.scss +232 -0
- package/src/styles/_sections.scss +29 -0
- package/src/styles.css +386 -3
- package/src/styles.scss +1 -0
- package/dist/connection-app-meta-CKBbgN7e.js.map +0 -1
- package/dist/connection-app-meta-DfA6Yqhh.cjs +0 -28
- package/dist/connection-app-meta-DfA6Yqhh.cjs.map +0 -1
package/dist/flow.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
"use client";"use strict";var io=Object.defineProperty;var ro=(e,s,i)=>s in e?io(e,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[s]=i;var ot=(e,s,i)=>ro(e,typeof s!="symbol"?s+"":s,i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),oe=require("@xyflow/react"),l=require("react"),o=require("./connection-app-meta-DfA6Yqhh.cjs"),Ee=require("./CodeBlock-C1IC5_6O.cjs"),Ie=require("@w6w/expr");function ao({x:e,y:s,items:i,onAction:n,onClose:a}){const u=l.useRef(null),[d,f]=l.useState({left:e,top:s});l.useLayoutEffect(()=>{const x=u.current,b=x==null?void 0:x.offsetParent;if(!x||!b)return;const g=x.offsetWidth,S=x.offsetHeight;f({left:e+g>b.clientWidth?Math.max(0,e-g):e,top:s+S>b.clientHeight?Math.max(0,s-S):s})},[e,s]),l.useEffect(()=>{var x,b;(b=(x=u.current)==null?void 0:x.querySelector("[role=menuitem]"))==null||b.focus({preventScroll:!0})},[]),l.useEffect(()=>{const x=S=>{var v;(v=u.current)!=null&&v.contains(S.target)||a(!1)},b=S=>{var v;(v=u.current)!=null&&v.contains(S.target)||a(!1)},g=()=>a(!1);return document.addEventListener("pointerdown",x,!0),document.addEventListener("scroll",b,!0),document.addEventListener("wheel",b,{capture:!0,passive:!0}),window.addEventListener("blur",g),window.addEventListener("resize",g),()=>{document.removeEventListener("pointerdown",x,!0),document.removeEventListener("scroll",b,!0),document.removeEventListener("wheel",b,!0),window.removeEventListener("blur",g),window.removeEventListener("resize",g)}},[a]);const p=x=>{x.disabled||(a(!1),n(x.action))};return t.jsx("div",{ref:u,className:"w6w-note-menu w6w-canvas-menu",role:"menu","aria-label":"Canvas actions","data-testid":"canvas-context-menu",style:{left:d.left,top:d.top},onContextMenu:x=>x.preventDefault(),onKeyDown:x=>{var v;x.stopPropagation();const b=[...((v=u.current)==null?void 0:v.querySelectorAll("[role=menuitem]"))??[]],g=b.indexOf(document.activeElement),S=R=>{var E;return(E=b[(R+b.length)%b.length])==null?void 0:E.focus()};if(x.key==="ArrowDown")S(g+1);else if(x.key==="ArrowUp")S(g<0?-1:g-1);else if(x.key==="Home")S(0);else if(x.key==="End")S(-1);else if(x.key==="Escape"||x.key==="Tab")a(!0);else if(x.key==="Enter"||x.key===" ")g>=0&&p(i[g]);else return;x.preventDefault()},children:i.map(x=>t.jsx("button",{type:"button",role:"menuitem",tabIndex:-1,"aria-disabled":x.disabled||void 0,className:`w6w-note-menu-item${x.danger?" danger":""}${x.separated?" separated":""}`,"data-action":x.action,onClick:()=>p(x),children:x.label},x.action))})}function co(e,s){return s===void 0?[...e]:e.includes(s)?[...e]:[s]}function lo(e,s,i={}){const n=[],a=e.length;if(a>0){const u=a>1?` ${a} nodes`:"";n.push({action:"duplicate",label:`Duplicate${u}`,disabled:s}),a===1&&i.replaceableTrigger&&n.push({action:"replace-trigger",label:"Replace trigger",disabled:s}),n.push({action:"delete",label:`Delete${u}`,disabled:s,danger:!0})}return n.push({action:"add-node",label:"Add node",disabled:s,separated:a>0}),n.push({action:"add-trigger",label:"Add trigger",disabled:s}),n}const hn=200,mn=200,gn=10240;function Yt(e){const s={};for(const[i,n]of Object.entries(e))s[i]=Math.round(n);return s}const uo=e=>!!e&&Number.isFinite(e.x)&&Number.isFinite(e.y),po=e=>!!e&&Number.isFinite(e.width)&&Number.isFinite(e.height);function Xs(e,s,i){return e&&e.map(n=>{const a=s==null?void 0:s[n.id],u=uo(a==null?void 0:a.position)?a.position:n.position,d=po(a==null?void 0:a.size)?a.size:n.size;return{...n,position:Yt(u),size:Yt(d)}})}function wn(e,s,i){if(!s)return e;const n={...e};return e.notes&&(n.notes=Xs(e.notes,i)),e.sections&&(n.sections=Xs(e.sections,i)),n}function is(e,s){return e.sections?{...e,sections:e.sections.map(i=>({...i,nodes:i.nodes.filter(n=>n!==s)}))}:e}function Zt(e,s,i){return e.sections?{...e,sections:e.sections.map(n=>({...n,nodes:n.nodes.map(a=>a===s?i:a)}))}:e}function Qt(e,s,i){if(!e.sections)return e;const n=new Set(i);return{...e,sections:e.sections.map(a=>{const u=a.nodes.filter(d=>!n.has(d));return a.id===s?{...a,nodes:[...new Set([...u,...i])]}:{...a,nodes:u}})}}function xn(e,s){return(e.sections??[]).filter(i=>i.nodes.includes(s)).map(i=>i.id)}function fo(e,s){const i=new TextEncoder;if(i.encode(e).length<=s)return e;let n="",a=0;for(const u of e){const d=i.encode(u).length;if(a+d>s)break;n+=u,a+=d}return n}function es(e){const s={...e};return e.notes&&(s.notes=e.notes.slice(0,hn).map(i=>({...i,content:fo(i.content,gn)}))),e.sections&&(s.sections=e.sections.slice(0,mn)),s}function ho(e,s,i){const n={};for(const d of[...e.notes??[],...e.sections??[]])n[d.id]={position:d.position,size:d.size};const a=(d,f)=>d==null?void 0:d.map(p=>{const x=f==null?void 0:f.find(b=>b.id===p.id);return x?{...p,position:x.position,size:x.size}:p}),u=i?e:{...e,...e.notes?{notes:a(e.notes,s==null?void 0:s.notes)}:{},...e.sections?{sections:a(e.sections,s==null?void 0:s.sections)}:{}};return wn(u,i,n)}const Ys=220;function mo(e){return e.length<=Ys?{text:e,clipped:!1,length:e.length}:{text:e.slice(0,Ys).trimEnd(),clipped:!0,length:e.length}}function go({params:e,values:s,testStartState:i,view:n="props",literalKeys:a}){const{sampleValues:u,nodeConfig:d,nodeMeta:f}=o.useExpressionOptions(),p=l.useMemo(()=>o.buildResolveScope(u,i,d,f),[u,i,d,f]),x=o.flattenParams(e),b=v=>{var R;return s[v]!==void 0?s[v]:(R=x.find(E=>E.key===v))==null?void 0:R.default},g=x.filter(v=>v.type!=="section"&&o.isParamVisible(v,b)).map(v=>Ie.effectiveParam(v,b));if(o.hasParamCustomization(s)){const v=o.previewCustomization(s.$merge,p,a),R=v!==null&&typeof v=="object"&&!Array.isArray(v),E=Zs(g,s,p,a);for(const[m,A]of Object.entries(s))m!=="$merge"&&(E[m]=a!=null&&a.includes(m)?A:o.previewCustomization(A,p));const D=R?{...E,...v}:E;return t.jsxs("div",{className:"w6w-resolved-params",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:R?"JSON customization applied after form values.":`JSON customization is not available as an object in this preview (${String(v)}). Test the step to validate it.`}),n==="code"?t.jsx(o.JsonEditor,{value:JSON.stringify(D,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"}):t.jsx("div",{className:"w6w-resolved-table",children:Object.entries(D).map(([m,A])=>{var O;return t.jsx(ts,{label:((O=x.find(U=>U.key===m))==null?void 0:O.label)??m,segments:[{status:"resolved",value:A}]},m)})})]})}if(n==="code"){const v=Zs(g,s,p,a);return t.jsx("div",{className:"w6w-resolved-params",children:t.jsx(o.JsonEditor,{value:JSON.stringify(v,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"})})}const S=g.filter(v=>!o.deepEqual(b(v.key),v.default));return g.length===0?t.jsx("div",{className:"w6w-resolved-params",children:t.jsx("p",{className:"w6w-muted w6w-small",children:"This action takes no parameters."})}):S.length===0?t.jsx("div",{className:"w6w-resolved-params",children:t.jsx("p",{className:"w6w-muted w6w-small",children:"Every configured value matches its default — nothing to show here. Switch to JSON to see the full set."})}):t.jsx("div",{className:"w6w-resolved-params w6w-resolved-table",children:S.map(v=>v.type==="vars"?t.jsx(wo,{param:v,value:s[v.key],scope:p},v.key):t.jsx(ts,{label:v.label??v.key,segments:a!=null&&a.includes(v.key)?[{status:"resolved",value:b(v.key)}]:o.resolveParamValue(b(v.key),p)},v.key))})}function Zs(e,s,i,n){const a={};for(const u of e)if(n!=null&&n.includes(u.key))a[u.key]=s[u.key]!==void 0?s[u.key]:u.default;else if(u.type==="vars"){const d=s[u.key]??u.default??[],f=o.dataVarRows(d);a[u.key]=f?o.resolveVarsJson(f,i):o.resolveParamJson(d,i)}else a[u.key]=o.resolveParamJson(s[u.key]!==void 0?s[u.key]:u.default,i);return a}function ts({label:e,segments:s}){return t.jsxs("div",{className:"w6w-resolved-row",children:[t.jsx("span",{className:"w6w-resolved-label",children:e}),t.jsx("div",{className:"w6w-resolved-value",children:t.jsx(bn,{segments:s})})]})}function wo({param:e,value:s,scope:i}){const n=s??e.default??[],a=o.dataVarRows(n);return a===null?t.jsx(ts,{label:e.label??e.key,segments:o.resolveParamValue(n,i)}):t.jsxs("div",{className:"w6w-resolved-row",children:[t.jsx("span",{className:"w6w-resolved-label",children:e.label??e.key}),a.length===0?t.jsx("p",{className:"w6w-muted w6w-small",children:"None configured."}):t.jsx("div",{className:"w6w-stack",children:a.map((u,d)=>t.jsxs("div",{className:"w6w-resolved-value",children:[t.jsx("code",{children:u.key||"(no key)"})," → ",t.jsx(bn,{segments:o.resolveParamValue(u.value,i)})]},d))})]})}function bn({segments:e}){return t.jsx(t.Fragment,{children:e.map((s,i)=>t.jsx(xo,{segment:s},i))})}function xo({segment:e}){switch(e.status){case"resolved":return e.ref?t.jsxs(t.Fragment,{children:[t.jsx(ft,{kind:"var",refName:e.ref}),t.jsx(Qs,{value:e.value})]}):t.jsx(Qs,{value:e.value});case"unresolved":return t.jsxs(t.Fragment,{children:[t.jsx(ft,{kind:"var",refName:e.ref}),t.jsx("span",{className:"w6w-param-unresolved",children:"unresolved"})]});case"at-run":return t.jsxs(t.Fragment,{children:[t.jsx(ft,{kind:"var",refName:e.ref}),t.jsx("span",{className:"w6w-param-unevaluated",children:"resolved at run"})]});case"not-evaluated":return t.jsxs(t.Fragment,{children:[t.jsx(ft,{kind:"expr"}),t.jsx("span",{className:"w6w-param-unevaluated",children:"not evaluated"})]});case"masked":return t.jsx(ft,{kind:"secret",refName:e.ref})}}function Qs({value:e}){const[s,i]=l.useState(!1),n=yo(e),a=mo(n);return a.clipped?t.jsxs(t.Fragment,{children:[s?t.jsx(Ee.Copyable,{value:n,label:"Copy resolved value",className:"w6w-resolved-copy",children:t.jsx("pre",{className:"w6w-resolved-text-full",children:n})}):t.jsxs("span",{children:[a.text,"…"]}),t.jsx("button",{type:"button",className:"w6w-resolved-more","aria-expanded":s,onClick:()=>i(u=>!u),children:s?"Show less":`Show all (${a.length.toLocaleString()} characters)`})]}):t.jsx("span",{children:n})}const bo={var:"◆",secret:"🔒",expr:"ƒ"};function ft({kind:e,refName:s}){const i=e==="expr"?"expr":o.varLabel(s??"");return t.jsxs("span",{className:`w6w-expr-chip w6w-expr-chip-${e}`,children:[t.jsx("span",{className:"w6w-expr-chip-sigil",children:bo[e]}),t.jsx("span",{className:"w6w-expr-chip-label",children:i})]})}function yo(e){if(e===null)return"null";if(e===void 0)return"(not set)";if(e==="")return'""';if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return String(e);try{return JSON.stringify(e)}catch{return String(e)}}function yn(e){return e.language==="python"||e.language==="typescript"?e.language:"javascript"}function jo({enabled:e,values:s,onChange:i}){const[n,a]=l.useState(null),u=l.useRef(!1),d=typeof s.code=="string"?s.code:"";return l.useEffect(()=>{if(!e||u.current)return;u.current=!0;const f=o.convertCodeBindingsToReads(d,yn(s));f.converted!==0&&(a({original:d,converted:f.converted}),i({...s,code:f.code}))},[e,d,s,i]),n?{converted:n.converted,undo:()=>{i({...s,code:n.original}),a(null)}}:null}function vo({values:e,conversion:s,readOnly:i}){const n=typeof e.code=="string"?e.code:"",a=s,u=o.findCodeBindings(n,yn(e)).length;return!a&&u===0?null:t.jsxs("output",{className:"w6w-hint w6w-script-converted",children:[a&&t.jsxs(t.Fragment,{children:["Converted ",a.converted," reference",a.converted===1?"":"s"," to code reads",!i&&t.jsxs(t.Fragment,{children:[" · ",t.jsx("button",{type:"button",className:"w6w-script-converted-undo",onClick:a.undo,children:"Undo"})]}),u>0&&" · "]}),u>0&&t.jsxs(t.Fragment,{children:[u," ",t.jsx("code",{children:"{{ }}"})," left in the code stay",u===1?"s":""," literal text — read ",u===1?"it":"them"," from"," ",t.jsx("code",{children:"state"}),", or bind under Custom input"]})]})}function en(e,s){return{nodeIds:e.filter(i=>i.selected).map(i=>i.id),edgeIds:s.filter(i=>i.selected).map(i=>i.id)}}function So(e,s,i,n){const a=new Set(e.nodeIds),u=new Set(e.edgeIds),d=s.filter(g=>a.has(g.id)),f=[...d.filter(g=>o.isForeachStep(g.data.step)),...d.filter(g=>!o.isForeachStep(g.data.step))];let p=s,x=i,b=n;for(const g of f)x=o.bridgeDeletedBodyStep(g.id,p,x),p=p.filter(S=>S.id!==g.id),b=is(b,g.id);return{nodes:p,edges:x.filter(g=>!u.has(g.id)),canvas:b}}function Co(e,s,i){var f;const n=new Set(e.nodeIds),a=new Set(e.edgeIds),u=i.filter(p=>a.has(p.id)&&!n.has(p.source)&&!n.has(p.target)),d=[];if(n.size===1)d.push(o.deleteStepMessage(e.nodeIds[0],s,i));else if(n.size>1){d.push(`Delete nodes ${[...n].map(x=>`"${x}"`).join(", ")}? Their connections are removed too.`);const p=new Set;for(const x of n)if(o.isForeachStep((f=s.find(b=>b.id===x))==null?void 0:f.data.step))for(const b of o.loopBody(x,s,i))n.has(b)||p.add(b);p.size&&d.push(`Loop body steps ${[...p].map(x=>`"${x}"`).join(", ")} stay as standalone steps.`)}return u.length&&d.push(`Delete ${u.length===1?"connection":"connections"} ${u.map(p=>`"${p.source} → ${p.target}"`).join(", ")}?`),d.join(" ")}function Mt(e,s,i,n,a){const u=o.flowToWorkflow({...e,connections:n},s,i);return{nodes:u.nodes.map(({with:d,...f})=>d&&Object.keys(d).length?{...f,with:d}:f),edges:u.edges??[],connections:u.connections??{},canvas:a,positions:Object.fromEntries(s.map(d=>[d.id,d.position]))}}function No(e,s){const i=o.workflowToFlow({...e,...s});return{...i,nodes:i.nodes.map(n=>({...n,position:s.positions[n.id]??n.position}))}}class ko{constructor(s,i=100){ot(this,"past",[]);ot(this,"future",[]);ot(this,"present");ot(this,"group");ot(this,"limit");this.limit=i,this.present=JSON.stringify(s)}reset(s){this.present=JSON.stringify(s),this.past=[],this.future=[],this.group=void 0}record(s,i){const n=JSON.stringify(s);n!==this.present&&((!i||i!==this.group)&&(this.past.push(this.present),this.past.length>this.limit&&this.past.shift()),this.present=n,this.group=i,this.future=[])}mark(){return this.present}rollbackTo(s){if(this.present===s)return;const i=this.past.lastIndexOf(s);return i>=0&&(this.past.length=i),this.present=s,this.future=[],this.group=void 0,JSON.parse(s)}undo(){const s=this.past.pop();if(s!==void 0)return this.future.push(this.present),this.present=s,this.group=void 0,JSON.parse(s)}redo(){const s=this.future.pop();if(s!==void 0)return this.past.push(this.present),this.present=s,this.group=void 0,JSON.parse(s)}}function qt(e){var i;const s=e;return!!(s!=null&&s.isContentEditable||(i=s==null?void 0:s.closest)!=null&&i.call(s,'input, textarea, select, [contenteditable="true"], [contenteditable=""], [role="textbox"], .cm-editor'))}const Eo=64,ht=24,Ze=32;function Lt(e){var s,i;return{width:((s=e.measured)==null?void 0:s.width)??e.width??200,height:((i=e.measured)==null?void 0:i.height)??e.height??64}}function To(e,s){return e.x<s.x+s.width&&e.x+e.width>s.x&&e.y<s.y+s.height&&e.y+e.height>s.y}function Io(e){const s=(a,u)=>{const d=new Map;for(const x of e){const b=x.position[a];d.set(b,Math.max(d.get(b)??0,Lt(x)[u]))}const f=new Map;let p=Number.NEGATIVE_INFINITY;for(const[x,b]of[...d].sort(([g],[S])=>g-S)){const g=Math.max(x,p);f.set(x,g),p=g+b+Eo}return f},i=s("x","width"),n=s("y","height");return e.map(a=>({...a,position:{x:i.get(a.position.x)??a.position.x,y:n.get(a.position.y)??a.position.y}}))}function Ao(e,s,i){var f;const n=Io(o.relayoutNodes(e,s));if(!((f=i.sections)!=null&&f.length))return{nodes:n,canvas:i};const a=new Map(n.map(p=>[p.id,p])),u=(i.notes??[]).map(p=>({...p.position,...p.size}));for(const p of i.sections)p.nodes.some(x=>a.has(x))||u.push({...p.position,...p.size,y:p.position.y-Ze,height:p.size.height+Ze});const d=i.sections.map(p=>{const x=new Set(p.nodes),b=n.filter(A=>x.has(A.id));if(!b.length)return p;const g=Math.min(...b.map(A=>A.position.x))-ht,S=Math.min(...b.map(A=>A.position.y))-ht,v=Math.max(...b.map(A=>A.position.x+Lt(A).width)),R=Math.max(...b.map(A=>A.position.y+Lt(A).height)),E={x:g,y:S,width:v+ht-g,height:R+ht-S},D=[...u,...[...a.values()].filter(A=>!x.has(A.id)).map(A=>({...A.position,...Lt(A)}))].sort((A,O)=>A.y-O.y);for(const A of D){const O={...E,y:E.y-Ze,height:E.height+Ze};To(O,A)&&(E.y=A.y+A.height+ht+Ze)}const m=E.y-S;for(const A of b)a.set(A.id,{...A,position:{x:A.position.x,y:A.position.y+m}});return u.push({...E,y:E.y-Ze,height:E.height+Ze}),{...p,position:{x:E.x,y:E.y},size:{width:E.width,height:E.height}}});return{nodes:n.map(p=>a.get(p.id)??p),canvas:{...i,sections:d}}}const Gt=6;function Po(e){let s=2166136261;for(let i=0;i<e.length;i++)s^=e.charCodeAt(i),s=Math.imul(s,16777619);return s>>>0}function Ro(e){const s=new Map;let i=new Set;for(const n of[...new Set(e)].sort()){i.size===Gt&&(i=new Set);let a=Po(n)%Gt;for(;i.has(a);)a=(a+1)%Gt;i.add(a),s.set(n,a+1)}return s}function rs(e){return`var(--w6w-loop-${e})`}function jn(e,s){const i=[],n=new Set([e]);for(let a=s.get(e);a&&!n.has(a);a=s.get(a))n.add(a),i.unshift(a);return i}function Mo(e,s,i){return s.size===0?e:e.map(n=>{var d;if(((d=n.data)==null?void 0:d.when)!=="each")return n;const a=n.sourceHandle===o.EACH_SOURCE_HANDLE?n.source:i.get(n.source),u=a?s.get(a):void 0;return u===void 0?n:{...n,style:{...n.style,"--w6w-loop-color":rs(u)}}})}function Lo(e,s){const i=s.get(e);return i===void 0?void 0:{"--w6w-loop-color":rs(i)}}function Fo(e){const s=[];for(const i of e){const n=o.isForeachStep(i.data.step);(n||i.data.loopOf)&&s.push([i.id,n?1:0,i.data.loopOf])}return JSON.stringify(s)}function Do(e){const s=JSON.parse(e);return{tones:Ro(s.filter(i=>i[1]===1).map(i=>i[0])),loopOf:new Map(s.map(i=>[i[0],i[2]]))}}const tn="Paused — test runs stop before this node",sn="Disabled — skipped in every run";function Qe(e){var s;return((s=e.ui)==null?void 0:s.paused)===!0}function We(e){return e.disabled===!0}function vn(e,s){const{ui:i,...n}=e,{paused:a,...u}=i??{},d=s?{...u,paused:!0}:u;return Object.keys(d).length>0?{...n,ui:d}:n}function Sn(e,s){const{disabled:i,...n}=e;return s?{...n,disabled:!0}:n}function ss(e,s){return e.filter(i=>i.id!==s&&Qe(i)).map(i=>i.id)}const Oo=["nodes","steps"];function nn(e,s){for(const i of Oo){const n=`${i}.${s}.output`;if(!e.startsWith(n))continue;const a=e.slice(n.length);if(a===""||a[0]==="."||a[0]==="[")return`foreach.item${a}`}return null}function Ft(e,s,i){if(typeof e=="string"){if(!e.includes("{{"))return e;const n=o.parseRootAnchoredTemplate(e);let a=!1;const u=n.map(d=>{if(d.kind!=="var"||d.ref===void 0)return d;const f=nn(d.ref,s);return f===null?d:(a=!0,i.includes(d.ref)||i.push(d.ref),{...d,ref:f})});return a?Ie.serializeTemplate(u):e}if(o.isDollarPath(e)){const n=e.$;if(typeof n!="string")return e;const a=nn(n,s);return a===null?e:(i.includes(n)||i.push(n),{$:a})}if(Array.isArray(e)){let n=!1;const a=e.map(u=>{const d=Ft(u,s,i);return d!==u&&(n=!0),d});return n?a:e}if(typeof e=="object"&&e!==null){let n=!1;const a={};for(const[u,d]of Object.entries(e)){const f=Ft(d,s,i);f!==d&&(n=!0),a[u]=f}return n?a:e}return e}function _o(e){if(typeof e=="string"){if(!e.includes("{{"))return!1;const s=o.parseRootAnchoredTemplate(e);return s.length===1&&s[0].kind==="var"}return o.isDollarPath(e)&&typeof e.$=="string"}function Cn(e){return Array.isArray(e)&&e.length===1&&_o(e[0])}function Wo(e){var s;try{const i=o.normalizeInput(e);if(!Array.isArray(i.nodes))return{};const n={},a=(d,f)=>{const p=Object.hasOwn(n,d)?n[d]:[];p.push(f),n[d]=p},u=new Map(i.nodes.map(d=>[d.id,d]));for(const[d,f]of Object.entries(o.definitionLoops(i))){const p=u.get(d);if(p&&Cn((s=p.with)==null?void 0:s.items)&&a(d,{code:"foreach_wrapped_items",fix:{kind:"unwrap_items",label:"Unwrap Items"}}),"invalid"in f){a(d,{code:"loop_body_invalid",reason:{...f.invalid}});continue}for(const x of f.body){const b=u.get(x);if(!(b!=null&&b.with))continue;const g=[];Ft(b.with,d,g),g.length>0&&a(x,{code:"foreach_body_refs_output",foreachId:d,refs:g,fix:{kind:"use_current_item",foreachId:d,label:"Use Current item"}})}}return n}catch{return{}}}function $o(e){const s=new Set,i=n=>{if(typeof n=="string")s.add(n);else if(Array.isArray(n))for(const a of n)i(a)};return i(e),s}function Bo(e){var s,i;try{const n=o.normalizeInput(e);if(!Array.isArray(n.nodes))return[];const a=n.nodes.filter(P=>typeof P=="object"&&P!==null&&typeof P.id=="string"),u=o.effectiveEdges({...n,nodes:a}).filter(P=>typeof(P==null?void 0:P.from)=="string"&&typeof(P==null?void 0:P.to)=="string"),d=[];for(const P of a)try{const M=Ie.staticWritePaths(Ie.effectiveStateConfig((s=P.uses)==null?void 0:s.app,(i=P.uses)==null?void 0:i.action,P.state));M.length>0&&d.push({id:P.id,paths:M})}catch{}if(d.length<2)return[];const f=new Map;for(const P of a)for(const M of o.controlOwnedIds(P))f.has(M)||f.set(M,P.id);const p=P=>{const M=[P];let C=P;for(;f.has(C)&&(C=f.get(C),!M.includes(C));)M.push(C);return M},x=P=>{const M=p(P);return M[M.length-1]},b=new Map;for(const P of u){const M=b.get(P.from)??[];M.push(P.to),b.set(P.from,M)}const g=new Map,S=P=>{const M=g.get(P);if(M)return M;const C=new Set,$=[...b.get(P)??[]];for(;$.length>0;){const G=$.pop();if(!C.has(G)){C.add(G);for(const V of b.get(G)??[])$.push(V)}}return g.set(P,C),C},v=(P,M)=>P===M||S(P).has(M),R=a.filter(P=>{var M;return((M=P.uses)==null?void 0:M.app)===o.CONTROL_APP&&P.uses.action==="parallel"}).map(P=>{var C;const M=(C=P.with)==null?void 0:C.branches;return Array.isArray(M)?M.map($o):[]}),E=(P,M)=>{for(const C of p(M)){const $=P.findIndex(G=>G.has(C));if($>=0)return $}return-1},D=[];for(const P of a){if(P.fanOut!=="parallel")continue;const M=new Map;for(const C of u){if(C.from!==P.id||o.isEachLink(C))continue;const $=C.when??"success",G=M.get($)??[];G.push(C.to),M.set($,G)}for(const C of M.values())C.length>=2&&D.push(C)}const m=(P,M)=>{for(const G of R){const V=E(G,P),w=E(G,M);if(V>=0&&w>=0&&V!==w)return!0}const C=x(P),$=x(M);return C===$||S(C).has($)||S($).has(C)?!1:D.some(G=>G.some((V,w)=>G.some((_,le)=>w!==le&&v(V,C)&&v(_,$))))},A=new Set,O=[];for(let P=0;P<d.length;P++)for(let M=P+1;M<d.length;M++){const C=d[P],$=d[M];if(!(C.id===$.id||!m(C.id,$.id)))for(const G of C.paths)for(const V of $.paths){if(!Ie.statePathsOverlap(G,V))continue;const w={code:"state_parallel_write",nodes:[C.id,$.id].sort(),path:[...G.length<=V.length?G:V]},_=JSON.stringify([w.nodes,w.path]);A.has(_)||(A.add(_),O.push(w))}}const U=(P,M)=>P<M?-1:P>M?1:0;return O.sort((P,M)=>U(P.code,M.code)||U(P.nodes.join(","),M.nodes.join(","))||U(P.path.join("."),M.path.join(".")))}catch{return[]}}function Vo(e){try{const s={};for(const i of Bo(e))for(const n of i.nodes){const a=Object.hasOwn(s,n)?s[n]:[];a.push({code:i.code,path:[...i.path],with:i.nodes.filter(u=>u!==n)}),s[n]=a}return s}catch{return{}}}function Nn(e,s){var i;if(s.code==="foreach_wrapped_items"){const n=(i=e.with)==null?void 0:i.items;return!e.with||!Cn(n)?e:{...e,with:{...e.with,items:n[0]}}}if(s.code==="foreach_body_refs_output"){if(!e.with)return e;const n=Ft(e.with,s.foreachId,[]);return n===e.with?e:{...e,with:n}}return e}function on(e,s,i){return e&&e.nodeId===s&&e.handleType===((i==null?void 0:i.type)??"source")?o.laneForSourceHandle(e.handleId):o.laneForSourceHandle(i==null?void 0:i.id)}function zo(e,s,i,n,a){var x;const u=(x=n.find(b=>b.id===e))==null?void 0:x.data.step,d=o.loopMembership(n,a)[e]!==void 0,f=i==="success"&&d?"each":i;if(f==="each"&&!d&&!o.isForeachStep(u))return null;const p=i==="success"&&o.isForeachStep(u)?o.FOREACH_DONE_ROUTE:void 0;return o.loopRefusal(e,s,f,n,a,p)}function Dt(e,s){var i;return(i=e.nodes??e.steps)==null?void 0:i[s]}function ns(e,s){const i=Dt(e,s);return(i==null?void 0:i.status)==="skipped"&&i.skipReason==="not_on_path"}const Ho=new Set(["succeeded","failed","canceled"]);function Jo(e,s,i=[]){var u,d;if(!e||[...i,s].some(f=>ns(e,f)))return"no-run";const n=Dt(e,s);if(n)return n.status;const a=new Set;for(const f of Object.values(e.nodes??e.steps??{}))if(Array.isArray(f==null?void 0:f.iterations))for(const p of f.iterations){const x=(d=(u=p==null?void 0:p.nodes)==null?void 0:u[s])==null?void 0:d.status;x&&a.add(x)}for(const f of["failed","running","succeeded","skipped"])if(a.has(f))return f;return"pending"}const rn={borderColor:"var(--w6w-border)",borderStyle:"solid",borderWidth:1,opacity:1};function kn(e,s){const i=s!==void 0&&Ho.has(s);switch(e){case"no-run":return rn;case"pending":return i?{borderColor:"var(--w6w-muted)",borderStyle:"dashed",borderWidth:1,opacity:.5}:{borderColor:"var(--w6w-border)",borderStyle:"dashed",borderWidth:1,opacity:1};case"running":return{borderColor:"var(--w6w-accent)",borderStyle:"solid",borderWidth:2,opacity:1};case"succeeded":return{borderColor:"var(--w6w-success)",borderStyle:"solid",borderWidth:2,opacity:1};case"failed":return{borderColor:"var(--w6w-danger)",borderStyle:"solid",borderWidth:2,opacity:1};case"skipped":return{borderColor:"var(--w6w-muted)",borderStyle:"dashed",borderWidth:1,opacity:.7};default:return rn}}function Uo(e,s,i,n,a){var d;if(!e||ns(e,s)||a!==void 0&&ns(e,a))return;const u=qo(e,s,i,n);return u==="taken"&&a!==void 0&&((d=Dt(e,a))==null?void 0:d.status)==="skipped"?"skipped":u}function qo(e,s,i,n){const a=Dt(e,s);if(!a)return;if(i==="each")return a.status==="skipped"?"skipped":void 0;const u=i??"success",d=a.output,f=n===o.FOREACH_DONE_ROUTE&&!(d&&typeof d=="object"&&"route"in d);if(n!==void 0&&!f&&a.status==="succeeded")return d&&typeof d=="object"&&"matched"in d?n==="false"!=(d.matched===!0)?"taken":"skipped":d&&typeof d=="object"&&"route"in d&&d.route===n?"taken":"skipped";if(a.status==="succeeded")return u==="success"?"taken":"skipped";if(a.status==="failed")return u==="error"?"taken":"skipped";if(a.status==="skipped")return"skipped"}const an={fields:[],sampleValues:{}};function as(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Go(e,s){var x;const i=e.map(b=>b.id),n=new Set(i),a=new Map(i.map(b=>[b,0])),u=new Map(i.map(b=>[b,[]]));for(const b of s)!n.has(b.source)||!n.has(b.target)||((x=u.get(b.source))==null||x.push(b.target),a.set(b.target,(a.get(b.target)??0)+1));const d=[],f=i.filter(b=>a.get(b)===0);for(;f.length>0;){const b=f.shift();d.push(b);for(const g of u.get(b)??[]){const S=(a.get(g)??0)-1;a.set(g,S),S===0&&f.push(g)}}const p=new Set(d);for(const b of i)p.has(b)||d.push(b);return d}const Ko=new Set(["string","number","boolean","object","array"]);function mt(e){if(!Array.isArray(e))return;const s={type:"object",fields:{}};let i=!1;for(const n of e){if(!as(n)||typeof n.key!="string"||n.key==="")continue;const a=n.key.split(".");let u=s;for(const p of a.slice(0,-1)){const x=u.fields[p];(x==null?void 0:x.type)!=="object"&&(u.fields[p]={type:"object",fields:{}}),u=u.fields[p]}const d=typeof n.type=="string"&&Ko.has(n.type)?n.type:"string";let f;if(d==="array"){const p=mt(n.items);f=p?{type:"array",items:p}:{type:"array"}}else d==="object"?f=mt(n.fields??n.properties)??{type:"object",fields:{}}:f={type:d};u.fields[a[a.length-1]]=f,i=!0}return i?s:void 0}function Xo(e,s){var x,b,g,S,v,R,E;const i=e.data.step,n=((x=s.testOutputs)==null?void 0:x[i.id])??((b=s.persistedOutputs)==null?void 0:b[i.id]);if(n!=null)return n;const{app:a,action:u}=i.uses;if(a===o.TRIGGER_APP&&((g=o.internalNodeDef(a,u))==null?void 0:g.group)==="trigger"){const D=o.fieldsToParams(o.asFieldDefs((S=i.with)==null?void 0:S.fields)).map(m=>({key:m.key}));return o.shapeToSkeleton(mt(D))}const d=(v=o.internalNodeDef(a,u))==null?void 0:v.output;if(d&&d.length>0)return o.shapeToSkeleton(mt(d));const f=i.uses.trigger===!0?(R=s.triggerDef)==null?void 0:R.call(s,a,u):(E=s.actionDef)==null?void 0:E.call(s,a,u),p=mt(f==null?void 0:f.output);return p?o.shapeToSkeleton(p):f==null?void 0:f.sample}function Yo(e,s){var f,p,x,b,g;const i=e.data.step,n=(f=s.previewOutputs)==null?void 0:f[i.id];if(n!=null)return n;const{app:a,action:u}=i.uses,d=i.uses.trigger===!0?(x=(p=s.shapes)==null?void 0:p.triggerDef)==null?void 0:x.call(p,a,u):(g=(b=s.shapes)==null?void 0:b.actionDef)==null?void 0:g.call(b,a,u);return d==null?void 0:d.sample}function Zo(e){switch(e){case"number":case"integer":return 0;case"boolean":return!1;case"object":return{};case"array":return[];default:return""}}function cn(e,s){const i=as(e.initialState)?{...e.initialState}:{};for(const n of e.variables??[])!n||typeof n.key!="string"||n.key===""||(n.default!==void 0?i[n.key]=n.default:s||(i[n.key]=Zo(n.type)));return i}function Kt(e){return(o.inferOutputFields(e)??[]).map(s=>s.key)}function Qo(e){const{anchorId:s,nodes:i,edges:n}=e;if(!s)return an;const a=e.shapes??{},u=e.floating?new Set(i.map(C=>C.id)):o.ancestorIds(s,n);u.delete(s);const d=new Map(i.map(C=>[C.id,C])),f=[],p=[],x=new Map;for(const C of Go(i,n)){if(!u.has(C))continue;const $=d.get(C);if(!$)continue;const{app:G,action:V}=$.data.step.uses,w=Ie.effectiveStateConfig(G,V,$.data.step.state);if(w.mode==="off")continue;const _=Xo($,a);if(_!==void 0){const{ops:de}=Ie.computeStateWrites(w,_);f.push(...de);for(const je of Kt(Ie.foldState({},de))){const ie=x.get(je)??new Set;ie.add(C),x.set(je,ie)}}const le=Yo($,e);le!==void 0&&p.push(...Ie.computeStateWrites(w,le).ops)}const b=cn(e,!1),g=Ie.foldState(b,f),S=Kt(g);if(S.length===0)return an;const v=new Set(Kt(b)),R=new Map,E=new Map;for(const C of n)u.has(C.source)&&(!u.has(C.target)&&C.target!==s||(R.set(C.target,[...R.get(C.target)??[],C.source]),E.set(C.source,[...E.get(C.source)??[],C.target])));const D=[...u].filter(C=>!(R.get(C)??[]).length),m=C=>{const $=new Set,G=D.filter(V=>!C.has(V));for(;G.length>0;){const V=G.pop();if(V===s)return!1;if(!$.has(V)){$.add(V);for(const w of E.get(V)??[])C.has(w)||G.push(w)}}return!0},A=Ie.foldState(cn(e,!0),p),O=p.length>0?Ie.foldState({},p):void 0,U=as(O)&&Object.keys(O).length>0?O:void 0,P=[],M={};for(const C of S){const $=x.get(C)??new Set,G=v.has(C)||$.size>0&&m($);P.push({key:C,path:!0,paths:G?"all":"some"});const V=o.valueAtPath(A,C);V!==void 0&&(M[`state.${C}`]=V)}return{fields:P,sampleValues:M,...U?{written:U}:{}}}const ei={registered:{label:"Registered",tone:"ok"},pending:{label:"Registering",tone:"pending"},failed:{label:"Registration failed",tone:"danger"},paused:{label:"Paused",tone:"muted"},destroying:{label:"Removing",tone:"muted"}},ln="Never fired";function ti(e){if(!e)return ln;const s=new Date(e);return Number.isNaN(s.getTime())?ln:`Last fired ${s.toISOString().slice(0,16).replace("T"," ")} UTC`}function si(e,s){var a;if(!(e!=null&&e.status))return null;const i=ei[e.status];if(!i)return null;const n=e.status==="failed";return{label:i.label,tone:i.tone,error:n?((a=e.lastError)==null?void 0:a.message)??null:null,lastFire:ti(e.lastFireAt),retryVisible:n&&s}}function ni(e){const s=new Map;for(const i of e)i.nodeId&&s.set(i.nodeId,i);return s}function oi(e){return(e??[]).filter(s=>{var i;return((i=s.uses)==null?void 0:i.trigger)===!0})}function ii(e,s){const[i,n]=l.useState({}),a=l.useRef(new Set),u=JSON.stringify([...new Set(s.map(d=>d.data.step.uses.app))].filter(d=>d&&!o.isInternalApp(d)).sort());return l.useEffect(()=>{const d=JSON.parse(u).filter(f=>!a.current.has(f));if(d.length!==0){for(const f of d)a.current.add(f);Promise.all(d.map(async f=>{try{return[f,await e.getAppActions(f)]}catch{return a.current.delete(f),null}})).then(f=>{const p=f.filter(x=>x!==null);p.length!==0&&n(x=>({...x,...Object.fromEntries(p)}))})}},[e,u]),i}function ri(e,s){const[i,n]=l.useState({}),a=l.useRef(new Set),u=JSON.stringify([...new Set(s.filter(d=>d.data.step.uses.trigger===!0).map(d=>d.data.step.uses.app))].filter(d=>d&&!o.isInternalApp(d)).sort());return l.useEffect(()=>{const d=e.getAppTriggers;if(typeof d!="function")return;const f=JSON.parse(u).filter(p=>!a.current.has(p));if(f.length!==0){for(const p of f)a.current.add(p);Promise.all(f.map(async p=>{try{return[p,await d.call(e,p)]}catch{return a.current.delete(p),null}})).then(p=>{const x=p.filter(b=>b!==null);x.length!==0&&n(b=>({...b,...Object.fromEntries(x)}))})}},[e,u]),i}function ai(e){return(s,i)=>{var n,a;return(a=(n=e[s])==null?void 0:n.find(u=>u.key===i))==null?void 0:a.ports}}const ci="Which outcome of the source node this edge carries. An error edge is drawn by dragging from the node's error exit port; use this control to re-lane an edge already drawn. An error edge overrides the node’s “On error” policy.";function dn(e,s,i,n){const a=e.find(u=>u.id===s);return[i,n,a==null?void 0:a.source,a==null?void 0:a.target]}const cs=l.createContext(void 0),ls=l.createContext(new Map),ds=l.createContext({tones:new Map,loopOf:new Map});function un(e){return`Can’t draw that edge: this node allows at most ${e} outgoing edge${e===1?"":"s"} per lane.`}const us=l.createContext(new Map),En=l.createContext({byNode:new Map,subs:[]});function li({apps:e,registration:s,children:i}){return t.jsx(us.Provider,{value:e,children:t.jsx(En.Provider,{value:s,children:i})})}const ps=l.createContext(null);function di(e){return t.jsx(oe.ReactFlowProvider,{children:t.jsx(ui,{...e})})}function pn(e,s){let i=s.length+1;for(;s.includes(`${e}-${i}`);)i++;return`${e}-${i}`}function Xt(e){var s,i;return{x:e.position.x,y:e.position.y,w:((s=e.measured)==null?void 0:s.width)??e.width??200,h:((i=e.measured)==null?void 0:i.height)??e.height??64}}function ui({onConnectionResourcesChange:e,value:s,onChange:i,readOnly:n,height:a=480,apps:u,exprOptions:d,project:f,runState:p,stepProblems:x,onTestRun:b,fitViewKey:g,onRunFromNode:S}){var zs,Hs,Js,Us,qs,Gs,Ks;const v=o.useW6WApi(),R=l.useMemo(()=>new Map((u??[]).map(r=>[r.id,r])),[u]),E=xi(s),[D,m]=l.useState(null),A=l.useMemo(()=>o.centralizeConnections(s),[s.id]),O=l.useMemo(()=>o.workflowToFlow(A),[A]),[U,P]=l.useState(A.connections??{}),M=l.useRef(U),C=l.useCallback(r=>{M.current=r,P(r)},[]),$=l.useCallback(r=>{const c=o.centralizeConnections({nodes:[r],connections:M.current});return c.connections!==M.current&&C(c.connections),c.nodes[0]},[C]),G=l.useMemo(()=>o.storedViewport(s),[s.id]),V=((zs=s.settings)==null?void 0:zs.savePosition)!==!1,[w,_,le]=oe.useNodesState(O.nodes),de=ii(v,w),je=ri(v,w),ie=l.useMemo(()=>ai(de),[de]),[N,K,T]=oe.useEdgesState(O.edges),[W,B]=l.useState(null),te=l.useMemo(()=>s.canvas??{},[s.id]),[H,z]=l.useState(te),[J]=l.useState(()=>new ko(Mt(A,O.nodes,O.edges,U,te))),Q=l.useRef(),[ue,it]=l.useState(0),[De,rt]=l.useState(!1),[ve,Ue]=l.useState(null),[Ae,me]=l.useState(null),[ae,Ne]=l.useState(null),[$e,se]=l.useState(!1),gt=l.useRef({});l.useEffect(()=>{$e||(gt.current={})},[$e]);const[re,Pe]=l.useState(null),[Oe,ke]=l.useState("props"),[ge,qe]=l.useState(null),[ye,Be]=l.useState(null),[Re,Me]=l.useState(null),at=l.useRef(!1),Se=l.useRef(null),[xe,_e]=l.useState(null),{screenToFlowPosition:Le,fitView:Fe}=oe.useReactFlow(),ct=o.useEffectiveTheme();l.useEffect(()=>{_(O.nodes),K(O.edges),B(null),Ne(null),Me(null),Pe(null),qe(null),z(te),C(A.connections??{}),J.reset(Mt(A,O.nodes,O.edges,A.connections??{},te)),Q.current=void 0},[O,te,A,_,K,C,J]),l.useEffect(()=>{_(r=>{const c=new Map(o.stampLoopOf(r,N).map(h=>[h.id,h.data.loopOf]));return r.map(h=>{const y=Jo(p,h.id,jn(h.id,c));return h.data.stepStatus===y&&h.data.runStatus===(p==null?void 0:p.status)?h:{...h,data:{...h.data,stepStatus:y,runStatus:p==null?void 0:p.status}}})}),K(r=>r.map(c=>{var I;const h=o.edgeLane(c),y=Uo(p,c.source,h,typeof((I=c.data)==null?void 0:I.route)=="string"?c.data.route:void 0,c.target),j=o.edgeVisuals(h,y);return c.className===j.className&&c.label===j.label?c:{...c,className:j.className,label:j.label}}))},[p,O,ue,_,K]),l.useEffect(()=>{_(r=>o.applyStepProblems(r,x))},[x,O,ue,_]);const et=l.useCallback((r,c)=>{var j,I;const{canvas:h,...y}=r;return!((j=c.notes)!=null&&j.length)&&!((I=c.sections)!=null&&I.length)?y:{...y,canvas:ho(c,s.canvas,V)}},[s.canvas,V]),Y=l.useCallback((r,c,h)=>{J.record(Mt(s,r,c,M.current,h??H),$e?gt.current:Q.current),i(et(o.flowToWorkflow({...s,connections:M.current},r,c),h??H))},[s,i,H,et,J,$e]),tt=l.useRef(()=>{});tt.current=r=>{if(n)return;const c=o.editConnectionResources(w.map(y=>y.data.step),M.current,r),h=w.map((y,j)=>({...y,data:{...y.data,step:c.nodes[j]}}));C(c.connections),_(h),Y(h,N)};const Ge=l.useCallback(r=>tt.current(r),[]),wt=l.useCallback(r=>{B(r),Ne(null),_(c=>c.map(h=>({...h,selected:h.id===r}))),K(c=>c.map(h=>({...h,selected:!1}))),Fe({nodes:[{id:r}],duration:300,maxZoom:1})},[_,K,Fe]),[lt,fe]=l.useState(null),xt=l.useMemo(()=>lt?w.map(r=>r.id===lt?{...r,className:`${r.className??""} w6w-connection-highlight`.trim()}:r):w,[w,lt]),bt=w.map(r=>({id:r.data.step.id,uses:r.data.step.uses})),yt=JSON.stringify(bt),jt=JSON.stringify([...R]);l.useEffect(()=>{e==null||e({workflowId:s.id,nodes:bt,apps:R,connections:U,readOnly:n,edit:Ge,focusNode:wt,highlightNode:fe})},[e,s.id,yt,jt,U,n,Ge,wt]),l.useEffect(()=>()=>e==null?void 0:e(null),[e]);const k=l.useCallback(r=>o.canConnect(r.source,r.target,w,N,ie,o.routeFromHandle(r.sourceHandle)),[w,N,ie]),[Z,X]=l.useState(null),we=l.useRef(null),Je=l.useRef(null);l.useEffect(()=>{_(r=>o.stampLoopOf(r,N))},[N,_]);const _n=l.useCallback(r=>{if(n)return;const c=o.applyConnect(r.source,r.target,w,N,o.laneForSourceHandle(r.sourceHandle),ie,o.routeFromHandle(r.sourceHandle));if(!c){const h=o.laneForSourceHandle(r.sourceHandle),y=o.connectRefusal(r.source,r.target,w,N,h,ie,o.routeFromHandle(r.sourceHandle));if(y&&y.refused==="loop"){X({nodeId:r.source,reason:y.reason});return}if(y){const I=N.find(F=>F.source===r.source&&o.edgeLane(F)===h);I&&(K(N.map(F=>({...F,selected:F.id===I.id}))),Ne(I.id),Ke({edgeId:I.id,message:un(y.cap)}));return}const j=o.connectConflict(r.source,r.target,w,N,o.laneForSourceHandle(r.sourceHandle));if(!j)return;K(N.map(I=>({...I,selected:I.id===j}))),Ne(j),Ke({edgeId:j,message:o.idClashMessage("Can’t draw that edge",j,dn(N,j,r.source,r.target))});return}Ke(null),X(null),K(c),Y(w,c)},[N,w,K,Y,n,ie]),Wn=l.useCallback((r,c)=>{var q,ee,ce;if(n||c.isValid)return;const h=c.fromNode;if(!h)return;const y=((q=c.fromHandle)==null?void 0:q.type)==="target"?"target":"source",j=c.toNode;if(j&&y==="source"){const ne=zo(h.id,j.id,on(Je.current,h.id,c.fromHandle),w,N);if(ne){X({nodeId:h.id,reason:ne});return}}const I=(ee=w.find(ne=>ne.id===h.id))==null?void 0:ee.data.step;if(I){const ne=o.nodePortsForStep(I,ie);if((y==="source"?ne.out:ne.in)<1)return}const F="changedTouches"in r?r.changedTouches[0]:r,L=Le({x:F.clientX,y:F.clientY});_e({nodeId:h.id,handleType:y,position:L,lane:on(Je.current,h.id,c.fromHandle),route:o.routeFromHandle((ce=c.fromHandle)==null?void 0:ce.id)}),se(!0)},[n,Le,w,N,ie]),hs=l.useCallback((r,c,h)=>{if(n)return;const y=w.find(q=>q.id===r);if(!y)return;const j=Xt(y),I=o.laneForSourceHandle(h),F=120,L=c==="target"?{x:j.x-j.w-F,y:j.y}:I==="error"?{x:j.x,y:j.y+j.h+F}:I==="each"?{x:j.x+j.w+F,y:j.y-j.h-F/2}:{x:j.x+j.w+F,y:j.y};_e({nodeId:r,handleType:c,position:L,lane:I,route:o.routeFromHandle(h)}),se(!0)},[n,w]),ms=l.useCallback(r=>{n||Me({nodeIds:[r],edgeIds:[]})},[n]),$n=l.useCallback(r=>{if(n)return;const c=So(r,w,N,H);_(c.nodes),K(c.edges),z(c.canvas),c.nodes.some(h=>h.id===W)||B(null),c.nodes.some(h=>h.id===re)||Pe(null),c.edges.some(h=>h.id===ae)||Ne(null),Y(c.nodes,c.edges,c.canvas)},[w,N,H,_,K,Y,n,W,re,ae]),gs=l.useCallback(()=>{if(n)return;const r=Ao(w,N,H);_(r.nodes),z(r.canvas),at.current=!0,Y(r.nodes,N,r.canvas)},[w,N,H,_,Y,n]),Bn=l.useCallback(()=>{n||gs()},[n,gs]);l.useEffect(()=>{at.current&&(at.current=!1,Fe({duration:300}))},[w,Fe]);const ws=l.useRef(g);l.useEffect(()=>{Object.is(ws.current,g)||(ws.current=g,Fe({duration:300}))},[g,Fe]);const[vt,Ke]=l.useState(null),st=l.useMemo(()=>N.find(r=>r.id===ae)??null,[N,ae]),Vn=l.useCallback(r=>{if(n||!ae)return;const c=N.find(F=>F.id===ae);if(!c||o.edgeLane(c)===r)return;const h=o.edgeWhenConflict(N,ae,r,w),y=o.relaneRefusal(N,ae,r,w,ie),j=h||y?null:o.setEdgeWhen(N,ae,r,w,ie);if(!j){if(y){Ke({edgeId:ae,message:un(y.cap)});return}Ke({edgeId:ae,message:h?o.idClashMessage("Can’t switch this edge",h,dn(N,h,c.source,c.target)):"This edge can’t be switched right now."});return}Ke(null),K(j);const I=j.find(F=>F.source===c.source&&F.target===c.target&&o.edgeLane(F)===r);Ne((I==null?void 0:I.id)??null),Y(w,j)},[N,w,K,Y,n,ae,ie]),zn=l.useCallback(r=>{if(n)return;const c=N.filter(h=>h.id!==r);c.length!==N.length&&(K(c),ae===r&&Ne(null),Y(w,c))},[w,N,K,Y,n,ae]),_t=l.useCallback(r=>{if(n)return;const c=r.map(I=>w.find(F=>F.id===I)).filter(I=>I!==void 0);if(c.length===0)return;const h=w.map(I=>I.id),y=c.map(I=>{const F=o.suggestStepId(h,`${I.data.step.id}_copy`);h.push(F);const L={...o.stripBody(structuredClone(I.data.step)),id:F};return{id:F,type:I.type,position:{x:I.position.x+40,y:I.position.y+60},data:{step:L,isInternal:I.data.isInternal},...c.length>1?{selected:!0}:{}}}),j=[...c.length>1?w.map(I=>I.selected?{...I,selected:!1}:I):w,...y];_(j),B(y[0].id),Y(j,N)},[w,N,_,Y,n]),xs=l.useCallback(r=>_t([r]),[_t]),Hn=l.useCallback(r=>{if(n)return;const c=o.isInternalApp(r.uses.app),h=w.map(ne=>ne.id),y=r.id&&!o.stepNameError(r.id,h)?r.id:o.suggestStepId(h,o.slugifyLabel(o.internalNodeLabel(r.uses.app,r.uses.action))),j=$({id:y,uses:r.uses,...r.with&&Object.keys(r.with).length>0?{with:r.with}:{}}),I={id:y,type:c?"control":"step",position:(xe==null?void 0:xe.position)??(ye==null?void 0:ye.position)??{x:80,y:80+w.length*24},data:{step:j,isInternal:c}},F=ye!=null&&ye.replaces?w.find(ne=>ne.id===ye.replaces):void 0;if(F&&o.isTriggerStep(r.uses)){const ne={...I,position:F.position},pe=[...w.filter(pt=>pt.id!==F.id),ne],he=o.renameStepInEdges(N,F.id,y),Te=Zt(H,F.id,y);return _(pe),K(he),z(Te),X(null),B(y),Y(pe,he,Te),y}const L=[...w,I];let q=N,ee=null;const ce=(ne,pe,he,Te)=>{const pt=o.connectRefusal(ne,pe,L,N,he,ie);pt&&pt.refused==="loop"&&(ee={nodeId:Te,reason:pt.reason})};if(xe){const[ne,pe]=xe.handleType==="target"?[y,xe.nodeId]:[xe.nodeId,y],he=o.applyConnect(ne,pe,L,N,xe.lane,ie,xe.route);he||ce(ne,pe,xe.lane,xe.nodeId),q=he??N}else{const ne=w.find(pe=>o.isTriggerStep(pe.data.step.uses));if(o.isTriggerStep(r.uses)){if(!ne){const pe=o.findChainRoot(w,N);if(pe){const he=o.applyConnect(y,pe.id,L,N,"success",ie);he||ce(y,pe.id,"success",pe.id),q=he??N}}}else{const he=(ne&&!N.some(Te=>Te.source===ne.id)?ne:void 0)??o.findChainTail(w,N);if(he){const Te=o.applyConnect(he.id,y,L,N,"success",ie);Te||ce(he.id,y,"success",he.id),q=Te??N}}}return _(L),q!==N&&K(q),X(ee),B(y),Y(L,q),y},[w,N,_,K,Y,n,xe,ye,ie,$,H]),bs=l.useCallback((r,c)=>{var q;let h=c;const y=(q=w.find(ee=>ee.id===r))==null?void 0:q.data.step;if(c.uses.connection&&!c.uses.connectionRef&&(y!=null&&y.uses.connectionRef)&&y.uses.app===c.uses.app){const ee=o.selectNodeConnection(o.withConnectionRef(c,y.uses.connectionRef),c.uses.connection,w.map(ce=>ce.data.step),M.current);C(ee.connections),h=ee.step}else h=$(c);const j=h.id!==r;if(j&&w.some(ee=>ee.id===h.id))return;const I=w.map(ee=>ee.id===r?{...ee,id:h.id,data:{step:h,isInternal:o.isInternalApp(h.uses.app)}}:ee);if(j){const ee=o.renameStepInEdges(N,r,h.id),ce=Zt(H,r,h.id);_(I),K(ee),z(ce),W===r&&B(h.id),re===r&&Pe(h.id),Y(I,ee,ce);return}_(I);const F=new Set(o.routesForStep(h).map(ee=>ee.id)),L=N.filter(ee=>{var ce;return ee.source!==h.id||((ce=ee.data)==null?void 0:ce.route)===void 0||F.has(String(ee.data.route))});L.length!==N.length&&K(L),Y(I,L)},[w,N,H,_,K,W,re,Y,$,C]),Xe=l.useCallback(r=>{n||(z(r),Y(w,N,r))},[n,w,N,Y]),Jn=l.useCallback(()=>{var j;if(n)return;const r=(j=Se.current)==null?void 0:j.getBoundingClientRect(),c=r?Le({x:r.left+r.width/2,y:r.top+r.height/2}):{x:0,y:0},h=H.notes??[],y={id:pn("note",h.map(I=>I.id)),color:"#facc15",position:{x:Math.round(c.x-100),y:Math.round(c.y-60)},size:{width:200,height:120},content:""};Xe(es({...H,notes:[...h,y]}))},[n,H,Le,Xe]),Un=l.useCallback((r,c)=>{if(n)return;const h=c?Math.min(r.x,c.x):r.x,y=c?Math.min(r.y,c.y):r.y,j=c?Math.abs(c.x-r.x):360,I=c?Math.abs(c.y-r.y):240,F=w.filter(ne=>{const pe=Xt(ne),he=pe.x+pe.w/2,Te=pe.y+pe.h/2;return he>=h&&he<=h+j&&Te>=y&&Te<=y+I}).map(ne=>ne.id),L=H.sections??[],q=pn("section",L.map(ne=>ne.id)),ee={id:q,title:"Section",color:"#6366f1",position:{x:Math.round(h),y:Math.round(y)},size:{width:Math.round(j),height:Math.round(I)},nodes:[]},ce={...H,sections:[...L,ee]};Xe(es(Qt(ce,q,F)))},[n,w,H,Xe]);l.useEffect(()=>{if(!De)return;const r=c=>{c.key==="Escape"&&(rt(!1),Ue(null))};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[De]);const qn=l.useCallback((r,c)=>{var F;if(n)return;const h=(F=H.sections)==null?void 0:F.find(L=>L.id===r);if(!h)return;const y=new Set(h.nodes),j=w.map(L=>y.has(L.id)?{...L,position:{x:L.position.x+c.dx,y:L.position.y+c.dy}}:L),I={...H,sections:(H.sections??[]).map(L=>L.id===r?{...L,position:{x:L.position.x+c.dx,y:L.position.y+c.dy}}:L)};_(j),z(I),Y(j,N,I)},[n,H,w,N,_,Y]),Gn=l.useCallback((r,c)=>{if(n)return;const h=r==="note"?{...H,notes:(H.notes??[]).filter(y=>y.id!==c)}:{...H,sections:(H.sections??[]).filter(y=>y.id!==c)};Xe(h)},[n,H,Xe]),Kn=r=>{let c=H;for(const h of r){const y=Xt(h),j=y.x+y.w/2,I=y.y+y.h/2,F=(c.sections??[]).find(q=>j>=q.position.x&&j<=q.position.x+q.size.width&&I>=q.position.y&&I<=q.position.y+q.size.height),L=xn(c,h.id);F?(L.length!==1||L[0]!==F.id)&&(c=Qt(c,F.id,[h.id])):L.length>0&&(c=is(c,h.id))}return c},Wt=l.useCallback((r,c,h)=>{(async()=>{const y=await v.saveStepTest(s.id,r,c).catch(j=>(console.error("step run fixture save failed",j),null));await v.recordStepTestRun(s.id,r,{stepTestId:(y==null?void 0:y.id)??null,status:h.status,input:c.input,output:h.output,error:h.error,...h.meta?{meta:h.meta}:{}})})().catch(y=>{console.error("step run persist failed",y)})},[v,s.id]),ys=l.useCallback(r=>{const c=w.find(h=>h.id===r);!c||!S&&o.isControlApp(c.data.step.uses.app)||m({stepId:r,status:"collect"})},[w,S]),Xn=l.useCallback(async(r,c,h)=>{if(!S)return;const y=w.find(F=>F.id===r);if(!y)return;const j=o.isTriggerStep(y.data.step.uses),I={stopAt:ss(w.map(F=>F.data.step),r),...h?{state:h}:{},...j?{input:c}:{}};m({stepId:r,status:"running"});try{await S(r,I),m(null)}catch(F){const L=F;m({stepId:r,status:"error",error:L.message??String(F),errorCode:L.code})}},[w,S]),St=l.useCallback((r,c)=>{if(n)return;const h=w.map(y=>y.id===r?{...y,data:{...y.data,step:c(y.data.step)}}:y);_(h),Y(h,N)},[w,N,_,Y,n]),js=l.useCallback(r=>St(r,c=>vn(c,!Qe(c))),[St]),vs=l.useCallback(r=>St(r,c=>Sn(c,!We(c))),[St]),Yn=l.useCallback(async(r,c,h)=>{b==null||b();const y=w.find(q=>q.id===r);if(!y)return;const j=y.data.step,I=o.isTriggerStep(j.uses),F=I?{input:c}:{...j.with??{},...c},L=I?{input:c,with:c}:{input:c,with:F};m({stepId:r,status:"running"});try{const q=await v.invokeAction(j.uses.app,j.uses.action,F,{connectionId:o.connectionIdFor(j,M.current),project:f,...h?{state:h}:{},workflowId:s.id}),ee=q.logs,ce=q.meta;m({stepId:r,status:"done",value:q.value,logs:ee,...ce?{meta:ce}:{}}),Wt(r,L,{status:"succeeded",output:q.value,...ce?{meta:ce}:{}})}catch(q){const ee=q;m({stepId:r,status:"error",error:ee.message??String(q),errorCode:ee.code}),Wt(r,L,{status:"failed",error:ee.message??String(q)})}},[w,v,Wt,f,b,s.id]),$t=l.useMemo(()=>({onEdit:r=>{ke("props"),Pe(r)},onEditJson:r=>{ke("json"),Pe(r)},onRun:ys,onDuplicate:xs,onDelete:ms,onTogglePause:js,onToggleDisable:vs,runsFromNode:!!S,onAddFromPort:hs,readOnly:n}),[ys,xs,ms,js,vs,S,hs,n]);l.useEffect(()=>{const r=Se.current;if(!r)return;const c=h=>{const y=h.target.closest(".react-flow__node");if(!y)return;const j=y.getAttribute("data-id");j&&(h.stopPropagation(),$t.onEdit(j))};return r.addEventListener("dblclick",c,!0),()=>r.removeEventListener("dblclick",c,!0)},[$t]);const nt=w.find(r=>r.id===re),Ct=(nt==null?void 0:nt.data.step)??null,Bt=D?((Hs=w.find(r=>r.id===D.stepId))==null?void 0:Hs.data.step)??null:null,Vt=(D==null?void 0:D.status)==="collect"&&!!Bt,Ss=l.useMemo(()=>{const r=new Map;for(const c of w)r.set(c.id,o.fanOutState(c.id,N).count);return r},[w,N]),Cs=Fo(w),Nt=l.useMemo(()=>Do(Cs),[Cs]),Zn=l.useMemo(()=>Mo(N,Nt.tones,Nt.loopOf),[N,Nt]),Qn=l.useMemo(()=>({step:yi,control:ji}),[]),[kt,Ns]=l.useState({}),[Et,ks]=l.useState({}),[Es,Ts]=l.useState({}),[Tt,Is]=l.useState({}),[Ve,It]=l.useState(null),[As,Ps]=l.useState([]),eo=re??Ve??"";l.useEffect(()=>{const r=v.loadNodeSamples;if(typeof r!="function"||!s.id){Ps([]);return}let c=!1;return r(s.id).then(h=>{c||Ps(Array.isArray(h)?h:[])},()=>{}),()=>{c=!0}},[v,s.id,eo]);const At=l.useMemo(()=>o.indexNodeSamples(As),[As]),zt=l.useMemo(()=>o.splitNodeOutputs(kt,At,Tt),[kt,At,Tt]),ze=l.useMemo(()=>o.splitPreviewOutputs(kt,At,Tt),[kt,At,Tt]),Ce=l.useMemo(()=>({actionDef:(r,c)=>{var h;return(h=de[r])==null?void 0:h.find(y=>y.key===c)},triggerDef:(r,c)=>{var h;return(h=je[r])==null?void 0:h.find(y=>y.key===c)},testOutputs:zt.fresh,persistedOutputs:zt.persisted,loopSamples:Es}),[de,je,zt,Es]),Ye=l.useMemo(()=>D?o.upstreamStateSources(D.stepId,w,N,Ce):void 0,[D,w,N,Ce]),to=l.useMemo(()=>(Ye==null?void 0:Ye.steps)??[],[Ye]),be=l.useMemo(()=>{const r=o.upstreamStateSources(re,w,N,Ce,Ve);return{...r,steps:o.excludeSelfStep(r.steps,re??Ve)}},[re,Ve,w,N,Ce]),dt=l.useMemo(()=>Qo({anchorId:re??Ve,nodes:w,edges:N,floating:o.isFloatingDraft(re,Ve,w,N),initialState:s.initialState,variables:s.variables,shapes:Ce,previewOutputs:{...ze.persisted,...ze.fresh}}),[re,Ve,w,N,s.initialState,s.variables,Ce,ze]),Rs=JSON.stringify([...be.steps.map(r=>r.id),...be.extraSampleIds??[]]);l.useEffect(()=>{const r=JSON.parse(Rs);if(!re&&!Ve||r.length===0){Ns({}),ks({}),Ts({}),Is({});return}let c=!1;return Promise.all(r.map(async h=>{try{const y=await v.listStepTests(s.id,h),j=y.length?y[y.length-1]:null;return j?{id:h,output:j.lastRunOutput,runAt:j.lastRunAt,meta:j.lastRunMeta,loopSample:o.foreachTestSample(j)}:null}catch{return null}})).then(h=>{if(c)return;const y={},j={},I={},F={};for(const L of h)L!=null&&L.meta&&(j[L.id]=L.meta),L!=null&&L.loopSample&&(I[L.id]=L.loopSample),!(!L||L.output===void 0||L.output===null)&&(y[L.id]=L.output,F[L.id]=L.runAt);Ns(y),Is(F),ks(j),Ts(I)}),()=>{c=!0}},[v,s.id,re,Ve,Rs]);const Ht=l.useMemo(()=>o.declaredSamples(w,Ce),[w,Ce]),Pt=l.useMemo(()=>({persisted:ze.persisted,samples:Ht.samples,event:Ht.event}),[ze.persisted,Ht]),Ms=l.useMemo(()=>o.upstreamSampleValues(be.steps,ze.fresh,Et,be.loop,Pt),[be.steps,be.loop,ze.fresh,Et,Pt]),Ls=l.useMemo(()=>o.upstreamSampleValueSources(be.steps,ze.fresh,Et,be.loop,Pt),[be.steps,be.loop,ze.fresh,Et,Pt]),Fs=o.useExpressionOptions(),Ds=l.useMemo(()=>o.nodeConfigSources(w),[w]),Os=l.useMemo(()=>o.nodeConfigValues(w,E.subs),[w,E.subs]),Jt=l.useMemo(()=>o.nodeMetaValues(w,E.subs,R,U),[w,E.subs,R,U]),Ut=l.useMemo(()=>({...d??{},steps:be.steps,hasTrigger:be.hasTrigger,eventOutputs:be.eventOutputs,eventOutputsFrom:be.eventOutputsFrom,loop:be.loop,stateShape:{fields:dt.fields,...dt.written?{written:dt.written}:{}},nodeConfigs:Ds,nodeConfig:Os,nodeMeta:Jt,valueSources:Ls,sampleValues:{...Fs.sampleValues??{},...(d==null?void 0:d.sampleValues)??{},...o.nodeMetaSampleValues(Jt),...Ms,...dt.sampleValues}}),[d,Fs.sampleValues,be,dt,Ms,Ls,Ds,Os,Jt]),ut=l.useRef(null);$e||re?ut.current===null&&(ut.current=J.mark()):ut.current=null;const _s=()=>{se(!1),_e(null),Be(null),It(null)},Ws=()=>{const r=ut.current;if(ut.current=null,n||r===null)return;const c=J.rollbackTo(r);c&&Bs(c)},$s=r=>{if(n)return;const c=J[r]();c&&Bs(c)},Bs=r=>{var y;const c=No(s,r);_(c.nodes.map(j=>({...j,selected:j.id===W}))),K(c.edges.map(j=>({...j,selected:j.id===ae}))),z(r.canvas),C(r.connections),c.nodes.some(j=>j.id===W)||B(null),c.edges.some(j=>j.id===ae)||Ne(null);const h=c.nodes.some(j=>j.id===re);h||Pe(null),se(!1),It(null),_e(null),Me(null),me(null),Be(null),qe(null),X(null),Ke(null),Q.current=void 0,it(j=>j+1),i(et(o.flowToWorkflow({...s,nodes:r.nodes,connections:r.connections},c.nodes,c.edges),r.canvas)),!h&&!D&&((y=Se.current)==null||y.focus({preventScroll:!0}))},Vs=l.useRef($s);Vs.current=$s,l.useEffect(()=>{const r=Se.current;if(!r)return;let c=r.contains(document.activeElement);const h=j=>{j.type==="focusin"&&j.target===document.body||(c=r.contains(j.target))},y=j=>{if(n||j.defaultPrevented||qt(j.target)||!r.contains(j.target)&&!(c&&j.target===document.body))return;const I=j.key.toLowerCase();!(j.ctrlKey||j.metaKey)||j.altKey||I!=="z"&&!(I==="y"&&!j.shiftKey)||(j.preventDefault(),Vs.current(I==="y"||j.shiftKey?"redo":"undo"))};return document.addEventListener("pointerdown",h),document.addEventListener("focusin",h),document.addEventListener("keydown",y),()=>{document.removeEventListener("pointerdown",h),document.removeEventListener("focusin",h),document.removeEventListener("keydown",y)}},[n]);const Rt=l.useCallback((r,c)=>{var L;if(qt(r.target))return;const h=(L=Se.current)==null?void 0:L.getBoundingClientRect();if(!h)return;r.preventDefault();const y=en(w,N),j=y.nodeIds,I=co(j,c),F=c!==void 0&&!j.includes(c);F&&_(w.map(q=>q.selected!==(q.id===c)?{...q,selected:q.id===c}:q)),qe({x:r.clientX-h.left,y:r.clientY-h.top,flow:Le({x:r.clientX,y:r.clientY}),nodeIds:I,edgeIds:F?[]:y.edgeIds})},[w,N,_,Le]),so=l.useCallback(r=>{var c;qe(null),r&&((c=Se.current)==null||c.focus({preventScroll:!0}))},[]),no=r=>{const c=ge;if(!(!c||n))if(r==="duplicate")_t(c.nodeIds);else if(r==="delete")Me({nodeIds:c.nodeIds,edgeIds:c.edgeIds});else if(r==="replace-trigger"){const h=w.find(y=>y.id===c.nodeIds[0]);if(!h)return;_e(null),Be({position:h.position,tab:"triggers",replaces:h.id}),se(!0)}else _e(null),Be({position:c.flow,...r==="add-trigger"?{tab:"triggers"}:{}}),se(!0)},oo=t.jsx(ps.Provider,{value:$t,children:t.jsx(cs.Provider,{value:ie,children:t.jsx(ls.Provider,{value:Ss,children:t.jsx(ds.Provider,{value:Nt,children:t.jsx(li,{apps:R,registration:E,children:t.jsx(o.WorkflowProjectProvider,{project:f,workflowId:s.id,children:t.jsx(o.ExpressionOptionsProvider,{value:Ut,children:t.jsxs("section",{ref:Se,className:"w6w-flow",tabIndex:-1,"aria-label":"Workflow editor",style:{width:"100%",height:a,position:"relative"},onFocusCapture:r=>{Q.current=qt(r.target)?{}:void 0},onBlurCapture:()=>{Q.current=void 0},onKeyDown:r=>{if(r.defaultPrevented||r.key!=="Backspace"&&r.key!=="Delete"||n||re||$e||Re)return;const c=r.target;if(c.isContentEditable||c.tagName==="INPUT"||c.tagName==="TEXTAREA"||c.tagName==="SELECT"||c.closest("dialog, .w6w-modal")!==null)return;const h=en(w,N);!h.nodeIds.length&&!h.edgeIds.length||(r.preventDefault(),!h.nodeIds.length&&h.edgeIds.length===1?zn(h.edgeIds[0]):Me(h))},children:[t.jsxs(oe.ReactFlow,{nodes:xt,edges:Zn,minZoom:.05,defaultEdgeOptions:{type:"smoothstep"},connectionLineType:oe.ConnectionLineType.SmoothStep,onNodesChange:le,onEdgesChange:T,onConnect:_n,onConnectStart:(r,c)=>{Je.current=c},onConnectEnd:Wn,onPaneClick:()=>X(null),onPaneContextMenu:r=>Rt(r),onNodeContextMenu:(r,c)=>Rt(r,c.id),onEdgeContextMenu:r=>Rt(r),onSelectionContextMenu:r=>Rt(r),onMoveStart:()=>qe(null),isValidConnection:k,onNodeDragStop:(r,c,h)=>{const y=Kn(h),j=y!==H;if(j&&z(y),!V&&!j){J.record(Mt(s,w,N,M.current,y));return}Y(w,N,y)},onMoveEnd:(r,c)=>{if(!r||n)return;const h=o.flowToWorkflow(s,w,N),y=o.withViewport(h,c);y!==h&&i(y,{viewportOnly:!0})},onSelectionChange:({nodes:r,edges:c})=>{var h,y,j,I;B(((h=r[0])==null?void 0:h.id)??null),Ne(((y=c[0])==null?void 0:y.id)??null),we.current!==(((j=r[0])==null?void 0:j.id)??null)&&(we.current=((I=r[0])==null?void 0:I.id)??null,X(null))},nodeTypes:Qn,nodesDraggable:!n,nodesConnectable:!n,connectOnClick:!1,elementsSelectable:!0,...G?{defaultViewport:G}:{fitView:!0,fitViewOptions:{maxZoom:1}},deleteKeyCode:null,colorMode:ct,proOptions:{hideAttribution:!0},children:[t.jsx(oe.Background,{gap:16}),t.jsx(oe.Controls,{showInteractive:!1,children:!n&&t.jsx(oe.ControlButton,{onClick:Bn,title:"Auto-layout — re-flow the graph into columns","aria-label":"Auto-layout the graph",children:t.jsx(Ee.Icon,{name:"layout"})})}),t.jsx(oe.MiniMap,{pannable:!0,zoomable:!0,style:{background:"var(--w6w-panel-2)"}}),!n&&t.jsxs(oe.Panel,{position:"top-left",className:"w6w-flow-tools",children:[t.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>se(!0),children:"+ Node"}),t.jsx(o.IconButton,{label:"Add note",icon:"sticky-note",className:"w6w-flow-tool","data-testid":"add-note",onClick:Jn}),t.jsx(o.IconButton,{label:"Draw section",title:"Draw section — drag a frame on the canvas (Esc cancels)",icon:"frame",className:`w6w-flow-tool${De?" active":""}`,"aria-pressed":De,"data-testid":"draw-section",onClick:()=>{rt(!De),Ue(null)}})]}),!n&&De&&t.jsx("div",{className:"w6w-section-draw nopan nodrag nowheel","data-testid":"section-draw-surface",onPointerDown:r=>{if(r.button!==0)return;r.currentTarget.setPointerCapture(r.pointerId);const{clientX:c,clientY:h}=r;Ue({sx:c,sy:h,ex:c,ey:h})},onPointerMove:r=>{const{clientX:c,clientY:h}=r;Ue(y=>y&&{...y,ex:c,ey:h})},onPointerUp:()=>{const r=ve;if(Ue(null),rt(!1),!r)return;const c=Le({x:r.sx,y:r.sy}),h=Math.abs(r.ex-r.sx)>6||Math.abs(r.ey-r.sy)>6;Un(c,h?Le({x:r.ex,y:r.ey}):null)},children:ve&&(()=>{var y;const r=(y=Se.current)==null?void 0:y.getBoundingClientRect(),c=(r==null?void 0:r.left)??0,h=(r==null?void 0:r.top)??0;return t.jsx("div",{className:"w6w-section-draw-rect",style:{left:Math.min(ve.sx,ve.ex)-c,top:Math.min(ve.sy,ve.ey)-h,width:Math.abs(ve.ex-ve.sx),height:Math.abs(ve.ey-ve.sy)}})})()}),!n&&st&&o.edgeLane(st)!=="each"&&((Js=w.find(r=>r.id===st.source))==null?void 0:Js.data.step.uses.app)!==o.ROUTER_APP&&t.jsx(oe.Panel,{position:"top-right",children:t.jsxs("div",{className:"w6w-edge-lane",children:[t.jsx("span",{className:"w6w-muted w6w-small",children:"Run on"}),["success","error"].map(r=>t.jsx("button",{type:"button",className:`w6w-btn w6w-btn-sm w6w-btn-ghost${o.edgeLane(st)===r?" active":""}`,"aria-pressed":o.edgeLane(st)===r,title:ci,onClick:()=>Vn(r),children:r==="success"?"Success":"Error"},r)),(vt==null?void 0:vt.edgeId)===st.id&&t.jsx("span",{className:"w6w-edge-lane-err w6w-small",role:"alert",children:vt.message})]})}),Z&&t.jsx(oe.NodeToolbar,{nodeId:Z.nodeId,position:oe.Position.Bottom,isVisible:!0,children:t.jsx("div",{className:"w6w-loop-notice w6w-small",role:"alert",children:o.loopRefusalMessage(Z.reason)})}),t.jsx(o.CanvasLayer,{canvas:H,readOnly:n,savePosition:V,onChange:Xe,onSectionDrop:qn,onRequestDelete:(r,c)=>!n&&me({kind:r,id:c})})]}),Ae&&t.jsx(o.ConfirmModal,{title:Ae.kind==="note"?"Delete note":"Delete section",message:Ae.kind==="note"?"Delete this note?":"Delete this section? Its nodes are kept.",confirmLabel:"Delete",onConfirm:()=>{Gn(Ae.kind,Ae.id),me(null)},onClose:()=>me(null)}),$e&&t.jsx(o.StepBuilderModal,{initialTab:ye==null?void 0:ye.tab,onClose:()=>{Ws(),_s()},onDone:_s,onAdd:r=>{const c=Hn(r);return c&&It(c),c},onDraftChange:(r,c)=>bs(r,{id:r,...c}),stepIds:w.map(r=>r.id),onOpenStep:r=>{se(!1),_e(null),Be(null),It(null),ke("props"),Pe(r)},workflowId:s.id,upstreamSteps:o.stepBuilderUpstreamSteps(xe,w,N),loop:o.stepBuilderLoop(xe,w,N,Ce)}),Ct&&re&&t.jsx(Si,{workflowId:s.id,step:Ct,restoreVersion:ue,upstreamSteps:Ut.steps??[],loop:Ut.loop,readOnly:n,fanOutCount:Ss.get(re)??0,stateOutputFields:(Ks=o.resolveOutputShape((Us=Ce.actionDef)==null?void 0:Us.call(Ce,Ct.uses.app,Ct.uses.action),(qs=Ce.testOutputs)==null?void 0:qs[re],(Gs=Ce.persistedOutputs)==null?void 0:Gs[re]))==null?void 0:Ks.fields.map(r=>r.key),initialView:Oe,stepProblems:nt==null?void 0:nt.data.stepProblems,otherStepIds:w.filter(r=>r.id!==re).map(r=>r.id),onChange:r=>bs(re,r),onClose:()=>Pe(null),onCancel:()=>{Ws(),Pe(null)},onTestRun:b}),D&&t.jsxs(o.Modal,{title:`${Vt?"Run node":"Test run"}: ${D.stepId}`,onClose:()=>m(null),children:[Vt&&Bt&&t.jsx(mi,{workflowId:s.id,step:Bt,upstreamSteps:to,loop:Ye==null?void 0:Ye.loop,continues:S?{stopAt:ss(w.map(r=>r.data.step),D.stepId)}:void 0,onCancel:()=>m(null),onRun:(r,c)=>S?Xn(D.stepId,r,c):Yn(D.stepId,r,c)},D.stepId),!Vt&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w6w-modal-body",children:[D.status==="running"&&t.jsx("p",{className:"w6w-muted w6w-small",children:"Running…"}),D.status==="error"&&t.jsxs("div",{className:"w6w-result w6w-error",children:[D.errorCode&&t.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:t.jsx("code",{children:D.errorCode})}),D.error||"The node failed with no error message."]}),D.status==="done"&&t.jsxs("div",{children:[t.jsx("div",{className:"w6w-muted w6w-small",style:{marginBottom:6},children:"Result"}),t.jsx(o.ResultViewer,{value:D.value,maxHeight:360}),D.meta&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Metadata"}),t.jsx(o.ResultViewer,{value:D.meta,maxHeight:360})]})]}),D.logs&&D.logs.length>0&&t.jsxs("div",{children:[t.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Console output"}),t.jsx(Ee.Copyable,{value:D.logs.join(`
|
|
2
|
-
`),label:"Copy console output",children:t.jsx("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:200,overflow:"auto",margin:0},children:D.logs.join(`
|
|
3
|
-
`)})})]})]}),t.jsx("div",{className:"w6w-modal-actions",children:t.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>m(null),children:"Close"})})]})]}),Re!==null&&t.jsx(o.ConfirmModal,{title:Re.nodeIds.length===1?"Delete node":Re.nodeIds.length>1?`Delete ${Re.nodeIds.length} nodes`:`Delete ${Re.edgeIds.length} connections`,message:Co(Re,w,N),confirmLabel:"Delete",autoFocusConfirm:!0,onConfirm:()=>{$n(Re),Me(null)},onClose:()=>Me(null)}),ge&&t.jsx(ao,{x:ge.x,y:ge.y,items:lo(ge.nodeIds,!!n,{replaceableTrigger:ge.nodeIds.length===1&&w.some(r=>r.id===ge.nodeIds[0]&&o.isTriggerStep(r.data.step.uses))}),onAction:no,onClose:so})]})})})})})})})});return t.jsx(o.WorkflowConnectionsContext.Provider,{value:{nodes:w.map(r=>r.data.step),connections:U,setConnections:C,readOnly:n},children:oo})}const pi=["code"];function Ot(e){try{const s=JSON.parse(e);return s&&typeof s=="object"&&!Array.isArray(s)?s:null}catch{return null}}function fi(e){try{const s=JSON.parse(e);if(Array.isArray(s))return{items:s}}catch{return null}return Ot(e)}function hi({items:e,save:s}){if(!e)return t.jsxs("output",{className:"w6w-small",style:{display:"block"},children:[t.jsx("strong",{children:"Items"})," doesn't resolve to a list yet: no step before this one has a saved test that produces it. Test an earlier step, or paste a sample list under"," ",t.jsx("strong",{children:"Override the incoming state"})," below."]});const i=e[0],n=i!==void 0?(o.inferOutputFields(i)??[]).map(a=>a.key):[];return t.jsxs("div",{className:"w6w-testout",children:[t.jsxs("div",{className:"w6w-testout-label",children:[e.length," ",e.length===1?"item":"items"]}),e.length===0?t.jsx("p",{className:"w6w-muted w6w-small",children:"The list is empty, so there is no item to sample."}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"w6w-testout-label",children:"First item"}),t.jsx(o.ResultViewer,{value:i,maxHeight:220})]}),s==="saved"&&t.jsxs("output",{className:"w6w-small",style:{display:"block"},children:["Saved as this loop's sample.",n.length>0&&t.jsxs(t.Fragment,{children:[" ","Steps on ",t.jsx("strong",{children:"Each item"})," now offer ",t.jsx("strong",{children:"Current item"})," ›"," ",n.map((a,u)=>t.jsxs("span",{children:[u>0&&", ",t.jsx("code",{children:a})]},a)),"."]})]}),s==="failed"&&t.jsx("p",{className:"w6w-small",role:"alert",children:"Couldn't save the sample. Try Test again."})]})}function Tn(e){const[s,i]=l.useState(null),[n,a]=l.useState("0"),[u,d]=l.useState({}),[f,p]=l.useState({}),x=s??o.loopItemText(e),b=((e==null?void 0:e.outer)??[]).map(v=>({foreachId:v.foreachId,name:v.name??v.foreachId,itemText:u[v.foreachId]??o.loopItemText(v),indexText:f[v.foreachId]??"0",setItemText:R=>d(E=>({...E,[v.foreachId]:R})),setIndexText:R=>p(E=>({...E,[v.foreachId]:R}))})),g=e?o.parseLoopSeed(x,n):void 0;let S=g!=null&&g.ok?{ok:!0,value:g.value}:g;if(e&&(g!=null&&g.ok)){const v={};for(const R of b){const E=o.parseLoopSeed(R.itemText,R.indexText);if(!E.ok){S={ok:!1,error:`${R.name}: ${E.error}`};break}v[R.foreachId]=E.value}S!=null&&S.ok&&(v[e.foreachId]=g.value,S={ok:!0,value:{...g.value,loops:v}})}return{active:!!e,itemText:x,indexText:n,setItemText:i,setIndexText:a,outers:b,parsed:S}}function In(e){var s;return(s=e.parsed)!=null&&s.ok?e.parsed.value:void 0}function fs(e){return e.parsed&&!e.parsed.ok?e.parsed.error:null}function An({seed:e,readOnly:s}){if(!e.active)return null;const i=fs(e);return t.jsxs("div",{className:"w6w-field w6w-loop-seed",children:[e.outers.map(n=>t.jsxs("div",{"data-testid":`loop-seed-outer-${n.foreachId}`,children:[t.jsxs("span",{children:[n.name," item"]}),t.jsx("textarea",{rows:3,value:n.itemText,readOnly:s,spellCheck:!1,"aria-label":`${n.name} item`,onChange:a=>n.setItemText(a.target.value)}),t.jsxs("span",{children:[n.name," index"]}),t.jsx("input",{type:"text",inputMode:"numeric",value:n.indexText,readOnly:s,"aria-label":`${n.name} index`,onChange:a=>n.setIndexText(a.target.value)})]},n.foreachId)),t.jsx("span",{children:"Current item"}),t.jsx("textarea",{rows:3,value:e.itemText,readOnly:s,spellCheck:!1,"aria-label":"Current item",onChange:n=>e.setItemText(n.target.value)}),t.jsx("span",{children:"Index"}),t.jsx("input",{type:"text",inputMode:"numeric",value:e.indexText,readOnly:s,"aria-label":"Index",onChange:n=>e.setIndexText(n.target.value)}),t.jsx("span",{className:"w6w-hint",children:"This step runs once per item of the For each. Test it as one iteration — starting from the sample item, or edit it."}),i&&t.jsx("span",{className:"w6w-hint",role:"alert",children:i})]})}function os({text:e,onChange:s,seeds:i,readOnly:n,expand:a,hint:u}){const d=Ot(e),f=d?Object.keys(d).length:0,p=f>0,[x,b]=l.useState(p);l.useEffect(()=>{(p||a)&&b(!0)},[p,a]);const g=S=>{s(JSON.stringify(S.lastRunOutput??S.input??{},null,2)),b(!0)};return t.jsxs("div",{className:"w6w-field w6w-incoming-state",children:[t.jsx("span",{children:"Incoming state"}),i.length>0&&t.jsx("div",{className:"w6w-seed-picker",children:t.jsx("div",{className:"w6w-seed-chips",children:i.map(S=>t.jsxs("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Use ${S.label}'s saved test as the incoming state`,disabled:n,onClick:()=>g(S.test),children:[t.jsx("code",{children:S.label}),S.test.lastRunStatus?t.jsxs("span",{className:"w6w-muted w6w-small",children:[" · ",S.test.lastRunStatus]}):null]},S.stepId))})}),t.jsxs("details",{className:"w6w-state-override",open:x,onToggle:S=>b(S.currentTarget.open),children:[t.jsxs("summary",{children:["Override the incoming state",f>0?` · ${f} key${f===1?"":"s"} set`:""]}),t.jsx("textarea",{rows:3,value:e,readOnly:n,spellCheck:!1,"aria-label":"Incoming state override (JSON)",onChange:S=>s(S.target.value)}),t.jsx("span",{className:"w6w-hint",children:u??t.jsxs(t.Fragment,{children:["JSON whose keys replace this step's parameters by name, for this test only — so a script's data goes under ",t.jsx("code",{children:"input"}),": ",t.jsx("code",{children:'{"input": {…}}'}),". Upstream outputs already reach ",t.jsx("code",{children:"{{ nodes.<id>.output }}"})," bindings from their saved tests. Reach for this to test against a state the flow cannot currently produce — a field no upstream step returns yet, or a case you can't reproduce by running the flow."]})})]})]})}function mi({workflowId:e,step:s,upstreamSteps:i,loop:n,onRun:a,onCancel:u,continues:d}){var H;const f=o.useW6WApi(),p=o.isTriggerStep(s.uses),x=o.isInternalApp(s.uses.app),b=l.useMemo(()=>{var z;return p?o.asFieldDefs((z=s.with)==null?void 0:z.fields):[]},[p,s.with]),g=l.useMemo(()=>p?o.fieldsToParams(b):x?o.internalNodeParams(s.uses.app,s.uses.action):null,[p,x,b,s.uses.app,s.uses.action]),[S,v]=l.useState(null),R=g??S;l.useEffect(()=>{if(g)return;if(!s.uses.app||!s.uses.action){v([]);return}let z=!1;return v(null),f.getAppActions(s.uses.app).then(J=>{var Q;z||v(((Q=J.find(ue=>ue.key===s.uses.action))==null?void 0:Q.params)??[])}).catch(()=>!z&&v([])),()=>{z=!0}},[f,g,s.uses.app,s.uses.action]);const[E,D]=l.useState(()=>{var z;return p?o.seedValues(o.asFieldDefs((z=s.with)==null?void 0:z.fields)):{}}),[m,A]=l.useState("{}"),O=o.useSeedSources(e,i,!p),U=Tn(n),P=(H=o.useExpressionOptions().stateShape)==null?void 0:H.written,M=o.startStateFromSeeds(O,In(U),P),C=o.useRememberedTestInput(e,s.id),[$,G]=l.useState(!1),[V,w]=l.useState(!1);l.useEffect(()=>{if(!C.loaded)return;let z=!1;const J=(Q,ue)=>{Q&&Object.keys(Q).length>0&&(p?D(it=>({...it,...Q})):A(JSON.stringify(Q,null,2)),ue&&w(!0)),G(!0)};if(C.input!==void 0){J(C.input,!0);return}return f.listStepTests(e,s.id).then(Q=>{if(z)return;const ue=Q.length?Q[Q.length-1]:null;J(p?ue==null?void 0:ue.with:ue==null?void 0:ue.input,!1)}).catch(()=>{z||G(!0)}),()=>{z=!0}},[f,e,s.id,p,C.loaded]);const[_,le]=l.useState(0),de=()=>{C.clear(),w(!1),p?D(o.seedValues(b)):A("{}"),le(z=>z+1)},je=z=>{D(z),N(!0),w(!1),le(J=>J+1)},[ie,N]=l.useState(!0),K=Ot(m),T=p?ie:K!==null,W=p?E:{...s.with??{},...K??{}},B=p?null:fs(U),te=!!R&&$&&T&&!B&&o.requiredParamsFilled(R,W);return t.jsxs("div",{className:"w6w-stepconfig",children:[t.jsx("div",{className:"w6w-modal-body",children:t.jsxs("div",{className:"w6w-stack",children:[d&&t.jsxs("p",{className:"w6w-muted w6w-small","data-testid":"run-from-node-hint",children:["Runs this node, then continues through every node after it",d.stopAt.length>0?t.jsxs(t.Fragment,{children:[" ","and stops before"," ",d.stopAt.length===1?"the paused node":"paused nodes"," ",d.stopAt.map((z,J)=>t.jsxs("span",{children:[J>0?", ":"",t.jsx("code",{children:z})]},z))]}):null,". Disabled nodes are skipped."]}),V&&R!==null&&$&&t.jsx(o.LastUsedNote,{onClear:de}),R===null||!$?t.jsx("p",{className:"w6w-muted w6w-small",children:R===null?"Loading parameters…":"Loading saved values…"}):p?t.jsxs(t.Fragment,{children:[t.jsx(o.PropertyEntryForm,{params:R,values:E,onChange:D,onValidityChange:N},_),s.uses.trigger===!0&&t.jsx(o.TriggerSampleButton,{app:s.uses.app,trigger:s.uses.action,onUse:je}),R.length===0&&t.jsxs("span",{className:"w6w-hint",children:["This trigger declares no fields — provide a sample payload to run with. It becomes the trigger's output state (",t.jsx("code",{children:"input"}),")."]})]}):t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:"w6w-muted w6w-small",children:["Runs ",t.jsx("code",{children:s.uses.action})," with the configuration saved on this node — only the incoming state changes per run. Edit the node to change how it is configured."]}),t.jsx(An,{seed:U}),t.jsx(os,{text:m,onChange:A,seeds:O})]})]})}),t.jsxs("div",{className:"w6w-modal-actions",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:u,children:"Cancel"}),!te&&R!==null&&$&&t.jsx("span",{className:"w6w-muted w6w-small",children:B?`${B} Fix it to run.`:T?p?"Fill the required fields to test.":"This step is missing required configuration — set it on the Configure tab.":p?"The payload must be a JSON object to run.":"The incoming state must be a JSON object to run."}),t.jsx("button",{type:"button",className:"w6w-btn",disabled:!te,onClick:()=>{C.save(p?E:K??{},R??[]),a(p?E:K??{},p?void 0:M)},children:"▶ Run"})]})]})}function gi(e){return e.uses.app===o.CONTROL_APP&&e.uses.action==="foreach"}function Pn({id:e}){const{tones:s,loopOf:i}=l.useContext(ds),n=jn(e,i);return n.length===0?null:t.jsx("span",{className:"w6w-loop-dots",children:n.map(a=>t.jsx("span",{className:"w6w-loop-dot",role:"img","aria-label":`In loop · ${a}`,title:`In loop · ${a}`,style:{background:rs(s.get(a)??1)}},a))})}function Rn(e){return Lo(e,l.useContext(ds).tones)}function He({type:e,position:s,multiple:i,id:n,variant:a,top:u,routeLabel:d}){const f=oe.useNodeId(),p=l.useContext(ps),x=!!f&&!!p&&!p.readOnly,b=()=>{x&&f&&p.onAddFromPort(f,e,n)},g=a==="error"?"a step that handles this step's failure":a==="each"?"the first step of this loop's body":e==="target"?"a step before this one":"the next step";return t.jsx(oe.Handle,{type:e,position:s,id:n,className:a==="error"?"w6w-handle-error":a==="each"?"w6w-handle-each":i?"w6w-handle-multi":void 0,style:{...i?{height:22,borderRadius:3,width:8}:{},...u?{top:u}:{}},onClick:x?b:void 0,title:d?`${d} — drag or click to connect`:x?`Drag to empty canvas (or click) to add ${g} · drag to a port to connect`:a==="error"?"On error — drag to route this step's failure separately":a==="each"?"Each item — drag to the first step to repeat for every item":i?e==="target"?"Accepts multiple incoming connections":"Multiple outgoing connections":void 0})}function Mn({id:e,step:s,runnable:i}){const n=l.useContext(ps);if(!n||n.readOnly)return null;const a=i||n.runsFromNode,u=n.runsFromNode?"Run from this node — continues through the nodes after it":"Test-run this node",d=Qe(s),f=We(s);return t.jsxs(oe.NodeToolbar,{position:oe.Position.Top,className:"w6w-node-toolbar",children:[a&&t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:u,"aria-label":u,onClick:()=>n.onRun(e),children:t.jsx(Ee.Icon,{name:"run",size:15})}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn","data-testid":"node-pause-toggle","aria-pressed":d,title:d?"Resume — test runs go through this node":"Pause — test runs stop before this node","aria-label":d?"Unpause node":"Pause node",onClick:()=>n.onTogglePause(e),children:t.jsx(Ee.Icon,{name:"pause",size:15})}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn","data-testid":"node-disable-toggle","aria-pressed":f,title:f?"Enable — this node runs again":"Disable — skip this node in every run","aria-label":f?"Enable node":"Disable node",onClick:()=>n.onToggleDisable(e),children:t.jsx(Ee.Icon,{name:"ban",size:15})}),t.jsx("span",{className:"w6w-node-toolbar-divider","aria-hidden":"true"}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Edit","aria-label":"Edit node",onClick:()=>n.onEdit(e),children:t.jsx(Ee.Icon,{name:"edit",size:15})}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Duplicate","aria-label":"Duplicate node",onClick:()=>n.onDuplicate(e),children:t.jsx(Ee.Icon,{name:"copy",size:15})}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn danger",title:"Delete","aria-label":"Delete node",onClick:()=>n.onDelete(e),children:t.jsx(Ee.Icon,{name:"trash",size:15})})]})}function Ln({step:e,count:s}){if(s<2)return null;const i=e.fanOut==="parallel",n=o.fanOutLabel(s,i?"parallel":"sequential");return t.jsxs("div",{className:"w6w-fanout-badge",role:"img","aria-label":n,title:n,children:[t.jsx("span",{"aria-hidden":"true",children:i?"⇉":"→"})," ",s]})}function Fn({step:e}){const s=Qe(e),i=We(e);return!s&&!i?null:t.jsxs("div",{children:[i&&t.jsxs("span",{className:"w6w-node-flag w6w-node-flag-disabled","data-testid":"step-disabled-badge",role:"img","aria-label":sn,title:sn,children:[t.jsx(Ee.Icon,{name:"ban",size:11})," Disabled"]}),s&&t.jsxs("span",{className:"w6w-node-flag w6w-node-flag-paused","data-testid":"step-paused-badge",role:"img","aria-label":tn,title:tn,children:[t.jsx(Ee.Icon,{name:"pause",size:11})," Paused"]})]})}function Dn(e){return!e||e.length===0?{}:{"data-step-problem":e.map(s=>s.code).join(" "),title:e.map(o.stepProblemTooltip).join(`
|
|
4
|
-
`)}}function On({problems:e}){if(!e||e.length===0)return null;const s=e.map(o.stepProblemTooltip).join(`
|
|
5
|
-
`);return t.jsx("span",{"data-step-problem-badge":"",role:"img","aria-label":s,title:s,style:{position:"absolute",top:-9,right:-9,width:18,height:18,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",background:"var(--w6w-danger)",color:"#fff"},children:t.jsx(Ee.Icon,{name:"warning",size:12})})}function wi(e){const s=o.useW6WApi(),i=e.uses.action,[n,a]=l.useState(null),u=e.uses.trigger===!0,d=e.uses.app;return l.useEffect(()=>{if(!u||!s.getAppTriggers)return;let f=!1;return s.getAppTriggers(d).then(p=>{var x;return!f&&a(((x=p.find(b=>b.key===i))==null?void 0:x.title)??null)}).catch(()=>{}),()=>{f=!0}},[s,d,i,u]),n||i}function xi(e){const s=o.useW6WApi(),i=s.listSubscriptionsForWorkflow,n=s.retrySubscriptionRegistration,a=e.id,u=[...oi(e.nodes),...(e.nodes??[]).filter(R=>{var E;return((E=R.uses)==null?void 0:E.app)===o.WEBHOOK_APP&&R.uses.trigger!==!0})],d=u.length>0,f=u.map(R=>`${R.id}:${R.uses.app}:${R.uses.action}:${o.connectionIdFor(R,e.connections)??""}`).join("|"),[p,x]=l.useState([]),b=l.useMemo(()=>ni(p),[p]),[g,S]=l.useState(0);l.useEffect(()=>{if(!i||!d){x([]);return}let R=!1;return i.call(s,a).then(E=>!R&&x(E)).catch(()=>{}),()=>{R=!0}},[s,i,a,d,f,g]);const v=l.useMemo(()=>n?async R=>{try{await n.call(s,R)}finally{S(E=>E+1)}}:void 0,[s,n]);return l.useMemo(()=>({byNode:b,subs:p,retry:v}),[b,p,v])}function bi({nodeId:e}){const{byNode:s,retry:i}=l.useContext(En),[n,a]=l.useState(!1),u=s.get(e),d=si(u,i!==void 0);return!u||!d?null:t.jsxs("div",{className:"w6w-small","data-trigger-registration":u.status,"data-tone":d.tone,style:{marginTop:3,paddingLeft:2},children:[t.jsx("span",{style:d.tone==="danger"?{color:"var(--w6w-danger)"}:void 0,children:d.label}),t.jsxs("span",{className:"w6w-muted",children:[" · ",d.lastFire]}),d.error&&t.jsx("div",{role:"alert",style:{color:"var(--w6w-danger)"},children:d.error}),d.retryVisible&&i&&t.jsx("button",{type:"button",className:"nodrag",disabled:n,onClick:()=>{a(!0),i(u.id).catch(()=>{}).finally(()=>a(!1))},children:"Retry"})]})}function yi({id:e,data:s,selected:i}){const n=s.step,u=l.useContext(us).get(n.uses.app),d=(u==null?void 0:u.displayName)||n.uses.app||"—",f=o.isTriggerStep(n.uses),p=wi(n),x=n.uses.trigger?`${d} · ${p}`:d,b=o.nodePortsForStep(n,l.useContext(cs)),g=kn(s.stepStatus??"no-run",s.runStatus),S=t.jsx(Ln,{step:n,count:l.useContext(ls).get(e)??0}),v=Rn(e);return t.jsxs("div",{className:[s.loopOf?"w6w-node-in-loop":"",We(n)?"w6w-node-disabled":""].filter(Boolean).join(" ")||void 0,"data-loop-of":s.loopOf,style:v,"data-disabled":We(n)||void 0,"data-paused":Qe(n)||void 0,children:[t.jsx(Mn,{id:e,step:n,runnable:!0}),t.jsxs("div",{className:f?"w6w-node-trigger":void 0,"data-node-kind":f?"trigger":void 0,"data-run-status":s.stepStatus??"no-run",...Dn(s.stepProblems),style:{position:"relative",...s.stepProblems?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${g.borderWidth}px ${g.borderStyle} ${i?"var(--w6w-accent)":g.borderColor}`,opacity:We(n)?.45:i?1:g.opacity,background:"var(--w6w-panel)",color:"var(--w6w-text)",...f?{}:{borderRadius:4,padding:"8px 12px"},minWidth:180,fontSize:13,display:"flex",alignItems:"center",gap:10},children:[t.jsx(On,{problems:s.stepProblems}),b.in>0&&t.jsx(He,{type:"target",position:oe.Position.Left,multiple:b.in>1}),t.jsx(o.AppIcon,{src:u==null?void 0:u.iconSvg,srcDark:u==null?void 0:u.iconSvgDark,brandColor:u==null?void 0:u.brandColor,name:d,size:28}),t.jsxs("div",{style:{minWidth:0},children:[t.jsx("div",{style:{fontWeight:600},children:x}),t.jsx("div",{className:"w6w-muted w6w-small",style:{marginTop:2},children:t.jsx("code",{children:n.uses.action||"—"})})]}),b.out>0&&t.jsxs(t.Fragment,{children:[t.jsx(He,{type:"source",position:oe.Position.Right,multiple:b.out>1}),!f&&t.jsx(He,{type:"source",position:oe.Position.Bottom,multiple:!1,id:o.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),S,t.jsx(Fn,{step:n}),f&&n.uses.trigger===!0&&t.jsx(bi,{nodeId:e}),s.loopOf&&t.jsx(Pn,{id:e}),t.jsxs("div",{className:"w6w-muted",style:{marginTop:3,fontSize:10,opacity:.75,paddingLeft:2},children:[n.id,u!=null&&u.version?` - v${u.version}`:""]}),n.notes&&t.jsx("div",{className:"w6w-muted w6w-node-notes",title:n.notes,children:n.notes})]})}function ji({id:e,data:s,selected:i}){const n=s.step,a=o.routesForStep(n),u=n.uses.app===o.ROUTER_APP,d=o.isIfStep(n),f=a.length?o.routerPortLayout(a):d?o.ifPortLayout():void 0,p=JSON.stringify(a.map(A=>A.id)),x=oe.useUpdateNodeInternals();l.useEffect(()=>{x(e)},[e,p,x]);const b=o.internalNodeLabel(n.uses.app,n.uses.action),g=o.internalNodeIcon(n.uses.app,n.uses.action),S=o.nodePortsForStep(n,l.useContext(cs)),v=o.isTriggerStep(n.uses),R=gi(n),E=kn(s.stepStatus??"no-run",s.runStatus),D=t.jsx(Ln,{step:n,count:l.useContext(ls).get(e)??0}),m=Rn(e);return t.jsxs("div",{className:[R?"w6w-node-foreach":"",s.loopOf?"w6w-node-in-loop":"",We(n)?"w6w-node-disabled":""].filter(Boolean).join(" ")||void 0,"data-loop-of":s.loopOf,style:m,"data-disabled":We(n)||void 0,"data-paused":Qe(n)||void 0,children:[t.jsx(Mn,{id:e,step:n,runnable:!o.isControlApp(n.uses.app)}),t.jsxs("div",{className:v?"w6w-node-trigger":u?"w6w-node-router":void 0,"data-node-kind":v?"trigger":void 0,"data-run-status":s.stepStatus??"no-run",...Dn(s.stepProblems),style:{position:"relative",...s.stepProblems?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${E.borderWidth}px ${E.borderStyle} ${i?"var(--w6w-accent)":E.borderColor}`,opacity:We(n)?.45:i?1:E.opacity,background:"var(--w6w-panel-2)",color:"var(--w6w-text)",...v?{}:{borderRadius:4,padding:"6px 14px 6px 8px"},minWidth:140,...f!=null&&f.minHeight?{minHeight:f.minHeight,boxSizing:"border-box"}:{},fontSize:13,display:"flex",alignItems:"center",gap:10},children:[t.jsx(On,{problems:s.stepProblems}),S.in>0&&t.jsx(He,{type:"target",position:oe.Position.Left,multiple:S.in>1}),g&&t.jsx(o.InternalIcon,{icon:g}),t.jsxs("div",{style:{minWidth:0,textAlign:"left"},children:[t.jsx("div",{style:{fontWeight:600},children:b}),t.jsx("div",{className:"w6w-muted w6w-small",style:{marginTop:2},children:t.jsx("code",{children:n.uses.action||"—"})})]}),R&&t.jsxs("div",{className:"w6w-foreach-ports w6w-small","aria-hidden":"true",children:[t.jsx("span",{children:"Each item"}),t.jsx("span",{children:"Done"})]}),d&&(f==null?void 0:f.right[0])&&t.jsx("span",{className:"w6w-if-true-label w6w-small","aria-hidden":"true",children:f.right[0].label}),!d&&!!(f!=null&&f.right.length)&&t.jsx("div",{className:"w6w-router-ports w6w-small",style:{gridTemplateRows:`repeat(${f.right.length}, 1fr)`},"aria-hidden":"true",children:f.right.map(A=>t.jsx("span",{title:A.label,children:A.label},A.id))}),S.out>0&&t.jsxs(t.Fragment,{children:[R&&t.jsx(He,{type:"source",position:oe.Position.Right,multiple:!1,id:o.EACH_SOURCE_HANDLE,variant:"each"}),f?t.jsxs(t.Fragment,{children:[f.right.map(A=>t.jsx(He,{type:"source",position:oe.Position.Right,multiple:!1,id:A.handleId,top:A.top,routeLabel:A.label},A.id)),f.bottom&&t.jsxs(t.Fragment,{children:[t.jsx(He,{type:"source",position:oe.Position.Bottom,multiple:!1,id:f.bottom.handleId,routeLabel:f.bottom.label}),t.jsx("span",{className:"w6w-router-fallback-label w6w-small","aria-hidden":"true",children:f.bottom.label})]})]}):t.jsx(He,{type:"source",position:oe.Position.Right,multiple:S.out>1,id:R?o.routeHandle(o.FOREACH_DONE_ROUTE):void 0}),!v&&!u&&!d&&n.uses.app!==o.RACE_APP&&t.jsx(He,{type:"source",position:oe.Position.Bottom,multiple:!1,id:o.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),D,t.jsx(Fn,{step:n}),s.loopOf&&t.jsx(Pn,{id:e}),s.legacyLoop&&t.jsx("div",{className:"w6w-loop-legacy-note w6w-small",children:"This loop was converted from an older definition. Its steps after For each now run once per item; check the order, then save."}),t.jsx("div",{className:"w6w-muted",style:{marginTop:3,fontSize:10,opacity:.75,paddingLeft:2},children:n.id}),n.notes&&t.jsx("div",{className:"w6w-muted w6w-node-notes",title:n.notes,children:n.notes})]})}function vi(e,s){var d,f;if(!s)return e;const i={...(e==null?void 0:e.steps)??{}};let n=!1;for(const[p,x]of Object.entries(s)){const b=/^nodes\.([^.]+)\.output$/.exec(p);!b||((d=i[b[1]])==null?void 0:d.output)!==void 0||(i[b[1]]={...i[b[1]]??{},output:x},n=!0)}const a=s["trigger.event"],u=a!==void 0&&((f=e==null?void 0:e.trigger)==null?void 0:f.event)===void 0;return!n&&!u?e:{...e??{},...n?{steps:i}:{},...u?{trigger:{...(e==null?void 0:e.trigger)??{},event:a}}:{}}}function Si(e){return t.jsx(Ci,{...e})}function Ci({workflowId:e,step:s,restoreVersion:i,upstreamSteps:n,loop:a,onChange:u,onClose:d,onCancel:f,readOnly:p,initialView:x="props",fanOutCount:b=0,stateOutputFields:g,onTestRun:S,stepProblems:v,otherStepIds:R}){var yt,jt;const E=o.useW6WApi(),D=l.useContext(us),[m,A]=l.useState(s),O=o.useWorkflowConnections(),U=o.connectionIdFor(m,O==null?void 0:O.connections),P={...m,uses:{...m.uses,connection:U}},C=m.uses.connectionRef!==void 0&&!U||o.isConnectionBlocked(P,v),$=v==null?void 0:v.find(k=>k.code==="unknown_connection"&&k.connection===U),G=(v??[]).filter(k=>"fix"in k),[V,w]=l.useState(C?"setup":"configure"),[_,le]=l.useState(x==="json"?"code":x==="settings"?"config":"props"),[de,je]=l.useState("props"),[ie,N]=l.useState(()=>o.stepToJson(s)),[K,T]=l.useState("{}"),W=l.useRef(null),[B,te]=l.useState(!1),H=l.useRef(i);l.useEffect(()=>{H.current!==i&&(H.current=i,A(s),N(o.stepToJson(s)))},[i,s]);const[z,J]=l.useState(!1),[Q,ue]=l.useState(null),[it,De]=l.useState(null),[rt,ve]=l.useState(null),[Ue,Ae]=l.useState(!1),me=o.isInternalApp(m.uses.app),ae=m.uses.trigger===!0;l.useEffect(()=>{if(me){ue(o.internalNodeParams(m.uses.app,m.uses.action));const Z=o.INTERNAL_NODES.filter(X=>X.app===m.uses.app&&X.groupActions&&!X.hidden);De(Z.length?Z.map(X=>({key:X.action,title:X.label,params:X.params})):null);return}if(!m.uses.app){De(null),ue([]);return}let k=!1;return ue(null),(ae?o.getTriggerDefs(E,m.uses.app):E.getAppActions(m.uses.app)).then(Z=>{var X;k||(De(Z),ue(m.uses.action?((X=Z.find(we=>we.key===m.uses.action))==null?void 0:X.params)??[]:[]))}).catch(()=>!k&&ue([])),()=>{k=!0}},[E,m.uses.app,m.uses.action,me,ae]);const Ne=l.useRef(0);l.useEffect(()=>()=>{Ne.current++},[]);const $e=l.useCallback(()=>{me||!m.uses.app||E.listConnectionsForApp(m.uses.app).then(k=>{ve(k),Ae(!1)}).catch(()=>Ae(!0))},[E,m.uses.app,me]);l.useEffect(()=>{if(me||!m.uses.app)return;let k=!1;return ve(null),Ae(!1),E.listConnectionsForApp(m.uses.app).then(Z=>{k||(ve(Z),Ae(!1))}).catch(()=>!k&&Ae(!0)),()=>{k=!0}},[E,m.uses.app,me]);const se=l.useCallback(k=>{A(k),u(k)},[u]),gt=jo({enabled:m.uses.app===o.SCRIPT_APP&&!p,values:m.with??{},onChange:k=>se({...m,with:k})}),re=k=>{k==="code"&&N(o.stepToJson(m)),le(k)},Pe=k=>{const Z=o.stepNameError(k,R??[]);return Z||se({...m,id:k}),Z},Oe=!!m.uses.app&&!!m.uses.action&&!o.isControlApp(m.uses.app),ke=o.isForeachStep(m),ge=o.isTriggerStep(m.uses),qe=V==="test"&&Oe&&!ge,ye=o.useSeedSources(e,n,Oe&&!ge||ke),Be=Tn(Oe&&!ge?a:void 0),Re=o.useExpressionOptions(),Me=o.startStateFromSeeds(ye,In(Be),(yt=Re.stateShape)==null?void 0:yt.written),at=vi(Me,Re.sampleValues),Se=o.useRememberedTestInput(Oe&&!ge||ke?e:void 0,m.id),[xe,_e]=l.useState(!1);l.useEffect(()=>{if((!Oe||ge)&&!ke||!Se.loaded)return;if(!ke&&Se.input!==void 0){const Z=Se.input;if(Object.keys(Z).length===0)return;const X=JSON.stringify(Z,null,2);T(we=>we.trim()==="{}"?X:we),_e(!0);return}let k=!1;return E.listStepTests(e,m.id).then(Z=>{if(k)return;const X=Z.length?Z[Z.length-1]:null;if(!(X!=null&&X.input)||Object.keys(X.input).length===0)return;const we=JSON.stringify(X.input,null,2);T(Je=>Je.trim()==="{}"?we:Je)}).catch(()=>{}),()=>{k=!0}},[E,e,m.id,Oe,ge,ke,Se.loaded]);const Le=ke?fi(K):Ot(K),Fe={...m.with??{},...Le??{}},ct=Le??{},et=!!Q&&!fs(Be)&&o.requiredParamsFilled(Q,Fe)&&(m.uses.app!==o.CALL_APP||z),Y=ke?o.resolveLoopItemsInState(Fe.items,Me):void 0,[tt,Ge]=l.useState("idle"),wt=k=>{T(k),Ge("idle")},lt=async()=>{if(Y){Ge("saving");try{await E.saveStepTest(e,m.id,o.foreachTestFixture(Y,ct)),Ge("saved")}catch{Ge("failed")}}},fe=D.get(m.uses.app),xt=me?o.internalNodeIcon(m.uses.app,m.uses.action):null,bt=me?xt?t.jsx(o.InternalIcon,{icon:xt}):null:t.jsx(o.AppIcon,{src:fe==null?void 0:fe.iconSvg,srcDark:fe==null?void 0:fe.iconSvgDark,brandColor:fe==null?void 0:fe.brandColor,name:fe==null?void 0:fe.displayName});return t.jsx(o.Modal,{ariaLabel:"Edit step",titleIcon:bt,title:t.jsx(o.StepNameEditor,{value:m.id,onCommit:Pe,readOnly:p}),onClose:f??d,size:"wide",children:t.jsxs("div",{className:"w6w-stepconfig",children:[t.jsxs("div",{className:"w6w-tabsbar",children:[t.jsx("div",{className:"w6w-subtabs",children:["setup","configure","test"].filter(k=>m.uses.app!==o.RACE_APP||k!=="test").map(k=>t.jsx("button",{type:"button",className:`w6w-subtab${V===k?" active":""}`,disabled:C&&k!=="setup",onClick:()=>w(k),children:k==="setup"?"Setup":k==="configure"?"Configure":"Test"},k))}),qe?t.jsx(o.ConfigViewToggle,{view:de,views:["props","code"],onChange:k=>je(k)}):t.jsx(o.ConfigViewToggle,{view:_,customized:o.hasParamCustomization(m.with??{}),onChange:re,disabled:V!=="configure"})]}),C&&$&&t.jsxs("div",{role:"alert",className:"w6w-field-error",children:["Connection ",$.connection," no longer exists — choose another to continue."]}),G.length>0&&t.jsx("div",{className:"w6w-stepproblem-fixes",style:{display:"grid",gap:6},children:G.map(k=>t.jsxs("div",{className:"w6w-small",style:{display:"flex",gap:8,alignItems:"center"},children:[t.jsx("span",{children:o.stepProblemTooltip(k)}),t.jsx("button",{type:"button",className:"w6w-btn","data-fix-code":k.code,disabled:p,onClick:()=>{const Z=Nn(m,k);se(Z),N(o.stepToJson(Z))},children:"fix"in k?k.fix.label:""})]},k.code))}),t.jsxs("div",{className:"w6w-stepconfig-body",children:[V==="setup"&&m.uses.app===o.CALL_APP&&t.jsx(o.CallTargetForm,{values:m.with??{},onChange:k=>se({...m,with:k}),readOnly:p,onValidityChange:J,setupOnly:!0}),V==="setup"&&m.uses.app!==o.CALL_APP&&t.jsx(Ei,{step:m,app:fe,actions:it,conns:rt,connsFailed:Ue,isInternal:me,actionLabel:ae?"Trigger":"Action",readOnly:p,onChangeAction:k=>{var X;const Z=me?o.internalNodeDefaults(m.uses.app,k):{};if(me)for(const we of o.internalNodeParams(m.uses.app,k))we.key in(m.with??{})&&(Z[we.key]=(X=m.with)==null?void 0:X[we.key]);se({...m,uses:{...m.uses,action:k},with:Z})},onChangeTriggerEvents:(k,Z)=>se({...m,uses:{...m.uses,action:k},with:{...m.with,actions:Z}}),onChangeConnection:k=>{if(!O){const{connectionRef:X,...we}=m.uses;se({...m,uses:{...we,connection:k}});return}const Z=o.selectNodeConnection(m,k,(O==null?void 0:O.nodes)??[m],(O==null?void 0:O.connections)??{});O==null||O.setConnections(Z.connections),se(Z.step)},onChangeConnectionRef:k=>se(o.withConnectionRef(m,k)),onConnectionCreated:$e,onChangeApp:k=>{const Z=++Ne.current;if(k===m.uses.app){se(m);return}const X={...m,uses:{app:k,action:"",...ae?{trigger:!0}:{}},with:{}};(o.isInternalApp(k)?Promise.resolve([]):E.listConnectionsForApp(k)).catch(()=>[]).then(we=>{if(Z!==Ne.current)return;const Je=o.defaultConnectionFor(X,we,(O==null?void 0:O.nodes)??[],(O==null?void 0:O.connections)??{});se({...X,uses:{...X.uses,...Je}})})}}),V==="configure"&&t.jsxs(t.Fragment,{children:[m.uses.app===o.WEBHOOK_APP&&E.listSubscriptionsForWorkflow&&E.createSubscription&&t.jsx(ki,{workflowId:e,step:m,readOnly:p}),Q===null?t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):_==="props"?m.uses.app===o.CALL_APP?t.jsx(o.CallTargetForm,{values:m.with??{},onChange:k=>se({...m,with:k}),readOnly:p,onValidityChange:J}):m.uses.app===o.RACE_APP?t.jsx("p",{className:"w6w-muted w6w-small",children:o.RACE_DESCRIPTION}):m.uses.action==="wait"&&o.isControlApp(m.uses.app)?t.jsx(o.WaitEditor,{values:m.with??{},readOnly:p,onChange:k=>se({...m,with:k})}):m.uses.action==="if"&&o.isControlApp(m.uses.app)?t.jsx(o.ConditionEditor,{values:m.with??{},readOnly:p,onChange:k=>se({...m,with:k})}):m.uses.app==="@w6w/stop"?t.jsx(o.StopEditor,{values:m.with??{},readOnly:p,onChange:k=>se({...m,with:k})}):m.uses.app===o.ROUTER_APP?t.jsx(o.RouterEditor,{values:m.with??{},readOnly:p,onChange:k=>se({...m,with:k})}):t.jsxs(t.Fragment,{children:[m.uses.app===o.SCRIPT_APP&&t.jsx(vo,{values:m.with??{},conversion:gt,readOnly:p}),t.jsx(o.ParamsForm,{params:Q,values:m.with??{},readOnly:p,onChange:k=>se({...m,with:k}),dynamic:me||!m.uses.action?void 0:{appId:m.uses.app,actionKey:m.uses.action,connectionId:C?void 0:U,appName:fe==null?void 0:fe.displayName}})]}):_==="code"?t.jsx(o.JsonEditor,{value:ie,onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":`Node ${m.id} JSON`,copyable:!0}):_==="params-code"?t.jsx(o.ParamCustomization,{values:m.with??{},onChange:k=>se({...m,with:k}),readOnly:p}):t.jsxs("div",{className:"w6w-stack",children:[t.jsx(o.NodeConfigForm,{config:{retry:m.retry,onError:m.onError,notes:m.notes},onChange:k=>se({...m,...k}),readOnly:p,failureHandling:!ge,retryControls:!o.isControlApp(m.uses.app)&&m.uses.app!==o.CALL_APP}),Ni,t.jsx(o.StepFanOutControl,{step:m,count:b,readOnly:p,onChange:se}),o.stateWriteVisible(m)&&t.jsx(o.StepStateControl,{step:m,inLoop:a!==void 0,outputFields:g,readOnly:p,onChange:se})]})]}),V==="test"&&t.jsx("div",{className:"w6w-stack",children:Oe?ge?t.jsx(o.TriggerFillForm,{app:m.uses.app,action:m.uses.action,fields:ae||(jt=m.with)==null?void 0:jt.fields,appTrigger:ae,persist:{workflowId:e,stepId:m.id,input:ct},listen:m.uses.app===o.WEBHOOK_APP&&E.listSubscriptionsForWorkflow&&E.startWebhookListen?{stepWith:m.with,readOnly:p}:void 0}):t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:"w6w-muted w6w-small",children:["Tests ",t.jsx("code",{children:m.uses.action})," with the configuration saved on this step — only the incoming state changes per run."]}),t.jsx(An,{seed:Be,readOnly:p}),xe&&!p&&t.jsx(o.LastUsedNote,{onClear:()=>{Se.clear(),_e(!1),T("{}")}}),t.jsx(os,{text:K,onChange:T,seeds:ye,readOnly:p}),Q===null?t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):t.jsx(go,{params:Q,values:Fe,testStartState:at,view:de,literalKeys:m.uses.app===o.SCRIPT_APP?pi:void 0}),t.jsx(o.StepTestRun,{ref:W,app:m.uses.app,action:m.uses.action,connectionId:U,values:Fe,state:Me,canRun:et,hideRunButton:!0,persist:{workflowId:e,stepId:m.id,input:ct},onBusyChange:te})]}):ke?t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:"w6w-muted w6w-small",children:["Resolves ",t.jsx("strong",{children:"Items"})," against the incoming state — nothing inside the loop runs. ",t.jsx("strong",{children:"Test"})," saves the first item as this loop's sample, so the steps on its ",t.jsx("strong",{children:"Each item"})," output can pick its keys. To run the loop's work, test a step on ",t.jsx("strong",{children:"Each item"}),": it runs once, on one item."]}),t.jsx(os,{text:K,onChange:wt,seeds:ye,readOnly:p,expand:!Y,hint:t.jsxs(t.Fragment,{children:["Paste a sample list — ",t.jsx("code",{children:'[{"id": 1, "name": "…"}]'})," — or"," ",t.jsx("code",{children:'{"items": […]}'}),". It replaces what ",t.jsx("strong",{children:"Items"})," ","resolves to, for this test only."]})}),t.jsx(hi,{items:Y,save:tt})]}):t.jsx("p",{className:"w6w-muted w6w-small",children:"Flow-control nodes can't be tested on their own."})})]}),t.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[f&&!p&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:f,children:"Cancel"}),m.uses.app===o.RACE_APP&&V==="configure"?t.jsx("button",{type:"button",className:"w6w-btn",onClick:d,children:"Done"}):V!=="test"?t.jsxs(t.Fragment,{children:[f&&!p&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:d,children:"Done"}),t.jsx("button",{type:"button",className:"w6w-btn",disabled:C,onClick:()=>w(V==="setup"?"configure":"test"),children:"Next →"})]}):t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:d,children:"Done"}),Oe&&!ge&&t.jsx("button",{type:"button",className:"w6w-btn",disabled:p||!et||B,onClick:()=>{var k;S==null||S(),(k=W.current)==null||k.run()},children:B?"Testing…":"Test"}),ke&&t.jsx("button",{type:"button",className:"w6w-btn",disabled:p||!(Y!=null&&Y.length)||tt==="saving",onClick:()=>void lt(),children:tt==="saving"?"Testing…":"Test"})]})]})]})})}const Ni=!1;function ki({workflowId:e,step:s,readOnly:i}){const n=o.useW6WApi(),[a,u]=l.useState(void 0),[d,f]=l.useState(null),[p,x]=l.useState(!1);l.useEffect(()=>{const g=n.listSubscriptionsForWorkflow;if(!g)return;let S=!1;return g(e).then(v=>{S||u(o.pickWebhookSubscription(v,s.id))}).catch(v=>!S&&f(v.message)),()=>{S=!0}},[n,e,s.id]);const b=()=>{const g=n.createSubscription;g&&(f(null),x(!0),g(o.WEBHOOK_APP,s.uses.action,{workflowId:e,connectionId:null,params:s.with??{}}).then(S=>{x(!1),u(S)}).catch(S=>{x(!1),f(S instanceof Error?S.message:String(S))}))};return t.jsxs("div",{className:"w6w-stack",children:[t.jsxs("p",{className:"w6w-muted w6w-small",children:[t.jsx("strong",{children:"Webhook URL"})," — the address a third party posts to."]}),d&&t.jsx("div",{className:"w6w-result w6w-error",children:d}),a!=null&&a.webhookUrl?t.jsx(Ee.Copyable,{value:a.webhookUrl,readOnly:!0,children:t.jsx("input",{type:"text",readOnly:!0,value:a.webhookUrl,"aria-label":"Webhook URL"})}):a===void 0?t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}):!i&&t.jsx("button",{type:"button",className:"w6w-btn",disabled:p,onClick:b,children:p?"Creating…":"Create webhook URL"})]})}function Ei({step:e,app:s,actions:i,conns:n,connsFailed:a,isInternal:u,actionLabel:d="Action",readOnly:f,onChangeAction:p,onChangeTriggerEvents:x,onChangeConnection:b,onChangeConnectionRef:g,onChangeApp:S,onConnectionCreated:v}){const R=e.uses.trigger?o.eventbriteTriggerChoices(e.uses.app,i,e.uses.action,e.with??{}):null,[E,D]=l.useState(null),m=l.useRef(null),A=o.useWorkflowConnections(),O=o.connectionIdFor(e,A==null?void 0:A.connections);return t.jsxs("div",{className:"w6w-stack",children:[e.uses.connectionRef&&!O&&t.jsx("p",{role:"alert",className:"w6w-field-error",children:"The shared connection is missing or unbound. Choose an account."}),t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:"App"}),t.jsxs("div",{className:"w6w-app-conn-row",ref:m,children:[t.jsxs("button",{type:"button",className:"w6w-app-conn-btn","aria-label":"App","aria-expanded":E==="app",disabled:f,onClick:()=>D(U=>U==="app"?null:"app"),children:[!u&&s&&t.jsx(o.AppIcon,{src:s.iconSvg,srcDark:s.iconSvgDark,brandColor:s.brandColor,name:s.displayName,size:20}),t.jsx("span",{className:"w6w-conn-label-name",children:u?e.uses.app:(s==null?void 0:s.displayName)??e.uses.app})]}),!u&&t.jsx(o.WorkflowConnectionPicker,{step:e,conns:n,failed:a,readOnly:f,open:E==="conn",onOpenChange:U=>D(U?"conn":null),anchorRef:m,onChangeConnection:b,onChangeConnectionRef:g,onConnectionCreated:v})]}),E==="app"&&t.jsx(o.AnchoredFlyout,{anchorRef:m,onClose:()=>D(null),children:t.jsx(o.AppPicker,{onSelectApp:U=>{const P=U.id===e.uses.app;S(U.id),D(P?"conn":null)}})})]}),u&&!(i!=null&&i.length)?t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:"Action"}),t.jsx("div",{className:"w6w-muted w6w-small",children:t.jsx("code",{children:e.uses.action})})]}):R?t.jsx(o.EventbriteTriggerPicker,{choices:R,readOnly:f,onChange:U=>x(R.triggerKey,U)}):t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:d}),t.jsx(o.Combobox,{value:e.uses.action,disabled:f||i===null,onChange:p,options:i===null?[{value:e.uses.action,label:e.uses.action}]:i.map(U=>({value:U.key,label:U.title??U.key}))})]})]})}function fn({trigger:e}){return t.jsx("span",{className:"w6w-connection-node-kind",role:"img","aria-label":e?"Trigger":"Node",children:t.jsx("svg",{"aria-hidden":"true",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:e?t.jsx("path",{d:"M13 2 4 14h7l-1 8 10-12h-7l1-8Z"}):t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"5",y:"5",width:"14",height:"14",rx:"3"}),t.jsx("path",{d:"M2 12h3m14 0h3"})]})})})}function Ti({resources:e}){const s=o.useW6WApi(),i=e.highlightNode;l.useEffect(()=>()=>i==null?void 0:i(null),[i]);const[n,a]=l.useState([]),[u,d]=l.useState(!0),[f,p]=l.useState(),[x,b]=l.useState(),[g,S]=l.useState(null),[v,R]=l.useState(!1),[E,D]=l.useState(!1),m=l.useRef(0),A=l.useCallback(async()=>{const T=++m.current;d(!0),p(void 0);try{const W=await s.listConnections();return T!==m.current?void 0:(a(W),W)}catch(W){T===m.current&&p(W.message)}finally{T===m.current&&d(!1)}},[s]);l.useEffect(()=>(A(),()=>{m.current++}),[A]);const[O,U]=l.useState(new Map),P=JSON.stringify([...new Set([...Object.values(e.connections).map(T=>T.app),...n.map(T=>T.appId)])].filter(T=>{var W;return!((W=e.apps)!=null&&W.has(T))&&!n.some(B=>B.appId===T&&B.app!==void 0)}).sort());l.useEffect(()=>{var H,z;let T=!1;const W=JSON.parse(P);if(u||!W.length)return;const B=(H=s.listAppsByIds)==null?void 0:H.bind(s),te=B?Promise.all(Array.from({length:Math.ceil(W.length/50)},(J,Q)=>B(W.slice(Q*50,(Q+1)*50)))).then(J=>J.flat()):(z=s.listApps)==null?void 0:z.call(s);return te==null||te.then(J=>{T||U(new Map(J.map(Q=>[Q.id,Q])))}).catch(()=>{}),()=>{T=!0}},[s,P,u]);const M=T=>{var H;const W=n.find(z=>z.appId===T&&z.app)??n.find(z=>z.appId===T&&z.app!==void 0),B=W?o.resolveConnectionAppMeta(W,O):O.get(T),te=(H=e.apps)==null?void 0:H.get(T);return te?{...B,...te}:B},C=T=>{var W;return((W=M(T))==null?void 0:W.displayName)||T},$=T=>{if(e.readOnly)return!1;try{return e.edit(T),b(void 0),!0}catch(W){return b(W.message),!1}},G=T=>o.nextWorkflowConnectionName(T.appId,e.connections),V=()=>{S(null),b(void 0),R(!1)},w=g!=null&&g.ref?e.connections[g.ref]:void 0,_=n.find(T=>T.id===(g==null?void 0:g.connection)),le=(w==null?void 0:w.app)??(_==null?void 0:_.appId),de=e.nodes.filter(T=>T.uses.app===le),je=e.nodes.filter(T=>(g==null?void 0:g.ref)!==void 0&&T.uses.connectionRef===g.ref),ie=n.filter(T=>!w||T.appId===w.app).map(T=>({value:T.id,label:w?T.displayName||T.id:`${C(T.appId)} · ${T.displayName||T.id}`}));g!=null&&g.connection&&!ie.some(T=>T.value===g.connection)&&ie.unshift({value:g.connection,label:g.connection.startsWith("zerocred:")?"Built-in":g.connection});const N=(T,W=28)=>{const B=M(T);return t.jsx(o.AppIcon,{src:B==null?void 0:B.iconSvg,srcDark:B==null?void 0:B.iconSvgDark,brandColor:B==null?void 0:B.brandColor,name:C(T),size:W})},K=()=>{if(!g||!g.name.trim()||!g.connection||!le)return;const T=g.ref!==void 0?{type:"update",ref:g.ref,name:g.name,connection:g.connection,nodeIds:g.allNodes?de.map(W=>W.id):void 0}:{type:"add",name:g.name,app:le,connection:g.connection};$(T)&&V()};return t.jsxs("div",{className:"w6w-stack","data-testid":"workflow-connections-panel",children:[t.jsxs("div",{className:"w6w-workflow-connections-heading",children:[t.jsx("h3",{children:"Connections"}),t.jsx(o.IconButton,{label:"Add connection",disabled:e.readOnly,onClick:()=>{b(void 0),S({name:"",connection:"",allNodes:!1})},children:t.jsx("svg",{"aria-hidden":"true",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:t.jsx("path",{d:"M12 5v14M5 12h14"})})})]}),f&&t.jsxs("div",{role:"alert",className:"w6w-stack",children:[t.jsxs("p",{className:"w6w-field-error",children:["Couldn’t load connections: ",f]}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>void A(),children:"Retry"})]}),Object.entries(e.connections).map(([T,W])=>{var z;const B=e.nodes.filter(J=>J.uses.connectionRef===T),te=n.find(J=>J.id===W.connection),H=(te==null?void 0:te.displayName)||((z=W.connection)!=null&&z.startsWith("zerocred:")?"Built-in":W.connection)||"No credentials selected";return t.jsxs("section",{className:"w6w-workflow-connection","data-connection-resource":T,children:[t.jsxs("div",{className:"w6w-connection-app-heading",children:[N(W.app),t.jsxs("div",{className:"w6w-connection-summary",children:[t.jsx("strong",{children:C(W.app)}),t.jsx("span",{className:"w6w-small",children:H}),t.jsxs("span",{className:"w6w-muted w6w-small",children:[T,te!=null&&te.state?` · ${te.state}`:""]})]}),t.jsx(o.IconButton,{icon:"edit",label:`Edit connection ${T}`,disabled:e.readOnly,onClick:()=>{b(void 0),S({ref:T,name:T,connection:W.connection??"",allNodes:!1})}})]}),B.length>0?t.jsxs("details",{className:"w6w-connection-consumers",onToggle:J=>{J.currentTarget.open||i==null||i(null)},children:[t.jsxs("summary",{className:"w6w-muted w6w-small",children:["Used by ",B.length," ",B.length===1?"node":"nodes"]}),t.jsx("ul",{className:"w6w-connection-node-list",children:B.map(J=>t.jsx("li",{children:e.focusNode?t.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost","aria-label":`Show ${J.id} on canvas`,onClick:()=>{var Q;return(Q=e.focusNode)==null?void 0:Q.call(e,J.id)},onMouseEnter:()=>i==null?void 0:i(J.id),onMouseLeave:()=>i==null?void 0:i(null),onFocus:()=>i==null?void 0:i(J.id),onBlur:()=>i==null?void 0:i(null),children:[t.jsx(fn,{trigger:o.isTriggerStep(J.uses)}),t.jsxs("span",{className:"w6w-connection-node-label",children:[t.jsx("strong",{children:J.uses.action}),t.jsx("span",{className:"w6w-muted w6w-small",children:J.id})]})]}):t.jsxs("span",{className:"w6w-connection-app-heading",children:[t.jsx(fn,{trigger:o.isTriggerStep(J.uses)}),t.jsxs("span",{className:"w6w-connection-node-label",children:[t.jsx("strong",{children:J.uses.action}),t.jsx("span",{className:"w6w-muted w6w-small",children:J.id})]})]})},J.id))})]}):t.jsx("span",{className:"w6w-muted w6w-small",children:"Not used by any nodes yet."})]},T)}),!Object.keys(e.connections).length&&t.jsx("p",{className:"w6w-muted w6w-small",children:"No workflow connections yet."}),g&&!E&&!v&&t.jsxs(o.Modal,{title:g.ref!==void 0?"Edit connection":"Add connection",titleIcon:le?N(le):void 0,subtitle:le?C(le):void 0,onClose:V,children:[t.jsxs("div",{className:"w6w-modal-body w6w-stack",children:[x&&t.jsx("p",{role:"alert",className:"w6w-field-error",children:x}),f&&t.jsxs("div",{role:"alert",className:"w6w-stack",children:[t.jsxs("p",{className:"w6w-field-error",children:["Couldn’t load credentials: ",f]}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>void A(),children:"Retry"})]}),g.ref!==void 0&&!w&&t.jsx("p",{role:"alert",children:"This workflow connection no longer exists."}),t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Workflow connection name"}),t.jsx("input",{className:"w6w-input","aria-label":"Workflow connection name",value:g.name,disabled:e.readOnly,onChange:T=>S({...g,name:T.target.value})})]}),t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:w?"Credentials":"Existing connection"}),t.jsx(o.Combobox,{"aria-label":w?"Credentials":"Connection to add",options:ie,value:g.connection,placeholder:u?"Loading connections…":"Choose a connection…",disabled:e.readOnly||u||!!f,onChange:T=>{const W=n.find(B=>B.id===T);S({...g,connection:T,name:!g.name&&W?G(W):g.name})}})]}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:e.readOnly,onClick:()=>D(!0),children:"Create new credentials"}),w&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"w6w-muted w6w-small",children:g.allNodes?`Saving applies these credentials to all ${de.length} ${C(w.app)} nodes.`:`Saving updates credentials for ${je.length} linked ${je.length===1?"node":"nodes"}.`}),de.length>0&&t.jsxs("label",{className:"w6w-connection-scope",children:[t.jsx("input",{type:"checkbox",checked:g.allNodes||de.every(T=>T.uses.connectionRef===g.ref),disabled:e.readOnly||de.every(T=>T.uses.connectionRef===g.ref),onChange:T=>S({...g,allNodes:T.target.checked})}),"Use for all ",de.length," ",C(w.app)," ",de.length===1?"node":"nodes"," in this workflow"]}),t.jsxs("div",{className:"w6w-connection-remove",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:e.readOnly||je.length>0,onClick:()=>R(!0),children:"Remove from workflow"}),je.length>0&&t.jsx("p",{className:"w6w-muted w6w-small",children:"Assign another connection to the linked nodes before removing this one."})]})]})]}),t.jsxs("div",{className:"w6w-modal-actions",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:V,children:"Cancel"}),t.jsx("button",{type:"button",className:"w6w-btn",disabled:e.readOnly||u||!!f||!g.name.trim()||!g.connection||!le||g.ref!==void 0&&!w,onClick:K,children:g.ref!==void 0?"Save changes":"Add to workflow"})]})]}),g&&v&&t.jsx(o.ConfirmModal,{title:"Remove workflow connection",message:`Remove “${g.ref}” from this workflow? The saved credentials will remain available.`,confirmLabel:"Remove",onClose:()=>R(!1),onConfirm:()=>{g.ref&&$({type:"remove",ref:g.ref})?V():R(!1)}}),g&&E&&t.jsx(o.AddConnectionModal,{initialAppId:w==null?void 0:w.app,onClose:()=>D(!1),onCreated:({connectionId:T})=>{D(!1),A().then(W=>{const B=W==null?void 0:W.find(te=>te.id===T);B&&S(te=>te?{...te,connection:B.id,name:te.name||G(B)}:null)})}})]})}exports.CALL_APP=o.CALL_APP;exports.CONTROL_APP=o.CONTROL_APP;exports.CanvasLayer=o.CanvasLayer;exports.DATA_APP=o.DATA_APP;exports.ExpressionOptionsProvider=o.ExpressionOptionsProvider;exports.INTERNAL_NODES=o.INTERNAL_NODES;exports.Markdown=o.Markdown;exports.RACE_APP=o.RACE_APP;exports.SCHEDULER_APP=o.SCHEDULER_APP;exports.SCRIPT_APP=o.SCRIPT_APP;exports.TRIGGER_APP=o.TRIGGER_APP;exports.WEBHOOK_APP=o.WEBHOOK_APP;exports.asFieldDefs=o.asFieldDefs;exports.centralizeConnections=o.centralizeConnections;exports.coerceDefault=o.coerceDefault;exports.connectionIdFor=o.connectionIdFor;exports.fieldWidget=o.fieldWidget;exports.fieldsToParams=o.fieldsToParams;exports.flowToWorkflow=o.flowToWorkflow;exports.internalNodeDefaults=o.internalNodeDefaults;exports.internalNodeIcon=o.internalNodeIcon;exports.internalNodeLabel=o.internalNodeLabel;exports.internalNodeParams=o.internalNodeParams;exports.isControlApp=o.isControlApp;exports.isInternalApp=o.isInternalApp;exports.isTriggerApp=o.isTriggerApp;exports.isTriggerStep=o.isTriggerStep;exports.seedValues=o.seedValues;exports.workflowToFlow=o.workflowToFlow;exports.MAX_NOTES=hn;exports.MAX_NOTE_BYTES=gn;exports.MAX_SECTIONS=mn;exports.WorkflowConnectionsPanel=Ti;exports.WorkflowFlowEditor=di;exports.applyStepProblemFix=Nn;exports.assignMembership=Qt;exports.clampCanvas=es;exports.findLoopProblems=Wo;exports.findStateWriteProblems=Vo;exports.isDisabledStep=We;exports.isPausedStep=Qe;exports.pausedStopAt=ss;exports.pruneSectionMembers=is;exports.renameSectionMember=Zt;exports.roundGeometry=Yt;exports.sectionsContaining=xn;exports.withCanvasGeometry=wn;exports.withDisabled=Sn;exports.withPaused=vn;
|
|
1
|
+
"use client";"use strict";var mo=Object.defineProperty;var wo=(t,s,o)=>s in t?mo(t,s,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[s]=o;var at=(t,s,o)=>wo(t,typeof s!="symbol"?s+"":s,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),le=require("@xyflow/react"),u=require("react"),i=require("./connection-app-meta-Dk6F3KEH.cjs"),we=require("./CodeBlock-C1IC5_6O.cjs"),Ae=require("@w6w/expr");function go({x:t,y:s,items:o,onAction:n,onClose:r}){const c=u.useRef(null),[l,f]=u.useState({left:t,top:s});u.useLayoutEffect(()=>{const x=c.current,h=x==null?void 0:x.offsetParent;if(!x||!h)return;const m=x.offsetWidth,k=x.offsetHeight;f({left:t+m>h.clientWidth?Math.max(0,t-m):t,top:s+k>h.clientHeight?Math.max(0,s-k):s})},[t,s]),u.useEffect(()=>{var x,h;(h=(x=c.current)==null?void 0:x.querySelector("[role=menuitem]"))==null||h.focus({preventScroll:!0})},[]),u.useEffect(()=>{const x=k=>{var j;(j=c.current)!=null&&j.contains(k.target)||r(!1)},h=k=>{var j;(j=c.current)!=null&&j.contains(k.target)||r(!1)},m=()=>r(!1);return document.addEventListener("pointerdown",x,!0),document.addEventListener("scroll",h,!0),document.addEventListener("wheel",h,{capture:!0,passive:!0}),window.addEventListener("blur",m),window.addEventListener("resize",m),()=>{document.removeEventListener("pointerdown",x,!0),document.removeEventListener("scroll",h,!0),document.removeEventListener("wheel",h,!0),window.removeEventListener("blur",m),window.removeEventListener("resize",m)}},[r]);const d=x=>{x.disabled||(r(!1),n(x.action))};return e.jsx("div",{ref:c,className:"w6w-note-menu w6w-canvas-menu",role:"menu","aria-label":"Canvas actions","data-testid":"canvas-context-menu",style:{left:l.left,top:l.top},onContextMenu:x=>x.preventDefault(),onKeyDown:x=>{var j;x.stopPropagation();const h=[...((j=c.current)==null?void 0:j.querySelectorAll("[role=menuitem]"))??[]],m=h.indexOf(document.activeElement),k=y=>{var C;return(C=h[(y+h.length)%h.length])==null?void 0:C.focus()};if(x.key==="ArrowDown")k(m+1);else if(x.key==="ArrowUp")k(m<0?-1:m-1);else if(x.key==="Home")k(0);else if(x.key==="End")k(-1);else if(x.key==="Escape"||x.key==="Tab")r(!0);else if(x.key==="Enter"||x.key===" ")m>=0&&d(o[m]);else return;x.preventDefault()},children:o.map(x=>e.jsx("button",{type:"button",role:"menuitem",tabIndex:-1,"aria-disabled":x.disabled||void 0,className:`w6w-note-menu-item${x.danger?" danger":""}${x.separated?" separated":""}`,"data-action":x.action,onClick:()=>d(x),children:x.label},x.action))})}const nn=i.customCssTemplate();function xo({value:t,onChange:s,readOnly:o,stepId:n}){const r=u.useMemo(()=>vo(t),[t]),c=u.useMemo(()=>{var S;return r?((S=i.parseFormDefinition(r))==null?void 0:S.problems)??[]:[]},[r]),[l,f]=u.useState(null),[d,x]=u.useState(null),[h,m]=u.useState(null),[k,j]=u.useState(0);if(!r)return e.jsxs("div",{className:"w6w-result w6w-error",children:["This form is not a form definition (it may be set by an expression). Edit it in the Parameters code view, or reset it.",!o&&e.jsx("div",{children:e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-sm",onClick:()=>s(i.defaultFormDefinition()),children:"Reset to a starter form"})})]});const y=r.fields,C=S=>s({...r,...S}),M=S=>C({fields:S}),w=S=>new Set(y.filter(g=>g.id!==S&&g.name).map(g=>g.name)),F=(S,g)=>{const P=y.find(ne=>ne.id===S);if(!P)return;let Y=yo({...P,...g});if(g.label!==void 0&&i.isInputField(P.type)){const ne=w(S),Z=i.uniqueName(i.slugName(P.label??""),ne);(!P.name||P.name===Z)&&(Y={...Y,name:i.uniqueName(i.slugName(g.label||P.type),ne)})}const B=P.name&&Y.name!==P.name?P.name:null;M(y.map(ne=>{var Z;return ne.id===S?Y:B&&((Z=ne.showIf)==null?void 0:Z.field)===B&&Y.name?{...ne,showIf:{...ne.showIf,field:Y.name}}:ne}))},W=(S,g=y.length)=>{const P=on(y),Y=i.newField(S,P,w()),B=[...y];B.splice(g,0,Y),M(B),f(P)},O=(S,g)=>{const P=y.findIndex(Z=>Z.id===S);if(P<0)return;const Y=g>P?g-1:g;if(Y===P||Y<0||Y>=y.length)return;const B=[...y],[ne]=B.splice(P,1);B.splice(Y,0,ne),M(B)},I=S=>{const g=on(y),P={...structuredClone(S),id:g};P.name&&(P.name=i.uniqueName(P.name,w()));const Y=y.findIndex(ne=>ne.id===S.id)+1,B=[...y];B.splice(Y,0,P),M(B),f(g)},R=()=>{x(null),m(null)},E=(S,g)=>{if(S.preventDefault(),o)return R();d&&O(d,g),R()},V=(S,g)=>{if(o||!d)return;S.preventDefault(),S.dataTransfer.dropEffect="move";const P=S.currentTarget.getBoundingClientRect();m(S.clientY>P.top+P.height/2?g+1:g)},K=y.filter(S=>i.isInputField(S.type)&&S.name);return e.jsxs("div",{className:"w6w-form-builder","data-testid":"form-builder",children:[c.length>0&&e.jsx("ul",{className:"w6w-form-problems","data-testid":"form-problems",children:c.map(S=>e.jsxs("li",{children:[e.jsx(we.Icon,{name:"warning",size:12})," ",S.fieldId?e.jsx("button",{type:"button",className:"w6w-form-problem-link",onClick:()=>f(S.fieldId??null),children:S.message}):S.message]},`${S.fieldId??"form"}:${S.message}`))}),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Form title"}),e.jsx("input",{type:"text",value:r.title??"",disabled:o,"aria-label":"Form title",onChange:S=>C({title:S.target.value})})]}),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Description"}),e.jsx("textarea",{rows:2,value:r.description??"",disabled:o,"aria-label":"Form description",onChange:S=>C({description:S.target.value||void 0})})]}),e.jsxs("div",{className:"w6w-form-section-label",children:["Fields ",e.jsx("span",{className:"w6w-muted",children:"· drag to reorder"})]}),e.jsxs("div",{className:"w6w-form-fields","data-testid":"form-fields",onDragLeave:S=>{S.currentTarget.contains(S.relatedTarget)||m(null)},children:[y.length===0&&e.jsx("div",{className:`w6w-form-empty${h===0?" is-drop-target":""}`,onDragOver:S=>{o||!d||(S.preventDefault(),m(0))},onDrop:S=>E(S,0),children:"No fields yet. Add one below."}),y.map((S,g)=>{const P=l===S.id,Y=["w6w-form-field",P?"is-open":"",d===S.id?"is-dragging":"",h===g?"is-drop-before":"",h===g+1&&g===y.length-1?"is-drop-after":"",S.type==="pageBreak"?"is-page-break":""].filter(Boolean).join(" ");return e.jsxs("div",{className:Y,"data-field-id":S.id,onDragOver:B=>V(B,g),onDrop:B=>E(B,h??g),children:[e.jsxs("div",{className:"w6w-form-field-head",children:[e.jsx("button",{type:"button",className:"w6w-icon-btn w6w-router-grip",draggable:!o,disabled:o,"aria-label":`Reorder ${Lt(S)}`,title:"Drag to reorder · arrow keys to move",onDragStart:B=>{B.dataTransfer.effectAllowed="move",B.dataTransfer.setData("text/plain",S.id);const ne=B.currentTarget.closest(".w6w-form-field");ne&&B.dataTransfer.setDragImage(ne,16,16),x(S.id)},onDragEnd:R,onKeyDown:B=>{B.key!=="ArrowUp"&&B.key!=="ArrowDown"||(B.preventDefault(),O(S.id,B.key==="ArrowUp"?g-1:g+2))},children:e.jsx(we.Icon,{name:"grip",size:14})}),e.jsxs("button",{type:"button",className:"w6w-form-field-summary","aria-expanded":P,onClick:()=>f(P?null:S.id),children:[e.jsx("span",{className:"w6w-form-field-type",children:i.FIELD_TYPE_LABELS[S.type]}),e.jsxs("span",{className:"w6w-form-field-label",children:[Lt(S),S.required?e.jsx("span",{className:"w6w-form-req",children:" *"}):null]}),S.name&&i.isInputField(S.type)&&e.jsx("code",{className:"w6w-form-field-name",children:S.name}),S.showIf&&e.jsx("span",{className:"w6w-form-field-badge",title:"Shown only when a condition holds",children:"if"}),e.jsx(we.Icon,{name:"chevron-down",size:12})]}),!o&&e.jsx(i.IconButton,{label:`Duplicate ${Lt(S)}`,icon:"copy",onClick:()=>I(S)}),e.jsx(i.DeleteButton,{label:`Remove ${Lt(S)}`,disabled:o,onClick:()=>M(y.filter(B=>B.id!==S.id))})]}),P&&e.jsx(ko,{field:S,earlier:K.filter(B=>y.indexOf(B)<g&&B.id!==S.id),readOnly:o,stepId:n,onPatch:B=>F(S.id,B)})]},S.id)})]}),!o&&e.jsx(i.Combobox,{className:"w6w-form-add",mode:"combobox","aria-label":"Add a field",placeholder:"+ Add a field…",options:jo,value:"",onChange:S=>{W(S),j(g=>g+1)}},k),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Submit button label"}),e.jsx("input",{type:"text",value:r.submitLabel??"",placeholder:"Submit",disabled:o,"aria-label":"Submit button label",onChange:S=>C({submitLabel:S.target.value||void 0})})]}),e.jsx(To,{form:r,save:C,readOnly:o}),e.jsx(Ao,{form:r,save:C,readOnly:o})]})}const bo=[{title:"Text",types:["text","textarea","email","number","phone","url","password"]},{title:"Choice",types:["select","radio","checkboxes","checkbox","rating"]},{title:"Date & time",types:["date","time","datetime"]},{title:"Other",types:["file","hidden"]},{title:"Layout",types:["heading","paragraph","pageBreak"]}],jo=bo.flatMap(t=>t.types.map(s=>({value:s,label:i.FIELD_TYPE_LABELS[s],group:t.title,keywords:`${t.title} ${s}`})));function vo(t){if(t==null||t==="")return i.defaultFormDefinition();let s=t;if(typeof s=="string")try{s=JSON.parse(s)}catch{return null}if(!s||typeof s!="object"||Array.isArray(s))return null;const o=s;if(!Array.isArray(o.fields))return null;if(o.fields.every(r=>r&&typeof r.id=="string"&&r.id))return o;const n=new Set;return{...o,fields:o.fields.filter(r=>r&&typeof r=="object").map((r,c)=>{let l=typeof r.id=="string"&&r.id&&!n.has(r.id)?r.id:`f_${c+1}`;for(;n.has(l);)l=`${l}_`;return n.add(l),{...r,id:l}})}}function on(t){const s=new Set(t.map(o=>o.id));for(;;){const o=`f_${Math.random().toString(36).slice(2,8)}`;if(!s.has(o))return o}}function yo(t){const s={};for(const[o,n]of Object.entries(t))n===void 0||n===""||(s[o]=n);return s}function Lt(t){return t.type==="pageBreak"?t.label?`New page: ${t.label}`:"New page":t.type==="paragraph"?So(t.help??"")||"Paragraph":t.label||t.name||i.FIELD_TYPE_LABELS[t.type]}function So(t,s=60){return t.length>s?`${t.slice(0,s-1)}…`:t}const No=t=>{if(t.trim()==="")return;const s=Number(t);return Number.isFinite(s)?s:void 0},Co={equals:"is",notEquals:"is not",contains:"contains",notContains:"does not contain",isEmpty:"is empty",isNotEmpty:"is not empty",greaterThan:"is greater than",lessThan:"is less than"};function ko({field:t,earlier:s,readOnly:o,stepId:n,onPatch:r}){const c=t.type,l=i.isInputField(c),f=i.CHOICE_FIELD_TYPES.has(c),d=i.TEXT_FIELD_TYPES.has(c),x=c==="checkboxes"||c==="select"&&t.multiple,h=(j,y,C={})=>e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:j}),C.area?e.jsx("textarea",{rows:3,value:String(t[y]??""),placeholder:C.placeholder,disabled:o,"aria-label":j,onChange:M=>r({[y]:M.target.value||void 0})}):e.jsx("input",{type:"text",value:String(t[y]??""),placeholder:C.placeholder,disabled:o,"aria-label":j,onChange:M=>r({[y]:M.target.value||void 0})}),C.hint&&e.jsx("span",{className:"w6w-hint",children:C.hint})]},String(y)),m=(j,y,C)=>e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:j}),e.jsx("input",{type:"number",value:t[y]===void 0?"":String(t[y]),placeholder:C,disabled:o,"aria-label":j,onChange:M=>r({[y]:No(M.target.value)})})]},String(y)),k=(j,y)=>e.jsxs("label",{className:"w6w-form-check",children:[e.jsx("input",{type:"checkbox",checked:!!t[y],disabled:o,onChange:C=>r({[y]:C.target.checked||void 0})}),j]},String(y));return c==="pageBreak"?e.jsxs("div",{className:"w6w-form-field-body",children:[h("Next page title","label",{placeholder:"Optional"}),e.jsx("span",{className:"w6w-hint",children:"Everything below this starts a new page with Back / Next."})]}):c==="heading"?e.jsxs("div",{className:"w6w-form-field-body",children:[h("Heading","label"),h("Text under the heading","help",{area:!0}),e.jsx(Zt,{field:t,earlier:s,readOnly:o,onPatch:r})]}):c==="paragraph"?e.jsxs("div",{className:"w6w-form-field-body",children:[h("Text","help",{area:!0}),e.jsx(Zt,{field:t,earlier:s,readOnly:o,onPatch:r})]}):e.jsxs("div",{className:"w6w-form-field-body",children:[e.jsxs("div",{className:"w6w-field-row",children:[h(c==="hidden"?"Description":"Label","label"),h("Answer key","name",{hint:t.name?e.jsxs(e.Fragment,{children:["Use as ",e.jsx("code",{children:`{{ nodes.${n??"<trigger>"}.output.data.${t.name} }}`})]}):"Letters, digits and _."})]}),c==="hidden"?h("Value","defaultValue",{hint:"Recorded with every response. A ?name=value in the form URL overrides it."}):e.jsxs(e.Fragment,{children:[h("Help text","help",{placeholder:"Shown under the label"}),(d||c==="number"||c==="select")&&h("Placeholder","placeholder"),e.jsxs("div",{className:"w6w-form-checks",children:[l&&k("Required","required"),c==="select"&&k("Allow several choices","multiple"),f&&k('Offer an "Other" answer',"allowOther"),c==="file"&&k("Allow several files","multiple"),e.jsxs("label",{className:"w6w-form-check",children:[e.jsx("input",{type:"checkbox",checked:t.width==="half",disabled:o,onChange:j=>r({width:j.target.checked?"half":void 0})}),"Half width"]})]})]}),f&&e.jsx(Eo,{options:t.options??[],readOnly:o,onChange:j=>r({options:j})}),d&&e.jsxs("div",{className:"w6w-field-row",children:[m("Min length","minLength"),m("Max length","maxLength")]}),d&&c!=="email"&&c!=="url"&&e.jsxs("div",{className:"w6w-field-row",children:[h("Pattern (regular expression)","pattern",{placeholder:"e.g. [A-Z]{2}\\d{4}"}),t.pattern&&h("Message when it does not match","patternMessage")]}),c==="textarea"&&m("Rows","rows","4"),c==="number"&&e.jsxs("div",{className:"w6w-field-row",children:[m("Min","min"),m("Max","max"),m("Step","step","any")]}),c==="rating"&&m("Stars","max","5"),(c==="date"||c==="time"||c==="datetime")&&e.jsxs("div",{className:"w6w-field-row",children:[h("Earliest","minDate",{placeholder:rn(c)}),h("Latest","maxDate",{placeholder:rn(c)})]}),x&&e.jsxs("div",{className:"w6w-field-row",children:[m("Pick at least","minSelected"),m("Pick at most","maxSelected")]}),c==="file"&&e.jsxs("div",{className:"w6w-field-row",children:[h("Accepted types","accept",{placeholder:".pdf,image/*"}),m("Max size per file (MB)","maxFileSizeMb","10"),t.multiple&&m("Max files","maxFiles")]}),c!=="hidden"&&c!=="file"&&c!=="checkboxes"&&c!=="checkbox"&&!x&&h("Default answer","defaultValue",{hint:"A ?name=value in the form URL overrides it."}),c==="checkbox"&&e.jsxs("label",{className:"w6w-form-check",children:[e.jsx("input",{type:"checkbox",checked:t.defaultValue===!0,disabled:o,onChange:j=>r({defaultValue:j.target.checked||void 0})}),"Checked by default"]}),c!=="hidden"&&e.jsx(Zt,{field:t,earlier:s,readOnly:o,onPatch:r})]})}function rn(t){return t==="time"?"09:00":t==="datetime"?"2026-01-31T09:00":"2026-01-31"}function Zt({field:t,earlier:s,readOnly:o,onPatch:n}){var f;const r=t.showIf;if(!r)return s.length===0||o?null:e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-form-cond-add",onClick:()=>n({showIf:{field:s[s.length-1].name??"",op:"equals",value:""}}),children:"+ Show only when…"});const c=r.op!=="isEmpty"&&r.op!=="isNotEmpty",l=s.find(d=>d.name===r.field);return e.jsxs("div",{className:"w6w-form-cond","data-testid":"form-condition",children:[e.jsx("span",{className:"w6w-small",children:"Show only when"}),e.jsxs("select",{value:r.field,disabled:o,"aria-label":"Depends on",onChange:d=>n({showIf:{...r,field:d.target.value}}),children:[!l&&e.jsx("option",{value:r.field,children:r.field||"—"}),s.map(d=>e.jsx("option",{value:d.name,children:d.label||d.name},d.id))]}),e.jsx("select",{value:r.op,disabled:o,"aria-label":"Comparison",onChange:d=>n({showIf:{...r,op:d.target.value}}),children:i.CONDITION_OPS.map(d=>e.jsx("option",{value:d,children:Co[d]},d))}),c&&((f=l==null?void 0:l.options)!=null&&f.length?e.jsxs("select",{value:r.value??"",disabled:o,"aria-label":"Value",onChange:d=>n({showIf:{...r,value:d.target.value}}),children:[e.jsx("option",{value:"",children:"—"}),l.options.map(d=>e.jsx("option",{value:d.value||d.label,children:d.label},d.value??d.label))]}):e.jsx("input",{type:"text",value:r.value??"",disabled:o,"aria-label":"Value",placeholder:(l==null?void 0:l.type)==="checkbox"?"true":"value",onChange:d=>n({showIf:{...r,value:d.target.value}})})),e.jsx(i.DeleteButton,{label:"Remove condition",disabled:o,onClick:()=>n({showIf:void 0})})]})}function Eo({options:t,readOnly:s,onChange:o}){const[n,r]=u.useState(null),[c,l]=u.useState(null),f=(x,h)=>{if(h<0||h>=t.length||x===h)return;const m=[...t],[k]=m.splice(x,1);m.splice(h,0,k),o(m)},d=(x,h)=>o(t.map((m,k)=>{if(k!==x)return m;const{value:j,...y}={...m,...h};return j?{...y,value:j}:y}));return e.jsxs("div",{className:"w6w-form-options","data-testid":"form-options",children:[e.jsx("span",{className:"w6w-small w6w-muted",children:"Options · the value is recorded (defaults to the label)"}),t.map((x,h)=>e.jsxs("div",{className:`w6w-form-option${n===h?" is-dragging":""}${c===h?" is-drop-before":""}`,onDragOver:m=>{s||n===null||n===h||(m.preventDefault(),l(h))},onDrop:m=>{m.preventDefault(),n!==null&&f(n,h),r(null),l(null)},children:[e.jsx("button",{type:"button",className:"w6w-icon-btn w6w-router-grip",draggable:!s,disabled:s,"aria-label":`Reorder option ${x.label}`,title:"Drag to reorder · arrow keys to move",onDragStart:m=>{m.dataTransfer.effectAllowed="move",m.dataTransfer.setData("text/plain",String(h)),r(h)},onDragEnd:()=>{r(null),l(null)},onKeyDown:m=>{m.key!=="ArrowUp"&&m.key!=="ArrowDown"||(m.preventDefault(),f(h,h+(m.key==="ArrowUp"?-1:1)))},children:e.jsx(we.Icon,{name:"grip",size:12})}),e.jsx("input",{type:"text",value:x.label,disabled:s,"aria-label":`Option ${h+1} label`,onChange:m=>d(h,{label:m.target.value})}),e.jsx("input",{type:"text",value:x.value??"",placeholder:x.label,disabled:s,"aria-label":`Option ${h+1} value`,onChange:m=>d(h,{value:m.target.value})}),e.jsx(i.DeleteButton,{label:`Remove option ${x.label}`,disabled:s,onClick:()=>o(t.filter((m,k)=>k!==h))})]},h)),!s&&e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-router-add",onClick:()=>{let x=t.length+1;for(;t.some(h=>h.label===`Option ${x}`);)x++;o([...t,{label:`Option ${x}`}])},children:"+ Add option"})]})}function To({form:t,save:s,readOnly:o}){const n=t.completion??{},r=l=>{const f={...n,...l};for(const d of Object.keys(f))(f[d]===void 0||f[d]==="")&&delete f[d];s({completion:f})},c=n.type==="redirect";return e.jsxs("details",{className:"w6w-section w6w-form-group","data-testid":"form-completion",children:[e.jsxs("summary",{className:"w6w-section-summary",children:[e.jsx("span",{className:"w6w-section-title",children:"After submitting"}),e.jsx("span",{className:"w6w-section-subtitle",children:c?`Redirect to ${n.redirectUrl||"…"}`:n.title||"Thank-you message"})]}),e.jsxs("div",{className:"w6w-form-group-body",children:[e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Show"}),e.jsxs("select",{value:c?"redirect":"message",disabled:o,"aria-label":"Completion",onChange:l=>r({type:l.target.value}),children:[e.jsx("option",{value:"message",children:"A thank-you message"}),e.jsx("option",{value:"redirect",children:"Redirect to a URL"})]})]}),c?e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Redirect URL"}),e.jsx("input",{type:"text",value:n.redirectUrl??"",placeholder:"https://example.com/thanks?email={{email}}",disabled:o,"aria-label":"Redirect URL",onChange:l=>r({redirectUrl:l.target.value})}),e.jsxs("span",{className:"w6w-hint",children:[e.jsx("code",{children:"{{name}}"})," inserts that answer (URL-encoded)."]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{type:"text",value:n.title??"",placeholder:"Thank you!",disabled:o,"aria-label":"Completion title",onChange:l=>r({title:l.target.value})})]}),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Message"}),e.jsx("textarea",{rows:2,value:n.message??"",disabled:o,"aria-label":"Completion message",onChange:l=>r({message:l.target.value})}),e.jsxs("span",{className:"w6w-hint",children:[e.jsx("code",{children:"{{name}}"})," inserts that answer. With “Wait for the workflow to finish”, a Respond to Webhook step can replace this screen."]})]}),e.jsxs("label",{className:"w6w-form-check",children:[e.jsx("input",{type:"checkbox",checked:!!n.allowAnother,disabled:o,onChange:l=>r({allowAnother:l.target.checked||void 0})}),"Offer “Submit another response”"]})]})]})]})}function Ao({form:t,save:s,readOnly:o}){const n=t.settings??{},r=l=>{const f={...n,...l};for(const d of Object.keys(f))(f[d]===void 0||f[d]==="")&&delete f[d];s({settings:f})},c=(l,f,d)=>e.jsxs("label",{className:"w6w-form-check",children:[e.jsx("input",{type:"checkbox",checked:n[f]??d,disabled:o,onChange:x=>r({[f]:x.target.checked})}),l]});return e.jsxs("details",{className:"w6w-section w6w-form-group","data-testid":"form-settings",children:[e.jsxs("summary",{className:"w6w-section-summary",children:[e.jsx("span",{className:"w6w-section-title",children:"Page settings"}),e.jsxs("span",{className:"w6w-section-subtitle",children:[n.closed?"Closed":"Open"," · ",n.theme??"auto"," theme"]})]}),e.jsxs("div",{className:"w6w-form-group-body",children:[e.jsxs("div",{className:"w6w-form-checks",children:[c("Pre-fill from ?name=value in the URL","allowPrefill",!0),c("Show page progress","showProgress",!0),e.jsxs("label",{className:"w6w-form-check",children:[e.jsx("input",{type:"checkbox",checked:!!n.hideBranding,disabled:o,onChange:l=>r({hideBranding:l.target.checked||void 0})}),"Hide “Powered by w6w”"]})]}),e.jsxs("div",{className:"w6w-field-row",children:[e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Theme"}),e.jsxs("select",{value:n.theme??"auto",disabled:o,"aria-label":"Theme",onChange:l=>r({theme:l.target.value}),children:[e.jsx("option",{value:"auto",children:"Follow the visitor's system"}),e.jsx("option",{value:"light",children:"Light"}),e.jsx("option",{value:"dark",children:"Dark"})]})]}),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Accent colour"}),e.jsxs("span",{className:"w6w-form-color",children:[e.jsx("input",{type:"color",value:/^#[0-9a-f]{6}$/i.test(n.accentColor??"")?n.accentColor:"#3355e6",disabled:o,"aria-label":"Accent colour picker",onChange:l=>r({accentColor:l.target.value})}),e.jsx("input",{type:"text",value:n.accentColor??"",placeholder:"#3355e6",disabled:o,"aria-label":"Accent colour",onChange:l=>r({accentColor:l.target.value})})]})]})]}),e.jsxs("label",{className:"w6w-form-check",children:[e.jsx("input",{type:"checkbox",checked:!!n.closed,disabled:o,onChange:l=>r({closed:l.target.checked||void 0})}),"Closed — stop accepting responses"]}),n.closed&&e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Closed message"}),e.jsx("input",{type:"text",value:n.closedMessage??"",placeholder:"This form is no longer accepting responses.",disabled:o,"aria-label":"Closed message",onChange:l=>r({closedMessage:l.target.value})})]}),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Custom CSS"}),e.jsx("textarea",{rows:8,className:"w6w-form-css",value:n.customCss??nn,spellCheck:!1,wrap:"off",disabled:o,"aria-label":"Custom CSS",onChange:l=>r({customCss:l.target.value===nn?void 0:l.target.value})})]})]})]})}function Io(t,s,o,n){return t.find(r=>r.nodeId===s&&r.appId===o&&r.triggerKey===n)??null}function Po(t){return(t??"").split(`
|
|
2
|
+
`).map(s=>s.trim().replace(/^(\d+[.)]|[-•*])\s+/,"")).filter(s=>s!=="")}function Ro({workflowId:t,nodeId:s,appId:o,triggerKey:n,appName:r,setup:c,connectionId:l,params:f,readOnly:d}){const x=i.useW6WApi(),[h,m]=u.useState(void 0),[k,j]=u.useState(null),y=u.useRef(null),C=JSON.stringify({connectionId:l,params:f});u.useEffect(()=>{const O=x.listSubscriptionsForWorkflow,I=x.createSubscription;if(!O){m(null);return}let R=!1;return m(void 0),j(null),y.current=null,(async()=>{const E=Io(await O.call(x,t),s,o,n);if(d||!I||E&&E.status!=="pending")return E;const V=await I.call(x,o,n,{workflowId:t,connectionId:l,params:f,nodeId:s});return y.current=C,V})().then(E=>!R&&m(E)).catch(E=>{R||(m(null),j(E instanceof Error?E.message:String(E)))}),()=>{R=!0}},[x,t,s,o,n,d]);const M=(h==null?void 0:h.status)==="pending"?h.id:null;u.useEffect(()=>{const O=x.createSubscription;if(!M||d||!O||y.current===null||y.current===C)return;const I=setTimeout(()=>{y.current=C,O.call(x,o,n,{workflowId:t,connectionId:l,params:f,nodeId:s}).then(R=>{j(null),m(R)}).catch(R=>j(R instanceof Error?R.message:String(R)))},600);return()=>clearTimeout(I)},[x,M,d,C,o,n,t,s]);const w=h==null?void 0:h.webhookUrl,F=Po(c.instructions),W=(h==null?void 0:h.lastFireAt)??null;return e.jsxs("div",{className:"w6w-stack w6w-url-panel","data-testid":"manual-webhook-panel",children:[e.jsxs("p",{className:"w6w-muted w6w-small",children:[e.jsx("strong",{children:"Webhook URL"})," — ",r," sends its events here."]}),k&&e.jsx("div",{className:"w6w-result w6w-error",children:k}),w?e.jsx("div",{className:"w6w-listen-url",children:e.jsx(we.Copyable,{value:w,readOnly:!0,children:e.jsx("input",{type:"text",readOnly:!0,value:w,"aria-label":"Webhook URL"})})}):h===void 0?e.jsx("p",{className:"w6w-muted w6w-small",children:"Getting the webhook URL…"}):!k&&e.jsx("p",{className:"w6w-muted w6w-small",children:"The webhook URL appears once the workflow is saved."}),e.jsxs("div",{className:"w6w-manual-webhook-note",role:"note","data-testid":"manual-webhook-note",children:[e.jsxs("strong",{children:["Add this URL in ",r," before the trigger works."]})," W6W can't add it for you, and nothing reaches this trigger until it is there."]}),F.length>0&&e.jsxs("div",{className:"w6w-manual-webhook-steps",children:[e.jsxs("span",{className:"w6w-small",children:["How to add it in ",r]}),e.jsx("ol",{className:"w6w-small","data-testid":"manual-webhook-steps",children:F.map((O,I)=>e.jsx("li",{children:O},I))})]}),h&&e.jsx("p",{className:"w6w-muted w6w-small","data-testid":"manual-webhook-status",children:W?`Last event received ${new Date(W).toLocaleString()}.`:h.status==="registered"?`Listening. No event from ${r} yet.`:"Starts the workflow once it is published."})]})}function Fo(t,s){return s===void 0?[...t]:t.includes(s)?[...t]:[s]}function Do(t,s,o={}){const n=[],r=t.length;if(r>0){const c=r>1?` ${r} nodes`:"";n.push({action:"duplicate",label:`Duplicate${c}`,disabled:s}),r===1&&o.replaceableTrigger&&n.push({action:"replace-trigger",label:"Replace trigger",disabled:s}),n.push({action:"delete",label:`Delete${c}`,disabled:s,danger:!0})}return n.push({action:"add-node",label:"Add node",disabled:s,separated:r>0}),n.push({action:"add-trigger",label:"Add trigger",disabled:s}),n}const Nn=200,Cn=200,kn=10240;function ns(t){const s={};for(const[o,n]of Object.entries(t))s[o]=Math.round(n);return s}const Lo=t=>!!t&&Number.isFinite(t.x)&&Number.isFinite(t.y),Mo=t=>!!t&&Number.isFinite(t.width)&&Number.isFinite(t.height);function an(t,s,o){return t&&t.map(n=>{const r=s==null?void 0:s[n.id],c=Lo(r==null?void 0:r.position)?r.position:n.position,l=Mo(r==null?void 0:r.size)?r.size:n.size;return{...n,position:ns(c),size:ns(l)}})}function En(t,s,o){if(!s)return t;const n={...t};return t.notes&&(n.notes=an(t.notes,o)),t.sections&&(n.sections=an(t.sections,o)),n}function us(t,s){return t.sections?{...t,sections:t.sections.map(o=>({...o,nodes:o.nodes.filter(n=>n!==s)}))}:t}function os(t,s,o){return t.sections?{...t,sections:t.sections.map(n=>({...n,nodes:n.nodes.map(r=>r===s?o:r)}))}:t}function is(t,s,o){if(!t.sections)return t;const n=new Set(o);return{...t,sections:t.sections.map(r=>{const c=r.nodes.filter(l=>!n.has(l));return r.id===s?{...r,nodes:[...new Set([...c,...o])]}:{...r,nodes:c}})}}function Tn(t,s){return(t.sections??[]).filter(o=>o.nodes.includes(s)).map(o=>o.id)}function _o(t,s){const o=new TextEncoder;if(o.encode(t).length<=s)return t;let n="",r=0;for(const c of t){const l=o.encode(c).length;if(r+l>s)break;n+=c,r+=l}return n}function rs(t){const s={...t};return t.notes&&(s.notes=t.notes.slice(0,Nn).map(o=>({...o,content:_o(o.content,kn)}))),t.sections&&(s.sections=t.sections.slice(0,Cn)),s}function Oo(t,s,o){const n={};for(const l of[...t.notes??[],...t.sections??[]])n[l.id]={position:l.position,size:l.size};const r=(l,f)=>l==null?void 0:l.map(d=>{const x=f==null?void 0:f.find(h=>h.id===d.id);return x?{...d,position:x.position,size:x.size}:d}),c=o?t:{...t,...t.notes?{notes:r(t.notes,s==null?void 0:s.notes)}:{},...t.sections?{sections:r(t.sections,s==null?void 0:s.sections)}:{}};return En(c,o,n)}const ln=220;function $o(t){return t.length<=ln?{text:t,clipped:!1,length:t.length}:{text:t.slice(0,ln).trimEnd(),clipped:!0,length:t.length}}function Wo({params:t,values:s,testStartState:o,view:n="props",literalKeys:r}){const{sampleValues:c,nodeConfig:l,nodeMeta:f}=i.useExpressionOptions(),d=u.useMemo(()=>i.buildResolveScope(c,o,l,f),[c,o,l,f]),x=i.flattenParams(t),h=j=>{var y;return s[j]!==void 0?s[j]:(y=x.find(C=>C.key===j))==null?void 0:y.default},m=x.filter(j=>j.type!=="section"&&i.isParamVisible(j,h)).map(j=>Ae.effectiveParam(j,h));if(i.hasParamCustomization(s)){const j=i.previewCustomization(s.$merge,d,r),y=j!==null&&typeof j=="object"&&!Array.isArray(j),C=cn(m,s,d,r);for(const[w,F]of Object.entries(s))w!=="$merge"&&(C[w]=r!=null&&r.includes(w)?F:i.previewCustomization(F,d));const M=y?{...C,...j}:C;return e.jsxs("div",{className:"w6w-resolved-params",children:[e.jsx("p",{className:"w6w-muted w6w-small",children:y?"JSON customization applied after form values.":`JSON customization is not available as an object in this preview (${String(j)}). Test the step to validate it.`}),n==="code"?e.jsx(i.JsonEditor,{value:JSON.stringify(M,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"}):e.jsx("div",{className:"w6w-resolved-table",children:Object.entries(M).map(([w,F])=>{var W;return e.jsx(as,{label:((W=x.find(O=>O.key===w))==null?void 0:W.label)??w,segments:[{status:"resolved",value:F}]},w)})})]})}if(n==="code"){const j=cn(m,s,d,r);return e.jsx("div",{className:"w6w-resolved-params",children:e.jsx(i.JsonEditor,{value:JSON.stringify(j,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"})})}const k=m.filter(j=>!i.deepEqual(h(j.key),j.default));return m.length===0?e.jsx("div",{className:"w6w-resolved-params",children:e.jsx("p",{className:"w6w-muted w6w-small",children:"This action takes no parameters."})}):k.length===0?e.jsx("div",{className:"w6w-resolved-params",children:e.jsx("p",{className:"w6w-muted w6w-small",children:"Every configured value matches its default — nothing to show here. Switch to JSON to see the full set."})}):e.jsx("div",{className:"w6w-resolved-params w6w-resolved-table",children:k.map(j=>j.type==="vars"?e.jsx(Bo,{param:j,value:s[j.key],scope:d},j.key):e.jsx(as,{label:j.label??j.key,segments:r!=null&&r.includes(j.key)?[{status:"resolved",value:h(j.key)}]:i.resolveParamValue(h(j.key),d)},j.key))})}function cn(t,s,o,n){const r={};for(const c of t)if(n!=null&&n.includes(c.key))r[c.key]=s[c.key]!==void 0?s[c.key]:c.default;else if(c.type==="vars"){const l=s[c.key]??c.default??[],f=i.dataVarRows(l);r[c.key]=f?i.resolveVarsJson(f,o):i.resolveParamJson(l,o)}else r[c.key]=i.resolveParamJson(s[c.key]!==void 0?s[c.key]:c.default,o);return r}function as({label:t,segments:s}){return e.jsxs("div",{className:"w6w-resolved-row",children:[e.jsx("span",{className:"w6w-resolved-label",children:t}),e.jsx("div",{className:"w6w-resolved-value",children:e.jsx(An,{segments:s})})]})}function Bo({param:t,value:s,scope:o}){const n=s??t.default??[],r=i.dataVarRows(n);return r===null?e.jsx(as,{label:t.label??t.key,segments:i.resolveParamValue(n,o)}):e.jsxs("div",{className:"w6w-resolved-row",children:[e.jsx("span",{className:"w6w-resolved-label",children:t.label??t.key}),r.length===0?e.jsx("p",{className:"w6w-muted w6w-small",children:"None configured."}):e.jsx("div",{className:"w6w-stack",children:r.map((c,l)=>e.jsxs("div",{className:"w6w-resolved-value",children:[e.jsx("code",{children:c.key||"(no key)"})," → ",e.jsx(An,{segments:i.resolveParamValue(c.value,o)})]},l))})]})}function An({segments:t}){return e.jsx(e.Fragment,{children:t.map((s,o)=>e.jsx(Vo,{segment:s},o))})}function Vo({segment:t}){switch(t.status){case"resolved":return t.ref?e.jsxs(e.Fragment,{children:[e.jsx(wt,{kind:"var",refName:t.ref}),e.jsx(dn,{value:t.value})]}):e.jsx(dn,{value:t.value});case"unresolved":return e.jsxs(e.Fragment,{children:[e.jsx(wt,{kind:"var",refName:t.ref}),e.jsx("span",{className:"w6w-param-unresolved",children:"unresolved"})]});case"at-run":return e.jsxs(e.Fragment,{children:[e.jsx(wt,{kind:"var",refName:t.ref}),e.jsx("span",{className:"w6w-param-unevaluated",children:"resolved at run"})]});case"not-evaluated":return e.jsxs(e.Fragment,{children:[e.jsx(wt,{kind:"expr"}),e.jsx("span",{className:"w6w-param-unevaluated",children:"not evaluated"})]});case"masked":return e.jsx(wt,{kind:"secret",refName:t.ref})}}function dn({value:t}){const[s,o]=u.useState(!1),n=Uo(t),r=$o(n);return r.clipped?e.jsxs(e.Fragment,{children:[s?e.jsx(we.Copyable,{value:n,label:"Copy resolved value",className:"w6w-resolved-copy",children:e.jsx("pre",{className:"w6w-resolved-text-full",children:n})}):e.jsxs("span",{children:[r.text,"…"]}),e.jsx("button",{type:"button",className:"w6w-resolved-more","aria-expanded":s,onClick:()=>o(c=>!c),children:s?"Show less":`Show all (${r.length.toLocaleString()} characters)`})]}):e.jsx("span",{children:n})}const zo={var:"◆",secret:"🔒",expr:"ƒ"};function wt({kind:t,refName:s}){const o=t==="expr"?"expr":i.varLabel(s??"");return e.jsxs("span",{className:`w6w-expr-chip w6w-expr-chip-${t}`,children:[e.jsx("span",{className:"w6w-expr-chip-sigil",children:zo[t]}),e.jsx("span",{className:"w6w-expr-chip-label",children:o})]})}function Uo(t){if(t===null)return"null";if(t===void 0)return"(not set)";if(t==="")return'""';if(typeof t=="string"||typeof t=="number"||typeof t=="boolean")return String(t);try{return JSON.stringify(t)}catch{return String(t)}}function In(t){return t.language==="python"||t.language==="typescript"?t.language:"javascript"}function Ho({enabled:t,values:s,onChange:o}){const[n,r]=u.useState(null),c=u.useRef(!1),l=typeof s.code=="string"?s.code:"";return u.useEffect(()=>{if(!t||c.current)return;c.current=!0;const f=i.convertCodeBindingsToReads(l,In(s));f.converted!==0&&(r({original:l,converted:f.converted}),o({...s,code:f.code}))},[t,l,s,o]),n?{converted:n.converted,undo:()=>{o({...s,code:n.original}),r(null)}}:null}function Jo({values:t,conversion:s,readOnly:o}){const n=typeof t.code=="string"?t.code:"",r=s,c=i.findCodeBindings(n,In(t)).length;return!r&&c===0?null:e.jsxs("output",{className:"w6w-hint w6w-script-converted",children:[r&&e.jsxs(e.Fragment,{children:["Converted ",r.converted," reference",r.converted===1?"":"s"," to code reads",!o&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("button",{type:"button",className:"w6w-script-converted-undo",onClick:r.undo,children:"Undo"})]}),c>0&&" · "]}),c>0&&e.jsxs(e.Fragment,{children:[c," ",e.jsx("code",{children:"{{ }}"})," left in the code stay",c===1?"s":""," literal text — read ",c===1?"it":"them"," from"," ",e.jsx("code",{children:"state"}),", or bind under Custom input"]})]})}function un(t,s){return{nodeIds:t.filter(o=>o.selected).map(o=>o.id),edgeIds:s.filter(o=>o.selected).map(o=>o.id)}}function qo(t,s,o,n){const r=new Set(t.nodeIds),c=new Set(t.edgeIds),l=s.filter(m=>r.has(m.id)),f=[...l.filter(m=>i.isForeachStep(m.data.step)),...l.filter(m=>!i.isForeachStep(m.data.step))];let d=s,x=o,h=n;for(const m of f)x=i.bridgeDeletedBodyStep(m.id,d,x),d=d.filter(k=>k.id!==m.id),h=us(h,m.id);return{nodes:d,edges:x.filter(m=>!c.has(m.id)),canvas:h}}function Go(t,s,o){var f;const n=new Set(t.nodeIds),r=new Set(t.edgeIds),c=o.filter(d=>r.has(d.id)&&!n.has(d.source)&&!n.has(d.target)),l=[];if(n.size===1)l.push(i.deleteStepMessage(t.nodeIds[0],s,o));else if(n.size>1){l.push(`Delete nodes ${[...n].map(x=>`"${x}"`).join(", ")}? Their connections are removed too.`);const d=new Set;for(const x of n)if(i.isForeachStep((f=s.find(h=>h.id===x))==null?void 0:f.data.step))for(const h of i.loopBody(x,s,o))n.has(h)||d.add(h);d.size&&l.push(`Loop body steps ${[...d].map(x=>`"${x}"`).join(", ")} stay as standalone steps.`)}return c.length&&l.push(`Delete ${c.length===1?"connection":"connections"} ${c.map(d=>`"${d.source} → ${d.target}"`).join(", ")}?`),l.join(" ")}function Mt(t,s,o,n,r){const c=i.flowToWorkflow({...t,connections:n},s,o);return{nodes:c.nodes.map(({with:l,...f})=>l&&Object.keys(l).length?{...f,with:l}:f),edges:c.edges??[],connections:c.connections??{},canvas:r,positions:Object.fromEntries(s.map(l=>[l.id,l.position]))}}function Ko(t,s){const o=i.workflowToFlow({...t,...s});return{...o,nodes:o.nodes.map(n=>({...n,position:s.positions[n.id]??n.position}))}}class Yo{constructor(s,o=100){at(this,"past",[]);at(this,"future",[]);at(this,"present");at(this,"group");at(this,"limit");this.limit=o,this.present=JSON.stringify(s)}reset(s){this.present=JSON.stringify(s),this.past=[],this.future=[],this.group=void 0}record(s,o){const n=JSON.stringify(s);n!==this.present&&((!o||o!==this.group)&&(this.past.push(this.present),this.past.length>this.limit&&this.past.shift()),this.present=n,this.group=o,this.future=[])}mark(){return this.present}rollbackTo(s){if(this.present===s)return;const o=this.past.lastIndexOf(s);return o>=0&&(this.past.length=o),this.present=s,this.future=[],this.group=void 0,JSON.parse(s)}undo(){const s=this.past.pop();if(s!==void 0)return this.future.push(this.present),this.present=s,this.group=void 0,JSON.parse(s)}redo(){const s=this.future.pop();if(s!==void 0)return this.past.push(this.present),this.present=s,this.group=void 0,JSON.parse(s)}}function Qt(t){var o;const s=t;return!!(s!=null&&s.isContentEditable||(o=s==null?void 0:s.closest)!=null&&o.call(s,'input, textarea, select, [contenteditable="true"], [contenteditable=""], [role="textbox"], .cm-editor'))}const Xo=64,gt=24,et=32;function _t(t){var s,o;return{width:((s=t.measured)==null?void 0:s.width)??t.width??200,height:((o=t.measured)==null?void 0:o.height)??t.height??64}}function Zo(t,s){return t.x<s.x+s.width&&t.x+t.width>s.x&&t.y<s.y+s.height&&t.y+t.height>s.y}function Qo(t){const s=(r,c)=>{const l=new Map;for(const x of t){const h=x.position[r];l.set(h,Math.max(l.get(h)??0,_t(x)[c]))}const f=new Map;let d=Number.NEGATIVE_INFINITY;for(const[x,h]of[...l].sort(([m],[k])=>m-k)){const m=Math.max(x,d);f.set(x,m),d=m+h+Xo}return f},o=s("x","width"),n=s("y","height");return t.map(r=>({...r,position:{x:o.get(r.position.x)??r.position.x,y:n.get(r.position.y)??r.position.y}}))}function ei(t,s,o){var f;const n=Qo(i.relayoutNodes(t,s));if(!((f=o.sections)!=null&&f.length))return{nodes:n,canvas:o};const r=new Map(n.map(d=>[d.id,d])),c=(o.notes??[]).map(d=>({...d.position,...d.size}));for(const d of o.sections)d.nodes.some(x=>r.has(x))||c.push({...d.position,...d.size,y:d.position.y-et,height:d.size.height+et});const l=o.sections.map(d=>{const x=new Set(d.nodes),h=n.filter(F=>x.has(F.id));if(!h.length)return d;const m=Math.min(...h.map(F=>F.position.x))-gt,k=Math.min(...h.map(F=>F.position.y))-gt,j=Math.max(...h.map(F=>F.position.x+_t(F).width)),y=Math.max(...h.map(F=>F.position.y+_t(F).height)),C={x:m,y:k,width:j+gt-m,height:y+gt-k},M=[...c,...[...r.values()].filter(F=>!x.has(F.id)).map(F=>({...F.position,..._t(F)}))].sort((F,W)=>F.y-W.y);for(const F of M){const W={...C,y:C.y-et,height:C.height+et};Zo(W,F)&&(C.y=F.y+F.height+gt+et)}const w=C.y-k;for(const F of h)r.set(F.id,{...F,position:{x:F.position.x,y:F.position.y+w}});return c.push({...C,y:C.y-et,height:C.height+et}),{...d,position:{x:C.x,y:C.y},size:{width:C.width,height:C.height}}});return{nodes:n.map(d=>r.get(d.id)??d),canvas:{...o,sections:l}}}const es=6;function ti(t){let s=2166136261;for(let o=0;o<t.length;o++)s^=t.charCodeAt(o),s=Math.imul(s,16777619);return s>>>0}function si(t){const s=new Map;let o=new Set;for(const n of[...new Set(t)].sort()){o.size===es&&(o=new Set);let r=ti(n)%es;for(;o.has(r);)r=(r+1)%es;o.add(r),s.set(n,r+1)}return s}function ps(t){return`var(--w6w-loop-${t})`}function Pn(t,s){const o=[],n=new Set([t]);for(let r=s.get(t);r&&!n.has(r);r=s.get(r))n.add(r),o.unshift(r);return o}function ni(t,s,o){return s.size===0?t:t.map(n=>{var l;if(((l=n.data)==null?void 0:l.when)!=="each")return n;const r=n.sourceHandle===i.EACH_SOURCE_HANDLE?n.source:o.get(n.source),c=r?s.get(r):void 0;return c===void 0?n:{...n,style:{...n.style,"--w6w-loop-color":ps(c)}}})}function oi(t,s){const o=s.get(t);return o===void 0?void 0:{"--w6w-loop-color":ps(o)}}function ii(t){const s=[];for(const o of t){const n=i.isForeachStep(o.data.step);(n||o.data.loopOf)&&s.push([o.id,n?1:0,o.data.loopOf])}return JSON.stringify(s)}function ri(t){const s=JSON.parse(t);return{tones:si(s.filter(o=>o[1]===1).map(o=>o[0])),loopOf:new Map(s.map(o=>[o[0],o[2]]))}}const pn="Paused — test runs stop before this node",fn="Disabled — skipped in every run";function tt(t){var s;return((s=t.ui)==null?void 0:s.paused)===!0}function We(t){return t.disabled===!0}function Rn(t,s){const{ui:o,...n}=t,{paused:r,...c}=o??{},l=s?{...c,paused:!0}:c;return Object.keys(l).length>0?{...n,ui:l}:n}function Fn(t,s){const{disabled:o,...n}=t;return s?{...n,disabled:!0}:n}function ls(t,s){return t.filter(o=>o.id!==s&&tt(o)).map(o=>o.id)}const ai=["nodes","steps"];function hn(t,s){for(const o of ai){const n=`${o}.${s}.output`;if(!t.startsWith(n))continue;const r=t.slice(n.length);if(r===""||r[0]==="."||r[0]==="[")return`foreach.item${r}`}return null}function Ot(t,s,o){if(typeof t=="string"){if(!t.includes("{{"))return t;const n=i.parseRootAnchoredTemplate(t);let r=!1;const c=n.map(l=>{if(l.kind!=="var"||l.ref===void 0)return l;const f=hn(l.ref,s);return f===null?l:(r=!0,o.includes(l.ref)||o.push(l.ref),{...l,ref:f})});return r?Ae.serializeTemplate(c):t}if(i.isDollarPath(t)){const n=t.$;if(typeof n!="string")return t;const r=hn(n,s);return r===null?t:(o.includes(n)||o.push(n),{$:r})}if(Array.isArray(t)){let n=!1;const r=t.map(c=>{const l=Ot(c,s,o);return l!==c&&(n=!0),l});return n?r:t}if(typeof t=="object"&&t!==null){let n=!1;const r={};for(const[c,l]of Object.entries(t)){const f=Ot(l,s,o);f!==l&&(n=!0),r[c]=f}return n?r:t}return t}function li(t){if(typeof t=="string"){if(!t.includes("{{"))return!1;const s=i.parseRootAnchoredTemplate(t);return s.length===1&&s[0].kind==="var"}return i.isDollarPath(t)&&typeof t.$=="string"}function Dn(t){return Array.isArray(t)&&t.length===1&&li(t[0])}function ci(t){var s;try{const o=i.normalizeInput(t);if(!Array.isArray(o.nodes))return{};const n={},r=(l,f)=>{const d=Object.hasOwn(n,l)?n[l]:[];d.push(f),n[l]=d},c=new Map(o.nodes.map(l=>[l.id,l]));for(const[l,f]of Object.entries(i.definitionLoops(o))){const d=c.get(l);if(d&&Dn((s=d.with)==null?void 0:s.items)&&r(l,{code:"foreach_wrapped_items",fix:{kind:"unwrap_items",label:"Unwrap Items"}}),"invalid"in f){r(l,{code:"loop_body_invalid",reason:{...f.invalid}});continue}for(const x of f.body){const h=c.get(x);if(!(h!=null&&h.with))continue;const m=[];Ot(h.with,l,m),m.length>0&&r(x,{code:"foreach_body_refs_output",foreachId:l,refs:m,fix:{kind:"use_current_item",foreachId:l,label:"Use Current item"}})}}return n}catch{return{}}}function di(t){const s=new Set,o=n=>{if(typeof n=="string")s.add(n);else if(Array.isArray(n))for(const r of n)o(r)};return o(t),s}function ui(t){var s,o;try{const n=i.normalizeInput(t);if(!Array.isArray(n.nodes))return[];const r=n.nodes.filter(I=>typeof I=="object"&&I!==null&&typeof I.id=="string"),c=i.effectiveEdges({...n,nodes:r}).filter(I=>typeof(I==null?void 0:I.from)=="string"&&typeof(I==null?void 0:I.to)=="string"),l=[];for(const I of r)try{const R=Ae.staticWritePaths(Ae.effectiveStateConfig((s=I.uses)==null?void 0:s.app,(o=I.uses)==null?void 0:o.action,I.state));R.length>0&&l.push({id:I.id,paths:R})}catch{}if(l.length<2)return[];const f=new Map;for(const I of r)for(const R of i.controlOwnedIds(I))f.has(R)||f.set(R,I.id);const d=I=>{const R=[I];let E=I;for(;f.has(E)&&(E=f.get(E),!R.includes(E));)R.push(E);return R},x=I=>{const R=d(I);return R[R.length-1]},h=new Map;for(const I of c){const R=h.get(I.from)??[];R.push(I.to),h.set(I.from,R)}const m=new Map,k=I=>{const R=m.get(I);if(R)return R;const E=new Set,V=[...h.get(I)??[]];for(;V.length>0;){const K=V.pop();if(!E.has(K)){E.add(K);for(const S of h.get(K)??[])V.push(S)}}return m.set(I,E),E},j=(I,R)=>I===R||k(I).has(R),y=r.filter(I=>{var R;return((R=I.uses)==null?void 0:R.app)===i.CONTROL_APP&&I.uses.action==="parallel"}).map(I=>{var E;const R=(E=I.with)==null?void 0:E.branches;return Array.isArray(R)?R.map(di):[]}),C=(I,R)=>{for(const E of d(R)){const V=I.findIndex(K=>K.has(E));if(V>=0)return V}return-1},M=[];for(const I of r){if(I.fanOut!=="parallel")continue;const R=new Map;for(const E of c){if(E.from!==I.id||i.isEachLink(E))continue;const V=E.when??"success",K=R.get(V)??[];K.push(E.to),R.set(V,K)}for(const E of R.values())E.length>=2&&M.push(E)}const w=(I,R)=>{for(const K of y){const S=C(K,I),g=C(K,R);if(S>=0&&g>=0&&S!==g)return!0}const E=x(I),V=x(R);return E===V||k(E).has(V)||k(V).has(E)?!1:M.some(K=>K.some((S,g)=>K.some((P,Y)=>g!==Y&&j(S,E)&&j(P,V))))},F=new Set,W=[];for(let I=0;I<l.length;I++)for(let R=I+1;R<l.length;R++){const E=l[I],V=l[R];if(!(E.id===V.id||!w(E.id,V.id)))for(const K of E.paths)for(const S of V.paths){if(!Ae.statePathsOverlap(K,S))continue;const g={code:"state_parallel_write",nodes:[E.id,V.id].sort(),path:[...K.length<=S.length?K:S]},P=JSON.stringify([g.nodes,g.path]);F.has(P)||(F.add(P),W.push(g))}}const O=(I,R)=>I<R?-1:I>R?1:0;return W.sort((I,R)=>O(I.code,R.code)||O(I.nodes.join(","),R.nodes.join(","))||O(I.path.join("."),R.path.join(".")))}catch{return[]}}function pi(t){try{const s={};for(const o of ui(t))for(const n of o.nodes){const r=Object.hasOwn(s,n)?s[n]:[];r.push({code:o.code,path:[...o.path],with:o.nodes.filter(c=>c!==n)}),s[n]=r}return s}catch{return{}}}function Ln(t,s){var o;if(s.code==="foreach_wrapped_items"){const n=(o=t.with)==null?void 0:o.items;return!t.with||!Dn(n)?t:{...t,with:{...t.with,items:n[0]}}}if(s.code==="foreach_body_refs_output"){if(!t.with)return t;const n=Ot(t.with,s.foreachId,[]);return n===t.with?t:{...t,with:n}}return t}function mn(t,s,o){return t&&t.nodeId===s&&t.handleType===((o==null?void 0:o.type)??"source")?i.laneForSourceHandle(t.handleId):i.laneForSourceHandle(o==null?void 0:o.id)}function fi(t,s,o,n,r){var x;const c=(x=n.find(h=>h.id===t))==null?void 0:x.data.step,l=i.loopMembership(n,r)[t]!==void 0,f=o==="success"&&l?"each":o;if(f==="each"&&!l&&!i.isForeachStep(c))return null;const d=o==="success"&&i.isForeachStep(c)?i.FOREACH_DONE_ROUTE:void 0;return i.loopRefusal(t,s,f,n,r,d)}function $t(t,s){var o;return(o=t.nodes??t.steps)==null?void 0:o[s]}function cs(t,s){const o=$t(t,s);return(o==null?void 0:o.status)==="skipped"&&o.skipReason==="not_on_path"}const hi=new Set(["succeeded","failed","canceled"]);function mi(t,s,o=[]){var c,l;if(!t||[...o,s].some(f=>cs(t,f)))return"no-run";const n=$t(t,s);if(n)return n.status;const r=new Set;for(const f of Object.values(t.nodes??t.steps??{}))if(Array.isArray(f==null?void 0:f.iterations))for(const d of f.iterations){const x=(l=(c=d==null?void 0:d.nodes)==null?void 0:c[s])==null?void 0:l.status;x&&r.add(x)}for(const f of["failed","running","succeeded","skipped"])if(r.has(f))return f;return"pending"}const wn={borderColor:"var(--w6w-border)",borderStyle:"solid",borderWidth:1,opacity:1};function Mn(t,s){const o=s!==void 0&&hi.has(s);switch(t){case"no-run":return wn;case"pending":return o?{borderColor:"var(--w6w-muted)",borderStyle:"dashed",borderWidth:1,opacity:.5}:{borderColor:"var(--w6w-border)",borderStyle:"dashed",borderWidth:1,opacity:1};case"running":return{borderColor:"var(--w6w-accent)",borderStyle:"solid",borderWidth:2,opacity:1};case"succeeded":return{borderColor:"var(--w6w-success)",borderStyle:"solid",borderWidth:2,opacity:1};case"failed":return{borderColor:"var(--w6w-danger)",borderStyle:"solid",borderWidth:2,opacity:1};case"skipped":return{borderColor:"var(--w6w-muted)",borderStyle:"dashed",borderWidth:1,opacity:.7};default:return wn}}function wi(t,s,o,n,r){var l;if(!t||cs(t,s)||r!==void 0&&cs(t,r))return;const c=gi(t,s,o,n);return c==="taken"&&r!==void 0&&((l=$t(t,r))==null?void 0:l.status)==="skipped"?"skipped":c}function gi(t,s,o,n){const r=$t(t,s);if(!r)return;if(o==="each")return r.status==="skipped"?"skipped":void 0;const c=o??"success",l=r.output,f=n===i.FOREACH_DONE_ROUTE&&!(l&&typeof l=="object"&&"route"in l);if(n!==void 0&&!f&&r.status==="succeeded")return l&&typeof l=="object"&&"matched"in l?n==="false"!=(l.matched===!0)?"taken":"skipped":l&&typeof l=="object"&&"route"in l&&l.route===n?"taken":"skipped";if(r.status==="succeeded")return c==="success"?"taken":"skipped";if(r.status==="failed")return c==="error"?"taken":"skipped";if(r.status==="skipped")return"skipped"}const gn={fields:[],sampleValues:{}};function fs(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function xi(t,s){var x;const o=t.map(h=>h.id),n=new Set(o),r=new Map(o.map(h=>[h,0])),c=new Map(o.map(h=>[h,[]]));for(const h of s)!n.has(h.source)||!n.has(h.target)||((x=c.get(h.source))==null||x.push(h.target),r.set(h.target,(r.get(h.target)??0)+1));const l=[],f=o.filter(h=>r.get(h)===0);for(;f.length>0;){const h=f.shift();l.push(h);for(const m of c.get(h)??[]){const k=(r.get(m)??0)-1;r.set(m,k),k===0&&f.push(m)}}const d=new Set(l);for(const h of o)d.has(h)||l.push(h);return l}const bi=new Set(["string","number","boolean","object","array"]);function xt(t){if(!Array.isArray(t))return;const s={type:"object",fields:{}};let o=!1;for(const n of t){if(!fs(n)||typeof n.key!="string"||n.key==="")continue;const r=n.key.split(".");let c=s;for(const d of r.slice(0,-1)){const x=c.fields[d];(x==null?void 0:x.type)!=="object"&&(c.fields[d]={type:"object",fields:{}}),c=c.fields[d]}const l=typeof n.type=="string"&&bi.has(n.type)?n.type:"string";let f;if(l==="array"){const d=xt(n.items);f=d?{type:"array",items:d}:{type:"array"}}else l==="object"?f=xt(n.fields??n.properties)??{type:"object",fields:{}}:f={type:l};c.fields[r[r.length-1]]=f,o=!0}return o?s:void 0}function ji(t,s){var x,h,m,k,j,y,C;const o=t.data.step,n=((x=s.testOutputs)==null?void 0:x[o.id])??((h=s.persistedOutputs)==null?void 0:h[o.id]);if(n!=null)return n;const{app:r,action:c}=o.uses;if(r===i.TRIGGER_APP&&((m=i.internalNodeDef(r,c))==null?void 0:m.group)==="trigger"){const M=i.fieldsToParams(i.asFieldDefs((k=o.with)==null?void 0:k.fields)).map(w=>({key:w.key}));return i.shapeToSkeleton(xt(M))}const l=(j=i.internalNodeDef(r,c))==null?void 0:j.output;if(l&&l.length>0)return i.shapeToSkeleton(xt(l));const f=o.uses.trigger===!0?(y=s.triggerDef)==null?void 0:y.call(s,r,c):(C=s.actionDef)==null?void 0:C.call(s,r,c),d=xt(f==null?void 0:f.output);return d?i.shapeToSkeleton(d):f==null?void 0:f.sample}function vi(t,s){var f,d,x,h,m;const o=t.data.step,n=(f=s.previewOutputs)==null?void 0:f[o.id];if(n!=null)return n;const{app:r,action:c}=o.uses,l=o.uses.trigger===!0?(x=(d=s.shapes)==null?void 0:d.triggerDef)==null?void 0:x.call(d,r,c):(m=(h=s.shapes)==null?void 0:h.actionDef)==null?void 0:m.call(h,r,c);return l==null?void 0:l.sample}function yi(t){switch(t){case"number":case"integer":return 0;case"boolean":return!1;case"object":return{};case"array":return[];default:return""}}function xn(t,s){const o=fs(t.initialState)?{...t.initialState}:{};for(const n of t.variables??[])!n||typeof n.key!="string"||n.key===""||(n.default!==void 0?o[n.key]=n.default:s||(o[n.key]=yi(n.type)));return o}function ts(t){return(i.inferOutputFields(t)??[]).map(s=>s.key)}function Si(t){const{anchorId:s,nodes:o,edges:n}=t;if(!s)return gn;const r=t.shapes??{},c=t.floating?new Set(o.map(E=>E.id)):i.ancestorIds(s,n);c.delete(s);const l=new Map(o.map(E=>[E.id,E])),f=[],d=[],x=new Map;for(const E of xi(o,n)){if(!c.has(E))continue;const V=l.get(E);if(!V)continue;const{app:K,action:S}=V.data.step.uses,g=Ae.effectiveStateConfig(K,S,V.data.step.state);if(g.mode==="off")continue;const P=ji(V,r);if(P!==void 0){const{ops:B}=Ae.computeStateWrites(g,P);f.push(...B);for(const ne of ts(Ae.foldState({},B))){const Z=x.get(ne)??new Set;Z.add(E),x.set(ne,Z)}}const Y=vi(V,t);Y!==void 0&&d.push(...Ae.computeStateWrites(g,Y).ops)}const h=xn(t,!1),m=Ae.foldState(h,f),k=ts(m);if(k.length===0)return gn;const j=new Set(ts(h)),y=new Map,C=new Map;for(const E of n)c.has(E.source)&&(!c.has(E.target)&&E.target!==s||(y.set(E.target,[...y.get(E.target)??[],E.source]),C.set(E.source,[...C.get(E.source)??[],E.target])));const M=[...c].filter(E=>!(y.get(E)??[]).length),w=E=>{const V=new Set,K=M.filter(S=>!E.has(S));for(;K.length>0;){const S=K.pop();if(S===s)return!1;if(!V.has(S)){V.add(S);for(const g of C.get(S)??[])E.has(g)||K.push(g)}}return!0},F=Ae.foldState(xn(t,!0),d),W=d.length>0?Ae.foldState({},d):void 0,O=fs(W)&&Object.keys(W).length>0?W:void 0,I=[],R={};for(const E of k){const V=x.get(E)??new Set,K=j.has(E)||V.size>0&&w(V);I.push({key:E,path:!0,paths:K?"all":"some"});const S=i.valueAtPath(F,E);S!==void 0&&(R[`state.${E}`]=S)}return{fields:I,sampleValues:R,...O?{written:O}:{}}}const Ni={registered:{label:"Registered",tone:"ok"},pending:{label:"Registering",tone:"pending"},failed:{label:"Registration failed",tone:"danger"},paused:{label:"Paused",tone:"muted"},destroying:{label:"Removing",tone:"muted"}},bn="Never fired";function Ci(t){if(!t)return bn;const s=new Date(t);return Number.isNaN(s.getTime())?bn:`Last fired ${s.toISOString().slice(0,16).replace("T"," ")} UTC`}function ki(t,s){var r;if(!(t!=null&&t.status))return null;const o=Ni[t.status];if(!o)return null;const n=t.status==="failed";return{label:o.label,tone:o.tone,error:n?((r=t.lastError)==null?void 0:r.message)??null:null,lastFire:Ci(t.lastFireAt),retryVisible:n&&s}}function Ei(t){const s=new Map;for(const o of t)o.nodeId&&s.set(o.nodeId,o);return s}function Ti(t){return(t??[]).filter(s=>{var o;return((o=s.uses)==null?void 0:o.trigger)===!0})}function Ai(t,s){const[o,n]=u.useState({}),r=u.useRef(new Set),c=JSON.stringify([...new Set(s.map(l=>l.data.step.uses.app))].filter(l=>l&&!i.isInternalApp(l)).sort());return u.useEffect(()=>{const l=JSON.parse(c).filter(f=>!r.current.has(f));if(l.length!==0){for(const f of l)r.current.add(f);Promise.all(l.map(async f=>{try{return[f,await t.getAppActions(f)]}catch{return r.current.delete(f),null}})).then(f=>{const d=f.filter(x=>x!==null);d.length!==0&&n(x=>({...x,...Object.fromEntries(d)}))})}},[t,c]),o}function Ii(t,s){const[o,n]=u.useState({}),r=u.useRef(new Set),c=JSON.stringify([...new Set(s.filter(l=>l.data.step.uses.trigger===!0).map(l=>l.data.step.uses.app))].filter(l=>l&&!i.isInternalApp(l)).sort());return u.useEffect(()=>{const l=t.getAppTriggers;if(typeof l!="function")return;const f=JSON.parse(c).filter(d=>!r.current.has(d));if(f.length!==0){for(const d of f)r.current.add(d);Promise.all(f.map(async d=>{try{return[d,await l.call(t,d)]}catch{return r.current.delete(d),null}})).then(d=>{const x=d.filter(h=>h!==null);x.length!==0&&n(h=>({...h,...Object.fromEntries(x)}))})}},[t,c]),o}function Pi(t){return(s,o)=>{var n,r;return(r=(n=t[s])==null?void 0:n.find(c=>c.key===o))==null?void 0:r.ports}}const Ri="Which outcome of the source node this edge carries. An error edge is drawn by dragging from the node's error exit port; use this control to re-lane an edge already drawn. An error edge overrides the node’s “On error” policy.";function jn(t,s,o,n){const r=t.find(c=>c.id===s);return[o,n,r==null?void 0:r.source,r==null?void 0:r.target]}const hs=u.createContext(void 0),ms=u.createContext(new Map),ws=u.createContext({tones:new Map,loopOf:new Map});function vn(t){return`Can’t draw that edge: this node allows at most ${t} outgoing edge${t===1?"":"s"} per lane.`}const gs=u.createContext(new Map),_n=u.createContext({byNode:new Map,subs:[]});function Fi({apps:t,registration:s,children:o}){return e.jsx(gs.Provider,{value:t,children:e.jsx(_n.Provider,{value:s,children:o})})}const xs=u.createContext(null);function Di(t){return e.jsx(le.ReactFlowProvider,{children:e.jsx(Li,{...t})})}function yn(t,s){let o=s.length+1;for(;s.includes(`${t}-${o}`);)o++;return`${t}-${o}`}function ss(t){var s,o;return{x:t.position.x,y:t.position.y,w:((s=t.measured)==null?void 0:s.width)??t.width??200,h:((o=t.measured)==null?void 0:o.height)??t.height??64}}function Li({onConnectionResourcesChange:t,value:s,onChange:o,readOnly:n,height:r=480,apps:c,exprOptions:l,project:f,runState:d,stepProblems:x,onTestRun:h,fitViewKey:m,onRunFromNode:k}){var Ys,Xs,Zs,Qs,en,tn,sn;const j=i.useW6WApi(),y=u.useMemo(()=>new Map((c??[]).map(a=>[a.id,a])),[c]),C=Vi(s),[M,w]=u.useState(null),F=u.useMemo(()=>i.centralizeConnections(s),[s.id]),W=u.useMemo(()=>i.workflowToFlow(F),[F]),[O,I]=u.useState(F.connections??{}),R=u.useRef(O),E=u.useCallback(a=>{R.current=a,I(a)},[]),V=u.useCallback(a=>{const p=i.centralizeConnections({nodes:[a],connections:R.current});return p.connections!==R.current&&E(p.connections),p.nodes[0]},[E]),K=u.useMemo(()=>i.storedViewport(s),[s.id]),S=((Ys=s.settings)==null?void 0:Ys.savePosition)!==!1,[g,P,Y]=le.useNodesState(W.nodes),B=Ai(j,g),ne=Ii(j,g),Z=u.useMemo(()=>Pi(B),[B]),[A,X,D]=le.useEdgesState(W.edges),[z,U]=u.useState(null),ie=u.useMemo(()=>s.canvas??{},[s.id]),[J,H]=u.useState(ie),[q]=u.useState(()=>new Yo(Mt(F,W.nodes,W.edges,O,ie))),Q=u.useRef(),[fe,Je]=u.useState(0),[_e,lt]=u.useState(!1),[Se,qe]=u.useState(null),[Ie,ge]=u.useState(null),[ce,ke]=u.useState(null),[Be,oe]=u.useState(!1),bt=u.useRef({});u.useEffect(()=>{Be||(bt.current={})},[Be]);const[de,Pe]=u.useState(null),[Oe,Ee]=u.useState("props"),[xe,Ge]=u.useState(null),[ye,Ve]=u.useState(null),[Re,Fe]=u.useState(null),ct=u.useRef(!1),Ne=u.useRef(null),[be,$e]=u.useState(null),{screenToFlowPosition:De,fitView:Le}=le.useReactFlow(),dt=i.useEffectiveTheme();u.useEffect(()=>{P(W.nodes),X(W.edges),U(null),ke(null),Fe(null),Pe(null),Ge(null),H(ie),E(F.connections??{}),q.reset(Mt(F,W.nodes,W.edges,F.connections??{},ie)),Q.current=void 0},[W,ie,F,P,X,E,q]),u.useEffect(()=>{P(a=>{const p=new Map(i.stampLoopOf(a,A).map(b=>[b.id,b.data.loopOf]));return a.map(b=>{const v=mi(d,b.id,Pn(b.id,p));return b.data.stepStatus===v&&b.data.runStatus===(d==null?void 0:d.status)?b:{...b,data:{...b.data,stepStatus:v,runStatus:d==null?void 0:d.status}}})}),X(a=>a.map(p=>{var L;const b=i.edgeLane(p),v=wi(d,p.source,b,typeof((L=p.data)==null?void 0:L.route)=="string"?p.data.route:void 0,p.target),N=i.edgeVisuals(b,v);return p.className===N.className&&p.label===N.label?p:{...p,className:N.className,label:N.label}}))},[d,W,fe,P,X]),u.useEffect(()=>{P(a=>i.applyStepProblems(a,x))},[x,W,fe,P]);const st=u.useCallback((a,p)=>{var N,L;const{canvas:b,...v}=a;return!((N=p.notes)!=null&&N.length)&&!((L=p.sections)!=null&&L.length)?v:{...v,canvas:Oo(p,s.canvas,S)}},[s.canvas,S]),ee=u.useCallback((a,p,b)=>{q.record(Mt(s,a,p,R.current,b??J),Be?bt.current:Q.current),o(st(i.flowToWorkflow({...s,connections:R.current},a,p),b??J))},[s,o,J,st,q,Be]),nt=u.useRef(()=>{});nt.current=a=>{if(n)return;const p=i.editConnectionResources(g.map(v=>v.data.step),R.current,a),b=g.map((v,N)=>({...v,data:{...v.data,step:p.nodes[N]}}));E(p.connections),P(b),ee(b,A)};const Ke=u.useCallback(a=>nt.current(a),[]),jt=u.useCallback(a=>{U(a),ke(null),P(p=>p.map(b=>({...b,selected:b.id===a}))),X(p=>p.map(b=>({...b,selected:!1}))),Le({nodes:[{id:a}],duration:300,maxZoom:1})},[P,X,Le]),[ut,ue]=u.useState(null),vt=u.useMemo(()=>ut?g.map(a=>a.id===ut?{...a,className:`${a.className??""} w6w-connection-highlight`.trim()}:a):g,[g,ut]),pt=g.map(a=>({id:a.data.step.id,uses:a.data.step.uses})),Bt=JSON.stringify(pt),yt=JSON.stringify([...y]);u.useEffect(()=>{t==null||t({workflowId:s.id,nodes:pt,apps:y,connections:O,readOnly:n,edit:Ke,focusNode:jt,highlightNode:ue})},[t,s.id,Bt,yt,O,n,Ke,jt]),u.useEffect(()=>()=>t==null?void 0:t(null),[t]);const St=u.useCallback(a=>i.canConnect(a.source,a.target,g,A,Z,i.routeFromHandle(a.sourceHandle)),[g,A,Z]),[ot,Me]=u.useState(null),T=u.useRef(null),te=u.useRef(null);u.useEffect(()=>{P(a=>i.stampLoopOf(a,A))},[A,P]);const ae=u.useCallback(a=>{if(n)return;const p=i.applyConnect(a.source,a.target,g,A,i.laneForSourceHandle(a.sourceHandle),Z,i.routeFromHandle(a.sourceHandle));if(!p){const b=i.laneForSourceHandle(a.sourceHandle),v=i.connectRefusal(a.source,a.target,g,A,b,Z,i.routeFromHandle(a.sourceHandle));if(v&&v.refused==="loop"){Me({nodeId:a.source,reason:v.reason});return}if(v){const L=A.find($=>$.source===a.source&&i.edgeLane($)===b);L&&(X(A.map($=>({...$,selected:$.id===L.id}))),ke(L.id),Xe({edgeId:L.id,message:vn(v.cap)}));return}const N=i.connectConflict(a.source,a.target,g,A,i.laneForSourceHandle(a.sourceHandle));if(!N)return;X(A.map(L=>({...L,selected:L.id===N}))),ke(N),Xe({edgeId:N,message:i.idClashMessage("Can’t draw that edge",N,jn(A,N,a.source,a.target))});return}Xe(null),Me(null),X(p),ee(g,p)},[A,g,X,ee,n,Z]),je=u.useCallback((a,p)=>{var G,se,pe;if(n||p.isValid)return;const b=p.fromNode;if(!b)return;const v=((G=p.fromHandle)==null?void 0:G.type)==="target"?"target":"source",N=p.toNode;if(N&&v==="source"){const re=fi(b.id,N.id,mn(te.current,b.id,p.fromHandle),g,A);if(re){Me({nodeId:b.id,reason:re});return}}const L=(se=g.find(re=>re.id===b.id))==null?void 0:se.data.step;if(L){const re=i.nodePortsForStep(L,Z);if((v==="source"?re.out:re.in)<1)return}const $="changedTouches"in a?a.changedTouches[0]:a,_=De({x:$.clientX,y:$.clientY});$e({nodeId:b.id,handleType:v,position:_,lane:mn(te.current,b.id,p.fromHandle),route:i.routeFromHandle((pe=p.fromHandle)==null?void 0:pe.id)}),oe(!0)},[n,De,g,A,Z]),Ye=u.useCallback((a,p,b)=>{if(n)return;const v=g.find(G=>G.id===a);if(!v)return;const N=ss(v),L=i.laneForSourceHandle(b),$=120,_=p==="target"?{x:N.x-N.w-$,y:N.y}:L==="error"?{x:N.x,y:N.y+N.h+$}:L==="each"?{x:N.x+N.w+$,y:N.y-N.h-$/2}:{x:N.x+N.w+$,y:N.y};$e({nodeId:a,handleType:p,position:_,lane:L,route:i.routeFromHandle(b)}),oe(!0)},[n,g]),js=u.useCallback(a=>{n||Fe({nodeIds:[a],edgeIds:[]})},[n]),Gn=u.useCallback(a=>{if(n)return;const p=qo(a,g,A,J);P(p.nodes),X(p.edges),H(p.canvas),p.nodes.some(b=>b.id===z)||U(null),p.nodes.some(b=>b.id===de)||Pe(null),p.edges.some(b=>b.id===ce)||ke(null),ee(p.nodes,p.edges,p.canvas)},[g,A,J,P,X,ee,n,z,de,ce]),vs=u.useCallback(()=>{if(n)return;const a=ei(g,A,J);P(a.nodes),H(a.canvas),ct.current=!0,ee(a.nodes,A,a.canvas)},[g,A,J,P,ee,n]),Kn=u.useCallback(()=>{n||vs()},[n,vs]);u.useEffect(()=>{ct.current&&(ct.current=!1,Le({duration:300}))},[g,Le]);const ys=u.useRef(m);u.useEffect(()=>{Object.is(ys.current,m)||(ys.current=m,Le({duration:300}))},[m,Le]);const[Nt,Xe]=u.useState(null),it=u.useMemo(()=>A.find(a=>a.id===ce)??null,[A,ce]),Yn=u.useCallback(a=>{if(n||!ce)return;const p=A.find($=>$.id===ce);if(!p||i.edgeLane(p)===a)return;const b=i.edgeWhenConflict(A,ce,a,g),v=i.relaneRefusal(A,ce,a,g,Z),N=b||v?null:i.setEdgeWhen(A,ce,a,g,Z);if(!N){if(v){Xe({edgeId:ce,message:vn(v.cap)});return}Xe({edgeId:ce,message:b?i.idClashMessage("Can’t switch this edge",b,jn(A,b,p.source,p.target)):"This edge can’t be switched right now."});return}Xe(null),X(N);const L=N.find($=>$.source===p.source&&$.target===p.target&&i.edgeLane($)===a);ke((L==null?void 0:L.id)??null),ee(g,N)},[A,g,X,ee,n,ce,Z]),Xn=u.useCallback(a=>{if(n)return;const p=A.filter(b=>b.id!==a);p.length!==A.length&&(X(p),ce===a&&ke(null),ee(g,p))},[g,A,X,ee,n,ce]),Vt=u.useCallback(a=>{if(n)return;const p=a.map(L=>g.find($=>$.id===L)).filter(L=>L!==void 0);if(p.length===0)return;const b=g.map(L=>L.id),v=p.map(L=>{const $=i.suggestStepId(b,`${L.data.step.id}_copy`);b.push($);const _={...i.stripBody(structuredClone(L.data.step)),id:$};return{id:$,type:L.type,position:{x:L.position.x+40,y:L.position.y+60},data:{step:_,isInternal:L.data.isInternal},...p.length>1?{selected:!0}:{}}}),N=[...p.length>1?g.map(L=>L.selected?{...L,selected:!1}:L):g,...v];P(N),U(v[0].id),ee(N,A)},[g,A,P,ee,n]),Ss=u.useCallback(a=>Vt([a]),[Vt]),Zn=u.useCallback(a=>{if(n)return;const p=i.isInternalApp(a.uses.app),b=g.map(re=>re.id),v=a.id&&!i.stepNameError(a.id,b)?a.id:i.suggestStepId(b,i.slugifyLabel(i.internalNodeLabel(a.uses.app,a.uses.action))),N=V({id:v,uses:a.uses,...a.with&&Object.keys(a.with).length>0?{with:a.with}:{}}),L={id:v,type:p?"control":"step",position:(be==null?void 0:be.position)??(ye==null?void 0:ye.position)??{x:80,y:80+g.length*24},data:{step:N,isInternal:p}},$=ye!=null&&ye.replaces?g.find(re=>re.id===ye.replaces):void 0;if($&&i.isTriggerStep(a.uses)){const re={...L,position:$.position},he=[...g.filter(mt=>mt.id!==$.id),re],me=i.renameStepInEdges(A,$.id,v),Te=os(J,$.id,v);return P(he),X(me),H(Te),Me(null),U(v),ee(he,me,Te),v}const _=[...g,L];let G=A,se=null;const pe=(re,he,me,Te)=>{const mt=i.connectRefusal(re,he,_,A,me,Z);mt&&mt.refused==="loop"&&(se={nodeId:Te,reason:mt.reason})};if(be){const[re,he]=be.handleType==="target"?[v,be.nodeId]:[be.nodeId,v],me=i.applyConnect(re,he,_,A,be.lane,Z,be.route);me||pe(re,he,be.lane,be.nodeId),G=me??A}else{const re=g.find(he=>i.isTriggerStep(he.data.step.uses));if(i.isTriggerStep(a.uses)){if(!re){const he=i.findChainRoot(g,A);if(he){const me=i.applyConnect(v,he.id,_,A,"success",Z);me||pe(v,he.id,"success",he.id),G=me??A}}}else{const me=(re&&!A.some(Te=>Te.source===re.id)?re:void 0)??i.findChainTail(g,A);if(me){const Te=i.applyConnect(me.id,v,_,A,"success",Z);Te||pe(me.id,v,"success",me.id),G=Te??A}}}return P(_),G!==A&&X(G),Me(se),U(v),ee(_,G),v},[g,A,P,X,ee,n,be,ye,Z,V,J]),Ns=u.useCallback((a,p)=>{var G;let b=p;const v=(G=g.find(se=>se.id===a))==null?void 0:G.data.step;if(p.uses.connection&&!p.uses.connectionRef&&(v!=null&&v.uses.connectionRef)&&v.uses.app===p.uses.app){const se=i.selectNodeConnection(i.withConnectionRef(p,v.uses.connectionRef),p.uses.connection,g.map(pe=>pe.data.step),R.current);E(se.connections),b=se.step}else b=V(p);const N=b.id!==a;if(N&&g.some(se=>se.id===b.id))return;const L=g.map(se=>se.id===a?{...se,id:b.id,data:{step:b,isInternal:i.isInternalApp(b.uses.app)}}:se);if(N){const se=i.renameStepInEdges(A,a,b.id),pe=os(J,a,b.id);P(L),X(se),H(pe),z===a&&U(b.id),de===a&&Pe(b.id),ee(L,se,pe);return}P(L);const $=new Set(i.routesForStep(b).map(se=>se.id)),_=A.filter(se=>{var pe;return se.source!==b.id||((pe=se.data)==null?void 0:pe.route)===void 0||$.has(String(se.data.route))});_.length!==A.length&&X(_),ee(L,_)},[g,A,J,P,X,z,de,ee,V,E]),Ze=u.useCallback(a=>{n||(H(a),ee(g,A,a))},[n,g,A,ee]),Qn=u.useCallback(()=>{var N;if(n)return;const a=(N=Ne.current)==null?void 0:N.getBoundingClientRect(),p=a?De({x:a.left+a.width/2,y:a.top+a.height/2}):{x:0,y:0},b=J.notes??[],v={id:yn("note",b.map(L=>L.id)),color:"#facc15",position:{x:Math.round(p.x-100),y:Math.round(p.y-60)},size:{width:200,height:120},content:""};Ze(rs({...J,notes:[...b,v]}))},[n,J,De,Ze]),eo=u.useCallback((a,p)=>{if(n)return;const b=p?Math.min(a.x,p.x):a.x,v=p?Math.min(a.y,p.y):a.y,N=p?Math.abs(p.x-a.x):360,L=p?Math.abs(p.y-a.y):240,$=g.filter(re=>{const he=ss(re),me=he.x+he.w/2,Te=he.y+he.h/2;return me>=b&&me<=b+N&&Te>=v&&Te<=v+L}).map(re=>re.id),_=J.sections??[],G=yn("section",_.map(re=>re.id)),se={id:G,title:"Section",color:"#6366f1",position:{x:Math.round(b),y:Math.round(v)},size:{width:Math.round(N),height:Math.round(L)},nodes:[]},pe={...J,sections:[..._,se]};Ze(rs(is(pe,G,$)))},[n,g,J,Ze]);u.useEffect(()=>{if(!_e)return;const a=p=>{p.key==="Escape"&&(lt(!1),qe(null))};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[_e]);const to=u.useCallback((a,p)=>{var $;if(n)return;const b=($=J.sections)==null?void 0:$.find(_=>_.id===a);if(!b)return;const v=new Set(b.nodes),N=g.map(_=>v.has(_.id)?{..._,position:{x:_.position.x+p.dx,y:_.position.y+p.dy}}:_),L={...J,sections:(J.sections??[]).map(_=>_.id===a?{..._,position:{x:_.position.x+p.dx,y:_.position.y+p.dy}}:_)};P(N),H(L),ee(N,A,L)},[n,J,g,A,P,ee]),so=u.useCallback((a,p)=>{if(n)return;const b=a==="note"?{...J,notes:(J.notes??[]).filter(v=>v.id!==p)}:{...J,sections:(J.sections??[]).filter(v=>v.id!==p)};Ze(b)},[n,J,Ze]),no=a=>{let p=J;for(const b of a){const v=ss(b),N=v.x+v.w/2,L=v.y+v.h/2,$=(p.sections??[]).find(G=>N>=G.position.x&&N<=G.position.x+G.size.width&&L>=G.position.y&&L<=G.position.y+G.size.height),_=Tn(p,b.id);$?(_.length!==1||_[0]!==$.id)&&(p=is(p,$.id,[b.id])):_.length>0&&(p=us(p,b.id))}return p},zt=u.useCallback((a,p,b)=>{(async()=>{const v=await j.saveStepTest(s.id,a,p).catch(N=>(console.error("step run fixture save failed",N),null));await j.recordStepTestRun(s.id,a,{stepTestId:(v==null?void 0:v.id)??null,status:b.status,input:p.input,output:b.output,error:b.error,...b.meta?{meta:b.meta}:{}})})().catch(v=>{console.error("step run persist failed",v)})},[j,s.id]),Cs=u.useCallback(a=>{const p=g.find(b=>b.id===a);!p||!k&&i.isControlApp(p.data.step.uses.app)||w({stepId:a,status:"collect"})},[g,k]),oo=u.useCallback(async(a,p,b)=>{if(!k)return;const v=g.find($=>$.id===a);if(!v)return;const N=i.isTriggerStep(v.data.step.uses),L={stopAt:ls(g.map($=>$.data.step),a),...b?{state:b}:{},...N?{input:p}:{}};w({stepId:a,status:"running"});try{await k(a,L),w(null)}catch($){const _=$;w({stepId:a,status:"error",error:_.message??String($),errorCode:_.code})}},[g,k]),Ct=u.useCallback((a,p)=>{if(n)return;const b=g.map(v=>v.id===a?{...v,data:{...v.data,step:p(v.data.step)}}:v);P(b),ee(b,A)},[g,A,P,ee,n]),ks=u.useCallback(a=>Ct(a,p=>Rn(p,!tt(p))),[Ct]),Es=u.useCallback(a=>Ct(a,p=>Fn(p,!We(p))),[Ct]),io=u.useCallback(async(a,p,b)=>{h==null||h();const v=g.find(G=>G.id===a);if(!v)return;const N=v.data.step,L=i.isTriggerStep(N.uses),$=L?{input:p}:{...N.with??{},...p},_=L?{input:p,with:p}:{input:p,with:$};w({stepId:a,status:"running"});try{const G=await j.invokeAction(N.uses.app,N.uses.action,$,{connectionId:i.connectionIdFor(N,R.current),project:f,...b?{state:b}:{},workflowId:s.id}),se=G.logs,pe=G.meta;w({stepId:a,status:"done",value:G.value,logs:se,...pe?{meta:pe}:{}}),zt(a,_,{status:"succeeded",output:G.value,...pe?{meta:pe}:{}})}catch(G){const se=G;w({stepId:a,status:"error",error:se.message??String(G),errorCode:se.code}),zt(a,_,{status:"failed",error:se.message??String(G)})}},[g,j,zt,f,h,s.id]),Ut=u.useMemo(()=>({onEdit:a=>{Ee("props"),Pe(a)},onEditJson:a=>{Ee("json"),Pe(a)},onRun:Cs,onDuplicate:Ss,onDelete:js,onTogglePause:ks,onToggleDisable:Es,runsFromNode:!!k,onAddFromPort:Ye,readOnly:n}),[Cs,Ss,js,ks,Es,k,Ye,n]);u.useEffect(()=>{const a=Ne.current;if(!a)return;const p=b=>{const v=b.target.closest(".react-flow__node");if(!v)return;const N=v.getAttribute("data-id");N&&(b.stopPropagation(),Ut.onEdit(N))};return a.addEventListener("dblclick",p,!0),()=>a.removeEventListener("dblclick",p,!0)},[Ut]);const rt=g.find(a=>a.id===de),kt=(rt==null?void 0:rt.data.step)??null,Ht=M?((Xs=g.find(a=>a.id===M.stepId))==null?void 0:Xs.data.step)??null:null,Jt=(M==null?void 0:M.status)==="collect"&&!!Ht,Ts=u.useMemo(()=>{const a=new Map;for(const p of g)a.set(p.id,i.fanOutState(p.id,A).count);return a},[g,A]),As=ii(g),Et=u.useMemo(()=>ri(As),[As]),ro=u.useMemo(()=>ni(A,Et.tones,Et.loopOf),[A,Et]),ao=u.useMemo(()=>({step:Ui,control:Hi}),[]),[Tt,Is]=u.useState({}),[At,Ps]=u.useState({}),[Rs,Fs]=u.useState({}),[It,Ds]=u.useState({}),[ze,Pt]=u.useState(null),[Ls,Ms]=u.useState([]),lo=de??ze??"";u.useEffect(()=>{const a=j.loadNodeSamples;if(typeof a!="function"||!s.id){Ms([]);return}let p=!1;return a(s.id).then(b=>{p||Ms(Array.isArray(b)?b:[])},()=>{}),()=>{p=!0}},[j,s.id,lo]);const Rt=u.useMemo(()=>i.indexNodeSamples(Ls),[Ls]),qt=u.useMemo(()=>i.splitNodeOutputs(Tt,Rt,It),[Tt,Rt,It]),Ue=u.useMemo(()=>i.splitPreviewOutputs(Tt,Rt,It),[Tt,Rt,It]),Ce=u.useMemo(()=>({actionDef:(a,p)=>{var b;return(b=B[a])==null?void 0:b.find(v=>v.key===p)},triggerDef:(a,p)=>{var b;return(b=ne[a])==null?void 0:b.find(v=>v.key===p)},testOutputs:qt.fresh,persistedOutputs:qt.persisted,loopSamples:Rs}),[B,ne,qt,Rs]),Qe=u.useMemo(()=>M?i.upstreamStateSources(M.stepId,g,A,Ce):void 0,[M,g,A,Ce]),co=u.useMemo(()=>(Qe==null?void 0:Qe.steps)??[],[Qe]),ve=u.useMemo(()=>{const a=i.upstreamStateSources(de,g,A,Ce,ze);return{...a,steps:i.excludeSelfStep(a.steps,de??ze)}},[de,ze,g,A,Ce]),ft=u.useMemo(()=>Si({anchorId:de??ze,nodes:g,edges:A,floating:i.isFloatingDraft(de,ze,g,A),initialState:s.initialState,variables:s.variables,shapes:Ce,previewOutputs:{...Ue.persisted,...Ue.fresh}}),[de,ze,g,A,s.initialState,s.variables,Ce,Ue]),_s=JSON.stringify([...ve.steps.map(a=>a.id),...ve.extraSampleIds??[]]);u.useEffect(()=>{const a=JSON.parse(_s);if(!de&&!ze||a.length===0){Is({}),Ps({}),Fs({}),Ds({});return}let p=!1;return Promise.all(a.map(async b=>{try{const v=await j.listStepTests(s.id,b),N=v.length?v[v.length-1]:null;return N?{id:b,output:N.lastRunOutput,runAt:N.lastRunAt,meta:N.lastRunMeta,loopSample:i.foreachTestSample(N)}:null}catch{return null}})).then(b=>{if(p)return;const v={},N={},L={},$={};for(const _ of b)_!=null&&_.meta&&(N[_.id]=_.meta),_!=null&&_.loopSample&&(L[_.id]=_.loopSample),!(!_||_.output===void 0||_.output===null)&&(v[_.id]=_.output,$[_.id]=_.runAt);Is(v),Ds($),Ps(N),Fs(L)}),()=>{p=!0}},[j,s.id,de,ze,_s]);const Gt=u.useMemo(()=>i.declaredSamples(g,Ce),[g,Ce]),Ft=u.useMemo(()=>({persisted:Ue.persisted,samples:Gt.samples,event:Gt.event}),[Ue.persisted,Gt]),Os=u.useMemo(()=>i.upstreamSampleValues(ve.steps,Ue.fresh,At,ve.loop,Ft),[ve.steps,ve.loop,Ue.fresh,At,Ft]),$s=u.useMemo(()=>i.upstreamSampleValueSources(ve.steps,Ue.fresh,At,ve.loop,Ft),[ve.steps,ve.loop,Ue.fresh,At,Ft]),Ws=i.useExpressionOptions(),Bs=u.useMemo(()=>i.nodeConfigSources(g),[g]),Vs=u.useMemo(()=>i.nodeConfigValues(g,C.subs),[g,C.subs]),Kt=u.useMemo(()=>i.nodeMetaValues(g,C.subs,y,O),[g,C.subs,y,O]),zs=u.useMemo(()=>[...new Set(Object.values(O).flatMap(a=>a.connection?[a.connection]:[]))].sort().join(","),[O]),[Us,uo]=u.useState(()=>new Map);u.useEffect(()=>{if(!zs)return;let a=!0;return j.listConnections().then(p=>{a&&uo(new Map(p.map(b=>[b.id,b])))}).catch(()=>{}),()=>{a=!1}},[j,zs]);const Yt=u.useMemo(()=>i.connectionExpressionSources(O,Us,y),[O,Us,y]),Xt=u.useMemo(()=>({...l??{},connections:Yt.sources,steps:ve.steps,hasTrigger:ve.hasTrigger,eventOutputs:ve.eventOutputs,eventOutputsFrom:ve.eventOutputsFrom,loop:ve.loop,stateShape:{fields:ft.fields,...ft.written?{written:ft.written}:{}},nodeConfigs:Bs,nodeConfig:Vs,nodeMeta:Kt,valueSources:$s,sampleValues:{...Ws.sampleValues??{},...(l==null?void 0:l.sampleValues)??{},...Yt.sampleValues,...i.nodeMetaSampleValues(Kt),...Os,...ft.sampleValues}}),[l,Ws.sampleValues,ve,ft,Os,$s,Bs,Vs,Kt,Yt]),ht=u.useRef(null);Be||de?ht.current===null&&(ht.current=q.mark()):ht.current=null;const Hs=()=>{oe(!1),$e(null),Ve(null),Pt(null)},Js=()=>{const a=ht.current;if(ht.current=null,n||a===null)return;const p=q.rollbackTo(a);p&&Gs(p)},qs=a=>{if(n)return;const p=q[a]();p&&Gs(p)},Gs=a=>{var v;const p=Ko(s,a);P(p.nodes.map(N=>({...N,selected:N.id===z}))),X(p.edges.map(N=>({...N,selected:N.id===ce}))),H(a.canvas),E(a.connections),p.nodes.some(N=>N.id===z)||U(null),p.edges.some(N=>N.id===ce)||ke(null);const b=p.nodes.some(N=>N.id===de);b||Pe(null),oe(!1),Pt(null),$e(null),Fe(null),ge(null),Ve(null),Ge(null),Me(null),Xe(null),Q.current=void 0,Je(N=>N+1),o(st(i.flowToWorkflow({...s,nodes:a.nodes,connections:a.connections},p.nodes,p.edges),a.canvas)),!b&&!M&&((v=Ne.current)==null||v.focus({preventScroll:!0}))},Ks=u.useRef(qs);Ks.current=qs,u.useEffect(()=>{const a=Ne.current;if(!a)return;let p=a.contains(document.activeElement);const b=N=>{N.type==="focusin"&&N.target===document.body||(p=a.contains(N.target))},v=N=>{if(n||N.defaultPrevented||Qt(N.target)||!a.contains(N.target)&&!(p&&N.target===document.body))return;const L=N.key.toLowerCase();!(N.ctrlKey||N.metaKey)||N.altKey||L!=="z"&&!(L==="y"&&!N.shiftKey)||(N.preventDefault(),Ks.current(L==="y"||N.shiftKey?"redo":"undo"))};return document.addEventListener("pointerdown",b),document.addEventListener("focusin",b),document.addEventListener("keydown",v),()=>{document.removeEventListener("pointerdown",b),document.removeEventListener("focusin",b),document.removeEventListener("keydown",v)}},[n]);const Dt=u.useCallback((a,p)=>{var _;if(Qt(a.target))return;const b=(_=Ne.current)==null?void 0:_.getBoundingClientRect();if(!b)return;a.preventDefault();const v=un(g,A),N=v.nodeIds,L=Fo(N,p),$=p!==void 0&&!N.includes(p);$&&P(g.map(G=>G.selected!==(G.id===p)?{...G,selected:G.id===p}:G)),Ge({x:a.clientX-b.left,y:a.clientY-b.top,flow:De({x:a.clientX,y:a.clientY}),nodeIds:L,edgeIds:$?[]:v.edgeIds})},[g,A,P,De]),po=u.useCallback(a=>{var p;Ge(null),a&&((p=Ne.current)==null||p.focus({preventScroll:!0}))},[]),fo=a=>{const p=xe;if(!(!p||n))if(a==="duplicate")Vt(p.nodeIds);else if(a==="delete")Fe({nodeIds:p.nodeIds,edgeIds:p.edgeIds});else if(a==="replace-trigger"){const b=g.find(v=>v.id===p.nodeIds[0]);if(!b)return;$e(null),Ve({position:b.position,tab:"triggers",replaces:b.id}),oe(!0)}else $e(null),Ve({position:p.flow,...a==="add-trigger"?{tab:"triggers"}:{}}),oe(!0)},ho=e.jsx(xs.Provider,{value:Ut,children:e.jsx(hs.Provider,{value:Z,children:e.jsx(ms.Provider,{value:Ts,children:e.jsx(ws.Provider,{value:Et,children:e.jsx(Fi,{apps:y,registration:C,children:e.jsx(i.WorkflowProjectProvider,{project:f,workflowId:s.id,children:e.jsx(i.ExpressionOptionsProvider,{value:Xt,children:e.jsxs("section",{ref:Ne,className:"w6w-flow",tabIndex:-1,"aria-label":"Workflow editor",style:{width:"100%",height:r,position:"relative"},onFocusCapture:a=>{Q.current=Qt(a.target)?{}:void 0},onBlurCapture:()=>{Q.current=void 0},onKeyDown:a=>{if(a.defaultPrevented||a.key!=="Backspace"&&a.key!=="Delete"||n||de||Be||Re)return;const p=a.target;if(p.isContentEditable||p.tagName==="INPUT"||p.tagName==="TEXTAREA"||p.tagName==="SELECT"||p.closest("dialog, .w6w-modal")!==null)return;const b=un(g,A);!b.nodeIds.length&&!b.edgeIds.length||(a.preventDefault(),!b.nodeIds.length&&b.edgeIds.length===1?Xn(b.edgeIds[0]):Fe(b))},children:[e.jsxs(le.ReactFlow,{nodes:vt,edges:ro,minZoom:.05,defaultEdgeOptions:{type:"smoothstep"},connectionLineType:le.ConnectionLineType.SmoothStep,onNodesChange:Y,onEdgesChange:D,onConnect:ae,onConnectStart:(a,p)=>{te.current=p},onConnectEnd:je,onPaneClick:()=>Me(null),onPaneContextMenu:a=>Dt(a),onNodeContextMenu:(a,p)=>Dt(a,p.id),onEdgeContextMenu:a=>Dt(a),onSelectionContextMenu:a=>Dt(a),onMoveStart:()=>Ge(null),isValidConnection:St,onNodeDragStop:(a,p,b)=>{const v=no(b),N=v!==J;if(N&&H(v),!S&&!N){q.record(Mt(s,g,A,R.current,v));return}ee(g,A,v)},onMoveEnd:(a,p)=>{if(!a||n)return;const b=i.flowToWorkflow(s,g,A),v=i.withViewport(b,p);v!==b&&o(v,{viewportOnly:!0})},onSelectionChange:({nodes:a,edges:p})=>{var b,v,N,L;U(((b=a[0])==null?void 0:b.id)??null),ke(((v=p[0])==null?void 0:v.id)??null),T.current!==(((N=a[0])==null?void 0:N.id)??null)&&(T.current=((L=a[0])==null?void 0:L.id)??null,Me(null))},nodeTypes:ao,nodesDraggable:!n,nodesConnectable:!n,connectOnClick:!1,elementsSelectable:!0,...K?{defaultViewport:K}:{fitView:!0,fitViewOptions:{maxZoom:1}},deleteKeyCode:null,colorMode:dt,proOptions:{hideAttribution:!0},children:[e.jsx(le.Background,{gap:16}),e.jsx(le.Controls,{showInteractive:!1,children:!n&&e.jsx(le.ControlButton,{onClick:Kn,title:"Auto-layout — re-flow the graph into columns","aria-label":"Auto-layout the graph",children:e.jsx(we.Icon,{name:"layout"})})}),e.jsx(le.MiniMap,{pannable:!0,zoomable:!0,style:{background:"var(--w6w-panel-2)"}}),!n&&e.jsxs(le.Panel,{position:"top-left",className:"w6w-flow-tools",children:[e.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>oe(!0),children:"+ Node"}),e.jsx(i.IconButton,{label:"Add note",icon:"sticky-note",className:"w6w-flow-tool","data-testid":"add-note",onClick:Qn}),e.jsx(i.IconButton,{label:"Draw section",title:"Draw section — drag a frame on the canvas (Esc cancels)",icon:"frame",className:`w6w-flow-tool${_e?" active":""}`,"aria-pressed":_e,"data-testid":"draw-section",onClick:()=>{lt(!_e),qe(null)}})]}),!n&&_e&&e.jsx("div",{className:"w6w-section-draw nopan nodrag nowheel","data-testid":"section-draw-surface",onPointerDown:a=>{if(a.button!==0)return;a.currentTarget.setPointerCapture(a.pointerId);const{clientX:p,clientY:b}=a;qe({sx:p,sy:b,ex:p,ey:b})},onPointerMove:a=>{const{clientX:p,clientY:b}=a;qe(v=>v&&{...v,ex:p,ey:b})},onPointerUp:()=>{const a=Se;if(qe(null),lt(!1),!a)return;const p=De({x:a.sx,y:a.sy}),b=Math.abs(a.ex-a.sx)>6||Math.abs(a.ey-a.sy)>6;eo(p,b?De({x:a.ex,y:a.ey}):null)},children:Se&&(()=>{var v;const a=(v=Ne.current)==null?void 0:v.getBoundingClientRect(),p=(a==null?void 0:a.left)??0,b=(a==null?void 0:a.top)??0;return e.jsx("div",{className:"w6w-section-draw-rect",style:{left:Math.min(Se.sx,Se.ex)-p,top:Math.min(Se.sy,Se.ey)-b,width:Math.abs(Se.ex-Se.sx),height:Math.abs(Se.ey-Se.sy)}})})()}),!n&&it&&i.edgeLane(it)!=="each"&&((Zs=g.find(a=>a.id===it.source))==null?void 0:Zs.data.step.uses.app)!==i.ROUTER_APP&&e.jsx(le.Panel,{position:"top-right",children:e.jsxs("div",{className:"w6w-edge-lane",children:[e.jsx("span",{className:"w6w-muted w6w-small",children:"Run on"}),["success","error"].map(a=>e.jsx("button",{type:"button",className:`w6w-btn w6w-btn-sm w6w-btn-ghost${i.edgeLane(it)===a?" active":""}`,"aria-pressed":i.edgeLane(it)===a,title:Ri,onClick:()=>Yn(a),children:a==="success"?"Success":"Error"},a)),(Nt==null?void 0:Nt.edgeId)===it.id&&e.jsx("span",{className:"w6w-edge-lane-err w6w-small",role:"alert",children:Nt.message})]})}),ot&&e.jsx(le.NodeToolbar,{nodeId:ot.nodeId,position:le.Position.Bottom,isVisible:!0,children:e.jsx("div",{className:"w6w-loop-notice w6w-small",role:"alert",children:i.loopRefusalMessage(ot.reason)})}),e.jsx(i.CanvasLayer,{canvas:J,readOnly:n,savePosition:S,onChange:Ze,onSectionDrop:to,onRequestDelete:(a,p)=>!n&&ge({kind:a,id:p})})]}),Ie&&e.jsx(i.ConfirmModal,{title:Ie.kind==="note"?"Delete note":"Delete section",message:Ie.kind==="note"?"Delete this note?":"Delete this section? Its nodes are kept.",confirmLabel:"Delete",onConfirm:()=>{so(Ie.kind,Ie.id),ge(null)},onClose:()=>ge(null)}),Be&&e.jsx(i.StepBuilderModal,{initialTab:ye==null?void 0:ye.tab,onClose:()=>{Js(),Hs()},onDone:Hs,onAdd:a=>{const p=Zn(a);return p&&Pt(p),p},onDraftChange:(a,p)=>Ns(a,{id:a,...p}),stepIds:g.map(a=>a.id),onOpenStep:a=>{oe(!1),$e(null),Ve(null),Pt(null),Ee("props"),Pe(a)},workflowId:s.id,upstreamSteps:i.stepBuilderUpstreamSteps(be,g,A),loop:i.stepBuilderLoop(be,g,A,Ce)}),kt&&de&&e.jsx(qi,{workflowId:s.id,step:kt,restoreVersion:fe,upstreamSteps:Xt.steps??[],loop:Xt.loop,readOnly:n,fanOutCount:Ts.get(de)??0,stateOutputFields:(sn=i.resolveOutputShape((Qs=Ce.actionDef)==null?void 0:Qs.call(Ce,kt.uses.app,kt.uses.action),(en=Ce.testOutputs)==null?void 0:en[de],(tn=Ce.persistedOutputs)==null?void 0:tn[de]))==null?void 0:sn.fields.map(a=>a.key),initialView:Oe,stepProblems:rt==null?void 0:rt.data.stepProblems,otherStepIds:g.filter(a=>a.id!==de).map(a=>a.id),onChange:a=>Ns(de,a),onClose:()=>Pe(null),onCancel:()=>{Js(),Pe(null)},onTestRun:h}),M&&e.jsxs(i.Modal,{title:`${Jt?"Run node":"Test run"}: ${M.stepId}`,onClose:()=>w(null),children:[Jt&&Ht&&e.jsx($i,{workflowId:s.id,step:Ht,upstreamSteps:co,loop:Qe==null?void 0:Qe.loop,continues:k?{stopAt:ls(g.map(a=>a.data.step),M.stepId)}:void 0,onCancel:()=>w(null),onRun:(a,p)=>k?oo(M.stepId,a,p):io(M.stepId,a,p)},M.stepId),!Jt&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"w6w-modal-body",children:[M.status==="running"&&e.jsx("p",{className:"w6w-muted w6w-small",children:"Running…"}),M.status==="error"&&e.jsxs("div",{className:"w6w-result w6w-error",children:[M.errorCode&&e.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:e.jsx("code",{children:M.errorCode})}),M.error||"The node failed with no error message."]}),M.status==="done"&&e.jsxs("div",{children:[e.jsx("div",{className:"w6w-muted w6w-small",style:{marginBottom:6},children:"Result"}),e.jsx(i.ResultViewer,{value:M.value,maxHeight:360}),M.meta&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Metadata"}),e.jsx(i.ResultViewer,{value:M.meta,maxHeight:360})]})]}),M.logs&&M.logs.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Console output"}),e.jsx(we.Copyable,{value:M.logs.join(`
|
|
3
|
+
`),label:"Copy console output",children:e.jsx("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:200,overflow:"auto",margin:0},children:M.logs.join(`
|
|
4
|
+
`)})})]})]}),e.jsx("div",{className:"w6w-modal-actions",children:e.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>w(null),children:"Close"})})]})]}),Re!==null&&e.jsx(i.ConfirmModal,{title:Re.nodeIds.length===1?"Delete node":Re.nodeIds.length>1?`Delete ${Re.nodeIds.length} nodes`:`Delete ${Re.edgeIds.length} connections`,message:Go(Re,g,A),confirmLabel:"Delete",autoFocusConfirm:!0,onConfirm:()=>{Gn(Re),Fe(null)},onClose:()=>Fe(null)}),xe&&e.jsx(go,{x:xe.x,y:xe.y,items:Do(xe.nodeIds,!!n,{replaceableTrigger:xe.nodeIds.length===1&&g.some(a=>a.id===xe.nodeIds[0]&&i.isTriggerStep(a.data.step.uses))}),onAction:fo,onClose:po})]})})})})})})})});return e.jsx(i.WorkflowConnectionsContext.Provider,{value:{nodes:g.map(a=>a.data.step),connections:O,setConnections:E,readOnly:n},children:ho})}const Mi=["code"];function Wt(t){try{const s=JSON.parse(t);return s&&typeof s=="object"&&!Array.isArray(s)?s:null}catch{return null}}function _i(t){try{const s=JSON.parse(t);if(Array.isArray(s))return{items:s}}catch{return null}return Wt(t)}function Oi({items:t,save:s}){if(!t)return e.jsxs("output",{className:"w6w-small",style:{display:"block"},children:[e.jsx("strong",{children:"Items"})," doesn't resolve to a list yet: no step before this one has a saved test that produces it. Test an earlier step, or paste a sample list under"," ",e.jsx("strong",{children:"Override the incoming state"})," below."]});const o=t[0],n=o!==void 0?(i.inferOutputFields(o)??[]).map(r=>r.key):[];return e.jsxs("div",{className:"w6w-testout",children:[e.jsxs("div",{className:"w6w-testout-label",children:[t.length," ",t.length===1?"item":"items"]}),t.length===0?e.jsx("p",{className:"w6w-muted w6w-small",children:"The list is empty, so there is no item to sample."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w6w-testout-label",children:"First item"}),e.jsx(i.ResultViewer,{value:o,maxHeight:220})]}),s==="saved"&&e.jsxs("output",{className:"w6w-small",style:{display:"block"},children:["Saved as this loop's sample.",n.length>0&&e.jsxs(e.Fragment,{children:[" ","Steps on ",e.jsx("strong",{children:"Each item"})," now offer ",e.jsx("strong",{children:"Current item"})," ›"," ",n.map((r,c)=>e.jsxs("span",{children:[c>0&&", ",e.jsx("code",{children:r})]},r)),"."]})]}),s==="failed"&&e.jsx("p",{className:"w6w-small",role:"alert",children:"Couldn't save the sample. Try Test again."})]})}function On(t){const[s,o]=u.useState(null),[n,r]=u.useState("0"),[c,l]=u.useState({}),[f,d]=u.useState({}),x=s??i.loopItemText(t),h=((t==null?void 0:t.outer)??[]).map(j=>({foreachId:j.foreachId,name:j.name??j.foreachId,itemText:c[j.foreachId]??i.loopItemText(j),indexText:f[j.foreachId]??"0",setItemText:y=>l(C=>({...C,[j.foreachId]:y})),setIndexText:y=>d(C=>({...C,[j.foreachId]:y}))})),m=t?i.parseLoopSeed(x,n):void 0;let k=m!=null&&m.ok?{ok:!0,value:m.value}:m;if(t&&(m!=null&&m.ok)){const j={};for(const y of h){const C=i.parseLoopSeed(y.itemText,y.indexText);if(!C.ok){k={ok:!1,error:`${y.name}: ${C.error}`};break}j[y.foreachId]=C.value}k!=null&&k.ok&&(j[t.foreachId]=m.value,k={ok:!0,value:{...m.value,loops:j}})}return{active:!!t,itemText:x,indexText:n,setItemText:o,setIndexText:r,outers:h,parsed:k}}function $n(t){var s;return(s=t.parsed)!=null&&s.ok?t.parsed.value:void 0}function bs(t){return t.parsed&&!t.parsed.ok?t.parsed.error:null}function Wn({seed:t,readOnly:s}){if(!t.active)return null;const o=bs(t);return e.jsxs("div",{className:"w6w-field w6w-loop-seed",children:[t.outers.map(n=>e.jsxs("div",{"data-testid":`loop-seed-outer-${n.foreachId}`,children:[e.jsxs("span",{children:[n.name," item"]}),e.jsx("textarea",{rows:3,value:n.itemText,readOnly:s,spellCheck:!1,"aria-label":`${n.name} item`,onChange:r=>n.setItemText(r.target.value)}),e.jsxs("span",{children:[n.name," index"]}),e.jsx("input",{type:"text",inputMode:"numeric",value:n.indexText,readOnly:s,"aria-label":`${n.name} index`,onChange:r=>n.setIndexText(r.target.value)})]},n.foreachId)),e.jsx("span",{children:"Current item"}),e.jsx("textarea",{rows:3,value:t.itemText,readOnly:s,spellCheck:!1,"aria-label":"Current item",onChange:n=>t.setItemText(n.target.value)}),e.jsx("span",{children:"Index"}),e.jsx("input",{type:"text",inputMode:"numeric",value:t.indexText,readOnly:s,"aria-label":"Index",onChange:n=>t.setIndexText(n.target.value)}),e.jsx("span",{className:"w6w-hint",children:"This step runs once per item of the For each. Test it as one iteration — starting from the sample item, or edit it."}),o&&e.jsx("span",{className:"w6w-hint",role:"alert",children:o})]})}function ds({text:t,onChange:s,seeds:o,readOnly:n,expand:r,hint:c}){const l=Wt(t),f=l?Object.keys(l).length:0,d=f>0,[x,h]=u.useState(d);u.useEffect(()=>{(d||r)&&h(!0)},[d,r]);const m=k=>{s(JSON.stringify(k.lastRunOutput??k.input??{},null,2)),h(!0)};return e.jsxs("div",{className:"w6w-field w6w-incoming-state",children:[e.jsx("span",{children:"Incoming state"}),o.length>0&&e.jsx("div",{className:"w6w-seed-picker",children:e.jsx("div",{className:"w6w-seed-chips",children:o.map(k=>e.jsxs("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Use ${k.label}'s saved test as the incoming state`,disabled:n,onClick:()=>m(k.test),children:[e.jsx("code",{children:k.label}),k.test.lastRunStatus?e.jsxs("span",{className:"w6w-muted w6w-small",children:[" · ",k.test.lastRunStatus]}):null]},k.stepId))})}),e.jsxs("details",{className:"w6w-state-override",open:x,onToggle:k=>h(k.currentTarget.open),children:[e.jsxs("summary",{children:["Override the incoming state",f>0?` · ${f} key${f===1?"":"s"} set`:""]}),e.jsx("textarea",{rows:3,value:t,readOnly:n,spellCheck:!1,"aria-label":"Incoming state override (JSON)",onChange:k=>s(k.target.value)}),e.jsx("span",{className:"w6w-hint",children:c??e.jsxs(e.Fragment,{children:["JSON whose keys replace this step's parameters by name, for this test only — so a script's data goes under ",e.jsx("code",{children:"input"}),": ",e.jsx("code",{children:'{"input": {…}}'}),". Upstream outputs already reach ",e.jsx("code",{children:"{{ nodes.<id>.output }}"})," bindings from their saved tests. Reach for this to test against a state the flow cannot currently produce — a field no upstream step returns yet, or a case you can't reproduce by running the flow."]})})]})]})}function $i({workflowId:t,step:s,upstreamSteps:o,loop:n,onRun:r,onCancel:c,continues:l}){var J;const f=i.useW6WApi(),d=i.isTriggerStep(s.uses),x=i.isInternalApp(s.uses.app),h=u.useMemo(()=>{var H;return d?i.asFieldDefs((H=s.with)==null?void 0:H.fields):[]},[d,s.with]),m=u.useMemo(()=>d?i.fieldsToParams(h):x?i.internalNodeParams(s.uses.app,s.uses.action):null,[d,x,h,s.uses.app,s.uses.action]),[k,j]=u.useState(null),y=m??k;u.useEffect(()=>{if(m)return;if(!s.uses.app||!s.uses.action){j([]);return}let H=!1;return j(null),f.getAppActions(s.uses.app).then(q=>{var Q;H||j(((Q=q.find(fe=>fe.key===s.uses.action))==null?void 0:Q.params)??[])}).catch(()=>!H&&j([])),()=>{H=!0}},[f,m,s.uses.app,s.uses.action]);const[C,M]=u.useState(()=>{var H;return d?i.seedValues(i.asFieldDefs((H=s.with)==null?void 0:H.fields)):{}}),[w,F]=u.useState("{}"),W=i.useSeedSources(t,o,!d),O=On(n),I=(J=i.useExpressionOptions().stateShape)==null?void 0:J.written,R=i.startStateFromSeeds(W,$n(O),I),E=i.useRememberedTestInput(t,s.id),[V,K]=u.useState(!1),[S,g]=u.useState(!1);u.useEffect(()=>{if(!E.loaded)return;let H=!1;const q=(Q,fe)=>{Q&&Object.keys(Q).length>0&&(d?M(Je=>({...Je,...Q})):F(JSON.stringify(Q,null,2)),fe&&g(!0)),K(!0)};if(E.input!==void 0){q(E.input,!0);return}return f.listStepTests(t,s.id).then(Q=>{if(H)return;const fe=Q.length?Q[Q.length-1]:null;q(d?fe==null?void 0:fe.with:fe==null?void 0:fe.input,!1)}).catch(()=>{H||K(!0)}),()=>{H=!0}},[f,t,s.id,d,E.loaded]);const[P,Y]=u.useState(0),B=()=>{E.clear(),g(!1),d?M(i.seedValues(h)):F("{}"),Y(H=>H+1)},ne=H=>{M(H),A(!0),g(!1),Y(q=>q+1)},[Z,A]=u.useState(!0),X=Wt(w),D=d?Z:X!==null,z=d?C:{...s.with??{},...X??{}},U=d?null:bs(O),ie=!!y&&V&&D&&!U&&i.requiredParamsFilled(y,z);return e.jsxs("div",{className:"w6w-stepconfig",children:[e.jsx("div",{className:"w6w-modal-body",children:e.jsxs("div",{className:"w6w-stack",children:[l&&e.jsxs("p",{className:"w6w-muted w6w-small","data-testid":"run-from-node-hint",children:["Runs this node, then continues through every node after it",l.stopAt.length>0?e.jsxs(e.Fragment,{children:[" ","and stops before"," ",l.stopAt.length===1?"the paused node":"paused nodes"," ",l.stopAt.map((H,q)=>e.jsxs("span",{children:[q>0?", ":"",e.jsx("code",{children:H})]},H))]}):null,". Disabled nodes are skipped."]}),S&&y!==null&&V&&e.jsx(i.LastUsedNote,{onClear:B}),y===null||!V?e.jsx("p",{className:"w6w-muted w6w-small",children:y===null?"Loading parameters…":"Loading saved values…"}):d?e.jsxs(e.Fragment,{children:[e.jsx(i.PropertyEntryForm,{params:y,values:C,onChange:M,onValidityChange:A},P),s.uses.trigger===!0&&e.jsx(i.TriggerSampleButton,{app:s.uses.app,trigger:s.uses.action,onUse:ne}),y.length===0&&e.jsxs("span",{className:"w6w-hint",children:["This trigger declares no fields — provide a sample payload to run with. It becomes the trigger's output state (",e.jsx("code",{children:"input"}),")."]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"w6w-muted w6w-small",children:["Runs ",e.jsx("code",{children:s.uses.action})," with the configuration saved on this node — only the incoming state changes per run. Edit the node to change how it is configured."]}),e.jsx(Wn,{seed:O}),e.jsx(ds,{text:w,onChange:F,seeds:W})]})]})}),e.jsxs("div",{className:"w6w-modal-actions",children:[e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:c,children:"Cancel"}),!ie&&y!==null&&V&&e.jsx("span",{className:"w6w-muted w6w-small",children:U?`${U} Fix it to run.`:D?d?"Fill the required fields to test.":"This step is missing required configuration — set it on the Configure tab.":d?"The payload must be a JSON object to run.":"The incoming state must be a JSON object to run."}),e.jsx("button",{type:"button",className:"w6w-btn",disabled:!ie,onClick:()=>{E.save(d?C:X??{},y??[]),r(d?C:X??{},d?void 0:R)},children:"▶ Run"})]})]})}function Wi(t){return t.uses.app===i.CONTROL_APP&&t.uses.action==="foreach"}function Bn({id:t}){const{tones:s,loopOf:o}=u.useContext(ws),n=Pn(t,o);return n.length===0?null:e.jsx("span",{className:"w6w-loop-dots",children:n.map(r=>e.jsx("span",{className:"w6w-loop-dot",role:"img","aria-label":`In loop · ${r}`,title:`In loop · ${r}`,style:{background:ps(s.get(r)??1)}},r))})}function Vn(t){return oi(t,u.useContext(ws).tones)}function He({type:t,position:s,multiple:o,id:n,variant:r,top:c,routeLabel:l}){const f=le.useNodeId(),d=u.useContext(xs),x=!!f&&!!d&&!d.readOnly,h=()=>{x&&f&&d.onAddFromPort(f,t,n)},m=r==="error"?"a step that handles this step's failure":r==="each"?"the first step of this loop's body":t==="target"?"a step before this one":"the next step";return e.jsx(le.Handle,{type:t,position:s,id:n,className:r==="error"?"w6w-handle-error":r==="each"?"w6w-handle-each":o?"w6w-handle-multi":void 0,style:{...o?{height:22,borderRadius:3,width:8}:{},...c?{top:c}:{}},onClick:x?h:void 0,title:l?`${l} — drag or click to connect`:x?`Drag to empty canvas (or click) to add ${m} · drag to a port to connect`:r==="error"?"On error — drag to route this step's failure separately":r==="each"?"Each item — drag to the first step to repeat for every item":o?t==="target"?"Accepts multiple incoming connections":"Multiple outgoing connections":void 0})}function zn({id:t,step:s,runnable:o}){const n=u.useContext(xs);if(!n||n.readOnly)return null;const r=o||n.runsFromNode,c=n.runsFromNode?"Run from this node — continues through the nodes after it":"Test-run this node",l=tt(s),f=We(s);return e.jsxs(le.NodeToolbar,{position:le.Position.Top,className:"w6w-node-toolbar",children:[r&&e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:c,"aria-label":c,onClick:()=>n.onRun(t),children:e.jsx(we.Icon,{name:"run",size:15})}),e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn","data-testid":"node-pause-toggle","aria-pressed":l,title:l?"Resume — test runs go through this node":"Pause — test runs stop before this node","aria-label":l?"Unpause node":"Pause node",onClick:()=>n.onTogglePause(t),children:e.jsx(we.Icon,{name:"pause",size:15})}),e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn","data-testid":"node-disable-toggle","aria-pressed":f,title:f?"Enable — this node runs again":"Disable — skip this node in every run","aria-label":f?"Enable node":"Disable node",onClick:()=>n.onToggleDisable(t),children:e.jsx(we.Icon,{name:"ban",size:15})}),e.jsx("span",{className:"w6w-node-toolbar-divider","aria-hidden":"true"}),e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Edit","aria-label":"Edit node",onClick:()=>n.onEdit(t),children:e.jsx(we.Icon,{name:"edit",size:15})}),e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Duplicate","aria-label":"Duplicate node",onClick:()=>n.onDuplicate(t),children:e.jsx(we.Icon,{name:"copy",size:15})}),e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn danger",title:"Delete","aria-label":"Delete node",onClick:()=>n.onDelete(t),children:e.jsx(we.Icon,{name:"trash",size:15})})]})}function Un({step:t,count:s}){if(s<2)return null;const o=t.fanOut==="parallel",n=i.fanOutLabel(s,o?"parallel":"sequential");return e.jsxs("div",{className:"w6w-fanout-badge",role:"img","aria-label":n,title:n,children:[e.jsx("span",{"aria-hidden":"true",children:o?"⇉":"→"})," ",s]})}function Hn({step:t}){const s=tt(t),o=We(t);return!s&&!o?null:e.jsxs("div",{children:[o&&e.jsxs("span",{className:"w6w-node-flag w6w-node-flag-disabled","data-testid":"step-disabled-badge",role:"img","aria-label":fn,title:fn,children:[e.jsx(we.Icon,{name:"ban",size:11})," Disabled"]}),s&&e.jsxs("span",{className:"w6w-node-flag w6w-node-flag-paused","data-testid":"step-paused-badge",role:"img","aria-label":pn,title:pn,children:[e.jsx(we.Icon,{name:"pause",size:11})," Paused"]})]})}function Jn(t){return!t||t.length===0?{}:{"data-step-problem":t.map(s=>s.code).join(" "),title:t.map(i.stepProblemTooltip).join(`
|
|
5
|
+
`)}}function qn({problems:t}){if(!t||t.length===0)return null;const s=t.map(i.stepProblemTooltip).join(`
|
|
6
|
+
`);return e.jsx("span",{"data-step-problem-badge":"",role:"img","aria-label":s,title:s,style:{position:"absolute",top:-9,right:-9,width:18,height:18,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",background:"var(--w6w-danger)",color:"#fff"},children:e.jsx(we.Icon,{name:"warning",size:12})})}function Bi(t){const s=i.useW6WApi(),o=t.uses.action,[n,r]=u.useState(null),c=t.uses.trigger===!0,l=t.uses.app;return u.useEffect(()=>{if(!c||!s.getAppTriggers)return;let f=!1;return s.getAppTriggers(l).then(d=>{var x;return!f&&r(((x=d.find(h=>h.key===o))==null?void 0:x.title)??null)}).catch(()=>{}),()=>{f=!0}},[s,l,o,c]),n||o}function Vi(t){const s=i.useW6WApi(),o=s.listSubscriptionsForWorkflow,n=s.retrySubscriptionRegistration,r=t.id,c=[...Ti(t.nodes),...(t.nodes??[]).filter(y=>{var C,M;return(((C=y.uses)==null?void 0:C.app)===i.WEBHOOK_APP||((M=y.uses)==null?void 0:M.app)===i.FORM_APP)&&y.uses.trigger!==!0})],l=c.length>0,f=c.map(y=>`${y.id}:${y.uses.app}:${y.uses.action}:${i.connectionIdFor(y,t.connections)??""}`).join("|"),[d,x]=u.useState([]),h=u.useMemo(()=>Ei(d),[d]),[m,k]=u.useState(0);u.useEffect(()=>{if(!o||!l){x([]);return}let y=!1;return o.call(s,r).then(C=>!y&&x(C)).catch(()=>{}),()=>{y=!0}},[s,o,r,l,f,m]);const j=u.useMemo(()=>n?async y=>{try{await n.call(s,y)}finally{k(C=>C+1)}}:void 0,[s,n]);return u.useMemo(()=>({byNode:h,subs:d,retry:j}),[h,d,j])}function zi({nodeId:t}){const{byNode:s,retry:o}=u.useContext(_n),[n,r]=u.useState(!1),c=s.get(t),l=ki(c,o!==void 0);return!c||!l?null:e.jsxs("div",{className:"w6w-small","data-trigger-registration":c.status,"data-tone":l.tone,style:{marginTop:3,paddingLeft:2},children:[e.jsx("span",{style:l.tone==="danger"?{color:"var(--w6w-danger)"}:void 0,children:l.label}),e.jsxs("span",{className:"w6w-muted",children:[" · ",l.lastFire]}),l.error&&e.jsx("div",{role:"alert",style:{color:"var(--w6w-danger)"},children:l.error}),l.retryVisible&&o&&e.jsx("button",{type:"button",className:"nodrag",disabled:n,onClick:()=>{r(!0),o(c.id).catch(()=>{}).finally(()=>r(!1))},children:"Retry"})]})}function Ui({id:t,data:s,selected:o}){const n=s.step,c=u.useContext(gs).get(n.uses.app),l=(c==null?void 0:c.displayName)||n.uses.app||"—",f=i.isTriggerStep(n.uses),d=Bi(n),x=n.uses.trigger?`${l} · ${d}`:l,h=i.nodePortsForStep(n,u.useContext(hs)),m=Mn(s.stepStatus??"no-run",s.runStatus),k=e.jsx(Un,{step:n,count:u.useContext(ms).get(t)??0}),j=Vn(t);return e.jsxs("div",{className:[s.loopOf?"w6w-node-in-loop":"",We(n)?"w6w-node-disabled":""].filter(Boolean).join(" ")||void 0,"data-loop-of":s.loopOf,style:j,"data-disabled":We(n)||void 0,"data-paused":tt(n)||void 0,children:[e.jsx(zn,{id:t,step:n,runnable:!0}),e.jsxs("div",{className:f?"w6w-node-trigger":void 0,"data-node-kind":f?"trigger":void 0,"data-run-status":s.stepStatus??"no-run",...Jn(s.stepProblems),style:{position:"relative",...s.stepProblems?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${m.borderWidth}px ${m.borderStyle} ${o?"var(--w6w-accent)":m.borderColor}`,opacity:We(n)?.45:o?1:m.opacity,background:"var(--w6w-panel)",color:"var(--w6w-text)",...f?{}:{borderRadius:4,padding:"8px 12px"},minWidth:180,fontSize:13,display:"flex",alignItems:"center",gap:10},children:[e.jsx(qn,{problems:s.stepProblems}),h.in>0&&e.jsx(He,{type:"target",position:le.Position.Left,multiple:h.in>1}),e.jsx(i.AppIcon,{src:c==null?void 0:c.iconSvg,srcDark:c==null?void 0:c.iconSvgDark,brandColor:c==null?void 0:c.brandColor,name:l,size:28}),e.jsxs("div",{style:{minWidth:0},children:[e.jsx("div",{style:{fontWeight:600},children:x}),e.jsx("div",{className:"w6w-muted w6w-small",style:{marginTop:2},children:e.jsx("code",{children:n.uses.action||"—"})})]}),h.out>0&&e.jsxs(e.Fragment,{children:[e.jsx(He,{type:"source",position:le.Position.Right,multiple:h.out>1}),!f&&e.jsx(He,{type:"source",position:le.Position.Bottom,multiple:!1,id:i.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),k,e.jsx(Hn,{step:n}),f&&n.uses.trigger===!0&&e.jsx(zi,{nodeId:t}),s.loopOf&&e.jsx(Bn,{id:t}),e.jsxs("div",{className:"w6w-muted",style:{marginTop:3,fontSize:10,opacity:.75,paddingLeft:2},children:[n.id,c!=null&&c.version?` - v${c.version}`:""]}),n.notes&&e.jsx("div",{className:"w6w-muted w6w-node-notes",title:n.notes,children:n.notes})]})}function Hi({id:t,data:s,selected:o}){const n=s.step,r=i.routesForStep(n),c=n.uses.app===i.ROUTER_APP,l=i.isIfStep(n),f=r.length?i.routerPortLayout(r):l?i.ifPortLayout():void 0,d=JSON.stringify(r.map(F=>F.id)),x=le.useUpdateNodeInternals();u.useEffect(()=>{x(t)},[t,d,x]);const h=i.internalNodeLabel(n.uses.app,n.uses.action),m=i.internalNodeIcon(n.uses.app,n.uses.action),k=i.nodePortsForStep(n,u.useContext(hs)),j=i.isTriggerStep(n.uses),y=Wi(n),C=Mn(s.stepStatus??"no-run",s.runStatus),M=e.jsx(Un,{step:n,count:u.useContext(ms).get(t)??0}),w=Vn(t);return e.jsxs("div",{className:[y?"w6w-node-foreach":"",s.loopOf?"w6w-node-in-loop":"",We(n)?"w6w-node-disabled":""].filter(Boolean).join(" ")||void 0,"data-loop-of":s.loopOf,style:w,"data-disabled":We(n)||void 0,"data-paused":tt(n)||void 0,children:[e.jsx(zn,{id:t,step:n,runnable:!i.isControlApp(n.uses.app)}),e.jsxs("div",{className:j?"w6w-node-trigger":c?"w6w-node-router":void 0,"data-node-kind":j?"trigger":void 0,"data-run-status":s.stepStatus??"no-run",...Jn(s.stepProblems),style:{position:"relative",...s.stepProblems?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${C.borderWidth}px ${C.borderStyle} ${o?"var(--w6w-accent)":C.borderColor}`,opacity:We(n)?.45:o?1:C.opacity,background:"var(--w6w-panel-2)",color:"var(--w6w-text)",...j?{}:{borderRadius:4,padding:"6px 14px 6px 8px"},minWidth:140,...f!=null&&f.minHeight?{minHeight:f.minHeight,boxSizing:"border-box"}:{},fontSize:13,display:"flex",alignItems:"center",gap:10},children:[e.jsx(qn,{problems:s.stepProblems}),k.in>0&&e.jsx(He,{type:"target",position:le.Position.Left,multiple:k.in>1}),m&&e.jsx(i.InternalIcon,{icon:m}),e.jsxs("div",{style:{minWidth:0,textAlign:"left"},children:[e.jsx("div",{style:{fontWeight:600},children:h}),e.jsx("div",{className:"w6w-muted w6w-small",style:{marginTop:2},children:e.jsx("code",{children:n.uses.action||"—"})})]}),y&&e.jsxs("div",{className:"w6w-foreach-ports w6w-small","aria-hidden":"true",children:[e.jsx("span",{children:"Each item"}),e.jsx("span",{children:"Done"})]}),l&&(f==null?void 0:f.right[0])&&e.jsx("span",{className:"w6w-if-true-label w6w-small","aria-hidden":"true",children:f.right[0].label}),!l&&!!(f!=null&&f.right.length)&&e.jsx("div",{className:"w6w-router-ports w6w-small",style:{gridTemplateRows:`repeat(${f.right.length}, 1fr)`},"aria-hidden":"true",children:f.right.map(F=>e.jsx("span",{title:F.label,children:F.label},F.id))}),k.out>0&&e.jsxs(e.Fragment,{children:[y&&e.jsx(He,{type:"source",position:le.Position.Right,multiple:!1,id:i.EACH_SOURCE_HANDLE,variant:"each"}),f?e.jsxs(e.Fragment,{children:[f.right.map(F=>e.jsx(He,{type:"source",position:le.Position.Right,multiple:!1,id:F.handleId,top:F.top,routeLabel:F.label},F.id)),f.bottom&&e.jsxs(e.Fragment,{children:[e.jsx(He,{type:"source",position:le.Position.Bottom,multiple:!1,id:f.bottom.handleId,routeLabel:f.bottom.label}),e.jsx("span",{className:"w6w-router-fallback-label w6w-small","aria-hidden":"true",children:f.bottom.label})]})]}):e.jsx(He,{type:"source",position:le.Position.Right,multiple:k.out>1,id:y?i.routeHandle(i.FOREACH_DONE_ROUTE):void 0}),!j&&!c&&!l&&n.uses.app!==i.RACE_APP&&e.jsx(He,{type:"source",position:le.Position.Bottom,multiple:!1,id:i.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),M,e.jsx(Hn,{step:n}),s.loopOf&&e.jsx(Bn,{id:t}),s.legacyLoop&&e.jsx("div",{className:"w6w-loop-legacy-note w6w-small",children:"This loop was converted from an older definition. Its steps after For each now run once per item; check the order, then save."}),e.jsx("div",{className:"w6w-muted",style:{marginTop:3,fontSize:10,opacity:.75,paddingLeft:2},children:n.id}),n.notes&&e.jsx("div",{className:"w6w-muted w6w-node-notes",title:n.notes,children:n.notes})]})}function Ji(t,s){var l,f;if(!s)return t;const o={...(t==null?void 0:t.steps)??{}};let n=!1;for(const[d,x]of Object.entries(s)){const h=/^nodes\.([^.]+)\.output$/.exec(d);!h||((l=o[h[1]])==null?void 0:l.output)!==void 0||(o[h[1]]={...o[h[1]]??{},output:x},n=!0)}const r=s["trigger.event"],c=r!==void 0&&((f=t==null?void 0:t.trigger)==null?void 0:f.event)===void 0;return!n&&!c?t:{...t??{},...n?{steps:o}:{},...c?{trigger:{...(t==null?void 0:t.trigger)??{},event:r}}:{}}}function qi(t){return e.jsx(Gi,{...t})}function Gi({workflowId:t,step:s,restoreVersion:o,upstreamSteps:n,loop:r,onChange:c,onClose:l,onCancel:f,readOnly:d,initialView:x="props",fanOutCount:h=0,stateOutputFields:m,onTestRun:k,stepProblems:j,otherStepIds:y}){var yt,St,ot,Me;const C=i.useW6WApi(),M=u.useContext(gs),[w,F]=u.useState(s),W=i.useWorkflowConnections(),O=i.connectionIdFor(w,W==null?void 0:W.connections),I={...w,uses:{...w.uses,connection:O}},E=w.uses.connectionRef!==void 0&&!O||i.isConnectionBlocked(I,j),V=j==null?void 0:j.find(T=>T.code==="unknown_connection"&&T.connection===O),K=(j??[]).filter(T=>"fix"in T),[S,g]=u.useState(E?"setup":"configure"),[P,Y]=u.useState(x==="json"?"code":x==="settings"?"config":"props"),[B,ne]=u.useState("props"),[Z,A]=u.useState(()=>i.stepToJson(s)),[X,D]=u.useState("{}"),z=u.useRef(null),[U,ie]=u.useState(!1),J=u.useRef(o);u.useEffect(()=>{J.current!==o&&(J.current=o,F(s),A(i.stepToJson(s)))},[o,s]);const[H,q]=u.useState(!1),[Q,fe]=u.useState(null),[Je,_e]=u.useState(null),[lt,Se]=u.useState(null),[qe,Ie]=u.useState(!1),ge=i.isInternalApp(w.uses.app),ce=w.uses.trigger===!0;u.useEffect(()=>{if(ge){fe(i.internalNodeParams(w.uses.app,w.uses.action));const te=i.INTERNAL_NODES.filter(ae=>ae.app===w.uses.app&&ae.groupActions&&!ae.hidden);_e(te.length?te.map(ae=>({key:ae.action,title:ae.label,params:ae.params})):null);return}if(!w.uses.app){_e(null),fe([]);return}let T=!1;return fe(null),(ce?i.getTriggerDefs(C,w.uses.app):C.getAppActions(w.uses.app)).then(te=>{var ae;T||(_e(te),fe(w.uses.action?((ae=te.find(je=>je.key===w.uses.action))==null?void 0:ae.params)??[]:[]))}).catch(()=>!T&&fe([])),()=>{T=!0}},[C,w.uses.app,w.uses.action,ge,ce]);const ke=u.useRef(0);u.useEffect(()=>()=>{ke.current++},[]);const Be=u.useCallback(()=>{ge||!w.uses.app||C.listConnectionsForApp(w.uses.app).then(T=>{Se(T),Ie(!1)}).catch(()=>Ie(!0))},[C,w.uses.app,ge]);u.useEffect(()=>{if(ge||!w.uses.app)return;let T=!1;return Se(null),Ie(!1),C.listConnectionsForApp(w.uses.app).then(te=>{T||(Se(te),Ie(!1))}).catch(()=>!T&&Ie(!0)),()=>{T=!0}},[C,w.uses.app,ge]);const oe=u.useCallback(T=>{F(T),c(T)},[c]),bt=Ho({enabled:w.uses.app===i.SCRIPT_APP&&!d,values:w.with??{},onChange:T=>oe({...w,with:T})}),de=T=>{T==="code"&&A(i.stepToJson(w)),Y(T)},Pe=T=>{const te=i.stepNameError(T,y??[]);return te||oe({...w,id:T}),te},Oe=!!w.uses.app&&!!w.uses.action&&!i.isControlApp(w.uses.app),Ee=i.isForeachStep(w),xe=i.isTriggerStep(w.uses),Ge=S==="test"&&Oe&&!xe,ye=i.useSeedSources(t,n,Oe&&!xe||Ee),Ve=On(Oe&&!xe?r:void 0),Re=i.useExpressionOptions(),Fe=i.startStateFromSeeds(ye,$n(Ve),(yt=Re.stateShape)==null?void 0:yt.written),ct=Ji(Fe,Re.sampleValues),Ne=i.useRememberedTestInput(Oe&&!xe||Ee?t:void 0,w.id),[be,$e]=u.useState(!1);u.useEffect(()=>{if((!Oe||xe)&&!Ee||!Ne.loaded)return;if(!Ee&&Ne.input!==void 0){const te=Ne.input;if(Object.keys(te).length===0)return;const ae=JSON.stringify(te,null,2);D(je=>je.trim()==="{}"?ae:je),$e(!0);return}let T=!1;return C.listStepTests(t,w.id).then(te=>{if(T)return;const ae=te.length?te[te.length-1]:null;if(!(ae!=null&&ae.input)||Object.keys(ae.input).length===0)return;const je=JSON.stringify(ae.input,null,2);D(Ye=>Ye.trim()==="{}"?je:Ye)}).catch(()=>{}),()=>{T=!0}},[C,t,w.id,Oe,xe,Ee,Ne.loaded]);const De=Ee?_i(X):Wt(X),Le={...w.with??{},...De??{}},dt=De??{},st=!!Q&&!bs(Ve)&&i.requiredParamsFilled(Q,Le)&&(w.uses.app!==i.CALL_APP||H),ee=Ee?i.resolveLoopItemsInState(Le.items,Fe):void 0,[nt,Ke]=u.useState("idle"),jt=T=>{D(T),Ke("idle")},ut=async()=>{if(ee){Ke("saving");try{await C.saveStepTest(t,w.id,i.foreachTestFixture(ee,dt)),Ke("saved")}catch{Ke("failed")}}},ue=M.get(w.uses.app),vt=ce?(St=Je==null?void 0:Je.find(T=>T.key===w.uses.action))==null?void 0:St.webhook:void 0,pt=ge?i.internalNodeIcon(w.uses.app,w.uses.action):null,Bt=ge?pt?e.jsx(i.InternalIcon,{icon:pt}):null:e.jsx(i.AppIcon,{src:ue==null?void 0:ue.iconSvg,srcDark:ue==null?void 0:ue.iconSvgDark,brandColor:ue==null?void 0:ue.brandColor,name:ue==null?void 0:ue.displayName});return e.jsx(i.Modal,{ariaLabel:"Edit step",titleIcon:Bt,title:e.jsx(i.StepNameEditor,{value:w.id,onCommit:Pe,readOnly:d}),onClose:f??l,size:"wide",children:e.jsxs("div",{className:"w6w-stepconfig",children:[e.jsxs("div",{className:"w6w-tabsbar",children:[e.jsx("div",{className:"w6w-subtabs",children:["setup","configure","test"].filter(T=>w.uses.app!==i.RACE_APP||T!=="test").map(T=>e.jsx("button",{type:"button",className:`w6w-subtab${S===T?" active":""}`,disabled:E&&T!=="setup",onClick:()=>g(T),children:T==="setup"?"Setup":T==="configure"?"Configure":"Test"},T))}),Ge?e.jsx(i.ConfigViewToggle,{view:B,views:["props","code"],onChange:T=>ne(T)}):e.jsx(i.ConfigViewToggle,{view:P,customized:i.hasParamCustomization(w.with??{}),onChange:de,disabled:S!=="configure"})]}),E&&V&&e.jsxs("div",{role:"alert",className:"w6w-field-error",children:["Connection ",V.connection," no longer exists — choose another to continue."]}),K.length>0&&e.jsx("div",{className:"w6w-stepproblem-fixes",style:{display:"grid",gap:6},children:K.map(T=>e.jsxs("div",{className:"w6w-small",style:{display:"flex",gap:8,alignItems:"center"},children:[e.jsx("span",{children:i.stepProblemTooltip(T)}),e.jsx("button",{type:"button",className:"w6w-btn","data-fix-code":T.code,disabled:d,onClick:()=>{const te=Ln(w,T);oe(te),A(i.stepToJson(te))},children:"fix"in T?T.fix.label:""})]},T.code))}),e.jsxs("div",{className:"w6w-stepconfig-body",children:[S==="setup"&&w.uses.app===i.CALL_APP&&e.jsx(i.CallTargetForm,{values:w.with??{},onChange:T=>oe({...w,with:T}),readOnly:d,onValidityChange:q,setupOnly:!0}),S==="setup"&&w.uses.app!==i.CALL_APP&&e.jsx(Xi,{step:w,app:ue,actions:Je,conns:lt,connsFailed:qe,isInternal:ge,actionLabel:ce?"Trigger":"Action",readOnly:d,onChangeAction:T=>{var ae;const te=ge?i.internalNodeDefaults(w.uses.app,T):{};if(ge)for(const je of i.internalNodeParams(w.uses.app,T))je.key in(w.with??{})&&(te[je.key]=(ae=w.with)==null?void 0:ae[je.key]);oe({...w,uses:{...w.uses,action:T},with:te})},onChangeTriggerEvents:(T,te)=>oe({...w,uses:{...w.uses,action:T},with:{...w.with,actions:te}}),onChangeConnection:T=>{if(!W){const{connectionRef:ae,...je}=w.uses;oe({...w,uses:{...je,connection:T}});return}const te=i.selectNodeConnection(w,T,(W==null?void 0:W.nodes)??[w],(W==null?void 0:W.connections)??{});W==null||W.setConnections(te.connections),oe(te.step)},onChangeConnectionRef:T=>oe(i.withConnectionRef(w,T)),onConnectionCreated:Be,onChangeApp:T=>{const te=++ke.current;if(T===w.uses.app){oe(w);return}const ae={...w,uses:{app:T,action:"",...ce?{trigger:!0}:{}},with:{}};(i.isInternalApp(T)?Promise.resolve([]):C.listConnectionsForApp(T)).catch(()=>[]).then(je=>{if(te!==ke.current)return;const Ye=i.defaultConnectionFor(ae,je,(W==null?void 0:W.nodes)??[],(W==null?void 0:W.connections)??{});oe({...ae,uses:{...ae.uses,...Ye}})})}}),S==="configure"&&e.jsxs(e.Fragment,{children:[(w.uses.app===i.WEBHOOK_APP||w.uses.app===i.FORM_APP)&&C.listSubscriptionsForWorkflow&&C.createSubscription&&e.jsx(Yi,{workflowId:t,step:w,readOnly:d}),ce&&vt&&w.uses.action&&C.listSubscriptionsForWorkflow&&e.jsx(Ro,{workflowId:t,nodeId:w.id,appId:w.uses.app,triggerKey:w.uses.action,appName:(ue==null?void 0:ue.displayName)??w.uses.app,setup:vt,connectionId:O&&!O.startsWith("zerocred:")?O:null,params:w.with??{},readOnly:d}),Q===null?e.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):P==="props"?w.uses.app===i.CALL_APP?e.jsx(i.CallTargetForm,{values:w.with??{},onChange:T=>oe({...w,with:T}),readOnly:d,onValidityChange:q}):w.uses.app===i.RACE_APP?e.jsx("p",{className:"w6w-muted w6w-small",children:i.RACE_DESCRIPTION}):w.uses.action==="wait"&&i.isControlApp(w.uses.app)?e.jsx(i.WaitEditor,{values:w.with??{},readOnly:d,onChange:T=>oe({...w,with:T})}):w.uses.action==="if"&&i.isControlApp(w.uses.app)?e.jsx(i.ConditionEditor,{values:w.with??{},readOnly:d,onChange:T=>oe({...w,with:T})}):w.uses.app==="@w6w/stop"?e.jsx(i.StopEditor,{values:w.with??{},readOnly:d,onChange:T=>oe({...w,with:T})}):w.uses.app===i.ROUTER_APP?e.jsx(i.RouterEditor,{values:w.with??{},readOnly:d,onChange:T=>oe({...w,with:T})}):w.uses.app===i.FORM_APP?e.jsxs("div",{className:"w6w-stack",children:[e.jsx(xo,{value:(ot=w.with)==null?void 0:ot.form,readOnly:d,stepId:w.id,onChange:T=>oe({...w,with:{...w.with,form:T}})}),e.jsx(i.ParamsForm,{params:Q.filter(T=>T.key!=="form"),values:w.with??{},readOnly:d,onChange:T=>oe({...w,with:T})})]}):e.jsxs(e.Fragment,{children:[w.uses.app===i.SCRIPT_APP&&e.jsx(Jo,{values:w.with??{},conversion:bt,readOnly:d}),e.jsx(i.ParamsForm,{params:Q,values:w.with??{},readOnly:d,onChange:T=>oe({...w,with:T}),dynamic:ge||!w.uses.action?void 0:{appId:w.uses.app,actionKey:w.uses.action,kind:i.isTriggerStep(w.uses)?"trigger":"action",connectionId:E?void 0:O,appName:ue==null?void 0:ue.displayName}})]}):P==="code"?e.jsx(i.JsonEditor,{value:Z,onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":`Node ${w.id} JSON`,copyable:!0}):P==="params-code"?e.jsx(i.ParamCustomization,{values:w.with??{},onChange:T=>oe({...w,with:T}),readOnly:d}):e.jsxs("div",{className:"w6w-stack",children:[e.jsx(i.NodeConfigForm,{config:{retry:w.retry,onError:w.onError,notes:w.notes},onChange:T=>oe({...w,...T}),readOnly:d,failureHandling:!xe,retryControls:!i.isControlApp(w.uses.app)&&w.uses.app!==i.CALL_APP}),Ki,e.jsx(i.StepFanOutControl,{step:w,count:h,readOnly:d,onChange:oe}),i.stateWriteVisible(w)&&e.jsx(i.StepStateControl,{step:w,inLoop:r!==void 0,outputFields:m,readOnly:d,onChange:oe})]})]}),S==="test"&&e.jsx("div",{className:"w6w-stack",children:Oe?xe?e.jsx(i.TriggerFillForm,{app:w.uses.app,action:w.uses.action,fields:ce||(Me=w.with)==null?void 0:Me.fields,appTrigger:ce,persist:{workflowId:t,stepId:w.id,input:dt},listen:(w.uses.app===i.WEBHOOK_APP||w.uses.app===i.FORM_APP)&&C.listSubscriptionsForWorkflow&&C.startWebhookListen?{stepWith:w.with,readOnly:d,appId:w.uses.app}:void 0}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"w6w-muted w6w-small",children:["Tests ",e.jsx("code",{children:w.uses.action})," with the configuration saved on this step — only the incoming state changes per run."]}),e.jsx(Wn,{seed:Ve,readOnly:d}),be&&!d&&e.jsx(i.LastUsedNote,{onClear:()=>{Ne.clear(),$e(!1),D("{}")}}),e.jsx(ds,{text:X,onChange:D,seeds:ye,readOnly:d}),Q===null?e.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):e.jsx(Wo,{params:Q,values:Le,testStartState:ct,view:B,literalKeys:w.uses.app===i.SCRIPT_APP?Mi:void 0}),e.jsx(i.StepTestRun,{ref:z,app:w.uses.app,action:w.uses.action,connectionId:O,values:Le,state:Fe,canRun:st,hideRunButton:!0,persist:{workflowId:t,stepId:w.id,input:dt},onBusyChange:ie})]}):Ee?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"w6w-muted w6w-small",children:["Resolves ",e.jsx("strong",{children:"Items"})," against the incoming state — nothing inside the loop runs. ",e.jsx("strong",{children:"Test"})," saves the first item as this loop's sample, so the steps on its ",e.jsx("strong",{children:"Each item"})," output can pick its keys. To run the loop's work, test a step on ",e.jsx("strong",{children:"Each item"}),": it runs once, on one item."]}),e.jsx(ds,{text:X,onChange:jt,seeds:ye,readOnly:d,expand:!ee,hint:e.jsxs(e.Fragment,{children:["Paste a sample list — ",e.jsx("code",{children:'[{"id": 1, "name": "…"}]'})," — or"," ",e.jsx("code",{children:'{"items": […]}'}),". It replaces what ",e.jsx("strong",{children:"Items"})," ","resolves to, for this test only."]})}),e.jsx(Oi,{items:ee,save:nt})]}):e.jsx("p",{className:"w6w-muted w6w-small",children:"Flow-control nodes can't be tested on their own."})})]}),e.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[f&&!d&&e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:f,children:"Cancel"}),w.uses.app===i.RACE_APP&&S==="configure"?e.jsx("button",{type:"button",className:"w6w-btn",onClick:l,children:"Done"}):S!=="test"?e.jsxs(e.Fragment,{children:[f&&!d&&e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:l,children:"Done"}),e.jsx("button",{type:"button",className:"w6w-btn",disabled:E,onClick:()=>g(S==="setup"?"configure":"test"),children:"Next →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:l,children:"Done"}),Oe&&!xe&&e.jsx("button",{type:"button",className:"w6w-btn",disabled:d||!st||U,onClick:()=>{var T;k==null||k(),(T=z.current)==null||T.run()},children:U?"Testing…":"Test"}),Ee&&e.jsx("button",{type:"button",className:"w6w-btn",disabled:d||!(ee!=null&&ee.length)||nt==="saving",onClick:()=>void ut(),children:nt==="saving"?"Testing…":"Test"})]})]})]})})}const Ki=!1;function Yi({workflowId:t,step:s,readOnly:o}){const n=i.useW6WApi(),r=s.uses.app===i.FORM_APP,[c,l]=u.useState(void 0),[f,d]=u.useState(null),[x,h]=u.useState(!1),m=(c==null?void 0:c.webhookUrl)??(c==null?void 0:c.formUrl);u.useEffect(()=>{const j=n.listSubscriptionsForWorkflow;if(!j)return;let y=!1;return j(t).then(C=>{y||l(r?i.pickFormSubscription(C,s.id):i.pickWebhookSubscription(C,s.id))}).catch(C=>!y&&d(C.message)),()=>{y=!0}},[n,t,s.id,r]);const k=()=>{const j=n.createSubscription;j&&(d(null),h(!0),j(r?i.FORM_APP:i.WEBHOOK_APP,s.uses.action,{workflowId:t,connectionId:null,params:r?{node:s.id}:s.with??{}}).then(y=>{h(!1),l(y)}).catch(y=>{h(!1),d(y instanceof Error?y.message:String(y))}))};return e.jsxs("div",{className:"w6w-stack w6w-url-panel",children:[e.jsx("p",{className:"w6w-muted w6w-small",children:r?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"Form URL"})," — share it, or embed it in an iframe. Each submission starts the workflow once it is published."]}):e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"Webhook URL"})," — the address a third party posts to."]})}),f&&e.jsx("div",{className:"w6w-result w6w-error",children:f}),m?e.jsxs("div",{className:"w6w-listen-url",children:[e.jsx(we.Copyable,{value:m,readOnly:!0,children:e.jsx("input",{type:"text",readOnly:!0,value:m,"aria-label":r?"Form URL":"Webhook URL"})}),r&&e.jsx("a",{className:"w6w-btn w6w-btn-ghost w6w-btn-sm",href:m,target:"_blank",rel:"noreferrer",children:"Open form"})]}):c===void 0?e.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}):!o&&e.jsx("button",{type:"button",className:"w6w-btn",disabled:x,onClick:k,children:x?"Creating…":r?"Create form URL":"Create webhook URL"})]})}function Xi({step:t,app:s,actions:o,conns:n,connsFailed:r,isInternal:c,actionLabel:l="Action",readOnly:f,onChangeAction:d,onChangeTriggerEvents:x,onChangeConnection:h,onChangeConnectionRef:m,onChangeApp:k,onConnectionCreated:j}){const y=t.uses.trigger?i.eventbriteTriggerChoices(t.uses.app,o,t.uses.action,t.with??{}):null,[C,M]=u.useState(null),w=u.useRef(null),F=i.useWorkflowConnections(),W=i.connectionIdFor(t,F==null?void 0:F.connections);return e.jsxs("div",{className:"w6w-stack",children:[t.uses.connectionRef&&!W&&e.jsx("p",{role:"alert",className:"w6w-field-error",children:"The shared connection is missing or unbound. Choose an account."}),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"App"}),e.jsxs("div",{className:"w6w-app-conn-row",ref:w,children:[e.jsxs("button",{type:"button",className:"w6w-app-conn-btn","aria-label":"App","aria-expanded":C==="app",disabled:f,onClick:()=>M(O=>O==="app"?null:"app"),children:[!c&&s&&e.jsx(i.AppIcon,{src:s.iconSvg,srcDark:s.iconSvgDark,brandColor:s.brandColor,name:s.displayName,size:20}),e.jsx("span",{className:"w6w-conn-label-name",children:c?t.uses.app:(s==null?void 0:s.displayName)??t.uses.app})]}),!c&&e.jsx(i.WorkflowConnectionPicker,{step:t,conns:n,failed:r,readOnly:f,open:C==="conn",onOpenChange:O=>M(O?"conn":null),anchorRef:w,onChangeConnection:h,onChangeConnectionRef:m,onConnectionCreated:j})]}),C==="app"&&e.jsx(i.AnchoredFlyout,{anchorRef:w,onClose:()=>M(null),children:e.jsx(i.AppPicker,{onSelectApp:O=>{const I=O.id===t.uses.app;k(O.id),M(I?"conn":null)}})})]}),c&&!(o!=null&&o.length)?e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Action"}),e.jsx("div",{className:"w6w-muted w6w-small",children:e.jsx("code",{children:t.uses.action})})]}):y?e.jsx(i.EventbriteTriggerPicker,{choices:y,readOnly:f,onChange:O=>x(y.triggerKey,O)}):e.jsxs("label",{className:"w6w-field",children:[e.jsx("span",{children:l}),e.jsx(i.Combobox,{value:t.uses.action,disabled:f||o===null,onChange:d,options:o===null?[{value:t.uses.action,label:t.uses.action}]:o.map(O=>({value:O.key,label:O.title??O.key}))})]})]})}function Sn({trigger:t}){return e.jsx("span",{className:"w6w-connection-node-kind",role:"img","aria-label":t?"Trigger":"Node",children:e.jsx("svg",{"aria-hidden":"true",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:t?e.jsx("path",{d:"M13 2 4 14h7l-1 8 10-12h-7l1-8Z"}):e.jsxs(e.Fragment,{children:[e.jsx("rect",{x:"5",y:"5",width:"14",height:"14",rx:"3"}),e.jsx("path",{d:"M2 12h3m14 0h3"})]})})})}function Zi({resources:t}){const s=i.useW6WApi(),o=t.highlightNode;u.useEffect(()=>()=>o==null?void 0:o(null),[o]);const[n,r]=u.useState([]),[c,l]=u.useState(!0),[f,d]=u.useState(),[x,h]=u.useState(),[m,k]=u.useState(null),[j,y]=u.useState(!1),[C,M]=u.useState(!1),w=u.useRef(0),F=u.useCallback(async()=>{const D=++w.current;l(!0),d(void 0);try{const z=await s.listConnections();return D!==w.current?void 0:(r(z),z)}catch(z){D===w.current&&d(z.message)}finally{D===w.current&&l(!1)}},[s]);u.useEffect(()=>(F(),()=>{w.current++}),[F]);const[W,O]=u.useState(new Map),I=JSON.stringify([...new Set([...Object.values(t.connections).map(D=>D.app),...n.map(D=>D.appId)])].filter(D=>{var z;return!((z=t.apps)!=null&&z.has(D))&&!n.some(U=>U.appId===D&&U.app!==void 0)}).sort());u.useEffect(()=>{var J,H;let D=!1;const z=JSON.parse(I);if(c||!z.length)return;const U=(J=s.listAppsByIds)==null?void 0:J.bind(s),ie=U?Promise.all(Array.from({length:Math.ceil(z.length/50)},(q,Q)=>U(z.slice(Q*50,(Q+1)*50)))).then(q=>q.flat()):(H=s.listApps)==null?void 0:H.call(s);return ie==null||ie.then(q=>{D||O(new Map(q.map(Q=>[Q.id,Q])))}).catch(()=>{}),()=>{D=!0}},[s,I,c]);const R=D=>{var J;const z=n.find(H=>H.appId===D&&H.app)??n.find(H=>H.appId===D&&H.app!==void 0),U=z?i.resolveConnectionAppMeta(z,W):W.get(D),ie=(J=t.apps)==null?void 0:J.get(D);return ie?{...U,...ie}:U},E=D=>{var z;return((z=R(D))==null?void 0:z.displayName)||D},V=D=>{if(t.readOnly)return!1;try{return t.edit(D),h(void 0),!0}catch(z){return h(z.message),!1}},K=D=>i.nextWorkflowConnectionName(D.appId,t.connections),S=()=>{k(null),h(void 0),y(!1)},g=m!=null&&m.ref?t.connections[m.ref]:void 0,P=n.find(D=>D.id===(m==null?void 0:m.connection)),Y=(g==null?void 0:g.app)??(P==null?void 0:P.appId),B=t.nodes.filter(D=>D.uses.app===Y),ne=t.nodes.filter(D=>(m==null?void 0:m.ref)!==void 0&&D.uses.connectionRef===m.ref),Z=n.filter(D=>!g||D.appId===g.app).map(D=>({value:D.id,label:g?D.displayName||D.id:`${E(D.appId)} · ${D.displayName||D.id}`}));m!=null&&m.connection&&!Z.some(D=>D.value===m.connection)&&Z.unshift({value:m.connection,label:m.connection.startsWith("zerocred:")?"Built-in":m.connection});const A=(D,z=28)=>{const U=R(D);return e.jsx(i.AppIcon,{src:U==null?void 0:U.iconSvg,srcDark:U==null?void 0:U.iconSvgDark,brandColor:U==null?void 0:U.brandColor,name:E(D),size:z})},X=()=>{if(!m||!m.name.trim()||!m.connection||!Y)return;const D=m.ref!==void 0?{type:"update",ref:m.ref,name:m.name,connection:m.connection,nodeIds:m.allNodes?B.map(z=>z.id):void 0}:{type:"add",name:m.name,app:Y,connection:m.connection};V(D)&&S()};return e.jsxs("div",{className:"w6w-stack","data-testid":"workflow-connections-panel",children:[e.jsxs("div",{className:"w6w-workflow-connections-heading",children:[e.jsx("h3",{children:"Connections"}),e.jsx(i.IconButton,{label:"Add connection",disabled:t.readOnly,onClick:()=>{h(void 0),k({name:"",connection:"",allNodes:!1})},children:e.jsx("svg",{"aria-hidden":"true",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M12 5v14M5 12h14"})})})]}),f&&e.jsxs("div",{role:"alert",className:"w6w-stack",children:[e.jsxs("p",{className:"w6w-field-error",children:["Couldn’t load connections: ",f]}),e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>void F(),children:"Retry"})]}),Object.entries(t.connections).map(([D,z])=>{var H;const U=t.nodes.filter(q=>q.uses.connectionRef===D),ie=n.find(q=>q.id===z.connection),J=(ie==null?void 0:ie.displayName)||((H=z.connection)!=null&&H.startsWith("zerocred:")?"Built-in":z.connection)||"No credentials selected";return e.jsxs("section",{className:"w6w-workflow-connection","data-connection-resource":D,children:[e.jsxs("div",{className:"w6w-connection-app-heading",children:[A(z.app),e.jsxs("div",{className:"w6w-connection-summary",children:[e.jsx("strong",{children:E(z.app)}),e.jsx("span",{className:"w6w-small",children:J}),e.jsxs("span",{className:"w6w-muted w6w-small",children:[D,ie!=null&&ie.state?` · ${ie.state}`:""]})]}),e.jsx(i.IconButton,{icon:"edit",label:`Edit connection ${D}`,disabled:t.readOnly,onClick:()=>{h(void 0),k({ref:D,name:D,connection:z.connection??"",allNodes:!1})}})]}),U.length>0?e.jsxs("details",{className:"w6w-connection-consumers",onToggle:q=>{q.currentTarget.open||o==null||o(null)},children:[e.jsxs("summary",{className:"w6w-muted w6w-small",children:["Used by ",U.length," ",U.length===1?"node":"nodes"]}),e.jsx("ul",{className:"w6w-connection-node-list",children:U.map(q=>e.jsx("li",{children:t.focusNode?e.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost","aria-label":`Show ${q.id} on canvas`,onClick:()=>{var Q;return(Q=t.focusNode)==null?void 0:Q.call(t,q.id)},onMouseEnter:()=>o==null?void 0:o(q.id),onMouseLeave:()=>o==null?void 0:o(null),onFocus:()=>o==null?void 0:o(q.id),onBlur:()=>o==null?void 0:o(null),children:[e.jsx(Sn,{trigger:i.isTriggerStep(q.uses)}),e.jsxs("span",{className:"w6w-connection-node-label",children:[e.jsx("strong",{children:q.uses.action}),e.jsx("span",{className:"w6w-muted w6w-small",children:q.id})]})]}):e.jsxs("span",{className:"w6w-connection-app-heading",children:[e.jsx(Sn,{trigger:i.isTriggerStep(q.uses)}),e.jsxs("span",{className:"w6w-connection-node-label",children:[e.jsx("strong",{children:q.uses.action}),e.jsx("span",{className:"w6w-muted w6w-small",children:q.id})]})]})},q.id))})]}):e.jsx("span",{className:"w6w-muted w6w-small",children:"Not used by any nodes yet."})]},D)}),!Object.keys(t.connections).length&&e.jsx("p",{className:"w6w-muted w6w-small",children:"No workflow connections yet."}),m&&!C&&!j&&e.jsxs(i.Modal,{title:m.ref!==void 0?"Edit connection":"Add connection",titleIcon:Y?A(Y):void 0,subtitle:Y?E(Y):void 0,onClose:S,children:[e.jsxs("div",{className:"w6w-modal-body w6w-stack",children:[x&&e.jsx("p",{role:"alert",className:"w6w-field-error",children:x}),f&&e.jsxs("div",{role:"alert",className:"w6w-stack",children:[e.jsxs("p",{className:"w6w-field-error",children:["Couldn’t load credentials: ",f]}),e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>void F(),children:"Retry"})]}),m.ref!==void 0&&!g&&e.jsx("p",{role:"alert",children:"This workflow connection no longer exists."}),e.jsxs("label",{className:"w6w-field",children:[e.jsx("span",{children:"Workflow connection name"}),e.jsx("input",{className:"w6w-input","aria-label":"Workflow connection name",value:m.name,disabled:t.readOnly,onChange:D=>k({...m,name:D.target.value})})]}),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:g?"Credentials":"Existing connection"}),e.jsx(i.Combobox,{"aria-label":g?"Credentials":"Connection to add",options:Z,value:m.connection,placeholder:c?"Loading connections…":"Choose a connection…",disabled:t.readOnly||c||!!f,onChange:D=>{const z=n.find(U=>U.id===D);k({...m,connection:D,name:!m.name&&z?K(z):m.name})}})]}),e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:t.readOnly,onClick:()=>M(!0),children:"Create new credentials"}),g&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"w6w-muted w6w-small",children:m.allNodes?`Saving applies these credentials to all ${B.length} ${E(g.app)} nodes.`:`Saving updates credentials for ${ne.length} linked ${ne.length===1?"node":"nodes"}.`}),B.length>0&&e.jsxs("label",{className:"w6w-connection-scope",children:[e.jsx("input",{type:"checkbox",checked:m.allNodes||B.every(D=>D.uses.connectionRef===m.ref),disabled:t.readOnly||B.every(D=>D.uses.connectionRef===m.ref),onChange:D=>k({...m,allNodes:D.target.checked})}),"Use for all ",B.length," ",E(g.app)," ",B.length===1?"node":"nodes"," in this workflow"]}),e.jsxs("div",{className:"w6w-connection-remove",children:[e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:t.readOnly||ne.length>0,onClick:()=>y(!0),children:"Remove from workflow"}),ne.length>0&&e.jsx("p",{className:"w6w-muted w6w-small",children:"Assign another connection to the linked nodes before removing this one."})]})]})]}),e.jsxs("div",{className:"w6w-modal-actions",children:[e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:S,children:"Cancel"}),e.jsx("button",{type:"button",className:"w6w-btn",disabled:t.readOnly||c||!!f||!m.name.trim()||!m.connection||!Y||m.ref!==void 0&&!g,onClick:X,children:m.ref!==void 0?"Save changes":"Add to workflow"})]})]}),m&&j&&e.jsx(i.ConfirmModal,{title:"Remove workflow connection",message:`Remove “${m.ref}” from this workflow? The saved credentials will remain available.`,confirmLabel:"Remove",onClose:()=>y(!1),onConfirm:()=>{m.ref&&V({type:"remove",ref:m.ref})?S():y(!1)}}),m&&C&&e.jsx(i.AddConnectionModal,{initialAppId:g==null?void 0:g.app,onClose:()=>M(!1),onCreated:({connectionId:D})=>{M(!1),F().then(z=>{const U=z==null?void 0:z.find(ie=>ie.id===D);U&&k(ie=>ie?{...ie,connection:U.id,name:ie.name||K(U)}:null)})}})]})}exports.CALL_APP=i.CALL_APP;exports.CONTROL_APP=i.CONTROL_APP;exports.CanvasLayer=i.CanvasLayer;exports.DATA_APP=i.DATA_APP;exports.ExpressionOptionsProvider=i.ExpressionOptionsProvider;exports.INTERNAL_NODES=i.INTERNAL_NODES;exports.Markdown=i.Markdown;exports.RACE_APP=i.RACE_APP;exports.SCHEDULER_APP=i.SCHEDULER_APP;exports.SCRIPT_APP=i.SCRIPT_APP;exports.TRIGGER_APP=i.TRIGGER_APP;exports.WEBHOOK_APP=i.WEBHOOK_APP;exports.asFieldDefs=i.asFieldDefs;exports.centralizeConnections=i.centralizeConnections;exports.coerceDefault=i.coerceDefault;exports.connectionIdFor=i.connectionIdFor;exports.fieldWidget=i.fieldWidget;exports.fieldsToParams=i.fieldsToParams;exports.flowToWorkflow=i.flowToWorkflow;exports.internalNodeDefaults=i.internalNodeDefaults;exports.internalNodeIcon=i.internalNodeIcon;exports.internalNodeLabel=i.internalNodeLabel;exports.internalNodeParams=i.internalNodeParams;exports.isControlApp=i.isControlApp;exports.isInternalApp=i.isInternalApp;exports.isTriggerApp=i.isTriggerApp;exports.isTriggerStep=i.isTriggerStep;exports.seedValues=i.seedValues;exports.workflowToFlow=i.workflowToFlow;exports.MAX_NOTES=Nn;exports.MAX_NOTE_BYTES=kn;exports.MAX_SECTIONS=Cn;exports.WorkflowConnectionsPanel=Zi;exports.WorkflowFlowEditor=Di;exports.applyStepProblemFix=Ln;exports.assignMembership=is;exports.clampCanvas=rs;exports.findLoopProblems=ci;exports.findStateWriteProblems=pi;exports.isDisabledStep=We;exports.isPausedStep=tt;exports.pausedStopAt=ls;exports.pruneSectionMembers=us;exports.renameSectionMember=os;exports.roundGeometry=ns;exports.sectionsContaining=Tn;exports.withCanvasGeometry=En;exports.withDisabled=Fn;exports.withPaused=Rn;
|
|
6
7
|
//# sourceMappingURL=flow.cjs.map
|