@w6w/ui 0.2.57 → 0.2.58
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 +9 -0
- package/dist/StepBuilderModal.d.ts +9 -2
- package/dist/TriggerFillForm.d.ts +4 -3
- package/dist/WorkflowFlowEditor.d.ts +6 -0
- package/dist/components/ExpressionOptions.d.ts +2 -0
- package/dist/condition-editor.d.ts +3 -1
- package/dist/connection-app-meta-CKTmUX08.cjs +24 -0
- package/dist/connection-app-meta-CKTmUX08.cjs.map +1 -0
- package/dist/{connection-app-meta-aURFNTx_.js → connection-app-meta-D5hNbJB5.js} +4462 -4234
- package/dist/connection-app-meta-D5hNbJB5.js.map +1 -0
- package/dist/flow-history.d.ts +8 -0
- package/dist/flow.cjs +5 -5
- package/dist/flow.cjs.map +1 -1
- package/dist/flow.mjs +2110 -2064
- package/dist/flow.mjs.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +9 -2
- package/dist/index.mjs.map +1 -1
- package/dist/provider.d.ts +6 -0
- package/dist/state-shape.d.ts +13 -0
- package/dist/step-preview-state.d.ts +10 -1
- package/dist/types.d.ts +8 -0
- package/package.json +3 -1
- package/src/code.css +2 -1
- package/src/styles/_box-reset.scss +22 -0
- package/src/styles/_canvas.scss +1 -4
- package/src/styles/_chips.scss +0 -1
- package/src/styles/_copyable.scss +3 -1
- package/src/styles/_data-stores.scss +15 -5
- package/src/styles/_data-table.scss +6 -0
- package/src/styles/_data-vars.scss +10 -0
- package/src/styles/_execution-log.scss +3 -4
- package/src/styles/_fields.scss +57 -25
- package/src/styles/_flow.scss +11 -0
- package/src/styles/_fx.scss +14 -47
- package/src/styles/_host-guard.scss +100 -0
- package/src/styles/_step-builder.scss +4 -2
- package/src/styles/_step-config.scss +4 -5
- package/src/styles.css +172 -95
- package/src/styles.scss +2 -0
- package/dist/connection-app-meta-BeYDm-cs.cjs +0 -24
- package/dist/connection-app-meta-BeYDm-cs.cjs.map +0 -1
- package/dist/connection-app-meta-aURFNTx_.js.map +0 -1
package/dist/flow.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use client";"use strict";var no=Object.defineProperty;var oo=(e,s,o)=>s in e?no(e,s,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[s]=o;var it=(e,s,o)=>oo(e,typeof s!="symbol"?s+"":s,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),be=require("@w6w/expr"),ne=require("@xyflow/react"),d=require("react"),i=require("./connection-app-meta-BeYDm-cs.cjs"),ve=require("./CodeBlock-BSX1pi6W.cjs");function io({x:e,y:s,items:o,onAction:n,onClose:a}){const c=d.useRef(null),[l,p]=d.useState({left:e,top:s});d.useLayoutEffect(()=>{const g=c.current,x=g==null?void 0:g.offsetParent;if(!g||!x)return;const h=g.offsetWidth,v=g.offsetHeight;p({left:e+h>x.clientWidth?Math.max(0,e-h):e,top:s+v>x.clientHeight?Math.max(0,s-v):s})},[e,s]),d.useEffect(()=>{var g,x;(x=(g=c.current)==null?void 0:g.querySelector("[role=menuitem]"))==null||x.focus({preventScroll:!0})},[]),d.useEffect(()=>{const g=v=>{var S;(S=c.current)!=null&&S.contains(v.target)||a(!1)},x=v=>{var S;(S=c.current)!=null&&S.contains(v.target)||a(!1)},h=()=>a(!1);return document.addEventListener("pointerdown",g,!0),document.addEventListener("scroll",x,!0),document.addEventListener("wheel",x,{capture:!0,passive:!0}),window.addEventListener("blur",h),window.addEventListener("resize",h),()=>{document.removeEventListener("pointerdown",g,!0),document.removeEventListener("scroll",x,!0),document.removeEventListener("wheel",x,!0),window.removeEventListener("blur",h),window.removeEventListener("resize",h)}},[a]);const m=g=>{g.disabled||(a(!1),n(g.action))};return t.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:g=>g.preventDefault(),onKeyDown:g=>{var S;g.stopPropagation();const x=[...((S=c.current)==null?void 0:S.querySelectorAll("[role=menuitem]"))??[]],h=x.indexOf(document.activeElement),v=P=>{var L;return(L=x[(P+x.length)%x.length])==null?void 0:L.focus()};if(g.key==="ArrowDown")v(h+1);else if(g.key==="ArrowUp")v(h<0?-1:h-1);else if(g.key==="Home")v(0);else if(g.key==="End")v(-1);else if(g.key==="Escape"||g.key==="Tab")a(!0);else if(g.key==="Enter"||g.key===" ")h>=0&&m(o[h]);else return;g.preventDefault()},children:o.map(g=>t.jsx("button",{type:"button",role:"menuitem",tabIndex:-1,"aria-disabled":g.disabled||void 0,className:`w6w-note-menu-item${g.danger?" danger":""}${g.separated?" separated":""}`,"data-action":g.action,onClick:()=>m(g),children:g.label},g.action))})}function ro(e){return e===null||typeof e!="object"||Array.isArray(e)?null:e}function ao({app:e,trigger:s,onUse:o}){const n=i.useW6WApi(),[a,c]=d.useState(null);return d.useEffect(()=>{var p;let l=!1;return c(null),(p=n.getAppTriggers)==null||p.call(n,e).then(m=>{var g;l||c(ro((g=m.find(x=>x.key===s))==null?void 0:g.sample))}).catch(()=>{}),()=>{l=!0}},[n,e,s]),a?t.jsx("div",{children:t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost","data-testid":"use-trigger-sample",onClick:()=>o(a),children:"Use sample event"})}):null}function co(e,s){return s===void 0?[...e]:e.includes(s)?[...e]:[s]}function lo(e,s){const o=[],n=e.length;if(n>0){const a=n>1?` ${n} nodes`:"";o.push({action:"duplicate",label:`Duplicate${a}`,disabled:s}),o.push({action:"delete",label:`Delete${a}`,disabled:s,danger:!0})}return o.push({action:"add-node",label:"Add node",disabled:s,separated:n>0}),o.push({action:"add-trigger",label:"Add trigger",disabled:s}),o}const dn=200,un=200,pn=10240;function Gt(e){const s={};for(const[o,n]of Object.entries(e))s[o]=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 zs(e,s,o){return e&&e.map(n=>{const a=s==null?void 0:s[n.id],c=uo(a==null?void 0:a.position)?a.position:n.position,l=po(a==null?void 0:a.size)?a.size:n.size;return{...n,position:Gt(c),size:Gt(l)}})}function fn(e,s,o){if(!s)return e;const n={...e};return e.notes&&(n.notes=zs(e.notes,o)),e.sections&&(n.sections=zs(e.sections,o)),n}function ts(e,s){return e.sections?{...e,sections:e.sections.map(o=>({...o,nodes:o.nodes.filter(n=>n!==s)}))}:e}function hn(e,s,o){return e.sections?{...e,sections:e.sections.map(n=>({...n,nodes:n.nodes.map(a=>a===s?o:a)}))}:e}function Kt(e,s,o){if(!e.sections)return e;const n=new Set(o);return{...e,sections:e.sections.map(a=>{const c=a.nodes.filter(l=>!n.has(l));return a.id===s?{...a,nodes:[...new Set([...c,...o])]}:{...a,nodes:c}})}}function mn(e,s){return(e.sections??[]).filter(o=>o.nodes.includes(s)).map(o=>o.id)}function fo(e,s){const o=new TextEncoder;if(o.encode(e).length<=s)return e;let n="",a=0;for(const c of e){const l=o.encode(c).length;if(a+l>s)break;n+=c,a+=l}return n}function Xt(e){const s={...e};return e.notes&&(s.notes=e.notes.slice(0,dn).map(o=>({...o,content:fo(o.content,pn)}))),e.sections&&(s.sections=e.sections.slice(0,un)),s}function ho(e,s,o){const n={};for(const l of[...e.notes??[],...e.sections??[]])n[l.id]={position:l.position,size:l.size};const a=(l,p)=>l==null?void 0:l.map(m=>{const g=p==null?void 0:p.find(x=>x.id===m.id);return g?{...m,position:g.position,size:g.size}:m}),c=o?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 fn(c,o,n)}const Hs=220;function mo(e){return e.length<=Hs?{text:e,clipped:!1,length:e.length}:{text:e.slice(0,Hs).trimEnd(),clipped:!0,length:e.length}}function wo({params:e,values:s,testStartState:o,view:n="props",literalKeys:a}){const{sampleValues:c,nodeConfig:l,nodeMeta:p}=i.useExpressionOptions(),m=d.useMemo(()=>i.buildResolveScope(c,o,l,p),[c,o,l,p]),g=i.flattenParams(e),x=S=>{var P;return s[S]!==void 0?s[S]:(P=g.find(L=>L.key===S))==null?void 0:P.default},h=g.filter(S=>S.type!=="section"&&i.isParamVisible(S,x)).map(S=>be.effectiveParam(S,x));if(i.hasParamCustomization(s)){const S=i.previewCustomization(s.$merge,m,a),P=S!==null&&typeof S=="object"&&!Array.isArray(S),L=Js(h,s,m,a);for(const[V,N]of Object.entries(s))V!=="$merge"&&(L[V]=a!=null&&a.includes(V)?N:i.previewCustomization(N,m));const f=P?{...L,...S}:L;return t.jsxs("div",{className:"w6w-resolved-params",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:P?"JSON customization applied after form values.":`JSON customization is not available as an object in this preview (${String(S)}). Test the step to validate it.`}),n==="code"?t.jsx(i.JsonEditor,{value:JSON.stringify(f,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(f).map(([V,N])=>{var J;return t.jsx(Yt,{label:((J=g.find(U=>U.key===V))==null?void 0:J.label)??V,segments:[{status:"resolved",value:N}]},V)})})]})}if(n==="code"){const S=Js(h,s,m,a);return t.jsx("div",{className:"w6w-resolved-params",children:t.jsx(i.JsonEditor,{value:JSON.stringify(S,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"})})}const v=h.filter(S=>!i.deepEqual(x(S.key),S.default));return h.length===0?t.jsx("div",{className:"w6w-resolved-params",children:t.jsx("p",{className:"w6w-muted w6w-small",children:"This action takes no parameters."})}):v.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:v.map(S=>S.type==="vars"?t.jsx(go,{param:S,value:s[S.key],scope:m},S.key):t.jsx(Yt,{label:S.label??S.key,segments:a!=null&&a.includes(S.key)?[{status:"resolved",value:x(S.key)}]:i.resolveParamValue(x(S.key),m)},S.key))})}function Js(e,s,o,n){const a={};for(const c of e)if(n!=null&&n.includes(c.key))a[c.key]=s[c.key]!==void 0?s[c.key]:c.default;else if(c.type==="vars"){const l=s[c.key]??c.default??[],p=i.dataVarRows(l);a[c.key]=p?i.resolveVarsJson(p,o):i.resolveParamJson(l,o)}else a[c.key]=i.resolveParamJson(s[c.key]!==void 0?s[c.key]:c.default,o);return a}function Yt({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(wn,{segments:s})})]})}function go({param:e,value:s,scope:o}){const n=s??e.default??[],a=i.dataVarRows(n);return a===null?t.jsx(Yt,{label:e.label??e.key,segments:i.resolveParamValue(n,o)}):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((c,l)=>t.jsxs("div",{className:"w6w-resolved-value",children:[t.jsx("code",{children:c.key||"(no key)"})," → ",t.jsx(wn,{segments:i.resolveParamValue(c.value,o)})]},l))})]})}function wn({segments:e}){return t.jsx(t.Fragment,{children:e.map((s,o)=>t.jsx(xo,{segment:s},o))})}function xo({segment:e}){switch(e.status){case"resolved":return e.ref?t.jsxs(t.Fragment,{children:[t.jsx(lt,{kind:"var",refName:e.ref}),t.jsx(Us,{value:e.value})]}):t.jsx(Us,{value:e.value});case"unresolved":return t.jsxs(t.Fragment,{children:[t.jsx(lt,{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(lt,{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(lt,{kind:"expr"}),t.jsx("span",{className:"w6w-param-unevaluated",children:"not evaluated"})]});case"masked":return t.jsx(lt,{kind:"secret",refName:e.ref})}}function Us({value:e}){const[s,o]=d.useState(!1),n=jo(e),a=mo(n);return a.clipped?t.jsxs(t.Fragment,{children:[s?t.jsx(ve.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:()=>o(c=>!c),children:s?"Show less":`Show all (${a.length.toLocaleString()} characters)`})]}):t.jsx("span",{children:n})}const bo={var:"◆",secret:"🔒",expr:"ƒ"};function lt({kind:e,refName:s}){const o=e==="expr"?"expr":i.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:o})]})}function jo(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 gn(e){return e.language==="python"||e.language==="typescript"?e.language:"javascript"}function yo({enabled:e,values:s,onChange:o}){const[n,a]=d.useState(null),c=d.useRef(!1),l=typeof s.code=="string"?s.code:"";return d.useEffect(()=>{if(!e||c.current)return;c.current=!0;const p=i.convertCodeBindingsToReads(l,gn(s));p.converted!==0&&(a({original:l,converted:p.converted}),o({...s,code:p.code}))},[e,l,s,o]),n?{converted:n.converted,undo:()=>{o({...s,code:n.original}),a(null)}}:null}function vo({values:e,conversion:s,readOnly:o}){const n=typeof e.code=="string"?e.code:"",a=s,c=i.findCodeBindings(n,gn(e)).length;return!a&&c===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",!o&&t.jsxs(t.Fragment,{children:[" · ",t.jsx("button",{type:"button",className:"w6w-script-converted-undo",onClick:a.undo,children:"Undo"})]}),c>0&&" · "]}),c>0&&t.jsxs(t.Fragment,{children:[c," ",t.jsx("code",{children:"{{ }}"})," left in the code stay",c===1?"s":""," literal text — read ",c===1?"it":"them"," from"," ",t.jsx("code",{children:"state"}),", or bind under Custom input"]})]})}function qs(e,s){return{nodeIds:e.filter(o=>o.selected).map(o=>o.id),edgeIds:s.filter(o=>o.selected).map(o=>o.id)}}function So(e,s,o,n){const a=new Set(e.nodeIds),c=new Set(e.edgeIds),l=s.filter(h=>a.has(h.id)),p=[...l.filter(h=>i.isForeachStep(h.data.step)),...l.filter(h=>!i.isForeachStep(h.data.step))];let m=s,g=o,x=n;for(const h of p)g=i.bridgeDeletedBodyStep(h.id,m,g),m=m.filter(v=>v.id!==h.id),x=ts(x,h.id);return{nodes:m,edges:g.filter(h=>!c.has(h.id)),canvas:x}}function Co(e,s,o){var p;const n=new Set(e.nodeIds),a=new Set(e.edgeIds),c=o.filter(m=>a.has(m.id)&&!n.has(m.source)&&!n.has(m.target)),l=[];if(n.size===1)l.push(i.deleteStepMessage(e.nodeIds[0],s,o));else if(n.size>1){l.push(`Delete nodes ${[...n].map(g=>`"${g}"`).join(", ")}? Their connections are removed too.`);const m=new Set;for(const g of n)if(i.isForeachStep((p=s.find(x=>x.id===g))==null?void 0:p.data.step))for(const x of i.loopBody(g,s,o))n.has(x)||m.add(x);m.size&&l.push(`Loop body steps ${[...m].map(g=>`"${g}"`).join(", ")} stay as standalone steps.`)}return c.length&&l.push(`Delete ${c.length===1?"connection":"connections"} ${c.map(m=>`"${m.source} → ${m.target}"`).join(", ")}?`),l.join(" ")}function No(e,s){const o={success:0,error:0};for(const a of s){if(a.source!==e)continue;const c=i.edgeLane(a);c!=="each"&&o[c]++}const n=Math.max(o.success,o.error);return{enabled:n>=2,count:n}}function ko(e,s){const{fanOut:o,...n}=e;return s==="parallel"?{...n,fanOut:"parallel"}:n}function Eo(e,s){return`Runs these ${e} nodes in ${s==="parallel"?"parallel":"sequence"}`}function Et(e,s,o,n,a){const c=i.flowToWorkflow({...e,connections:n},s,o);return{nodes:c.nodes.map(({with:l,...p})=>l&&Object.keys(l).length?{...p,with:l}:p),edges:c.edges??[],connections:c.connections??{},canvas:a,positions:Object.fromEntries(s.map(l=>[l.id,l.position]))}}function Ao(e,s){const o=i.workflowToFlow({...e,...s});return{...o,nodes:o.nodes.map(n=>({...n,position:s.positions[n.id]??n.position}))}}class To{constructor(s,o=100){it(this,"past",[]);it(this,"future",[]);it(this,"present");it(this,"group");it(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=[])}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 Ht(e){var o;const s=e;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 Po=64,dt=24,Qe=32;function At(e){var s,o;return{width:((s=e.measured)==null?void 0:s.width)??e.width??200,height:((o=e.measured)==null?void 0:o.height)??e.height??64}}function Io(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 Ro(e){const s=(a,c)=>{const l=new Map;for(const g of e){const x=g.position[a];l.set(x,Math.max(l.get(x)??0,At(g)[c]))}const p=new Map;let m=Number.NEGATIVE_INFINITY;for(const[g,x]of[...l].sort(([h],[v])=>h-v)){const h=Math.max(g,m);p.set(g,h),m=h+x+Po}return p},o=s("x","width"),n=s("y","height");return e.map(a=>({...a,position:{x:o.get(a.position.x)??a.position.x,y:n.get(a.position.y)??a.position.y}}))}function Mo(e,s,o){var p;const n=Ro(i.relayoutNodes(e,s));if(!((p=o.sections)!=null&&p.length))return{nodes:n,canvas:o};const a=new Map(n.map(m=>[m.id,m])),c=(o.notes??[]).map(m=>({...m.position,...m.size}));for(const m of o.sections)m.nodes.some(g=>a.has(g))||c.push({...m.position,...m.size,y:m.position.y-Qe,height:m.size.height+Qe});const l=o.sections.map(m=>{const g=new Set(m.nodes),x=n.filter(N=>g.has(N.id));if(!x.length)return m;const h=Math.min(...x.map(N=>N.position.x))-dt,v=Math.min(...x.map(N=>N.position.y))-dt,S=Math.max(...x.map(N=>N.position.x+At(N).width)),P=Math.max(...x.map(N=>N.position.y+At(N).height)),L={x:h,y:v,width:S+dt-h,height:P+dt-v},f=[...c,...[...a.values()].filter(N=>!g.has(N.id)).map(N=>({...N.position,...At(N)}))].sort((N,J)=>N.y-J.y);for(const N of f){const J={...L,y:L.y-Qe,height:L.height+Qe};Io(J,N)&&(L.y=N.y+N.height+dt+Qe)}const V=L.y-v;for(const N of x)a.set(N.id,{...N,position:{x:N.position.x,y:N.position.y+V}});return c.push({...L,y:L.y-Qe,height:L.height+Qe}),{...m,position:{x:L.x,y:L.y},size:{width:L.width,height:L.height}}});return{nodes:n.map(m=>a.get(m.id)??m),canvas:{...o,sections:l}}}const Jt=6;function Lo(e){let s=2166136261;for(let o=0;o<e.length;o++)s^=e.charCodeAt(o),s=Math.imul(s,16777619);return s>>>0}function Fo(e){const s=new Map;let o=new Set;for(const n of[...new Set(e)].sort()){o.size===Jt&&(o=new Set);let a=Lo(n)%Jt;for(;o.has(a);)a=(a+1)%Jt;o.add(a),s.set(n,a+1)}return s}function ss(e){return`var(--w6w-loop-${e})`}function xn(e,s){const o=[],n=new Set([e]);for(let a=s.get(e);a&&!n.has(a);a=s.get(a))n.add(a),o.unshift(a);return o}function Do(e,s,o){return s.size===0?e:e.map(n=>{var l;if(((l=n.data)==null?void 0:l.when)!=="each")return n;const a=n.sourceHandle===i.EACH_SOURCE_HANDLE?n.source:o.get(n.source),c=a?s.get(a):void 0;return c===void 0?n:{...n,style:{...n.style,"--w6w-loop-color":ss(c)}}})}function Oo(e,s){const o=s.get(e);return o===void 0?void 0:{"--w6w-loop-color":ss(o)}}function _o(e){const s=[];for(const o of e){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 Wo(e){const s=JSON.parse(e);return{tones:Fo(s.filter(o=>o[1]===1).map(o=>o[0])),loopOf:new Map(s.map(o=>[o[0],o[2]]))}}const Gs="Paused — test runs stop before this node",Ks="Disabled — skipped in every run";function et(e){var s;return((s=e.ui)==null?void 0:s.paused)===!0}function Fe(e){return e.disabled===!0}function bn(e,s){const{ui:o,...n}=e,{paused:a,...c}=o??{},l=s?{...c,paused:!0}:c;return Object.keys(l).length>0?{...n,ui:l}:n}function jn(e,s){const{disabled:o,...n}=e;return s?{...n,disabled:!0}:n}function Zt(e,s){return e.filter(o=>o.id!==s&&et(o)).map(o=>o.id)}const $o=["nodes","steps"];function Xs(e,s){for(const o of $o){const n=`${o}.${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 Tt(e,s,o){if(typeof e=="string"){if(!e.includes("{{"))return e;const n=i.parseRootAnchoredTemplate(e);let a=!1;const c=n.map(l=>{if(l.kind!=="var"||l.ref===void 0)return l;const p=Xs(l.ref,s);return p===null?l:(a=!0,o.includes(l.ref)||o.push(l.ref),{...l,ref:p})});return a?be.serializeTemplate(c):e}if(i.isDollarPath(e)){const n=e.$;if(typeof n!="string")return e;const a=Xs(n,s);return a===null?e:(o.includes(n)||o.push(n),{$:a})}if(Array.isArray(e)){let n=!1;const a=e.map(c=>{const l=Tt(c,s,o);return l!==c&&(n=!0),l});return n?a:e}if(typeof e=="object"&&e!==null){let n=!1;const a={};for(const[c,l]of Object.entries(e)){const p=Tt(l,s,o);p!==l&&(n=!0),a[c]=p}return n?a:e}return e}function Bo(e){if(typeof e=="string"){if(!e.includes("{{"))return!1;const s=i.parseRootAnchoredTemplate(e);return s.length===1&&s[0].kind==="var"}return i.isDollarPath(e)&&typeof e.$=="string"}function yn(e){return Array.isArray(e)&&e.length===1&&Bo(e[0])}function Vo(e){var s;try{const o=i.normalizeInput(e);if(!Array.isArray(o.nodes))return{};const n={},a=(l,p)=>{const m=Object.hasOwn(n,l)?n[l]:[];m.push(p),n[l]=m},c=new Map(o.nodes.map(l=>[l.id,l]));for(const[l,p]of Object.entries(i.definitionLoops(o))){const m=c.get(l);if(m&&yn((s=m.with)==null?void 0:s.items)&&a(l,{code:"foreach_wrapped_items",fix:{kind:"unwrap_items",label:"Unwrap Items"}}),"invalid"in p){a(l,{code:"loop_body_invalid",reason:{...p.invalid}});continue}for(const g of p.body){const x=c.get(g);if(!(x!=null&&x.with))continue;const h=[];Tt(x.with,l,h),h.length>0&&a(g,{code:"foreach_body_refs_output",foreachId:l,refs:h,fix:{kind:"use_current_item",foreachId:l,label:"Use Current item"}})}}return n}catch{return{}}}function zo(e){const s=new Set,o=n=>{if(typeof n=="string")s.add(n);else if(Array.isArray(n))for(const a of n)o(a)};return o(e),s}function Ho(e){var s,o;try{const n=i.normalizeInput(e);if(!Array.isArray(n.nodes))return[];const a=n.nodes.filter(C=>typeof C=="object"&&C!==null&&typeof C.id=="string"),c=i.effectiveEdges({...n,nodes:a}).filter(C=>typeof(C==null?void 0:C.from)=="string"&&typeof(C==null?void 0:C.to)=="string"),l=[];for(const C of a)try{const T=be.staticWritePaths(be.effectiveStateConfig((s=C.uses)==null?void 0:s.app,(o=C.uses)==null?void 0:o.action,C.state));T.length>0&&l.push({id:C.id,paths:T})}catch{}if(l.length<2)return[];const p=new Map;for(const C of a)for(const T of i.controlOwnedIds(C))p.has(T)||p.set(T,C.id);const m=C=>{const T=[C];let R=C;for(;p.has(R)&&(R=p.get(R),!T.includes(R));)T.push(R);return T},g=C=>{const T=m(C);return T[T.length-1]},x=new Map;for(const C of c){const T=x.get(C.from)??[];T.push(C.to),x.set(C.from,T)}const h=new Map,v=C=>{const T=h.get(C);if(T)return T;const R=new Set,B=[...x.get(C)??[]];for(;B.length>0;){const z=B.pop();if(!R.has(z)){R.add(z);for(const Z of x.get(z)??[])B.push(Z)}}return h.set(C,R),R},S=(C,T)=>C===T||v(C).has(T),P=a.filter(C=>{var T;return((T=C.uses)==null?void 0:T.app)===i.CONTROL_APP&&C.uses.action==="parallel"}).map(C=>{var R;const T=(R=C.with)==null?void 0:R.branches;return Array.isArray(T)?T.map(zo):[]}),L=(C,T)=>{for(const R of m(T)){const B=C.findIndex(z=>z.has(R));if(B>=0)return B}return-1},f=[];for(const C of a){if(C.fanOut!=="parallel")continue;const T=new Map;for(const R of c){if(R.from!==C.id||i.isEachLink(R))continue;const B=R.when??"success",z=T.get(B)??[];z.push(R.to),T.set(B,z)}for(const R of T.values())R.length>=2&&f.push(R)}const V=(C,T)=>{for(const z of P){const Z=L(z,C),b=L(z,T);if(Z>=0&&b>=0&&Z!==b)return!0}const R=g(C),B=g(T);return R===B||v(R).has(B)||v(B).has(R)?!1:f.some(z=>z.some((Z,b)=>z.some((W,le)=>b!==le&&S(Z,R)&&S(W,B))))},N=new Set,J=[];for(let C=0;C<l.length;C++)for(let T=C+1;T<l.length;T++){const R=l[C],B=l[T];if(!(R.id===B.id||!V(R.id,B.id)))for(const z of R.paths)for(const Z of B.paths){if(!be.statePathsOverlap(z,Z))continue;const b={code:"state_parallel_write",nodes:[R.id,B.id].sort(),path:[...z.length<=Z.length?z:Z]},W=JSON.stringify([b.nodes,b.path]);N.has(W)||(N.add(W),J.push(b))}}const U=(C,T)=>C<T?-1:C>T?1:0;return J.sort((C,T)=>U(C.code,T.code)||U(C.nodes.join(","),T.nodes.join(","))||U(C.path.join("."),T.path.join(".")))}catch{return[]}}function Jo(e){try{const s={};for(const o of Ho(e))for(const n of o.nodes){const a=Object.hasOwn(s,n)?s[n]:[];a.push({code:o.code,path:[...o.path],with:o.nodes.filter(c=>c!==n)}),s[n]=a}return s}catch{return{}}}function vn(e,s){var o;if(s.code==="foreach_wrapped_items"){const n=(o=e.with)==null?void 0:o.items;return!e.with||!yn(n)?e:{...e,with:{...e.with,items:n[0]}}}if(s.code==="foreach_body_refs_output"){if(!e.with)return e;const n=Tt(e.with,s.foreachId,[]);return n===e.with?e:{...e,with:n}}return e}function Ys(e,s,o){return e&&e.nodeId===s&&e.handleType===((o==null?void 0:o.type)??"source")?i.laneForSourceHandle(e.handleId):i.laneForSourceHandle(o==null?void 0:o.id)}function Uo(e,s,o,n,a){var m;const c=(m=n.find(g=>g.id===e))==null?void 0:m.data.step,l=i.loopMembership(n,a)[e]!==void 0,p=o==="success"&&l?"each":o;return p==="each"&&!l&&!i.isForeachStep(c)?null:i.loopRefusal(e,s,p,n,a)}const qo=["off","root","key","pick","append"],Go={off:"Off",root:"Merge at root",key:"Under a key",pick:"Pick fields",append:"Append"};function Ko(e){return be.effectiveStateConfig(e.uses.app,e.uses.action,e.state)}function Xo(e,s){return JSON.stringify(e)===JSON.stringify(s)}function Yo(e,s){const{state:o,...n}=e,a=be.effectiveStateConfig(e.uses.app,e.uses.action,void 0);return Xo(s,a)?n:{...n,state:s}}function Zo(e,s){switch(s){case"key":return{mode:"key",key:e.id};case"pick":return{mode:"pick",map:[{from:"",to:e.id}]};case"append":return{mode:"append",path:e.id};case"root":return{mode:"root"};default:return{mode:"off"}}}function Qo(e){return!i.isControlApp(e.uses.app)}function Pt(e,s){var o;return(o=e.nodes??e.steps)==null?void 0:o[s]}function Qt(e,s){const o=Pt(e,s);return(o==null?void 0:o.status)==="skipped"&&o.skipReason==="not_on_path"}const ei=new Set(["succeeded","failed","canceled"]);function ti(e,s,o=[]){var c,l;if(!e||[...o,s].some(p=>Qt(e,p)))return"no-run";const n=Pt(e,s);if(n)return n.status;const a=new Set;for(const p of Object.values(e.nodes??e.steps??{}))if(Array.isArray(p==null?void 0:p.iterations))for(const m of p.iterations){const g=(l=(c=m==null?void 0:m.nodes)==null?void 0:c[s])==null?void 0:l.status;g&&a.add(g)}for(const p of["failed","running","succeeded","skipped"])if(a.has(p))return p;return"pending"}const Zs={borderColor:"var(--w6w-border)",borderStyle:"solid",borderWidth:1,opacity:1};function Sn(e,s){const o=s!==void 0&&ei.has(s);switch(e){case"no-run":return Zs;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 Zs}}function si(e,s,o,n,a){var l;if(!e||Qt(e,s)||a!==void 0&&Qt(e,a))return;const c=ni(e,s,o,n);return c==="taken"&&a!==void 0&&((l=Pt(e,a))==null?void 0:l.status)==="skipped"?"skipped":c}function ni(e,s,o,n){const a=Pt(e,s);if(!a)return;if(o==="each")return a.status==="skipped"?"skipped":void 0;const c=o??"success",l=a.output,p=n===i.FOREACH_DONE_ROUTE&&!(l&&typeof l=="object"&&"route"in l);if(n!==void 0&&!p&&a.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(a.status==="succeeded")return c==="success"?"taken":"skipped";if(a.status==="failed")return c==="error"?"taken":"skipped";if(a.status==="skipped")return"skipped"}const Qs={fields:[],sampleValues:{}};function Cn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function oi(e,s){var g;const o=e.map(x=>x.id),n=new Set(o),a=new Map(o.map(x=>[x,0])),c=new Map(o.map(x=>[x,[]]));for(const x of s)!n.has(x.source)||!n.has(x.target)||((g=c.get(x.source))==null||g.push(x.target),a.set(x.target,(a.get(x.target)??0)+1));const l=[],p=o.filter(x=>a.get(x)===0);for(;p.length>0;){const x=p.shift();l.push(x);for(const h of c.get(x)??[]){const v=(a.get(h)??0)-1;a.set(h,v),v===0&&p.push(h)}}const m=new Set(l);for(const x of o)m.has(x)||l.push(x);return l}const ii=new Set(["string","number","boolean","object","array"]);function ut(e){if(!Array.isArray(e))return;const s={type:"object",fields:{}};let o=!1;for(const n of e){if(!Cn(n)||typeof n.key!="string"||n.key==="")continue;const a=n.key.split(".");let c=s;for(const m of a.slice(0,-1)){const g=c.fields[m];(g==null?void 0:g.type)!=="object"&&(c.fields[m]={type:"object",fields:{}}),c=c.fields[m]}const l=typeof n.type=="string"&&ii.has(n.type)?n.type:"string";let p;if(l==="array"){const m=ut(n.items);p=m?{type:"array",items:m}:{type:"array"}}else l==="object"?p=ut(n.fields??n.properties)??{type:"object",fields:{}}:p={type:l};c.fields[a[a.length-1]]=p,o=!0}return o?s:void 0}function ri(e,s){var g,x,h,v,S,P,L;const o=e.data.step,n=((g=s.testOutputs)==null?void 0:g[o.id])??((x=s.persistedOutputs)==null?void 0:x[o.id]);if(n!=null)return n;const{app:a,action:c}=o.uses;if(a===i.TRIGGER_APP&&((h=i.internalNodeDef(a,c))==null?void 0:h.group)==="trigger"){const f=i.fieldsToParams(i.asFieldDefs((v=o.with)==null?void 0:v.fields)).map(V=>({key:V.key}));return i.shapeToSkeleton(ut(f))}const l=(S=i.internalNodeDef(a,c))==null?void 0:S.output;if(l&&l.length>0)return i.shapeToSkeleton(ut(l));const p=o.uses.trigger===!0?(P=s.triggerDef)==null?void 0:P.call(s,a,c):(L=s.actionDef)==null?void 0:L.call(s,a,c),m=ut(p==null?void 0:p.output);return m?i.shapeToSkeleton(m):p==null?void 0:p.sample}function ai(e,s){var p,m,g,x,h;const o=e.data.step,n=(p=s.previewOutputs)==null?void 0:p[o.id];if(n!=null)return n;const{app:a,action:c}=o.uses,l=o.uses.trigger===!0?(g=(m=s.shapes)==null?void 0:m.triggerDef)==null?void 0:g.call(m,a,c):(h=(x=s.shapes)==null?void 0:x.actionDef)==null?void 0:h.call(x,a,c);return l==null?void 0:l.sample}function ci(e){switch(e){case"number":case"integer":return 0;case"boolean":return!1;case"object":return{};case"array":return[];default:return""}}function en(e,s){const o=Cn(e.initialState)?{...e.initialState}:{};for(const n of e.variables??[])!n||typeof n.key!="string"||n.key===""||(n.default!==void 0?o[n.key]=n.default:s||(o[n.key]=ci(n.type)));return o}function Ut(e){return(i.inferOutputFields(e)??[]).map(s=>s.key)}function li(e){const{anchorId:s,nodes:o,edges:n}=e;if(!s)return Qs;const a=e.shapes??{},c=i.ancestorIds(s,n);c.delete(s);const l=new Map(o.map(C=>[C.id,C])),p=[],m=[],g=new Map;for(const C of oi(o,n)){if(!c.has(C))continue;const T=l.get(C);if(!T)continue;const{app:R,action:B}=T.data.step.uses,z=be.effectiveStateConfig(R,B,T.data.step.state);if(z.mode==="off")continue;const Z=ri(T,a);if(Z!==void 0){const{ops:W}=be.computeStateWrites(z,Z);p.push(...W);for(const le of Ut(be.foldState({},W))){const ue=g.get(le)??new Set;ue.add(C),g.set(le,ue)}}const b=ai(T,e);b!==void 0&&m.push(...be.computeStateWrites(z,b).ops)}const x=en(e,!1),h=be.foldState(x,p),v=Ut(h);if(v.length===0)return Qs;const S=new Set(Ut(x)),P=new Map,L=new Map;for(const C of n)c.has(C.source)&&(!c.has(C.target)&&C.target!==s||(P.set(C.target,[...P.get(C.target)??[],C.source]),L.set(C.source,[...L.get(C.source)??[],C.target])));const f=[...c].filter(C=>!(P.get(C)??[]).length),V=C=>{const T=new Set,R=f.filter(B=>!C.has(B));for(;R.length>0;){const B=R.pop();if(B===s)return!1;if(!T.has(B)){T.add(B);for(const z of L.get(B)??[])C.has(z)||R.push(z)}}return!0},N=be.foldState(en(e,!0),m),J=[],U={};for(const C of v){const T=g.get(C)??new Set,R=S.has(C)||T.size>0&&V(T);J.push({key:C,path:!0,paths:R?"all":"some"});const B=i.valueAtPath(N,C);B!==void 0&&(U[`state.${C}`]=B)}return{fields:J,sampleValues:U}}const di={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"}},tn="Never fired";function ui(e){if(!e)return tn;const s=new Date(e);return Number.isNaN(s.getTime())?tn:`Last fired ${s.toISOString().slice(0,16).replace("T"," ")} UTC`}function pi(e,s){var a;if(!(e!=null&&e.status))return null;const o=di[e.status];if(!o)return null;const n=e.status==="failed";return{label:o.label,tone:o.tone,error:n?((a=e.lastError)==null?void 0:a.message)??null:null,lastFire:ui(e.lastFireAt),retryVisible:n&&s}}function fi(e){const s=new Map;for(const o of e)o.nodeId&&s.set(o.nodeId,o);return s}function hi(e){return(e??[]).filter(s=>{var o;return((o=s.uses)==null?void 0:o.trigger)===!0})}function mi(e,s){const[o,n]=d.useState({}),a=d.useRef(new Set),c=JSON.stringify([...new Set(s.map(l=>l.data.step.uses.app))].filter(l=>l&&!i.isInternalApp(l)).sort());return d.useEffect(()=>{const l=JSON.parse(c).filter(p=>!a.current.has(p));if(l.length!==0){for(const p of l)a.current.add(p);Promise.all(l.map(async p=>{try{return[p,await e.getAppActions(p)]}catch{return a.current.delete(p),null}})).then(p=>{const m=p.filter(g=>g!==null);m.length!==0&&n(g=>({...g,...Object.fromEntries(m)}))})}},[e,c]),o}function wi(e,s){const[o,n]=d.useState({}),a=d.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 d.useEffect(()=>{const l=e.getAppTriggers;if(typeof l!="function")return;const p=JSON.parse(c).filter(m=>!a.current.has(m));if(p.length!==0){for(const m of p)a.current.add(m);Promise.all(p.map(async m=>{try{return[m,await l.call(e,m)]}catch{return a.current.delete(m),null}})).then(m=>{const g=m.filter(x=>x!==null);g.length!==0&&n(x=>({...x,...Object.fromEntries(g)}))})}},[e,c]),o}function gi(e){return(s,o)=>{var n,a;return(a=(n=e[s])==null?void 0:n.find(c=>c.key===o))==null?void 0:a.ports}}const xi="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 sn(e,s,o,n){const a=e.find(c=>c.id===s);return[o,n,a==null?void 0:a.source,a==null?void 0:a.target]}const ns=d.createContext(void 0),os=d.createContext(new Map),is=d.createContext({tones:new Map,loopOf:new Map});function nn(e){return`Can’t draw that edge: this node allows at most ${e} outgoing edge${e===1?"":"s"} per lane.`}const rs=d.createContext(new Map),Nn=d.createContext({byNode:new Map,subs:[]});function bi({apps:e,registration:s,children:o}){return t.jsx(rs.Provider,{value:e,children:t.jsx(Nn.Provider,{value:s,children:o})})}const as=d.createContext(null);function ji(e){return t.jsx(ne.ReactFlowProvider,{children:t.jsx(yi,{...e})})}function on(e,s){let o=s.length+1;for(;s.includes(`${e}-${o}`);)o++;return`${e}-${o}`}function qt(e){var s,o;return{x:e.position.x,y:e.position.y,w:((s=e.measured)==null?void 0:s.width)??e.width??200,h:((o=e.measured)==null?void 0:o.height)??e.height??64}}function yi({onConnectionResourcesChange:e,value:s,onChange:o,readOnly:n,height:a=480,apps:c,exprOptions:l,project:p,runState:m,stepProblems:g,onTestRun:x,fitViewKey:h,onRunFromNode:v}){var Ds,Os,_s,Ws,$s,Bs,Vs;const S=i.useW6WApi(),P=d.useMemo(()=>new Map((c??[]).map(r=>[r.id,r])),[c]),L=Ai(s),[f,V]=d.useState(null),N=d.useMemo(()=>i.centralizeConnections(s),[s.id]),J=d.useMemo(()=>i.workflowToFlow(N),[N]),[U,C]=d.useState(N.connections??{}),T=d.useRef(U),R=d.useCallback(r=>{T.current=r,C(r)},[]),B=d.useCallback(r=>{const u=i.centralizeConnections({nodes:[r],connections:T.current});return u.connections!==T.current&&R(u.connections),u.nodes[0]},[R]),z=d.useMemo(()=>i.storedViewport(s),[s.id]),Z=((Ds=s.settings)==null?void 0:Ds.savePosition)!==!1,[b,W,le]=ne.useNodesState(J.nodes),ue=mi(S,b),ke=wi(S,b),oe=d.useMemo(()=>gi(ue),[ue]),[E,X,I]=ne.useEdgesState(J.edges),[D,H]=d.useState(null),O=d.useMemo(()=>s.canvas??{},[s.id]),[$,G]=d.useState(O),[_]=d.useState(()=>new To(Et(N,J.nodes,J.edges,U,O))),ae=d.useRef(),[ze,rt]=d.useState(0),[He,qe]=d.useState(!1),[Se,Ee]=d.useState(null),[pe,Me]=d.useState(null),[de,Ae]=d.useState(null),[te,De]=d.useState(!1),pt=d.useRef({});d.useEffect(()=>{te||(pt.current={})},[te]);const[re,he]=d.useState(null),[Te,je]=d.useState("props"),[Ge,Oe]=d.useState(null),[Pe,Je]=d.useState(null),[Le,ye]=d.useState(null),at=d.useRef(!1),Ie=d.useRef(null),[me,Re]=d.useState(null),{screenToFlowPosition:Ce,fitView:_e}=ne.useReactFlow(),We=i.useEffectiveTheme();d.useEffect(()=>{W(J.nodes),X(J.edges),H(null),Ae(null),ye(null),he(null),Oe(null),G(O),R(N.connections??{}),_.reset(Et(N,J.nodes,J.edges,N.connections??{},O)),ae.current=void 0},[J,O,N,W,X,R,_]),d.useEffect(()=>{W(r=>{const u=new Map(i.stampLoopOf(r,E).map(w=>[w.id,w.data.loopOf]));return r.map(w=>{const j=ti(m,w.id,xn(w.id,u));return w.data.stepStatus===j&&w.data.runStatus===(m==null?void 0:m.status)?w:{...w,data:{...w.data,stepStatus:j,runStatus:m==null?void 0:m.status}}})}),X(r=>r.map(u=>{var k;const w=i.edgeLane(u),j=si(m,u.source,w,typeof((k=u.data)==null?void 0:k.route)=="string"?u.data.route:void 0,u.target),y=i.edgeVisuals(w,j);return u.className===y.className&&u.label===y.label?u:{...u,className:y.className,label:y.label}}))},[m,J,ze,W,X]),d.useEffect(()=>{W(r=>i.applyStepProblems(r,g))},[g,J,ze,W]);const Ke=d.useCallback((r,u)=>{var y,k;const{canvas:w,...j}=r;return!((y=u.notes)!=null&&y.length)&&!((k=u.sections)!=null&&k.length)?j:{...j,canvas:ho(u,s.canvas,Z)}},[s.canvas,Z]),Q=d.useCallback((r,u,w)=>{_.record(Et(s,r,u,T.current,w??$),te?pt.current:ae.current),o(Ke(i.flowToWorkflow({...s,connections:T.current},r,u),w??$))},[s,o,$,Ke,_,te]),ft=d.useRef(()=>{});ft.current=r=>{if(n)return;const u=i.editConnectionResources(b.map(j=>j.data.step),T.current,r),w=b.map((j,y)=>({...j,data:{...j.data,step:u.nodes[y]}}));R(u.connections),W(w),Q(w,E)};const ht=d.useCallback(r=>ft.current(r),[]),ce=d.useCallback(r=>{H(r),Ae(null),W(u=>u.map(w=>({...w,selected:w.id===r}))),X(u=>u.map(w=>({...w,selected:!1}))),_e({nodes:[{id:r}],duration:300,maxZoom:1})},[W,X,_e]),[tt,Rt]=d.useState(null),mt=d.useMemo(()=>tt?b.map(r=>r.id===tt?{...r,className:`${r.className??""} w6w-connection-highlight`.trim()}:r):b,[b,tt]),ct=b.map(r=>({id:r.data.step.id,uses:r.data.step.uses})),A=JSON.stringify(ct),Y=JSON.stringify([...P]);d.useEffect(()=>{e==null||e({workflowId:s.id,nodes:ct,apps:P,connections:U,readOnly:n,edit:ht,focusNode:ce,highlightNode:Rt})},[e,s.id,A,Y,U,n,ht,ce]),d.useEffect(()=>()=>e==null?void 0:e(null),[e]);const se=d.useCallback(r=>i.canConnect(r.source,r.target,b,E,oe,i.routeFromHandle(r.sourceHandle)),[b,E,oe]),[fe,Ne]=d.useState(null),ls=d.useRef(null),Mt=d.useRef(null);d.useEffect(()=>{W(r=>i.stampLoopOf(r,E))},[E,W]);const Dn=d.useCallback(r=>{if(n)return;const u=i.applyConnect(r.source,r.target,b,E,i.laneForSourceHandle(r.sourceHandle),oe,i.routeFromHandle(r.sourceHandle));if(!u){const w=i.laneForSourceHandle(r.sourceHandle),j=i.connectRefusal(r.source,r.target,b,E,w,oe,i.routeFromHandle(r.sourceHandle));if(j&&j.refused==="loop"){Ne({nodeId:r.source,reason:j.reason});return}if(j){const k=E.find(F=>F.source===r.source&&i.edgeLane(F)===w);k&&(X(E.map(F=>({...F,selected:F.id===k.id}))),Ae(k.id),Xe({edgeId:k.id,message:nn(j.cap)}));return}const y=i.connectConflict(r.source,r.target,b,E,i.laneForSourceHandle(r.sourceHandle));if(!y)return;X(E.map(k=>({...k,selected:k.id===y}))),Ae(y),Xe({edgeId:y,message:i.idClashMessage("Can’t draw that edge",y,sn(E,y,r.source,r.target))});return}Xe(null),Ne(null),X(u),Q(b,u)},[E,b,X,Q,n,oe]),On=d.useCallback((r,u)=>{var q,K,ee;if(n||u.isValid)return;const w=u.fromNode;if(!w)return;const j=((q=u.fromHandle)==null?void 0:q.type)==="target"?"target":"source",y=u.toNode;if(y&&j==="source"){const ie=Uo(w.id,y.id,Ys(Mt.current,w.id,u.fromHandle),b,E);if(ie){Ne({nodeId:w.id,reason:ie});return}}const k=(K=b.find(ie=>ie.id===w.id))==null?void 0:K.data.step;if(k){const ie=i.nodePortsForStep(k,oe);if((j==="source"?ie.out:ie.in)<1)return}const F="changedTouches"in r?r.changedTouches[0]:r,M=Ce({x:F.clientX,y:F.clientY});Re({nodeId:w.id,handleType:j,position:M,lane:Ys(Mt.current,w.id,u.fromHandle),route:i.routeFromHandle((ee=u.fromHandle)==null?void 0:ee.id)}),De(!0)},[n,Ce,b,E,oe]),ds=d.useCallback((r,u,w)=>{if(n)return;const j=b.find(q=>q.id===r);if(!j)return;const y=qt(j),k=i.laneForSourceHandle(w),F=120,M=u==="target"?{x:y.x-y.w-F,y:y.y}:k==="error"?{x:y.x,y:y.y+y.h+F}:k==="each"?{x:y.x+y.w+F,y:y.y-y.h-F/2}:{x:y.x+y.w+F,y:y.y};Re({nodeId:r,handleType:u,position:M,lane:k,route:i.routeFromHandle(w)}),De(!0)},[n,b]),us=d.useCallback(r=>{n||ye({nodeIds:[r],edgeIds:[]})},[n]),_n=d.useCallback(r=>{if(n)return;const u=So(r,b,E,$);W(u.nodes),X(u.edges),G(u.canvas),u.nodes.some(w=>w.id===D)||H(null),u.nodes.some(w=>w.id===re)||he(null),u.edges.some(w=>w.id===de)||Ae(null),Q(u.nodes,u.edges,u.canvas)},[b,E,$,W,X,Q,n,D,re,de]),ps=d.useCallback(()=>{if(n)return;const r=Mo(b,E,$);W(r.nodes),G(r.canvas),at.current=!0,Q(r.nodes,E,r.canvas)},[b,E,$,W,Q,n]),Wn=d.useCallback(()=>{n||ps()},[n,ps]);d.useEffect(()=>{at.current&&(at.current=!1,_e({duration:300}))},[b,_e]);const fs=d.useRef(h);d.useEffect(()=>{Object.is(fs.current,h)||(fs.current=h,_e({duration:300}))},[h,_e]);const[wt,Xe]=d.useState(null),st=d.useMemo(()=>E.find(r=>r.id===de)??null,[E,de]),$n=d.useCallback(r=>{if(n||!de)return;const u=E.find(F=>F.id===de);if(!u||i.edgeLane(u)===r)return;const w=i.edgeWhenConflict(E,de,r,b),j=i.relaneRefusal(E,de,r,b,oe),y=w||j?null:i.setEdgeWhen(E,de,r,b,oe);if(!y){if(j){Xe({edgeId:de,message:nn(j.cap)});return}Xe({edgeId:de,message:w?i.idClashMessage("Can’t switch this edge",w,sn(E,w,u.source,u.target)):"This edge can’t be switched right now."});return}Xe(null),X(y);const k=y.find(F=>F.source===u.source&&F.target===u.target&&i.edgeLane(F)===r);Ae((k==null?void 0:k.id)??null),Q(b,y)},[E,b,X,Q,n,de,oe]),Bn=d.useCallback(r=>{if(n)return;const u=E.filter(w=>w.id!==r);u.length!==E.length&&(X(u),de===r&&Ae(null),Q(b,u))},[b,E,X,Q,n,de]),Lt=d.useCallback(r=>{if(n)return;const u=r.map(k=>b.find(F=>F.id===k)).filter(k=>k!==void 0);if(u.length===0)return;const w=b.map(k=>k.id),j=u.map(k=>{const F=i.suggestStepId(w,`${k.data.step.id}_copy`);w.push(F);const M={...i.stripBody(structuredClone(k.data.step)),id:F};return{id:F,type:k.type,position:{x:k.position.x+40,y:k.position.y+60},data:{step:M,isInternal:k.data.isInternal},...u.length>1?{selected:!0}:{}}}),y=[...u.length>1?b.map(k=>k.selected?{...k,selected:!1}:k):b,...j];W(y),H(j[0].id),Q(y,E)},[b,E,W,Q,n]),hs=d.useCallback(r=>Lt([r]),[Lt]),Vn=d.useCallback(r=>{if(n)return;const u=i.isInternalApp(r.uses.app),w=b.map(ee=>ee.id),j=r.id&&!i.stepNameError(r.id,w)?r.id:i.suggestStepId(w,i.slugifyLabel(i.internalNodeLabel(r.uses.app,r.uses.action))),y=B({id:j,uses:r.uses,...r.with&&Object.keys(r.with).length>0?{with:r.with}:{}}),k={id:j,type:u?"control":"step",position:(me==null?void 0:me.position)??(Pe==null?void 0:Pe.position)??{x:80,y:80+b.length*24},data:{step:y,isInternal:u}},F=[...b,k];let M=E,q=null;const K=(ee,ie,we,Be)=>{const ot=i.connectRefusal(ee,ie,F,E,we,oe);ot&&ot.refused==="loop"&&(q={nodeId:Be,reason:ot.reason})};if(me){const[ee,ie]=me.handleType==="target"?[j,me.nodeId]:[me.nodeId,j],we=i.applyConnect(ee,ie,F,E,me.lane,oe,me.route);we||K(ee,ie,me.lane,me.nodeId),M=we??E}else{const ee=b.find(ie=>i.isTriggerStep(ie.data.step.uses));if(i.isTriggerStep(r.uses)){if(!ee){const ie=i.findChainRoot(b,E);if(ie){const we=i.applyConnect(j,ie.id,F,E,"success",oe);we||K(j,ie.id,"success",ie.id),M=we??E}}}else{const we=(ee&&!E.some(Be=>Be.source===ee.id)?ee:void 0)??i.findChainTail(b,E);if(we){const Be=i.applyConnect(we.id,j,F,E,"success",oe);Be||K(we.id,j,"success",we.id),M=Be??E}}}return W(F),M!==E&&X(M),Ne(q),H(j),Q(F,M),j},[b,E,W,X,Q,n,me,Pe,oe,B]),ms=d.useCallback((r,u)=>{var q;let w=u;const j=(q=b.find(K=>K.id===r))==null?void 0:q.data.step;if(u.uses.connection&&!u.uses.connectionRef&&(j!=null&&j.uses.connectionRef)&&j.uses.app===u.uses.app){const K=i.selectNodeConnection(i.withConnectionRef(u,j.uses.connectionRef),u.uses.connection,b.map(ee=>ee.data.step),T.current);R(K.connections),w=K.step}else w=B(u);const y=w.id!==r;if(y&&b.some(K=>K.id===w.id))return;const k=b.map(K=>K.id===r?{...K,id:w.id,data:{step:w,isInternal:i.isInternalApp(w.uses.app)}}:K);if(y){const K=i.renameStepInEdges(E,r,w.id),ee=hn($,r,w.id);W(k),X(K),G(ee),D===r&&H(w.id),re===r&&he(w.id),Q(k,K,ee);return}W(k);const F=new Set(i.routesForStep(w).map(K=>K.id)),M=E.filter(K=>{var ee;return K.source!==w.id||((ee=K.data)==null?void 0:ee.route)===void 0||F.has(String(K.data.route))});M.length!==E.length&&X(M),Q(k,M)},[b,E,$,W,X,D,re,Q,B,R]),Ye=d.useCallback(r=>{n||(G(r),Q(b,E,r))},[n,b,E,Q]),zn=d.useCallback(()=>{var y;if(n)return;const r=(y=Ie.current)==null?void 0:y.getBoundingClientRect(),u=r?Ce({x:r.left+r.width/2,y:r.top+r.height/2}):{x:0,y:0},w=$.notes??[],j={id:on("note",w.map(k=>k.id)),color:"#facc15",position:{x:Math.round(u.x-100),y:Math.round(u.y-60)},size:{width:200,height:120},content:""};Ye(Xt({...$,notes:[...w,j]}))},[n,$,Ce,Ye]),Hn=d.useCallback((r,u)=>{if(n)return;const w=u?Math.min(r.x,u.x):r.x,j=u?Math.min(r.y,u.y):r.y,y=u?Math.abs(u.x-r.x):360,k=u?Math.abs(u.y-r.y):240,F=b.filter(ie=>{const we=qt(ie),Be=we.x+we.w/2,ot=we.y+we.h/2;return Be>=w&&Be<=w+y&&ot>=j&&ot<=j+k}).map(ie=>ie.id),M=$.sections??[],q=on("section",M.map(ie=>ie.id)),K={id:q,title:"Section",color:"#6366f1",position:{x:Math.round(w),y:Math.round(j)},size:{width:Math.round(y),height:Math.round(k)},nodes:[]},ee={...$,sections:[...M,K]};Ye(Xt(Kt(ee,q,F)))},[n,b,$,Ye]);d.useEffect(()=>{if(!He)return;const r=u=>{u.key==="Escape"&&(qe(!1),Ee(null))};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[He]);const Jn=d.useCallback((r,u)=>{var F;if(n)return;const w=(F=$.sections)==null?void 0:F.find(M=>M.id===r);if(!w)return;const j=new Set(w.nodes),y=b.map(M=>j.has(M.id)?{...M,position:{x:M.position.x+u.dx,y:M.position.y+u.dy}}:M),k={...$,sections:($.sections??[]).map(M=>M.id===r?{...M,position:{x:M.position.x+u.dx,y:M.position.y+u.dy}}:M)};W(y),G(k),Q(y,E,k)},[n,$,b,E,W,Q]),Un=d.useCallback((r,u)=>{if(n)return;const w=r==="note"?{...$,notes:($.notes??[]).filter(j=>j.id!==u)}:{...$,sections:($.sections??[]).filter(j=>j.id!==u)};Ye(w)},[n,$,Ye]),qn=r=>{let u=$;for(const w of r){const j=qt(w),y=j.x+j.w/2,k=j.y+j.h/2,F=(u.sections??[]).find(q=>y>=q.position.x&&y<=q.position.x+q.size.width&&k>=q.position.y&&k<=q.position.y+q.size.height),M=mn(u,w.id);F?(M.length!==1||M[0]!==F.id)&&(u=Kt(u,F.id,[w.id])):M.length>0&&(u=ts(u,w.id))}return u},Ft=d.useCallback((r,u,w)=>{(async()=>{const j=await S.saveStepTest(s.id,r,u).catch(y=>(console.error("step run fixture save failed",y),null));await S.recordStepTestRun(s.id,r,{stepTestId:(j==null?void 0:j.id)??null,status:w.status,input:u.input,output:w.output,error:w.error,...w.meta?{meta:w.meta}:{}})})().catch(j=>{console.error("step run persist failed",j)})},[S,s.id]),ws=d.useCallback(r=>{const u=b.find(w=>w.id===r);!u||!v&&i.isControlApp(u.data.step.uses.app)||V({stepId:r,status:"collect"})},[b,v]),Gn=d.useCallback(async(r,u,w)=>{if(!v)return;const j=b.find(F=>F.id===r);if(!j)return;const y=i.isTriggerStep(j.data.step.uses),k={stopAt:Zt(b.map(F=>F.data.step),r),...w?{state:w}:{},...y?{input:u}:{}};V({stepId:r,status:"running"});try{await v(r,k),V(null)}catch(F){const M=F;V({stepId:r,status:"error",error:M.message??String(F),errorCode:M.code})}},[b,v]),gt=d.useCallback((r,u)=>{if(n)return;const w=b.map(j=>j.id===r?{...j,data:{...j.data,step:u(j.data.step)}}:j);W(w),Q(w,E)},[b,E,W,Q,n]),gs=d.useCallback(r=>gt(r,u=>bn(u,!et(u))),[gt]),xs=d.useCallback(r=>gt(r,u=>jn(u,!Fe(u))),[gt]),Kn=d.useCallback(async(r,u,w)=>{x==null||x();const j=b.find(q=>q.id===r);if(!j)return;const y=j.data.step,k=i.isTriggerStep(y.uses),F=k?{input:u}:{...y.with??{},...u},M=k?{input:u,with:u}:{input:u,with:F};V({stepId:r,status:"running"});try{const q=await S.invokeAction(y.uses.app,y.uses.action,F,{connectionId:i.connectionIdFor(y,T.current),project:p,...w?{state:w}:{},workflowId:s.id}),K=q.logs,ee=q.meta;V({stepId:r,status:"done",value:q.value,logs:K,...ee?{meta:ee}:{}}),Ft(r,M,{status:"succeeded",output:q.value,...ee?{meta:ee}:{}})}catch(q){const K=q;V({stepId:r,status:"error",error:K.message??String(q),errorCode:K.code}),Ft(r,M,{status:"failed",error:K.message??String(q)})}},[b,S,Ft,p,x,s.id]),Dt=d.useMemo(()=>({onEdit:r=>{je("props"),he(r)},onEditJson:r=>{je("json"),he(r)},onRun:ws,onDuplicate:hs,onDelete:us,onTogglePause:gs,onToggleDisable:xs,runsFromNode:!!v,onAddFromPort:ds,readOnly:n}),[ws,hs,us,gs,xs,v,ds,n]);d.useEffect(()=>{const r=Ie.current;if(!r)return;const u=w=>{const j=w.target.closest(".react-flow__node");if(!j)return;const y=j.getAttribute("data-id");y&&(w.stopPropagation(),Dt.onEdit(y))};return r.addEventListener("dblclick",u,!0),()=>r.removeEventListener("dblclick",u,!0)},[Dt]);const nt=b.find(r=>r.id===re),xt=(nt==null?void 0:nt.data.step)??null,Ot=f?((Os=b.find(r=>r.id===f.stepId))==null?void 0:Os.data.step)??null:null,_t=(f==null?void 0:f.status)==="collect"&&!!Ot,bs=d.useMemo(()=>{const r=new Map;for(const u of b)r.set(u.id,No(u.id,E).count);return r},[b,E]),js=_o(b),bt=d.useMemo(()=>Wo(js),[js]),Xn=d.useMemo(()=>Do(E,bt.tones,bt.loopOf),[E,bt]),Yn=d.useMemo(()=>({step:Pi,control:Ii}),[]),[jt,ys]=d.useState({}),[yt,vs]=d.useState({}),[Ss,Cs]=d.useState({}),[vt,Ns]=d.useState({}),[Ue,St]=d.useState(null),[ks,Es]=d.useState([]),Zn=re??Ue??"";d.useEffect(()=>{const r=S.loadNodeSamples;if(typeof r!="function"||!s.id){Es([]);return}let u=!1;return r(s.id).then(w=>{u||Es(Array.isArray(w)?w:[])},()=>{}),()=>{u=!0}},[S,s.id,Zn]);const Ct=d.useMemo(()=>i.indexNodeSamples(ks),[ks]),Wt=d.useMemo(()=>i.splitNodeOutputs(jt,Ct,vt),[jt,Ct,vt]),$e=d.useMemo(()=>i.splitPreviewOutputs(jt,Ct,vt),[jt,Ct,vt]),xe=d.useMemo(()=>({actionDef:(r,u)=>{var w;return(w=ue[r])==null?void 0:w.find(j=>j.key===u)},triggerDef:(r,u)=>{var w;return(w=ke[r])==null?void 0:w.find(j=>j.key===u)},testOutputs:Wt.fresh,persistedOutputs:Wt.persisted,loopSamples:Ss}),[ue,ke,Wt,Ss]),Ze=d.useMemo(()=>f?i.upstreamStateSources(f.stepId,b,E,xe):void 0,[f,b,E,xe]),Qn=d.useMemo(()=>(Ze==null?void 0:Ze.steps)??[],[Ze]),ge=d.useMemo(()=>{const r=i.upstreamStateSources(re,b,E,xe,Ue);return{...r,steps:i.excludeSelfStep(r.steps,re??Ue)}},[re,Ue,b,E,xe]),$t=d.useMemo(()=>li({anchorId:re??Ue,nodes:b,edges:E,initialState:s.initialState,variables:s.variables,shapes:xe,previewOutputs:{...$e.persisted,...$e.fresh}}),[re,Ue,b,E,s.initialState,s.variables,xe,$e]),As=JSON.stringify([...ge.steps.map(r=>r.id),...ge.extraSampleIds??[]]);d.useEffect(()=>{const r=JSON.parse(As);if(!re&&!Ue||r.length===0){ys({}),vs({}),Cs({}),Ns({});return}let u=!1;return Promise.all(r.map(async w=>{try{const j=await S.listStepTests(s.id,w),y=j.length?j[j.length-1]:null;return y?{id:w,output:y.lastRunOutput,runAt:y.lastRunAt,meta:y.lastRunMeta,loopSample:i.foreachTestSample(y)}:null}catch{return null}})).then(w=>{if(u)return;const j={},y={},k={},F={};for(const M of w)M!=null&&M.meta&&(y[M.id]=M.meta),M!=null&&M.loopSample&&(k[M.id]=M.loopSample),!(!M||M.output===void 0||M.output===null)&&(j[M.id]=M.output,F[M.id]=M.runAt);ys(j),Ns(F),vs(y),Cs(k)}),()=>{u=!0}},[S,s.id,re,Ue,As]);const Bt=d.useMemo(()=>i.declaredSamples(b,xe),[b,xe]),Nt=d.useMemo(()=>({persisted:$e.persisted,samples:Bt.samples,event:Bt.event}),[$e.persisted,Bt]),Ts=d.useMemo(()=>i.upstreamSampleValues(ge.steps,$e.fresh,yt,ge.loop,Nt),[ge.steps,ge.loop,$e.fresh,yt,Nt]),Ps=d.useMemo(()=>i.upstreamSampleValueSources(ge.steps,$e.fresh,yt,ge.loop,Nt),[ge.steps,ge.loop,$e.fresh,yt,Nt]),Is=i.useExpressionOptions(),Rs=d.useMemo(()=>i.nodeConfigSources(b),[b]),Ms=d.useMemo(()=>i.nodeConfigValues(b,L.subs),[b,L.subs]),Vt=d.useMemo(()=>i.nodeMetaValues(b,L.subs,P,U),[b,L.subs,P,U]),zt=d.useMemo(()=>({...l??{},steps:ge.steps,hasTrigger:ge.hasTrigger,eventOutputs:ge.eventOutputs,eventOutputsFrom:ge.eventOutputsFrom,loop:ge.loop,stateShape:{fields:$t.fields},nodeConfigs:Rs,nodeConfig:Ms,nodeMeta:Vt,valueSources:Ps,sampleValues:{...Is.sampleValues??{},...(l==null?void 0:l.sampleValues)??{},...i.nodeMetaSampleValues(Vt),...Ts,...$t.sampleValues}}),[l,Is.sampleValues,ge,$t,Ts,Ps,Rs,Ms,Vt]),Ls=r=>{var y;if(n)return;const u=_[r]();if(!u)return;const w=Ao(s,u);W(w.nodes.map(k=>({...k,selected:k.id===D}))),X(w.edges.map(k=>({...k,selected:k.id===de}))),G(u.canvas),R(u.connections),w.nodes.some(k=>k.id===D)||H(null),w.edges.some(k=>k.id===de)||Ae(null);const j=w.nodes.some(k=>k.id===re);j||he(null),De(!1),St(null),Re(null),ye(null),Me(null),Je(null),Oe(null),Ne(null),Xe(null),ae.current=void 0,rt(k=>k+1),o(Ke(i.flowToWorkflow({...s,nodes:u.nodes,connections:u.connections},w.nodes,w.edges),u.canvas)),!j&&!f&&((y=Ie.current)==null||y.focus({preventScroll:!0}))},Fs=d.useRef(Ls);Fs.current=Ls,d.useEffect(()=>{const r=Ie.current;if(!r)return;let u=r.contains(document.activeElement);const w=y=>{y.type==="focusin"&&y.target===document.body||(u=r.contains(y.target))},j=y=>{if(n||y.defaultPrevented||Ht(y.target)||!r.contains(y.target)&&!(u&&y.target===document.body))return;const k=y.key.toLowerCase();!(y.ctrlKey||y.metaKey)||y.altKey||k!=="z"&&!(k==="y"&&!y.shiftKey)||(y.preventDefault(),Fs.current(k==="y"||y.shiftKey?"redo":"undo"))};return document.addEventListener("pointerdown",w),document.addEventListener("focusin",w),document.addEventListener("keydown",j),()=>{document.removeEventListener("pointerdown",w),document.removeEventListener("focusin",w),document.removeEventListener("keydown",j)}},[n]);const kt=d.useCallback((r,u)=>{var M;if(Ht(r.target))return;const w=(M=Ie.current)==null?void 0:M.getBoundingClientRect();if(!w)return;r.preventDefault();const j=qs(b,E),y=j.nodeIds,k=co(y,u),F=u!==void 0&&!y.includes(u);F&&W(b.map(q=>q.selected!==(q.id===u)?{...q,selected:q.id===u}:q)),Oe({x:r.clientX-w.left,y:r.clientY-w.top,flow:Ce({x:r.clientX,y:r.clientY}),nodeIds:k,edgeIds:F?[]:j.edgeIds})},[b,E,W,Ce]),eo=d.useCallback(r=>{var u;Oe(null),r&&((u=Ie.current)==null||u.focus({preventScroll:!0}))},[]),to=r=>{const u=Ge;!u||n||(r==="duplicate"?Lt(u.nodeIds):r==="delete"?ye({nodeIds:u.nodeIds,edgeIds:u.edgeIds}):(Re(null),Je({position:u.flow,...r==="add-trigger"?{tab:"triggers"}:{}}),De(!0)))},so=t.jsx(as.Provider,{value:Dt,children:t.jsx(ns.Provider,{value:oe,children:t.jsx(os.Provider,{value:bs,children:t.jsx(is.Provider,{value:bt,children:t.jsx(bi,{apps:P,registration:L,children:t.jsx(i.WorkflowProjectProvider,{project:p,workflowId:s.id,children:t.jsx(i.ExpressionOptionsProvider,{value:zt,children:t.jsxs("section",{ref:Ie,className:"w6w-flow",tabIndex:-1,"aria-label":"Workflow editor",style:{width:"100%",height:a,position:"relative"},onFocusCapture:r=>{ae.current=Ht(r.target)?{}:void 0},onBlurCapture:()=>{ae.current=void 0},onKeyDown:r=>{if(r.defaultPrevented||r.key!=="Backspace"&&r.key!=="Delete"||n||re||te||Le)return;const u=r.target;if(u.isContentEditable||u.tagName==="INPUT"||u.tagName==="TEXTAREA"||u.tagName==="SELECT"||u.closest("dialog, .w6w-modal")!==null)return;const w=qs(b,E);!w.nodeIds.length&&!w.edgeIds.length||(r.preventDefault(),!w.nodeIds.length&&w.edgeIds.length===1?Bn(w.edgeIds[0]):ye(w))},children:[t.jsxs(ne.ReactFlow,{nodes:mt,edges:Xn,minZoom:.05,defaultEdgeOptions:{type:"smoothstep"},connectionLineType:ne.ConnectionLineType.SmoothStep,onNodesChange:le,onEdgesChange:I,onConnect:Dn,onConnectStart:(r,u)=>{Mt.current=u},onConnectEnd:On,onPaneClick:()=>Ne(null),onPaneContextMenu:r=>kt(r),onNodeContextMenu:(r,u)=>kt(r,u.id),onEdgeContextMenu:r=>kt(r),onSelectionContextMenu:r=>kt(r),onMoveStart:()=>Oe(null),isValidConnection:se,onNodeDragStop:(r,u,w)=>{const j=qn(w),y=j!==$;if(y&&G(j),!Z&&!y){_.record(Et(s,b,E,T.current,j));return}Q(b,E,j)},onMoveEnd:(r,u)=>{if(!r||n)return;const w=i.flowToWorkflow(s,b,E),j=i.withViewport(w,u);j!==w&&o(j,{viewportOnly:!0})},onSelectionChange:({nodes:r,edges:u})=>{var w,j,y,k;H(((w=r[0])==null?void 0:w.id)??null),Ae(((j=u[0])==null?void 0:j.id)??null),ls.current!==(((y=r[0])==null?void 0:y.id)??null)&&(ls.current=((k=r[0])==null?void 0:k.id)??null,Ne(null))},nodeTypes:Yn,nodesDraggable:!n,nodesConnectable:!n,connectOnClick:!1,elementsSelectable:!0,...z?{defaultViewport:z}:{fitView:!0},deleteKeyCode:null,colorMode:We,proOptions:{hideAttribution:!0},children:[t.jsx(ne.Background,{gap:16}),t.jsx(ne.Controls,{showInteractive:!1,children:!n&&t.jsx(ne.ControlButton,{onClick:Wn,title:"Auto-layout — re-flow the graph into columns","aria-label":"Auto-layout the graph",children:t.jsx(ve.Icon,{name:"layout"})})}),t.jsx(ne.MiniMap,{pannable:!0,zoomable:!0,style:{background:"var(--w6w-panel-2)"}}),!n&&t.jsxs(ne.Panel,{position:"top-left",className:"w6w-flow-tools",children:[t.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>De(!0),children:"+ Node"}),t.jsx(i.IconButton,{label:"Add note",icon:"sticky-note",className:"w6w-flow-tool","data-testid":"add-note",onClick:zn}),t.jsx(i.IconButton,{label:"Draw section",title:"Draw section — drag a frame on the canvas (Esc cancels)",icon:"frame",className:`w6w-flow-tool${He?" active":""}`,"aria-pressed":He,"data-testid":"draw-section",onClick:()=>{qe(!He),Ee(null)}})]}),!n&&He&&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:u,clientY:w}=r;Ee({sx:u,sy:w,ex:u,ey:w})},onPointerMove:r=>{const{clientX:u,clientY:w}=r;Ee(j=>j&&{...j,ex:u,ey:w})},onPointerUp:()=>{const r=Se;if(Ee(null),qe(!1),!r)return;const u=Ce({x:r.sx,y:r.sy}),w=Math.abs(r.ex-r.sx)>6||Math.abs(r.ey-r.sy)>6;Hn(u,w?Ce({x:r.ex,y:r.ey}):null)},children:Se&&(()=>{var j;const r=(j=Ie.current)==null?void 0:j.getBoundingClientRect(),u=(r==null?void 0:r.left)??0,w=(r==null?void 0:r.top)??0;return t.jsx("div",{className:"w6w-section-draw-rect",style:{left:Math.min(Se.sx,Se.ex)-u,top:Math.min(Se.sy,Se.ey)-w,width:Math.abs(Se.ex-Se.sx),height:Math.abs(Se.ey-Se.sy)}})})()}),!n&&st&&i.edgeLane(st)!=="each"&&((_s=b.find(r=>r.id===st.source))==null?void 0:_s.data.step.uses.app)!==i.ROUTER_APP&&t.jsx(ne.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${i.edgeLane(st)===r?" active":""}`,"aria-pressed":i.edgeLane(st)===r,title:xi,onClick:()=>$n(r),children:r==="success"?"Success":"Error"},r)),(wt==null?void 0:wt.edgeId)===st.id&&t.jsx("span",{className:"w6w-edge-lane-err w6w-small",role:"alert",children:wt.message})]})}),fe&&t.jsx(ne.NodeToolbar,{nodeId:fe.nodeId,position:ne.Position.Bottom,isVisible:!0,children:t.jsx("div",{className:"w6w-loop-notice w6w-small",role:"alert",children:i.loopRefusalMessage(fe.reason)})}),t.jsx(i.CanvasLayer,{canvas:$,readOnly:n,savePosition:Z,onChange:Ye,onSectionDrop:Jn,onRequestDelete:(r,u)=>!n&&Me({kind:r,id:u})})]}),pe&&t.jsx(i.ConfirmModal,{title:pe.kind==="note"?"Delete note":"Delete section",message:pe.kind==="note"?"Delete this note?":"Delete this section? Its nodes are kept.",confirmLabel:"Delete",onConfirm:()=>{Un(pe.kind,pe.id),Me(null)},onClose:()=>Me(null)}),te&&t.jsx(i.StepBuilderModal,{initialTab:Pe==null?void 0:Pe.tab,onClose:()=>{De(!1),Re(null),Je(null),St(null)},onAdd:r=>{const u=Vn(r);return u&&St(u),u},onDraftChange:(r,u)=>ms(r,{id:r,...u}),stepIds:b.map(r=>r.id),onOpenStep:r=>{De(!1),Re(null),Je(null),St(null),je("props"),he(r)},workflowId:s.id,upstreamSteps:i.stepBuilderUpstreamSteps(me,b,E),loop:i.stepBuilderLoop(me,b,E,xe)}),xt&&re&&t.jsx(Mi,{workflowId:s.id,step:xt,restoreVersion:ze,upstreamSteps:zt.steps??[],loop:zt.loop,readOnly:n,fanOutCount:bs.get(re)??0,stateOutputFields:(Vs=i.resolveOutputShape((Ws=xe.actionDef)==null?void 0:Ws.call(xe,xt.uses.app,xt.uses.action),($s=xe.testOutputs)==null?void 0:$s[re],(Bs=xe.persistedOutputs)==null?void 0:Bs[re]))==null?void 0:Vs.fields.map(r=>r.key),initialView:Te,stepProblems:nt==null?void 0:nt.data.stepProblems,otherStepIds:b.filter(r=>r.id!==re).map(r=>r.id),onChange:r=>ms(re,r),onClose:()=>he(null),onTestRun:x}),f&&t.jsxs(i.Modal,{title:`${_t?"Run node":"Test run"}: ${f.stepId}`,onClose:()=>V(null),children:[_t&&Ot&&t.jsx(Ni,{workflowId:s.id,step:Ot,upstreamSteps:Qn,loop:Ze==null?void 0:Ze.loop,continues:v?{stopAt:Zt(b.map(r=>r.data.step),f.stepId)}:void 0,onCancel:()=>V(null),onRun:(r,u)=>v?Gn(f.stepId,r,u):Kn(f.stepId,r,u)},f.stepId),!_t&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w6w-modal-body",children:[f.status==="running"&&t.jsx("p",{className:"w6w-muted w6w-small",children:"Running…"}),f.status==="error"&&t.jsxs("div",{className:"w6w-result w6w-error",children:[f.errorCode&&t.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:t.jsx("code",{children:f.errorCode})}),f.error||"The node failed with no error message."]}),f.status==="done"&&t.jsxs("div",{children:[t.jsx("div",{className:"w6w-muted w6w-small",style:{marginBottom:6},children:"Result"}),t.jsx(i.ResultViewer,{value:f.value,maxHeight:360}),f.meta&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Metadata"}),t.jsx(i.ResultViewer,{value:f.meta,maxHeight:360})]})]}),f.logs&&f.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(ve.Copyable,{value:f.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:
|
|
3
|
-
`)})})]})]}),t.jsx("div",{className:"w6w-modal-actions",children:t.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>V(null),children:"Close"})})]})]}),Le!==null&&t.jsx(i.ConfirmModal,{title:Le.nodeIds.length===1?"Delete node":Le.nodeIds.length>1?`Delete ${Le.nodeIds.length} nodes`:`Delete ${Le.edgeIds.length} connections`,message:Co(Le,b,E),confirmLabel:"Delete",autoFocusConfirm:!0,onConfirm:()=>{_n(Le),ye(null)},onClose:()=>ye(null)}),Ge&&t.jsx(io,{x:Ge.x,y:Ge.y,items:lo(Ge.nodeIds,!!n),onAction:to,onClose:eo})]})})})})})})})});return t.jsx(i.WorkflowConnectionsContext.Provider,{value:{nodes:b.map(r=>r.data.step),connections:U,setConnections:R,readOnly:n},children:so})}const vi=["code"];function It(e){try{const s=JSON.parse(e);return s&&typeof s=="object"&&!Array.isArray(s)?s:null}catch{return null}}function Si(e){try{const s=JSON.parse(e);if(Array.isArray(s))return{items:s}}catch{return null}return It(e)}function Ci({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 o=e[0],n=o!==void 0?(i.inferOutputFields(o)??[]).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(i.ResultViewer,{value:o,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,c)=>t.jsxs("span",{children:[c>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 kn(e){const[s,o]=d.useState(null),[n,a]=d.useState("0"),c=s??i.loopItemText(e),l=e?i.parseLoopSeed(c,n):void 0;return{active:!!e,itemText:c,indexText:n,setItemText:o,setIndexText:a,parsed:l}}function En(e){var s;return(s=e.parsed)!=null&&s.ok?e.parsed.value:void 0}function cs(e){return e.parsed&&!e.parsed.ok?e.parsed.error:null}function An({seed:e,readOnly:s}){if(!e.active)return null;const o=cs(e);return t.jsxs("div",{className:"w6w-field w6w-loop-seed",children:[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."}),o&&t.jsx("span",{className:"w6w-hint",role:"alert",children:o})]})}function es({text:e,onChange:s,seeds:o,readOnly:n,expand:a,hint:c}){const l=It(e),p=l?Object.keys(l).length:0,m=p>0,[g,x]=d.useState(m);d.useEffect(()=>{(m||a)&&x(!0)},[m,a]);const h=v=>{s(JSON.stringify(v.lastRunOutput??v.input??{},null,2)),x(!0)};return t.jsxs("div",{className:"w6w-field w6w-incoming-state",children:[t.jsx("span",{children:"Incoming state"}),o.length>0&&t.jsx("div",{className:"w6w-seed-picker",children:t.jsx("div",{className:"w6w-seed-chips",children:o.map(v=>t.jsxs("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Use ${v.label}'s saved test as the incoming state`,disabled:n,onClick:()=>h(v.test),children:[t.jsx("code",{children:v.label}),v.test.lastRunStatus?t.jsxs("span",{className:"w6w-muted w6w-small",children:[" · ",v.test.lastRunStatus]}):null]},v.stepId))})}),t.jsxs("details",{className:"w6w-state-override",open:g,onToggle:v=>x(v.currentTarget.open),children:[t.jsxs("summary",{children:["Override the incoming state",p>0?` · ${p} key${p===1?"":"s"} set`:""]}),t.jsx("textarea",{rows:3,value:e,readOnly:n,spellCheck:!1,"aria-label":"Incoming state override (JSON)",onChange:v=>s(v.target.value)}),t.jsx("span",{className:"w6w-hint",children:c??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 Ni({workflowId:e,step:s,upstreamSteps:o,loop:n,onRun:a,onCancel:c,continues:l}){const p=i.useW6WApi(),m=i.isTriggerStep(s.uses),g=i.isInternalApp(s.uses.app),x=d.useMemo(()=>{var O;return m?i.asFieldDefs((O=s.with)==null?void 0:O.fields):[]},[m,s.with]),h=d.useMemo(()=>m?i.fieldsToParams(x):g?i.internalNodeParams(s.uses.app,s.uses.action):null,[m,g,x,s.uses.app,s.uses.action]),[v,S]=d.useState(null),P=h??v;d.useEffect(()=>{if(h)return;if(!s.uses.app||!s.uses.action){S([]);return}let O=!1;return S(null),p.getAppActions(s.uses.app).then($=>{var G;O||S(((G=$.find(_=>_.key===s.uses.action))==null?void 0:G.params)??[])}).catch(()=>!O&&S([])),()=>{O=!0}},[p,h,s.uses.app,s.uses.action]);const[L,f]=d.useState(()=>{var O;return m?i.seedValues(i.asFieldDefs((O=s.with)==null?void 0:O.fields)):{}}),[V,N]=d.useState("{}"),J=i.useSeedSources(e,o,!m),U=kn(n),C=i.startStateFromSeeds(J,En(U)),T=i.useRememberedTestInput(e,s.id),[R,B]=d.useState(!1),[z,Z]=d.useState(!1);d.useEffect(()=>{if(!T.loaded)return;let O=!1;const $=(G,_)=>{G&&Object.keys(G).length>0&&(m?f(ae=>({...ae,...G})):N(JSON.stringify(G,null,2)),_&&Z(!0)),B(!0)};if(T.input!==void 0){$(T.input,!0);return}return p.listStepTests(e,s.id).then(G=>{if(O)return;const _=G.length?G[G.length-1]:null;$(m?_==null?void 0:_.with:_==null?void 0:_.input,!1)}).catch(()=>{O||B(!0)}),()=>{O=!0}},[p,e,s.id,m,T.loaded]);const[b,W]=d.useState(0),le=()=>{T.clear(),Z(!1),m?f(i.seedValues(x)):N("{}"),W(O=>O+1)},ue=O=>{f(O),oe(!0),Z(!1),W($=>$+1)},[ke,oe]=d.useState(!0),E=It(V),X=m?ke:E!==null,I=m?L:{...s.with??{},...E??{}},D=m?null:cs(U),H=!!P&&R&&X&&!D&&i.requiredParamsFilled(P,I);return t.jsxs("div",{className:"w6w-stepconfig",children:[t.jsx("div",{className:"w6w-modal-body",children:t.jsxs("div",{className:"w6w-stack",children:[l&&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",l.stopAt.length>0?t.jsxs(t.Fragment,{children:[" ","and stops before"," ",l.stopAt.length===1?"the paused node":"paused nodes"," ",l.stopAt.map((O,$)=>t.jsxs("span",{children:[$>0?", ":"",t.jsx("code",{children:O})]},O))]}):null,". Disabled nodes are skipped."]}),z&&P!==null&&R&&t.jsx(i.LastUsedNote,{onClear:le}),P===null||!R?t.jsx("p",{className:"w6w-muted w6w-small",children:P===null?"Loading parameters…":"Loading saved values…"}):m?t.jsxs(t.Fragment,{children:[t.jsx(i.PropertyEntryForm,{params:P,values:L,onChange:f,onValidityChange:oe},b),s.uses.trigger===!0&&t.jsx(ao,{app:s.uses.app,trigger:s.uses.action,onUse:ue}),P.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(es,{text:V,onChange:N,seeds:J})]})]})}),t.jsxs("div",{className:"w6w-modal-actions",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:c,children:"Cancel"}),!H&&P!==null&&R&&t.jsx("span",{className:"w6w-muted w6w-small",children:D?`${D} Fix it to run.`:X?m?"Fill the required fields to test.":"This step is missing required configuration — set it on the Configure tab.":m?"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:!H,onClick:()=>{T.save(m?L:E??{},P??[]),a(m?L:E??{},m?void 0:C)},children:"▶ Run"})]})]})}function ki(e){return e.uses.app===i.CONTROL_APP&&e.uses.action==="foreach"}function Tn({id:e}){const{tones:s,loopOf:o}=d.useContext(is),n=xn(e,o);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:ss(s.get(a)??1)}},a))})}function Pn(e){return Oo(e,d.useContext(is).tones)}function Ve({type:e,position:s,multiple:o,id:n,variant:a,top:c,routeLabel:l}){const p=ne.useNodeId(),m=d.useContext(as),g=!!p&&!!m&&!m.readOnly,x=()=>{g&&p&&m.onAddFromPort(p,e,n)},h=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(ne.Handle,{type:e,position:s,id:n,className:a==="error"?"w6w-handle-error":a==="each"?"w6w-handle-each":o?"w6w-handle-multi":void 0,style:{...o?{height:22,borderRadius:3,width:8}:{},...c?{top:c}:{}},onClick:g?x:void 0,title:l?`${l} — drag or click to connect`:g?`Drag to empty canvas (or click) to add ${h} · 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":o?e==="target"?"Accepts multiple incoming connections":"Multiple outgoing connections":void 0})}function In({id:e,step:s,runnable:o}){const n=d.useContext(as);if(!n||n.readOnly)return null;const a=o||n.runsFromNode,c=n.runsFromNode?"Run from this node — continues through the nodes after it":"Test-run this node",l=et(s),p=Fe(s);return t.jsxs(ne.NodeToolbar,{position:ne.Position.Top,className:"w6w-node-toolbar",children:[a&&t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:c,"aria-label":c,onClick:()=>n.onRun(e),children:t.jsx(ve.Icon,{name:"run",size:15})}),t.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(e),children:t.jsx(ve.Icon,{name:"pause",size:15})}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn","data-testid":"node-disable-toggle","aria-pressed":p,title:p?"Enable — this node runs again":"Disable — skip this node in every run","aria-label":p?"Enable node":"Disable node",onClick:()=>n.onToggleDisable(e),children:t.jsx(ve.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(ve.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(ve.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(ve.Icon,{name:"trash",size:15})})]})}function Rn({step:e,count:s}){if(s<2)return null;const o=e.fanOut==="parallel",n=Eo(s,o?"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:o?"⇉":"→"})," ",s]})}function Mn({step:e}){const s=et(e),o=Fe(e);return!s&&!o?null:t.jsxs("div",{children:[o&&t.jsxs("span",{className:"w6w-node-flag w6w-node-flag-disabled","data-testid":"step-disabled-badge",role:"img","aria-label":Ks,title:Ks,children:[t.jsx(ve.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":Gs,title:Gs,children:[t.jsx(ve.Icon,{name:"pause",size:11})," Paused"]})]})}function Ln(e){return!e||e.length===0?{}:{"data-step-problem":e.map(s=>s.code).join(" "),title:e.map(i.stepProblemTooltip).join(`
|
|
4
|
-
`)}}function
|
|
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(ve.Icon,{name:"warning",size:12})})}function Ei(e){const s=i.useW6WApi(),o=e.uses.action,[n,a]=d.useState(null),c=e.uses.trigger===!0,l=e.uses.app;return d.useEffect(()=>{if(!c||!s.getAppTriggers)return;let p=!1;return s.getAppTriggers(l).then(m=>{var g;return!p&&a(((g=m.find(x=>x.key===o))==null?void 0:g.title)??null)}).catch(()=>{}),()=>{p=!0}},[s,l,o,c]),n||o}function Ai(e){const s=i.useW6WApi(),o=s.listSubscriptionsForWorkflow,n=s.retrySubscriptionRegistration,a=e.id,c=[...hi(e.nodes),...(e.nodes??[]).filter(P=>{var L;return((L=P.uses)==null?void 0:L.app)===i.WEBHOOK_APP&&P.uses.trigger!==!0})],l=c.length>0,p=c.map(P=>`${P.id}:${P.uses.app}:${P.uses.action}:${i.connectionIdFor(P,e.connections)??""}`).join("|"),[m,g]=d.useState([]),x=d.useMemo(()=>fi(m),[m]),[h,v]=d.useState(0);d.useEffect(()=>{if(!o||!l){g([]);return}let P=!1;return o.call(s,a).then(L=>!P&&g(L)).catch(()=>{}),()=>{P=!0}},[s,o,a,l,p,h]);const S=d.useMemo(()=>n?async P=>{try{await n.call(s,P)}finally{v(L=>L+1)}}:void 0,[s,n]);return d.useMemo(()=>({byNode:x,subs:m,retry:S}),[x,m,S])}function Ti({nodeId:e}){const{byNode:s,retry:o}=d.useContext(Nn),[n,a]=d.useState(!1),c=s.get(e),l=pi(c,o!==void 0);return!c||!l?null:t.jsxs("div",{className:"w6w-small","data-trigger-registration":c.status,"data-tone":l.tone,style:{marginTop:3,paddingLeft:2},children:[t.jsx("span",{style:l.tone==="danger"?{color:"var(--w6w-danger)"}:void 0,children:l.label}),t.jsxs("span",{className:"w6w-muted",children:[" · ",l.lastFire]}),l.error&&t.jsx("div",{role:"alert",style:{color:"var(--w6w-danger)"},children:l.error}),l.retryVisible&&o&&t.jsx("button",{type:"button",className:"nodrag",disabled:n,onClick:()=>{a(!0),o(c.id).catch(()=>{}).finally(()=>a(!1))},children:"Retry"})]})}function Pi({id:e,data:s,selected:o}){const n=s.step,c=d.useContext(rs).get(n.uses.app),l=(c==null?void 0:c.displayName)||n.uses.app||"—",p=i.isTriggerStep(n.uses),m=Ei(n),g=n.uses.trigger?`${l} · ${m}`:l,x=i.nodePortsForStep(n,d.useContext(ns)),h=Sn(s.stepStatus??"no-run",s.runStatus),v=t.jsx(Rn,{step:n,count:d.useContext(os).get(e)??0}),S=Pn(e);return t.jsxs("div",{className:[s.loopOf?"w6w-node-in-loop":"",Fe(n)?"w6w-node-disabled":""].filter(Boolean).join(" ")||void 0,"data-loop-of":s.loopOf,style:S,"data-disabled":Fe(n)||void 0,"data-paused":et(n)||void 0,children:[t.jsx(In,{id:e,step:n,runnable:!0}),t.jsxs("div",{className:p?"w6w-node-trigger":void 0,"data-node-kind":p?"trigger":void 0,"data-run-status":s.stepStatus??"no-run",...Ln(s.stepProblems),style:{position:"relative",...s.stepProblems?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${h.borderWidth}px ${h.borderStyle} ${o?"var(--w6w-accent)":h.borderColor}`,opacity:Fe(n)?.45:o?1:h.opacity,background:"var(--w6w-panel)",color:"var(--w6w-text)",...p?{}:{borderRadius:4,padding:"8px 12px"},minWidth:180,fontSize:13,display:"flex",alignItems:"center",gap:10},children:[t.jsx(Fn,{problems:s.stepProblems}),x.in>0&&t.jsx(Ve,{type:"target",position:ne.Position.Left,multiple:x.in>1}),t.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}),t.jsxs("div",{style:{minWidth:0},children:[t.jsx("div",{style:{fontWeight:600},children:g}),t.jsx("div",{className:"w6w-muted w6w-small",style:{marginTop:2},children:t.jsx("code",{children:n.uses.action||"—"})})]}),x.out>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{type:"source",position:ne.Position.Right,multiple:x.out>1}),!p&&t.jsx(Ve,{type:"source",position:ne.Position.Bottom,multiple:!1,id:i.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),v,t.jsx(Mn,{step:n}),p&&n.uses.trigger===!0&&t.jsx(Ti,{nodeId:e}),s.loopOf&&t.jsx(Tn,{id:e}),t.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&&t.jsx("div",{className:"w6w-muted w6w-node-notes",title:n.notes,children:n.notes})]})}function Ii({id:e,data:s,selected:o}){const n=s.step,a=i.routesForStep(n),c=n.uses.app===i.ROUTER_APP,l=i.isIfStep(n),p=a.length?i.routerPortLayout(a):l?i.ifPortLayout():void 0,m=JSON.stringify(a.map(N=>N.id)),g=ne.useUpdateNodeInternals();d.useEffect(()=>{g(e)},[e,m,g]);const x=i.internalNodeLabel(n.uses.app,n.uses.action),h=i.internalNodeIcon(n.uses.app,n.uses.action),v=i.nodePortsForStep(n,d.useContext(ns)),S=i.isTriggerStep(n.uses),P=ki(n),L=Sn(s.stepStatus??"no-run",s.runStatus),f=t.jsx(Rn,{step:n,count:d.useContext(os).get(e)??0}),V=Pn(e);return t.jsxs("div",{className:[P?"w6w-node-foreach":"",s.loopOf?"w6w-node-in-loop":"",Fe(n)?"w6w-node-disabled":""].filter(Boolean).join(" ")||void 0,"data-loop-of":s.loopOf,style:V,"data-disabled":Fe(n)||void 0,"data-paused":et(n)||void 0,children:[t.jsx(In,{id:e,step:n,runnable:!i.isControlApp(n.uses.app)}),t.jsxs("div",{className:S?"w6w-node-trigger":c?"w6w-node-router":void 0,"data-node-kind":S?"trigger":void 0,"data-run-status":s.stepStatus??"no-run",...Ln(s.stepProblems),style:{position:"relative",...s.stepProblems?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${L.borderWidth}px ${L.borderStyle} ${o?"var(--w6w-accent)":L.borderColor}`,opacity:Fe(n)?.45:o?1:L.opacity,background:"var(--w6w-panel-2)",color:"var(--w6w-text)",...S?{}:{borderRadius:4,padding:"6px 14px 6px 8px"},minWidth:140,...p!=null&&p.minHeight?{minHeight:p.minHeight,boxSizing:"border-box"}:{},fontSize:13,display:"flex",alignItems:"center",gap:10},children:[t.jsx(Fn,{problems:s.stepProblems}),v.in>0&&t.jsx(Ve,{type:"target",position:ne.Position.Left,multiple:v.in>1}),h&&t.jsx(i.InternalIcon,{icon:h}),t.jsxs("div",{style:{minWidth:0,textAlign:"left"},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||"—"})})]}),P&&t.jsxs("div",{className:"w6w-foreach-ports w6w-small","aria-hidden":"true",children:[t.jsx("span",{children:"Each item"}),t.jsx("span",{children:"Done"})]}),!!(p!=null&&p.right.length)&&t.jsx("div",{className:"w6w-router-ports w6w-small",style:{gridTemplateRows:`repeat(${p.right.length}, 1fr)`},"aria-hidden":"true",children:p.right.map(N=>t.jsx("span",{title:N.label,children:N.label},N.id))}),v.out>0&&t.jsxs(t.Fragment,{children:[P&&t.jsx(Ve,{type:"source",position:ne.Position.Right,multiple:!1,id:i.EACH_SOURCE_HANDLE,variant:"each"}),p?t.jsxs(t.Fragment,{children:[p.right.map(N=>t.jsx(Ve,{type:"source",position:ne.Position.Right,multiple:!1,id:N.handleId,top:N.top,routeLabel:N.label},N.id)),p.bottom&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{type:"source",position:ne.Position.Bottom,multiple:!1,id:p.bottom.handleId,routeLabel:p.bottom.label}),t.jsx("span",{className:"w6w-router-fallback-label w6w-small","aria-hidden":"true",children:p.bottom.label})]})]}):t.jsx(Ve,{type:"source",position:ne.Position.Right,multiple:v.out>1,id:P?i.routeHandle(i.FOREACH_DONE_ROUTE):void 0}),!S&&!c&&!l&&n.uses.app!==i.RACE_APP&&t.jsx(Ve,{type:"source",position:ne.Position.Bottom,multiple:!1,id:i.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),f,t.jsx(Mn,{step:n}),s.loopOf&&t.jsx(Tn,{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 Ri(e,s){var l,p;if(!s)return e;const o={...(e==null?void 0:e.steps)??{}};let n=!1;for(const[m,g]of Object.entries(s)){const x=/^nodes\.([^.]+)\.output$/.exec(m);!x||((l=o[x[1]])==null?void 0:l.output)!==void 0||(o[x[1]]={...o[x[1]]??{},output:g},n=!0)}const a=s["trigger.event"],c=a!==void 0&&((p=e==null?void 0:e.trigger)==null?void 0:p.event)===void 0;return!n&&!c?e:{...e??{},...n?{steps:o}:{},...c?{trigger:{...(e==null?void 0:e.trigger)??{},event:a}}:{}}}function Mi(e){return t.jsx(Li,{...e})}function Li({workflowId:e,step:s,restoreVersion:o,upstreamSteps:n,loop:a,onChange:c,onClose:l,readOnly:p,initialView:m="props",fanOutCount:g=0,stateOutputFields:x,onTestRun:h,stepProblems:v,otherStepIds:S}){var mt,ct;const P=i.useW6WApi(),L=d.useContext(rs),[f,V]=d.useState(s),N=i.useWorkflowConnections(),J=i.connectionIdFor(f,N==null?void 0:N.connections),U={...f,uses:{...f.uses,connection:J}},T=f.uses.connectionRef!==void 0&&!J||i.isConnectionBlocked(U,v),R=v==null?void 0:v.find(A=>A.code==="unknown_connection"&&A.connection===J),B=(v??[]).filter(A=>"fix"in A),[z,Z]=d.useState(T?"setup":"configure"),[b,W]=d.useState(m==="json"?"code":m==="settings"?"config":"props"),[le,ue]=d.useState("props"),[ke,oe]=d.useState(()=>i.stepToJson(s)),[E,X]=d.useState("{}"),I=d.useRef(null),[D,H]=d.useState(!1),O=d.useRef(o);d.useEffect(()=>{O.current!==o&&(O.current=o,V(s),oe(i.stepToJson(s)))},[o,s]);const[$,G]=d.useState(!1),[_,ae]=d.useState(null),[ze,rt]=d.useState(null),[He,qe]=d.useState(null),[Se,Ee]=d.useState(!1),pe=i.isInternalApp(f.uses.app),Me=f.uses.trigger===!0;d.useEffect(()=>{if(pe){ae(i.internalNodeParams(f.uses.app,f.uses.action));const Y=i.INTERNAL_NODES.filter(se=>se.app===f.uses.app&&se.groupActions&&!se.hidden);rt(Y.length?Y.map(se=>({key:se.action,title:se.label,params:se.params})):null);return}if(!f.uses.app){rt(null),ae([]);return}let A=!1;return ae(null),(Me?i.getTriggerDefs(P,f.uses.app):P.getAppActions(f.uses.app)).then(Y=>{var se;A||(rt(Y),ae(f.uses.action?((se=Y.find(fe=>fe.key===f.uses.action))==null?void 0:se.params)??[]:[]))}).catch(()=>!A&&ae([])),()=>{A=!0}},[P,f.uses.app,f.uses.action,pe,Me]);const de=d.useRef(0);d.useEffect(()=>()=>{de.current++},[]);const Ae=d.useCallback(()=>{pe||!f.uses.app||P.listConnectionsForApp(f.uses.app).then(A=>{qe(A),Ee(!1)}).catch(()=>Ee(!0))},[P,f.uses.app,pe]);d.useEffect(()=>{if(pe||!f.uses.app)return;let A=!1;return qe(null),Ee(!1),P.listConnectionsForApp(f.uses.app).then(Y=>{A||(qe(Y),Ee(!1))}).catch(()=>!A&&Ee(!0)),()=>{A=!0}},[P,f.uses.app,pe]);const te=d.useCallback(A=>{V(A),c(A)},[c]),De=yo({enabled:f.uses.app===i.SCRIPT_APP&&!p,values:f.with??{},onChange:A=>te({...f,with:A})}),pt=A=>{A==="code"&&oe(i.stepToJson(f)),W(A)},re=A=>{const Y=i.stepNameError(A,S??[]);return Y||te({...f,id:A}),Y},he=!!f.uses.app&&!!f.uses.action&&!i.isControlApp(f.uses.app),Te=i.isForeachStep(f),je=i.isTriggerStep(f.uses),Ge=z==="test"&&he&&!je,Oe=i.useSeedSources(e,n,he&&!je||Te),Pe=kn(he&&!je?a:void 0),Je=i.startStateFromSeeds(Oe,En(Pe)),Le=Ri(Je,i.useExpressionOptions().sampleValues),ye=i.useRememberedTestInput(he&&!je||Te?e:void 0,f.id),[at,Ie]=d.useState(!1);d.useEffect(()=>{if((!he||je)&&!Te||!ye.loaded)return;if(!Te&&ye.input!==void 0){const Y=ye.input;if(Object.keys(Y).length===0)return;const se=JSON.stringify(Y,null,2);X(fe=>fe.trim()==="{}"?se:fe),Ie(!0);return}let A=!1;return P.listStepTests(e,f.id).then(Y=>{if(A)return;const se=Y.length?Y[Y.length-1]:null;if(!(se!=null&&se.input)||Object.keys(se.input).length===0)return;const fe=JSON.stringify(se.input,null,2);X(Ne=>Ne.trim()==="{}"?fe:Ne)}).catch(()=>{}),()=>{A=!0}},[P,e,f.id,he,je,Te,ye.loaded]);const me=Te?Si(E):It(E),Re={...f.with??{},...me??{}},Ce=me??{},_e=!!_&&!cs(Pe)&&i.requiredParamsFilled(_,Re)&&(f.uses.app!==i.CALL_APP||$),We=Te?i.resolveLoopItemsInState(Re.items,Je):void 0,[Ke,Q]=d.useState("idle"),ft=A=>{X(A),Q("idle")},ht=async()=>{if(We){Q("saving");try{await P.saveStepTest(e,f.id,i.foreachTestFixture(We,Ce)),Q("saved")}catch{Q("failed")}}},ce=L.get(f.uses.app),tt=pe?i.internalNodeIcon(f.uses.app,f.uses.action):null,Rt=pe?tt?t.jsx(i.InternalIcon,{icon:tt}):null:t.jsx(i.AppIcon,{src:ce==null?void 0:ce.iconSvg,srcDark:ce==null?void 0:ce.iconSvgDark,brandColor:ce==null?void 0:ce.brandColor,name:ce==null?void 0:ce.displayName});return t.jsx(i.Modal,{ariaLabel:"Edit step",titleIcon:Rt,title:t.jsx(i.StepNameEditor,{value:f.id,onCommit:re,readOnly:p}),onClose:l,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(A=>f.uses.app!==i.RACE_APP||A!=="test").map(A=>t.jsx("button",{type:"button",className:`w6w-subtab${z===A?" active":""}`,disabled:T&&A!=="setup",onClick:()=>Z(A),children:A==="setup"?"Setup":A==="configure"?"Configure":"Test"},A))}),Ge?t.jsx(i.ConfigViewToggle,{view:le,views:["props","code"],onChange:A=>ue(A)}):t.jsx(i.ConfigViewToggle,{view:b,customized:i.hasParamCustomization(f.with??{}),onChange:pt,disabled:z!=="configure"})]}),T&&R&&t.jsxs("div",{role:"alert",className:"w6w-field-error",children:["Connection ",R.connection," no longer exists — choose another to continue."]}),B.length>0&&t.jsx("div",{className:"w6w-stepproblem-fixes",style:{display:"grid",gap:6},children:B.map(A=>t.jsxs("div",{className:"w6w-small",style:{display:"flex",gap:8,alignItems:"center"},children:[t.jsx("span",{children:i.stepProblemTooltip(A)}),t.jsx("button",{type:"button",className:"w6w-btn","data-fix-code":A.code,disabled:p,onClick:()=>{const Y=vn(f,A);te(Y),oe(i.stepToJson(Y))},children:"fix"in A?A.fix.label:""})]},A.code))}),t.jsxs("div",{className:"w6w-stepconfig-body",children:[z==="setup"&&f.uses.app===i.CALL_APP&&t.jsx(i.CallTargetForm,{values:f.with??{},onChange:A=>te({...f,with:A}),readOnly:p,onValidityChange:G,setupOnly:!0}),z==="setup"&&f.uses.app!==i.CALL_APP&&t.jsx(Wi,{step:f,app:ce,actions:ze,conns:He,connsFailed:Se,isInternal:pe,actionLabel:Me?"Trigger":"Action",readOnly:p,onChangeAction:A=>{var se;const Y=pe?i.internalNodeDefaults(f.uses.app,A):{};if(pe)for(const fe of i.internalNodeParams(f.uses.app,A))fe.key in(f.with??{})&&(Y[fe.key]=(se=f.with)==null?void 0:se[fe.key]);te({...f,uses:{...f.uses,action:A},with:Y})},onChangeTriggerEvents:(A,Y)=>te({...f,uses:{...f.uses,action:A},with:{...f.with,actions:Y}}),onChangeConnection:A=>{if(!N){const{connectionRef:se,...fe}=f.uses;te({...f,uses:{...fe,connection:A}});return}const Y=i.selectNodeConnection(f,A,(N==null?void 0:N.nodes)??[f],(N==null?void 0:N.connections)??{});N==null||N.setConnections(Y.connections),te(Y.step)},onChangeConnectionRef:A=>te(i.withConnectionRef(f,A)),onConnectionCreated:Ae,onChangeApp:A=>{const Y=++de.current;if(A===f.uses.app){te(f);return}const se={...f,uses:{app:A,action:"",...Me?{trigger:!0}:{}},with:{}};(i.isInternalApp(A)?Promise.resolve([]):P.listConnectionsForApp(A)).catch(()=>[]).then(fe=>{if(Y!==de.current)return;const Ne=i.defaultConnectionFor(se,fe,(N==null?void 0:N.nodes)??[],(N==null?void 0:N.connections)??{});te({...se,uses:{...se.uses,...Ne}})})}}),z==="configure"&&t.jsxs(t.Fragment,{children:[f.uses.app===i.WEBHOOK_APP&&P.listSubscriptionsForWorkflow&&P.createSubscription&&t.jsx(_i,{workflowId:e,step:f,readOnly:p}),_===null?t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):b==="props"?f.uses.app===i.CALL_APP?t.jsx(i.CallTargetForm,{values:f.with??{},onChange:A=>te({...f,with:A}),readOnly:p,onValidityChange:G}):f.uses.app===i.RACE_APP?t.jsx("p",{className:"w6w-muted w6w-small",children:i.RACE_DESCRIPTION}):f.uses.action==="wait"&&i.isControlApp(f.uses.app)?t.jsx(i.WaitEditor,{values:f.with??{},readOnly:p,onChange:A=>te({...f,with:A})}):f.uses.action==="if"&&i.isControlApp(f.uses.app)?t.jsx(i.ConditionEditor,{values:f.with??{},readOnly:p,onChange:A=>te({...f,with:A})}):f.uses.app==="@w6w/stop"?t.jsx(i.StopEditor,{values:f.with??{},readOnly:p,onChange:A=>te({...f,with:A})}):f.uses.app===i.ROUTER_APP?t.jsx(i.RouterEditor,{values:f.with??{},readOnly:p,onChange:A=>te({...f,with:A})}):t.jsxs(t.Fragment,{children:[f.uses.app===i.SCRIPT_APP&&t.jsx(vo,{values:f.with??{},conversion:De,readOnly:p}),t.jsx(i.ParamsForm,{params:_,values:f.with??{},readOnly:p,onChange:A=>te({...f,with:A}),dynamic:pe||!f.uses.action?void 0:{appId:f.uses.app,actionKey:f.uses.action,connectionId:T?void 0:J,appName:ce==null?void 0:ce.displayName}})]}):b==="code"?t.jsx(i.JsonEditor,{value:ke,onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":`Node ${f.id} JSON`,copyable:!0}):b==="params-code"?t.jsx(i.ParamCustomization,{values:f.with??{},onChange:A=>te({...f,with:A}),readOnly:p}):t.jsxs("div",{className:"w6w-stack",children:[t.jsx(i.NodeConfigForm,{config:{retry:f.retry,onError:f.onError,notes:f.notes},onChange:A=>te({...f,...A}),readOnly:p,failureHandling:!je,retryControls:!i.isControlApp(f.uses.app)&&f.uses.app!==i.CALL_APP}),Fi,t.jsx(Di,{step:f,count:g,readOnly:p,onChange:te}),Qo(f)&&t.jsx(Oi,{step:f,inLoop:a!==void 0,outputFields:x,readOnly:p,onChange:te})]})]}),z==="test"&&t.jsx("div",{className:"w6w-stack",children:he?Me?t.jsx(i.AppTriggerTestNote,{title:((mt=ze==null?void 0:ze.find(A=>A.key===f.uses.action))==null?void 0:mt.title)??f.uses.action,app:(ce==null?void 0:ce.displayName)??f.uses.app}):je?t.jsx(i.TriggerFillForm,{app:f.uses.app,action:f.uses.action,fields:(ct=f.with)==null?void 0:ct.fields,persist:{workflowId:e,stepId:f.id,input:Ce},listen:f.uses.app===i.WEBHOOK_APP&&P.listSubscriptionsForWorkflow&&P.startWebhookListen?{stepWith:f.with,readOnly:p}:void 0}):t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:"w6w-muted w6w-small",children:["Tests ",t.jsx("code",{children:f.uses.action})," with the configuration saved on this step — only the incoming state changes per run."]}),t.jsx(An,{seed:Pe,readOnly:p}),at&&!p&&t.jsx(i.LastUsedNote,{onClear:()=>{ye.clear(),Ie(!1),X("{}")}}),t.jsx(es,{text:E,onChange:X,seeds:Oe,readOnly:p}),_===null?t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):t.jsx(wo,{params:_,values:Re,testStartState:Le,view:le,literalKeys:f.uses.app===i.SCRIPT_APP?vi:void 0}),t.jsx(i.StepTestRun,{ref:I,app:f.uses.app,action:f.uses.action,connectionId:J,values:Re,state:Je,canRun:_e,hideRunButton:!0,persist:{workflowId:e,stepId:f.id,input:Ce},onBusyChange:H})]}):Te?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(es,{text:E,onChange:ft,seeds:Oe,readOnly:p,expand:!We,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(Ci,{items:We,save:Ke})]}):t.jsx("p",{className:"w6w-muted w6w-small",children:"Flow-control nodes can't be tested on their own."})})]}),t.jsx("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:f.uses.app===i.RACE_APP&&z==="configure"?t.jsx("button",{type:"button",className:"w6w-btn",onClick:l,children:"Done"}):z!=="test"?t.jsx("button",{type:"button",className:"w6w-btn",disabled:T,onClick:()=>Z(z==="setup"?"configure":"test"),children:"Next →"}):t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:l,children:"Done"}),he&&!je&&t.jsx("button",{type:"button",className:"w6w-btn",disabled:p||!_e||D,onClick:()=>{var A;h==null||h(),(A=I.current)==null||A.run()},children:D?"Testing…":"Test"}),Te&&t.jsx("button",{type:"button",className:"w6w-btn",disabled:p||!(We!=null&&We.length)||Ke==="saving",onClick:()=>void ht(),children:Ke==="saving"?"Testing…":"Test"})]})})]})})}const Fi=!1;function Di({step:e,count:s,readOnly:o,onChange:n}){const a=s>=2,c=e.fanOut==="parallel"?"parallel":"sequential";return t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Run next nodes"}),t.jsxs("select",{"aria-label":"Run next nodes",value:c,disabled:o||!a,onChange:l=>n(ko(e,l.target.value)),children:[t.jsx("option",{value:"sequential",children:"In sequence"}),t.jsx("option",{value:"parallel",children:"In parallel"})]}),!a&&t.jsx("span",{className:"w6w-muted w6w-small",children:"Connect two or more steps after this one to choose how they run."})]})}function rn({to:e}){return t.jsxs("div",{className:"w6w-state-map-row w6w-state-map-head","aria-hidden":"true",children:[t.jsx("span",{children:"From this step output"}),t.jsx("span",{}),t.jsx("span",{children:e})]})}function an(){return t.jsx("span",{className:"w6w-state-map-arrow","aria-hidden":"true",children:"→"})}function cn({label:e,fields:s,value:o,readOnly:n,onChange:a}){const c=d.useMemo(()=>(s??[]).map(l=>({value:l,label:l})),[s]);return t.jsx(i.Combobox,{mode:"combobox",forceSelection:!1,"aria-label":e,placeholder:"Whole output, or e.g. order",options:c,value:o,disabled:n,emptyText:c.length>0?"No matching field — keep typing a path":"Test this step to list its output fields, or type a path",onChange:a})}function Oi({step:e,inLoop:s,outputFields:o,readOnly:n,onChange:a}){const c=Ko(e),l=be.validateStateConfig(c),p=h=>a(Yo(e,h)),m=c.mode==="pick"&&Array.isArray(c.map)?c.map:[],g=(h,v)=>p({mode:"pick",map:m.map((S,P)=>P===h?{...S,...v}:S)}),x=h=>{if(c.mode!=="append")return;const v=h.path??c.path,S="from"in h?h.from:c.from;p({mode:"append",path:v,...S?{from:S}:{}})};return t.jsxs("div",{className:"w6w-field w6w-stack",children:[t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Write to state"}),t.jsx("select",{"aria-label":"Write to state",value:c.mode,disabled:n,onChange:h=>p(Zo(e,h.target.value)),children:qo.map(h=>t.jsx("option",{value:h,children:Go[h]},h))})]}),c.mode==="key"&&t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"To state key"}),t.jsx("input",{type:"text","aria-label":"State key",placeholder:"e.g. order",value:c.key,disabled:n,onChange:h=>p({mode:"key",key:h.target.value})}),t.jsxs("span",{className:"w6w-hint",children:["Copies the whole step output into ",t.jsx("code",{children:"state.<key>"}),". A dotted key such as"," ",t.jsx("code",{children:"order.id"})," nests."]})]}),c.mode==="pick"&&t.jsxs("div",{className:"w6w-stack",children:[t.jsx(rn,{to:"To state key"}),m.length===0&&t.jsx("p",{className:"w6w-muted w6w-small",children:"No fields yet — add one below."}),m.map((h,v)=>t.jsxs("div",{className:"w6w-datavar-row w6w-state-map-row",children:[t.jsx(cn,{label:"From output field",fields:o,value:h.from,readOnly:n,onChange:S=>g(v,{from:S})}),t.jsx(an,{}),t.jsx("input",{type:"text","aria-label":"To state path",placeholder:"e.g. order",value:h.to,disabled:n,onChange:S=>g(v,{to:S.target.value})}),!n&&t.jsx(i.DeleteButton,{label:"Remove field",onClick:()=>p({mode:"pick",map:m.filter((S,P)=>P!==v)})})]},v)),!n&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-state-map-add","aria-label":"Add field",onClick:()=>p({mode:"pick",map:[...m,{from:"",to:""}]}),children:"+ Add field"}),t.jsxs("span",{className:"w6w-hint",children:["Copies ",t.jsx("code",{children:"output.<path>"})," into ",t.jsx("code",{children:"state.<key>"}),". Leave the left side blank to copy the whole output."]})]}),c.mode==="append"&&t.jsxs("div",{className:"w6w-stack",children:[t.jsx(rn,{to:"Append to state list"}),t.jsxs("div",{className:"w6w-datavar-row w6w-state-map-row",children:[t.jsx(cn,{label:"Output field to append",fields:o,value:c.from??"",readOnly:n,onChange:h=>x({from:h})}),t.jsx(an,{}),t.jsx("input",{type:"text","aria-label":"Append to state path",placeholder:"e.g. orders",value:c.path,disabled:n,onChange:h=>x({path:h.target.value})})]}),t.jsxs("span",{className:"w6w-hint",children:["Appends ",t.jsx("code",{children:"output.<path>"})," to the list at ",t.jsx("code",{children:"state.<key>"}),". Leave the left side blank to append the whole output."]})]}),l.length>0&&t.jsx("div",{role:"alert",className:"w6w-state-write-issues w6w-small",children:l.map(h=>t.jsx("div",{children:h.message},`${h.code}:${h.message}`))}),c.mode!=="off"&&t.jsxs("span",{className:"w6w-muted w6w-small",children:["Writing ",t.jsx("code",{children:"null"})," deletes the key, and secrets are stored masked."]}),s&&t.jsx("span",{className:"w6w-muted w6w-small",children:"This step is inside a For each, so it writes once per item — Append collects one entry per item."})]})}function _i({workflowId:e,step:s,readOnly:o}){const n=i.useW6WApi(),[a,c]=d.useState(void 0),[l,p]=d.useState(null),[m,g]=d.useState(!1);d.useEffect(()=>{const h=n.listSubscriptionsForWorkflow;if(!h)return;let v=!1;return h(e).then(S=>{v||c(i.pickWebhookSubscription(S,s.id))}).catch(S=>!v&&p(S.message)),()=>{v=!0}},[n,e,s.id]);const x=()=>{const h=n.createSubscription;h&&(p(null),g(!0),h(i.WEBHOOK_APP,s.uses.action,{workflowId:e,connectionId:null,params:s.with??{}}).then(v=>{g(!1),c(v)}).catch(v=>{g(!1),p(v instanceof Error?v.message:String(v))}))};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."]}),l&&t.jsx("div",{className:"w6w-result w6w-error",children:l}),a!=null&&a.webhookUrl?t.jsx(ve.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…"}):!o&&t.jsx("button",{type:"button",className:"w6w-btn",disabled:m,onClick:x,children:m?"Creating…":"Create webhook URL"})]})}function Wi({step:e,app:s,actions:o,conns:n,connsFailed:a,isInternal:c,actionLabel:l="Action",readOnly:p,onChangeAction:m,onChangeTriggerEvents:g,onChangeConnection:x,onChangeConnectionRef:h,onChangeApp:v,onConnectionCreated:S}){const P=e.uses.trigger?i.eventbriteTriggerChoices(e.uses.app,o,e.uses.action,e.with??{}):null,[L,f]=d.useState(null),V=d.useRef(null),N=i.useWorkflowConnections(),J=i.connectionIdFor(e,N==null?void 0:N.connections);return t.jsxs("div",{className:"w6w-stack",children:[e.uses.connectionRef&&!J&&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:V,children:[t.jsxs("button",{type:"button",className:"w6w-app-conn-btn","aria-label":"App","aria-expanded":L==="app",disabled:p,onClick:()=>f(U=>U==="app"?null:"app"),children:[!c&&s&&t.jsx(i.AppIcon,{src:s.iconSvg,srcDark:s.iconSvgDark,brandColor:s.brandColor,name:s.displayName,size:20}),t.jsx("span",{className:"w6w-conn-label-name",children:c?e.uses.app:(s==null?void 0:s.displayName)??e.uses.app})]}),!c&&t.jsx(i.WorkflowConnectionPicker,{step:e,conns:n,failed:a,readOnly:p,open:L==="conn",onOpenChange:U=>f(U?"conn":null),anchorRef:V,onChangeConnection:x,onChangeConnectionRef:h,onConnectionCreated:S})]}),L==="app"&&t.jsx(i.AnchoredFlyout,{anchorRef:V,onClose:()=>f(null),children:t.jsx(i.AppPicker,{onSelectApp:U=>{const C=U.id===e.uses.app;v(U.id),f(C?"conn":null)}})})]}),c&&!(o!=null&&o.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})})]}):P?t.jsx(i.EventbriteTriggerPicker,{choices:P,readOnly:p,onChange:U=>g(P.triggerKey,U)}):t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:l}),t.jsx(i.Combobox,{value:e.uses.action,disabled:p||o===null,onChange:m,options:o===null?[{value:e.uses.action,label:e.uses.action}]:o.map(U=>({value:U.key,label:U.title??U.key}))})]})]})}function ln({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 $i({resources:e}){const s=i.useW6WApi(),o=e.highlightNode;d.useEffect(()=>()=>o==null?void 0:o(null),[o]);const[n,a]=d.useState([]),[c,l]=d.useState(!0),[p,m]=d.useState(),[g,x]=d.useState(),[h,v]=d.useState(null),[S,P]=d.useState(!1),[L,f]=d.useState(!1),V=d.useRef(0),N=d.useCallback(async()=>{const I=++V.current;l(!0),m(void 0);try{const D=await s.listConnections();return I!==V.current?void 0:(a(D),D)}catch(D){I===V.current&&m(D.message)}finally{I===V.current&&l(!1)}},[s]);d.useEffect(()=>(N(),()=>{V.current++}),[N]);const[J,U]=d.useState(new Map),C=JSON.stringify([...new Set([...Object.values(e.connections).map(I=>I.app),...n.map(I=>I.appId)])].filter(I=>{var D;return!((D=e.apps)!=null&&D.has(I))&&!n.some(H=>H.appId===I&&H.app!==void 0)}).sort());d.useEffect(()=>{var $,G;let I=!1;const D=JSON.parse(C);if(c||!D.length)return;const H=($=s.listAppsByIds)==null?void 0:$.bind(s),O=H?Promise.all(Array.from({length:Math.ceil(D.length/50)},(_,ae)=>H(D.slice(ae*50,(ae+1)*50)))).then(_=>_.flat()):(G=s.listApps)==null?void 0:G.call(s);return O==null||O.then(_=>{I||U(new Map(_.map(ae=>[ae.id,ae])))}).catch(()=>{}),()=>{I=!0}},[s,C,c]);const T=I=>{var $;const D=n.find(G=>G.appId===I&&G.app)??n.find(G=>G.appId===I&&G.app!==void 0),H=D?i.resolveConnectionAppMeta(D,J):J.get(I),O=($=e.apps)==null?void 0:$.get(I);return O?{...H,...O}:H},R=I=>{var D;return((D=T(I))==null?void 0:D.displayName)||I},B=I=>{if(e.readOnly)return!1;try{return e.edit(I),x(void 0),!0}catch(D){return x(D.message),!1}},z=I=>i.nextWorkflowConnectionName(I.appId,e.connections),Z=()=>{v(null),x(void 0),P(!1)},b=h!=null&&h.ref?e.connections[h.ref]:void 0,W=n.find(I=>I.id===(h==null?void 0:h.connection)),le=(b==null?void 0:b.app)??(W==null?void 0:W.appId),ue=e.nodes.filter(I=>I.uses.app===le),ke=e.nodes.filter(I=>(h==null?void 0:h.ref)!==void 0&&I.uses.connectionRef===h.ref),oe=n.filter(I=>!b||I.appId===b.app).map(I=>({value:I.id,label:b?I.displayName||I.id:`${R(I.appId)} · ${I.displayName||I.id}`}));h!=null&&h.connection&&!oe.some(I=>I.value===h.connection)&&oe.unshift({value:h.connection,label:h.connection.startsWith("zerocred:")?"Built-in":h.connection});const E=(I,D=28)=>{const H=T(I);return t.jsx(i.AppIcon,{src:H==null?void 0:H.iconSvg,srcDark:H==null?void 0:H.iconSvgDark,brandColor:H==null?void 0:H.brandColor,name:R(I),size:D})},X=()=>{if(!h||!h.name.trim()||!h.connection||!le)return;const I=h.ref!==void 0?{type:"update",ref:h.ref,name:h.name,connection:h.connection,nodeIds:h.allNodes?ue.map(D=>D.id):void 0}:{type:"add",name:h.name,app:le,connection:h.connection};B(I)&&Z()};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(i.IconButton,{label:"Add connection",disabled:e.readOnly,onClick:()=>{x(void 0),v({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"})})})]}),p&&t.jsxs("div",{role:"alert",className:"w6w-stack",children:[t.jsxs("p",{className:"w6w-field-error",children:["Couldn’t load connections: ",p]}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>void N(),children:"Retry"})]}),Object.entries(e.connections).map(([I,D])=>{var G;const H=e.nodes.filter(_=>_.uses.connectionRef===I),O=n.find(_=>_.id===D.connection),$=(O==null?void 0:O.displayName)||((G=D.connection)!=null&&G.startsWith("zerocred:")?"Built-in":D.connection)||"No credentials selected";return t.jsxs("section",{className:"w6w-workflow-connection","data-connection-resource":I,children:[t.jsxs("div",{className:"w6w-connection-app-heading",children:[E(D.app),t.jsxs("div",{className:"w6w-connection-summary",children:[t.jsx("strong",{children:R(D.app)}),t.jsx("span",{className:"w6w-small",children:$}),t.jsxs("span",{className:"w6w-muted w6w-small",children:[I,O!=null&&O.state?` · ${O.state}`:""]})]}),t.jsx(i.IconButton,{icon:"edit",label:`Edit connection ${I}`,disabled:e.readOnly,onClick:()=>{x(void 0),v({ref:I,name:I,connection:D.connection??"",allNodes:!1})}})]}),H.length>0?t.jsxs("details",{className:"w6w-connection-consumers",onToggle:_=>{_.currentTarget.open||o==null||o(null)},children:[t.jsxs("summary",{className:"w6w-muted w6w-small",children:["Used by ",H.length," ",H.length===1?"node":"nodes"]}),t.jsx("ul",{className:"w6w-connection-node-list",children:H.map(_=>t.jsx("li",{children:e.focusNode?t.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost","aria-label":`Show ${_.id} on canvas`,onClick:()=>{var ae;return(ae=e.focusNode)==null?void 0:ae.call(e,_.id)},onMouseEnter:()=>o==null?void 0:o(_.id),onMouseLeave:()=>o==null?void 0:o(null),onFocus:()=>o==null?void 0:o(_.id),onBlur:()=>o==null?void 0:o(null),children:[t.jsx(ln,{trigger:i.isTriggerStep(_.uses)}),t.jsxs("span",{className:"w6w-connection-node-label",children:[t.jsx("strong",{children:_.uses.action}),t.jsx("span",{className:"w6w-muted w6w-small",children:_.id})]})]}):t.jsxs("span",{className:"w6w-connection-app-heading",children:[t.jsx(ln,{trigger:i.isTriggerStep(_.uses)}),t.jsxs("span",{className:"w6w-connection-node-label",children:[t.jsx("strong",{children:_.uses.action}),t.jsx("span",{className:"w6w-muted w6w-small",children:_.id})]})]})},_.id))})]}):t.jsx("span",{className:"w6w-muted w6w-small",children:"Not used by any nodes yet."})]},I)}),!Object.keys(e.connections).length&&t.jsx("p",{className:"w6w-muted w6w-small",children:"No workflow connections yet."}),h&&!L&&!S&&t.jsxs(i.Modal,{title:h.ref!==void 0?"Edit connection":"Add connection",titleIcon:le?E(le):void 0,subtitle:le?R(le):void 0,onClose:Z,children:[t.jsxs("div",{className:"w6w-modal-body w6w-stack",children:[g&&t.jsx("p",{role:"alert",className:"w6w-field-error",children:g}),p&&t.jsxs("div",{role:"alert",className:"w6w-stack",children:[t.jsxs("p",{className:"w6w-field-error",children:["Couldn’t load credentials: ",p]}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>void N(),children:"Retry"})]}),h.ref!==void 0&&!b&&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:h.name,disabled:e.readOnly,onChange:I=>v({...h,name:I.target.value})})]}),t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:b?"Credentials":"Existing connection"}),t.jsx(i.Combobox,{"aria-label":b?"Credentials":"Connection to add",options:oe,value:h.connection,placeholder:c?"Loading connections…":"Choose a connection…",disabled:e.readOnly||c||!!p,onChange:I=>{const D=n.find(H=>H.id===I);v({...h,connection:I,name:!h.name&&D?z(D):h.name})}})]}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:e.readOnly,onClick:()=>f(!0),children:"Create new credentials"}),b&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"w6w-muted w6w-small",children:h.allNodes?`Saving applies these credentials to all ${ue.length} ${R(b.app)} nodes.`:`Saving updates credentials for ${ke.length} linked ${ke.length===1?"node":"nodes"}.`}),ue.length>0&&t.jsxs("label",{className:"w6w-connection-scope",children:[t.jsx("input",{type:"checkbox",checked:h.allNodes||ue.every(I=>I.uses.connectionRef===h.ref),disabled:e.readOnly||ue.every(I=>I.uses.connectionRef===h.ref),onChange:I=>v({...h,allNodes:I.target.checked})}),"Use for all ",ue.length," ",R(b.app)," ",ue.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||ke.length>0,onClick:()=>P(!0),children:"Remove from workflow"}),ke.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:Z,children:"Cancel"}),t.jsx("button",{type:"button",className:"w6w-btn",disabled:e.readOnly||c||!!p||!h.name.trim()||!h.connection||!le||h.ref!==void 0&&!b,onClick:X,children:h.ref!==void 0?"Save changes":"Add to workflow"})]})]}),h&&S&&t.jsx(i.ConfirmModal,{title:"Remove workflow connection",message:`Remove “${h.ref}” from this workflow? The saved credentials will remain available.`,confirmLabel:"Remove",onClose:()=>P(!1),onConfirm:()=>{h.ref&&B({type:"remove",ref:h.ref})?Z():P(!1)}}),h&&L&&t.jsx(i.AddConnectionModal,{initialAppId:b==null?void 0:b.app,onClose:()=>f(!1),onCreated:({connectionId:I})=>{f(!1),N().then(D=>{const H=D==null?void 0:D.find(O=>O.id===I);H&&v(O=>O?{...O,connection:H.id,name:O.name||z(H)}: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=dn;exports.MAX_NOTE_BYTES=pn;exports.MAX_SECTIONS=un;exports.WorkflowConnectionsPanel=$i;exports.WorkflowFlowEditor=ji;exports.applyStepProblemFix=vn;exports.assignMembership=Kt;exports.clampCanvas=Xt;exports.findLoopProblems=Vo;exports.findStateWriteProblems=Jo;exports.isDisabledStep=Fe;exports.isPausedStep=et;exports.pausedStopAt=Zt;exports.pruneSectionMembers=ts;exports.renameSectionMember=hn;exports.roundGeometry=Gt;exports.sectionsContaining=mn;exports.withCanvasGeometry=fn;exports.withDisabled=jn;exports.withPaused=bn;
|
|
1
|
+
"use client";"use strict";var ao=Object.defineProperty;var co=(e,s,o)=>s in e?ao(e,s,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[s]=o;var it=(e,s,o)=>co(e,typeof s!="symbol"?s+"":s,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),be=require("@w6w/expr"),oe=require("@xyflow/react"),d=require("react"),i=require("./connection-app-meta-CKTmUX08.cjs"),ke=require("./CodeBlock-BSX1pi6W.cjs");function lo({x:e,y:s,items:o,onAction:n,onClose:a}){const l=d.useRef(null),[c,f]=d.useState({left:e,top:s});d.useLayoutEffect(()=>{const g=l.current,x=g==null?void 0:g.offsetParent;if(!g||!x)return;const h=g.offsetWidth,v=g.offsetHeight;f({left:e+h>x.clientWidth?Math.max(0,e-h):e,top:s+v>x.clientHeight?Math.max(0,s-v):s})},[e,s]),d.useEffect(()=>{var g,x;(x=(g=l.current)==null?void 0:g.querySelector("[role=menuitem]"))==null||x.focus({preventScroll:!0})},[]),d.useEffect(()=>{const g=v=>{var S;(S=l.current)!=null&&S.contains(v.target)||a(!1)},x=v=>{var S;(S=l.current)!=null&&S.contains(v.target)||a(!1)},h=()=>a(!1);return document.addEventListener("pointerdown",g,!0),document.addEventListener("scroll",x,!0),document.addEventListener("wheel",x,{capture:!0,passive:!0}),window.addEventListener("blur",h),window.addEventListener("resize",h),()=>{document.removeEventListener("pointerdown",g,!0),document.removeEventListener("scroll",x,!0),document.removeEventListener("wheel",x,!0),window.removeEventListener("blur",h),window.removeEventListener("resize",h)}},[a]);const p=g=>{g.disabled||(a(!1),n(g.action))};return t.jsx("div",{ref:l,className:"w6w-note-menu w6w-canvas-menu",role:"menu","aria-label":"Canvas actions","data-testid":"canvas-context-menu",style:{left:c.left,top:c.top},onContextMenu:g=>g.preventDefault(),onKeyDown:g=>{var S;g.stopPropagation();const x=[...((S=l.current)==null?void 0:S.querySelectorAll("[role=menuitem]"))??[]],h=x.indexOf(document.activeElement),v=R=>{var A;return(A=x[(R+x.length)%x.length])==null?void 0:A.focus()};if(g.key==="ArrowDown")v(h+1);else if(g.key==="ArrowUp")v(h<0?-1:h-1);else if(g.key==="Home")v(0);else if(g.key==="End")v(-1);else if(g.key==="Escape"||g.key==="Tab")a(!0);else if(g.key==="Enter"||g.key===" ")h>=0&&p(o[h]);else return;g.preventDefault()},children:o.map(g=>t.jsx("button",{type:"button",role:"menuitem",tabIndex:-1,"aria-disabled":g.disabled||void 0,className:`w6w-note-menu-item${g.danger?" danger":""}${g.separated?" separated":""}`,"data-action":g.action,onClick:()=>p(g),children:g.label},g.action))})}function uo(e){return e===null||typeof e!="object"||Array.isArray(e)?null:e}function po({app:e,trigger:s,onUse:o}){const n=i.useW6WApi(),[a,l]=d.useState(null);return d.useEffect(()=>{var f;let c=!1;return l(null),(f=n.getAppTriggers)==null||f.call(n,e).then(p=>{var g;c||l(uo((g=p.find(x=>x.key===s))==null?void 0:g.sample))}).catch(()=>{}),()=>{c=!0}},[n,e,s]),a?t.jsx("div",{children:t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost","data-testid":"use-trigger-sample",onClick:()=>o(a),children:"Use sample event"})}):null}function fo(e,s){return s===void 0?[...e]:e.includes(s)?[...e]:[s]}function ho(e,s){const o=[],n=e.length;if(n>0){const a=n>1?` ${n} nodes`:"";o.push({action:"duplicate",label:`Duplicate${a}`,disabled:s}),o.push({action:"delete",label:`Delete${a}`,disabled:s,danger:!0})}return o.push({action:"add-node",label:"Add node",disabled:s,separated:n>0}),o.push({action:"add-trigger",label:"Add trigger",disabled:s}),o}const wn=200,gn=200,xn=10240;function Yt(e){const s={};for(const[o,n]of Object.entries(e))s[o]=Math.round(n);return s}const mo=e=>!!e&&Number.isFinite(e.x)&&Number.isFinite(e.y),wo=e=>!!e&&Number.isFinite(e.width)&&Number.isFinite(e.height);function Ks(e,s,o){return e&&e.map(n=>{const a=s==null?void 0:s[n.id],l=mo(a==null?void 0:a.position)?a.position:n.position,c=wo(a==null?void 0:a.size)?a.size:n.size;return{...n,position:Yt(l),size:Yt(c)}})}function bn(e,s,o){if(!s)return e;const n={...e};return e.notes&&(n.notes=Ks(e.notes,o)),e.sections&&(n.sections=Ks(e.sections,o)),n}function os(e,s){return e.sections?{...e,sections:e.sections.map(o=>({...o,nodes:o.nodes.filter(n=>n!==s)}))}:e}function jn(e,s,o){return e.sections?{...e,sections:e.sections.map(n=>({...n,nodes:n.nodes.map(a=>a===s?o:a)}))}:e}function Zt(e,s,o){if(!e.sections)return e;const n=new Set(o);return{...e,sections:e.sections.map(a=>{const l=a.nodes.filter(c=>!n.has(c));return a.id===s?{...a,nodes:[...new Set([...l,...o])]}:{...a,nodes:l}})}}function yn(e,s){return(e.sections??[]).filter(o=>o.nodes.includes(s)).map(o=>o.id)}function go(e,s){const o=new TextEncoder;if(o.encode(e).length<=s)return e;let n="",a=0;for(const l of e){const c=o.encode(l).length;if(a+c>s)break;n+=l,a+=c}return n}function Qt(e){const s={...e};return e.notes&&(s.notes=e.notes.slice(0,wn).map(o=>({...o,content:go(o.content,xn)}))),e.sections&&(s.sections=e.sections.slice(0,gn)),s}function xo(e,s,o){const n={};for(const c of[...e.notes??[],...e.sections??[]])n[c.id]={position:c.position,size:c.size};const a=(c,f)=>c==null?void 0:c.map(p=>{const g=f==null?void 0:f.find(x=>x.id===p.id);return g?{...p,position:g.position,size:g.size}:p}),l=o?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 bn(l,o,n)}const Xs=220;function bo(e){return e.length<=Xs?{text:e,clipped:!1,length:e.length}:{text:e.slice(0,Xs).trimEnd(),clipped:!0,length:e.length}}function jo({params:e,values:s,testStartState:o,view:n="props",literalKeys:a}){const{sampleValues:l,nodeConfig:c,nodeMeta:f}=i.useExpressionOptions(),p=d.useMemo(()=>i.buildResolveScope(l,o,c,f),[l,o,c,f]),g=i.flattenParams(e),x=S=>{var R;return s[S]!==void 0?s[S]:(R=g.find(A=>A.key===S))==null?void 0:R.default},h=g.filter(S=>S.type!=="section"&&i.isParamVisible(S,x)).map(S=>be.effectiveParam(S,x));if(i.hasParamCustomization(s)){const S=i.previewCustomization(s.$merge,p,a),R=S!==null&&typeof S=="object"&&!Array.isArray(S),A=Ys(h,s,p,a);for(const[m,P]of Object.entries(s))m!=="$merge"&&(A[m]=a!=null&&a.includes(m)?P:i.previewCustomization(P,p));const D=R?{...A,...S}:A;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(S)}). Test the step to validate it.`}),n==="code"?t.jsx(i.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,P])=>{var O;return t.jsx(es,{label:((O=g.find(J=>J.key===m))==null?void 0:O.label)??m,segments:[{status:"resolved",value:P}]},m)})})]})}if(n==="code"){const S=Ys(h,s,p,a);return t.jsx("div",{className:"w6w-resolved-params",children:t.jsx(i.JsonEditor,{value:JSON.stringify(S,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"})})}const v=h.filter(S=>!i.deepEqual(x(S.key),S.default));return h.length===0?t.jsx("div",{className:"w6w-resolved-params",children:t.jsx("p",{className:"w6w-muted w6w-small",children:"This action takes no parameters."})}):v.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:v.map(S=>S.type==="vars"?t.jsx(yo,{param:S,value:s[S.key],scope:p},S.key):t.jsx(es,{label:S.label??S.key,segments:a!=null&&a.includes(S.key)?[{status:"resolved",value:x(S.key)}]:i.resolveParamValue(x(S.key),p)},S.key))})}function Ys(e,s,o,n){const a={};for(const l of e)if(n!=null&&n.includes(l.key))a[l.key]=s[l.key]!==void 0?s[l.key]:l.default;else if(l.type==="vars"){const c=s[l.key]??l.default??[],f=i.dataVarRows(c);a[l.key]=f?i.resolveVarsJson(f,o):i.resolveParamJson(c,o)}else a[l.key]=i.resolveParamJson(s[l.key]!==void 0?s[l.key]:l.default,o);return a}function es({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(vn,{segments:s})})]})}function yo({param:e,value:s,scope:o}){const n=s??e.default??[],a=i.dataVarRows(n);return a===null?t.jsx(es,{label:e.label??e.key,segments:i.resolveParamValue(n,o)}):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((l,c)=>t.jsxs("div",{className:"w6w-resolved-value",children:[t.jsx("code",{children:l.key||"(no key)"})," → ",t.jsx(vn,{segments:i.resolveParamValue(l.value,o)})]},c))})]})}function vn({segments:e}){return t.jsx(t.Fragment,{children:e.map((s,o)=>t.jsx(vo,{segment:s},o))})}function vo({segment:e}){switch(e.status){case"resolved":return e.ref?t.jsxs(t.Fragment,{children:[t.jsx(pt,{kind:"var",refName:e.ref}),t.jsx(Zs,{value:e.value})]}):t.jsx(Zs,{value:e.value});case"unresolved":return t.jsxs(t.Fragment,{children:[t.jsx(pt,{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(pt,{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(pt,{kind:"expr"}),t.jsx("span",{className:"w6w-param-unevaluated",children:"not evaluated"})]});case"masked":return t.jsx(pt,{kind:"secret",refName:e.ref})}}function Zs({value:e}){const[s,o]=d.useState(!1),n=Co(e),a=bo(n);return a.clipped?t.jsxs(t.Fragment,{children:[s?t.jsx(ke.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:()=>o(l=>!l),children:s?"Show less":`Show all (${a.length.toLocaleString()} characters)`})]}):t.jsx("span",{children:n})}const So={var:"◆",secret:"🔒",expr:"ƒ"};function pt({kind:e,refName:s}){const o=e==="expr"?"expr":i.varLabel(s??"");return t.jsxs("span",{className:`w6w-expr-chip w6w-expr-chip-${e}`,children:[t.jsx("span",{className:"w6w-expr-chip-sigil",children:So[e]}),t.jsx("span",{className:"w6w-expr-chip-label",children:o})]})}function Co(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 Sn(e){return e.language==="python"||e.language==="typescript"?e.language:"javascript"}function No({enabled:e,values:s,onChange:o}){const[n,a]=d.useState(null),l=d.useRef(!1),c=typeof s.code=="string"?s.code:"";return d.useEffect(()=>{if(!e||l.current)return;l.current=!0;const f=i.convertCodeBindingsToReads(c,Sn(s));f.converted!==0&&(a({original:c,converted:f.converted}),o({...s,code:f.code}))},[e,c,s,o]),n?{converted:n.converted,undo:()=>{o({...s,code:n.original}),a(null)}}:null}function ko({values:e,conversion:s,readOnly:o}){const n=typeof e.code=="string"?e.code:"",a=s,l=i.findCodeBindings(n,Sn(e)).length;return!a&&l===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",!o&&t.jsxs(t.Fragment,{children:[" · ",t.jsx("button",{type:"button",className:"w6w-script-converted-undo",onClick:a.undo,children:"Undo"})]}),l>0&&" · "]}),l>0&&t.jsxs(t.Fragment,{children:[l," ",t.jsx("code",{children:"{{ }}"})," left in the code stay",l===1?"s":""," literal text — read ",l===1?"it":"them"," from"," ",t.jsx("code",{children:"state"}),", or bind under Custom input"]})]})}function Qs(e,s){return{nodeIds:e.filter(o=>o.selected).map(o=>o.id),edgeIds:s.filter(o=>o.selected).map(o=>o.id)}}function Eo(e,s,o,n){const a=new Set(e.nodeIds),l=new Set(e.edgeIds),c=s.filter(h=>a.has(h.id)),f=[...c.filter(h=>i.isForeachStep(h.data.step)),...c.filter(h=>!i.isForeachStep(h.data.step))];let p=s,g=o,x=n;for(const h of f)g=i.bridgeDeletedBodyStep(h.id,p,g),p=p.filter(v=>v.id!==h.id),x=os(x,h.id);return{nodes:p,edges:g.filter(h=>!l.has(h.id)),canvas:x}}function Ao(e,s,o){var f;const n=new Set(e.nodeIds),a=new Set(e.edgeIds),l=o.filter(p=>a.has(p.id)&&!n.has(p.source)&&!n.has(p.target)),c=[];if(n.size===1)c.push(i.deleteStepMessage(e.nodeIds[0],s,o));else if(n.size>1){c.push(`Delete nodes ${[...n].map(g=>`"${g}"`).join(", ")}? Their connections are removed too.`);const p=new Set;for(const g of n)if(i.isForeachStep((f=s.find(x=>x.id===g))==null?void 0:f.data.step))for(const x of i.loopBody(g,s,o))n.has(x)||p.add(x);p.size&&c.push(`Loop body steps ${[...p].map(g=>`"${g}"`).join(", ")} stay as standalone steps.`)}return l.length&&c.push(`Delete ${l.length===1?"connection":"connections"} ${l.map(p=>`"${p.source} → ${p.target}"`).join(", ")}?`),c.join(" ")}function To(e,s){const o={success:0,error:0};for(const a of s){if(a.source!==e)continue;const l=i.edgeLane(a);l!=="each"&&o[l]++}const n=Math.max(o.success,o.error);return{enabled:n>=2,count:n}}function Po(e,s){const{fanOut:o,...n}=e;return s==="parallel"?{...n,fanOut:"parallel"}:n}function Io(e,s){return`Runs these ${e} nodes in ${s==="parallel"?"parallel":"sequence"}`}function Mt(e,s,o,n,a){const l=i.flowToWorkflow({...e,connections:n},s,o);return{nodes:l.nodes.map(({with:c,...f})=>c&&Object.keys(c).length?{...f,with:c}:f),edges:l.edges??[],connections:l.connections??{},canvas:a,positions:Object.fromEntries(s.map(c=>[c.id,c.position]))}}function Ro(e,s){const o=i.workflowToFlow({...e,...s});return{...o,nodes:o.nodes.map(n=>({...n,position:s.positions[n.id]??n.position}))}}class Mo{constructor(s,o=100){it(this,"past",[]);it(this,"future",[]);it(this,"present");it(this,"group");it(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(e){var o;const s=e;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 Lo=64,ft=24,Ye=32;function Lt(e){var s,o;return{width:((s=e.measured)==null?void 0:s.width)??e.width??200,height:((o=e.measured)==null?void 0:o.height)??e.height??64}}function Fo(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 Do(e){const s=(a,l)=>{const c=new Map;for(const g of e){const x=g.position[a];c.set(x,Math.max(c.get(x)??0,Lt(g)[l]))}const f=new Map;let p=Number.NEGATIVE_INFINITY;for(const[g,x]of[...c].sort(([h],[v])=>h-v)){const h=Math.max(g,p);f.set(g,h),p=h+x+Lo}return f},o=s("x","width"),n=s("y","height");return e.map(a=>({...a,position:{x:o.get(a.position.x)??a.position.x,y:n.get(a.position.y)??a.position.y}}))}function Oo(e,s,o){var f;const n=Do(i.relayoutNodes(e,s));if(!((f=o.sections)!=null&&f.length))return{nodes:n,canvas:o};const a=new Map(n.map(p=>[p.id,p])),l=(o.notes??[]).map(p=>({...p.position,...p.size}));for(const p of o.sections)p.nodes.some(g=>a.has(g))||l.push({...p.position,...p.size,y:p.position.y-Ye,height:p.size.height+Ye});const c=o.sections.map(p=>{const g=new Set(p.nodes),x=n.filter(P=>g.has(P.id));if(!x.length)return p;const h=Math.min(...x.map(P=>P.position.x))-ft,v=Math.min(...x.map(P=>P.position.y))-ft,S=Math.max(...x.map(P=>P.position.x+Lt(P).width)),R=Math.max(...x.map(P=>P.position.y+Lt(P).height)),A={x:h,y:v,width:S+ft-h,height:R+ft-v},D=[...l,...[...a.values()].filter(P=>!g.has(P.id)).map(P=>({...P.position,...Lt(P)}))].sort((P,O)=>P.y-O.y);for(const P of D){const O={...A,y:A.y-Ye,height:A.height+Ye};Fo(O,P)&&(A.y=P.y+P.height+ft+Ye)}const m=A.y-v;for(const P of x)a.set(P.id,{...P,position:{x:P.position.x,y:P.position.y+m}});return l.push({...A,y:A.y-Ye,height:A.height+Ye}),{...p,position:{x:A.x,y:A.y},size:{width:A.width,height:A.height}}});return{nodes:n.map(p=>a.get(p.id)??p),canvas:{...o,sections:c}}}const Gt=6;function _o(e){let s=2166136261;for(let o=0;o<e.length;o++)s^=e.charCodeAt(o),s=Math.imul(s,16777619);return s>>>0}function Wo(e){const s=new Map;let o=new Set;for(const n of[...new Set(e)].sort()){o.size===Gt&&(o=new Set);let a=_o(n)%Gt;for(;o.has(a);)a=(a+1)%Gt;o.add(a),s.set(n,a+1)}return s}function is(e){return`var(--w6w-loop-${e})`}function Cn(e,s){const o=[],n=new Set([e]);for(let a=s.get(e);a&&!n.has(a);a=s.get(a))n.add(a),o.unshift(a);return o}function $o(e,s,o){return s.size===0?e:e.map(n=>{var c;if(((c=n.data)==null?void 0:c.when)!=="each")return n;const a=n.sourceHandle===i.EACH_SOURCE_HANDLE?n.source:o.get(n.source),l=a?s.get(a):void 0;return l===void 0?n:{...n,style:{...n.style,"--w6w-loop-color":is(l)}}})}function Bo(e,s){const o=s.get(e);return o===void 0?void 0:{"--w6w-loop-color":is(o)}}function Vo(e){const s=[];for(const o of e){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 zo(e){const s=JSON.parse(e);return{tones:Wo(s.filter(o=>o[1]===1).map(o=>o[0])),loopOf:new Map(s.map(o=>[o[0],o[2]]))}}const en="Paused — test runs stop before this node",tn="Disabled — skipped in every run";function Ze(e){var s;return((s=e.ui)==null?void 0:s.paused)===!0}function De(e){return e.disabled===!0}function Nn(e,s){const{ui:o,...n}=e,{paused:a,...l}=o??{},c=s?{...l,paused:!0}:l;return Object.keys(c).length>0?{...n,ui:c}:n}function kn(e,s){const{disabled:o,...n}=e;return s?{...n,disabled:!0}:n}function ts(e,s){return e.filter(o=>o.id!==s&&Ze(o)).map(o=>o.id)}const Ho=["nodes","steps"];function sn(e,s){for(const o of Ho){const n=`${o}.${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,o){if(typeof e=="string"){if(!e.includes("{{"))return e;const n=i.parseRootAnchoredTemplate(e);let a=!1;const l=n.map(c=>{if(c.kind!=="var"||c.ref===void 0)return c;const f=sn(c.ref,s);return f===null?c:(a=!0,o.includes(c.ref)||o.push(c.ref),{...c,ref:f})});return a?be.serializeTemplate(l):e}if(i.isDollarPath(e)){const n=e.$;if(typeof n!="string")return e;const a=sn(n,s);return a===null?e:(o.includes(n)||o.push(n),{$:a})}if(Array.isArray(e)){let n=!1;const a=e.map(l=>{const c=Ft(l,s,o);return c!==l&&(n=!0),c});return n?a:e}if(typeof e=="object"&&e!==null){let n=!1;const a={};for(const[l,c]of Object.entries(e)){const f=Ft(c,s,o);f!==c&&(n=!0),a[l]=f}return n?a:e}return e}function Jo(e){if(typeof e=="string"){if(!e.includes("{{"))return!1;const s=i.parseRootAnchoredTemplate(e);return s.length===1&&s[0].kind==="var"}return i.isDollarPath(e)&&typeof e.$=="string"}function En(e){return Array.isArray(e)&&e.length===1&&Jo(e[0])}function Uo(e){var s;try{const o=i.normalizeInput(e);if(!Array.isArray(o.nodes))return{};const n={},a=(c,f)=>{const p=Object.hasOwn(n,c)?n[c]:[];p.push(f),n[c]=p},l=new Map(o.nodes.map(c=>[c.id,c]));for(const[c,f]of Object.entries(i.definitionLoops(o))){const p=l.get(c);if(p&&En((s=p.with)==null?void 0:s.items)&&a(c,{code:"foreach_wrapped_items",fix:{kind:"unwrap_items",label:"Unwrap Items"}}),"invalid"in f){a(c,{code:"loop_body_invalid",reason:{...f.invalid}});continue}for(const g of f.body){const x=l.get(g);if(!(x!=null&&x.with))continue;const h=[];Ft(x.with,c,h),h.length>0&&a(g,{code:"foreach_body_refs_output",foreachId:c,refs:h,fix:{kind:"use_current_item",foreachId:c,label:"Use Current item"}})}}return n}catch{return{}}}function qo(e){const s=new Set,o=n=>{if(typeof n=="string")s.add(n);else if(Array.isArray(n))for(const a of n)o(a)};return o(e),s}function Go(e){var s,o;try{const n=i.normalizeInput(e);if(!Array.isArray(n.nodes))return[];const a=n.nodes.filter(I=>typeof I=="object"&&I!==null&&typeof I.id=="string"),l=i.effectiveEdges({...n,nodes:a}).filter(I=>typeof(I==null?void 0:I.from)=="string"&&typeof(I==null?void 0:I.to)=="string"),c=[];for(const I of a)try{const M=be.staticWritePaths(be.effectiveStateConfig((s=I.uses)==null?void 0:s.app,(o=I.uses)==null?void 0:o.action,I.state));M.length>0&&c.push({id:I.id,paths:M})}catch{}if(c.length<2)return[];const f=new Map;for(const I of a)for(const M of i.controlOwnedIds(I))f.has(M)||f.set(M,I.id);const p=I=>{const M=[I];let C=I;for(;f.has(C)&&(C=f.get(C),!M.includes(C));)M.push(C);return M},g=I=>{const M=p(I);return M[M.length-1]},x=new Map;for(const I of l){const M=x.get(I.from)??[];M.push(I.to),x.set(I.from,M)}const h=new Map,v=I=>{const M=h.get(I);if(M)return M;const C=new Set,$=[...x.get(I)??[]];for(;$.length>0;){const q=$.pop();if(!C.has(q)){C.add(q);for(const B of x.get(q)??[])$.push(B)}}return h.set(I,C),C},S=(I,M)=>I===M||v(I).has(M),R=a.filter(I=>{var M;return((M=I.uses)==null?void 0:M.app)===i.CONTROL_APP&&I.uses.action==="parallel"}).map(I=>{var C;const M=(C=I.with)==null?void 0:C.branches;return Array.isArray(M)?M.map(qo):[]}),A=(I,M)=>{for(const C of p(M)){const $=I.findIndex(q=>q.has(C));if($>=0)return $}return-1},D=[];for(const I of a){if(I.fanOut!=="parallel")continue;const M=new Map;for(const C of l){if(C.from!==I.id||i.isEachLink(C))continue;const $=C.when??"success",q=M.get($)??[];q.push(C.to),M.set($,q)}for(const C of M.values())C.length>=2&&D.push(C)}const m=(I,M)=>{for(const q of R){const B=A(q,I),b=A(q,M);if(B>=0&&b>=0&&B!==b)return!0}const C=g(I),$=g(M);return C===$||v(C).has($)||v($).has(C)?!1:D.some(q=>q.some((B,b)=>q.some((W,de)=>b!==de&&S(B,C)&&S(W,$))))},P=new Set,O=[];for(let I=0;I<c.length;I++)for(let M=I+1;M<c.length;M++){const C=c[I],$=c[M];if(!(C.id===$.id||!m(C.id,$.id)))for(const q of C.paths)for(const B of $.paths){if(!be.statePathsOverlap(q,B))continue;const b={code:"state_parallel_write",nodes:[C.id,$.id].sort(),path:[...q.length<=B.length?q:B]},W=JSON.stringify([b.nodes,b.path]);P.has(W)||(P.add(W),O.push(b))}}const J=(I,M)=>I<M?-1:I>M?1:0;return O.sort((I,M)=>J(I.code,M.code)||J(I.nodes.join(","),M.nodes.join(","))||J(I.path.join("."),M.path.join(".")))}catch{return[]}}function Ko(e){try{const s={};for(const o of Go(e))for(const n of o.nodes){const a=Object.hasOwn(s,n)?s[n]:[];a.push({code:o.code,path:[...o.path],with:o.nodes.filter(l=>l!==n)}),s[n]=a}return s}catch{return{}}}function An(e,s){var o;if(s.code==="foreach_wrapped_items"){const n=(o=e.with)==null?void 0:o.items;return!e.with||!En(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 nn(e,s,o){return e&&e.nodeId===s&&e.handleType===((o==null?void 0:o.type)??"source")?i.laneForSourceHandle(e.handleId):i.laneForSourceHandle(o==null?void 0:o.id)}function Xo(e,s,o,n,a){var p;const l=(p=n.find(g=>g.id===e))==null?void 0:p.data.step,c=i.loopMembership(n,a)[e]!==void 0,f=o==="success"&&c?"each":o;return f==="each"&&!c&&!i.isForeachStep(l)?null:i.loopRefusal(e,s,f,n,a)}const Yo=["off","root","key","pick","append"],Zo={off:"Off",root:"Merge at root",key:"Under a key",pick:"Pick fields",append:"Append"};function Qo(e){return be.effectiveStateConfig(e.uses.app,e.uses.action,e.state)}function ei(e,s){return JSON.stringify(e)===JSON.stringify(s)}function ti(e,s){const{state:o,...n}=e,a=be.effectiveStateConfig(e.uses.app,e.uses.action,void 0);return ei(s,a)?n:{...n,state:s}}function si(e,s){switch(s){case"key":return{mode:"key",key:e.id};case"pick":return{mode:"pick",map:[{from:"",to:e.id}]};case"append":return{mode:"append",path:e.id};case"root":return{mode:"root"};default:return{mode:"off"}}}function ni(e){return!i.isControlApp(e.uses.app)}function Dt(e,s){var o;return(o=e.nodes??e.steps)==null?void 0:o[s]}function ss(e,s){const o=Dt(e,s);return(o==null?void 0:o.status)==="skipped"&&o.skipReason==="not_on_path"}const oi=new Set(["succeeded","failed","canceled"]);function ii(e,s,o=[]){var l,c;if(!e||[...o,s].some(f=>ss(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 g=(c=(l=p==null?void 0:p.nodes)==null?void 0:l[s])==null?void 0:c.status;g&&a.add(g)}for(const f of["failed","running","succeeded","skipped"])if(a.has(f))return f;return"pending"}const on={borderColor:"var(--w6w-border)",borderStyle:"solid",borderWidth:1,opacity:1};function Tn(e,s){const o=s!==void 0&&oi.has(s);switch(e){case"no-run":return on;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 on}}function ri(e,s,o,n,a){var c;if(!e||ss(e,s)||a!==void 0&&ss(e,a))return;const l=ai(e,s,o,n);return l==="taken"&&a!==void 0&&((c=Dt(e,a))==null?void 0:c.status)==="skipped"?"skipped":l}function ai(e,s,o,n){const a=Dt(e,s);if(!a)return;if(o==="each")return a.status==="skipped"?"skipped":void 0;const l=o??"success",c=a.output,f=n===i.FOREACH_DONE_ROUTE&&!(c&&typeof c=="object"&&"route"in c);if(n!==void 0&&!f&&a.status==="succeeded")return c&&typeof c=="object"&&"matched"in c?n==="false"!=(c.matched===!0)?"taken":"skipped":c&&typeof c=="object"&&"route"in c&&c.route===n?"taken":"skipped";if(a.status==="succeeded")return l==="success"?"taken":"skipped";if(a.status==="failed")return l==="error"?"taken":"skipped";if(a.status==="skipped")return"skipped"}const rn={fields:[],sampleValues:{}};function rs(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function ci(e,s){var g;const o=e.map(x=>x.id),n=new Set(o),a=new Map(o.map(x=>[x,0])),l=new Map(o.map(x=>[x,[]]));for(const x of s)!n.has(x.source)||!n.has(x.target)||((g=l.get(x.source))==null||g.push(x.target),a.set(x.target,(a.get(x.target)??0)+1));const c=[],f=o.filter(x=>a.get(x)===0);for(;f.length>0;){const x=f.shift();c.push(x);for(const h of l.get(x)??[]){const v=(a.get(h)??0)-1;a.set(h,v),v===0&&f.push(h)}}const p=new Set(c);for(const x of o)p.has(x)||c.push(x);return c}const li=new Set(["string","number","boolean","object","array"]);function ht(e){if(!Array.isArray(e))return;const s={type:"object",fields:{}};let o=!1;for(const n of e){if(!rs(n)||typeof n.key!="string"||n.key==="")continue;const a=n.key.split(".");let l=s;for(const p of a.slice(0,-1)){const g=l.fields[p];(g==null?void 0:g.type)!=="object"&&(l.fields[p]={type:"object",fields:{}}),l=l.fields[p]}const c=typeof n.type=="string"&&li.has(n.type)?n.type:"string";let f;if(c==="array"){const p=ht(n.items);f=p?{type:"array",items:p}:{type:"array"}}else c==="object"?f=ht(n.fields??n.properties)??{type:"object",fields:{}}:f={type:c};l.fields[a[a.length-1]]=f,o=!0}return o?s:void 0}function di(e,s){var g,x,h,v,S,R,A;const o=e.data.step,n=((g=s.testOutputs)==null?void 0:g[o.id])??((x=s.persistedOutputs)==null?void 0:x[o.id]);if(n!=null)return n;const{app:a,action:l}=o.uses;if(a===i.TRIGGER_APP&&((h=i.internalNodeDef(a,l))==null?void 0:h.group)==="trigger"){const D=i.fieldsToParams(i.asFieldDefs((v=o.with)==null?void 0:v.fields)).map(m=>({key:m.key}));return i.shapeToSkeleton(ht(D))}const c=(S=i.internalNodeDef(a,l))==null?void 0:S.output;if(c&&c.length>0)return i.shapeToSkeleton(ht(c));const f=o.uses.trigger===!0?(R=s.triggerDef)==null?void 0:R.call(s,a,l):(A=s.actionDef)==null?void 0:A.call(s,a,l),p=ht(f==null?void 0:f.output);return p?i.shapeToSkeleton(p):f==null?void 0:f.sample}function ui(e,s){var f,p,g,x,h;const o=e.data.step,n=(f=s.previewOutputs)==null?void 0:f[o.id];if(n!=null)return n;const{app:a,action:l}=o.uses,c=o.uses.trigger===!0?(g=(p=s.shapes)==null?void 0:p.triggerDef)==null?void 0:g.call(p,a,l):(h=(x=s.shapes)==null?void 0:x.actionDef)==null?void 0:h.call(x,a,l);return c==null?void 0:c.sample}function pi(e){switch(e){case"number":case"integer":return 0;case"boolean":return!1;case"object":return{};case"array":return[];default:return""}}function an(e,s){const o=rs(e.initialState)?{...e.initialState}:{};for(const n of e.variables??[])!n||typeof n.key!="string"||n.key===""||(n.default!==void 0?o[n.key]=n.default:s||(o[n.key]=pi(n.type)));return o}function Kt(e){return(i.inferOutputFields(e)??[]).map(s=>s.key)}function fi(e){const{anchorId:s,nodes:o,edges:n}=e;if(!s)return rn;const a=e.shapes??{},l=e.floating?new Set(o.map(C=>C.id)):i.ancestorIds(s,n);l.delete(s);const c=new Map(o.map(C=>[C.id,C])),f=[],p=[],g=new Map;for(const C of ci(o,n)){if(!l.has(C))continue;const $=c.get(C);if(!$)continue;const{app:q,action:B}=$.data.step.uses,b=be.effectiveStateConfig(q,B,$.data.step.state);if(b.mode==="off")continue;const W=di($,a);if(W!==void 0){const{ops:ue}=be.computeStateWrites(b,W);f.push(...ue);for(const je of Kt(be.foldState({},ue))){const ie=g.get(je)??new Set;ie.add(C),g.set(je,ie)}}const de=ui($,e);de!==void 0&&p.push(...be.computeStateWrites(b,de).ops)}const x=an(e,!1),h=be.foldState(x,f),v=Kt(h);if(v.length===0)return rn;const S=new Set(Kt(x)),R=new Map,A=new Map;for(const C of n)l.has(C.source)&&(!l.has(C.target)&&C.target!==s||(R.set(C.target,[...R.get(C.target)??[],C.source]),A.set(C.source,[...A.get(C.source)??[],C.target])));const D=[...l].filter(C=>!(R.get(C)??[]).length),m=C=>{const $=new Set,q=D.filter(B=>!C.has(B));for(;q.length>0;){const B=q.pop();if(B===s)return!1;if(!$.has(B)){$.add(B);for(const b of A.get(B)??[])C.has(b)||q.push(b)}}return!0},P=be.foldState(an(e,!0),p),O=p.length>0?be.foldState({},p):void 0,J=rs(O)&&Object.keys(O).length>0?O:void 0,I=[],M={};for(const C of v){const $=g.get(C)??new Set,q=S.has(C)||$.size>0&&m($);I.push({key:C,path:!0,paths:q?"all":"some"});const B=i.valueAtPath(P,C);B!==void 0&&(M[`state.${C}`]=B)}return{fields:I,sampleValues:M,...J?{written:J}:{}}}const hi={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"}},cn="Never fired";function mi(e){if(!e)return cn;const s=new Date(e);return Number.isNaN(s.getTime())?cn:`Last fired ${s.toISOString().slice(0,16).replace("T"," ")} UTC`}function wi(e,s){var a;if(!(e!=null&&e.status))return null;const o=hi[e.status];if(!o)return null;const n=e.status==="failed";return{label:o.label,tone:o.tone,error:n?((a=e.lastError)==null?void 0:a.message)??null:null,lastFire:mi(e.lastFireAt),retryVisible:n&&s}}function gi(e){const s=new Map;for(const o of e)o.nodeId&&s.set(o.nodeId,o);return s}function xi(e){return(e??[]).filter(s=>{var o;return((o=s.uses)==null?void 0:o.trigger)===!0})}function bi(e,s){const[o,n]=d.useState({}),a=d.useRef(new Set),l=JSON.stringify([...new Set(s.map(c=>c.data.step.uses.app))].filter(c=>c&&!i.isInternalApp(c)).sort());return d.useEffect(()=>{const c=JSON.parse(l).filter(f=>!a.current.has(f));if(c.length!==0){for(const f of c)a.current.add(f);Promise.all(c.map(async f=>{try{return[f,await e.getAppActions(f)]}catch{return a.current.delete(f),null}})).then(f=>{const p=f.filter(g=>g!==null);p.length!==0&&n(g=>({...g,...Object.fromEntries(p)}))})}},[e,l]),o}function ji(e,s){const[o,n]=d.useState({}),a=d.useRef(new Set),l=JSON.stringify([...new Set(s.filter(c=>c.data.step.uses.trigger===!0).map(c=>c.data.step.uses.app))].filter(c=>c&&!i.isInternalApp(c)).sort());return d.useEffect(()=>{const c=e.getAppTriggers;if(typeof c!="function")return;const f=JSON.parse(l).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 c.call(e,p)]}catch{return a.current.delete(p),null}})).then(p=>{const g=p.filter(x=>x!==null);g.length!==0&&n(x=>({...x,...Object.fromEntries(g)}))})}},[e,l]),o}function yi(e){return(s,o)=>{var n,a;return(a=(n=e[s])==null?void 0:n.find(l=>l.key===o))==null?void 0:a.ports}}const vi="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 ln(e,s,o,n){const a=e.find(l=>l.id===s);return[o,n,a==null?void 0:a.source,a==null?void 0:a.target]}const as=d.createContext(void 0),cs=d.createContext(new Map),ls=d.createContext({tones:new Map,loopOf:new Map});function dn(e){return`Can’t draw that edge: this node allows at most ${e} outgoing edge${e===1?"":"s"} per lane.`}const ds=d.createContext(new Map),Pn=d.createContext({byNode:new Map,subs:[]});function Si({apps:e,registration:s,children:o}){return t.jsx(ds.Provider,{value:e,children:t.jsx(Pn.Provider,{value:s,children:o})})}const us=d.createContext(null);function Ci(e){return t.jsx(oe.ReactFlowProvider,{children:t.jsx(Ni,{...e})})}function un(e,s){let o=s.length+1;for(;s.includes(`${e}-${o}`);)o++;return`${e}-${o}`}function Xt(e){var s,o;return{x:e.position.x,y:e.position.y,w:((s=e.measured)==null?void 0:s.width)??e.width??200,h:((o=e.measured)==null?void 0:o.height)??e.height??64}}function Ni({onConnectionResourcesChange:e,value:s,onChange:o,readOnly:n,height:a=480,apps:l,exprOptions:c,project:f,runState:p,stepProblems:g,onTestRun:x,fitViewKey:h,onRunFromNode:v}){var Vs,zs,Hs,Js,Us,qs,Gs;const S=i.useW6WApi(),R=d.useMemo(()=>new Map((l??[]).map(r=>[r.id,r])),[l]),A=Ri(s),[D,m]=d.useState(null),P=d.useMemo(()=>i.centralizeConnections(s),[s.id]),O=d.useMemo(()=>i.workflowToFlow(P),[P]),[J,I]=d.useState(P.connections??{}),M=d.useRef(J),C=d.useCallback(r=>{M.current=r,I(r)},[]),$=d.useCallback(r=>{const u=i.centralizeConnections({nodes:[r],connections:M.current});return u.connections!==M.current&&C(u.connections),u.nodes[0]},[C]),q=d.useMemo(()=>i.storedViewport(s),[s.id]),B=((Vs=s.settings)==null?void 0:Vs.savePosition)!==!1,[b,W,de]=oe.useNodesState(O.nodes),ue=bi(S,b),je=ji(S,b),ie=d.useMemo(()=>yi(ue),[ue]),[k,X,E]=oe.useEdgesState(O.edges),[_,V]=d.useState(null),ee=d.useMemo(()=>s.canvas??{},[s.id]),[U,z]=d.useState(ee),[H]=d.useState(()=>new Mo(Mt(P,O.nodes,O.edges,J,ee))),Z=d.useRef(),[pe,ze]=d.useState(0),[Le,rt]=d.useState(!1),[ye,Je]=d.useState(null),[Ee,he]=d.useState(null),[ce,Ce]=d.useState(null),[Oe,te]=d.useState(!1),mt=d.useRef({});d.useEffect(()=>{Oe||(mt.current={})},[Oe]);const[ae,Ae]=d.useState(null),[Fe,Ne]=d.useState("props"),[xe,Ue]=d.useState(null),[Te,He]=d.useState(null),[Pe,Ie]=d.useState(null),at=d.useRef(!1),ve=d.useRef(null),[we,_e]=d.useState(null),{screenToFlowPosition:Re,fitView:Me}=oe.useReactFlow(),ct=i.useEffectiveTheme();d.useEffect(()=>{W(O.nodes),X(O.edges),V(null),Ce(null),Ie(null),Ae(null),Ue(null),z(ee),C(P.connections??{}),H.reset(Mt(P,O.nodes,O.edges,P.connections??{},ee)),Z.current=void 0},[O,ee,P,W,X,C,H]),d.useEffect(()=>{W(r=>{const u=new Map(i.stampLoopOf(r,k).map(w=>[w.id,w.data.loopOf]));return r.map(w=>{const j=ii(p,w.id,Cn(w.id,u));return w.data.stepStatus===j&&w.data.runStatus===(p==null?void 0:p.status)?w:{...w,data:{...w.data,stepStatus:j,runStatus:p==null?void 0:p.status}}})}),X(r=>r.map(u=>{var T;const w=i.edgeLane(u),j=ri(p,u.source,w,typeof((T=u.data)==null?void 0:T.route)=="string"?u.data.route:void 0,u.target),y=i.edgeVisuals(w,j);return u.className===y.className&&u.label===y.label?u:{...u,className:y.className,label:y.label}}))},[p,O,pe,W,X]),d.useEffect(()=>{W(r=>i.applyStepProblems(r,g))},[g,O,pe,W]);const Qe=d.useCallback((r,u)=>{var y,T;const{canvas:w,...j}=r;return!((y=u.notes)!=null&&y.length)&&!((T=u.sections)!=null&&T.length)?j:{...j,canvas:xo(u,s.canvas,B)}},[s.canvas,B]),Q=d.useCallback((r,u,w)=>{H.record(Mt(s,r,u,M.current,w??U),Oe?mt.current:Z.current),o(Qe(i.flowToWorkflow({...s,connections:M.current},r,u),w??U))},[s,o,U,Qe,H,Oe]),et=d.useRef(()=>{});et.current=r=>{if(n)return;const u=i.editConnectionResources(b.map(j=>j.data.step),M.current,r),w=b.map((j,y)=>({...j,data:{...j.data,step:u.nodes[y]}}));C(u.connections),W(w),Q(w,k)};const qe=d.useCallback(r=>et.current(r),[]),wt=d.useCallback(r=>{V(r),Ce(null),W(u=>u.map(w=>({...w,selected:w.id===r}))),X(u=>u.map(w=>({...w,selected:!1}))),Me({nodes:[{id:r}],duration:300,maxZoom:1})},[W,X,Me]),[lt,le]=d.useState(null),gt=d.useMemo(()=>lt?b.map(r=>r.id===lt?{...r,className:`${r.className??""} w6w-connection-highlight`.trim()}:r):b,[b,lt]),xt=b.map(r=>({id:r.data.step.id,uses:r.data.step.uses})),bt=JSON.stringify(xt),jt=JSON.stringify([...R]);d.useEffect(()=>{e==null||e({workflowId:s.id,nodes:xt,apps:R,connections:J,readOnly:n,edit:qe,focusNode:wt,highlightNode:le})},[e,s.id,bt,jt,J,n,qe,wt]),d.useEffect(()=>()=>e==null?void 0:e(null),[e]);const yt=d.useCallback(r=>i.canConnect(r.source,r.target,b,k,ie,i.routeFromHandle(r.sourceHandle)),[b,k,ie]),[N,G]=d.useState(null),se=d.useRef(null),fe=d.useRef(null);d.useEffect(()=>{W(r=>i.stampLoopOf(r,k))},[k,W]);const tt=d.useCallback(r=>{if(n)return;const u=i.applyConnect(r.source,r.target,b,k,i.laneForSourceHandle(r.sourceHandle),ie,i.routeFromHandle(r.sourceHandle));if(!u){const w=i.laneForSourceHandle(r.sourceHandle),j=i.connectRefusal(r.source,r.target,b,k,w,ie,i.routeFromHandle(r.sourceHandle));if(j&&j.refused==="loop"){G({nodeId:r.source,reason:j.reason});return}if(j){const T=k.find(F=>F.source===r.source&&i.edgeLane(F)===w);T&&(X(k.map(F=>({...F,selected:F.id===T.id}))),Ce(T.id),Ge({edgeId:T.id,message:dn(j.cap)}));return}const y=i.connectConflict(r.source,r.target,b,k,i.laneForSourceHandle(r.sourceHandle));if(!y)return;X(k.map(T=>({...T,selected:T.id===y}))),Ce(y),Ge({edgeId:y,message:i.idClashMessage("Can’t draw that edge",y,ln(k,y,r.source,r.target))});return}Ge(null),G(null),X(u),Q(b,u)},[k,b,X,Q,n,ie]),Bn=d.useCallback((r,u)=>{var K,Y,ne;if(n||u.isValid)return;const w=u.fromNode;if(!w)return;const j=((K=u.fromHandle)==null?void 0:K.type)==="target"?"target":"source",y=u.toNode;if(y&&j==="source"){const re=Xo(w.id,y.id,nn(fe.current,w.id,u.fromHandle),b,k);if(re){G({nodeId:w.id,reason:re});return}}const T=(Y=b.find(re=>re.id===w.id))==null?void 0:Y.data.step;if(T){const re=i.nodePortsForStep(T,ie);if((j==="source"?re.out:re.in)<1)return}const F="changedTouches"in r?r.changedTouches[0]:r,L=Re({x:F.clientX,y:F.clientY});_e({nodeId:w.id,handleType:j,position:L,lane:nn(fe.current,w.id,u.fromHandle),route:i.routeFromHandle((ne=u.fromHandle)==null?void 0:ne.id)}),te(!0)},[n,Re,b,k,ie]),fs=d.useCallback((r,u,w)=>{if(n)return;const j=b.find(K=>K.id===r);if(!j)return;const y=Xt(j),T=i.laneForSourceHandle(w),F=120,L=u==="target"?{x:y.x-y.w-F,y:y.y}:T==="error"?{x:y.x,y:y.y+y.h+F}:T==="each"?{x:y.x+y.w+F,y:y.y-y.h-F/2}:{x:y.x+y.w+F,y:y.y};_e({nodeId:r,handleType:u,position:L,lane:T,route:i.routeFromHandle(w)}),te(!0)},[n,b]),hs=d.useCallback(r=>{n||Ie({nodeIds:[r],edgeIds:[]})},[n]),Vn=d.useCallback(r=>{if(n)return;const u=Eo(r,b,k,U);W(u.nodes),X(u.edges),z(u.canvas),u.nodes.some(w=>w.id===_)||V(null),u.nodes.some(w=>w.id===ae)||Ae(null),u.edges.some(w=>w.id===ce)||Ce(null),Q(u.nodes,u.edges,u.canvas)},[b,k,U,W,X,Q,n,_,ae,ce]),ms=d.useCallback(()=>{if(n)return;const r=Oo(b,k,U);W(r.nodes),z(r.canvas),at.current=!0,Q(r.nodes,k,r.canvas)},[b,k,U,W,Q,n]),zn=d.useCallback(()=>{n||ms()},[n,ms]);d.useEffect(()=>{at.current&&(at.current=!1,Me({duration:300}))},[b,Me]);const ws=d.useRef(h);d.useEffect(()=>{Object.is(ws.current,h)||(ws.current=h,Me({duration:300}))},[h,Me]);const[vt,Ge]=d.useState(null),st=d.useMemo(()=>k.find(r=>r.id===ce)??null,[k,ce]),Hn=d.useCallback(r=>{if(n||!ce)return;const u=k.find(F=>F.id===ce);if(!u||i.edgeLane(u)===r)return;const w=i.edgeWhenConflict(k,ce,r,b),j=i.relaneRefusal(k,ce,r,b,ie),y=w||j?null:i.setEdgeWhen(k,ce,r,b,ie);if(!y){if(j){Ge({edgeId:ce,message:dn(j.cap)});return}Ge({edgeId:ce,message:w?i.idClashMessage("Can’t switch this edge",w,ln(k,w,u.source,u.target)):"This edge can’t be switched right now."});return}Ge(null),X(y);const T=y.find(F=>F.source===u.source&&F.target===u.target&&i.edgeLane(F)===r);Ce((T==null?void 0:T.id)??null),Q(b,y)},[k,b,X,Q,n,ce,ie]),Jn=d.useCallback(r=>{if(n)return;const u=k.filter(w=>w.id!==r);u.length!==k.length&&(X(u),ce===r&&Ce(null),Q(b,u))},[b,k,X,Q,n,ce]),_t=d.useCallback(r=>{if(n)return;const u=r.map(T=>b.find(F=>F.id===T)).filter(T=>T!==void 0);if(u.length===0)return;const w=b.map(T=>T.id),j=u.map(T=>{const F=i.suggestStepId(w,`${T.data.step.id}_copy`);w.push(F);const L={...i.stripBody(structuredClone(T.data.step)),id:F};return{id:F,type:T.type,position:{x:T.position.x+40,y:T.position.y+60},data:{step:L,isInternal:T.data.isInternal},...u.length>1?{selected:!0}:{}}}),y=[...u.length>1?b.map(T=>T.selected?{...T,selected:!1}:T):b,...j];W(y),V(j[0].id),Q(y,k)},[b,k,W,Q,n]),gs=d.useCallback(r=>_t([r]),[_t]),Un=d.useCallback(r=>{if(n)return;const u=i.isInternalApp(r.uses.app),w=b.map(ne=>ne.id),j=r.id&&!i.stepNameError(r.id,w)?r.id:i.suggestStepId(w,i.slugifyLabel(i.internalNodeLabel(r.uses.app,r.uses.action))),y=$({id:j,uses:r.uses,...r.with&&Object.keys(r.with).length>0?{with:r.with}:{}}),T={id:j,type:u?"control":"step",position:(we==null?void 0:we.position)??(Te==null?void 0:Te.position)??{x:80,y:80+b.length*24},data:{step:y,isInternal:u}},F=[...b,T];let L=k,K=null;const Y=(ne,re,me,Be)=>{const ot=i.connectRefusal(ne,re,F,k,me,ie);ot&&ot.refused==="loop"&&(K={nodeId:Be,reason:ot.reason})};if(we){const[ne,re]=we.handleType==="target"?[j,we.nodeId]:[we.nodeId,j],me=i.applyConnect(ne,re,F,k,we.lane,ie,we.route);me||Y(ne,re,we.lane,we.nodeId),L=me??k}else{const ne=b.find(re=>i.isTriggerStep(re.data.step.uses));if(i.isTriggerStep(r.uses)){if(!ne){const re=i.findChainRoot(b,k);if(re){const me=i.applyConnect(j,re.id,F,k,"success",ie);me||Y(j,re.id,"success",re.id),L=me??k}}}else{const me=(ne&&!k.some(Be=>Be.source===ne.id)?ne:void 0)??i.findChainTail(b,k);if(me){const Be=i.applyConnect(me.id,j,F,k,"success",ie);Be||Y(me.id,j,"success",me.id),L=Be??k}}}return W(F),L!==k&&X(L),G(K),V(j),Q(F,L),j},[b,k,W,X,Q,n,we,Te,ie,$]),xs=d.useCallback((r,u)=>{var K;let w=u;const j=(K=b.find(Y=>Y.id===r))==null?void 0:K.data.step;if(u.uses.connection&&!u.uses.connectionRef&&(j!=null&&j.uses.connectionRef)&&j.uses.app===u.uses.app){const Y=i.selectNodeConnection(i.withConnectionRef(u,j.uses.connectionRef),u.uses.connection,b.map(ne=>ne.data.step),M.current);C(Y.connections),w=Y.step}else w=$(u);const y=w.id!==r;if(y&&b.some(Y=>Y.id===w.id))return;const T=b.map(Y=>Y.id===r?{...Y,id:w.id,data:{step:w,isInternal:i.isInternalApp(w.uses.app)}}:Y);if(y){const Y=i.renameStepInEdges(k,r,w.id),ne=jn(U,r,w.id);W(T),X(Y),z(ne),_===r&&V(w.id),ae===r&&Ae(w.id),Q(T,Y,ne);return}W(T);const F=new Set(i.routesForStep(w).map(Y=>Y.id)),L=k.filter(Y=>{var ne;return Y.source!==w.id||((ne=Y.data)==null?void 0:ne.route)===void 0||F.has(String(Y.data.route))});L.length!==k.length&&X(L),Q(T,L)},[b,k,U,W,X,_,ae,Q,$,C]),Ke=d.useCallback(r=>{n||(z(r),Q(b,k,r))},[n,b,k,Q]),qn=d.useCallback(()=>{var y;if(n)return;const r=(y=ve.current)==null?void 0:y.getBoundingClientRect(),u=r?Re({x:r.left+r.width/2,y:r.top+r.height/2}):{x:0,y:0},w=U.notes??[],j={id:un("note",w.map(T=>T.id)),color:"#facc15",position:{x:Math.round(u.x-100),y:Math.round(u.y-60)},size:{width:200,height:120},content:""};Ke(Qt({...U,notes:[...w,j]}))},[n,U,Re,Ke]),Gn=d.useCallback((r,u)=>{if(n)return;const w=u?Math.min(r.x,u.x):r.x,j=u?Math.min(r.y,u.y):r.y,y=u?Math.abs(u.x-r.x):360,T=u?Math.abs(u.y-r.y):240,F=b.filter(re=>{const me=Xt(re),Be=me.x+me.w/2,ot=me.y+me.h/2;return Be>=w&&Be<=w+y&&ot>=j&&ot<=j+T}).map(re=>re.id),L=U.sections??[],K=un("section",L.map(re=>re.id)),Y={id:K,title:"Section",color:"#6366f1",position:{x:Math.round(w),y:Math.round(j)},size:{width:Math.round(y),height:Math.round(T)},nodes:[]},ne={...U,sections:[...L,Y]};Ke(Qt(Zt(ne,K,F)))},[n,b,U,Ke]);d.useEffect(()=>{if(!Le)return;const r=u=>{u.key==="Escape"&&(rt(!1),Je(null))};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[Le]);const Kn=d.useCallback((r,u)=>{var F;if(n)return;const w=(F=U.sections)==null?void 0:F.find(L=>L.id===r);if(!w)return;const j=new Set(w.nodes),y=b.map(L=>j.has(L.id)?{...L,position:{x:L.position.x+u.dx,y:L.position.y+u.dy}}:L),T={...U,sections:(U.sections??[]).map(L=>L.id===r?{...L,position:{x:L.position.x+u.dx,y:L.position.y+u.dy}}:L)};W(y),z(T),Q(y,k,T)},[n,U,b,k,W,Q]),Xn=d.useCallback((r,u)=>{if(n)return;const w=r==="note"?{...U,notes:(U.notes??[]).filter(j=>j.id!==u)}:{...U,sections:(U.sections??[]).filter(j=>j.id!==u)};Ke(w)},[n,U,Ke]),Yn=r=>{let u=U;for(const w of r){const j=Xt(w),y=j.x+j.w/2,T=j.y+j.h/2,F=(u.sections??[]).find(K=>y>=K.position.x&&y<=K.position.x+K.size.width&&T>=K.position.y&&T<=K.position.y+K.size.height),L=yn(u,w.id);F?(L.length!==1||L[0]!==F.id)&&(u=Zt(u,F.id,[w.id])):L.length>0&&(u=os(u,w.id))}return u},Wt=d.useCallback((r,u,w)=>{(async()=>{const j=await S.saveStepTest(s.id,r,u).catch(y=>(console.error("step run fixture save failed",y),null));await S.recordStepTestRun(s.id,r,{stepTestId:(j==null?void 0:j.id)??null,status:w.status,input:u.input,output:w.output,error:w.error,...w.meta?{meta:w.meta}:{}})})().catch(j=>{console.error("step run persist failed",j)})},[S,s.id]),bs=d.useCallback(r=>{const u=b.find(w=>w.id===r);!u||!v&&i.isControlApp(u.data.step.uses.app)||m({stepId:r,status:"collect"})},[b,v]),Zn=d.useCallback(async(r,u,w)=>{if(!v)return;const j=b.find(F=>F.id===r);if(!j)return;const y=i.isTriggerStep(j.data.step.uses),T={stopAt:ts(b.map(F=>F.data.step),r),...w?{state:w}:{},...y?{input:u}:{}};m({stepId:r,status:"running"});try{await v(r,T),m(null)}catch(F){const L=F;m({stepId:r,status:"error",error:L.message??String(F),errorCode:L.code})}},[b,v]),St=d.useCallback((r,u)=>{if(n)return;const w=b.map(j=>j.id===r?{...j,data:{...j.data,step:u(j.data.step)}}:j);W(w),Q(w,k)},[b,k,W,Q,n]),js=d.useCallback(r=>St(r,u=>Nn(u,!Ze(u))),[St]),ys=d.useCallback(r=>St(r,u=>kn(u,!De(u))),[St]),Qn=d.useCallback(async(r,u,w)=>{x==null||x();const j=b.find(K=>K.id===r);if(!j)return;const y=j.data.step,T=i.isTriggerStep(y.uses),F=T?{input:u}:{...y.with??{},...u},L=T?{input:u,with:u}:{input:u,with:F};m({stepId:r,status:"running"});try{const K=await S.invokeAction(y.uses.app,y.uses.action,F,{connectionId:i.connectionIdFor(y,M.current),project:f,...w?{state:w}:{},workflowId:s.id}),Y=K.logs,ne=K.meta;m({stepId:r,status:"done",value:K.value,logs:Y,...ne?{meta:ne}:{}}),Wt(r,L,{status:"succeeded",output:K.value,...ne?{meta:ne}:{}})}catch(K){const Y=K;m({stepId:r,status:"error",error:Y.message??String(K),errorCode:Y.code}),Wt(r,L,{status:"failed",error:Y.message??String(K)})}},[b,S,Wt,f,x,s.id]),$t=d.useMemo(()=>({onEdit:r=>{Ne("props"),Ae(r)},onEditJson:r=>{Ne("json"),Ae(r)},onRun:bs,onDuplicate:gs,onDelete:hs,onTogglePause:js,onToggleDisable:ys,runsFromNode:!!v,onAddFromPort:fs,readOnly:n}),[bs,gs,hs,js,ys,v,fs,n]);d.useEffect(()=>{const r=ve.current;if(!r)return;const u=w=>{const j=w.target.closest(".react-flow__node");if(!j)return;const y=j.getAttribute("data-id");y&&(w.stopPropagation(),$t.onEdit(y))};return r.addEventListener("dblclick",u,!0),()=>r.removeEventListener("dblclick",u,!0)},[$t]);const nt=b.find(r=>r.id===ae),Ct=(nt==null?void 0:nt.data.step)??null,Bt=D?((zs=b.find(r=>r.id===D.stepId))==null?void 0:zs.data.step)??null:null,Vt=(D==null?void 0:D.status)==="collect"&&!!Bt,vs=d.useMemo(()=>{const r=new Map;for(const u of b)r.set(u.id,To(u.id,k).count);return r},[b,k]),Ss=Vo(b),Nt=d.useMemo(()=>zo(Ss),[Ss]),eo=d.useMemo(()=>$o(k,Nt.tones,Nt.loopOf),[k,Nt]),to=d.useMemo(()=>({step:Li,control:Fi}),[]),[kt,Cs]=d.useState({}),[Et,Ns]=d.useState({}),[ks,Es]=d.useState({}),[At,As]=d.useState({}),[We,Tt]=d.useState(null),[Ts,Ps]=d.useState([]),so=ae??We??"";d.useEffect(()=>{const r=S.loadNodeSamples;if(typeof r!="function"||!s.id){Ps([]);return}let u=!1;return r(s.id).then(w=>{u||Ps(Array.isArray(w)?w:[])},()=>{}),()=>{u=!0}},[S,s.id,so]);const Pt=d.useMemo(()=>i.indexNodeSamples(Ts),[Ts]),zt=d.useMemo(()=>i.splitNodeOutputs(kt,Pt,At),[kt,Pt,At]),$e=d.useMemo(()=>i.splitPreviewOutputs(kt,Pt,At),[kt,Pt,At]),Se=d.useMemo(()=>({actionDef:(r,u)=>{var w;return(w=ue[r])==null?void 0:w.find(j=>j.key===u)},triggerDef:(r,u)=>{var w;return(w=je[r])==null?void 0:w.find(j=>j.key===u)},testOutputs:zt.fresh,persistedOutputs:zt.persisted,loopSamples:ks}),[ue,je,zt,ks]),Xe=d.useMemo(()=>D?i.upstreamStateSources(D.stepId,b,k,Se):void 0,[D,b,k,Se]),no=d.useMemo(()=>(Xe==null?void 0:Xe.steps)??[],[Xe]),ge=d.useMemo(()=>{const r=i.upstreamStateSources(ae,b,k,Se,We);return{...r,steps:i.excludeSelfStep(r.steps,ae??We)}},[ae,We,b,k,Se]),dt=d.useMemo(()=>fi({anchorId:ae??We,nodes:b,edges:k,floating:i.isFloatingDraft(ae,We,b,k),initialState:s.initialState,variables:s.variables,shapes:Se,previewOutputs:{...$e.persisted,...$e.fresh}}),[ae,We,b,k,s.initialState,s.variables,Se,$e]),Is=JSON.stringify([...ge.steps.map(r=>r.id),...ge.extraSampleIds??[]]);d.useEffect(()=>{const r=JSON.parse(Is);if(!ae&&!We||r.length===0){Cs({}),Ns({}),Es({}),As({});return}let u=!1;return Promise.all(r.map(async w=>{try{const j=await S.listStepTests(s.id,w),y=j.length?j[j.length-1]:null;return y?{id:w,output:y.lastRunOutput,runAt:y.lastRunAt,meta:y.lastRunMeta,loopSample:i.foreachTestSample(y)}:null}catch{return null}})).then(w=>{if(u)return;const j={},y={},T={},F={};for(const L of w)L!=null&&L.meta&&(y[L.id]=L.meta),L!=null&&L.loopSample&&(T[L.id]=L.loopSample),!(!L||L.output===void 0||L.output===null)&&(j[L.id]=L.output,F[L.id]=L.runAt);Cs(j),As(F),Ns(y),Es(T)}),()=>{u=!0}},[S,s.id,ae,We,Is]);const Ht=d.useMemo(()=>i.declaredSamples(b,Se),[b,Se]),It=d.useMemo(()=>({persisted:$e.persisted,samples:Ht.samples,event:Ht.event}),[$e.persisted,Ht]),Rs=d.useMemo(()=>i.upstreamSampleValues(ge.steps,$e.fresh,Et,ge.loop,It),[ge.steps,ge.loop,$e.fresh,Et,It]),Ms=d.useMemo(()=>i.upstreamSampleValueSources(ge.steps,$e.fresh,Et,ge.loop,It),[ge.steps,ge.loop,$e.fresh,Et,It]),Ls=i.useExpressionOptions(),Fs=d.useMemo(()=>i.nodeConfigSources(b),[b]),Ds=d.useMemo(()=>i.nodeConfigValues(b,A.subs),[b,A.subs]),Jt=d.useMemo(()=>i.nodeMetaValues(b,A.subs,R,J),[b,A.subs,R,J]),Ut=d.useMemo(()=>({...c??{},steps:ge.steps,hasTrigger:ge.hasTrigger,eventOutputs:ge.eventOutputs,eventOutputsFrom:ge.eventOutputsFrom,loop:ge.loop,stateShape:{fields:dt.fields,...dt.written?{written:dt.written}:{}},nodeConfigs:Fs,nodeConfig:Ds,nodeMeta:Jt,valueSources:Ms,sampleValues:{...Ls.sampleValues??{},...(c==null?void 0:c.sampleValues)??{},...i.nodeMetaSampleValues(Jt),...Rs,...dt.sampleValues}}),[c,Ls.sampleValues,ge,dt,Rs,Ms,Fs,Ds,Jt]),ut=d.useRef(null);Oe||ae?ut.current===null&&(ut.current=H.mark()):ut.current=null;const Os=()=>{te(!1),_e(null),He(null),Tt(null)},_s=()=>{const r=ut.current;if(ut.current=null,n||r===null)return;const u=H.rollbackTo(r);u&&$s(u)},Ws=r=>{if(n)return;const u=H[r]();u&&$s(u)},$s=r=>{var j;const u=Ro(s,r);W(u.nodes.map(y=>({...y,selected:y.id===_}))),X(u.edges.map(y=>({...y,selected:y.id===ce}))),z(r.canvas),C(r.connections),u.nodes.some(y=>y.id===_)||V(null),u.edges.some(y=>y.id===ce)||Ce(null);const w=u.nodes.some(y=>y.id===ae);w||Ae(null),te(!1),Tt(null),_e(null),Ie(null),he(null),He(null),Ue(null),G(null),Ge(null),Z.current=void 0,ze(y=>y+1),o(Qe(i.flowToWorkflow({...s,nodes:r.nodes,connections:r.connections},u.nodes,u.edges),r.canvas)),!w&&!D&&((j=ve.current)==null||j.focus({preventScroll:!0}))},Bs=d.useRef(Ws);Bs.current=Ws,d.useEffect(()=>{const r=ve.current;if(!r)return;let u=r.contains(document.activeElement);const w=y=>{y.type==="focusin"&&y.target===document.body||(u=r.contains(y.target))},j=y=>{if(n||y.defaultPrevented||qt(y.target)||!r.contains(y.target)&&!(u&&y.target===document.body))return;const T=y.key.toLowerCase();!(y.ctrlKey||y.metaKey)||y.altKey||T!=="z"&&!(T==="y"&&!y.shiftKey)||(y.preventDefault(),Bs.current(T==="y"||y.shiftKey?"redo":"undo"))};return document.addEventListener("pointerdown",w),document.addEventListener("focusin",w),document.addEventListener("keydown",j),()=>{document.removeEventListener("pointerdown",w),document.removeEventListener("focusin",w),document.removeEventListener("keydown",j)}},[n]);const Rt=d.useCallback((r,u)=>{var L;if(qt(r.target))return;const w=(L=ve.current)==null?void 0:L.getBoundingClientRect();if(!w)return;r.preventDefault();const j=Qs(b,k),y=j.nodeIds,T=fo(y,u),F=u!==void 0&&!y.includes(u);F&&W(b.map(K=>K.selected!==(K.id===u)?{...K,selected:K.id===u}:K)),Ue({x:r.clientX-w.left,y:r.clientY-w.top,flow:Re({x:r.clientX,y:r.clientY}),nodeIds:T,edgeIds:F?[]:j.edgeIds})},[b,k,W,Re]),oo=d.useCallback(r=>{var u;Ue(null),r&&((u=ve.current)==null||u.focus({preventScroll:!0}))},[]),io=r=>{const u=xe;!u||n||(r==="duplicate"?_t(u.nodeIds):r==="delete"?Ie({nodeIds:u.nodeIds,edgeIds:u.edgeIds}):(_e(null),He({position:u.flow,...r==="add-trigger"?{tab:"triggers"}:{}}),te(!0)))},ro=t.jsx(us.Provider,{value:$t,children:t.jsx(as.Provider,{value:ie,children:t.jsx(cs.Provider,{value:vs,children:t.jsx(ls.Provider,{value:Nt,children:t.jsx(Si,{apps:R,registration:A,children:t.jsx(i.WorkflowProjectProvider,{project:f,workflowId:s.id,children:t.jsx(i.ExpressionOptionsProvider,{value:Ut,children:t.jsxs("section",{ref:ve,className:"w6w-flow",tabIndex:-1,"aria-label":"Workflow editor",style:{width:"100%",height:a,position:"relative"},onFocusCapture:r=>{Z.current=qt(r.target)?{}:void 0},onBlurCapture:()=>{Z.current=void 0},onKeyDown:r=>{if(r.defaultPrevented||r.key!=="Backspace"&&r.key!=="Delete"||n||ae||Oe||Pe)return;const u=r.target;if(u.isContentEditable||u.tagName==="INPUT"||u.tagName==="TEXTAREA"||u.tagName==="SELECT"||u.closest("dialog, .w6w-modal")!==null)return;const w=Qs(b,k);!w.nodeIds.length&&!w.edgeIds.length||(r.preventDefault(),!w.nodeIds.length&&w.edgeIds.length===1?Jn(w.edgeIds[0]):Ie(w))},children:[t.jsxs(oe.ReactFlow,{nodes:gt,edges:eo,minZoom:.05,defaultEdgeOptions:{type:"smoothstep"},connectionLineType:oe.ConnectionLineType.SmoothStep,onNodesChange:de,onEdgesChange:E,onConnect:tt,onConnectStart:(r,u)=>{fe.current=u},onConnectEnd:Bn,onPaneClick:()=>G(null),onPaneContextMenu:r=>Rt(r),onNodeContextMenu:(r,u)=>Rt(r,u.id),onEdgeContextMenu:r=>Rt(r),onSelectionContextMenu:r=>Rt(r),onMoveStart:()=>Ue(null),isValidConnection:yt,onNodeDragStop:(r,u,w)=>{const j=Yn(w),y=j!==U;if(y&&z(j),!B&&!y){H.record(Mt(s,b,k,M.current,j));return}Q(b,k,j)},onMoveEnd:(r,u)=>{if(!r||n)return;const w=i.flowToWorkflow(s,b,k),j=i.withViewport(w,u);j!==w&&o(j,{viewportOnly:!0})},onSelectionChange:({nodes:r,edges:u})=>{var w,j,y,T;V(((w=r[0])==null?void 0:w.id)??null),Ce(((j=u[0])==null?void 0:j.id)??null),se.current!==(((y=r[0])==null?void 0:y.id)??null)&&(se.current=((T=r[0])==null?void 0:T.id)??null,G(null))},nodeTypes:to,nodesDraggable:!n,nodesConnectable:!n,connectOnClick:!1,elementsSelectable:!0,...q?{defaultViewport:q}:{fitView:!0},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:zn,title:"Auto-layout — re-flow the graph into columns","aria-label":"Auto-layout the graph",children:t.jsx(ke.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:()=>te(!0),children:"+ Node"}),t.jsx(i.IconButton,{label:"Add note",icon:"sticky-note",className:"w6w-flow-tool","data-testid":"add-note",onClick:qn}),t.jsx(i.IconButton,{label:"Draw section",title:"Draw section — drag a frame on the canvas (Esc cancels)",icon:"frame",className:`w6w-flow-tool${Le?" active":""}`,"aria-pressed":Le,"data-testid":"draw-section",onClick:()=>{rt(!Le),Je(null)}})]}),!n&&Le&&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:u,clientY:w}=r;Je({sx:u,sy:w,ex:u,ey:w})},onPointerMove:r=>{const{clientX:u,clientY:w}=r;Je(j=>j&&{...j,ex:u,ey:w})},onPointerUp:()=>{const r=ye;if(Je(null),rt(!1),!r)return;const u=Re({x:r.sx,y:r.sy}),w=Math.abs(r.ex-r.sx)>6||Math.abs(r.ey-r.sy)>6;Gn(u,w?Re({x:r.ex,y:r.ey}):null)},children:ye&&(()=>{var j;const r=(j=ve.current)==null?void 0:j.getBoundingClientRect(),u=(r==null?void 0:r.left)??0,w=(r==null?void 0:r.top)??0;return t.jsx("div",{className:"w6w-section-draw-rect",style:{left:Math.min(ye.sx,ye.ex)-u,top:Math.min(ye.sy,ye.ey)-w,width:Math.abs(ye.ex-ye.sx),height:Math.abs(ye.ey-ye.sy)}})})()}),!n&&st&&i.edgeLane(st)!=="each"&&((Hs=b.find(r=>r.id===st.source))==null?void 0:Hs.data.step.uses.app)!==i.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${i.edgeLane(st)===r?" active":""}`,"aria-pressed":i.edgeLane(st)===r,title:vi,onClick:()=>Hn(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})]})}),N&&t.jsx(oe.NodeToolbar,{nodeId:N.nodeId,position:oe.Position.Bottom,isVisible:!0,children:t.jsx("div",{className:"w6w-loop-notice w6w-small",role:"alert",children:i.loopRefusalMessage(N.reason)})}),t.jsx(i.CanvasLayer,{canvas:U,readOnly:n,savePosition:B,onChange:Ke,onSectionDrop:Kn,onRequestDelete:(r,u)=>!n&&he({kind:r,id:u})})]}),Ee&&t.jsx(i.ConfirmModal,{title:Ee.kind==="note"?"Delete note":"Delete section",message:Ee.kind==="note"?"Delete this note?":"Delete this section? Its nodes are kept.",confirmLabel:"Delete",onConfirm:()=>{Xn(Ee.kind,Ee.id),he(null)},onClose:()=>he(null)}),Oe&&t.jsx(i.StepBuilderModal,{initialTab:Te==null?void 0:Te.tab,onClose:()=>{_s(),Os()},onDone:Os,onAdd:r=>{const u=Un(r);return u&&Tt(u),u},onDraftChange:(r,u)=>xs(r,{id:r,...u}),stepIds:b.map(r=>r.id),onOpenStep:r=>{te(!1),_e(null),He(null),Tt(null),Ne("props"),Ae(r)},workflowId:s.id,upstreamSteps:i.stepBuilderUpstreamSteps(we,b,k),loop:i.stepBuilderLoop(we,b,k,Se)}),Ct&&ae&&t.jsx(Oi,{workflowId:s.id,step:Ct,restoreVersion:pe,upstreamSteps:Ut.steps??[],loop:Ut.loop,readOnly:n,fanOutCount:vs.get(ae)??0,stateOutputFields:(Gs=i.resolveOutputShape((Js=Se.actionDef)==null?void 0:Js.call(Se,Ct.uses.app,Ct.uses.action),(Us=Se.testOutputs)==null?void 0:Us[ae],(qs=Se.persistedOutputs)==null?void 0:qs[ae]))==null?void 0:Gs.fields.map(r=>r.key),initialView:Fe,stepProblems:nt==null?void 0:nt.data.stepProblems,otherStepIds:b.filter(r=>r.id!==ae).map(r=>r.id),onChange:r=>xs(ae,r),onClose:()=>Ae(null),onCancel:()=>{_s(),Ae(null)},onTestRun:x}),D&&t.jsxs(i.Modal,{title:`${Vt?"Run node":"Test run"}: ${D.stepId}`,onClose:()=>m(null),children:[Vt&&Bt&&t.jsx(Ti,{workflowId:s.id,step:Bt,upstreamSteps:no,loop:Xe==null?void 0:Xe.loop,continues:v?{stopAt:ts(b.map(r=>r.data.step),D.stepId)}:void 0,onCancel:()=>m(null),onRun:(r,u)=>v?Zn(D.stepId,r,u):Qn(D.stepId,r,u)},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(i.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(i.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(ke.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"})})]})]}),Pe!==null&&t.jsx(i.ConfirmModal,{title:Pe.nodeIds.length===1?"Delete node":Pe.nodeIds.length>1?`Delete ${Pe.nodeIds.length} nodes`:`Delete ${Pe.edgeIds.length} connections`,message:Ao(Pe,b,k),confirmLabel:"Delete",autoFocusConfirm:!0,onConfirm:()=>{Vn(Pe),Ie(null)},onClose:()=>Ie(null)}),xe&&t.jsx(lo,{x:xe.x,y:xe.y,items:ho(xe.nodeIds,!!n),onAction:io,onClose:oo})]})})})})})})})});return t.jsx(i.WorkflowConnectionsContext.Provider,{value:{nodes:b.map(r=>r.data.step),connections:J,setConnections:C,readOnly:n},children:ro})}const ki=["code"];function Ot(e){try{const s=JSON.parse(e);return s&&typeof s=="object"&&!Array.isArray(s)?s:null}catch{return null}}function Ei(e){try{const s=JSON.parse(e);if(Array.isArray(s))return{items:s}}catch{return null}return Ot(e)}function Ai({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 o=e[0],n=o!==void 0?(i.inferOutputFields(o)??[]).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(i.ResultViewer,{value:o,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,l)=>t.jsxs("span",{children:[l>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 In(e){const[s,o]=d.useState(null),[n,a]=d.useState("0"),l=s??i.loopItemText(e),c=e?i.parseLoopSeed(l,n):void 0;return{active:!!e,itemText:l,indexText:n,setItemText:o,setIndexText:a,parsed:c}}function Rn(e){var s;return(s=e.parsed)!=null&&s.ok?e.parsed.value:void 0}function ps(e){return e.parsed&&!e.parsed.ok?e.parsed.error:null}function Mn({seed:e,readOnly:s}){if(!e.active)return null;const o=ps(e);return t.jsxs("div",{className:"w6w-field w6w-loop-seed",children:[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."}),o&&t.jsx("span",{className:"w6w-hint",role:"alert",children:o})]})}function ns({text:e,onChange:s,seeds:o,readOnly:n,expand:a,hint:l}){const c=Ot(e),f=c?Object.keys(c).length:0,p=f>0,[g,x]=d.useState(p);d.useEffect(()=>{(p||a)&&x(!0)},[p,a]);const h=v=>{s(JSON.stringify(v.lastRunOutput??v.input??{},null,2)),x(!0)};return t.jsxs("div",{className:"w6w-field w6w-incoming-state",children:[t.jsx("span",{children:"Incoming state"}),o.length>0&&t.jsx("div",{className:"w6w-seed-picker",children:t.jsx("div",{className:"w6w-seed-chips",children:o.map(v=>t.jsxs("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Use ${v.label}'s saved test as the incoming state`,disabled:n,onClick:()=>h(v.test),children:[t.jsx("code",{children:v.label}),v.test.lastRunStatus?t.jsxs("span",{className:"w6w-muted w6w-small",children:[" · ",v.test.lastRunStatus]}):null]},v.stepId))})}),t.jsxs("details",{className:"w6w-state-override",open:g,onToggle:v=>x(v.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:v=>s(v.target.value)}),t.jsx("span",{className:"w6w-hint",children:l??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 Ti({workflowId:e,step:s,upstreamSteps:o,loop:n,onRun:a,onCancel:l,continues:c}){var U;const f=i.useW6WApi(),p=i.isTriggerStep(s.uses),g=i.isInternalApp(s.uses.app),x=d.useMemo(()=>{var z;return p?i.asFieldDefs((z=s.with)==null?void 0:z.fields):[]},[p,s.with]),h=d.useMemo(()=>p?i.fieldsToParams(x):g?i.internalNodeParams(s.uses.app,s.uses.action):null,[p,g,x,s.uses.app,s.uses.action]),[v,S]=d.useState(null),R=h??v;d.useEffect(()=>{if(h)return;if(!s.uses.app||!s.uses.action){S([]);return}let z=!1;return S(null),f.getAppActions(s.uses.app).then(H=>{var Z;z||S(((Z=H.find(pe=>pe.key===s.uses.action))==null?void 0:Z.params)??[])}).catch(()=>!z&&S([])),()=>{z=!0}},[f,h,s.uses.app,s.uses.action]);const[A,D]=d.useState(()=>{var z;return p?i.seedValues(i.asFieldDefs((z=s.with)==null?void 0:z.fields)):{}}),[m,P]=d.useState("{}"),O=i.useSeedSources(e,o,!p),J=In(n),I=(U=i.useExpressionOptions().stateShape)==null?void 0:U.written,M=i.startStateFromSeeds(O,Rn(J),I),C=i.useRememberedTestInput(e,s.id),[$,q]=d.useState(!1),[B,b]=d.useState(!1);d.useEffect(()=>{if(!C.loaded)return;let z=!1;const H=(Z,pe)=>{Z&&Object.keys(Z).length>0&&(p?D(ze=>({...ze,...Z})):P(JSON.stringify(Z,null,2)),pe&&b(!0)),q(!0)};if(C.input!==void 0){H(C.input,!0);return}return f.listStepTests(e,s.id).then(Z=>{if(z)return;const pe=Z.length?Z[Z.length-1]:null;H(p?pe==null?void 0:pe.with:pe==null?void 0:pe.input,!1)}).catch(()=>{z||q(!0)}),()=>{z=!0}},[f,e,s.id,p,C.loaded]);const[W,de]=d.useState(0),ue=()=>{C.clear(),b(!1),p?D(i.seedValues(x)):P("{}"),de(z=>z+1)},je=z=>{D(z),k(!0),b(!1),de(H=>H+1)},[ie,k]=d.useState(!0),X=Ot(m),E=p?ie:X!==null,_=p?A:{...s.with??{},...X??{}},V=p?null:ps(J),ee=!!R&&$&&E&&!V&&i.requiredParamsFilled(R,_);return t.jsxs("div",{className:"w6w-stepconfig",children:[t.jsx("div",{className:"w6w-modal-body",children:t.jsxs("div",{className:"w6w-stack",children:[c&&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",c.stopAt.length>0?t.jsxs(t.Fragment,{children:[" ","and stops before"," ",c.stopAt.length===1?"the paused node":"paused nodes"," ",c.stopAt.map((z,H)=>t.jsxs("span",{children:[H>0?", ":"",t.jsx("code",{children:z})]},z))]}):null,". Disabled nodes are skipped."]}),B&&R!==null&&$&&t.jsx(i.LastUsedNote,{onClear:ue}),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(i.PropertyEntryForm,{params:R,values:A,onChange:D,onValidityChange:k},W),s.uses.trigger===!0&&t.jsx(po,{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(Mn,{seed:J}),t.jsx(ns,{text:m,onChange:P,seeds:O})]})]})}),t.jsxs("div",{className:"w6w-modal-actions",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:l,children:"Cancel"}),!ee&&R!==null&&$&&t.jsx("span",{className:"w6w-muted w6w-small",children:V?`${V} Fix it to run.`:E?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:!ee,onClick:()=>{C.save(p?A:X??{},R??[]),a(p?A:X??{},p?void 0:M)},children:"▶ Run"})]})]})}function Pi(e){return e.uses.app===i.CONTROL_APP&&e.uses.action==="foreach"}function Ln({id:e}){const{tones:s,loopOf:o}=d.useContext(ls),n=Cn(e,o);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:is(s.get(a)??1)}},a))})}function Fn(e){return Bo(e,d.useContext(ls).tones)}function Ve({type:e,position:s,multiple:o,id:n,variant:a,top:l,routeLabel:c}){const f=oe.useNodeId(),p=d.useContext(us),g=!!f&&!!p&&!p.readOnly,x=()=>{g&&f&&p.onAddFromPort(f,e,n)},h=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":o?"w6w-handle-multi":void 0,style:{...o?{height:22,borderRadius:3,width:8}:{},...l?{top:l}:{}},onClick:g?x:void 0,title:c?`${c} — drag or click to connect`:g?`Drag to empty canvas (or click) to add ${h} · 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":o?e==="target"?"Accepts multiple incoming connections":"Multiple outgoing connections":void 0})}function Dn({id:e,step:s,runnable:o}){const n=d.useContext(us);if(!n||n.readOnly)return null;const a=o||n.runsFromNode,l=n.runsFromNode?"Run from this node — continues through the nodes after it":"Test-run this node",c=Ze(s),f=De(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:l,"aria-label":l,onClick:()=>n.onRun(e),children:t.jsx(ke.Icon,{name:"run",size:15})}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn","data-testid":"node-pause-toggle","aria-pressed":c,title:c?"Resume — test runs go through this node":"Pause — test runs stop before this node","aria-label":c?"Unpause node":"Pause node",onClick:()=>n.onTogglePause(e),children:t.jsx(ke.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(ke.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(ke.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(ke.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(ke.Icon,{name:"trash",size:15})})]})}function On({step:e,count:s}){if(s<2)return null;const o=e.fanOut==="parallel",n=Io(s,o?"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:o?"⇉":"→"})," ",s]})}function _n({step:e}){const s=Ze(e),o=De(e);return!s&&!o?null:t.jsxs("div",{children:[o&&t.jsxs("span",{className:"w6w-node-flag w6w-node-flag-disabled","data-testid":"step-disabled-badge",role:"img","aria-label":tn,title:tn,children:[t.jsx(ke.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":en,title:en,children:[t.jsx(ke.Icon,{name:"pause",size:11})," Paused"]})]})}function Wn(e){return!e||e.length===0?{}:{"data-step-problem":e.map(s=>s.code).join(" "),title:e.map(i.stepProblemTooltip).join(`
|
|
4
|
+
`)}}function $n({problems:e}){if(!e||e.length===0)return null;const s=e.map(i.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(ke.Icon,{name:"warning",size:12})})}function Ii(e){const s=i.useW6WApi(),o=e.uses.action,[n,a]=d.useState(null),l=e.uses.trigger===!0,c=e.uses.app;return d.useEffect(()=>{if(!l||!s.getAppTriggers)return;let f=!1;return s.getAppTriggers(c).then(p=>{var g;return!f&&a(((g=p.find(x=>x.key===o))==null?void 0:g.title)??null)}).catch(()=>{}),()=>{f=!0}},[s,c,o,l]),n||o}function Ri(e){const s=i.useW6WApi(),o=s.listSubscriptionsForWorkflow,n=s.retrySubscriptionRegistration,a=e.id,l=[...xi(e.nodes),...(e.nodes??[]).filter(R=>{var A;return((A=R.uses)==null?void 0:A.app)===i.WEBHOOK_APP&&R.uses.trigger!==!0})],c=l.length>0,f=l.map(R=>`${R.id}:${R.uses.app}:${R.uses.action}:${i.connectionIdFor(R,e.connections)??""}`).join("|"),[p,g]=d.useState([]),x=d.useMemo(()=>gi(p),[p]),[h,v]=d.useState(0);d.useEffect(()=>{if(!o||!c){g([]);return}let R=!1;return o.call(s,a).then(A=>!R&&g(A)).catch(()=>{}),()=>{R=!0}},[s,o,a,c,f,h]);const S=d.useMemo(()=>n?async R=>{try{await n.call(s,R)}finally{v(A=>A+1)}}:void 0,[s,n]);return d.useMemo(()=>({byNode:x,subs:p,retry:S}),[x,p,S])}function Mi({nodeId:e}){const{byNode:s,retry:o}=d.useContext(Pn),[n,a]=d.useState(!1),l=s.get(e),c=wi(l,o!==void 0);return!l||!c?null:t.jsxs("div",{className:"w6w-small","data-trigger-registration":l.status,"data-tone":c.tone,style:{marginTop:3,paddingLeft:2},children:[t.jsx("span",{style:c.tone==="danger"?{color:"var(--w6w-danger)"}:void 0,children:c.label}),t.jsxs("span",{className:"w6w-muted",children:[" · ",c.lastFire]}),c.error&&t.jsx("div",{role:"alert",style:{color:"var(--w6w-danger)"},children:c.error}),c.retryVisible&&o&&t.jsx("button",{type:"button",className:"nodrag",disabled:n,onClick:()=>{a(!0),o(l.id).catch(()=>{}).finally(()=>a(!1))},children:"Retry"})]})}function Li({id:e,data:s,selected:o}){const n=s.step,l=d.useContext(ds).get(n.uses.app),c=(l==null?void 0:l.displayName)||n.uses.app||"—",f=i.isTriggerStep(n.uses),p=Ii(n),g=n.uses.trigger?`${c} · ${p}`:c,x=i.nodePortsForStep(n,d.useContext(as)),h=Tn(s.stepStatus??"no-run",s.runStatus),v=t.jsx(On,{step:n,count:d.useContext(cs).get(e)??0}),S=Fn(e);return t.jsxs("div",{className:[s.loopOf?"w6w-node-in-loop":"",De(n)?"w6w-node-disabled":""].filter(Boolean).join(" ")||void 0,"data-loop-of":s.loopOf,style:S,"data-disabled":De(n)||void 0,"data-paused":Ze(n)||void 0,children:[t.jsx(Dn,{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",...Wn(s.stepProblems),style:{position:"relative",...s.stepProblems?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${h.borderWidth}px ${h.borderStyle} ${o?"var(--w6w-accent)":h.borderColor}`,opacity:De(n)?.45:o?1:h.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($n,{problems:s.stepProblems}),x.in>0&&t.jsx(Ve,{type:"target",position:oe.Position.Left,multiple:x.in>1}),t.jsx(i.AppIcon,{src:l==null?void 0:l.iconSvg,srcDark:l==null?void 0:l.iconSvgDark,brandColor:l==null?void 0:l.brandColor,name:c,size:28}),t.jsxs("div",{style:{minWidth:0},children:[t.jsx("div",{style:{fontWeight:600},children:g}),t.jsx("div",{className:"w6w-muted w6w-small",style:{marginTop:2},children:t.jsx("code",{children:n.uses.action||"—"})})]}),x.out>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{type:"source",position:oe.Position.Right,multiple:x.out>1}),!f&&t.jsx(Ve,{type:"source",position:oe.Position.Bottom,multiple:!1,id:i.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),v,t.jsx(_n,{step:n}),f&&n.uses.trigger===!0&&t.jsx(Mi,{nodeId:e}),s.loopOf&&t.jsx(Ln,{id:e}),t.jsxs("div",{className:"w6w-muted",style:{marginTop:3,fontSize:10,opacity:.75,paddingLeft:2},children:[n.id,l!=null&&l.version?` - v${l.version}`:""]}),n.notes&&t.jsx("div",{className:"w6w-muted w6w-node-notes",title:n.notes,children:n.notes})]})}function Fi({id:e,data:s,selected:o}){const n=s.step,a=i.routesForStep(n),l=n.uses.app===i.ROUTER_APP,c=i.isIfStep(n),f=a.length?i.routerPortLayout(a):c?i.ifPortLayout():void 0,p=JSON.stringify(a.map(P=>P.id)),g=oe.useUpdateNodeInternals();d.useEffect(()=>{g(e)},[e,p,g]);const x=i.internalNodeLabel(n.uses.app,n.uses.action),h=i.internalNodeIcon(n.uses.app,n.uses.action),v=i.nodePortsForStep(n,d.useContext(as)),S=i.isTriggerStep(n.uses),R=Pi(n),A=Tn(s.stepStatus??"no-run",s.runStatus),D=t.jsx(On,{step:n,count:d.useContext(cs).get(e)??0}),m=Fn(e);return t.jsxs("div",{className:[R?"w6w-node-foreach":"",s.loopOf?"w6w-node-in-loop":"",De(n)?"w6w-node-disabled":""].filter(Boolean).join(" ")||void 0,"data-loop-of":s.loopOf,style:m,"data-disabled":De(n)||void 0,"data-paused":Ze(n)||void 0,children:[t.jsx(Dn,{id:e,step:n,runnable:!i.isControlApp(n.uses.app)}),t.jsxs("div",{className:S?"w6w-node-trigger":l?"w6w-node-router":void 0,"data-node-kind":S?"trigger":void 0,"data-run-status":s.stepStatus??"no-run",...Wn(s.stepProblems),style:{position:"relative",...s.stepProblems?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${A.borderWidth}px ${A.borderStyle} ${o?"var(--w6w-accent)":A.borderColor}`,opacity:De(n)?.45:o?1:A.opacity,background:"var(--w6w-panel-2)",color:"var(--w6w-text)",...S?{}:{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($n,{problems:s.stepProblems}),v.in>0&&t.jsx(Ve,{type:"target",position:oe.Position.Left,multiple:v.in>1}),h&&t.jsx(i.InternalIcon,{icon:h}),t.jsxs("div",{style:{minWidth:0,textAlign:"left"},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||"—"})})]}),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"})]}),c&&(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}),!c&&!!(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(P=>t.jsx("span",{title:P.label,children:P.label},P.id))}),v.out>0&&t.jsxs(t.Fragment,{children:[R&&t.jsx(Ve,{type:"source",position:oe.Position.Right,multiple:!1,id:i.EACH_SOURCE_HANDLE,variant:"each"}),f?t.jsxs(t.Fragment,{children:[f.right.map(P=>t.jsx(Ve,{type:"source",position:oe.Position.Right,multiple:!1,id:P.handleId,top:P.top,routeLabel:P.label},P.id)),f.bottom&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{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(Ve,{type:"source",position:oe.Position.Right,multiple:v.out>1,id:R?i.routeHandle(i.FOREACH_DONE_ROUTE):void 0}),!S&&!l&&!c&&n.uses.app!==i.RACE_APP&&t.jsx(Ve,{type:"source",position:oe.Position.Bottom,multiple:!1,id:i.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),D,t.jsx(_n,{step:n}),s.loopOf&&t.jsx(Ln,{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 Di(e,s){var c,f;if(!s)return e;const o={...(e==null?void 0:e.steps)??{}};let n=!1;for(const[p,g]of Object.entries(s)){const x=/^nodes\.([^.]+)\.output$/.exec(p);!x||((c=o[x[1]])==null?void 0:c.output)!==void 0||(o[x[1]]={...o[x[1]]??{},output:g},n=!0)}const a=s["trigger.event"],l=a!==void 0&&((f=e==null?void 0:e.trigger)==null?void 0:f.event)===void 0;return!n&&!l?e:{...e??{},...n?{steps:o}:{},...l?{trigger:{...(e==null?void 0:e.trigger)??{},event:a}}:{}}}function Oi(e){return t.jsx(_i,{...e})}function _i({workflowId:e,step:s,restoreVersion:o,upstreamSteps:n,loop:a,onChange:l,onClose:c,onCancel:f,readOnly:p,initialView:g="props",fanOutCount:x=0,stateOutputFields:h,onTestRun:v,stepProblems:S,otherStepIds:R}){var bt,jt,yt;const A=i.useW6WApi(),D=d.useContext(ds),[m,P]=d.useState(s),O=i.useWorkflowConnections(),J=i.connectionIdFor(m,O==null?void 0:O.connections),I={...m,uses:{...m.uses,connection:J}},C=m.uses.connectionRef!==void 0&&!J||i.isConnectionBlocked(I,S),$=S==null?void 0:S.find(N=>N.code==="unknown_connection"&&N.connection===J),q=(S??[]).filter(N=>"fix"in N),[B,b]=d.useState(C?"setup":"configure"),[W,de]=d.useState(g==="json"?"code":g==="settings"?"config":"props"),[ue,je]=d.useState("props"),[ie,k]=d.useState(()=>i.stepToJson(s)),[X,E]=d.useState("{}"),_=d.useRef(null),[V,ee]=d.useState(!1),U=d.useRef(o);d.useEffect(()=>{U.current!==o&&(U.current=o,P(s),k(i.stepToJson(s)))},[o,s]);const[z,H]=d.useState(!1),[Z,pe]=d.useState(null),[ze,Le]=d.useState(null),[rt,ye]=d.useState(null),[Je,Ee]=d.useState(!1),he=i.isInternalApp(m.uses.app),ce=m.uses.trigger===!0;d.useEffect(()=>{if(he){pe(i.internalNodeParams(m.uses.app,m.uses.action));const G=i.INTERNAL_NODES.filter(se=>se.app===m.uses.app&&se.groupActions&&!se.hidden);Le(G.length?G.map(se=>({key:se.action,title:se.label,params:se.params})):null);return}if(!m.uses.app){Le(null),pe([]);return}let N=!1;return pe(null),(ce?i.getTriggerDefs(A,m.uses.app):A.getAppActions(m.uses.app)).then(G=>{var se;N||(Le(G),pe(m.uses.action?((se=G.find(fe=>fe.key===m.uses.action))==null?void 0:se.params)??[]:[]))}).catch(()=>!N&&pe([])),()=>{N=!0}},[A,m.uses.app,m.uses.action,he,ce]);const Ce=d.useRef(0);d.useEffect(()=>()=>{Ce.current++},[]);const Oe=d.useCallback(()=>{he||!m.uses.app||A.listConnectionsForApp(m.uses.app).then(N=>{ye(N),Ee(!1)}).catch(()=>Ee(!0))},[A,m.uses.app,he]);d.useEffect(()=>{if(he||!m.uses.app)return;let N=!1;return ye(null),Ee(!1),A.listConnectionsForApp(m.uses.app).then(G=>{N||(ye(G),Ee(!1))}).catch(()=>!N&&Ee(!0)),()=>{N=!0}},[A,m.uses.app,he]);const te=d.useCallback(N=>{P(N),l(N)},[l]),mt=No({enabled:m.uses.app===i.SCRIPT_APP&&!p,values:m.with??{},onChange:N=>te({...m,with:N})}),ae=N=>{N==="code"&&k(i.stepToJson(m)),de(N)},Ae=N=>{const G=i.stepNameError(N,R??[]);return G||te({...m,id:N}),G},Fe=!!m.uses.app&&!!m.uses.action&&!i.isControlApp(m.uses.app),Ne=i.isForeachStep(m),xe=i.isTriggerStep(m.uses),Ue=B==="test"&&Fe&&!xe,Te=i.useSeedSources(e,n,Fe&&!xe||Ne),He=In(Fe&&!xe?a:void 0),Pe=i.useExpressionOptions(),Ie=i.startStateFromSeeds(Te,Rn(He),(bt=Pe.stateShape)==null?void 0:bt.written),at=Di(Ie,Pe.sampleValues),ve=i.useRememberedTestInput(Fe&&!xe||Ne?e:void 0,m.id),[we,_e]=d.useState(!1);d.useEffect(()=>{if((!Fe||xe)&&!Ne||!ve.loaded)return;if(!Ne&&ve.input!==void 0){const G=ve.input;if(Object.keys(G).length===0)return;const se=JSON.stringify(G,null,2);E(fe=>fe.trim()==="{}"?se:fe),_e(!0);return}let N=!1;return A.listStepTests(e,m.id).then(G=>{if(N)return;const se=G.length?G[G.length-1]:null;if(!(se!=null&&se.input)||Object.keys(se.input).length===0)return;const fe=JSON.stringify(se.input,null,2);E(tt=>tt.trim()==="{}"?fe:tt)}).catch(()=>{}),()=>{N=!0}},[A,e,m.id,Fe,xe,Ne,ve.loaded]);const Re=Ne?Ei(X):Ot(X),Me={...m.with??{},...Re??{}},ct=Re??{},Qe=!!Z&&!ps(He)&&i.requiredParamsFilled(Z,Me)&&(m.uses.app!==i.CALL_APP||z),Q=Ne?i.resolveLoopItemsInState(Me.items,Ie):void 0,[et,qe]=d.useState("idle"),wt=N=>{E(N),qe("idle")},lt=async()=>{if(Q){qe("saving");try{await A.saveStepTest(e,m.id,i.foreachTestFixture(Q,ct)),qe("saved")}catch{qe("failed")}}},le=D.get(m.uses.app),gt=he?i.internalNodeIcon(m.uses.app,m.uses.action):null,xt=he?gt?t.jsx(i.InternalIcon,{icon:gt}):null:t.jsx(i.AppIcon,{src:le==null?void 0:le.iconSvg,srcDark:le==null?void 0:le.iconSvgDark,brandColor:le==null?void 0:le.brandColor,name:le==null?void 0:le.displayName});return t.jsx(i.Modal,{ariaLabel:"Edit step",titleIcon:xt,title:t.jsx(i.StepNameEditor,{value:m.id,onCommit:Ae,readOnly:p}),onClose:f??c,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(N=>m.uses.app!==i.RACE_APP||N!=="test").map(N=>t.jsx("button",{type:"button",className:`w6w-subtab${B===N?" active":""}`,disabled:C&&N!=="setup",onClick:()=>b(N),children:N==="setup"?"Setup":N==="configure"?"Configure":"Test"},N))}),Ue?t.jsx(i.ConfigViewToggle,{view:ue,views:["props","code"],onChange:N=>je(N)}):t.jsx(i.ConfigViewToggle,{view:W,customized:i.hasParamCustomization(m.with??{}),onChange:ae,disabled:B!=="configure"})]}),C&&$&&t.jsxs("div",{role:"alert",className:"w6w-field-error",children:["Connection ",$.connection," no longer exists — choose another to continue."]}),q.length>0&&t.jsx("div",{className:"w6w-stepproblem-fixes",style:{display:"grid",gap:6},children:q.map(N=>t.jsxs("div",{className:"w6w-small",style:{display:"flex",gap:8,alignItems:"center"},children:[t.jsx("span",{children:i.stepProblemTooltip(N)}),t.jsx("button",{type:"button",className:"w6w-btn","data-fix-code":N.code,disabled:p,onClick:()=>{const G=An(m,N);te(G),k(i.stepToJson(G))},children:"fix"in N?N.fix.label:""})]},N.code))}),t.jsxs("div",{className:"w6w-stepconfig-body",children:[B==="setup"&&m.uses.app===i.CALL_APP&&t.jsx(i.CallTargetForm,{values:m.with??{},onChange:N=>te({...m,with:N}),readOnly:p,onValidityChange:H,setupOnly:!0}),B==="setup"&&m.uses.app!==i.CALL_APP&&t.jsx(zi,{step:m,app:le,actions:ze,conns:rt,connsFailed:Je,isInternal:he,actionLabel:ce?"Trigger":"Action",readOnly:p,onChangeAction:N=>{var se;const G=he?i.internalNodeDefaults(m.uses.app,N):{};if(he)for(const fe of i.internalNodeParams(m.uses.app,N))fe.key in(m.with??{})&&(G[fe.key]=(se=m.with)==null?void 0:se[fe.key]);te({...m,uses:{...m.uses,action:N},with:G})},onChangeTriggerEvents:(N,G)=>te({...m,uses:{...m.uses,action:N},with:{...m.with,actions:G}}),onChangeConnection:N=>{if(!O){const{connectionRef:se,...fe}=m.uses;te({...m,uses:{...fe,connection:N}});return}const G=i.selectNodeConnection(m,N,(O==null?void 0:O.nodes)??[m],(O==null?void 0:O.connections)??{});O==null||O.setConnections(G.connections),te(G.step)},onChangeConnectionRef:N=>te(i.withConnectionRef(m,N)),onConnectionCreated:Oe,onChangeApp:N=>{const G=++Ce.current;if(N===m.uses.app){te(m);return}const se={...m,uses:{app:N,action:"",...ce?{trigger:!0}:{}},with:{}};(i.isInternalApp(N)?Promise.resolve([]):A.listConnectionsForApp(N)).catch(()=>[]).then(fe=>{if(G!==Ce.current)return;const tt=i.defaultConnectionFor(se,fe,(O==null?void 0:O.nodes)??[],(O==null?void 0:O.connections)??{});te({...se,uses:{...se.uses,...tt}})})}}),B==="configure"&&t.jsxs(t.Fragment,{children:[m.uses.app===i.WEBHOOK_APP&&A.listSubscriptionsForWorkflow&&A.createSubscription&&t.jsx(Vi,{workflowId:e,step:m,readOnly:p}),Z===null?t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):W==="props"?m.uses.app===i.CALL_APP?t.jsx(i.CallTargetForm,{values:m.with??{},onChange:N=>te({...m,with:N}),readOnly:p,onValidityChange:H}):m.uses.app===i.RACE_APP?t.jsx("p",{className:"w6w-muted w6w-small",children:i.RACE_DESCRIPTION}):m.uses.action==="wait"&&i.isControlApp(m.uses.app)?t.jsx(i.WaitEditor,{values:m.with??{},readOnly:p,onChange:N=>te({...m,with:N})}):m.uses.action==="if"&&i.isControlApp(m.uses.app)?t.jsx(i.ConditionEditor,{values:m.with??{},readOnly:p,onChange:N=>te({...m,with:N})}):m.uses.app==="@w6w/stop"?t.jsx(i.StopEditor,{values:m.with??{},readOnly:p,onChange:N=>te({...m,with:N})}):m.uses.app===i.ROUTER_APP?t.jsx(i.RouterEditor,{values:m.with??{},readOnly:p,onChange:N=>te({...m,with:N})}):t.jsxs(t.Fragment,{children:[m.uses.app===i.SCRIPT_APP&&t.jsx(ko,{values:m.with??{},conversion:mt,readOnly:p}),t.jsx(i.ParamsForm,{params:Z,values:m.with??{},readOnly:p,onChange:N=>te({...m,with:N}),dynamic:he||!m.uses.action?void 0:{appId:m.uses.app,actionKey:m.uses.action,connectionId:C?void 0:J,appName:le==null?void 0:le.displayName}})]}):W==="code"?t.jsx(i.JsonEditor,{value:ie,onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":`Node ${m.id} JSON`,copyable:!0}):W==="params-code"?t.jsx(i.ParamCustomization,{values:m.with??{},onChange:N=>te({...m,with:N}),readOnly:p}):t.jsxs("div",{className:"w6w-stack",children:[t.jsx(i.NodeConfigForm,{config:{retry:m.retry,onError:m.onError,notes:m.notes},onChange:N=>te({...m,...N}),readOnly:p,failureHandling:!xe,retryControls:!i.isControlApp(m.uses.app)&&m.uses.app!==i.CALL_APP}),Wi,t.jsx($i,{step:m,count:x,readOnly:p,onChange:te}),ni(m)&&t.jsx(Bi,{step:m,inLoop:a!==void 0,outputFields:h,readOnly:p,onChange:te})]})]}),B==="test"&&t.jsx("div",{className:"w6w-stack",children:Fe?ce?t.jsx(i.AppTriggerTestNote,{title:((jt=ze==null?void 0:ze.find(N=>N.key===m.uses.action))==null?void 0:jt.title)??m.uses.action,app:(le==null?void 0:le.displayName)??m.uses.app}):xe?t.jsx(i.TriggerFillForm,{app:m.uses.app,action:m.uses.action,fields:(yt=m.with)==null?void 0:yt.fields,persist:{workflowId:e,stepId:m.id,input:ct},listen:m.uses.app===i.WEBHOOK_APP&&A.listSubscriptionsForWorkflow&&A.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(Mn,{seed:He,readOnly:p}),we&&!p&&t.jsx(i.LastUsedNote,{onClear:()=>{ve.clear(),_e(!1),E("{}")}}),t.jsx(ns,{text:X,onChange:E,seeds:Te,readOnly:p}),Z===null?t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):t.jsx(jo,{params:Z,values:Me,testStartState:at,view:ue,literalKeys:m.uses.app===i.SCRIPT_APP?ki:void 0}),t.jsx(i.StepTestRun,{ref:_,app:m.uses.app,action:m.uses.action,connectionId:J,values:Me,state:Ie,canRun:Qe,hideRunButton:!0,persist:{workflowId:e,stepId:m.id,input:ct},onBusyChange:ee})]}):Ne?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(ns,{text:X,onChange:wt,seeds:Te,readOnly:p,expand:!Q,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(Ai,{items:Q,save:et})]}):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===i.RACE_APP&&B==="configure"?t.jsx("button",{type:"button",className:"w6w-btn",onClick:c,children:"Done"}):B!=="test"?t.jsxs(t.Fragment,{children:[f&&!p&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:c,children:"Done"}),t.jsx("button",{type:"button",className:"w6w-btn",disabled:C,onClick:()=>b(B==="setup"?"configure":"test"),children:"Next →"})]}):t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:c,children:"Done"}),Fe&&!xe&&t.jsx("button",{type:"button",className:"w6w-btn",disabled:p||!Qe||V,onClick:()=>{var N;v==null||v(),(N=_.current)==null||N.run()},children:V?"Testing…":"Test"}),Ne&&t.jsx("button",{type:"button",className:"w6w-btn",disabled:p||!(Q!=null&&Q.length)||et==="saving",onClick:()=>void lt(),children:et==="saving"?"Testing…":"Test"})]})]})]})})}const Wi=!1;function $i({step:e,count:s,readOnly:o,onChange:n}){const a=s>=2,l=e.fanOut==="parallel"?"parallel":"sequential";return t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Run next nodes"}),t.jsxs("select",{"aria-label":"Run next nodes",value:l,disabled:o||!a,onChange:c=>n(Po(e,c.target.value)),children:[t.jsx("option",{value:"sequential",children:"In sequence"}),t.jsx("option",{value:"parallel",children:"In parallel"})]}),!a&&t.jsx("span",{className:"w6w-muted w6w-small",children:"Connect two or more steps after this one to choose how they run."})]})}function pn({to:e}){return t.jsxs("div",{className:"w6w-state-map-row w6w-state-map-head","aria-hidden":"true",children:[t.jsx("span",{children:"From this step output"}),t.jsx("span",{}),t.jsx("span",{children:e})]})}function fn(){return t.jsx("span",{className:"w6w-state-map-arrow","aria-hidden":"true",children:"→"})}function hn({label:e,fields:s,value:o,readOnly:n,onChange:a}){const l=d.useMemo(()=>(s??[]).map(c=>({value:c,label:c})),[s]);return t.jsx(i.Combobox,{mode:"combobox",forceSelection:!1,"aria-label":e,placeholder:"Whole output, or e.g. order",options:l,value:o,disabled:n,emptyText:l.length>0?"No matching field — keep typing a path":"Test this step to list its output fields, or type a path",onChange:a})}function Bi({step:e,inLoop:s,outputFields:o,readOnly:n,onChange:a}){const l=Qo(e),c=be.validateStateConfig(l),f=h=>a(ti(e,h)),p=l.mode==="pick"&&Array.isArray(l.map)?l.map:[],g=(h,v)=>f({mode:"pick",map:p.map((S,R)=>R===h?{...S,...v}:S)}),x=h=>{if(l.mode!=="append")return;const v=h.path??l.path,S="from"in h?h.from:l.from;f({mode:"append",path:v,...S?{from:S}:{}})};return t.jsxs("div",{className:"w6w-field w6w-stack",children:[t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Write to state"}),t.jsx("select",{"aria-label":"Write to state",value:l.mode,disabled:n,onChange:h=>f(si(e,h.target.value)),children:Yo.map(h=>t.jsx("option",{value:h,children:Zo[h]},h))})]}),l.mode==="key"&&t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"To state key"}),t.jsx("input",{type:"text","aria-label":"State key",placeholder:"e.g. order",value:l.key,disabled:n,onChange:h=>f({mode:"key",key:h.target.value})}),t.jsxs("span",{className:"w6w-hint",children:["Copies the whole step output into ",t.jsx("code",{children:"state.<key>"}),". A dotted key such as"," ",t.jsx("code",{children:"order.id"})," nests."]})]}),l.mode==="pick"&&t.jsxs("div",{className:"w6w-stack",children:[t.jsx(pn,{to:"To state key"}),p.length===0&&t.jsx("p",{className:"w6w-muted w6w-small",children:"No fields yet — add one below."}),p.map((h,v)=>t.jsxs("div",{className:"w6w-datavar-row w6w-state-map-row",children:[t.jsx(hn,{label:"From output field",fields:o,value:h.from,readOnly:n,onChange:S=>g(v,{from:S})}),t.jsx(fn,{}),t.jsx("input",{type:"text","aria-label":"To state path",placeholder:"e.g. order",value:h.to,disabled:n,onChange:S=>g(v,{to:S.target.value})}),!n&&t.jsx(i.DeleteButton,{label:"Remove field",onClick:()=>f({mode:"pick",map:p.filter((S,R)=>R!==v)})})]},v)),!n&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-state-map-add","aria-label":"Add field",onClick:()=>f({mode:"pick",map:[...p,{from:"",to:""}]}),children:"+ Add field"}),t.jsxs("span",{className:"w6w-hint",children:["Copies ",t.jsx("code",{children:"output.<path>"})," into ",t.jsx("code",{children:"state.<key>"}),". Leave the left side blank to copy the whole output."]})]}),l.mode==="append"&&t.jsxs("div",{className:"w6w-stack",children:[t.jsx(pn,{to:"Append to state list"}),t.jsxs("div",{className:"w6w-datavar-row w6w-state-map-row",children:[t.jsx(hn,{label:"Output field to append",fields:o,value:l.from??"",readOnly:n,onChange:h=>x({from:h})}),t.jsx(fn,{}),t.jsx("input",{type:"text","aria-label":"Append to state path",placeholder:"e.g. orders",value:l.path,disabled:n,onChange:h=>x({path:h.target.value})})]}),t.jsxs("span",{className:"w6w-hint",children:["Appends ",t.jsx("code",{children:"output.<path>"})," to the list at ",t.jsx("code",{children:"state.<key>"}),". Leave the left side blank to append the whole output."]})]}),c.length>0&&t.jsx("div",{role:"alert",className:"w6w-state-write-issues w6w-small",children:c.map(h=>t.jsx("div",{children:h.message},`${h.code}:${h.message}`))}),l.mode!=="off"&&t.jsxs("span",{className:"w6w-muted w6w-small",children:["Writing ",t.jsx("code",{children:"null"})," deletes the key, and secrets are stored masked."]}),s&&t.jsx("span",{className:"w6w-muted w6w-small",children:"This step is inside a For each, so it writes once per item — Append collects one entry per item."})]})}function Vi({workflowId:e,step:s,readOnly:o}){const n=i.useW6WApi(),[a,l]=d.useState(void 0),[c,f]=d.useState(null),[p,g]=d.useState(!1);d.useEffect(()=>{const h=n.listSubscriptionsForWorkflow;if(!h)return;let v=!1;return h(e).then(S=>{v||l(i.pickWebhookSubscription(S,s.id))}).catch(S=>!v&&f(S.message)),()=>{v=!0}},[n,e,s.id]);const x=()=>{const h=n.createSubscription;h&&(f(null),g(!0),h(i.WEBHOOK_APP,s.uses.action,{workflowId:e,connectionId:null,params:s.with??{}}).then(v=>{g(!1),l(v)}).catch(v=>{g(!1),f(v instanceof Error?v.message:String(v))}))};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."]}),c&&t.jsx("div",{className:"w6w-result w6w-error",children:c}),a!=null&&a.webhookUrl?t.jsx(ke.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…"}):!o&&t.jsx("button",{type:"button",className:"w6w-btn",disabled:p,onClick:x,children:p?"Creating…":"Create webhook URL"})]})}function zi({step:e,app:s,actions:o,conns:n,connsFailed:a,isInternal:l,actionLabel:c="Action",readOnly:f,onChangeAction:p,onChangeTriggerEvents:g,onChangeConnection:x,onChangeConnectionRef:h,onChangeApp:v,onConnectionCreated:S}){const R=e.uses.trigger?i.eventbriteTriggerChoices(e.uses.app,o,e.uses.action,e.with??{}):null,[A,D]=d.useState(null),m=d.useRef(null),P=i.useWorkflowConnections(),O=i.connectionIdFor(e,P==null?void 0:P.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":A==="app",disabled:f,onClick:()=>D(J=>J==="app"?null:"app"),children:[!l&&s&&t.jsx(i.AppIcon,{src:s.iconSvg,srcDark:s.iconSvgDark,brandColor:s.brandColor,name:s.displayName,size:20}),t.jsx("span",{className:"w6w-conn-label-name",children:l?e.uses.app:(s==null?void 0:s.displayName)??e.uses.app})]}),!l&&t.jsx(i.WorkflowConnectionPicker,{step:e,conns:n,failed:a,readOnly:f,open:A==="conn",onOpenChange:J=>D(J?"conn":null),anchorRef:m,onChangeConnection:x,onChangeConnectionRef:h,onConnectionCreated:S})]}),A==="app"&&t.jsx(i.AnchoredFlyout,{anchorRef:m,onClose:()=>D(null),children:t.jsx(i.AppPicker,{onSelectApp:J=>{const I=J.id===e.uses.app;v(J.id),D(I?"conn":null)}})})]}),l&&!(o!=null&&o.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(i.EventbriteTriggerPicker,{choices:R,readOnly:f,onChange:J=>g(R.triggerKey,J)}):t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:c}),t.jsx(i.Combobox,{value:e.uses.action,disabled:f||o===null,onChange:p,options:o===null?[{value:e.uses.action,label:e.uses.action}]:o.map(J=>({value:J.key,label:J.title??J.key}))})]})]})}function mn({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 Hi({resources:e}){const s=i.useW6WApi(),o=e.highlightNode;d.useEffect(()=>()=>o==null?void 0:o(null),[o]);const[n,a]=d.useState([]),[l,c]=d.useState(!0),[f,p]=d.useState(),[g,x]=d.useState(),[h,v]=d.useState(null),[S,R]=d.useState(!1),[A,D]=d.useState(!1),m=d.useRef(0),P=d.useCallback(async()=>{const E=++m.current;c(!0),p(void 0);try{const _=await s.listConnections();return E!==m.current?void 0:(a(_),_)}catch(_){E===m.current&&p(_.message)}finally{E===m.current&&c(!1)}},[s]);d.useEffect(()=>(P(),()=>{m.current++}),[P]);const[O,J]=d.useState(new Map),I=JSON.stringify([...new Set([...Object.values(e.connections).map(E=>E.app),...n.map(E=>E.appId)])].filter(E=>{var _;return!((_=e.apps)!=null&&_.has(E))&&!n.some(V=>V.appId===E&&V.app!==void 0)}).sort());d.useEffect(()=>{var U,z;let E=!1;const _=JSON.parse(I);if(l||!_.length)return;const V=(U=s.listAppsByIds)==null?void 0:U.bind(s),ee=V?Promise.all(Array.from({length:Math.ceil(_.length/50)},(H,Z)=>V(_.slice(Z*50,(Z+1)*50)))).then(H=>H.flat()):(z=s.listApps)==null?void 0:z.call(s);return ee==null||ee.then(H=>{E||J(new Map(H.map(Z=>[Z.id,Z])))}).catch(()=>{}),()=>{E=!0}},[s,I,l]);const M=E=>{var U;const _=n.find(z=>z.appId===E&&z.app)??n.find(z=>z.appId===E&&z.app!==void 0),V=_?i.resolveConnectionAppMeta(_,O):O.get(E),ee=(U=e.apps)==null?void 0:U.get(E);return ee?{...V,...ee}:V},C=E=>{var _;return((_=M(E))==null?void 0:_.displayName)||E},$=E=>{if(e.readOnly)return!1;try{return e.edit(E),x(void 0),!0}catch(_){return x(_.message),!1}},q=E=>i.nextWorkflowConnectionName(E.appId,e.connections),B=()=>{v(null),x(void 0),R(!1)},b=h!=null&&h.ref?e.connections[h.ref]:void 0,W=n.find(E=>E.id===(h==null?void 0:h.connection)),de=(b==null?void 0:b.app)??(W==null?void 0:W.appId),ue=e.nodes.filter(E=>E.uses.app===de),je=e.nodes.filter(E=>(h==null?void 0:h.ref)!==void 0&&E.uses.connectionRef===h.ref),ie=n.filter(E=>!b||E.appId===b.app).map(E=>({value:E.id,label:b?E.displayName||E.id:`${C(E.appId)} · ${E.displayName||E.id}`}));h!=null&&h.connection&&!ie.some(E=>E.value===h.connection)&&ie.unshift({value:h.connection,label:h.connection.startsWith("zerocred:")?"Built-in":h.connection});const k=(E,_=28)=>{const V=M(E);return t.jsx(i.AppIcon,{src:V==null?void 0:V.iconSvg,srcDark:V==null?void 0:V.iconSvgDark,brandColor:V==null?void 0:V.brandColor,name:C(E),size:_})},X=()=>{if(!h||!h.name.trim()||!h.connection||!de)return;const E=h.ref!==void 0?{type:"update",ref:h.ref,name:h.name,connection:h.connection,nodeIds:h.allNodes?ue.map(_=>_.id):void 0}:{type:"add",name:h.name,app:de,connection:h.connection};$(E)&&B()};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(i.IconButton,{label:"Add connection",disabled:e.readOnly,onClick:()=>{x(void 0),v({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 P(),children:"Retry"})]}),Object.entries(e.connections).map(([E,_])=>{var z;const V=e.nodes.filter(H=>H.uses.connectionRef===E),ee=n.find(H=>H.id===_.connection),U=(ee==null?void 0:ee.displayName)||((z=_.connection)!=null&&z.startsWith("zerocred:")?"Built-in":_.connection)||"No credentials selected";return t.jsxs("section",{className:"w6w-workflow-connection","data-connection-resource":E,children:[t.jsxs("div",{className:"w6w-connection-app-heading",children:[k(_.app),t.jsxs("div",{className:"w6w-connection-summary",children:[t.jsx("strong",{children:C(_.app)}),t.jsx("span",{className:"w6w-small",children:U}),t.jsxs("span",{className:"w6w-muted w6w-small",children:[E,ee!=null&&ee.state?` · ${ee.state}`:""]})]}),t.jsx(i.IconButton,{icon:"edit",label:`Edit connection ${E}`,disabled:e.readOnly,onClick:()=>{x(void 0),v({ref:E,name:E,connection:_.connection??"",allNodes:!1})}})]}),V.length>0?t.jsxs("details",{className:"w6w-connection-consumers",onToggle:H=>{H.currentTarget.open||o==null||o(null)},children:[t.jsxs("summary",{className:"w6w-muted w6w-small",children:["Used by ",V.length," ",V.length===1?"node":"nodes"]}),t.jsx("ul",{className:"w6w-connection-node-list",children:V.map(H=>t.jsx("li",{children:e.focusNode?t.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost","aria-label":`Show ${H.id} on canvas`,onClick:()=>{var Z;return(Z=e.focusNode)==null?void 0:Z.call(e,H.id)},onMouseEnter:()=>o==null?void 0:o(H.id),onMouseLeave:()=>o==null?void 0:o(null),onFocus:()=>o==null?void 0:o(H.id),onBlur:()=>o==null?void 0:o(null),children:[t.jsx(mn,{trigger:i.isTriggerStep(H.uses)}),t.jsxs("span",{className:"w6w-connection-node-label",children:[t.jsx("strong",{children:H.uses.action}),t.jsx("span",{className:"w6w-muted w6w-small",children:H.id})]})]}):t.jsxs("span",{className:"w6w-connection-app-heading",children:[t.jsx(mn,{trigger:i.isTriggerStep(H.uses)}),t.jsxs("span",{className:"w6w-connection-node-label",children:[t.jsx("strong",{children:H.uses.action}),t.jsx("span",{className:"w6w-muted w6w-small",children:H.id})]})]})},H.id))})]}):t.jsx("span",{className:"w6w-muted w6w-small",children:"Not used by any nodes yet."})]},E)}),!Object.keys(e.connections).length&&t.jsx("p",{className:"w6w-muted w6w-small",children:"No workflow connections yet."}),h&&!A&&!S&&t.jsxs(i.Modal,{title:h.ref!==void 0?"Edit connection":"Add connection",titleIcon:de?k(de):void 0,subtitle:de?C(de):void 0,onClose:B,children:[t.jsxs("div",{className:"w6w-modal-body w6w-stack",children:[g&&t.jsx("p",{role:"alert",className:"w6w-field-error",children:g}),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 P(),children:"Retry"})]}),h.ref!==void 0&&!b&&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:h.name,disabled:e.readOnly,onChange:E=>v({...h,name:E.target.value})})]}),t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:b?"Credentials":"Existing connection"}),t.jsx(i.Combobox,{"aria-label":b?"Credentials":"Connection to add",options:ie,value:h.connection,placeholder:l?"Loading connections…":"Choose a connection…",disabled:e.readOnly||l||!!f,onChange:E=>{const _=n.find(V=>V.id===E);v({...h,connection:E,name:!h.name&&_?q(_):h.name})}})]}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:e.readOnly,onClick:()=>D(!0),children:"Create new credentials"}),b&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"w6w-muted w6w-small",children:h.allNodes?`Saving applies these credentials to all ${ue.length} ${C(b.app)} nodes.`:`Saving updates credentials for ${je.length} linked ${je.length===1?"node":"nodes"}.`}),ue.length>0&&t.jsxs("label",{className:"w6w-connection-scope",children:[t.jsx("input",{type:"checkbox",checked:h.allNodes||ue.every(E=>E.uses.connectionRef===h.ref),disabled:e.readOnly||ue.every(E=>E.uses.connectionRef===h.ref),onChange:E=>v({...h,allNodes:E.target.checked})}),"Use for all ",ue.length," ",C(b.app)," ",ue.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:B,children:"Cancel"}),t.jsx("button",{type:"button",className:"w6w-btn",disabled:e.readOnly||l||!!f||!h.name.trim()||!h.connection||!de||h.ref!==void 0&&!b,onClick:X,children:h.ref!==void 0?"Save changes":"Add to workflow"})]})]}),h&&S&&t.jsx(i.ConfirmModal,{title:"Remove workflow connection",message:`Remove “${h.ref}” from this workflow? The saved credentials will remain available.`,confirmLabel:"Remove",onClose:()=>R(!1),onConfirm:()=>{h.ref&&$({type:"remove",ref:h.ref})?B():R(!1)}}),h&&A&&t.jsx(i.AddConnectionModal,{initialAppId:b==null?void 0:b.app,onClose:()=>D(!1),onCreated:({connectionId:E})=>{D(!1),P().then(_=>{const V=_==null?void 0:_.find(ee=>ee.id===E);V&&v(ee=>ee?{...ee,connection:V.id,name:ee.name||q(V)}: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=wn;exports.MAX_NOTE_BYTES=xn;exports.MAX_SECTIONS=gn;exports.WorkflowConnectionsPanel=Hi;exports.WorkflowFlowEditor=Ci;exports.applyStepProblemFix=An;exports.assignMembership=Zt;exports.clampCanvas=Qt;exports.findLoopProblems=Uo;exports.findStateWriteProblems=Ko;exports.isDisabledStep=De;exports.isPausedStep=Ze;exports.pausedStopAt=ts;exports.pruneSectionMembers=os;exports.renameSectionMember=jn;exports.roundGeometry=Yt;exports.sectionsContaining=yn;exports.withCanvasGeometry=bn;exports.withDisabled=kn;exports.withPaused=Nn;
|
|
6
6
|
//# sourceMappingURL=flow.cjs.map
|